2016-12-02 14:20:07 +01:00
|
|
|
// Copyright (c) 2013-2017 The btcsuite developers
|
2014-01-03 17:10:25 +01:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
package lbcutil_test
|
2014-01-03 17:10:25 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2014-01-08 06:05:07 +01:00
|
|
|
"encoding/hex"
|
2014-03-19 02:18:44 +01:00
|
|
|
"fmt"
|
2014-01-03 17:10:25 +01:00
|
|
|
"reflect"
|
2017-07-25 07:47:41 +02:00
|
|
|
"strings"
|
2014-01-03 17:10:25 +01:00
|
|
|
"testing"
|
2014-05-28 00:06:00 +02:00
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
"github.com/lbryio/lbcd/chaincfg"
|
|
|
|
"github.com/lbryio/lbcd/wire"
|
|
|
|
"github.com/lbryio/lbcutil"
|
2017-02-16 17:07:38 +01:00
|
|
|
"golang.org/x/crypto/ripemd160"
|
2014-01-03 17:10:25 +01:00
|
|
|
)
|
|
|
|
|
2019-01-17 01:07:58 +01:00
|
|
|
type CustomParamStruct struct {
|
2020-07-08 11:22:13 +02:00
|
|
|
Net wire.BitcoinNet
|
2019-01-17 01:07:58 +01:00
|
|
|
PubKeyHashAddrID byte
|
|
|
|
ScriptHashAddrID byte
|
2020-07-08 11:22:13 +02:00
|
|
|
Bech32HRPSegwit string
|
2019-01-17 01:07:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var CustomParams = CustomParamStruct{
|
2020-07-08 11:22:13 +02:00
|
|
|
Net: 0xdbb6c0fb, // litecoin mainnet HD version bytes
|
|
|
|
PubKeyHashAddrID: 0x30, // starts with L
|
|
|
|
ScriptHashAddrID: 0x32, // starts with M
|
|
|
|
Bech32HRPSegwit: "ltc", // starts with ltc
|
2019-01-17 01:07:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// We use this function to be able to test functionality in DecodeAddress for
|
|
|
|
// defaultNet addresses
|
|
|
|
func applyCustomParams(params chaincfg.Params, customParams CustomParamStruct) chaincfg.Params {
|
2020-07-08 11:22:13 +02:00
|
|
|
params.Net = customParams.Net
|
2019-01-17 01:07:58 +01:00
|
|
|
params.PubKeyHashAddrID = customParams.PubKeyHashAddrID
|
|
|
|
params.ScriptHashAddrID = customParams.ScriptHashAddrID
|
2020-07-08 11:22:13 +02:00
|
|
|
params.Bech32HRPSegwit = customParams.Bech32HRPSegwit
|
2019-01-17 01:07:58 +01:00
|
|
|
return params
|
|
|
|
}
|
|
|
|
|
|
|
|
var customParams = applyCustomParams(chaincfg.MainNetParams, CustomParams)
|
|
|
|
|
2014-01-03 17:10:25 +01:00
|
|
|
func TestAddresses(t *testing.T) {
|
|
|
|
tests := []struct {
|
2014-03-19 02:18:44 +01:00
|
|
|
name string
|
|
|
|
addr string
|
|
|
|
encoded string
|
|
|
|
valid bool
|
2021-09-10 22:30:39 +02:00
|
|
|
result lbcutil.Address
|
|
|
|
f func() (lbcutil.Address, error)
|
2015-02-06 05:04:58 +01:00
|
|
|
net *chaincfg.Params
|
2014-01-03 17:10:25 +01:00
|
|
|
}{
|
|
|
|
// Positive P2PKH tests.
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2pkh",
|
|
|
|
addr: "1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX",
|
|
|
|
encoded: "1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKeyHash(
|
2014-01-03 17:10:25 +01:00
|
|
|
[ripemd160.Size]byte{
|
|
|
|
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
|
|
|
|
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84},
|
2015-02-06 05:04:58 +01:00
|
|
|
chaincfg.MainNetParams.PubKeyHashAddrID),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-03 17:10:25 +01:00
|
|
|
pkHash := []byte{
|
|
|
|
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
|
|
|
|
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKeyHash(pkHash, &chaincfg.MainNetParams)
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2pkh 2",
|
|
|
|
addr: "12MzCDwodF9G1e7jfwLXfR164RNtx4BRVG",
|
|
|
|
encoded: "12MzCDwodF9G1e7jfwLXfR164RNtx4BRVG",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKeyHash(
|
2014-01-03 17:10:25 +01:00
|
|
|
[ripemd160.Size]byte{
|
|
|
|
0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b, 0xf4,
|
|
|
|
0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad, 0xaa},
|
2015-02-06 05:04:58 +01:00
|
|
|
chaincfg.MainNetParams.PubKeyHashAddrID),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-03 17:10:25 +01:00
|
|
|
pkHash := []byte{
|
|
|
|
0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b, 0xf4,
|
|
|
|
0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad, 0xaa}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKeyHash(pkHash, &chaincfg.MainNetParams)
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2019-01-17 01:07:58 +01:00
|
|
|
{
|
|
|
|
name: "litecoin mainnet p2pkh",
|
|
|
|
addr: "LM2WMpR1Rp6j3Sa59cMXMs1SPzj9eXpGc1",
|
|
|
|
encoded: "LM2WMpR1Rp6j3Sa59cMXMs1SPzj9eXpGc1",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKeyHash(
|
2019-01-17 01:07:58 +01:00
|
|
|
[ripemd160.Size]byte{
|
|
|
|
0x13, 0xc6, 0x0d, 0x8e, 0x68, 0xd7, 0x34, 0x9f, 0x5b, 0x4c,
|
|
|
|
0xa3, 0x62, 0xc3, 0x95, 0x4b, 0x15, 0x04, 0x50, 0x61, 0xb1},
|
|
|
|
CustomParams.PubKeyHashAddrID),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2019-01-17 01:07:58 +01:00
|
|
|
pkHash := []byte{
|
|
|
|
0x13, 0xc6, 0x0d, 0x8e, 0x68, 0xd7, 0x34, 0x9f, 0x5b, 0x4c,
|
|
|
|
0xa3, 0x62, 0xc3, 0x95, 0x4b, 0x15, 0x04, 0x50, 0x61, 0xb1}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKeyHash(pkHash, &customParams)
|
2019-01-17 01:07:58 +01:00
|
|
|
},
|
|
|
|
net: &customParams,
|
|
|
|
},
|
2014-01-03 17:10:25 +01:00
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "testnet p2pkh",
|
|
|
|
addr: "mrX9vMRYLfVy1BnZbc5gZjuyaqH3ZW2ZHz",
|
|
|
|
encoded: "mrX9vMRYLfVy1BnZbc5gZjuyaqH3ZW2ZHz",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKeyHash(
|
2014-01-03 17:10:25 +01:00
|
|
|
[ripemd160.Size]byte{
|
|
|
|
0x78, 0xb3, 0x16, 0xa0, 0x86, 0x47, 0xd5, 0xb7, 0x72, 0x83,
|
|
|
|
0xe5, 0x12, 0xd3, 0x60, 0x3f, 0x1f, 0x1c, 0x8d, 0xe6, 0x8f},
|
2015-02-06 05:04:58 +01:00
|
|
|
chaincfg.TestNet3Params.PubKeyHashAddrID),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-03 17:10:25 +01:00
|
|
|
pkHash := []byte{
|
|
|
|
0x78, 0xb3, 0x16, 0xa0, 0x86, 0x47, 0xd5, 0xb7, 0x72, 0x83,
|
|
|
|
0xe5, 0x12, 0xd3, 0x60, 0x3f, 0x1f, 0x1c, 0x8d, 0xe6, 0x8f}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKeyHash(pkHash, &chaincfg.TestNet3Params)
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.TestNet3Params,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Negative P2PKH tests.
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "p2pkh wrong hash length",
|
|
|
|
addr: "",
|
|
|
|
valid: false,
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-03 17:10:25 +01:00
|
|
|
pkHash := []byte{
|
|
|
|
0x00, 0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b,
|
|
|
|
0xf4, 0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad,
|
|
|
|
0xaa}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKeyHash(pkHash, &chaincfg.MainNetParams)
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2017-07-25 07:47:41 +02:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "p2pkh bad checksum",
|
|
|
|
addr: "1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gY",
|
|
|
|
valid: false,
|
2017-07-25 07:47:41 +02:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Positive P2SH tests.
|
|
|
|
{
|
|
|
|
// Taken from transactions:
|
|
|
|
// output: 3c9018e8d5615c306d72397f8f5eef44308c98fb576a88e030c25456b4f3a7ac
|
|
|
|
// input: 837dea37ddc8b1e3ce646f1a656e79bbd8cc7f558ac56a169626d649ebe2a3ba.
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2sh",
|
|
|
|
addr: "3QJmV3qfvL9SuYo34YihAf3sRCW3qSinyC",
|
|
|
|
encoded: "3QJmV3qfvL9SuYo34YihAf3sRCW3qSinyC",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressScriptHash(
|
2014-01-03 17:10:25 +01:00
|
|
|
[ripemd160.Size]byte{
|
|
|
|
0xf8, 0x15, 0xb0, 0x36, 0xd9, 0xbb, 0xbc, 0xe5, 0xe9, 0xf2,
|
|
|
|
0xa0, 0x0a, 0xbd, 0x1b, 0xf3, 0xdc, 0x91, 0xe9, 0x55, 0x10},
|
2015-02-06 05:04:58 +01:00
|
|
|
chaincfg.MainNetParams.ScriptHashAddrID),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-03 17:10:25 +01:00
|
|
|
script := []byte{
|
|
|
|
0x52, 0x41, 0x04, 0x91, 0xbb, 0xa2, 0x51, 0x09, 0x12, 0xa5,
|
|
|
|
0xbd, 0x37, 0xda, 0x1f, 0xb5, 0xb1, 0x67, 0x30, 0x10, 0xe4,
|
|
|
|
0x3d, 0x2c, 0x6d, 0x81, 0x2c, 0x51, 0x4e, 0x91, 0xbf, 0xa9,
|
|
|
|
0xf2, 0xeb, 0x12, 0x9e, 0x1c, 0x18, 0x33, 0x29, 0xdb, 0x55,
|
|
|
|
0xbd, 0x86, 0x8e, 0x20, 0x9a, 0xac, 0x2f, 0xbc, 0x02, 0xcb,
|
|
|
|
0x33, 0xd9, 0x8f, 0xe7, 0x4b, 0xf2, 0x3f, 0x0c, 0x23, 0x5d,
|
|
|
|
0x61, 0x26, 0xb1, 0xd8, 0x33, 0x4f, 0x86, 0x41, 0x04, 0x86,
|
|
|
|
0x5c, 0x40, 0x29, 0x3a, 0x68, 0x0c, 0xb9, 0xc0, 0x20, 0xe7,
|
|
|
|
0xb1, 0xe1, 0x06, 0xd8, 0xc1, 0x91, 0x6d, 0x3c, 0xef, 0x99,
|
|
|
|
0xaa, 0x43, 0x1a, 0x56, 0xd2, 0x53, 0xe6, 0x92, 0x56, 0xda,
|
|
|
|
0xc0, 0x9e, 0xf1, 0x22, 0xb1, 0xa9, 0x86, 0x81, 0x8a, 0x7c,
|
|
|
|
0xb6, 0x24, 0x53, 0x2f, 0x06, 0x2c, 0x1d, 0x1f, 0x87, 0x22,
|
|
|
|
0x08, 0x48, 0x61, 0xc5, 0xc3, 0x29, 0x1c, 0xcf, 0xfe, 0xf4,
|
|
|
|
0xec, 0x68, 0x74, 0x41, 0x04, 0x8d, 0x24, 0x55, 0xd2, 0x40,
|
|
|
|
0x3e, 0x08, 0x70, 0x8f, 0xc1, 0xf5, 0x56, 0x00, 0x2f, 0x1b,
|
|
|
|
0x6c, 0xd8, 0x3f, 0x99, 0x2d, 0x08, 0x50, 0x97, 0xf9, 0x97,
|
|
|
|
0x4a, 0xb0, 0x8a, 0x28, 0x83, 0x8f, 0x07, 0x89, 0x6f, 0xba,
|
|
|
|
0xb0, 0x8f, 0x39, 0x49, 0x5e, 0x15, 0xfa, 0x6f, 0xad, 0x6e,
|
|
|
|
0xdb, 0xfb, 0x1e, 0x75, 0x4e, 0x35, 0xfa, 0x1c, 0x78, 0x44,
|
|
|
|
0xc4, 0x1f, 0x32, 0x2a, 0x18, 0x63, 0xd4, 0x62, 0x13, 0x53,
|
|
|
|
0xae}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressScriptHash(script, &chaincfg.MainNetParams)
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2019-01-17 01:07:58 +01:00
|
|
|
{
|
|
|
|
name: "litecoin mainnet P2SH ",
|
|
|
|
addr: "MVcg9uEvtWuP5N6V48EHfEtbz48qR8TKZ9",
|
|
|
|
encoded: "MVcg9uEvtWuP5N6V48EHfEtbz48qR8TKZ9",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressScriptHash(
|
2019-01-17 01:07:58 +01:00
|
|
|
[ripemd160.Size]byte{
|
|
|
|
0xee, 0x34, 0xac, 0x67, 0x6b, 0xda, 0xf6, 0xe3, 0x70, 0xc8,
|
|
|
|
0xc8, 0x20, 0xb9, 0x48, 0xed, 0xfa, 0xd3, 0xa8, 0x73, 0xd8},
|
|
|
|
CustomParams.ScriptHashAddrID),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2019-01-17 01:07:58 +01:00
|
|
|
pkHash := []byte{
|
|
|
|
0xEE, 0x34, 0xAC, 0x67, 0x6B, 0xDA, 0xF6, 0xE3, 0x70, 0xC8,
|
|
|
|
0xC8, 0x20, 0xB9, 0x48, 0xED, 0xFA, 0xD3, 0xA8, 0x73, 0xD8}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressScriptHashFromHash(pkHash, &customParams)
|
2019-01-17 01:07:58 +01:00
|
|
|
},
|
|
|
|
net: &customParams,
|
|
|
|
},
|
2014-01-03 17:10:25 +01:00
|
|
|
{
|
|
|
|
// Taken from transactions:
|
|
|
|
// output: b0539a45de13b3e0403909b8bd1a555b8cbe45fd4e3f3fda76f3a5f52835c29d
|
|
|
|
// input: (not yet redeemed at time test was written)
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2sh 2",
|
|
|
|
addr: "3NukJ6fYZJ5Kk8bPjycAnruZkE5Q7UW7i8",
|
|
|
|
encoded: "3NukJ6fYZJ5Kk8bPjycAnruZkE5Q7UW7i8",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressScriptHash(
|
2014-01-03 17:10:25 +01:00
|
|
|
[ripemd160.Size]byte{
|
|
|
|
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
|
|
|
|
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4},
|
2015-02-06 05:04:58 +01:00
|
|
|
chaincfg.MainNetParams.ScriptHashAddrID),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-03 17:10:25 +01:00
|
|
|
hash := []byte{
|
|
|
|
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
|
|
|
|
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressScriptHashFromHash(hash, &chaincfg.MainNetParams)
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// Taken from bitcoind base58_keys_valid.
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "testnet p2sh",
|
|
|
|
addr: "2NBFNJTktNa7GZusGbDbGKRZTxdK9VVez3n",
|
|
|
|
encoded: "2NBFNJTktNa7GZusGbDbGKRZTxdK9VVez3n",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressScriptHash(
|
2014-01-03 17:10:25 +01:00
|
|
|
[ripemd160.Size]byte{
|
|
|
|
0xc5, 0x79, 0x34, 0x2c, 0x2c, 0x4c, 0x92, 0x20, 0x20, 0x5e,
|
|
|
|
0x2c, 0xdc, 0x28, 0x56, 0x17, 0x04, 0x0c, 0x92, 0x4a, 0x0a},
|
2015-02-06 05:04:58 +01:00
|
|
|
chaincfg.TestNet3Params.ScriptHashAddrID),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-03 17:10:25 +01:00
|
|
|
hash := []byte{
|
|
|
|
0xc5, 0x79, 0x34, 0x2c, 0x2c, 0x4c, 0x92, 0x20, 0x20, 0x5e,
|
|
|
|
0x2c, 0xdc, 0x28, 0x56, 0x17, 0x04, 0x0c, 0x92, 0x4a, 0x0a}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressScriptHashFromHash(hash, &chaincfg.TestNet3Params)
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.TestNet3Params,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Negative P2SH tests.
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "p2sh wrong hash length",
|
|
|
|
addr: "",
|
|
|
|
valid: false,
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-03 17:10:25 +01:00
|
|
|
hash := []byte{
|
|
|
|
0x00, 0xf8, 0x15, 0xb0, 0x36, 0xd9, 0xbb, 0xbc, 0xe5, 0xe9,
|
|
|
|
0xf2, 0xa0, 0x0a, 0xbd, 0x1b, 0xf3, 0xdc, 0x91, 0xe9, 0x55,
|
|
|
|
0x10}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressScriptHashFromHash(hash, &chaincfg.MainNetParams)
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2017-07-25 07:47:41 +02:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-03 17:10:25 +01:00
|
|
|
},
|
2014-01-08 06:05:07 +01:00
|
|
|
|
|
|
|
// Positive P2PK tests.
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2pk compressed (0x02)",
|
|
|
|
addr: "02192d74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4",
|
|
|
|
encoded: "13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
|
|
|
0x52, 0xc6, 0xb4},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFCompressed, chaincfg.MainNetParams.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
|
|
|
0x52, 0xc6, 0xb4}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2pk compressed (0x03)",
|
|
|
|
addr: "03b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65",
|
|
|
|
encoded: "15sHANNUBSh6nDp8XkDPmQcW6n3EFwmvE6",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
|
|
|
0xb1, 0x6e, 0x65},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFCompressed, chaincfg.MainNetParams.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
|
|
|
0xb1, 0x6e, 0x65}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2pk uncompressed (0x04)",
|
|
|
|
addr: "0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2" +
|
|
|
|
"e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3",
|
|
|
|
encoded: "12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFUncompressed, chaincfg.MainNetParams.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2pk hybrid (0x06)",
|
|
|
|
addr: "06192d74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4" +
|
|
|
|
"0d45264838c0bd96852662ce6a847b197376830160c6d2eb5e6a4c44d33f453e",
|
|
|
|
encoded: "1Ja5rs7XBZnK88EuLVcFqYGMEbBitzchmX",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x06, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
|
|
|
0x52, 0xc6, 0xb4, 0x0d, 0x45, 0x26, 0x48, 0x38, 0xc0, 0xbd,
|
|
|
|
0x96, 0x85, 0x26, 0x62, 0xce, 0x6a, 0x84, 0x7b, 0x19, 0x73,
|
|
|
|
0x76, 0x83, 0x01, 0x60, 0xc6, 0xd2, 0xeb, 0x5e, 0x6a, 0x4c,
|
|
|
|
0x44, 0xd3, 0x3f, 0x45, 0x3e},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFHybrid, chaincfg.MainNetParams.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x06, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
|
|
|
0x52, 0xc6, 0xb4, 0x0d, 0x45, 0x26, 0x48, 0x38, 0xc0, 0xbd,
|
|
|
|
0x96, 0x85, 0x26, 0x62, 0xce, 0x6a, 0x84, 0x7b, 0x19, 0x73,
|
|
|
|
0x76, 0x83, 0x01, 0x60, 0xc6, 0xd2, 0xeb, 0x5e, 0x6a, 0x4c,
|
|
|
|
0x44, 0xd3, 0x3f, 0x45, 0x3e}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "mainnet p2pk hybrid (0x07)",
|
|
|
|
addr: "07b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65" +
|
|
|
|
"37a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b",
|
|
|
|
encoded: "1ExqMmf6yMxcBMzHjbj41wbqYuqoX6uBLG",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x07, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
|
|
|
0xb1, 0x6e, 0x65, 0x37, 0xa5, 0x76, 0x78, 0x2e, 0xba, 0x66,
|
|
|
|
0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
|
|
|
|
0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
|
|
|
|
0x1e, 0x09, 0x08, 0xef, 0x7b},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFHybrid, chaincfg.MainNetParams.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x07, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
|
|
|
0xb1, 0x6e, 0x65, 0x37, 0xa5, 0x76, 0x78, 0x2e, 0xba, 0x66,
|
|
|
|
0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
|
|
|
|
0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
|
|
|
|
0x1e, 0x09, 0x08, 0xef, 0x7b}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.MainNetParams)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.MainNetParams,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "testnet p2pk compressed (0x02)",
|
|
|
|
addr: "02192d74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4",
|
|
|
|
encoded: "mhiDPVP2nJunaAgTjzWSHCYfAqxxrxzjmo",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
|
|
|
0x52, 0xc6, 0xb4},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFCompressed, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x02, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
|
|
|
0x52, 0xc6, 0xb4}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.TestNet3Params,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "testnet p2pk compressed (0x03)",
|
|
|
|
addr: "03b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65",
|
|
|
|
encoded: "mkPETRTSzU8MZLHkFKBmbKppxmdw9qT42t",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
|
|
|
0xb1, 0x6e, 0x65},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFCompressed, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x03, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
|
|
|
0xb1, 0x6e, 0x65}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.TestNet3Params,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "testnet p2pk uncompressed (0x04)",
|
|
|
|
addr: "0411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5" +
|
|
|
|
"cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3",
|
|
|
|
encoded: "mh8YhPYEAYs3E7EVyKtB5xrcfMExkkdEMF",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFUncompressed, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, 0x6b,
|
|
|
|
0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, 0x8a, 0x38,
|
|
|
|
0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, 0xb1, 0x48, 0xa6,
|
|
|
|
0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, 0xdd, 0xfb, 0x84, 0xcc,
|
|
|
|
0xf9, 0x74, 0x44, 0x64, 0xf8, 0x2e, 0x16, 0x0b, 0xfa, 0x9b,
|
|
|
|
0x8b, 0x64, 0xf9, 0xd4, 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43,
|
|
|
|
0xf6, 0x56, 0xb4, 0x12, 0xa3}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.TestNet3Params,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "testnet p2pk hybrid (0x06)",
|
|
|
|
addr: "06192d74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b" +
|
|
|
|
"40d45264838c0bd96852662ce6a847b197376830160c6d2eb5e6a4c44d33f453e",
|
|
|
|
encoded: "my639vCVzbDZuEiX44adfTUg6anRomZLEP",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x06, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
|
|
|
0x52, 0xc6, 0xb4, 0x0d, 0x45, 0x26, 0x48, 0x38, 0xc0, 0xbd,
|
|
|
|
0x96, 0x85, 0x26, 0x62, 0xce, 0x6a, 0x84, 0x7b, 0x19, 0x73,
|
|
|
|
0x76, 0x83, 0x01, 0x60, 0xc6, 0xd2, 0xeb, 0x5e, 0x6a, 0x4c,
|
|
|
|
0x44, 0xd3, 0x3f, 0x45, 0x3e},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFHybrid, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x06, 0x19, 0x2d, 0x74, 0xd0, 0xcb, 0x94, 0x34, 0x4c, 0x95,
|
|
|
|
0x69, 0xc2, 0xe7, 0x79, 0x01, 0x57, 0x3d, 0x8d, 0x79, 0x03,
|
|
|
|
0xc3, 0xeb, 0xec, 0x3a, 0x95, 0x77, 0x24, 0x89, 0x5d, 0xca,
|
|
|
|
0x52, 0xc6, 0xb4, 0x0d, 0x45, 0x26, 0x48, 0x38, 0xc0, 0xbd,
|
|
|
|
0x96, 0x85, 0x26, 0x62, 0xce, 0x6a, 0x84, 0x7b, 0x19, 0x73,
|
|
|
|
0x76, 0x83, 0x01, 0x60, 0xc6, 0xd2, 0xeb, 0x5e, 0x6a, 0x4c,
|
|
|
|
0x44, 0xd3, 0x3f, 0x45, 0x3e}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.TestNet3Params,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
|
|
|
{
|
2014-03-19 02:18:44 +01:00
|
|
|
name: "testnet p2pk hybrid (0x07)",
|
|
|
|
addr: "07b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6" +
|
|
|
|
"537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b",
|
|
|
|
encoded: "muUnepk5nPPrxUTuTAhRqrpAQuSWS5fVii",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressPubKey(
|
2014-01-08 06:05:07 +01:00
|
|
|
[]byte{
|
|
|
|
0x07, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
|
|
|
0xb1, 0x6e, 0x65, 0x37, 0xa5, 0x76, 0x78, 0x2e, 0xba, 0x66,
|
|
|
|
0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
|
|
|
|
0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
|
|
|
|
0x1e, 0x09, 0x08, 0xef, 0x7b},
|
2021-09-10 22:30:39 +02:00
|
|
|
lbcutil.PKFHybrid, chaincfg.TestNet3Params.PubKeyHashAddrID),
|
|
|
|
f: func() (lbcutil.Address, error) {
|
2014-01-08 06:05:07 +01:00
|
|
|
serializedPubKey := []byte{
|
|
|
|
0x07, 0xb0, 0xbd, 0x63, 0x42, 0x34, 0xab, 0xbb, 0x1b, 0xa1,
|
|
|
|
0xe9, 0x86, 0xe8, 0x84, 0x18, 0x5c, 0x61, 0xcf, 0x43, 0xe0,
|
|
|
|
0x01, 0xf9, 0x13, 0x7f, 0x23, 0xc2, 0xc4, 0x09, 0x27, 0x3e,
|
|
|
|
0xb1, 0x6e, 0x65, 0x37, 0xa5, 0x76, 0x78, 0x2e, 0xba, 0x66,
|
|
|
|
0x8a, 0x7e, 0xf8, 0xbd, 0x3b, 0x3c, 0xfb, 0x1e, 0xdb, 0x71,
|
|
|
|
0x17, 0xab, 0x65, 0x12, 0x9b, 0x8a, 0x2e, 0x68, 0x1f, 0x3c,
|
|
|
|
0x1e, 0x09, 0x08, 0xef, 0x7b}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressPubKey(serializedPubKey, &chaincfg.TestNet3Params)
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2015-02-06 05:04:58 +01:00
|
|
|
net: &chaincfg.TestNet3Params,
|
2014-01-08 06:05:07 +01:00
|
|
|
},
|
2017-07-25 07:47:41 +02:00
|
|
|
// Segwit address tests.
|
|
|
|
{
|
|
|
|
name: "segwit mainnet p2wpkh v0",
|
|
|
|
addr: "BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4",
|
|
|
|
encoded: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressWitnessPubKeyHash(
|
2017-07-25 07:47:41 +02:00
|
|
|
0,
|
|
|
|
[20]byte{
|
|
|
|
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94,
|
|
|
|
0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6},
|
|
|
|
chaincfg.MainNetParams.Bech32HRPSegwit),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2017-07-25 07:47:41 +02:00
|
|
|
pkHash := []byte{
|
|
|
|
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94,
|
|
|
|
0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressWitnessPubKeyHash(pkHash, &chaincfg.MainNetParams)
|
2017-07-25 07:47:41 +02:00
|
|
|
},
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit mainnet p2wsh v0",
|
|
|
|
addr: "bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3",
|
|
|
|
encoded: "bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressWitnessScriptHash(
|
2017-07-25 07:47:41 +02:00
|
|
|
0,
|
|
|
|
[32]byte{
|
|
|
|
0x18, 0x63, 0x14, 0x3c, 0x14, 0xc5, 0x16, 0x68,
|
|
|
|
0x04, 0xbd, 0x19, 0x20, 0x33, 0x56, 0xda, 0x13,
|
|
|
|
0x6c, 0x98, 0x56, 0x78, 0xcd, 0x4d, 0x27, 0xa1,
|
|
|
|
0xb8, 0xc6, 0x32, 0x96, 0x04, 0x90, 0x32, 0x62},
|
|
|
|
chaincfg.MainNetParams.Bech32HRPSegwit),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2017-07-25 07:47:41 +02:00
|
|
|
scriptHash := []byte{
|
|
|
|
0x18, 0x63, 0x14, 0x3c, 0x14, 0xc5, 0x16, 0x68,
|
|
|
|
0x04, 0xbd, 0x19, 0x20, 0x33, 0x56, 0xda, 0x13,
|
|
|
|
0x6c, 0x98, 0x56, 0x78, 0xcd, 0x4d, 0x27, 0xa1,
|
|
|
|
0xb8, 0xc6, 0x32, 0x96, 0x04, 0x90, 0x32, 0x62}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressWitnessScriptHash(scriptHash, &chaincfg.MainNetParams)
|
2017-07-25 07:47:41 +02:00
|
|
|
},
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit testnet p2wpkh v0",
|
|
|
|
addr: "tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx",
|
|
|
|
encoded: "tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressWitnessPubKeyHash(
|
2017-07-25 07:47:41 +02:00
|
|
|
0,
|
|
|
|
[20]byte{
|
|
|
|
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94,
|
|
|
|
0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6},
|
|
|
|
chaincfg.TestNet3Params.Bech32HRPSegwit),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2017-07-25 07:47:41 +02:00
|
|
|
pkHash := []byte{
|
|
|
|
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94,
|
|
|
|
0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressWitnessPubKeyHash(pkHash, &chaincfg.TestNet3Params)
|
2017-07-25 07:47:41 +02:00
|
|
|
},
|
|
|
|
net: &chaincfg.TestNet3Params,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit testnet p2wsh v0",
|
|
|
|
addr: "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7",
|
|
|
|
encoded: "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressWitnessScriptHash(
|
2017-07-25 07:47:41 +02:00
|
|
|
0,
|
|
|
|
[32]byte{
|
|
|
|
0x18, 0x63, 0x14, 0x3c, 0x14, 0xc5, 0x16, 0x68,
|
|
|
|
0x04, 0xbd, 0x19, 0x20, 0x33, 0x56, 0xda, 0x13,
|
|
|
|
0x6c, 0x98, 0x56, 0x78, 0xcd, 0x4d, 0x27, 0xa1,
|
|
|
|
0xb8, 0xc6, 0x32, 0x96, 0x04, 0x90, 0x32, 0x62},
|
|
|
|
chaincfg.TestNet3Params.Bech32HRPSegwit),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2017-07-25 07:47:41 +02:00
|
|
|
scriptHash := []byte{
|
|
|
|
0x18, 0x63, 0x14, 0x3c, 0x14, 0xc5, 0x16, 0x68,
|
|
|
|
0x04, 0xbd, 0x19, 0x20, 0x33, 0x56, 0xda, 0x13,
|
|
|
|
0x6c, 0x98, 0x56, 0x78, 0xcd, 0x4d, 0x27, 0xa1,
|
|
|
|
0xb8, 0xc6, 0x32, 0x96, 0x04, 0x90, 0x32, 0x62}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressWitnessScriptHash(scriptHash, &chaincfg.TestNet3Params)
|
2017-07-25 07:47:41 +02:00
|
|
|
},
|
|
|
|
net: &chaincfg.TestNet3Params,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit testnet p2wsh witness v0",
|
|
|
|
addr: "tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy",
|
|
|
|
encoded: "tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressWitnessScriptHash(
|
2017-07-25 07:47:41 +02:00
|
|
|
0,
|
|
|
|
[32]byte{
|
|
|
|
0x00, 0x00, 0x00, 0xc4, 0xa5, 0xca, 0xd4, 0x62,
|
|
|
|
0x21, 0xb2, 0xa1, 0x87, 0x90, 0x5e, 0x52, 0x66,
|
|
|
|
0x36, 0x2b, 0x99, 0xd5, 0xe9, 0x1c, 0x6c, 0xe2,
|
|
|
|
0x4d, 0x16, 0x5d, 0xab, 0x93, 0xe8, 0x64, 0x33},
|
|
|
|
chaincfg.TestNet3Params.Bech32HRPSegwit),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2017-07-25 07:47:41 +02:00
|
|
|
scriptHash := []byte{
|
|
|
|
0x00, 0x00, 0x00, 0xc4, 0xa5, 0xca, 0xd4, 0x62,
|
|
|
|
0x21, 0xb2, 0xa1, 0x87, 0x90, 0x5e, 0x52, 0x66,
|
|
|
|
0x36, 0x2b, 0x99, 0xd5, 0xe9, 0x1c, 0x6c, 0xe2,
|
|
|
|
0x4d, 0x16, 0x5d, 0xab, 0x93, 0xe8, 0x64, 0x33}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressWitnessScriptHash(scriptHash, &chaincfg.TestNet3Params)
|
2017-07-25 07:47:41 +02:00
|
|
|
},
|
|
|
|
net: &chaincfg.TestNet3Params,
|
|
|
|
},
|
2020-07-08 11:22:13 +02:00
|
|
|
{
|
|
|
|
name: "segwit litecoin mainnet p2wpkh v0",
|
|
|
|
addr: "LTC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KGMN4N9",
|
|
|
|
encoded: "ltc1qw508d6qejxtdg4y5r3zarvary0c5xw7kgmn4n9",
|
|
|
|
valid: true,
|
2021-09-10 22:30:39 +02:00
|
|
|
result: lbcutil.TstAddressWitnessPubKeyHash(
|
2020-07-08 11:22:13 +02:00
|
|
|
0,
|
|
|
|
[20]byte{
|
|
|
|
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94,
|
|
|
|
0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6},
|
|
|
|
CustomParams.Bech32HRPSegwit,
|
|
|
|
),
|
2021-09-10 22:30:39 +02:00
|
|
|
f: func() (lbcutil.Address, error) {
|
2020-07-08 11:22:13 +02:00
|
|
|
pkHash := []byte{
|
|
|
|
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94,
|
|
|
|
0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6}
|
2021-09-10 22:30:39 +02:00
|
|
|
return lbcutil.NewAddressWitnessPubKeyHash(pkHash, &customParams)
|
2020-07-08 11:22:13 +02:00
|
|
|
},
|
|
|
|
net: &customParams,
|
|
|
|
},
|
2017-07-25 07:47:41 +02:00
|
|
|
// Unsupported witness versions (version 0 only supported at this point)
|
|
|
|
{
|
|
|
|
name: "segwit mainnet witness v1",
|
|
|
|
addr: "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit mainnet witness v16",
|
|
|
|
addr: "BC1SW50QA3JX3S",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit mainnet witness v2",
|
|
|
|
addr: "bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
// Invalid segwit addresses
|
|
|
|
{
|
|
|
|
name: "segwit invalid hrp",
|
|
|
|
addr: "tc1qw508d6qejxtdg4y5r3zarvary0c5xw7kg3g4ty",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.TestNet3Params,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit invalid checksum",
|
|
|
|
addr: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit invalid witness version",
|
|
|
|
addr: "BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit invalid program length",
|
|
|
|
addr: "bc1rw5uspcuh",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit invalid program length",
|
|
|
|
addr: "bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kw5rljs90",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit invalid program length for witness version 0 (per BIP141)",
|
|
|
|
addr: "BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.MainNetParams,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit mixed case",
|
|
|
|
addr: "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.TestNet3Params,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit zero padding of more than 4 bits",
|
|
|
|
addr: "tb1pw508d6qejxtdg4y5r3zarqfsj6c3",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.TestNet3Params,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "segwit non-zero padding in 8-to-5 conversion",
|
|
|
|
addr: "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv",
|
|
|
|
valid: false,
|
|
|
|
net: &chaincfg.TestNet3Params,
|
|
|
|
},
|
2014-01-03 17:10:25 +01:00
|
|
|
}
|
|
|
|
|
2020-07-08 11:22:13 +02:00
|
|
|
if err := chaincfg.Register(&customParams); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2014-01-03 17:10:25 +01:00
|
|
|
for _, test := range tests {
|
2014-03-19 02:18:44 +01:00
|
|
|
// Decode addr and compare error against valid.
|
2021-09-10 22:30:39 +02:00
|
|
|
decoded, err := lbcutil.DecodeAddress(test.addr, test.net)
|
2014-03-19 02:18:44 +01:00
|
|
|
if (err == nil) != test.valid {
|
|
|
|
t.Errorf("%v: decoding test failed: %v", test.name, err)
|
|
|
|
return
|
2014-01-08 06:05:07 +01:00
|
|
|
}
|
2014-01-03 17:10:25 +01:00
|
|
|
|
2014-01-08 06:05:07 +01:00
|
|
|
if err == nil {
|
2014-03-19 02:18:44 +01:00
|
|
|
// Ensure the stringer returns the same address as the
|
|
|
|
// original.
|
|
|
|
if decodedStringer, ok := decoded.(fmt.Stringer); ok {
|
2017-07-25 07:47:41 +02:00
|
|
|
addr := test.addr
|
|
|
|
|
|
|
|
// For Segwit addresses the string representation
|
|
|
|
// will always be lower case, so in that case we
|
|
|
|
// convert the original to lower case first.
|
|
|
|
if strings.Contains(test.name, "segwit") {
|
|
|
|
addr = strings.ToLower(addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if addr != decodedStringer.String() {
|
2014-03-19 02:18:44 +01:00
|
|
|
t.Errorf("%v: String on decoded value does not match expected value: %v != %v",
|
|
|
|
test.name, test.addr, decodedStringer.String())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2014-01-03 17:10:25 +01:00
|
|
|
|
2014-03-19 02:18:44 +01:00
|
|
|
// Encode again and compare against the original.
|
|
|
|
encoded := decoded.EncodeAddress()
|
|
|
|
if test.encoded != encoded {
|
2014-01-08 06:05:07 +01:00
|
|
|
t.Errorf("%v: decoding and encoding produced different addressess: %v != %v",
|
2014-03-19 02:18:44 +01:00
|
|
|
test.name, test.encoded, encoded)
|
2014-01-08 06:05:07 +01:00
|
|
|
return
|
|
|
|
}
|
2014-01-03 17:10:25 +01:00
|
|
|
|
2014-01-08 06:05:07 +01:00
|
|
|
// Perform type-specific calculations.
|
|
|
|
var saddr []byte
|
|
|
|
switch d := decoded.(type) {
|
2021-09-10 22:30:39 +02:00
|
|
|
case *lbcutil.AddressPubKeyHash:
|
|
|
|
saddr = lbcutil.TstAddressSAddr(encoded)
|
2014-01-03 17:10:25 +01:00
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
case *lbcutil.AddressScriptHash:
|
|
|
|
saddr = lbcutil.TstAddressSAddr(encoded)
|
2014-01-03 17:10:25 +01:00
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
case *lbcutil.AddressPubKey:
|
2014-01-08 06:05:07 +01:00
|
|
|
// Ignore the error here since the script
|
|
|
|
// address is checked below.
|
|
|
|
saddr, _ = hex.DecodeString(d.String())
|
2021-09-10 22:30:39 +02:00
|
|
|
case *lbcutil.AddressWitnessPubKeyHash:
|
|
|
|
saddr = lbcutil.TstAddressSegwitSAddr(encoded)
|
|
|
|
case *lbcutil.AddressWitnessScriptHash:
|
|
|
|
saddr = lbcutil.TstAddressSegwitSAddr(encoded)
|
2014-01-08 06:05:07 +01:00
|
|
|
}
|
|
|
|
|
2014-04-20 22:01:48 +02:00
|
|
|
// Check script address, as well as the Hash160 method for P2PKH and
|
|
|
|
// P2SH addresses.
|
2014-01-08 06:05:07 +01:00
|
|
|
if !bytes.Equal(saddr, decoded.ScriptAddress()) {
|
|
|
|
t.Errorf("%v: script addresses do not match:\n%x != \n%x",
|
|
|
|
test.name, saddr, decoded.ScriptAddress())
|
|
|
|
return
|
|
|
|
}
|
2014-04-20 22:01:48 +02:00
|
|
|
switch a := decoded.(type) {
|
2021-09-10 22:30:39 +02:00
|
|
|
case *lbcutil.AddressPubKeyHash:
|
2014-04-20 22:01:48 +02:00
|
|
|
if h := a.Hash160()[:]; !bytes.Equal(saddr, h) {
|
|
|
|
t.Errorf("%v: hashes do not match:\n%x != \n%x",
|
|
|
|
test.name, saddr, h)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
case *lbcutil.AddressScriptHash:
|
2014-04-20 22:01:48 +02:00
|
|
|
if h := a.Hash160()[:]; !bytes.Equal(saddr, h) {
|
|
|
|
t.Errorf("%v: hashes do not match:\n%x != \n%x",
|
|
|
|
test.name, saddr, h)
|
|
|
|
return
|
|
|
|
}
|
2017-07-25 07:47:41 +02:00
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
case *lbcutil.AddressWitnessPubKeyHash:
|
2017-07-25 07:47:41 +02:00
|
|
|
if hrp := a.Hrp(); test.net.Bech32HRPSegwit != hrp {
|
|
|
|
t.Errorf("%v: hrps do not match:\n%x != \n%x",
|
|
|
|
test.name, test.net.Bech32HRPSegwit, hrp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
expVer := test.result.(*lbcutil.AddressWitnessPubKeyHash).WitnessVersion()
|
2017-07-25 07:47:41 +02:00
|
|
|
if v := a.WitnessVersion(); v != expVer {
|
|
|
|
t.Errorf("%v: witness versions do not match:\n%x != \n%x",
|
|
|
|
test.name, expVer, v)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if p := a.WitnessProgram(); !bytes.Equal(saddr, p) {
|
|
|
|
t.Errorf("%v: witness programs do not match:\n%x != \n%x",
|
|
|
|
test.name, saddr, p)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
case *lbcutil.AddressWitnessScriptHash:
|
2017-07-25 07:47:41 +02:00
|
|
|
if hrp := a.Hrp(); test.net.Bech32HRPSegwit != hrp {
|
|
|
|
t.Errorf("%v: hrps do not match:\n%x != \n%x",
|
|
|
|
test.name, test.net.Bech32HRPSegwit, hrp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
expVer := test.result.(*lbcutil.AddressWitnessScriptHash).WitnessVersion()
|
2017-07-25 07:47:41 +02:00
|
|
|
if v := a.WitnessVersion(); v != expVer {
|
|
|
|
t.Errorf("%v: witness versions do not match:\n%x != \n%x",
|
|
|
|
test.name, expVer, v)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if p := a.WitnessProgram(); !bytes.Equal(saddr, p) {
|
|
|
|
t.Errorf("%v: witness programs do not match:\n%x != \n%x",
|
|
|
|
test.name, saddr, p)
|
|
|
|
return
|
|
|
|
}
|
2014-04-20 22:01:48 +02:00
|
|
|
}
|
2014-01-08 06:05:07 +01:00
|
|
|
|
2014-03-19 02:18:44 +01:00
|
|
|
// Ensure the address is for the expected network.
|
2014-02-26 20:51:49 +01:00
|
|
|
if !decoded.IsForNet(test.net) {
|
2014-01-08 06:05:07 +01:00
|
|
|
t.Errorf("%v: calculated network does not match expected",
|
|
|
|
test.name)
|
|
|
|
return
|
2014-01-03 17:10:25 +01:00
|
|
|
}
|
2021-05-27 10:08:03 +02:00
|
|
|
} else {
|
|
|
|
// If there is an error, make sure we can print it
|
|
|
|
// correctly.
|
|
|
|
errStr := err.Error()
|
|
|
|
if errStr == "" {
|
|
|
|
t.Errorf("%v: error was non-nil but message is"+
|
|
|
|
"empty: %v", test.name, err)
|
|
|
|
}
|
2014-01-03 17:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if !test.valid {
|
|
|
|
// If address is invalid, but a creation function exists,
|
|
|
|
// verify that it returns a nil addr and non-nil error.
|
|
|
|
if test.f != nil {
|
|
|
|
_, err := test.f()
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("%v: address is invalid but creating new address succeeded",
|
|
|
|
test.name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valid test, compare address created with f against expected result.
|
|
|
|
addr, err := test.f()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%v: address is valid but creating new address failed with error %v",
|
|
|
|
test.name, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(addr, test.result) {
|
|
|
|
t.Errorf("%v: created address does not match expected result",
|
|
|
|
test.name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|