Example #1
0
def test_send_tx_sync_mode_wrong_sequence_fail(requests_mock):
    requests_mock.register_uri(
        "POST",
        "{}/txs".format(TEST_RPC),
        json={
            "height":
            "0",
            "txhash":
            "611F45A21BB7937E451CDE78D124218603644635CC40A97D2BC1E854CED8D6E6",
            "code":
            4,
            "raw_log":
            "unauthorized: signature verification failed; verify correct account sequence and chain-id",
        },
        status_code=200,
    )
    assert client.send_tx_sync_mode(
        TEST_WRONG_SEQUENCE_MSG
    ) == TransactionSyncMode(
        tx_hash=HexBytes(
            bytes.fromhex(
                "611F45A21BB7937E451CDE78D124218603644635CC40A97D2BC1E854CED8D6E6"
            )),
        code=4,
        error_log=
        "unauthorized: signature verification failed; verify correct account sequence and chain-id",
    )
Example #2
0
def test_send_tx_block_wrong_sequence_fail(requests_mock):
    requests_mock.register_uri(
        "POST",
        "{}/txs".format(TEST_RPC),
        json={
            "height": "0",
            "txhash": "7F1CFFD674CAAEEB25922E9C6E9F8F8CEF7A325E25B64E8DAB070D7409FD1F72",
            "codespace": "sdk",
            "code": 4,
            "raw_log": "unauthorized: signature verification failed; verify correct account sequence and chain-id",
            "gas_wanted": "1000000",
            "gas_used": "27402",
        },
        status_code=200,
    )

    assert client.send_tx_block_mode(TEST_MSG) == TransactionBlockMode(
        height=0,
        tx_hash=HexBytes(bytes.fromhex("7F1CFFD674CAAEEB25922E9C6E9F8F8CEF7A325E25B64E8DAB070D7409FD1F72")),
        gas_wanted=1000000,
        gas_used=1000000,
        code=4,
        log=[],
        error_log="unauthorized: signature verification failed; verify correct account sequence and chain-id",
    )
Example #3
0
def test_send_tx_async_mode_success(requests_mock):
    requests_mock.register_uri(
        "POST",
        "{}/txs".format(TEST_RPC),
        json={
            "height": "0",
            "txhash": "E204AAD58ACA8F00942B1BB66D9F745F5E2C21E04C5DF6A0CB73DF02B6B51121",
            "raw_log": "[]",
        },
        status_code=200,
    )

    assert client.send_tx_async_mode(TEST_MSG) == TransactionAsyncMode(
        tx_hash=HexBytes(bytes.fromhex("E204AAD58ACA8F00942B1BB66D9F745F5E2C21E04C5DF6A0CB73DF02B6B51121"))
    )
Example #4
0
def test_send_tx_sync_mode_return_only_code(requests_mock):
    requests_mock.register_uri(
        "POST",
        "{}/txs".format(TEST_RPC),
        json={
            "height": "0",
            "txhash": "611F45A21BB7937E451CDE78D124218603644635CC40A97D2BC1E854CED8D6E6",
            "code": 19,
        },
        status_code=200,
    )
    assert client.send_tx_sync_mode(TEST_WRONG_SEQUENCE_MSG) == TransactionSyncMode(
        tx_hash=HexBytes(bytes.fromhex("611F45A21BB7937E451CDE78D124218603644635CC40A97D2BC1E854CED8D6E6")),
        code=19,
        error_log=None,
    )
Example #5
0
def test_send_tx_block_return_code(requests_mock):
    requests_mock.register_uri(
        "POST",
        "{}/txs".format(TEST_RPC),
        json={
            "height": "0",
            "txhash": "7F1CFFD674CAAEEB25922E9C6E9F8F8CEF7A325E25B64E8DAB070D7409FD1F72",
            "codespace": "sdk",
            "code": 19,
            "gas_wanted": "1000000",
            "gas_used": "27402",
        },
        status_code=200,
    )

    assert client.send_tx_block_mode(TEST_MSG) == TransactionBlockMode(
        height=0,
        tx_hash=HexBytes(bytes.fromhex("7F1CFFD674CAAEEB25922E9C6E9F8F8CEF7A325E25B64E8DAB070D7409FD1F72")),
        gas_wanted=1000000,
        gas_used=1000000,
        code=19,
        log=[],
        error_log=None,
    )
