Debian Codegraph @

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 json
33 import random
34
35 """Test multisig transfers
36 """
37
38 from framework.daemon import Daemon
39 from framework.wallet import Wallet
40
41 TEST_CASES = \
42 [
43 # M N Primary Address
44 [2, 2, '45J58b7PmKJFSiNPFFrTdtfMcFGnruP7V4CMuRpX7NsH4j3jGHKAjo3YJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ3gr7sG'],
45 [2, 3, '44G2TQNfsiURKkvxp7gbgaJY8WynZvANnhmyMAwv6WeEbAvyAWMfKXRhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5duN94i'],
46 [3, 3, '41mro238grj56GnrWkakAKTkBy2yDcXYsUZ2iXCM9pe5Ueajd2RRc6Fhh3uBXT2UAKhAsUJ7Fg5zjjF2U1iGciFk5ief4ZP'],
47 [3, 4, '44vZSprQKJQRFe6t1VHgU4ESvq2dv7TjBLVGE7QscKxMdFSiyyPCEV64NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6dakeff'],
48 [2, 4, '47puypSwsV1gvUDratmX4y58fSwikXVehEiBhVLxJA1gRCxHyrRgTDr4NnKUQssFPyWxc2meyt7j63F2S2qtCTRL6aRPj5U'],
49 [1, 2, '4A8RnBQixry4VXkqeWhmg8L7vWJVDJj4FN9PV4E7Mgad5ZZ6LKQdn8dYJP2RePX6HMaSkbvTbrWUFhDNcNcHgtNmQ4S8RSB']
50 ]
51
52 PUB_ADDRS = [case[2] for case in TEST_CASES]
53
54 class MultisigTest():
55 def run_test(self):
56 self.reset()
57 for pub_addr in PUB_ADDRS:
58 self.mine(pub_addr, 4)
59 self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80)
60
61 self.test_states()
62
63 self.fund_addrs_with_normal_wallet(PUB_ADDRS)
64
65 for M, N, pub_addr in TEST_CASES:
66 assert M <= N
67 shuffled_participants = list(range(N))
68 random.shuffle(shuffled_participants)
69 shuffled_signers = shuffled_participants[:M]
70
71 expected_outputs = 5 # each wallet owns four mined outputs & one transferred output
72
73 # Create multisig wallet and test transferring
74 self.create_multisig_wallets(M, N, pub_addr)
75 self.import_multisig_info(shuffled_signers if M != 1 else shuffled_participants, expected_outputs)
76 txid = self.transfer(shuffled_signers)
77 expected_outputs += 1
78 self.import_multisig_info(shuffled_participants, expected_outputs)
79 self.check_transaction(txid)
80
81 # If more than 1 signer, try to freeze key image of one signer, make tx using that key
82 # image on another signer, then have first signer sign multisg_txset. Should fail
83 if M != 1:
84 txid = self.try_transfer_frozen(shuffled_signers)
85 expected_outputs += 1
86 self.import_multisig_info(shuffled_participants, expected_outputs)
87 self.check_transaction(txid)
88
89 # Recreate wallet from multisig seed and test transferring
90 self.remake_some_multisig_wallets_by_multsig_seed(M)
91 self.import_multisig_info(shuffled_signers if M != 1 else shuffled_participants, expected_outputs)
92 txid = self.transfer(shuffled_signers)
93 expected_outputs += 1
94 self.import_multisig_info(shuffled_participants, expected_outputs)
95 self.check_transaction(txid)
96
97 def reset(self):
98 print('Resetting blockchain')
99 daemon = Daemon()
100 res = daemon.get_height()
101 daemon.pop_blocks(res.height - 1)
102 daemon.flush_txpool()
103
104 def mine(self, address, blocks):
105 print("Mining some blocks")
106 daemon = Daemon()
107 daemon.generateblocks(address, blocks)
108
109 # This method sets up N_total wallets with a threshold of M_threshold doing the following steps:
110 # * restore_deterministic_wallet(w/ hardcoded seeds)
111 # * prepare_multisig(enable_multisig_experimental = True)
112 # * make_multisig()
113 # * exchange_multisig_keys()
114 def create_multisig_wallets(self, M_threshold, N_total, expected_address):
115 print('Creating ' + str(M_threshold) + '/' + str(N_total) + ' multisig wallet')
116 seeds = [
117 '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',
118 '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',
119 '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',
120 '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',
121 ]
122 assert M_threshold <= N_total
123 assert N_total <= len(seeds)
124
125 # restore_deterministic_wallet() & prepare_multisig()
126 self.wallet = [None] * N_total
127 info = []
128 for i in range(N_total):
129 self.wallet[i] = Wallet(idx = i)
130 try: self.wallet[i].close_wallet()
131 except: pass
132 res = self.wallet[i].restore_deterministic_wallet(seed = seeds[i])
133 res = self.wallet[i].prepare_multisig(enable_multisig_experimental = True)
134 assert len(res.multisig_info) > 0
135 info.append(res.multisig_info)
136
137 # Assert that all wallets are multisig
138 for i in range(N_total):
139 res = self.wallet[i].is_multisig()
140 assert res.multisig == False
141
142 # make_multisig() with each other's info
143 addresses = []
144 next_stage = []
145 for i in range(N_total):
146 res = self.wallet[i].make_multisig(info, M_threshold)
147 addresses.append(res.address)
148 next_stage.append(res.multisig_info)
149
150 # Assert multisig paramaters M/N for each wallet
151 for i in range(N_total):
152 res = self.wallet[i].is_multisig()
153 assert res.multisig == True
154 assert not res.ready
155 assert res.threshold == M_threshold
156 assert res.total == N_total
157
158 # exchange_multisig_keys()
159 num_exchange_multisig_keys_stages = 0
160 while True: # while not all wallets are ready
161 n_ready = 0
162 for i in range(N_total):
163 res = self.wallet[i].is_multisig()
164 if res.ready == True:
165 n_ready += 1
166 assert n_ready == 0 or n_ready == N_total # No partial readiness
167 if n_ready == N_total:
168 break
169 info = next_stage
170 next_stage = []
171 addresses = []
172 for i in range(N_total):
173 res = self.wallet[i].exchange_multisig_keys(info)
174 next_stage.append(res.multisig_info)
175 addresses.append(res.address)
176 num_exchange_multisig_keys_stages += 1
177
178 # We should only need N - M + 1 key exchange rounds
179 assert num_exchange_multisig_keys_stages == N_total - M_threshold + 1
180
181 # Assert that the all wallets have expected public address
182 for i in range(N_total):
183 assert addresses[i] == expected_address, addresses[i]
184 self.wallet_address = expected_address
185
186 # Assert multisig paramaters M/N and "ready" for each wallet
187 for i in range(N_total):
188 res = self.wallet[i].is_multisig()
189 assert res.multisig == True
190 assert res.ready == True
191 assert res.threshold == M_threshold
192 assert res.total == N_total
193
194 # We want to test if multisig wallets can receive normal transfers as well and mining transfers
195 def fund_addrs_with_normal_wallet(self, addrs):
196 print("Funding multisig wallets with normal wallet-to-wallet transfers")
197
198 # Generate normal deterministic wallet
199 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'
200 assert not hasattr(self, 'wallet') or not self.wallet
201 self.wallet = [Wallet(idx = 0)]
202 res = self.wallet[0].restore_deterministic_wallet(seed = normal_seed)
203 assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
204
205 self.wallet[0].refresh()
206
207 # Check that we own enough spendable enotes
208 res = self.wallet[0].incoming_transfers(transfer_type = 'available')
209 assert 'transfers' in res
210 num_outs_spendable = 0
211 min_out_amount = None
212 for t in res.transfers:
213 if not t.spent:
214 num_outs_spendable += 1
215 min_out_amount = min(min_out_amount, t.amount) if min_out_amount is not None else t.amount
216 assert num_outs_spendable >= 2 * len(addrs)
217
218 # Transfer to addrs and mine to confirm tx
219 dsts = [{'address': addr, 'amount': int(min_out_amount * 0.95)} for addr in addrs]
220 res = self.wallet[0].transfer(dsts, get_tx_metadata = True)
221 tx_hex = res.tx_metadata
222 res = self.wallet[0].relay_tx(tx_hex)
223 self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 10)
224
225 def remake_some_multisig_wallets_by_multsig_seed(self, threshold):
226 N = len(self.wallet)
227 num_signers_to_remake = random.randint(1, N) # Do at least one
228 signers_to_remake = list(range(N))
229 random.shuffle(signers_to_remake)
230 signers_to_remake = signers_to_remake[:num_signers_to_remake]
231
232 for i in signers_to_remake:
233 print("Remaking {}/{} multsig wallet from multisig seed: #{}".format(threshold, N, i+1))
234
235 otherwise_unused_seed = \
236 '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'
237
238 # Get information about wallet, will compare against later
239 old_viewkey = self.wallet[i].query_key('view_key').key
240 old_spendkey = self.wallet[i].query_key('spend_key').key
241 old_multisig_seed = self.wallet[i].query_key('mnemonic').key
242
243 # Close old wallet and restore w/ random seed so we know that restoring actually did something
244 self.wallet[i].close_wallet()
245 self.wallet[i].restore_deterministic_wallet(seed=otherwise_unused_seed)
246 mid_viewkey = self.wallet[i].query_key('view_key').key
247 assert mid_viewkey != old_viewkey
248
249 # Now restore w/ old multisig seed and check against original
250 self.wallet[i].close_wallet()
251 self.wallet[i].restore_deterministic_wallet(seed=old_multisig_seed, enable_multisig_experimental=True)
252 new_viewkey = self.wallet[i].query_key('view_key').key
253 new_spendkey = self.wallet[i].query_key('spend_key').key
254 new_multisig_seed = self.wallet[i].query_key('mnemonic').key
255 assert new_viewkey == old_viewkey
256 assert new_spendkey == old_spendkey
257 assert new_multisig_seed == old_multisig_seed
258
259 self.wallet[i].refresh()
260
261 def test_states(self):
262 print('Testing multisig states')
263 seeds = [
264 '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',
265 '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',
266 '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',
267 ]
268 info2of2 = []
269 wallet2of2 = [None, None]
270 for i in range(2):
271 wallet2of2[i] = Wallet(idx = i)
272 try: wallet2of2[i].close_wallet()
273 except: pass
274 res = wallet2of2[i].restore_deterministic_wallet(seed = seeds[i])
275 res = wallet2of2[i].is_multisig()
276 assert not res.multisig
277 res = wallet2of2[i].prepare_multisig(enable_multisig_experimental = True)
278 assert len(res.multisig_info) > 0
279 info2of2.append(res.multisig_info)
280
281 kex_info = []
282 res = wallet2of2[0].make_multisig(info2of2, 2)
283 kex_info.append(res.multisig_info)
284 res = wallet2of2[1].make_multisig(info2of2, 2)
285 kex_info.append(res.multisig_info)
286 res = wallet2of2[0].exchange_multisig_keys(kex_info)
287 res = wallet2of2[0].is_multisig()
288 assert res.multisig
289 assert res.ready
290
291 ok = False
292 try: res = wallet2of2[0].prepare_multisig(enable_multisig_experimental = True)
293 except: ok = True
294 assert ok
295
296 ok = False
297 try: res = wallet2of2[0].make_multisig(info2of2, 2)
298 except: ok = True
299 assert ok
300
301 info2of3 = []
302 wallet2of3 = [None, None, None]
303 for i in range(3):
304 wallet2of3[i] = Wallet(idx = i)
305 try: wallet2of3[i].close_wallet()
306 except: pass
307 res = wallet2of3[i].restore_deterministic_wallet(seed = seeds[i])
308 res = wallet2of3[i].is_multisig()
309 assert not res.multisig
310 res = wallet2of3[i].prepare_multisig(enable_multisig_experimental = True)
311 assert len(res.multisig_info) > 0
312 info2of3.append(res.multisig_info)
313
314 for i in range(3):
315 ok = False
316 try: res = wallet2of3[i].exchange_multisig_keys(info)
317 except: ok = True
318 assert ok
319 res = wallet2of3[i].is_multisig()
320 assert not res.multisig
321
322 res = wallet2of3[1].make_multisig(info2of3, 2)
323 res = wallet2of3[1].is_multisig()
324 assert res.multisig
325 assert not res.ready
326
327 ok = False
328 try: res = wallet2of3[1].prepare_multisig(enable_multisig_experimental = True)
329 except: ok = True
330 assert ok
331
332 ok = False
333 try: res = wallet2of3[1].make_multisig(info2of3[0:2], 2)
334 except: ok = True
335 assert ok
336
337 def import_multisig_info(self, signers, expected_outputs):
338 assert len(signers) >= 2
339
340 print('Importing multisig info from ' + str(signers))
341
342 info = []
343 for i in signers:
344 self.wallet[i].refresh()
345 res = self.wallet[i].export_multisig_info()
346 assert len(res.info) > 0
347 info.append(res.info)
348 for i in signers:
349 res = self.wallet[i].import_multisig_info(info)
350 assert res.n_outputs == expected_outputs
351
352 def transfer(self, signers):
353 assert len(signers) >= 1
354
355 daemon = Daemon()
356
357 print("Creating multisig transaction from wallet " + str(signers[0]))
358
359 dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000}
360 res = self.wallet[signers[0]].transfer([dst])
361 assert len(res.tx_hash) == 0 # not known yet
362 txid = res.tx_hash
363 assert len(res.tx_key) == 32*2
364 assert res.amount > 0
365 amount = res.amount
366 assert res.fee > 0
367 fee = res.fee
368 assert len(res.tx_blob) == 0
369 assert len(res.tx_metadata) == 0
370 assert len(res.multisig_txset) > 0
371 assert len(res.unsigned_txset) == 0
372 multisig_txset = res.multisig_txset
373
374 daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
375 for i in range(len(self.wallet)):
376 self.wallet[i].refresh()
377
378 for i in range(len(signers[1:])):
379 print('Signing multisig transaction with wallet ' + str(signers[i+1]))
380 res = self.wallet[signers[i+1]].describe_transfer(multisig_txset = multisig_txset)
381 assert len(res.desc) == 1
382 desc = res.desc[0]
383 assert desc.amount_in >= amount + fee
384 assert desc.amount_out == desc.amount_in - fee
385 assert desc.ring_size == 16
386 assert desc.unlock_time == 0
387 assert not 'payment_id' in desc or desc.payment_id in ['', '0000000000000000']
388 assert desc.change_amount == desc.amount_in - 1000000000000 - fee
389 assert desc.change_address == self.wallet_address
390 assert desc.fee == fee
391 assert len(desc.recipients) == 1
392 rec = desc.recipients[0]
393 assert rec.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
394 assert rec.amount == 1000000000000
395
396 res = self.wallet[signers[i+1]].sign_multisig(multisig_txset)
397 multisig_txset = res.tx_data_hex
398 assert len(res.tx_hash_list if 'tx_hash_list' in res else []) == (i == len(signers[1:]) - 1)
399
400 if i < len(signers[1:]) - 1:
401 print('Submitting multisig transaction prematurely with wallet ' + str(signers[-1]))
402 ok = False
403 try: self.wallet[signers[-1]].submit_multisig(multisig_txset)
404 except: ok = True
405 assert ok
406
407 print('Submitting multisig transaction with wallet ' + str(signers[-1]))
408 res = self.wallet[signers[-1]].submit_multisig(multisig_txset)
409 assert len(res.tx_hash_list) == 1
410 txid = res.tx_hash_list[0]
411
412 # Retrieve spent key images from daemon
413 res = daemon.get_transactions([txid], decode_as_json = True)
414 assert len(res.txs) == 1
415 tx = res.txs[0]
416 assert tx.tx_hash == txid
417 assert len(tx.as_json) > 0
418 try:
419 j = json.loads(tx.as_json)
420 except:
421 j = None
422 assert j
423 assert len(j['vin']) >= 1
424 spent_key_images = [vin['key']['k_image'] for vin in j['vin']]
425 assert len(spent_key_images) == len(j['vin'])
426
427 for i in range(len(self.wallet)):
428 # Check if the wallet knows about any spent key images (all signers *should*, non-signers *might*)
429 is_a_signer = len([x for x in signers if x == i]) > 0
430 knows_key_image = False
431 for ki in spent_key_images:
432 try:
433 res = self.wallet[i].frozen(ki)
434 knows_key_image = True
435 except AssertionError:
436 if is_a_signer:
437 raise ValueError('Signer should know about spent key image')
438 pass
439 self.wallet[i].refresh()
440 res = self.wallet[i].get_transfers()
441 # Any wallet that knows about any spent key images should be able to detect the spend in the pool
442 assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == (1 if knows_key_image else 0)
443 assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 0
444
445 daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
446 return txid
447
448 def try_transfer_frozen(self, signers):
449 assert len(signers) >= 2
450
451 daemon = Daemon()
452
453 print("Creating multisig transaction from wallet " + str(signers[0]))
454
455 dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000}
456 res = self.wallet[signers[0]].transfer([dst])
457 assert len(res.tx_hash) == 0 # not known yet
458 txid = res.tx_hash
459 assert len(res.tx_key) == 32*2
460 assert res.amount > 0
461 amount = res.amount
462 assert res.fee > 0
463 fee = res.fee
464 assert len(res.tx_blob) == 0
465 assert len(res.tx_metadata) == 0
466 assert len(res.multisig_txset) > 0
467 assert len(res.unsigned_txset) == 0
468 spent_key_images = res.spent_key_images.key_images
469 multisig_txset = res.multisig_txset
470
471 daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
472 for i in range(len(self.wallet)):
473 self.wallet[i].refresh()
474
475 for i in range(len(signers[1:])):
476 # Check that each signer wallet has key image and it is not frozen
477 for ki in spent_key_images:
478 frozen = self.wallet[signers[i+1]].frozen(ki).frozen
479 assert not frozen
480
481 # Freeze key image involved with initiated transfer
482 assert len(spent_key_images)
483 ki0 = spent_key_images[0]
484 print("Freezing involved key image:", ki0)
485 self.wallet[signers[1]].freeze(ki0)
486 frozen = self.wallet[signers[1]].frozen(ki).frozen
487 assert frozen
488
489 # Try signing multisig (this operation should fail b/c of the frozen key image)
490 print("Attemping to sign with frozen key image. This should fail")
491 try:
492 res = self.wallet[signers[1]].sign_multisig(multisig_txset)
493 raise ValueError('sign_multisig should not have succeeded w/ frozen enotes')
494 except AssertionError:
495 pass
496
497 # Thaw key image and continue transfer as normal
498 print("Thawing key image and continuing transfer as normal")
499 self.wallet[signers[1]].thaw(ki0)
500 frozen = self.wallet[signers[1]].frozen(ki).frozen
501 assert not frozen
502
503 for i in range(len(signers[1:])):
504 print('Signing multisig transaction with wallet ' + str(signers[i+1]))
505 res = self.wallet[signers[i+1]].describe_transfer(multisig_txset = multisig_txset)
506 assert len(res.desc) == 1
507 desc = res.desc[0]
508 assert desc.amount_in >= amount + fee
509 assert desc.amount_out == desc.amount_in - fee
510 assert desc.ring_size == 16
511 assert desc.unlock_time == 0
512 assert not 'payment_id' in desc or desc.payment_id in ['', '0000000000000000']
513 assert desc.change_amount == desc.amount_in - 1000000000000 - fee
514 assert desc.change_address == self.wallet_address
515 assert desc.fee == fee
516 assert len(desc.recipients) == 1
517 rec = desc.recipients[0]
518 assert rec.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
519 assert rec.amount == 1000000000000
520
521 res = self.wallet[signers[i+1]].sign_multisig(multisig_txset)
522 multisig_txset = res.tx_data_hex
523 assert len(res.tx_hash_list if 'tx_hash_list' in res else []) == (i == len(signers[1:]) - 1)
524
525 if i < len(signers[1:]) - 1:
526 print('Submitting multisig transaction prematurely with wallet ' + str(signers[-1]))
527 ok = False
528 try: self.wallet[signers[-1]].submit_multisig(multisig_txset)
529 except: ok = True
530 assert ok
531
532 print('Submitting multisig transaction with wallet ' + str(signers[-1]))
533 res = self.wallet[signers[-1]].submit_multisig(multisig_txset)
534 assert len(res.tx_hash_list) == 1
535 txid = res.tx_hash_list[0]
536
537 for i in range(len(self.wallet)):
538 # Make sure wallet knows about the key image
539 frozen = self.wallet[i].frozen(ki).frozen
540 assert not frozen
541 self.wallet[i].refresh()
542 res = self.wallet[i].get_transfers()
543 # Since all wallets should have key image, all wallets should be able to detect the spend in the pool
544 assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == 1
545 assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 0
546
547 daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
548 return txid
549
550 def check_transaction(self, txid):
551 for i in range(len(self.wallet)):
552 self.wallet[i].refresh()
553 res = self.wallet[i].get_transfers()
554 assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == 0
555 assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 1
556
557
558 class Guard:
559 def __enter__(self):
560 for i in range(4):
561 Wallet(idx = i).auto_refresh(False)
562 def __exit__(self, exc_type, exc_value, traceback):
563 for i in range(4):
564 Wallet(idx = i).auto_refresh(True)
565
566 if __name__ == '__main__':
567 with Guard() as guard:
568 MultisigTest().run_test()