Exemplo n.º 1
0
def test_api_get_transaction_by_hash_not_found():
    tx_hash = 'th_LUKGEWyZSwyND7vcQwZwLgUXi23WJLQb9jKgJTr1it9QFViMC'
    try:
        EPOCH_CLI.get_transaction_by_hash(hash=tx_hash)
        assert False
    except openapi.OpenAPIClientException as e:
        assert e.code == 404
Exemplo n.º 2
0
def test_api_get_transaction_by_hash_bad_request():
    tx_hash = 'th_LUKG'
    try:
        EPOCH_CLI.get_transaction_by_hash(hash=tx_hash)
        assert False
    except openapi.OpenAPIClientException as e:
        assert e.code == 400
Exemplo n.º 3
0
def test_name_revocation():
    domain = random_domain()
    name = EPOCH_CLI.AEName(domain)
    name.full_claim_blocking(ACCOUNT)
    name.revoke(ACCOUNT)
    assert name.status == AEName.Status.REVOKED
    assert EPOCH_CLI.AEName(domain).is_available()
Exemplo n.º 4
0
def test_name_status_unavailable():
    # claim a domain
    domain = random_domain()
    print(f"domain is {domain}")
    occupy_name = EPOCH_CLI.AEName(domain)
    occupy_name.full_claim_blocking(ACCOUNT)
    # try to get the same name
    same_name = EPOCH_CLI.AEName(domain)
    assert not same_name.is_available()
Exemplo n.º 5
0
def test_api_get_generation_transaction_count_by_hash():
    # get the latest block
    block_hash = EPOCH_CLI.get_current_key_block_hash()
    print(block_hash)
    assert block_hash is not None
    # get the transaction count that should be a number >= 0
    generation = EPOCH_CLI.get_generation_by_hash(hash=block_hash)
    print(generation)
    assert len(generation.micro_blocks) >= 0
Exemplo n.º 6
0
def test_api_get_genesis_block():
    node_status = EPOCH_CLI.get_status()
    genesis_block = EPOCH_CLI.get_key_block_by_hash(
        hash=node_status.genesis_key_block_hash)
    zero_height_block = EPOCH_CLI.get_key_block_by_height(
        height=0)  # these should be equivalent
    # assert type(genesis_block) == BlockWithTx
    # assert type(zero_height_block) == BlockWithTx
    assert genesis_block.height == genesis_block.height == 0
    # TODO: The following check should not fail. I feel that's a problem with
    # TODO: the current state of the api  --devsnd
    assert genesis_block.hash == zero_height_block.hash
Exemplo n.º 7
0
def test_oracle_registration():
    weather_oracle = WeatherOracle(
        query_format="{'city': str}",
        response_format="{'temp_c': int}",
        default_query_fee=0,
        default_fee=10,
        default_ttl=50,
        default_query_ttl=2,
        default_response_ttl=2,
    )
    EPOCH_CLI.register_oracle(weather_oracle)
    EPOCH_CLI.listen_until(weather_oracle.is_ready, timeout=5)
    assert weather_oracle.oracle_id is not None
Exemplo n.º 8
0
def test_name_update():
    # claim a domain
    domain = random_domain()
    print(f"domain is {domain}")
    name = EPOCH_CLI.AEName(domain)
    print("Claim name ", domain)
    name.full_claim_blocking(ACCOUNT)
    # domain claimed
    name.update_status()
    assert not EPOCH_CLI.AEName(domain).is_available(), 'The name should be claimed now'
    name.update_status()
    print("claimed name", name)
    print("pointers", name.pointers)
    assert len(name.pointers) > 0, 'Pointers should not be empty'
    assert name.pointers[0]['id'] == ACCOUNT.get_address()
    assert name.pointers[0]['key'] == "account_pubkey"
Exemplo n.º 9
0
def test_cli_name_claim(account_path):
    # create a random domain
    domain = random_domain()
    print(f"Domain is {domain}")
    # call the cli
    call_aecli('name', 'claim', account_path, domain, '--password', 'aeternity_bc')
    EPOCH_CLI.AEName(domain).status == AEName.Status.CLAIMED
Exemplo n.º 10
0
def test_cli_spend(account_path):
    # generate a new address
    recipient_address = Account.generate().get_address()
    # call the cli
    call_aecli('account', 'spend', account_path, recipient_address, "90", '--password', 'aeternity_bc')
    # test that the recipient account has the requested amount
    print(f"recipient address is {recipient_address}")
    recipient_account = EPOCH_CLI.get_account_by_pubkey(pubkey=recipient_address)
    print(f"recipient address {recipient_address}, balance {recipient_account.balance}")
    assert recipient_account.balance == 90