Example #6
0
def test_send_tx_block_mode_success(requests_mock):
    requests_mock.register_uri(
        "POST",
        "{}/txs".format(TEST_RPC),
        json={
            "height": "715786",
            "txhash": "2DE264D16164BCCF695E960553FED537EDC00D0E3EDF69D6BFE4168C476AD03C",
            "raw_log": '[{"msg_index":0,"log":"","events":[{"type":"message","attributes":[{"key":"action","value":"request"}]},{"type":"raw_request","attributes":[{"key":"data_source_id","value":"1"},{"key":"data_source_hash","value":"c56de9061a78ac96748c83e8a22330accf6ee8ebb499c8525613149a70ec49d0"},{"key":"external_id","value":"1"},{"key":"calldata","value":"BTC"},{"key":"data_source_id","value":"2"},{"key":"data_source_hash","value":"dd155f719c5201336d4852830a3ad446ddf01b1ab647cf6ea5d7b9e7678a7479"},{"key":"external_id","value":"2"},{"key":"calldata","value":"BTC"},{"key":"data_source_id","value":"3"},{"key":"data_source_hash","value":"f3bad1a6d88cd30ce311d6845f114422f9c2c52c32c45b5086d69d052ad90921"},{"key":"external_id","value":"3"},{"key":"calldata","value":"BTC"}]},{"type":"request","attributes":[{"key":"id","value":"51"},{"key":"client_id","value":"from_pyband"},{"key":"oracle_script_id","value":"1"},{"key":"calldata","value":"000000034254430000000000000001"},{"key":"ask_count","value":"4"},{"key":"min_count","value":"3"},{"key":"gas_used","value":"2405"},{"key":"validator","value":"bandvaloper1cg26m90y3wk50p9dn8pema8zmaa22plx3ensxr"},{"key":"validator","value":"bandvaloper1ma0cxd4wpcqk3kz7fr8x609rqmgqgvrpem0txh"},{"key":"validator","value":"bandvaloper1j9vk75jjty02elhwqqjehaspfslaem8pr20qst"},{"key":"validator","value":"bandvaloper1p40yh3zkmhcv0ecqp3mcazy83sa57rgjde6wec"}]}]}]',
            "logs": [
                {
                    "msg_index": 0,
                    "log": "",
                    "events": [
                        {
                            "type": "message",
                            "attributes": [{"key": "action", "value": "request"}],
                        },
                        {
                            "type": "raw_request",
                            "attributes": [
                                {"key": "data_source_id", "value": "1"},
                                {
                                    "key": "data_source_hash",
                                    "value": "c56de9061a78ac96748c83e8a22330accf6ee8ebb499c8525613149a70ec49d0",
                                },
                                {"key": "external_id", "value": "1"},
                                {"key": "calldata", "value": "BTC"},
                                {"key": "data_source_id", "value": "2"},
                                {
                                    "key": "data_source_hash",
                                    "value": "dd155f719c5201336d4852830a3ad446ddf01b1ab647cf6ea5d7b9e7678a7479",
                                },
                                {"key": "external_id", "value": "2"},
                                {"key": "calldata", "value": "BTC"},
                                {"key": "data_source_id", "value": "3"},
                                {
                                    "key": "data_source_hash",
                                    "value": "f3bad1a6d88cd30ce311d6845f114422f9c2c52c32c45b5086d69d052ad90921",
                                },
                                {"key": "external_id", "value": "3"},
                                {"key": "calldata", "value": "BTC"},
                            ],
                        },
                        {
                            "type": "request",
                            "attributes": [
                                {"key": "id", "value": "51"},
                                {"key": "client_id", "value": "from_pyband"},
                                {"key": "oracle_script_id", "value": "1"},
                                {
                                    "key": "calldata",
                                    "value": "000000034254430000000000000001",
                                },
                                {"key": "ask_count", "value": "4"},
                                {"key": "min_count", "value": "3"},
                                {"key": "gas_used", "value": "2405"},
                                {
                                    "key": "validator",
                                    "value": "bandvaloper1cg26m90y3wk50p9dn8pema8zmaa22plx3ensxr",
                                },
                                {
                                    "key": "validator",
                                    "value": "bandvaloper1ma0cxd4wpcqk3kz7fr8x609rqmgqgvrpem0txh",
                                },
                                {
                                    "key": "validator",
                                    "value": "bandvaloper1j9vk75jjty02elhwqqjehaspfslaem8pr20qst",
                                },
                                {
                                    "key": "validator",
                                    "value": "bandvaloper1p40yh3zkmhcv0ecqp3mcazy83sa57rgjde6wec",
                                },
                            ],
                        },
                    ],
                }
            ],
            "gas_wanted": "1000000",
            "gas_used": "343054",
        },
        status_code=200,
    )

    assert client.send_tx_block_mode(TEST_MSG) == TransactionBlockMode(
        height=715786,
        tx_hash=HexBytes(bytes.fromhex("2DE264D16164BCCF695E960553FED537EDC00D0E3EDF69D6BFE4168C476AD03C")),
        gas_wanted=1000000,
        gas_used=1000000,
        log=[
            {
                "msg_index": 0,
                "log": "",
                "events": [
                    {
                        "type": "message",
                        "attributes": [{"key": "action", "value": "request"}],
                    },
                    {
                        "type": "raw_request",
                        "attributes": [
                            {"key": "data_source_id", "value": "1"},
                            {
                                "key": "data_source_hash",
                                "value": "c56de9061a78ac96748c83e8a22330accf6ee8ebb499c8525613149a70ec49d0",
                            },
                            {"key": "external_id", "value": "1"},
                            {"key": "calldata", "value": "BTC"},
                            {"key": "data_source_id", "value": "2"},
                            {
                                "key": "data_source_hash",
                                "value": "dd155f719c5201336d4852830a3ad446ddf01b1ab647cf6ea5d7b9e7678a7479",
                            },
                            {"key": "external_id", "value": "2"},
                            {"key": "calldata", "value": "BTC"},
                            {"key": "data_source_id", "value": "3"},
                            {
                                "key": "data_source_hash",
                                "value": "f3bad1a6d88cd30ce311d6845f114422f9c2c52c32c45b5086d69d052ad90921",
                            },
                            {"key": "external_id", "value": "3"},
                            {"key": "calldata", "value": "BTC"},
                        ],
                    },
                    {
                        "type": "request",
                        "attributes": [
                            {"key": "id", "value": "51"},
                            {"key": "client_id", "value": "from_pyband"},
                            {"key": "oracle_script_id", "value": "1"},
                            {
                                "key": "calldata",
                                "value": "000000034254430000000000000001",
                            },
                            {"key": "ask_count", "value": "4"},
                            {"key": "min_count", "value": "3"},
                            {"key": "gas_used", "value": "2405"},
                            {
                                "key": "validator",
                                "value": "bandvaloper1cg26m90y3wk50p9dn8pema8zmaa22plx3ensxr",
                            },
                            {
                                "key": "validator",
                                "value": "bandvaloper1ma0cxd4wpcqk3kz7fr8x609rqmgqgvrpem0txh",
                            },
                            {
                                "key": "validator",
                                "value": "bandvaloper1j9vk75jjty02elhwqqjehaspfslaem8pr20qst",
                            },
                            {
                                "key": "validator",
                                "value": "bandvaloper1p40yh3zkmhcv0ecqp3mcazy83sa57rgjde6wec",
                            },
                        ],
                    },
                ],
            }
        ],
        error_log=None,
        code=0,
    )
