Changeset View
Changeset View
Standalone View
Standalone View
test/functional/utxocommit_vector.py
| #!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
| # Copyright (c) 2015-2016 The Bitcoin developers | # Copyright (c) 2015-2016 The Bitcoin developers | ||||
| # Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
| # Test the UTXO commitment against fixed test vectors | # Test the UTXO commitment against fixed test vectors | ||||
| from test_framework.blocktools import (create_block, create_coinbase) | from test_framework.blocktools import (create_block, create_coinbase) | ||||
| from test_framework.mininode import (COutPoint, | from test_framework.mininode import (FromHex, | ||||
| CBlock, | |||||
| COutPoint, | |||||
| CTxIn, | CTxIn, | ||||
| NetworkThread, | NetworkThread, | ||||
| NodeConn, | NodeConn, | ||||
| NodeConnCB, | NodeConnCB, | ||||
| msg_block) | msg_block) | ||||
| from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
| from test_framework.util import ( | from test_framework.util import ( | ||||
| p2p_port, assert_equal, hex_str_to_bytes, bytes_to_hex_str) | p2p_port, assert_equal, hex_str_to_bytes, bytes_to_hex_str) | ||||
| # Test vectors coinbase 1,2,3 are taken from block 1,2,3 of the mainchain. | # Test vectors coinbase 1,2,3 are taken from block 1,2,3 of the mainchain. | ||||
| # The resulting testvectors are calculated in the ECMH spec. | # The resulting testvectors are calculated in the ECMH spec. | ||||
| # The txin_script is included to ensure the txid is correct | # The txin_script is included to ensure the txid is correct | ||||
| coinbases = [ | coinbases = [ | ||||
| { | { | ||||
| "txin_script": "04ffff001d0104", | "txin_script": "04ffff001d0104", | ||||
| "scriptpubkey": "410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac", | "scriptpubkey": "410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac", | ||||
| "commitment_after": "5e294984c0b6ff1c897bdbb6f7cf3ef801e2f13bc73428aacdf8cb8d3bd2f0e5" | "commitment_after": "5e294984c0b6ff1c897bdbb6f7cf3ef801e2f13bc73428aacdf8cb8d3bd2f0e5" | ||||
| }, | }, | ||||
| { | { | ||||
| "txin_script": "04ffff001d010b", | "txin_script": "04ffff001d010b", | ||||
| "scriptpubkey": "41047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac", | "scriptpubkey": "41047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac", | ||||
| "commitment_after": "48098f4ca9bb5dac273e56316db6412369ed1fa8beb579570532d16347fefccc" | "commitment_after": "48098f4ca9bb5dac273e56316db6412369ed1fa8beb579570532d16347fefccc" | ||||
| }, | }, | ||||
| { | { | ||||
| "txin_script": "04ffff001d010e", | "txin_script": "04ffff001d010e", | ||||
| "scriptpubkey": "410494b9d3e76c5b1629ecf97fff95d7a4bbdac87cc26099ada28066c6ff1eb9191223cd897194a08d0c2726c5747f1db49e8cf90e75dc3e3550ae9b30086f3cd5aaac", | "scriptpubkey": "410494b9d3e76c5b1629ecf97fff95d7a4bbdac87cc26099ada28066c6ff1eb9191223cd897194a08d0c2726c5747f1db49e8cf90e75dc3e3550ae9b30086f3cd5aaac", | ||||
| "commitment_after": "47fbdff4767c32a4ea74ca4386590f6222ee8396b8b4f00ef56e9b4943f42493" | "commitment_after": "47fbdff4767c32a4ea74ca4386590f6222ee8396b8b4f00ef56e9b4943f42493" | ||||
| } | } | ||||
| ] | ] | ||||
| # UTXO version 0 magic | |||||
| PREFIX = b"\x6a\x24UTX0" | |||||
| class UtxoCommitVectorTest(BitcoinTestFramework): | class UtxoCommitVectorTest(BitcoinTestFramework): | ||||
| def set_test_params(self): | def set_test_params(self): | ||||
| self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
| self.num_nodes = 1 | self.num_nodes = 1 | ||||
| def setup_network(self): | def setup_network(self): | ||||
| self.setup_nodes() | self.setup_nodes() | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
| # verify | # verify | ||||
| expected = hex_str_to_bytes(coinbases[n]['commitment_after'])[::-1] | expected = hex_str_to_bytes(coinbases[n]['commitment_after'])[::-1] | ||||
| assert_equal(hex_str_to_bytes( | assert_equal(hex_str_to_bytes( | ||||
| txoutsetinfo['commitment_calculated']), expected) | txoutsetinfo['commitment_calculated']), expected) | ||||
| assert_equal(hex_str_to_bytes( | assert_equal(hex_str_to_bytes( | ||||
| txoutsetinfo['commitment']), expected) | txoutsetinfo['commitment']), expected) | ||||
| # check coinbase of generated block | |||||
| bhash = self.nodes[0].generate(1) | |||||
| block = FromHex(CBlock(), self.nodes[0].getblock(bhash[0], False)) | |||||
| expected = hex_str_to_bytes(coinbases[-1]['commitment_after'])[::-1] | |||||
| assert_equal(block.get_coinbase_commitment(PREFIX), expected) | |||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||
| UtxoCommitVectorTest().main() | UtxoCommitVectorTest().main() | ||||