-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress_test.go
53 lines (42 loc) · 1.11 KB
/
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
package chia_address_generator
import (
"encoding/hex"
bls "github.com/chuwt/chia-bls-go"
"testing"
)
var (
testPkBytes, _ = hex.DecodeString("aaf079d607cabb95c0039c51317cd6e84e66bb6b5c9aecf8fdc4f0ba97c7f2ec8bb2b1831ad3ea0ba8f701a26177e43e")
testAddress = "xch1knrllhacj7j2m7xqt64klys3kfalewr5p94dg9cpxfygpr70secqdnnl9r"
)
func TestGenerateAddress(t *testing.T) {
pk, err := bls.NewPublicKey(testPkBytes)
if err != nil {
t.Fatal(err)
}
addr1, err := NewAddressFromPkBytes(testPkBytes, "xch")
if err != nil {
t.Fatal(err)
}
addr2, err := NewAddressFromPK(pk, "xch")
if err != nil {
t.Fatal(err)
}
addr3, err := NewAddressFromPKHex(pk.Hex(), "xch")
if err != nil {
t.Fatal(err)
}
t.Log(testAddress == addr1 && addr1 == addr2 && addr2 == addr3, addr1)
}
func TestPH2Addr(t *testing.T) {
prefix, puzzleHash, err := GetPuzzleHashFromAddress(testAddress)
if err != nil {
t.Fatal(err)
}
t.Log("prefix:", prefix)
t.Log("puzzleHash", hex.EncodeToString(puzzleHash))
address, err := GetAddressFromPuzzleHash(puzzleHash, prefix)
if err != nil {
t.Fatal(err)
}
t.Log(address == testAddress, address)
}