Пример #1
0
def test_timeunlock_encoding():
    valid_tx_hash = bytes.fromhex('89789C6D36CB0779184CB616D3EC67C453A84D12439E9A25ACCC767EC6CA5F00')
    valid_tx = bytes.fromhex(
        '9201F0625DEE0A1CC4050C6C0A140B1A85684331AB8C73A6ECBF8B2A02DF379E0E2F1010126E0A26EB5AE987210350BE56D5'
        '4E71C36648F4A59518E83E1B78E7A041581A0764AA72E1E9986E029E1240306B11C7173D73A6A43D0C04F2C18453553CD805'
        'E5C56D6F78E5F02D2E32D36B7657045E30EED250D28FA12C17685C5AAE97AD73BF6F3A75986FAF09723E39C418442010'
    )
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    from_address = 'bnb1pvdg26zrxx4ccuaxajlck2szmumeur30k2eru9'
    tx = BnbTransaction.from_obj({
        'account_number': 68,
        'from': from_address,
        'memo': '',
        'msgs': [
            {
                'type': 'tokens/TimeUnlockMsg',
                'from': from_address,
                'time_lock_id': 16,
            }
        ],
        'source': 0,
        'sequence': 16,
    })
    valid_sig = base64.b64decode(
        'MGsRxxc9c6akPQwE8sGEU1U82AXlxW1veOXwLS4y02t2VwReMO7SUNKPoSwXaFxarpetc79vOnWYb68Jcj45xA=='
    )
    valid_public_key = base64.b64decode(
        'A1C+VtVOccNmSPSllRjoPht456BBWBoHZKpy4emYbgKe'
    )
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #2
0
def test_unfreeze():
    valid_tx_hash = bytes.fromhex('85A02C52AA88005D807049053D59B86D96469F595820ECE11B283CF78C50E4A0')
    valid_tx = bytes.fromhex(
        'A301F0625DEE0A2A6515FF0D0A141AD3AB3E43C28AC9A9083878E2DECA092B09DAFC12075048422D32444618A0ADBFF5FE20' +
        '126F0A26EB5AE9872103F405490307AC7FBC888F3CB13D6D9162845EF5DFC233158BFEF0DD9E2F3599DA12409E0734BFE788' +
        '309C51C752D8D998530693CFD5A33A2865A92E41C9B1127DF4D45CDE81F47ABA6E258886E3841F7A867C6F93165F2D76D07D' +
        'D97FD0ED8878102018C66C20532001'
    )
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    valid_sig = base64.b64decode(
        'ngc0v+eIMJxRx1LY2ZhTBpPP1aM6KGWpLkHJsRJ99NRc3oH0erpuJYiG44QfeoZ8b5MWXy120H3Zf9DtiHgQIA=='
    )
    valid_public_key = base64.b64decode('A/QFSQMHrH+8iI88sT1tkWKEXvXfwjMVi/7w3Z4vNZna')
    tx = BnbTransaction.from_obj({
        'account_number': 13894,
        'from': 'bnb1rtf6k0jrc29vn2gg8puw9hk2py4snkhuez89fk',
        'memo': '',
        'msgs': [
            {
                'type': 'tokens/UnfreezeMsg',
                'amount': 1133580900000,
                'from': 'bnb1rtf6k0jrc29vn2gg8puw9hk2py4snkhuez89fk',
                'symbol': 'PHB-2DF'
            }
        ],
        'source': '1',
        'sequence': '83'
    })
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #3
0
def test_burn():
    valid_tx_hash = bytes.fromhex('89BFE0037ED2A13E507FBAD452E8267397DB0A54B81DF227B6150CDB6094FCE5')
    valid_tx = bytes.fromhex(
        'A801F0625DEE0A307ED2D2A00A149A68092EE3D99C69A70BAC9EEAE16F8A5175DC0A120A555344532E422D43323718808090' +
        '948E8A9BF37C12700A26EB5AE98721024A754FAF37E8C48BEE248A8094BC24E8FA601CD5EE83F7DD96C00574CE09DCAE1240' +
        '64FDC6E9FDF19DDB5CCFC148187D67A80E41AEF590D5C38AC425F3114D2245EC290FFFDEA422C798360421B3F5E66797C340' +
        'DBF183CA1CC5184956D10D5987E818D5C5012006'
    )
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    from_address = 'bnb1nf5qjthrmxwxnfct4j0w4ct03fghthq24qt990'
    valid_public_key = base64.b64decode('Akp1T6836MSL7iSKgJS8JOj6YBzV7oP33ZbABXTOCdyu')
    valid_sig = base64.b64decode(
        "ZP3G6f3xndtcz8FIGH1nqA5BrvWQ1cOKxCXzEU0iRewpD//epCLHmDYEIbP15meXw0Db8YPKHMUYSVbRDVmH6A==")
    tx = BnbTransaction.from_obj({
        'account_number': 25301,
        'from': from_address,
        'memo': '',
        'msgs': [
            {
                'type': 'tokens/BurnMsg',
                'amount': 9000000000000000000,
                'from': from_address,
                'symbol': "USDS.B-C27",
            }
        ],
        'sequence': '6',
        'source': '0'
    })
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #4
0
def test_freeze():
    valid_tx_hash = bytes.fromhex('B06C319E2CFEF19FD65DB485585BA8DB6C241A8143F39F4436B14949C4BAAC99')
    valid_tx = bytes.fromhex(
        'A401F0625DEE0A2BE774B32D0A141AD3AB3E43C28AC9A9083878E2DECA092B09DAFC12075048422D32444618909AD79FA680' +
        '02126F0A26EB5AE9872103F405490307AC7FBC888F3CB13D6D9162845EF5DFC233158BFEF0DD9E2F3599DA1240DFAC8DF469' +
        '000B73AF1492458BDBBF00FE2D9E7300A61EFAA72C8F084DA36712589A66C0785148CF2839F74022B072519D2431A124610C' +
        'F491A5F00F8B62FE4B18C66C205B2001'
    )
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    valid_sig = base64.b64decode(
        '36yN9GkAC3OvFJJFi9u/AP4tnnMAph76pyyPCE2jZxJYmmbAeFFIzyg590AisHJRnSQxoSRhDPSRpfAPi2L+Sw=='
    )
    valid_public_key = base64.b64decode('A/QFSQMHrH+8iI88sT1tkWKEXvXfwjMVi/7w3Z4vNZna')
    tx = BnbTransaction.from_obj({
        'account_number': 13894,
        'from': 'bnb1rtf6k0jrc29vn2gg8puw9hk2py4snkhuez89fk',
        'memo': '',
        'msgs': [
            {
                'type': 'tokens/FreezeMsg',
                'amount': 8806360010000,
                'from': 'bnb1rtf6k0jrc29vn2gg8puw9hk2py4snkhuez89fk',
                'symbol': 'PHB-2DF'
            }
        ],
        'source': '1',
        'sequence': '91'
    })
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #5
0
def test_vote_encoding():
    valid_tx_hash = bytes.fromhex('8B57150E0A57F88BA3F7821EF9468C9A64F0E9D7CB470CE158A48A9520E4358D')
    valid_tx = bytes.fromhex(
        '9601F0625DEE0A1EA1CADD36083A1214E536C4580B28F72AA78BD3C730812C7F4FAA05D31801126E0A26EB5AE987210252BF' +
        'F8BFEF6B650D87E6BEBC90E0EE3C08AACB208F483FC646D320AD19149E711240391E522EFB3AE41F6B25884C801F067B2FA1' +
        '051DBE5BF9727F55C2EFC89B7F7C3D5B77CB96A862442575125E3210E64F8518CBFE615EE0C617059294611567631813202E' +
        '2003'
    )
    from_address = 'bnb1u5mvgkqt9rmj4fut60rnpqfv0a865pwnn90v9q'
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    tx = BnbTransaction.from_obj({
        'account_number': 19,
        'from': from_address,
        'memo': '',
        'msgs': [
            {
                'type': 'cosmos-sdk/MsgVote',
                'option': 'Yes',
                'voter': from_address,
                'proposal_id': '58',
            }
        ],
        'source': '3',
        'sequence': '46'
    })
    valid_sig = base64.b64decode(
        'OR5SLvs65B9rJYhMgB8Gey+hBR2+W/lyf1XC78ibf3w9W3fLlqhiRCV1El4yEOZPhRjL/mFe4MYXBZKUYRVnYw=='
    )
    valid_public_key = base64.b64decode('AlK/+L/va2UNh+a+vJDg7jwIqssgj0g/xkbTIK0ZFJ5x')
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #6
0
def test_recent_issue_asset_encoding():
    valid_tx_hash = bytes.fromhex('1AC6A272F3FECF1B2B98DE720E916C97B5BD9857722879D239CC93F192CA5DA8')
    valid_tx = bytes.fromhex(
        'AB01F0625DEE0A3317EFAB800A149A68092EE3D99C69A70BAC9EEAE16F8A5175DC0A1204555344531A055553445342208080' +
        '90948E8A9BF37C280112700A26EB5AE98721024A754FAF37E8C48BEE248A8094BC24E8FA601CD5EE83F7DD96C00574CE09DC' +
        'AE1240128FAC6859D4101409287C5968D55AE5A23C74D1863B8384D4CA0475857CD95E1A14A86AFCC5E2AA777D854A92A466' +
        '66123B49C403DA3C2CB25E3617E94F854118D5C5012007'
    )
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    valid_sig = base64.b64decode(
        'Eo+saFnUEBQJKHxZaNVa5aI8dNGGO4OE1MoEdYV82V4aFKhq/MXiqnd9hUqSpGZmEjtJxAPaPCyyXjYX6U+FQQ=='
    )
    valid_public_key = base64.b64decode('Akp1T6836MSL7iSKgJS8JOj6YBzV7oP33ZbABXTOCdyu')
    tx = BnbTransaction.from_obj({
        'account_number': 25301,
        'from': 'bnb1nf5qjthrmxwxnfct4j0w4ct03fghthq24qt990',
        'sequence': 7,
        'memo': '',
        'msgs': [
            {
                'type': 'tokens/IssueMsg',
                'from': 'bnb1nf5qjthrmxwxnfct4j0w4ct03fghthq24qt990',
                'name': 'USDS',
                'symbol': 'USDSB',
                'total_supply': 9000000000000000000,
                'mintable': True
            }
        ]
    })
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig)
Пример #7
0
def test_listdex():
    valid_tx_hash = bytes.fromhex('2426AF82B24B9F8E126CE386594028BBDEF84F54D73D07CF0F16C40B18D42BF6')
    valid_tx = bytes.fromhex(
        'B201F0625DEE0A38B41DE13F0A14EDB243FACB78CE48A777E2BE7C904D931650AFF4103F1A08425443422D31444522095553' +
        '4453422D314143288090AEEA962112700A26EB5AE9872103FB3D12E8C28238BBD8E96DA24AB8965F4F5AF2A054DED841356E' +
        '39E88F646D6112402487C1CC7515932128F28657BD596AF5256EFADB807B1C2CCEBD1397D75837ED1F1D561F858DE9891291' +
        'F77ABCC36A2B974A5764C58716B565D791651CDFF33B18AA800320032001'
    )
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    tx = BnbTransaction.from_obj({
        'account_number': 49194,
        'from': 'bnb1akey87kt0r8y3fmhu2l8eyzdjvt9ptl5cppz0v',
        'memo': '',
        'msgs': [
            {
                'type': 'dex/ListMsg',
                'init_price': '1140000000000',
                'from': 'bnb1akey87kt0r8y3fmhu2l8eyzdjvt9ptl5cppz0v',
                'proposal_id': '63',
                'quote_asset_symbol': 'USDSB-1AC',
                'base_asset_symbol': 'BTCB-1DE',
            }
        ],
        'source': '1',
        'sequence': '3'
    })
    valid_sig = base64.b64decode(
        'JIfBzHUVkyEo8oZXvVlq9SVu+tuAexwszr0Tl9dYN+0fHVYfhY3piRKR93q8w2orl0pXZMWHFrVl15FlHN/zOw=='
    )
    valid_public_key = base64.b64decode('A/s9EujCgji72Oltokq4ll9PWvKgVN7YQTVuOeiPZG1h')
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #8
0
def test_send_signed_encoding():
    valid_tx = bytes.fromhex(
        'D701F0625DEE0A502A2C87FA0A240A14BC44784B0C99AA301DAC66C8A477354E039FDB13120C0A03424E4210EE8389EB900112' +
        '240A148EA70D7D2EA8A14BA2B33D18D5DFBD6FAE0A6EA8120C0A03424E4210EE8389EB900112720A26EB5AE987210217067B36' +
        'F33C1178D09DFB7B8B59853EDC871A7044F2F7DDAD885DDFB353152D1240408B7BC4FE6DB3DEB5632DEB61B3B30A37E7CA8467' +
        '1392DC998F9BF25AA0BD227A3B0BF07237235901A7EBC6D815BEDAD8CCD7D93AF75D8F703D057B24ED0BF818D7F10120A2B601' +
        '1A093130353433343133322001'
    )
    valid_tx_hash = bytes.fromhex('4FE530CE21059C75F03FE89E95756EE7B5EF93002800BA0D93134C440F5BD902')
    assert hashlib.sha256(valid_tx).digest() == valid_tx_hash
    tx = BnbTransaction.from_obj({
        'account_number': 30935,
        'sequence': 23330,
        'from': 'bnb1h3z8sjcvnx4rq8dvvmy2gae4fcpelkcn292qwu',
        'memo': '105434132',
        'msgs': [
            {
                'type': 'cosmos-sdk/Send',
                'inputs': [
                    {
                        'address': 'bnb1h3z8sjcvnx4rq8dvvmy2gae4fcpelkcn292qwu',
                        'coins': [
                            {
                                'amount': '38879248878',
                                'denom': 'BNB'
                            }
                        ]
                    }
                ],
                'outputs': [
                    {
                        'address': 'bnb136ns6lfw4zs5hg4n85vdthaad7hq5m4gtkgf23',
                        'coins': [
                            {
                                'amount': '38879248878',
                                'denom': 'BNB'
                            }
                        ]
                    }
                ]
            }
        ],
        'source': '1'
    })
    valid_sig = bytes.fromhex(
        '408b7bc4fe6db3deb5632deb61b3b30a37e7ca84671392dc998f9bf25aa0bd227a3b0bf07237235901a7ebc6d815bedad8ccd7' +
        'd93af75d8f703d057b24ed0bf8'
    )
    valid_public_key = bytes.fromhex('0217067b36f33c1178d09dfb7b8b59853edc871a7044f2f7ddad885ddfb353152d')
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #9
0
def test_proposal_encoding():
    valid_tx_hash = bytes.fromhex('2957AB7430288A3C787A247FBADED70649210FA2F9EDD67874314B349DB6530E')
    valid_sig = base64.b64decode(
        'UaIOIJW6PkOjmF+kMojJxpMmGVJc6PnnRjyFpgFGeBAiETanwvWp1vUFNHT5hyh42+nP2dpJCTeSIJBj5NkVYw==')
    valid_public_key = base64.b64decode('Aut6gsEmgMh2JxOqvEe6zswkEbSbcVDPIeKqndFiF3IB')
    valid_tx = bytes.fromhex(
        'DB02F0625DEE0AE301B42D614E0A116C697374204D4954482D4337362F424E42129B017B22626173655F61737365745F7379' +
        '6D626F6C223A224D4954482D433736222C2271756F74655F61737365745F73796D626F6C223A22424E42222C22696E69745F' +
        '7072696365223A3233303030302C226465736372697074696F6E223A226C697374204D4954482D4337362F424E42222C2265' +
        '78706972655F74696D65223A22323031392D30342D32375431383A30303A30302B30383A3030227D18042214A5870BE8CA8D' +
        '62085927D61CFBF458BFE81B25D42A0C0A03424E421080D0DBC3F4023080E098D4DAEE02126F0A26EB5AE9872102EB7A82C1' +
        '2680C8762713AABC47BACECC2411B49B7150CF21E2AA9DD162177201124051A20E2095BA3E43A3985FA43288C9C693261952' +
        '5CE8F9E7463C85A601467810221136A7C2F5A9D6F5053474F9872878DBE9CFD9DA49093792209063E4D9156318B7052001'
    )
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    description = (
        "{\"base_asset_symbol\":\"MITH-C76\",\"quote_asset_symbol\":\"BNB\",\"init_price\":230000," +
        "\"description\":\"list MITH-C76/BNB\",\"expire_time\":\"2019-04-27T18:00:00+08:00\"}"
    )
    from_address = 'bnb15krsh6x2343qskf86cw0hazchl5pkfw53zllut'
    tx = BnbTransaction.from_obj({
        'account_number': 695,
        'sequence': 1,
        'from': from_address,
        'source': '0',
        'memo': '',
        'msgs': [
            {
                'type': 'cosmos-sdk/MsgSubmitProposal',
                'title': 'list MITH-C76/BNB',
                'description': description,
                'proposal_type': 'ListTradingPair',
                'proposer': from_address,
                'initial_deposit': [{
                    'amount': '100000000000',
                    'denom': 'BNB',
                }],
                'voting_period': '12600000000000'
            }
        ]
    })
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    assert valid_tx_hash == tx.hash()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #10
0
def test_new_order():
    valid_tx_hash = bytes.fromhex('7EDD4657C441C68D7D345875A80E3A10B942BDA96188C937997E843CCE284209')
    valid_tx = bytes.fromhex(
        'E001F0625DEE0A66CE6DC0430A140917565C2C7CC07696435D13B40B438BE38FADC6122A3039313735363543324337434330'
        '37363936343335443133423430423433384245333846414443362D381A0D524156454E2D4636365F424E422002280230BC50'
        '3880C0DFDA8EE906400312700A26EB5AE9872102D08F5389E408E26134C7EBA87119A2814DE924EEE5C61E1ED99D6F468256'
        '64AC1240CF4D2BE853D8EBA348353A91ED3BCF2C0164004DAF898153444E91E4A2BAC02106E4D1B3686D70F2B756274D90BF'
        '120BA87A3CCC412E1D20618CAB480CE69A5718C7A00420072002'
    )
    assert hashlib.sha256(valid_tx).digest() == valid_tx_hash
    from_address = 'bnb1pyt4vhpv0nq8d9jrt5fmgz6r303cltwxu27xn2'
    tx = BnbTransaction.from_obj({
        'account_number': 69703,
        'from': from_address,
        'memo': '',
        'msgs': [
            {
                'type': 'dex/NewOrder',
                'id': '0917565C2C7CC07696435D13B40B438BE38FADC6-8',
                'ordertype': 2,
                'price': 10300,
                'quantity': 30000000000000,
                'sender': from_address,
                'side': 2,
                'symbol': 'RAVEN-F66_BNB',
                'timeinforce': 3
            }
        ],
        'sequence': 7,
        'source': 2
    })
    valid_public_key = base64.b64decode(
        'AtCPU4nkCOJhNMfrqHEZooFN6STu5cYeHtmdb0aCVmSs',
    )
    valid_sig = base64.b64decode(
        'z00r6FPY66NINTqR7TvPLAFkAE2viYFTRE6R5KK6wCEG5NGzaG1w8rdWJ02QvxILqHo8zEEuHSBhjKtIDOaaVw=='
    )
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    print(valid_tx.hex())
    print(tx.encode().hex())
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #11
0
def test_timelock_encoding():
    valid_tx_hash = bytes.fromhex('7617B5B7C96E9FD560826481C79D3579A76B51BC7459F0EFF812F4567667FD89')
    valid_tx = bytes.fromhex(
        'A501F0625DEE0A2F079215310A140B1A85684331AB8C73A6ECBF8B2A02DF379E0E2F1204746573741A070A03424E42100120'
        'F587BBE905126E0A26EB5AE987210350BE56D54E71C36648F4A59518E83E1B78E7A041581A0764AA72E1E9986E029E12404E'
        '5C8823B4CF57371CEE14E21A9589118E2F82271FD426C907673A69E3BB1B7A36046102F6B6AD6E05FEBADD9030BE6F49819B'
        'C7B2FFF5D792EF9D2DB5DF29FE1844200F'
    )
    assert valid_tx_hash == hashlib.sha256(valid_tx).digest()
    from_address = 'bnb1pvdg26zrxx4ccuaxajlck2szmumeur30k2eru9'
    tx = BnbTransaction.from_obj({
        'account_number': 68,
        'from': from_address,
        'memo': '',
        'msgs': [
            {
                'type': 'tokens/TimeLockMsg',
                'from': from_address,
                'description': 'test',
                "lock_time": "1563345909",
                'amount': [
                    {
                        'amount': 1,
                        'denom': 'BNB',
                    }
                ]
            }
        ],
        'source': 0,
        'sequence': 15,
    })
    valid_sig = base64.b64decode(
        'TlyII7TPVzcc7hTiGpWJEY4vgicf1CbJB2c6aeO7G3o2BGEC9ratbgX+ut2QML5vSYGbx7L/9deS750ttd8p/g=='
    )
    valid_public_key = base64.b64decode(
        'A1C+VtVOccNmSPSllRjoPht456BBWBoHZKpy4emYbgKe'
    )
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #12
0
def test_issue_signed_encoding():
    valid_tx = bytes.fromhex(
        'A801F0625DEE0A3317EFAB800A14A5870BE8CA8D62085927D61CFBF458BFE81B25D412074D69746872696C1A044D4954482080' +
        '80A8EC85AFD1B101126D0A26EB5AE9872102EB7A82C12680C8762713AABC47BACECC2411B49B7150CF21E2AA9DD16217720112' +
        '4062437A3A64AEFB6C9C0C29468E0A9CA3DDEC9E8F3F70DFBC67D58A1D7A68BFF841BE5DBEFBE6D3D63622EACE4B30BB61608D' +
        '89059996E8E356740BE54776EDDB18B705'
    )
    valid_tx_hash = bytes.fromhex('C7696AD989D8258FFD85EBE01245EE50EB15756929F03247DFF8B581867B6EC7')
    assert hashlib.sha256(valid_tx).digest() == valid_tx_hash
    from_address = 'bnb15krsh6x2343qskf86cw0hazchl5pkfw53zllut'
    tx = BnbTransaction.from_obj({
        'account_number': 695,
        'sequence': 0,
        'from': from_address,
        'memo': '',
        'msgs': [
            {
                'type': 'tokens/IssueMsg',
                'from': from_address,
                'name': 'Mithril',
                'symbol': 'MITH',
                'total_supply': 100000000000000000,
                'mintable': False
            }
        ],
        'source': '0'
    })
    valid_sig = bytes.fromhex(
        '62437a3a64aefb6c9c0c29468e0a9ca3ddec9e8f3f70dfbc67d58a1d7a68bff841be5dbefbe6d3d63622eace4b30bb61608d89' +
        '059996e8e356740be54776eddb'
    )
    valid_public_key = bytes.fromhex('02eb7a82c12680c8762713aabc47bacecc2411b49b7150cf21e2aa9dd162177201')
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    assert valid_tx == tx.encode()
    assert valid_tx_hash == tx.hash()
    tx.remove_sig()
    print(tx.signing_json())
    assert verify_sig(uncompress_key(valid_public_key), tx.signing_hash(), valid_sig), 'Wrong json encoding'
