use of com.hedera.hashgraph.sdk.FileCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractBytecodeIntegrationTest method getCostInsufficientTxFeeQueryContractBytecode.
@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeQueryContractBytecode() 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(100));
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
bytecodeQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
}).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
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.FileCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractBytecodeIntegrationTest method getCostSmallMaxQueryContractBytecode.
@Test
@DisplayName("Error, max is smaller than set payment.")
void getCostSmallMaxQueryContractBytecode() 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(Hbar.fromTinybars(1));
assertThatExceptionOfType(MaxQueryPaymentExceededException.class).isThrownBy(() -> {
bytecodeQuery.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.FileCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractCallIntegrationTest method cannotCallContractFunctionWhenContractIDIsNotSet.
@Test
@DisplayName("Cannot call contract function when contract ID is not set")
void cannotCallContractFunctionWhenContractIDIsNotSet() 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().setGas(100000).setFunction("getMessage").execute(testEnv.client);
}).withMessageContaining(Status.INVALID_CONTRACT_ID.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.FileCreateTransaction in project hedera-sdk-java by hashgraph.
the class ContractCallIntegrationTest method getCostInsufficientTxFeeContractCallFunction.
@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeContractCallFunction() 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(new Hbar(100));
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
callQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
}).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
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.FileCreateTransaction in project hedera-sdk-java by hashgraph.
the class DeleteFileExample method main.
public static void main(String[] args) throws PrecheckStatusException, TimeoutException, ReceiptStatusException {
Client client = Client.forName(HEDERA_NETWORK);
// Defaults the operator account ID and key such that all generated transactions will be paid for
// by this account and be signed by this key
client.setOperator(OPERATOR_ID, OPERATOR_KEY);
// The file is required to be a byte array,
// you can easily use the bytes of a file instead.
String fileContents = "Hedera hashgraph is great!";
TransactionResponse transactionResponse = new FileCreateTransaction().setKeys(OPERATOR_KEY).setContents(fileContents).setMaxTransactionFee(new Hbar(2)).execute(client);
TransactionReceipt receipt = transactionResponse.getReceipt(client);
FileId newFileId = Objects.requireNonNull(receipt.fileId);
System.out.println("file: " + newFileId);
// now delete the file
TransactionResponse fileDeleteTransactionResponse = new FileDeleteTransaction().setFileId(newFileId).execute(client);
// if this doesn't throw then the transaction was a success
fileDeleteTransactionResponse.getReceipt(client);
System.out.println("File deleted successfully.");
new FileInfoQuery().setFileId(newFileId).execute(client);
// note the above fileInfo will fail with FILE_DELETED due to a known issue on Hedera
}
Aggregations