def test_wallet_persistence(): """ test the persistence of a wallet to a file. """ wallet.initialize_wallet() wallet.wallet_state["keys"] = [] my_key_pairs = keys[:] for _ in range(25): key_index = secrets.randbelow(len(my_key_pairs)) wallet.wallet_state["keys"].append(keys[key_index]) # remove any duplicates wallet.wallet_state["keys"] = list(set(wallet.wallet_state["keys"])) wallet.value_spent(0) wallet.value_received(0) wallet_str = json.dumps(wallet.wallet_state) wallet_copy = json.loads(wallet_str) assert wallet.save_wallet() == True assert wallet.load_wallet() == True assert wallet.wallet_state["received"] == wallet_copy["received"] assert wallet.wallet_state["spent"] == wallet_copy["spent"] assert wallet.wallet_state["received_last_block_scanned"] == wallet_copy["received_last_block_scanned"] assert wallet.wallet_state["spent_last_block_scanned"] == wallet_copy["spent_last_block_scanned"] max = len(wallet_copy["keys"]) ctr = 0 for ctr in range(max): assert wallet.wallet_state["keys"][ctr][0] == wallet_copy["keys"][ctr][0] assert wallet.wallet_state["keys"][ctr][1] == wallet_copy["keys"][ctr][1]
def test_one_received(): """ test that for a given public key owned by the wallet-holder, at least one transaction fragment exists in the wallet. """ wallet.initialize_wallet() wallet.wallet_state["keys"] = [] key_index = secrets.randbelow(len(keys)) wallet.wallet_state["keys"].append(keys[key_index]) ctr = 0 wallet.value_received(0) for received in wallet.wallet_state["received"]: if received["public_key"] == wallet.wallet_state["keys"][0][1]: ctr += 1 assert ctr >= 1
def test_received_and_spent(): """ test that if a transaction fragment is spent then it has also been received by the wallet-owner. """ wallet.initialize_wallet() wallet.wallet_state["keys"] = [] key_index = secrets.randbelow(len(keys)) wallet.wallet_state["keys"].append(keys[key_index]) wallet.value_received(0) wallet.value_spent(0) assert len(wallet.wallet_state["received"]) >= 1 for spent in wallet.wallet_state["spent"]: ctr = 0 assert spent["public_key"] == wallet.wallet_state[keys][0][1] ptr = spent["fragmentid"] for received in wallet.wallet_state["received"]: if received["fragmentid"] == ptr: ctr += 1 assert ctr == 1 ctr = 0
def test_values_spent(index): """ test that values spent pertain to public keys owned by the wallet-owner. Note: At least 55 private-public keys must hav been generated. """ wallet.initialize_wallet() wallet.wallet_state["keys"] = [] my_key_pairs = keys[:] for _ in range(index): key_index = secrets.randbelow(len(my_key_pairs)) wallet.wallet_state["keys"].append(keys[key_index]) # remove any duplicates wallet.wallet_state["keys"] = list(set(wallet.wallet_state["keys"])) my_public_keys = [] for key_pair in wallet.wallet_state["keys"]: my_public_keys.append(key_pair[1]) wallet.value_spent(0) for spent in wallet.wallet_state["spent"]: assert spent["public_key"] in my_public_keys
def test_values_received(index): """ test that each value received by the wallet-owner pertains to a public key owned by the wallet-owner. Note: At least 55 private-public keys must have been generated. """ wallet.initialize_wallet() wallet.wallet_state["keys"] = [] my_key_pairs = keys[:] for _ in range(index): key_index = secrets.randbelow(len(my_key_pairs)) wallet.wallet_state["keys"].append(keys[key_index]) # remove any duplicates wallet.wallet_state["keys"] = list(set(wallet.wallet_state["keys"])) my_public_keys = [] for key_pair in wallet.wallet_state["keys"]: my_public_keys.append(key_pair[1]) wallet.value_received(0) for received in wallet.wallet_state["received"]: assert received["public_key"] in my_public_keys
assert interactive password = "" while len(password) < config.WALLET_PASSWORD_LENGTH: res = wallet.make_wallet_password( prompt="Creating new application wallet", password=password) if 'error' in res: print res['error'] continue else: password = res['password'] break pk_hex = keylib.ECPrivateKey().to_hex() res = wallet.initialize_wallet(password=password, interactive=interactive, hex_privkey=pk_hex, config_dir=config_dir, wallet_path=wallet_path) if 'error' in res: log.error("Failed to create wallet '%s.%s@%s': %s" % (app_account_id, app_name, name, res['error'])) return res pub_hex = keylib.ECPrivateKey(pk_hex).public_key().to_hex() # preferred storage drivers? conf = config.get_config(config_path) if app_storage_drivers is None: app_storage_drivers = conf['storage_drivers'] if proxy is None: