use of com.hedera.hashgraph.sdk.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractCallIntegrationTest method getCostBigMaxContractCallFunction.
@Test
@DisplayName("Can get cost, even with a big max")
void getCostBigMaxContractCallFunction() 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").setQueryPayment(new Hbar(1));
var result = callQuery.execute(testEnv.client);
assertThat(result.getString(0)).isEqualTo("Hello from Hedera.");
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 ContractCreateIntegrationTest method canCreateContractWithNoAdminKey.
@Test
@DisplayName("Can create contract with no admin key")
void canCreateContractWithNoAdminKey() 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().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 info = new ContractInfoQuery().setContractId(contractId).execute(testEnv.client);
assertThat(info.contractId).isEqualTo(contractId);
assertThat(info.accountId).isNotNull();
assertThat(Objects.requireNonNull(info.accountId).toString()).isEqualTo(Objects.requireNonNull(contractId).toString());
assertThat(info.adminKey).isNotNull();
// assertEquals(info.adminKey, contractId);
assertThat(info.storage).isEqualTo(128);
assertThat(info.contractMemo).isEqualTo("[e2e::ContractCreateTransaction]");
testEnv.close();
}
use of com.hedera.hashgraph.sdk.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractCreateIntegrationTest method canCreateContract.
@Test
@DisplayName("Can create contract")
void canCreateContract() 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 info = new ContractInfoQuery().setContractId(contractId).execute(testEnv.client);
assertThat(info.contractId).isEqualTo(contractId);
assertThat(info.accountId).isNotNull();
assertThat(Objects.requireNonNull(info.accountId).toString()).isEqualTo(Objects.requireNonNull(contractId).toString());
assertThat(info.adminKey).isNotNull();
assertThat(Objects.requireNonNull(info.adminKey).toString()).isEqualTo(Objects.requireNonNull(testEnv.operatorKey).toString());
assertThat(info.storage).isEqualTo(128);
assertThat(info.contractMemo).isEqualTo("[e2e::ContractCreateTransaction]");
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 ContractCreateIntegrationTest method cannotCreateContractWhenBytecodeFileIdIsNotSet.
@Test
@DisplayName("Cannot create contract when bytecode file ID is not set")
void cannotCreateContractWhenBytecodeFileIdIsNotSet() throws Exception {
var testEnv = new IntegrationTestEnv(1);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.INVALID_FILE_ID.toString());
testEnv.close();
}
use of com.hedera.hashgraph.sdk.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractCreateIntegrationTest method cannotCreateContractWhenConstructorParametersAreNotSet.
@Test
@DisplayName("Cannot create contract when constructor parameters are not set")
void cannotCreateContractWhenConstructorParametersAreNotSet() 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);
assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.CONTRACT_REVERT_EXECUTED.toString());
new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
Aggregations