diff options
| author | Ross Nicoll <[email protected]> | 2018-02-11 21:00:50 +0000 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2018-09-19 22:11:47 +0100 |
| commit | 9c3a11b2488f3e01e6763bc1217598a4d1c69bde (patch) | |
| tree | ed6b54c5b71a4543a32968dc5b1d391bfe59dfed /qa | |
| parent | Insert Dogecoin testnet merkle tree root value (#1469) (diff) | |
| download | discoin-9c3a11b2488f3e01e6763bc1217598a4d1c69bde.tar.xz discoin-9c3a11b2488f3e01e6763bc1217598a4d1c69bde.zip | |
Clean up RPC tests (#1465)
* Enable full block tests
* Fix invalidblocktest
* Move watch only address funding to immediately before it's used, so node 0 doesn't spend the output before it checks it later.
* Fix `fundrawtransaction` tests and sanitize fee calculation at the same time
* Correct resolution of chain parameters when validating tx inputs, especially from previous coinbase transactions
* Set block versions on full block tests so that the generated blocks are AuxPoW compatible
Diffstat (limited to 'qa')
| -rwxr-xr-x | qa/pull-tester/rpc-tests.py | 4 | ||||
| -rwxr-xr-x | qa/rpc-tests/fundrawtransaction.py | 23 | ||||
| -rwxr-xr-x | qa/rpc-tests/invalidblockrequest.py | 4 | ||||
| -rwxr-xr-x | qa/rpc-tests/mempool_spendcoinbase.py | 20 | ||||
| -rwxr-xr-x | qa/rpc-tests/p2p-fullblocktest.py | 3 |
5 files changed, 30 insertions, 24 deletions
diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py index 849b4e7e8..797e876f7 100755 --- a/qa/pull-tester/rpc-tests.py +++ b/qa/pull-tester/rpc-tests.py @@ -103,7 +103,7 @@ testScripts = [ 'wallet-hd.py', 'walletbackup.py', # vv Tests less than 5m vv - # 'p2p-fullblocktest.py', + 'p2p-fullblocktest.py', 'fundrawtransaction.py', #'p2p-compactblocks.py', # 'segwit.py', @@ -145,7 +145,7 @@ testScripts = [ 'keypool.py', 'p2p-mempool.py', 'prioritise_transaction.py', - # 'invalidblockrequest.py', + 'invalidblockrequest.py', # 'invalidtxrequest.py', # 'p2p-versionbits-warning.py', 'preciousblock.py', diff --git a/qa/rpc-tests/fundrawtransaction.py b/qa/rpc-tests/fundrawtransaction.py index 0bf083cc4..643b5ee32 100755 --- a/qa/rpc-tests/fundrawtransaction.py +++ b/qa/rpc-tests/fundrawtransaction.py @@ -59,13 +59,6 @@ class RawTransactionsTest(BitcoinTestFramework): rawmatch = self.nodes[2].fundrawtransaction(rawmatch, {"changePosition":1, "subtractFeeFromOutputs":[0]}) assert_equal(rawmatch["changepos"], -1) - watchonly_address = self.nodes[0].getnewaddress() - watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"] - watchonly_amount = Decimal(200) - self.nodes[3].importpubkey(watchonly_pubkey, "", True) - watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, watchonly_amount) - self.nodes[0].sendtoaddress(self.nodes[3].getnewaddress(), watchonly_amount / 10) - self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5) self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0) self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5.0) @@ -587,6 +580,16 @@ class RawTransactionsTest(BitcoinTestFramework): # test a fundrawtransaction using only watchonly # ################################################## + watchonly_address = self.nodes[0].getnewaddress() + watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"] + watchonly_amount = Decimal(2000) + self.nodes[3].importpubkey(watchonly_pubkey, "", True) + watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, watchonly_amount) + self.nodes[0].sendtoaddress(self.nodes[3].getnewaddress(), watchonly_amount / 10) + + self.nodes[0].generate(1) + self.sync_all() + inputs = [] outputs = {self.nodes[2].getnewaddress() : watchonly_amount / 2} rawtx = self.nodes[3].createrawtransaction(inputs, outputs) @@ -638,7 +641,7 @@ class RawTransactionsTest(BitcoinTestFramework): result = self.nodes[3].fundrawtransaction(rawtx) # uses min_relay_tx_fee (set by settxfee) result2 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 2*min_relay_tx_fee}) result3 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 10*min_relay_tx_fee}) - result_fee_rate = result['fee'] * 1000 / count_bytes(result['hex']) + result_fee_rate = result['fee'] * 1000 / round_tx_size(count_bytes(result['hex'])) assert_fee_amount(result2['fee'], count_bytes(result2['hex']), 2 * result_fee_rate) assert_fee_amount(result3['fee'], count_bytes(result3['hex']), 10 * result_fee_rate) @@ -676,7 +679,7 @@ class RawTransactionsTest(BitcoinTestFramework): assert_equal(len(self.nodes[3].listunspent(1)), 1) inputs = [] - outputs = {self.nodes[2].getnewaddress(): 1} + outputs = {self.nodes[2].getnewaddress(): 10} rawtx = self.nodes[3].createrawtransaction(inputs, outputs) result = [self.nodes[3].fundrawtransaction(rawtx), # uses min_relay_tx_fee (set by settxfee) @@ -699,7 +702,7 @@ class RawTransactionsTest(BitcoinTestFramework): assert_equal(change[3] + result[3]['fee'], change[4]) inputs = [] - outputs = {self.nodes[2].getnewaddress(): value for value in (1.0, 1.1, 1.2, 1.3)} + outputs = {self.nodes[2].getnewaddress(): value for value in (10, 11, 12, 13)} keys = list(outputs.keys()) rawtx = self.nodes[3].createrawtransaction(inputs, outputs) diff --git a/qa/rpc-tests/invalidblockrequest.py b/qa/rpc-tests/invalidblockrequest.py index 3d8107a76..660a770fa 100755 --- a/qa/rpc-tests/invalidblockrequest.py +++ b/qa/rpc-tests/invalidblockrequest.py @@ -58,7 +58,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework): Now we need that block to mature so we can spend the coinbase. ''' test = TestInstance(sync_every_block=False) - for i in range(100): + for i in range(60): block = create_block(self.tip, create_coinbase(height), self.block_time) block.solve() self.tip = block.sha256 @@ -103,7 +103,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework): ''' block3 = create_block(self.tip, create_coinbase(height), self.block_time) self.block_time += 1 - block3.vtx[0].vout[0].nValue = 100 * COIN # Too high! + block3.vtx[0].vout[0].nValue = 10000000 * COIN # Too high! block3.vtx[0].sha256=None block3.vtx[0].calc_sha256() block3.hashMerkleRoot = block3.calc_merkle_root() diff --git a/qa/rpc-tests/mempool_spendcoinbase.py b/qa/rpc-tests/mempool_spendcoinbase.py index e74a4541e..3fdba761d 100755 --- a/qa/rpc-tests/mempool_spendcoinbase.py +++ b/qa/rpc-tests/mempool_spendcoinbase.py @@ -6,8 +6,8 @@ # # Test spending coinbase transactions. # The coinbase transaction in block N can appear in block -# N+100... so is valid in the mempool when the best block -# height is N+99. +# N+60... so is valid in the mempool when the best block +# height is N+59. # This test makes sure coinbase spends that will be mature # in the next block are accepted into the memory pool, # but less mature coinbase spends are NOT. @@ -43,21 +43,21 @@ class MempoolSpendCoinbaseTest(BitcoinTestFramework): coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ] spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 500000) for txid in coinbase_txids ] - spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0]) + spend_61_id = self.nodes[0].sendrawtransaction(spends_raw[0]) - # coinbase at height 102 should be too immature to spend + # coinbase at height 62 should be too immature to spend assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, spends_raw[1]) - # mempool should have just spend_101: - assert_equal(self.nodes[0].getrawmempool(), [ spend_101_id ]) + # mempool should have just spend_61: + assert_equal(self.nodes[0].getrawmempool(), [ spend_61_id ]) - # mine a block, spend_101 should get confirmed + # mine a block, spend_61 should get confirmed self.nodes[0].generate(1) assert_equal(set(self.nodes[0].getrawmempool()), set()) - # ... and now height 102 can be spent: - spend_102_id = self.nodes[0].sendrawtransaction(spends_raw[1]) - assert_equal(self.nodes[0].getrawmempool(), [ spend_102_id ]) + # ... and now height 62 can be spent: + spend_62_id = self.nodes[0].sendrawtransaction(spends_raw[1]) + assert_equal(self.nodes[0].getrawmempool(), [ spend_62_id ]) if __name__ == '__main__': MempoolSpendCoinbaseTest().main() diff --git a/qa/rpc-tests/p2p-fullblocktest.py b/qa/rpc-tests/p2p-fullblocktest.py index a73a0c344..467f6745d 100755 --- a/qa/rpc-tests/p2p-fullblocktest.py +++ b/qa/rpc-tests/p2p-fullblocktest.py @@ -616,6 +616,7 @@ class FullBlockTest(ComparisonTestFramework): height = self.block_heights[self.tip.sha256] + 1 coinbase = create_coinbase(height, self.coinbase_pubkey) b44 = CBlock() + b44.nVersion = 0x620004 b44.nTime = self.tip.nTime + 1 b44.hashPrevBlock = self.tip.sha256 b44.nBits = 0x207fffff @@ -630,6 +631,7 @@ class FullBlockTest(ComparisonTestFramework): # A block with a non-coinbase as the first tx non_coinbase = create_tx(out[15].tx, out[15].n, 1) b45 = CBlock() + b44.nVersion = 0x620004 b45.nTime = self.tip.nTime + 1 b45.hashPrevBlock = self.tip.sha256 b45.nBits = 0x207fffff @@ -645,6 +647,7 @@ class FullBlockTest(ComparisonTestFramework): # A block with no txns tip(44) b46 = CBlock() + b44.nVersion = 0x620004 b46.nTime = b44.nTime+1 b46.hashPrevBlock = b44.sha256 b46.nBits = 0x207fffff |