Add canDecode flag to tests.
This commit adds a new flag to the tests which controls whether or not an address can be decoded. This is to support the upcoming public key address type and possible future addresses which aren't directly decodable.
This commit is contained in:
parent
8928b361d4
commit
de0c59fee1
1 changed files with 95 additions and 81 deletions
|
@ -18,15 +18,17 @@ func TestAddresses(t *testing.T) {
|
|||
name string
|
||||
addr string
|
||||
valid bool
|
||||
canDecode bool
|
||||
result btcutil.Address
|
||||
f func() (btcutil.Address, error)
|
||||
net btcwire.BitcoinNet // only checked for P2PKH and P2SH
|
||||
net btcwire.BitcoinNet
|
||||
}{
|
||||
// Positive P2PKH tests.
|
||||
{
|
||||
name: "mainnet p2pkh",
|
||||
addr: "1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX",
|
||||
valid: true,
|
||||
canDecode: true,
|
||||
result: btcutil.TstAddressPubKeyHash(
|
||||
[ripemd160.Size]byte{
|
||||
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
|
||||
|
@ -44,6 +46,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "mainnet p2pkh 2",
|
||||
addr: "12MzCDwodF9G1e7jfwLXfR164RNtx4BRVG",
|
||||
valid: true,
|
||||
canDecode: true,
|
||||
result: btcutil.TstAddressPubKeyHash(
|
||||
[ripemd160.Size]byte{
|
||||
0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b, 0xf4,
|
||||
|
@ -61,6 +64,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "testnet p2pkh",
|
||||
addr: "mrX9vMRYLfVy1BnZbc5gZjuyaqH3ZW2ZHz",
|
||||
valid: true,
|
||||
canDecode: true,
|
||||
result: btcutil.TstAddressPubKeyHash(
|
||||
[ripemd160.Size]byte{
|
||||
0x78, 0xb3, 0x16, 0xa0, 0x86, 0x47, 0xd5, 0xb7, 0x72, 0x83,
|
||||
|
@ -80,6 +84,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "p2pkh wrong byte identifier/net",
|
||||
addr: "MrX9vMRYLfVy1BnZbc5gZjuyaqH3ZW2ZHz",
|
||||
valid: false,
|
||||
canDecode: true,
|
||||
f: func() (btcutil.Address, error) {
|
||||
pkHash := []byte{
|
||||
0x78, 0xb3, 0x16, 0xa0, 0x86, 0x47, 0xd5, 0xb7, 0x72, 0x83,
|
||||
|
@ -91,6 +96,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "p2pkh wrong hash length",
|
||||
addr: "",
|
||||
valid: false,
|
||||
canDecode: true,
|
||||
f: func() (btcutil.Address, error) {
|
||||
pkHash := []byte{
|
||||
0x00, 0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b,
|
||||
|
@ -103,6 +109,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "p2pkh bad checksum",
|
||||
addr: "1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gY",
|
||||
valid: false,
|
||||
canDecode: true,
|
||||
},
|
||||
|
||||
// Positive P2SH tests.
|
||||
|
@ -113,6 +120,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "mainnet p2sh",
|
||||
addr: "3QJmV3qfvL9SuYo34YihAf3sRCW3qSinyC",
|
||||
valid: true,
|
||||
canDecode: true,
|
||||
result: btcutil.TstAddressScriptHash(
|
||||
[ripemd160.Size]byte{
|
||||
0xf8, 0x15, 0xb0, 0x36, 0xd9, 0xbb, 0xbc, 0xe5, 0xe9, 0xf2,
|
||||
|
@ -152,6 +160,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "mainnet p2sh 2",
|
||||
addr: "3NukJ6fYZJ5Kk8bPjycAnruZkE5Q7UW7i8",
|
||||
valid: true,
|
||||
canDecode: true,
|
||||
result: btcutil.TstAddressScriptHash(
|
||||
[ripemd160.Size]byte{
|
||||
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
|
||||
|
@ -170,6 +179,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "testnet p2sh",
|
||||
addr: "2NBFNJTktNa7GZusGbDbGKRZTxdK9VVez3n",
|
||||
valid: true,
|
||||
canDecode: true,
|
||||
result: btcutil.TstAddressScriptHash(
|
||||
[ripemd160.Size]byte{
|
||||
0xc5, 0x79, 0x34, 0x2c, 0x2c, 0x4c, 0x92, 0x20, 0x20, 0x5e,
|
||||
|
@ -189,6 +199,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "p2sh wrong hash length",
|
||||
addr: "",
|
||||
valid: false,
|
||||
canDecode: true,
|
||||
f: func() (btcutil.Address, error) {
|
||||
hash := []byte{
|
||||
0x00, 0xf8, 0x15, 0xb0, 0x36, 0xd9, 0xbb, 0xbc, 0xe5, 0xe9,
|
||||
|
@ -201,6 +212,7 @@ func TestAddresses(t *testing.T) {
|
|||
name: "p2sh wrong byte identifier/net",
|
||||
addr: "0NBFNJTktNa7GZusGbDbGKRZTxdK9VVez3n",
|
||||
valid: false,
|
||||
canDecode: true,
|
||||
f: func() (btcutil.Address, error) {
|
||||
hash := []byte{
|
||||
0xc5, 0x79, 0x34, 0x2c, 0x2c, 0x4c, 0x92, 0x20, 0x20, 0x5e,
|
||||
|
@ -211,6 +223,7 @@ func TestAddresses(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if test.canDecode {
|
||||
// Decode addr and compare error against valid.
|
||||
decoded, err := btcutil.DecodeAddr(test.addr)
|
||||
if (err == nil) != test.valid {
|
||||
|
@ -263,6 +276,7 @@ func TestAddresses(t *testing.T) {
|
|||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !test.valid {
|
||||
// If address is invalid, but a creation function exists,
|
||||
|
|
Loading…
Add table
Reference in a new issue