def test_contract_native_without_dry_run(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() assert (contract_native.address is not None) call_info, call_result = contract_native.main(12) assert (call_result == 12 and not hasattr(call_info, 'tx_hash')) call_info, call_result = contract_native.main(12, use_dry_run=False) assert (call_result == 12 and hasattr(call_info, 'tx_hash'))
def test_contract_native_default_account_overriding(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() assert (contract_native.address is not None) call_info, _ = contract_native.main(12) assert (call_info.caller_id == chain_fixture.ALICE.get_address()) call_info, _ = contract_native.main(12, account=chain_fixture.BOB) assert (call_info.caller_id == chain_fixture.BOB.get_address()) contract_native.set_account(chain_fixture.BOB) call_info, _ = contract_native.main(12) assert (call_info.caller_id == chain_fixture.BOB.get_address())
def test_contract_native_without_default_account(compiler_fixture, chain_fixture): identity_contract = "contract Identity =\n entrypoint main(x : int) = x" compiler = compiler_fixture.COMPILER contract_native = ContractNative(client=chain_fixture.NODE_CLI, source=identity_contract, compiler=compiler) contract_native.deploy(account=chain_fixture.ALICE) assert (contract_native.address is not None) call_info, call_result = contract_native.main(12, account=chain_fixture.BOB) assert (call_result == 12) try: _, call_result = contract_native.main(12) raise ValueError("Method call should fail") except Exception as e: assert ( str(e) == "Please provide an account to sign contract call transactions. You can set a default account using 'set_account' method" )
def test_contract_native_without_default_account(compiler_fixture, chain_fixture): identity_contract = "contract Identity =\n entrypoint main(x : int) = x" compiler = compiler_fixture.COMPILER contract_native = ContractNative(client=chain_fixture.NODE_CLI, source=identity_contract, compiler=compiler) contract_native.deploy(account=chain_fixture.ALICE) assert (contract_native.address is not None) call_info, call_result = contract_native.main(12, account=chain_fixture.BOB) assert (call_result == 12)