17 def __init__(self, tx = CTransaction(), n = -1):
22 This reimplements tests from the bitcoinj/FullBlockTestGenerator used 25 We use the testing framework in which we expect a particular answer from 31 ''' Can either run this test as 1 node with expected answers, or two and compare them. 32 Change the "outcome" variable from each TestInstance object to only do the comparison. ''' 45 test.add_all_connections(self.
nodes)
51 [ tx.rehash()
for tx
in tx_list ]
52 block.vtx.extend(tx_list)
53 block.hashMerkleRoot = block.calc_merkle_root()
60 def next_block(self, number, spend=None, additional_coinbase_value=0, script=None):
64 base_block_hash = self.
tip.sha256
68 coinbase.vout[0].nValue += additional_coinbase_value
70 coinbase.vout[0].nValue += spend.tx.vout[spend.n].nValue - 1
75 tx.vin.append(
CTxIn(
COutPoint(spend.tx.sha256, spend.n), b
"", 0xffffffff))
79 tx.vout.append(
CTxOut(0,
CScript([random.randint(0,255), height & 255])))
83 tx.vout.append(
CTxOut(1, script))
86 scriptPubKey = bytearray(spend.tx.vout[spend.n].scriptPubKey)
87 if (scriptPubKey[0] == OP_TRUE):
91 (sighash, err) =
SignatureHash(spend.tx.vout[spend.n].scriptPubKey, tx, 0, SIGHASH_ALL)
93 tx.vin[0].scriptSig = scriptSig
100 assert number
not in self.
blocks 101 self.
blocks[number] = block
107 spendable_outputs = []
110 def save_spendable_output():
111 spendable_outputs.append(self.
tip)
114 def get_spendable_output():
122 def rejected(reject = None):
133 def update_block(block_number, new_transactions):
134 block = self.
blocks[block_number]
135 old_hash = block.sha256
142 self.
blocks[block_number] = block
151 save_spendable_output()
159 test.blocks_and_transactions.append([self.
tip,
True])
160 save_spendable_output()
167 out0 = get_spendable_output()
169 save_spendable_output()
172 out1 = get_spendable_output()
173 b2 = block(2, spend=out1)
184 b3 = block(3, spend=out1)
193 out2 = get_spendable_output()
203 save_spendable_output()
206 out3 = get_spendable_output()
219 out4 = get_spendable_output()
229 block(9, spend=out4, additional_coinbase_value=1)
238 block(10, spend=out3)
241 block(11, spend=out4, additional_coinbase_value=1)
251 b12 = block(12, spend=out3)
252 save_spendable_output()
254 b13 = block(13, spend=out4)
259 save_spendable_output()
260 out5 = get_spendable_output()
263 block(14, spend=out5, additional_coinbase_value=1)
274 lots_of_checksigs =
CScript([OP_CHECKSIG] * (1000000 // 50 - 1))
276 block(15, spend=out5, script=lots_of_checksigs)
281 out6 = get_spendable_output()
282 too_many_checksigs =
CScript([OP_CHECKSIG] * (1000000 // 50))
283 block(16, spend=out6, script=too_many_checksigs)
292 block(17, spend=txout_b3)
293 yield rejected(
RejectResult(16, b
'bad-txns-inputs-missingorspent'))
301 block(18, spend=txout_b3)
304 block(19, spend=out6)
312 out7 = get_spendable_output()
313 block(20, spend=out7)
314 yield rejected(
RejectResult(16, b
'bad-txns-premature-spend-of-coinbase'))
322 block(21, spend=out6)
325 block(22, spend=out5)
334 b23 = block(23, spend=out6)
335 old_hash = b23.sha256
337 script_length = MAX_BLOCK_SIZE - len(b23.serialize()) - 69
338 script_output =
CScript([b
'\x00' * script_length])
339 tx.vout.append(
CTxOut(0, script_output))
341 b23 = update_block(23, [tx])
348 b24 = block(24, spend=out6)
349 script_length = MAX_BLOCK_SIZE - len(b24.serialize()) - 69
350 script_output =
CScript([b
'\x00' * (script_length+1)])
351 tx.vout = [
CTxOut(0, script_output)]
352 b24 = update_block(24, [tx])
356 b25 = block(25, spend=out7)
365 b26 = block(26, spend=out6)
366 b26.vtx[0].vin[0].scriptSig = b
'\x00' 370 b26 = update_block(26, [])
374 b27 = block(27, spend=out7)
379 b28 = block(28, spend=out6)
380 b28.vtx[0].vin[0].scriptSig = b
'\x00' * 101
382 b28 = update_block(28, [])
386 b29 = block(29, spend=out7)
395 b30.vtx[0].vin[0].scriptSig = b
'\x00' * 100
397 b30 = update_block(30, [])
401 if __name__ ==
'__main__':
def add_transactions_to_block(self, block, tx_list)
def __init__(self, tx=CTransaction(), n=-1)
def sync_masternodes(rpc_connections)
def SignatureHash(script, txTo, inIdx, hashtype)
def next_block(self, number, spend=None, additional_coinbase_value=0, script=None)
UniValue getbestblockhash(const UniValue ¶ms, bool fHelp)
def assert_equal(thing1, thing2)