Skip to content

Commit b3950ff

Browse files
Fuzzbawlsfurszy
authored andcommitted
Tests: update nothingatstake test file
- reintroduce spam transactions - make disk size usage output in kilobytes - add assertion check after stopping node for disk size usage - do fuckall with the node(s) setup (this was in the original script, but likely doesn't change anything from how I had it previously)
1 parent f40f576 commit b3950ff

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

test/functional/stratisx-nothingatstake.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ def create_transaction(prevtx, n, sig, value, nTime, scriptPubKey=CScript()):
9898

9999

100100
def dir_size(path):
101-
size = subprocess.check_output(['du','-sh', path]).split()[0].decode('utf-8')
101+
size = subprocess.check_output(['du','-shk', path]).split()[0].decode('utf-8')
102102
return size
103103

104104

105-
NUM_TRANSACTIONS_IN_BLOCK = 1 #6500
105+
NUM_TRANSACTIONS_IN_BLOCK = 6500
106106

107107

108108
class StratiXDOSTest(BitcoinTestFramework):
109109

110110
def create_main_block(self, hashPrevBlock, block_height):
111111
current_time = int(time.time())
112-
nTime = current_time
112+
nTime = current_time & 0xfffffff0
113113

114114
coinbase = create_coinbase(block_height+1)
115115
coinbase.vout[0].nValue = 0
@@ -129,9 +129,9 @@ def create_main_block(self, hashPrevBlock, block_height):
129129
del self.staking_prevouts[block.prevoutStake]
130130

131131
# create spam for the block. random transactions
132-
#for j in range(NUM_TRANSACTIONS_IN_BLOCK):
133-
# tx = create_transaction(block.vtx[0], 0, b"1729", j, nTime, scriptPubKey=CScript([self.block_sig_key.get_pubkey(), OP_CHECKSIG]))
134-
# block.vtx.append(tx)
132+
for j in range(NUM_TRANSACTIONS_IN_BLOCK):
133+
tx = create_transaction(block.vtx[0], 0, b"1729", j, nTime, scriptPubKey=CScript([self.block_sig_key.get_pubkey(), OP_CHECKSIG]))
134+
block.vtx.append(tx)
135135
block.hashMerkleRoot = block.calc_merkle_root()
136136

137137
block.rehash()
@@ -163,14 +163,12 @@ def sign_single_tx(self, prev_outpoint, nTime):
163163
stake_tx_unsigned = CTransaction()
164164
stake_tx_unsigned.nTime = nTime
165165
stake_tx_unsigned.vin.append(CTxIn(prev_outpoint))
166+
stake_tx_unsigned.vin[0].nSequence = 0xffffffff
166167
stake_tx_unsigned.vout.append(CTxOut())
167168
stake_tx_unsigned.vout.append(CTxOut(int(outNValue*COIN), scriptPubKey))
168169
#stake_tx_unsigned.vout.append(CTxOut(int(outNValue*COIN), scriptPubKey))
169-
print(bytes_to_hex_str(stake_tx_unsigned.serialize()))
170-
print("\n\n")
171170

172171
stake_tx_signed_raw_hex = self.node.signrawtransaction(bytes_to_hex_str(stake_tx_unsigned.serialize()))['hex']
173-
print(stake_tx_signed_raw_hex)
174172
# print(stake_tx_signed_raw_hex)
175173
# f = io.BytesIO(hex_str_to_bytes(stake_tx_signed_raw_hex))
176174
# print(f)
@@ -201,24 +199,31 @@ def set_test_params(self):
201199
def setup_network(self):
202200
# Can't rely on syncing all the nodes when staking=1
203201
self.setup_nodes()
202+
for i in range(self.num_nodes - 1):
203+
for j in range(i+1, self.num_nodes):
204+
connect_nodes_bi(self.nodes, i, j)
204205

205206
def run_test(self):
206207
# Setup the p2p connections and start up the network thread.
207-
self.nodes[0].add_p2p_connection(TestNode())
208+
self.test_nodes = []
209+
for i in range(self.num_nodes):
210+
self.test_nodes.append(TestNode())
211+
self.test_nodes[i].peer_connect('127.0.0.1', p2p_port(i))
212+
#self.nodes[0].add_p2p_connection(TestNode())
208213

209214
network_thread_start() # Start up network handling in another thread
210215

211216
self.node = self.nodes[0]
212217

213218
# Let the test nodes get in sync
214219
for i in range(self.num_nodes):
215-
self.nodes[i].p2p.wait_for_verack()
220+
self.test_nodes[i].wait_for_verack()
216221

217222
FORK_DEPTH = 2 # Depth at which we are creating a fork. We are mining
218223

219224
# 1) Starting mining blocks
220-
self.log.info("Mining 200 blocks..")
221-
self.node.generate(200)
225+
self.log.info("Mining 150 blocks..")
226+
self.node.generate(150)
222227

223228
# 2) Collect the possible prevouts and spend them
224229
self.log.info("Collecting all unspent coins which we generated from mining..")
@@ -229,8 +234,8 @@ def run_test(self):
229234
self.spend_tx()
230235

231236
# 3) Start mining again so that spent prevouts get confirmted in a block.
232-
self.log.info("Mining 150 more blocks to confirm the transactions..")
233-
self.node.generate(150)
237+
self.log.info("Mining 20 more blocks to confirm the transactions..")
238+
self.node.generate(20)
234239

235240
self.log.info("Sleeping 5 sec. Now mining PoS blocks based on already spent transactions..")
236241
time.sleep(5)
@@ -241,7 +246,8 @@ def run_test(self):
241246

242247
pastBlockHash = self.node.getblockhash(block_count - FORK_DEPTH - 1)
243248

244-
self.log.info("Initial size of data dir: %s" % dir_size(self.node.datadir))
249+
init_size = dir_size(self.node.datadir + "/regtest/blocks")
250+
self.log.info("Initial size of data dir: %s kilobytes" % str(init_size))
245251
MAX_BLOCKS = 30
246252
for i in range(0, MAX_BLOCKS):
247253
if i % 5 == 0:
@@ -250,11 +256,14 @@ def run_test(self):
250256
block = self.create_main_block(pastBlockHash, height)
251257
# print(bytes(block.serialize()).hex())
252258
msg = msg_block(block)
253-
self.nodes[0].p2p.send_and_ping(msg)
259+
self.test_nodes[0].send_message(msg)
254260
# In each iteration, send a `block` message with the maximum number of entries
255261
self.log.info("Sent %s blocks out of %s" % (str(i), str(MAX_BLOCKS)))
256-
time.sleep(2)
257-
self.log.info("Final size of data dir: %s" % dir_size(self.node.datadir))
262+
self.stop_node(0)
263+
time.sleep(5)
264+
final_size = dir_size(self.node.datadir + "/regtest/blocks")
265+
self.log.info("Final size of data dir: %s kilobytes" % str(final_size))
266+
assert_equal(final_size, init_size)
258267

259268

260269
if __name__ == '__main__':

0 commit comments

Comments
 (0)