Merge #15773: test: Add BitcoinTestFramework::sync_* methods

fafe5f0d09 test: Remove unused imports (MarcoFalke)
fa16a09215 scripted-diff: use self.sync_* methods (MarcoFalke)
faf77f9b90 test: Pass self to test_simple_bumpfee_succeeds (MarcoFalke)
fa6dc7c5c3 test: Add BitcoinTestFramework::sync_* methods (MarcoFalke)
fafe008cb4 test: Pass at most one node group to sync_all (MarcoFalke)
fa4680ed09 scripted-diff: Rename sync_blocks to send_blocks to avoid name collisions and confusion (MarcoFalke)

Pull request description:

  This adds methods to the test framework that can be called by just `self.sync_*()`.

  This avoids having to import the underlying util method. Also, in the default case, where all nodes are synced this avoid having to pass `self.nodes` explicitly.

  So the effective changes are:

  ```diff
  @@
  -from test_framework.util import sync_blocks, sync_mempools
  @@
  -        sync_blocks(self.nodes)
  +        self.sync_blocks()
  @@
  -        sync_mempools(self.nodes)
  +        self.sync_mempools()

ACKs for commit fafe5f:
  promag:
    utACK fafe5f0.
  jonatack:
    ACK fafe5f0d09, nice simplification.

Tree-SHA512: 5c81840edf9fb3c5de2d7bf95ca36a5a8d23567cd1479a0f4044547c2080e9a3c5cf375357bc8eebb5b68829be050a171ab2512cfd47b89feed51fe3bad2cd72
This commit is contained in:
MarcoFalke 2019-04-11 13:22:37 -04:00
commit 0e9cb2d24d
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
32 changed files with 331 additions and 288 deletions

View file

@ -117,7 +117,7 @@ class ExampleTest(BitcoinTestFramework):
# sync_all() should not include node2, since we're not expecting it to # sync_all() should not include node2, since we're not expecting it to
# sync. # sync.
connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 1)
self.sync_all([self.nodes[0:2]]) self.sync_all(self.nodes[0:2])
# Use setup_nodes() to customize the node start behaviour (for example if # Use setup_nodes() to customize the node start behaviour (for example if
# you don't want to start all nodes at the start of the test). # you don't want to start all nodes at the start of the test).
@ -141,7 +141,7 @@ class ExampleTest(BitcoinTestFramework):
# Generating a block on one of the nodes will get us out of IBD # Generating a block on one of the nodes will get us out of IBD
blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)] blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)]
self.sync_all([self.nodes[0:2]]) self.sync_all(self.nodes[0:2])
# Notice above how we called an RPC by calling a method with the same # Notice above how we called an RPC by calling a method with the same
# name on the node object. Notice also how we used a keyword argument # name on the node object. Notice also how we used a keyword argument

View file

@ -10,7 +10,13 @@ from test_framework.blocktools import create_block, create_coinbase, add_witness
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, ToHex from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, ToHex
from test_framework.script import CScript from test_framework.script import CScript
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, get_bip9_status, satoshi_round, sync_blocks from test_framework.util import (
assert_equal,
assert_greater_than,
assert_raises_rpc_error,
get_bip9_status,
satoshi_round,
)
SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31) SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height) SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height)
@ -385,7 +391,7 @@ class BIP68Test(BitcoinTestFramework):
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], "locked_in") assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], "locked_in")
self.nodes[0].generate(1) self.nodes[0].generate(1)
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], "active") assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], "active")
sync_blocks(self.nodes) self.sync_blocks()
# Use self.nodes[1] to test that version 2 transactions are standard. # Use self.nodes[1] to test that version 2 transactions are standard.
def test_version2_relay(self): def test_version2_relay(self):

View file

@ -98,7 +98,7 @@ class FullBlockTest(BitcoinTestFramework):
# Create a new block # Create a new block
b0 = self.next_block(0) b0 = self.next_block(0)
self.save_spendable_output() self.save_spendable_output()
self.sync_blocks([b0]) self.send_blocks([b0])
# These constants chosen specifically to trigger an immature coinbase spend # These constants chosen specifically to trigger an immature coinbase spend
# at a certain time below. # at a certain time below.
@ -110,7 +110,7 @@ class FullBlockTest(BitcoinTestFramework):
for i in range(NUM_BUFFER_BLOCKS_TO_GENERATE): for i in range(NUM_BUFFER_BLOCKS_TO_GENERATE):
blocks.append(self.next_block("maturitybuffer.{}".format(i))) blocks.append(self.next_block("maturitybuffer.{}".format(i)))
self.save_spendable_output() self.save_spendable_output()
self.sync_blocks(blocks) self.send_blocks(blocks)
# collect spendable outputs now to avoid cluttering the code later on # collect spendable outputs now to avoid cluttering the code later on
out = [] out = []
@ -126,7 +126,7 @@ class FullBlockTest(BitcoinTestFramework):
b2 = self.next_block(2, spend=out[1]) b2 = self.next_block(2, spend=out[1])
self.save_spendable_output() self.save_spendable_output()
self.sync_blocks([b1, b2], timeout=4) self.send_blocks([b1, b2], timeout=4)
# Select a txn with an output eligible for spending. This won't actually be spent, # Select a txn with an output eligible for spending. This won't actually be spent,
# since we're testing submission of a series of blocks with invalid txns. # since we're testing submission of a series of blocks with invalid txns.
@ -162,7 +162,7 @@ class FullBlockTest(BitcoinTestFramework):
badtx.vout = [] badtx.vout = []
badtx.rehash() badtx.rehash()
badblock = self.update_block(blockname, [badtx]) badblock = self.update_block(blockname, [badtx])
self.sync_blocks( self.send_blocks(
[badblock], success=False, [badblock], success=False,
reject_reason=(template.block_reject_reason or template.reject_reason), reject_reason=(template.block_reject_reason or template.reject_reason),
reconnect=True, timeout=2) reconnect=True, timeout=2)
@ -179,7 +179,7 @@ class FullBlockTest(BitcoinTestFramework):
self.move_tip(1) self.move_tip(1)
b3 = self.next_block(3, spend=out[1]) b3 = self.next_block(3, spend=out[1])
txout_b3 = b3.vtx[1] txout_b3 = b3.vtx[1]
self.sync_blocks([b3], False) self.send_blocks([b3], False)
# Now we add another block to make the alternative chain longer. # Now we add another block to make the alternative chain longer.
# #
@ -187,7 +187,7 @@ class FullBlockTest(BitcoinTestFramework):
# \-> b3 (1) -> b4 (2) # \-> b3 (1) -> b4 (2)
self.log.info("Reorg to a longer chain") self.log.info("Reorg to a longer chain")
b4 = self.next_block(4, spend=out[2]) b4 = self.next_block(4, spend=out[2])
self.sync_blocks([b4]) self.send_blocks([b4])
# ... and back to the first chain. # ... and back to the first chain.
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -195,11 +195,11 @@ class FullBlockTest(BitcoinTestFramework):
self.move_tip(2) self.move_tip(2)
b5 = self.next_block(5, spend=out[2]) b5 = self.next_block(5, spend=out[2])
self.save_spendable_output() self.save_spendable_output()
self.sync_blocks([b5], False) self.send_blocks([b5], False)
self.log.info("Reorg back to the original chain") self.log.info("Reorg back to the original chain")
b6 = self.next_block(6, spend=out[3]) b6 = self.next_block(6, spend=out[3])
self.sync_blocks([b6], True) self.send_blocks([b6], True)
# Try to create a fork that double-spends # Try to create a fork that double-spends
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -208,10 +208,10 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a chain with a double spend, even if it is longer") self.log.info("Reject a chain with a double spend, even if it is longer")
self.move_tip(5) self.move_tip(5)
b7 = self.next_block(7, spend=out[2]) b7 = self.next_block(7, spend=out[2])
self.sync_blocks([b7], False) self.send_blocks([b7], False)
b8 = self.next_block(8, spend=out[4]) b8 = self.next_block(8, spend=out[4])
self.sync_blocks([b8], False, reconnect=True) self.send_blocks([b8], False, reconnect=True)
# Try to create a block that has too much fee # Try to create a block that has too much fee
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -220,7 +220,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block where the miner creates too much coinbase reward") self.log.info("Reject a block where the miner creates too much coinbase reward")
self.move_tip(6) self.move_tip(6)
b9 = self.next_block(9, spend=out[4], additional_coinbase_value=1) b9 = self.next_block(9, spend=out[4], additional_coinbase_value=1)
self.sync_blocks([b9], success=False, reject_reason='bad-cb-amount', reconnect=True) self.send_blocks([b9], success=False, reject_reason='bad-cb-amount', reconnect=True)
# Create a fork that ends in a block with too much fee (the one that causes the reorg) # Create a fork that ends in a block with too much fee (the one that causes the reorg)
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -229,10 +229,10 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a chain where the miner creates too much coinbase reward, even if the chain is longer") self.log.info("Reject a chain where the miner creates too much coinbase reward, even if the chain is longer")
self.move_tip(5) self.move_tip(5)
b10 = self.next_block(10, spend=out[3]) b10 = self.next_block(10, spend=out[3])
self.sync_blocks([b10], False) self.send_blocks([b10], False)
b11 = self.next_block(11, spend=out[4], additional_coinbase_value=1) b11 = self.next_block(11, spend=out[4], additional_coinbase_value=1)
self.sync_blocks([b11], success=False, reject_reason='bad-cb-amount', reconnect=True) self.send_blocks([b11], success=False, reject_reason='bad-cb-amount', reconnect=True)
# Try again, but with a valid fork first # Try again, but with a valid fork first
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -245,7 +245,7 @@ class FullBlockTest(BitcoinTestFramework):
b13 = self.next_block(13, spend=out[4]) b13 = self.next_block(13, spend=out[4])
self.save_spendable_output() self.save_spendable_output()
b14 = self.next_block(14, spend=out[5], additional_coinbase_value=1) b14 = self.next_block(14, spend=out[5], additional_coinbase_value=1)
self.sync_blocks([b12, b13, b14], success=False, reject_reason='bad-cb-amount', reconnect=True) self.send_blocks([b12, b13, b14], success=False, reject_reason='bad-cb-amount', reconnect=True)
# New tip should be b13. # New tip should be b13.
assert_equal(node.getbestblockhash(), b13.hash) assert_equal(node.getbestblockhash(), b13.hash)
@ -259,12 +259,12 @@ class FullBlockTest(BitcoinTestFramework):
self.move_tip(13) self.move_tip(13)
b15 = self.next_block(15, spend=out[5], script=lots_of_checksigs) b15 = self.next_block(15, spend=out[5], script=lots_of_checksigs)
self.save_spendable_output() self.save_spendable_output()
self.sync_blocks([b15], True) self.send_blocks([b15], True)
self.log.info("Reject a block with too many checksigs") self.log.info("Reject a block with too many checksigs")
too_many_checksigs = CScript([OP_CHECKSIG] * (MAX_BLOCK_SIGOPS)) too_many_checksigs = CScript([OP_CHECKSIG] * (MAX_BLOCK_SIGOPS))
b16 = self.next_block(16, spend=out[6], script=too_many_checksigs) b16 = self.next_block(16, spend=out[6], script=too_many_checksigs)
self.sync_blocks([b16], success=False, reject_reason='bad-blk-sigops', reconnect=True) self.send_blocks([b16], success=False, reject_reason='bad-blk-sigops', reconnect=True)
# Attempt to spend a transaction created on a different fork # Attempt to spend a transaction created on a different fork
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -273,7 +273,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block with a spend from a re-org'ed out tx") self.log.info("Reject a block with a spend from a re-org'ed out tx")
self.move_tip(15) self.move_tip(15)
b17 = self.next_block(17, spend=txout_b3) b17 = self.next_block(17, spend=txout_b3)
self.sync_blocks([b17], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b17], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
# Attempt to spend a transaction created on a different fork (on a fork this time) # Attempt to spend a transaction created on a different fork (on a fork this time)
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -283,10 +283,10 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block with a spend from a re-org'ed out tx (on a forked chain)") self.log.info("Reject a block with a spend from a re-org'ed out tx (on a forked chain)")
self.move_tip(13) self.move_tip(13)
b18 = self.next_block(18, spend=txout_b3) b18 = self.next_block(18, spend=txout_b3)
self.sync_blocks([b18], False) self.send_blocks([b18], False)
b19 = self.next_block(19, spend=out[6]) b19 = self.next_block(19, spend=out[6])
self.sync_blocks([b19], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b19], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
# Attempt to spend a coinbase at depth too low # Attempt to spend a coinbase at depth too low
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -295,7 +295,7 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block spending an immature coinbase.") self.log.info("Reject a block spending an immature coinbase.")
self.move_tip(15) self.move_tip(15)
b20 = self.next_block(20, spend=out[7]) b20 = self.next_block(20, spend=out[7])
self.sync_blocks([b20], success=False, reject_reason='bad-txns-premature-spend-of-coinbase') self.send_blocks([b20], success=False, reject_reason='bad-txns-premature-spend-of-coinbase')
# Attempt to spend a coinbase at depth too low (on a fork this time) # Attempt to spend a coinbase at depth too low (on a fork this time)
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -305,10 +305,10 @@ class FullBlockTest(BitcoinTestFramework):
self.log.info("Reject a block spending an immature coinbase (on a forked chain)") self.log.info("Reject a block spending an immature coinbase (on a forked chain)")
self.move_tip(13) self.move_tip(13)
b21 = self.next_block(21, spend=out[6]) b21 = self.next_block(21, spend=out[6])
self.sync_blocks([b21], False) self.send_blocks([b21], False)
b22 = self.next_block(22, spend=out[5]) b22 = self.next_block(22, spend=out[5])
self.sync_blocks([b22], success=False, reject_reason='bad-txns-premature-spend-of-coinbase') self.send_blocks([b22], success=False, reject_reason='bad-txns-premature-spend-of-coinbase')
# Create a block on either side of MAX_BLOCK_BASE_SIZE and make sure its accepted/rejected # Create a block on either side of MAX_BLOCK_BASE_SIZE and make sure its accepted/rejected
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -326,7 +326,7 @@ class FullBlockTest(BitcoinTestFramework):
b23 = self.update_block(23, [tx]) b23 = self.update_block(23, [tx])
# Make sure the math above worked out to produce a max-sized block # Make sure the math above worked out to produce a max-sized block
assert_equal(len(b23.serialize()), MAX_BLOCK_BASE_SIZE) assert_equal(len(b23.serialize()), MAX_BLOCK_BASE_SIZE)
self.sync_blocks([b23], True) self.send_blocks([b23], True)
self.save_spendable_output() self.save_spendable_output()
self.log.info("Reject a block of size MAX_BLOCK_BASE_SIZE + 1") self.log.info("Reject a block of size MAX_BLOCK_BASE_SIZE + 1")
@ -337,10 +337,10 @@ class FullBlockTest(BitcoinTestFramework):
tx.vout = [CTxOut(0, script_output)] tx.vout = [CTxOut(0, script_output)]
b24 = self.update_block(24, [tx]) b24 = self.update_block(24, [tx])
assert_equal(len(b24.serialize()), MAX_BLOCK_BASE_SIZE + 1) assert_equal(len(b24.serialize()), MAX_BLOCK_BASE_SIZE + 1)
self.sync_blocks([b24], success=False, reject_reason='bad-blk-length', reconnect=True) self.send_blocks([b24], success=False, reject_reason='bad-blk-length', reconnect=True)
b25 = self.next_block(25, spend=out[7]) b25 = self.next_block(25, spend=out[7])
self.sync_blocks([b25], False) self.send_blocks([b25], False)
# Create blocks with a coinbase input script size out of range # Create blocks with a coinbase input script size out of range
# genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3) # genesis -> b1 (0) -> b2 (1) -> b5 (2) -> b6 (3)
@ -355,11 +355,11 @@ class FullBlockTest(BitcoinTestFramework):
# update_block causes the merkle root to get updated, even with no new # update_block causes the merkle root to get updated, even with no new
# transactions, and updates the required state. # transactions, and updates the required state.
b26 = self.update_block(26, []) b26 = self.update_block(26, [])
self.sync_blocks([b26], success=False, reject_reason='bad-cb-length', reconnect=True) self.send_blocks([b26], success=False, reject_reason='bad-cb-length', reconnect=True)
# Extend the b26 chain to make sure bitcoind isn't accepting b26 # Extend the b26 chain to make sure bitcoind isn't accepting b26
b27 = self.next_block(27, spend=out[7]) b27 = self.next_block(27, spend=out[7])
self.sync_blocks([b27], False) self.send_blocks([b27], False)
# Now try a too-large-coinbase script # Now try a too-large-coinbase script
self.move_tip(15) self.move_tip(15)
@ -367,11 +367,11 @@ class FullBlockTest(BitcoinTestFramework):
b28.vtx[0].vin[0].scriptSig = b'\x00' * 101 b28.vtx[0].vin[0].scriptSig = b'\x00' * 101
b28.vtx[0].rehash() b28.vtx[0].rehash()
b28 = self.update_block(28, []) b28 = self.update_block(28, [])
self.sync_blocks([b28], success=False, reject_reason='bad-cb-length', reconnect=True) self.send_blocks([b28], success=False, reject_reason='bad-cb-length', reconnect=True)
# Extend the b28 chain to make sure bitcoind isn't accepting b28 # Extend the b28 chain to make sure bitcoind isn't accepting b28
b29 = self.next_block(29, spend=out[7]) b29 = self.next_block(29, spend=out[7])
self.sync_blocks([b29], False) self.send_blocks([b29], False)
# b30 has a max-sized coinbase scriptSig. # b30 has a max-sized coinbase scriptSig.
self.move_tip(23) self.move_tip(23)
@ -379,7 +379,7 @@ class FullBlockTest(BitcoinTestFramework):
b30.vtx[0].vin[0].scriptSig = b'\x00' * 100 b30.vtx[0].vin[0].scriptSig = b'\x00' * 100
b30.vtx[0].rehash() b30.vtx[0].rehash()
b30 = self.update_block(30, []) b30 = self.update_block(30, [])
self.sync_blocks([b30], True) self.send_blocks([b30], True)
self.save_spendable_output() self.save_spendable_output()
# b31 - b35 - check sigops of OP_CHECKMULTISIG / OP_CHECKMULTISIGVERIFY / OP_CHECKSIGVERIFY # b31 - b35 - check sigops of OP_CHECKMULTISIG / OP_CHECKMULTISIGVERIFY / OP_CHECKSIGVERIFY
@ -395,7 +395,7 @@ class FullBlockTest(BitcoinTestFramework):
lots_of_multisigs = CScript([OP_CHECKMULTISIG] * ((MAX_BLOCK_SIGOPS - 1) // 20) + [OP_CHECKSIG] * 19) lots_of_multisigs = CScript([OP_CHECKMULTISIG] * ((MAX_BLOCK_SIGOPS - 1) // 20) + [OP_CHECKSIG] * 19)
b31 = self.next_block(31, spend=out[8], script=lots_of_multisigs) b31 = self.next_block(31, spend=out[8], script=lots_of_multisigs)
assert_equal(get_legacy_sigopcount_block(b31), MAX_BLOCK_SIGOPS) assert_equal(get_legacy_sigopcount_block(b31), MAX_BLOCK_SIGOPS)
self.sync_blocks([b31], True) self.send_blocks([b31], True)
self.save_spendable_output() self.save_spendable_output()
# this goes over the limit because the coinbase has one sigop # this goes over the limit because the coinbase has one sigop
@ -403,33 +403,33 @@ class FullBlockTest(BitcoinTestFramework):
too_many_multisigs = CScript([OP_CHECKMULTISIG] * (MAX_BLOCK_SIGOPS // 20)) too_many_multisigs = CScript([OP_CHECKMULTISIG] * (MAX_BLOCK_SIGOPS // 20))
b32 = self.next_block(32, spend=out[9], script=too_many_multisigs) b32 = self.next_block(32, spend=out[9], script=too_many_multisigs)
assert_equal(get_legacy_sigopcount_block(b32), MAX_BLOCK_SIGOPS + 1) assert_equal(get_legacy_sigopcount_block(b32), MAX_BLOCK_SIGOPS + 1)
self.sync_blocks([b32], success=False, reject_reason='bad-blk-sigops', reconnect=True) self.send_blocks([b32], success=False, reject_reason='bad-blk-sigops', reconnect=True)
# CHECKMULTISIGVERIFY # CHECKMULTISIGVERIFY
self.log.info("Accept a block with the max number of OP_CHECKMULTISIGVERIFY sigops") self.log.info("Accept a block with the max number of OP_CHECKMULTISIGVERIFY sigops")
self.move_tip(31) self.move_tip(31)
lots_of_multisigs = CScript([OP_CHECKMULTISIGVERIFY] * ((MAX_BLOCK_SIGOPS - 1) // 20) + [OP_CHECKSIG] * 19) lots_of_multisigs = CScript([OP_CHECKMULTISIGVERIFY] * ((MAX_BLOCK_SIGOPS - 1) // 20) + [OP_CHECKSIG] * 19)
b33 = self.next_block(33, spend=out[9], script=lots_of_multisigs) b33 = self.next_block(33, spend=out[9], script=lots_of_multisigs)
self.sync_blocks([b33], True) self.send_blocks([b33], True)
self.save_spendable_output() self.save_spendable_output()
self.log.info("Reject a block with too many OP_CHECKMULTISIGVERIFY sigops") self.log.info("Reject a block with too many OP_CHECKMULTISIGVERIFY sigops")
too_many_multisigs = CScript([OP_CHECKMULTISIGVERIFY] * (MAX_BLOCK_SIGOPS // 20)) too_many_multisigs = CScript([OP_CHECKMULTISIGVERIFY] * (MAX_BLOCK_SIGOPS // 20))
b34 = self.next_block(34, spend=out[10], script=too_many_multisigs) b34 = self.next_block(34, spend=out[10], script=too_many_multisigs)
self.sync_blocks([b34], success=False, reject_reason='bad-blk-sigops', reconnect=True) self.send_blocks([b34], success=False, reject_reason='bad-blk-sigops', reconnect=True)
# CHECKSIGVERIFY # CHECKSIGVERIFY
self.log.info("Accept a block with the max number of OP_CHECKSIGVERIFY sigops") self.log.info("Accept a block with the max number of OP_CHECKSIGVERIFY sigops")
self.move_tip(33) self.move_tip(33)
lots_of_checksigs = CScript([OP_CHECKSIGVERIFY] * (MAX_BLOCK_SIGOPS - 1)) lots_of_checksigs = CScript([OP_CHECKSIGVERIFY] * (MAX_BLOCK_SIGOPS - 1))
b35 = self.next_block(35, spend=out[10], script=lots_of_checksigs) b35 = self.next_block(35, spend=out[10], script=lots_of_checksigs)
self.sync_blocks([b35], True) self.send_blocks([b35], True)
self.save_spendable_output() self.save_spendable_output()
self.log.info("Reject a block with too many OP_CHECKSIGVERIFY sigops") self.log.info("Reject a block with too many OP_CHECKSIGVERIFY sigops")
too_many_checksigs = CScript([OP_CHECKSIGVERIFY] * (MAX_BLOCK_SIGOPS)) too_many_checksigs = CScript([OP_CHECKSIGVERIFY] * (MAX_BLOCK_SIGOPS))
b36 = self.next_block(36, spend=out[11], script=too_many_checksigs) b36 = self.next_block(36, spend=out[11], script=too_many_checksigs)
self.sync_blocks([b36], success=False, reject_reason='bad-blk-sigops', reconnect=True) self.send_blocks([b36], success=False, reject_reason='bad-blk-sigops', reconnect=True)
# Check spending of a transaction in a block which failed to connect # Check spending of a transaction in a block which failed to connect
# #
@ -446,12 +446,12 @@ class FullBlockTest(BitcoinTestFramework):
txout_b37 = b37.vtx[1] txout_b37 = b37.vtx[1]
tx = self.create_and_sign_transaction(out[11], 0) tx = self.create_and_sign_transaction(out[11], 0)
b37 = self.update_block(37, [tx]) b37 = self.update_block(37, [tx])
self.sync_blocks([b37], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b37], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
# attempt to spend b37's first non-coinbase tx, at which point b37 was still considered valid # attempt to spend b37's first non-coinbase tx, at which point b37 was still considered valid
self.move_tip(35) self.move_tip(35)
b38 = self.next_block(38, spend=txout_b37) b38 = self.next_block(38, spend=txout_b37)
self.sync_blocks([b38], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b38], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
# Check P2SH SigOp counting # Check P2SH SigOp counting
# #
@ -501,7 +501,7 @@ class FullBlockTest(BitcoinTestFramework):
b39_outputs += 1 b39_outputs += 1
b39 = self.update_block(39, []) b39 = self.update_block(39, [])
self.sync_blocks([b39], True) self.send_blocks([b39], True)
self.save_spendable_output() self.save_spendable_output()
# Test sigops in P2SH redeem scripts # Test sigops in P2SH redeem scripts
@ -543,7 +543,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.rehash() tx.rehash()
new_txs.append(tx) new_txs.append(tx)
self.update_block(40, new_txs) self.update_block(40, new_txs)
self.sync_blocks([b40], success=False, reject_reason='bad-blk-sigops', reconnect=True) self.send_blocks([b40], success=False, reject_reason='bad-blk-sigops', reconnect=True)
# same as b40, but one less sigop # same as b40, but one less sigop
self.log.info("Accept a block with the max number of P2SH sigops") self.log.info("Accept a block with the max number of P2SH sigops")
@ -556,7 +556,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.vout.append(CTxOut(1, CScript([OP_CHECKSIG] * b41_sigops_to_fill))) tx.vout.append(CTxOut(1, CScript([OP_CHECKSIG] * b41_sigops_to_fill)))
tx.rehash() tx.rehash()
self.update_block(41, [tx]) self.update_block(41, [tx])
self.sync_blocks([b41], True) self.send_blocks([b41], True)
# Fork off of b39 to create a constant base again # Fork off of b39 to create a constant base again
# #
@ -569,7 +569,7 @@ class FullBlockTest(BitcoinTestFramework):
b43 = self.next_block(43, spend=out[13]) b43 = self.next_block(43, spend=out[13])
self.save_spendable_output() self.save_spendable_output()
self.sync_blocks([b42, b43], True) self.send_blocks([b42, b43], True)
# Test a number of really invalid scenarios # Test a number of really invalid scenarios
# #
@ -591,7 +591,7 @@ class FullBlockTest(BitcoinTestFramework):
self.tip = b44 self.tip = b44
self.block_heights[b44.sha256] = height self.block_heights[b44.sha256] = height
self.blocks[44] = b44 self.blocks[44] = b44
self.sync_blocks([b44], True) self.send_blocks([b44], True)
self.log.info("Reject a block with a non-coinbase as the first tx") self.log.info("Reject a block with a non-coinbase as the first tx")
non_coinbase = self.create_tx(out[15], 0, 1) non_coinbase = self.create_tx(out[15], 0, 1)
@ -606,7 +606,7 @@ class FullBlockTest(BitcoinTestFramework):
self.block_heights[b45.sha256] = self.block_heights[self.tip.sha256] + 1 self.block_heights[b45.sha256] = self.block_heights[self.tip.sha256] + 1
self.tip = b45 self.tip = b45
self.blocks[45] = b45 self.blocks[45] = b45
self.sync_blocks([b45], success=False, reject_reason='bad-cb-missing', reconnect=True) self.send_blocks([b45], success=False, reject_reason='bad-cb-missing', reconnect=True)
self.log.info("Reject a block with no transactions") self.log.info("Reject a block with no transactions")
self.move_tip(44) self.move_tip(44)
@ -621,7 +621,7 @@ class FullBlockTest(BitcoinTestFramework):
self.tip = b46 self.tip = b46
assert 46 not in self.blocks assert 46 not in self.blocks
self.blocks[46] = b46 self.blocks[46] = b46
self.sync_blocks([b46], success=False, reject_reason='bad-blk-length', reconnect=True) self.send_blocks([b46], success=False, reject_reason='bad-blk-length', reconnect=True)
self.log.info("Reject a block with invalid work") self.log.info("Reject a block with invalid work")
self.move_tip(44) self.move_tip(44)
@ -630,35 +630,35 @@ class FullBlockTest(BitcoinTestFramework):
while b47.sha256 < target: while b47.sha256 < target:
b47.nNonce += 1 b47.nNonce += 1
b47.rehash() b47.rehash()
self.sync_blocks([b47], False, force_send=True, reject_reason='high-hash') self.send_blocks([b47], False, force_send=True, reject_reason='high-hash')
self.log.info("Reject a block with a timestamp >2 hours in the future") self.log.info("Reject a block with a timestamp >2 hours in the future")
self.move_tip(44) self.move_tip(44)
b48 = self.next_block(48, solve=False) b48 = self.next_block(48, solve=False)
b48.nTime = int(time.time()) + 60 * 60 * 3 b48.nTime = int(time.time()) + 60 * 60 * 3
b48.solve() b48.solve()
self.sync_blocks([b48], False, force_send=True, reject_reason='time-too-new') self.send_blocks([b48], False, force_send=True, reject_reason='time-too-new')
self.log.info("Reject a block with invalid merkle hash") self.log.info("Reject a block with invalid merkle hash")
self.move_tip(44) self.move_tip(44)
b49 = self.next_block(49) b49 = self.next_block(49)
b49.hashMerkleRoot += 1 b49.hashMerkleRoot += 1
b49.solve() b49.solve()
self.sync_blocks([b49], success=False, reject_reason='bad-txnmrklroot', reconnect=True) self.send_blocks([b49], success=False, reject_reason='bad-txnmrklroot', reconnect=True)
self.log.info("Reject a block with incorrect POW limit") self.log.info("Reject a block with incorrect POW limit")
self.move_tip(44) self.move_tip(44)
b50 = self.next_block(50) b50 = self.next_block(50)
b50.nBits = b50.nBits - 1 b50.nBits = b50.nBits - 1
b50.solve() b50.solve()
self.sync_blocks([b50], False, force_send=True, reject_reason='bad-diffbits', reconnect=True) self.send_blocks([b50], False, force_send=True, reject_reason='bad-diffbits', reconnect=True)
self.log.info("Reject a block with two coinbase transactions") self.log.info("Reject a block with two coinbase transactions")
self.move_tip(44) self.move_tip(44)
b51 = self.next_block(51) b51 = self.next_block(51)
cb2 = create_coinbase(51, self.coinbase_pubkey) cb2 = create_coinbase(51, self.coinbase_pubkey)
b51 = self.update_block(51, [cb2]) b51 = self.update_block(51, [cb2])
self.sync_blocks([b51], success=False, reject_reason='bad-cb-multiple', reconnect=True) self.send_blocks([b51], success=False, reject_reason='bad-cb-multiple', reconnect=True)
self.log.info("Reject a block with duplicate transactions") self.log.info("Reject a block with duplicate transactions")
# Note: txns have to be in the right position in the merkle tree to trigger this error # Note: txns have to be in the right position in the merkle tree to trigger this error
@ -666,7 +666,7 @@ class FullBlockTest(BitcoinTestFramework):
b52 = self.next_block(52, spend=out[15]) b52 = self.next_block(52, spend=out[15])
tx = self.create_tx(b52.vtx[1], 0, 1) tx = self.create_tx(b52.vtx[1], 0, 1)
b52 = self.update_block(52, [tx, tx]) b52 = self.update_block(52, [tx, tx])
self.sync_blocks([b52], success=False, reject_reason='bad-txns-duplicate', reconnect=True) self.send_blocks([b52], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
# Test block timestamps # Test block timestamps
# -> b31 (8) -> b33 (9) -> b35 (10) -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15) # -> b31 (8) -> b33 (9) -> b35 (10) -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15)
@ -674,21 +674,21 @@ class FullBlockTest(BitcoinTestFramework):
# #
self.move_tip(43) self.move_tip(43)
b53 = self.next_block(53, spend=out[14]) b53 = self.next_block(53, spend=out[14])
self.sync_blocks([b53], False) self.send_blocks([b53], False)
self.save_spendable_output() self.save_spendable_output()
self.log.info("Reject a block with timestamp before MedianTimePast") self.log.info("Reject a block with timestamp before MedianTimePast")
b54 = self.next_block(54, spend=out[15]) b54 = self.next_block(54, spend=out[15])
b54.nTime = b35.nTime - 1 b54.nTime = b35.nTime - 1
b54.solve() b54.solve()
self.sync_blocks([b54], False, force_send=True, reject_reason='time-too-old') self.send_blocks([b54], False, force_send=True, reject_reason='time-too-old')
# valid timestamp # valid timestamp
self.move_tip(53) self.move_tip(53)
b55 = self.next_block(55, spend=out[15]) b55 = self.next_block(55, spend=out[15])
b55.nTime = b35.nTime b55.nTime = b35.nTime
self.update_block(55, []) self.update_block(55, [])
self.sync_blocks([b55], True) self.send_blocks([b55], True)
self.save_spendable_output() self.save_spendable_output()
# Test Merkle tree malleability # Test Merkle tree malleability
@ -733,7 +733,7 @@ class FullBlockTest(BitcoinTestFramework):
assert_equal(len(b56.vtx), 3) assert_equal(len(b56.vtx), 3)
b56 = self.update_block(56, [tx1]) b56 = self.update_block(56, [tx1])
assert_equal(b56.hash, b57.hash) assert_equal(b56.hash, b57.hash)
self.sync_blocks([b56], success=False, reject_reason='bad-txns-duplicate', reconnect=True) self.send_blocks([b56], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
# b57p2 - a good block with 6 tx'es, don't submit until end # b57p2 - a good block with 6 tx'es, don't submit until end
self.move_tip(55) self.move_tip(55)
@ -753,13 +753,13 @@ class FullBlockTest(BitcoinTestFramework):
assert_equal(b56p2.hash, b57p2.hash) assert_equal(b56p2.hash, b57p2.hash)
assert_equal(len(b56p2.vtx), 6) assert_equal(len(b56p2.vtx), 6)
b56p2 = self.update_block("b56p2", [tx3, tx4]) b56p2 = self.update_block("b56p2", [tx3, tx4])
self.sync_blocks([b56p2], success=False, reject_reason='bad-txns-duplicate', reconnect=True) self.send_blocks([b56p2], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
self.move_tip("57p2") self.move_tip("57p2")
self.sync_blocks([b57p2], True) self.send_blocks([b57p2], True)
self.move_tip(57) self.move_tip(57)
self.sync_blocks([b57], False) # The tip is not updated because 57p2 seen first self.send_blocks([b57], False) # The tip is not updated because 57p2 seen first
self.save_spendable_output() self.save_spendable_output()
# Test a few invalid tx types # Test a few invalid tx types
@ -778,7 +778,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.vout.append(CTxOut(0, b"")) tx.vout.append(CTxOut(0, b""))
tx.calc_sha256() tx.calc_sha256()
b58 = self.update_block(58, [tx]) b58 = self.update_block(58, [tx])
self.sync_blocks([b58], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b58], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
# tx with output value > input value # tx with output value > input value
self.log.info("Reject a block with a transaction with outputs > inputs") self.log.info("Reject a block with a transaction with outputs > inputs")
@ -786,12 +786,12 @@ class FullBlockTest(BitcoinTestFramework):
b59 = self.next_block(59) b59 = self.next_block(59)
tx = self.create_and_sign_transaction(out[17], 51 * COIN) tx = self.create_and_sign_transaction(out[17], 51 * COIN)
b59 = self.update_block(59, [tx]) b59 = self.update_block(59, [tx])
self.sync_blocks([b59], success=False, reject_reason='bad-txns-in-belowout', reconnect=True) self.send_blocks([b59], success=False, reject_reason='bad-txns-in-belowout', reconnect=True)
# reset to good chain # reset to good chain
self.move_tip(57) self.move_tip(57)
b60 = self.next_block(60, spend=out[17]) b60 = self.next_block(60, spend=out[17])
self.sync_blocks([b60], True) self.send_blocks([b60], True)
self.save_spendable_output() self.save_spendable_output()
# Test BIP30 # Test BIP30
@ -810,7 +810,7 @@ class FullBlockTest(BitcoinTestFramework):
b61.vtx[0].rehash() b61.vtx[0].rehash()
b61 = self.update_block(61, []) b61 = self.update_block(61, [])
assert_equal(b60.vtx[0].serialize(), b61.vtx[0].serialize()) assert_equal(b60.vtx[0].serialize(), b61.vtx[0].serialize())
self.sync_blocks([b61], success=False, reject_reason='bad-txns-BIP30', reconnect=True) self.send_blocks([b61], success=False, reject_reason='bad-txns-BIP30', reconnect=True)
# Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests) # Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests)
# #
@ -827,7 +827,7 @@ class FullBlockTest(BitcoinTestFramework):
assert tx.vin[0].nSequence < 0xffffffff assert tx.vin[0].nSequence < 0xffffffff
tx.calc_sha256() tx.calc_sha256()
b62 = self.update_block(62, [tx]) b62 = self.update_block(62, [tx])
self.sync_blocks([b62], success=False, reject_reason='bad-txns-nonfinal') self.send_blocks([b62], success=False, reject_reason='bad-txns-nonfinal')
# Test a non-final coinbase is also rejected # Test a non-final coinbase is also rejected
# #
@ -841,7 +841,7 @@ class FullBlockTest(BitcoinTestFramework):
b63.vtx[0].vin[0].nSequence = 0xDEADBEEF b63.vtx[0].vin[0].nSequence = 0xDEADBEEF
b63.vtx[0].rehash() b63.vtx[0].rehash()
b63 = self.update_block(63, []) b63 = self.update_block(63, [])
self.sync_blocks([b63], success=False, reject_reason='bad-txns-nonfinal') self.send_blocks([b63], success=False, reject_reason='bad-txns-nonfinal')
# This checks that a block with a bloated VARINT between the block_header and the array of tx such that # This checks that a block with a bloated VARINT between the block_header and the array of tx such that
# the block is > MAX_BLOCK_BASE_SIZE with the bloated varint, but <= MAX_BLOCK_BASE_SIZE without the bloated varint, # the block is > MAX_BLOCK_BASE_SIZE with the bloated varint, but <= MAX_BLOCK_BASE_SIZE without the bloated varint,
@ -875,7 +875,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0))) tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0)))
b64a = self.update_block("64a", [tx]) b64a = self.update_block("64a", [tx])
assert_equal(len(b64a.serialize()), MAX_BLOCK_BASE_SIZE + 8) assert_equal(len(b64a.serialize()), MAX_BLOCK_BASE_SIZE + 8)
self.sync_blocks([b64a], success=False, reject_reason='non-canonical ReadCompactSize()') self.send_blocks([b64a], success=False, reject_reason='non-canonical ReadCompactSize()')
# bitcoind doesn't disconnect us for sending a bloated block, but if we subsequently # bitcoind doesn't disconnect us for sending a bloated block, but if we subsequently
# resend the header message, it won't send us the getdata message again. Just # resend the header message, it won't send us the getdata message again. Just
@ -891,7 +891,7 @@ class FullBlockTest(BitcoinTestFramework):
assert_equal(len(b64.serialize()), MAX_BLOCK_BASE_SIZE) assert_equal(len(b64.serialize()), MAX_BLOCK_BASE_SIZE)
self.blocks[64] = b64 self.blocks[64] = b64
b64 = self.update_block(64, []) b64 = self.update_block(64, [])
self.sync_blocks([b64], True) self.send_blocks([b64], True)
self.save_spendable_output() self.save_spendable_output()
# Spend an output created in the block itself # Spend an output created in the block itself
@ -904,7 +904,7 @@ class FullBlockTest(BitcoinTestFramework):
tx1 = self.create_and_sign_transaction(out[19], out[19].vout[0].nValue) tx1 = self.create_and_sign_transaction(out[19], out[19].vout[0].nValue)
tx2 = self.create_and_sign_transaction(tx1, 0) tx2 = self.create_and_sign_transaction(tx1, 0)
b65 = self.update_block(65, [tx1, tx2]) b65 = self.update_block(65, [tx1, tx2])
self.sync_blocks([b65], True) self.send_blocks([b65], True)
self.save_spendable_output() self.save_spendable_output()
# Attempt to spend an output created later in the same block # Attempt to spend an output created later in the same block
@ -917,7 +917,7 @@ class FullBlockTest(BitcoinTestFramework):
tx1 = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue) tx1 = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue)
tx2 = self.create_and_sign_transaction(tx1, 1) tx2 = self.create_and_sign_transaction(tx1, 1)
b66 = self.update_block(66, [tx2, tx1]) b66 = self.update_block(66, [tx2, tx1])
self.sync_blocks([b66], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b66], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
# Attempt to double-spend a transaction created in a block # Attempt to double-spend a transaction created in a block
# #
@ -932,7 +932,7 @@ class FullBlockTest(BitcoinTestFramework):
tx2 = self.create_and_sign_transaction(tx1, 1) tx2 = self.create_and_sign_transaction(tx1, 1)
tx3 = self.create_and_sign_transaction(tx1, 2) tx3 = self.create_and_sign_transaction(tx1, 2)
b67 = self.update_block(67, [tx1, tx2, tx3]) b67 = self.update_block(67, [tx1, tx2, tx3])
self.sync_blocks([b67], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b67], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
# More tests of block subsidy # More tests of block subsidy
# #
@ -951,14 +951,14 @@ class FullBlockTest(BitcoinTestFramework):
b68 = self.next_block(68, additional_coinbase_value=10) b68 = self.next_block(68, additional_coinbase_value=10)
tx = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue - 9) tx = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue - 9)
b68 = self.update_block(68, [tx]) b68 = self.update_block(68, [tx])
self.sync_blocks([b68], success=False, reject_reason='bad-cb-amount', reconnect=True) self.send_blocks([b68], success=False, reject_reason='bad-cb-amount', reconnect=True)
self.log.info("Accept a block claiming the correct subsidy in the coinbase transaction") self.log.info("Accept a block claiming the correct subsidy in the coinbase transaction")
self.move_tip(65) self.move_tip(65)
b69 = self.next_block(69, additional_coinbase_value=10) b69 = self.next_block(69, additional_coinbase_value=10)
tx = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue - 10) tx = self.create_and_sign_transaction(out[20], out[20].vout[0].nValue - 10)
self.update_block(69, [tx]) self.update_block(69, [tx])
self.sync_blocks([b69], True) self.send_blocks([b69], True)
self.save_spendable_output() self.save_spendable_output()
# Test spending the outpoint of a non-existent transaction # Test spending the outpoint of a non-existent transaction
@ -975,7 +975,7 @@ class FullBlockTest(BitcoinTestFramework):
tx.vin.append(CTxIn(COutPoint(bogus_tx.sha256, 0), b"", 0xffffffff)) tx.vin.append(CTxIn(COutPoint(bogus_tx.sha256, 0), b"", 0xffffffff))
tx.vout.append(CTxOut(1, b"")) tx.vout.append(CTxOut(1, b""))
b70 = self.update_block(70, [tx]) b70 = self.update_block(70, [tx])
self.sync_blocks([b70], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b70], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
# Test accepting an invalid block which has the same hash as a valid one (via merkle tree tricks) # Test accepting an invalid block which has the same hash as a valid one (via merkle tree tricks)
# #
@ -1000,10 +1000,10 @@ class FullBlockTest(BitcoinTestFramework):
assert_equal(b72.sha256, b71.sha256) assert_equal(b72.sha256, b71.sha256)
self.move_tip(71) self.move_tip(71)
self.sync_blocks([b71], success=False, reject_reason='bad-txns-duplicate', reconnect=True) self.send_blocks([b71], success=False, reject_reason='bad-txns-duplicate', reconnect=True)
self.move_tip(72) self.move_tip(72)
self.sync_blocks([b72], True) self.send_blocks([b72], True)
self.save_spendable_output() self.save_spendable_output()
# Test some invalid scripts and MAX_BLOCK_SIGOPS # Test some invalid scripts and MAX_BLOCK_SIGOPS
@ -1038,7 +1038,7 @@ class FullBlockTest(BitcoinTestFramework):
tx = self.create_and_sign_transaction(out[22], 1, CScript(a)) tx = self.create_and_sign_transaction(out[22], 1, CScript(a))
b73 = self.update_block(73, [tx]) b73 = self.update_block(73, [tx])
assert_equal(get_legacy_sigopcount_block(b73), MAX_BLOCK_SIGOPS + 1) assert_equal(get_legacy_sigopcount_block(b73), MAX_BLOCK_SIGOPS + 1)
self.sync_blocks([b73], success=False, reject_reason='bad-blk-sigops', reconnect=True) self.send_blocks([b73], success=False, reject_reason='bad-blk-sigops', reconnect=True)
# b74/75 - if we push an invalid script element, all previous sigops are counted, # b74/75 - if we push an invalid script element, all previous sigops are counted,
# but sigops after the element are not counted. # but sigops after the element are not counted.
@ -1062,7 +1062,7 @@ class FullBlockTest(BitcoinTestFramework):
a[MAX_BLOCK_SIGOPS + 4] = 0xff a[MAX_BLOCK_SIGOPS + 4] = 0xff
tx = self.create_and_sign_transaction(out[22], 1, CScript(a)) tx = self.create_and_sign_transaction(out[22], 1, CScript(a))
b74 = self.update_block(74, [tx]) b74 = self.update_block(74, [tx])
self.sync_blocks([b74], success=False, reject_reason='bad-blk-sigops', reconnect=True) self.send_blocks([b74], success=False, reject_reason='bad-blk-sigops', reconnect=True)
self.move_tip(72) self.move_tip(72)
b75 = self.next_block(75) b75 = self.next_block(75)
@ -1075,7 +1075,7 @@ class FullBlockTest(BitcoinTestFramework):
a[MAX_BLOCK_SIGOPS + 3] = 0xff a[MAX_BLOCK_SIGOPS + 3] = 0xff
tx = self.create_and_sign_transaction(out[22], 1, CScript(a)) tx = self.create_and_sign_transaction(out[22], 1, CScript(a))
b75 = self.update_block(75, [tx]) b75 = self.update_block(75, [tx])
self.sync_blocks([b75], True) self.send_blocks([b75], True)
self.save_spendable_output() self.save_spendable_output()
# Check that if we push an element filled with CHECKSIGs, they are not counted # Check that if we push an element filled with CHECKSIGs, they are not counted
@ -1086,7 +1086,7 @@ class FullBlockTest(BitcoinTestFramework):
a[MAX_BLOCK_SIGOPS - 1] = 0x4e # PUSHDATA4, but leave the following bytes as just checksigs a[MAX_BLOCK_SIGOPS - 1] = 0x4e # PUSHDATA4, but leave the following bytes as just checksigs
tx = self.create_and_sign_transaction(out[23], 1, CScript(a)) tx = self.create_and_sign_transaction(out[23], 1, CScript(a))
b76 = self.update_block(76, [tx]) b76 = self.update_block(76, [tx])
self.sync_blocks([b76], True) self.send_blocks([b76], True)
self.save_spendable_output() self.save_spendable_output()
# Test transaction resurrection # Test transaction resurrection
@ -1111,33 +1111,33 @@ class FullBlockTest(BitcoinTestFramework):
b77 = self.next_block(77) b77 = self.next_block(77)
tx77 = self.create_and_sign_transaction(out[24], 10 * COIN) tx77 = self.create_and_sign_transaction(out[24], 10 * COIN)
b77 = self.update_block(77, [tx77]) b77 = self.update_block(77, [tx77])
self.sync_blocks([b77], True) self.send_blocks([b77], True)
self.save_spendable_output() self.save_spendable_output()
b78 = self.next_block(78) b78 = self.next_block(78)
tx78 = self.create_tx(tx77, 0, 9 * COIN) tx78 = self.create_tx(tx77, 0, 9 * COIN)
b78 = self.update_block(78, [tx78]) b78 = self.update_block(78, [tx78])
self.sync_blocks([b78], True) self.send_blocks([b78], True)
b79 = self.next_block(79) b79 = self.next_block(79)
tx79 = self.create_tx(tx78, 0, 8 * COIN) tx79 = self.create_tx(tx78, 0, 8 * COIN)
b79 = self.update_block(79, [tx79]) b79 = self.update_block(79, [tx79])
self.sync_blocks([b79], True) self.send_blocks([b79], True)
# mempool should be empty # mempool should be empty
assert_equal(len(self.nodes[0].getrawmempool()), 0) assert_equal(len(self.nodes[0].getrawmempool()), 0)
self.move_tip(77) self.move_tip(77)
b80 = self.next_block(80, spend=out[25]) b80 = self.next_block(80, spend=out[25])
self.sync_blocks([b80], False, force_send=True) self.send_blocks([b80], False, force_send=True)
self.save_spendable_output() self.save_spendable_output()
b81 = self.next_block(81, spend=out[26]) b81 = self.next_block(81, spend=out[26])
self.sync_blocks([b81], False, force_send=True) # other chain is same length self.send_blocks([b81], False, force_send=True) # other chain is same length
self.save_spendable_output() self.save_spendable_output()
b82 = self.next_block(82, spend=out[27]) b82 = self.next_block(82, spend=out[27])
self.sync_blocks([b82], True) # now this chain is longer, triggers re-org self.send_blocks([b82], True) # now this chain is longer, triggers re-org
self.save_spendable_output() self.save_spendable_output()
# now check that tx78 and tx79 have been put back into the peer's mempool # now check that tx78 and tx79 have been put back into the peer's mempool
@ -1161,7 +1161,7 @@ class FullBlockTest(BitcoinTestFramework):
tx2.rehash() tx2.rehash()
b83 = self.update_block(83, [tx1, tx2]) b83 = self.update_block(83, [tx1, tx2])
self.sync_blocks([b83], True) self.send_blocks([b83], True)
self.save_spendable_output() self.save_spendable_output()
# Reorg on/off blocks that have OP_RETURN in them (and try to spend them) # Reorg on/off blocks that have OP_RETURN in them (and try to spend them)
@ -1188,30 +1188,30 @@ class FullBlockTest(BitcoinTestFramework):
tx5 = self.create_tx(tx1, 4, 0, CScript([OP_RETURN])) tx5 = self.create_tx(tx1, 4, 0, CScript([OP_RETURN]))
b84 = self.update_block(84, [tx1, tx2, tx3, tx4, tx5]) b84 = self.update_block(84, [tx1, tx2, tx3, tx4, tx5])
self.sync_blocks([b84], True) self.send_blocks([b84], True)
self.save_spendable_output() self.save_spendable_output()
self.move_tip(83) self.move_tip(83)
b85 = self.next_block(85, spend=out[29]) b85 = self.next_block(85, spend=out[29])
self.sync_blocks([b85], False) # other chain is same length self.send_blocks([b85], False) # other chain is same length
b86 = self.next_block(86, spend=out[30]) b86 = self.next_block(86, spend=out[30])
self.sync_blocks([b86], True) self.send_blocks([b86], True)
self.move_tip(84) self.move_tip(84)
b87 = self.next_block(87, spend=out[30]) b87 = self.next_block(87, spend=out[30])
self.sync_blocks([b87], False) # other chain is same length self.send_blocks([b87], False) # other chain is same length
self.save_spendable_output() self.save_spendable_output()
b88 = self.next_block(88, spend=out[31]) b88 = self.next_block(88, spend=out[31])
self.sync_blocks([b88], True) self.send_blocks([b88], True)
self.save_spendable_output() self.save_spendable_output()
# trying to spend the OP_RETURN output is rejected # trying to spend the OP_RETURN output is rejected
b89a = self.next_block("89a", spend=out[32]) b89a = self.next_block("89a", spend=out[32])
tx = self.create_tx(tx1, 0, 0, CScript([OP_TRUE])) tx = self.create_tx(tx1, 0, 0, CScript([OP_TRUE]))
b89a = self.update_block("89a", [tx]) b89a = self.update_block("89a", [tx])
self.sync_blocks([b89a], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True) self.send_blocks([b89a], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
self.log.info("Test a re-org of one week's worth of blocks (1088 blocks)") self.log.info("Test a re-org of one week's worth of blocks (1088 blocks)")
@ -1232,7 +1232,7 @@ class FullBlockTest(BitcoinTestFramework):
self.save_spendable_output() self.save_spendable_output()
spend = self.get_spendable_output() spend = self.get_spendable_output()
self.sync_blocks(blocks, True, timeout=480) self.send_blocks(blocks, True, timeout=480)
chain1_tip = i chain1_tip = i
# now create alt chain of same length # now create alt chain of same length
@ -1240,22 +1240,22 @@ class FullBlockTest(BitcoinTestFramework):
blocks2 = [] blocks2 = []
for i in range(89, LARGE_REORG_SIZE + 89): for i in range(89, LARGE_REORG_SIZE + 89):
blocks2.append(self.next_block("alt" + str(i), version=4)) blocks2.append(self.next_block("alt" + str(i), version=4))
self.sync_blocks(blocks2, False, force_send=True) self.send_blocks(blocks2, False, force_send=True)
# extend alt chain to trigger re-org # extend alt chain to trigger re-org
block = self.next_block("alt" + str(chain1_tip + 1), version=4) block = self.next_block("alt" + str(chain1_tip + 1), version=4)
self.sync_blocks([block], True, timeout=480) self.send_blocks([block], True, timeout=480)
# ... and re-org back to the first chain # ... and re-org back to the first chain
self.move_tip(chain1_tip) self.move_tip(chain1_tip)
block = self.next_block(chain1_tip + 1, version=4) block = self.next_block(chain1_tip + 1, version=4)
self.sync_blocks([block], False, force_send=True) self.send_blocks([block], False, force_send=True)
block = self.next_block(chain1_tip + 2, version=4) block = self.next_block(chain1_tip + 2, version=4)
self.sync_blocks([block], True, timeout=480) self.send_blocks([block], True, timeout=480)
self.log.info("Reject a block with an invalid block header version") self.log.info("Reject a block with an invalid block header version")
b_v1 = self.next_block('b_v1', version=1) b_v1 = self.next_block('b_v1', version=1)
self.sync_blocks([b_v1], success=False, force_send=True, reject_reason='bad-version(0x00000001)') self.send_blocks([b_v1], success=False, force_send=True, reject_reason='bad-version(0x00000001)')
self.move_tip(chain1_tip + 2) self.move_tip(chain1_tip + 2)
b_cb34 = self.next_block('b_cb34', version=4) b_cb34 = self.next_block('b_cb34', version=4)
@ -1263,7 +1263,7 @@ class FullBlockTest(BitcoinTestFramework):
b_cb34.vtx[0].rehash() b_cb34.vtx[0].rehash()
b_cb34.hashMerkleRoot = b_cb34.calc_merkle_root() b_cb34.hashMerkleRoot = b_cb34.calc_merkle_root()
b_cb34.solve() b_cb34.solve()
self.sync_blocks([b_cb34], success=False, reject_reason='bad-cb-height', reconnect=True) self.send_blocks([b_cb34], success=False, reject_reason='bad-cb-height', reconnect=True)
# Helper methods # Helper methods
################ ################
@ -1372,7 +1372,7 @@ class FullBlockTest(BitcoinTestFramework):
self.nodes[0].disconnect_p2ps() self.nodes[0].disconnect_p2ps()
self.bootstrap_p2p(timeout=timeout) self.bootstrap_p2p(timeout=timeout)
def sync_blocks(self, blocks, success=True, reject_reason=None, force_send=False, reconnect=False, timeout=60): def send_blocks(self, blocks, success=True, reject_reason=None, force_send=False, reconnect=False, timeout=60):
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. """Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block.
Call with success = False if the tip shouldn't advance to the most recent block.""" Call with success = False if the tip shouldn't advance to the most recent block."""

View file

@ -168,7 +168,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
block.solve() block.solve()
return block return block
def sync_blocks(self, blocks, success=True): def send_blocks(self, blocks, success=True):
"""Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. """Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block.
Call with success = False if the tip shouldn't advance to the most recent block.""" Call with success = False if the tip shouldn't advance to the most recent block."""
@ -190,7 +190,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
self.log.info("Test that the csv softfork is DEFINED") self.log.info("Test that the csv softfork is DEFINED")
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'defined') assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'defined')
test_blocks = self.generate_blocks(61, 4) test_blocks = self.generate_blocks(61, 4)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
self.log.info("Advance from DEFINED to STARTED, height = 143") self.log.info("Advance from DEFINED to STARTED, height = 143")
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'started') assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'started')
@ -202,7 +202,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
test_blocks = self.generate_blocks(20, 4, test_blocks) # 0x00000004 (signalling not) test_blocks = self.generate_blocks(20, 4, test_blocks) # 0x00000004 (signalling not)
test_blocks = self.generate_blocks(50, 536871169, test_blocks) # 0x20000101 (signalling ready) test_blocks = self.generate_blocks(50, 536871169, test_blocks) # 0x20000101 (signalling ready)
test_blocks = self.generate_blocks(24, 536936448, test_blocks) # 0x20010000 (signalling not) test_blocks = self.generate_blocks(24, 536936448, test_blocks) # 0x20010000 (signalling not)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
self.log.info("Failed to advance past STARTED, height = 287") self.log.info("Failed to advance past STARTED, height = 287")
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'started') assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'started')
@ -214,14 +214,14 @@ class BIP68_112_113Test(BitcoinTestFramework):
test_blocks = self.generate_blocks(26, 4, test_blocks) # 0x00000004 (signalling not) test_blocks = self.generate_blocks(26, 4, test_blocks) # 0x00000004 (signalling not)
test_blocks = self.generate_blocks(50, 536871169, test_blocks) # 0x20000101 (signalling ready) test_blocks = self.generate_blocks(50, 536871169, test_blocks) # 0x20000101 (signalling ready)
test_blocks = self.generate_blocks(10, 536936448, test_blocks) # 0x20010000 (signalling not) test_blocks = self.generate_blocks(10, 536936448, test_blocks) # 0x20010000 (signalling not)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
self.log.info("Advanced from STARTED to LOCKED_IN, height = 431") self.log.info("Advanced from STARTED to LOCKED_IN, height = 431")
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'locked_in') assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'locked_in')
# Generate 140 more version 4 blocks # Generate 140 more version 4 blocks
test_blocks = self.generate_blocks(140, 4) test_blocks = self.generate_blocks(140, 4)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
# Inputs at height = 572 # Inputs at height = 572
# #
@ -264,7 +264,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
# 2 more version 4 blocks # 2 more version 4 blocks
test_blocks = self.generate_blocks(2, 4) test_blocks = self.generate_blocks(2, 4)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
self.log.info("Not yet advanced to ACTIVE, height = 574 (will activate for block 576, not 575)") self.log.info("Not yet advanced to ACTIVE, height = 574 (will activate for block 576, not 575)")
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'locked_in') assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'locked_in')
@ -318,7 +318,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
# try BIP 112 with seq=9 txs # try BIP 112 with seq=9 txs
success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1)) success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v1))
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1)) success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v1))
self.sync_blocks([self.create_test_block(success_txs)]) self.send_blocks([self.create_test_block(success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
self.log.info("Test version 2 txs") self.log.info("Test version 2 txs")
@ -337,12 +337,12 @@ class BIP68_112_113Test(BitcoinTestFramework):
# try BIP 112 with seq=9 txs # try BIP 112 with seq=9 txs
success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2)) success_txs.extend(all_rlt_txs(bip112txs_vary_nSequence_9_v2))
success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2)) success_txs.extend(all_rlt_txs(bip112txs_vary_OP_CSV_9_v2))
self.sync_blocks([self.create_test_block(success_txs)]) self.send_blocks([self.create_test_block(success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
# 1 more version 4 block to get us to height 575 so the fork should now be active for the next block # 1 more version 4 block to get us to height 575 so the fork should now be active for the next block
test_blocks = self.generate_blocks(1, 4) test_blocks = self.generate_blocks(1, 4)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'active') assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'active')
self.log.info("Post-Soft Fork Tests.") self.log.info("Post-Soft Fork Tests.")
@ -354,74 +354,74 @@ class BIP68_112_113Test(BitcoinTestFramework):
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2)
for bip113tx in [bip113signed1, bip113signed2]: for bip113tx in [bip113signed1, bip113signed2]:
self.sync_blocks([self.create_test_block([bip113tx])], success=False) self.send_blocks([self.create_test_block([bip113tx])], success=False)
# BIP 113 tests should now pass if the locktime is < MTP # BIP 113 tests should now pass if the locktime is < MTP
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1) bip113signed1 = sign_transaction(self.nodes[0], bip113tx_v1)
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2) bip113signed2 = sign_transaction(self.nodes[0], bip113tx_v2)
for bip113tx in [bip113signed1, bip113signed2]: for bip113tx in [bip113signed1, bip113signed2]:
self.sync_blocks([self.create_test_block([bip113tx])]) self.send_blocks([self.create_test_block([bip113tx])])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
# Next block height = 580 after 4 blocks of random version # Next block height = 580 after 4 blocks of random version
test_blocks = self.generate_blocks(4, 1234) test_blocks = self.generate_blocks(4, 1234)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
self.log.info("BIP 68 tests") self.log.info("BIP 68 tests")
self.log.info("Test version 1 txs - all should still pass") self.log.info("Test version 1 txs - all should still pass")
success_txs = [] success_txs = []
success_txs.extend(all_rlt_txs(bip68txs_v1)) success_txs.extend(all_rlt_txs(bip68txs_v1))
self.sync_blocks([self.create_test_block(success_txs)]) self.send_blocks([self.create_test_block(success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
self.log.info("Test version 2 txs") self.log.info("Test version 2 txs")
# All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass # All txs with SEQUENCE_LOCKTIME_DISABLE_FLAG set pass
bip68success_txs = [tx['tx'] for tx in bip68txs_v2 if tx['sdf']] bip68success_txs = [tx['tx'] for tx in bip68txs_v2 if tx['sdf']]
self.sync_blocks([self.create_test_block(bip68success_txs)]) self.send_blocks([self.create_test_block(bip68success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
# All txs without flag fail as we are at delta height = 8 < 10 and delta time = 8 * 600 < 10 * 512 # All txs without flag fail as we are at delta height = 8 < 10 and delta time = 8 * 600 < 10 * 512
bip68timetxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and tx['stf']] bip68timetxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and tx['stf']]
for tx in bip68timetxs: for tx in bip68timetxs:
self.sync_blocks([self.create_test_block([tx])], success=False) self.send_blocks([self.create_test_block([tx])], success=False)
bip68heighttxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and not tx['stf']] bip68heighttxs = [tx['tx'] for tx in bip68txs_v2 if not tx['sdf'] and not tx['stf']]
for tx in bip68heighttxs: for tx in bip68heighttxs:
self.sync_blocks([self.create_test_block([tx])], success=False) self.send_blocks([self.create_test_block([tx])], success=False)
# Advance one block to 581 # Advance one block to 581
test_blocks = self.generate_blocks(1, 1234) test_blocks = self.generate_blocks(1, 1234)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
# Height txs should fail and time txs should now pass 9 * 600 > 10 * 512 # Height txs should fail and time txs should now pass 9 * 600 > 10 * 512
bip68success_txs.extend(bip68timetxs) bip68success_txs.extend(bip68timetxs)
self.sync_blocks([self.create_test_block(bip68success_txs)]) self.send_blocks([self.create_test_block(bip68success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
for tx in bip68heighttxs: for tx in bip68heighttxs:
self.sync_blocks([self.create_test_block([tx])], success=False) self.send_blocks([self.create_test_block([tx])], success=False)
# Advance one block to 582 # Advance one block to 582
test_blocks = self.generate_blocks(1, 1234) test_blocks = self.generate_blocks(1, 1234)
self.sync_blocks(test_blocks) self.send_blocks(test_blocks)
# All BIP 68 txs should pass # All BIP 68 txs should pass
bip68success_txs.extend(bip68heighttxs) bip68success_txs.extend(bip68heighttxs)
self.sync_blocks([self.create_test_block(bip68success_txs)]) self.send_blocks([self.create_test_block(bip68success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
self.log.info("BIP 112 tests") self.log.info("BIP 112 tests")
self.log.info("Test version 1 txs") self.log.info("Test version 1 txs")
# -1 OP_CSV tx should fail # -1 OP_CSV tx should fail
self.sync_blocks([self.create_test_block([bip112tx_special_v1])], success=False) self.send_blocks([self.create_test_block([bip112tx_special_v1])], success=False)
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 1 txs should still pass # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 1 txs should still pass
success_txs = [tx['tx'] for tx in bip112txs_vary_OP_CSV_v1 if tx['sdf']] success_txs = [tx['tx'] for tx in bip112txs_vary_OP_CSV_v1 if tx['sdf']]
success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if tx['sdf']] success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if tx['sdf']]
self.sync_blocks([self.create_test_block(success_txs)]) self.send_blocks([self.create_test_block(success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, version 1 txs should now fail # If SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV, version 1 txs should now fail
@ -430,18 +430,18 @@ class BIP68_112_113Test(BitcoinTestFramework):
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']] fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']]
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']] fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v1 if not tx['sdf']]
for tx in fail_txs: for tx in fail_txs:
self.sync_blocks([self.create_test_block([tx])], success=False) self.send_blocks([self.create_test_block([tx])], success=False)
self.log.info("Test version 2 txs") self.log.info("Test version 2 txs")
# -1 OP_CSV tx should fail # -1 OP_CSV tx should fail
self.sync_blocks([self.create_test_block([bip112tx_special_v2])], success=False) self.send_blocks([self.create_test_block([bip112tx_special_v2])], success=False)
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 2 txs should pass (all sequence locks are met) # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in argument to OP_CSV, version 2 txs should pass (all sequence locks are met)
success_txs = [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if tx['sdf']] success_txs = [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if tx['sdf']]
success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v2 if tx['sdf']] success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v2 if tx['sdf']]
self.sync_blocks([self.create_test_block(success_txs)]) self.send_blocks([self.create_test_block(success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
# SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV for all remaining txs ## # SEQUENCE_LOCKTIME_DISABLE_FLAG is unset in argument to OP_CSV for all remaining txs ##
@ -450,23 +450,23 @@ class BIP68_112_113Test(BitcoinTestFramework):
fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2) fail_txs = all_rlt_txs(bip112txs_vary_nSequence_9_v2)
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']] fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_9_v2 if not tx['sdf']]
for tx in fail_txs: for tx in fail_txs:
self.sync_blocks([self.create_test_block([tx])], success=False) self.send_blocks([self.create_test_block([tx])], success=False)
# If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail # If SEQUENCE_LOCKTIME_DISABLE_FLAG is set in nSequence, tx should fail
fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if tx['sdf']] fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if tx['sdf']]
for tx in fail_txs: for tx in fail_txs:
self.sync_blocks([self.create_test_block([tx])], success=False) self.send_blocks([self.create_test_block([tx])], success=False)
# If sequencelock types mismatch, tx should fail # If sequencelock types mismatch, tx should fail
fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and tx['stf']] fail_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and tx['stf']]
fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']] fail_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]
for tx in fail_txs: for tx in fail_txs:
self.sync_blocks([self.create_test_block([tx])], success=False) self.send_blocks([self.create_test_block([tx])], success=False)
# Remaining txs should pass, just test masking works properly # Remaining txs should pass, just test masking works properly
success_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and not tx['stf']] success_txs = [tx['tx'] for tx in bip112txs_vary_nSequence_v2 if not tx['sdf'] and not tx['stf']]
success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and not tx['stf']] success_txs += [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and not tx['stf']]
self.sync_blocks([self.create_test_block(success_txs)]) self.send_blocks([self.create_test_block(success_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
# Additional test, of checking that comparison of two time types works properly # Additional test, of checking that comparison of two time types works properly
@ -476,7 +476,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
signtx = sign_transaction(self.nodes[0], tx) signtx = sign_transaction(self.nodes[0], tx)
time_txs.append(signtx) time_txs.append(signtx)
self.sync_blocks([self.create_test_block(time_txs)]) self.send_blocks([self.create_test_block(time_txs)])
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
# TODO: Test empty stack fails # TODO: Test empty stack fails

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2014-2018 The Bitcoin Core developers # Copyright (c) 2014-2019 The Bitcoin Core 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 fee estimation code.""" """Test fee estimation code."""
@ -15,8 +15,6 @@ from test_framework.util import (
assert_greater_than_or_equal, assert_greater_than_or_equal,
connect_nodes, connect_nodes,
satoshi_round, satoshi_round,
sync_blocks,
sync_mempools,
) )
# Construct 2 trivial P2SH's and the ScriptSigs that spend them # Construct 2 trivial P2SH's and the ScriptSigs that spend them
@ -162,9 +160,9 @@ class EstimateFeeTest(BitcoinTestFramework):
self.memutxo, Decimal("0.005"), min_fee, min_fee) self.memutxo, Decimal("0.005"), min_fee, min_fee)
tx_kbytes = (len(txhex) // 2) / 1000.0 tx_kbytes = (len(txhex) // 2) / 1000.0
self.fees_per_kb.append(float(fee) / tx_kbytes) self.fees_per_kb.append(float(fee) / tx_kbytes)
sync_mempools(self.nodes[0:3], wait=.1) self.sync_mempools(self.nodes[0:3], wait=.1)
mined = mining_node.getblock(mining_node.generate(1)[0], True)["tx"] mined = mining_node.getblock(mining_node.generate(1)[0], True)["tx"]
sync_blocks(self.nodes[0:3], wait=.1) self.sync_blocks(self.nodes[0:3], wait=.1)
# update which txouts are confirmed # update which txouts are confirmed
newmem = [] newmem = []
for utx in self.memutxo: for utx in self.memutxo:
@ -237,7 +235,7 @@ class EstimateFeeTest(BitcoinTestFramework):
while len(self.nodes[1].getrawmempool()) > 0: while len(self.nodes[1].getrawmempool()) > 0:
self.nodes[1].generate(1) self.nodes[1].generate(1)
sync_blocks(self.nodes[0:3], wait=.1) self.sync_blocks(self.nodes[0:3], wait=.1)
self.log.info("Final estimates after emptying mempools") self.log.info("Final estimates after emptying mempools")
check_estimates(self.nodes[1], self.fees_per_kb) check_estimates(self.nodes[1], self.fees_per_kb)

View file

@ -14,7 +14,14 @@ from test_framework.blocktools import create_coinbase
from test_framework.messages import CBlock, ToHex from test_framework.messages import CBlock, ToHex
from test_framework.script import CScript, OP_RETURN, OP_NOP from test_framework.script import CScript, OP_RETURN, OP_NOP
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, connect_nodes, disconnect_nodes, sync_blocks, wait_until from test_framework.util import (
assert_equal,
assert_greater_than,
assert_raises_rpc_error,
connect_nodes,
disconnect_nodes,
wait_until,
)
MIN_BLOCKS_TO_KEEP = 288 MIN_BLOCKS_TO_KEEP = 288
@ -100,7 +107,7 @@ class PruneTest(BitcoinTestFramework):
connect_nodes(self.nodes[0], 2) connect_nodes(self.nodes[0], 2)
connect_nodes(self.nodes[0], 3) connect_nodes(self.nodes[0], 3)
connect_nodes(self.nodes[0], 4) connect_nodes(self.nodes[0], 4)
sync_blocks(self.nodes[0:5]) self.sync_blocks(self.nodes[0:5])
def setup_nodes(self): def setup_nodes(self):
self.add_nodes(self.num_nodes, self.extra_args) self.add_nodes(self.num_nodes, self.extra_args)
@ -111,13 +118,13 @@ class PruneTest(BitcoinTestFramework):
def create_big_chain(self): def create_big_chain(self):
# Start by creating some coinbases we can spend later # Start by creating some coinbases we can spend later
self.nodes[1].generate(200) self.nodes[1].generate(200)
sync_blocks(self.nodes[0:2]) self.sync_blocks(self.nodes[0:2])
self.nodes[0].generate(150) self.nodes[0].generate(150)
# Then mine enough full blocks to create more than 550MiB of data # Then mine enough full blocks to create more than 550MiB of data
mine_large_blocks(self.nodes[0], 645) mine_large_blocks(self.nodes[0], 645)
sync_blocks(self.nodes[0:5]) self.sync_blocks(self.nodes[0:5])
def test_height_min(self): def test_height_min(self):
assert os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")), "blk00000.dat is missing, pruning too early" assert os.path.isfile(os.path.join(self.prunedir, "blk00000.dat")), "blk00000.dat is missing, pruning too early"
@ -153,7 +160,7 @@ class PruneTest(BitcoinTestFramework):
# Create connections in the order so both nodes can see the reorg at the same time # Create connections in the order so both nodes can see the reorg at the same time
connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 1)
connect_nodes(self.nodes[0], 2) connect_nodes(self.nodes[0], 2)
sync_blocks(self.nodes[0:3]) self.sync_blocks(self.nodes[0:3])
self.log.info("Usage can be over target because of high stale rate: %d" % calc_usage(self.prunedir)) self.log.info("Usage can be over target because of high stale rate: %d" % calc_usage(self.prunedir))
@ -190,7 +197,7 @@ class PruneTest(BitcoinTestFramework):
self.log.info("Reconnect nodes") self.log.info("Reconnect nodes")
connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 1)
connect_nodes(self.nodes[1], 2) connect_nodes(self.nodes[1], 2)
sync_blocks(self.nodes[0:3], timeout=120) self.sync_blocks(self.nodes[0:3], timeout=120)
self.log.info("Verify height on node 2: %d" % self.nodes[2].getblockcount()) self.log.info("Verify height on node 2: %d" % self.nodes[2].getblockcount())
self.log.info("Usage possibly still high because of stale blocks in block files: %d" % calc_usage(self.prunedir)) self.log.info("Usage possibly still high because of stale blocks in block files: %d" % calc_usage(self.prunedir))
@ -345,7 +352,7 @@ class PruneTest(BitcoinTestFramework):
self.log.info("Syncing node 5 to test wallet") self.log.info("Syncing node 5 to test wallet")
connect_nodes(self.nodes[0], 5) connect_nodes(self.nodes[0], 5)
nds = [self.nodes[0], self.nodes[5]] nds = [self.nodes[0], self.nodes[5]]
sync_blocks(nds, wait=5, timeout=300) self.sync_blocks(nds, wait=5, timeout=300)
self.stop_node(5) # stop and start to trigger rescan self.stop_node(5) # stop and start to trigger rescan
self.start_node(5, extra_args=["-prune=550"]) self.start_node(5, extra_args=["-prune=550"])
self.log.info("Success") self.log.info("Success")

View file

@ -18,7 +18,13 @@ from test_framework.blocktools import witness_script, send_to_witness
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, sha256, ToHex from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, sha256, ToHex
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE, OP_DROP from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE, OP_DROP
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, hex_str_to_bytes, sync_blocks, try_rpc from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
connect_nodes,
hex_str_to_bytes,
try_rpc,
)
NODE_0 = 0 NODE_0 = 0
NODE_2 = 2 NODE_2 = 2
@ -76,13 +82,13 @@ class SegWitTest(BitcoinTestFramework):
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script) send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
block = node.generate(1) block = node.generate(1)
assert_equal(len(node.getblock(block[0])["tx"]), 2) assert_equal(len(node.getblock(block[0])["tx"]), 2)
sync_blocks(self.nodes) self.sync_blocks()
def skip_mine(self, node, txid, sign, redeem_script=""): def skip_mine(self, node, txid, sign, redeem_script=""):
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script) send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
block = node.generate(1) block = node.generate(1)
assert_equal(len(node.getblock(block[0])["tx"]), 1) assert_equal(len(node.getblock(block[0])["tx"]), 1)
sync_blocks(self.nodes) self.sync_blocks()
def fail_accept(self, node, error_msg, txid, sign, redeem_script=""): def fail_accept(self, node, error_msg, txid, sign, redeem_script=""):
assert_raises_rpc_error(-26, error_msg, send_to_witness, use_p2wsh=1, node=node, utxo=getutxo(txid), pubkey=self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=sign, insert_redeem_script=redeem_script) assert_raises_rpc_error(-26, error_msg, send_to_witness, use_p2wsh=1, node=node, utxo=getutxo(txid), pubkey=self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=sign, insert_redeem_script=redeem_script)
@ -131,7 +137,7 @@ class SegWitTest(BitcoinTestFramework):
p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], True, Decimal("49.999"))) p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], True, Decimal("49.999")))
self.nodes[0].generate(1) # block 163 self.nodes[0].generate(1) # block 163
sync_blocks(self.nodes) self.sync_blocks()
# Make sure all nodes recognize the transactions as theirs # Make sure all nodes recognize the transactions as theirs
assert_equal(self.nodes[0].getbalance(), balance_presetup - 60 * 50 + 20 * Decimal("49.999") + 50) assert_equal(self.nodes[0].getbalance(), balance_presetup - 60 * 50 + 20 * Decimal("49.999") + 50)
@ -139,7 +145,7 @@ class SegWitTest(BitcoinTestFramework):
assert_equal(self.nodes[2].getbalance(), 20 * Decimal("49.999")) assert_equal(self.nodes[2].getbalance(), 20 * Decimal("49.999"))
self.nodes[0].generate(260) # block 423 self.nodes[0].generate(260) # block 423
sync_blocks(self.nodes) self.sync_blocks()
self.log.info("Verify witness txs are skipped for mining before the fork") self.log.info("Verify witness txs are skipped for mining before the fork")
self.skip_mine(self.nodes[2], wit_ids[NODE_2][WIT_V0][0], True) # block 424 self.skip_mine(self.nodes[2], wit_ids[NODE_2][WIT_V0][0], True) # block 424
@ -156,7 +162,7 @@ class SegWitTest(BitcoinTestFramework):
self.log.info("Verify previous witness txs skipped for mining can now be mined") self.log.info("Verify previous witness txs skipped for mining can now be mined")
assert_equal(len(self.nodes[2].getrawmempool()), 4) assert_equal(len(self.nodes[2].getrawmempool()), 4)
blockhash = self.nodes[2].generate(1)[0] # block 432 (first block with new rules; 432 = 144 * 3) blockhash = self.nodes[2].generate(1)[0] # block 432 (first block with new rules; 432 = 144 * 3)
sync_blocks(self.nodes) self.sync_blocks()
assert_equal(len(self.nodes[2].getrawmempool()), 0) assert_equal(len(self.nodes[2].getrawmempool()), 0)
segwit_tx_list = self.nodes[2].getblock(blockhash)["tx"] segwit_tx_list = self.nodes[2].getblock(blockhash)["tx"]
assert_equal(len(segwit_tx_list), 5) assert_equal(len(segwit_tx_list), 5)
@ -538,7 +544,7 @@ class SegWitTest(BitcoinTestFramework):
signresults = self.nodes[0].signrawtransactionwithwallet(tx.serialize_without_witness().hex())['hex'] signresults = self.nodes[0].signrawtransactionwithwallet(tx.serialize_without_witness().hex())['hex']
txid = self.nodes[0].sendrawtransaction(signresults, 0) txid = self.nodes[0].sendrawtransaction(signresults, 0)
txs_mined[txid] = self.nodes[0].generate(1)[0] txs_mined[txid] = self.nodes[0].generate(1)[0]
sync_blocks(self.nodes) self.sync_blocks()
watchcount = 0 watchcount = 0
spendcount = 0 spendcount = 0
for i in self.nodes[0].listunspent(): for i in self.nodes[0].listunspent():
@ -590,7 +596,7 @@ class SegWitTest(BitcoinTestFramework):
signresults = self.nodes[0].signrawtransactionwithwallet(tx.serialize_without_witness().hex())['hex'] signresults = self.nodes[0].signrawtransactionwithwallet(tx.serialize_without_witness().hex())['hex']
self.nodes[0].sendrawtransaction(signresults, 0) self.nodes[0].sendrawtransaction(signresults, 0)
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -8,7 +8,11 @@ from decimal import Decimal
from test_framework.messages import COIN from test_framework.messages import COIN
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, satoshi_round, sync_blocks, sync_mempools from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
satoshi_round,
)
MAX_ANCESTORS = 25 MAX_ANCESTORS = 25
MAX_DESCENDANTS = 25 MAX_DESCENDANTS = 25
@ -163,7 +167,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
# Check that prioritising a tx before it's added to the mempool works # Check that prioritising a tx before it's added to the mempool works
# First clear the mempool by mining a block. # First clear the mempool by mining a block.
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
assert_equal(len(self.nodes[0].getrawmempool()), 0) assert_equal(len(self.nodes[0].getrawmempool()), 0)
# Prioritise a transaction that has been mined, then add it back to the # Prioritise a transaction that has been mined, then add it back to the
# mempool by using invalidateblock. # mempool by using invalidateblock.
@ -228,7 +232,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
# Test reorg handling # Test reorg handling
# First, the basics: # First, the basics:
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
self.nodes[1].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[1].invalidateblock(self.nodes[0].getbestblockhash())
self.nodes[1].reconsiderblock(self.nodes[0].getbestblockhash()) self.nodes[1].reconsiderblock(self.nodes[0].getbestblockhash())
@ -283,12 +287,12 @@ class MempoolPackagesTest(BitcoinTestFramework):
rawtx = self.nodes[0].createrawtransaction(inputs, outputs) rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
txid = self.nodes[0].sendrawtransaction(signedtx['hex']) txid = self.nodes[0].sendrawtransaction(signedtx['hex'])
sync_mempools(self.nodes) self.sync_mempools()
# Now try to disconnect the tip on each node... # Now try to disconnect the tip on each node...
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash()) self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
sync_blocks(self.nodes) self.sync_blocks()
if __name__ == '__main__': if __name__ == '__main__':
MempoolPackagesTest().main() MempoolPackagesTest().main()

View file

@ -10,7 +10,7 @@ import time
from test_framework.messages import msg_feefilter from test_framework.messages import msg_feefilter
from test_framework.mininode import mininode_lock, P2PInterface from test_framework.mininode import mininode_lock, P2PInterface
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import sync_blocks, sync_mempools
def hashToHex(hash): def hashToHex(hash):
return format(hash, '064x') return format(hash, '064x')
@ -50,7 +50,7 @@ class FeeFilterTest(BitcoinTestFramework):
node0 = self.nodes[0] node0 = self.nodes[0]
# Get out of IBD # Get out of IBD
node1.generate(1) node1.generate(1)
sync_blocks(self.nodes) self.sync_blocks()
self.nodes[0].add_p2p_connection(TestP2PConn()) self.nodes[0].add_p2p_connection(TestP2PConn())
@ -71,7 +71,7 @@ class FeeFilterTest(BitcoinTestFramework):
# Change tx fee rate to 10 sat/byte and test they are no longer received # Change tx fee rate to 10 sat/byte and test they are no longer received
node1.settxfee(Decimal("0.00010000")) node1.settxfee(Decimal("0.00010000"))
[node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)] [node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
sync_mempools(self.nodes) # must be sure node 0 has received all txs self.sync_mempools() # must be sure node 0 has received all txs
# Send one transaction from node0 that should be received, so that we # Send one transaction from node0 that should be received, so that we
# we can sync the test on receipt (if node1's txs were relayed, they'd # we can sync the test on receipt (if node1's txs were relayed, they'd

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2017-2018 The Bitcoin Core developers # Copyright (c) 2017-2019 The Bitcoin Core 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.
"""Tests NODE_NETWORK_LIMITED. """Tests NODE_NETWORK_LIMITED.
@ -11,7 +11,13 @@ and that it responds to getdata requests for blocks correctly:
from test_framework.messages import CInv, msg_getdata, msg_verack, NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS from test_framework.messages import CInv, msg_getdata, msg_verack, NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS
from test_framework.mininode import P2PInterface, mininode_lock from test_framework.mininode import P2PInterface, mininode_lock
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, disconnect_nodes, connect_nodes_bi, sync_blocks, wait_until from test_framework.util import (
assert_equal,
disconnect_nodes,
connect_nodes_bi,
wait_until,
)
class P2PIgnoreInv(P2PInterface): class P2PIgnoreInv(P2PInterface):
firstAddrnServices = 0 firstAddrnServices = 0
@ -60,7 +66,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.") self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
blocks = self.nodes[1].generatetoaddress(292, self.nodes[1].get_deterministic_priv_key().address) blocks = self.nodes[1].generatetoaddress(292, self.nodes[1].get_deterministic_priv_key().address)
sync_blocks([self.nodes[0], self.nodes[1]]) self.sync_blocks([self.nodes[0], self.nodes[1]])
self.log.info("Make sure we can max retrieve block at tip-288.") self.log.info("Make sure we can max retrieve block at tip-288.")
node.send_getdata_for_block(blocks[1]) # last block in valid range node.send_getdata_for_block(blocks[1]) # last block in valid range
@ -86,7 +92,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
# because node 2 is in IBD and node 0 is a NODE_NETWORK_LIMITED peer, sync must not be possible # because node 2 is in IBD and node 0 is a NODE_NETWORK_LIMITED peer, sync must not be possible
connect_nodes_bi(self.nodes, 0, 2) connect_nodes_bi(self.nodes, 0, 2)
try: try:
sync_blocks([self.nodes[0], self.nodes[2]], timeout=5) self.sync_blocks([self.nodes[0], self.nodes[2]], timeout=5)
except: except:
pass pass
# node2 must remain at height 0 # node2 must remain at height 0
@ -96,7 +102,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
connect_nodes_bi(self.nodes, 1, 2) connect_nodes_bi(self.nodes, 1, 2)
# sync must be possible # sync must be possible
sync_blocks(self.nodes) self.sync_blocks()
# disconnect all peers # disconnect all peers
self.disconnect_all() self.disconnect_all()
@ -108,7 +114,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
# sync must be possible, node 1 is no longer in IBD and should therefore connect to node 0 (NODE_NETWORK_LIMITED) # sync must be possible, node 1 is no longer in IBD and should therefore connect to node 0 (NODE_NETWORK_LIMITED)
sync_blocks([self.nodes[0], self.nodes[1]]) self.sync_blocks([self.nodes[0], self.nodes[1]])
if __name__ == '__main__': if __name__ == '__main__':
NodeNetworkLimitedTest().main() NodeNetworkLimitedTest().main()

View file

@ -77,8 +77,6 @@ from test_framework.util import (
disconnect_nodes, disconnect_nodes,
get_bip9_status, get_bip9_status,
hex_str_to_bytes, hex_str_to_bytes,
sync_blocks,
sync_mempools,
) )
# The versionbit bit used to signal activation of SegWit # The versionbit bit used to signal activation of SegWit
@ -283,7 +281,7 @@ class SegWitTest(BitcoinTestFramework):
func(self, *args, **kwargs) func(self, *args, **kwargs)
# Each subtest should leave some utxos for the next subtest # Each subtest should leave some utxos for the next subtest
assert self.utxo assert self.utxo
sync_blocks(self.nodes) self.sync_blocks()
# Assert segwit status is as expected at end of subtest # Assert segwit status is as expected at end of subtest
assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], self.segwit_status) assert_equal(get_bip9_status(self.nodes[0], 'segwit')['status'], self.segwit_status)
@ -644,7 +642,7 @@ class SegWitTest(BitcoinTestFramework):
# Mine it on test_node to create the confirmed output. # Mine it on test_node to create the confirmed output.
test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_tx, with_witness=True, accepted=True) test_transaction_acceptance(self.nodes[0], self.test_node, p2sh_tx, with_witness=True, accepted=True)
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
# Now test standardness of v0 P2WSH outputs. # Now test standardness of v0 P2WSH outputs.
# Start by creating a transaction with two outputs. # Start by creating a transaction with two outputs.
@ -675,7 +673,7 @@ class SegWitTest(BitcoinTestFramework):
tx3 = CTransaction() tx3 = CTransaction()
# tx and tx2 were both accepted. Don't bother trying to reclaim the # tx and tx2 were both accepted. Don't bother trying to reclaim the
# P2PKH output; just send tx's first output back to an anyone-can-spend. # P2PKH output; just send tx's first output back to an anyone-can-spend.
sync_mempools([self.nodes[0], self.nodes[1]]) self.sync_mempools([self.nodes[0], self.nodes[1]])
tx3.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")] tx3.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")]
tx3.vout = [CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))] tx3.vout = [CTxOut(tx.vout[0].nValue - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))]
tx3.wit.vtxinwit.append(CTxInWitness()) tx3.wit.vtxinwit.append(CTxInWitness())
@ -694,7 +692,7 @@ class SegWitTest(BitcoinTestFramework):
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=True) test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=True)
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
self.utxo.pop(0) self.utxo.pop(0)
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue)) self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
assert_equal(len(self.nodes[1].getrawmempool()), 0) assert_equal(len(self.nodes[1].getrawmempool()), 0)
@ -732,7 +730,7 @@ class SegWitTest(BitcoinTestFramework):
block = self.build_next_block() block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx]) self.update_witness_block_with_transactions(block, [tx])
test_witness_block(self.nodes[0], self.test_node, block, accepted=True, with_witness=True) test_witness_block(self.nodes[0], self.test_node, block, accepted=True, with_witness=True)
sync_blocks(self.nodes) self.sync_blocks()
# Now test attempts to spend the output. # Now test attempts to spend the output.
spend_tx = CTransaction() spend_tx = CTransaction()
@ -1377,7 +1375,7 @@ class SegWitTest(BitcoinTestFramework):
for i in range(NUM_SEGWIT_VERSIONS): for i in range(NUM_SEGWIT_VERSIONS):
self.utxo.append(UTXO(tx.sha256, i, split_value)) self.utxo.append(UTXO(tx.sha256, i, split_value))
sync_blocks(self.nodes) self.sync_blocks()
temp_utxo = [] temp_utxo = []
tx = CTransaction() tx = CTransaction()
witness_program = CScript([OP_TRUE]) witness_program = CScript([OP_TRUE])
@ -1395,7 +1393,7 @@ class SegWitTest(BitcoinTestFramework):
temp_utxo.append(UTXO(tx.sha256, 0, tx.vout[0].nValue)) temp_utxo.append(UTXO(tx.sha256, 0, tx.vout[0].nValue))
self.nodes[0].generate(1) # Mine all the transactions self.nodes[0].generate(1) # Mine all the transactions
sync_blocks(self.nodes) self.sync_blocks()
assert len(self.nodes[0].getrawmempool()) == 0 assert len(self.nodes[0].getrawmempool()) == 0
# Finally, verify that version 0 -> version 1 transactions # Finally, verify that version 0 -> version 1 transactions
@ -1432,7 +1430,7 @@ class SegWitTest(BitcoinTestFramework):
block = self.build_next_block() block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx2, tx3]) self.update_witness_block_with_transactions(block, [tx2, tx3])
test_witness_block(self.nodes[0], self.test_node, block, accepted=True) test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
sync_blocks(self.nodes) self.sync_blocks()
# Add utxo to our list # Add utxo to our list
self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue)) self.utxo.append(UTXO(tx3.sha256, 0, tx3.vout[0].nValue))
@ -1460,7 +1458,7 @@ class SegWitTest(BitcoinTestFramework):
# Now test a premature spend. # Now test a premature spend.
self.nodes[0].generate(98) self.nodes[0].generate(98)
sync_blocks(self.nodes) self.sync_blocks()
block2 = self.build_next_block() block2 = self.build_next_block()
self.update_witness_block_with_transactions(block2, [spend_tx]) self.update_witness_block_with_transactions(block2, [spend_tx])
test_witness_block(self.nodes[0], self.test_node, block2, accepted=False) test_witness_block(self.nodes[0], self.test_node, block2, accepted=False)
@ -1470,7 +1468,7 @@ class SegWitTest(BitcoinTestFramework):
block2 = self.build_next_block() block2 = self.build_next_block()
self.update_witness_block_with_transactions(block2, [spend_tx]) self.update_witness_block_with_transactions(block2, [spend_tx])
test_witness_block(self.nodes[0], self.test_node, block2, accepted=True) test_witness_block(self.nodes[0], self.test_node, block2, accepted=True)
sync_blocks(self.nodes) self.sync_blocks()
@subtest @subtest
def test_uncompressed_pubkey(self): def test_uncompressed_pubkey(self):
@ -1600,7 +1598,7 @@ class SegWitTest(BitcoinTestFramework):
block = self.build_next_block() block = self.build_next_block()
self.update_witness_block_with_transactions(block, [tx]) self.update_witness_block_with_transactions(block, [tx])
test_witness_block(self.nodes[0], self.test_node, block, accepted=True) test_witness_block(self.nodes[0], self.test_node, block, accepted=True)
sync_blocks(self.nodes) self.sync_blocks()
self.utxo.pop(0) self.utxo.pop(0)
# Test each hashtype # Test each hashtype
@ -1779,7 +1777,7 @@ class SegWitTest(BitcoinTestFramework):
tx.rehash() tx.rehash()
test_transaction_acceptance(self.nodes[0], self.test_node, tx, False, True) test_transaction_acceptance(self.nodes[0], self.test_node, tx, False, True)
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
# We'll add an unnecessary witness to this transaction that would cause # We'll add an unnecessary witness to this transaction that would cause
# it to be non-standard, to test that violating policy with a witness # it to be non-standard, to test that violating policy with a witness
@ -1808,7 +1806,7 @@ class SegWitTest(BitcoinTestFramework):
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, False, True) test_transaction_acceptance(self.nodes[0], self.test_node, tx3, False, True)
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
# Update our utxo list; we spent the first entry. # Update our utxo list; we spent the first entry.
self.utxo.pop(0) self.utxo.pop(0)
@ -1844,7 +1842,7 @@ class SegWitTest(BitcoinTestFramework):
test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True) test_transaction_acceptance(self.nodes[0], self.test_node, tx, with_witness=False, accepted=True)
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
# Creating transactions for tests # Creating transactions for tests
p2wsh_txs = [] p2wsh_txs = []
@ -1908,7 +1906,7 @@ class SegWitTest(BitcoinTestFramework):
self.nodes[0].generate(1) # Mine and clean up the mempool of non-standard node self.nodes[0].generate(1) # Mine and clean up the mempool of non-standard node
# Valid but non-standard transactions in a block should be accepted by standard node # Valid but non-standard transactions in a block should be accepted by standard node
sync_blocks(self.nodes) self.sync_blocks()
assert_equal(len(self.nodes[0].getrawmempool()), 0) assert_equal(len(self.nodes[0].getrawmempool()), 0)
assert_equal(len(self.nodes[1].getrawmempool()), 0) assert_equal(len(self.nodes[1].getrawmempool()), 0)
@ -1923,7 +1921,7 @@ class SegWitTest(BitcoinTestFramework):
self.start_node(2, extra_args=["-vbparams=segwit:0:999999999999"]) self.start_node(2, extra_args=["-vbparams=segwit:0:999999999999"])
connect_nodes(self.nodes[0], 2) connect_nodes(self.nodes[0], 2)
sync_blocks(self.nodes) self.sync_blocks()
# Make sure that this peer thinks segwit has activated. # Make sure that this peer thinks segwit has activated.
assert get_bip9_status(self.nodes[2], 'segwit')['status'] == "active" assert get_bip9_status(self.nodes[2], 'segwit')['status'] == "active"
@ -2020,7 +2018,7 @@ class SegWitTest(BitcoinTestFramework):
test_witness_block(self.nodes[0], self.test_node, block_4, accepted=True) test_witness_block(self.nodes[0], self.test_node, block_4, accepted=True)
# Reset the tip back down for the next test # Reset the tip back down for the next test
sync_blocks(self.nodes) self.sync_blocks()
for x in self.nodes: for x in self.nodes:
x.invalidateblock(block_4.hash) x.invalidateblock(block_4.hash)

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2014-2018 The Bitcoin Core developers # Copyright (c) 2014-2019 The Bitcoin Core 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 behavior of headers messages to announce blocks. """Test behavior of headers messages to announce blocks.
@ -103,7 +103,6 @@ from test_framework.mininode import (
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
sync_blocks,
wait_until, wait_until,
) )
@ -225,7 +224,7 @@ class SendHeadersTest(BitcoinTestFramework):
# make sure all invalidated blocks are node0's # make sure all invalidated blocks are node0's
self.nodes[0].generatetoaddress(length, self.nodes[0].get_deterministic_priv_key().address) self.nodes[0].generatetoaddress(length, self.nodes[0].get_deterministic_priv_key().address)
sync_blocks(self.nodes, wait=0.1) self.sync_blocks(self.nodes, wait=0.1)
for x in self.nodes[0].p2ps: for x in self.nodes[0].p2ps:
x.wait_for_block_announcement(int(self.nodes[0].getbestblockhash(), 16)) x.wait_for_block_announcement(int(self.nodes[0].getbestblockhash(), 16))
x.clear_block_announcements() x.clear_block_announcements()
@ -234,7 +233,7 @@ class SendHeadersTest(BitcoinTestFramework):
hash_to_invalidate = self.nodes[1].getblockhash(tip_height - (length - 1)) hash_to_invalidate = self.nodes[1].getblockhash(tip_height - (length - 1))
self.nodes[1].invalidateblock(hash_to_invalidate) self.nodes[1].invalidateblock(hash_to_invalidate)
all_hashes = self.nodes[1].generatetoaddress(length + 1, self.nodes[1].get_deterministic_priv_key().address) # Must be longer than the orig chain all_hashes = self.nodes[1].generatetoaddress(length + 1, self.nodes[1].get_deterministic_priv_key().address) # Must be longer than the orig chain
sync_blocks(self.nodes, wait=0.1) self.sync_blocks(self.nodes, wait=0.1)
return [int(x, 16) for x in all_hashes] return [int(x, 16) for x in all_hashes]
def run_test(self): def run_test(self):

View file

@ -57,7 +57,11 @@ from test_framework.blocktools import create_block, create_coinbase, create_tx_w
from test_framework.messages import CBlockHeader, CInv, msg_block, msg_headers, msg_inv from test_framework.messages import CBlockHeader, CInv, msg_block, msg_headers, msg_inv
from test_framework.mininode import mininode_lock, P2PInterface from test_framework.mininode import mininode_lock, P2PInterface
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, sync_blocks from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
connect_nodes,
)
class AcceptBlockTest(BitcoinTestFramework): class AcceptBlockTest(BitcoinTestFramework):
@ -302,7 +306,7 @@ class AcceptBlockTest(BitcoinTestFramework):
# 9. Connect node1 to node0 and ensure it is able to sync # 9. Connect node1 to node0 and ensure it is able to sync
connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 1)
sync_blocks([self.nodes[0], self.nodes[1]]) self.sync_blocks([self.nodes[0], self.nodes[1]])
self.log.info("Successfully synced nodes 1 and 0") self.log.info("Successfully synced nodes 1 and 0")
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2014-2018 The Bitcoin Core developers # Copyright (c) 2014-2019 The Bitcoin Core 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 getchaintips RPC. """Test the getchaintips RPC.
@ -28,7 +28,8 @@ class GetChainTipsTest (BitcoinTestFramework):
self.split_network() self.split_network()
self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address) self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
self.nodes[2].generatetoaddress(20, self.nodes[2].get_deterministic_priv_key().address) self.nodes[2].generatetoaddress(20, self.nodes[2].get_deterministic_priv_key().address)
self.sync_all([self.nodes[:2], self.nodes[2:]]) self.sync_all(self.nodes[:2])
self.sync_all(self.nodes[2:])
tips = self.nodes[1].getchaintips () tips = self.nodes[1].getchaintips ()
assert_equal (len (tips), 1) assert_equal (len (tips), 1)

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2014-2018 The Bitcoin Core developers # Copyright (c) 2014-2019 The Bitcoin Core 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 invalidateblock RPC.""" """Test the invalidateblock RPC."""
@ -9,7 +9,6 @@ from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
connect_nodes_bi, connect_nodes_bi,
sync_blocks,
wait_until, wait_until,
) )
@ -35,7 +34,7 @@ class InvalidateTest(BitcoinTestFramework):
self.log.info("Connect nodes to force a reorg") self.log.info("Connect nodes to force a reorg")
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
sync_blocks(self.nodes[0:2]) self.sync_blocks(self.nodes[0:2])
assert_equal(self.nodes[0].getblockcount(), 6) assert_equal(self.nodes[0].getblockcount(), 6)
badhash = self.nodes[1].getblockhash(2) badhash = self.nodes[1].getblockhash(2)
@ -47,7 +46,7 @@ class InvalidateTest(BitcoinTestFramework):
self.log.info("Make sure we won't reorg to a lower work chain:") self.log.info("Make sure we won't reorg to a lower work chain:")
connect_nodes_bi(self.nodes, 1, 2) connect_nodes_bi(self.nodes, 1, 2)
self.log.info("Sync node 2 to node 1 so both have 6 blocks") self.log.info("Sync node 2 to node 1 so both have 6 blocks")
sync_blocks(self.nodes[1:3]) self.sync_blocks(self.nodes[1:3])
assert_equal(self.nodes[2].getblockcount(), 6) assert_equal(self.nodes[2].getblockcount(), 6)
self.log.info("Invalidate block 5 on node 1 so its tip is now at 4") self.log.info("Invalidate block 5 on node 1 so its tip is now at 4")
self.nodes[1].invalidateblock(self.nodes[1].getblockhash(5)) self.nodes[1].invalidateblock(self.nodes[1].getblockhash(5))

View file

@ -8,7 +8,6 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
connect_nodes_bi, connect_nodes_bi,
sync_blocks,
) )
def unidirectional_node_sync_via_rpc(node_src, node_dest): def unidirectional_node_sync_via_rpc(node_src, node_dest):
@ -72,7 +71,7 @@ class PreciousTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getbestblockhash(), hashC) assert_equal(self.nodes[0].getbestblockhash(), hashC)
self.log.info("Make Node1 prefer block C") self.log.info("Make Node1 prefer block C")
self.nodes[1].preciousblock(hashC) self.nodes[1].preciousblock(hashC)
sync_blocks(self.nodes[0:2]) # wait because node 1 may not have downloaded hashC self.sync_blocks(self.nodes[0:2]) # wait because node 1 may not have downloaded hashC
assert_equal(self.nodes[1].getbestblockhash(), hashC) assert_equal(self.nodes[1].getbestblockhash(), hashC)
self.log.info("Make Node1 prefer block G again") self.log.info("Make Node1 prefer block G again")
self.nodes[1].preciousblock(hashG) self.nodes[1].preciousblock(hashG)
@ -86,7 +85,7 @@ class PreciousTest(BitcoinTestFramework):
self.log.info("Mine another block (E-F-G-)H on Node 0 and reorg Node 1") self.log.info("Mine another block (E-F-G-)H on Node 0 and reorg Node 1")
self.nodes[0].generatetoaddress(1, gen_address(0)) self.nodes[0].generatetoaddress(1, gen_address(0))
assert_equal(self.nodes[0].getblockcount(), 6) assert_equal(self.nodes[0].getblockcount(), 6)
sync_blocks(self.nodes[0:2]) self.sync_blocks(self.nodes[0:2])
hashH = self.nodes[0].getbestblockhash() hashH = self.nodes[0].getbestblockhash()
assert_equal(self.nodes[1].getbestblockhash(), hashH) assert_equal(self.nodes[1].getbestblockhash(), hashH)
self.log.info("Node1 should not be able to prefer block C anymore") self.log.info("Node1 should not be able to prefer block C anymore")

View file

@ -7,7 +7,13 @@
from decimal import Decimal from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes_bi, disconnect_nodes, find_output, sync_blocks from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
connect_nodes_bi,
disconnect_nodes,
find_output,
)
import json import json
import os import os
@ -41,7 +47,7 @@ class PSBTTest(BitcoinTestFramework):
online_node.importaddress(offline_addr, "", False) online_node.importaddress(offline_addr, "", False)
mining_node.sendtoaddress(address=offline_addr, amount=1.0) mining_node.sendtoaddress(address=offline_addr, amount=1.0)
mining_node.generate(nblocks=1) mining_node.generate(nblocks=1)
sync_blocks([mining_node, online_node]) self.sync_blocks([mining_node, online_node])
# Construct an unsigned PSBT on the online node (who doesn't know the output is Segwit, so will include a non-witness UTXO) # Construct an unsigned PSBT on the online node (who doesn't know the output is Segwit, so will include a non-witness UTXO)
utxos = online_node.listunspent(addresses=[offline_addr]) utxos = online_node.listunspent(addresses=[offline_addr])
@ -56,7 +62,7 @@ class PSBTTest(BitcoinTestFramework):
# Make sure we can mine the resulting transaction # Make sure we can mine the resulting transaction
txid = mining_node.sendrawtransaction(mining_node.finalizepsbt(signed_psbt)["hex"]) txid = mining_node.sendrawtransaction(mining_node.finalizepsbt(signed_psbt)["hex"])
mining_node.generate(1) mining_node.generate(1)
sync_blocks([mining_node, online_node]) self.sync_blocks([mining_node, online_node])
assert_equal(online_node.gettxout(txid,0)["confirmations"], 1) assert_equal(online_node.gettxout(txid,0)["confirmations"], 1)
# Reconnect # Reconnect

View file

@ -396,7 +396,8 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
""" """
disconnect_nodes(self.nodes[1], 2) disconnect_nodes(self.nodes[1], 2)
disconnect_nodes(self.nodes[2], 1) disconnect_nodes(self.nodes[2], 1)
self.sync_all([self.nodes[:2], self.nodes[2:]]) self.sync_all(self.nodes[:2])
self.sync_all(self.nodes[2:])
def join_network(self): def join_network(self):
""" """
@ -405,13 +406,15 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
connect_nodes_bi(self.nodes, 1, 2) connect_nodes_bi(self.nodes, 1, 2)
self.sync_all() self.sync_all()
def sync_all(self, node_groups=None): def sync_blocks(self, nodes=None, **kwargs):
if not node_groups: sync_blocks(nodes or self.nodes, **kwargs)
node_groups = [self.nodes]
for group in node_groups: def sync_mempools(self, nodes=None, **kwargs):
sync_blocks(group) sync_mempools(nodes or self.nodes, **kwargs)
sync_mempools(group)
def sync_all(self, nodes=None, **kwargs):
self.sync_blocks(nodes, **kwargs)
self.sync_mempools(nodes, **kwargs)
# Private helper methods. These should not be accessed by the subclass test scripts. # Private helper methods. These should not be accessed by the subclass test scripts.
@ -497,7 +500,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
# see the tip age check in IsInitialBlockDownload(). # see the tip age check in IsInitialBlockDownload().
for i in range(8): for i in range(8):
self.nodes[0].generatetoaddress(25 if i != 7 else 24, self.nodes[i % 4].get_deterministic_priv_key().address) self.nodes[0].generatetoaddress(25 if i != 7 else 24, self.nodes[i % 4].get_deterministic_priv_key().address)
sync_blocks(self.nodes) self.sync_blocks()
for n in self.nodes: for n in self.nodes:
assert_equal(n.getblockchaininfo()["blocks"], 199) assert_equal(n.getblockchaininfo()["blocks"], 199)

View file

@ -18,8 +18,6 @@ from test_framework.util import (
assert_raises_rpc_error, assert_raises_rpc_error,
connect_nodes, connect_nodes,
disconnect_nodes, disconnect_nodes,
sync_blocks,
sync_mempools,
) )
@ -33,12 +31,12 @@ class AbandonConflictTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.nodes[1].generate(100) self.nodes[1].generate(100)
sync_blocks(self.nodes) self.sync_blocks()
balance = self.nodes[0].getbalance() balance = self.nodes[0].getbalance()
txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10"))
txB = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) txB = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10"))
txC = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) txC = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10"))
sync_mempools(self.nodes) self.sync_mempools()
self.nodes[1].generate(1) self.nodes[1].generate(1)
# Can not abandon non-wallet transaction # Can not abandon non-wallet transaction
@ -46,7 +44,7 @@ class AbandonConflictTest(BitcoinTestFramework):
# Can not abandon confirmed transaction # Can not abandon confirmed transaction
assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: self.nodes[0].abandontransaction(txid=txA)) assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: self.nodes[0].abandontransaction(txid=txA))
sync_blocks(self.nodes) self.sync_blocks()
newbalance = self.nodes[0].getbalance() newbalance = self.nodes[0].getbalance()
assert balance - newbalance < Decimal("0.001") #no more than fees lost assert balance - newbalance < Decimal("0.001") #no more than fees lost
balance = newbalance balance = newbalance
@ -163,7 +161,7 @@ class AbandonConflictTest(BitcoinTestFramework):
self.nodes[1].generate(1) self.nodes[1].generate(1)
connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 1)
sync_blocks(self.nodes) self.sync_blocks()
# Verify that B and C's 10 BTC outputs are available for spending again because AB1 is now conflicted # Verify that B and C's 10 BTC outputs are available for spending again because AB1 is now conflicted
newbalance = self.nodes[0].getbalance() newbalance = self.nodes[0].getbalance()

View file

@ -63,8 +63,6 @@ from test_framework.util import (
assert_greater_than, assert_greater_than,
assert_raises_rpc_error, assert_raises_rpc_error,
connect_nodes_bi, connect_nodes_bi,
sync_blocks,
sync_mempools,
) )
@ -220,7 +218,7 @@ class AddressTypeTest(BitcoinTestFramework):
# Mine 101 blocks on node5 to bring nodes out of IBD and make sure that # Mine 101 blocks on node5 to bring nodes out of IBD and make sure that
# no coinbases are maturing for the nodes-under-test during the test # no coinbases are maturing for the nodes-under-test during the test
self.nodes[5].generate(101) self.nodes[5].generate(101)
sync_blocks(self.nodes) self.sync_blocks()
uncompressed_1 = "0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee" uncompressed_1 = "0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee"
uncompressed_2 = "047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77" uncompressed_2 = "047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77"
@ -287,7 +285,7 @@ class AddressTypeTest(BitcoinTestFramework):
self.log.debug("Sending: {}".format(sends)) self.log.debug("Sending: {}".format(sends))
self.nodes[from_node].sendmany("", sends) self.nodes[from_node].sendmany("", sends)
sync_mempools(self.nodes) self.sync_mempools()
unconf_balances = self.get_balances(False) unconf_balances = self.get_balances(False)
self.log.debug("Check unconfirmed balances: {}".format(unconf_balances)) self.log.debug("Check unconfirmed balances: {}".format(unconf_balances))
@ -298,7 +296,7 @@ class AddressTypeTest(BitcoinTestFramework):
# node5 collects fee and block subsidy to keep accounting simple # node5 collects fee and block subsidy to keep accounting simple
self.nodes[5].generate(1) self.nodes[5].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
# Verify that the receiving wallet contains a UTXO with the expected address, and expected descriptor # Verify that the receiving wallet contains a UTXO with the expected address, and expected descriptor
for n, to_node in enumerate(range(from_node, from_node + 4)): for n, to_node in enumerate(range(from_node, from_node + 4)):
@ -328,7 +326,7 @@ class AddressTypeTest(BitcoinTestFramework):
# Fund node 4: # Fund node 4:
self.nodes[5].sendtoaddress(self.nodes[4].getnewaddress(), Decimal("1")) self.nodes[5].sendtoaddress(self.nodes[4].getnewaddress(), Decimal("1"))
self.nodes[5].generate(1) self.nodes[5].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
assert_equal(self.nodes[4].getbalance(), 1) assert_equal(self.nodes[4].getbalance(), 1)
self.log.info("Nodes with addresstype=legacy never use a P2WPKH change output") self.log.info("Nodes with addresstype=legacy never use a P2WPKH change output")

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2014-2018 The Bitcoin Core developers # Copyright (c) 2014-2019 The Bitcoin Core 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 wallet backup features. """Test the wallet backup features.
@ -36,7 +36,12 @@ from random import randint
import shutil import shutil
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, sync_blocks, sync_mempools from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
connect_nodes,
)
class WalletBackupTest(BitcoinTestFramework): class WalletBackupTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
@ -75,9 +80,9 @@ class WalletBackupTest(BitcoinTestFramework):
# Have the miner (node3) mine a block. # Have the miner (node3) mine a block.
# Must sync mempools before mining. # Must sync mempools before mining.
sync_mempools(self.nodes) self.sync_mempools()
self.nodes[3].generate(1) self.nodes[3].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
# As above, this mirrors the original bash test. # As above, this mirrors the original bash test.
def start_three(self): def start_three(self):
@ -102,13 +107,13 @@ class WalletBackupTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.log.info("Generating initial blockchain") self.log.info("Generating initial blockchain")
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
self.nodes[1].generate(1) self.nodes[1].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
self.nodes[2].generate(1) self.nodes[2].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
self.nodes[3].generate(100) self.nodes[3].generate(100)
sync_blocks(self.nodes) self.sync_blocks()
assert_equal(self.nodes[0].getbalance(), 50) assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[1].getbalance(), 50) assert_equal(self.nodes[1].getbalance(), 50)
@ -165,7 +170,7 @@ class WalletBackupTest(BitcoinTestFramework):
self.log.info("Re-starting nodes") self.log.info("Re-starting nodes")
self.start_three() self.start_three()
sync_blocks(self.nodes) self.sync_blocks()
assert_equal(self.nodes[0].getbalance(), balance0) assert_equal(self.nodes[0].getbalance(), balance0)
assert_equal(self.nodes[1].getbalance(), balance1) assert_equal(self.nodes[1].getbalance(), balance1)
@ -189,7 +194,7 @@ class WalletBackupTest(BitcoinTestFramework):
self.nodes[1].importwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump')) self.nodes[1].importwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump'))
self.nodes[2].importwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump')) self.nodes[2].importwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump'))
sync_blocks(self.nodes) self.sync_blocks()
assert_equal(self.nodes[0].getbalance(), balance0) assert_equal(self.nodes[0].getbalance(), balance0)
assert_equal(self.nodes[1].getbalance(), balance1) assert_equal(self.nodes[1].getbalance(), balance1)

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2018 The Bitcoin Core developers # Copyright (c) 2018-2019 The Bitcoin Core 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 wallet balance RPC methods.""" """Test the wallet balance RPC methods."""

View file

@ -13,7 +13,6 @@ from test_framework.util import (
assert_fee_amount, assert_fee_amount,
assert_raises_rpc_error, assert_raises_rpc_error,
connect_nodes_bi, connect_nodes_bi,
sync_blocks,
wait_until, wait_until,
) )
@ -33,7 +32,7 @@ class WalletTest(BitcoinTestFramework):
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
connect_nodes_bi(self.nodes, 1, 2) connect_nodes_bi(self.nodes, 1, 2)
connect_nodes_bi(self.nodes, 0, 2) connect_nodes_bi(self.nodes, 0, 2)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size): def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size):
"""Return curr_balance after asserting the fee was in range""" """Return curr_balance after asserting the fee was in range"""
@ -58,9 +57,9 @@ class WalletTest(BitcoinTestFramework):
assert_equal(walletinfo['immature_balance'], 50) assert_equal(walletinfo['immature_balance'], 50)
assert_equal(walletinfo['balance'], 0) assert_equal(walletinfo['balance'], 0)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
self.nodes[1].generate(101) self.nodes[1].generate(101)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
assert_equal(self.nodes[0].getbalance(), 50) assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[1].getbalance(), 50) assert_equal(self.nodes[1].getbalance(), 50)
@ -107,7 +106,7 @@ class WalletTest(BitcoinTestFramework):
# Have node0 mine a block, thus it will collect its own fee. # Have node0 mine a block, thus it will collect its own fee.
self.nodes[0].generate(1) self.nodes[0].generate(1)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
# Exercise locking of unspent outputs # Exercise locking of unspent outputs
unspent_0 = self.nodes[2].listunspent()[0] unspent_0 = self.nodes[2].listunspent()[0]
@ -143,7 +142,7 @@ class WalletTest(BitcoinTestFramework):
# Have node1 generate 100 blocks (so node0 can recover the fee) # Have node1 generate 100 blocks (so node0 can recover the fee)
self.nodes[1].generate(100) self.nodes[1].generate(100)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
# node0 should end up with 100 btc in block rewards plus fees, but # node0 should end up with 100 btc in block rewards plus fees, but
# minus the 21 plus fees sent to node2 # minus the 21 plus fees sent to node2
@ -172,7 +171,7 @@ class WalletTest(BitcoinTestFramework):
# Have node1 mine a block to confirm transactions: # Have node1 mine a block to confirm transactions:
self.nodes[1].generate(1) self.nodes[1].generate(1)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
assert_equal(self.nodes[0].getbalance(), 0) assert_equal(self.nodes[0].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 94) assert_equal(self.nodes[2].getbalance(), 94)
@ -187,14 +186,14 @@ class WalletTest(BitcoinTestFramework):
self.nodes[2].settxfee(fee_per_byte * 1000) self.nodes[2].settxfee(fee_per_byte * 1000)
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False) txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
self.nodes[2].generate(1) self.nodes[2].generate(1)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(self.nodes[0].getbalance(), Decimal('10')) assert_equal(self.nodes[0].getbalance(), Decimal('10'))
# Send 10 BTC with subtract fee from amount # Send 10 BTC with subtract fee from amount
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True) txid = self.nodes[2].sendtoaddress(address, 10, "", "", True)
self.nodes[2].generate(1) self.nodes[2].generate(1)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
node_2_bal -= Decimal('10') node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal) assert_equal(self.nodes[2].getbalance(), node_2_bal)
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
@ -202,7 +201,7 @@ class WalletTest(BitcoinTestFramework):
# Sendmany 10 BTC # Sendmany 10 BTC
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", []) txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [])
self.nodes[2].generate(1) self.nodes[2].generate(1)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
node_0_bal += Decimal('10') node_0_bal += Decimal('10')
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
assert_equal(self.nodes[0].getbalance(), node_0_bal) assert_equal(self.nodes[0].getbalance(), node_0_bal)
@ -210,7 +209,7 @@ class WalletTest(BitcoinTestFramework):
# Sendmany 10 BTC with subtract fee from amount # Sendmany 10 BTC with subtract fee from amount
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address]) txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address])
self.nodes[2].generate(1) self.nodes[2].generate(1)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
node_2_bal -= Decimal('10') node_2_bal -= Decimal('10')
assert_equal(self.nodes[2].getbalance(), node_2_bal) assert_equal(self.nodes[2].getbalance(), node_2_bal)
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])) node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
@ -254,18 +253,18 @@ class WalletTest(BitcoinTestFramework):
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
connect_nodes_bi(self.nodes, 1, 2) connect_nodes_bi(self.nodes, 1, 2)
connect_nodes_bi(self.nodes, 0, 2) connect_nodes_bi(self.nodes, 0, 2)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
txid_not_broadcast = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2) txid_not_broadcast = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast) tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast)
self.nodes[1].generate(1) # mine a block, tx should not be in there self.nodes[1].generate(1) # mine a block, tx should not be in there
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
assert_equal(self.nodes[2].getbalance(), node_2_bal) # should not be changed because tx was not broadcasted assert_equal(self.nodes[2].getbalance(), node_2_bal) # should not be changed because tx was not broadcasted
# now broadcast from another node, mine a block, sync, and check the balance # now broadcast from another node, mine a block, sync, and check the balance
self.nodes[1].sendrawtransaction(tx_obj_not_broadcast['hex']) self.nodes[1].sendrawtransaction(tx_obj_not_broadcast['hex'])
self.nodes[1].generate(1) self.nodes[1].generate(1)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
node_2_bal += 2 node_2_bal += 2
tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast) tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast)
assert_equal(self.nodes[2].getbalance(), node_2_bal) assert_equal(self.nodes[2].getbalance(), node_2_bal)
@ -281,10 +280,10 @@ class WalletTest(BitcoinTestFramework):
connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 0, 1)
connect_nodes_bi(self.nodes, 1, 2) connect_nodes_bi(self.nodes, 1, 2)
connect_nodes_bi(self.nodes, 0, 2) connect_nodes_bi(self.nodes, 0, 2)
sync_blocks(self.nodes[0:3]) self.sync_blocks(self.nodes[0:3])
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes[0:3]) self.sync_blocks(self.nodes[0:3])
node_2_bal += 2 node_2_bal += 2
# tx should be added to balance because after restarting the nodes tx should be broadcast # tx should be added to balance because after restarting the nodes tx should be broadcast
@ -341,7 +340,7 @@ class WalletTest(BitcoinTestFramework):
address_to_import = self.nodes[2].getnewaddress() address_to_import = self.nodes[2].getnewaddress()
txid = self.nodes[0].sendtoaddress(address_to_import, 1) txid = self.nodes[0].sendtoaddress(address_to_import, 1)
self.nodes[0].generate(1) self.nodes[0].generate(1)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
# 2. Import address from node2 to node1 # 2. Import address from node2 to node1
self.nodes[1].importaddress(address_to_import) self.nodes[1].importaddress(address_to_import)
@ -367,15 +366,15 @@ class WalletTest(BitcoinTestFramework):
coinbase_addr = self.nodes[1].getnewaddress() coinbase_addr = self.nodes[1].getnewaddress()
block_hash = self.nodes[0].generatetoaddress(1, coinbase_addr)[0] block_hash = self.nodes[0].generatetoaddress(1, coinbase_addr)[0]
coinbase_txid = self.nodes[0].getblock(block_hash)['tx'][0] coinbase_txid = self.nodes[0].getblock(block_hash)['tx'][0]
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
# Check that the txid and balance is found by node1 # Check that the txid and balance is found by node1
self.nodes[1].gettransaction(coinbase_txid) self.nodes[1].gettransaction(coinbase_txid)
# check if wallet or blockchain maintenance changes the balance # check if wallet or blockchain maintenance changes the balance
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
blocks = self.nodes[0].generate(2) blocks = self.nodes[0].generate(2)
self.sync_all([self.nodes[0:3]]) self.sync_all(self.nodes[0:3])
balance_nodes = [self.nodes[i].getbalance() for i in range(3)] balance_nodes = [self.nodes[i].getbalance() for i in range(3)]
block_count = self.nodes[0].getblockcount() block_count = self.nodes[0].getblockcount()

View file

@ -19,7 +19,13 @@ import io
from test_framework.blocktools import add_witness_commitment, create_block, create_coinbase, send_to_witness from test_framework.blocktools import add_witness_commitment, create_block, create_coinbase, send_to_witness
from test_framework.messages import BIP125_SEQUENCE_NUMBER, CTransaction from test_framework.messages import BIP125_SEQUENCE_NUMBER, CTransaction
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, connect_nodes_bi, hex_str_to_bytes, sync_mempools from test_framework.util import (
assert_equal,
assert_greater_than,
assert_raises_rpc_error,
connect_nodes_bi,
hex_str_to_bytes,
)
WALLET_PASSPHRASE = "test" WALLET_PASSPHRASE = "test"
WALLET_PASSPHRASE_TIMEOUT = 3600 WALLET_PASSPHRASE_TIMEOUT = 3600
@ -60,7 +66,7 @@ class BumpFeeTest(BitcoinTestFramework):
self.log.info("Running tests") self.log.info("Running tests")
dest_address = peer_node.getnewaddress() dest_address = peer_node.getnewaddress()
test_simple_bumpfee_succeeds(rbf_node, peer_node, dest_address) test_simple_bumpfee_succeeds(self, rbf_node, peer_node, dest_address)
test_segwit_bumpfee_succeeds(rbf_node, dest_address) test_segwit_bumpfee_succeeds(rbf_node, dest_address)
test_nonrbf_bumpfee_fails(peer_node, dest_address) test_nonrbf_bumpfee_fails(peer_node, dest_address)
test_notmine_bumpfee_fails(rbf_node, peer_node, dest_address) test_notmine_bumpfee_fails(rbf_node, peer_node, dest_address)
@ -76,16 +82,16 @@ class BumpFeeTest(BitcoinTestFramework):
self.log.info("Success") self.log.info("Success")
def test_simple_bumpfee_succeeds(rbf_node, peer_node, dest_address): def test_simple_bumpfee_succeeds(self, rbf_node, peer_node, dest_address):
rbfid = spend_one_input(rbf_node, dest_address) rbfid = spend_one_input(rbf_node, dest_address)
rbftx = rbf_node.gettransaction(rbfid) rbftx = rbf_node.gettransaction(rbfid)
sync_mempools((rbf_node, peer_node)) self.sync_mempools((rbf_node, peer_node))
assert rbfid in rbf_node.getrawmempool() and rbfid in peer_node.getrawmempool() assert rbfid in rbf_node.getrawmempool() and rbfid in peer_node.getrawmempool()
bumped_tx = rbf_node.bumpfee(rbfid) bumped_tx = rbf_node.bumpfee(rbfid)
assert_equal(bumped_tx["errors"], []) assert_equal(bumped_tx["errors"], [])
assert bumped_tx["fee"] - abs(rbftx["fee"]) > 0 assert bumped_tx["fee"] - abs(rbftx["fee"]) > 0
# check that bumped_tx propagates, original tx was evicted and has a wallet conflict # check that bumped_tx propagates, original tx was evicted and has a wallet conflict
sync_mempools((rbf_node, peer_node)) self.sync_mempools((rbf_node, peer_node))
assert bumped_tx["txid"] in rbf_node.getrawmempool() assert bumped_tx["txid"] in rbf_node.getrawmempool()
assert bumped_tx["txid"] in peer_node.getrawmempool() assert bumped_tx["txid"] in peer_node.getrawmempool()
assert rbfid not in rbf_node.getrawmempool() assert rbfid not in rbf_node.getrawmempool()

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2014-2018 The Bitcoin Core developers # Copyright (c) 2014-2019 The Bitcoin Core 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 wallet import RPCs. """Test wallet import RPCs.
@ -20,7 +20,12 @@ happened previously.
""" """
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_raises_rpc_error, connect_nodes, sync_blocks, assert_equal, set_node_times) from test_framework.util import (
assert_raises_rpc_error,
connect_nodes,
assert_equal,
set_node_times,
)
import collections import collections
import enum import enum
@ -161,7 +166,7 @@ class ImportRescanTest(BitcoinTestFramework):
timestamp = self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())["time"] timestamp = self.nodes[0].getblockheader(self.nodes[0].getbestblockhash())["time"]
set_node_times(self.nodes, timestamp + TIMESTAMP_WINDOW + 1) set_node_times(self.nodes, timestamp + TIMESTAMP_WINDOW + 1)
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
# For each variation of wallet key import, invoke the import RPC and # For each variation of wallet key import, invoke the import RPC and
# check the results from getbalance and listtransactions. # check the results from getbalance and listtransactions.
@ -187,7 +192,7 @@ class ImportRescanTest(BitcoinTestFramework):
# Generate a block containing the new transactions. # Generate a block containing the new transactions.
self.nodes[0].generate(1) self.nodes[0].generate(1)
assert_equal(self.nodes[0].getrawmempool(), []) assert_equal(self.nodes[0].getrawmempool(), [])
sync_blocks(self.nodes) self.sync_blocks()
# Check the latest results from getbalance and listtransactions. # Check the latest results from getbalance and listtransactions.
for variant in IMPORT_VARIANTS: for variant in IMPORT_VARIANTS:

View file

@ -17,7 +17,6 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
connect_nodes_bi, connect_nodes_bi,
sync_blocks,
) )
@ -67,7 +66,7 @@ class KeypoolRestoreTest(BitcoinTestFramework):
self.nodes[0].generate(1) self.nodes[0].generate(1)
self.nodes[0].sendtoaddress(addr_extpool, 5) self.nodes[0].sendtoaddress(addr_extpool, 5)
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
self.log.info("Restart node with wallet backup") self.log.info("Restart node with wallet backup")
self.stop_node(idx) self.stop_node(idx)

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2014-2018 The Bitcoin Core developers # Copyright (c) 2014-2019 The Bitcoin Core 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 listreceivedbyaddress RPC.""" """Test the listreceivedbyaddress RPC."""
@ -10,7 +10,6 @@ from test_framework.util import (
assert_array_result, assert_array_result,
assert_equal, assert_equal,
assert_raises_rpc_error, assert_raises_rpc_error,
sync_blocks,
) )
@ -24,7 +23,7 @@ class ReceivedByTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
# Generate block to get out of IBD # Generate block to get out of IBD
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes) self.sync_blocks()
# save the number of coinbase reward addresses so far # save the number of coinbase reward addresses so far
num_cb_reward_addresses = len(self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True)) num_cb_reward_addresses = len(self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True))

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2017-2018 The Bitcoin Core developers # Copyright (c) 2017-2019 The Bitcoin Core 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 listsincelast RPC.""" """Test the listsincelast RPC."""
@ -98,7 +98,8 @@ class ListSinceBlockTest (BitcoinTestFramework):
self.nodes[2].generate(7) self.nodes[2].generate(7)
self.log.info('lastblockhash=%s' % (lastblockhash)) self.log.info('lastblockhash=%s' % (lastblockhash))
self.sync_all([self.nodes[:2], self.nodes[2:]]) self.sync_all(self.nodes[:2])
self.sync_all(self.nodes[2:])
self.join_network() self.join_network()

View file

@ -12,7 +12,6 @@ from test_framework.util import (
assert_array_result, assert_array_result,
assert_equal, assert_equal,
hex_str_to_bytes, hex_str_to_bytes,
sync_mempools,
) )
def tx_from_hex(hexstring): def tx_from_hex(hexstring):
@ -127,7 +126,7 @@ class ListTransactionsTest(BitcoinTestFramework):
txid_1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1) txid_1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
assert not is_opt_in(self.nodes[0], txid_1) assert not is_opt_in(self.nodes[0], txid_1)
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_1}, {"bip125-replaceable": "no"}) assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_1}, {"bip125-replaceable": "no"})
sync_mempools(self.nodes) self.sync_mempools()
assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_1}, {"bip125-replaceable": "no"}) assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_1}, {"bip125-replaceable": "no"})
# Tx2 will build off txid_1, still not opting in to RBF. # Tx2 will build off txid_1, still not opting in to RBF.
@ -147,7 +146,7 @@ class ListTransactionsTest(BitcoinTestFramework):
# ...and check the result # ...and check the result
assert not is_opt_in(self.nodes[1], txid_2) assert not is_opt_in(self.nodes[1], txid_2)
assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_2}, {"bip125-replaceable": "no"}) assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_2}, {"bip125-replaceable": "no"})
sync_mempools(self.nodes) self.sync_mempools()
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_2}, {"bip125-replaceable": "no"}) assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_2}, {"bip125-replaceable": "no"})
# Tx3 will opt-in to RBF # Tx3 will opt-in to RBF
@ -163,7 +162,7 @@ class ListTransactionsTest(BitcoinTestFramework):
assert is_opt_in(self.nodes[0], txid_3) assert is_opt_in(self.nodes[0], txid_3)
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_3}, {"bip125-replaceable": "yes"}) assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_3}, {"bip125-replaceable": "yes"})
sync_mempools(self.nodes) self.sync_mempools()
assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_3}, {"bip125-replaceable": "yes"}) assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_3}, {"bip125-replaceable": "yes"})
# Tx4 will chain off tx3. Doesn't signal itself, but depends on one # Tx4 will chain off tx3. Doesn't signal itself, but depends on one
@ -177,7 +176,7 @@ class ListTransactionsTest(BitcoinTestFramework):
assert not is_opt_in(self.nodes[1], txid_4) assert not is_opt_in(self.nodes[1], txid_4)
assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "yes"}) assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "yes"})
sync_mempools(self.nodes) self.sync_mempools()
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "yes"}) assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "yes"})
# Replace tx3, and check that tx4 becomes unknown # Replace tx3, and check that tx4 becomes unknown
@ -189,7 +188,7 @@ class ListTransactionsTest(BitcoinTestFramework):
assert is_opt_in(self.nodes[0], txid_3b) assert is_opt_in(self.nodes[0], txid_3b)
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "unknown"}) assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "unknown"})
sync_mempools(self.nodes) self.sync_mempools()
assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "unknown"}) assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "unknown"})
# Check gettransaction as well: # Check gettransaction as well:

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2017-2018 The Bitcoin Core developers # Copyright (c) 2017-2019 The Bitcoin Core 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 that the wallet resends transactions periodically.""" """Test that the wallet resends transactions periodically."""

View file

@ -10,7 +10,6 @@ from test_framework.util import (
assert_equal, assert_equal,
connect_nodes, connect_nodes,
disconnect_nodes, disconnect_nodes,
sync_blocks,
) )
from test_framework.messages import CTransaction, COIN from test_framework.messages import CTransaction, COIN
@ -87,7 +86,7 @@ class TxnMallTest(BitcoinTestFramework):
# Have node0 mine a block, if requested: # Have node0 mine a block, if requested:
if (self.options.mine_block): if (self.options.mine_block):
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes[0:2]) self.sync_blocks(self.nodes[0:2])
tx1 = self.nodes[0].gettransaction(txid1) tx1 = self.nodes[0].gettransaction(txid1)
tx2 = self.nodes[0].gettransaction(txid2) tx2 = self.nodes[0].gettransaction(txid2)
@ -123,7 +122,7 @@ class TxnMallTest(BitcoinTestFramework):
self.nodes[2].sendrawtransaction(node0_tx2["hex"]) self.nodes[2].sendrawtransaction(node0_tx2["hex"])
self.nodes[2].sendrawtransaction(tx2["hex"]) self.nodes[2].sendrawtransaction(tx2["hex"])
self.nodes[2].generate(1) # Mine another block to make sure we sync self.nodes[2].generate(1) # Mine another block to make sure we sync
sync_blocks(self.nodes) self.sync_blocks()
# Re-fetch transaction info: # Re-fetch transaction info:
tx1 = self.nodes[0].gettransaction(txid1) tx1 = self.nodes[0].gettransaction(txid1)

View file

@ -11,7 +11,6 @@ from test_framework.util import (
connect_nodes, connect_nodes,
disconnect_nodes, disconnect_nodes,
find_output, find_output,
sync_blocks,
) )
class TxnMallTest(BitcoinTestFramework): class TxnMallTest(BitcoinTestFramework):
@ -86,7 +85,7 @@ class TxnMallTest(BitcoinTestFramework):
# Have node0 mine a block: # Have node0 mine a block:
if (self.options.mine_block): if (self.options.mine_block):
self.nodes[0].generate(1) self.nodes[0].generate(1)
sync_blocks(self.nodes[0:2]) self.sync_blocks(self.nodes[0:2])
tx1 = self.nodes[0].gettransaction(txid1) tx1 = self.nodes[0].gettransaction(txid1)
tx2 = self.nodes[0].gettransaction(txid2) tx2 = self.nodes[0].gettransaction(txid2)
@ -119,7 +118,7 @@ class TxnMallTest(BitcoinTestFramework):
# Reconnect the split network, and sync chain: # Reconnect the split network, and sync chain:
connect_nodes(self.nodes[1], 2) connect_nodes(self.nodes[1], 2)
self.nodes[2].generate(1) # Mine another block to make sure we sync self.nodes[2].generate(1) # Mine another block to make sure we sync
sync_blocks(self.nodes) self.sync_blocks()
assert_equal(self.nodes[0].gettransaction(doublespend_txid)["confirmations"], 2) assert_equal(self.nodes[0].gettransaction(doublespend_txid)["confirmations"], 2)
# Re-fetch transaction info: # Re-fetch transaction info: