-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_test.go
More file actions
65 lines (56 loc) · 1.89 KB
/
hash_test.go
File metadata and controls
65 lines (56 loc) · 1.89 KB
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
package outscript_test
import (
"encoding/hex"
"testing"
"github.com/KarpelesLab/outscript"
"github.com/KarpelesLab/secp256k1"
)
func TestOutHashP2WPKH(t *testing.T) {
key := secp256k1.PrivKeyFromBytes(must(hex.DecodeString("eb696a065ef48a2192da5b28b694f87544b30fae8327c4510137a922f32c6dcf")))
out := must(outscript.New(key.PubKey()).Out("p2wpkh"))
h := out.Hash()
if len(h) != 20 {
t.Errorf("expected 20-byte hash, got %d", len(h))
}
}
func TestOutHashP2PKH(t *testing.T) {
key := secp256k1.PrivKeyFromBytes(must(hex.DecodeString("eb696a065ef48a2192da5b28b694f87544b30fae8327c4510137a922f32c6dcf")))
out := must(outscript.New(key.PubKey()).Out("p2pkh"))
h := out.Hash()
if len(h) != 20 {
t.Errorf("expected 20-byte hash, got %d", len(h))
}
}
func TestOutHashP2PK(t *testing.T) {
key := secp256k1.PrivKeyFromBytes(must(hex.DecodeString("eb696a065ef48a2192da5b28b694f87544b30fae8327c4510137a922f32c6dcf")))
out := must(outscript.New(key.PubKey()).Out("p2pk"))
h := out.Hash()
if len(h) != 20 {
t.Errorf("expected 20-byte hash (ripemd160), got %d", len(h))
}
}
func TestOutHashP2SH(t *testing.T) {
key := secp256k1.PrivKeyFromBytes(must(hex.DecodeString("eb696a065ef48a2192da5b28b694f87544b30fae8327c4510137a922f32c6dcf")))
out := must(outscript.New(key.PubKey()).Out("p2sh:p2pkh"))
// GuessOut will identify this as p2sh
guessed := outscript.GuessOut(out.Bytes(), nil)
h := guessed.Hash()
if len(h) != 20 {
t.Errorf("expected 20-byte hash for p2sh, got %d", len(h))
}
}
func TestOutHashEth(t *testing.T) {
out := must(outscript.ParseEvmAddress("0x2AeB8ADD8337360E088B7D9ce4e857b9BE60f3a7"))
h := out.Hash()
if len(h) != 20 {
t.Errorf("expected 20-byte hash for eth, got %d", len(h))
}
}
func TestOutHashUnknown(t *testing.T) {
script := []byte{0x01, 0x02, 0x03}
out := outscript.GuessOut(script, nil)
h := out.Hash()
if h != nil {
t.Error("expected nil hash for invalid script")
}
}