def test_contract_native_verify_contract_id(compiler_fixture, chain_fixture): identity_contract = "contract Identity =\n entrypoint main(x : int) = x" compiler = compiler_fixture.COMPILER account = chain_fixture.ALICE contract_native = ContractNative(client=chain_fixture.NODE_CLI, source=identity_contract, compiler=compiler, account=account) contract_native.deploy() contract_native.at(contract_native.address) INVALID_ADDRESS = 'ct_M9yohHgcLjhpp1Z8SaA1UTmRMQzR4FWjJHajGga8KBoZTEPwC' try: contract_native.at(INVALID_ADDRESS) except Exception as e: assert str(e) == 'Contract not deployed'
def test_contract_native_verify_contract_id(compiler_fixture, chain_fixture): identity_contract = "contract Identity =\n entrypoint main(x : int) = x" identity_contract_2 = """contract Identity = entrypoint main(x : int) = x entrypoint mainString(x : string) = x""" compiler = compiler_fixture.COMPILER account = chain_fixture.ALICE contract_native = ContractNative(client=chain_fixture.NODE_CLI, source=identity_contract, compiler=compiler, account=account) contract_native.deploy() contract_native.at(contract_native.address) contract_native_2 = ContractNative(client=chain_fixture.NODE_CLI, source=identity_contract_2, compiler=compiler, account=account) contract_native_2.deploy() INVALID_ADDRESS = 'ct_M9yohHgcLjhpp1Z8SaA1UTmRMQzR4FWjJHajGga8KBoZTEPwC' try: contract_native_2.at(contract_native.address) raise RuntimeError("Method call should fail") except Exception as e: assert str(e) == 'Invalid contract' try: contract_native.at(INVALID_ADDRESS) raise RuntimeError("Method call should fail") except Exception as e: assert str(e) == 'Contract not deployed' try: contract_native.at('ak_11111') raise RuntimeError("Method call should fail") except Exception as e: assert str(e) == 'Invalid contract address ak_11111'
def test_example_contract_native(chain_fixture): NODE_URL = os.environ.get('TEST_URL', 'http://127.0.0.1:3013') NODE_INTERNAL_URL = os.environ.get('TEST_DEBUG_URL', 'http://127.0.0.1:3113') COMPILER_URL = os.environ.get('TEST_COMPILER__URL', 'https://compiler.aepps.com') node_cli = NodeClient( Config( external_url=NODE_URL, internal_url=NODE_INTERNAL_URL, blocking_mode=True, )) compiler = CompilerClient(compiler_url=COMPILER_URL) sender_account = chain_fixture.ALICE # genrate ALICE account (and transfer AE to alice account) alice = Account.generate() node_cli.spend(sender_account, alice.get_address(), 5000000000000000000) CONTRACT_FILE = os.path.join(os.path.dirname(__file__), "testdata/CryptoHamster.aes") # read contract file with open(CONTRACT_FILE, 'r') as file: crypto_hamster_contract = file.read() """ Initialize the contract instance Note: To disable use of dry-run endpoint add the parameter use_dry_run=False """ crypto_hamster = ContractNative(client=node_cli, compiler=compiler, account=alice, source=crypto_hamster_contract) # deploy the contract # (also pass the args of thr init function - if any) tx = crypto_hamster.deploy() print(f"contract address: {crypto_hamster.address}") # PART 2 Call the contract CONTRACT_ID = crypto_hamster.address # CONTRACT_ID is the address of the deployed contract crypto_hamster.at(CONTRACT_ID) # call the contract method (stateful) tx_info, tx_result = crypto_hamster.add_test_value(1, 2) print(f"Transaction Hash: {tx_info.tx_hash}") print(f"Transaction Result/Return Data: {tx_result}") assert (tx_result == 3) assert (hasattr(tx_info, 'tx_hash')) # call contract method (not stateful) tx_info, tx_result = crypto_hamster.get_hamster_dna( "SuperCryptoHamster", None) print(f"Transaction Result/Return Data: {tx_result}") assert tx_result is not None assert not hasattr(tx_info, 'tx_hash')