13 from io
import BytesIO
18 This test is meant to exercise BIP forks 19 Connect to a single node. 20 regtest lock-in with 108/144 block signalling 21 activation after a further 144 blocks 22 mine 2 block and save coinbases for later use 23 mine 141 blocks to transition from DEFINED to STARTED 24 mine 100 blocks signalling readiness and 44 not in order to fail to change state this period 25 mine 108 blocks signalling readiness and 36 blocks not signalling readiness (STARTED->LOCKED_IN) 26 mine a further 143 blocks (LOCKED_IN) 27 test that enforcement has not triggered (which triggers ACTIVE) 28 test that enforcement has triggered 39 extra_args=[[
'-debug',
'-whitelist=127.0.0.1']],
40 binary=[self.options.testbinary])
49 from_txid = node.getblock(coinbase)[
'tx'][0]
50 inputs = [{
"txid" : from_txid,
"vout" : 0}]
51 outputs = { to_address : amount }
52 rawtx = node.createrawtransaction(inputs, outputs)
67 for i
in xrange(number):
69 block.nVersion = version
72 test_blocks.append([block,
True])
74 self.
tip = block.sha256
80 for row
in info[
'bip9_softforks']:
83 raise IndexError (
'key:"%s" not found' % key)
86 def test_BIP(self, bipName, activated_version, invalidate, invalidatePostSignature, bitno):
97 assert(bipName
not in tmpl[
'rules'])
98 assert(bipName
not in tmpl[
'vbavailable'])
109 assert(bipName
not in tmpl[
'rules'])
112 assert(tmpl[
'version'] & activated_version)
125 assert(bipName
not in tmpl[
'rules'])
128 assert(tmpl[
'version'] & activated_version)
141 assert(bipName
not in tmpl[
'rules'])
150 assert(bipName
not in tmpl[
'rules'])
159 invalidatePostSignature(spendtx)
162 block.nVersion = activated_version
163 block.vtx.append(spendtx)
164 block.hashMerkleRoot = block.calc_merkle_root()
169 self.
tip = block.sha256
175 assert(bipName
in tmpl[
'rules'])
176 assert(bipName
not in tmpl[
'vbavailable'])
178 assert(
not (tmpl[
'version'] & (1 << bitno)))
187 invalidatePostSignature(spendtx)
192 block.vtx.append(spendtx)
193 block.hashMerkleRoot = block.calc_merkle_root()
202 shutil.rmtree(self.options.tmpdir)
205 self.
test.clear_all_connections()
206 self.
test.add_all_connections(self.
nodes)
211 for test
in itertools.chain(
222 '''Modify the signature in vin 0 of the tx to fail CSV 223 Prepends -1 CSV DROP in the scriptSig itself. 225 tx.vin[0].scriptSig =
CScript([OP_1NEGATE, OP_CHECKSEQUENCEVERIFY, OP_DROP] +
226 list(
CScript(tx.vin[0].scriptSig)))
229 '''Modify the nSequence to make it fails once sequence lock rule is activated (high timespan) 231 tx.vin[0].nSequence = 0x00FFFFFF
235 '''Modify the nLockTime to make it fails once MTP rule is activated 238 tx.vin[0].nSequence = 0x90FFFFFF
241 if __name__ ==
'__main__':
def test_BIP(self, bipName, activated_version, invalidate, invalidatePostSignature, bitno)
def hex_str_to_bytes(hex_str)
UniValue getblocktemplate(const UniValue ¶ms, bool fHelp)
def mtp_invalidate(self, tx)
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None)
def get_bip9_status(self, key)
UniValue getnewaddress(const UniValue ¶ms, bool fHelp)
def sign_transaction(self, node, tx)
def create_transaction(self, node, coinbase, to_address, amount)
def csv_invalidate(self, tx)
UniValue generate(const UniValue ¶ms, bool fHelp)
UniValue getbestblockhash(const UniValue ¶ms, bool fHelp)
def generate_blocks(self, number, version, test_blocks=[])
def assert_equal(thing1, thing2)
UniValue getblockchaininfo(const UniValue ¶ms, bool fHelp)
def sequence_lock_invalidate(self, tx)
def bytes_to_hex_str(byte_str)