use of com.hedera.hashgraph.sdk.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class SystemIntegrationTest method allSystemTransactionsAreNotSupported.
@Test
@DisplayName("All system transactions are not supported")
void allSystemTransactionsAreNotSupported() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var fileId = Objects.requireNonNull(new FileCreateTransaction().setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client).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(PrecheckStatusException.class).isThrownBy(() -> {
new SystemDeleteTransaction().setContractId(contractId).setExpirationTime(Instant.now()).execute(testEnv.client);
}).withMessageContaining(Status.NOT_SUPPORTED.toString());
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
new SystemDeleteTransaction().setFileId(fileId).setExpirationTime(Instant.now()).execute(testEnv.client);
}).withMessageContaining(Status.NOT_SUPPORTED.toString());
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
new SystemUndeleteTransaction().setContractId(contractId).execute(testEnv.client);
}).withMessageContaining(Status.NOT_SUPPORTED.toString());
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
new SystemUndeleteTransaction().setFileId(fileId).execute(testEnv.client);
}).withMessageContaining(Status.NOT_SUPPORTED.toString());
testEnv.close();
}
use of com.hedera.hashgraph.sdk.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractBytecodeIntegrationTest method canQueryContractBytecode.
@Test
@DisplayName("Can query contract bytecode")
void canQueryContractBytecode() throws Exception {
var testEnv = new IntegrationTestEnv(1);
@Var var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
response = new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client);
var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);
var bytecode = new ContractByteCodeQuery().setContractId(contractId).execute(testEnv.client);
assertThat(bytecode.size()).isEqualTo(798);
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.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractBytecodeIntegrationTest method getCostBigMaxQueryContractBytecode.
@Test
@DisplayName("Can get cost, even with a big max")
void getCostBigMaxQueryContractBytecode() throws Exception {
var testEnv = new IntegrationTestEnv(1);
@Var var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
response = new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client);
var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);
var bytecodeQuery = new ContractByteCodeQuery().setContractId(contractId).setMaxQueryPayment(new Hbar(1000));
var cost = bytecodeQuery.getCost(testEnv.client);
var bytecode = bytecodeQuery.setQueryPayment(cost).execute(testEnv.client);
assertThat(bytecode.size()).isEqualTo(798);
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.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractCallIntegrationTest method getCostSmallMaxContractCallFunction.
@Test
@DisplayName("Error, max is smaller than set payment.")
void getCostSmallMaxContractCallFunction() throws Exception {
var testEnv = new IntegrationTestEnv(1);
@Var var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
response = new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client);
var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);
var callQuery = new ContractCallQuery().setContractId(contractId).setGas(100000).setFunction("getMessage").setMaxQueryPayment(Hbar.fromTinybars(1));
assertThatExceptionOfType(MaxQueryPaymentExceededException.class).isThrownBy(() -> {
callQuery.execute(testEnv.client);
});
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.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractCallIntegrationTest method cannotCallContractFunctionWhenGasIsNotSet.
@Test
@DisplayName("Cannot call contract function when gas is not set")
void cannotCallContractFunctionWhenGasIsNotSet() 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(PrecheckStatusException.class).isThrownBy(() -> {
new ContractCallQuery().setContractId(contractId).setFunction("getMessage").execute(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