示例#1
0
def test_msg_request_creation_min_count_fail():
    msg_request = MsgRequest(
        oracle_script_id=1,
        calldata=bytes.fromhex("000000034254430000000000000001"),
        ask_count=3,
        min_count=0,
        client_id="from_pyband",
        sender=Address.from_acc_bech32("band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
    )
    with pytest.raises(ValueError, match="invalid min count got: min count: 0"):
        msg_request.validate()
示例#2
0
def test_msg_request_creation_client_id_count_fail():
    msg_request = MsgRequest(
        oracle_script_id=1,
        calldata=bytes.fromhex("000000034254430000000000000001"),
        ask_count=3,
        min_count=2,
        client_id="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum",
        sender=Address.from_acc_bech32("band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
    )
    with pytest.raises(ValueError, match="too long client id"):
        msg_request.validate()
示例#3
0
def test_msg_request_creation_oracle_script_id_fail():
    msg_request = MsgRequest(
        oracle_script_id=0,
        calldata=bytes.fromhex("000000034254430000000000000001"),
        ask_count=4,
        min_count=3,
        client_id="from_pyband",
        sender=Address.from_acc_bech32(
            "band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
    )
    with pytest.raises(NegativeIntegerError,
                       match="oracle script id cannot less than zero"):
        msg_request.validate()
示例#4
0
def test_msg_request_get_sender():
    msg_request = MsgRequest(
        oracle_script_id=1,
        calldata=bytes.fromhex("000000034254430000000000000001"),
        ask_count=4,
        min_count=3,
        client_id="from_pyband",
        sender=Address.from_acc_bech32(
            "band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
    )

    assert msg_request.get_sender().to_acc_bech32(
    ) == "band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"
示例#5
0
def test_get_tx_data_success():
    priv = PrivateKey.from_mnemonic("s")
    pubkey = priv.to_pubkey()
    addr = pubkey.to_address()

    t = (
        Transaction()
        .with_messages(
            MsgRequest(
                oracle_script_id=1,
                calldata=bytes.fromhex("000000034254430000000000000001"),
                ask_count=4,
                min_count=3,
                client_id="from_pyband",
                sender=addr,
            )
        )
        .with_account_num(100)
        .with_sequence(30)
        .with_chain_id("bandchain")
    )

    raw_data = t.get_sign_data()
    signature = priv.sign(raw_data)
    raw_tx = t.get_tx_data(signature, pubkey)

    assert raw_tx == {
        "msg": [
            {
                "type": "oracle/Request",
                "value": {
                    "oracle_script_id": "1",
                    "calldata": "AAAAA0JUQwAAAAAAAAAB",
                    "ask_count": "4",
                    "min_count": "3",
                    "client_id": "from_pyband",
                    "sender": "band1jrhuqrymzt4mnvgw8cvy3s9zhx3jj0dq30qpte",
                },
            }
        ],
        "fee": {"gas": "200000", "amount": [{"denom": "uband", "amount": "0"}]},
        "memo": "",
        "signatures": [
            {
                "signature": "aFvTgkY9F14dHfp2mtq8V2eCTKUtY1T9WKs99jmR8To3JB16cawbmpa1TRUdzfnqLXBh+o6XUuF4bHWR6xbCCw==",
                "pub_key": {
                    "type": "tendermint/PubKeySecp256k1",
                    "value": "A/5wi9pmUk/SxrzpBoLjhVWoUeA9Ku5PYpsF3pD1Htm8",
                },
                "account_number": "100",
                "sequence": "30",
            }
        ],
    }
示例#6
0
def test_msg_request_creation_success():
    msg_request = MsgRequest(
        oracle_script_id=1,
        calldata=bytes.fromhex("000000034254430000000000000001"),
        ask_count=4,
        min_count=3,
        client_id="from_pyband",
        sender=Address.from_acc_bech32("band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
    )
    assert msg_request.validate() == True

    assert msg_request.as_json() == {
        "type": "oracle/Request",
        "value": {
            "oracle_script_id": "1",
            "calldata": "AAAAA0JUQwAAAAAAAAAB",
            "ask_count": "4",
            "min_count": "3",
            "client_id": "from_pyband",
            "sender": "band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c",
        },
    }
示例#7
0
def test_get_sign_data_chain_id_fail():
    t = (Transaction().with_messages(
        MsgRequest(
            oracle_script_id=1,
            calldata=bytes.fromhex("000000034254430000000000000001"),
            ask_count=4,
            min_count=3,
            client_id="from_pyband",
            sender=Address.from_acc_bech32(
                "band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
        )).with_account_num(100).with_sequence(30))

    with pytest.raises(ValueError, match="chain_id should be defined"):
        t.get_sign_data()
示例#8
0
def test_get_sign_data_memo_fail():
    t = (Transaction().with_messages(
        MsgRequest(
            oracle_script_id=1,
            calldata=bytes.fromhex("000000034254430000000000000001"),
            ask_count=4,
            min_count=3,
            client_id="from_pyband",
            sender=Address.from_acc_bech32(
                "band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
        )).with_account_num(100).with_sequence(30).with_chain_id("bandchain"))

    with pytest.raises(ValueError, match="memo is too large"):
        t.with_memo(
            "This is the longest memo in the world. This is the longest memo in the world. This is the longest memo in the world. This is the longest memo in the world. This is the longest memo in the world. This is the longest memo in the world. This is the longest memo in the world.This is the longest memo in the world. This is the longest memo in the world.This is the longest memo in the world."
        )
示例#9
0
def test_get_sign_data_success():
    t = (Transaction().with_messages(
        MsgRequest(
            oracle_script_id=1,
            calldata=bytes.fromhex("000000034254430000000000000001"),
            ask_count=4,
            min_count=3,
            client_id="from_pyband",
            sender=Address.from_acc_bech32(
                "band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
        )).with_account_num(100).with_sequence(30).with_chain_id("bandchain"))

    assert (
        t.get_sign_data() ==
        b'{"account_number":"100","chain_id":"bandchain","fee":{"amount":[{"amount":"0","denom":"uband"}],"gas":"200000"},"memo":"","msgs":[{"type":"oracle/Request","value":{"ask_count":"4","calldata":"AAAAA0JUQwAAAAAAAAAB","client_id":"from_pyband","min_count":"3","oracle_script_id":"1","sender":"band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"}}],"sequence":"30"}'
    )
示例#10
0
def test_get_sign_data_with_auto_success(requests_mock):

    requests_mock.register_uri(
        "GET",
        "{}/auth/accounts/band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c".format(TEST_RPC),
        json={
            "height": "650788",
            "result": {
                "type": "cosmos-sdk/Account",
                "value": {
                    "address": "band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c",
                    "coins": [{"denom": "uband", "amount": "104082359107"}],
                    "public_key": {
                        "type": "tendermint/PubKeySecp256k1",
                        "value": "A/5wi9pmUk/SxrzpBoLjhVWoUeA9Ku5PYpsF3pD1Htm8",
                    },
                    "account_number": "36",
                    "sequence": "927",
                },
            },
        },
        status_code=200,
    )

    t = (
        Transaction()
        .with_messages(
            MsgRequest(
                oracle_script_id=1,
                calldata=bytes.fromhex("000000034254430000000000000001"),
                ask_count=4,
                min_count=3,
                client_id="from_pyband",
                sender=Address.from_acc_bech32("band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"),
            )
        )
        .with_auto(client)
        .with_chain_id("bandchain")
        .with_gas(500000)
        .with_fee(10)
    )

    assert (
        t.get_sign_data()
        == b'{"account_number":"36","chain_id":"bandchain","fee":{"amount":[{"amount":"10","denom":"uband"}],"gas":"500000"},"memo":"","msgs":[{"type":"oracle/Request","value":{"ask_count":"4","calldata":"AAAAA0JUQwAAAAAAAAAB","client_id":"from_pyband","min_count":"3","oracle_script_id":"1","sender":"band13eznuehmqzd3r84fkxu8wklxl22r2qfmtlth8c"}}],"sequence":"927"}'
    )