diff options
author | MarcoFalke <falke.marco@gmail.com> | 2019-05-13 15:38:10 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2019-05-20 12:25:27 -0400 |
commit | b6c1f9478f52b01f0858c402b3e73761f83e4fc6 (patch) | |
tree | 3c873282948414ee212ed084af56eb386ad03605 /test/functional | |
parent | 86031083c71e257778e95e21e81532b310472358 (diff) | |
download | bitcoin-b6c1f9478f52b01f0858c402b3e73761f83e4fc6.tar.xz |
Disallow extended encoding for non-witness transactions (take 3)
Github-Pull: #16021
Rebased-From: fa2b52af32f6a4b9c22c270f36e92960c29ef364
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/p2p_segwit.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py index ff7f1dd0c9..22d3cb1014 100755 --- a/test/functional/p2p_segwit.py +++ b/test/functional/p2p_segwit.py @@ -2043,9 +2043,9 @@ class SegWitTest(BitcoinTestFramework): # TODO: test p2sh sigop counting def test_superfluous_witness(self): - # Serialization of tx that puts witness flag to 1 always + # Serialization of tx that puts witness flag to 3 always def serialize_with_bogus_witness(tx): - flags = 1 + flags = 3 r = b"" r += struct.pack("<i", tx.nVersion) if flags: @@ -2064,9 +2064,29 @@ class SegWitTest(BitcoinTestFramework): r += struct.pack("<I", tx.nLockTime) return r - raw = self.nodes[0].createrawtransaction([{"txid":"00"*32, "vout":0}], {self.nodes[0].getnewaddress():1}) + class msg_bogus_tx(msg_tx): + def serialize(self): + return serialize_with_bogus_witness(self.tx) + + self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(address_type='bech32'), 5) + self.nodes[0].generate(1) + unspent = next(u for u in self.nodes[0].listunspent() if u['spendable'] and u['address'].startswith('bcrt')) + + raw = self.nodes[0].createrawtransaction([{"txid": unspent['txid'], "vout": unspent['vout']}], {self.nodes[0].getnewaddress(): 1}) tx = FromHex(CTransaction(), raw) assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, serialize_with_bogus_witness(tx).hex()) + with self.nodes[0].assert_debug_log(['Superfluous witness record']): + self.nodes[0].p2p.send_message(msg_bogus_tx(tx)) + self.nodes[0].p2p.sync_with_ping() + raw = self.nodes[0].signrawtransactionwithwallet(raw) + assert raw['complete'] + raw = raw['hex'] + tx = FromHex(CTransaction(), raw) + assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, serialize_with_bogus_witness(tx).hex()) + with self.nodes[0].assert_debug_log(['Unknown transaction optional data']): + self.nodes[0].p2p.send_message(msg_bogus_tx(tx)) + self.nodes[0].p2p.sync_with_ping() + if __name__ == '__main__': SegWitTest().main() |