use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS in project hedera-services by hashgraph.
the class ExtCodeCopyOperationSuite method verifiesExistence.
HapiApiSpec verifiesExistence() {
final String CONTRACT = "extCodeCopyOpChecker";
final String INVALID_ADDRESS = "0x0000000000000000000000000000000000123456";
ByteString EMPTY_BYTECODE = ByteString.EMPTY;
return defaultHapiSpec("VerifiesExistence").given(fileCreate("bytecode").path(ContractResources.EXT_CODE_OPERATIONS_CHECKER_CONTRACT), contractCreate("extCodeCopyOpChecker").bytecode("bytecode").gas(300_000L)).when().then(contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, INVALID_ADDRESS).hasKnownStatus(INVALID_SOLIDITY_ADDRESS), contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, INVALID_ADDRESS).hasAnswerOnlyPrecheck(INVALID_SOLIDITY_ADDRESS), withOpContext((spec, opLog) -> {
AccountID accountID = spec.registry().getAccountID(DEFAULT_PAYER);
ContractID contractID = spec.registry().getContractId(CONTRACT);
String accountSolidityAddress = asHexedSolidityAddress(accountID);
String contractAddress = asHexedSolidityAddress(contractID);
final var call = contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, accountSolidityAddress).via("callRecord");
final var callRecord = getTxnRecord("callRecord");
final var accountCodeCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, accountSolidityAddress).saveResultTo("accountCode");
final var contractCodeCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, contractAddress).saveResultTo("contractCode");
final var getBytecodeCall = getContractBytecode(CONTRACT).saveResultTo("contractGetBytecode");
allRunFor(spec, call, callRecord, accountCodeCallLocal, contractCodeCallLocal, getBytecodeCall);
final var recordResult = callRecord.getResponseRecord().getContractCallResult();
final var accountCode = spec.registry().getBytes("accountCode");
final var contractCode = spec.registry().getBytes("contractCode");
final var getBytecode = spec.registry().getBytes("contractGetBytecode");
Assertions.assertEquals(EMPTY_BYTECODE, recordResult.getContractCallResult());
Assertions.assertArrayEquals(EMPTY_BYTECODE.toByteArray(), accountCode);
Assertions.assertArrayEquals(getBytecode, contractCode);
}));
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS in project hedera-services by hashgraph.
the class ExtCodeHashOperationSuite method verifiesExistence.
HapiApiSpec verifiesExistence() {
final String CONTRACT = "extCodeHashOpChecker";
final String INVALID_ADDRESS = "0x0000000000000000000000000000000000123456";
final ByteString EXPECTED_ACCOUNT_HASH = ByteString.copyFrom(Hash.keccak256(Bytes.EMPTY).toArray());
return defaultHapiSpec("VerifiesExistence").given(fileCreate("bytecode").path(ContractResources.EXT_CODE_OPERATIONS_CHECKER_CONTRACT), contractCreate(CONTRACT).bytecode("bytecode").gas(300_000L)).when().then(contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, INVALID_ADDRESS).hasKnownStatus(INVALID_SOLIDITY_ADDRESS), contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, INVALID_ADDRESS).hasAnswerOnlyPrecheck(INVALID_SOLIDITY_ADDRESS), withOpContext((spec, opLog) -> {
AccountID accountID = spec.registry().getAccountID(DEFAULT_PAYER);
ContractID contractID = spec.registry().getContractId(CONTRACT);
String accountSolidityAddress = asHexedSolidityAddress(accountID);
String contractAddress = asHexedSolidityAddress(contractID);
final var call = contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, accountSolidityAddress).via("callRecord");
final var callRecord = getTxnRecord("callRecord");
final var accountCodeHashCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, accountSolidityAddress).saveResultTo("accountCodeHash");
final var contractCodeHash = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, contractAddress).saveResultTo("contractCodeHash");
final var getBytecode = getContractBytecode(CONTRACT).saveResultTo("contractBytecode");
allRunFor(spec, call, callRecord, accountCodeHashCallLocal, contractCodeHash, getBytecode);
final var recordResult = callRecord.getResponseRecord().getContractCallResult();
final var accountCodeHash = spec.registry().getBytes("accountCodeHash");
final var contractCodeResult = spec.registry().getBytes("contractCodeHash");
final var contractBytecode = spec.registry().getBytes("contractBytecode");
final var expectedContractCodeHash = ByteString.copyFrom(Hash.keccak256(Bytes.of(contractBytecode)).toArray()).toByteArray();
Assertions.assertEquals(EXPECTED_ACCOUNT_HASH, recordResult.getContractCallResult());
Assertions.assertArrayEquals(EXPECTED_ACCOUNT_HASH.toByteArray(), accountCodeHash);
Assertions.assertArrayEquals(expectedContractCodeHash, contractCodeResult);
}));
}
Aggregations