forked from lightninglabs/lndinit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_init_wallet_test.go
38 lines (29 loc) · 1007 Bytes
/
cmd_init_wallet_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"io/ioutil"
"testing"
"github.com/stretchr/testify/require"
)
var (
testSeedWithNewline = []byte("seed phrase with newline\n")
testPasswordWithNewline = []byte("p4ssw0rd\r\n\n\r\r\n")
)
// TestReadInput makes sure input files are always trimmed so we don't have any
// newline characters left over.
func TestReadInput(t *testing.T) {
cmd := newInitWalletCommand()
cmd.File.Seed = writeToTempFile(t, testSeedWithNewline)
cmd.File.WalletPassword = writeToTempFile(t, testPasswordWithNewline)
seed, seedPassphrase, walletPassword, err := cmd.readInput(true)
require.NoError(t, err)
require.Equal(t, "seed phrase with newline", seed)
require.Equal(t, "", seedPassphrase)
require.Equal(t, "p4ssw0rd", walletPassword)
}
func writeToTempFile(t *testing.T, data []byte) string {
tempFileName, err := ioutil.TempFile("", "*.txt")
require.NoError(t, err)
err = ioutil.WriteFile(tempFileName.Name(), data, 0600)
require.NoError(t, err)
return tempFileName.Name()
}