def create(self, idx): print('Creating hot and cold wallet') self.hot_wallet = Wallet(idx = 0) # close the wallet if any, will throw if none is loaded try: self.hot_wallet.close_wallet() except: pass self.cold_wallet = Wallet(idx = 1) # close the wallet if any, will throw if none is loaded try: self.cold_wallet.close_wallet() except: pass 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' res = self.cold_wallet.restore_deterministic_wallet(seed = seed) self.cold_wallet.set_daemon('127.0.0.1:11111', ssl_support = "disabled") spend_key = self.cold_wallet.query_key("spend_key").key view_key = self.cold_wallet.query_key("view_key").key res = self.hot_wallet.generate_from_keys(viewkey = view_key, address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm') ok = False try: res = self.hot_wallet.query_key("spend_key") except: ok = True assert ok ok = False try: self.hot_wallet.query_key("mnemonic") except: ok = True assert ok assert self.cold_wallet.query_key("view_key").key == view_key assert self.cold_wallet.get_address().address == self.hot_wallet.get_address().address
def create(self): print('Creating wallet') wallet = Wallet() # close the wallet if any, will throw if none is loaded try: wallet.close_wallet() except: pass res = wallet.restore_deterministic_wallet(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')
def mine(self): print("Mining some blocks") daemon = Daemon() wallet = Wallet() daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80) wallet.refresh()
def check_main_address(self): print('Getting address') wallet = Wallet() res = wallet.get_address() assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', res assert len(res.addresses) == 1 assert res.addresses[0].address == res.address assert res.addresses[0].address_index == 0 assert res.addresses[0].used == False
def check_keys(self): print('Checking keys') wallet = Wallet() res = wallet.query_key('view_key') assert res.key == '49774391fa5e8d249fc2c5b45dadef13534bf2483dede880dac88f061e809100' res = wallet.query_key('spend_key') assert res.key == '148d78d2aba7dbca5cd8f6abcfb0b3c009ffbdbea1ff373d50ed94d78286640e' res = wallet.query_key('mnemonic') assert res.key == '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'
def mine(self): print("Mining some blocks") daemon = Daemon() wallet = Wallet() daemon.generateblocks( '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80) wallet.refresh()
def create(self): print('Creating wallet') wallet = Wallet() # close the wallet if any, will throw if none is loaded try: wallet.close_wallet() except: pass 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' res = wallet.restore_deterministic_wallet(seed = seed) assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert res.seed == seed
def create(self): print('Creating wallet') wallet = Wallet() # close the wallet if any, will throw if none is loaded try: wallet.close_wallet() except: pass 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' res = wallet.restore_deterministic_wallet(seed=seed)
def run_test(self): daemon = Daemon() wallet = Wallet() destinations = wallet.make_uniform_destinations('44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A',1,3) self._test_speed_generateblocks(daemon=daemon, blocks=70) for i in range(1, 10): while wallet.get_balance().unlocked_balance == 0: print('Waiting for wallet to refresh...') sleep(1) self._test_speed_transfer_split(wallet=wallet) self._test_speed_generateblocks(daemon=daemon, blocks=10)
def create_txes(self, address, ntxes): print('Creating ' + str(ntxes) + ' transactions') daemon = Daemon() wallet = Wallet() dst = {'address': address, 'amount': 1000000000000} txes = {} for i in range(ntxes): res = wallet.transfer([dst], get_tx_hex = True) txes[res.tx_hash] = res return txes
def create_txes(self, address, ntxes): print('Creating ' + str(ntxes) + ' transactions') daemon = Daemon() wallet = Wallet() dst = {'address': address, 'amount': 1000000000000} txes = {} for i in range(ntxes): res = wallet.transfer([dst], get_tx_hex=True) txes[res.tx_hash] = res return txes
def test_access_account(self): print('Testing access account') daemon = Daemon(idx=1) wallet = Wallet(idx=3) res = daemon.rpc_access_info(client=self.get_signature()) credits = res.credits res = daemon.rpc_access_account(self.get_signature(), 0) assert res.credits == credits res = daemon.rpc_access_account(self.get_signature(), 50) assert res.credits == credits + 50 res = daemon.rpc_access_account(self.get_signature(), -10) assert res.credits == credits + 40 res = daemon.rpc_access_account(self.get_signature(), -(credits + 50)) assert res.credits == 0 res = daemon.rpc_access_account(self.get_signature(), 2**63 - 5) assert res.credits == 2**63 - 5 res = daemon.rpc_access_account(self.get_signature(), 2**63 - 1) assert res.credits == 2**64 - 6 res = daemon.rpc_access_account(self.get_signature(), 2) assert res.credits == 2**64 - 4 res = daemon.rpc_access_account(self.get_signature(), 8) assert res.credits == 2**64 - 1 res = daemon.rpc_access_account(self.get_signature(), -1) assert res.credits == 2**64 - 2 res = daemon.rpc_access_account(self.get_signature(), -(2**63 - 1)) assert res.credits == 2**64 - 2 - (2**63 - 1) res = daemon.rpc_access_account(self.get_signature(), -(2**63 - 1)) assert res.credits == 0
def run_test(self): self.reset() daemon = Daemon() wallet = Wallet() # close the wallet if any, will throw if none is loaded try: wallet.close_wallet() except: pass wallet.restore_deterministic_wallet( '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' ) destinations = [] for i in range(3): destinations.append({ "amount": 1, "address": '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A' }) self._test_speed_generateblocks(daemon=daemon, blocks=70) for i in range(1, 10): while wallet.get_balance().unlocked_balance == 0: print('Waiting for wallet to refresh...') sleep(1) self._test_speed_transfer_split(wallet=wallet) self._test_speed_generateblocks(daemon=daemon, blocks=10)
def run_test(self): self.reset() daemon = Daemon() wallet = Wallet() # close the wallet if any, will throw if none is loaded try: wallet.close_wallet() except: pass wallet.restore_deterministic_wallet( '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' ) destinations = [] for i in range(3): destinations.append({ "amount": 1, "address": '888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H' }) self._test_speed_generateblocks(daemon=daemon, blocks=70) for i in range(1, 10): while wallet.get_balance().unlocked_balance == 0: print('Waiting for wallet to refresh...') sleep(1) self._test_speed_transfer_split(wallet=wallet) self._test_speed_generateblocks(daemon=daemon, blocks=10)
def languages(self): print('Testing languages') wallet = Wallet() res = wallet.get_languages() assert 'English' in res.languages assert 'English' in res.languages_local assert 'Dutch' in res.languages assert 'Nederlands' in res.languages_local assert 'Japanese' in res.languages assert u'日本語' in res.languages_local try: wallet.close_wallet() except: pass languages = res.languages for language in languages: print('Creating ' + str(language) + ' wallet') wallet.create_wallet(filename = '', language = language) res = wallet.query_key('mnemonic') wallet.close_wallet()
def test_access_payment(self): print('Testing access payment') daemon = Daemon(idx=1) wallet = Wallet(idx=3) # Try random nonces till we find one that's valid so we get a load of credits res = daemon.rpc_access_info(client = self.get_signature()) credits = res.credits cookie = res.cookie nonce = 0 while credits <= 100: nonce += 1 try: res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature()) break except: pass assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails res = daemon.rpc_access_info(client = self.get_signature()) credits = res.credits assert credits > 0 res = daemon.get_info(client = self.get_signature()) assert res.credits == credits - 1 credits = res.credits res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 100) block_hashes = res.blocks # ask for 1 block -> 1 credit res = daemon.getblockheadersrange(0, 0, client = self.get_signature()) assert res.credits == credits - 1 credits = res.credits # ask for 100 blocks -> >1 credit res = daemon.getblockheadersrange(1, 100, client = self.get_signature()) assert res.credits < credits - 1 credits = res.credits # external users res = daemon.rpc_access_pay(payment = 1, paying_for = 'foo', client = self.get_signature()) assert res.credits == credits - 1 res = daemon.rpc_access_pay(payment = 4, paying_for = 'bar', client = self.get_signature()) assert res.credits == credits - 5 res = daemon.rpc_access_pay(payment = credits, paying_for = 'baz', client = self.get_signature()) assert "PAYMENT REQUIRED" in res.status res = daemon.rpc_access_pay(payment = 2, paying_for = 'quux', client = self.get_signature()) assert res.credits == credits - 7 res = daemon.rpc_access_pay(payment = 3, paying_for = 'bar', client = self.get_signature()) assert res.credits == credits - 10 # that should be rejected because its cost is massive ok = False try: res = daemon.get_output_histogram(amounts = [], client = self.get_signature()) except Exception as e: print('e: ' + str(e)); ok = "PAYMENT REQUIRED" in e.status assert ok or "PAYMENT REQUIRED" in res.status
def create(self, idx): print('Creating hot and cold wallet') self.hot_wallet = Wallet(idx=0) # close the wallet if any, will throw if none is loaded try: self.hot_wallet.close_wallet() except: pass self.cold_wallet = Wallet(idx=1) # close the wallet if any, will throw if none is loaded try: self.cold_wallet.close_wallet() except: pass 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' res = self.cold_wallet.restore_deterministic_wallet(seed=seed) self.cold_wallet.set_daemon('127.0.0.1:11111', ssl_support="disabled") spend_key = self.cold_wallet.query_key("spend_key").key view_key = self.cold_wallet.query_key("view_key").key res = self.hot_wallet.generate_from_keys( viewkey=view_key, address= '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' ) ok = False try: res = self.hot_wallet.query_key("spend_key") except: ok = True assert ok ok = False try: self.hot_wallet.query_key("mnemonic") except: ok = True assert ok assert self.cold_wallet.query_key("view_key").key == view_key assert self.cold_wallet.get_address( ).address == self.hot_wallet.get_address().address
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 attributes(self): print('Testing attributes') wallet = Wallet() ok = False try: res = wallet.get_attribute('foo') except: ok = True assert ok res = wallet.set_attribute('foo', 'bar') res = wallet.get_attribute('foo') assert res.value == 'bar' res = wallet.set_attribute('foo', 'いっしゅん') res = wallet.get_attribute('foo') assert res.value == u'いっしゅん' ok = False try: res = wallet.get_attribute('いちりゅう') except: ok = True assert ok res = wallet.set_attribute('いちりゅう', 'いっぽう') res = wallet.get_attribute('いちりゅう') assert res.value == u'いっぽう'
def create(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', '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', ] self.wallet = [None] * len(seeds) for i in range(len(seeds)): self.wallet[i] = Wallet(idx = i) # close the wallet if any, will throw if none is loaded try: self.wallet[i].close_wallet() except: pass res = self.wallet[i].restore_deterministic_wallet(seed = seeds[i])
def create(self): print('Creating wallets') seeds = [ 'upbeat wade toenail italics maverick anybody eluded altitude tumbling emotion against okay inkling ankle karate stunning doing verification slid zinger cucumber blender dual extra wade verification', 'upbeat wade toenail italics maverick anybody eluded altitude tumbling emotion against okay inkling ankle karate stunning doing verification slid zinger cucumber blender dual extra wade verification', 'upbeat wade toenail italics maverick anybody eluded altitude tumbling emotion against okay inkling ankle karate stunning doing verification slid zinger cucumber blender dual extra wade verification', ] self.wallet = [None] * len(seeds) for i in range(len(seeds)): self.wallet[i] = Wallet(idx=i) # close the wallet if any, will throw if none is loaded try: self.wallet[i].close_wallet() except: pass res = self.wallet[i].restore_deterministic_wallet(seed=seeds[i])
def test_free_access(self): print('Testing free access') daemon = Daemon(idx=0) wallet = Wallet(idx=0) res = daemon.rpc_access_info(client = self.get_signature()) assert res.credits_per_hash_found == 0 assert res.diff == 0 assert res.credits == 0 res = daemon.get_info(client = self.get_signature()) assert res.credits == 0 # any nonce will do here res = daemon.rpc_access_submit_nonce(nonce = 0, cookie = 0, client = self.get_signature()) assert res.credits == 0
class AddressValidationTest(): def run_test(self): self.create() self.check_bad_addresses() self.check_good_addresses() def create(self): print('Creating wallet') 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' address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' self.wallet = Wallet() # close the wallet if any, will throw if none is loaded try: self.wallet.close_wallet() except: pass res = self.wallet.restore_deterministic_wallet(seed = seed) assert res.address == address assert res.seed == seed def check_bad_addresses(self): print('Validating bad addresses') bad_addresses = ['', 'a', '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWD9', ' ', '@', '42ey'] for address in bad_addresses: res = self.wallet.validate_address(address, any_net_type = False) assert not res.valid res = self.wallet.validate_address(address, any_net_type = True) assert not res.valid def check_good_addresses(self): print('Validating good addresses') addresses = [ [ 'mainnet', '', '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' ], [ 'mainnet', '', '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW' ], [ 'testnet', '', '9ujeXrjzf7bfeK3KZdCqnYaMwZVFuXemPU8Ubw335rj2FN1CdMiWNyFV3ksEfMFvRp9L9qum5UxkP5rN9aLcPxbH1au4WAB' ], [ 'stagenet', '', '53teqCAESLxeJ1REzGMAat1ZeHvuajvDiXqboEocPaDRRmqWoVPzy46GLo866qRFjbNhfkNckyhST3WEvBviDwpUDd7DSzB' ], [ 'mainnet', 'i', '4BxSHvcgTwu25WooY4BVmgdcKwZu5EksVZSZkDd6ooxSVVqQ4ubxXkhLF6hEqtw96i9cf3cVfLw8UWe95bdDKfRQeYtPwLm1Jiw7AKt2LY' ], [ 'mainnet', 's', '8AsN91rznfkBGTY8psSNkJBg9SZgxxGGRUhGwRptBhgr5XSQ1XzmA9m8QAnoxydecSh5aLJXdrgXwTDMMZ1AuXsN1EX5Mtm' ], [ 'mainnet', 's', '86kKnBKFqzCLxtK1Jmx2BkNBDBSMDEVaRYMMyVbeURYDWs8uNGDZURKCA5yRcyMxHzPcmCf1q2fSdhQVcaKsFrtGRsdGfNk' ], [ 'testnet', 'i', 'AApMA1VuhiCaHzr5X2KXi2Zc9oJ3VaGjkfChxxpRpxkyKf1NetvbRbQTbFMrGkr85DjnEH7JsBaoUFsgKwZnmtnVWnoB8MDotCsLb7eWwz' ], [ 'testnet', 's', 'BdKg9udkvckC5T58a8Nmtb6BNsgRAxs7uA2D49sWNNX5HPW5Us6Wxu8QMXrnSx3xPBQQ2iu9kwEcRGAoiz6EPmcZKbF62GS' ], [ 'testnet', 's', 'BcFvPa3fT4gVt5QyRDe5Vv7VtUFao9ci8NFEy3r254KF7R1N2cNB5FYhGvrHbMStv4D6VDzZ5xtxeKV8vgEPMnDcNFuwZb9' ], [ 'stagenet', 'i', '5K8mwfjumVseCcQEjNbf59Um6R9NfVUNkHTLhhPCmNvgDLVS88YW5tScnm83rw9mfgYtchtDDTW5jEfMhygi27j1QYphX38hg6m4VMtN29' ], [ 'stagenet', 's', '73LhUiix4DVFMcKhsPRG51QmCsv8dYYbL6GcQoLwEEFvPvkVvc7BhebfA4pnEFF9Lq66hwvLqBvpHjTcqvpJMHmmNjPPBqa' ], [ 'stagenet', 's', '7A1Hr63MfgUa8pkWxueD5xBqhQczkusYiCMYMnJGcGmuQxa7aDBxN1G7iCuLCNB3VPeb2TW7U9FdxB27xKkWKfJ8VhUZthF' ], ] for any_net_type in [True, False]: for address in addresses: res = self.wallet.validate_address(address[2], any_net_type = any_net_type) if any_net_type or address[0] == 'mainnet': assert res.valid assert res.integrated == (address[1] == 'i') assert res.subaddress == (address[1] == 's') assert res.nettype == address[0] else: assert not res.valid
def create(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.address = [ '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW', ] self.wallet = [None, None] for i in range(2): self.wallet[i] = Wallet(idx = i) # close the wallet if any, will throw if none is loaded try: self.wallet[i].close_wallet() except: pass res = self.wallet[i].restore_deterministic_wallet(seed = seeds[i]) assert res.address == self.address[i] assert res.seed == seeds[i]
class GetOutputDistributionTest(): def run_test(self): self.reset() self.create() self.test_get_output_distribution() def reset(self): print('Resetting blockchain') daemon = Daemon() res = daemon.get_height() daemon.pop_blocks(res.height - 1) daemon.flush_txpool() def create(self): self.wallet = Wallet() # close the wallet if any, will throw if none is loaded try: self.wallet.close_wallet() except: pass res = self.wallet.restore_deterministic_wallet( 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' ) def test_get_output_distribution(self): print("Test get_output_distribution") daemon = Daemon() res = daemon.get_output_distribution([0], 0, 0) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 1 assert d.distribution[0] == 0 res = daemon.generateblocks( '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1) res = daemon.get_output_distribution([0], 0, 0) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 2 assert d.distribution[0] == 0 assert d.distribution[1] == 1 res = daemon.pop_blocks(1) res = daemon.get_output_distribution([0], 0, 0) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 1 assert d.distribution[0] == 0 res = daemon.generateblocks( '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 3) res = daemon.get_output_distribution([0], 0, 0, cumulative=True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 4 assert d.distribution[0] == 0 assert d.distribution[1] == 1 assert d.distribution[2] == 2 assert d.distribution[3] == 3 # extend res = daemon.generateblocks( '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80) res = daemon.get_output_distribution([0], 0, 0, cumulative=True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 84 for h in range(len(d.distribution)): assert d.distribution[h] == h # pop and replace, this will do through the "trim and extend" path res = daemon.pop_blocks(2) self.wallet.refresh() dst = { 'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000 } self.wallet.transfer([dst]) res = daemon.generateblocks( '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1) for step in range( 3 ): # the second will be cached, the third will also be cached, but we get it in non-cumulative mode res = daemon.get_output_distribution([0], 0, 0, cumulative=step < 3) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 83 for h in range(len(d.distribution)): assert d.distribution[h] == (h if step < 3 else 1) + ( 2 if h == len(d.distribution) - 1 else 0) # start at 0, end earlier res = daemon.get_output_distribution([0], 0, 40, cumulative=True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 41 for h in range(len(d.distribution)): assert d.distribution[h] == h # start after 0, end earlier res = daemon.get_output_distribution([0], 10, 20, cumulative=True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 9 assert d.binary == False assert len(d.distribution) == 11 for h in range(len(d.distribution)): assert d.distribution[h] == 10 + h # straddling up res = daemon.get_output_distribution([0], 15, 25, cumulative=True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 14 assert d.binary == False assert len(d.distribution) == 11 for h in range(len(d.distribution)): assert d.distribution[h] == 15 + h # straddling down res = daemon.get_output_distribution([0], 8, 18, cumulative=True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 7 assert d.binary == False assert len(d.distribution) == 11 for h in range(len(d.distribution)): assert d.distribution[h] == 8 + h # encompassing res = daemon.get_output_distribution([0], 5, 20, cumulative=True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 4 assert d.binary == False assert len(d.distribution) == 16 for h in range(len(d.distribution)): assert d.distribution[h] == 5 + h # single res = daemon.get_output_distribution([0], 2, 2, cumulative=True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 1 assert d.binary == False assert len(d.distribution) == 1 assert d.distribution[0] == 2 # a non existent amount res = daemon.get_output_distribution([1], 0, 0) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 1 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 83 for h in range(len(d.distribution)): assert d.distribution[h] == 0
def change_password(self): print('Testing password change') wallet = Wallet() # close the wallet if any, will throw if none is loaded try: wallet.close_wallet() except: pass self.remove_wallet_files('test1') 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' res = wallet.restore_deterministic_wallet(seed=seed, filename='test1') assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert res.seed == seed wallet.close_wallet() res = wallet.open_wallet('test1', password='') res = wallet.get_address() assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' res = wallet.change_wallet_password(old_password='', new_password='******') wallet.close_wallet() ok = False try: res = wallet.open_wallet('test1', password='') except: ok = True assert ok res = wallet.open_wallet('test1', password='******') res = wallet.get_address() assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' wallet.close_wallet() self.remove_wallet_files('test1')
def open_close(self): print('Testing open/close') wallet = Wallet() res = wallet.get_address() assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' wallet.close_wallet() ok = False try: res = wallet.get_address() except: ok = True assert ok wallet.restore_deterministic_wallet( seed= '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' ) res = wallet.get_address() assert res.address == '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW' wallet.close_wallet() ok = False try: wallet.get_address() except: ok = True assert ok wallet.restore_deterministic_wallet( 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' ) res = wallet.get_address() assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
def tags(self): print('Testing tags') wallet = Wallet() res = wallet.get_account_tags() assert not 'account_tags' in res or len(res.account_tags) == 0 ok = False try: res = wallet.get_accounts('tag') except: ok = True assert ok or not 'subaddress_accounts' in res or res.subaddress_accounts == 0 wallet.tag_accounts('tag0', [1]) res = wallet.get_account_tags() assert len(res.account_tags) == 1 assert res.account_tags[0].tag == 'tag0' assert res.account_tags[0].label == '' assert res.account_tags[0].accounts == [1] res = wallet.get_accounts('tag0') assert len(res.subaddress_accounts) == 1 assert res.subaddress_accounts[0].account_index == 1 assert res.subaddress_accounts[ 0].base_address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' assert res.subaddress_accounts[0].balance == 0 assert res.subaddress_accounts[0].unlocked_balance == 0 assert res.subaddress_accounts[0].label == 'idx1_new' assert res.subaddress_accounts[0].tag == 'tag0' wallet.untag_accounts([0]) res = wallet.get_account_tags() assert len(res.account_tags) == 1 assert res.account_tags[0].tag == 'tag0' assert res.account_tags[0].label == '' assert res.account_tags[0].accounts == [1] wallet.untag_accounts([1]) res = wallet.get_account_tags() assert not 'account_tags' in res or len(res.account_tags) == 0 wallet.tag_accounts('tag0', [0]) wallet.tag_accounts('tag1', [1]) res = wallet.get_account_tags() assert len(res.account_tags) == 2 x = [x for x in res.account_tags if x.tag == 'tag0'] assert len(x) == 1 assert x[0].tag == 'tag0' assert x[0].label == '' assert x[0].accounts == [0] x = [x for x in res.account_tags if x.tag == 'tag1'] assert len(x) == 1 assert x[0].tag == 'tag1' assert x[0].label == '' assert x[0].accounts == [1] wallet.tag_accounts('tagA', [0, 1]) res = wallet.get_account_tags() assert len(res.account_tags) == 1 assert res.account_tags[0].tag == 'tagA' assert res.account_tags[0].label == '' assert res.account_tags[0].accounts == [0, 1] wallet.tag_accounts('tagB', [1, 0]) res = wallet.get_account_tags() assert len(res.account_tags) == 1 assert res.account_tags[0].tag == 'tagB' assert res.account_tags[0].label == '' assert res.account_tags[0].accounts == [0, 1] wallet.set_account_tag_description('tagB', 'tag B') res = wallet.get_account_tags() assert len(res.account_tags) == 1 assert res.account_tags[0].tag == 'tagB' assert res.account_tags[0].label == 'tag B' assert res.account_tags[0].accounts == [0, 1] res = wallet.get_accounts('tagB') assert len(res.subaddress_accounts) == 2 subaddress_accounts = [] for x in res.subaddress_accounts: assert x.balance == 0 assert x.unlocked_balance == 0 subaddress_accounts.append( (x.account_index, x.base_address, x.label)) assert sorted(subaddress_accounts) == [ (0, '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'main'), (1, '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', 'idx1_new') ]
def create_subaddresses(self): print('Creating subaddresses') wallet = Wallet() res = wallet.create_account("idx1") assert res.account_index == 1, res assert res.address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', res res = wallet.create_account("idx2") assert res.account_index == 2, res assert res.address == '8Bdb75y2MhvbkvaBnG7vYP6DCNneLWcXqNmfPmyyDkavAUUgrHQEAhTNK3jEq69kGPDrd3i5inPivCwTvvA12eQ4SJk9iyy', res res = wallet.get_address(0, 0) assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', res assert len(res.addresses) == 1 assert res.addresses[0].address_index == 0, res res = wallet.get_address(1, 0) assert res.address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', res assert len(res.addresses) == 1 assert res.addresses[0].label == 'idx1', res assert res.addresses[0].address_index == 0, res res = wallet.get_address(2, 0) assert res.address == '8Bdb75y2MhvbkvaBnG7vYP6DCNneLWcXqNmfPmyyDkavAUUgrHQEAhTNK3jEq69kGPDrd3i5inPivCwTvvA12eQ4SJk9iyy', res assert len(res.addresses) == 1 assert res.addresses[0].label == 'idx2', res assert res.addresses[0].address_index == 0, res res = wallet.create_address(0, "sub_0_1") res = wallet.create_address(1, "sub_1_1") res = wallet.create_address(1, "sub_1_2") res = wallet.get_address(0, [1]) assert len(res.addresses) == 1 assert res.addresses[ 0].address == '84QRUYawRNrU3NN1VpFRndSukeyEb3Xpv8qZjjsoJZnTYpDYceuUTpog13D7qPxpviS7J29bSgSkR11hFFoXWk2yNdsR9WF' assert res.addresses[0].label == 'sub_0_1' res = wallet.get_address(1, [1]) assert len(res.addresses) == 1 assert res.addresses[ 0].address == '87qyoPVaEcWikVBmG1TaP1KumZ3hB3Q5f4wZRjuppNdwYjWzs2RgbLYQgtpdu2YdoTT3EZhiUGaPJQt2FsykeFZbCtaGXU4' assert res.addresses[0].label == 'sub_1_1' res = wallet.get_address(1, [2]) assert len(res.addresses) == 1 assert res.addresses[ 0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' assert res.addresses[0].label == 'sub_1_2' res = wallet.get_address(1, [0, 1, 2]) assert len(res.addresses) == 3 assert res.addresses[ 0].address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' assert res.addresses[0].label == 'idx1' assert res.addresses[ 1].address == '87qyoPVaEcWikVBmG1TaP1KumZ3hB3Q5f4wZRjuppNdwYjWzs2RgbLYQgtpdu2YdoTT3EZhiUGaPJQt2FsykeFZbCtaGXU4' assert res.addresses[1].label == 'sub_1_1' assert res.addresses[ 2].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' assert res.addresses[2].label == 'sub_1_2' res = wallet.label_address((1, 2), "sub_1_2_new") res = wallet.get_address(1, [2]) assert len(res.addresses) == 1 assert res.addresses[ 0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' assert res.addresses[0].label == 'sub_1_2_new' res = wallet.label_account(1, "idx1_new") res = wallet.get_address(1, [0]) assert len(res.addresses) == 1 assert res.addresses[ 0].address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' assert res.addresses[0].label == 'idx1_new' res = wallet.get_address_index( '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' ) assert res.index == {'major': 1, 'minor': 2} res = wallet.get_address_index( '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' ) assert res.index == {'major': 0, 'minor': 0} res = wallet.get_address_index( '84QRUYawRNrU3NN1VpFRndSukeyEb3Xpv8qZjjsoJZnTYpDYceuUTpog13D7qPxpviS7J29bSgSkR11hFFoXWk2yNdsR9WF' ) assert res.index == {'major': 0, 'minor': 1} res = wallet.get_address_index( '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' ) assert res.index == {'major': 1, 'minor': 0} res = wallet.label_account(0, "main")
def mine(self): print("Test mining") daemon = Daemon() wallet = Wallet() # check info/height/balance before generating blocks res_info = daemon.get_info() prev_height = res_info.height res_getbalance = wallet.get_balance() prev_balance = res_getbalance.balance res_status = daemon.mining_status() res = daemon.start_mining('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', threads_count = 1) res_status = daemon.mining_status() assert res_status.active == True assert res_status.threads_count == 1 assert res_status.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert res_status.is_background_mining_enabled == False assert res_status.block_reward >= 600000000000 # wait till we mined a few of them timeout = 5 timeout_height = prev_height while True: time.sleep(1) res_info = daemon.get_info() height = res_info.height if height >= prev_height + 5: break if height > timeout_height: timeout = 5 timeout_height = height else: timeout -= 1 assert timeout >= 0 res = daemon.stop_mining() res_status = daemon.mining_status() assert res_status.active == False res_info = daemon.get_info() new_height = res_info.height wallet.refresh() res_getbalance = wallet.get_balance() balance = res_getbalance.balance assert balance >= prev_balance + (new_height - prev_height) * 600000000000 res = daemon.start_mining('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', threads_count = 1, do_background_mining = True) res_status = daemon.mining_status() assert res_status.active == True assert res_status.threads_count == 1 assert res_status.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert res_status.is_background_mining_enabled == True assert res_status.block_reward >= 600000000000 # don't wait, might be a while if the machine is busy, which it probably is res = daemon.stop_mining() res_status = daemon.mining_status() assert res_status.active == False
def create_subaddresses(self): print('Creating subaddresses') wallet = Wallet() res = wallet.create_account("idx1") assert res.account_index == 1, res assert res.address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', res res = wallet.create_account("idx2") assert res.account_index == 2, res assert res.address == '8Bdb75y2MhvbkvaBnG7vYP6DCNneLWcXqNmfPmyyDkavAUUgrHQEAhTNK3jEq69kGPDrd3i5inPivCwTvvA12eQ4SJk9iyy', res res = wallet.get_address(0, 0) assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', res assert len(res.addresses) == 1 assert res.addresses[0].address_index == 0, res res = wallet.get_address(1, 0) assert res.address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf', res assert len(res.addresses) == 1 assert res.addresses[0].label == 'idx1', res assert res.addresses[0].address_index == 0, res res = wallet.get_address(2, 0) assert res.address == '8Bdb75y2MhvbkvaBnG7vYP6DCNneLWcXqNmfPmyyDkavAUUgrHQEAhTNK3jEq69kGPDrd3i5inPivCwTvvA12eQ4SJk9iyy', res assert len(res.addresses) == 1 assert res.addresses[0].label == 'idx2', res assert res.addresses[0].address_index == 0, res res = wallet.create_address(0, "sub_0_1") res = wallet.create_address(1, "sub_1_1") res = wallet.create_address(1, "sub_1_2") res = wallet.get_address(0, [1]) assert len(res.addresses) == 1 assert res.addresses[0].address == '84QRUYawRNrU3NN1VpFRndSukeyEb3Xpv8qZjjsoJZnTYpDYceuUTpog13D7qPxpviS7J29bSgSkR11hFFoXWk2yNdsR9WF' assert res.addresses[0].label == 'sub_0_1' res = wallet.get_address(1, [1]) assert len(res.addresses) == 1 assert res.addresses[0].address == '87qyoPVaEcWikVBmG1TaP1KumZ3hB3Q5f4wZRjuppNdwYjWzs2RgbLYQgtpdu2YdoTT3EZhiUGaPJQt2FsykeFZbCtaGXU4' assert res.addresses[0].label == 'sub_1_1' res = wallet.get_address(1, [2]) assert len(res.addresses) == 1 assert res.addresses[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' assert res.addresses[0].label == 'sub_1_2' res = wallet.get_address(1, [0, 1, 2]) assert len(res.addresses) == 3 assert res.addresses[0].address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' assert res.addresses[0].label == 'idx1' assert res.addresses[1].address == '87qyoPVaEcWikVBmG1TaP1KumZ3hB3Q5f4wZRjuppNdwYjWzs2RgbLYQgtpdu2YdoTT3EZhiUGaPJQt2FsykeFZbCtaGXU4' assert res.addresses[1].label == 'sub_1_1' assert res.addresses[2].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' assert res.addresses[2].label == 'sub_1_2' res = wallet.label_address((1, 2), "sub_1_2_new") res = wallet.get_address(1, [2]) assert len(res.addresses) == 1 assert res.addresses[0].address == '87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB' assert res.addresses[0].label == 'sub_1_2_new' res = wallet.label_account(1, "idx1_new") res = wallet.get_address(1, [0]) assert len(res.addresses) == 1 assert res.addresses[0].address == '82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf' assert res.addresses[0].label == 'idx1_new' res = wallet.get_address_index('87KfgTZ8ER5D3Frefqnrqif11TjVsTPaTcp37kqqKMrdDRUhpJRczeR7KiBmSHF32UJLP3HHhKUDmEQyJrv2mV8yFDCq8eB') assert res.index == {'major': 1, 'minor': 2} res = wallet.get_address_index('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm') assert res.index == {'major': 0, 'minor': 0} res = wallet.get_address_index('84QRUYawRNrU3NN1VpFRndSukeyEb3Xpv8qZjjsoJZnTYpDYceuUTpog13D7qPxpviS7J29bSgSkR11hFFoXWk2yNdsR9WF') assert res.index == {'major': 0, 'minor': 1} res = wallet.get_address_index('82pP87g1Vkd3LUMssBCumk3MfyEsFqLAaGDf6oxddu61EgSFzt8gCwUD4tr3kp9TUfdPs2CnpD7xLZzyC1Ei9UsW3oyCWDf') assert res.index == {'major': 1, 'minor': 0}
def test_coinevo_uri(self): print('Testing coinevo: URI') wallet = Wallet() utf8string = [u'えんしゅう', u'あまやかす'] quoted_utf8string = [ urllib_quote(x.encode('utf8')) for x in utf8string ] ok = False try: res = wallet.make_uri() except: ok = True assert ok ok = False try: res = wallet.make_uri(address='') except: ok = True assert ok ok = False try: res = wallet.make_uri(address='kjshdkj') except: ok = True assert ok for address in [ '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', '4BxSHvcgTwu25WooY4BVmgdcKwZu5EksVZSZkDd6ooxSVVqQ4ubxXkhLF6hEqtw96i9cf3cVfLw8UWe95bdDKfRQeYtPwLm1Jiw7AKt2LY', '8AsN91rznfkBGTY8psSNkJBg9SZgxxGGRUhGwRptBhgr5XSQ1XzmA9m8QAnoxydecSh5aLJXdrgXwTDMMZ1AuXsN1EX5Mtm' ]: res = wallet.make_uri(address=address) assert res.uri == 'coinevo:' + address res = wallet.parse_uri(res.uri) assert res.uri.address == address assert res.uri.payment_id == '' assert res.uri.amount == 0 assert res.uri.tx_description == '' assert res.uri.recipient_name == '' assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 res = wallet.make_uri(address=address, amount=11000000000) assert res.uri == 'coinevo:' + address + '?tx_amount=0.011' or res.uri == 'coinevo:' + address + '?tx_amount=0.011000000000' res = wallet.parse_uri(res.uri) assert res.uri.address == address assert res.uri.payment_id == '' assert res.uri.amount == 11000000000 assert res.uri.tx_description == '' assert res.uri.recipient_name == '' assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' res = wallet.make_uri(address=address, tx_description=utf8string[0]) assert res.uri == 'coinevo:' + address + '?tx_description=' + quoted_utf8string[ 0] res = wallet.parse_uri(res.uri) assert res.uri.address == address assert res.uri.payment_id == '' assert res.uri.amount == 0 assert res.uri.tx_description == utf8string[0] assert res.uri.recipient_name == '' assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 res = wallet.make_uri(address=address, recipient_name=utf8string[0]) assert res.uri == 'coinevo:' + address + '?recipient_name=' + quoted_utf8string[ 0] res = wallet.parse_uri(res.uri) assert res.uri.address == address assert res.uri.payment_id == '' assert res.uri.amount == 0 assert res.uri.tx_description == '' assert res.uri.recipient_name == utf8string[0] assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 res = wallet.make_uri(address=address, recipient_name=utf8string[0], tx_description=utf8string[1]) assert res.uri == 'coinevo:' + address + '?recipient_name=' + quoted_utf8string[ 0] + '&tx_description=' + quoted_utf8string[1] res = wallet.parse_uri(res.uri) assert res.uri.address == address assert res.uri.payment_id == '' assert res.uri.amount == 0 assert res.uri.tx_description == utf8string[1] assert res.uri.recipient_name == utf8string[0] assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 res = wallet.make_uri(address=address, recipient_name=utf8string[0], tx_description=utf8string[1], amount=1000000000000) assert res.uri == 'coinevo:' + address + '?tx_amount=1.000000000000&recipient_name=' + quoted_utf8string[ 0] + '&tx_description=' + quoted_utf8string[1] res = wallet.parse_uri(res.uri) assert res.uri.address == address assert res.uri.payment_id == '' assert res.uri.amount == 1000000000000 assert res.uri.tx_description == utf8string[1] assert res.uri.recipient_name == utf8string[0] assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 res = wallet.make_uri(address=address, recipient_name=utf8string[0], tx_description=utf8string[1], amount=1000000000000, payment_id='1' * 64) assert res.uri == 'coinevo:' + address + '?tx_payment_id=' + '1' * 64 + '&tx_amount=1.000000000000&recipient_name=' + quoted_utf8string[ 0] + '&tx_description=' + quoted_utf8string[1] res = wallet.parse_uri(res.uri) assert res.uri.address == address assert res.uri.payment_id == '1' * 64 assert res.uri.amount == 1000000000000 assert res.uri.tx_description == utf8string[1] assert res.uri.recipient_name == utf8string[0] assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 # spaces must be encoded as %20 res = wallet.make_uri(address=address, tx_description=' ' + utf8string[1] + ' ' + utf8string[0] + ' ', amount=1000000000000) assert res.uri == 'coinevo:' + address + '?tx_amount=1.000000000000&tx_description=%20' + quoted_utf8string[ 1] + '%20' + quoted_utf8string[0] + '%20' res = wallet.parse_uri(res.uri) assert res.uri.address == address assert res.uri.payment_id == '' assert res.uri.amount == 1000000000000 assert res.uri.tx_description == ' ' + utf8string[ 1] + ' ' + utf8string[0] + ' ' assert res.uri.recipient_name == '' assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 # the example from the docs res = wallet.parse_uri( 'coinevo:46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcuwufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em?tx_amount=239.39014&tx_description=donation' ) assert res.uri.address == '46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcuwufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em' assert res.uri.amount == 239390140000000 assert res.uri.tx_description == 'donation' assert res.uri.recipient_name == '' assert res.uri.payment_id == '' assert not 'unknown_parameters' in res or len( res.unknown_parameters) == 0 # malformed/invalid for uri in [ '', ':', 'coinevo', 'notcoinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'COINEVO:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'COINEVO::42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'coinevo:', 'coinevo:badaddress', 'coinevo:tx_amount=10', 'coinevo:?tx_amount=10', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=-1', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=1e12', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=+12', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=1+2', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=A', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=0x2', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=222222222222222222222', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDn?tx_amount=10', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount=', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount=10=', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount=10=&', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm&tx_amount=10=&foo=bar', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_amount=10&tx_amount=20', 'coinevo:42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm?tx_payment_id=1111111111111111', 'coinevo:4BxSHvcgTwu25WooY4BVmgdcKwZu5EksVZSZkDd6ooxSVVqQ4ubxXkhLF6hEqtw96i9cf3cVfLw8UWe95bdDKfRQeYtPwLm1Jiw7AKt2LY?tx_payment_id=' + '1' * 64, 'coinevo:9ujeXrjzf7bfeK3KZdCqnYaMwZVFuXemPU8Ubw335rj2FN1CdMiWNyFV3ksEfMFvRp9L9qum5UxkP5rN9aLcPxbH1au4WAB', 'coinevo:5K8mwfjumVseCcQEjNbf59Um6R9NfVUNkHTLhhPCmNvgDLVS88YW5tScnm83rw9mfgYtchtDDTW5jEfMhygi27j1QYphX38hg6m4VMtN29', 'coinevo:7A1Hr63MfgUa8pkWxueD5xBqhQczkusYiCMYMnJGcGmuQxa7aDBxN1G7iCuLCNB3VPeb2TW7U9FdxB27xKkWKfJ8VhUZthF', ]: ok = False try: res = wallet.parse_uri(uri) except: ok = True assert ok, res # unknown parameters but otherwise valid res = wallet.parse_uri('coinevo:' + address + '?tx_amount=239.39014&foo=bar') assert res.uri.address == address assert res.uri.amount == 239390140000000 assert res.unknown_parameters == ['foo=bar'], res res = wallet.parse_uri('coinevo:' + address + '?tx_amount=239.39014&foo=bar&baz=quux') assert res.uri.address == address assert res.uri.amount == 239390140000000 assert res.unknown_parameters == ['foo=bar', 'baz=quux'], res res = wallet.parse_uri('coinevo:' + address + '?tx_amount=239.39014&%20=%20') assert res.uri.address == address assert res.uri.amount == 239390140000000 assert res.unknown_parameters == ['%20=%20'], res res = wallet.parse_uri('coinevo:' + address + '?tx_amount=239.39014&unknown=' + quoted_utf8string[0]) assert res.uri.address == address assert res.uri.amount == 239390140000000 assert res.unknown_parameters == [u'unknown=' + quoted_utf8string[0] ], res
class ColdSigningTest(): def run_test(self): self.reset() self.create(0) self.mine() self.transfer() def reset(self): print('Resetting blockchain') daemon = Daemon() daemon.pop_blocks(1000) daemon.flush_txpool() def create(self, idx): print('Creating hot and cold wallet') self.hot_wallet = Wallet(idx = 0) # close the wallet if any, will throw if none is loaded try: self.hot_wallet.close_wallet() except: pass self.cold_wallet = Wallet(idx = 1) # close the wallet if any, will throw if none is loaded try: self.cold_wallet.close_wallet() except: pass 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' res = self.cold_wallet.restore_deterministic_wallet(seed = seed) self.cold_wallet.set_daemon('127.0.0.1:11111', ssl_support = "disabled") spend_key = self.cold_wallet.query_key("spend_key").key view_key = self.cold_wallet.query_key("view_key").key res = self.hot_wallet.generate_from_keys(viewkey = view_key, address = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm') ok = False try: res = self.hot_wallet.query_key("spend_key") except: ok = True assert ok ok = False try: self.hot_wallet.query_key("mnemonic") except: ok = True assert ok assert self.cold_wallet.query_key("view_key").key == view_key assert self.cold_wallet.get_address().address == self.hot_wallet.get_address().address def mine(self): print("Mining some blocks") daemon = Daemon() wallet = Wallet() daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80) wallet.refresh() def transfer(self): daemon = Daemon() print("Creating transaction in hot wallet") dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000} payment_id = '1234500000012345abcde00000abcdeff1234500000012345abcde00000abcde' self.hot_wallet.refresh() res = self.hot_wallet.export_outputs() self.cold_wallet.import_outputs(res.outputs_data_hex) res = self.cold_wallet.export_key_images(True) self.hot_wallet.import_key_images(res.signed_key_images, offset = res.offset) res = self.hot_wallet.transfer([dst], ring_size = 11, payment_id = payment_id, get_tx_key = False) assert len(res.tx_hash) == 32*2 txid = res.tx_hash assert len(res.tx_key) == 0 assert res.amount > 0 amount = res.amount assert res.fee > 0 fee = res.fee assert len(res.tx_blob) == 0 assert len(res.tx_metadata) == 0 assert len(res.multisig_txset) == 0 assert len(res.unsigned_txset) > 0 unsigned_txset = res.unsigned_txset print('Signing transaction with cold wallet') res = self.cold_wallet.describe_transfer(unsigned_txset = unsigned_txset) assert len(res.desc) == 1 desc = res.desc[0] assert desc.amount_in >= amount + fee assert desc.amount_out == desc.amount_in - fee assert desc.ring_size == 11 assert desc.unlock_time == 0 assert desc.payment_id == payment_id assert desc.change_amount == desc.amount_in - 1000000000000 - fee assert desc.change_address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert desc.fee == fee assert len(desc.recipients) == 1 rec = desc.recipients[0] assert rec.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert rec.amount == 1000000000000 res = self.cold_wallet.sign_transfer(unsigned_txset) assert len(res.signed_txset) > 0 signed_txset = res.signed_txset assert len(res.tx_hash_list) == 1 txid = res.tx_hash_list[0] assert len(txid) == 64 print('Submitting transaction with hot wallet') res = self.hot_wallet.submit_transfer(signed_txset) assert len(res.tx_hash_list) > 0 assert res.tx_hash_list[0] == txid res = self.hot_wallet.get_transfers() 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) self.hot_wallet.refresh() res = self.hot_wallet.get_transfers() assert len([x for x in (res['pending'] if 'pending' in res else []) if x.txid == txid]) == 0 assert len([x for x in (res['out'] if 'out' in res else []) if x.txid == txid]) == 1 res = self.hot_wallet.get_tx_key(txid) assert len(res.tx_key) == 0 or res.tx_key == '01' + '0' * 62 # identity is used as placeholder res = self.cold_wallet.get_tx_key(txid) assert len(res.tx_key) == 64
def open_close(self): print('Testing open/close') wallet = Wallet() res = wallet.get_address() assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' wallet.close_wallet() ok = False try: res = wallet.get_address() except: ok = True assert ok wallet.restore_deterministic_wallet(seed = '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') res = wallet.get_address() assert res.address == '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW' wallet.close_wallet() ok = False try: wallet.get_address() except: ok = True assert ok wallet.restore_deterministic_wallet(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') res = wallet.get_address() assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
def __enter__(self): for i in range(4): Wallet(idx=i).auto_refresh(False)
def test_access_mining(self): print('Testing access mining') daemon = Daemon(idx=1) wallet = Wallet(idx=3) res = daemon.rpc_access_info(client=self.get_signature()) assert len(res.hashing_blob) > 39 assert res.height == 1 assert res.top_hash == '418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3' assert res.credits_per_hash_found == 5000 assert res.diff == 10 assert res.credits == 0 cookie = res.cookie # Try random nonces till we find one that's valid and one that's invalid nonce = 0 found_valid = 0 found_invalid = 0 last_credits = 0 loop_time = time.time() while found_valid == 0 or found_invalid == 0: nonce += 1 try: res = daemon.rpc_access_submit_nonce( nonce=nonce, cookie=cookie, client=self.get_signature()) found_valid += 1 assert res.credits == last_credits + 5000 except Exception as e: found_invalid += 1 res = daemon.rpc_access_info(client=self.get_signature()) cookie = res.cookie loop_time = time.time() assert res.credits < last_credits or res.credits == 0 assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails last_credits = res.credits if time.time() >= loop_time + 10: res = daemon.rpc_access_info(client=self.get_signature()) cookie = res.cookie loop_time = time.time() # we should now have 1 valid nonce, and a number of bad ones res = daemon.rpc_access_info(client=self.get_signature()) assert len(res.hashing_blob) > 39 assert res.height > 1 assert res.top_hash != '418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3' # here, any share matches network diff assert res.credits_per_hash_found == 5000 assert res.diff == 10 cookie = res.cookie res = daemon.rpc_access_data() assert len(res.entries) > 0 e = [x for x in res.entries if x['client'] == self.public_key] assert len(e) == 1 e = e[0] assert e.nonces_stale == 0 assert e.nonces_bad == found_invalid assert e.nonces_good == found_valid assert e.nonces_dupe == 0 # Try random nonces till we find one that's valid so we get a load of credits loop_time = time.time() while last_credits == 0: nonce += 1 try: res = daemon.rpc_access_submit_nonce( nonce=nonce, cookie=cookie, client=self.get_signature()) found_valid += 1 last_credits = res.credits break except: found_invalid += 1 assert nonce < 1000 # can't find a valid none -> the RPC probably fails if time.time() >= loop_time + 10: res = daemon.rpc_access_info(client=self.get_signature()) cookie = res.cookie loop_time = time.time() # we should now have at least 5000 res = daemon.rpc_access_info(client=self.get_signature()) assert res.credits == last_credits assert res.credits >= 5000 # last one was a valid nonce res = daemon.rpc_access_data() assert len(res.entries) > 0 e = [x for x in res.entries if x['client'] == self.public_key] assert len(e) == 1 e = e[0] assert e.nonces_stale == 0 assert e.nonces_bad == found_invalid assert e.nonces_good == found_valid assert e.nonces_dupe == 0 assert e.balance == 5000 assert e.credits_total >= 5000 # find a valid one, then check dupes aren't allowed res = daemon.rpc_access_info(client=self.get_signature()) cookie = res.cookie old_cookie = cookie # we keep that so can submit a stale later loop_time = time.time() while True: nonce += 1 try: res = daemon.rpc_access_submit_nonce( nonce=nonce, cookie=cookie, client=self.get_signature()) found_valid += 1 break except: found_invalid += 1 assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails if time.time() >= loop_time + 10: res = daemon.rpc_access_info(client=self.get_signature()) cookie = res.cookie loop_time = time.time() res = daemon.rpc_access_data() assert len(res.entries) > 0 e = [x for x in res.entries if x['client'] == self.public_key] assert len(e) == 1 e = e[0] assert e.nonces_stale == 0 assert e.nonces_bad == found_invalid assert e.nonces_good == found_valid assert e.nonces_dupe == 0 ok = False try: res = daemon.rpc_access_submit_nonce(nonce=nonce, cookie=cookie, client=self.get_signature()) except: ok = True assert ok res = daemon.rpc_access_data() assert len(res.entries) > 0 e = [x for x in res.entries if x['client'] == self.public_key] assert len(e) == 1 e = e[0] assert e.nonces_stale == 0 assert e.nonces_bad == found_invalid assert e.nonces_good == found_valid assert e.nonces_dupe == 1 # find stales without updating cookie, one within 5 seconds (accepted), one later (rejected) res = daemon.rpc_access_info(client=self.get_signature()) cookie = res.cookie # let the daemon update its timestamp, but use old cookie found_close_stale = 0 found_late_stale = 0 loop_time = time.time() while found_close_stale == 0 or found_late_stale == 0: nonce += 1 try: res = daemon.rpc_access_submit_nonce( nonce=nonce, cookie=cookie, client=self.get_signature()) found_close_stale += 1 found_valid += 1 time.sleep( 15 ) # now we've got an early stale, wait till they become late stales except Exception as e: #if e[0]['error']['code'] == -18: # stale if "'code': -18" in str( e ): # stale (ugly version, but also works with python 3) found_late_stale += 1 else: found_invalid += 1 assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails if time.time() >= loop_time + 10: res = daemon.rpc_access_info(client=self.get_signature()) # cookie = res.cookie # let the daemon update its timestamp, but use old cookie loop_time = time.time() res = daemon.rpc_access_data() assert len(res.entries) > 0 e = [x for x in res.entries if x['client'] == self.public_key] assert len(e) == 1 e = e[0] assert e.nonces_stale == found_late_stale # close stales are accepted, don't count here assert e.nonces_bad == found_invalid assert e.nonces_good == found_valid assert e.nonces_dupe == 1 # find very stale with old cookie (rejected) res = daemon.rpc_access_info(client=self.get_signature()) nonce += 1 ok = False try: res = daemon.rpc_access_submit_nonce(nonce=nonce, cookie=old_cookie, client=self.get_signature()) except: found_late_stale += 1 ok = True assert ok res = daemon.rpc_access_data() assert len(res.entries) > 0 e = [x for x in res.entries if x['client'] == self.public_key] assert len(e) == 1 e = e[0] assert e.nonces_stale == found_late_stale assert e.nonces_bad == found_invalid assert e.nonces_good == found_valid assert e.nonces_dupe == 1
def create_multisig_wallets(self, M_threshold, N_total, expected_address): print('Creating ' + str(M_threshold) + '/' + str(N_total) + ' multisig wallet') 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', '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', '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', ] assert M_threshold <= N_total assert N_total <= len(seeds) self.wallet = [None] * N_total info = [] for i in range(N_total): self.wallet[i] = Wallet(idx=i) try: self.wallet[i].close_wallet() except: pass res = self.wallet[i].restore_deterministic_wallet(seed=seeds[i]) res = self.wallet[i].prepare_multisig() assert len(res.multisig_info) > 0 info.append(res.multisig_info) for i in range(N_total): res = self.wallet[i].is_multisig() assert res.multisig == False addresses = [] next_stage = [] for i in range(N_total): res = self.wallet[i].make_multisig(info, M_threshold) addresses.append(res.address) next_stage.append(res.multisig_info) for i in range(N_total): res = self.wallet[i].is_multisig() assert res.multisig == True assert res.ready == (M_threshold == N_total) assert res.threshold == M_threshold assert res.total == N_total while True: n_empty = 0 for i in range(len(next_stage)): if len(next_stage[i]) == 0: n_empty += 1 assert n_empty == 0 or n_empty == len(next_stage) if n_empty == len(next_stage): break info = next_stage next_stage = [] addresses = [] for i in range(N_total): res = self.wallet[i].exchange_multisig_keys(info) next_stage.append(res.multisig_info) addresses.append(res.address) for i in range(N_total): assert addresses[i] == expected_address self.wallet_address = expected_address for i in range(N_total): res = self.wallet[i].is_multisig() assert res.multisig == True assert res.ready == True assert res.threshold == M_threshold assert res.total == N_total
class GetOutputDistributionTest(): def run_test(self): self.reset() self.create() self.test_get_output_distribution() def reset(self): print('Resetting blockchain') daemon = Daemon() daemon.pop_blocks(1000) daemon.flush_txpool() def create(self): self.wallet = Wallet() # close the wallet if any, will throw if none is loaded try: self.wallet.close_wallet() except: pass res = self.wallet.restore_deterministic_wallet(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') def test_get_output_distribution(self): print("Test get_output_distribution") daemon = Daemon() res = daemon.get_output_distribution([0], 0, 0) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 1 assert d.distribution[0] == 0 res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1) res = daemon.get_output_distribution([0], 0, 0) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 2 assert d.distribution[0] == 0 assert d.distribution[1] == 1 res = daemon.pop_blocks(1) res = daemon.get_output_distribution([0], 0, 0) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 1 assert d.distribution[0] == 0 res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 3) res = daemon.get_output_distribution([0], 0, 0, cumulative = True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 4 assert d.distribution[0] == 0 assert d.distribution[1] == 1 assert d.distribution[2] == 2 assert d.distribution[3] == 3 # extend res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 80) res = daemon.get_output_distribution([0], 0, 0, cumulative = True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 84 for h in range(len(d.distribution)): assert d.distribution[h] == h # pop and replace, this will do through the "trim and extend" path res = daemon.pop_blocks(2) self.wallet.refresh() dst = {'address': '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 'amount': 1000000000000} self.wallet.transfer([dst]) res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1) for step in range(3): # the second will be cached, the third will also be cached, but we get it in non-cumulative mode res = daemon.get_output_distribution([0], 0, 0, cumulative = step < 3) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 83 for h in range(len(d.distribution)): assert d.distribution[h] == (h if step < 3 else 1) + (2 if h == len(d.distribution) - 1 else 0) # start at 0, end earlier res = daemon.get_output_distribution([0], 0, 40, cumulative = True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 41 for h in range(len(d.distribution)): assert d.distribution[h] == h # start after 0, end earlier res = daemon.get_output_distribution([0], 10, 20, cumulative = True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 9 assert d.binary == False assert len(d.distribution) == 11 for h in range(len(d.distribution)): assert d.distribution[h] == 10 + h # straddling up res = daemon.get_output_distribution([0], 15, 25, cumulative = True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 14 assert d.binary == False assert len(d.distribution) == 11 for h in range(len(d.distribution)): assert d.distribution[h] == 15 + h # straddling down res = daemon.get_output_distribution([0], 8, 18, cumulative = True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 7 assert d.binary == False assert len(d.distribution) == 11 for h in range(len(d.distribution)): assert d.distribution[h] == 8 + h # encompassing res = daemon.get_output_distribution([0], 5, 20, cumulative = True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 4 assert d.binary == False assert len(d.distribution) == 16 for h in range(len(d.distribution)): assert d.distribution[h] == 5 + h # single res = daemon.get_output_distribution([0], 2, 2, cumulative = True) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 0 assert d.base == 1 assert d.binary == False assert len(d.distribution) == 1 assert d.distribution[0] == 2 # a non existent amount res = daemon.get_output_distribution([1], 0, 0) assert len(res.distributions) == 1 d = res.distributions[0] assert d.amount == 1 assert d.base == 0 assert d.binary == False assert len(d.distribution) == 83 for h in range(len(d.distribution)): assert d.distribution[h] == 0
def __exit__(self, exc_type, exc_value, traceback): for i in range(4): Wallet(idx=i).auto_refresh(True)
def check(self): wallet = Wallet() print('Checking local address') res = wallet.make_integrated_address(payment_id = '0123456789abcdef') assert res.integrated_address == '4CMe2PUhs4J4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfSbLRB61BQVATzerHGj' assert res.payment_id == '0123456789abcdef' res = wallet.split_integrated_address(res.integrated_address) assert res.standard_address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert res.payment_id == '0123456789abcdef' print('Checking different address') res = wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', payment_id = '1122334455667788') assert res.integrated_address == '4GYjoMG9Y2BBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCVSs1ZojwrDCGS5rUuo' assert res.payment_id == '1122334455667788' res = wallet.split_integrated_address(res.integrated_address) assert res.standard_address == '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK' assert res.payment_id == '1122334455667788' print('Checking bad payment id') fails = 0 try: wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', payment_id = '11223344556677880') except: fails += 1 try: wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', payment_id = '112233445566778') except: fails += 1 try: wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', payment_id = '') except: fails += 1 try: wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', payment_id = '112233445566778g') except: fails += 1 try: wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', payment_id = '1122334455667788112233445566778811223344556677881122334455667788') except: fails += 1 assert fails == 5 print('Checking bad standard address') fails = 0 try: wallet.make_integrated_address(standard_address = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerr', payment_id = '1122334455667788') except: fails += 1 try: wallet.make_integrated_address(standard_address = '4GYjoMG9Y2BBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCVSs1ZojwrDCGS5rUuo', payment_id = '1122334455667788') except: fails += 1 assert fails == 2