2019-03-21 00:21:28 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-05-07 02:36:54 +00:00
|
|
|
# Copyright (c) 2019-2020 The Monero Project
|
2019-03-21 00:21:28 +00:00
|
|
|
#
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
# permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
# conditions and the following disclaimer.
|
|
|
|
#
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
# of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
# materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
# used to endorse or promote products derived from this software without specific
|
|
|
|
# prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2019-05-29 11:45:25 +00:00
|
|
|
from __future__ import print_function
|
2019-03-21 00:21:28 +00:00
|
|
|
|
|
|
|
"""Test misc proofs (tx key, send, receive, reserve)
|
|
|
|
"""
|
|
|
|
|
2019-03-22 14:35:23 +00:00
|
|
|
from framework.daemon import Daemon
|
|
|
|
from framework.wallet import Wallet
|
2019-03-21 00:21:28 +00:00
|
|
|
|
|
|
|
class ProofsTest():
|
|
|
|
def run_test(self):
|
2019-04-19 22:47:44 +00:00
|
|
|
self.reset()
|
2019-03-21 00:21:28 +00:00
|
|
|
self.mine('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80)
|
|
|
|
self.create_wallets()
|
|
|
|
txid, tx_key, amount = self.transfer()
|
|
|
|
self.check_tx_key(txid, tx_key, amount)
|
|
|
|
self.check_tx_proof(txid, amount)
|
2019-04-29 20:08:47 +00:00
|
|
|
self.check_spend_proof(txid)
|
2019-03-21 00:21:28 +00:00
|
|
|
self.check_reserve_proof()
|
|
|
|
|
2019-04-19 22:47:44 +00:00
|
|
|
def reset(self):
|
2019-05-29 11:45:25 +00:00
|
|
|
print('Resetting blockchain')
|
2019-04-19 22:47:44 +00:00
|
|
|
daemon = Daemon()
|
2019-05-26 18:14:01 +00:00
|
|
|
res = daemon.get_height()
|
|
|
|
daemon.pop_blocks(res.height - 1)
|
2019-04-19 22:47:44 +00:00
|
|
|
daemon.flush_txpool()
|
|
|
|
|
2019-03-21 00:21:28 +00:00
|
|
|
def mine(self, address, blocks):
|
|
|
|
print("Mining some blocks")
|
|
|
|
daemon = Daemon()
|
|
|
|
daemon.generateblocks(address, blocks)
|
|
|
|
|
|
|
|
def transfer(self):
|
|
|
|
print('Creating transaction')
|
|
|
|
self.wallet[0].refresh()
|
|
|
|
dst = {'address': '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW', 'amount':123456789000}
|
|
|
|
res = self.wallet[0].transfer([dst], get_tx_key = True)
|
|
|
|
assert len(res.tx_hash) == 64
|
|
|
|
assert len(res.tx_key) == 64
|
|
|
|
daemon = Daemon()
|
|
|
|
daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
|
|
|
|
return (res.tx_hash, res.tx_key, 123456789000)
|
|
|
|
|
|
|
|
def create_wallets(self):
|
|
|
|
print('Creating wallets')
|
|
|
|
seeds = [
|
|
|
|
'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',
|
|
|
|
'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',
|
|
|
|
]
|
|
|
|
self.wallet = [None, None]
|
|
|
|
for i in range(2):
|
|
|
|
self.wallet[i] = Wallet(idx = i)
|
|
|
|
try: self.wallet[i].close_wallet()
|
|
|
|
except: pass
|
|
|
|
res = self.wallet[i].restore_deterministic_wallet(seed = seeds[i])
|
|
|
|
|
|
|
|
def check_tx_key(self, txid, tx_key, amount):
|
|
|
|
daemon = Daemon()
|
|
|
|
|
|
|
|
print('Checking tx key')
|
|
|
|
|
|
|
|
self.wallet[0].refresh()
|
|
|
|
self.wallet[1].refresh()
|
|
|
|
|
|
|
|
sending_address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
|
|
|
receiving_address = '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW'
|
|
|
|
res = self.wallet[0].get_tx_key(txid)
|
|
|
|
assert res.tx_key == tx_key
|
|
|
|
res = self.wallet[0].check_tx_key(txid = txid, tx_key = tx_key, address = receiving_address)
|
|
|
|
assert res.received == amount
|
|
|
|
assert not res.in_pool
|
|
|
|
assert res.confirmations == 1
|
|
|
|
res = self.wallet[1].check_tx_key(txid = txid, tx_key = tx_key, address = receiving_address)
|
|
|
|
assert res.received == amount
|
|
|
|
assert not res.in_pool
|
|
|
|
assert res.confirmations == 1
|
|
|
|
|
|
|
|
self.wallet[1].check_tx_key(txid = txid, tx_key = tx_key, address = sending_address)
|
|
|
|
assert res.received >= 0 # might be change
|
|
|
|
assert not res.in_pool
|
|
|
|
assert res.confirmations == 1
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: self.wallet[1].check_tx_key(txid = '0' * 64, tx_key = tx_key, address = receiving_address)
|
|
|
|
except: ok = True
|
|
|
|
assert ok
|
|
|
|
|
|
|
|
res = self.wallet[1].check_tx_key(txid = txid, tx_key = '0' * 64, address = receiving_address)
|
|
|
|
assert res.received == 0
|
|
|
|
assert not res.in_pool
|
|
|
|
assert res.confirmations == 1
|
|
|
|
|
|
|
|
def check_tx_proof(self, txid, amount):
|
|
|
|
daemon = Daemon()
|
|
|
|
|
|
|
|
print('Checking tx proof')
|
|
|
|
|
|
|
|
self.wallet[0].refresh()
|
|
|
|
self.wallet[1].refresh()
|
|
|
|
|
|
|
|
sending_address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
|
|
|
receiving_address = '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW'
|
|
|
|
res = self.wallet[0].get_tx_proof(txid, sending_address, 'foo');
|
2020-08-09 22:42:15 +00:00
|
|
|
assert res.signature.startswith('InProofV2');
|
2019-03-21 00:21:28 +00:00
|
|
|
signature0i = res.signature
|
|
|
|
res = self.wallet[0].get_tx_proof(txid, receiving_address, 'bar');
|
2020-08-09 22:42:15 +00:00
|
|
|
assert res.signature.startswith('OutProofV2');
|
2019-03-21 00:21:28 +00:00
|
|
|
signature0o = res.signature
|
|
|
|
res = self.wallet[1].get_tx_proof(txid, receiving_address, 'baz');
|
2020-08-09 22:42:15 +00:00
|
|
|
assert res.signature.startswith('InProofV2');
|
2019-03-21 00:21:28 +00:00
|
|
|
signature1 = res.signature
|
|
|
|
|
|
|
|
res = self.wallet[0].check_tx_proof(txid, sending_address, 'foo', signature0i);
|
|
|
|
assert res.good
|
|
|
|
assert res.received > 0 # likely change
|
|
|
|
assert not res.in_pool
|
|
|
|
assert res.confirmations == 1
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof('0' * 64, sending_address, 'foo', signature0i);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof(txid, receiving_address, 'foo', signature0i);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof(txid, sending_address, '', signature0i);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof(txid, sending_address, 'foo', signature1);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
|
|
|
|
res = self.wallet[0].check_tx_proof(txid, receiving_address, 'bar', signature0o);
|
|
|
|
assert res.good
|
|
|
|
assert res.received == amount
|
|
|
|
assert not res.in_pool
|
|
|
|
assert res.confirmations == 1
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof('0' * 64, receiving_address, 'bar', signature0o);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof(txid, sending_address, 'bar', signature0o);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof(txid, receiving_address, '', signature0o);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof(txid, receiving_address, 'bar', signature0i);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
|
|
|
|
res = self.wallet[1].check_tx_proof(txid, receiving_address, 'baz', signature1);
|
|
|
|
assert res.good
|
|
|
|
assert res.received == amount
|
|
|
|
assert not res.in_pool
|
|
|
|
assert res.confirmations == 1
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[1].check_tx_proof('0' * 64, receiving_address, 'baz', signature1);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[1].check_tx_proof(txid, sending_address, 'baz', signature1);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[1].check_tx_proof(txid, receiving_address, '', signature1);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[1].check_tx_proof(txid, receiving_address, 'baz', signature0o);
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
2020-08-09 22:42:15 +00:00
|
|
|
|
|
|
|
# Test bad cross-version verification
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof(txid, sending_address, 'foo', signature0i.replace('ProofV2','ProofV1'));
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[0].check_tx_proof(txid, receiving_address, 'bar', signature0o.replace('ProofV2','ProofV1'));
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[1].check_tx_proof(txid, receiving_address, 'baz', signature1.replace('ProofV2','ProofV1'));
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
2019-04-29 20:08:47 +00:00
|
|
|
def check_spend_proof(self, txid):
|
|
|
|
daemon = Daemon()
|
|
|
|
|
|
|
|
print('Checking spend proof')
|
|
|
|
|
|
|
|
self.wallet[0].refresh()
|
|
|
|
self.wallet[1].refresh()
|
|
|
|
|
|
|
|
res = self.wallet[0].get_spend_proof(txid, message = 'foo')
|
|
|
|
assert len(res.signature) > 0
|
|
|
|
signature = res.signature
|
|
|
|
res = self.wallet[1].check_spend_proof(txid, message = 'foo', signature = signature)
|
|
|
|
assert res.good
|
|
|
|
|
|
|
|
res = self.wallet[0].get_spend_proof(txid, message = 'foobar')
|
|
|
|
assert len(res.signature) > 0
|
|
|
|
signature2 = res.signature
|
|
|
|
res = self.wallet[1].check_spend_proof(txid, message = 'foobar', signature = signature2)
|
|
|
|
assert res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[1].check_spend_proof('0' * 64, message = 'foo', signature = signature)
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[1].check_spend_proof(txid, message = 'bar', signature = signature)
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[1].check_spend_proof(txid, message = 'foo', signature = signature2)
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
2019-03-21 00:21:28 +00:00
|
|
|
|
|
|
|
def check_reserve_proof(self):
|
|
|
|
daemon = Daemon()
|
|
|
|
|
|
|
|
print('Checking reserve proof')
|
|
|
|
|
|
|
|
address0 = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
|
|
|
|
address1 = '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW'
|
|
|
|
|
|
|
|
self.wallet[0].refresh()
|
|
|
|
res = self.wallet[0].get_balance()
|
|
|
|
balance0 = res.balance
|
|
|
|
self.wallet[1].refresh()
|
|
|
|
res = self.wallet[1].get_balance()
|
|
|
|
balance1 = res.balance
|
|
|
|
|
|
|
|
res = self.wallet[0].get_reserve_proof(all_ = True, message = 'foo')
|
2020-08-09 22:42:15 +00:00
|
|
|
assert res.signature.startswith('ReserveProofV2')
|
2019-03-21 00:21:28 +00:00
|
|
|
signature = res.signature
|
|
|
|
for i in range(2):
|
|
|
|
res = self.wallet[i].check_reserve_proof(address = address0, message = 'foo', signature = signature)
|
|
|
|
assert res.good
|
|
|
|
assert res.total == balance0
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[i].check_reserve_proof(address = address0, message = 'bar', signature = signature)
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[i].check_reserve_proof(address = address1, message = 'foo', signature = signature)
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
2020-08-09 22:42:15 +00:00
|
|
|
# Test bad cross-version verification
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[i].check_reserve_proof(address = address0, message = 'foo', signature = signature.replace('ProofV2','ProofV1'))
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
2019-03-21 00:21:28 +00:00
|
|
|
amount = int(balance0 / 10)
|
|
|
|
res = self.wallet[0].get_reserve_proof(all_ = False, amount = amount, message = 'foo')
|
2020-08-09 22:42:15 +00:00
|
|
|
assert res.signature.startswith('ReserveProofV2')
|
2019-03-21 00:21:28 +00:00
|
|
|
signature = res.signature
|
|
|
|
for i in range(2):
|
|
|
|
res = self.wallet[i].check_reserve_proof(address = address0, message = 'foo', signature = signature)
|
|
|
|
assert res.good
|
|
|
|
assert res.total >= amount and res.total <= balance0
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[i].check_reserve_proof(address = address0, message = 'bar', signature = signature)
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[i].check_reserve_proof(address = address1, message = 'foo', signature = signature)
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
2020-08-09 22:42:15 +00:00
|
|
|
# Test bad cross-version verification
|
|
|
|
ok = False
|
|
|
|
try: res = self.wallet[i].check_reserve_proof(address = address0, message = 'foo', signature = signature.replace('ProofV2','ProofV1'))
|
|
|
|
except: ok = True
|
|
|
|
assert ok or not res.good
|
|
|
|
|
2019-03-21 00:21:28 +00:00
|
|
|
ok = False
|
|
|
|
try: self.wallet[0].get_reserve_proof(all_ = False, amount = balance0 + 1, message = 'foo')
|
|
|
|
except: ok = True
|
|
|
|
assert ok
|
|
|
|
|
|
|
|
|
|
|
|
class Guard:
|
|
|
|
def __enter__(self):
|
|
|
|
for i in range(4):
|
|
|
|
Wallet(idx = i).auto_refresh(False)
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
|
|
for i in range(4):
|
|
|
|
Wallet(idx = i).auto_refresh(True)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
with Guard() as guard:
|
|
|
|
ProofsTest().run_test()
|