Пример #13
0
def test_cancel_order():
    valid_tx_hash = bytes.fromhex('E28E8BEA823FCBD64FC9825932ED98CFDCE36447EF651AD1D0534B6C167A1911')
    valid_tx = bytes.fromhex(
        'CD01F0625DEE0A53166E681B0A14915734BD8050E5AA03F9D056ECC1F695E86CC9BF120B544F502D3439315F424E421A2A39'
        '3135373334424438303530453541413033463944303536454343314636393545383643433942462D3212700A26EB5AE98721'
        '030D56B78B7BA4DDE1D50D05C2D06ED334716A88C7A6E10ACC68F82A711882D1F31240B0E10084BCF273B6873A7F275EB195'
        '788A7054E48DCA0CB5AEC745467F19AAA46120236C3220D65E2C2801184773DC4E32EE8F33CE87DC13951E5818723CC60318'
        '98910920022001'
    )
    assert hashlib.sha256(valid_tx).digest() == valid_tx_hash
    from_address = 'bnb1j9tnf0vq2rj65qle6ptwes0kjh5xejdle3fpuj'
    tx = BnbTransaction.from_obj({
        'account_number': 149656,
        'from': from_address,
        'memo': '',
        'msgs': [
            {
                'type': 'dex/CancelOrder',
                'refid': '915734BD8050E5AA03F9D056ECC1F695E86CC9BF-2',
                'sender': from_address,
                'symbol': 'TOP-491_BNB'
            }
        ],
        'sequence': 2,
        'source': 1
    })
    valid_public_key = base64.b64decode(
        'Aw1Wt4t7pN3h1Q0FwtBu0zRxaojHpuEKzGj4KnEYgtHz'
    )
    valid_sig = base64.b64decode(
        'sOEAhLzyc7aHOn8nXrGVeIpwVOSNygy1rsdFRn8ZqqRhICNsMiDWXiwoARhHc9xOMu6PM86H3BOVHlgYcjzGAw=='
    )
    tx.apply_sig(valid_sig, uncompress_key(valid_public_key))
    print(valid_tx.hex())
    print(tx.encode().hex())
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
Пример #14
0
def test_recent_proposal():
    valid_tx_hash = bytes.fromhex('A531406A5C4926EDF60A600FDECED280439E8BBEAD99460C60BE8F913588A196')
    from_address = 'bnb1xljnjk7msm5t5lwp4zv2ua80rrxzn2s2afce4j'
    valid_pubkey = base64.b64decode('A27f07q13gBGytyhIuID9XnnPHS8NnJIpZKO1gGtIwPm')
    valid_sig = base64.b64decode(
        'l8aL4qYXAZSdtb8z7rtw3PIx2T21XPL1ZW8mGLmLUY5sYvsoELWrIMPiEcpfgWb5/QRaaXIML9gI3FzTJgd0Bg==')
    description = (
        "{\"base_asset_symbol\":\"NODE-F3A\",\"quote_asset_symbol\":\"BNB\",\"init_price\":2941176," +
        "\"description\":\"list NODE-F3A/BNB\",\"expire_time\":\"2019-10-10T00:00:00Z\"}"
    )
    valid_tx = bytes.fromhex(
        'D802F0625DEE0ADF01B42D614E0A116C697374204E4F44452D4633412F424E421297017B22626173655F61737365745F7379' +
        '6D626F6C223A224E4F44452D463341222C2271756F74655F61737365745F73796D626F6C223A22424E42222C22696E69745F' +
        '7072696365223A323934313137362C226465736372697074696F6E223A226C697374204E4F44452D4633412F424E42222C22' +
        '6578706972655F74696D65223A22323031392D31302D31305430303A30303A30305A227D1804221437E5395BDB86E8BA7DC1' +
        'A898AE74EF18CC29AA0A2A0B0A03424E42108094EBDC033080809CDE91E7B00112700A26EB5AE98721036EDFD3BAB5DE0046' +
        'CADCA122E203F579E73C74BC367248A5928ED601AD2303E6124097C68BE2A61701949DB5BF33EEBB70DCF231D93DB55CF2F5' +
        '656F2618B98B518E6C62FB2810B5AB20C3E211CA5F8166F9FD045A69720C2FD808DC5CD326077406189DDB012003'
    )
    assert hashlib.sha256(valid_tx).digest() == valid_tx_hash
    tx = BnbTransaction.from_obj({
        'account_number': 28061,
        'sequence': 3,
        'from': from_address,
        'source': '0',
        'memo': '',
        'msgs': [
            {
                'type': 'cosmos-sdk/MsgSubmitProposal',
                'title': "list NODE-F3A/BNB",
                'description': description,
                'proposal_type': 'ListTradingPair',
                'proposer': from_address,
                'initial_deposit': [{
                    'amount': '1000000000',
                    'denom': 'BNB',
                }],
                'voting_period': '777600000000000'
            }
        ]
    })
    tx.apply_sig(valid_sig, uncompress_key(valid_pubkey))
    assert valid_tx == tx.encode()
    tx.remove_sig()
    print(tx.signing_json())
    valid_signing_bytes = bytes.fromhex(
        '7B226163636F756E745F6E756D626572223A223238303631222C22636861696E5F6964223A2242696E616E63652D43686169' +
        '6E2D546967726973222C2264617461223A6E756C6C2C226D656D6F223A22222C226D736773223A5B7B226465736372697074' +
        '696F6E223A227B5C22626173655F61737365745F73796D626F6C5C223A5C224E4F44452D4633415C222C5C2271756F74655F' +
        '61737365745F73796D626F6C5C223A5C22424E425C222C5C22696E69745F70726963655C223A323934313137362C5C226465' +
        '736372697074696F6E5C223A5C226C697374204E4F44452D4633412F424E425C222C5C226578706972655F74696D655C223A' +
        '5C22323031392D31302D31305430303A30303A30305A5C227D222C22696E697469616C5F6465706F736974223A5B7B22616D' +
        '6F756E74223A2231303030303030303030222C2264656E6F6D223A22424E42227D5D2C2270726F706F73616C5F7479706522' +
        '3A224C69737454726164696E6750616972222C2270726F706F736572223A22626E6231786C6A6E6A6B376D736D3574356C77' +
        '70347A7632756138307272787A6E32733261666365346A222C227469746C65223A226C697374204E4F44452D4633412F424E' +
        '42222C22766F74696E675F706572696F64223A22373737363030303030303030303030227D5D2C2273657175656E6365223A' +
        '2233222C22736F75726365223A2230227D'
    )
    print(valid_signing_bytes)
    assert tx.signing_json() == valid_signing_bytes
    assert verify_sig(uncompress_key(valid_pubkey), tx.signing_hash(), valid_sig), 'Wrong json encoding'