1212For each test, nodes[1] sends 3 blocks.
1313
1414At the beginning nodes[0] mines 50 blocks (201-250) to reach PoS activation.
15- After tests 1-3, before tests 4-6, nodes[0] sends five transactions (included
16- in block 261) to nodes[1].
17- Each tx spends one 250-PIV utxo to send 240.06 PIV (so nodes[1] can later
18- mint 6 zerocoins from it: 100 + 100 + 10 + 10 + 10 + 10 + fee).
19- Then nodes[0] stakes 40 more blocks (261-300) to reach zPoS phase.
2015
2116** Test_1:
2217(Nodes[1] spams a PoS block on main chain.)
4641 - nodes[1] spams fork block with height 252
4742 (using a different coinstake input) --> [ACCEPTED]
4843--> ends at height 260
49-
50- ** Test_4:
51- (Nodes[1] spams a zPoS blocks on main chain.)
52- (Staked zerocoins spent on the same block being staked.)
53- --> starts at height 300
54- - nodes[0] stakes 5 blocks (301-305) and, at each block, nodes[1] mints 6 zerocoins
55- - nodes[0] stakes 35 more blocks (306-340), so the minted zerocoins mature
56- - nodes[1] saves his mature coins 'coins_to_spend' at block 340
57- - nodes[0] stakes 5 blocks (341-345) to be used as buffer for adding the fork chain later
58- - nodes[1] spams 3 blocks with height 346 --> [REJECTED]
59- --> ends at height 345
60-
61- ** Test_5:
62- (Nodes[1] spams a zPoS block on main chain.)
63- (Staked zerocoins spent earlier on main chain.)
64- --> starts at height 345
65- - nodes[1] spends coins_to_spend at block 346
66- - nodes[0] mines 5 more blocks (346-350) to include the spends
67- - nodes[1] spams 3 blocks with height 351 --> [REJECTED]
68- --> ends at height 350
69-
70- ** Test_6:
71- (Nodes[1] spams zPoS blocks on a forked chain.)
72- (Staked zerocoins spent later on main chain.)
73- --> starts at height 350
74- - nodes[1] spams fork block with height 341 --> [ACCEPTED]
75- - nodes[1] spams fork block with height 342
76- (using the same coinstake input as previous block) --> [REJECTED]
77- - nodes[1] spams fork block with height 342
78- (using a different coinstake input) --> [ACCEPTED]
79- --> ends at height 350
8044"""
8145
8246from io import BytesIO
8852from test_framework .util import (
8953 sync_blocks ,
9054 assert_equal ,
91- assert_raises_rpc_error ,
9255 bytes_to_hex_str ,
93- hash256 ,
94- set_node_times ,
95- DecimalAmt
56+ set_node_times
9657)
9758
9859
@@ -113,10 +74,7 @@ def log_title(self):
11374 description = "Tests the 'fake stake' scenarios.\n " \
11475 "1) Stake on main chain with coinstake input spent on the same block\n " \
11576 "2) Stake on main chain with coinstake input spent on a previous block\n " \
116- "3) Stake on a fork chain with coinstake input spent (later) in main chain\n " \
117- "4) zPoS stake on main chain with zpiv coinstake input spent on the same block\n " \
118- "5) zPoS stake on main chain with zpiv coinstake input spent on a previous block\n " \
119- "6) zPoS stake on a fork chain with zpiv coinstake input spent (later) in main chain"
77+ "3) Stake on a fork chain with coinstake input spent (later) in main chain\n "
12078 self .log .info ("\n \n %s\n %s\n %s\n " , title , underline , description )
12179
12280
@@ -142,24 +100,6 @@ def run_test(self):
142100 self .test_2 ()
143101 self .test_3 ()
144102
145- # nodes[0] sends five transactions (included in block 261) to nodes[1].
146- print () # add blank line without log indent
147- self .log .info ("** Fake Stake - Intermission" )
148- self .log .info ("Sending 5 txes from nodes[0] to nodes[1]..." )
149- for i in range (5 ):
150- self .log .info ("%d) %s..." % (i , self .nodes [0 ].sendtoaddress (self .recipient_1 , 240.06 )[:16 ]))
151-
152- # Then nodes[0] stakes 40 more blocks (261-300) to reach zPIV phase
153- self .log .info ("Staking 40 blocks to reach zPoS phase..." )
154- for i in range (40 ):
155- self .mocktime = self .generate_pos (0 , self .mocktime )
156- sync_blocks (self .nodes )
157-
158- # Check Tests 4-6
159- self .test_4 ()
160- self .test_5 ()
161- self .test_6 ()
162-
163103
164104 # ** PoS block - cstake input spent on the same block
165105 def test_1 (self ):
@@ -221,94 +161,15 @@ def test_3(self):
221161 self .fake_stake (list (self .utxos_to_spend ), nHeight = 251 )
222162 self .log .info ("--> Test_3 passed" )
223163
224- # ** zPoS block - cstake zerocoin input spent on the same block
225- def test_4 (self ):
226- print () # add blank line without log indent
227- self .log .info ("** Fake Stake - Test_4" )
228-
229- # nodes[0] stakes 5 blocks (301-305) and, at each block, nodes[1] mints 6 zerocoins
230- self .log .info ("Staking 5 blocks and minting zerocoins..." )
231- for i in range (5 ):
232- self .nodes [1 ].mintzerocoin (240 )
233- self .sync_all ()
234- self .mocktime = self .generate_pos (0 , self .mocktime )
235- sync_blocks (self .nodes )
236-
237- # nodes[0] stakes 35 more blocks (306-340), so the minted zerocoins mature
238- self .log .info ("Staking 35 more blocks to mature the mints..." )
239- for i in range (35 ):
240- self .mocktime = self .generate_pos (0 , self .mocktime )
241- sync_blocks (self .nodes )
242-
243- # nodes[1] saves his mature coins 'coins_to_spend' at block 340
244- assert_equal (self .nodes [1 ].getblockcount (), 340 )
245- self .coins_to_spend = self .nodes [1 ].listmintedzerocoins (True , True )
246- assert_equal (len (self .coins_to_spend ), 24 )
247- self .log .info ("24 mature 'coins_to_spend' collected." )
248-
249- # nodes[0] stakes 5 blocks (341-345) to be used as buffer for adding the fork chain later
250- self .log .info ("Mining 5 blocks as fork depth..." )
251- for i in range (5 ):
252- self .mocktime = self .generate_pos (0 , self .mocktime )
253- sync_blocks (self .nodes )
254-
255- # nodes[1] spams blocks with height 346 --> [REJECTED]
256- assert_equal (self .nodes [1 ].getblockcount (), 345 )
257- self .fake_stake (list (self .coins_to_spend ), isZPoS = True , fDoubleSpend = True )
258- self .log .info ("--> Test_4 passed" )
259-
260- # ** zPoS block - cstake zerocoin input spent in the past
261- def test_5 (self ):
262- print () # add blank line without log indent
263- self .log .info ("** Fake Stake - Test_5" )
264-
265- # nodes[1] spends coins_to_spend at block 346
266- assert_equal (self .nodes [1 ].getblockcount (), 345 )
267- self .log .info ("Spending coins_to_spend from nodes[1] to nodes[0] on block 346..." )
268- txids = []
269- for i in range (4 ):
270- txids .append (self .nodes [1 ].spendzerocoin (240 , False , False , self .recipient_0 , False )['txid' ])
271- self .log .info ("%d) %s..." % (i , txids [- 1 ][:16 ]))
272- self .sync_all ()
273-
274- # nodes[0] mines 5 more blocks (346-350) to include the spends
275- self .log .info ("Mining 5 blocks to include the spends..." )
276- for i in range (5 ):
277- self .mocktime = self .generate_pow (0 , self .mocktime )
278- sync_blocks (self .nodes )
279- for txid in txids :
280- self .check_tx_in_chain (0 , txid )
281-
282- # nodes[1] spams blocks with height 351 --> [REJECTED]
283- assert_equal (self .nodes [1 ].getblockcount (), 350 )
284- self .fake_stake (list (self .coins_to_spend ), isZPoS = True )
285- self .log .info ("--> Test_5 passed" )
286-
287- # ** zPoS block - cstake zerocoin input spent in the future
288- def test_6 (self ):
289- print () # add blank line without log indent
290- self .log .info ("** Fake Stake - Test_6" )
291-
292- # nodes[1] spams fork block with height 341 --> [ACCEPTED]
293- # nodes[1] spams fork block with height 342
294- # (using the same coinstake input as previous block) --> [REJECTED]
295- # nodes[1] spams fork block with height 342
296- # (using a different coinstake input) --> [ACCEPTED]
297- assert_equal (self .nodes [1 ].getblockcount (), 350 )
298- self .fake_stake (list (self .coins_to_spend ), isZPoS = True , nHeight = 341 )
299- self .log .info ("--> Test_6 passed" )
300-
301164
302165 def fake_stake (self ,
303166 staking_utxo_list ,
304167 nHeight = - 1 ,
305- isZPoS = False ,
306168 fDoubleSpend = False ):
307169 """ General method to create, send and test the spam blocks
308170 :param staking_utxo_list: (string list) utxos to use for staking
309171 nHeight: (int, optional) height of the staked block.
310172 Used only for fork chain. In main chain it's current height + 1
311- isZPoS: (bool) stake the block with zerocoin inputs for coinstake
312173 fDoubleSpend: (bool) if true, stake input is double spent in block.vtx
313174 :return:
314175 """
@@ -340,32 +201,29 @@ def fake_stake(self,
340201 nTime += 60
341202 prevBlockHash = bHash
342203
343- stakeInputs = self .get_prevouts (1 , staking_utxo_list , isZPoS , nHeight - 1 )
204+ stakeInputs = self .get_prevouts (1 , staking_utxo_list , False , nHeight - 1 )
344205 # Update stake inputs for second block sent on forked chain (must stake the same input)
345206 if not isMainChain and i == 1 :
346- stakeInputs = self .get_prevouts (1 , [stakedUtxo ], isZPoS , nHeight - 1 )
207+ stakeInputs = self .get_prevouts (1 , [stakedUtxo ], False , nHeight - 1 )
347208
348209 # Make spam txes sending the inputs to DUMMY_KEY in order to test double spends
349210 if fDoubleSpend :
350- spending_prevouts = self .get_prevouts (1 , staking_utxo_list , isZPoS )
211+ spending_prevouts = self .get_prevouts (1 , staking_utxo_list )
351212 block_txes = self .make_txes (1 , spending_prevouts , self .DUMMY_KEY .get_pubkey ())
352213
353214 # Stake the spam block
354215 block = self .stake_block (1 , nHeight , prevBlockHash , stakeInputs ,
355216 nTime , "" , block_txes , fDoubleSpend )
356217 # Log stake input
357- if not isZPoS :
358- prevout = COutPoint ()
359- prevout .deserialize_uniqueness (BytesIO (block .prevoutStake ))
360- self .log .info ("Staked input: [%s...-%s]" % ('{:x}' .format (prevout .hash )[:12 ], prevout .n ))
361- else :
362- self .log .info ("Staked coin with serial hash [%s...]" % block .prevoutStake .hex ()[:16 ])
218+ prevout = COutPoint ()
219+ prevout .deserialize_uniqueness (BytesIO (block .prevoutStake ))
220+ self .log .info ("Staked input: [%s...-%s]" % ('{:x}' .format (prevout .hash )[:12 ], prevout .n ))
363221
364222 # Try submitblock and check result
365223 self .log .info ("Trying to send block [%s...] with height=%d" % (block .hash [:16 ], nHeight ))
366224 var = self .nodes [1 ].submitblock (bytes_to_hex_str (block .serialize ()))
367225 sleep (1 )
368- if (not fMustBeAccepted and var not in [None , "rejected" , "bad-txns-invalid-zpiv" ]):
226+ if (not fMustBeAccepted and var not in [None , "rejected" ]):
369227 raise AssertionError ("Error, block submitted (%s) in %s chain" % (var , chainName ))
370228 elif (fMustBeAccepted and var != "inconclusive" ):
371229 raise AssertionError ("Error, block not submitted (%s) in %s chain" % (var , chainName ))
@@ -376,12 +234,8 @@ def fake_stake(self,
376234 self .checkBlockHash (bHash , fMustBeAccepted )
377235
378236 # Update curr block data
379- if isZPoS :
380- stakedUtxo = [x for x in staking_utxo_list if
381- x ['hash stake' ] == block .prevoutStake [::- 1 ].hex ()][0 ]
382- else :
383- stakedUtxo = [x for x in staking_utxo_list if COutPoint (
384- int (x ['txid' ], 16 ), x ['vout' ]).serialize_uniqueness () == block .prevoutStake ][0 ]
237+ stakedUtxo = [x for x in staking_utxo_list if COutPoint (
238+ int (x ['txid' ], 16 ), x ['vout' ]).serialize_uniqueness () == block .prevoutStake ][0 ]
385239
386240 # Remove the used coinstake input (except before second block on fork chain)
387241 if isMainChain or i != 0 :
0 commit comments