|
14 | 14 | print(sys.argv[1]) |
15 | 15 | print(sys.argv[2]) |
16 | 16 |
|
| 17 | +# Sync mempool, make a block, sync blocks |
| 18 | +def sync_all(sidechain, sidechain2): |
| 19 | + timeout = 20 |
| 20 | + while len(sidechain.getrawmempool()) != len(sidechain2.getrawmempool()): |
| 21 | + time.sleep(1) |
| 22 | + timeout -= 1 |
| 23 | + if timeout == 0: |
| 24 | + raise Exception("Peg-in has failed to propagate.") |
| 25 | + block = sidechain2.generate(1) |
| 26 | + while sidechain.getblockcount() != sidechain2.getblockcount(): |
| 27 | + time.sleep(1) |
| 28 | + timeout -= 1 |
| 29 | + if timeout == 0: |
| 30 | + raise Exception("Blocks are not propagating.") |
| 31 | + return block |
| 32 | + |
17 | 33 | fedpeg_key="cPxqWyf1HDGpGFH1dnfjz8HbiWxvwG8WXyetbuAiw4thKXUdXLpR" |
18 | 34 | fedpeg_pubkey="512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae" |
19 | 35 |
|
|
88 | 104 |
|
89 | 105 | try: |
90 | 106 |
|
91 | | - # Default is 8, meaning 8+2 confirms for mempool acceptance normally |
| 107 | + # Default is 8, meaning 8+2 confirms for wallet acceptance normally |
92 | 108 | # this will require 10+2. |
93 | 109 | sidechain_args = " -peginconfirmationdepth=10 " |
94 | 110 |
|
|
116 | 132 |
|
117 | 133 | addr = bitcoin.getnewaddress() |
118 | 134 |
|
119 | | - # Lockup some funds to unlock later |
120 | | - sidechain.sendtomainchain(addr, 50) |
121 | | - # Tests withdrawlock tracking in database |
122 | | - sidechain.generate(1) |
123 | | - # Tests withdrawlock in mempool |
124 | | - sidechain.sendtomainchain(addr, 50) |
125 | | - |
126 | 135 | addrs = sidechain.getpeginaddress() |
127 | 136 | txid1 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24) |
128 | | - txid2 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24) |
129 | 137 | # 10+2 confirms required to get into mempool and confirm |
130 | 138 | bitcoin.generate(11) |
131 | 139 | time.sleep(2) |
|
137 | 145 | pegtxid = sidechain.claimpegin(raw, proof) |
138 | 146 | raise Exception("Peg-in should not mature enough yet, need another block.") |
139 | 147 | except JSONRPCException as e: |
140 | | - assert("Withdraw proof validation failed" in e.error["message"]) |
| 148 | + assert("Peg-in Bitcoin transaction needs more confirmations to be sent." in e.error["message"]) |
141 | 149 | pass |
142 | 150 |
|
143 | 151 | # Should fail due to non-matching wallet address |
144 | 152 | try: |
145 | 153 | pegtxid = sidechain.claimpegin(raw, proof, sidechain.getnewaddress()) |
146 | | - raise Exception("Peg-in with non-matching address should fail.") |
| 154 | + raise Exception("Peg-in with non-matching claim_script should fail.") |
147 | 155 | except JSONRPCException as e: |
148 | | - assert("Failed to find output in bitcoinTx to the mainchain_address" in e.error["message"]) |
| 156 | + assert("Given claim_script does not match the given Bitcoin transaction." in e.error["message"]) |
149 | 157 | pass |
150 | 158 |
|
151 | 159 | # 12 confirms allows in mempool |
152 | 160 | bitcoin.generate(1) |
153 | | - |
154 | | - timeout = 20 |
155 | | - # Both should succeed via wallet lookup for address match, and when given |
| 161 | + # Should succeed via wallet lookup for address match, and when given |
156 | 162 | pegtxid1 = sidechain.claimpegin(raw, proof) |
157 | 163 |
|
158 | | - proof = bitcoin.gettxoutproof([txid2]) |
159 | | - raw = bitcoin.getrawtransaction(txid2) |
160 | | - pegtxid2 = sidechain.claimpegin(raw, proof, addrs["sidechain_address"]) |
161 | | - |
162 | | - while len(sidechain.getrawmempool()) != len(sidechain2.getrawmempool()): |
163 | | - time.sleep(1) |
164 | | - timeout -= 1 |
165 | | - if timeout == 0: |
166 | | - raise Exception("Peg-in has failed to propagate.") |
167 | | - sidechain2.generate(1) |
168 | | - while sidechain.getblockcount() != sidechain2.getblockcount(): |
169 | | - time.sleep(1) |
170 | | - timeout -= 1 |
171 | | - if timeout == 0: |
172 | | - raise Exception("Blocks are not propagating.") |
173 | | - |
| 164 | + # Will invalidate the block that confirms this transaction later |
| 165 | + blockhash = sync_all(sidechain, sidechain2) |
| 166 | + sidechain.generate(5) |
174 | 167 |
|
175 | 168 | tx1 = sidechain.gettransaction(pegtxid1) |
176 | | - tx2 = sidechain.gettransaction(pegtxid2) |
177 | 169 |
|
178 | | - if "confirmations" in tx1 and tx1["confirmations"] > 0 and "confirmations" in tx2 and tx2["confirmations"] > 0: |
| 170 | + if "confirmations" in tx1 and tx1["confirmations"] == 6: |
179 | 171 | print("Peg-in is confirmed: Success!") |
180 | 172 | else: |
181 | 173 | raise Exception("Peg-in confirmation has failed.") |
182 | 174 |
|
183 | | - # Make a few large locks, then do many claims in mempool |
184 | | - n_locks = 10 |
185 | | - n_claims = 30 |
| 175 | + # Look at pegin fields |
| 176 | + decoded = sidechain.decoderawtransaction(tx1["hex"]) |
| 177 | + assert decoded["vin"][0]["is_pegin"] == True |
| 178 | + assert len(decoded["vin"][0]["pegin_witness"]) > 0 |
| 179 | + |
| 180 | + # Quick reorg checks of pegs |
| 181 | + sidechain.invalidateblock(blockhash[0]) |
| 182 | + if sidechain.gettransaction(pegtxid1)["confirmations"] != 0: |
| 183 | + raise Exception("Peg-in didn't unconfirm after invalidateblock call.") |
| 184 | + # Re-enters block |
| 185 | + sidechain.generate(1) |
| 186 | + if sidechain.gettransaction(pegtxid1)["confirmations"] != 1: |
| 187 | + raise Exception("Peg-in should have one confirm on side block.") |
| 188 | + sidechain.reconsiderblock(blockhash[0]) |
| 189 | + if sidechain.gettransaction(pegtxid1)["confirmations"] != 6: |
| 190 | + raise Exception("Peg-in should be back to 6 confirms.") |
| 191 | + |
| 192 | + # Do many claims in mempool |
| 193 | + n_claims = 100 |
186 | 194 |
|
187 | 195 | print("Flooding mempool with many small claims") |
188 | 196 | pegtxs = [] |
189 | | - for i in range(n_locks): |
190 | | - # Lockup some funds to unlock later |
191 | | - sidechain.sendtomainchain(addr, 50) |
192 | | - sidechain.generate(1) |
193 | 197 | sidechain.generate(101) |
194 | 198 |
|
195 | 199 | for i in range(n_claims): |
|
200 | 204 | raw = bitcoin.getrawtransaction(txid) |
201 | 205 | pegtxs += [sidechain.claimpegin(raw, proof)] |
202 | 206 |
|
203 | | - sidechain.generate(1) |
| 207 | + sync_all(sidechain, sidechain2) |
| 208 | + |
| 209 | + sidechain2.generate(1) |
204 | 210 | for pegtxid in pegtxs: |
205 | 211 | tx = sidechain.gettransaction(pegtxid) |
206 | 212 | if "confirmations" not in tx or tx["confirmations"] == 0: |
207 | 213 | raise Exception("Peg-in confirmation has failed.") |
208 | 214 |
|
209 | 215 | print("Success!") |
210 | 216 |
|
211 | | - # Testing sidechain info RPC |
212 | | - sideinfo = sidechain.getsidechaininfo() |
213 | | - assert sideinfo["fedpegscript"] == fedpeg_pubkey |
214 | | - assert sideinfo["pegged_asset"] == sidechain.dumpassetlabels()["bitcoin"] |
215 | | - assert sideinfo["min_peg_diff"] == "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" |
216 | | - assert sideinfo["parent_blockhash"] == "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206" |
217 | | - |
218 | 217 | except JSONRPCException as e: |
219 | 218 | print("Pegging testing failed, aborting:") |
220 | 219 | print(e.error) |
|
0 commit comments