-
Notifications
You must be signed in to change notification settings - Fork 3
/
usable_address_test.go
128 lines (102 loc) · 4.4 KB
/
usable_address_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package cnlib
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestMetaAddress_Receive_Segwit_Address(t *testing.T) {
path := NewDerivationPath(BaseCoinBip84MainNet, 0, 0)
wallet := NewHDWalletFromWords(w, BaseCoinBip84MainNet)
usableAddress, err := newUsableAddressWithDerivationPath(wallet, path)
assert.Nil(t, err)
meta, err := usableAddress.MetaAddress()
assert.Nil(t, err)
expectedAddr := "bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu"
expectedPubkey := "0430d54fd0dd420a6e5f8d3624f5f3482cae350f79d5f0753bf5beef9c2d91af3c04717159ce0828a7f686c2c7510b7aa7d4c685ebc2051642ccbebc7099e2f679"
assert.Equal(t, expectedAddr, meta.Address)
assert.Equal(t, path, meta.DerivationPath)
assert.Equal(t, expectedPubkey, meta.UncompressedPublicKey)
}
func TestMetaAddress_Change_Segwit_Address(t *testing.T) {
path := NewDerivationPath(BaseCoinBip84MainNet, 1, 0)
wallet := NewHDWalletFromWords(w, BaseCoinBip84MainNet)
usableAddress, err := newUsableAddressWithDerivationPath(wallet, path)
assert.Nil(t, err)
meta, err := usableAddress.MetaAddress()
assert.Nil(t, err)
expectedAddr := "bc1q8c6fshw2dlwun7ekn9qwf37cu2rn755upcp6el"
expectedPubkey := ""
assert.Equal(t, expectedAddr, meta.Address)
assert.Equal(t, path, meta.DerivationPath)
assert.Equal(t, expectedPubkey, meta.UncompressedPublicKey)
}
func TestMetaAddress_RegTestAddresses(t *testing.T) {
rpath0 := NewDerivationPath(BaseCoinBip84TestNet, 0, 0)
rpath1 := NewDerivationPath(BaseCoinBip84TestNet, 0, 1)
rpath2 := NewDerivationPath(BaseCoinBip84TestNet, 0, 2)
cpath0 := NewDerivationPath(BaseCoinBip84TestNet, 1, 0)
cpath1 := NewDerivationPath(BaseCoinBip84TestNet, 1, 1)
cpath2 := NewDerivationPath(BaseCoinBip84TestNet, 1, 2)
rexp0 := "bcrt1q6rz28mcfaxtmd6v789l9rrlrusdprr9pz3cppk"
rexp1 := "bcrt1qd7spv5q28348xl4myc8zmh983w5jx32cs707jh"
rexp2 := "bcrt1qxdyjf6h5d6qxap4n2dap97q4j5ps6ua8jkxz0z"
cexp0 := "bcrt1q9u62588spffmq4dzjxsr5l297znf3z6jkgnhsw"
cexp1 := "bcrt1qkwgskuzmmwwvqajnyr7yp9hgvh5y45kg984qvy"
cexp2 := "bcrt1q2vma00td2g9llw8hwa8ny3r774rtt7ae3q2e44"
wallet := NewHDWalletFromWords(w, BaseCoinBip84TestNet)
rua0, err := newUsableAddressWithDerivationPath(wallet, rpath0)
assert.Nil(t, err)
rua1, err := newUsableAddressWithDerivationPath(wallet, rpath1)
assert.Nil(t, err)
rua2, err := newUsableAddressWithDerivationPath(wallet, rpath2)
assert.Nil(t, err)
cua0, err := newUsableAddressWithDerivationPath(wallet, cpath0)
assert.Nil(t, err)
cua1, err := newUsableAddressWithDerivationPath(wallet, cpath1)
assert.Nil(t, err)
cua2, err := newUsableAddressWithDerivationPath(wallet, cpath2)
assert.Nil(t, err)
rua0meta, err := rua0.MetaAddress()
assert.Nil(t, err)
rua1meta, err := rua1.MetaAddress()
assert.Nil(t, err)
rua2meta, err := rua2.MetaAddress()
assert.Nil(t, err)
cua0meta, err := cua0.MetaAddress()
assert.Nil(t, err)
cua1meta, err := cua1.MetaAddress()
assert.Nil(t, err)
cua2meta, err := cua2.MetaAddress()
assert.Nil(t, err)
assert.Equal(t, rexp0, rua0meta.Address)
assert.Equal(t, rexp1, rua1meta.Address)
assert.Equal(t, rexp2, rua2meta.Address)
assert.Equal(t, cexp0, cua0meta.Address)
assert.Equal(t, cexp1, cua1meta.Address)
assert.Equal(t, cexp2, cua2meta.Address)
}
func TestMetaAddress_Receive_LegacySegwit_Address(t *testing.T) {
path := NewDerivationPath(BaseCoinBip49MainNet, 0, 0)
wallet := NewHDWalletFromWords(w, BaseCoinBip49MainNet)
usableAddress, err := newUsableAddressWithDerivationPath(wallet, path)
assert.Nil(t, err)
meta, err := usableAddress.MetaAddress()
assert.Nil(t, err)
expectedAddr := "37VucYSaXLCAsxYyAPfbSi9eh4iEcbShgf"
expectedPubkey := "049b3b694b8fc5b5e07fb069c783cac754f5d38c3e08bed1960e31fdb1dda35c2449bdd1f0ae7d37a04991d4f5927efd359c13189437d9eae0faf7d003ffd04c89"
assert.Equal(t, expectedAddr, meta.Address)
assert.Equal(t, path, meta.DerivationPath)
assert.Equal(t, expectedPubkey, meta.UncompressedPublicKey)
}
func TestMetaAddress_Change_LegacySegwit_Address(t *testing.T) {
path := NewDerivationPath(BaseCoinBip49MainNet, 1, 0)
wallet := NewHDWalletFromWords(w, BaseCoinBip49MainNet)
usableAddress, err := newUsableAddressWithDerivationPath(wallet, path)
assert.Nil(t, err)
meta, err := usableAddress.MetaAddress()
assert.Nil(t, err)
expectedAddr := "34K56kSjgUCUSD8GTtuF7c9Zzwokbs6uZ7"
expectedPubkey := ""
assert.Equal(t, expectedAddr, meta.Address)
assert.Equal(t, path, meta.DerivationPath)
assert.Equal(t, expectedPubkey, meta.UncompressedPublicKey)
}