Skip to content

Commit

Permalink
address: use correct hrp and update tests
Browse files Browse the repository at this point in the history
lcoin originally used the incorrect hrp, lc, instead
of ltc. changing the value in the networks constants
broke tests, so this commit also fixes those tests
that broke when the hrp was updated
  • Loading branch information
Mark Tyneway committed Feb 24, 2019
1 parent 94aeac3 commit df5c412
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lib/protocol/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ main.addressPrefix = {
scripthash: 0x32,
witnesspubkeyhash: 0x06,
witnessscripthash: 0x0a,
bech32: 'lc'
bech32: 'ltc',
};

/**
Expand Down Expand Up @@ -593,7 +593,7 @@ testnet.addressPrefix = {
scripthash: 0xc4,
witnesspubkeyhash: 0x03,
witnessscripthash: 0x28,
bech32: 'tb'
bech32: 'tltc',
};

testnet.requireStandard = false;
Expand Down Expand Up @@ -750,7 +750,7 @@ regtest.addressPrefix = {
scripthash: 0x26,
witnesspubkeyhash: 0x7a,
witnessscripthash: 0x14,
bech32: 'rb'
bech32: 'rltc'
};

regtest.requireStandard = false;
Expand Down Expand Up @@ -920,7 +920,7 @@ simnet.addressPrefix = {
scripthash: 0x7b,
witnesspubkeyhash: 0x19,
witnessscripthash: 0x28,
bech32: 'sb'
bech32: 'sltc'
};

simnet.requireStandard = false;
Expand Down
26 changes: 18 additions & 8 deletions test/bech32-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ const Address = require('../lib/primitives/address');

const validAddresses = [
[
'BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4',
'LTC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KGMN4N9',
Buffer.from([
0x00, 0x14, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6
])
],
[
'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7',
'tltc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qsnr4fp',
Buffer.from([
0x00, 0x20, 0x18, 0x63, 0x14, 0x3c, 0x14, 0xc5, 0x16, 0x68, 0x04,
0xbd, 0x19, 0x20, 0x33, 0x56, 0xda, 0x13, 0x6c, 0x98, 0x56, 0x78,
Expand All @@ -47,8 +47,7 @@ const validAddresses = [
])
],
[
'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw50'
+ '8d6qejxtdg4y5r3zarvary0c5xw7k7grplx',
'ltc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k0tul4w',
Buffer.from([
0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6,
Expand All @@ -57,20 +56,20 @@ const validAddresses = [
])
],
[
'BC1SW50QA3JX3S',
'LTC1SW50QZGYDF5',
Buffer.from([
0x90, 0x02, 0x75, 0x1e
])
],
[
'bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj',
'ltc1zw508d6qejxtdg4y5r3zarvaryvdzur3w',
Buffer.from([
0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23
])
],
[
'tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy',
'tltc1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesu9tmgm',
Buffer.from([
0x00, 0x20, 0x00, 0x00, 0x00, 0xc4, 0xa5, 0xca, 0xd4, 0x62, 0x21,
0xb2, 0xa1, 0x87, 0x90, 0x5e, 0x52, 0x66, 0x36, 0x2b, 0x99, 0xd5,
Expand All @@ -81,16 +80,27 @@ const validAddresses = [
];

const invalidAddresses = [
// invalid hrp
'tc1qw508d6qejxtdg4y5r3zarvary0c5xw7kg3g4ty',
// invalid checksum
'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5',
// invalid witness version
'BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2',
// invalid program length
'bc1rw5uspcuh',
// invalid program length
'bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d'
+ '6qejxtdg4y5r3zarvary0c5xw7kw5rljs90',
// invalid program length for witness version 0
'BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P',
// mixed case
'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7',
// zero padding of more than 4 bits
'tb1pw508d6qejxtdg4y5r3zarqfsj6c3',
'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv'
// non zero padding in 8 to 5 conversion
'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv',
// empty data section
'bc1gmk9yu'
];

function createProgram(version, program) {
Expand Down

0 comments on commit df5c412

Please sign in to comment.