use of com.hedera.hashgraph.sdk.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractInfoIntegrationTest method canQueryContractInfoWhenAdminKeyIsNull.
@Test
@DisplayName("Can query contract info when admin key is null")
void canQueryContractInfoWhenAdminKeyIsNull() 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(contractId.toString());
assertThat(info.adminKey).isNotNull();
// TODO: Fix this when we know it's correct
// 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 ContractInfoIntegrationTest method getCostBigMaxContractInfoFunction.
@Test
@DisplayName("Can get cost, even with a big max")
@SuppressWarnings("UnusedVariable")
void getCostBigMaxContractInfoFunction() 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 infoQuery = new ContractInfoQuery().setContractId(contractId).setMaxQueryPayment(new Hbar(10000));
var cost = infoQuery.getCost(testEnv.client);
var result = infoQuery.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 ContractUpdateIntegrationTest method cannotUpdateContractThatIsImmutable.
@Test
@DisplayName("Cannot update contract that is immutable")
void cannotUpdateContractThatIsImmutable() 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().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 ContractUpdateTransaction().setContractId(contractId).setContractMemo("[e2e::ContractUpdateTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
}).withMessageContaining(Status.MODIFYING_IMMUTABLE_CONTRACT.toString());
testEnv.close();
}
use of com.hedera.hashgraph.sdk.ContractCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractUpdateIntegrationTest method canUpdateContract.
@Test
@DisplayName("Can update contract")
void canUpdateContract() 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 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(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 ContractUpdateTransaction().setContractId(contractId).setContractMemo("[e2e::ContractUpdateTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
info = new ContractInfoQuery().setContractId(contractId).execute(testEnv.client);
assertThat(info.contractId).isEqualTo(contractId);
assertThat(info.accountId).isNotNull();
assertThat(Objects.requireNonNull(info.accountId).toString()).isEqualTo(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::ContractUpdateTransaction]");
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-mirror-node by hashgraph.
the class ContractClient method createContract.
public NetworkTransactionResponse createContract(FileId fileId, long gas, Hbar payableAmount, ContractFunctionParameters contractFunctionParameters) {
log.debug("Create new contract");
String memo = getMemo("Create contract");
ContractCreateTransaction contractCreateTransaction = new ContractCreateTransaction().setAdminKey(sdkClient.getExpandedOperatorAccountId().getPublicKey()).setBytecodeFileId(fileId).setContractMemo(memo).setGas(gas).setTransactionMemo(memo);
if (contractFunctionParameters != null) {
contractCreateTransaction.setConstructorParameters(contractFunctionParameters);
}
if (payableAmount != null) {
contractCreateTransaction.setInitialBalance(payableAmount);
}
NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(contractCreateTransaction);
ContractId contractId = networkTransactionResponse.getReceipt().contractId;
log.debug("Created new contract {}", contractId);
TransactionRecord transactionRecord = getTransactionRecord(networkTransactionResponse.getTransactionId());
logContractFunctionResult("constructor", transactionRecord.contractFunctionResult);
return networkTransactionResponse;
}
Aggregations