Skip to content

Commit

Permalink
Fix tests for non-v0 witnesses
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Aug 2, 2017
1 parent 20c2746 commit 0692344
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions ref/c/tests.c
Expand Up @@ -38,7 +38,7 @@ static struct valid_address_data valid_address[] = {
{
"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx",
42, {
0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x51, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6,
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c,
0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6
Expand All @@ -47,13 +47,13 @@ static struct valid_address_data valid_address[] = {
{
"BC1SW50QA3JX3S",
4, {
0x90, 0x02, 0x75, 0x1e
0x60, 0x02, 0x75, 0x1e
}
},
{
"bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj",
18, {
0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x52, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23
}
},
Expand Down Expand Up @@ -81,7 +81,7 @@ static const char* invalid_address[] = {
};

static void segwit_scriptpubkey(uint8_t* scriptpubkey, size_t* scriptpubkeylen, int witver, const uint8_t* witprog, size_t witprog_len) {
scriptpubkey[0] = witver ? (0x80 | witver) : 0;
scriptpubkey[0] = witver ? (0x50 + witver) : 0;
scriptpubkey[1] = witprog_len;
memcpy(scriptpubkey + 2, witprog, witprog_len);
*scriptpubkeylen = witprog_len + 2;
Expand Down
8 changes: 4 additions & 4 deletions ref/go/src/bech32/bech32_test.go
Expand Up @@ -28,7 +28,7 @@ import (

func segwitScriptpubkey(version int, program []int) []int {
if version != 0 {
version += 0x80
version += 0x50
}
return append(append([]int{version}, len(program)), program...)
}
Expand Down Expand Up @@ -63,20 +63,20 @@ var validAddress = []item{
},
item{"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx",
[]int{
0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x51, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6,
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c,
0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6,
},
},
item{"BC1SW50QA3JX3S",
[]int{
0x90, 0x02, 0x75, 0x1e,
0x60, 0x02, 0x75, 0x1e,
},
},
item{"bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj",
[]int{
0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x52, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23,
},
},
Expand Down
8 changes: 4 additions & 4 deletions ref/haskell/test/Spec.hs
Expand Up @@ -28,9 +28,9 @@ validAddresses = map mapTuple
, ("tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7"
,"00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262")
, ("bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx"
,"8128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6")
, ("BC1SW50QA3JX3S", "9002751e")
, ("bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "8210751e76e8199196d454941c45d1b3a323")
,"5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6")
, ("BC1SW50QA3JX3S", "6002751e")
, ("bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "5210751e76e8199196d454941c45d1b3a323")
, ("tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy"
,"0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433")
]
Expand All @@ -56,7 +56,7 @@ hexDecode s = let (ret, rest) = B16.decode s

segwitScriptPubkey :: Word8 -> [Word8] -> BS.ByteString
segwitScriptPubkey witver witprog = BS.pack $ witver' : (fromIntegral $ length witprog) : witprog
where witver' = if witver == 0 then 0 else witver + 0x80
where witver' = if witver == 0 then 0 else witver + 0x50

tests :: TestTree
tests = testGroup "Tests"
Expand Down
8 changes: 4 additions & 4 deletions ref/javascript/tests.js
Expand Up @@ -22,7 +22,7 @@ var segwit_addr = require('./segwit_addr.js');
var bech32 = require('./bech32');

function segwit_scriptpubkey(version, program) {
return [version ? version + 0x80 : 0, program.length].concat(program);
return [version ? version + 0x50 : 0, program.length].concat(program);
}

var VALID_CHECKSUM = [
Expand Down Expand Up @@ -53,7 +53,7 @@ var VALID_ADDRESS = [
[
"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx",
[
0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x51, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6,
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c,
0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6
Expand All @@ -62,13 +62,13 @@ var VALID_ADDRESS = [
[
"BC1SW50QA3JX3S",
[
0x90, 0x02, 0x75, 0x1e
0x60, 0x02, 0x75, 0x1e
]
],
[
"bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj",
[
0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x52, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23
]
],
Expand Down
8 changes: 4 additions & 4 deletions ref/python/tests.py
Expand Up @@ -29,7 +29,7 @@

def segwit_scriptpubkey(witver, witprog):
"""Construct a Segwit scriptPubKey for a given witness program."""
return bytes([witver + 0x80 if witver else 0, len(witprog)] + witprog)
return bytes([witver + 0x50 if witver else 0, len(witprog)] + witprog)

VALID_CHECKSUM = [
"A12UEL5L",
Expand All @@ -44,9 +44,9 @@ def segwit_scriptpubkey(witver, witprog):
["tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7",
"00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262"],
["bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx",
"8128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"],
["BC1SW50QA3JX3S", "9002751e"],
["bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "8210751e76e8199196d454941c45d1b3a323"],
"5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"],
["BC1SW50QA3JX3S", "6002751e"],
["bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "5210751e76e8199196d454941c45d1b3a323"],
["tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy",
"0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433"],
]
Expand Down
2 changes: 1 addition & 1 deletion ref/ruby/segwit_addr.rb
Expand Up @@ -31,7 +31,7 @@ def initialize(addr = nil)
end

def to_scriptpubkey
v = ver == 0 ? ver : ver + 0x80
v = ver == 0 ? ver : ver + 0x50
([v, prog.length].pack("CC") + prog.map{|p|[p].pack("C")}.join).unpack('H*').first
end

Expand Down
6 changes: 3 additions & 3 deletions ref/ruby/test_bech32.rb
Expand Up @@ -37,9 +37,9 @@ class TestBech32 < Test::Unit::TestCase
["tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7",
"00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262"],
["bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx",
"8128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"],
["BC1SW50QA3JX3S", "9002751e"],
["bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "8210751e76e8199196d454941c45d1b3a323"],
"5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"],
["BC1SW50QA3JX3S", "6002751e"],
["bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj", "5210751e76e8199196d454941c45d1b3a323"],
["tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy",
"0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433"],
]
Expand Down
6 changes: 3 additions & 3 deletions ref/rust/src/lib.rs
Expand Up @@ -170,7 +170,7 @@ mod tests {
(
"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx",
vec![
0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x51, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6,
0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c,
0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6
Expand All @@ -179,13 +179,13 @@ mod tests {
(
"BC1SW50QA3JX3S",
vec![
0x90, 0x02, 0x75, 0x1e
0x60, 0x02, 0x75, 0x1e
]
),
(
"bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj",
vec![
0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x52, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54,
0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23
]
),
Expand Down
6 changes: 3 additions & 3 deletions ref/rust/src/wit_prog.rs
Expand Up @@ -130,7 +130,7 @@ impl WitnessProgram {
let mut pubkey: Vec<u8> = Vec::new();
let mut v = self.version;
if v > 0 {
v += 0x80;
v += 0x50;
}
pubkey.push(v);
pubkey.push(self.program.len() as u8);
Expand All @@ -152,8 +152,8 @@ impl WitnessProgram {
}
// Process script version
let mut v: u8 = pubkey[0];
if v > 0x80 {
v -= 0x80;
if v > 0x50 {
v -= 0x50;
}
let program = &pubkey[2..];
Ok(WitnessProgram {
Expand Down

0 comments on commit 0692344

Please sign in to comment.