def test_contract_native_full(compiler_fixture, chain_fixture): compiler = compiler_fixture.COMPILER account = chain_fixture.ALICE contract_native = ContractNative(client=chain_fixture.NODE_CLI, source=contract, compiler=compiler, account=account) contract_native.deploy("abcd", 12, "A", {"key": "value"}) assert (contract_native.address is not None) _, call_result = contract_native.intFn(12) assert (call_result == 12) _, call_result = contract_native.stringFn("test_call") assert (call_result == 'test_call') _, call_result = contract_native.addressFn( chain_fixture.ALICE.get_address()) assert (call_result == chain_fixture.ALICE.get_address()) _, call_result = contract_native.boolFn(False) assert (call_result == False) _, call_result = contract_native.tupleFn(["test", 1]) assert (call_result == ["test", 1]) _, call_result = contract_native.listFn([1, 2, 3, 4, 5]) assert (call_result == [1, 2, 3, 4, 5]) _, call_result = contract_native.mapFn({ "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi": ["test", 12] }) assert (call_result == { 'ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi': ['test', 12] }) _, call_result = contract_native.intOption(12) assert (call_result == 12) _, call_result = contract_native.setRecord({ "value": "test1", "key": 12, "testOption": "test2", "testmap": { "key1": "value1" } }) assert (call_result == []) _, call_result = contract_native.getRecord() assert (call_result == { 'key': 12, 'testOption': 'test2', 'value': 'test1', "testmap": { "key1": "value1" } }) _, call_result = contract_native.retrieve() assert (call_result == ['test1', 12]) _, call_result = contract_native.datTypeFn({"Year": []}) assert (call_result == 'Year') try: call_info = contract_native.intOption(12, 13) raise RuntimeError("Method call should fail") except Exception as e: expected_error_message = "Invalid number of arguments. Expected 1, Provided 2" assert (str(e) == expected_error_message) try: call_info, call_result = contract_native.cause_error_require() raise RuntimeError("Method call should fail") except Exception as e: expected_error_message = "Error occurred while executing the contract method. Error Type: abort. Error Message: require failed" assert str(e) == expected_error_message try: call_info, call_result = contract_native.cause_error_abort( use_dry_run=False) raise RuntimeError("Method call should fail") except Exception as e: expected_error_message = "Error occurred while executing the contract method. Error Type: abort. Error Message: triggered abort" assert str(e) == expected_error_message try: call_info, call_result = contract_native.spend_all() raise RuntimeError("Method call should fail") except Exception as e: expected_error_message = "Error occurred while executing the contract method. Error Type: error. Error Message: " assert str(e) == expected_error_message try: call_info, call_result = contract_native.try_switch('name1') raise RuntimeError("Method call should fail") except Exception as e: expected_error_message = "Error occurred while executing the contract method. Error Type: abort. Error Message: name not found" assert str(e) == expected_error_message
def test_contract_native(compiler_fixture, chain_fixture): compiler = compiler_fixture.COMPILER account = chain_fixture.ALICE contract_native = ContractNative(client=chain_fixture.NODE_CLI, source=contract, compiler=compiler, account=account) contract_native.deploy("abcd", 12, "A") assert (contract_native.address is not None) _, call_result = contract_native.intFn(12) assert (call_result == 12) _, call_result = contract_native.stringFn("test_call") assert (call_result == 'test_call') _, call_result = contract_native.addressFn( chain_fixture.ALICE.get_address()) assert (call_result == chain_fixture.ALICE.get_address()) _, call_result = contract_native.boolFn(False) assert (call_result == False) _, call_result = contract_native.tupleFn(["test", 1]) assert (call_result == ["test", 1]) _, call_result = contract_native.listFn([1, 2, 3, 4, 5]) assert (call_result == [1, 2, 3, 4, 5]) _, call_result = contract_native.mapFn({ "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi": ["test", 12] }) assert (call_result == { 'ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi': ['test', 12] }) _, call_result = contract_native.intOption(12) assert (call_result == 12) _, call_result = contract_native.setRecord({ "value": "test1", "key": 12, "testOption": "test2" }) assert (call_result == []) _, call_result = contract_native.getRecord() assert (call_result == { 'key': 12, 'testOption': 'test2', 'value': 'test1' }) _, call_result = contract_native.retrieve() assert (call_result == ['test1', 12]) _, call_result = contract_native.datTypeFn({"Year": []}) assert (call_result == {'Year': []}) try: call_info = contract_native.intOption(12, 13) raise ValueError("Method call should fail") except Exception as e: expected_error_message = "Invalid number of arguments. Expected 1, Provided 2" assert (str(e) == expected_error_message)