package addresses import ( "bytes" "encoding/hex" "strings" "testing" ) func TestBase58(t *testing.T) { p := make([]byte, 20) s := Base58Check(0, p) if s != "1111111111111111111114oLvT2" { t.Fatal(s) } v, q, e := DecodeBase58(s) if e != nil || v != 0 || !bytes.Equal(p, q) { t.Fatal(v, q, e) } if _, _, e = DecodeBase58(s[:len(s)-1] + "3"); e == nil { t.Fatal("checksum") } } func TestWitness(t *testing.T) { p, _ := hex.DecodeString("751e76e8199196d454941c45d1b3a323f1433bd6") s, e := EncodeWitness("bc", 0, p) if e != nil || s != "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4" { t.Fatal(s, e) } for _, h := range []string{"bc", "tb", "bcrt"} { for _, v := range []byte{0, 1, 16} { p := make([]byte, 32) s, e := EncodeWitness(h, v, p) if e != nil { t.Fatal(e) } w, q, e := DecodeWitness(strings.ToUpper(s), h) if e != nil || w != v || !bytes.Equal(p, q) { t.Fatal(s, e) } if _, _, e = DecodeWitness(s, "xx"); e == nil { t.Fatal("network") } if _, _, e = DecodeWitness("B"+s[1:], h); e == nil { t.Fatal("mixed case") } } } } func TestScript(t *testing.T) { s, e := WitnessScript(1, make([]byte, 32)) if e != nil || len(s) != 34 || s[0] != 0x51 || s[1] != 32 { t.Fatal(s, e) } if _, e = EncodeWitness("bc", 0, make([]byte, 21)); e == nil { t.Fatal("length") } }