use of com.hedera.hashgraph.sdk.ContractExecuteTransaction in project hedera-sdk-java by hashgraph.
the class ContractCreateFlowIntegrationTest method createContractWithFlow.
@Test
@DisplayName("Create contract with flow")
void createContractWithFlow() throws Throwable {
var testEnv = new IntegrationTestEnv(1);
var response = new ContractCreateFlow().setBytecode(SMART_CONTRACT_BYTECODE).setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setContractMemo("[e2e::ContractCreateFlow]").execute(testEnv.client);
var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);
var receipt = new ContractExecuteTransaction().setContractId(contractId).setGas(100000).setFunction("setMessage", new ContractFunctionParameters().addString("new message")).execute(testEnv.client).getReceipt(testEnv.client);
assertThat(receipt.status).isEqualTo(Status.SUCCESS);
new ContractDeleteTransaction().setTransferAccountId(testEnv.operatorId).setContractId(contractId).setTransferAccountId(testEnv.operatorId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.ContractExecuteTransaction in project hedera-sdk-java by hashgraph.
the class ContractExecuteIntegrationTest method cannotExecuteContractWhenContractFunctionParametersAreNotSet.
@Test
@DisplayName("Cannot execute contract when contract function parameters are not set")
void cannotExecuteContractWhenContractFunctionParametersAreNotSet() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
var contractId = Objects.requireNonNull(new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client).getReceipt(testEnv.client).contractId);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new ContractExecuteTransaction().setContractId(contractId).setGas(100000).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.CONTRACT_REVERT_EXECUTED.toString());
new ContractDeleteTransaction().setTransferAccountId(testEnv.operatorId).setContractId(contractId).execute(testEnv.client).getReceipt(testEnv.client);
new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.ContractExecuteTransaction in project hedera-sdk-java by hashgraph.
the class ContractExecuteIntegrationTest method cannotExecuteContractWhenContractIDIsNotSet.
@Test
@DisplayName("Cannot execute contract when contract ID is not set")
void cannotExecuteContractWhenContractIDIsNotSet() throws Exception {
var testEnv = new IntegrationTestEnv(1);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new ContractExecuteTransaction().setGas(100000).setFunction("setMessage", new ContractFunctionParameters().addString("new message")).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.INVALID_CONTRACT_ID.toString());
testEnv.close();
}
use of com.hedera.hashgraph.sdk.ContractExecuteTransaction in project hedera-mirror-node by hashgraph.
the class ContractClient method executeContract.
public NetworkTransactionResponse executeContract(ContractId contractId, long gas, String functionName, ContractFunctionParameters parameters, Hbar payableAmount) {
log.debug("Call contract {}'s function {}", contractId, functionName);
ContractExecuteTransaction contractExecuteTransaction = new ContractExecuteTransaction().setContractId(contractId).setGas(gas).setTransactionMemo(getMemo("Execute contract")).setMaxTransactionFee(Hbar.from(100));
if (parameters == null) {
contractExecuteTransaction.setFunction(functionName);
} else {
contractExecuteTransaction.setFunction(functionName, parameters);
}
if (payableAmount != null) {
contractExecuteTransaction.setPayableAmount(payableAmount);
}
NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(contractExecuteTransaction);
TransactionRecord transactionRecord = getTransactionRecord(networkTransactionResponse.getTransactionId());
logContractFunctionResult(functionName, transactionRecord.contractFunctionResult);
return networkTransactionResponse;
}
use of com.hedera.hashgraph.sdk.ContractExecuteTransaction in project hedera-sdk-java by hashgraph.
the class ContractExecuteIntegrationTest method cannotExecuteContractWhenGasIsNotSet.
@Test
@DisplayName("Cannot execute contract when gas is not set")
void cannotExecuteContractWhenGasIsNotSet() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
var contractId = Objects.requireNonNull(new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client).getReceipt(testEnv.client).contractId);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new ContractExecuteTransaction().setContractId(contractId).setFunction("setMessage", new ContractFunctionParameters().addString("new message")).execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.INSUFFICIENT_GAS.toString());
new ContractDeleteTransaction().setTransferAccountId(testEnv.operatorId).setContractId(contractId).execute(testEnv.client).getReceipt(testEnv.client);
new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
Aggregations