Exemplo n.º 11
0
def test_cli_inspect_key_block_by_hash():
    height = EPOCH_CLI.get_current_key_block_height()
    jh = call_aecli('inspect', str(height))
    # retrieve the block hash
    jb = call_aecli('inspect', jh.get("hash"))

    assert jh.get("height") == jb.get("height")
    assert jh.get("hash") == jb.get("hash")
    assert jh.get("time") == jb.get("time")
    assert jh.get("miner") == jb.get("miner")
    assert jh.get("nonce") == jb.get("nonce")
Exemplo n.º 12
0
def test_api_get_block_by_hash():

    has_kb, has_mb = False, False
    while not has_kb or not has_mb:
        # the latest block could be both micro or key block
        latest_block = EPOCH_CLI.get_top_block()
        has_mb = latest_block.hash.startswith(
            "mh_") or has_mb  # check if is a microblock
        has_kb = latest_block.hash.startswith(
            "kh_") or has_kb  # check if is a keyblock
        print(has_kb, has_mb, latest_block.hash)
        # create a transaction so the top block is going to be an micro block
        if not has_mb:
            account = Account.generate().get_address()
            EPOCH_CLI.spend(ACCOUNT, account, 100)
        # wait for the next block
        # client.wait_for_next_block()
        block = EPOCH_CLI.get_block_by_hash(hash=latest_block.hash)
        # assert block.hash == latest_block.hash
        assert block.height == latest_block.height
Exemplo n.º 13
0
def test_cli_inspect_transaction_by_hash():
    # fill the account from genesys
    na = Account.generate()
    amount = random.randint(50, 150)
    _, _, tx_hash = EPOCH_CLI.spend(ACCOUNT, na.get_address(), amount)
    # now inspect the transaction
    j = call_aecli('inspect', tx_hash)
    assert j.get("hash") == tx_hash
    assert j.get("block_height") > 0
    assert j.get("tx", {}).get("recipient_id") == na.get_address()
    assert j.get("tx", {}).get("sender_id") == ACCOUNT.get_address()
    assert j.get("tx", {}).get("amount") == amount
Exemplo n.º 14
0
def test_signing_create_transaction():
    # generate a new account
    new_account = Account.generate()
    receiver_address = new_account.get_address()
    # create a spend transaction
    txb = TxBuilder(EPOCH_CLI, ACCOUNT)
    tx, sg, tx_hash = txb.tx_spend(receiver_address, 321, "test test ",
                                   TEST_FEE, TEST_TTL)
    # this call will fail if the hashes of the transaction do not match
    txb.post_transaction(tx, tx_hash)
    # make sure this works for very short block times
    spend_tx = EPOCH_CLI.get_transaction_by_hash(hash=tx_hash)
    assert spend_tx.signatures[0] == sg
Exemplo n.º 15
0
def test_name_transfer_ownership():
    name = EPOCH_CLI.AEName(random_domain())
    name.full_claim_blocking(ACCOUNT)
    assert name.status == AEName.Status.CLAIMED
    name.update_status()
    assert name.pointers[0]['id'] == ACCOUNT.get_address()
    assert name.pointers[0]['key'] == "account_pubkey"

    new_key_pair = Account.generate()
    # put some coins into the account so the account is in the state tree
    # otherwise it couldn't become the owner of an address.
    EPOCH_CLI.spend(ACCOUNT, new_key_pair.get_address(), 100)
    # now transfer the name to the other account
    name.transfer_ownership(ACCOUNT, new_key_pair.get_address())
    assert name.status == AEName.Status.TRANSFERRED
    # try changing the target using that new account
    name.update_status()
    name.update(new_key_pair, new_key_pair.get_address())
    name.update_status()
    assert len(name.pointers) > 0, 'Pointers should not be empty'
    assert name.pointers[0]['id'] == new_key_pair.get_address()
    assert name.pointers[0]['key'] == "account_pubkey"
Exemplo n.º 16
0
def test_name_claim_lifecycle():
    try:
        domain = random_domain()
        name = EPOCH_CLI.AEName(domain)
        assert name.status == AEName.Status.UNKNOWN
        name.update_status()
        assert name.status == AEName.Status.AVAILABLE
        name.preclaim(ACCOUNT)
        assert name.status == AEName.Status.PRECLAIMED
        name.claim(ACCOUNT)
        assert name.status == AEName.Status.CLAIMED
    except Exception as e:
        print(e)
        assert e is None
