def test_sign_offline(cluster): """ check simple transfer tx success - send 1cro from community to reserve """ # 1. first create two hd new wallet seed = "dune car envelope chuckle elbow slight proud fury remove candy uphold \ puzzle call select sibling sport gadget please want vault glance verb damage gown" wallet_1 = Wallet(seed) address_1 = wallet_1.address wallet_2 = Wallet.new() address_2 = wallet_2.address sender_addr = cluster.address("signer1") sender_balance = cluster.balance(sender_addr) assert sender_balance > 100 * 10**8 balance_1 = cluster.balance(wallet_1.address) assert balance_1 == 0 balance_2 = cluster.balance(wallet_2.address) assert balance_2 == 0 # 2. transfer some coin to wallet_1 cluster.transfer(sender_addr, address_1, "100cro") wait_for_new_blocks(cluster, 2) assert cluster.balance(sender_addr) == sender_balance - 100 * 10**8 assert cluster.balance(address_1) == 100 * 10**8 # 3. get the send's account info port = ports.api_port(cluster.base_port(0)) api = ApiUtil(port) amount = 1 * 10**8 # make transaction without/with fee for fee in [0, 600000]: sender_account_info = api.account_info(address_1) balance_1_before = api.balance(address_1) balance_2_before = api.balance(address_2) tx = Transaction( wallet=wallet_1, account_num=sender_account_info["account_num"], sequence=sender_account_info["sequence"], chain_id=cluster.chain_id, fee=fee, ) tx.add_transfer(to_address=address_2, amount=amount, base_denom="basecro") signed_tx = tx.get_pushable() assert isinstance(signed_tx, dict) api.broadcast_tx(signed_tx) wait_for_new_blocks(cluster, 3) balance_1_after = api.balance(address_1) balance_2_after = api.balance(address_2) assert balance_2_after == balance_2_before + amount assert balance_1_after == balance_1_before - amount - fee
def test_multi_signature_batch(cluster, tmp_path): # prepare files m_txt = tmp_path / "bm.txt" p1_txt = tmp_path / "bp1.txt" p2_txt = tmp_path / "bp2.txt" tx_txt = tmp_path / "btx.txt" multi_wallet_name = "multitest2" # make multi-sig cluster.make_multisig(multi_wallet_name, "msigner1", "msigner2") multi_addr = cluster.address(multi_wallet_name) signer1_addr = cluster.address("msigner1") signer2_addr = cluster.address("msigner2") # send amount to multi-sig cluster.transfer(signer1_addr, multi_addr, "500basecro") wait_for_new_blocks(cluster, 1) multi_balance = cluster.balance(multi_addr) assert 500 == multi_balance signer1_balance = cluster.balance(signer1_addr) signer2_balance = cluster.balance(signer2_addr) # send amount from multisig to msigner1 and msigner2 with open(m_txt, "a") as f: multi_tx = cluster.transfer(multi_addr, signer1_addr, "100basecro", generate_only=True) f.write(json.dumps(multi_tx)) f.write("\n") multi_tx = cluster.transfer(multi_addr, signer2_addr, "100basecro", generate_only=True) f.write(json.dumps(multi_tx)) # multisign the tx port = ports.api_port(cluster.base_port(0)) api = ApiUtil(port) multi_account_info = api.account_info(multi_addr) account_num = multi_account_info["account_num"] sequence = multi_account_info["sequence"] signature2 = cluster.sign_batch_multisig_tx(m_txt, multi_addr, "msigner1", account_num, sequence) with open(p1_txt, "w") as f: f.write(signature2) signature3 = cluster.sign_batch_multisig_tx(m_txt, multi_addr, "msigner2", account_num, sequence) with open(p2_txt, "w") as f: f.write(signature3) final_multi_tx = cluster.combine_batch_multisig_tx(m_txt, multi_wallet_name, p1_txt, p2_txt) for line in final_multi_tx.splitlines(): with open(tx_txt, "w") as f: f.write(line) assert len(line) > 0 cluster.broadcast_tx(tx_txt) # check multisig balance multi_balance = cluster.balance(multi_addr) wait_for_new_blocks(cluster, 4) assert 300 == multi_balance # check singer2 balance assert cluster.balance(signer1_addr) == signer1_balance + 100 assert cluster.balance(signer2_addr) == signer2_balance + 100