add test case for litecoin bech32 addresses
This commit is contained in:
parent
f648594deb
commit
4649e4b73b
1 changed files with 33 additions and 2 deletions
|
@ -13,25 +13,32 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CustomParamStruct struct {
|
type CustomParamStruct struct {
|
||||||
|
Net wire.BitcoinNet
|
||||||
PubKeyHashAddrID byte
|
PubKeyHashAddrID byte
|
||||||
ScriptHashAddrID byte
|
ScriptHashAddrID byte
|
||||||
|
Bech32HRPSegwit string
|
||||||
}
|
}
|
||||||
|
|
||||||
var CustomParams = CustomParamStruct{
|
var CustomParams = CustomParamStruct{
|
||||||
PubKeyHashAddrID: 0x30, // starts with L
|
Net: 0xdbb6c0fb, // litecoin mainnet HD version bytes
|
||||||
ScriptHashAddrID: 0x32, // starts with M
|
PubKeyHashAddrID: 0x30, // starts with L
|
||||||
|
ScriptHashAddrID: 0x32, // starts with M
|
||||||
|
Bech32HRPSegwit: "ltc", // starts with ltc
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use this function to be able to test functionality in DecodeAddress for
|
// We use this function to be able to test functionality in DecodeAddress for
|
||||||
// defaultNet addresses
|
// defaultNet addresses
|
||||||
func applyCustomParams(params chaincfg.Params, customParams CustomParamStruct) chaincfg.Params {
|
func applyCustomParams(params chaincfg.Params, customParams CustomParamStruct) chaincfg.Params {
|
||||||
|
params.Net = customParams.Net
|
||||||
params.PubKeyHashAddrID = customParams.PubKeyHashAddrID
|
params.PubKeyHashAddrID = customParams.PubKeyHashAddrID
|
||||||
params.ScriptHashAddrID = customParams.ScriptHashAddrID
|
params.ScriptHashAddrID = customParams.ScriptHashAddrID
|
||||||
|
params.Bech32HRPSegwit = customParams.Bech32HRPSegwit
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,6 +635,26 @@ func TestAddresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
net: &chaincfg.TestNet3Params,
|
net: &chaincfg.TestNet3Params,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "segwit litecoin mainnet p2wpkh v0",
|
||||||
|
addr: "LTC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KGMN4N9",
|
||||||
|
encoded: "ltc1qw508d6qejxtdg4y5r3zarvary0c5xw7kgmn4n9",
|
||||||
|
valid: true,
|
||||||
|
result: btcutil.TstAddressWitnessPubKeyHash(
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
f: func() (btcutil.Address, error) {
|
||||||
|
pkHash := []byte{
|
||||||
|
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94,
|
||||||
|
0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6}
|
||||||
|
return btcutil.NewAddressWitnessPubKeyHash(pkHash, &customParams)
|
||||||
|
},
|
||||||
|
net: &customParams,
|
||||||
|
},
|
||||||
// Unsupported witness versions (version 0 only supported at this point)
|
// Unsupported witness versions (version 0 only supported at this point)
|
||||||
{
|
{
|
||||||
name: "segwit mainnet witness v1",
|
name: "segwit mainnet witness v1",
|
||||||
|
@ -704,6 +731,10 @@ func TestAddresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := chaincfg.Register(&customParams); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
// Decode addr and compare error against valid.
|
// Decode addr and compare error against valid.
|
||||||
decoded, err := btcutil.DecodeAddress(test.addr, test.net)
|
decoded, err := btcutil.DecodeAddress(test.addr, test.net)
|
||||||
|
|
Loading…
Reference in a new issue