1414print (sys .argv [1 ])
1515print (sys .argv [2 ])
1616
17+ # Sync mempool, make a block, sync blocks
1718def sync_all (sidechain , sidechain2 ):
1819 timeout = 20
1920 while len (sidechain .getrawmempool ()) != len (sidechain2 .getrawmempool ()):
2021 time .sleep (1 )
2122 timeout -= 1
2223 if timeout == 0 :
2324 raise Exception ("Peg-in has failed to propagate." )
24- sidechain2 .generate (1 )
25+ block = sidechain2 .generate (1 )
2526 while sidechain .getblockcount () != sidechain2 .getblockcount ():
2627 time .sleep (1 )
2728 timeout -= 1
2829 if timeout == 0 :
2930 raise Exception ("Blocks are not propagating." )
31+ return block
3032
3133fedpeg_key = "cPxqWyf1HDGpGFH1dnfjz8HbiWxvwG8WXyetbuAiw4thKXUdXLpR"
3234fedpeg_pubkey = "512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"
@@ -156,19 +158,32 @@ def sync_all(sidechain, sidechain2):
156158
157159 # 12 confirms allows in mempool
158160 bitcoin .generate (1 )
159-
160161 # Should succeed via wallet lookup for address match, and when given
161162 pegtxid1 = sidechain .claimpegin (raw , proof )
162163
163- sync_all (sidechain , sidechain2 )
164+ # Will invalidate the block that confirms this transaction later
165+ blockhash = sync_all (sidechain , sidechain2 )
166+ sidechain .generate (5 )
164167
165168 tx1 = sidechain .gettransaction (pegtxid1 )
166169
167- if "confirmations" in tx1 and tx1 ["confirmations" ] > 0 :
170+ if "confirmations" in tx1 and tx1 ["confirmations" ] == 6 :
168171 print ("Peg-in is confirmed: Success!" )
169172 else :
170173 raise Exception ("Peg-in confirmation has failed." )
171174
175+ # Quick reorg checks of pegs
176+ sidechain .invalidateblock (blockhash [0 ])
177+ if sidechain .gettransaction (pegtxid1 )["confirmations" ] != 0 :
178+ raise Exception ("Peg-in didn't unconfirm after invalidateblock call." )
179+ # Re-enters block
180+ sidechain .generate (1 )
181+ if sidechain .gettransaction (pegtxid1 )["confirmations" ] != 1 :
182+ raise Exception ("Peg-in should have one confirm on side block." )
183+ sidechain .reconsiderblock (blockhash [0 ])
184+ if sidechain .gettransaction (pegtxid1 )["confirmations" ] != 6 :
185+ raise Exception ("Peg-in should be back to 6 confirms." )
186+
172187 # Do many claims in mempool
173188 n_claims = 100
174189
@@ -192,8 +207,6 @@ def sync_all(sidechain, sidechain2):
192207 if "confirmations" not in tx or tx ["confirmations" ] == 0 :
193208 raise Exception ("Peg-in confirmation has failed." )
194209
195- # TODO test reorgs, conflicting peg-ins
196-
197210 print ("Success!" )
198211
199212except JSONRPCException as e :
0 commit comments