Example #7
0
def test_get_latest_block(requests_mock):
    requests_mock.register_uri(
        "GET",
        "{}/blocks/latest".format(TEST_RPC),
        json={
            "block_id": {
                "hash": "391E99908373F8590C928E0619956DA3D87EB654445DA4F25A185C9718561D53",
                "parts": {
                    "total": "1",
                    "hash": "9DC1DB39B7DDB97DE353DFB2898198BAADEFB7DF8090BF22678714F769D69F42",
                },
            },
            "block": {
                "header": {
                    "version": {"block": "10", "app": "0"},
                    "chain_id": "bandchain",
                    "height": "1032007",
                    "time": "2020-11-05T09:15:18.445494105Z",
                    "last_block_id": {
                        "hash": "4BC01E257662B5F9337D615D06D5D19D8D79F7BA5A4022A85B4DC4ED3C59F7CA",
                        "parts": {
                            "total": "1",
                            "hash": "6471C0A51FB7043171EAA76CAFA900B36A4494F47F975980732529D247E8EBA5",
                        },
                    },
                    "last_commit_hash": "17B2CE4ABA910E85847537F1323DB95C9F16C20C60E9B9BBB04C633C3125BD92",
                    "data_hash": "EFE5E3F549554FEE8EB9B393740C250D74580427A96A175ABB105806039CFFE2",
                    "validators_hash": "E3F0EA129867E1AB4D7D6A97C23771D4D89B9E4DFE0A5B11E03B681244E00151",
                    "next_validators_hash": "E3F0EA129867E1AB4D7D6A97C23771D4D89B9E4DFE0A5B11E03B681244E00151",
                    "consensus_hash": "0EAA6F4F4B8BD1CC222D93BBD391D07F074DE6BE5A52C6964875BB355B7D0B45",
                    "app_hash": "6E2B1ECE9D912D86C25182E8B7419583ABCE978BFC66DC2556BB0D06A8D528EF",
                    "last_results_hash": "",
                    "evidence_hash": "",
                    "proposer_address": "BDB6A0728C8DFE2124536F16F2BA428FE767A8F9",
                },
                "data": {
                    "txs": [
                        "yAEoKBapCj5CcI40CAESDwAAAANCVEMAAAAAAAAAARgEIAMqC2Zyb21fcHliYW5kMhSQ78AMmxLrubEOPhhIwKK5oyk9oBIQCgoKBXViYW5kEgEwEMCEPRpqCibrWumHIQP+cIvaZlJP0sa86QaC44VVqFHgPSruT2KbBd6Q9R7ZvBJANbPqLRAgwwULWWwb5O2/eb6ddtDr65kRFgDcOTTGIqQS5Iz1NvHWHfkPKRoM8egErMsgE9YnuE+pAqoc/YvNfiIEVEVTVA=="
                    ]
                },
                "evidence": {"evidence": None},
                "last_commit": {
                    "height": "1032006",
                    "round": "0",
                    "block_id": {
                        "hash": "4BC01E257662B5F9337D615D06D5D19D8D79F7BA5A4022A85B4DC4ED3C59F7CA",
                        "parts": {
                            "total": "1",
                            "hash": "6471C0A51FB7043171EAA76CAFA900B36A4494F47F975980732529D247E8EBA5",
                        },
                    },
                    "signatures": [
                        {
                            "block_id_flag": 3,
                            "validator_address": "5179B0BB203248E03D2A1342896133B5C58E1E44",
                            "timestamp": "2020-11-05T09:15:18.53815896Z",
                            "signature": "TZY24CKwZOE8wqfE0NM3qzkQ7qCpCrGEHNZdf8n31L4otZzbKGfOL05kGtBsGkTnZkVv7aJmrJ7XbvIzv0SREQ==",
                        },
                        {
                            "block_id_flag": 2,
                            "validator_address": "BDB6A0728C8DFE2124536F16F2BA428FE767A8F9",
                            "timestamp": "2020-11-05T09:15:18.445494105Z",
                            "signature": "mcUMQtCR38MK69IeUDri0zkfllsXKgnVFTsFwNaO/7cnBaIUUz9U4d3H9EjSH4kANJxWRFO3dSnPy1uOD36K6A==",
                        },
                        {
                            "block_id_flag": 3,
                            "validator_address": "F0C23921727D869745C4F9703CF33996B1D2B715",
                            "timestamp": "2020-11-05T09:15:18.537783045Z",
                            "signature": "fpr26xz+Gg5Rl7Fvx34a0QZpb5yJc5P4t5Z1OctIDQ0VMmh9vEWagsqQGErt1bm+CaKFtkFfZZ4CU0DKN27GbQ==",
                        },
                        {
                            "block_id_flag": 3,
                            "validator_address": "F23391B5DBF982E37FB7DADEA64AAE21CAE4C172",
                            "timestamp": "2020-11-05T09:15:18.539946947Z",
                            "signature": "KGsiIaralMMr1M9A7Ulhbc0THt1pLgNIrNQ6Kx+oGtwjl2w5ke5iivAAtZMduhyIAUMhrp6PN7ZvKgv9TPCNNw==",
                        },
                    ],
                },
            },
        },
        status_code=200,
    )

    assert client.get_latest_block() == Block(
        block=BlockHeader(
            header=BlockHeaderInfo(
                chain_id="bandchain",
                height=1032007,
                time=Timestamp(parse_datetime("2020-11-05T09:15:18.445494105Z")),
                last_commit_hash=HexBytes(
                    bytes.fromhex("17B2CE4ABA910E85847537F1323DB95C9F16C20C60E9B9BBB04C633C3125BD92")
                ),
                data_hash=HexBytes(bytes.fromhex("EFE5E3F549554FEE8EB9B393740C250D74580427A96A175ABB105806039CFFE2")),
                validators_hash=HexBytes(
                    bytes.fromhex("E3F0EA129867E1AB4D7D6A97C23771D4D89B9E4DFE0A5B11E03B681244E00151")
                ),
                next_validators_hash=HexBytes(
                    bytes.fromhex("E3F0EA129867E1AB4D7D6A97C23771D4D89B9E4DFE0A5B11E03B681244E00151")
                ),
                consensus_hash=HexBytes(
                    bytes.fromhex("0EAA6F4F4B8BD1CC222D93BBD391D07F074DE6BE5A52C6964875BB355B7D0B45")
                ),
                app_hash=HexBytes(bytes.fromhex("6E2B1ECE9D912D86C25182E8B7419583ABCE978BFC66DC2556BB0D06A8D528EF")),
                last_results_hash=HexBytes(bytes.fromhex("")),
                evidence_hash=HexBytes(bytes.fromhex("")),
                proposer_address=HexBytes(bytes.fromhex("BDB6A0728C8DFE2124536F16F2BA428FE767A8F9")),
            )
        ),
        block_id=BlockID(
            hash=HexBytes(bytes.fromhex("391E99908373F8590C928E0619956DA3D87EB654445DA4F25A185C9718561D53"))
        ),
    )
