Пример #1
0
def test_subtraction_result_below_zero_should_raise_exception(
        local_test_network_config):
    one_cro = CROCoin(1, CRO_DENOM, local_test_network_config)
    two_cro = CROCoin(2, CRO_DENOM, local_test_network_config)

    with pytest.raises(ValueError, match="Amount cannot be negative"):
        one_cro - two_cro
Пример #2
0
def test_crocoin_with_integer_amount(
        local_test_network_config: "NetworkConfig", amount):
    coin_with_denom = CROCoin(amount, local_test_network_config.coin_denom,
                              local_test_network_config)
    coin_with_base_denom = CROCoin(
        coin_with_denom.amount_base,
        local_test_network_config.coin_base_denom,
        local_test_network_config,
    )

    assert coin_with_denom == coin_with_base_denom
Пример #3
0
def test_addition_result_more_than_max_should_raise_exception(
        local_test_network_config):
    max_supply_cro = CROCoin(MAX_CRO_SUPPLY, CRO_DENOM,
                             local_test_network_config)
    one_cro = CROCoin(1, CRO_DENOM, local_test_network_config)

    with pytest.raises(
            ValueError,
            match=
            rf"^Input is more than maximum cro supply .* got 3000000000100000000basecro$",  # noqa: 501
    ):
        max_supply_cro + one_cro
Пример #4
0
def simple_transaction():
    client = GrpcClient(LOCAL_NETWORK)

    sending_wallet = Wallet(
        MNEMONIC_PHRASE, LOCAL_NETWORK.derivation_path, LOCAL_NETWORK.address_prefix
    )
    sending_account = client.query_account(sending_wallet.address)
    sending_account_init_bal = client.query_account_balance(sending_wallet.address)
    receiving_account_init_bal = client.query_account_balance(TO_ADDRESS)

    print(
        f"sending account initial balance: {sending_account_init_bal.balance.amount}"
        f"{sending_account_init_bal.balance.denom}"
    )
    print(
        f"receiving account initial balance: {receiving_account_init_bal.balance.amount}"
        f"{receiving_account_init_bal.balance.denom}"
    )

    ten_cro = CROCoin("10", "cro", LOCAL_NETWORK)
    one_cro_fee = CROCoin("1", "cro", LOCAL_NETWORK)

    msg_send = MsgSend(
        from_address=sending_wallet.address,
        to_address=TO_ADDRESS,
        amount=[ten_cro.protobuf_coin_message],
    )
    tx = Transaction(
        chain_id=LOCAL_NETWORK.chain_id,
        from_wallets=[sending_wallet],
        msgs=[msg_send],
        account_number=sending_account.account_number,
        fee=[one_cro_fee.protobuf_coin_message],
        client=client,
    )

    signature_alice = sending_wallet.sign(tx.sign_doc.SerializeToString())
    signed_tx = tx.set_signatures(signature_alice).signed_tx

    client.broadcast_transaction(signed_tx.SerializeToString())

    sending_account_aft_bal = client.query_account_balance(sending_wallet.address)
    receiving_account_aft_bal = client.query_account_balance(TO_ADDRESS)

    print("After transaction of sending 10cro with a 1cro fee:")
    print(
        f"sending account after balance: {sending_account_aft_bal.balance.amount}"
        f"{sending_account_aft_bal.balance.denom}"
    )
    print(
        f"receiving account after balance: {receiving_account_aft_bal.balance.amount}"
        f"{receiving_account_aft_bal.balance.denom}"
    )
Пример #5
0
def test_crocoin_with_wrong_unit_should_raise_exception(
        amount, wrong_unit, local_test_network_config: "NetworkConfig"):
    with pytest.raises(
            AssertionError,
            match=
            f"unit should be {local_test_network_config.coin_denom} or {local_test_network_config.coin_base_denom}, got {wrong_unit}",  # noqa: 501
    ):
        CROCoin(amount, wrong_unit, local_test_network_config)
Пример #6
0
def test_crocoin_beyond_max_supply_should_raise_exception(
        invalid_amount, unit, invalid_amount_base,
        local_test_network_config: "NetworkConfig"):

    with pytest.raises(
            ValueError,
            match=
            rf"^Input is more than maximum cro supply .* got {invalid_amount_base}basecro$",  # noqa: 501
    ):
        CROCoin(invalid_amount, unit, local_test_network_config)
