def transfer_transaction(wallet_sender, wallet_receiver, amount_cro, view_keys=[]): balance_sender_begin = wallet_sender.balance balance_receiver_begin = wallet_receiver.balance tx = Transaction(wallet_sender) view_keys.extend([wallet_receiver.view_key()]) tx.transfer(wallet_receiver.create_address("transfer"), amount_cro, view_keys=view_keys) balance_sender = wallet_sender.balance assert balance_sender["pending"] > 0 assert balance_sender[ "total"] == balance_sender_begin["total"] - amount_cro * CRO t = 0 while t < 30 and balance_sender["pending"] > 0: time.sleep(1) wallet_sender.sync(enable_fast_forward=False) balance_sender = wallet_sender.balance t += 1 wallet_receiver.sync(enable_fast_forward=False) balance_receiver = wallet_receiver.balance assert balance_sender[ "total"] == balance_sender_begin["total"] - amount_cro * CRO assert balance_receiver[ "total"] == balance_receiver_begin["total"] + amount_cro * CRO
def withdraw_transactions(wallet, staking_address, transfer_address=None, view_keys=[]): tx = Transaction(wallet) transfer_address = transfer_address or wallet.create_address() tx.withdraw(staking_address, transfer_address, view_keys=view_keys) i = 0 while i < 30: wallet.sync() balance = wallet.balance if balance["available"] > 0: break time.sleep(1)
def withdraw_transactions(wallet, staking_address): # test withdraw all unbounded tx = Transaction(wallet) tx.withdraw(staking_address, wallet.create_address()) i = 0 while i < 30: wallet.sync() balance = wallet.balance if balance["available"] >0: break time.sleep(1) assert balance["available"] == 500000000000000000
def deposit_transaction(wallet, staking_address, amount_cro): staking_state_before = wallet.state(staking_address) wallet_balance_begin = wallet.balance tx = Transaction(wallet) tx.deposit(staking_address, amount_cro) time.sleep(3) wallet.sync() wallet_balance_end = wallet.balance assert wallet_balance_begin["available"] == wallet_balance_end["available"] + amount_cro * CRO h = tx.history[-1] assert amount_cro*CRO == h["amount"] assert "OUT" == h["side"] staking_state_after = wallet.state(staking_address) assert staking_state_before['bonded'] + amount_cro*CRO == staking_state_after["bonded"]
def test_withdraw_to_other_wallet(): # the tx-query cert_validation is 200 (setted in .drone.yaml), check the cert refresh or not test_cert_expiration() state2 = wallet_2.state(staking_address_wallet_1) unbounded_transaction(wallet_1, staking_address_wallet_1, 10000) wallet_2.sync() state3 = wallet_2.state(staking_address_wallet_1) assert state3['bonded'] == state2['bonded'] - 10000 * CRO assert state3['unbonded'] == state2['unbonded'] + 10000 * CRO # the time must bigger than the max_age_duration(nano seconds) in tendermint genesis.json state3 = wallet_2.state(staking_address_wallet_1) time.sleep(10) withdraw_transactions(wallet_1, staking_address_wallet_1, wallet_2.create_address("transfer"), view_keys=[wallet_1.view_key(), wallet_2.view_key()]) # check the receiver wallet history time.sleep(3) wallet_2.sync() history = Transaction(wallet_2).history[-1] assert history["side"] == "IN" assert history["tx_type"] == "Withdraw" assert history["amount"] == 10000 * CRO state4 = wallet_2.state(staking_address_wallet_1) # check the staking state of staking_address_wallet_1 assert state3["unbonded"] - 10000 * CRO == state4["unbonded"]
def transfer_to_other_wallet(wallet_sender, wallet_receiver, amount_cro): balance_sender_begin = wallet_sender.balance balance_receiver_begin = wallet_receiver.balance tx = Transaction(wallet_sender) view_keys = [wallet_receiver.view_key()] tx.transfer(wallet_receiver.create_address(), amount_cro, view_keys=view_keys) balance_sender = wallet_sender.balance assert balance_sender["pending"] > 0 assert balance_sender["total"] == balance_sender_begin["total"] - amount_cro * CRO t = 0 while t < 30 and balance_sender["pending"] > 0: time.sleep(1) wallet_sender.sync() balance_sender = wallet_sender.balance t += 1 wallet_receiver.sync() balance_receiver = wallet_receiver.balance assert balance_sender["total"] == balance_sender_begin["total"] - amount_cro * CRO assert balance_receiver["total"] == balance_receiver_begin["total"] + amount_cro * CRO
def deposit_to_self_address_transaction(wallet, staking_address, amount_cro): wallet_balance_begin = wallet.balance tx = Transaction(wallet) tx_id = tx.deposit(staking_address, amount_cro) time.sleep(3) wallet.sync() t = 0 find_tx = False while t < 30 and not find_tx: time.sleep(1) wallet.sync() for tx_info in tx.history: if tx_info["tx_id"] == tx_id: find_tx = True assert tx_info["tx_type"] == "Deposit" assert tx_info["amount"] == amount_cro * CRO break wallet_balance_end = wallet.balance assert wallet_balance_begin["available"] == wallet_balance_end["available"] + amount_cro * CRO
def transfer_to_other_wallet(wallet_sender, wallet_receiver, amount_cro, sender_hardware=None, receiver_hardware=None): balance_sender_begin = wallet_sender.balance balance_receiver_begin = wallet_receiver.balance tx = Transaction(wallet_sender, sender_hardware) view_keys = [wallet_receiver.view_key()] tx.transfer(wallet_receiver.create_address("transfer", receiver_hardware), amount_cro, view_keys=view_keys) balance_sender = wallet_sender.balance assert balance_sender["pending"] > 0 assert balance_sender["total"] == balance_sender_begin["total"] - amount_cro * CRO t = 0 while t < 30 and balance_sender["pending"] > 0: time.sleep(1) wallet_sender.sync(disable_fast_forward=True) balance_sender = wallet_sender.balance t += 1 wallet_receiver.sync(disable_fast_forward=True) balance_receiver = wallet_receiver.balance assert balance_sender["total"] == balance_sender_begin["total"] - amount_cro * CRO assert balance_receiver["total"] == balance_receiver_begin["total"] + amount_cro * CRO
def test_transactions(): os.environ['CRYPTO_CLIENT_TENDERMINT'] = 'ws://localhost:26667/websocket' wallet_sender, _wallet_receiver = init_wallet() # test withdraw all unbounded tx = Transaction(wallet_sender) staking_address = "0x5e7e1e79d80b861a94598c721598951098dd3825" tx.withdraw(staking_address, wallet_sender.create_address()) i = 0 while i < 30: wallet_sender.sync() balance = wallet_sender.balance() if balance["available"] >0: break time.sleep(1) print(".", end='') if i % 10 == 0: print("\n", balance) i += 1 assert balance["available"] == 500000000000000000
def unbounded_transaction(wallet, staking_address, amount_cro): tx = Transaction(wallet) tx.unbond(staking_address, amount_cro) time.sleep(3) wallet.sync()