Example #8
0
    RequestInfo,
    Report,
    Result,
    RequestPacketData,
    ResponsePacketData,
)

VALIDATOR_TEST = "bandvaloper1p40yh3zkmhcv0ecqp3mcazy83sa57rgjde6wec"

BlOCK_TEST = Block(
    block=BlockHeader(header=BlockHeaderInfo(
        chain_id="bandchain",
        height=136639,
        time=EpochTime(parse_epoch_time("2020-11-05T09:15:18.445494105Z")),
        last_commit_hash=HexBytes(
            bytes.fromhex(
                "17B2CE4ABA910E85847537F1323DB95C9F16C20C60E9B9BBB04C633C3125BD92"
            )),
        data_hash=HexBytes(
            bytes.fromhex(
                "EFE5E3F549554FEE8EB9B393740C250D74580427A96A175ABB105806039CFFE2"
            )),
        validators_hash=HexBytes(
            bytes.fromhex(
                "E3F0EA129867E1AB4D7D6A97C23771D4D89B9E4DFE0A5B11E03B681244E00151"
            )),
        next_validators_hash=HexBytes(
            bytes.fromhex(
                "E3F0EA129867E1AB4D7D6A97C23771D4D89B9E4DFE0A5B11E03B681244E00151"
            )),
        consensus_hash=HexBytes(
            bytes.fromhex(