def test_2_msgs_in_1_tx(blockchain_accounts,
                        local_test_network_config: "NetworkConfig"):
    client = GrpcClient(local_test_network_config)
    alice_info = get_blockchain_account_info(blockchain_accounts, ALICE)
    alice_wallet = Wallet(alice_info["mnemonic"])
    alice_account = client.query_account(alice_info["address"])
    bob_info = get_blockchain_account_info(blockchain_accounts, BOB)
    bob_wallet = Wallet(bob_info["mnemonic"])
    alice_bal_init = client.query_account_balance(alice_wallet.address)
    bob_bal_init = client.query_account_balance(bob_wallet.address)
    alice_coin_init = CROCoin(alice_bal_init.balance.amount,
                              alice_bal_init.balance.denom,
                              local_test_network_config)
    bob_coin_init = CROCoin(bob_bal_init.balance.amount,
                            bob_bal_init.balance.denom,
                            local_test_network_config)

    ten_cro = CROCoin("10", CRO_DENOM, local_test_network_config)
    twnenty_cro = CROCoin("20", CRO_DENOM, local_test_network_config)
    one_cro_fee = CROCoin("1", CRO_DENOM, local_test_network_config)
    msg_send_10_cro = MsgSend(
        from_address=alice_info["address"],
        to_address=bob_info["address"],
        amount=[ten_cro.protobuf_coin_message],
    )
    msg_send_20_cro = MsgSend(
        from_address=alice_info["address"],
        to_address=bob_info["address"],
        amount=[twnenty_cro.protobuf_coin_message],
    )

    tx = Transaction(
        chain_id=local_test_network_config.chain_id,
        from_wallets=[alice_wallet],
        msgs=[msg_send_10_cro],
        account_number=alice_account.account_number,
        fee=[one_cro_fee.protobuf_coin_message],
        client=client,
    ).append_message(msg_send_20_cro)

    signature_alice = alice_wallet.sign(tx.sign_doc.SerializeToString())
    signed_tx = tx.set_signatures(signature_alice).signed_tx

    client.broadcast_transaction(signed_tx.SerializeToString())

    alice_bal_aft = client.query_account_balance(alice_wallet.address)
    bob_bal_aft = client.query_account_balance(bob_wallet.address)
    alice_coin_aft = CROCoin(alice_bal_aft.balance.amount,
                             alice_bal_aft.balance.denom,
                             local_test_network_config)
    bob_coin_aft = CROCoin(bob_bal_aft.balance.amount,
                           bob_bal_aft.balance.denom,
                           local_test_network_config)

    assert alice_coin_aft == alice_coin_init - ten_cro - twnenty_cro - one_cro_fee
    assert bob_coin_aft == bob_coin_init + ten_cro + twnenty_cro
Пример #8
0
def test_crocoin_with_denom_input(local_test_network_config: "NetworkConfig",
                                  amount, expected_amount,
                                  expected_base_amount):
    cro_coin = CROCoin(amount, local_test_network_config.coin_denom,
                       local_test_network_config)

    assert cro_coin.amount == expected_amount
    assert cro_coin.amount_with_unit == f"{expected_amount}{local_test_network_config.coin_denom}"
    assert cro_coin.amount_base == expected_base_amount
    assert (
        cro_coin.amount_base_with_unit ==
        f"{expected_base_amount}{local_test_network_config.coin_base_denom}")
Пример #9
0
def test_crocoin_less_than_1basecro_should_raise_exception(
        invalid_amount, unit, local_test_network_config: "NetworkConfig"):
    with pytest.raises(ValueError, match="Amount is less than 1basecro"):
        CROCoin(invalid_amount, unit, local_test_network_config)
Пример #10
0
def test_crocoin_below_zero_should_raise_exception(
        below_zero_amount, unit, local_test_network_config: "NetworkConfig"):
    with pytest.raises(ValueError, match="Amount cannot be negative"):
        CROCoin(below_zero_amount, unit, local_test_network_config)