Пример #1
0
def test_parse():
    address = bytes.fromhex("000000000000000000000000000000000000000000000000000000000a550c18")
    assert parse_address(AccountConfig.association_address()) == address
    assert parse_address("0xa550c18") == address
    assert parse_address("0xA550c18") == address
    assert parse_address("0x0A550c18") == address
    assert parse_address("a550c18") is None
    assert parse_address(AccountConfig.association_address()+"1") is None
Пример #2
0
def test_faucet_account(capsys):
    faucet_account = Account.gen_faucet_account(None)
    assert faucet_account.address_hex == AccountConfig.association_address()
    assert faucet_account.sequence_number == 0
    assert faucet_account.status == AccountStatus.Local
    json_print(faucet_account)
    assert capsys.readouterr().out == """{
Пример #3
0
def test_equal_address():
    hexaddr = AccountConfig.association_address()
    bytesaddr = parse_address("0xa550c18")
    intsaddr = bytes_to_int_list(bytesaddr)
    assert Address.equal_address(hexaddr, bytesaddr)
    assert Address.equal_address(hexaddr, intsaddr)
    assert False == Address.equal_address(hexaddr, parse_address("0x123"))
Пример #4
0
def test_parse_as_transaction_argument():
    address = bytes.fromhex(
        "000000000000000000000000000000000000000000000000000000000a550c18")
    addr = TransactionArgument.parse_as_transaction_argument(
        AccountConfig.association_address())
    assert bytes(addr.value) == address
    assert addr.Address
    hello = TransactionArgument.parse_as_transaction_argument(
        'b"48656c6c6f20776f726c6421"')
    assert hello.ByteArray
    assert bytes(hello.value) == b"Hello world!"
    i = TransactionArgument.parse_as_transaction_argument('1234')
    assert i.U64
    assert i.value == 1234
    with pytest.raises(Exception):
        TransactionArgument.parse_as_transaction_argument('abc')
    with pytest.raises(Exception):
        TransactionArgument.parse_as_transaction_argument('-1')
    with pytest.raises(Exception):
        TransactionArgument.parse_as_transaction_argument(
            AccountConfig.association_address() + "0")
Пример #5
0
 def mint_coins_with_faucet_service(self,
                                    receiver,
                                    micro_libra,
                                    is_blocking=False):
     url = "http://{}?amount={}&address={}".format(self.faucet_host,
                                                   micro_libra, receiver)
     resp = requests.post(url)
     if resp.status_code != 200:
         raise IOError(
             "Failed to send request to faucent service: {}".format(
                 self.faucet_host))
     sequence_number = int(resp.text)
     if is_blocking:
         self.wait_for_transaction(AccountConfig.association_address(),
                                   sequence_number)
     return sequence_number
Пример #6
0
def test_strict_parse_address():
    address = bytes.fromhex("000000000000000000000000000000000000000000000000000000000a550c18")
    hexstr = AccountConfig.association_address()
    assert strict_parse_address(hexstr) == address
    assert strict_parse_address("0x"+hexstr) == address
    assert strict_parse_address(f"'{hexstr}'") == address
    assert strict_parse_address(f'"{hexstr}"') == address
    with pytest.raises(ValueError):
        strict_parse_address("0"+hexstr)
    with pytest.raises(ValueError):
        strict_parse_address("0X"+hexstr)
    with pytest.raises(ValueError):
        strict_parse_address("0x0"+hexstr)
    with pytest.raises(ValueError):
        strict_parse_address("'"+hexstr+'"')
    with pytest.raises(ValueError):
        strict_parse_address("0")
    with pytest.raises(ValueError):
        strict_parse_address("")
    with pytest.raises(TypeError):
        strict_parse_address(None)
    with pytest.raises(ValueError):
        strict_parse_address(b'abc')
Пример #7
0
 def faucet_account(cls, private_key):
     return cls(private_key, AccountConfig.association_address())