-
Notifications
You must be signed in to change notification settings - Fork 1
/
target_test.go
64 lines (48 loc) · 2.07 KB
/
target_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
package gobtcsign
import (
"testing"
"github.com/btcsuite/btcd/chaincfg"
"github.com/stretchr/testify/require"
)
func TestNewAddressTuple_ValidAddress(t *testing.T) {
// 测试有效地址
address := "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
res := NewAddressTuple(address)
t.Log("address:", res.Address)
require.Equal(t, address, res.Address)
require.NoError(t, res.VerifyMatch(&chaincfg.MainNetParams))
pkScript, err := res.GetPkScript(&chaincfg.MainNetParams)
require.NoError(t, err)
t.Log("pk-script:", pkScript)
expected := []byte{118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172}
require.Equal(t, expected, pkScript)
}
func TestNewAddressTuple_AddressPredefined_PkScriptPredefined(t *testing.T) {
// 测试预设 PkScript
address := "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
res := &AddressTuple{
Address: address,
PkScript: []byte{118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172},
}
t.Log("address:", res.Address)
t.Log("predefined pk-script:", res.PkScript)
require.Equal(t, address, res.Address)
require.NoError(t, res.VerifyMatch(&chaincfg.MainNetParams))
pkScript, err := res.GetPkScript(&chaincfg.MainNetParams)
require.NoError(t, err)
expected := []byte{118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172}
require.Equal(t, expected, pkScript)
}
func TestNewAddressTuple_PkScriptPredefined(t *testing.T) {
// 测试预设 PkScript
res := &AddressTuple{
Address: "",
PkScript: []byte{118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172},
}
t.Log("predefined pk-script:", res.PkScript)
require.NoError(t, res.VerifyMatch(&chaincfg.MainNetParams))
pkScript, err := res.GetPkScript(&chaincfg.MainNetParams)
require.NoError(t, err)
expected := []byte{118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172}
require.Equal(t, expected, pkScript)
}