-
Notifications
You must be signed in to change notification settings - Fork 14
/
zecaddr_test.go
63 lines (50 loc) · 1.17 KB
/
zecaddr_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
package zecutil
import (
"testing"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
)
func TestEncode(t *testing.T) {
var (
wif *btcutil.WIF
err error
)
if wif, err = btcutil.DecodeWIF(testWif); err != nil {
t.Fatal("can't parse wif")
}
var encodedAddr string
encodedAddr, err = Encode(wif.PrivKey.PubKey().SerializeCompressed(), &chaincfg.Params{
Name: "testnet3",
})
if err != nil {
t.Fatal(err)
}
expectedAddr := senderAddr
if expectedAddr != encodedAddr {
t.Fatal("incorrect encode", "expected", expectedAddr, "got", encodedAddr)
}
_, err = Encode(wif.PrivKey.PubKey().SerializeCompressed(), &chaincfg.Params{
Name: "dummy",
})
if err == nil {
t.Fatal("incorect error, got nil")
}
}
func TestDecode(t *testing.T) {
addrs := []string{
"tmF834qorixnCV18bVrkM8WN1Xasy5eXcZV",
"tmRfZVuDK6gVDfwJie1zepKjAELqaGAgWZr",
}
for _, addr := range addrs {
a, err := DecodeAddress(addr, "testnet3")
if err != nil {
t.Fatal("got err", "expected nil", "got", err)
}
if !a.IsForNet(&chaincfg.Params{Name: "testnet3"}) {
t.Fatal("incorrect net")
}
if a.EncodeAddress() != addr {
t.Fatal("incorrect decode")
}
}
}