Exemplo n.º 17
0
def test_sophia_contract_tx_call():
    contract = EPOCH_CLI.Contract(aer_identity_contract)
    tx = contract.tx_create(ACCOUNT, gas=1000)
    print("contract: ", contract.address)
    print("tx contract: ", tx)

    result = contract.tx_call(ACCOUNT, 'main', '42', gas=1000)
    assert result is not None
    assert result.return_type == 'ok'
    print("return", result.return_value)
    print("raw", hashing.decode(result.return_value))
    # assert result.return_value.lower() == hashing.encode("cb", f'{hex(42)[2:].zfill(64).lower()}')

    val, remote_type = contract.decode_data(result.return_value, 'int')
    assert val == 42
    assert remote_type == 'word'
Exemplo n.º 18
0
def test_oracle_query_received():
    weather_oracle = WeatherOracle(
        query_format="{'city': str}",
        response_format="{'temp_c': int}",
        default_query_fee=0,
        default_fee=10,
        default_ttl=50,
        default_query_ttl=2,
        default_response_ttl=2,
    )
    EPOCH_CLI.register_oracle(weather_oracle)
    EPOCH_CLI.listen_until(weather_oracle.is_ready, timeout=5)
    weather_query = WeatherQuery(
        oracle_pubkey=weather_oracle.oracle_id,
        query_fee=0,
        fee=10,
        query_ttl=2,
        response_ttl=2,
    )
    EPOCH_CLI.mount(weather_query)
    weather_query.query("{'city': 'Berlin'}")
    EPOCH_CLI.listen_until(lambda: weather_query.response_received, timeout=5)
Exemplo n.º 19
0
def test_sophia_encode_calldata():
    contract = EPOCH_CLI.Contract(aer_identity_contract)
    result = contract.encode_calldata('main', '1')
    assert result is not None
    assert utils.is_valid_hash(result, prefix='cb')
Exemplo n.º 20
0
def test_sophia_contract_tx_create():
    contract = EPOCH_CLI.Contract(aer_identity_contract)
    contract.tx_create(ACCOUNT, gas=10000)
    assert contract.address is not None
    assert len(contract.address) > 0
    assert contract.address.startswith('ct')
Exemplo n.º 21
0
def test_name_status_availavle():
    name = EPOCH_CLI.AEName(random_domain())
    assert name.status == AEName.Status.UNKNOWN
    name.update_status()
    assert name.status == AEName.Status.AVAILABLE
Exemplo n.º 22
0
def test_name_is_available():
    name = EPOCH_CLI.AEName(random_domain())
    assert name.is_available()
Exemplo n.º 23
0
def test_name_validation_succeeds():
    EPOCH_CLI.AEName('test.test')
Exemplo n.º 24
0
def test_name_validation_fails():
    with raises(ValueError):
        EPOCH_CLI.AEName('test.lol')
Exemplo n.º 25
0
def test_sophia_contract_compile():
    contract = EPOCH_CLI.Contract(aer_identity_contract)
    assert contract is not None
    utils.is_valid_hash(contract.bytecode, prefix='cb')
Exemplo n.º 26
0
def test_name_committment():
    domain = random_domain()
    name = EPOCH_CLI.AEName(domain)
    cl = name._get_commitment_hash()
    cr = name.client.get_commitment_id(name=name.domain, salt=name.preclaim_salt)
    assert cl == cr.commitment_id
Exemplo n.º 27
0
def test_evm_contract_compile():
    contract = EPOCH_CLI.Contract(aer_identity_contract, abi=Contract.EVM)
    print(contract)
    assert contract.bytecode is not None
    assert utils.is_valid_hash(contract.bytecode, prefix='cb')
Exemplo n.º 28
0
def test_sophia_broken_encode_calldata():
    with raises(ContractError):
        contract = EPOCH_CLI.Contract(broken_contract)
        result = contract.encode_calldata('IdentityBroken.main', '1')
        print(result)
Exemplo n.º 29
0
def test_sophia_broken_contract_compile():
    with raises(ContractError):
        contract = EPOCH_CLI.Contract(broken_contract)
        print(contract.source_code)
Exemplo n.º 30
0
def test_sophia_contract_call():
    contract = EPOCH_CLI.Contract(aer_identity_contract)
    result = contract.call('main', '1')
    assert result is not None
    assert result.out