Debian Codegraph @

monero/tests/functional_tests/multisig.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 # Copyright (c) 2019-2022, The Monero Project
4 #
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without modification, are
8 # permitted provided that the following conditions are met:
9 #
10 # 1. Redistributions of source code must retain the above copyright notice, this list of
11 # conditions and the following disclaimer.
12 #
13 # 2. Redistributions in binary form must reproduce the above copyright notice, this list
14 # of conditions and the following disclaimer in the documentation and/or other
15 # materials provided with the distribution.
16 #
17 # 3. Neither the name of the copyright holder nor the names of its contributors may be
18 # used to endorse or promote products derived from this software without specific
19 # prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
22 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24 # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 from __future__ import print_function
32 import random
33
34 """Test multisig transfers
35 """
36
37 from framework.daemon import Daemon
38 from framework.wallet import Wallet
39
40 TEST_CASES = \
41 [
42 # M N Primary Address
43 [2, 2, '45J58b7PmKJFSiNPFFrTdtfMcFGnruP7V4CMuRpX7NsH4j3jGHKAjo3YJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ3gr7sG'],
44 [2, 3, '44G2TQNfsiURKkvxp7gbgaJY8WynZvANnhmyMAwv6WeEbAvyAWMfKXRhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5duN94i'],
45 [3, 3, '41mro238grj56GnrWkakAKTkBy2yDcXYsUZ2iXCM9pe5Ueajd2RRc6Fhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5ief4ZP'],
46 [3, 4, '44vZSprQKJQRFe6t1VHgU4ESvq2dv7TjBLVGE7QscKxMdFSiyyPCEV64NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6dakeff'],
47 [2, 4, '47puypSwsV1gvUDratmX4y58fSwikXVehEiBhVLxJA1gRCxHyrRgTDr4NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6aRPj5U'],
48 [1, 2, '4A8RnBQixry4VXkqeWhmg8L7vWJVDJj4FN9PV4E7Mgad5ZZ6LKQdn8dYJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ4S8RSB']
49 ]
50
51 PUB_ADDRS = [case[2] for case in TEST_CASES]
52
53 class MultisigTest():
54 def run_test(self):
55 self.reset()
56 for pub_addr in PUB_ADDRS:
57 self.mine(pub_addr, 4)
58 self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80)
59
60 self.test_states()
61
62 self.fund_addrs_with_normal_wallet(PUB_ADDRS)
63
64 for M, N, pub_addr in TEST_CASES:
65 assert M <= N
66 shuffled_participants = list(range(N))
67 random.shuffle(shuffled_participants)
68 shuffled_signers = shuffled_participants[:M]
69
70 expected_outputs = 5 # each wallet owns four mined outputs & one transferred output
71
72 # Create multisig wallet and test transferring
73 self.create_multisig_wallets(M, N, pub_addr)
74 self.import_multisig_info(shuffled_signers if M != 1 else shuffled_participants, expected_outputs)
75 txid = self.transfer(shuffled_signers)
76 expected_outputs += 1
77 self.import_multisig_info(shuffled_participants, expected_outputs)
78 self.check_transaction(txid)
79
80 # If more than 1 signer, try to freeze key image of one signer, make tx using that key
81 # image on another signer, then have first signer sign multisg_txset. Should fail
82 if M != 1:
83 txid = self.try_transfer_frozen(shuffled_signers)
84 expected_outputs += 1
85 self.import_multisig_info(shuffled_participants, expected_outputs)
86 self.check_transaction(txid)
87
88 # Recreate wallet from multisig seed and test transferring
89 self.remake_some_multisig_wallets_by_multsig_seed(M)
90 self.import_multisig_info(shuffled_signers if M != 1 else shuffled_participants, expected_outputs)
91 txid = self.transfer(shuffled_signers)
92 expected_outputs += 1
93 self.import_multisig_info(shuffled_participants, expected_outputs)
94 self.check_transaction(txid)
95
96 def reset(self):
97 print('Resetting blockchain')
98 daemon = Daemon()
99 res = daemon.get_height()
100 daemon.pop_blocks(res.height - 1)
101 daemon.flush_txpool()
102
103 def mine(self, address, blocks):
104 print("Mining some blocks")
105 daemon = Daemon()
106 daemon.generateblocks(address, blocks)
107
108 # This method sets up N_total wallets with a threshold of M_threshold doing the following steps:
109 # * restore_deterministic_wallet(w/ hardcoded seeds)
110 # * prepare_multisig(enable_multisig_experimental = True)
111 # * make_multisig()
112 # * exchange_multisig_keys()
113 def create_multisig_wallets(self, M_threshold, N_total, expected_address):
114 print('Creating ' + str(M_threshold) + '/' + str(N_total) + ' multisig wallet')
115 seeds = [
116 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted',
117 'peeled mixture ionic radar utopia puddle buying illness nuns gadget river spout cavernous bounced paradise drunk looking cottage jump tequila melting went winter adjust spout',
118 'dilute gutter certain antics pamphlet macro enjoy left slid guarded bogeys upload nineteen bomb jubilee enhanced irritate turnip eggs swung jukebox loudly reduce sedan slid',
119 'waking gown buffet negative reorder speedy baffles hotel pliers dewdrop actress diplomat lymph emit ajar mailed kennel cynical jaunt justice weavers height teardrop toyed lymph',
120 ]
121 assert M_threshold <= N_total
122 assert N_total <= len(seeds)
123
124 # restore_deterministic_wallet() & prepare_multisig()
125 self.wallet = [None] * N_total
126 info = []
127 for i in range(N_total):
128 self.wallet[i] = Wallet(idx = i)
129 try: self.wallet[i].close_wallet()
130 except: pass
131 res = self.wallet[i].restore_deterministic_wallet(seed = seeds[i])
132 res = self.wallet[i].prepare_multisig(enable_multisig_experimental = True)
133 assert len(res.multisig_info) > 0
134 info.append(res.multisig_info)
135
136 # Assert that all wallets are multisig
137 for i in range(N_total):
138 res = self.wallet[i].is_multisig()
139 assert res.multisig == False
140
141 # make_multisig() with each other's info
142 addresses = []
143 next_stage = []
144 for i in range(N_total):
145 res = self.wallet[i].make_multisig(info, M_threshold)
146 addresses.append(res.address)
147 next_stage.append(res.multisig_info)
148
149 # Assert multisig paramaters M/N for each wallet
150 for i in range(N_total):
151 res = self.wallet[i].is_multisig()
152 assert res.multisig == True
153 assert not res.ready
154 assert res.threshold == M_threshold
155 assert res.total == N_total
156
157 # exchange_multisig_keys()
158 num_exchange_multisig_keys_stages = 0
159 while True: # while not all wallets are ready
160 n_ready = 0
161 for i in range(N_total):
162 res = self.wallet[i].is_multisig()
163 if res.ready == True:
164 n_ready += 1
165 assert n_ready == 0 or n_ready == N_total # No partial readiness
166 if n_ready == N_total:
167 break
168 info = next_stage
169 next_stage = []
170 addresses = []
171 for i in range(N_total):
172 res = self.wallet[i].exchange_multisig_keys(info)
173 next_stage.append(res.multisig_info)
174 addresses.append(res.address)
175 num_exchange_multisig_keys_stages += 1
176
177 # We should only need N - M + 1 key exchange rounds
178 assert num_exchange_multisig_keys_stages == N_total - M_threshold + 1
179
180 # Assert that the all wallets have expected public address
181 for i in range(N_total):
182 assert addresses[i] == expected_address, addresses[i]
183 self.wallet_address = expected_address
184
185 # Assert multisig paramaters M/N and "ready" for each wallet
186 for i in range(N_total):
187 res = self.wallet[i].is_multisig()
188 assert res.multisig == True
189 assert res.ready == True
190 assert res.threshold == M_threshold
191 assert res.total == N_total
192
193 # We want to test if multisig wallets can receive normal transfers as well and mining transfers
194 def fund_addrs_with_normal_wallet(self, addrs):
195 print("Funding multisig wallets with normal wallet-to-wallet transfers")
196
197 # Generate normal deterministic wallet
198 normal_seed = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted'
199 assert not hasattr(self, 'wallet') or not self.wallet
200 self.wallet = [Wallet(idx = 0)]
201 res = self.wallet[0].restore_deterministic_wallet(seed = normal_seed)
202 assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
203
204 self.wallet[0].refresh()
205
206 # Check that we own enough spendable enotes
207 res = self.wallet[0].incoming_transfers(transfer_type = 'available')
208 assert 'transfers' in res
209 num_outs_spendable = 0
210 min_out_amount = None
211 for t in res.transfers:
212 if not t.spent:
213 num_outs_spendable += 1
214 min_out_amount = min(min_out_amount, t.amount) if min_out_amount is not None else t.amount
215 assert num_outs_spendable >= 2 * len(addrs)
216
217 # Transfer to addrs and mine to confirm tx
218 dsts = [{'address': addr, 'amount': int(min_out_amount * 0.95)} for addr in addrs]
219 res = self.wallet[0].transfer(dsts, get_tx_metadata = True)
220 tx_hex = res.tx_metadata
221 res = self.wallet[0].relay_tx(tx_hex)
222 self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 10)
223
224 def remake_some_multisig_wallets_by_multsig_seed(self, threshold):
225 N = len(self.wallet)
226 num_signers_to_remake = random.randint(1, N) # Do at least one
227 signers_to_remake = list(range(N))
228 random.shuffle(signers_to_remake)
229 signers_to_remake = signers_to_remake[:num_signers_to_remake]
230
231 for i in signers_to_remake:
232 print("Remaking {}/{} multsig wallet from multisig seed: #{}".format(threshold, N, i+1))
233
234 otherwise_unused_seed = \
235 'factual wiggle awakened maul sash biscuit pause reinvest fonts sleepless knowledge tossed jewels request gusts dagger gumball onward dotted amended powder cynical strained topic request'
236
237 # Get information about wallet, will compare against later
238 old_viewkey = self.wallet[i].query_key('view_key').key
239 old_spendkey = self.wallet[i].query_key('spend_key').key
240 old_multisig_seed = self.wallet[i].query_key('mnemonic').key
241
242 # Close old wallet and restore w/ random seed so we know that restoring actually did something
243 self.wallet[i].close_wallet()
244 self.wallet[i].restore_deterministic_wallet(seed=otherwise_unused_seed)
245 mid_viewkey = self.wallet[i].query_key('view_key').key
246 assert mid_viewkey != old_viewkey
247
248 # Now restore w/ old multisig seed and check against original
249 self.wallet[i].close_wallet()
250 self.wallet[i].restore_deterministic_wallet(seed=old_multisig_seed, enable_multisig_experimental=True)
251 new_viewkey = self.wallet[i].query_key('view_key').key
252 new_spendkey = self.wallet[i].query_key('spend_key').key
253 new_multisig_seed = self.wallet[i].query_key('mnemonic').key
254 assert new_viewkey == old_viewkey
255 assert new_spendkey == old_spendkey
256 assert new_multisig_seed == old_multisig_seed
257
258 self.wallet[i].refresh()
259
260 def test_states(self):
261 print('Testing multisig states')
262 seeds = [
263 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted',
264 'peeled mixture ionic radar utopia puddle buying illness nuns gadget river spout cavernous bounced paradise drunk looking cottage jump tequila melting went winter adjust spout',
265 'dilute gutter certain antics pamphlet macro enjoy left slid guarded bogeys upload nineteen bomb jubilee enhanced irritate turnip eggs swung jukebox loudly reduce sedan slid',
266 ]
267 info2of2 = []
268 wallet2of2 = [None, None]
269 for i in range(2):
270 wallet2of2[i] = Wallet(idx = i)
271 try: wallet2of2[i].close_wallet()
272 except: pass
273 res = wallet2of2[i].restore_deterministic_wallet(seed = seeds[i])
274 res = wallet2of2[i].is_multisig()
275 assert not res.multisig
276 res = wallet2of2[i].prepare_multisig(enable_multisig_experimental = True)
277 assert len(res.multisig_info) > 0
278 info2of2.append(res.multisig_info)
279
280 kex_info = []
281 res = wallet2of2[0].make_multisig(info2of2, 2)
282 kex_info.append(res.multisig_info)
283 res = wallet2of2[1].make_multisig(info2of2, 2)
284 kex_info.append(res.multisig_info)
285 res = wallet2of2[0].exchange_multisig_keys(kex_info)
286 res = wallet2of2[0].is_multisig()
287 assert res.multisig
288 assert res.ready
289
290 ok = False
291 try: res = wallet2of2[0].prepare_multisig(enable_multisig_experimental = True)
292 except: ok = True
293 assert ok
294
295 ok = False
296 try: res = wallet2of2[0].make_multisig(info2of2, 2)
297 except: ok = True
298 assert ok
299
300 info2of3 = []
301 wallet2of3 = [None, None, None]
302 for i in range(3):
303 wallet2of3[i] = Wallet(idx = i)
304 try: wallet2of3[i].close_wallet()
305 except: pass
306 res = wallet2of3[i].restore_deterministic_wallet(seed = seeds[i])
307 res = wallet2of3[i].is_multisig()
308 assert not res.multisig
309 res = wallet2of3[i].prepare_multisig(enable_multisig_experimental = True)
310 assert len(res.multisig_info) > 0
311 info2of3.append(res.multisig_info)
312
313 for i in range(3):
314 ok = False
315 try: res = wallet2of3[i].exchange_multisig_keys(info)
316 except: ok = True
317 assert ok
318 res = wallet2of3[i].is_multisig()
319 assert not res.multisig
320
321 res = wallet2of3[1].make_multisig(info2of3, 2)
322 res = wallet2of3[1].is_multisig()
323 assert res.multisig
324 assert not res.ready
325
326 ok = False
327 try: res = wallet2of3[1].prepare_multisig(enable_multisig_experimental = True)
328 except: ok = True
329 assert ok
330
331 ok = False
332 try: res = wallet2of3[1].make_multisig(info2of3[0:2], 2)
333 except: ok = True
334 assert ok
335
336 def import_multisig_info(self, signers, expected_outputs):
337 assert len(signers) >= 2
338
339 print('Importing multisig info from ' + str(signers))
340
341 info = []
342 for i in signers:
343 self.wallet[i].refresh()
344 res = self.wallet[i].export_multisig_info()
345 assert len(res.info) > 0
346 info.append(res.info)
347 for i in signers:
348 res = self.wallet[i].import_multisig_info(info)
349 assert res.n_outputs == expected_outputs
350
351 def transfer(self, signers):
352 assert len(signers) >= 1
353
354 daemon = Daemon()
355
356 print("Creating multisig transaction from wallet " + str(signers[0]))
357
358 dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000}
359 res = self.wallet[signers[0]].transfer([dst])
360 assert len(res.tx_hash) == 0 # not known yet
361 txid = res.tx_hash
362 assert len(res.tx_key) == 32*2
363 assert res.amount > 0
364 amount = res.amount
365 assert res.fee > 0
366 fee = res.fee
367 assert len(res.tx_blob) == 0
368 assert len(res.tx_metadata) == 0
369 assert len(res.multisig_txset) > 0
370 assert len(res.unsigned_txset) == 0
371 multisig_txset = res.multisig_txset
372
373 daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
374 for i in range(len(self.wallet)):
375 self.wallet[i].refresh()
376
377 for i in range(len(signers[1:])):
378 print('Signing multisig transaction with wallet ' + str(signers[i+1]))
379 res = self.wallet[signers[i+1]].describe_transfer(multisig_txset = multisig_txset)
380 assert len(res.desc) == 1
381 desc = res.desc[0]
382 assert desc.amount_in >= amount + fee
383 assert desc.amount_out == desc.amount_in - fee
384 assert desc.ring_size == 16
385 assert desc.unlock_time == 0
386 assert not 'payment_id' in desc or desc.payment_id in ['', '0000000000000000']
387 assert desc.change_amount == desc.amount_in - 1000000000000 - fee
388 assert desc.change_address == self.wallet_address
389 assert desc.fee == fee
390 assert len(desc.recipients) == 1
391 rec = desc.recipients[0]
392 assert rec.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
393 assert rec.amount == 1000000000000
394
395 res = self.wallet[signers[i+1]].sign_multisig(multisig_txset)
396 multisig_txset = res.tx_data_hex
397 assert len(res.tx_hash_list if 'tx_hash_list' in res else []) == (i == len(signers[1:]) - 1)
398
399 if i < len(signers[1:]) - 1:
400 print('Submitting multisig transaction prematurely with wallet ' + str(signers[-1]))
401 ok = False
402 try: self.wallet[signers[-1]].submit_multisig(multisig_txset)
403 except: ok = True
404 assert ok
405
406 print('Submitting multisig transaction with wallet ' + str(signers[-1]))
407 res = self.wallet[signers[-1]].submit_multisig(multisig_txset)
408 assert len(res.tx_hash_list) == 1
409 txid = res.tx_hash_list[0]
410
411 for i in range(len(self.wallet)):
412 self.wallet[i].refresh()
413 res = self.wallet[i].get_transfers()
414 assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == (1 if i == signers[-1] else 0)
415 assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 0
416
417 daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
418 return txid
419
420 def try_transfer_frozen(self, signers):
421 assert len(signers) >= 2
422
423 daemon = Daemon()
424
425 print("Creating multisig transaction from wallet " + str(signers[0]))
426
427 dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000}
428 res = self.wallet[signers[0]].transfer([dst])
429 assert len(res.tx_hash) == 0 # not known yet
430 txid = res.tx_hash
431 assert len(res.tx_key) == 32*2
432 assert res.amount > 0
433 amount = res.amount
434 assert res.fee > 0
435 fee = res.fee
436 assert len(res.tx_blob) == 0
437 assert len(res.tx_metadata) == 0
438 assert len(res.multisig_txset) > 0
439 assert len(res.unsigned_txset) == 0
440 spent_key_images = res.spent_key_images.key_images
441 multisig_txset = res.multisig_txset
442
443 daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
444 for i in range(len(self.wallet)):
445 self.wallet[i].refresh()
446
447 for i in range(len(signers[1:])):
448 # Check that each signer wallet has key image and it is not frozen
449 for ki in spent_key_images:
450 frozen = self.wallet[signers[i+1]].frozen(ki).frozen
451 assert not frozen
452
453 # Freeze key image involved with initiated transfer
454 assert len(spent_key_images)
455 ki0 = spent_key_images[0]
456 print("Freezing involved key image:", ki0)
457 self.wallet[signers[1]].freeze(ki0)
458 frozen = self.wallet[signers[1]].frozen(ki).frozen
459 assert frozen
460
461 # Try signing multisig (this operation should fail b/c of the frozen key image)
462 print("Attemping to sign with frozen key image. This should fail")
463 try:
464 res = self.wallet[signers[1]].sign_multisig(multisig_txset)
465 raise ValueError('sign_multisig should not have succeeded w/ frozen enotes')
466 except AssertionError:
467 pass
468
469 # Thaw key image and continue transfer as normal
470 print("Thawing key image and continuing transfer as normal")
471 self.wallet[signers[1]].thaw(ki0)
472 frozen = self.wallet[signers[1]].frozen(ki).frozen
473 assert not frozen
474
475 for i in range(len(signers[1:])):
476 print('Signing multisig transaction with wallet ' + str(signers[i+1]))
477 res = self.wallet[signers[i+1]].describe_transfer(multisig_txset = multisig_txset)
478 assert len(res.desc) == 1
479 desc = res.desc[0]
480 assert desc.amount_in >= amount + fee
481 assert desc.amount_out == desc.amount_in - fee
482 assert desc.ring_size == 16
483 assert desc.unlock_time == 0
484 assert not 'payment_id' in desc or desc.payment_id in ['', '0000000000000000']
485 assert desc.change_amount == desc.amount_in - 1000000000000 - fee
486 assert desc.change_address == self.wallet_address
487 assert desc.fee == fee
488 assert len(desc.recipients) == 1
489 rec = desc.recipients[0]
490 assert rec.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
491 assert rec.amount == 1000000000000
492
493 res = self.wallet[signers[i+1]].sign_multisig(multisig_txset)
494 multisig_txset = res.tx_data_hex
495 assert len(res.tx_hash_list if 'tx_hash_list' in res else []) == (i == len(signers[1:]) - 1)
496
497 if i < len(signers[1:]) - 1:
498 print('Submitting multisig transaction prematurely with wallet ' + str(signers[-1]))
499 ok = False
500 try: self.wallet[signers[-1]].submit_multisig(multisig_txset)
501 except: ok = True
502 assert ok
503
504 print('Submitting multisig transaction with wallet ' + str(signers[-1]))
505 res = self.wallet[signers[-1]].submit_multisig(multisig_txset)
506 assert len(res.tx_hash_list) == 1
507 txid = res.tx_hash_list[0]
508
509 for i in range(len(self.wallet)):
510 self.wallet[i].refresh()
511 res = self.wallet[i].get_transfers()
512 assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == (1 if i == signers[-1] else 0)
513 assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 0
514
515 daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
516 return txid
517
518 def check_transaction(self, txid):
519 for i in range(len(self.wallet)):
520 self.wallet[i].refresh()
521 res = self.wallet[i].get_transfers()
522 assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == 0
523 assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 1
524
525
526 class Guard:
527 def __enter__(self):
528 for i in range(4):
529 Wallet(idx = i).auto_refresh(False)
530 def __exit__(self, exc_type, exc_value, traceback):
531 for i in range(4):
532 Wallet(idx = i).auto_refresh(True)
533
534 if __name__ == '__main__':
535 with Guard() as guard:
536 MultisigTest().run_test()