def get_event_handle_by_query_path(self, query_path): if AccountConfig.account_received_event_path() == query_path: return self.received_events elif AccountConfig.account_sent_event_path() == query_path: return self.sent_events else: libra.proof.bail("Unrecognized query path: {}", query_path)
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
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 == """{
def get_account_resource_or_default(cls, blob): if blob: omap = AccountState.deserialize(blob.blob).ordered_map resource = omap[AccountConfig.account_resource_path()] return cls.deserialize(resource) else: return cls()
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"))
def get_events_received(self, address, start_sequence_number, ascending=True, limit=1): path = AccountConfig.account_received_event_path() return self.get_events(address, path, start_sequence_number, ascending, limit)
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")
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
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')
def validator_set_tag(cls) -> StructTag: return StructTag(hex_to_int_list(AccountConfig.core_code_address()), cls.VALIDATOR_SET_MODULE_NAME, cls.VALIDATOR_SET_STRUCT_NAME, [])
def test_resource_access_vec(): array = AccessPath.resource_access_vec(AccountConfig.account_struct_tag(), []) assert bytes(array) == AccountConfig.account_resource_path()
def faucet_account(cls, private_key): return cls(private_key, AccountConfig.association_address())
def get_resource(self): resource = self.ordered_map[AccountConfig.account_resource_path()] if resource: return AccountResource.deserialize(resource) else: return None
def execute(self, client, params, **kwargs): json_print_in_cmd(AccountConfig.all_config(), sort_keys=False)