MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / run_test

Method run_test

test/functional/feature_block.py:81–1206  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

79 self.skip_if_no_wallet()
80
81 def run_test(self):
82 node = self.nodes[0] # convenience reference to the node
83
84 self.bootstrap_p2p() # Add one p2p connection to the node
85
86 self.block_heights = {}
87 self.coinbase_key = CECKey()
88 self.coinbase_key.set_secretbytes(b"horsebattery")
89 self.coinbase_pubkey = self.coinbase_key.get_pubkey()
90 self.tip = None
91 self.blocks = {}
92 self.genesis_hash = int(self.nodes[0].getbestblockhash(), 16)
93 self.block_heights[self.genesis_hash] = 0
94 self.spendable_outputs = []
95
96 # Create a new block
97 b0 = self.next_block(0)
98 self.save_spendable_output()
99 self.sync_blocks([b0])
100
101 # Allow the block to mature
102 blocks = []
103 for i in range(99):
104 blocks.append(self.next_block(5000 + i))
105 self.save_spendable_output()
106 self.sync_blocks(blocks)
107
108 # collect spendable outputs now to avoid cluttering the code later on
109 out = []
110 for i in range(33):
111 out.append(self.get_spendable_output())
112
113 # Start by building a couple of blocks on top (which output is spent is
114 # in parentheses):
115 # genesis -> b1 (0) -> b2 (1)
116 b1 = self.next_block(1, spend=out[0])
117 self.save_spendable_output()
118
119 b2 = self.next_block(2, spend=out[1])
120 self.save_spendable_output()
121
122 self.sync_blocks([b1, b2])
123
124 # Fork like this:
125 #
126 # genesis -> b1 (0) -> b2 (1)
127 # \-> b3 (1)
128 #
129 # Nothing should happen at this point. We saw b2 first so it takes priority.
130 self.log.info("Don't reorg to a chain of the same length")
131 self.move_tip(1)
132 b3 = self.next_block(3, spend=out[1])
133 txout_b3 = b3.vtx[1]
134 self.sync_blocks([b3], False)
135
136 # Now we add another block to make the alternative chain longer.
137 #
138 # genesis -> b1 (0) -> b2 (1)

Callers

nothing calls this directly

Calls 15

bootstrap_p2pMethod · 0.95
next_blockMethod · 0.95
save_spendable_outputMethod · 0.95
sync_blocksMethod · 0.95
get_spendable_outputMethod · 0.95
move_tipMethod · 0.95
serializeMethod · 0.95
update_blockMethod · 0.95
rehashMethod · 0.95
create_txMethod · 0.95
sign_txMethod · 0.95

Tested by

no test coverage detected