aboutsummaryrefslogtreecommitdiff
path: root/tests/functional_tests/multisig.py
diff options
context:
space:
mode:
authorj-berman <justinberman@protonmail.com>2025-09-15 09:47:17 -0700
committerj-berman <justinberman@protonmail.com>2025-10-07 11:02:17 -0700
commit9239d36691bfe94dda12cc925903fed5e761fbe3 (patch)
tree6cd7880b0d335d007ac04794c90655938a698f53 /tests/functional_tests/multisig.py
parenta440e917906b92b74daa107e49fcb963266242fa (diff)
downloadmonzero-core-9239d36691bfe94dda12cc925903fed5e761fbe3.tar.gz
monzero-core-9239d36691bfe94dda12cc925903fed5e761fbe3.tar.xz
monzero-core-9239d36691bfe94dda12cc925903fed5e761fbe3.zip
wallet: identify spends in pool when scanning
- Make sure to mark identified spends in the pool as spends. The wallet might not know these have been spent if it wasn't the wallet that relayed the tx to the daemon, or the wallet was cleared via rescan_bc. - Make sure to add spends to m_unconfirmed_txs if not present. - Make sure to process the entire pool again if refreshing for the first time. The wallet fetches pool and blocks at the same time. The wallet scans blocks first, then pool. If the wallet identifies received outputs in the chain, then it may have spent those received outputs in the pool. So we make sure to re-process the entire pool again after scanning the chain for the first time. - Multisig wallets that know about spent key images can now detect spend txs in the pool. Update tests for that.
Diffstat (limited to 'tests/functional_tests/multisig.py')
-rwxr-xr-xtests/functional_tests/multisig.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/tests/functional_tests/multisig.py b/tests/functional_tests/multisig.py
index 3da983d69..6d40056d6 100755
--- a/tests/functional_tests/multisig.py
+++ b/tests/functional_tests/multisig.py
@@ -29,6 +29,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
+import json
import random
"""Test multisig transfers
@@ -408,10 +409,37 @@ class MultisigTest():
assert len(res.tx_hash_list) == 1
txid = res.tx_hash_list[0]
+ # Retrieve spent key images from daemon
+ res = daemon.get_transactions([txid], decode_as_json = True)
+ assert len(res.txs) == 1
+ tx = res.txs[0]
+ assert tx.tx_hash == txid
+ assert len(tx.as_json) > 0
+ try:
+ j = json.loads(tx.as_json)
+ except:
+ j = None
+ assert j
+ assert len(j['vin']) >= 1
+ spent_key_images = [vin['key']['k_image'] for vin in j['vin']]
+ assert len(spent_key_images) == len(j['vin'])
+
for i in range(len(self.wallet)):
+ # Check if the wallet knows about any spent key images (all signers *should*, non-signers *might*)
+ is_a_signer = len([x for x in signers if x == i]) > 0
+ knows_key_image = False
+ for ki in spent_key_images:
+ try:
+ res = self.wallet[i].frozen(ki)
+ knows_key_image = True
+ except AssertionError:
+ if is_a_signer:
+ raise ValueError('Signer should know about spent key image')
+ pass
self.wallet[i].refresh()
res = self.wallet[i].get_transfers()
- assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == (1 if i == signers[-1] else 0)
+ # Any wallet that knows about any spent key images should be able to detect the spend in the pool
+ assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == (1 if knows_key_image else 0)
assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 0
daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
@@ -507,9 +535,13 @@ class MultisigTest():
txid = res.tx_hash_list[0]
for i in range(len(self.wallet)):
+ # Make sure wallet knows about the key image
+ frozen = self.wallet[i].frozen(ki).frozen
+ assert not frozen
self.wallet[i].refresh()
res = self.wallet[i].get_transfers()
- assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == (1 if i == signers[-1] else 0)
+ # Since all wallets should have key image, all wallets should be able to detect the spend in the pool
+ assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == 1
assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 0
daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)