From 3da628ad0584553ae3f277ff2d261d4c89609255 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Fri, 11 Oct 2024 08:24:25 +0200 Subject: [PATCH] chore: format Java code Signed-off-by: Jendrik Johannes --- examples/src/main/java/module-info.java | 4 +- .../sdk/AccountCreateTransaction.java | 30 +- .../sdk/AccountUpdateTransaction.java | 33 +- .../hashgraph/sdk/AddressBookQuery.java | 93 +- .../com/hedera/hashgraph/sdk/BaseNetwork.java | 44 +- .../com/hedera/hashgraph/sdk/BaseNode.java | 33 +- .../hashgraph/sdk/ChunkedTransaction.java | 128 +- .../java/com/hedera/hashgraph/sdk/Client.java | 149 +- .../hashgraph/sdk/ContractCreateFlow.java | 115 +- .../sdk/ContractCreateTransaction.java | 23 +- .../sdk/ContractFunctionParameters.java | 256 +- .../sdk/ContractUpdateTransaction.java | 32 +- .../com/hedera/hashgraph/sdk/Endpoint.java | 28 +- .../hedera/hashgraph/sdk/EntityIdHelper.java | 82 +- .../com/hedera/hashgraph/sdk/FeeSchedule.java | 33 +- .../hashgraph/sdk/FileCreateTransaction.java | 20 +- .../hashgraph/sdk/FileUpdateTransaction.java | 27 +- .../hashgraph/sdk/FreezeTransaction.java | 29 +- .../hashgraph/sdk/HederaTrustManager.java | 36 +- .../com/hedera/hashgraph/sdk/Keystore.java | 21 +- .../hashgraph/sdk/LiveHashAddTransaction.java | 22 +- .../com/hedera/hashgraph/sdk/Mnemonic.java | 78 +- .../com/hedera/hashgraph/sdk/Network.java | 76 +- .../com/hedera/hashgraph/sdk/NodeAddress.java | 56 +- .../com/hedera/hashgraph/sdk/PrivateKey.java | 26 +- .../com/hedera/hashgraph/sdk/PublicKey.java | 23 +- .../sdk/ScheduleCreateTransaction.java | 19 +- .../sdk/SystemDeleteTransaction.java | 21 +- .../hashgraph/sdk/TokenCreateTransaction.java | 32 +- .../hashgraph/sdk/TokenUpdateTransaction.java | 19 +- .../hashgraph/sdk/TopicCreateTransaction.java | 16 +- .../hedera/hashgraph/sdk/TopicMessage.java | 67 +- .../hashgraph/sdk/TopicMessageQuery.java | 64 +- .../hashgraph/sdk/TopicUpdateTransaction.java | 23 +- .../com/hedera/hashgraph/sdk/Transaction.java | 394 ++- .../hedera/hashgraph/sdk/TransactionId.java | 82 +- ...ccountAllowanceApproveTransactionTest.java | 100 +- ...AccountAllowanceDeleteTransactionTest.java | 47 +- .../sdk/AccountBalanceQueryTest.java | 23 +- .../sdk/AccountCreateTransactionTest.java | 80 +- .../sdk/AccountDeleteTransactionTest.java | 46 +- .../hedera/hashgraph/sdk/AccountIdTest.java | 86 +- .../hashgraph/sdk/AccountInfoQueryTest.java | 18 +- .../hedera/hashgraph/sdk/AccountInfoTest.java | 66 +- .../sdk/AccountRecordsQueryTest.java | 18 +- .../sdk/AccountStakersQueryTest.java | 18 +- .../sdk/AccountUpdateTransactionTest.java | 82 +- .../hedera/hashgraph/sdk/AllowancesTest.java | 62 +- .../hashgraph/sdk/AssessedCustomFeeTest.java | 64 +- .../sdk/ContractByteCodeQueryTest.java | 16 +- .../hashgraph/sdk/ContractCallQueryTest.java | 54 +- .../sdk/ContractCreateTransactionTest.java | 91 +- .../sdk/ContractDeleteTransactionTest.java | 45 +- .../sdk/ContractExecuteTransactionTest.java | 46 +- .../sdk/ContractFunctionParametersTest.java | 689 ++-- .../hedera/hashgraph/sdk/ContractIdTest.java | 42 +- .../hashgraph/sdk/ContractInfoQueryTest.java | 16 +- .../hashgraph/sdk/ContractInfoTest.java | 28 +- .../hashgraph/sdk/ContractLogInfoTest.java | 41 +- .../hashgraph/sdk/ContractNonceInfoTest.java | 36 +- .../sdk/ContractUpdateTransactionTest.java | 91 +- .../sdk/CryptoTransferTransactionTest.java | 164 +- .../hashgraph/sdk/CustomFeeListTest.java | 51 +- .../hashgraph/sdk/CustomFixedFeeTest.java | 30 +- .../sdk/CustomFractionalFeeTest.java | 38 +- .../hashgraph/sdk/CustomRoyaltyFeeTest.java | 29 +- .../hashgraph/sdk/DelegateContractIdTest.java | 27 +- .../sdk/EthereumTransactionTest.java | 47 +- .../hedera/hashgraph/sdk/ExecutableTest.java | 217 +- .../hashgraph/sdk/FeeSchedulesTest.java | 63 +- .../sdk/FileAppendTransactionTest.java | 190 +- .../hashgraph/sdk/FileContentsQueryTest.java | 16 +- .../sdk/FileCreateTransactionTest.java | 46 +- .../sdk/FileDeleteTransactionTest.java | 40 +- .../com/hedera/hashgraph/sdk/FileIdTest.java | 17 +- .../hashgraph/sdk/FileInfoQueryTest.java | 16 +- .../hedera/hashgraph/sdk/FileInfoTest.java | 39 +- .../sdk/FileUpdateTransactionTest.java | 48 +- .../hashgraph/sdk/FreezeTransactionTest.java | 51 +- .../com/hedera/hashgraph/sdk/KeyTest.java | 90 +- .../sdk/LiveHashAddTransactionTest.java | 49 +- .../sdk/LiveHashDeleteTransactionTest.java | 45 +- .../hashgraph/sdk/LiveHashQueryTest.java | 25 +- .../sdk/MessageSubmitTransactionTest.java | 43 +- .../sdk/NetworkVersionInfoQueryTest.java | 39 +- .../hashgraph/sdk/NetworkVersionInfoTest.java | 30 +- .../com/hedera/hashgraph/sdk/NftIdTest.java | 32 +- .../sdk/NodeCreateTransactionTest.java | 71 +- .../sdk/NodeDeleteTransactionTest.java | 29 +- .../sdk/NodeUpdateTransactionTest.java | 75 +- .../hashgraph/sdk/PrngTransactionTest.java | 46 +- .../hedera/hashgraph/sdk/ProxyStakerTest.java | 27 +- .../sdk/ScheduleCreateTransactionTest.java | 50 +- .../sdk/ScheduleDeleteTransactionTest.java | 40 +- .../hashgraph/sdk/ScheduleInfoQueryTest.java | 18 +- .../hashgraph/sdk/ScheduleInfoTest.java | 105 +- .../sdk/ScheduleSignTransactionTest.java | 36 +- .../com/hedera/hashgraph/sdk/Snapshot.java | 47 +- .../hedera/hashgraph/sdk/StakingInfoTest.java | 51 +- .../sdk/SystemDeleteTransactionTest.java | 80 +- .../sdk/SystemUndeleteTransactionTest.java | 56 +- .../sdk/TokenAirdropTransactionTest.java | 78 +- .../sdk/TokenAssociateTransactionTest.java | 59 +- .../hashgraph/sdk/TokenAssociationTest.java | 42 +- .../sdk/TokenBurnTransactionTest.java | 60 +- .../TokenCancelAirdropTransactionTest.java | 60 +- .../sdk/TokenClaimAirdropTransactionTest.java | 60 +- .../sdk/TokenCreateTransactionTest.java | 214 +- .../sdk/TokenDeleteTransactionTest.java | 44 +- .../sdk/TokenDissociateTransactionTest.java | 53 +- ...TokenFeeScheduleUpdateTransactionTest.java | 55 +- .../sdk/TokenFreezeTransactionTest.java | 42 +- .../sdk/TokenGrantKycTransactionTest.java | 44 +- .../hashgraph/sdk/TokenInfoQueryTest.java | 22 +- .../hedera/hashgraph/sdk/TokenInfoTest.java | 194 +- .../sdk/TokenMintTransactionTest.java | 91 +- .../hashgraph/sdk/TokenNftInfoQueryTest.java | 41 +- .../hashgraph/sdk/TokenNftInfoTest.java | 40 +- .../sdk/TokenPauseTransactionTest.java | 41 +- .../sdk/TokenRejectTransactionTest.java | 49 +- .../hashgraph/sdk/TokenRelationshipTest.java | 35 +- .../sdk/TokenRevokeKycTransactionTest.java | 44 +- .../hashgraph/sdk/TokenSupplyTypeTest.java | 36 +- .../hedera/hashgraph/sdk/TokenTypeTest.java | 25 +- .../sdk/TokenUnfreezeTransactionTest.java | 43 +- .../sdk/TokenUnpauseTransactionTest.java | 40 +- .../sdk/TokenUpdateNftsTransactionTest.java | 41 +- .../sdk/TokenUpdateTransactionTest.java | 124 +- .../sdk/TokenWipeTransactionTest.java | 80 +- .../sdk/TopicCreateTransactionTest.java | 51 +- .../sdk/TopicDeleteTransactionTest.java | 41 +- .../com/hedera/hashgraph/sdk/TopicIdTest.java | 16 +- .../hashgraph/sdk/TopicInfoQueryTest.java | 16 +- .../hedera/hashgraph/sdk/TopicInfoTest.java | 49 +- .../hashgraph/sdk/TopicMessageQueryTest.java | 219 +- .../TopicMessageSubmitTransactionTest.java | 84 +- .../sdk/TopicUpdateTransactionTest.java | 101 +- .../hashgraph/sdk/TransactionIdTest.java | 39 +- .../sdk/TransactionReceiptQueryTest.java | 21 +- .../hashgraph/sdk/TransactionReceiptTest.java | 65 +- .../sdk/TransactionRecordQueryTest.java | 23 +- .../hashgraph/sdk/TransactionRecordTest.java | 128 +- .../AccountUpdateIntegrationTest.java | 60 +- .../integration/ClientIntegrationTest.java | 82 +- .../ContractBytecodeIntegrationTest.java | 390 ++- .../ContractCallIntegrationTest.java | 346 +- .../ContractCreateIntegrationTest.java | 179 +- .../ContractDeleteIntegrationTest.java | 114 +- .../ContractExecuteIntegrationTest.java | 182 +- ...ractFunctionParametersIntegrationTest.java | 1995 +++++++---- .../ContractInfoIntegrationTest.java | 215 +- .../ContractNonceInfoIntegrationTest.java | 56 +- .../ContractUpdateIntegrationTest.java | 132 +- .../FileAppendIntegrationTest.java | 121 +- .../FileUpdateIntegrationTest.java | 111 +- .../test/integration/IntegrationTestEnv.java | 57 +- .../ScheduleCreateIntegrationTest.java | 292 +- .../integration/SystemIntegrationTest.java | 81 +- ...TokenFeeScheduleUpdateIntegrationTest.java | 171 +- .../TokenNftTransferIntegrationTest.java | 150 +- .../TokenTransferIntegrationTest.java | 183 +- .../TokenUpdateIntegrationTest.java | 2980 +++++++++-------- .../TopicMessageSubmitIntegrationTest.java | 83 +- .../TransactionIntegrationTest.java | 268 +- 164 files changed, 8998 insertions(+), 8212 deletions(-) diff --git a/examples/src/main/java/module-info.java b/examples/src/main/java/module-info.java index 75e9b2bed..76dfdf8c1 100644 --- a/examples/src/main/java/module-info.java +++ b/examples/src/main/java/module-info.java @@ -19,11 +19,9 @@ */ module com.hedera.hashgraph.examples { - requires com.hedera.hashgraph.sdk; // requires com.hedera.hashgraph.sdk.full; - requires com.google.gson; + requires com.hedera.hashgraph.sdk; requires io.github.cdimascio.dotenv.java; - requires static java.annotation; } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountCreateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountCreateTransaction.java index 86c5af66c..3e9e4ec7a 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountCreateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountCreateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -28,10 +25,9 @@ import com.hedera.hashgraph.sdk.proto.TransactionResponse; import io.grpc.MethodDescriptor; import java.time.Duration; - -import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Create a new Hedera™ account. @@ -39,8 +35,10 @@ public final class AccountCreateTransaction extends Transaction { @Nullable private AccountId proxyAccountId = null; + @Nullable private Key key = null; + private String accountMemo = ""; private Hbar initialBalance = new Hbar(0); private boolean receiverSigRequired = false; @@ -71,7 +69,9 @@ public AccountCreateTransaction() { * @param txs Compound list of transaction id's list of (AccountId, Transaction) records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - AccountCreateTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + AccountCreateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -392,12 +392,12 @@ public AccountCreateTransaction setAlias(String aliasEvmAddress) { */ CryptoCreateTransactionBody.Builder build() { var builder = CryptoCreateTransactionBody.newBuilder() - .setInitialBalance(initialBalance.toTinybars()) - .setReceiverSigRequired(receiverSigRequired) - .setAutoRenewPeriod(DurationConverter.toProtobuf(autoRenewPeriod)) - .setMemo(accountMemo) - .setMaxAutomaticTokenAssociations(maxAutomaticTokenAssociations) - .setDeclineReward(declineStakingReward); + .setInitialBalance(initialBalance.toTinybars()) + .setReceiverSigRequired(receiverSigRequired) + .setAutoRenewPeriod(DurationConverter.toProtobuf(autoRenewPeriod)) + .setMemo(accountMemo) + .setMaxAutomaticTokenAssociations(maxAutomaticTokenAssociations) + .setDeclineReward(declineStakingReward); if (proxyAccountId != null) { builder.setProxyAccountID(proxyAccountId.toProtobuf()); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountUpdateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountUpdateTransaction.java index 3b7fa00b9..b39057a0d 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountUpdateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountUpdateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.BoolValue; @@ -31,10 +28,9 @@ import io.grpc.MethodDescriptor; import java.time.Duration; import java.time.Instant; - -import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Change properties for the given account. @@ -55,20 +51,28 @@ public final class AccountUpdateTransaction extends Transaction { @Nullable private AccountId accountId = null; + @Nullable private AccountId proxyAccountId = null; + @Nullable private Key key = null; + @Nullable private Instant expirationTime = null; + @Nullable private Duration autoRenewPeriod = null; + @Nullable private Boolean receiverSigRequired = null; + @Nullable private String accountMemo = null; + @Nullable private Integer maxAutomaticTokenAssociations = null; + @Nullable private Key aliasKey; @@ -84,8 +88,7 @@ public final class AccountUpdateTransaction extends Transaction> txs) throws InvalidProtocolBufferException { + AccountUpdateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -485,7 +490,8 @@ void initFromTransactionBody() { accountMemo = body.getMemo().getValue(); } if (body.hasMaxAutomaticTokenAssociations()) { - maxAutomaticTokenAssociations = body.getMaxAutomaticTokenAssociations().getValue(); + maxAutomaticTokenAssociations = + body.getMaxAutomaticTokenAssociations().getValue(); } if (body.hasDeclineReward()) { @@ -545,7 +551,8 @@ CryptoUpdateTransactionBody.Builder build() { } if (declineStakingReward != null) { - builder.setDeclineReward(BoolValue.newBuilder().setValue(declineStakingReward).build()); + builder.setDeclineReward( + BoolValue.newBuilder().setValue(declineStakingReward).build()); } return builder; diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/AddressBookQuery.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/AddressBookQuery.java index aa101b384..7eb4a050b 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/AddressBookQuery.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/AddressBookQuery.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.mirror.NetworkServiceGrpc; @@ -46,26 +43,28 @@ public class AddressBookQuery { @Nullable private FileId fileId = null; + @Nullable private Integer limit = null; + private int maxAttempts = 10; private Duration maxBackoff = Duration.ofSeconds(8L); /** * Constructor. */ - public AddressBookQuery() { - } + public AddressBookQuery() {} private static boolean shouldRetry(Throwable throwable) { if (throwable instanceof StatusRuntimeException statusRuntimeException) { var code = statusRuntimeException.getStatus().getCode(); var description = statusRuntimeException.getStatus().getDescription(); - return (code == io.grpc.Status.Code.UNAVAILABLE) || - (code == io.grpc.Status.Code.RESOURCE_EXHAUSTED) || - (code == Status.Code.INTERNAL && description != null && Executable.RST_STREAM.matcher(description) - .matches()); + return (code == io.grpc.Status.Code.UNAVAILABLE) + || (code == io.grpc.Status.Code.RESOURCE_EXHAUSTED) + || (code == Status.Code.INTERNAL + && description != null + && Executable.RST_STREAM.matcher(description).matches()); } return false; @@ -169,10 +168,8 @@ public NodeAddressBook execute(Client client, Duration timeout) { var deadline = Deadline.after(timeout.toMillis(), TimeUnit.MILLISECONDS); for (int attempt = 1; true; attempt++) { try { - var addressProtoIter = ClientCalls.blockingServerStreamingCall( - buildCall(client, deadline), - buildQuery() - ); + var addressProtoIter = + ClientCalls.blockingServerStreamingCall(buildCall(client, deadline), buildQuery()); List addresses = new ArrayList<>(); while (addressProtoIter.hasNext()) { addresses.add(NodeAddress.fromProtobuf(addressProtoIter.next())); @@ -223,31 +220,31 @@ public CompletableFuture executeAsync(Client client, Duration t void executeAsync(Client client, Deadline deadline, CompletableFuture returnFuture, int attempt) { List addresses = new ArrayList<>(); ClientCalls.asyncServerStreamingCall( - buildCall(client, deadline), - buildQuery(), - new StreamObserver() { - @Override - public void onNext(com.hedera.hashgraph.sdk.proto.NodeAddress addressProto) { - addresses.add(NodeAddress.fromProtobuf(addressProto)); - } + buildCall(client, deadline), + buildQuery(), + new StreamObserver() { + @Override + public void onNext(com.hedera.hashgraph.sdk.proto.NodeAddress addressProto) { + addresses.add(NodeAddress.fromProtobuf(addressProto)); + } - @Override - public void onError(Throwable error) { - if (attempt >= maxAttempts || !shouldRetry(error)) { - LOGGER.error("Error attempting to get address book at FileId {}", fileId, error); - returnFuture.completeExceptionally(error); - return; + @Override + public void onError(Throwable error) { + if (attempt >= maxAttempts || !shouldRetry(error)) { + LOGGER.error("Error attempting to get address book at FileId {}", fileId, error); + returnFuture.completeExceptionally(error); + return; + } + warnAndDelay(attempt, error); + addresses.clear(); + executeAsync(client, deadline, returnFuture, attempt + 1); } - warnAndDelay(attempt, error); - addresses.clear(); - executeAsync(client, deadline, returnFuture, attempt + 1); - } - @Override - public void onCompleted() { - returnFuture.complete(new NodeAddressBook().setNodeAddresses(addresses)); - } - }); + @Override + public void onCompleted() { + returnFuture.complete(new NodeAddressBook().setNodeAddresses(addresses)); + } + }); } /** @@ -266,13 +263,14 @@ com.hedera.hashgraph.sdk.proto.mirror.AddressBookQuery buildQuery() { return builder.build(); } - private ClientCall - buildCall(Client client, Deadline deadline) { + private ClientCall< + com.hedera.hashgraph.sdk.proto.mirror.AddressBookQuery, com.hedera.hashgraph.sdk.proto.NodeAddress> + buildCall(Client client, Deadline deadline) { try { - return client.mirrorNetwork.getNextMirrorNode().getChannel().newCall( - NetworkServiceGrpc.getGetNodesMethod(), - CallOptions.DEFAULT.withDeadline(deadline) - ); + return client.mirrorNetwork + .getNextMirrorNode() + .getChannel() + .newCall(NetworkServiceGrpc.getGetNodesMethod(), CallOptions.DEFAULT.withDeadline(deadline)); } catch (InterruptedException e) { throw new RuntimeException(e); } @@ -281,8 +279,11 @@ com.hedera.hashgraph.sdk.proto.mirror.AddressBookQuery buildQuery() { private void warnAndDelay(int attempt, Throwable error) { var delay = Math.min(500 * (long) Math.pow(2, attempt), maxBackoff.toMillis()); LOGGER.warn( - "Error fetching address book at FileId {} during attempt #{}. Waiting {} ms before next attempt: {}", - fileId, attempt, delay, error.getMessage()); + "Error fetching address book at FileId {} during attempt #{}. Waiting {} ms before next attempt: {}", + fileId, + attempt, + delay, + error.getMessage()); try { Thread.sleep(delay); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNetwork.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNetwork.java index 0897a0bfe..fc20d9078 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNetwork.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNetwork.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +12,19 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.common.annotations.VisibleForTesting; import java.time.Duration; import java.time.Instant; - -import javax.annotation.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import javax.annotation.Nullable; /** * Abstracts away most of the similar functionality between {@link Network} and {@link MirrorNetwork} @@ -38,9 +34,9 @@ * @param - The specific node type for this network. */ abstract class BaseNetwork< - BaseNetworkT extends BaseNetwork, - KeyT, - BaseNodeT extends BaseNode> { + BaseNetworkT extends BaseNetwork, + KeyT, + BaseNodeT extends BaseNode> { protected static final Integer DEFAULT_MAX_NODE_ATTEMPTS = -1; protected static final Random random = new Random(); @@ -220,7 +216,7 @@ synchronized BaseNetworkT setMaxNodeBackoff(Duration maxNodeBackoff) { * * @return the minimum node readmit time */ - synchronized public Duration getMinNodeReadmitTime() { + public synchronized Duration getMinNodeReadmitTime() { return minNodeReadmitTime; } @@ -229,7 +225,7 @@ synchronized public Duration getMinNodeReadmitTime() { * * @param minNodeReadmitTime the minimum node readmit time */ - synchronized public void setMinNodeReadmitTime(Duration minNodeReadmitTime) { + public synchronized void setMinNodeReadmitTime(Duration minNodeReadmitTime) { this.minNodeReadmitTime = minNodeReadmitTime; for (var node : nodes) { @@ -310,12 +306,10 @@ protected List getNodesToRemove(Map network) { return nodes; } - private boolean nodeIsInGivenNetwork(BaseNodeT node, Map network) { + private boolean nodeIsInGivenNetwork(BaseNodeT node, Map network) { for (var entry : network.entrySet()) { - if ( - node.getKey().equals(entry.getValue()) && - node.address.equals(BaseNodeAddress.fromString(entry.getKey())) - ) { + if (node.getKey().equals(entry.getValue()) + && node.address.equals(BaseNodeAddress.fromString(entry.getKey()))) { return true; } } @@ -367,7 +361,8 @@ synchronized BaseNetworkT setNetwork(Map network) throws TimeoutEx for (var entry : network.entrySet()) { var node = createNodeFromNetworkEntry(entry); - if (newNodeKeys.contains(node.getKey()) && newNodeAddresses.contains(node.getAddress().toString())) { + if (newNodeKeys.contains(node.getKey()) + && newNodeAddresses.contains(node.getAddress().toString())) { continue; } @@ -459,13 +454,13 @@ synchronized void readmitNodes() { } } - this.earliestReadmitTime = nextEarliestReadmitTime; if (this.earliestReadmitTime.isBefore(now.plus(minNodeReadmitTime))) { this.earliestReadmitTime = now.plus(minNodeReadmitTime); } - outer: for (var i = 0; i < this.nodes.size(); i++) { + outer: + for (var i = 0; i < this.nodes.size(); i++) { // Check if `healthyNodes` already contains this node for (var j = 0; j < this.healthyNodes.size(); j++) { if (this.nodes.get(i) == this.healthyNodes.get(j)) { @@ -478,7 +473,6 @@ synchronized void readmitNodes() { this.healthyNodes.add(this.nodes.get(i)); } } - } } @@ -531,7 +525,7 @@ protected synchronized List getNumberOfMostHealthyNodes(int count) th var returnNodes = new HashMap(count); - for (var i = 0; i < count; i++ ) { + for (var i = 0; i < count; i++) { var node = getRandomNode(); if (!returnNodes.containsKey(node.getKey())) { @@ -544,7 +538,6 @@ protected synchronized List getNumberOfMostHealthyNodes(int count) th return returnList; } - synchronized void beginClose() { for (var node : nodes) { if (node.channel != null) { @@ -563,7 +556,8 @@ synchronized Throwable awaitClose(Instant deadline, @Nullable Throwable previous for (var node : nodes) { if (node.channel != null) { - var timeoutMillis = Duration.between(Instant.now(), deadline).toMillis(); + var timeoutMillis = + Duration.between(Instant.now(), deadline).toMillis(); if (timeoutMillis <= 0 || !node.channel.awaitTermination(timeoutMillis, TimeUnit.MILLISECONDS)) { throw new TimeoutException("Failed to properly shutdown all channels"); } else { diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java index 5ee01304d..0d4286f30 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/BaseNode.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import io.grpc.ChannelCredentials; @@ -26,7 +23,6 @@ import io.grpc.ManagedChannelBuilder; import io.grpc.TlsChannelCredentials; import io.grpc.inprocess.InProcessChannelBuilder; - import java.lang.module.ModuleDescriptor; import java.time.Duration; import java.time.Instant; @@ -281,12 +277,12 @@ synchronized ManagedChannel getChannel() { } channel = channelBuilder - .keepAliveTimeout(10, TimeUnit.SECONDS) - .keepAliveWithoutCalls(true) - .disableRetry() - .userAgent(getUserAgent()) - .executor(executor) - .build(); + .keepAliveTimeout(10, TimeUnit.SECONDS) + .keepAliveWithoutCalls(true) + .disableRetry() + .userAgent(getUserAgent()) + .executor(executor) + .build(); return channel; } @@ -320,7 +316,6 @@ boolean channelFailedToConnect(Instant timeoutTime) { return !hasConnected; } - private CompletableFuture channelFailedToConnectAsync(int i, ConnectivityState state) { hasConnected = (state == ConnectivityState.READY); if (i >= GET_STATE_MAX_ATTEMPTS || hasConnected) { @@ -368,12 +363,14 @@ private String getUserAgent() { String implementationVersion; if (theModule.getName() == null) { // running on classpath - implementationVersion = - thePackage != null ? thePackage.getImplementationVersion() : null; + implementationVersion = thePackage != null ? thePackage.getImplementationVersion() : null; } else { // running on module path - implementationVersion = - theModule.getDescriptor().version().map(ModuleDescriptor.Version::toString).orElse(null); + implementationVersion = theModule + .getDescriptor() + .version() + .map(ModuleDescriptor.Version::toString) + .orElse(null); } return "hedera-sdk-java/" + ((implementationVersion != null) ? ("v" + implementationVersion) : "DEV"); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/ChunkedTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/ChunkedTransaction.java index 876845179..aa969b131 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/ChunkedTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/ChunkedTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -64,7 +61,9 @@ abstract class ChunkedTransaction> extends Trans * @param txs Compound list of transaction id's list of (AccountId, Transaction) records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - ChunkedTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + ChunkedTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); } @@ -184,7 +183,8 @@ public T setChunkSize(int chunkSize) { @Override public byte[] getTransactionHash() { if (outerTransactions.size() > nodeAccountIds.size()) { - throw new IllegalStateException("a single transaction hash can not be calculated for a chunked transaction, try calling `getAllTransactionHashesPerNode`"); + throw new IllegalStateException( + "a single transaction hash can not be calculated for a chunked transaction, try calling `getAllTransactionHashesPerNode`"); } return super.getTransactionHash(); @@ -193,7 +193,8 @@ public byte[] getTransactionHash() { @Override public Map getTransactionHashPerNode() { if (outerTransactions.size() > nodeAccountIds.size()) { - throw new IllegalStateException("a single transaction hash can not be calculated for a chunked transaction, try calling `getAllTransactionHashesPerNode`"); + throw new IllegalStateException( + "a single transaction hash can not be calculated for a chunked transaction, try calling `getAllTransactionHashesPerNode`"); } return super.getTransactionHashPerNode(); @@ -206,7 +207,8 @@ public Map getTransactionHashPerNode() { */ public final List> getAllTransactionHashesPerNode() { if (!this.isFrozen()) { - throw new IllegalStateException("transaction must have been frozen before calculating the hash will be stable, try calling `freeze`"); + throw new IllegalStateException( + "transaction must have been frozen before calculating the hash will be stable, try calling `freeze`"); } transactionIds.setLocked(true); @@ -224,8 +226,11 @@ public final List> getAllTransactionHashesPerNode() { for (var nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex) { hashes.put( - nodeAccountIds.get(nodeIndex), - hash(outerTransactions.get(offset + nodeIndex).getSignedTransactionBytes().toByteArray())); + nodeAccountIds.get(nodeIndex), + hash(outerTransactions + .get(offset + nodeIndex) + .getSignedTransactionBytes() + .toByteArray())); } transactionHashes.add(hashes); @@ -237,7 +242,8 @@ public final List> getAllTransactionHashesPerNode() { @Override public T addSignature(PublicKey publicKey, byte[] signature) { if (data.size() > chunkSize) { - throw new IllegalStateException("Cannot manually add signature to chunked transaction with length greater than " + chunkSize); + throw new IllegalStateException( + "Cannot manually add signature to chunked transaction with length greater than " + chunkSize); } return super.addSignature(publicKey, signature); } @@ -245,7 +251,8 @@ public T addSignature(PublicKey publicKey, byte[] signature) { @Override public Map> getSignatures() { if (data.size() > chunkSize) { - throw new IllegalStateException("Cannot call getSignatures() on a chunked transaction with length greater than " + chunkSize); + throw new IllegalStateException( + "Cannot call getSignatures() on a chunked transaction with length greater than " + chunkSize); } return super.getSignatures(); } @@ -289,7 +296,8 @@ private void freezeAndSign(Client client) { } @Override - public TransactionResponse execute(Client client, Duration timeoutPerChunk) throws TimeoutException, PrecheckStatusException { + public TransactionResponse execute(Client client, Duration timeoutPerChunk) + throws TimeoutException, PrecheckStatusException { return executeAll(client, timeoutPerChunk).get(0); } @@ -314,7 +322,8 @@ public List executeAll(Client client) throws PrecheckStatus * @throws TimeoutException when the transaction times out * @throws PrecheckStatusException when the precheck fails */ - public List executeAll(Client client, Duration timeoutPerChunk) throws PrecheckStatusException, TimeoutException { + public List executeAll(Client client, Duration timeoutPerChunk) + throws PrecheckStatusException, TimeoutException { freezeAndSign(client); var responses = new ArrayList(transactionIds.size()); @@ -324,9 +333,9 @@ public List executeAll(Client client, Duration timeoutPerCh if (shouldGetReceipt()) { new TransactionReceiptQuery() - .setNodeAccountIds(Collections.singletonList(response.nodeId)) - .setTransactionId(response.transactionId) - .execute(client, timeoutPerChunk); + .setNodeAccountIds(Collections.singletonList(response.nodeId)) + .setTransactionId(response.transactionId) + .execute(client, timeoutPerChunk); } responses.add(response); @@ -356,21 +365,20 @@ public CompletableFuture> executeAllAsync(Client clien freezeAndSign(client); CompletableFuture> future = - CompletableFuture.supplyAsync(() -> new ArrayList<>(transactionIds.size())); + CompletableFuture.supplyAsync(() -> new ArrayList<>(transactionIds.size())); for (var i = 0; i < transactionIds.size(); i++) { future = future.thenCompose(list -> { var responseFuture = super.executeAsync(client, timeoutPerChunk); Function> receiptFuture = - (TransactionResponse response) -> response.getReceiptAsync(client, timeoutPerChunk) - .thenApply(receipt -> response); + (TransactionResponse response) -> response.getReceiptAsync(client, timeoutPerChunk) + .thenApply(receipt -> response); - Function> addToList = - (response) -> { - list.add(response); - return list; - }; + Function> addToList = (response) -> { + list.add(response); + return list; + }; if (shouldGetReceipt()) { return responseFuture.thenCompose(receiptFuture).thenApply(addToList); @@ -400,7 +408,8 @@ public void executeAllAsync(Client client, BiConsumer, * @param timeout The timeout after which the execution attempt will be cancelled. * @param callback a BiConsumer which handles the result or error. */ - public void executeAllAsync(Client client, Duration timeout, BiConsumer, Throwable> callback) { + public void executeAllAsync( + Client client, Duration timeout, BiConsumer, Throwable> callback) { ConsumerHelper.biConsumer(executeAllAsync(client, timeout), callback); } @@ -411,7 +420,8 @@ public void executeAllAsync(Client client, Duration timeout, BiConsumer> onSuccess, Consumer onFailure) { + public void executeAllAsync( + Client client, Consumer> onSuccess, Consumer onFailure) { ConsumerHelper.twoConsumers(executeAllAsync(client), onSuccess, onFailure); } @@ -423,12 +433,17 @@ public void executeAllAsync(Client client, Consumer> o * @param onSuccess a Consumer which consumes the result on success. * @param onFailure a Consumer which consumes the error on failure. */ - public void executeAllAsync(Client client, Duration timeout, Consumer> onSuccess, Consumer onFailure) { + public void executeAllAsync( + Client client, + Duration timeout, + Consumer> onSuccess, + Consumer onFailure) { ConsumerHelper.twoConsumers(executeAllAsync(client, timeout), onSuccess, onFailure); } @Override - public CompletableFuture executeAsync(Client client, Duration timeoutPerChunk) { + public CompletableFuture executeAsync( + Client client, Duration timeoutPerChunk) { return executeAllAsync(client, timeoutPerChunk).thenApply(responses -> responses.get(0)); } @@ -437,25 +452,18 @@ public ScheduleCreateTransaction schedule() { requireNotFrozen(); if (!nodeAccountIds.isEmpty()) { throw new IllegalStateException( - "The underlying transaction for a scheduled transaction cannot have node account IDs set" - ); + "The underlying transaction for a scheduled transaction cannot have node account IDs set"); } if (data.size() > chunkSize) { - throw new IllegalStateException("Cannot schedule a chunked transaction with length greater than " + chunkSize); + throw new IllegalStateException( + "Cannot schedule a chunked transaction with length greater than " + chunkSize); } var bodyBuilder = spawnBodyBuilder(null); onFreeze(bodyBuilder); - onFreezeChunk( - bodyBuilder, - null, - 0, - data.size(), - 1, - 1 - ); + onFreezeChunk(bodyBuilder, null, 0, data.size(), 1, 1); return doSchedule(bodyBuilder); } @@ -469,8 +477,7 @@ int getRequiredChunks() { } if (requiredChunks > maxChunks) { - throw new IllegalArgumentException( - "message of " + this.data.size() + " bytes requires " + requiredChunks + throw new IllegalArgumentException("message of " + this.data.size() + " bytes requires " + requiredChunks + " chunks but the maximum allowed chunks is " + maxChunks + ", try using setMaxChunks"); } return requiredChunks; @@ -492,26 +499,23 @@ void wipeTransactionLists(int requiredChunks) { } onFreezeChunk( - Objects.requireNonNull(frozenBodyBuilder).setTransactionID(transactionIds.get(i).toProtobuf()), - transactionIds.get(0).toProtobuf(), - startIndex, - endIndex, - i, - requiredChunks - ); + Objects.requireNonNull(frozenBodyBuilder) + .setTransactionID(transactionIds.get(i).toProtobuf()), + transactionIds.get(0).toProtobuf(), + startIndex, + endIndex, + i, + requiredChunks); } // For each node we add a transaction with that node for (var nodeId : nodeAccountIds) { sigPairLists.add(SignatureMap.newBuilder()); innerSignedTransactions.add(SignedTransaction.newBuilder() - .setBodyBytes( - frozenBodyBuilder - .setNodeAccountID(nodeId.toProtobuf()) - .build() - .toByteString() - ) - ); + .setBodyBytes(frozenBodyBuilder + .setNodeAccountID(nodeId.toProtobuf()) + .build() + .toByteString())); outerTransactions.add(null); } } @@ -520,7 +524,13 @@ void wipeTransactionLists(int requiredChunks) { /** * A common base for file and topic message transactions. */ - abstract void onFreezeChunk(TransactionBody.Builder body, @Nullable TransactionID initialTransactionId, int startIndex, int endIndex, int chunk, int total); + abstract void onFreezeChunk( + TransactionBody.Builder body, + @Nullable TransactionID initialTransactionId, + int startIndex, + int endIndex, + int chunk, + int total); /** * Should the receipt be retrieved? diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java index bfd1668fb..e41b359ac 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Client.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.common.annotations.VisibleForTesting; @@ -79,13 +76,17 @@ public final class Client implements AutoCloseable { final ExecutorService executor; private final AtomicReference grpcDeadline = new AtomicReference(DEFAULT_GRPC_DEADLINE); private final Set subscriptions = ConcurrentHashMap.newKeySet(); + @Nullable Hbar defaultMaxTransactionFee = null; + Hbar defaultMaxQueryPayment = DEFAULT_MAX_QUERY_PAYMENT; Network network; MirrorNetwork mirrorNetwork; + @Nullable private Operator operator; + private Duration requestTimeout = DEFAULT_REQUEST_TIMEOUT; private Duration closeTimeout = DEFAULT_CLOSE_TIMEOUT; private int maxAttempts = DEFAULT_MAX_ATTEMPTS; @@ -96,8 +97,10 @@ public final class Client implements AutoCloseable { // If networkUpdatePeriod is null, any network updates in progress will not complete @Nullable private Duration networkUpdatePeriod; + @Nullable private CompletableFuture networkUpdateFuture; + private Logger logger = new Logger(LogLevel.SILENT); /** @@ -109,12 +112,11 @@ public final class Client implements AutoCloseable { */ @VisibleForTesting Client( - ExecutorService executor, - Network network, - MirrorNetwork mirrorNetwork, - @Nullable Duration networkUpdateInitialDelay, - @Nullable Duration networkUpdatePeriod - ) { + ExecutorService executor, + Network network, + MirrorNetwork mirrorNetwork, + @Nullable Duration networkUpdateInitialDelay, + @Nullable Duration networkUpdatePeriod) { this.executor = executor; this.network = network; this.mirrorNetwork = mirrorNetwork; @@ -129,15 +131,19 @@ public final class Client implements AutoCloseable { */ static ExecutorService createExecutor() { var threadFactory = new ThreadFactoryBuilder() - .setNameFormat("hedera-sdk-%d") - .setDaemon(true) - .build(); + .setNameFormat("hedera-sdk-%d") + .setDaemon(true) + .build(); int nThreads = Runtime.getRuntime().availableProcessors(); - return new ThreadPoolExecutor(nThreads, nThreads, - 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue<>(), - threadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); + return new ThreadPoolExecutor( + nThreads, + nThreads, + 0L, + TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<>(), + threadFactory, + new ThreadPoolExecutor.CallerRunsPolicy()); } /** @@ -160,7 +166,6 @@ public static Client forNetwork(Map networkMap, ExecutorServi return new Client(executor, network, mirrorNetwork, null, null); } - /** * Construct a client given a set of nodes. * @@ -205,8 +210,8 @@ public static Client forMainnet(ExecutorService executor) { var network = Network.forMainnet(executor); var mirrorNetwork = MirrorNetwork.forMainnet(executor); - return new Client(executor, network, mirrorNetwork, NETWORK_UPDATE_INITIAL_DELAY, - DEFAULT_NETWORK_UPDATE_PERIOD); + return new Client( + executor, network, mirrorNetwork, NETWORK_UPDATE_INITIAL_DELAY, DEFAULT_NETWORK_UPDATE_PERIOD); } /** @@ -221,8 +226,8 @@ public static Client forTestnet(ExecutorService executor) { var network = Network.forTestnet(executor); var mirrorNetwork = MirrorNetwork.forTestnet(executor); - return new Client(executor, network, mirrorNetwork, NETWORK_UPDATE_INITIAL_DELAY, - DEFAULT_NETWORK_UPDATE_PERIOD); + return new Client( + executor, network, mirrorNetwork, NETWORK_UPDATE_INITIAL_DELAY, DEFAULT_NETWORK_UPDATE_PERIOD); } /** @@ -238,11 +243,10 @@ public static Client forPreviewnet(ExecutorService executor) { var network = Network.forPreviewnet(executor); var mirrorNetwork = MirrorNetwork.forPreviewnet(executor); - return new Client(executor, network, mirrorNetwork, NETWORK_UPDATE_INITIAL_DELAY, - DEFAULT_NETWORK_UPDATE_PERIOD); + return new Client( + executor, network, mirrorNetwork, NETWORK_UPDATE_INITIAL_DELAY, DEFAULT_NETWORK_UPDATE_PERIOD); } - /** * Construct a Hedera client pre-configured for Mainnet access. @@ -305,8 +309,9 @@ public static Client fromConfig(Reader json) throws Exception { var networks = config.network.getAsJsonObject(); Map nodes = new HashMap<>(networks.size()); for (Map.Entry entry : networks.entrySet()) { - nodes.put(entry.getValue().toString().replace("\"", ""), - AccountId.fromString(entry.getKey().replace("\"", ""))); + nodes.put( + entry.getValue().toString().replace("\"", ""), + AccountId.fromString(entry.getKey().replace("\"", ""))); } client = Client.forNetwork(nodes); if (config.networkName != null) { @@ -315,7 +320,7 @@ public static Client fromConfig(Reader json) throws Exception { client.setNetworkName(NetworkName.fromString(networkNameString)); } catch (Exception ignored) { throw new IllegalArgumentException("networkName in config was \"" + networkNameString - + "\", expected either \"mainnet\", \"testnet\" or \"previewnet\""); + + "\", expected either \"mainnet\", \"testnet\" or \"previewnet\""); } } } else { @@ -324,8 +329,7 @@ public static Client fromConfig(Reader json) throws Exception { case MAINNET -> Client.forMainnet(); case TESTNET -> Client.forTestnet(); case PREVIEWNET -> Client.forPreviewnet(); - default -> throw new JsonParseException("Illegal argument for network."); - }; + default -> throw new JsonParseException("Illegal argument for network.");}; } if (config.operator != null) { @@ -335,7 +339,7 @@ public static Client fromConfig(Reader json) throws Exception { client.setOperator(operatorAccount, privateKey); } - //already set in previous set network if? + // already set in previous set network if? if (config.mirrorNetwork != null) { if (config.mirrorNetwork.isJsonArray()) { var mirrors = config.mirrorNetwork.getAsJsonArray(); @@ -385,7 +389,7 @@ public static Client fromConfigFile(File file) throws Exception { * * @return the list of mirror nodes */ - synchronized public List getMirrorNetwork() { + public synchronized List getMirrorNetwork() { return mirrorNetwork.getNetwork(); } @@ -415,18 +419,21 @@ private synchronized void scheduleNetworkUpdate(@Nullable Duration delay) { networkUpdateFuture.thenRun(() -> { // Checking networkUpdatePeriod != null must be synchronized, so I've put it in a synchronized method. requireNetworkUpdatePeriodNotNull(() -> { - new AddressBookQuery().setFileId(FileId.ADDRESS_BOOK).executeAsync(this) - .thenCompose(addressBook -> requireNetworkUpdatePeriodNotNull(() -> { - try { - this.setNetworkFromAddressBook(addressBook); - } catch (Throwable error) { - return CompletableFuture.failedFuture(error); - } - return CompletableFuture.completedFuture(null); - })).exceptionally(error -> { - logger.warn("Failed to update address book via mirror node query ", error); - return null; - }); + new AddressBookQuery() + .setFileId(FileId.ADDRESS_BOOK) + .executeAsync(this) + .thenCompose(addressBook -> requireNetworkUpdatePeriodNotNull(() -> { + try { + this.setNetworkFromAddressBook(addressBook); + } catch (Throwable error) { + return CompletableFuture.failedFuture(error); + } + return CompletableFuture.completedFuture(null); + })) + .exceptionally(error -> { + logger.warn("Failed to update address book via mirror node query ", error); + return null; + }); scheduleNetworkUpdate(networkUpdatePeriod); return null; }); @@ -464,7 +471,7 @@ void untrackSubscription(SubscriptionHandle subscriptionHandle) { * @return {@code this} */ public synchronized Client setNetworkFromAddressBook(NodeAddressBook addressBook, boolean updateAddressBook) - throws InterruptedException, TimeoutException { + throws InterruptedException, TimeoutException { network.setNetwork(Network.addressBookToNetwork(addressBook.nodeAddresses)); if (updateAddressBook) { network.setAddressBook(addressBook); @@ -481,7 +488,7 @@ public synchronized Client setNetworkFromAddressBook(NodeAddressBook addressBook * @throws TimeoutException when shutting down nodes */ public synchronized Client setNetworkFromAddressBook(NodeAddressBook addressBook) - throws InterruptedException, TimeoutException { + throws InterruptedException, TimeoutException { return setNetworkFromAddressBook(addressBook, false); } @@ -490,7 +497,7 @@ public synchronized Client setNetworkFromAddressBook(NodeAddressBook addressBook * * @return the client's network */ - synchronized public Map getNetwork() { + public synchronized Map getNetwork() { return network.getNetwork(); } @@ -503,7 +510,7 @@ synchronized public Map getNetwork() { * @throws InterruptedException when a thread is interrupted while it's waiting, sleeping, or otherwise occupied */ public synchronized Client setNetwork(Map network) - throws InterruptedException, TimeoutException { + throws InterruptedException, TimeoutException { this.network.setNetwork(network); return this; } @@ -599,9 +606,9 @@ public Void ping(AccountId nodeAccountId) throws PrecheckStatusException, Timeou */ public Void ping(AccountId nodeAccountId, Duration timeout) throws PrecheckStatusException, TimeoutException { new AccountBalanceQuery() - .setAccountId(nodeAccountId) - .setNodeAccountIds(Collections.singletonList(nodeAccountId)) - .execute(this, timeout); + .setAccountId(nodeAccountId) + .setNodeAccountIds(Collections.singletonList(nodeAccountId)) + .execute(this, timeout); return null; } @@ -626,16 +633,16 @@ public CompletableFuture pingAsync(AccountId nodeAccountId) { public CompletableFuture pingAsync(AccountId nodeAccountId, Duration timeout) { var result = new CompletableFuture(); new AccountBalanceQuery() - .setAccountId(nodeAccountId) - .setNodeAccountIds(Collections.singletonList(nodeAccountId)) - .executeAsync(this, timeout) - .whenComplete((balance, error) -> { - if (error == null) { - result.complete(null); - } else { - result.completeExceptionally(error); - } - }); + .setAccountId(nodeAccountId) + .setNodeAccountIds(Collections.singletonList(nodeAccountId)) + .executeAsync(this, timeout) + .whenComplete((balance, error) -> { + if (error == null) { + result.complete(null); + } else { + result.completeExceptionally(error); + } + }); return result; } @@ -679,8 +686,8 @@ public void pingAsync(AccountId nodeAccountId, Consumer onSuccess, Consume * @param onSuccess a Consumer which consumes the result on success. * @param onFailure a Consumer which consumes the error on failure. */ - public void pingAsync(AccountId nodeAccountId, Duration timeout, Consumer onSuccess, - Consumer onFailure) { + public void pingAsync( + AccountId nodeAccountId, Duration timeout, Consumer onSuccess, Consumer onFailure) { ConsumerHelper.twoConsumers(pingAsync(nodeAccountId, timeout), onSuccess, onFailure); } @@ -736,7 +743,8 @@ public synchronized CompletableFuture pingAllAsync(Duration timeoutPerPing list.add(pingAsync(nodeAccountId, timeoutPerPing)); } - return CompletableFuture.allOf(list.toArray(new CompletableFuture[0])).thenApply((v) -> null); + return CompletableFuture.allOf(list.toArray(new CompletableFuture[0])) + .thenApply((v) -> null); } /** @@ -812,16 +820,15 @@ public synchronized Client setOperator(AccountId accountId, PrivateKey privateKe * @param transactionSigner The signer for the operator * @return {@code this} */ - public synchronized Client setOperatorWith(AccountId accountId, PublicKey publicKey, - UnaryOperator transactionSigner) { + public synchronized Client setOperatorWith( + AccountId accountId, PublicKey publicKey, UnaryOperator transactionSigner) { if (getNetworkName() != null) { try { accountId.validateChecksum(this); } catch (BadEntityIdException exc) { throw new IllegalArgumentException( - "Tried to set the client operator account ID to an account ID with an invalid checksum: " - + exc.getMessage() - ); + "Tried to set the client operator account ID to an account ID with an invalid checksum: " + + exc.getMessage()); } } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractCreateFlow.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractCreateFlow.java index c5cba04d4..7d9703761 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractCreateFlow.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractCreateFlow.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -80,24 +77,35 @@ public class ContractCreateFlow { static final int FILE_CREATE_MAX_BYTES = 2048; private String bytecode = ""; + @Nullable private Integer maxChunks = null; + @Nullable private Key adminKey = null; + private long gas = 0; private Hbar initialBalance = Hbar.ZERO; + @Nullable private AccountId proxyAccountId = null; + private int maxAutomaticTokenAssociations = 0; + @Nullable private Duration autoRenewPeriod = null; + @Nullable private AccountId autoRenewAccountId = null; + private byte[] constructorParameters = {}; + @Nullable private String contractMemo = null; + @Nullable private List nodeAccountIds = null; + private String createBytecode = ""; private String appendBytecode = ""; @@ -124,8 +132,7 @@ public class ContractCreateFlow { /** * Constructor */ - public ContractCreateFlow() { - } + public ContractCreateFlow() {} /** * Extract the hex-encoded bytecode of the contract. @@ -568,8 +575,8 @@ private void splitBytecode() { private FileCreateTransaction createFileCreateTransaction(Client client) { var fileCreateTx = new FileCreateTransaction() - .setKeys(Objects.requireNonNull(client.getOperatorPublicKey())) - .setContents(createBytecode); + .setKeys(Objects.requireNonNull(client.getOperatorPublicKey())) + .setContents(createBytecode); if (nodeAccountIds != null) { fileCreateTx.setNodeAccountIds(nodeAccountIds); } @@ -577,9 +584,7 @@ private FileCreateTransaction createFileCreateTransaction(Client client) { } private FileAppendTransaction createFileAppendTransaction(FileId fileId) { - var fileAppendTx = new FileAppendTransaction() - .setFileId(fileId) - .setContents(appendBytecode); + var fileAppendTx = new FileAppendTransaction().setFileId(fileId).setContents(appendBytecode); if (maxChunks != null) { fileAppendTx.setMaxChunks(maxChunks); } @@ -591,12 +596,12 @@ private FileAppendTransaction createFileAppendTransaction(FileId fileId) { private ContractCreateTransaction createContractCreateTransaction(FileId fileId) { var contractCreateTx = new ContractCreateTransaction() - .setBytecodeFileId(fileId) - .setConstructorParameters(constructorParameters) - .setGas(gas) - .setInitialBalance(initialBalance) - .setMaxAutomaticTokenAssociations(maxAutomaticTokenAssociations) - .setDeclineStakingReward(declineStakingReward); + .setBytecodeFileId(fileId) + .setConstructorParameters(constructorParameters) + .setGas(gas) + .setInitialBalance(initialBalance) + .setMaxAutomaticTokenAssociations(maxAutomaticTokenAssociations) + .setDeclineStakingReward(declineStakingReward); if (adminKey != null) { contractCreateTx.setAdminKey(adminKey); } @@ -639,8 +644,8 @@ private ContractCreateTransaction createContractCreateTransaction(FileId fileId) */ TransactionReceiptQuery createTransactionReceiptQuery(TransactionResponse response) { return new TransactionReceiptQuery() - .setNodeAccountIds(Collections.singletonList(response.nodeId)) - .setTransactionId(response.transactionId); + .setNodeAccountIds(Collections.singletonList(response.nodeId)) + .setTransactionId(response.transactionId); } /** @@ -665,23 +670,20 @@ public TransactionResponse execute(Client client) throws PrecheckStatusException * @throws TimeoutException when the transaction times out */ public TransactionResponse execute(Client client, Duration timeoutPerTransaction) - throws PrecheckStatusException, TimeoutException { + throws PrecheckStatusException, TimeoutException { try { splitBytecode(); var fileId = createFileCreateTransaction(client) - .execute(client, timeoutPerTransaction) - .getReceipt(client, timeoutPerTransaction) - .fileId; + .execute(client, timeoutPerTransaction) + .getReceipt(client, timeoutPerTransaction) + .fileId; Objects.requireNonNull(fileId); if (!appendBytecode.isEmpty()) { - createFileAppendTransaction(fileId) - .execute(client, timeoutPerTransaction); + createFileAppendTransaction(fileId).execute(client, timeoutPerTransaction); } var response = createContractCreateTransaction(fileId).execute(client, timeoutPerTransaction); response.getReceipt(client, timeoutPerTransaction); - new FileDeleteTransaction() - .setFileId(fileId) - .execute(client, timeoutPerTransaction); + new FileDeleteTransaction().setFileId(fileId).execute(client, timeoutPerTransaction); return response; } catch (ReceiptStatusException e) { throw new RuntimeException(e); @@ -707,26 +709,30 @@ public CompletableFuture executeAsync(Client client) { */ public CompletableFuture executeAsync(Client client, Duration timeoutPerTransaction) { splitBytecode(); - return createFileCreateTransaction(client).executeAsync(client, timeoutPerTransaction) - .thenCompose(fileCreateResponse -> createTransactionReceiptQuery(fileCreateResponse) + return createFileCreateTransaction(client) .executeAsync(client, timeoutPerTransaction) - .thenApply(receipt -> receipt.fileId)).thenCompose(fileId -> { - CompletableFuture appendFuture = - appendBytecode.isEmpty() ? CompletableFuture.completedFuture(null) : - createFileAppendTransaction(fileId).executeAsync(client, timeoutPerTransaction) - .thenApply(ignored -> null); - return appendFuture.thenCompose( - ignored -> createContractCreateTransaction(fileId).executeAsync(client, timeoutPerTransaction) - .thenApply(contractCreateResponse -> { - createTransactionReceiptQuery(contractCreateResponse).executeAsync(client, - timeoutPerTransaction).thenRun(() -> { - new FileDeleteTransaction() - .setFileId(fileId) - .executeAsync(client, timeoutPerTransaction); - }); - return contractCreateResponse; - })); - }); + .thenCompose(fileCreateResponse -> createTransactionReceiptQuery(fileCreateResponse) + .executeAsync(client, timeoutPerTransaction) + .thenApply(receipt -> receipt.fileId)) + .thenCompose(fileId -> { + CompletableFuture appendFuture = appendBytecode.isEmpty() + ? CompletableFuture.completedFuture(null) + : createFileAppendTransaction(fileId) + .executeAsync(client, timeoutPerTransaction) + .thenApply(ignored -> null); + return appendFuture.thenCompose(ignored -> createContractCreateTransaction(fileId) + .executeAsync(client, timeoutPerTransaction) + .thenApply(contractCreateResponse -> { + createTransactionReceiptQuery(contractCreateResponse) + .executeAsync(client, timeoutPerTransaction) + .thenRun(() -> { + new FileDeleteTransaction() + .setFileId(fileId) + .executeAsync(client, timeoutPerTransaction); + }); + return contractCreateResponse; + })); + }); } /** @@ -746,8 +752,8 @@ public void executeAsync(Client client, BiConsumer callback) { + public void executeAsync( + Client client, Duration timeoutPerTransaction, BiConsumer callback) { ConsumerHelper.biConsumer(executeAsync(client, timeoutPerTransaction), callback); } @@ -770,8 +776,11 @@ public void executeAsync(Client client, Consumer onSuccess, * @param onSuccess a Consumer which consumes the result on success. * @param onFailure a Consumer which consumes the error on failure. */ - public void executeAsync(Client client, Duration timeoutPerTransaction, Consumer onSuccess, - Consumer onFailure) { + public void executeAsync( + Client client, + Duration timeoutPerTransaction, + Consumer onSuccess, + Consumer onFailure) { ConsumerHelper.twoConsumers(executeAsync(client, timeoutPerTransaction), onSuccess, onFailure); } } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractCreateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractCreateTransaction.java index a21f336ae..d132b62ac 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractCreateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractCreateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -27,12 +24,11 @@ import com.hedera.hashgraph.sdk.proto.TransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionResponse; import io.grpc.MethodDescriptor; -import org.bouncycastle.util.Arrays; import java.time.Duration; - -import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; +import org.bouncycastle.util.Arrays; /** * Start a new smart contract instance. @@ -82,6 +78,7 @@ public final class ContractCreateTransaction extends Transaction> txs) throws InvalidProtocolBufferException { + ContractCreateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -191,7 +193,6 @@ public byte[] getBytecode() { * @param bytecode The bytecode * @return {@code this} */ - public ContractCreateTransaction setBytecode(byte[] bytecode) { Objects.requireNonNull(bytecode); requireNotFrozen(); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractFunctionParameters.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractFunctionParameters.java index 93a8ec3c9..6a0ac64de 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractFunctionParameters.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractFunctionParameters.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -76,13 +73,11 @@ public final class ContractFunctionParameters { private static ByteString encodeString(String string) { ByteString strBytes = ByteString.copyFromUtf8(string); // prepend the size of the string in UTF-8 bytes - return int256(strBytes.size(), 32) - .concat(rightPad32(strBytes)); + return int256(strBytes.size(), 32).concat(rightPad32(strBytes)); } private static ByteString encodeBytes(byte[] bytes) { - return int256(bytes.length, 32) - .concat(rightPad32(ByteString.copyFrom(bytes))); + return int256(bytes.length, 32).concat(rightPad32(ByteString.copyFrom(bytes))); } private static ByteString encodeBytes32(byte[] bytes) { @@ -100,8 +95,7 @@ private static ByteString encodeBool(boolean bool) { private static ByteString encodeArray(Stream elements) { List list = elements.collect(Collectors.toList()); - return int256(list.size(), 32) - .concat(ByteString.copyFrom(list)); + return int256(list.size(), 32).concat(ByteString.copyFrom(list)); } private static ByteString encodeDynArr(List elements) { @@ -155,9 +149,9 @@ static ByteString int256(long val, int bitWidth, boolean signed) { static byte[] getTruncatedBytes(BigInteger bigInt, int bitWidth) { byte[] bytes = bigInt.toByteArray(); int expectedBytes = bitWidth / 8; - return bytes.length <= expectedBytes ? - bytes : - Arrays.copyOfRange(bytes, bytes.length - expectedBytes, bytes.length); + return bytes.length <= expectedBytes + ? bytes + : Arrays.copyOfRange(bytes, bytes.length - expectedBytes, bytes.length); } static ByteString int256(BigInteger bigInt, int bitWidth) { @@ -184,9 +178,8 @@ static ByteString leftPad32(ByteString input) { static ByteString leftPad32(ByteString input, boolean negative) { int rem = 32 - input.size() % 32; return rem == 32 - ? input - : (negative ? negativePadding : padding).substring(0, rem) - .concat(input); + ? input + : (negative ? negativePadding : padding).substring(0, rem).concat(input); } static ByteString leftPad32(byte[] input, boolean negative) { @@ -202,8 +195,7 @@ private static byte[] decodeAddress(String address) { address = address.startsWith("0x") ? address.substring(2) : address; if (address.length() != ADDRESS_LEN_HEX) { - throw new IllegalArgumentException( - "Solidity addresses must be 40 hex chars"); + throw new IllegalArgumentException("Solidity addresses must be 40 hex chars"); } try { @@ -236,8 +228,8 @@ public ContractFunctionParameters addString(String param) { */ public ContractFunctionParameters addStringArray(String[] strings) { List byteStrings = Arrays.stream(strings) - .map(ContractFunctionParameters::encodeString) - .collect(Collectors.toList()); + .map(ContractFunctionParameters::encodeString) + .collect(Collectors.toList()); ByteString argBytes = encodeDynArr(byteStrings); @@ -266,8 +258,8 @@ public ContractFunctionParameters addBytes(byte[] param) { */ public ContractFunctionParameters addBytesArray(byte[][] param) { List byteArrays = Arrays.stream(param) - .map(ContractFunctionParameters::encodeBytes) - .collect(Collectors.toList()); + .map(ContractFunctionParameters::encodeBytes) + .collect(Collectors.toList()); args.add(new Argument("bytes[]", encodeDynArr(byteArrays), true)); @@ -300,8 +292,7 @@ public ContractFunctionParameters addBytes32(byte[] param) { */ public ContractFunctionParameters addBytes32Array(byte[][] param) { // array of fixed-size elements - Stream byteArrays = Arrays.stream(param) - .map(ContractFunctionParameters::encodeBytes32); + Stream byteArrays = Arrays.stream(param).map(ContractFunctionParameters::encodeBytes32); args.add(new Argument("bytes32[]", encodeArray(byteArrays), true)); @@ -332,8 +323,7 @@ public ContractFunctionParameters addBoolArray(boolean[] param) { boolWrapperArray[i] = param[i]; } - Stream bools = Arrays.stream(boolWrapperArray) - .map(ContractFunctionParameters::encodeBool); + Stream bools = Arrays.stream(boolWrapperArray).map(ContractFunctionParameters::encodeBool); args.add(new Argument("bool[]", encodeArray(bools), true)); @@ -737,9 +727,8 @@ public ContractFunctionParameters addInt256(BigInteger value) { public ContractFunctionParameters addInt8Array(byte[] intArray) { IntStream intStream = IntStream.range(0, intArray.length).map(idx -> intArray[idx]); - ByteString arrayBytes = ByteString.copyFrom( - intStream.mapToObj(i -> int256(i, 8)) - .collect(Collectors.toList())); + ByteString arrayBytes = + ByteString.copyFrom(intStream.mapToObj(i -> int256(i, 8)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -756,8 +745,7 @@ public ContractFunctionParameters addInt8Array(byte[] intArray) { */ public ContractFunctionParameters addInt16Array(int[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> int256(i, 16)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> int256(i, 16)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -774,8 +762,7 @@ public ContractFunctionParameters addInt16Array(int[] intArray) { */ public ContractFunctionParameters addInt24Array(int[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> int256(i, 24)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> int256(i, 24)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -792,8 +779,7 @@ public ContractFunctionParameters addInt24Array(int[] intArray) { */ public ContractFunctionParameters addInt32Array(int[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> int256(i, 32)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> int256(i, 32)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -810,8 +796,7 @@ public ContractFunctionParameters addInt32Array(int[] intArray) { */ public ContractFunctionParameters addInt40Array(long[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> int256(i, 40)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> int256(i, 40)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -828,8 +813,7 @@ public ContractFunctionParameters addInt40Array(long[] intArray) { */ public ContractFunctionParameters addInt48Array(long[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> int256(i, 48)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> int256(i, 48)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -846,8 +830,7 @@ public ContractFunctionParameters addInt48Array(long[] intArray) { */ public ContractFunctionParameters addInt56Array(long[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> int256(i, 56)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> int256(i, 56)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -864,8 +847,7 @@ public ContractFunctionParameters addInt56Array(long[] intArray) { */ public ContractFunctionParameters addInt64Array(long[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> int256(i, 64)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> int256(i, 64)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -882,8 +864,7 @@ public ContractFunctionParameters addInt64Array(long[] intArray) { */ public ContractFunctionParameters addInt72Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 72)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 72)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -900,8 +881,7 @@ public ContractFunctionParameters addInt72Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt80Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 80)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 80)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -918,8 +898,7 @@ public ContractFunctionParameters addInt80Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt88Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 88)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 88)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -936,8 +915,7 @@ public ContractFunctionParameters addInt88Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt96Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 96)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 96)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -954,8 +932,7 @@ public ContractFunctionParameters addInt96Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt104Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 104)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 104)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -972,8 +949,7 @@ public ContractFunctionParameters addInt104Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt112Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 112)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 112)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -990,8 +966,7 @@ public ContractFunctionParameters addInt112Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt120Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 120)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 120)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1008,8 +983,7 @@ public ContractFunctionParameters addInt120Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt128Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 128)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 128)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1026,8 +1000,7 @@ public ContractFunctionParameters addInt128Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt136Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 136)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 136)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1044,8 +1017,7 @@ public ContractFunctionParameters addInt136Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt144Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 144)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 144)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1062,8 +1034,7 @@ public ContractFunctionParameters addInt144Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt152Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 152)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 152)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1080,8 +1051,7 @@ public ContractFunctionParameters addInt152Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt160Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 160)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 160)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1098,8 +1068,7 @@ public ContractFunctionParameters addInt160Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt168Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 168)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 168)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1116,8 +1085,7 @@ public ContractFunctionParameters addInt168Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt176Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 176)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 176)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1134,8 +1102,7 @@ public ContractFunctionParameters addInt176Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt184Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 184)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 184)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1152,8 +1119,7 @@ public ContractFunctionParameters addInt184Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt192Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 192)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 192)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1170,8 +1136,7 @@ public ContractFunctionParameters addInt192Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt200Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 200)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 200)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1188,8 +1153,7 @@ public ContractFunctionParameters addInt200Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt208Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 208)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 208)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1206,8 +1170,7 @@ public ContractFunctionParameters addInt208Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt216Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 216)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 216)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1224,8 +1187,7 @@ public ContractFunctionParameters addInt216Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt224Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 224)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 224)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1242,8 +1204,7 @@ public ContractFunctionParameters addInt224Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt232Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 232)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 232)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1260,8 +1221,7 @@ public ContractFunctionParameters addInt232Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt240Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 240)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 240)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1278,8 +1238,7 @@ public ContractFunctionParameters addInt240Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt248Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 248)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 248)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1296,8 +1255,7 @@ public ContractFunctionParameters addInt248Array(BigInteger[] intArray) { */ public ContractFunctionParameters addInt256Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> int256(i, 256)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> int256(i, 256)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1820,9 +1778,8 @@ public ContractFunctionParameters addUint256(BigInteger value) { public ContractFunctionParameters addUint8Array(byte[] intArray) { IntStream intStream = IntStream.range(0, intArray.length).map(idx -> intArray[idx]); - ByteString arrayBytes = ByteString.copyFrom( - intStream.mapToObj(i -> uint256(i, 8)) - .collect(Collectors.toList())); + ByteString arrayBytes = + ByteString.copyFrom(intStream.mapToObj(i -> uint256(i, 8)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1842,8 +1799,7 @@ public ContractFunctionParameters addUint8Array(byte[] intArray) { */ public ContractFunctionParameters addUint16Array(int[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> uint256(i, 16)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> uint256(i, 16)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1863,8 +1819,7 @@ public ContractFunctionParameters addUint16Array(int[] intArray) { */ public ContractFunctionParameters addUint24Array(int[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> uint256(i, 24)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> uint256(i, 24)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1884,8 +1839,7 @@ public ContractFunctionParameters addUint24Array(int[] intArray) { */ public ContractFunctionParameters addUint32Array(int[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> uint256(i, 32)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> uint256(i, 32)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1905,8 +1859,7 @@ public ContractFunctionParameters addUint32Array(int[] intArray) { */ public ContractFunctionParameters addUint40Array(long[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> uint256(i, 40)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> uint256(i, 40)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1926,8 +1879,7 @@ public ContractFunctionParameters addUint40Array(long[] intArray) { */ public ContractFunctionParameters addUint48Array(long[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> uint256(i, 48)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> uint256(i, 48)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1947,8 +1899,7 @@ public ContractFunctionParameters addUint48Array(long[] intArray) { */ public ContractFunctionParameters addUint56Array(long[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> uint256(i, 56)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> uint256(i, 56)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1968,8 +1919,7 @@ public ContractFunctionParameters addUint56Array(long[] intArray) { */ public ContractFunctionParameters addUint64Array(long[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).mapToObj(i -> uint256(i, 64)) - .collect(Collectors.toList())); + Arrays.stream(intArray).mapToObj(i -> uint256(i, 64)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -1990,8 +1940,7 @@ public ContractFunctionParameters addUint64Array(long[] intArray) { */ public ContractFunctionParameters addUint72Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 72)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 72)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2012,8 +1961,7 @@ public ContractFunctionParameters addUint72Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint80Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 80)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 80)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2034,8 +1982,7 @@ public ContractFunctionParameters addUint80Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint88Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 88)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 88)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2056,8 +2003,7 @@ public ContractFunctionParameters addUint88Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint96Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 96)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 96)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2078,8 +2024,7 @@ public ContractFunctionParameters addUint96Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint104Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 104)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 104)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2100,8 +2045,7 @@ public ContractFunctionParameters addUint104Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint112Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 112)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 112)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2122,8 +2066,7 @@ public ContractFunctionParameters addUint112Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint120Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 120)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 120)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2144,8 +2087,7 @@ public ContractFunctionParameters addUint120Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint128Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 128)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 128)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2166,8 +2108,7 @@ public ContractFunctionParameters addUint128Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint136Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 136)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 136)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2188,8 +2129,7 @@ public ContractFunctionParameters addUint136Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint144Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 144)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 144)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2210,8 +2150,7 @@ public ContractFunctionParameters addUint144Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint152Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 152)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 152)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2232,8 +2171,7 @@ public ContractFunctionParameters addUint152Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint160Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 160)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 160)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2254,8 +2192,7 @@ public ContractFunctionParameters addUint160Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint168Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 168)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 168)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2276,8 +2213,7 @@ public ContractFunctionParameters addUint168Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint176Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 176)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 176)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2298,8 +2234,7 @@ public ContractFunctionParameters addUint176Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint184Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 184)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 184)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2320,8 +2255,7 @@ public ContractFunctionParameters addUint184Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint192Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 192)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 192)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2342,8 +2276,7 @@ public ContractFunctionParameters addUint192Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint200Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 200)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 200)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2364,8 +2297,7 @@ public ContractFunctionParameters addUint200Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint208Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 208)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 208)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2386,8 +2318,7 @@ public ContractFunctionParameters addUint208Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint216Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 216)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 216)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2408,8 +2339,7 @@ public ContractFunctionParameters addUint216Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint224Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 224)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 224)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2430,8 +2360,7 @@ public ContractFunctionParameters addUint224Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint232Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 232)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 232)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2452,8 +2381,7 @@ public ContractFunctionParameters addUint232Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint240Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 240)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 240)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2474,8 +2402,7 @@ public ContractFunctionParameters addUint240Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint248Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 248)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 248)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2496,8 +2423,7 @@ public ContractFunctionParameters addUint248Array(BigInteger[] intArray) { */ public ContractFunctionParameters addUint256Array(BigInteger[] intArray) { ByteString arrayBytes = ByteString.copyFrom( - Arrays.stream(intArray).map(i -> uint256(i, 256)) - .collect(Collectors.toList())); + Arrays.stream(intArray).map(i -> uint256(i, 256)).collect(Collectors.toList())); arrayBytes = uint256(intArray.length, 32).concat(arrayBytes); @@ -2535,11 +2461,10 @@ public ContractFunctionParameters addAddress(String address) { * @throws NullPointerException if any value in the array is null. */ public ContractFunctionParameters addAddressArray(String[] addresses) { - ByteString addressArray = encodeArray( - Arrays.stream(addresses).map(a -> { - byte[] address = decodeAddress(a); - return leftPad32(ByteString.copyFrom(address)); - })); + ByteString addressArray = encodeArray(Arrays.stream(addresses).map(a -> { + byte[] address = decodeAddress(a); + return leftPad32(ByteString.copyFrom(address)); + })); args.add(new Argument("address[]", addressArray, true)); @@ -2612,8 +2537,7 @@ ByteString toBytes(@Nullable String funcName) { var dynamicArgs = new ArrayList(); - ContractFunctionSelector functionSelector = funcName != null - ? new ContractFunctionSelector(funcName) : null; + ContractFunctionSelector functionSelector = funcName != null ? new ContractFunctionSelector(funcName) : null; // iterate the arguments and determine whether they are dynamic or not for (Argument arg : args) { @@ -2642,7 +2566,7 @@ ByteString toBytes(@Nullable String funcName) { return ByteString.copyFrom(paramsBytes); } - private final static class Argument { + private static final class Argument { private final String type; private final ByteString value; diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractUpdateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractUpdateTransaction.java index bcc748da4..3a0f6b259 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractUpdateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractUpdateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.BoolValue; @@ -31,10 +28,9 @@ import io.grpc.MethodDescriptor; import java.time.Duration; import java.time.Instant; - -import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Modify a smart contract instance to have the given parameter values. @@ -62,18 +58,25 @@ public final class ContractUpdateTransaction extends Transaction { @Nullable private ContractId contractId = null; + @Nullable private AccountId proxyAccountId = null; + @Nullable private FileId bytecodeFileId = null; + @Nullable private Instant expirationTime = null; + @Nullable private Key adminKey = null; + @Nullable private Integer maxAutomaticTokenAssociations = null; + @Nullable private Duration autoRenewPeriod = null; + @Nullable private String contractMemo = null; @@ -92,8 +95,7 @@ public final class ContractUpdateTransaction extends Transaction> txs) throws InvalidProtocolBufferException { + ContractUpdateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -480,7 +484,8 @@ void initFromTransactionBody() { adminKey = Key.fromProtobufKey(body.getAdminKey()); } if (body.hasMaxAutomaticTokenAssociations()) { - maxAutomaticTokenAssociations = body.getMaxAutomaticTokenAssociations().getValue(); + maxAutomaticTokenAssociations = + body.getMaxAutomaticTokenAssociations().getValue(); } if (body.hasAutoRenewPeriod()) { autoRenewPeriod = DurationConverter.fromProtobuf(body.getAutoRenewPeriod()); @@ -544,7 +549,8 @@ ContractUpdateTransactionBody.Builder build() { } if (declineStakingReward != null) { - builder.setDeclineReward(BoolValue.newBuilder().setValue(declineStakingReward).build()); + builder.setDeclineReward( + BoolValue.newBuilder().setValue(declineStakingReward).build()); } if (autoRenewAccountId != null) { diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java index f9f6642c0..11d47cfb5 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Endpoint.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; import com.hedera.hashgraph.sdk.proto.ServiceEndpoint; - -import java.util.Arrays; import javax.annotation.Nullable; -import java.util.Objects; /** * Utility class used internally by the sdk. @@ -41,8 +35,7 @@ public class Endpoint implements Cloneable { /** * Constructor. */ - public Endpoint() { - } + public Endpoint() {} /** * Create an endpoint object from a service endpoint protobuf. @@ -58,9 +51,9 @@ static Endpoint fromProtobuf(ServiceEndpoint serviceEndpoint) { } return new Endpoint() - .setAddress(serviceEndpoint.getIpAddressV4().toByteArray()) - .setPort(port) - .setDomainName(serviceEndpoint.getDomainName()); + .setAddress(serviceEndpoint.getIpAddressV4().toByteArray()) + .setPort(port) + .setDomainName(serviceEndpoint.getDomainName()); } /** @@ -146,9 +139,10 @@ public String toString() { if (this.domainName != null && !this.domainName.isEmpty()) { return domainName + ":" + port; } else { - return ((int) address[0] & 0x000000FF) + "." + ((int) address[1] & 0x000000FF) + "." + - ((int) address[2] & 0x000000FF) + "." + ((int) address[3] & 0x000000FF) + - ":" + port; + return ((int) address[0] & 0x000000FF) + "." + ((int) address[1] & 0x000000FF) + "." + + ((int) address[2] & 0x000000FF) + + "." + ((int) address[3] & 0x000000FF) + ":" + + port; } } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/EntityIdHelper.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/EntityIdHelper.java index 0a07af183..3aa62f6af 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/EntityIdHelper.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/EntityIdHelper.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.gson.JsonObject; @@ -51,16 +48,15 @@ class EntityIdHelper { */ static final int SOLIDITY_ADDRESS_LEN_HEX = SOLIDITY_ADDRESS_LEN * 2; - private static final Pattern ENTITY_ID_REGEX = Pattern.compile( - "(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-([a-z]{5}))?$"); + private static final Pattern ENTITY_ID_REGEX = + Pattern.compile("(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-([a-z]{5}))?$"); static final Duration MIRROR_NODE_CONNECTION_TIMEOUT = Duration.ofSeconds(30); /** * Constructor. */ - private EntityIdHelper() { - } + private EntityIdHelper() {} /** * Generate an R object from a string. @@ -74,14 +70,13 @@ static R fromString(String idString, WithIdNums constructObjectWithIdNums var match = ENTITY_ID_REGEX.matcher(idString); if (!match.find()) { throw new IllegalArgumentException( - "Invalid ID \"" + idString + "\": format should look like 0.0.123 or 0.0.123-vfmkw" - ); + "Invalid ID \"" + idString + "\": format should look like 0.0.123 or 0.0.123-vfmkw"); } return constructObjectWithIdNums.apply( - Long.parseLong(match.group(1)), - Long.parseLong(match.group(2)), - Long.parseLong(match.group(3)), - match.group(4)); + Long.parseLong(match.group(1)), + Long.parseLong(match.group(2)), + Long.parseLong(match.group(3)), + match.group(4)); } /** @@ -98,8 +93,7 @@ static R fromSolidityAddress(String address, WithIdNums withAddress) { private static R fromSolidityAddress(byte[] address, WithIdNums withAddress) { if (address.length != SOLIDITY_ADDRESS_LEN) { - throw new IllegalArgumentException( - "Solidity addresses must be 20 bytes or 40 hex chars"); + throw new IllegalArgumentException("Solidity addresses must be 20 bytes or 40 hex chars"); } var buf = ByteBuffer.wrap(address); @@ -116,8 +110,7 @@ public static byte[] decodeSolidityAddress(String address) { address = address.startsWith("0x") ? address.substring(2) : address; if (address.length() != SOLIDITY_ADDRESS_LEN_HEX) { - throw new IllegalArgumentException( - "Solidity addresses must be 20 bytes or 40 hex chars"); + throw new IllegalArgumentException("Solidity addresses must be 20 bytes or 40 hex chars"); } try { @@ -140,8 +133,7 @@ static String toSolidityAddress(long shard, long realm, long num) { throw new IllegalStateException("shard out of 32-bit range " + shard); } - return Hex.toHexString( - ByteBuffer.allocate(20) + return Hex.toHexString(ByteBuffer.allocate(20) .putInt((int) shard) .putLong(realm) .putLong(num) @@ -157,7 +149,8 @@ static String toSolidityAddress(long shard, long realm, long num) { */ static String checksum(LedgerId ledgerId, String addr) { StringBuilder answer = new StringBuilder(); - List d = new ArrayList<>(); // Digits with 10 for ".", so if addr == "0.0.123" then d == [0, 10, 0, 10, 1, 2, 3] + List d = + new ArrayList<>(); // Digits with 10 for ".", so if addr == "0.0.123" then d == [0, 10, 0, 10, 1, 2, 3] long s0 = 0; // Sum of even positions (mod 11) long s1 = 0; // Sum of odd positions (mod 11) long s = 0; // Weighted sum of all positions (mod p3) @@ -167,7 +160,7 @@ static String checksum(LedgerId ledgerId, String addr) { long p3 = 26 * 26 * 26; // 3 digits in base 26 long p5 = 26 * 26 * 26 * 26 * 26; // 5 digits in base 26 long asciiA = Character.codePointAt("a", 0); // 97 - long m = 1_000_003; //min prime greater than a million. Used for the final permutation. + long m = 1_000_003; // min prime greater than a million. Used for the final permutation. long w = 31; // Sum s of digit values weights them by powers of w. Should be coprime to p5. List h = new ArrayList<>(ledgerId.toBytes().length + 6); @@ -214,16 +207,14 @@ static String checksum(LedgerId ledgerId, String addr) { * @throws BadEntityIdException */ static void validate(long shard, long realm, long num, Client client, @Nullable String checksum) - throws BadEntityIdException { + throws BadEntityIdException { if (client.getNetworkName() == null) { throw new IllegalStateException( - "Can't validate checksum without knowing which network the ID is for. Ensure client's network name is set."); + "Can't validate checksum without knowing which network the ID is for. Ensure client's network name is set."); } if (checksum != null) { - String expectedChecksum = EntityIdHelper.checksum( - client.getLedgerId(), - EntityIdHelper.toString(shard, realm, num) - ); + String expectedChecksum = + EntityIdHelper.checksum(client.getLedgerId(), EntityIdHelper.toString(shard, realm, num)); if (!checksum.equals(expectedChecksum)) { throw new BadEntityIdException(shard, realm, num, checksum, expectedChecksum); } @@ -254,11 +245,11 @@ static String toString(long shard, long realm, long num) { */ static String toStringWithChecksum(long shard, long realm, long num, Client client, @Nullable String checksum) { if (client.getLedgerId() != null) { - return "" + shard + "." + realm + "." + num + "-" + checksum(client.getLedgerId(), - EntityIdHelper.toString(shard, realm, num)); + return "" + shard + "." + realm + "." + num + "-" + + checksum(client.getLedgerId(), EntityIdHelper.toString(shard, realm, num)); } else { throw new IllegalStateException( - "Can't derive checksum for ID without knowing which network the ID is for. Ensure client's ledgerId is set."); + "Can't derive checksum for ID without knowing which network the ID is for. Ensure client's ledgerId is set."); } } @@ -291,8 +282,7 @@ public static boolean isLongZeroAddress(byte[] address) { public static CompletableFuture getAccountNumFromMirrorNodeAsync(Client client, String evmAddress) { String apiEndpoint = "/accounts/" + evmAddress; return performQueryToMirrorNodeAsync(client, apiEndpoint) - .thenApply(response -> - parseNumFromMirrorNodeResponse(response, "account")); + .thenApply(response -> parseNumFromMirrorNodeResponse(response, "account")); } /** @@ -310,8 +300,8 @@ public static CompletableFuture getAccountNumFromMirrorNodeAsync(Client cl public static CompletableFuture getEvmAddressFromMirrorNodeAsync(Client client, long num) { String apiEndpoint = "/accounts/" + num; return performQueryToMirrorNodeAsync(client, apiEndpoint) - .thenApply(response -> - EvmAddress.fromString(parseEvmAddressFromMirrorNodeResponse(response, "evm_address"))); + .thenApply(response -> + EvmAddress.fromString(parseEvmAddressFromMirrorNodeResponse(response, "evm_address"))); } /** @@ -331,14 +321,13 @@ public static CompletableFuture getContractNumFromMirrorNodeAsync(Client c CompletableFuture responseFuture = performQueryToMirrorNodeAsync(client, apiEndpoint); - return responseFuture.thenApply(response -> - parseNumFromMirrorNodeResponse(response, "contract_id")); + return responseFuture.thenApply(response -> parseNumFromMirrorNodeResponse(response, "contract_id")); } private static CompletableFuture performQueryToMirrorNodeAsync(Client client, String apiEndpoint) { Optional mirrorUrl = client.getMirrorNetwork().stream() - .map(url -> url.substring(0, url.indexOf(":"))) - .findFirst(); + .map(url -> url.substring(0, url.indexOf(":"))) + .findFirst(); if (mirrorUrl.isEmpty()) { return CompletableFuture.failedFuture(new IllegalArgumentException("Mirror URL not found")); @@ -352,12 +341,13 @@ private static CompletableFuture performQueryToMirrorNodeAsync(Client cl HttpClient httpClient = HttpClient.newHttpClient(); HttpRequest httpRequest = HttpRequest.newBuilder() - .timeout(MIRROR_NODE_CONNECTION_TIMEOUT) - .uri(URI.create(apiUrl)) - .build(); + .timeout(MIRROR_NODE_CONNECTION_TIMEOUT) + .uri(URI.create(apiUrl)) + .build(); - return httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()) - .thenApply(HttpResponse::body); + return httpClient + .sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()) + .thenApply(HttpResponse::body); } private static long parseNumFromMirrorNodeResponse(String responseBody, String memberName) { diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/FeeSchedule.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/FeeSchedule.java index f5afd5acd..bc7125289 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/FeeSchedule.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/FeeSchedule.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,19 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.common.base.MoreObjects; import com.google.protobuf.InvalidProtocolBufferException; import java.time.Instant; - -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; +import javax.annotation.Nullable; /** * The fee schedule for a specific hedera functionality and the time period this fee schedule will expire. @@ -36,14 +32,14 @@ */ public class FeeSchedule implements Cloneable { private List transactionFeeSchedules = new ArrayList<>(); + @Nullable private Instant expirationTime; /** * Constructor. */ - public FeeSchedule() { - } + public FeeSchedule() {} /** * Create a fee schedule from a protobuf. @@ -53,10 +49,12 @@ public FeeSchedule() { */ static FeeSchedule fromProtobuf(com.hedera.hashgraph.sdk.proto.FeeSchedule feeSchedule) { FeeSchedule returnFeeSchedule = new FeeSchedule() - .setExpirationTime(feeSchedule.hasExpiryTime() ? InstantConverter.fromProtobuf(feeSchedule.getExpiryTime()) : null); + .setExpirationTime( + feeSchedule.hasExpiryTime() + ? InstantConverter.fromProtobuf(feeSchedule.getExpiryTime()) + : null); for (var transactionFeeSchedule : feeSchedule.getTransactionFeeScheduleList()) { - returnFeeSchedule - .addTransactionFeeSchedule(TransactionFeeSchedule.fromProtobuf(transactionFeeSchedule)); + returnFeeSchedule.addTransactionFeeSchedule(TransactionFeeSchedule.fromProtobuf(transactionFeeSchedule)); } return returnFeeSchedule; } @@ -69,7 +67,8 @@ static FeeSchedule fromProtobuf(com.hedera.hashgraph.sdk.proto.FeeSchedule feeSc * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ public static FeeSchedule fromBytes(byte[] bytes) throws InvalidProtocolBufferException { - return fromProtobuf(com.hedera.hashgraph.sdk.proto.FeeSchedule.parseFrom(bytes).toBuilder().build()); + return fromProtobuf(com.hedera.hashgraph.sdk.proto.FeeSchedule.parseFrom(bytes).toBuilder() + .build()); } /** @@ -151,9 +150,9 @@ com.hedera.hashgraph.sdk.proto.FeeSchedule toProtobuf() { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("transactionFeeSchedules", getTransactionFeeSchedules()) - .add("expirationTime", getExpirationTime()) - .toString(); + .add("transactionFeeSchedules", getTransactionFeeSchedules()) + .add("expirationTime", getExpirationTime()) + .toString(); } /** diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/FileCreateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/FileCreateTransaction.java index 39dc787be..962d6c078 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/FileCreateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/FileCreateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -27,15 +24,14 @@ import com.hedera.hashgraph.sdk.proto.TransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionResponse; import io.grpc.MethodDescriptor; -import java.time.Instant; - -import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Creates a file with the content by submitting the transaction. @@ -46,8 +42,10 @@ public final class FileCreateTransaction extends Transaction> txs) throws InvalidProtocolBufferException { + FileCreateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/FileUpdateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/FileUpdateTransaction.java index 053a19634..917f09629 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/FileUpdateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/FileUpdateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -28,15 +25,14 @@ import com.hedera.hashgraph.sdk.proto.TransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionResponse; import io.grpc.MethodDescriptor; -import java.time.Instant; - -import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Updates a file by submitting the transaction. @@ -47,19 +43,22 @@ public final class FileUpdateTransaction extends Transaction> txs) throws InvalidProtocolBufferException { + FileUpdateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -109,7 +110,7 @@ public FileUpdateTransaction setFileId(FileId fileId) { /** * Get the keys which must sign any transactions modifying this file. * - * @return the list of keys + * @return the list of keys */ @Nullable public Collection getKeys() { diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/FreezeTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/FreezeTransaction.java index b78ca0e6d..212ee94e2 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/FreezeTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/FreezeTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -30,11 +27,10 @@ import java.time.Instant; import java.time.OffsetTime; import java.time.ZoneOffset; - -import javax.annotation.Nullable; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Set the freezing period in which the platform will stop creating events and accepting transactions. @@ -43,18 +39,20 @@ public final class FreezeTransaction extends Transaction { private int endHour = 0; private int endMinute = 0; + @Nullable private Instant startTime = null; + @Nullable private FileId fileId = null; + private byte[] fileHash = {}; private FreezeType freezeType = FreezeType.UNKNOWN_FREEZE_TYPE; /** * Constructor. */ - public FreezeTransaction() { - } + public FreezeTransaction() {} /** * Constructor. @@ -63,7 +61,9 @@ public FreezeTransaction() { * records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - FreezeTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + FreezeTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -108,7 +108,7 @@ public FreezeTransaction setStartTime(Instant startTime) { */ @Deprecated public FreezeTransaction setStartTime(int hour, int minute) { - return setStartTime(Instant.ofEpochMilli(((long)hour * 60 * 60 + (long)minute * 60) * 1000)); + return setStartTime(Instant.ofEpochMilli(((long) hour * 60 * 60 + (long) minute * 60) * 1000)); } /** @@ -191,7 +191,7 @@ public FileId getFileId() { /** * Assign the file id. * - * @param fileId the file id + * @param fileId the file id * @return {@code this} */ public FreezeTransaction setFileId(FileId fileId) { @@ -247,8 +247,7 @@ public FreezeTransaction setFreezeType(FreezeType freezeType) { } @Override - void validateChecksums(Client client) { - } + void validateChecksums(Client client) {} @Override MethodDescriptor getMethodDescriptor() { diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/HederaTrustManager.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/HederaTrustManager.java index dae46e2da..42d4ab7f1 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/HederaTrustManager.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/HederaTrustManager.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,19 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; -import org.bouncycastle.util.encoders.Hex; -import org.bouncycastle.util.io.pem.PemObject; -import org.bouncycastle.util.io.pem.PemWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.Nullable; -import javax.net.ssl.X509TrustManager; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; @@ -36,6 +25,13 @@ import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import javax.annotation.Nullable; +import javax.net.ssl.X509TrustManager; +import org.bouncycastle.util.encoders.Hex; +import org.bouncycastle.util.io.pem.PemObject; +import org.bouncycastle.util.io.pem.PemWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Internal class used by node. @@ -58,7 +54,8 @@ class HederaTrustManager implements X509TrustManager { HederaTrustManager(@Nullable ByteString certHash, boolean verifyCertificate) { if (certHash == null || certHash.isEmpty()) { if (verifyCertificate) { - throw new IllegalStateException("transport security and certificate verification are enabled, but no applicable address book was found"); + throw new IllegalStateException( + "transport security and certificate verification are enabled, but no applicable address book was found"); } logger.warn("skipping certificate check since no cert hash was found"); @@ -70,7 +67,8 @@ class HederaTrustManager implements X509TrustManager { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) { - throw new UnsupportedOperationException("Attempted to use HederaTrustManager to verify a client, but this trust manager is for verifying server only"); + throw new UnsupportedOperationException( + "Attempted to use HederaTrustManager to verify a client, but this trust manager is for verifying server only"); } @Override @@ -82,10 +80,8 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws for (var cert : chain) { byte[] pem; - try ( - var outputStream = new ByteArrayOutputStream(); - var pemWriter = new PemWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) - ) { + try (var outputStream = new ByteArrayOutputStream(); + var pemWriter = new PemWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))) { pemWriter.writeObject(new PemObject(CERTIFICATE, cert.getEncoded())); pemWriter.flush(); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Keystore.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Keystore.java index 6e94cb54e..97aa154d6 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Keystore.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Keystore.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.gson.Gson; @@ -25,10 +22,6 @@ import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import com.google.gson.stream.JsonWriter; -import java.util.Optional; -import org.bouncycastle.crypto.params.KeyParameter; -import org.bouncycastle.util.encoders.Hex; - import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -37,6 +30,9 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.Objects; +import java.util.Optional; +import org.bouncycastle.crypto.params.KeyParameter; +import org.bouncycastle.util.encoders.Hex; /** * Internal utility class to serialize / deserialize between java object / json representation. @@ -57,8 +53,9 @@ public Keystore(PrivateKey privateKey) { public static Keystore fromStream(InputStream stream, String passphrase) throws IOException { try { - JsonObject jsonObject = jsonParser.parse(new InputStreamReader(stream, StandardCharsets.UTF_8)) - .getAsJsonObject(); + JsonObject jsonObject = jsonParser + .parse(new InputStreamReader(stream, StandardCharsets.UTF_8)) + .getAsJsonObject(); return fromJson(jsonObject, passphrase); } catch (IllegalStateException e) { throw new BadKeyException(Optional.ofNullable(e.getMessage()).orElse("failed to parse Keystore")); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/LiveHashAddTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/LiveHashAddTransaction.java index 97d52d502..c8edf782c 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/LiveHashAddTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/LiveHashAddTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -29,13 +26,12 @@ import com.hedera.hashgraph.sdk.proto.TransactionResponse; import io.grpc.MethodDescriptor; import java.time.Duration; - -import javax.annotation.Nullable; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * A hash---presumably of some kind of credential or certificate---along with a list of keys, @@ -44,17 +40,19 @@ public final class LiveHashAddTransaction extends Transaction { @Nullable private AccountId accountId = null; + private byte[] hash = {}; + @Nullable private KeyList keys = null; + @Nullable private Duration duration = null; /** * Constructor. */ - public LiveHashAddTransaction() { - } + public LiveHashAddTransaction() {} /** * Constructor. @@ -63,7 +61,9 @@ public LiveHashAddTransaction() { * records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - LiveHashAddTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + LiveHashAddTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Mnemonic.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Mnemonic.java index 3a5004a0d..b88ece2c1 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Mnemonic.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Mnemonic.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,18 +12,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.google.common.base.Joiner; import com.hedera.hashgraph.sdk.utils.Bip32Utils; -import org.bouncycastle.crypto.digests.SHA256Digest; -import org.bouncycastle.crypto.digests.SHA512Digest; -import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator; -import org.bouncycastle.crypto.params.KeyParameter; - -import javax.annotation.Nullable; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -41,12 +34,15 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.function.Consumer; import java.util.function.Supplier; - -import static java.nio.charset.StandardCharsets.UTF_8; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.annotation.Nullable; +import org.bouncycastle.crypto.digests.SHA256Digest; +import org.bouncycastle.crypto.digests.SHA512Digest; +import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator; +import org.bouncycastle.crypto.params.KeyParameter; /** * BIP-39 24-word mnemonic phrases compatible with the Android and iOS mobile wallets. @@ -56,6 +52,7 @@ public final class Mnemonic { // but the implementation is meant to wait until free space is needed @Nullable private static SoftReference> bip39WordList = null; + @Nullable private static SoftReference> legacyWordList = null; @@ -205,24 +202,17 @@ private static int getWordIndex(CharSequence word, boolean isLegacy) { private static List getWordList(boolean isLegacy) { if (isLegacy) { return getSpecificWordList( - () -> legacyWordList, - () -> readWordList(true), - (newWordList) -> legacyWordList = newWordList - ); + () -> legacyWordList, () -> readWordList(true), (newWordList) -> legacyWordList = newWordList); } else { return getSpecificWordList( - () -> bip39WordList, - () -> readWordList(false), - (newWordList) -> bip39WordList = newWordList - ); + () -> bip39WordList, () -> readWordList(false), (newWordList) -> bip39WordList = newWordList); } } private static synchronized List getSpecificWordList( - Supplier>> getCurrentWordList, - Supplier> getNewWordList, - Consumer>> setCurrentWordList - ) { + Supplier>> getCurrentWordList, + Supplier> getNewWordList, + Consumer>> setCurrentWordList) { var localWordList = getCurrentWordList.get(); if (localWordList == null || localWordList.get() == null) { List words = getNewWordList.get(); @@ -237,7 +227,8 @@ private static synchronized List getSpecificWordList( private static List readWordList(boolean isLegacy) { if (isLegacy) { InputStream wordStream = Mnemonic.class.getClassLoader().getResourceAsStream("legacy-english.txt"); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(wordStream), UTF_8))) { + try (BufferedReader reader = + new BufferedReader(new InputStreamReader(Objects.requireNonNull(wordStream), UTF_8))) { ArrayList words = new ArrayList<>(4096); for (String word = reader.readLine(); word != null; word = reader.readLine()) { @@ -249,7 +240,8 @@ private static List readWordList(boolean isLegacy) { } } else { InputStream wordStream = Mnemonic.class.getClassLoader().getResourceAsStream("bip39-english.txt"); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(wordStream), UTF_8))) { + try (BufferedReader reader = + new BufferedReader(new InputStreamReader(Objects.requireNonNull(wordStream), UTF_8))) { ArrayList words = new ArrayList<>(2048); for (String word = reader.readLine(); word != null; word = reader.readLine()) { @@ -410,10 +402,7 @@ byte[] toSeed(String passphrase) { // BIP-39 seed generation PKCS5S2ParametersGenerator pbkdf2 = new PKCS5S2ParametersGenerator(new SHA512Digest()); - pbkdf2.init( - toString().getBytes(UTF_8), - salt.getBytes(UTF_8), - 2048); + pbkdf2.init(toString().getBytes(UTF_8), salt.getBytes(UTF_8), 2048); KeyParameter key = (KeyParameter) pbkdf2.generateDerivedParameters(512); return key.getKey(); @@ -422,8 +411,7 @@ byte[] toSeed(String passphrase) { private byte[] wordsToEntropyAndChecksum() { if (words.size() != 24 && words.size() != 12) { // should be checked in `validate()` - throw new IllegalStateException( - "(BUG) expected 24-word mnemonic, got " + words.size() + " words"); + throw new IllegalStateException("(BUG) expected 24-word mnemonic, got " + words.size() + " words"); } ByteBuffer buffer; if (words.size() == 12) { @@ -473,7 +461,7 @@ private byte[] wordsToLegacyEntropy() throws BadMnemonicException { for (var i = 0; i < data.length - 1; i += 1) { result[i] = data[i] ^ crc; } - //int to byte conversion + // int to byte conversion ByteBuffer byteBuffer = ByteBuffer.allocate(result.length * 4); IntBuffer intBuffer = byteBuffer.asIntBuffer(); intBuffer.put(result); @@ -487,7 +475,7 @@ private byte[] wordsToLegacyEntropy() throws BadMnemonicException { var i = 0; var j = 3; byte[] array2 = new byte[data.length - 1]; - //remove all the fill 0s + // remove all the fill 0s while (j < array.length) { array2[i] = array[j]; i++; @@ -550,7 +538,7 @@ public PrivateKey toStandardEd25519PrivateKey(String passphrase, int index) { var seed = this.toSeed(passphrase); PrivateKey derivedKey = PrivateKey.fromSeedED25519(seed); - for (int i : new int[]{44, 3030, 0, 0, index}) { + for (int i : new int[] {44, 3030, 0, 0, index}) { derivedKey = derivedKey.derive(i); } @@ -569,9 +557,7 @@ public PrivateKey toStandardEd25519PrivateKey(String passphrase, int index) { * e.g. "m/44'/60'/0'/0/0" * @return an array of integers designed to be used with PrivateKey#derive */ - private int[] calculateDerivationPathValues(String derivationPath) - throws IllegalArgumentException - { + private int[] calculateDerivationPathValues(String derivationPath) throws IllegalArgumentException { if (derivationPath == null || derivationPath.isEmpty()) { throw new IllegalArgumentException("Derivation path cannot be null or empty"); } @@ -642,12 +628,8 @@ private PrivateKey toStandardECDSAsecp256k1PrivateKeyImpl(String passphrase, int */ public PrivateKey toStandardECDSAsecp256k1PrivateKey(String passphrase, int index) { // Harden the first 3 indexes - final int[] derivationPathValues = new int[]{ - Bip32Utils.toHardenedIndex(44), - Bip32Utils.toHardenedIndex(3030), - Bip32Utils.toHardenedIndex(0), - 0, - index + final int[] derivationPathValues = new int[] { + Bip32Utils.toHardenedIndex(44), Bip32Utils.toHardenedIndex(3030), Bip32Utils.toHardenedIndex(0), 0, index }; return toStandardECDSAsecp256k1PrivateKeyImpl(passphrase, derivationPathValues); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Network.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Network.java index 350dc0a6d..d9024828c 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Network.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Network.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.common.io.ByteStreams; @@ -80,8 +77,8 @@ static Network forNetwork(ExecutorService executor, Map netwo */ static Network forMainnet(ExecutorService executor) { var addressBook = getAddressBookForLedger(LedgerId.MAINNET); - HashMap network = addressBookToNetwork( - Objects.requireNonNull(addressBook).values()); + HashMap network = + addressBookToNetwork(Objects.requireNonNull(addressBook).values()); return new Network(executor, network).setLedgerIdInternal(LedgerId.MAINNET, addressBook); } @@ -93,8 +90,8 @@ static Network forMainnet(ExecutorService executor) { */ static Network forTestnet(ExecutorService executor) { var addressBook = getAddressBookForLedger(LedgerId.TESTNET); - HashMap network = addressBookToNetwork( - Objects.requireNonNull(addressBook).values()); + HashMap network = + addressBookToNetwork(Objects.requireNonNull(addressBook).values()); return new Network(executor, network).setLedgerIdInternal(LedgerId.TESTNET, addressBook); } @@ -106,8 +103,8 @@ static Network forTestnet(ExecutorService executor) { */ static Network forPreviewnet(ExecutorService executor) { var addressBook = getAddressBookForLedger(LedgerId.PREVIEWNET); - HashMap network = addressBookToNetwork( - Objects.requireNonNull(addressBook).values()); + HashMap network = + addressBookToNetwork(Objects.requireNonNull(addressBook).values()); return new Network(executor, network).setLedgerIdInternal(LedgerId.PREVIEWNET, addressBook); } @@ -141,7 +138,8 @@ synchronized Network setLedgerId(@Nullable LedgerId ledgerId) { return setLedgerIdInternal(ledgerId, getAddressBookForLedger(ledgerId)); } - private Network setLedgerIdInternal(@Nullable LedgerId ledgerId, @Nullable Map addressBook) { + private Network setLedgerIdInternal( + @Nullable LedgerId ledgerId, @Nullable Map addressBook) { super.setLedgerId(ledgerId); this.addressBook = addressBook; @@ -154,25 +152,27 @@ private Network setLedgerIdInternal(@Nullable LedgerId ledgerId, @Nullable Map newAddressBook = addressBook.getNodeAddresses().stream() - .filter(nodeAddress -> Objects.nonNull(nodeAddress.getAccountId())) - .collect(Collectors.toMap(NodeAddress::getAccountId, Function.identity(), - /* - * Here we index by AccountId ignoring any subsequent entries with the same AccountId. - * - * Currently, this seems to be needed when reloading predefined address book for testnet which contains - * multiple entries with the same AccountId. - * - * If it becomes necessary to better handle such cases, either the one-to-one mapping from AccountId to - * single NodeAddress should be abandoned or NodeAddresses with the same AccountId may need to be merged. - * */ - (a, b) -> a)); + .filter(nodeAddress -> Objects.nonNull(nodeAddress.getAccountId())) + .collect(Collectors.toMap( + NodeAddress::getAccountId, + Function.identity(), + /* + * Here we index by AccountId ignoring any subsequent entries with the same AccountId. + * + * Currently, this seems to be needed when reloading predefined address book for testnet which contains + * multiple entries with the same AccountId. + * + * If it becomes necessary to better handle such cases, either the one-to-one mapping from AccountId to + * single NodeAddress should be abandoned or NodeAddresses with the same AccountId may need to be merged. + * */ + (a, b) -> a)); /* - * Here we preserve the certificate hash in the case where one is previously defined and no new one is provided. - * - * Currently, this seems to be needed since the downloaded address book lacks the certificate hash. However, - * it is expected the certificate hash will be provided in the future in which case this workaround will no - * longer be necessary. - * */ + * Here we preserve the certificate hash in the case where one is previously defined and no new one is provided. + * + * Currently, this seems to be needed since the downloaded address book lacks the certificate hash. However, + * it is expected the certificate hash will be provided in the future in which case this workaround will no + * longer be necessary. + * */ if (null != this.addressBook) { for (Map.Entry entry : newAddressBook.entrySet()) { NodeAddress previous = this.addressBook.get(entry.getKey()); @@ -192,16 +192,16 @@ void setAddressBook(NodeAddressBook addressBook) { @Nullable private static Map getAddressBookForLedger(@Nullable LedgerId ledgerId) { - return (ledgerId == null || !ledgerId.isKnownNetwork()) ? - null : - readAddressBookResource("addressbook/" + ledgerId + ".pb"); + return (ledgerId == null || !ledgerId.isKnownNetwork()) + ? null + : readAddressBookResource("addressbook/" + ledgerId + ".pb"); } static HashMap addressBookToNetwork(Collection addressBook) { var network = new HashMap(); for (var nodeAddress : addressBook) { for (var endpoint : nodeAddress.addresses) { - network.put(endpoint.toString(), nodeAddress.accountId); + network.put(endpoint.toString(), nodeAddress.accountId); } } return network; @@ -214,7 +214,8 @@ static HashMap addressBookToNetwork(Collection a * @return the list of address book records */ static Map readAddressBookResource(String fileName) { - try (var inputStream = Objects.requireNonNull(Network.class.getResource("/" + fileName)).openStream()) { + try (var inputStream = Objects.requireNonNull(Network.class.getResource("/" + fileName)) + .openStream()) { var contents = ByteStreams.toByteArray(inputStream); var nodeAddressBook = NodeAddressBook.fromBytes(ByteString.copyFrom(contents)); var map = new HashMap(); @@ -248,8 +249,7 @@ synchronized Map getNetwork() { @Override protected Node createNodeFromNetworkEntry(Map.Entry entry) { - return new Node(entry.getValue(), entry.getKey(), executor) - .setVerifyCertificates(verifyCertificates); + return new Node(entry.getValue(), entry.getKey(), executor).setVerifyCertificates(verifyCertificates); } /** diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/NodeAddress.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/NodeAddress.java index 350455a03..741dafef2 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/NodeAddress.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/NodeAddress.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,19 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.common.base.MoreObjects; import com.google.protobuf.ByteString; import com.hedera.hashgraph.sdk.proto.ServiceEndpoint; - -import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.annotation.Nullable; /** * The metadata for a Node – including IP Address, and the crypto account associated with the Node. @@ -71,8 +67,7 @@ public class NodeAddress implements Cloneable { /** * Constructor. */ - NodeAddress() { - } + NodeAddress() {} /** * Create a node from a protobuf. @@ -84,12 +79,10 @@ static NodeAddress fromProtobuf(com.hedera.hashgraph.sdk.proto.NodeAddress nodeA var address = new ArrayList(nodeAddress.getServiceEndpointCount()); if (!nodeAddress.getIpAddress().isEmpty()) { - address.add( - Endpoint.fromProtobuf(ServiceEndpoint.newBuilder() + address.add(Endpoint.fromProtobuf(ServiceEndpoint.newBuilder() .setIpAddressV4(nodeAddress.getIpAddress()) .setPort(nodeAddress.getPortno()) - .build()) - ); + .build())); } for (var endpoint : nodeAddress.getServiceEndpointList()) { @@ -97,12 +90,12 @@ static NodeAddress fromProtobuf(com.hedera.hashgraph.sdk.proto.NodeAddress nodeA } var node = new NodeAddress() - .setPublicKey(nodeAddress.getRSAPubKey()) - .setNodeId(nodeAddress.getNodeId()) - .setCertHash(nodeAddress.getNodeCertHash()) - .setAddresses(address) - .setDescription(nodeAddress.getDescription()) - .setStake(nodeAddress.getStake()); + .setPublicKey(nodeAddress.getRSAPubKey()) + .setNodeId(nodeAddress.getNodeId()) + .setCertHash(nodeAddress.getNodeCertHash()) + .setAddresses(address) + .setDescription(nodeAddress.getDescription()) + .setStake(nodeAddress.getStake()); if (nodeAddress.hasNodeAccountId()) { node.setAccountId(AccountId.fromProtobuf(nodeAddress.getNodeAccountId())); @@ -124,7 +117,7 @@ public String getPublicKey() { /** * Assign the public key. * - * @param publicKey the public key + * @param publicKey the public key * @return {@code this} */ public NodeAddress setPublicKey(String publicKey) { @@ -156,7 +149,7 @@ public NodeAddress setAccountId(AccountId accountId) { /** * Extract the node id. * - * @return the node id + * @return the node id */ public long getNodeId() { return nodeId; @@ -270,8 +263,7 @@ public NodeAddress setStake(long stake) { * @return the protobuf representation. */ com.hedera.hashgraph.sdk.proto.NodeAddress toProtobuf() { - var builder = com.hedera.hashgraph.sdk.proto.NodeAddress.newBuilder() - .setNodeId(nodeId); + var builder = com.hedera.hashgraph.sdk.proto.NodeAddress.newBuilder().setNodeId(nodeId); if (certHash != null) { builder.setNodeCertHash(certHash); @@ -299,14 +291,14 @@ com.hedera.hashgraph.sdk.proto.NodeAddress toProtobuf() { @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("publicKey", publicKey) - .add("accountId", accountId) - .add("nodeId", nodeId) - .add("certHash", certHash != null ? new String(certHash.toByteArray(), StandardCharsets.UTF_8) : null) - .add("addresses", addresses) - .add("description", description) - .add("stake", stake) - .toString(); + .add("publicKey", publicKey) + .add("accountId", accountId) + .add("nodeId", nodeId) + .add("certHash", certHash != null ? new String(certHash.toByteArray(), StandardCharsets.UTF_8) : null) + .add("addresses", addresses) + .add("description", description) + .add("stake", stake) + .toString(); } @Override diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/PrivateKey.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/PrivateKey.java index 7152727c3..a0cf98737 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/PrivateKey.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/PrivateKey.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.Arrays; +import javax.annotation.Nonnegative; +import javax.annotation.Nullable; import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; import org.bouncycastle.asn1.sec.ECPrivateKey; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; @@ -26,13 +29,6 @@ import org.bouncycastle.math.ec.rfc8032.Ed25519; import org.bouncycastle.util.encoders.Hex; -import javax.annotation.Nonnegative; -import javax.annotation.Nullable; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.util.Arrays; - /** * A private key on the Hedera™ network. */ @@ -116,7 +112,7 @@ public static PrivateKey fromMnemonic(Mnemonic mnemonic, String passphrase) { // we pre-derive most of the path as the mobile wallets don't expose more than the index // https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki // https://github.com/satoshilabs/slips/blob/master/slip-0044.md - for (int index : new int[]{44, 3030, 0, 0}) { + for (int index : new int[] {44, 3030, 0, 0}) { derivedKey = derivedKey.derive(index); } @@ -187,7 +183,7 @@ public static PrivateKey fromStringECDSA(String privateKey) { */ public static PrivateKey fromBytes(byte[] privateKey) { if ((privateKey.length == Ed25519.SECRET_KEY_SIZE) - || (privateKey.length == Ed25519.SECRET_KEY_SIZE + Ed25519.PUBLIC_KEY_SIZE)) { + || (privateKey.length == Ed25519.SECRET_KEY_SIZE + Ed25519.PUBLIC_KEY_SIZE)) { // If this is a 32 or 64 byte string, assume an Ed25519 private key return new PrivateKeyED25519(Arrays.copyOfRange(privateKey, 0, Ed25519.SECRET_KEY_SIZE), null); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java index 0b338bcae..769601bef 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/PublicKey.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.SignaturePair; +import javax.annotation.Nonnegative; +import javax.annotation.Nullable; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.math.ec.rfc8032.Ed25519; import org.bouncycastle.util.encoders.Hex; -import javax.annotation.Nonnegative; -import javax.annotation.Nullable; - /** * A public key on the Hedera™ network. */ @@ -50,8 +46,7 @@ public static PublicKey fromBytes(byte[] publicKey) { } else if (publicKey.length == 65) { // compress the 65 byte form return new PublicKeyECDSA( - Key.ECDSA_SECP256K1_CURVE.getCurve().decodePoint(publicKey).getEncoded(true) - ); + Key.ECDSA_SECP256K1_CURVE.getCurve().decodePoint(publicKey).getEncoded(true)); } // Assume a DER-encoded private key descriptor @@ -135,7 +130,7 @@ public static PublicKey fromStringDER(String publicKey) { * @return the new key */ private static PublicKey fromSubjectKeyInfo(SubjectPublicKeyInfo subjectPublicKeyInfo) { - if(subjectPublicKeyInfo.getAlgorithm().equals(new AlgorithmIdentifier(ID_ED25519))) { + if (subjectPublicKeyInfo.getAlgorithm().equals(new AlgorithmIdentifier(ID_ED25519))) { return PublicKeyED25519.fromSubjectKeyInfoInternal(subjectPublicKeyInfo); } else { // assume ECDSA @@ -202,7 +197,9 @@ public boolean verifyTransaction(Transaction transaction) { if (sigPair.getPubKeyPrefix().equals(ByteString.copyFrom(toBytesRaw()))) { found = true; - if (!verify(signedTransaction.getBodyBytes().toByteArray(), extractSignatureFromProtobuf(sigPair).toByteArray())) { + if (!verify( + signedTransaction.getBodyBytes().toByteArray(), + extractSignatureFromProtobuf(sigPair).toByteArray())) { return false; } } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/ScheduleCreateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/ScheduleCreateTransaction.java index 4cd57c784..e7c03c5a9 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/ScheduleCreateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/ScheduleCreateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; @@ -27,10 +24,9 @@ import com.hedera.hashgraph.sdk.proto.TransactionResponse; import io.grpc.MethodDescriptor; import java.time.Instant; - -import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Create a scheduled transaction. @@ -40,10 +36,13 @@ public final class ScheduleCreateTransaction extends Transaction { @Nullable private AccountId payerAccountId = null; + @Nullable private SchedulableTransactionBody transactionToSchedule = null; + @Nullable private Key adminKey = null; + private String scheduleMemo = ""; @Nullable @@ -65,7 +64,9 @@ public ScheduleCreateTransaction() { * records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - ScheduleCreateTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + ScheduleCreateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/SystemDeleteTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/SystemDeleteTransaction.java index d3807ee26..ba717a101 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/SystemDeleteTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/SystemDeleteTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; @@ -47,16 +44,17 @@ public final class SystemDeleteTransaction extends Transaction { @Nullable private FileId fileId = null; + @Nullable private ContractId contractId = null; + @Nullable private Instant expirationTime = null; /** * Constructor. */ - public SystemDeleteTransaction() { - } + public SystemDeleteTransaction() {} /** * Constructor. @@ -65,7 +63,9 @@ public SystemDeleteTransaction() { * records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - SystemDeleteTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + SystemDeleteTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -207,7 +207,8 @@ void validateChecksums(Client client) throws BadEntityIdException { CompletableFuture onExecuteAsync(Client client) { int modesEnabled = (fileId != null ? 1 : 0) + (contractId != null ? 1 : 0); if (modesEnabled != 1) { - throw new IllegalStateException("SystemDeleteTransaction must have exactly 1 of the following fields set: contractId, fileId"); + throw new IllegalStateException( + "SystemDeleteTransaction must have exactly 1 of the following fields set: contractId, fileId"); } return super.onExecuteAsync(client); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenCreateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenCreateTransaction.java index 7af57a37a..481b7ec73 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenCreateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenCreateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -29,13 +26,12 @@ import io.grpc.MethodDescriptor; import java.time.Duration; import java.time.Instant; - -import javax.annotation.Nonnegative; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Objects; +import javax.annotation.Nonnegative; +import javax.annotation.Nullable; /** * Create a new fungible or non-fungible token (NFT) on the Hedera network. @@ -209,7 +205,9 @@ public TokenCreateTransaction() { * records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - TokenCreateTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + TokenCreateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -486,7 +484,7 @@ public Key getPauseKey() { /** * Assign the pause key. * - * @param key the pause key + * @param key the pause key * @return {@code this} */ public TokenCreateTransaction setPauseKey(Key key) { @@ -688,7 +686,7 @@ public TokenSupplyType getSupplyType() { /** * Assign the supply type. * - * @param supplyType the supply type + * @param supplyType the supply type * @return {@code this} */ public TokenCreateTransaction setSupplyType(TokenSupplyType supplyType) { @@ -742,12 +740,10 @@ public TokenCreateTransaction setTokenMetadata(byte[] tokenMetadata) { @Override public TokenCreateTransaction freezeWith(@Nullable Client client) { - if ( - autoRenewPeriod != null && - autoRenewAccountId == null && - client != null && - client.getOperatorAccountId() != null - ) { + if (autoRenewPeriod != null + && autoRenewAccountId == null + && client != null + && client.getOperatorAccountId() != null) { autoRenewAccountId = client.getOperatorAccountId(); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenUpdateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenUpdateTransaction.java index 39a27fba0..792d91ac6 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenUpdateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenUpdateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -31,10 +28,9 @@ import io.grpc.MethodDescriptor; import java.time.Duration; import java.time.Instant; - -import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * A transaction that updates the properties of an existing token. The admin @@ -168,8 +164,7 @@ public class TokenUpdateTransaction extends Transaction /** * Constructor. */ - public TokenUpdateTransaction() { - } + public TokenUpdateTransaction() {} /** * Constructor. @@ -178,7 +173,9 @@ public TokenUpdateTransaction() { * records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - TokenUpdateTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + TokenUpdateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicCreateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicCreateTransaction.java index 73bf7509d..890af8e51 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicCreateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicCreateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; @@ -27,10 +24,9 @@ import com.hedera.hashgraph.sdk.proto.TransactionResponse; import io.grpc.MethodDescriptor; import java.time.Duration; - -import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Create a topic to be used for consensus. @@ -107,7 +103,9 @@ public TopicCreateTransaction() { * records * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ - TopicCreateTransaction(LinkedHashMap> txs) throws InvalidProtocolBufferException { + TopicCreateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicMessage.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicMessage.java index 69bb8f2ef..55efef638 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicMessage.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicMessage.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,19 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.common.base.MoreObjects; import com.google.protobuf.ByteString; import com.hedera.hashgraph.sdk.proto.mirror.ConsensusTopicResponse; -import java.time.Instant; - -import javax.annotation.Nullable; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.List; +import javax.annotation.Nullable; /** * Topic message records. @@ -72,13 +68,12 @@ public final class TopicMessage { * @param transactionId the transaction id */ TopicMessage( - Instant lastConsensusTimestamp, - byte[] message, - byte[] lastRunningHash, - long lastSequenceNumber, - @Nullable TopicMessageChunk[] chunks, - @Nullable TransactionId transactionId - ) { + Instant lastConsensusTimestamp, + byte[] message, + byte[] lastRunningHash, + long lastSequenceNumber, + @Nullable TopicMessageChunk[] chunks, + @Nullable TransactionId transactionId) { this.consensusTimestamp = lastConsensusTimestamp; this.contents = message; this.runningHash = lastRunningHash; @@ -95,15 +90,14 @@ public final class TopicMessage { */ static TopicMessage ofSingle(ConsensusTopicResponse response) { return new TopicMessage( - InstantConverter.fromProtobuf(response.getConsensusTimestamp()), - response.getMessage().toByteArray(), - response.getRunningHash().toByteArray(), - response.getSequenceNumber(), - new TopicMessageChunk[]{new TopicMessageChunk(response)}, - response.hasChunkInfo() && response.getChunkInfo().hasInitialTransactionID() ? - TransactionId.fromProtobuf(response.getChunkInfo().getInitialTransactionID()) : - null - ); + InstantConverter.fromProtobuf(response.getConsensusTimestamp()), + response.getMessage().toByteArray(), + response.getRunningHash().toByteArray(), + response.getSequenceNumber(), + new TopicMessageChunk[] {new TopicMessageChunk(response)}, + response.hasChunkInfo() && response.getChunkInfo().hasInitialTransactionID() + ? TransactionId.fromProtobuf(response.getChunkInfo().getInitialTransactionID()) + : null); } /** @@ -140,22 +134,21 @@ static TopicMessage ofMany(List responses) { var lastReceived = responses.get(responses.size() - 1); return new TopicMessage( - InstantConverter.fromProtobuf(lastReceived.getConsensusTimestamp()), - wholeMessage.array(), - lastReceived.getRunningHash().toByteArray(), - lastReceived.getSequenceNumber(), - chunks, - transactionId - ); + InstantConverter.fromProtobuf(lastReceived.getConsensusTimestamp()), + wholeMessage.array(), + lastReceived.getRunningHash().toByteArray(), + lastReceived.getSequenceNumber(), + chunks, + transactionId); } @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("consensusTimestamp", consensusTimestamp) - .add("contents", new String(contents, StandardCharsets.UTF_8)) - .add("runningHash", runningHash) - .add("sequenceNumber", sequenceNumber) - .toString(); + .add("consensusTimestamp", consensusTimestamp) + .add("contents", new String(contents, StandardCharsets.UTF_8)) + .add("runningHash", runningHash) + .add("sequenceNumber", sequenceNumber) + .toString(); } } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicMessageQuery.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicMessageQuery.java index 6a9b15107..5a28f68b8 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicMessageQuery.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicMessageQuery.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.Timestamp; @@ -184,8 +181,8 @@ private void onComplete() { private void onError(Throwable throwable, TopicMessage topicMessage) { var topicId = TopicId.fromProtobuf(builder.getTopicID()); - if (throwable instanceof StatusRuntimeException sre && sre.getStatus().getCode() - .equals(Status.Code.CANCELLED)) { + if (throwable instanceof StatusRuntimeException sre + && sre.getStatus().getCode().equals(Status.Code.CANCELLED)) { LOGGER.warn("Call is cancelled for topic {}.", topicId); } else { LOGGER.error("Error attempting to subscribe to topic {}:", topicId, throwable); @@ -215,11 +212,12 @@ private boolean shouldRetry(Throwable throwable) { var code = statusRuntimeException.getStatus().getCode(); var description = statusRuntimeException.getStatus().getDescription(); - return (code == Status.Code.NOT_FOUND) || - (code == Status.Code.UNAVAILABLE) || - (code == Status.Code.RESOURCE_EXHAUSTED) || - (code == Status.Code.INTERNAL && description != null && Executable.RST_STREAM.matcher(description) - .matches()); + return (code == Status.Code.NOT_FOUND) + || (code == Status.Code.UNAVAILABLE) + || (code == Status.Code.RESOURCE_EXHAUSTED) + || (code == Status.Code.INTERNAL + && description != null + && Executable.RST_STREAM.matcher(description).matches()); } return false; @@ -238,8 +236,8 @@ public SubscriptionHandle subscribe(Client client, Consumer onNext HashMap> pendingMessages = new HashMap<>(); try { - makeStreamingCall(client, subscriptionHandle, onNext, 0, new AtomicLong(), new AtomicReference<>(), - pendingMessages); + makeStreamingCall( + client, subscriptionHandle, onNext, 0, new AtomicLong(), new AtomicReference<>(), pendingMessages); } catch (InterruptedException e) { throw new RuntimeException(e); } @@ -248,17 +246,18 @@ public SubscriptionHandle subscribe(Client client, Consumer onNext } private void makeStreamingCall( - Client client, - SubscriptionHandle subscriptionHandle, - Consumer onNext, - int attempt, - AtomicLong counter, - AtomicReference lastMessage, - HashMap> pendingMessages - ) throws InterruptedException { + Client client, + SubscriptionHandle subscriptionHandle, + Consumer onNext, + int attempt, + AtomicLong counter, + AtomicReference lastMessage, + HashMap> pendingMessages) + throws InterruptedException { // TODO: check status of channel before using it? - ClientCall call = - client.mirrorNetwork.getNextMirrorNode().getChannel() + ClientCall call = client.mirrorNetwork + .getNextMirrorNode() + .getChannel() .newCall(ConsensusServiceGrpc.getSubscribeTopicMethod(), CallOptions.DEFAULT); subscriptionHandle.setOnUnsubscribe(() -> { @@ -291,7 +290,8 @@ public void onNext(ConsensusTopicResponse consensusTopicResponse) { lastMessage.set(consensusTopicResponse); // Short circuit for no chunks or 1/1 chunks - if (!consensusTopicResponse.hasChunkInfo() || consensusTopicResponse.getChunkInfo().getTotal() == 1) { + if (!consensusTopicResponse.hasChunkInfo() + || consensusTopicResponse.getChunkInfo().getTotal() == 1) { var message = TopicMessage.ofSingle(consensusTopicResponse); try { @@ -338,8 +338,12 @@ public void onError(Throwable t) { var delay = Math.min(500 * (long) Math.pow(2, attempt), maxBackoff.toMillis()); var topicId = TopicId.fromProtobuf(builder.getTopicID()); - LOGGER.warn("Error subscribing to topic {} during attempt #{}. Waiting {} ms before next attempt: {}", - topicId, attempt, delay, t.getMessage()); + LOGGER.warn( + "Error subscribing to topic {} during attempt #{}. Waiting {} ms before next attempt: {}", + topicId, + attempt, + delay, + t.getMessage()); call.cancel("unsubscribed", null); // Cannot use `CompletableFuture` here since this future is never polled @@ -350,8 +354,8 @@ public void onError(Throwable t) { } try { - makeStreamingCall(client, subscriptionHandle, onNext, attempt + 1, counter, lastMessage, - pendingMessages); + makeStreamingCall( + client, subscriptionHandle, onNext, attempt + 1, counter, lastMessage, pendingMessages); } catch (InterruptedException e) { throw new RuntimeException(e); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicUpdateTransaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicUpdateTransaction.java index e8743dc53..e479737e4 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicUpdateTransaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TopicUpdateTransaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; @@ -29,10 +26,9 @@ import io.grpc.MethodDescriptor; import java.time.Duration; import java.time.Instant; - -import javax.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Objects; +import javax.annotation.Nullable; /** * Update a topic. @@ -87,8 +83,7 @@ public final class TopicUpdateTransaction extends Transaction> txs) throws InvalidProtocolBufferException { + TopicUpdateTransaction( + LinkedHashMap> txs) + throws InvalidProtocolBufferException { super(txs); initFromTransactionBody(); } @@ -395,9 +392,7 @@ void validateChecksums(Client client) throws BadEntityIdException { topicId.validateChecksum(client); } - if ((autoRenewAccountId != null) && - !autoRenewAccountId.equals(new AccountId(0)) - ) { + if ((autoRenewAccountId != null) && !autoRenewAccountId.equals(new AccountId(0))) { autoRenewAccountId.validateChecksum(client); } } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Transaction.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Transaction.java index 488ba06f4..4a5fdc983 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Transaction.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Transaction.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -51,8 +48,11 @@ * @param The type of the transaction. Used to enable chaining. */ public abstract class Transaction> - extends - Executable { + extends Executable< + T, + com.hedera.hashgraph.sdk.proto.Transaction, + com.hedera.hashgraph.sdk.proto.TransactionResponse, + TransactionResponse> { /** * Default auto renew duration for accounts, contracts, topics, and files (entities) @@ -67,7 +67,8 @@ public abstract class Transaction> /** * Dummy transaction ID used to assist in deserializing incomplete Transactions. */ - protected static final TransactionId DUMMY_TRANSACTION_ID = TransactionId.withValidStart(DUMMY_ACCOUNT_ID, Instant.EPOCH); + protected static final TransactionId DUMMY_TRANSACTION_ID = + TransactionId.withValidStart(DUMMY_ACCOUNT_ID, Instant.EPOCH); /** * Default transaction duration @@ -99,7 +100,8 @@ public abstract class Transaction> * except pointing to different nodes. When retrying a transaction after a network error or retry-able status * response, we try a different transaction and thus a different node. */ - protected List innerSignedTransactions = Collections.emptyList(); + protected List innerSignedTransactions = + Collections.emptyList(); /** * A set of signatures corresponding to every unique public key used to sign the transaction. @@ -133,9 +135,12 @@ public abstract class Transaction> * Should the transaction id be regenerated */ protected Boolean regenerateTransactionId = null; + private Duration transactionValidDuration; + @Nullable private Hbar maxTransactionFee = null; + private String memo = ""; /** @@ -171,11 +176,14 @@ public abstract class Transaction> * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ Transaction(LinkedHashMap> txs) - throws InvalidProtocolBufferException { - LinkedHashMap transactionMap = txs.values().iterator().next(); - if (!transactionMap.isEmpty() && transactionMap.keySet().iterator().next().equals(DUMMY_ACCOUNT_ID)) { + throws InvalidProtocolBufferException { + LinkedHashMap transactionMap = + txs.values().iterator().next(); + if (!transactionMap.isEmpty() + && transactionMap.keySet().iterator().next().equals(DUMMY_ACCOUNT_ID)) { // If the first account ID is a dummy account ID, then only the source TransactionBody needs to be copied. - var signedTransaction = SignedTransaction.parseFrom(transactionMap.values().iterator().next().getSignedTransactionBytes()); + var signedTransaction = SignedTransaction.parseFrom( + transactionMap.values().iterator().next().getSignedTransactionBytes()); sourceTransactionBody = TransactionBody.parseFrom(signedTransaction.getBodyBytes()); } else { var txCount = txs.keySet().size(); @@ -196,14 +204,16 @@ public abstract class Transaction> nodeAccountIds.add(nodeEntry.getKey()); } - var transaction = SignedTransaction.parseFrom(nodeEntry.getValue().getSignedTransactionBytes()); + var transaction = + SignedTransaction.parseFrom(nodeEntry.getValue().getSignedTransactionBytes()); outerTransactions.add(nodeEntry.getValue()); sigPairLists.add(transaction.getSigMap().toBuilder()); innerSignedTransactions.add(transaction.toBuilder()); if (publicKeys.isEmpty()) { for (var sigPair : transaction.getSigMap().getSigPairList()) { - publicKeys.add(PublicKey.fromBytes(sigPair.getPubKeyPrefix().toByteArray())); + publicKeys.add(PublicKey.fromBytes( + sigPair.getPubKeyPrefix().toByteArray())); signers.add(null); } } @@ -217,24 +227,22 @@ public abstract class Transaction> TransactionBody firstTxBody = null; for (int j = 0; j < nodeCount; j++) { int k = i * nodeCount + j; - var txBody = TransactionBody.parseFrom(innerSignedTransactions.get(k).getBodyBytes()); + var txBody = TransactionBody.parseFrom( + innerSignedTransactions.get(k).getBodyBytes()); if (firstTxBody == null) { firstTxBody = txBody; } else { requireProtoMatches( - firstTxBody, - txBody, - new HashSet<>(List.of("NodeAccountID")), - "TransactionBody" - ); + firstTxBody, txBody, new HashSet<>(List.of("NodeAccountID")), "TransactionBody"); } } } - sourceTransactionBody = TransactionBody.parseFrom(innerSignedTransactions.get(0).getBodyBytes()); + sourceTransactionBody = + TransactionBody.parseFrom(innerSignedTransactions.get(0).getBodyBytes()); } setTransactionValidDuration( - DurationConverter.fromProtobuf(sourceTransactionBody.getTransactionValidDuration())); + DurationConverter.fromProtobuf(sourceTransactionBody.getTransactionValidDuration())); setMaxTransactionFee(Hbar.fromTinybars(sourceTransactionBody.getTransactionFee())); setTransactionMemo(sourceTransactionBody.getMemo()); @@ -252,7 +260,8 @@ public abstract class Transaction> * @throws InvalidProtocolBufferException when there is an issue with the protobuf */ public static Transaction fromBytes(byte[] bytes) throws InvalidProtocolBufferException { - var txs = new LinkedHashMap>(); + var txs = new LinkedHashMap< + TransactionId, LinkedHashMap>(); TransactionBody.DataCase dataCase = TransactionBody.DataCase.DATA_NOT_SET; var list = TransactionList.parseFrom(bytes); @@ -264,13 +273,14 @@ public static Transaction fromBytes(byte[] bytes) throws InvalidProtocolBuffe if (transaction.getSignedTransactionBytes().isEmpty()) { txBody = TransactionBody.parseFrom(transaction.getBodyBytes()); - transaction.setSignedTransactionBytes(SignedTransaction.newBuilder() - .setBodyBytes(transaction.getBodyBytes()) - .setSigMap(transaction.getSigMap()) - .build() - .toByteString()) - .clearBodyBytes() - .clearSigMap(); + transaction + .setSignedTransactionBytes(SignedTransaction.newBuilder() + .setBodyBytes(transaction.getBodyBytes()) + .setSigMap(transaction.getSigMap()) + .build() + .toByteString()) + .clearBodyBytes() + .clearSigMap(); } else { var signedTransaction = SignedTransaction.parseFrom(transaction.getSignedTransactionBytes()); txBody = TransactionBody.parseFrom(signedTransaction.getBodyBytes()); @@ -278,10 +288,11 @@ public static Transaction fromBytes(byte[] bytes) throws InvalidProtocolBuffe dataCase = txBody.getDataCase(); - var account = txBody.hasNodeAccountID() ? AccountId.fromProtobuf(txBody.getNodeAccountID()) - : DUMMY_ACCOUNT_ID; - var transactionId = txBody.hasTransactionID() ? TransactionId.fromProtobuf(txBody.getTransactionID()) - : DUMMY_TRANSACTION_ID; + var account = + txBody.hasNodeAccountID() ? AccountId.fromProtobuf(txBody.getNodeAccountID()) : DUMMY_ACCOUNT_ID; + var transactionId = txBody.hasTransactionID() + ? TransactionId.fromProtobuf(txBody.getTransactionID()) + : DUMMY_TRANSACTION_ID; var linked = new LinkedHashMap(); linked.put(account, transaction.build()); @@ -295,14 +306,16 @@ public static Transaction fromBytes(byte[] bytes) throws InvalidProtocolBuffe dataCase = txBody.getDataCase(); } - var account = txBody.hasNodeAccountID() ? AccountId.fromProtobuf(txBody.getNodeAccountID()) - : DUMMY_ACCOUNT_ID; - var transactionId = txBody.hasTransactionID() ? TransactionId.fromProtobuf(txBody.getTransactionID()) - : DUMMY_TRANSACTION_ID; + var account = txBody.hasNodeAccountID() + ? AccountId.fromProtobuf(txBody.getNodeAccountID()) + : DUMMY_ACCOUNT_ID; + var transactionId = txBody.hasTransactionID() + ? TransactionId.fromProtobuf(txBody.getTransactionID()) + : DUMMY_TRANSACTION_ID; - var linked = txs.containsKey(transactionId) ? - Objects.requireNonNull(txs.get(transactionId)) : - new LinkedHashMap(); + var linked = txs.containsKey(transactionId) + ? Objects.requireNonNull(txs.get(transactionId)) + : new LinkedHashMap(); linked.put(account, transaction); @@ -372,93 +385,125 @@ public static Transaction fromBytes(byte[] bytes) throws InvalidProtocolBuffe * @return the new transaction */ public static Transaction fromScheduledTransaction( - com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody scheduled) { + com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody scheduled) { var body = TransactionBody.newBuilder() - .setMemo(scheduled.getMemo()) - .setTransactionFee(scheduled.getTransactionFee()); + .setMemo(scheduled.getMemo()) + .setTransactionFee(scheduled.getTransactionFee()); return switch (scheduled.getDataCase()) { - case CONTRACTCALL -> - new ContractExecuteTransaction(body.setContractCall(scheduled.getContractCall()).build()); + case CONTRACTCALL -> new ContractExecuteTransaction( + body.setContractCall(scheduled.getContractCall()).build()); case CONTRACTCREATEINSTANCE -> new ContractCreateTransaction( - body.setContractCreateInstance(scheduled.getContractCreateInstance()).build()); + body.setContractCreateInstance(scheduled.getContractCreateInstance()) + .build()); case CONTRACTUPDATEINSTANCE -> new ContractUpdateTransaction( - body.setContractUpdateInstance(scheduled.getContractUpdateInstance()).build()); + body.setContractUpdateInstance(scheduled.getContractUpdateInstance()) + .build()); case CONTRACTDELETEINSTANCE -> new ContractDeleteTransaction( - body.setContractDeleteInstance(scheduled.getContractDeleteInstance()).build()); + body.setContractDeleteInstance(scheduled.getContractDeleteInstance()) + .build()); case CRYPTOAPPROVEALLOWANCE -> new AccountAllowanceApproveTransaction( - body.setCryptoApproveAllowance(scheduled.getCryptoApproveAllowance()).build()); + body.setCryptoApproveAllowance(scheduled.getCryptoApproveAllowance()) + .build()); case CRYPTODELETEALLOWANCE -> new AccountAllowanceDeleteTransaction( - body.setCryptoDeleteAllowance(scheduled.getCryptoDeleteAllowance()).build()); + body.setCryptoDeleteAllowance(scheduled.getCryptoDeleteAllowance()) + .build()); case CRYPTOCREATEACCOUNT -> new AccountCreateTransaction( - body.setCryptoCreateAccount(scheduled.getCryptoCreateAccount()).build()); - case CRYPTODELETE -> - new AccountDeleteTransaction(body.setCryptoDelete(scheduled.getCryptoDelete()).build()); - case CRYPTOTRANSFER -> - new TransferTransaction(body.setCryptoTransfer(scheduled.getCryptoTransfer()).build()); + body.setCryptoCreateAccount(scheduled.getCryptoCreateAccount()) + .build()); + case CRYPTODELETE -> new AccountDeleteTransaction( + body.setCryptoDelete(scheduled.getCryptoDelete()).build()); + case CRYPTOTRANSFER -> new TransferTransaction( + body.setCryptoTransfer(scheduled.getCryptoTransfer()).build()); case CRYPTOUPDATEACCOUNT -> new AccountUpdateTransaction( - body.setCryptoUpdateAccount(scheduled.getCryptoUpdateAccount()).build()); - case FILEAPPEND -> new FileAppendTransaction(body.setFileAppend(scheduled.getFileAppend()).build()); - case FILECREATE -> new FileCreateTransaction(body.setFileCreate(scheduled.getFileCreate()).build()); - case FILEDELETE -> new FileDeleteTransaction(body.setFileDelete(scheduled.getFileDelete()).build()); - case FILEUPDATE -> new FileUpdateTransaction(body.setFileUpdate(scheduled.getFileUpdate()).build()); - case NODECREATE -> new NodeCreateTransaction(body.setNodeCreate(scheduled.getNodeCreate()).build()); - case NODEUPDATE -> new NodeUpdateTransaction(body.setNodeUpdate(scheduled.getNodeUpdate()).build()); - case NODEDELETE -> new NodeDeleteTransaction(body.setNodeDelete(scheduled.getNodeDelete()).build()); - case SYSTEMDELETE -> new SystemDeleteTransaction(body.setSystemDelete(scheduled.getSystemDelete()).build()); - case SYSTEMUNDELETE -> - new SystemUndeleteTransaction(body.setSystemUndelete(scheduled.getSystemUndelete()).build()); - case FREEZE -> new FreezeTransaction(body.setFreeze(scheduled.getFreeze()).build()); + body.setCryptoUpdateAccount(scheduled.getCryptoUpdateAccount()) + .build()); + case FILEAPPEND -> new FileAppendTransaction( + body.setFileAppend(scheduled.getFileAppend()).build()); + case FILECREATE -> new FileCreateTransaction( + body.setFileCreate(scheduled.getFileCreate()).build()); + case FILEDELETE -> new FileDeleteTransaction( + body.setFileDelete(scheduled.getFileDelete()).build()); + case FILEUPDATE -> new FileUpdateTransaction( + body.setFileUpdate(scheduled.getFileUpdate()).build()); + case NODECREATE -> new NodeCreateTransaction( + body.setNodeCreate(scheduled.getNodeCreate()).build()); + case NODEUPDATE -> new NodeUpdateTransaction( + body.setNodeUpdate(scheduled.getNodeUpdate()).build()); + case NODEDELETE -> new NodeDeleteTransaction( + body.setNodeDelete(scheduled.getNodeDelete()).build()); + case SYSTEMDELETE -> new SystemDeleteTransaction( + body.setSystemDelete(scheduled.getSystemDelete()).build()); + case SYSTEMUNDELETE -> new SystemUndeleteTransaction( + body.setSystemUndelete(scheduled.getSystemUndelete()).build()); + case FREEZE -> new FreezeTransaction( + body.setFreeze(scheduled.getFreeze()).build()); case CONSENSUSCREATETOPIC -> new TopicCreateTransaction( - body.setConsensusCreateTopic(scheduled.getConsensusCreateTopic()).build()); + body.setConsensusCreateTopic(scheduled.getConsensusCreateTopic()) + .build()); case CONSENSUSUPDATETOPIC -> new TopicUpdateTransaction( - body.setConsensusUpdateTopic(scheduled.getConsensusUpdateTopic()).build()); + body.setConsensusUpdateTopic(scheduled.getConsensusUpdateTopic()) + .build()); case CONSENSUSDELETETOPIC -> new TopicDeleteTransaction( - body.setConsensusDeleteTopic(scheduled.getConsensusDeleteTopic()).build()); + body.setConsensusDeleteTopic(scheduled.getConsensusDeleteTopic()) + .build()); case CONSENSUSSUBMITMESSAGE -> new TopicMessageSubmitTransaction( - body.setConsensusSubmitMessage(scheduled.getConsensusSubmitMessage()).build()); - case TOKENCREATION -> - new TokenCreateTransaction(body.setTokenCreation(scheduled.getTokenCreation()).build()); - case TOKENFREEZE -> new TokenFreezeTransaction(body.setTokenFreeze(scheduled.getTokenFreeze()).build()); - case TOKENUNFREEZE -> - new TokenUnfreezeTransaction(body.setTokenUnfreeze(scheduled.getTokenUnfreeze()).build()); - case TOKENGRANTKYC -> - new TokenGrantKycTransaction(body.setTokenGrantKyc(scheduled.getTokenGrantKyc()).build()); - case TOKENREVOKEKYC -> - new TokenRevokeKycTransaction(body.setTokenRevokeKyc(scheduled.getTokenRevokeKyc()).build()); - case TOKENDELETION -> - new TokenDeleteTransaction(body.setTokenDeletion(scheduled.getTokenDeletion()).build()); - case TOKENUPDATE -> new TokenUpdateTransaction(body.setTokenUpdate(scheduled.getTokenUpdate()).build()); - case TOKEN_UPDATE_NFTS -> new TokenUpdateNftsTransaction(body.setTokenUpdateNfts(scheduled.getTokenUpdateNfts()).build()); - case TOKENMINT -> new TokenMintTransaction(body.setTokenMint(scheduled.getTokenMint()).build()); - case TOKENBURN -> new TokenBurnTransaction(body.setTokenBurn(scheduled.getTokenBurn()).build()); - case TOKENWIPE -> new TokenWipeTransaction(body.setTokenWipe(scheduled.getTokenWipe()).build()); - case TOKENASSOCIATE -> - new TokenAssociateTransaction(body.setTokenAssociate(scheduled.getTokenAssociate()).build()); - case TOKENDISSOCIATE -> - new TokenDissociateTransaction(body.setTokenDissociate(scheduled.getTokenDissociate()).build()); + body.setConsensusSubmitMessage(scheduled.getConsensusSubmitMessage()) + .build()); + case TOKENCREATION -> new TokenCreateTransaction( + body.setTokenCreation(scheduled.getTokenCreation()).build()); + case TOKENFREEZE -> new TokenFreezeTransaction( + body.setTokenFreeze(scheduled.getTokenFreeze()).build()); + case TOKENUNFREEZE -> new TokenUnfreezeTransaction( + body.setTokenUnfreeze(scheduled.getTokenUnfreeze()).build()); + case TOKENGRANTKYC -> new TokenGrantKycTransaction( + body.setTokenGrantKyc(scheduled.getTokenGrantKyc()).build()); + case TOKENREVOKEKYC -> new TokenRevokeKycTransaction( + body.setTokenRevokeKyc(scheduled.getTokenRevokeKyc()).build()); + case TOKENDELETION -> new TokenDeleteTransaction( + body.setTokenDeletion(scheduled.getTokenDeletion()).build()); + case TOKENUPDATE -> new TokenUpdateTransaction( + body.setTokenUpdate(scheduled.getTokenUpdate()).build()); + case TOKEN_UPDATE_NFTS -> new TokenUpdateNftsTransaction( + body.setTokenUpdateNfts(scheduled.getTokenUpdateNfts()).build()); + case TOKENMINT -> new TokenMintTransaction( + body.setTokenMint(scheduled.getTokenMint()).build()); + case TOKENBURN -> new TokenBurnTransaction( + body.setTokenBurn(scheduled.getTokenBurn()).build()); + case TOKENWIPE -> new TokenWipeTransaction( + body.setTokenWipe(scheduled.getTokenWipe()).build()); + case TOKENASSOCIATE -> new TokenAssociateTransaction( + body.setTokenAssociate(scheduled.getTokenAssociate()).build()); + case TOKENDISSOCIATE -> new TokenDissociateTransaction( + body.setTokenDissociate(scheduled.getTokenDissociate()).build()); case TOKEN_FEE_SCHEDULE_UPDATE -> new TokenFeeScheduleUpdateTransaction( - body.setTokenFeeScheduleUpdate(scheduled.getTokenFeeScheduleUpdate()).build()); - case TOKEN_PAUSE -> new TokenPauseTransaction(body.setTokenPause(scheduled.getTokenPause()).build()); - case TOKEN_UNPAUSE -> - new TokenUnpauseTransaction(body.setTokenUnpause(scheduled.getTokenUnpause()).build()); - case TOKENREJECT -> - new TokenRejectTransaction(body.setTokenReject(scheduled.getTokenReject()).build()); - case TOKENAIRDROP -> new TokenAirdropTransaction(body.setTokenAirdrop(scheduled.getTokenAirdrop()).build()); - case TOKENCANCELAIRDROP -> new TokenCancelAirdropTransaction(body.setTokenCancelAirdrop(scheduled.getTokenCancelAirdrop()).build()); - case TOKENCLAIMAIRDROP -> new TokenClaimAirdropTransaction(body.setTokenCancelAirdrop(scheduled.getTokenCancelAirdrop()).build()); - case SCHEDULEDELETE -> - new ScheduleDeleteTransaction(body.setScheduleDelete(scheduled.getScheduleDelete()).build()); + body.setTokenFeeScheduleUpdate(scheduled.getTokenFeeScheduleUpdate()) + .build()); + case TOKEN_PAUSE -> new TokenPauseTransaction( + body.setTokenPause(scheduled.getTokenPause()).build()); + case TOKEN_UNPAUSE -> new TokenUnpauseTransaction( + body.setTokenUnpause(scheduled.getTokenUnpause()).build()); + case TOKENREJECT -> new TokenRejectTransaction( + body.setTokenReject(scheduled.getTokenReject()).build()); + case TOKENAIRDROP -> new TokenAirdropTransaction( + body.setTokenAirdrop(scheduled.getTokenAirdrop()).build()); + case TOKENCANCELAIRDROP -> new TokenCancelAirdropTransaction( + body.setTokenCancelAirdrop(scheduled.getTokenCancelAirdrop()) + .build()); + case TOKENCLAIMAIRDROP -> new TokenClaimAirdropTransaction( + body.setTokenCancelAirdrop(scheduled.getTokenCancelAirdrop()) + .build()); + case SCHEDULEDELETE -> new ScheduleDeleteTransaction( + body.setScheduleDelete(scheduled.getScheduleDelete()).build()); default -> throw new IllegalStateException("schedulable transaction did not have a transaction set"); }; } private static void throwProtoMatchException(String fieldName, String aWas, String bWas) { - throw new IllegalArgumentException( - "fromBytes() failed because " + fieldName + - " fields in TransactionBody protobuf messages in the TransactionList did not match: A was " + - aWas + ", B was " + bWas - ); + throw new IllegalArgumentException("fromBytes() failed because " + fieldName + + " fields in TransactionBody protobuf messages in the TransactionList did not match: A was " + + aWas + + ", B was " + bWas); } private static void requireProtoMatches(Object protoA, Object protoB, Set ignoreSet, String thisFieldName) { @@ -475,14 +520,13 @@ private static void requireProtoMatches(Object protoA, Object protoB, Set getTransactionHashPerNode() { if (!this.isFrozen()) { throw new IllegalStateException( - "transaction must have been frozen before calculating the hash will be stable, try calling `freeze`"); + "transaction must have been frozen before calculating the hash will be stable, try calling `freeze`"); } buildAllTransactions(); @@ -806,7 +848,9 @@ public Map getTransactionHashPerNode() { var hashes = new HashMap(); for (var i = 0; i < outerTransactions.size(); i++) { - hashes.put(nodeAccountIds.get(i), hash(outerTransactions.get(i).getSignedTransactionBytes().toByteArray())); + hashes.put( + nodeAccountIds.get(i), + hash(outerTransactions.get(i).getSignedTransactionBytes().toByteArray())); } return hashes; @@ -824,7 +868,8 @@ final TransactionId getTransactionIdInternal() { */ public final TransactionId getTransactionId() { if (transactionIds.isEmpty() || !this.isFrozen()) { - throw new IllegalStateException("No transaction ID generated yet. Try freezing the transaction or manually setting the transaction ID."); + throw new IllegalStateException( + "No transaction ID generated yet. Try freezing the transaction or manually setting the transaction ID."); } return transactionIds.setLocked(true).getCurrent(); @@ -922,8 +967,7 @@ public T signWithOperator(Client client) { var operator = client.getOperator(); if (operator == null) { - throw new IllegalStateException( - "`client` must have an `operator` to sign with the operator"); + throw new IllegalStateException("`client` must have an `operator` to sign with the operator"); } if (!isFrozen()) { @@ -982,16 +1026,15 @@ protected Map> getSignaturesAtOffset(int offse var sigMap = sigPairLists.get(i + offset); var nodeAccountId = nodeAccountIds.get(i); - var keyMap = map.containsKey(nodeAccountId) ? - Objects.requireNonNull(map.get(nodeAccountId)) : - new HashMap(sigMap.getSigPairCount()); + var keyMap = map.containsKey(nodeAccountId) + ? Objects.requireNonNull(map.get(nodeAccountId)) + : new HashMap(sigMap.getSigPairCount()); map.put(nodeAccountId, keyMap); for (var sigPair : sigMap.getSigPairList()) { keyMap.put( - PublicKey.fromBytes(sigPair.getPubKeyPrefix().toByteArray()), - sigPair.getEd25519().toByteArray() - ); + PublicKey.fromBytes(sigPair.getPubKeyPrefix().toByteArray()), + sigPair.getEd25519().toByteArray()); } } @@ -1032,7 +1075,7 @@ protected boolean isFrozen() { protected void requireNotFrozen() { if (isFrozen()) { throw new IllegalStateException( - "transaction is immutable; it has at least one signature or has been explicitly frozen"); + "transaction is immutable; it has at least one signature or has been explicitly frozen"); } } @@ -1053,9 +1096,9 @@ protected TransactionBody.Builder spawnBodyBuilder(@Nullable Client client) { var feeHbars = maxTransactionFee != null ? maxTransactionFee : defaultFee; return TransactionBody.newBuilder() - .setTransactionFee(feeHbars.toTinybars()) - .setTransactionValidDuration(DurationConverter.toProtobuf(transactionValidDuration).toBuilder()) - .setMemo(memo); + .setTransactionFee(feeHbars.toTinybars()) + .setTransactionValidDuration(DurationConverter.toProtobuf(transactionValidDuration).toBuilder()) + .setMemo(memo); } /** @@ -1092,19 +1135,18 @@ public T freezeWith(@Nullable Client client) { transactionIds.setList(Collections.singletonList(TransactionId.generate(operator.accountId))); } else { // no client means there must be an explicitly set node ID and transaction ID - throw new IllegalStateException( - "`client` must have an `operator` or `transactionId` must be set"); + throw new IllegalStateException("`client` must have an `operator` or `transactionId` must be set"); } } else { throw new IllegalStateException( - "Transaction ID must be set, or operator must be provided via freezeWith()"); + "Transaction ID must be set, or operator must be provided via freezeWith()"); } } if (nodeAccountIds.isEmpty()) { if (client == null) { throw new IllegalStateException( - "`client` must be provided or both `nodeId` and `transactionId` must be set"); + "`client` must be provided or both `nodeId` and `transactionId` must be set"); } try { @@ -1114,7 +1156,8 @@ public T freezeWith(@Nullable Client client) { } } - frozenBodyBuilder = spawnBodyBuilder(client).setTransactionID(transactionIds.get(0).toProtobuf()); + frozenBodyBuilder = + spawnBodyBuilder(client).setTransactionID(transactionIds.get(0).toProtobuf()); onFreeze(frozenBodyBuilder); int requiredChunks = getRequiredChunks(); @@ -1123,7 +1166,7 @@ public T freezeWith(@Nullable Client client) { var clientDefaultRegenerateTransactionId = client != null ? client.getDefaultRegenerateTransactionId() : null; regenerateTransactionId = - regenerateTransactionId != null ? regenerateTransactionId : clientDefaultRegenerateTransactionId; + regenerateTransactionId != null ? regenerateTransactionId : clientDefaultRegenerateTransactionId; // noinspection unchecked return (T) this; @@ -1176,7 +1219,8 @@ void generateTransactionIds(TransactionId initialTransactionId, int count) { */ void wipeTransactionLists(int requiredChunks) { if (!transactionIds.isEmpty()) { - Objects.requireNonNull(frozenBodyBuilder).setTransactionID(getTransactionIdInternal().toProtobuf()); + Objects.requireNonNull(frozenBodyBuilder) + .setTransactionID(getTransactionIdInternal().toProtobuf()); } outerTransactions = new ArrayList<>(nodeAccountIds.size()); @@ -1186,11 +1230,10 @@ void wipeTransactionLists(int requiredChunks) { for (AccountId nodeId : nodeAccountIds) { sigPairLists.add(SignatureMap.newBuilder()); innerSignedTransactions.add(SignedTransaction.newBuilder() - .setBodyBytes(Objects.requireNonNull(frozenBodyBuilder) - .setNodeAccountID(nodeId.toProtobuf()) - .build() - .toByteString() - )); + .setBodyBytes(Objects.requireNonNull(frozenBodyBuilder) + .setNodeAccountID(nodeId.toProtobuf()) + .build() + .toByteString())); outerTransactions.add(null); } } @@ -1216,22 +1259,22 @@ void buildAllTransactions() { void buildTransaction(int index) { // Check if transaction is already built. // Every time a signer is added via sign() or signWith(), all outerTransactions are nullified. - if ( - outerTransactions.get(index) != null && - !outerTransactions.get(index).getSignedTransactionBytes().isEmpty() - ) { + if (outerTransactions.get(index) != null + && !outerTransactions.get(index).getSignedTransactionBytes().isEmpty()) { return; } signTransaction(index); - outerTransactions.set(index, com.hedera.hashgraph.sdk.proto.Transaction.newBuilder() - .setSignedTransactionBytes( - innerSignedTransactions.get(index) - .setSigMap(sigPairLists.get(index)) - .build() - .toByteString() - ).build()); + outerTransactions.set( + index, + com.hedera.hashgraph.sdk.proto.Transaction.newBuilder() + .setSignedTransactionBytes(innerSignedTransactions + .get(index) + .setSigMap(sigPairLists.get(index)) + .build() + .toByteString()) + .build()); } /** @@ -1254,9 +1297,7 @@ void signTransaction(int index) { var signatureBytes = signers.get(i).apply(bodyBytes); - sigPairLists - .get(index) - .addSigPair(publicKeys.get(i).toSignaturePairProtobuf(signatureBytes)); + sigPairLists.get(index).addSigPair(publicKeys.get(i).toSignaturePairProtobuf(signatureBytes)); } } @@ -1282,10 +1323,9 @@ final com.hedera.hashgraph.sdk.proto.Transaction makeRequest() { @Override TransactionResponse mapResponse( - com.hedera.hashgraph.sdk.proto.TransactionResponse transactionResponse, - AccountId nodeId, - com.hedera.hashgraph.sdk.proto.Transaction request - ) { + com.hedera.hashgraph.sdk.proto.TransactionResponse transactionResponse, + AccountId nodeId, + com.hedera.hashgraph.sdk.proto.Transaction request) { var transactionId = Objects.requireNonNull(getTransactionIdInternal()); var hash = hash(request.getSignedTransactionBytes().toByteArray()); transactionIds.advance(); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java index abcbb4938..9d7a2fc13 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionId.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static java.util.concurrent.CompletableFuture.completedFuture; @@ -70,7 +67,6 @@ public final class TransactionId implements Comparable { private static final AtomicLong monotonicTime = new AtomicLong(); - /** * No longer part of the public API. Use `Transaction.withValidStart()` instead. * @@ -136,11 +132,13 @@ public static TransactionId generate(AccountId accountId) { */ static TransactionId fromProtobuf(TransactionID transactionID) { var accountId = transactionID.hasAccountID() ? AccountId.fromProtobuf(transactionID.getAccountID()) : null; - var validStart = transactionID.hasTransactionValidStart() ? InstantConverter.fromProtobuf(transactionID.getTransactionValidStart()) : null; + var validStart = transactionID.hasTransactionValidStart() + ? InstantConverter.fromProtobuf(transactionID.getTransactionValidStart()) + : null; return new TransactionId(accountId, validStart) - .setScheduled(transactionID.getScheduled()) - .setNonce((transactionID.getNonce() != 0) ? transactionID.getNonce() : null); + .setScheduled(transactionID.getScheduled()) + .setNonce((transactionID.getNonce() != 0) ? transactionID.getNonce() : null); } /** @@ -172,9 +170,9 @@ public static TransactionId fromString(String s) { throw new IllegalArgumentException("expecting {account}@{seconds}.{nanos}"); } - @Nullable Instant validStart = Instant.ofEpochSecond( - Long.parseLong(validStartParts[0]), - Long.parseLong(validStartParts[1])); + @Nullable + Instant validStart = + Instant.ofEpochSecond(Long.parseLong(validStartParts[0]), Long.parseLong(validStartParts[1])); return new TransactionId(accountId, validStart).setScheduled(scheduled).setNonce(nonce); } @@ -240,7 +238,8 @@ public TransactionId setNonce(@Nullable Integer nonce) { * @throws PrecheckStatusException when the precheck fails * @throws ReceiptStatusException when there is an issue with the receipt */ - public TransactionReceipt getReceipt(Client client) throws TimeoutException, PrecheckStatusException, ReceiptStatusException { + public TransactionReceipt getReceipt(Client client) + throws TimeoutException, PrecheckStatusException, ReceiptStatusException { return getReceipt(client, client.getRequestTimeout()); } @@ -254,10 +253,9 @@ public TransactionReceipt getReceipt(Client client) throws TimeoutException, Pre * @throws PrecheckStatusException when the precheck fails * @throws ReceiptStatusException when there is an issue with the receipt */ - public TransactionReceipt getReceipt(Client client, Duration timeout) throws TimeoutException, PrecheckStatusException, ReceiptStatusException { - var receipt = new TransactionReceiptQuery() - .setTransactionId(this) - .execute(client, timeout); + public TransactionReceipt getReceipt(Client client, Duration timeout) + throws TimeoutException, PrecheckStatusException, ReceiptStatusException { + var receipt = new TransactionReceiptQuery().setTransactionId(this).execute(client, timeout); if (receipt.status != Status.SUCCESS) { throw new ReceiptStatusException(this, receipt); @@ -285,15 +283,15 @@ public CompletableFuture getReceiptAsync(Client client) { */ public CompletableFuture getReceiptAsync(Client client, Duration timeout) { return new TransactionReceiptQuery() - .setTransactionId(this) - .executeAsync(client, timeout) - .thenCompose(receipt -> { - if (receipt.status != Status.SUCCESS) { - return failedFuture(new ReceiptStatusException(this, receipt)); - } + .setTransactionId(this) + .executeAsync(client, timeout) + .thenCompose(receipt -> { + if (receipt.status != Status.SUCCESS) { + return failedFuture(new ReceiptStatusException(this, receipt)); + } - return completedFuture(receipt); - }); + return completedFuture(receipt); + }); } /** @@ -336,7 +334,8 @@ public void getReceiptAsync(Client client, Consumer onSucces * @param onSuccess a Consumer which consumes the result on success. * @param onFailure a Consumer which consumes the error on failure. */ - public void getReceiptAsync(Client client, Duration timeout, Consumer onSuccess, Consumer onFailure) { + public void getReceiptAsync( + Client client, Duration timeout, Consumer onSuccess, Consumer onFailure) { ConsumerHelper.twoConsumers(getReceiptAsync(client, timeout), onSuccess, onFailure); } @@ -349,7 +348,8 @@ public void getReceiptAsync(Client client, Duration timeout, Consumer getRecordAsync(Client client) { */ public CompletableFuture getRecordAsync(Client client, Duration timeout) { // note: we get the receipt first to ensure consensus has been reached - return getReceiptAsync(client, timeout).thenCompose(receipt -> new TransactionRecordQuery() - .setTransactionId(this) - .executeAsync(client, timeout)); + return getReceiptAsync(client, timeout) + .thenCompose(receipt -> + new TransactionRecordQuery().setTransactionId(this).executeAsync(client, timeout)); } /** @@ -435,7 +434,8 @@ public void getRecordAsync(Client client, Consumer onSuccess, * @param onSuccess a Consumer which consumes the result on success. * @param onFailure a Consumer which consumes the error on failure. */ - public void getRecordAsync(Client client, Duration timeout, Consumer onSuccess, Consumer onFailure) { + public void getRecordAsync( + Client client, Duration timeout, Consumer onSuccess, Consumer onFailure) { ConsumerHelper.twoConsumers(getRecordAsync(client, timeout), onSuccess, onFailure); } @@ -445,9 +445,7 @@ public void getRecordAsync(Client client, Duration timeout, Consumer tx.deleteTokenNftAllowanceAllSerials(testTokenId, testOwnerAccountId, testSpenderAccountId)); + assertThrows( + IllegalStateException.class, + () -> tx.deleteTokenNftAllowanceAllSerials(testTokenId, testOwnerAccountId, testSpenderAccountId)); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountAllowanceDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountAllowanceDeleteTransactionTest.java index d8f21eab6..82e46a599 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountAllowanceDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountAllowanceDeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.CryptoDeleteAllowanceTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class AccountAllowanceDeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -50,17 +46,17 @@ public static void afterAll() { AccountAllowanceDeleteTransaction spawnTestTransaction() { var ownerId = AccountId.fromString("5.6.7"); return new AccountAllowanceDeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .deleteAllHbarAllowances(ownerId) - .deleteAllTokenAllowances(TokenId.fromString("2.2.2"), ownerId) - .deleteAllTokenNftAllowances(TokenId.fromString("4.4.4").nft(123), ownerId) - .deleteAllTokenNftAllowances(TokenId.fromString("4.4.4").nft(456), ownerId) - .deleteAllTokenNftAllowances(TokenId.fromString("8.8.8").nft(456), ownerId) - .deleteAllTokenNftAllowances(TokenId.fromString("4.4.4").nft(789), ownerId) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .deleteAllHbarAllowances(ownerId) + .deleteAllTokenAllowances(TokenId.fromString("2.2.2"), ownerId) + .deleteAllTokenNftAllowances(TokenId.fromString("4.4.4").nft(123), ownerId) + .deleteAllTokenNftAllowances(TokenId.fromString("4.4.4").nft(456), ownerId) + .deleteAllTokenNftAllowances(TokenId.fromString("8.8.8").nft(456), ownerId) + .deleteAllTokenNftAllowances(TokenId.fromString("4.4.4").nft(789), ownerId) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -78,8 +74,9 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setCryptoDeleteAllowance(CryptoDeleteAllowanceTransactionBody.newBuilder().build()) - .build(); + .setCryptoDeleteAllowance( + CryptoDeleteAllowanceTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountBalanceQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountBalanceQueryTest.java index b43763872..f313b6709 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountBalanceQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountBalanceQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,17 +37,19 @@ public static void afterAll() { void shouldSerializeWithAccountId() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new AccountBalanceQuery() - .setAccountId(AccountId.fromString("0.0.5005")) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setAccountId(AccountId.fromString("0.0.5005")) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test void shouldSerializeWithContractId() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new AccountBalanceQuery() - .setContractId(ContractId.fromString("0.0.5005")) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setContractId(ContractId.fromString("0.0.5005")) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountCreateTransactionTest.java index a997f9b3c..4cb7b9bc8 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountCreateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountCreateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +12,25 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.CryptoCreateTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Duration; import java.time.Instant; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class AccountCreateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -50,37 +46,37 @@ public static void afterAll() { AccountCreateTransaction spawnTestTransaction() { return new AccountCreateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setKey(unusedPrivateKey) - .setInitialBalance(Hbar.fromTinybars(450)) - .setProxyAccountId(AccountId.fromString("0.0.1001")) - .setAccountMemo("some dumb memo") - .setReceiverSignatureRequired(true) - .setAutoRenewPeriod(Duration.ofHours(10)) - .setStakedAccountId(AccountId.fromString("0.0.3")) - .setAlias("0x5c562e90feaf0eebd33ea75d21024f249d451417") - .setMaxAutomaticTokenAssociations(100) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setKey(unusedPrivateKey) + .setInitialBalance(Hbar.fromTinybars(450)) + .setProxyAccountId(AccountId.fromString("0.0.1001")) + .setAccountMemo("some dumb memo") + .setReceiverSignatureRequired(true) + .setAutoRenewPeriod(Duration.ofHours(10)) + .setStakedAccountId(AccountId.fromString("0.0.3")) + .setAlias("0x5c562e90feaf0eebd33ea75d21024f249d451417") + .setMaxAutomaticTokenAssociations(100) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } AccountCreateTransaction spawnTestTransaction2() { return new AccountCreateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setKey(unusedPrivateKey) - .setInitialBalance(Hbar.fromTinybars(450)) - .setProxyAccountId(AccountId.fromString("0.0.1001")) - .setAccountMemo("some dumb memo") - .setReceiverSignatureRequired(true) - .setAutoRenewPeriod(Duration.ofHours(10)) - .setStakedNodeId(4L) - .setMaxAutomaticTokenAssociations(100) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setKey(unusedPrivateKey) + .setInitialBalance(Hbar.fromTinybars(450)) + .setProxyAccountId(AccountId.fromString("0.0.1001")) + .setAccountMemo("some dumb memo") + .setReceiverSignatureRequired(true) + .setAutoRenewPeriod(Duration.ofHours(10)) + .setStakedNodeId(4L) + .setMaxAutomaticTokenAssociations(100) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -127,8 +123,8 @@ void propertiesTest() { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setCryptoCreateAccount(CryptoCreateTransactionBody.newBuilder().build()) - .build(); + .setCryptoCreateAccount(CryptoCreateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountDeleteTransactionTest.java index a9ad9c4e3..94f67112c 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountDeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.CryptoDeleteTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class AccountDeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,20 +45,18 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private AccountDeleteTransaction spawnTestTransaction() { return new AccountDeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(AccountId.fromString("0.0.5007")) - .setTransferAccountId(AccountId.fromString("0.0.5008")) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(AccountId.fromString("0.0.5007")) + .setTransferAccountId(AccountId.fromString("0.0.5008")) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -75,10 +69,10 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setCryptoDelete( - CryptoDeleteTransactionBody.newBuilder() - .setDeleteAccountID(AccountId.fromString("6.6.6").toProtobuf()).build()) - .build(); + .setCryptoDelete(CryptoDeleteTransactionBody.newBuilder() + .setDeleteAccountID(AccountId.fromString("6.6.6").toProtobuf()) + .build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountIdTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountIdTest.java index 12e242ebb..1082c8f93 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountIdTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountIdTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,22 +12,21 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.google.protobuf.InvalidProtocolBufferException; import io.github.jsonSnapshot.SnapshotMatcher; +import java.util.concurrent.TimeoutException; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.concurrent.TimeoutException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - class AccountIdTest { static Client mainnetClient; @@ -60,17 +56,20 @@ void fromString() { @Test void fromStringWithChecksumOnMainnet() { - SnapshotMatcher.expect(AccountId.fromString("0.0.123-vfmkw").toStringWithChecksum(mainnetClient)).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromString("0.0.123-vfmkw").toStringWithChecksum(mainnetClient)) + .toMatchSnapshot(); } @Test void fromStringWithChecksumOnTestnet() { - SnapshotMatcher.expect(AccountId.fromString("0.0.123-esxsf").toStringWithChecksum(testnetClient)).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromString("0.0.123-esxsf").toStringWithChecksum(testnetClient)) + .toMatchSnapshot(); } @Test void fromStringWithChecksumOnPreviewnet() { - SnapshotMatcher.expect(AccountId.fromString("0.0.123-ogizo").toStringWithChecksum(previewnetClient)).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromString("0.0.123-ogizo").toStringWithChecksum(previewnetClient)) + .toMatchSnapshot(); } @Test @@ -119,62 +118,82 @@ void malformedIdChecksum2() { @Test void malformedAliasKey() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { - AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf777"); + AccountId.fromString( + "0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf777"); }); } @Test void malformedAliasKey2() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { - AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf777g"); + AccountId.fromString( + "0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf777g"); }); } @Test void malformedAliasKey3() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { - AccountId.fromString("0.0.303a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777"); + AccountId.fromString( + "0.0.303a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777"); }); } @Test void fromStringWithAliasKey() { - SnapshotMatcher.expect(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromString( + "0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777") + .toString()) + .toMatchSnapshot(); } @Test void fromStringWithEvmAddress() { - SnapshotMatcher.expect(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82da").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82da") + .toString()) + .toMatchSnapshot(); } @Test void fromSolidityAddress() { - SnapshotMatcher.expect(AccountId.fromSolidityAddress("000000000000000000000000000000000000138D").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromSolidityAddress("000000000000000000000000000000000000138D") + .toString()) + .toMatchSnapshot(); } @Test void fromSolidityAddressWith0x() { - SnapshotMatcher.expect(AccountId.fromSolidityAddress("0x000000000000000000000000000000000000138D").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromSolidityAddress("0x000000000000000000000000000000000000138D") + .toString()) + .toMatchSnapshot(); } @Test void toBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(Hex.toHexString(new AccountId(5005).toProtobuf().toByteArray())).toMatchSnapshot(); + SnapshotMatcher.expect(Hex.toHexString(new AccountId(5005).toProtobuf().toByteArray())) + .toMatchSnapshot(); } @Test void toBytesAlias() { - SnapshotMatcher.expect(Hex.toHexString(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777").toBytes())).toMatchSnapshot(); + SnapshotMatcher.expect(Hex.toHexString(AccountId.fromString( + "0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777") + .toBytes())) + .toMatchSnapshot(); } @Test void toBytesEvmAddress() { - SnapshotMatcher.expect(Hex.toHexString(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82da").toBytes())).toMatchSnapshot(); + SnapshotMatcher.expect(Hex.toHexString(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82da") + .toBytes())) + .toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(AccountId.fromBytes(new AccountId(5005).toBytes()).toString()).toMatchSnapshot(); + SnapshotMatcher.expect( + AccountId.fromBytes(new AccountId(5005).toBytes()).toString()) + .toMatchSnapshot(); } @Test @@ -186,26 +205,35 @@ void toFromProtobuf() { @Test void fromBytesAlias() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(AccountId.fromBytes(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777").toBytes()).toString()).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromBytes(AccountId.fromString( + "0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777") + .toBytes()) + .toString()) + .toMatchSnapshot(); } @Test void toFromProtobufAliasKey() { - var id1 = AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777"); + var id1 = AccountId.fromString( + "0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777"); var id2 = AccountId.fromProtobuf(id1.toProtobuf()); assertThat(id2).isEqualTo(id1); } @Test void toFromProtobufEcdsaAliasKey() { - var id1 = AccountId.fromString("0.0.302d300706052b8104000a032200035d348292bbb8b511fdbe24e3217ec099944b4728999d337f9a025f4193324525"); + var id1 = AccountId.fromString( + "0.0.302d300706052b8104000a032200035d348292bbb8b511fdbe24e3217ec099944b4728999d337f9a025f4193324525"); var id2 = AccountId.fromProtobuf(id1.toProtobuf()); assertThat(id2).isEqualTo(id1); } @Test void fromBytesEvmAddress() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(AccountId.fromBytes(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82da").toBytes()).toString()).toMatchSnapshot(); + SnapshotMatcher.expect(AccountId.fromBytes(AccountId.fromString("0.0.302a300506032b6570032100114e6abc371b82da") + .toBytes()) + .toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountInfoQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountInfoQueryTest.java index 4a74a3528..2e4bb59ae 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountInfoQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountInfoQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,9 +37,10 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new AccountInfoQuery() - .setAccountId(AccountId.fromString("0.0.5005")) - .setMaxQueryPayment(Hbar.fromTinybars(100_000)) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setAccountId(AccountId.fromString("0.0.5005")) + .setMaxQueryPayment(Hbar.fromTinybars(100_000)) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountInfoTest.java index 2500af52a..bbff25c62 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountInfoTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -25,38 +22,38 @@ import com.hedera.hashgraph.sdk.proto.KeyList; import com.hedera.hashgraph.sdk.proto.LiveHash; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Duration; +import java.time.Instant; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Duration; -import java.time.Instant; - public class AccountInfoTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final byte[] hash = {0, 1, 2}; - private static final LiveHash liveHash = LiveHash.newBuilder().setAccountId(new AccountId(10).toProtobuf()) - .setDuration(DurationConverter.toProtobuf(Duration.ofDays(11))) - .setHash(ByteString.copyFrom(hash)) - .setKeys(KeyList.newBuilder().addKeys(privateKey.getPublicKey().toProtobufKey())) - .build(); + private static final LiveHash liveHash = LiveHash.newBuilder() + .setAccountId(new AccountId(10).toProtobuf()) + .setDuration(DurationConverter.toProtobuf(Duration.ofDays(11))) + .setHash(ByteString.copyFrom(hash)) + .setKeys(KeyList.newBuilder().addKeys(privateKey.getPublicKey().toProtobufKey())) + .build(); private static final CryptoGetInfoResponse.AccountInfo info = CryptoGetInfoResponse.AccountInfo.newBuilder() - .setAccountID(new AccountId(1).toProtobuf()) - .setDeleted(true) - .setProxyReceived(2) - .setKey(privateKey.getPublicKey().toProtobufKey()) - .setBalance(3) - .setGenerateSendRecordThreshold(4) - .setGenerateReceiveRecordThreshold(5) - .setReceiverSigRequired(true) - .setExpirationTime(InstantConverter.toProtobuf(Instant.ofEpochMilli(6))) - .setAutoRenewPeriod(DurationConverter.toProtobuf(Duration.ofDays(7))) - .setProxyAccountID(new AccountId(8).toProtobuf()) - .addLiveHashes(liveHash) - .setLedgerId(LedgerId.PREVIEWNET.toByteString()) - .setEthereumNonce(1001) - .build(); + .setAccountID(new AccountId(1).toProtobuf()) + .setDeleted(true) + .setProxyReceived(2) + .setKey(privateKey.getPublicKey().toProtobufKey()) + .setBalance(3) + .setGenerateSendRecordThreshold(4) + .setGenerateReceiveRecordThreshold(5) + .setReceiverSigRequired(true) + .setExpirationTime(InstantConverter.toProtobuf(Instant.ofEpochMilli(6))) + .setAutoRenewPeriod(DurationConverter.toProtobuf(Duration.ofDays(7))) + .setProxyAccountID(new AccountId(8).toProtobuf()) + .addLiveHashes(liveHash) + .setLedgerId(LedgerId.PREVIEWNET.toByteString()) + .setEthereumNonce(1001) + .build(); @BeforeAll public static void beforeAll() { @@ -70,25 +67,24 @@ public static void afterAll() { @Test void fromProtobufWithOtherOptions() { - SnapshotMatcher.expect(AccountInfo.fromProtobuf(info).toString()) - .toMatchSnapshot(); + SnapshotMatcher.expect(AccountInfo.fromProtobuf(info).toString()).toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { SnapshotMatcher.expect(AccountInfo.fromBytes(info.toByteArray()).toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void toBytes() throws InvalidProtocolBufferException { SnapshotMatcher.expect(AccountInfo.fromBytes(info.toByteArray()).toBytes()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void toProtobuf() throws InvalidProtocolBufferException { SnapshotMatcher.expect(AccountInfo.fromProtobuf(info).toProtobuf().toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountRecordsQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountRecordsQueryTest.java index 5e2d4366e..52c9b0704 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountRecordsQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountRecordsQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,9 +37,10 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new AccountRecordsQuery() - .setAccountId(AccountId.fromString("0.0.5005")) - .setMaxQueryPayment(Hbar.fromTinybars(100_000)) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setAccountId(AccountId.fromString("0.0.5005")) + .setMaxQueryPayment(Hbar.fromTinybars(100_000)) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountStakersQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountStakersQueryTest.java index 2015b2e3c..571878c0c 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountStakersQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountStakersQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,9 +37,10 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new AccountStakersQuery() - .setAccountId(AccountId.fromString("0.0.5005")) - .setMaxQueryPayment(Hbar.fromTinybars(100_000)) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setAccountId(AccountId.fromString("0.0.5005")) + .setMaxQueryPayment(Hbar.fromTinybars(100_000)) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountUpdateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountUpdateTransactionTest.java index 06af2f055..c836e6167 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountUpdateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AccountUpdateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +12,25 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.CryptoUpdateTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Duration; import java.time.Instant; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class AccountUpdateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -50,38 +46,38 @@ public static void afterAll() { AccountUpdateTransaction spawnTestTransaction() { return new AccountUpdateTransaction() - .setKey(unusedPrivateKey) - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(AccountId.fromString("0.0.2002")) - .setProxyAccountId(AccountId.fromString("0.0.1001")) - .setAutoRenewPeriod(Duration.ofHours(10)) - .setExpirationTime(Instant.ofEpochSecond(1554158543)) - .setReceiverSignatureRequired(false) - .setMaxAutomaticTokenAssociations(100) - .setAccountMemo("Some memo") - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setStakedAccountId(AccountId.fromString("0.0.3")) - .freeze() - .sign(unusedPrivateKey); + .setKey(unusedPrivateKey) + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(AccountId.fromString("0.0.2002")) + .setProxyAccountId(AccountId.fromString("0.0.1001")) + .setAutoRenewPeriod(Duration.ofHours(10)) + .setExpirationTime(Instant.ofEpochSecond(1554158543)) + .setReceiverSignatureRequired(false) + .setMaxAutomaticTokenAssociations(100) + .setAccountMemo("Some memo") + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setStakedAccountId(AccountId.fromString("0.0.3")) + .freeze() + .sign(unusedPrivateKey); } AccountUpdateTransaction spawnTestTransaction2() { return new AccountUpdateTransaction() - .setKey(unusedPrivateKey) - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(AccountId.fromString("0.0.2002")) - .setProxyAccountId(AccountId.fromString("0.0.1001")) - .setAutoRenewPeriod(Duration.ofHours(10)) - .setExpirationTime(Instant.ofEpochSecond(1554158543)) - .setReceiverSignatureRequired(false) - .setMaxAutomaticTokenAssociations(100) - .setAccountMemo("Some memo") - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setStakedNodeId(4L) - .freeze() - .sign(unusedPrivateKey); + .setKey(unusedPrivateKey) + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(AccountId.fromString("0.0.2002")) + .setProxyAccountId(AccountId.fromString("0.0.1001")) + .setAutoRenewPeriod(Duration.ofHours(10)) + .setExpirationTime(Instant.ofEpochSecond(1554158543)) + .setReceiverSignatureRequired(false) + .setMaxAutomaticTokenAssociations(100) + .setAccountMemo("Some memo") + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setStakedNodeId(4L) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -111,8 +107,8 @@ void shouldBytes2() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setCryptoUpdateAccount(CryptoUpdateTransactionBody.newBuilder().build()) - .build(); + .setCryptoUpdateAccount(CryptoUpdateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AllowancesTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AllowancesTest.java index 11b235320..26f23237b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AllowancesTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AllowancesTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.InvalidProtocolBufferException; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.util.ArrayList; import java.util.Collections; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class AllowancesTest { @BeforeAll @@ -44,11 +40,7 @@ public static void afterAll() { TokenAllowance spawnTokenAllowance() { return new TokenAllowance( - TokenId.fromString("1.2.3"), - AccountId.fromString("4.5.6"), - AccountId.fromString("5.5.5"), - 777 - ); + TokenId.fromString("1.2.3"), AccountId.fromString("4.5.6"), AccountId.fromString("5.5.5"), 777); } TokenNftAllowance spawnNftAllowance() { @@ -56,24 +48,22 @@ TokenNftAllowance spawnNftAllowance() { serials.add(123L); serials.add(456L); return new TokenNftAllowance( - TokenId.fromString("1.1.1"), - AccountId.fromString("2.2.2"), - AccountId.fromString("3.3.3"), - null, - serials, - null - ); + TokenId.fromString("1.1.1"), + AccountId.fromString("2.2.2"), + AccountId.fromString("3.3.3"), + null, + serials, + null); } TokenNftAllowance spawnAllNftAllowance() { return new TokenNftAllowance( - TokenId.fromString("1.1.1"), - AccountId.fromString("2.2.2"), - AccountId.fromString("3.3.3"), - null, - Collections.emptyList(), - true - ); + TokenId.fromString("1.1.1"), + AccountId.fromString("2.2.2"), + AccountId.fromString("3.3.3"), + null, + Collections.emptyList(), + true); } HbarAllowance spawnHbarAllowance() { @@ -83,11 +73,11 @@ HbarAllowance spawnHbarAllowance() { @Test void shouldSerialize() { SnapshotMatcher.expect( - spawnHbarAllowance().toString(), - spawnTokenAllowance().toString(), - spawnNftAllowance().toString(), - spawnAllNftAllowance().toString() - ).toMatchSnapshot(); + spawnHbarAllowance().toString(), + spawnTokenAllowance().toString(), + spawnNftAllowance().toString(), + spawnAllNftAllowance().toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/AssessedCustomFeeTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/AssessedCustomFeeTest.java index d111a21bd..01c310909 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/AssessedCustomFeeTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/AssessedCustomFeeTest.java @@ -1,32 +1,45 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; +import java.util.List; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - public class AssessedCustomFeeTest { private static final int amount = 1; private static final TokenId tokenId = new TokenId(2, 3, 4); private static final AccountId feeCollector = new AccountId(5, 6, 7); - private static final List payerAccountIds = List.of( - new AccountId(8, 9, 10), - new AccountId(11, 12, 13), - new AccountId(14, 15, 16) - ); + private static final List payerAccountIds = + List.of(new AccountId(8, 9, 10), new AccountId(11, 12, 13), new AccountId(14, 15, 16)); private final com.hedera.hashgraph.sdk.proto.AssessedCustomFee fee = - com.hedera.hashgraph.sdk.proto.AssessedCustomFee.newBuilder() - .setAmount(amount) - .setTokenId(tokenId.toProtobuf()) - .setFeeCollectorAccountId(feeCollector.toProtobuf()) - .addAllEffectivePayerAccountId(payerAccountIds.stream().map(AccountId::toProtobuf).toList()) - .build(); + com.hedera.hashgraph.sdk.proto.AssessedCustomFee.newBuilder() + .setAmount(amount) + .setTokenId(tokenId.toProtobuf()) + .setFeeCollectorAccountId(feeCollector.toProtobuf()) + .addAllEffectivePayerAccountId( + payerAccountIds.stream().map(AccountId::toProtobuf).toList()) + .build(); @BeforeAll public static void beforeAll() { @@ -40,15 +53,10 @@ public static void afterAll() { AssessedCustomFee spawnAssessedCustomFeeExample() { return new AssessedCustomFee( - 201, - TokenId.fromString("1.2.3"), - AccountId.fromString("4.5.6"), - List.of( - AccountId.fromString("0.0.1"), - AccountId.fromString("0.0.2"), - AccountId.fromString("0.0.3") - ) - ); + 201, + TokenId.fromString("1.2.3"), + AccountId.fromString("4.5.6"), + List.of(AccountId.fromString("0.0.1"), AccountId.fromString("0.0.2"), AccountId.fromString("0.0.3"))); } @Test @@ -57,8 +65,9 @@ void shouldSerialize() throws Exception { byte[] assessedCustomFeeBytes = originalAssessedCustomFee.toBytes(); var copyAssessedCustomFee = AssessedCustomFee.fromBytes(assessedCustomFeeBytes); assertThat(originalAssessedCustomFee.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(copyAssessedCustomFee.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalAssessedCustomFee.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(copyAssessedCustomFee.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalAssessedCustomFee.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test @@ -68,7 +77,8 @@ void fromProtobuf() { @Test void toProtobuf() { - SnapshotMatcher.expect(AssessedCustomFee.fromProtobuf(fee).toProtobuf().toString()).toMatchSnapshot(); + SnapshotMatcher.expect(AssessedCustomFee.fromProtobuf(fee).toProtobuf().toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractByteCodeQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractByteCodeQueryTest.java index 514cd9243..41ab9af60 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractByteCodeQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractByteCodeQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,8 +37,9 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new ContractByteCodeQuery() - .setContractId(ContractId.fromString("0.0.5005")) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setContractId(ContractId.fromString("0.0.5005")) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractCallQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractCallQueryTest.java index 7e1e33cb0..846a827d7 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractCallQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractCallQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; - public class ContractCallQueryTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -47,31 +43,31 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new ContractCallQuery() - .setContractId(ContractId.fromString("0.0.5005")) - .setGas(1541) - .setSenderAccountId(AccountId.fromString("1.2.3")) - .setFunction("foo", - new ContractFunctionParameters() - .addString("Hello") - .addString("world!")) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setContractId(ContractId.fromString("0.0.5005")) + .setGas(1541) + .setSenderAccountId(AccountId.fromString("1.2.3")) + .setFunction( + "foo", + new ContractFunctionParameters().addString("Hello").addString("world!")) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test void setFunctionParameters() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new ContractCallQuery() - .setContractId(ContractId.fromString("0.0.5005")) - .setGas(1541) - .setSenderAccountId(AccountId.fromString("1.2.3")) - .setFunctionParameters( - new ContractFunctionParameters() - .addString("Hello") - .addString("world!") - .toBytes(null) - .toByteArray()) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setContractId(ContractId.fromString("0.0.5005")) + .setGas(1541) + .setSenderAccountId(AccountId.fromString("1.2.3")) + .setFunctionParameters(new ContractFunctionParameters() + .addString("Hello") + .addString("world!") + .toBytes(null) + .toByteArray()) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractCreateTransactionTest.java index d044aa21b..fb2cac9fd 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractCreateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractCreateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,27 +12,26 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.ContractCreateTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Duration; +import java.time.Instant; +import java.util.Arrays; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Duration; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class ContractCreateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -51,52 +47,48 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } @Test void shouldSerialize2() { - SnapshotMatcher.expect(spawnTestTransaction2() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction2().toString()).toMatchSnapshot(); } private ContractCreateTransaction spawnTestTransaction() { return new ContractCreateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setBytecodeFileId(FileId.fromString("0.0.3003")) - .setAdminKey(unusedPrivateKey) - .setGas(0) - .setInitialBalance(Hbar.fromTinybars(1000)) - .setStakedAccountId(AccountId.fromString("0.0.3")) - .setMaxAutomaticTokenAssociations(101) - .setAutoRenewPeriod(Duration.ofHours(10)) - .setConstructorParameters(new byte[]{10, 11, 12, 13, 25}) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setAutoRenewAccountId(new AccountId(30)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setBytecodeFileId(FileId.fromString("0.0.3003")) + .setAdminKey(unusedPrivateKey) + .setGas(0) + .setInitialBalance(Hbar.fromTinybars(1000)) + .setStakedAccountId(AccountId.fromString("0.0.3")) + .setMaxAutomaticTokenAssociations(101) + .setAutoRenewPeriod(Duration.ofHours(10)) + .setConstructorParameters(new byte[] {10, 11, 12, 13, 25}) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setAutoRenewAccountId(new AccountId(30)) + .freeze() + .sign(unusedPrivateKey); } private ContractCreateTransaction spawnTestTransaction2() { return new ContractCreateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setBytecode(Hex.decode("deadbeef")) - .setAdminKey(unusedPrivateKey) - .setGas(0) - .setInitialBalance(Hbar.fromTinybars(1000)) - .setStakedNodeId(4L) - .setMaxAutomaticTokenAssociations(101) - .setAutoRenewPeriod(Duration.ofHours(10)) - .setConstructorParameters(new byte[]{10, 11, 12, 13, 25}) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setAutoRenewAccountId(new AccountId(30)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setBytecode(Hex.decode("deadbeef")) + .setAdminKey(unusedPrivateKey) + .setGas(0) + .setInitialBalance(Hbar.fromTinybars(1000)) + .setStakedNodeId(4L) + .setMaxAutomaticTokenAssociations(101) + .setAutoRenewPeriod(Duration.ofHours(10)) + .setConstructorParameters(new byte[] {10, 11, 12, 13, 25}) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setAutoRenewAccountId(new AccountId(30)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -116,8 +108,9 @@ void shouldBytes2() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setContractCreateInstance(ContractCreateTransactionBody.newBuilder().build()) - .build(); + .setContractCreateInstance( + ContractCreateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractDeleteTransactionTest.java index 841be3025..fd1978a30 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractDeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.ContractDeleteTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class ContractDeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,21 +45,19 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private ContractDeleteTransaction spawnTestTransaction() { return new ContractDeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setContractId(ContractId.fromString("0.0.5007")) - .setTransferAccountId(new AccountId(9)) - .setTransferContractId(ContractId.fromString("0.0.5008")) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setContractId(ContractId.fromString("0.0.5007")) + .setTransferAccountId(new AccountId(9)) + .setTransferContractId(ContractId.fromString("0.0.5008")) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -76,8 +70,9 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setContractDeleteInstance(ContractDeleteTransactionBody.newBuilder().build()) - .build(); + .setContractDeleteInstance( + ContractDeleteTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractExecuteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractExecuteTransactionTest.java index 7912f01c4..53613d9e1 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractExecuteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractExecuteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +12,25 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.ByteString; import com.hedera.hashgraph.sdk.proto.ContractCallTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class ContractExecuteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -50,22 +46,20 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private ContractExecuteTransaction spawnTestTransaction() { return new ContractExecuteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setContractId(ContractId.fromString("0.0.5007")) - .setGas(10) - .setPayableAmount(Hbar.fromTinybars(1000)) - .setFunctionParameters(ByteString.copyFrom(new byte[]{24, 43, 11})) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setContractId(ContractId.fromString("0.0.5007")) + .setGas(10) + .setPayableAmount(Hbar.fromTinybars(1000)) + .setFunctionParameters(ByteString.copyFrom(new byte[] {24, 43, 11})) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -78,8 +72,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setContractCall(ContractCallTransactionBody.newBuilder().build()) - .build(); + .setContractCall(ContractCallTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractFunctionParametersTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractFunctionParametersTest.java index aee579651..a00f5684b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractFunctionParametersTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractFunctionParametersTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +12,21 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.google.protobuf.ByteString; import io.github.jsonSnapshot.SnapshotMatcher; +import java.lang.reflect.Array; +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -31,16 +37,6 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.lang.reflect.Array; -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - public class ContractFunctionParametersTest { @BeforeAll public static void beforeAll() { @@ -55,139 +51,132 @@ public static void afterAll() { @SuppressWarnings("unused") private static List int256Arguments() { return List.of( - Arguments.of(0, "0000000000000000000000000000000000000000000000000000000000000000"), - Arguments.of(2, "0000000000000000000000000000000000000000000000000000000000000002"), - Arguments.of(255, "00000000000000000000000000000000000000000000000000000000000000ff"), - Arguments.of(4095, "0000000000000000000000000000000000000000000000000000000000000fff"), - Arguments.of(127 << 24, "000000000000000000000000000000000000000000000000000000007f000000"), - Arguments.of(2047 << 20, "000000000000000000000000000000000000000000000000000000007ff00000"), - // deadbeef as an integer literal is negative - Arguments.of(0xdeadbeefL, "00000000000000000000000000000000000000000000000000000000deadbeef"), - Arguments.of(-1, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), - Arguments.of(-2, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"), - Arguments.of(-256, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00"), - Arguments.of(-4096, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000"), - Arguments.of(255 << 24, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000"), - Arguments.of(4095 << 20, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000"), - Arguments.of(0xdeadbeef, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffdeadbeef") - ); + Arguments.of(0, "0000000000000000000000000000000000000000000000000000000000000000"), + Arguments.of(2, "0000000000000000000000000000000000000000000000000000000000000002"), + Arguments.of(255, "00000000000000000000000000000000000000000000000000000000000000ff"), + Arguments.of(4095, "0000000000000000000000000000000000000000000000000000000000000fff"), + Arguments.of(127 << 24, "000000000000000000000000000000000000000000000000000000007f000000"), + Arguments.of(2047 << 20, "000000000000000000000000000000000000000000000000000000007ff00000"), + // deadbeef as an integer literal is negative + Arguments.of(0xdeadbeefL, "00000000000000000000000000000000000000000000000000000000deadbeef"), + Arguments.of(-1, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + Arguments.of(-2, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"), + Arguments.of(-256, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00"), + Arguments.of(-4096, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000"), + Arguments.of(255 << 24, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000"), + Arguments.of(4095 << 20, "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000"), + Arguments.of(0xdeadbeef, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffdeadbeef")); } @SuppressWarnings("unused") private static List uInt256Arguments() { return List.of( - Arguments.of(0, "0000000000000000000000000000000000000000000000000000000000000000", 8), - Arguments.of(2, "0000000000000000000000000000000000000000000000000000000000000002", 8), - Arguments.of(255, "00000000000000000000000000000000000000000000000000000000000000ff", 8), - Arguments.of(4095, "0000000000000000000000000000000000000000000000000000000000000fff", 32), - Arguments.of(127 << 24, "000000000000000000000000000000000000000000000000000000007f000000", 32), - Arguments.of(2047 << 20, "000000000000000000000000000000000000000000000000000000007ff00000", 32), - // deadbeef as an integer literal is negative - Arguments.of(0xdeadbeef, "00000000000000000000000000000000000000000000000000000000deadbeef", 32), - Arguments.of(-1, "000000000000000000000000000000000000000000000000ffffffffffffffff", 64), - Arguments.of(-2, "000000000000000000000000000000000000000000000000fffffffffffffffe", 64), - Arguments.of(-256, "000000000000000000000000000000000000000000000000ffffffffffffff00", 64), - Arguments.of(-4096, "000000000000000000000000000000000000000000000000fffffffffffff000", 64), - Arguments.of(255 << 24, "000000000000000000000000000000000000000000000000ffffffffff000000", 64), - Arguments.of(4095 << 20, "000000000000000000000000000000000000000000000000fffffffffff00000", 64), - Arguments.of(0xdeadbeefL, "00000000000000000000000000000000000000000000000000000000deadbeef", 64) - ); + Arguments.of(0, "0000000000000000000000000000000000000000000000000000000000000000", 8), + Arguments.of(2, "0000000000000000000000000000000000000000000000000000000000000002", 8), + Arguments.of(255, "00000000000000000000000000000000000000000000000000000000000000ff", 8), + Arguments.of(4095, "0000000000000000000000000000000000000000000000000000000000000fff", 32), + Arguments.of(127 << 24, "000000000000000000000000000000000000000000000000000000007f000000", 32), + Arguments.of(2047 << 20, "000000000000000000000000000000000000000000000000000000007ff00000", 32), + // deadbeef as an integer literal is negative + Arguments.of(0xdeadbeef, "00000000000000000000000000000000000000000000000000000000deadbeef", 32), + Arguments.of(-1, "000000000000000000000000000000000000000000000000ffffffffffffffff", 64), + Arguments.of(-2, "000000000000000000000000000000000000000000000000fffffffffffffffe", 64), + Arguments.of(-256, "000000000000000000000000000000000000000000000000ffffffffffffff00", 64), + Arguments.of(-4096, "000000000000000000000000000000000000000000000000fffffffffffff000", 64), + Arguments.of(255 << 24, "000000000000000000000000000000000000000000000000ffffffffff000000", 64), + Arguments.of(4095 << 20, "000000000000000000000000000000000000000000000000fffffffffff00000", 64), + Arguments.of(0xdeadbeefL, "00000000000000000000000000000000000000000000000000000000deadbeef", 64)); } @Test @DisplayName("encodes int types correctly") void intTypes() { ContractFunctionParameters params = new ContractFunctionParameters() - .addUint8((byte) 0x1) - .addInt8((byte) -0x2) - .addUint32(0x3) - .addInt32(-0x4) - .addUint64(0x4) - .addInt64(-0x5) - .addUint256(BigInteger.valueOf(0x6)) - .addInt256(BigInteger.valueOf(-0x7)) - .addUint8Array(new byte[]{(byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4}) - .addInt8Array(new byte[]{(byte) -0x5, (byte) 0x6, (byte) 0x7, (byte) -0x8}) - .addUint32Array(new int[]{0x9, 0xA, 0xB, 0xC}) - .addInt32Array(new int[]{-0xD, 0xE, 0xF, -0x10}) - .addUint64Array(new long[]{0x11, 0x12, 0x13, 0x14}) - .addInt64Array(new long[]{-0x15, 0x16, 0x17, -0x18}) - .addUint256Array(new BigInteger[]{BigInteger.valueOf(0x19)}) - .addInt256Array(new BigInteger[]{BigInteger.valueOf(-0x1A)}); - - assertThat( - "11bcd903" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb" + - "0000000000000000000000000000000000000000000000000000000000000006" + - "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9" + - "0000000000000000000000000000000000000000000000000000000000000200" + - "00000000000000000000000000000000000000000000000000000000000002a0" + - "0000000000000000000000000000000000000000000000000000000000000340" + - "00000000000000000000000000000000000000000000000000000000000003e0" + - "0000000000000000000000000000000000000000000000000000000000000480" + - "0000000000000000000000000000000000000000000000000000000000000520" + - "00000000000000000000000000000000000000000000000000000000000005c0" + - "0000000000000000000000000000000000000000000000000000000000000600" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb" + - "0000000000000000000000000000000000000000000000000000000000000006" + - "0000000000000000000000000000000000000000000000000000000000000007" + - "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "0000000000000000000000000000000000000000000000000000000000000009" + - "000000000000000000000000000000000000000000000000000000000000000a" + - "000000000000000000000000000000000000000000000000000000000000000b" + - "000000000000000000000000000000000000000000000000000000000000000c" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff3" + - "000000000000000000000000000000000000000000000000000000000000000e" + - "000000000000000000000000000000000000000000000000000000000000000f" + - "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "0000000000000000000000000000000000000000000000000000000000000011" + - "0000000000000000000000000000000000000000000000000000000000000012" + - "0000000000000000000000000000000000000000000000000000000000000013" + - "0000000000000000000000000000000000000000000000000000000000000014" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeb" + - "0000000000000000000000000000000000000000000000000000000000000016" + - "0000000000000000000000000000000000000000000000000000000000000017" + - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000000000000000000000000000000000000000000019" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6" - ).isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); + .addUint8((byte) 0x1) + .addInt8((byte) -0x2) + .addUint32(0x3) + .addInt32(-0x4) + .addUint64(0x4) + .addInt64(-0x5) + .addUint256(BigInteger.valueOf(0x6)) + .addInt256(BigInteger.valueOf(-0x7)) + .addUint8Array(new byte[] {(byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4}) + .addInt8Array(new byte[] {(byte) -0x5, (byte) 0x6, (byte) 0x7, (byte) -0x8}) + .addUint32Array(new int[] {0x9, 0xA, 0xB, 0xC}) + .addInt32Array(new int[] {-0xD, 0xE, 0xF, -0x10}) + .addUint64Array(new long[] {0x11, 0x12, 0x13, 0x14}) + .addInt64Array(new long[] {-0x15, 0x16, 0x17, -0x18}) + .addUint256Array(new BigInteger[] {BigInteger.valueOf(0x19)}) + .addInt256Array(new BigInteger[] {BigInteger.valueOf(-0x1A)}); + + assertThat("11bcd903" + "0000000000000000000000000000000000000000000000000000000000000001" + + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + + "0000000000000000000000000000000000000000000000000000000000000003" + + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb" + + "0000000000000000000000000000000000000000000000000000000000000006" + + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9" + + "0000000000000000000000000000000000000000000000000000000000000200" + + "00000000000000000000000000000000000000000000000000000000000002a0" + + "0000000000000000000000000000000000000000000000000000000000000340" + + "00000000000000000000000000000000000000000000000000000000000003e0" + + "0000000000000000000000000000000000000000000000000000000000000480" + + "0000000000000000000000000000000000000000000000000000000000000520" + + "00000000000000000000000000000000000000000000000000000000000005c0" + + "0000000000000000000000000000000000000000000000000000000000000600" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000003" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb" + + "0000000000000000000000000000000000000000000000000000000000000006" + + "0000000000000000000000000000000000000000000000000000000000000007" + + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "0000000000000000000000000000000000000000000000000000000000000009" + + "000000000000000000000000000000000000000000000000000000000000000a" + + "000000000000000000000000000000000000000000000000000000000000000b" + + "000000000000000000000000000000000000000000000000000000000000000c" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff3" + + "000000000000000000000000000000000000000000000000000000000000000e" + + "000000000000000000000000000000000000000000000000000000000000000f" + + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "0000000000000000000000000000000000000000000000000000000000000011" + + "0000000000000000000000000000000000000000000000000000000000000012" + + "0000000000000000000000000000000000000000000000000000000000000013" + + "0000000000000000000000000000000000000000000000000000000000000014" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeb" + + "0000000000000000000000000000000000000000000000000000000000000016" + + "0000000000000000000000000000000000000000000000000000000000000017" + + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000019" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6") + .isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); } @Test @DisplayName("uint256 chops off sign bit if length is 256 bits") void uint256BitLength() { var params = new ContractFunctionParameters() - .addUint256(BigInteger.valueOf(2).pow(255)); + .addUint256(BigInteger.valueOf(2).pow(255)); - assertThat( - "2fbebd38" + - "8000000000000000000000000000000000000000000000000000000000000000" - ).isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); + assertThat("2fbebd38" + "8000000000000000000000000000000000000000000000000000000000000000") + .isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); } @Test @DisplayName("uint256 errors if less than 0") void uint256Errors() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { - new ContractFunctionParameters() - .addUint256(BigInteger.valueOf(-0x1)); + new ContractFunctionParameters().addUint256(BigInteger.valueOf(-0x1)); }); /* @@ -202,27 +191,26 @@ void uint256Errors() { @DisplayName("encodes addresses correctly") void addresses() { var params = new ContractFunctionParameters() - .addAddress("1122334455667788990011223344556677889900") - .addAddress("0x1122334455667788990011223344556677889900") - .addAddressArray(new String[]{"1122334455667788990011223344556677889900", "1122334455667788990011223344556677889900"}); - - assertThat( - "7d48c86d" + - "0000000000000000000000001122334455667788990011223344556677889900" + - "0000000000000000000000001122334455667788990011223344556677889900" + - "0000000000000000000000000000000000000000000000000000000000000060" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001122334455667788990011223344556677889900" + - "0000000000000000000000001122334455667788990011223344556677889900" - ).isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); + .addAddress("1122334455667788990011223344556677889900") + .addAddress("0x1122334455667788990011223344556677889900") + .addAddressArray(new String[] { + "1122334455667788990011223344556677889900", "1122334455667788990011223344556677889900" + }); + + assertThat("7d48c86d" + "0000000000000000000000001122334455667788990011223344556677889900" + + "0000000000000000000000001122334455667788990011223344556677889900" + + "0000000000000000000000000000000000000000000000000000000000000060" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000001122334455667788990011223344556677889900" + + "0000000000000000000000001122334455667788990011223344556677889900") + .isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); } @Test @DisplayName("encodes functions correctly") void addressesError() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { - new ContractFunctionParameters() - .addAddress("112233445566778899001122334455667788990011"); + new ContractFunctionParameters().addAddress("112233445566778899001122334455667788990011"); }); } @@ -230,14 +218,14 @@ void addressesError() { @DisplayName("encodes functions correctly") void functions() { var params = new ContractFunctionParameters() - .addFunction("1122334455667788990011223344556677889900", new byte[]{1, 2, 3, 4}) - .addFunction("0x1122334455667788990011223344556677889900", new ContractFunctionSelector("randomFunction").addBool()); - - assertThat( - "c99c40cd" + - "1122334455667788990011223344556677889900010203040000000000000000" + - "112233445566778899001122334455667788990063441d820000000000000000" - ).isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); + .addFunction("1122334455667788990011223344556677889900", new byte[] {1, 2, 3, 4}) + .addFunction( + "0x1122334455667788990011223344556677889900", + new ContractFunctionSelector("randomFunction").addBool()); + + assertThat("c99c40cd" + "1122334455667788990011223344556677889900010203040000000000000000" + + "112233445566778899001122334455667788990063441d820000000000000000") + .isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); } @Test @@ -245,169 +233,153 @@ void functions() { void functionsError() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { new ContractFunctionParameters() - .addFunction("112233445566778899001122334455667788990011", new byte[]{1, 2, 3, 4}); + .addFunction("112233445566778899001122334455667788990011", new byte[] {1, 2, 3, 4}); }); assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { new ContractFunctionParameters() - .addFunction("1122334455667788990011223344556677889900", new byte[]{1, 2, 3, 4, 5}); + .addFunction("1122334455667788990011223344556677889900", new byte[] {1, 2, 3, 4, 5}); }); } @Test @DisplayName("encodes bytes32 correctly") void bytes() { - var params = new ContractFunctionParameters() - .addBytes32(new byte[]{ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 - }); + var params = new ContractFunctionParameters().addBytes32(new byte[] { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 + }); - assertThat( - "11e814c1" + - "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20" - ).isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); + assertThat("11e814c1" + "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20") + .isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); } @Test @DisplayName("fails to encode bytes32 if length too long") void bytesError() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { - new ContractFunctionParameters() - .addBytes32(new byte[]{ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33 - }); - } - ); + new ContractFunctionParameters().addBytes32(new byte[] { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33 + }); + }); } @Test @DisplayName("encodes boolean correctly") void bool() { - var params = new ContractFunctionParameters() - .addBool(true) - .addBool(false); + var params = new ContractFunctionParameters().addBool(true).addBool(false); - assertThat( - "b3cedfcf" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000000000000000000000000000000000000000000000" - ).isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); + assertThat("b3cedfcf" + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000000") + .isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); } @Test @DisplayName("encodes dynamic params correctly") void dynamicParamsEncoding() { - ByteString paramsStringArg = new ContractFunctionParameters() - .addString("Hello, world!") - .toBytes("set_message"); + ByteString paramsStringArg = + new ContractFunctionParameters().addString("Hello, world!").toBytes("set_message"); ByteString paramsBytesArg = new ContractFunctionParameters() - .addBytes("Hello, world!".getBytes(StandardCharsets.UTF_8)) - .toBytes("set_message"); + .addBytes("Hello, world!".getBytes(StandardCharsets.UTF_8)) + .toBytes("set_message"); String paramsStringArgHex = Hex.toHexString(paramsStringArg.toByteArray()); String paramsBytesArgHex = Hex.toHexString(paramsBytesArg.toByteArray()); - assertThat( - "2e982602" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "000000000000000000000000000000000000000000000000000000000000000d" - + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000" - ).isEqualTo(paramsStringArgHex); + assertThat("2e982602" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "000000000000000000000000000000000000000000000000000000000000000d" + + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000") + .isEqualTo(paramsStringArgHex); // signature should encode differently but the contents are identical - assertThat( - "010473a7" - + "0000000000000000000000000000000000000000000000000000000000000020" - + "000000000000000000000000000000000000000000000000000000000000000d" - + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000" - ).isEqualTo(paramsBytesArgHex); + assertThat("010473a7" + + "0000000000000000000000000000000000000000000000000000000000000020" + + "000000000000000000000000000000000000000000000000000000000000000d" + + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000") + .isEqualTo(paramsBytesArgHex); } @Test @DisplayName("encodes static params correctly") void staticParamsEncoding() { ContractFunctionParameters params = new ContractFunctionParameters() - .addInt32(0x11223344) - .addInt32(-65536) - .addUint64(-65536) - .addAddress("00112233445566778899aabbccddeeff00112233"); + .addInt32(0x11223344) + .addInt32(-65536) + .addUint64(-65536) + .addAddress("00112233445566778899aabbccddeeff00112233"); String paramsHex = Hex.toHexString(params.toBytes(null).toByteArray()); - assertThat( - "0000000000000000000000000000000000000000000000000000000011223344" - // sign-extended - + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000" - // zero-padded - + "000000000000000000000000000000000000000000000000ffffffffffff0000" - + "00000000000000000000000000112233445566778899aabbccddeeff00112233" - ).isEqualTo(paramsHex); + assertThat("0000000000000000000000000000000000000000000000000000000011223344" + // sign-extended + + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000" + // zero-padded + + "000000000000000000000000000000000000000000000000ffffffffffff0000" + + "00000000000000000000000000112233445566778899aabbccddeeff00112233") + .isEqualTo(paramsHex); } @Test @DisplayName("encodes mixed static and dynamic params correctly") void mixedParamsEncoding() { ContractFunctionParameters params = new ContractFunctionParameters() - .addInt256(BigInteger.valueOf(0xdeadbeef).shiftLeft(8)) - .addString("Hello, world!") - .addBytes(new byte[]{-1, -18, 63, 127}) - .addBool(true) - .addUint8Array(new byte[]{-1, 127}); + .addInt256(BigInteger.valueOf(0xdeadbeef).shiftLeft(8)) + .addString("Hello, world!") + .addBytes(new byte[] {-1, -18, 63, 127}) + .addBool(true) + .addUint8Array(new byte[] {-1, 127}); String paramsHex = Hex.toHexString(params.toBytes("foo").toByteArray()); - assertThat( - "6a5bb8f2" - + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffdeadbeef00" - + "00000000000000000000000000000000000000000000000000000000000000a0" - + "00000000000000000000000000000000000000000000000000000000000000e0" - + "0000000000000000000000000000000000000000000000000000000000000001" - + "0000000000000000000000000000000000000000000000000000000000000120" - + "000000000000000000000000000000000000000000000000000000000000000d" - + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000004" - + "ffee3f7f00000000000000000000000000000000000000000000000000000000" - + "0000000000000000000000000000000000000000000000000000000000000002" - + "00000000000000000000000000000000000000000000000000000000000000ff" - + "000000000000000000000000000000000000000000000000000000000000007f" - ).isEqualTo(paramsHex); + assertThat("6a5bb8f2" + + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffdeadbeef00" + + "00000000000000000000000000000000000000000000000000000000000000a0" + + "00000000000000000000000000000000000000000000000000000000000000e0" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000000120" + + "000000000000000000000000000000000000000000000000000000000000000d" + + "48656c6c6f2c20776f726c642100000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "ffee3f7f00000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "00000000000000000000000000000000000000000000000000000000000000ff" + + "000000000000000000000000000000000000000000000000000000000000007f") + .isEqualTo(paramsHex); } @Test @DisplayName("encodes array types correctly") void arrayTypesEncoding() { ContractFunctionParameters params = new ContractFunctionParameters() - .addStringArray(new String[]{"hello", ",", "world!"}) - .addInt32Array(new int[]{0x88, 0x99, 0xAA, 0xBB}) - .addInt256Array(new BigInteger[]{BigInteger.valueOf(0x1111)}); - - assertThat( - "025838fc" + - "0000000000000000000000000000000000000000000000000000000000000060" + - "00000000000000000000000000000000000000000000000000000000000001a0" + - "0000000000000000000000000000000000000000000000000000000000000240" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "0000000000000000000000000000000000000000000000000000000000000060" + - "00000000000000000000000000000000000000000000000000000000000000a0" + - "00000000000000000000000000000000000000000000000000000000000000e0" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "2c00000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000006" + - "776f726c64210000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "0000000000000000000000000000000000000000000000000000000000000088" + - "0000000000000000000000000000000000000000000000000000000000000099" + - "00000000000000000000000000000000000000000000000000000000000000aa" + - "00000000000000000000000000000000000000000000000000000000000000bb" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000000000000000000000000000000000000000001111" - ).isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); + .addStringArray(new String[] {"hello", ",", "world!"}) + .addInt32Array(new int[] {0x88, 0x99, 0xAA, 0xBB}) + .addInt256Array(new BigInteger[] {BigInteger.valueOf(0x1111)}); + + assertThat("025838fc" + "0000000000000000000000000000000000000000000000000000000000000060" + + "00000000000000000000000000000000000000000000000000000000000001a0" + + "0000000000000000000000000000000000000000000000000000000000000240" + + "0000000000000000000000000000000000000000000000000000000000000003" + + "0000000000000000000000000000000000000000000000000000000000000060" + + "00000000000000000000000000000000000000000000000000000000000000a0" + + "00000000000000000000000000000000000000000000000000000000000000e0" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "2c00000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000006" + + "776f726c64210000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000004" + + "0000000000000000000000000000000000000000000000000000000000000088" + + "0000000000000000000000000000000000000000000000000000000000000099" + + "00000000000000000000000000000000000000000000000000000000000000aa" + + "00000000000000000000000000000000000000000000000000000000000000bb" + + "0000000000000000000000000000000000000000000000000000000000000001" + + "0000000000000000000000000000000000000000000000000000000000001111") + .isEqualTo(Hex.toHexString(params.toBytes("foo").toByteArray())); } @Test @@ -415,67 +387,92 @@ void arrayTypesEncoding() { void fixedBytesArrayEncoding() { // each string should be padded to 32 bytes and have no length prefix - ContractFunctionParameters params = new ContractFunctionParameters() - .addBytes32Array(new byte[][]{ - "Hello".getBytes(StandardCharsets.UTF_8), - ",".getBytes(StandardCharsets.UTF_8), - "world!".getBytes(StandardCharsets.UTF_8) - }); + ContractFunctionParameters params = new ContractFunctionParameters().addBytes32Array(new byte[][] { + "Hello".getBytes(StandardCharsets.UTF_8), + ",".getBytes(StandardCharsets.UTF_8), + "world!".getBytes(StandardCharsets.UTF_8) + }); assertThat( - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000003" + // length of array - "48656c6c6f000000000000000000000000000000000000000000000000000000" + // "Hello" UTF-8 encoded - "2c00000000000000000000000000000000000000000000000000000000000000" + // "," UTF-8 encoded - "776f726c64210000000000000000000000000000000000000000000000000000" // "world!" UTF-8 encoded - ).isEqualTo(Hex.toHexString(params.toBytes(null).toByteArray())); + "0000000000000000000000000000000000000000000000000000000000000020" + + "0000000000000000000000000000000000000000000000000000000000000003" + + // length of array + "48656c6c6f000000000000000000000000000000000000000000000000000000" + + // "Hello" UTF-8 encoded + "2c00000000000000000000000000000000000000000000000000000000000000" + + // "," UTF-8 encoded + "776f726c64210000000000000000000000000000000000000000000000000000" // "world!" UTF-8 + // encoded + ) + .isEqualTo(Hex.toHexString(params.toBytes(null).toByteArray())); } @Test @DisplayName("bytes[] encodes correctly") void dynBytesArrayEncoding() { // result should be the exact same as the strings test below - ContractFunctionParameters params = new ContractFunctionParameters() - .addBytesArray(new byte[][]{ - "Hello".getBytes(StandardCharsets.UTF_8), - ",".getBytes(StandardCharsets.UTF_8), - "world!".getBytes(StandardCharsets.UTF_8) - }); + ContractFunctionParameters params = new ContractFunctionParameters().addBytesArray(new byte[][] { + "Hello".getBytes(StandardCharsets.UTF_8), + ",".getBytes(StandardCharsets.UTF_8), + "world!".getBytes(StandardCharsets.UTF_8) + }); assertThat( - "0000000000000000000000000000000000000000000000000000000000000020" + // offset to array - "0000000000000000000000000000000000000000000000000000000000000003" + // length of array - "0000000000000000000000000000000000000000000000000000000000000060" + // first element offset, relative to beginning of this list (after length) - "00000000000000000000000000000000000000000000000000000000000000a0" + // second element offset - "00000000000000000000000000000000000000000000000000000000000000e0" + // third element offset - "0000000000000000000000000000000000000000000000000000000000000005" + // "Hello".length - "48656c6c6f000000000000000000000000000000000000000000000000000000" + // "Hello" UTF-8 encoded - "0000000000000000000000000000000000000000000000000000000000000001" + // ",".length - "2c00000000000000000000000000000000000000000000000000000000000000" + // "," UTF-8 encoded - "0000000000000000000000000000000000000000000000000000000000000006" + // "world!".length - "776f726c64210000000000000000000000000000000000000000000000000000" // "world!" UTF-8 encoded - ).isEqualTo(Hex.toHexString(params.toBytes(null).toByteArray())); + "0000000000000000000000000000000000000000000000000000000000000020" + // offset to array + "0000000000000000000000000000000000000000000000000000000000000003" + + // length of array + "0000000000000000000000000000000000000000000000000000000000000060" + + // first element offset, relative to beginning of this list (after length) + "00000000000000000000000000000000000000000000000000000000000000a0" + + // second element offset + "00000000000000000000000000000000000000000000000000000000000000e0" + + // third element offset + "0000000000000000000000000000000000000000000000000000000000000005" + + // "Hello".length + "48656c6c6f000000000000000000000000000000000000000000000000000000" + + // "Hello" UTF-8 encoded + "0000000000000000000000000000000000000000000000000000000000000001" + + // ",".length + "2c00000000000000000000000000000000000000000000000000000000000000" + + // "," UTF-8 encoded + "0000000000000000000000000000000000000000000000000000000000000006" + + // "world!".length + "776f726c64210000000000000000000000000000000000000000000000000000" // "world!" UTF-8 + // encoded + ) + .isEqualTo(Hex.toHexString(params.toBytes(null).toByteArray())); } @Test @DisplayName("issue 376: string[] encodes correctly") void stringArrayEncoding() { - ContractFunctionParameters params = new ContractFunctionParameters() - .addStringArray(new String[]{"Hello", ",", "world!"}); + ContractFunctionParameters params = + new ContractFunctionParameters().addStringArray(new String[] {"Hello", ",", "world!"}); assertThat( - "0000000000000000000000000000000000000000000000000000000000000020" + // offset to array - "0000000000000000000000000000000000000000000000000000000000000003" + // length of array - "0000000000000000000000000000000000000000000000000000000000000060" + // first element offset, relative to beginning of this list (after length) - "00000000000000000000000000000000000000000000000000000000000000a0" + // second element offset - "00000000000000000000000000000000000000000000000000000000000000e0" + // third element offset - "0000000000000000000000000000000000000000000000000000000000000005" + // "Hello".length - "48656c6c6f000000000000000000000000000000000000000000000000000000" + // "Hello" UTF-8 encoded - "0000000000000000000000000000000000000000000000000000000000000001" + // ",".length - "2c00000000000000000000000000000000000000000000000000000000000000" + // "," UTF-8 encoded - "0000000000000000000000000000000000000000000000000000000000000006" + // "world!".length - "776f726c64210000000000000000000000000000000000000000000000000000" // "world!" UTF-8 encoded - ).isEqualTo(Hex.toHexString(params.toBytes(null).toByteArray())); + "0000000000000000000000000000000000000000000000000000000000000020" + // offset to array + "0000000000000000000000000000000000000000000000000000000000000003" + + // length of array + "0000000000000000000000000000000000000000000000000000000000000060" + + // first element offset, relative to beginning of this list (after length) + "00000000000000000000000000000000000000000000000000000000000000a0" + + // second element offset + "00000000000000000000000000000000000000000000000000000000000000e0" + + // third element offset + "0000000000000000000000000000000000000000000000000000000000000005" + + // "Hello".length + "48656c6c6f000000000000000000000000000000000000000000000000000000" + + // "Hello" UTF-8 encoded + "0000000000000000000000000000000000000000000000000000000000000001" + + // ",".length + "2c00000000000000000000000000000000000000000000000000000000000000" + + // "," UTF-8 encoded + "0000000000000000000000000000000000000000000000000000000000000006" + + // "world!".length + "776f726c64210000000000000000000000000000000000000000000000000000" // "world!" UTF-8 + // encoded + ) + .isEqualTo(Hex.toHexString(params.toBytes(null).toByteArray())); } @Test @@ -490,13 +487,13 @@ void bigIntChecks() { String rangeErr = "BigInteger out of range for Solidity integers"; - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> params.addInt256(BigInteger.ONE.shiftLeft(255)) - ).satisfies(error -> assertThat(error.getMessage()).isEqualTo(rangeErr)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> params.addInt256(BigInteger.ONE.shiftLeft(255))) + .satisfies(error -> assertThat(error.getMessage()).isEqualTo(rangeErr)); - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> params.addInt256(BigInteger.ONE.negate().shiftLeft(256)) - ).satisfies(error -> assertThat(error.getMessage()).isEqualTo(rangeErr)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> params.addInt256(BigInteger.ONE.negate().shiftLeft(256))) + .satisfies(error -> assertThat(error.getMessage()).isEqualTo(rangeErr)); } @Test @@ -506,70 +503,73 @@ void addressParamChecks() { String lenErr = "Solidity addresses must be 40 hex chars"; - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> params.addAddress("") - ).satisfies(error -> assertThat(error.getMessage()).isEqualTo(lenErr)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> params.addAddress("")) + .satisfies(error -> assertThat(error.getMessage()).isEqualTo(lenErr)); - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> params.addAddress("aabbccdd") - ).satisfies(error -> assertThat(error.getMessage()).isEqualTo(lenErr)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> params.addAddress("aabbccdd")) + .satisfies(error -> assertThat(error.getMessage()).isEqualTo(lenErr)); - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> params.addAddress("00112233445566778899aabbccddeeff0011223344") - ).satisfies(error -> assertThat(error.getMessage()).isEqualTo(lenErr)); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> params.addAddress("00112233445566778899aabbccddeeff0011223344")) + .satisfies(error -> assertThat(error.getMessage()).isEqualTo(lenErr)); - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> params.addAddress("gghhii--__zz66778899aabbccddeeff00112233") - ).satisfies(error -> assertThat(error.getMessage()).isEqualTo("failed to decode Solidity address as hex")); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> params.addAddress("gghhii--__zz66778899aabbccddeeff00112233")) + .satisfies( + error -> assertThat(error.getMessage()).isEqualTo("failed to decode Solidity address as hex")); } @ParameterizedTest @DisplayName("int256() encodes correctly") @MethodSource("int256Arguments") void int256EncodesCorrectly(long val, String hexString) { - assertThat(hexString).isEqualTo( - Hex.toHexString(ContractFunctionParameters.int256(val, 64).toByteArray()) - ); + assertThat(hexString) + .isEqualTo(Hex.toHexString( + ContractFunctionParameters.int256(val, 64).toByteArray())); } @ParameterizedTest @DisplayName("uint256() encodes correctly") @MethodSource("uInt256Arguments") void uInt256EncodesCorrectly(long val, String hexString, int bitWidth) { - assertThat(hexString).isEqualTo( - Hex.toHexString(ContractFunctionParameters.uint256(val, bitWidth).toByteArray()) - ); + assertThat(hexString) + .isEqualTo(Hex.toHexString( + ContractFunctionParameters.uint256(val, bitWidth).toByteArray())); } @Test void intSizesEncodeCorrectly() throws Exception { List snapshotStrings = new ArrayList<>(); - for (int n = 8; n <= 256; n+= 8) { + for (int n = 8; n <= 256; n += 8) { var bitWidth = n; - var argType = ((Supplier>)() -> { - if (bitWidth == 8) { - return byte.class; - } else if (bitWidth <= 32) { - return int.class; - } else if (bitWidth <= 64) { - return long.class; - } else { - return BigInteger.class; - } - }).get(); - - var argVal = ((Supplier)() -> { - if (bitWidth == 8) { - return (byte) (1 << (bitWidth - 1)); - } else if (bitWidth <= 32) { - return (1 << (bitWidth - 1)); - } else if (bitWidth <= 64) { - return (1L << (bitWidth - 1)); - } else { - return BigInteger.ONE.shiftLeft(bitWidth - 1); - } - }).get(); + var argType = ((Supplier>) () -> { + if (bitWidth == 8) { + return byte.class; + } else if (bitWidth <= 32) { + return int.class; + } else if (bitWidth <= 64) { + return long.class; + } else { + return BigInteger.class; + } + }) + .get(); + + var argVal = ((Supplier) () -> { + if (bitWidth == 8) { + return (byte) (1 << (bitWidth - 1)); + } else if (bitWidth <= 32) { + return (1 << (bitWidth - 1)); + } else if (bitWidth <= 64) { + return (1L << (bitWidth - 1)); + } else { + return BigInteger.ONE.shiftLeft(bitWidth - 1); + } + }) + .get(); var argArrayVal = Array.newInstance(argType, 2); Array.set(argArrayVal, 0, argVal); @@ -588,7 +588,8 @@ void intSizesEncodeCorrectly() throws Exception { addIntArrayMethod.invoke(params, argArrayVal); addUintArrayMethod.invoke(params, argArrayVal); - snapshotStrings.add("bitWidth = " + bitWidth + ": " + Hex.toHexString(params.toBytes(null).toByteArray())); + snapshotStrings.add("bitWidth = " + bitWidth + ": " + + Hex.toHexString(params.toBytes(null).toByteArray())); } SnapshotMatcher.expect(snapshotStrings.toArray()).toMatchSnapshot(); } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractIdTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractIdTest.java index f7522a5f4..81500f91e 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractIdTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractIdTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.InvalidProtocolBufferException; import io.github.jsonSnapshot.SnapshotMatcher; import org.bouncycastle.util.encoders.Hex; @@ -26,9 +25,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - - class ContractIdTest { @BeforeAll public static void beforeAll() { @@ -47,27 +43,37 @@ void fromString() { @Test void fromSolidityAddress() { - SnapshotMatcher.expect(ContractId.fromSolidityAddress("000000000000000000000000000000000000138D").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(ContractId.fromSolidityAddress("000000000000000000000000000000000000138D") + .toString()) + .toMatchSnapshot(); } @Test void fromSolidityAddressWith0x() { - SnapshotMatcher.expect(ContractId.fromSolidityAddress("0x000000000000000000000000000000000000138D").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(ContractId.fromSolidityAddress("0x000000000000000000000000000000000000138D") + .toString()) + .toMatchSnapshot(); } @Test void fromEvmAddress() { - SnapshotMatcher.expect(ContractId.fromEvmAddress(1, 2, "98329e006610472e6B372C080833f6D79ED833cf").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(ContractId.fromEvmAddress(1, 2, "98329e006610472e6B372C080833f6D79ED833cf") + .toString()) + .toMatchSnapshot(); } @Test void fromEvmAddressWith0x() { - SnapshotMatcher.expect(ContractId.fromEvmAddress(1, 2, "0x98329e006610472e6B372C080833f6D79ED833cf").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(ContractId.fromEvmAddress(1, 2, "0x98329e006610472e6B372C080833f6D79ED833cf") + .toString()) + .toMatchSnapshot(); } @Test void fromStringWithEvmAddress() { - SnapshotMatcher.expect(ContractId.fromString("1.2.98329e006610472e6B372C080833f6D79ED833cf").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(ContractId.fromString("1.2.98329e006610472e6B372C080833f6D79ED833cf") + .toString()) + .toMatchSnapshot(); } @Test @@ -85,7 +91,9 @@ void toBytes() throws InvalidProtocolBufferException { @Test void fromBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(ContractId.fromBytes(new ContractId(5005).toBytes()).toString()).toMatchSnapshot(); + SnapshotMatcher.expect( + ContractId.fromBytes(new ContractId(5005).toBytes()).toString()) + .toMatchSnapshot(); } @Test @@ -95,6 +103,8 @@ void toSolidityAddress() { @Test void toSolidityAddress2() { - SnapshotMatcher.expect(ContractId.fromEvmAddress(1, 2, "0x98329e006610472e6B372C080833f6D79ED833cf").toSolidityAddress()).toMatchSnapshot(); + SnapshotMatcher.expect(ContractId.fromEvmAddress(1, 2, "0x98329e006610472e6B372C080833f6D79ED833cf") + .toSolidityAddress()) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractInfoQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractInfoQueryTest.java index 6c16d2d19..6862f869e 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractInfoQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractInfoQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,8 +37,9 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new ContractInfoQuery() - .setContractId(ContractId.fromString("0.0.5005")) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setContractId(ContractId.fromString("0.0.5005")) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractInfoTest.java index 4188b1391..6f0934f16 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractInfoTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,22 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.ContractGetInfoResponse; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Duration; +import java.time.Instant; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Duration; -import java.time.Instant; - - public class ContractInfoTest { - private final ContractGetInfoResponse.ContractInfo info = - ContractGetInfoResponse.ContractInfo.newBuilder() + private final ContractGetInfoResponse.ContractInfo info = ContractGetInfoResponse.ContractInfo.newBuilder() .setContractID(new ContractId(1).toProtobuf()) .setAccountID(new AccountId(2).toProtobuf()) .setContractAccountID("3") @@ -57,25 +51,23 @@ public static void afterAll() { @Test void fromProtobuf() { - SnapshotMatcher.expect(ContractInfo.fromProtobuf(info).toString()) - .toMatchSnapshot(); + SnapshotMatcher.expect(ContractInfo.fromProtobuf(info).toString()).toMatchSnapshot(); } @Test void toProtobuf() { - SnapshotMatcher.expect(ContractInfo.fromProtobuf(info).toProtobuf()) - .toMatchSnapshot(); + SnapshotMatcher.expect(ContractInfo.fromProtobuf(info).toProtobuf()).toMatchSnapshot(); } @Test void toBytes() { SnapshotMatcher.expect(Hex.toHexString(ContractInfo.fromProtobuf(info).toBytes())) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { SnapshotMatcher.expect(ContractInfo.fromBytes(info.toByteArray()).toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractLogInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractLogInfoTest.java index 358569620..9390543bc 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractLogInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractLogInfoTest.java @@ -1,23 +1,38 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.ContractLoginfo; import io.github.jsonSnapshot.SnapshotMatcher; +import java.nio.charset.StandardCharsets; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.nio.charset.StandardCharsets; - public class ContractLogInfoTest { private static final ContractLoginfo info = ContractLoginfo.newBuilder() - .setContractID(new ContractId(10).toProtobuf()) - .setBloom(ByteString.copyFrom("bloom", StandardCharsets.UTF_8)) - .addTopic(ByteString.copyFrom("bloom", StandardCharsets.UTF_8)) - .setData(ByteString.copyFrom("data", StandardCharsets.UTF_8)) - .build(); + .setContractID(new ContractId(10).toProtobuf()) + .setBloom(ByteString.copyFrom("bloom", StandardCharsets.UTF_8)) + .addTopic(ByteString.copyFrom("bloom", StandardCharsets.UTF_8)) + .setData(ByteString.copyFrom("data", StandardCharsets.UTF_8)) + .build(); @BeforeAll public static void beforeAll() { @@ -31,25 +46,25 @@ public static void afterAll() { @Test void fromProtobuf() { - SnapshotMatcher.expect(ContractLogInfo.fromProtobuf(info).toString()) - .toMatchSnapshot(); + SnapshotMatcher.expect(ContractLogInfo.fromProtobuf(info).toString()).toMatchSnapshot(); } @Test void toProtobuf() throws InvalidProtocolBufferException { SnapshotMatcher.expect(ContractLogInfo.fromProtobuf(info).toProtobuf().toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { SnapshotMatcher.expect(ContractLogInfo.fromBytes(info.toByteArray()).toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void toBytes() { - SnapshotMatcher.expect(Hex.toHexString(ContractLogInfo.fromProtobuf(info).toBytes())) - .toMatchSnapshot(); + SnapshotMatcher.expect( + Hex.toHexString(ContractLogInfo.fromProtobuf(info).toBytes())) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractNonceInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractNonceInfoTest.java index a9c3c6f5b..1d8c20925 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractNonceInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractNonceInfoTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; @@ -9,10 +25,10 @@ public class ContractNonceInfoTest { private final com.hedera.hashgraph.sdk.proto.ContractNonceInfo info = - com.hedera.hashgraph.sdk.proto.ContractNonceInfo.newBuilder() - .setContractId(new ContractId(1).toProtobuf()) - .setNonce(2) - .build(); + com.hedera.hashgraph.sdk.proto.ContractNonceInfo.newBuilder() + .setContractId(new ContractId(1).toProtobuf()) + .setNonce(2) + .build(); @BeforeAll public static void beforeAll() { @@ -26,25 +42,25 @@ public static void afterAll() { @Test void fromProtobuf() { - SnapshotMatcher.expect(ContractNonceInfo.fromProtobuf(info).toString()) - .toMatchSnapshot(); + SnapshotMatcher.expect(ContractNonceInfo.fromProtobuf(info).toString()).toMatchSnapshot(); } @Test void toProtobuf() { SnapshotMatcher.expect(ContractNonceInfo.fromProtobuf(info).toProtobuf()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void toBytes() { - SnapshotMatcher.expect(Hex.toHexString(ContractNonceInfo.fromProtobuf(info).toBytes())) - .toMatchSnapshot(); + SnapshotMatcher.expect( + Hex.toHexString(ContractNonceInfo.fromProtobuf(info).toBytes())) + .toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { SnapshotMatcher.expect(ContractNonceInfo.fromBytes(info.toByteArray()).toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractUpdateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractUpdateTransactionTest.java index f16c49e0a..d9debc2bb 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractUpdateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ContractUpdateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +12,25 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.ContractUpdateTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Duration; import java.time.Instant; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class ContractUpdateTransactionTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -50,52 +46,48 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } @Test void shouldSerialize2() { - SnapshotMatcher.expect(spawnTestTransaction2() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction2().toString()).toMatchSnapshot(); } private ContractUpdateTransaction spawnTestTransaction() { return new ContractUpdateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setContractId(ContractId.fromString("0.0.5007")) - .setAdminKey(privateKey) - .setMaxAutomaticTokenAssociations(101) - .setAutoRenewPeriod(Duration.ofDays(1)) - .setContractMemo("3") - .setStakedAccountId(AccountId.fromString("0.0.3")) - .setExpirationTime(Instant.ofEpochMilli(4)) - .setProxyAccountId(new AccountId(4)) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setAutoRenewAccountId(new AccountId(30)) - .freeze() - .sign(privateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setContractId(ContractId.fromString("0.0.5007")) + .setAdminKey(privateKey) + .setMaxAutomaticTokenAssociations(101) + .setAutoRenewPeriod(Duration.ofDays(1)) + .setContractMemo("3") + .setStakedAccountId(AccountId.fromString("0.0.3")) + .setExpirationTime(Instant.ofEpochMilli(4)) + .setProxyAccountId(new AccountId(4)) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setAutoRenewAccountId(new AccountId(30)) + .freeze() + .sign(privateKey); } private ContractUpdateTransaction spawnTestTransaction2() { return new ContractUpdateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setContractId(ContractId.fromString("0.0.5007")) - .setAdminKey(privateKey) - .setMaxAutomaticTokenAssociations(101) - .setAutoRenewPeriod(Duration.ofDays(1)) - .setContractMemo("3") - .setStakedNodeId(4L) - .setExpirationTime(Instant.ofEpochMilli(4)) - .setProxyAccountId(new AccountId(4)) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setAutoRenewAccountId(new AccountId(30)) - .freeze() - .sign(privateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setContractId(ContractId.fromString("0.0.5007")) + .setAdminKey(privateKey) + .setMaxAutomaticTokenAssociations(101) + .setAutoRenewPeriod(Duration.ofDays(1)) + .setContractMemo("3") + .setStakedNodeId(4L) + .setExpirationTime(Instant.ofEpochMilli(4)) + .setProxyAccountId(new AccountId(4)) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setAutoRenewAccountId(new AccountId(30)) + .freeze() + .sign(privateKey); } @Test @@ -115,8 +107,9 @@ void shouldBytes2() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setContractUpdateInstance(ContractUpdateTransactionBody.newBuilder().build()) - .build(); + .setContractUpdateInstance( + ContractUpdateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/CryptoTransferTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/CryptoTransferTransactionTest.java index e9d673352..40d8dee3e 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/CryptoTransferTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/CryptoTransferTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,28 +12,27 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.CryptoTransferTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionList; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - public class CryptoTransferTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -52,59 +48,90 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TransferTransaction spawnTestTransaction() { return new TransferTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .addHbarTransfer(AccountId.fromString("0.0.5008"), Hbar.fromTinybars(400)) - .addHbarTransfer(AccountId.fromString("0.0.5006"), Hbar.fromTinybars(800).negated()) - .addHbarTransfer(AccountId.fromString("0.0.5007"), Hbar.fromTinybars(400)) - .addTokenTransfer(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5008"), 400) - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5006"), -800, 3) - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5007"), 400, 3) - .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5008"), 1) - .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), -1) - .addNftTransfer(TokenId.fromString("0.0.3").nft(2), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5007")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(1), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5007")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(3), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5006")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(4), AccountId.fromString("0.0.5007"), AccountId.fromString("0.0.5006")) - .addNftTransfer(TokenId.fromString("0.0.2").nft(4), AccountId.fromString("0.0.5007"), AccountId.fromString("0.0.5006")) - .setHbarTransferApproval(AccountId.fromString("0.0.5007"), true) - .setTokenTransferApproval(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), true) - .setNftTransferApproval(new NftId(TokenId.fromString("0.0.4"), 4), true) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .addHbarTransfer(AccountId.fromString("0.0.5008"), Hbar.fromTinybars(400)) + .addHbarTransfer( + AccountId.fromString("0.0.5006"), Hbar.fromTinybars(800).negated()) + .addHbarTransfer(AccountId.fromString("0.0.5007"), Hbar.fromTinybars(400)) + .addTokenTransfer(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5008"), 400) + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5006"), -800, 3) + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5007"), 400, 3) + .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5008"), 1) + .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), -1) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(2), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5007")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(1), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5007")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(3), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5006")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(4), + AccountId.fromString("0.0.5007"), + AccountId.fromString("0.0.5006")) + .addNftTransfer( + TokenId.fromString("0.0.2").nft(4), + AccountId.fromString("0.0.5007"), + AccountId.fromString("0.0.5006")) + .setHbarTransferApproval(AccountId.fromString("0.0.5007"), true) + .setTokenTransferApproval(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), true) + .setNftTransferApproval(new NftId(TokenId.fromString("0.0.4"), 4), true) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } private TransferTransaction spawnModifiedTestTransaction() { return new TransferTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .addHbarTransfer(AccountId.fromString("0.0.5008"), Hbar.fromTinybars(400)) - .addHbarTransfer(AccountId.fromString("0.0.5006"), Hbar.fromTinybars(800).negated()) - .addHbarTransfer(AccountId.fromString("0.0.5007"), Hbar.fromTinybars(400)) - .addTokenTransfer(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5008"), 400) - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5006"), -800, 3) - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5007"), 400, 3) - .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5008"), 1) - .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), -1) - .addNftTransfer(TokenId.fromString("0.0.3").nft(2), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5007")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(1), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5007")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(3), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5006")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(4), AccountId.fromString("0.0.5007"), AccountId.fromString("0.0.5006")) - .addNftTransfer(TokenId.fromString("0.0.2").nft(4), AccountId.fromString("0.0.5007"), AccountId.fromString("0.0.5006")) - .setHbarTransferApproval(AccountId.fromString("0.0.5007"), true) - // !!! .setTokenTransferApproval(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), true) !!! - .setNftTransferApproval(new NftId(TokenId.fromString("0.0.4"), 4), true) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .addHbarTransfer(AccountId.fromString("0.0.5008"), Hbar.fromTinybars(400)) + .addHbarTransfer( + AccountId.fromString("0.0.5006"), Hbar.fromTinybars(800).negated()) + .addHbarTransfer(AccountId.fromString("0.0.5007"), Hbar.fromTinybars(400)) + .addTokenTransfer(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5008"), 400) + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5006"), -800, 3) + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5007"), 400, 3) + .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5008"), 1) + .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), -1) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(2), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5007")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(1), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5007")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(3), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5006")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(4), + AccountId.fromString("0.0.5007"), + AccountId.fromString("0.0.5006")) + .addNftTransfer( + TokenId.fromString("0.0.2").nft(4), + AccountId.fromString("0.0.5007"), + AccountId.fromString("0.0.5006")) + .setHbarTransferApproval(AccountId.fromString("0.0.5007"), true) + // !!! .setTokenTransferApproval(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), true) + // !!! + .setNftTransferApproval(new NftId(TokenId.fromString("0.0.4"), 4), true) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -118,8 +145,8 @@ void shouldBytes() throws Exception { void decimalsMustBeConsistent() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { new TransferTransaction() - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.8"), 100, 2) - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.7"), -100, 3); + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.8"), 100, 2) + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.7"), -100, 3); }); } @@ -135,13 +162,12 @@ void canGetDecimals() { @Test void transactionBodiesMustMatch() throws InvalidProtocolBufferException { - com.hedera.hashgraph.sdk.proto.Transaction tx1 = TransactionList.parseFrom(spawnTestTransaction().toBytes()) - .getTransactionList(0); - com.hedera.hashgraph.sdk.proto.Transaction tx2 = TransactionList.parseFrom(spawnModifiedTestTransaction().toBytes()) - .getTransactionList(1); - var brokenTxList = TransactionList.newBuilder() - .addTransactionList(tx1) - .addTransactionList(tx2); + com.hedera.hashgraph.sdk.proto.Transaction tx1 = + TransactionList.parseFrom(spawnTestTransaction().toBytes()).getTransactionList(0); + com.hedera.hashgraph.sdk.proto.Transaction tx2 = TransactionList.parseFrom( + spawnModifiedTestTransaction().toBytes()) + .getTransactionList(1); + var brokenTxList = TransactionList.newBuilder().addTransactionList(tx1).addTransactionList(tx2); var brokenTxBytes = brokenTxList.build().toByteArray(); assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { Transaction.fromBytes(brokenTxBytes); @@ -151,8 +177,8 @@ void transactionBodiesMustMatch() throws InvalidProtocolBufferException { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setCryptoTransfer(CryptoTransferTransactionBody.newBuilder().build()) - .build(); + .setCryptoTransfer(CryptoTransferTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFeeListTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFeeListTest.java index 10219974d..09f9458e7 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFeeListTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFeeListTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +12,19 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - public class CustomFeeListTest { @BeforeAll public static void beforeAll() { @@ -40,28 +36,25 @@ public static void afterAll() { SnapshotMatcher.validateSnapshots(); } - static private List spawnCustomFeeListExample() { + private static List spawnCustomFeeListExample() { var returnList = new ArrayList(); returnList.add(new CustomFixedFee() - .setFeeCollectorAccountId(new AccountId(4322)) - .setDenominatingTokenId(new TokenId(483902)) - .setAmount(10) - ); + .setFeeCollectorAccountId(new AccountId(4322)) + .setDenominatingTokenId(new TokenId(483902)) + .setAmount(10)); returnList.add(new CustomFractionalFee() - .setFeeCollectorAccountId(new AccountId(389042)) - .setNumerator(3) - .setDenominator(7) - .setMin(3) - .setMax(100) - ); + .setFeeCollectorAccountId(new AccountId(389042)) + .setNumerator(3) + .setDenominator(7) + .setMin(3) + .setMax(100)); returnList.add(new CustomRoyaltyFee() - .setFeeCollectorAccountId(new AccountId(23423)) - .setNumerator(5) - .setDenominator(8) - .setFallbackFee(new CustomFixedFee() - .setDenominatingTokenId(new TokenId(483902)) - .setAmount(10)) - ); + .setFeeCollectorAccountId(new AccountId(23423)) + .setNumerator(5) + .setDenominator(8) + .setFallbackFee(new CustomFixedFee() + .setDenominatingTokenId(new TokenId(483902)) + .setAmount(10))); return returnList; } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFixedFeeTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFixedFeeTest.java index 913709a2f..c5536dcb0 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFixedFeeTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFixedFeeTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,18 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.FixedFee; import io.github.jsonSnapshot.SnapshotMatcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class CustomFixedFeeTest { private static final boolean allCollectorsAreExempt = true; private static final AccountId feeCollectorAccountId = new AccountId(1, 2, 3); @@ -34,9 +31,9 @@ public class CustomFixedFeeTest { private static final TokenId tokenId = new TokenId(5, 6, 7); private final FixedFee fee = FixedFee.newBuilder() - .setAmount(amount) - .setDenominatingTokenId(tokenId.toProtobuf()) - .build(); + .setAmount(amount) + .setDenominatingTokenId(tokenId.toProtobuf()) + .build(); @BeforeAll public static void beforeAll() { @@ -56,8 +53,8 @@ void fromProtobuf() { @Test void deepCloneSubclass() { var customFixedFee = new CustomFixedFee() - .setFeeCollectorAccountId(feeCollectorAccountId) - .setAllCollectorsAreExempt(allCollectorsAreExempt); + .setFeeCollectorAccountId(feeCollectorAccountId) + .setAllCollectorsAreExempt(allCollectorsAreExempt); var clonedCustomFixedFee = customFixedFee.deepCloneSubclass(); assertThat(clonedCustomFixedFee.getFeeCollectorAccountId()).isEqualTo(feeCollectorAccountId); @@ -66,12 +63,15 @@ void deepCloneSubclass() { @Test void toProtobuf() { - SnapshotMatcher.expect(CustomFixedFee.fromProtobuf(fee).toProtobuf().toString()).toMatchSnapshot(); + SnapshotMatcher.expect(CustomFixedFee.fromProtobuf(fee).toProtobuf().toString()) + .toMatchSnapshot(); } @Test void toFixedFeeProtobuf() { - SnapshotMatcher.expect(CustomFixedFee.fromProtobuf(fee).toFixedFeeProtobuf().toString()).toMatchSnapshot(); + SnapshotMatcher.expect( + CustomFixedFee.fromProtobuf(fee).toFixedFeeProtobuf().toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFractionalFeeTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFractionalFeeTest.java index 0771c91cc..66dfcc49e 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFractionalFeeTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomFractionalFeeTest.java @@ -1,5 +1,23 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.Fraction; import com.hedera.hashgraph.sdk.proto.FractionalFee; import io.github.jsonSnapshot.SnapshotMatcher; @@ -7,8 +25,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class CustomFractionalFeeTest { private static final boolean allCollectorsAreExempt = true; private static final AccountId feeCollectorAccountId = new AccountId(1, 2, 3); @@ -19,11 +35,11 @@ public class CustomFractionalFeeTest { private static final FeeAssessmentMethod feeAssessmentMethod = FeeAssessmentMethod.EXCLUSIVE; private final FractionalFee fee = FractionalFee.newBuilder() - .setFractionalAmount(Fraction.newBuilder().setNumerator(numerator).setDenominator(denominator)) - .setMinimumAmount(minAmount) - .setMaximumAmount(maxAmount) - .setNetOfTransfers(true) - .build(); + .setFractionalAmount(Fraction.newBuilder().setNumerator(numerator).setDenominator(denominator)) + .setMinimumAmount(minAmount) + .setMaximumAmount(maxAmount) + .setNetOfTransfers(true) + .build(); @BeforeAll public static void beforeAll() { @@ -43,8 +59,8 @@ void fromProtobuf() { @Test void deepCloneSubclass() { var customFractionalFee = new CustomFractionalFee() - .setFeeCollectorAccountId(feeCollectorAccountId) - .setAllCollectorsAreExempt(allCollectorsAreExempt); + .setFeeCollectorAccountId(feeCollectorAccountId) + .setAllCollectorsAreExempt(allCollectorsAreExempt); var clonedCustomFractionalFee = customFractionalFee.deepCloneSubclass(); assertThat(clonedCustomFractionalFee.getFeeCollectorAccountId()).isEqualTo(feeCollectorAccountId); @@ -53,7 +69,9 @@ void deepCloneSubclass() { @Test void toProtobuf() { - SnapshotMatcher.expect(CustomFractionalFee.fromProtobuf(fee).toProtobuf().toString()).toMatchSnapshot(); + SnapshotMatcher.expect( + CustomFractionalFee.fromProtobuf(fee).toProtobuf().toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomRoyaltyFeeTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomRoyaltyFeeTest.java index 5ab1dca14..f254d7a2b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomRoyaltyFeeTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/CustomRoyaltyFeeTest.java @@ -1,10 +1,7 @@ -/*- +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * - * Hedera C++ SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License") + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -15,10 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.FixedFee; import com.hedera.hashgraph.sdk.proto.Fraction; import com.hedera.hashgraph.sdk.proto.RoyaltyFee; @@ -27,8 +26,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class CustomRoyaltyFeeTest { private static final boolean allCollectorsAreExempt = true; private static final AccountId feeCollectorAccountId = new AccountId(1, 2, 3); @@ -37,9 +34,10 @@ public class CustomRoyaltyFeeTest { private static final CustomFixedFee fallbackFee = new CustomFixedFee().setAmount(6); private final RoyaltyFee fee = RoyaltyFee.newBuilder() - .setExchangeValueFraction(Fraction.newBuilder().setNumerator(numerator).setDenominator(denominator)) - .setFallbackFee(FixedFee.newBuilder().setAmount(6).build()) - .build(); + .setExchangeValueFraction( + Fraction.newBuilder().setNumerator(numerator).setDenominator(denominator)) + .setFallbackFee(FixedFee.newBuilder().setAmount(6).build()) + .build(); @BeforeAll public static void beforeAll() { @@ -59,8 +57,8 @@ void fromProtobuf() { @Test void deepCloneSubclass() { var customRoyaltyFee = new CustomRoyaltyFee() - .setFeeCollectorAccountId(feeCollectorAccountId) - .setAllCollectorsAreExempt(allCollectorsAreExempt); + .setFeeCollectorAccountId(feeCollectorAccountId) + .setAllCollectorsAreExempt(allCollectorsAreExempt); var clonedCustomRoyaltyFee = customRoyaltyFee.deepCloneSubclass(); assertThat(clonedCustomRoyaltyFee.getFeeCollectorAccountId()).isEqualTo(feeCollectorAccountId); @@ -69,7 +67,8 @@ void deepCloneSubclass() { @Test void toProtobuf() { - SnapshotMatcher.expect(CustomRoyaltyFee.fromProtobuf(fee).toProtobuf().toString()).toMatchSnapshot(); + SnapshotMatcher.expect(CustomRoyaltyFee.fromProtobuf(fee).toProtobuf().toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/DelegateContractIdTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/DelegateContractIdTest.java index 70d17abd1..9499af239 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/DelegateContractIdTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/DelegateContractIdTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; @@ -39,27 +36,35 @@ public static void afterAll() { @Test void fromString() { - SnapshotMatcher.expect(DelegateContractId.fromString("0.0.5005").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(DelegateContractId.fromString("0.0.5005").toString()) + .toMatchSnapshot(); } @Test void fromSolidityAddress() { - SnapshotMatcher.expect(DelegateContractId.fromSolidityAddress("000000000000000000000000000000000000138D").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(DelegateContractId.fromSolidityAddress("000000000000000000000000000000000000138D") + .toString()) + .toMatchSnapshot(); } @Test void fromSolidityAddressWith0x() { - SnapshotMatcher.expect(DelegateContractId.fromSolidityAddress("0x000000000000000000000000000000000000138D").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(DelegateContractId.fromSolidityAddress("0x000000000000000000000000000000000000138D") + .toString()) + .toMatchSnapshot(); } @Test void toBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(Hex.toHexString(new DelegateContractId(5005).toBytes())).toMatchSnapshot(); + SnapshotMatcher.expect(Hex.toHexString(new DelegateContractId(5005).toBytes())) + .toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(DelegateContractId.fromBytes(new DelegateContractId(5005).toBytes()).toString()).toMatchSnapshot(); + SnapshotMatcher.expect(DelegateContractId.fromBytes(new DelegateContractId(5005).toBytes()) + .toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/EthereumTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/EthereumTransactionTest.java index baa8144b9..46efe2b54 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/EthereumTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/EthereumTransactionTest.java @@ -1,19 +1,34 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class EthereumTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -29,21 +44,19 @@ public static void afterAll() { EthereumTransaction spawnTestTransaction() { return new EthereumTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setEthereumData(Hex.decode("deadbeef")) - .setCallDataFileId(FileId.fromString("4.5.6")) - .setMaxGasAllowanceHbar(Hbar.fromString("3")) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setEthereumData(Hex.decode("deadbeef")) + .setCallDataFileId(FileId.fromString("4.5.6")) + .setMaxGasAllowanceHbar(Hbar.fromString("3")) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ExecutableTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ExecutableTest.java index fd85ccfa3..d6dc079bd 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ExecutableTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ExecutableTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import com.hedera.hashgraph.sdk.logger.LogLevel; import com.hedera.hashgraph.sdk.logger.Logger; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -27,11 +32,6 @@ import com.hedera.hashgraph.sdk.proto.ResponseHeader; import io.grpc.MethodDescriptor; import io.grpc.StatusRuntimeException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.stubbing.Answer; - -import javax.annotation.Nullable; import java.time.Duration; import java.time.Instant; import java.util.Arrays; @@ -41,14 +41,10 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import javax.annotation.Nullable; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.stubbing.Answer; class ExecutableTest { Client client; @@ -74,11 +70,7 @@ void setup() { when(network.getNodeProxies(new AccountId(4))).thenReturn(List.of(node4)); when(network.getNodeProxies(new AccountId(5))).thenReturn(List.of(node5)); - nodeAccountIds = Arrays.asList( - new AccountId(3), - new AccountId(4), - new AccountId(5) - ); + nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5)); } @Test @@ -95,7 +87,6 @@ void firstNodeHealthy() { assertThat(node).isEqualTo(node3); } - @Test void calloptionsShouldRespectGrpcDeadline() { when(node3.isHealthy()).thenReturn(true); @@ -273,33 +264,29 @@ void successfulExecute() throws PrecheckStatusException, TimeoutException { var tx = new DummyTransaction() { @Nullable @Override - TransactionResponse mapResponse(com.hedera.hashgraph.sdk.proto.TransactionResponse response, - AccountId nodeId, com.hedera.hashgraph.sdk.proto.Transaction request) { + TransactionResponse mapResponse( + com.hedera.hashgraph.sdk.proto.TransactionResponse response, + AccountId nodeId, + com.hedera.hashgraph.sdk.proto.Transaction request) { return new TransactionResponse( - new AccountId(3), - TransactionId.withValidStart(new AccountId(3), now), - new byte[]{1, 2, 3}, - null) - .setValidateStatus(true); + new AccountId(3), + TransactionId.withValidStart(new AccountId(3), now), + new byte[] {1, 2, 3}, + null) + .setValidateStatus(true); } }; - var nodeAccountIds = Arrays.asList( - new AccountId(3), - new AccountId(4), - new AccountId(5) - ); + var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5)); tx.setNodeAccountIds(nodeAccountIds); - var txResp = - com.hedera.hashgraph.sdk.proto.TransactionResponse - .newBuilder() + var txResp = com.hedera.hashgraph.sdk.proto.TransactionResponse.newBuilder() .setNodeTransactionPrecheckCode(ResponseCodeEnum.OK) .build(); tx.blockingUnaryCall = (grpcRequest) -> txResp; - com.hedera.hashgraph.sdk.TransactionResponse resp = (com.hedera.hashgraph.sdk.TransactionResponse) tx.execute( - client); + com.hedera.hashgraph.sdk.TransactionResponse resp = + (com.hedera.hashgraph.sdk.TransactionResponse) tx.execute(client); assertThat(resp.nodeId).isEqualTo(new AccountId(3)); assertThat(resp.getValidateStatus()).isTrue(); @@ -318,32 +305,28 @@ void executeWithChannelFailure() throws PrecheckStatusException, TimeoutExceptio var tx = new DummyTransaction() { @Nullable @Override - TransactionResponse mapResponse(com.hedera.hashgraph.sdk.proto.TransactionResponse response, - AccountId nodeId, com.hedera.hashgraph.sdk.proto.Transaction request) { + TransactionResponse mapResponse( + com.hedera.hashgraph.sdk.proto.TransactionResponse response, + AccountId nodeId, + com.hedera.hashgraph.sdk.proto.Transaction request) { return new TransactionResponse( - new AccountId(4), - TransactionId.withValidStart(new AccountId(4), now), - new byte[]{1, 2, 3}, - null); + new AccountId(4), + TransactionId.withValidStart(new AccountId(4), now), + new byte[] {1, 2, 3}, + null); } }; - var nodeAccountIds = Arrays.asList( - new AccountId(3), - new AccountId(4), - new AccountId(5) - ); + var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5)); tx.setNodeAccountIds(nodeAccountIds); - var txResp = - com.hedera.hashgraph.sdk.proto.TransactionResponse - .newBuilder() + var txResp = com.hedera.hashgraph.sdk.proto.TransactionResponse.newBuilder() .setNodeTransactionPrecheckCode(ResponseCodeEnum.OK) .build(); tx.blockingUnaryCall = (grpcRequest) -> txResp; - com.hedera.hashgraph.sdk.TransactionResponse resp = (com.hedera.hashgraph.sdk.TransactionResponse) tx.execute( - client); + com.hedera.hashgraph.sdk.TransactionResponse resp = + (com.hedera.hashgraph.sdk.TransactionResponse) tx.execute(client); verify(node3).channelFailedToConnect(any(Instant.class)); verify(node4).channelFailedToConnect(any(Instant.class)); @@ -364,8 +347,8 @@ void executeWithAllUnhealthyNodes() throws PrecheckStatusException, TimeoutExcep when(node3.channelFailedToConnect(any(Instant.class))).thenAnswer((Answer) inv -> i.get() == 0); when(node4.channelFailedToConnect(any(Instant.class))).thenAnswer((Answer) inv -> i.get() == 0); - when(node5.channelFailedToConnect(any(Instant.class))).thenAnswer( - (Answer) inv -> i.getAndIncrement() == 0); + when(node5.channelFailedToConnect(any(Instant.class))) + .thenAnswer((Answer) inv -> i.getAndIncrement() == 0); when(node3.getRemainingTimeForBackoff()).thenReturn(500L); when(node4.getRemainingTimeForBackoff()).thenReturn(600L); @@ -375,32 +358,28 @@ void executeWithAllUnhealthyNodes() throws PrecheckStatusException, TimeoutExcep var tx = new DummyTransaction() { @Nullable @Override - TransactionResponse mapResponse(com.hedera.hashgraph.sdk.proto.TransactionResponse response, - AccountId nodeId, com.hedera.hashgraph.sdk.proto.Transaction request) { + TransactionResponse mapResponse( + com.hedera.hashgraph.sdk.proto.TransactionResponse response, + AccountId nodeId, + com.hedera.hashgraph.sdk.proto.Transaction request) { return new TransactionResponse( - new AccountId(3), - TransactionId.withValidStart(new AccountId(3), now), - new byte[]{1, 2, 3}, - null); + new AccountId(3), + TransactionId.withValidStart(new AccountId(3), now), + new byte[] {1, 2, 3}, + null); } }; - var nodeAccountIds = Arrays.asList( - new AccountId(3), - new AccountId(4), - new AccountId(5) - ); + var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5)); tx.setNodeAccountIds(nodeAccountIds); - var txResp = - com.hedera.hashgraph.sdk.proto.TransactionResponse - .newBuilder() + var txResp = com.hedera.hashgraph.sdk.proto.TransactionResponse.newBuilder() .setNodeTransactionPrecheckCode(ResponseCodeEnum.OK) .build(); tx.blockingUnaryCall = (grpcRequest) -> txResp; - com.hedera.hashgraph.sdk.TransactionResponse resp = (com.hedera.hashgraph.sdk.TransactionResponse) tx.execute( - client); + com.hedera.hashgraph.sdk.TransactionResponse resp = + (com.hedera.hashgraph.sdk.TransactionResponse) tx.execute(client); verify(node3, times(2)).channelFailedToConnect(any(Instant.class)); verify(node4).channelFailedToConnect(any(Instant.class)); @@ -419,11 +398,7 @@ void executeExhaustRetries() { when(node5.channelFailedToConnect(any(Instant.class))).thenReturn(true); var tx = new DummyTransaction(); - var nodeAccountIds = Arrays.asList( - new AccountId(3), - new AccountId(4), - new AccountId(5) - ); + var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5)); tx.setNodeAccountIds(nodeAccountIds); assertThatExceptionOfType(MaxAttemptsExceededException.class).isThrownBy(() -> tx.execute(client)); } @@ -439,11 +414,7 @@ void executeRetriableErrorDuringCall() { when(node4.channelFailedToConnect(any(Instant.class))).thenReturn(false); var tx = new DummyTransaction(); - var nodeAccountIds = Arrays.asList( - new AccountId(3), - new AccountId(4), - new AccountId(5) - ); + var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5)); tx.setNodeAccountIds(nodeAccountIds); tx.blockingUnaryCall = (grpcRequest) -> { @@ -463,11 +434,10 @@ void executeRetriableErrorDuringCall() { @Test void testChannelFailedToConnectTimeout() { TransactionResponse transactionResponse = new TransactionResponse( - new AccountId(3), - TransactionId.withValidStart(new AccountId(3), java.time.Instant.now()), - new byte[]{1, 2, 3}, - null - ); + new AccountId(3), + TransactionId.withValidStart(new AccountId(3), java.time.Instant.now()), + new byte[] {1, 2, 3}, + null); var tx = new DummyTransaction(); tx.blockingUnaryCall = (grpcRequest) -> { @@ -477,8 +447,8 @@ void testChannelFailedToConnectTimeout() { when(node3.isHealthy()).thenReturn(true); when(node3.channelFailedToConnect(any(Instant.class))).thenReturn(true); - assertThatExceptionOfType(MaxAttemptsExceededException.class).isThrownBy( - () -> transactionResponse.getReceipt(client, Duration.ofSeconds(2))); + assertThatExceptionOfType(MaxAttemptsExceededException.class) + .isThrownBy(() -> transactionResponse.getReceipt(client, Duration.ofSeconds(2))); } @Test @@ -501,19 +471,15 @@ ExecutionState getExecutionState(Status status, Response response) { return i.getAndIncrement() == 0 ? ExecutionState.RETRY : ExecutionState.SUCCESS; } }; - var nodeAccountIds = Arrays.asList( - new AccountId(3), - new AccountId(4), - new AccountId(5) - ); + var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5)); tx.setNodeAccountIds(nodeAccountIds); var receipt = com.hedera.hashgraph.sdk.proto.TransactionReceipt.newBuilder() - .setStatus(ResponseCodeEnum.OK) - .build(); + .setStatus(ResponseCodeEnum.OK) + .build(); var receiptResp = com.hedera.hashgraph.sdk.proto.TransactionGetReceiptResponse.newBuilder() - .setReceipt(receipt) - .build(); + .setReceipt(receipt) + .build(); var resp = Response.newBuilder().setTransactionGetReceipt(receiptResp).build(); tx.blockingUnaryCall = (grpcRequest) -> resp; @@ -523,7 +489,6 @@ ExecutionState getExecutionState(Status status, Response response) { verify(node4).channelFailedToConnect(any(Instant.class)); } - @Test void executeUserError() throws PrecheckStatusException, TimeoutException { when(node3.isHealthy()).thenReturn(true); @@ -535,16 +500,10 @@ Status mapResponseStatus(com.hedera.hashgraph.sdk.proto.TransactionResponse resp return Status.ACCOUNT_DELETED; } }; - var nodeAccountIds = Arrays.asList( - new AccountId(3), - new AccountId(4), - new AccountId(5) - ); + var nodeAccountIds = Arrays.asList(new AccountId(3), new AccountId(4), new AccountId(5)); tx.setNodeAccountIds(nodeAccountIds); - var txResp = - com.hedera.hashgraph.sdk.proto.TransactionResponse - .newBuilder() + var txResp = com.hedera.hashgraph.sdk.proto.TransactionResponse.newBuilder() .setNodeTransactionPrecheckCode(ResponseCodeEnum.ACCOUNT_DELETED) .build(); @@ -558,8 +517,8 @@ Status mapResponseStatus(com.hedera.hashgraph.sdk.proto.TransactionResponse resp void shouldRetryReturnsCorrectStates() { var tx = new DummyTransaction(); - assertThat(tx.getExecutionState(Status.PLATFORM_TRANSACTION_NOT_CREATED, null)).isEqualTo( - ExecutionState.SERVER_ERROR); + assertThat(tx.getExecutionState(Status.PLATFORM_TRANSACTION_NOT_CREATED, null)) + .isEqualTo(ExecutionState.SERVER_ERROR); assertThat(tx.getExecutionState(Status.PLATFORM_NOT_ACTIVE, null)).isEqualTo(ExecutionState.SERVER_ERROR); assertThat(tx.getExecutionState(Status.BUSY, null)).isEqualTo(ExecutionState.RETRY); assertThat(tx.getExecutionState(Status.OK, null)).isEqualTo(ExecutionState.SUCCESS); @@ -578,12 +537,14 @@ void shouldSetMaxRetry() { } static class DummyTransaction> - extends - Executable { + extends Executable< + T, + com.hedera.hashgraph.sdk.proto.Transaction, + com.hedera.hashgraph.sdk.proto.TransactionResponse, + com.hedera.hashgraph.sdk.TransactionResponse> { @Override - void onExecute(Client client) { - } + void onExecute(Client client) {} @Nullable @Override @@ -599,8 +560,10 @@ com.hedera.hashgraph.sdk.proto.Transaction makeRequest() { @Nullable @Override - TransactionResponse mapResponse(com.hedera.hashgraph.sdk.proto.TransactionResponse response, AccountId nodeId, - com.hedera.hashgraph.sdk.proto.Transaction request) { + TransactionResponse mapResponse( + com.hedera.hashgraph.sdk.proto.TransactionResponse response, + AccountId nodeId, + com.hedera.hashgraph.sdk.proto.Transaction request) { return null; } @@ -611,7 +574,8 @@ Status mapResponseStatus(com.hedera.hashgraph.sdk.proto.TransactionResponse resp @Nullable @Override - MethodDescriptor getMethodDescriptor() { + MethodDescriptor + getMethodDescriptor() { return null; } @@ -624,12 +588,11 @@ TransactionId getTransactionIdInternal() { static class DummyQuery extends Query { @Override - void onExecute(Client client) { - } + void onExecute(Client client) {} @Override - TransactionReceipt mapResponse(Response response, AccountId nodeId, - com.hedera.hashgraph.sdk.proto.Query request) { + TransactionReceipt mapResponse( + Response response, AccountId nodeId, com.hedera.hashgraph.sdk.proto.Query request) { return null; } @@ -644,8 +607,7 @@ MethodDescriptor getMethodDescri } @Override - void onMakeRequest(com.hedera.hashgraph.sdk.proto.Query.Builder queryBuilder, QueryHeader header) { - } + void onMakeRequest(com.hedera.hashgraph.sdk.proto.Query.Builder queryBuilder, QueryHeader header) {} @Override ResponseHeader mapResponseHeader(Response response) { @@ -658,7 +620,6 @@ QueryHeader mapRequestHeader(com.hedera.hashgraph.sdk.proto.Query request) { } @Override - void validateChecksums(Client client) { - } + void validateChecksums(Client client) {} } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FeeSchedulesTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FeeSchedulesTest.java index fcf9dec41..0ca522ee4 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FeeSchedulesTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FeeSchedulesTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,19 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; - -import static org.assertj.core.api.Assertions.assertThat; - public class FeeSchedulesTest { @BeforeAll public static void beforeAll() { @@ -41,32 +37,22 @@ public static void afterAll() { FeeSchedules spawnFeeSchedulesExample() { return new FeeSchedules() - .setCurrent(new FeeSchedule() - .setExpirationTime(Instant.ofEpochSecond(1554158542)) - .addTransactionFeeSchedule(new TransactionFeeSchedule() - .addFee(new FeeData() - .setNodeData(new FeeComponents()) - .setNetworkData(new FeeComponents() - .setMin(2) - .setMax(5) - ) - .setServiceData(new FeeComponents()) - ) - ) - ) - .setNext(new FeeSchedule() - .setExpirationTime(Instant.ofEpochSecond(1554158222)) - .addTransactionFeeSchedule(new TransactionFeeSchedule() - .addFee(new FeeData() - .setNodeData(new FeeComponents() - .setMin(1) - .setMax(2) - ) - .setNetworkData(new FeeComponents()) - .setServiceData(new FeeComponents()) - ) - ) - ); + .setCurrent(new FeeSchedule() + .setExpirationTime(Instant.ofEpochSecond(1554158542)) + .addTransactionFeeSchedule(new TransactionFeeSchedule() + .addFee(new FeeData() + .setNodeData(new FeeComponents()) + .setNetworkData( + new FeeComponents().setMin(2).setMax(5)) + .setServiceData(new FeeComponents())))) + .setNext(new FeeSchedule() + .setExpirationTime(Instant.ofEpochSecond(1554158222)) + .addTransactionFeeSchedule(new TransactionFeeSchedule() + .addFee(new FeeData() + .setNodeData( + new FeeComponents().setMin(1).setMax(2)) + .setNetworkData(new FeeComponents()) + .setServiceData(new FeeComponents())))); } @Test @@ -75,8 +61,9 @@ void shouldSerialize() throws Exception { byte[] feeSchedulesBytes = originalFeeSchedules.toBytes(); var copyFeeSchedules = FeeSchedules.fromBytes(feeSchedulesBytes); assertThat(copyFeeSchedules.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(originalFeeSchedules.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalFeeSchedules.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(originalFeeSchedules.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalFeeSchedules.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileAppendTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileAppendTransactionTest.java index c7be96651..9519a95b2 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileAppendTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileAppendTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,78 +12,77 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.proto.FileAppendTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.bouncycastle.util.encoders.Hex; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Instant; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.bouncycastle.util.encoders.Hex; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class FileAppendTransactionTest { - public static final String BIG_CONTENTS = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur aliquam augue sem, ut mattis dui laoreet a. Curabitur consequat est euismod, scelerisque metus et, tristique dui. Nulla commodo mauris ut faucibus ultricies. Quisque venenatis nisl nec augue tempus, at efficitur elit eleifend. Duis pharetra felis metus, sed dapibus urna vehicula id. Duis non venenatis turpis, sit amet ornare orci. Donec non interdum quam. Sed finibus nunc et risus finibus, non sagittis lorem cursus. Proin pellentesque tempor aliquam. Sed congue nisl in enim bibendum, condimentum vehicula nisi feugiat.\n" + - "\n" + - "Suspendisse non sodales arcu. Suspendisse sodales, lorem ac mollis blandit, ipsum neque porttitor nulla, et sodales arcu ante fermentum tellus. Integer sagittis dolor sed augue fringilla accumsan. Cras vitae finibus arcu, sit amet varius dolor. Etiam id finibus dolor, vitae luctus velit. Proin efficitur augue nec pharetra accumsan. Aliquam lobortis nisl diam, vel fermentum purus finibus id. Etiam at finibus orci, et tincidunt turpis. Aliquam imperdiet congue lacus vel facilisis. Phasellus id magna vitae enim dapibus vestibulum vitae quis augue. Morbi eu consequat enim. Maecenas neque nulla, pulvinar sit amet consequat sed, tempor sed magna. Mauris lacinia sem feugiat faucibus aliquet. Etiam congue non turpis at commodo. Nulla facilisi.\n" + - "\n" + - "Nunc velit turpis, cursus ornare fringilla eu, lacinia posuere leo. Mauris rutrum ultricies dui et suscipit. Curabitur in euismod ligula. Curabitur vitae faucibus orci. Phasellus volutpat vestibulum diam sit amet vestibulum. In vel purus leo. Nulla condimentum lectus vestibulum lectus faucibus, id lobortis eros consequat. Proin mollis libero elit, vel aliquet nisi imperdiet et. Morbi ornare est velit, in vehicula nunc malesuada quis. Donec vehicula convallis interdum.\n" + - "\n" + - "Integer pellentesque in nibh vitae aliquet. Ut at justo id libero dignissim hendrerit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Praesent quis ornare lectus. Nam malesuada non diam quis cursus. Phasellus a libero ligula. Suspendisse ligula elit, congue et nisi sit amet, cursus euismod dolor. Morbi aliquam, nulla a posuere pellentesque, diam massa ornare risus, nec eleifend neque eros et elit.\n" + - "\n" + - "Pellentesque a sodales dui. Sed in efficitur ante. Duis eget volutpat elit, et ornare est. Nam felis dolor, placerat mattis diam id, maximus lobortis quam. Sed pellentesque lobortis sem sed placerat. Pellentesque augue odio, molestie sed lectus sit amet, congue volutpat massa. Quisque congue consequat nunc id fringilla. Duis semper nulla eget enim venenatis dapibus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque varius turpis nibh, sit amet malesuada mauris malesuada quis. Vivamus dictum egestas placerat. Vivamus id augue elit.\n" + - "\n" + - "Cras fermentum volutpat eros, vitae euismod lorem viverra nec. Donec lectus augue, porta eleifend odio sit amet, condimentum rhoncus urna. Nunc sed odio velit. Morbi non cursus odio, eget imperdiet erat. Nunc rhoncus massa non neque volutpat, sit amet faucibus ante congue. Phasellus nec lorem vel leo accumsan lobortis. Maecenas id ligula bibendum purus suscipit posuere ac eget diam. Nam in quam pretium, semper erat auctor, iaculis odio. Maecenas placerat, nisi ac elementum tempor, felis nulla porttitor orci, ac rhoncus diam justo in elit. Etiam lobortis fermentum ligula in tincidunt. Donec quis vestibulum nunc. Sed eros diam, interdum in porta lobortis, gravida eu magna. Donec diam purus, finibus et sollicitudin quis, fringilla nec nisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur ultricies sagittis dapibus. Etiam ullamcorper aliquet libero, eu venenatis mauris suscipit id.\n" + - "\n" + - "Ut interdum eleifend sem, vel bibendum ipsum volutpat eget. Nunc ac dignissim augue. Aliquam ornare aliquet magna id dignissim. Vestibulum velit sem, lacinia eu rutrum in, rhoncus vitae mauris. Pellentesque scelerisque pulvinar mauris non cursus. Integer id dolor porta, bibendum sem vel, pretium tortor. Fusce a nisi convallis, interdum quam condimentum, suscipit dolor. Sed magna diam, efficitur non nunc in, tincidunt varius mi. Aliquam ullamcorper nulla eu fermentum bibendum. Vivamus a felis pretium, hendrerit enim vitae, hendrerit leo. Suspendisse lacinia lectus a diam consectetur suscipit. Aenean hendrerit nisl sed diam venenatis pellentesque. Nullam egestas lectus a consequat pharetra. Vivamus ornare tellus auctor, facilisis lacus id, feugiat dui. Nam id est ut est rhoncus varius.\n" + - "\n" + - "Aenean vel vehicula erat. Aenean gravida risus vitae purus sodales, quis dictum enim porta. Ut elit elit, fermentum sed posuere non, accumsan eu justo. Integer porta malesuada quam, et elementum massa suscipit nec. Donec in elit diam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis suscipit vel ante volutpat vestibulum.\n" + - "\n" + - "Pellentesque ex arcu, euismod et sapien ut, vulputate suscipit enim. Donec mattis sagittis augue, et mattis lacus. Cras placerat consequat lorem sed luctus. Nam suscipit aliquam sem ac imperdiet. Mauris a semper augue, pulvinar fringilla magna. Integer pretium massa non risus commodo hendrerit. Sed dictum libero id erat sodales mattis. Etiam auctor dolor lectus, ut sagittis enim lobortis vitae. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec orci lobortis, cursus risus eget, sollicitudin massa. Integer vel tincidunt mi, id eleifend quam. Nullam facilisis nisl eu mauris congue, vitae euismod nisi malesuada. Vivamus sit amet urna et libero sagittis dictum.\n" + - "\n" + - "In hac habitasse platea dictumst. Aliquam erat volutpat. Ut dictum, mi a viverra venenatis, mi urna pulvinar nisi, nec gravida lectus diam eget urna. Ut dictum sit amet nisl ut dignissim. Sed sed mauris scelerisque, efficitur augue in, vulputate turpis. Proin dolor justo, bibendum et sollicitudin feugiat, imperdiet sed mi. Sed elementum vitae massa vel lobortis. Cras vitae massa sit amet libero dictum tempus.\n" + - "\n" + - "Vivamus ut mauris lectus. Curabitur placerat ornare scelerisque. Cras malesuada nunc quis tortor pretium bibendum vel sed dui. Cras lobortis nibh eu erat blandit, sit amet consequat neque fermentum. Phasellus imperdiet molestie tristique. Cras auctor purus erat, id mollis ligula porttitor eget. Mauris porta pharetra odio et finibus. Suspendisse eu est a ligula bibendum cursus. Mauris ac laoreet libero. Nullam volutpat sem quis rhoncus gravida.\n" + - "\n" + - "Donec malesuada lacus ac iaculis cursus. Sed sem orci, feugiat ac est ut, ultricies posuere nisi. Suspendisse potenti. Phasellus ut ultricies purus. Etiam sem tortor, fermentum quis aliquam eget, consequat ut nulla. Aliquam dictum metus in mi fringilla, vel gravida nulla accumsan. Cras aliquam eget leo vel posuere. Vivamus vitae malesuada nunc. Morbi placerat magna mi, id suscipit lacus auctor quis. Nam at lorem vel odio finibus fringilla ut ac velit. Donec laoreet at nibh quis vehicula.\n" + - "\n" + - "Fusce ac tristique nisi. Donec leo nisi, consectetur at tellus sit amet, consectetur ultrices dui. Quisque gravida mollis tempor. Maecenas semper, sapien ut dignissim feugiat, massa enim viverra dolor, non varius eros nulla nec felis. Nunc massa lacus, ornare et feugiat id, bibendum quis purus. Praesent viverra elit sit amet purus consectetur venenatis. Maecenas nibh risus, elementum sit amet enim sagittis, ultrices malesuada lectus. Vivamus non felis ante. Ut vulputate ex arcu. Aliquam porta gravida porta. Aliquam eros leo, malesuada quis eros non, maximus tristique neque. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam ligula orci, mollis vel luctus nec, venenatis vitae est. Fusce rutrum convallis nisi.\n" + - "\n" + - "Nunc laoreet eget nibh in feugiat. Pellentesque nec arcu cursus, gravida dolor a, pellentesque nisi. Praesent vel justo blandit, placerat risus eget, consectetur orci. Sed maximus metus mi, ut euismod augue ultricies in. Nunc id risus hendrerit, aliquet lorem nec, congue justo. Vestibulum vel nunc ac est euismod mattis ac vitae nulla. Donec blandit luctus mauris, sit amet bibendum dui egestas et. Aenean nec lorem nec elit ornare rutrum nec eget ligula. Fusce a ipsum vitae neque elementum pharetra. Pellentesque ullamcorper ullamcorper libero, vitae porta sem sagittis vel. Interdum et malesuada fames ac ante ipsum primis in faucibus.\n" + - "\n" + - "Duis at massa sit amet risus pellentesque varius sit amet vitae eros. Cras tempor aliquet sapien, vehicula varius neque volutpat et. Donec purus nibh, pellentesque ut lobortis nec, ultricies ultricies nisl. Sed accumsan ut dui sit amet vulputate. Suspendisse eu facilisis massa, a hendrerit mauris. Nulla elementum molestie tincidunt. Donec mi justo, ornare vel tempor id, gravida et orci. Nam molestie erat nec nisi bibendum accumsan. Duis vitae tempor ante. Morbi congue mauris vel sagittis facilisis. Vivamus vehicula odio orci, a tempor nibh euismod in. Proin mattis, nibh at feugiat porta, purus velit posuere felis, quis volutpat sapien dui vel odio. Nam fermentum sem nec euismod aliquet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam erat volutpat.\n" + - "\n" + - "Mauris congue lacus tortor. Pellentesque arcu eros, accumsan imperdiet porttitor vitae, mattis nec justo. Nullam ac aliquam mauris. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse potenti. Fusce accumsan tempus felis a sagittis. Maecenas et velit odio. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Aliquam eros lacus, volutpat non urna sed, tincidunt ullamcorper elit. Sed sit amet gravida libero. In varius mi vel diam sollicitudin mollis.\n" + - "\n" + - "Aenean varius, diam vitae hendrerit feugiat, libero augue ultrices odio, eget consequat sem tellus eu nisi. Nam dapibus enim et auctor sollicitudin. Nunc iaculis eros orci, ac accumsan eros malesuada ut. Ut semper augue felis, nec sodales lorem consectetur non. Cras gravida eleifend est, et sagittis eros imperdiet congue. Fusce id tellus dapibus nunc scelerisque tempus. Donec tempor placerat libero, in commodo nisi bibendum eu. Donec id eros non est sollicitudin luctus. Duis bibendum bibendum tellus nec viverra. Aliquam non faucibus ex, nec luctus dui. Curabitur efficitur varius urna non dignissim. Suspendisse elit elit, ultrices in elementum eu, tempor at magna.\n" + - "\n" + - "Nunc in purus sit amet mi laoreet pulvinar placerat eget sapien. Donec vel felis at dui ultricies euismod quis vel neque. Donec tincidunt urna non eros pretium blandit. Nullam congue tincidunt condimentum. Curabitur et libero nibh. Proin ultricies risus id imperdiet scelerisque. Suspendisse purus mi, viverra vitae risus ut, tempus tincidunt enim. Ut luctus lobortis nisl, eget venenatis tortor cursus non. Mauris finibus nisl quis gravida ultricies. Fusce elementum lacus sit amet nunc congue, in porta nulla tincidunt.\n" + - "\n" + - "Mauris ante risus, imperdiet blandit posuere in, blandit eu ipsum. Integer et auctor arcu. Integer quis elementum purus. Nunc in ultricies nisl, sed rutrum risus. Suspendisse venenatis eros nec lorem rhoncus, in scelerisque velit condimentum. Etiam condimentum quam felis, in elementum odio mattis et. In ut nibh porttitor, hendrerit tellus vel, luctus magna. Vestibulum et ligula et dolor pellentesque porta. Aenean efficitur porta massa et bibendum. Nulla vehicula sem in risus volutpat, a eleifend elit maximus.\n" + - "\n" + - "Proin orci lorem, auctor a felis eu, pretium lobortis nulla. Phasellus aliquam efficitur interdum. Sed sit amet velit rutrum est dictum facilisis. Duis cursus enim at nisl tincidunt, eu molestie elit vehicula. Cras pellentesque nisl id enim feugiat fringilla. In quis tincidunt neque. Nam eu consectetur dolor. Ut id interdum mauris. Mauris nunc tortor, placerat in tempor ut, vestibulum eu nisl. Integer vel dapibus ipsum. Nunc id erat pulvinar, tincidunt magna id, condimentum massa. Pellentesque consequat est eget odio placerat vehicula. Etiam augue neque, sagittis non leo eu, tristique scelerisque dui. Ut dui urna, blandit quis urna ac, tincidunt tristique turpis.\n" + - "\n" + - "Suspendisse venenatis rhoncus ligula ultrices condimentum. In id laoreet eros. Suspendisse suscipit fringilla leo id euismod. Sed in quam libero. Ut at ligula tellus. Sed tristique gravida dui, at egestas odio aliquam iaculis. Praesent imperdiet velit quis nibh consequat, quis pretium sem sagittis. Donec tortor ex, congue sit amet pulvinar ac, rutrum non est. Praesent ipsum magna, venenatis sit amet vulputate id, eleifend ac ipsum.\n" + - "\n" + - "In consequat, nisi iaculis laoreet elementum, massa mauris varius nisi, et porta nisi velit at urna. Maecenas sit amet aliquet eros, a rhoncus nisl. Maecenas convallis enim nunc. Morbi purus nisl, aliquam ac tincidunt sed, mattis in augue. Quisque et elementum quam, vitae maximus orci. Suspendisse hendrerit risus nec vehicula placerat. Nulla et lectus nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n" + - "\n" + - "Etiam ut sodales ex. Nulla luctus, magna eu scelerisque sagittis, nibh quam consectetur neque, non rutrum dolor metus nec ex. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed egestas augue elit, sollicitudin accumsan massa lobortis ac. Curabitur placerat, dolor a aliquam maximus, velit ipsum laoreet ligula, id ullamcorper lacus nibh eget nisl. Donec eget lacus venenatis enim consequat auctor vel in.\n"; + public static final String BIG_CONTENTS = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur aliquam augue sem, ut mattis dui laoreet a. Curabitur consequat est euismod, scelerisque metus et, tristique dui. Nulla commodo mauris ut faucibus ultricies. Quisque venenatis nisl nec augue tempus, at efficitur elit eleifend. Duis pharetra felis metus, sed dapibus urna vehicula id. Duis non venenatis turpis, sit amet ornare orci. Donec non interdum quam. Sed finibus nunc et risus finibus, non sagittis lorem cursus. Proin pellentesque tempor aliquam. Sed congue nisl in enim bibendum, condimentum vehicula nisi feugiat.\n" + + "\n" + + "Suspendisse non sodales arcu. Suspendisse sodales, lorem ac mollis blandit, ipsum neque porttitor nulla, et sodales arcu ante fermentum tellus. Integer sagittis dolor sed augue fringilla accumsan. Cras vitae finibus arcu, sit amet varius dolor. Etiam id finibus dolor, vitae luctus velit. Proin efficitur augue nec pharetra accumsan. Aliquam lobortis nisl diam, vel fermentum purus finibus id. Etiam at finibus orci, et tincidunt turpis. Aliquam imperdiet congue lacus vel facilisis. Phasellus id magna vitae enim dapibus vestibulum vitae quis augue. Morbi eu consequat enim. Maecenas neque nulla, pulvinar sit amet consequat sed, tempor sed magna. Mauris lacinia sem feugiat faucibus aliquet. Etiam congue non turpis at commodo. Nulla facilisi.\n" + + "\n" + + "Nunc velit turpis, cursus ornare fringilla eu, lacinia posuere leo. Mauris rutrum ultricies dui et suscipit. Curabitur in euismod ligula. Curabitur vitae faucibus orci. Phasellus volutpat vestibulum diam sit amet vestibulum. In vel purus leo. Nulla condimentum lectus vestibulum lectus faucibus, id lobortis eros consequat. Proin mollis libero elit, vel aliquet nisi imperdiet et. Morbi ornare est velit, in vehicula nunc malesuada quis. Donec vehicula convallis interdum.\n" + + "\n" + + "Integer pellentesque in nibh vitae aliquet. Ut at justo id libero dignissim hendrerit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Praesent quis ornare lectus. Nam malesuada non diam quis cursus. Phasellus a libero ligula. Suspendisse ligula elit, congue et nisi sit amet, cursus euismod dolor. Morbi aliquam, nulla a posuere pellentesque, diam massa ornare risus, nec eleifend neque eros et elit.\n" + + "\n" + + "Pellentesque a sodales dui. Sed in efficitur ante. Duis eget volutpat elit, et ornare est. Nam felis dolor, placerat mattis diam id, maximus lobortis quam. Sed pellentesque lobortis sem sed placerat. Pellentesque augue odio, molestie sed lectus sit amet, congue volutpat massa. Quisque congue consequat nunc id fringilla. Duis semper nulla eget enim venenatis dapibus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque varius turpis nibh, sit amet malesuada mauris malesuada quis. Vivamus dictum egestas placerat. Vivamus id augue elit.\n" + + "\n" + + "Cras fermentum volutpat eros, vitae euismod lorem viverra nec. Donec lectus augue, porta eleifend odio sit amet, condimentum rhoncus urna. Nunc sed odio velit. Morbi non cursus odio, eget imperdiet erat. Nunc rhoncus massa non neque volutpat, sit amet faucibus ante congue. Phasellus nec lorem vel leo accumsan lobortis. Maecenas id ligula bibendum purus suscipit posuere ac eget diam. Nam in quam pretium, semper erat auctor, iaculis odio. Maecenas placerat, nisi ac elementum tempor, felis nulla porttitor orci, ac rhoncus diam justo in elit. Etiam lobortis fermentum ligula in tincidunt. Donec quis vestibulum nunc. Sed eros diam, interdum in porta lobortis, gravida eu magna. Donec diam purus, finibus et sollicitudin quis, fringilla nec nisi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur ultricies sagittis dapibus. Etiam ullamcorper aliquet libero, eu venenatis mauris suscipit id.\n" + + "\n" + + "Ut interdum eleifend sem, vel bibendum ipsum volutpat eget. Nunc ac dignissim augue. Aliquam ornare aliquet magna id dignissim. Vestibulum velit sem, lacinia eu rutrum in, rhoncus vitae mauris. Pellentesque scelerisque pulvinar mauris non cursus. Integer id dolor porta, bibendum sem vel, pretium tortor. Fusce a nisi convallis, interdum quam condimentum, suscipit dolor. Sed magna diam, efficitur non nunc in, tincidunt varius mi. Aliquam ullamcorper nulla eu fermentum bibendum. Vivamus a felis pretium, hendrerit enim vitae, hendrerit leo. Suspendisse lacinia lectus a diam consectetur suscipit. Aenean hendrerit nisl sed diam venenatis pellentesque. Nullam egestas lectus a consequat pharetra. Vivamus ornare tellus auctor, facilisis lacus id, feugiat dui. Nam id est ut est rhoncus varius.\n" + + "\n" + + "Aenean vel vehicula erat. Aenean gravida risus vitae purus sodales, quis dictum enim porta. Ut elit elit, fermentum sed posuere non, accumsan eu justo. Integer porta malesuada quam, et elementum massa suscipit nec. Donec in elit diam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis suscipit vel ante volutpat vestibulum.\n" + + "\n" + + "Pellentesque ex arcu, euismod et sapien ut, vulputate suscipit enim. Donec mattis sagittis augue, et mattis lacus. Cras placerat consequat lorem sed luctus. Nam suscipit aliquam sem ac imperdiet. Mauris a semper augue, pulvinar fringilla magna. Integer pretium massa non risus commodo hendrerit. Sed dictum libero id erat sodales mattis. Etiam auctor dolor lectus, ut sagittis enim lobortis vitae. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur nec orci lobortis, cursus risus eget, sollicitudin massa. Integer vel tincidunt mi, id eleifend quam. Nullam facilisis nisl eu mauris congue, vitae euismod nisi malesuada. Vivamus sit amet urna et libero sagittis dictum.\n" + + "\n" + + "In hac habitasse platea dictumst. Aliquam erat volutpat. Ut dictum, mi a viverra venenatis, mi urna pulvinar nisi, nec gravida lectus diam eget urna. Ut dictum sit amet nisl ut dignissim. Sed sed mauris scelerisque, efficitur augue in, vulputate turpis. Proin dolor justo, bibendum et sollicitudin feugiat, imperdiet sed mi. Sed elementum vitae massa vel lobortis. Cras vitae massa sit amet libero dictum tempus.\n" + + "\n" + + "Vivamus ut mauris lectus. Curabitur placerat ornare scelerisque. Cras malesuada nunc quis tortor pretium bibendum vel sed dui. Cras lobortis nibh eu erat blandit, sit amet consequat neque fermentum. Phasellus imperdiet molestie tristique. Cras auctor purus erat, id mollis ligula porttitor eget. Mauris porta pharetra odio et finibus. Suspendisse eu est a ligula bibendum cursus. Mauris ac laoreet libero. Nullam volutpat sem quis rhoncus gravida.\n" + + "\n" + + "Donec malesuada lacus ac iaculis cursus. Sed sem orci, feugiat ac est ut, ultricies posuere nisi. Suspendisse potenti. Phasellus ut ultricies purus. Etiam sem tortor, fermentum quis aliquam eget, consequat ut nulla. Aliquam dictum metus in mi fringilla, vel gravida nulla accumsan. Cras aliquam eget leo vel posuere. Vivamus vitae malesuada nunc. Morbi placerat magna mi, id suscipit lacus auctor quis. Nam at lorem vel odio finibus fringilla ut ac velit. Donec laoreet at nibh quis vehicula.\n" + + "\n" + + "Fusce ac tristique nisi. Donec leo nisi, consectetur at tellus sit amet, consectetur ultrices dui. Quisque gravida mollis tempor. Maecenas semper, sapien ut dignissim feugiat, massa enim viverra dolor, non varius eros nulla nec felis. Nunc massa lacus, ornare et feugiat id, bibendum quis purus. Praesent viverra elit sit amet purus consectetur venenatis. Maecenas nibh risus, elementum sit amet enim sagittis, ultrices malesuada lectus. Vivamus non felis ante. Ut vulputate ex arcu. Aliquam porta gravida porta. Aliquam eros leo, malesuada quis eros non, maximus tristique neque. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam ligula orci, mollis vel luctus nec, venenatis vitae est. Fusce rutrum convallis nisi.\n" + + "\n" + + "Nunc laoreet eget nibh in feugiat. Pellentesque nec arcu cursus, gravida dolor a, pellentesque nisi. Praesent vel justo blandit, placerat risus eget, consectetur orci. Sed maximus metus mi, ut euismod augue ultricies in. Nunc id risus hendrerit, aliquet lorem nec, congue justo. Vestibulum vel nunc ac est euismod mattis ac vitae nulla. Donec blandit luctus mauris, sit amet bibendum dui egestas et. Aenean nec lorem nec elit ornare rutrum nec eget ligula. Fusce a ipsum vitae neque elementum pharetra. Pellentesque ullamcorper ullamcorper libero, vitae porta sem sagittis vel. Interdum et malesuada fames ac ante ipsum primis in faucibus.\n" + + "\n" + + "Duis at massa sit amet risus pellentesque varius sit amet vitae eros. Cras tempor aliquet sapien, vehicula varius neque volutpat et. Donec purus nibh, pellentesque ut lobortis nec, ultricies ultricies nisl. Sed accumsan ut dui sit amet vulputate. Suspendisse eu facilisis massa, a hendrerit mauris. Nulla elementum molestie tincidunt. Donec mi justo, ornare vel tempor id, gravida et orci. Nam molestie erat nec nisi bibendum accumsan. Duis vitae tempor ante. Morbi congue mauris vel sagittis facilisis. Vivamus vehicula odio orci, a tempor nibh euismod in. Proin mattis, nibh at feugiat porta, purus velit posuere felis, quis volutpat sapien dui vel odio. Nam fermentum sem nec euismod aliquet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam erat volutpat.\n" + + "\n" + + "Mauris congue lacus tortor. Pellentesque arcu eros, accumsan imperdiet porttitor vitae, mattis nec justo. Nullam ac aliquam mauris. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse potenti. Fusce accumsan tempus felis a sagittis. Maecenas et velit odio. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Aliquam eros lacus, volutpat non urna sed, tincidunt ullamcorper elit. Sed sit amet gravida libero. In varius mi vel diam sollicitudin mollis.\n" + + "\n" + + "Aenean varius, diam vitae hendrerit feugiat, libero augue ultrices odio, eget consequat sem tellus eu nisi. Nam dapibus enim et auctor sollicitudin. Nunc iaculis eros orci, ac accumsan eros malesuada ut. Ut semper augue felis, nec sodales lorem consectetur non. Cras gravida eleifend est, et sagittis eros imperdiet congue. Fusce id tellus dapibus nunc scelerisque tempus. Donec tempor placerat libero, in commodo nisi bibendum eu. Donec id eros non est sollicitudin luctus. Duis bibendum bibendum tellus nec viverra. Aliquam non faucibus ex, nec luctus dui. Curabitur efficitur varius urna non dignissim. Suspendisse elit elit, ultrices in elementum eu, tempor at magna.\n" + + "\n" + + "Nunc in purus sit amet mi laoreet pulvinar placerat eget sapien. Donec vel felis at dui ultricies euismod quis vel neque. Donec tincidunt urna non eros pretium blandit. Nullam congue tincidunt condimentum. Curabitur et libero nibh. Proin ultricies risus id imperdiet scelerisque. Suspendisse purus mi, viverra vitae risus ut, tempus tincidunt enim. Ut luctus lobortis nisl, eget venenatis tortor cursus non. Mauris finibus nisl quis gravida ultricies. Fusce elementum lacus sit amet nunc congue, in porta nulla tincidunt.\n" + + "\n" + + "Mauris ante risus, imperdiet blandit posuere in, blandit eu ipsum. Integer et auctor arcu. Integer quis elementum purus. Nunc in ultricies nisl, sed rutrum risus. Suspendisse venenatis eros nec lorem rhoncus, in scelerisque velit condimentum. Etiam condimentum quam felis, in elementum odio mattis et. In ut nibh porttitor, hendrerit tellus vel, luctus magna. Vestibulum et ligula et dolor pellentesque porta. Aenean efficitur porta massa et bibendum. Nulla vehicula sem in risus volutpat, a eleifend elit maximus.\n" + + "\n" + + "Proin orci lorem, auctor a felis eu, pretium lobortis nulla. Phasellus aliquam efficitur interdum. Sed sit amet velit rutrum est dictum facilisis. Duis cursus enim at nisl tincidunt, eu molestie elit vehicula. Cras pellentesque nisl id enim feugiat fringilla. In quis tincidunt neque. Nam eu consectetur dolor. Ut id interdum mauris. Mauris nunc tortor, placerat in tempor ut, vestibulum eu nisl. Integer vel dapibus ipsum. Nunc id erat pulvinar, tincidunt magna id, condimentum massa. Pellentesque consequat est eget odio placerat vehicula. Etiam augue neque, sagittis non leo eu, tristique scelerisque dui. Ut dui urna, blandit quis urna ac, tincidunt tristique turpis.\n" + + "\n" + + "Suspendisse venenatis rhoncus ligula ultrices condimentum. In id laoreet eros. Suspendisse suscipit fringilla leo id euismod. Sed in quam libero. Ut at ligula tellus. Sed tristique gravida dui, at egestas odio aliquam iaculis. Praesent imperdiet velit quis nibh consequat, quis pretium sem sagittis. Donec tortor ex, congue sit amet pulvinar ac, rutrum non est. Praesent ipsum magna, venenatis sit amet vulputate id, eleifend ac ipsum.\n" + + "\n" + + "In consequat, nisi iaculis laoreet elementum, massa mauris varius nisi, et porta nisi velit at urna. Maecenas sit amet aliquet eros, a rhoncus nisl. Maecenas convallis enim nunc. Morbi purus nisl, aliquam ac tincidunt sed, mattis in augue. Quisque et elementum quam, vitae maximus orci. Suspendisse hendrerit risus nec vehicula placerat. Nulla et lectus nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\n" + + "\n" + + "Etiam ut sodales ex. Nulla luctus, magna eu scelerisque sagittis, nibh quam consectetur neque, non rutrum dolor metus nec ex. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed egestas augue elit, sollicitudin accumsan massa lobortis ac. Curabitur placerat, dolor a aliquam maximus, velit ipsum laoreet ligula, id ullamcorper lacus nibh eget nisl. Donec eget lacus venenatis enim consequat auctor vel in.\n"; private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final PrivateKey secondPrivateKey = PrivateKey.fromString( - "302e020100300506032b65700422042099b8587e5abccf6999b0d42b88c581c45284290450487ce90095561c85af11e4" - ); + "302e020100300506032b65700422042099b8587e5abccf6999b0d42b88c581c45284290450487ce90095561c85af11e4"); final Instant validStart = Instant.ofEpochSecond(1554158542); @BeforeAll @@ -102,19 +98,19 @@ public static void afterAll() { @Test void shouldSerialize() { SnapshotMatcher.expect(spawnTestTransaction(Collections.singletonList(AccountId.fromString("0.0.5005"))) - .toString() - ).toMatchSnapshot(); + .toString()) + .toMatchSnapshot(); } private FileAppendTransaction spawnTestTransaction(List accountIds) { return new FileAppendTransaction() - .setNodeAccountIds(accountIds) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setFileId(FileId.fromString("0.0.6006")) - .setContents(new byte[]{1, 2, 3, 4}) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(accountIds) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setFileId(FileId.fromString("0.0.6006")) + .setContents(new byte[] {1, 2, 3, 4}) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -123,20 +119,19 @@ void shouldSerializeBigContents() { nodeAccountIds.add(AccountId.fromString("0.0.444")); nodeAccountIds.add(AccountId.fromString("0.0.555")); - SnapshotMatcher.expect(spawnTestTransactionBigContents(nodeAccountIds) - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransactionBigContents(nodeAccountIds).toString()) + .toMatchSnapshot(); } private FileAppendTransaction spawnTestTransactionBigContents(ArrayList nodeAccountIds) { return new FileAppendTransaction() - .setNodeAccountIds(nodeAccountIds) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setFileId(FileId.fromString("0.0.6006")) - .setContents(BIG_CONTENTS) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(nodeAccountIds) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setFileId(FileId.fromString("0.0.6006")) + .setContents(BIG_CONTENTS) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } String hashesToString(List> hashes) { @@ -145,7 +140,11 @@ String hashesToString(List> hashes) { for (var tx : hashes) { outString.append("{"); for (var entry : tx.entrySet()) { - outString.append(entry.getKey().toString()).append("=").append(Hex.toHexString(entry.getValue())).append(", "); + outString + .append(entry.getKey().toString()) + .append("=") + .append(Hex.toHexString(entry.getValue())) + .append(", "); } outString.append("}, "); } @@ -158,11 +157,9 @@ void shouldHash() { nodeAccountIds.add(AccountId.fromString("0.0.444")); nodeAccountIds.add(AccountId.fromString("0.0.555")); - SnapshotMatcher.expect( - hashesToString(spawnTestTransactionBigContents(nodeAccountIds) - .getAllTransactionHashesPerNode() - ) - ).toMatchSnapshot(); + SnapshotMatcher.expect(hashesToString( + spawnTestTransactionBigContents(nodeAccountIds).getAllTransactionHashesPerNode())) + .toMatchSnapshot(); } String signaturesToString(Map> signatures) { @@ -171,7 +168,11 @@ String signaturesToString(Map> signatures) { for (var nodeEntry : signatures.entrySet()) { outString.append(nodeEntry.getKey()).append("={"); for (var sigEntry : nodeEntry.getValue().entrySet()) { - outString.append(sigEntry.getKey()).append("=").append(Hex.toHexString(sigEntry.getValue())).append(", "); + outString + .append(sigEntry.getKey()) + .append("=") + .append(Hex.toHexString(sigEntry.getValue())) + .append(", "); } outString.append("}, "); } @@ -192,9 +193,8 @@ void shouldGetSignatures() { var nodeAccountIds = new ArrayList(); nodeAccountIds.add(AccountId.fromString("0.0.444")); nodeAccountIds.add(AccountId.fromString("0.0.555")); - var signatures = spawnTestTransaction(nodeAccountIds) - .sign(secondPrivateKey) - .getSignatures(); + var signatures = + spawnTestTransaction(nodeAccountIds).sign(secondPrivateKey).getSignatures(); SnapshotMatcher.expect(signaturesToString(signatures)).toMatchSnapshot(); } @@ -204,8 +204,8 @@ void shouldGetAllSignatures() { nodeAccountIds.add(AccountId.fromString("0.0.444")); nodeAccountIds.add(AccountId.fromString("0.0.555")); var signatures = spawnTestTransactionBigContents(nodeAccountIds) - .sign(secondPrivateKey) - .getAllSignatures(); + .sign(secondPrivateKey) + .getAllSignatures(); SnapshotMatcher.expect(allSignaturesToString(signatures)).toMatchSnapshot(); } @@ -225,8 +225,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setFileAppend(FileAppendTransactionBody.newBuilder().build()) - .build(); + .setFileAppend(FileAppendTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileContentsQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileContentsQueryTest.java index 9911fb244..478c226ad 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileContentsQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileContentsQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,8 +37,9 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new FileContentsQuery() - .setFileId(FileId.fromString("0.0.5005")) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setFileId(FileId.fromString("0.0.5005")) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileCreateTransactionTest.java index d7e8208b7..4acf3cb60 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileCreateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileCreateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.FileCreateTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class FileCreateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,22 +45,20 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private FileCreateTransaction spawnTestTransaction() { return new FileCreateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setContents(new byte[]{1, 2, 3, 4}) - .setExpirationTime(Instant.ofEpochSecond(1554158728)) - .setKeys(unusedPrivateKey) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setFileMemo("Hello memo") - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setContents(new byte[] {1, 2, 3, 4}) + .setExpirationTime(Instant.ofEpochSecond(1554158728)) + .setKeys(unusedPrivateKey) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setFileMemo("Hello memo") + .freeze() + .sign(unusedPrivateKey); } @Test @@ -77,8 +71,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setFileCreate(FileCreateTransactionBody.newBuilder().build()) - .build(); + .setFileCreate(FileCreateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileDeleteTransactionTest.java index 2a40687f9..d5b444765 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileDeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.FileDeleteTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class FileDeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,19 +45,17 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private FileDeleteTransaction spawnTestTransaction() { return new FileDeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setFileId(FileId.fromString("0.0.6006")) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setFileId(FileId.fromString("0.0.6006")) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -74,8 +68,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setFileDelete(FileDeleteTransactionBody.newBuilder().build()) - .build(); + .setFileDelete(FileDeleteTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileIdTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileIdTest.java index cbcf26ab6..ae973fc97 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileIdTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileIdTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; @@ -47,15 +44,17 @@ void toBytes() throws InvalidProtocolBufferException { SnapshotMatcher.expect(Hex.toHexString(new FileId(5005).toBytes())).toMatchSnapshot(); } - @Test void fromBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(FileId.fromBytes(new FileId(5005).toBytes()).toString()).toMatchSnapshot(); + SnapshotMatcher.expect(FileId.fromBytes(new FileId(5005).toBytes()).toString()) + .toMatchSnapshot(); } @Test void fromSolidityAddress() { - SnapshotMatcher.expect(FileId.fromSolidityAddress("000000000000000000000000000000000000138D").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(FileId.fromSolidityAddress("000000000000000000000000000000000000138D") + .toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileInfoQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileInfoQueryTest.java index 2bb229aac..3fd819bd2 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileInfoQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileInfoQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,8 +37,9 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new FileInfoQuery() - .setFileId(FileId.fromString("0.0.5005")) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setFileId(FileId.fromString("0.0.5005")) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileInfoTest.java index 3fbbb64b4..d56461073 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileInfoTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,35 +12,32 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.FileGetInfoResponse; import com.hedera.hashgraph.sdk.proto.KeyList; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; - - public class FileInfoTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final FileGetInfoResponse.FileInfo info = FileGetInfoResponse.FileInfo.newBuilder() - .setFileID(new FileId(1).toProtobuf()) - .setSize(2) - .setExpirationTime(InstantConverter.toProtobuf(Instant.ofEpochMilli(3))) - .setDeleted(true) - .setKeys(KeyList.newBuilder() - .addKeys(privateKey.getPublicKey().toProtobufKey())) - .setLedgerId(LedgerId.MAINNET.toByteString()) - .build(); + .setFileID(new FileId(1).toProtobuf()) + .setSize(2) + .setExpirationTime(InstantConverter.toProtobuf(Instant.ofEpochMilli(3))) + .setDeleted(true) + .setKeys(KeyList.newBuilder().addKeys(privateKey.getPublicKey().toProtobufKey())) + .setLedgerId(LedgerId.MAINNET.toByteString()) + .build(); @BeforeAll public static void beforeAll() { @@ -57,25 +51,24 @@ public static void afterAll() { @Test void fromProtobuf() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(FileInfo.fromProtobuf(info).toString()) - .toMatchSnapshot(); + SnapshotMatcher.expect(FileInfo.fromProtobuf(info).toString()).toMatchSnapshot(); } @Test void toProtobuf() throws InvalidProtocolBufferException { SnapshotMatcher.expect(FileInfo.fromProtobuf(info).toProtobuf().toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { SnapshotMatcher.expect(FileInfo.fromBytes(info.toByteArray()).toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void toBytes() { SnapshotMatcher.expect(Hex.toHexString(FileInfo.fromProtobuf(info).toBytes())) - .toMatchSnapshot(); + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileUpdateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileUpdateTransactionTest.java index 70fba11b0..7f25d16c3 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FileUpdateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FileUpdateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.FileUpdateTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class FileUpdateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,23 +45,21 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private FileUpdateTransaction spawnTestTransaction() { return new FileUpdateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setFileId(FileId.fromString("0.0.6006")) - .setExpirationTime(Instant.ofEpochSecond(1554158728)) - .setContents(new byte[]{1, 2, 3, 4, 5}) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setKeys(unusedPrivateKey) - .setFileMemo("Hello memo") - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setFileId(FileId.fromString("0.0.6006")) + .setExpirationTime(Instant.ofEpochSecond(1554158728)) + .setContents(new byte[] {1, 2, 3, 4, 5}) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setKeys(unusedPrivateKey) + .setFileMemo("Hello memo") + .freeze() + .sign(unusedPrivateKey); } @Test @@ -78,8 +72,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setFileUpdate(FileUpdateTransactionBody.newBuilder().build()) - .build(); + .setFileUpdate(FileUpdateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/FreezeTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/FreezeTransactionTest.java index 51e1daf61..ba9ed750d 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/FreezeTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/FreezeTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,31 +12,30 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.google.protobuf.ByteString; import com.hedera.hashgraph.sdk.proto.FreezeTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.Timestamp; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class FreezeTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final FileId testFileId = FileId.fromString("4.5.6"); private static final byte[] testFileHash = Hex.decode("1723904587120938954702349857"); @@ -63,11 +59,16 @@ void shouldSerialize() { } private FreezeTransaction spawnTestTransaction() { - return new FreezeTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setFileId(testFileId).setFileHash(testFileHash).setStartTime(validStart).setFreezeType(testFreezeType) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)).freeze().sign(unusedPrivateKey); + return new FreezeTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setFileId(testFileId) + .setFileHash(testFileHash) + .setStartTime(validStart) + .setFreezeType(testFreezeType) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -80,7 +81,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setFreeze(FreezeTransactionBody.newBuilder().build()).build(); + .setFreeze(FreezeTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -89,10 +91,11 @@ void fromScheduledTransaction() { @Test void constructFreezeTransactionFromTransactionBodyProtobuf() { - var transactionBody = FreezeTransactionBody.newBuilder().setUpdateFile(testFileId.toProtobuf()) - .setFileHash(ByteString.copyFrom(testFileHash)) - .setStartTime(Timestamp.newBuilder().setSeconds(validStart.getEpochSecond())) - .setFreezeType(testFreezeType.code); + var transactionBody = FreezeTransactionBody.newBuilder() + .setUpdateFile(testFileId.toProtobuf()) + .setFileHash(ByteString.copyFrom(testFileHash)) + .setStartTime(Timestamp.newBuilder().setSeconds(validStart.getEpochSecond())) + .setFreezeType(testFreezeType.code); var tx = TransactionBody.newBuilder().setFreeze(transactionBody).build(); var freezeTransaction = new FreezeTransaction(tx); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/KeyTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/KeyTest.java index 4ca77a79e..367d5873b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/KeyTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/KeyTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,28 +12,27 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static com.hedera.hashgraph.sdk.Key.fromBytes; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.Key; import com.hedera.hashgraph.sdk.proto.KeyList; import com.hedera.hashgraph.sdk.proto.ThresholdKey; +import java.math.BigInteger; +import java.util.List; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.math.BigInteger; -import java.util.List; - -import static com.hedera.hashgraph.sdk.Key.fromBytes; -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNoException; - class KeyTest { @Test @DisplayName("can sign and verify a message") @@ -75,8 +71,8 @@ void calculateRecoveryIdECDSA() { System.arraycopy(signature, 0, r, 0, 32); final byte[] s = new byte[32]; System.arraycopy(signature, 32, s, 0, 32); - var recId = ((PrivateKeyECDSA) privateKey).getRecoveryId(r,s,message); - assertThat(recId).isBetween(0,1); + var recId = ((PrivateKeyECDSA) privateKey).getRecoveryId(r, s, message); + assertThat(recId).isBetween(0, 1); } @Test @@ -91,25 +87,25 @@ void failToCalculateRecoveryIdWithIllegalInputDataECDSA() { final byte[] s = new byte[32]; System.arraycopy(signature, 32, s, 0, 32); // recover public key with recId > 1 - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> Crypto.recoverPublicKeyECDSAFromSignature(2, BigInteger.ONE, BigInteger.ONE, Crypto.calcKeccak256(message)) - ); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Crypto.recoverPublicKeyECDSAFromSignature( + 2, BigInteger.ONE, BigInteger.ONE, Crypto.calcKeccak256(message))); // recover public key with negative 'r' or 's' - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> Crypto.recoverPublicKeyECDSAFromSignature(0, BigInteger.valueOf(-1), BigInteger.ONE, Crypto.calcKeccak256(message)) - ); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Crypto.recoverPublicKeyECDSAFromSignature( + 0, BigInteger.valueOf(-1), BigInteger.ONE, Crypto.calcKeccak256(message))); // calculate recId with wrong message var wrongMessage = "Hello".getBytes(UTF_8); - assertThatExceptionOfType(IllegalStateException.class).isThrownBy( - () -> ((PrivateKeyECDSA) privateKey).getRecoveryId(r,s,wrongMessage) - ); + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> ((PrivateKeyECDSA) privateKey).getRecoveryId(r, s, wrongMessage)); } @Test @DisplayName("can convert from protobuf ED25519 key to PublicKey") void fromProtoKeyEd25519() { var keyBytes = Hex.decode("0011223344556677889900112233445566778899001122334455667788990011"); - var protoKey = Key.newBuilder().setEd25519(ByteString.copyFrom(keyBytes)).build(); + var protoKey = + Key.newBuilder().setEd25519(ByteString.copyFrom(keyBytes)).build(); var cut = PublicKey.fromProtobufKey(protoKey); @@ -133,7 +129,7 @@ void fromProtoKeyECDSA() throws InvalidProtocolBufferException { @DisplayName("can convert from protobuf key list to PublicKey") void fromProtoKeyKeyList() { // given - var keyBytes = new byte[][]{ + var keyBytes = new byte[][] { Hex.decode("0011223344556677889900112233445566778899001122334455667788990011"), Hex.decode("aa11223344556677889900112233445566778899001122334455667788990011") }; @@ -164,7 +160,7 @@ void fromProtoKeyKeyList() { @DisplayName("can convert from protobuf threshold key to PublicKey") void fromProtoKeyThresholdKey() { // given - var keyBytes = new byte[][]{ + var keyBytes = new byte[][] { Hex.decode("0011223344556677889900112233445566778899001122334455667788990011"), Hex.decode("aa11223344556677889900112233445566778899001122334455667788990011") }; @@ -197,20 +193,20 @@ void fromProtoKeyThresholdKey() { @DisplayName("Throws given unsupported key") void throwsUnsupportedKey() { byte[] keyBytes = {0, 1, 2}; - var protoKey = Key.newBuilder().setRSA3072(ByteString.copyFrom(keyBytes)).build(); - assertThatExceptionOfType(IllegalStateException.class).isThrownBy( - () -> com.hedera.hashgraph.sdk.Key.fromProtobufKey(protoKey) - ); + var protoKey = + Key.newBuilder().setRSA3072(ByteString.copyFrom(keyBytes)).build(); + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(() -> com.hedera.hashgraph.sdk.Key.fromProtobufKey(protoKey)); } @Test @DisplayName("Key equals") void keyEquals() { var key1 = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); var key2 = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); assertThat(key2.toString()).isEqualTo(key1.toString()); assertThat(key2.getPublicKey()).isEqualTo(key1.getPublicKey()); @@ -221,7 +217,7 @@ void keyEquals() { @DisplayName("Key has hash") void keyHash() { var key = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); assertThatNoException().isThrownBy(key::hashCode); } @@ -230,13 +226,13 @@ void keyHash() { @DisplayName("KeyList methods") void keyListMethods() { var key1 = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); var key2 = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11"); var key3 = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12"); var keyList = com.hedera.hashgraph.sdk.KeyList.withThreshold(1); keyList.add(key1); @@ -253,7 +249,7 @@ void keyListMethods() { assertThat(arr[1]).isEqualTo(key2); assertThat(arr[2]).isEqualTo(key3); - arr = new com.hedera.hashgraph.sdk.Key[]{null, null, null}; + arr = new com.hedera.hashgraph.sdk.Key[] {null, null, null}; keyList.toArray(arr); assertThat(arr[0]).isEqualTo(key1); assertThat(arr[1]).isEqualTo(key2); @@ -280,7 +276,8 @@ void keyListMethods() { @DisplayName("can convert from bytes ED25519 key to Key") void fromBytesEd25519() throws InvalidProtocolBufferException { var keyBytes = Hex.decode("0011223344556677889900112233445566778899001122334455667788990011"); - var protoKey = Key.newBuilder().setEd25519(ByteString.copyFrom(keyBytes)).build(); + var protoKey = + Key.newBuilder().setEd25519(ByteString.copyFrom(keyBytes)).build(); var bytes = protoKey.toByteArray(); var cut = fromBytes(bytes); @@ -303,7 +300,7 @@ void fromBytesECDSA() throws InvalidProtocolBufferException { @Test @DisplayName("can convert from bytes key list to Key") void fromBytesKeyList() throws InvalidProtocolBufferException { - var keyBytes = new byte[][]{ + var keyBytes = new byte[][] { Hex.decode("0011223344556677889900112233445566778899001122334455667788990011"), Hex.decode("aa11223344556677889900112233445566778899001122334455667788990011") }; @@ -332,7 +329,7 @@ void fromBytesKeyList() throws InvalidProtocolBufferException { @Test @DisplayName("can convert from bytes threshold key to Key") void fromBytesThresholdKey() throws InvalidProtocolBufferException { - var keyBytes = new byte[][]{ + var keyBytes = new byte[][] { Hex.decode("0011223344556677889900112233445566778899001122334455667788990011"), Hex.decode("aa11223344556677889900112233445566778899001122334455667788990011") }; @@ -364,11 +361,10 @@ void fromBytesThresholdKey() throws InvalidProtocolBufferException { @DisplayName("Throws given unsupported key") void throwsUnsupportedKeyFromBytes() { byte[] keyBytes = {0, 1, 2}; - var protoKey = Key.newBuilder().setRSA3072(ByteString.copyFrom(keyBytes)).build(); + var protoKey = + Key.newBuilder().setRSA3072(ByteString.copyFrom(keyBytes)).build(); var bytes = protoKey.toByteArray(); - assertThatExceptionOfType(IllegalStateException.class).isThrownBy( - () -> fromBytes(bytes) - ); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> fromBytes(bytes)); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashAddTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashAddTransactionTest.java index d27509851..de8f63d76 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashAddTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashAddTransactionTest.java @@ -1,21 +1,36 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.ByteString; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; class LiveHashAddTransactionTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -31,21 +46,19 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private LiveHashAddTransaction spawnTestTransaction() { return new LiveHashAddTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(AccountId.fromString("0.0.100")) - .setHash(ByteString.copyFrom("hash", StandardCharsets.UTF_8)) - .setKeys(privateKey) - .setDuration(Duration.ofDays(30)) - .freeze() - .sign(privateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(AccountId.fromString("0.0.100")) + .setHash(ByteString.copyFrom("hash", StandardCharsets.UTF_8)) + .setKeys(privateKey) + .setDuration(Duration.ofDays(30)) + .freeze() + .sign(privateKey); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashDeleteTransactionTest.java index ed687d7f2..17dbea987 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashDeleteTransactionTest.java @@ -1,20 +1,35 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.ByteString; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; class LiveHashDeleteTransactionTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -30,19 +45,17 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private LiveHashDeleteTransaction spawnTestTransaction() { return new LiveHashDeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(AccountId.fromString("0.0.100")) - .setHash(ByteString.copyFrom("hash", StandardCharsets.UTF_8)) - .freeze() - .sign(privateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(AccountId.fromString("0.0.100")) + .setHash(ByteString.copyFrom("hash", StandardCharsets.UTF_8)) + .freeze() + .sign(privateKey); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashQueryTest.java index 5bc859aab..145f697a5 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/LiveHashQueryTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -23,9 +39,10 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new LiveHashQuery() - .setAccountId(AccountId.fromString("0.0.100")) - .setHash(hash) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setAccountId(AccountId.fromString("0.0.100")) + .setHash(hash) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/MessageSubmitTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/MessageSubmitTransactionTest.java index 187b0ecb9..40c42021e 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/MessageSubmitTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/MessageSubmitTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.ConsensusSubmitMessageTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class MessageSubmitTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -56,27 +52,26 @@ void shouldBytes() throws Exception { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TopicMessageSubmitTransaction spawnTestTransaction() { return new TopicMessageSubmitTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTopicId(TopicId.fromString("0.0.5007")) - .setMessage("hello") - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTopicId(TopicId.fromString("0.0.5007")) + .setMessage("hello") + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setConsensusSubmitMessage(ConsensusSubmitMessageTransactionBody.newBuilder().build()) - .build(); + .setConsensusSubmitMessage( + ConsensusSubmitMessageTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/NetworkVersionInfoQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NetworkVersionInfoQueryTest.java index d05f3fec6..5a079413b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/NetworkVersionInfoQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/NetworkVersionInfoQueryTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -23,18 +39,15 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new NetworkVersionInfoQuery() - .setMaxQueryPayment(Hbar.fromTinybars(100_000)) - .onMakeRequest( - builder, - QueryHeader - .newBuilder() - .setPayment( - Transaction.newBuilder() - .setSignedTransactionBytes( - ByteString.fromHex("deadbeef") - ).build() - ).build() - ); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setMaxQueryPayment(Hbar.fromTinybars(100_000)) + .onMakeRequest( + builder, + QueryHeader.newBuilder() + .setPayment(Transaction.newBuilder() + .setSignedTransactionBytes(ByteString.fromHex("deadbeef")) + .build()) + .build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/NetworkVersionInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NetworkVersionInfoTest.java index 3920aa6b3..800437692 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/NetworkVersionInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/NetworkVersionInfoTest.java @@ -1,12 +1,28 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class NetworkVersionInfoTest { @BeforeAll public static void beforeAll() { @@ -19,10 +35,7 @@ public static void afterAll() { } NetworkVersionInfo spawnNetworkVerionInfoExample() { - return new NetworkVersionInfo( - new SemanticVersion(1, 2, 3), - new SemanticVersion(4, 5, 6) - ); + return new NetworkVersionInfo(new SemanticVersion(1, 2, 3), new SemanticVersion(4, 5, 6)); } @Test @@ -31,7 +44,8 @@ void shouldSerialize() throws Exception { byte[] networkVersionInfoBytes = originalNetworkVersionInfo.toBytes(); var copyNetworkVersionInfo = NetworkVersionInfo.fromBytes(networkVersionInfoBytes); assertThat(originalNetworkVersionInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(copyNetworkVersionInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalNetworkVersionInfo.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(copyNetworkVersionInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalNetworkVersionInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/NftIdTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NftIdTest.java index cb313d93f..a056956c3 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/NftIdTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/NftIdTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.InvalidProtocolBufferException; import io.github.jsonSnapshot.SnapshotMatcher; +import java.util.concurrent.TimeoutException; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.concurrent.TimeoutException; - -import static org.assertj.core.api.Assertions.assertThat; - class NftIdTest { static Client mainnetClient; @@ -71,26 +67,32 @@ void toFromString() { @Test void fromStringWithChecksumOnMainnet() { - SnapshotMatcher.expect(NftId.fromString("0.0.123-vfmkw/7584").toStringWithChecksum(mainnetClient)).toMatchSnapshot(); + SnapshotMatcher.expect(NftId.fromString("0.0.123-vfmkw/7584").toStringWithChecksum(mainnetClient)) + .toMatchSnapshot(); } @Test void fromStringWithChecksumOnTestnet() { - SnapshotMatcher.expect(NftId.fromString("0.0.123-esxsf@584903").toStringWithChecksum(testnetClient)).toMatchSnapshot(); + SnapshotMatcher.expect(NftId.fromString("0.0.123-esxsf@584903").toStringWithChecksum(testnetClient)) + .toMatchSnapshot(); } @Test void fromStringWithChecksumOnPreviewnet() { - SnapshotMatcher.expect(NftId.fromString("0.0.123-ogizo/487302").toStringWithChecksum(previewnetClient)).toMatchSnapshot(); + SnapshotMatcher.expect(NftId.fromString("0.0.123-ogizo/487302").toStringWithChecksum(previewnetClient)) + .toMatchSnapshot(); } @Test void toBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(Hex.toHexString(new TokenId(5005).nft(4920).toBytes())).toMatchSnapshot(); + SnapshotMatcher.expect(Hex.toHexString(new TokenId(5005).nft(4920).toBytes())) + .toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(NftId.fromBytes(new TokenId(5005).nft(574489).toBytes()).toString()).toMatchSnapshot(); + SnapshotMatcher.expect( + NftId.fromBytes(new TokenId(5005).nft(574489).toBytes()).toString()) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java index 4760e728e..c30257f1e 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeCreateTransactionTest.java @@ -1,7 +1,4 @@ -/*- - * - * Hedera Java SDK - * +/* * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static org.assertj.core.api.Assertions.assertThat; @@ -37,32 +34,28 @@ public class NodeCreateTransactionTest { private static final PrivateKey TEST_PRIVATE_KEY = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final AccountId TEST_ACCOUNT_ID = AccountId.fromString("0.6.9"); private static final String TEST_DESCRIPTION = "Test description"; - private static final List TEST_GOSSIP_ENDPOINTS = List.of( - spawnTestEndpoint((byte) 0), - spawnTestEndpoint((byte) 1), - spawnTestEndpoint((byte) 2) - ); + private static final List TEST_GOSSIP_ENDPOINTS = + List.of(spawnTestEndpoint((byte) 0), spawnTestEndpoint((byte) 1), spawnTestEndpoint((byte) 2)); private static final List TEST_SERVICE_ENDPOINTS = List.of( - spawnTestEndpoint((byte) 3), - spawnTestEndpoint((byte) 4), - spawnTestEndpoint((byte) 5), - spawnTestEndpoint((byte) 6) - ); + spawnTestEndpoint((byte) 3), + spawnTestEndpoint((byte) 4), + spawnTestEndpoint((byte) 5), + spawnTestEndpoint((byte) 6)); - private static final byte[] TEST_GOSSIP_CA_CERTIFICATE = new byte[]{0, 1, 2, 3, 4}; + private static final byte[] TEST_GOSSIP_CA_CERTIFICATE = new byte[] {0, 1, 2, 3, 4}; - private static final byte[] TEST_GRPC_CERTIFICATE_HASH = new byte[]{5, 6, 7, 8, 9}; + private static final byte[] TEST_GRPC_CERTIFICATE_HASH = new byte[] {5, 6, 7, 8, 9}; private static final PublicKey TEST_ADMIN_KEY = PrivateKey.fromString( - "302e020100300506032b65700422042062c4b69e9f45a554e5424fb5a6fe5e6ac1f19ead31dc7718c2d980fd1f998d4b") - .getPublicKey(); + "302e020100300506032b65700422042062c4b69e9f45a554e5424fb5a6fe5e6ac1f19ead31dc7718c2d980fd1f998d4b") + .getPublicKey(); final Instant TEST_VALID_START = Instant.ofEpochSecond(1554158542); @@ -83,26 +76,25 @@ void shouldSerialize() { private static Endpoint spawnTestEndpoint(byte offset) { return new Endpoint() - .setAddress(new byte[] {0x00, 0x01, 0x02, 0x03}) - .setDomainName(offset + "unit.test.com") - .setPort(42 + offset); + .setAddress(new byte[] {0x00, 0x01, 0x02, 0x03}) + .setDomainName(offset + "unit.test.com") + .setPort(42 + offset); } private NodeCreateTransaction spawnTestTransaction() { return new NodeCreateTransaction() - .setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), TEST_VALID_START)) - .setAccountId(TEST_ACCOUNT_ID) - .setDescription(TEST_DESCRIPTION) - .setGossipEndpoints(TEST_GOSSIP_ENDPOINTS) - .setServiceEndpoints(TEST_SERVICE_ENDPOINTS) - .setGossipCaCertificate(TEST_GOSSIP_CA_CERTIFICATE) - .setGrpcCertificateHash(TEST_GRPC_CERTIFICATE_HASH) - .setAdminKey(TEST_ADMIN_KEY) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(TEST_PRIVATE_KEY); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), TEST_VALID_START)) + .setAccountId(TEST_ACCOUNT_ID) + .setDescription(TEST_DESCRIPTION) + .setGossipEndpoints(TEST_GOSSIP_ENDPOINTS) + .setServiceEndpoints(TEST_SERVICE_ENDPOINTS) + .setGossipCaCertificate(TEST_GOSSIP_CA_CERTIFICATE) + .setGrpcCertificateHash(TEST_GRPC_CERTIFICATE_HASH) + .setAdminKey(TEST_ADMIN_KEY) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(TEST_PRIVATE_KEY); } @Test @@ -115,7 +107,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setNodeCreate(NodeCreateTransactionBody.newBuilder().build()).build(); + .setNodeCreate(NodeCreateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -141,7 +134,9 @@ void constructNodeCreateTransactionFromTransactionBodyProtobuf() { transactionBodyBuilder.setGrpcCertificateHash(ByteString.copyFrom(TEST_GRPC_CERTIFICATE_HASH)); transactionBodyBuilder.setAdminKey(TEST_ADMIN_KEY.toProtobufKey()); - var tx = TransactionBody.newBuilder().setNodeCreate(transactionBodyBuilder.build()).build(); + var tx = TransactionBody.newBuilder() + .setNodeCreate(transactionBodyBuilder.build()) + .build(); var nodeCreateTransaction = new NodeCreateTransaction(tx); assertThat(nodeCreateTransaction.getAccountId()).isEqualTo(TEST_ACCOUNT_ID); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeDeleteTransactionTest.java index 67ea54004..1537a526f 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeDeleteTransactionTest.java @@ -1,7 +1,4 @@ -/*- - * - * Hedera Java SDK - * +/* * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +32,7 @@ public class NodeDeleteTransactionTest { private static final PrivateKey TEST_PRIVATE_KEY = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final long TEST_NODE_ID = 420; @@ -58,13 +55,12 @@ void shouldSerialize() { private NodeDeleteTransaction spawnTestTransaction() { return new NodeDeleteTransaction() - .setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), TEST_VALID_START)) - .setNodeId(TEST_NODE_ID) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(TEST_PRIVATE_KEY); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), TEST_VALID_START)) + .setNodeId(TEST_NODE_ID) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(TEST_PRIVATE_KEY); } @Test @@ -77,7 +73,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setNodeDelete(NodeDeleteTransactionBody.newBuilder().build()).build(); + .setNodeDelete(NodeDeleteTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -90,7 +87,9 @@ void constructNodeDeleteTransactionFromTransactionBodyProtobuf() { transactionBodyBuilder.setNodeId(TEST_NODE_ID); - var tx = TransactionBody.newBuilder().setNodeDelete(transactionBodyBuilder.build()).build(); + var tx = TransactionBody.newBuilder() + .setNodeDelete(transactionBodyBuilder.build()) + .build(); var nodeDeleteTransaction = new NodeDeleteTransaction(tx); assertThat(nodeDeleteTransaction.getNodeId()).isEqualTo(TEST_NODE_ID); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeUpdateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeUpdateTransactionTest.java index b07b52c90..1b7732396 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeUpdateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/NodeUpdateTransactionTest.java @@ -1,7 +1,4 @@ -/*- - * - * Hedera Java SDK - * +/* * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static org.assertj.core.api.Assertions.assertThat; @@ -39,7 +36,7 @@ public class NodeUpdateTransactionTest { private static final PrivateKey TEST_PRIVATE_KEY = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final long TEST_NODE_ID = 420; @@ -47,26 +44,22 @@ public class NodeUpdateTransactionTest { private static final String TEST_DESCRIPTION = "Test description"; - private static final List TEST_GOSSIP_ENDPOINTS = List.of( - spawnTestEndpoint((byte) 0), - spawnTestEndpoint((byte) 1), - spawnTestEndpoint((byte) 2) - ); + private static final List TEST_GOSSIP_ENDPOINTS = + List.of(spawnTestEndpoint((byte) 0), spawnTestEndpoint((byte) 1), spawnTestEndpoint((byte) 2)); private static final List TEST_SERVICE_ENDPOINTS = List.of( - spawnTestEndpoint((byte) 3), - spawnTestEndpoint((byte) 4), - spawnTestEndpoint((byte) 5), - spawnTestEndpoint((byte) 6) - ); + spawnTestEndpoint((byte) 3), + spawnTestEndpoint((byte) 4), + spawnTestEndpoint((byte) 5), + spawnTestEndpoint((byte) 6)); - private static final byte[] TEST_GOSSIP_CA_CERTIFICATE = new byte[]{0, 1, 2, 3, 4}; + private static final byte[] TEST_GOSSIP_CA_CERTIFICATE = new byte[] {0, 1, 2, 3, 4}; - private static final byte[] TEST_GRPC_CERTIFICATE_HASH = new byte[]{5, 6, 7, 8, 9}; + private static final byte[] TEST_GRPC_CERTIFICATE_HASH = new byte[] {5, 6, 7, 8, 9}; private static final PublicKey TEST_ADMIN_KEY = PrivateKey.fromString( - "302e020100300506032b65700422042062c4b69e9f45a554e5424fb5a6fe5e6ac1f19ead31dc7718c2d980fd1f998d4b") - .getPublicKey(); + "302e020100300506032b65700422042062c4b69e9f45a554e5424fb5a6fe5e6ac1f19ead31dc7718c2d980fd1f998d4b") + .getPublicKey(); final Instant TEST_VALID_START = Instant.ofEpochSecond(1554158542); @@ -87,28 +80,27 @@ void shouldSerialize() { private static Endpoint spawnTestEndpoint(byte offset) { return new Endpoint() - .setAddress(new byte[] {0x00, 0x01, 0x02, 0x03}) - .setDomainName(offset + "unit.test.com") - .setPort(42 + offset); + .setAddress(new byte[] {0x00, 0x01, 0x02, 0x03}) + .setDomainName(offset + "unit.test.com") + .setPort(42 + offset); } private NodeUpdateTransaction spawnTestTransaction() { return new NodeUpdateTransaction() - .setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), TEST_VALID_START)) - .setNodeId(TEST_NODE_ID) - .setAccountId(TEST_ACCOUNT_ID) - .setAccountId(TEST_ACCOUNT_ID) - .setDescription(TEST_DESCRIPTION) - .setGossipEndpoints(TEST_GOSSIP_ENDPOINTS) - .setServiceEndpoints(TEST_SERVICE_ENDPOINTS) - .setGossipCaCertificate(TEST_GOSSIP_CA_CERTIFICATE) - .setGrpcCertificateHash(TEST_GRPC_CERTIFICATE_HASH) - .setAdminKey(TEST_ADMIN_KEY) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(TEST_PRIVATE_KEY); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), TEST_VALID_START)) + .setNodeId(TEST_NODE_ID) + .setAccountId(TEST_ACCOUNT_ID) + .setAccountId(TEST_ACCOUNT_ID) + .setDescription(TEST_DESCRIPTION) + .setGossipEndpoints(TEST_GOSSIP_ENDPOINTS) + .setServiceEndpoints(TEST_SERVICE_ENDPOINTS) + .setGossipCaCertificate(TEST_GOSSIP_CA_CERTIFICATE) + .setGrpcCertificateHash(TEST_GRPC_CERTIFICATE_HASH) + .setAdminKey(TEST_ADMIN_KEY) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(TEST_PRIVATE_KEY); } @Test @@ -121,7 +113,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setNodeUpdate(NodeUpdateTransactionBody.newBuilder().build()).build(); + .setNodeUpdate(NodeUpdateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -148,7 +141,9 @@ void constructNodeUpdateTransactionFromTransactionBodyProtobuf() { transactionBodyBuilder.setGrpcCertificateHash(BytesValue.of(ByteString.copyFrom(TEST_GRPC_CERTIFICATE_HASH))); transactionBodyBuilder.setAdminKey(TEST_ADMIN_KEY.toProtobufKey()); - var tx = TransactionBody.newBuilder().setNodeUpdate(transactionBodyBuilder.build()).build(); + var tx = TransactionBody.newBuilder() + .setNodeUpdate(transactionBodyBuilder.build()) + .build(); var nodeUpdateTransaction = new NodeUpdateTransaction(tx); assertThat(nodeUpdateTransaction.getNodeId()).isEqualTo(TEST_NODE_ID); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/PrngTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/PrngTransactionTest.java index 948076080..6a341c85b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/PrngTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/PrngTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,22 +12,21 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - public class PrngTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -46,34 +42,30 @@ public static void afterAll() { private PrngTransaction spawnTestTransaction() { return new PrngTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } private PrngTransaction spawnTestTransaction2() { return new PrngTransaction() - .setRange(100) - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setRange(100) + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } @Test void shouldSerialize2() { - SnapshotMatcher.expect(spawnTestTransaction2() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction2().toString()).toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ProxyStakerTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ProxyStakerTest.java index 0ab2f70eb..ca6eccb7d 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ProxyStakerTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ProxyStakerTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.ProxyStaker; @@ -8,9 +24,9 @@ public class ProxyStakerTest { private static final ProxyStaker proxyStaker = ProxyStaker.newBuilder() - .setAccountID(new AccountId(100).toProtobuf()) - .setAmount(10) - .build(); + .setAccountID(new AccountId(100).toProtobuf()) + .setAmount(10) + .build(); @BeforeAll public static void beforeAll() { @@ -24,7 +40,8 @@ public static void afterAll() { @Test void fromProtobuf() { - SnapshotMatcher.expect(com.hedera.hashgraph.sdk.ProxyStaker.fromProtobuf(proxyStaker).toString()) - .toMatchSnapshot(); + SnapshotMatcher.expect(com.hedera.hashgraph.sdk.ProxyStaker.fromProtobuf(proxyStaker) + .toString()) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleCreateTransactionTest.java index ff055cce1..e99124bd3 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleCreateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleCreateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,23 +12,22 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class ScheduleCreateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -45,28 +41,26 @@ public static void afterAll() { SnapshotMatcher.validateSnapshots(); } - @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private ScheduleCreateTransaction spawnTestTransaction() { var transferTransaction = new TransferTransaction() - .addHbarTransfer(AccountId.fromString("0.0.555"), new Hbar(-10)) - .addHbarTransfer(AccountId.fromString("0.0.333"), new Hbar(10)); - return transferTransaction.schedule() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAdminKey(unusedPrivateKey) - .setPayerAccountId(AccountId.fromString("0.0.222")) - .setScheduleMemo("hi") - .setMaxTransactionFee(new Hbar(1)) - .setExpirationTime(validStart) - .freeze() - .sign(unusedPrivateKey); + .addHbarTransfer(AccountId.fromString("0.0.555"), new Hbar(-10)) + .addHbarTransfer(AccountId.fromString("0.0.333"), new Hbar(10)); + return transferTransaction + .schedule() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAdminKey(unusedPrivateKey) + .setPayerAccountId(AccountId.fromString("0.0.222")) + .setScheduleMemo("hi") + .setMaxTransactionFee(new Hbar(1)) + .setExpirationTime(validStart) + .freeze() + .sign(unusedPrivateKey); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleDeleteTransactionTest.java index d9eed28d1..5643bccd9 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleDeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.ScheduleDeleteTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class ScheduleDeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,19 +45,17 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private ScheduleDeleteTransaction spawnTestTransaction() { return new ScheduleDeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setScheduleId(ScheduleId.fromString("0.0.444")) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setScheduleId(ScheduleId.fromString("0.0.444")) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -74,8 +68,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setScheduleDelete(ScheduleDeleteTransactionBody.newBuilder().build()) - .build(); + .setScheduleDelete(ScheduleDeleteTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleInfoQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleInfoQueryTest.java index 31d584475..d8bdb4941 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleInfoQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleInfoQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,9 +37,10 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new ScheduleInfoQuery() - .setScheduleId(ScheduleId.fromString("0.0.5005")) - .setMaxQueryPayment(Hbar.fromTinybars(100_000)) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setScheduleId(ScheduleId.fromString("0.0.5005")) + .setMaxQueryPayment(Hbar.fromTinybars(100_000)) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleInfoTest.java index 4f15f7c45..3b1f9f9b1 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleInfoTest.java @@ -1,20 +1,35 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.CryptoDeleteTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; - -import static org.assertj.core.api.Assertions.assertThat; - public class ScheduleInfoTest { private static final PublicKey unusedPublicKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10" - ).getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10") + .getPublicKey(); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -30,42 +45,46 @@ public static void afterAll() { ScheduleInfo spawnScheduleInfoExample() { return new ScheduleInfo( - ScheduleId.fromString("1.2.3"), - AccountId.fromString("4.5.6"), - AccountId.fromString("2.3.4"), - SchedulableTransactionBody.newBuilder() - .setCryptoDelete(CryptoDeleteTransactionBody.newBuilder() - .setDeleteAccountID(AccountId.fromString("6.6.6").toProtobuf()).build()).build(), - KeyList.of(unusedPublicKey), - unusedPublicKey, - TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart), - "memo", - validStart, - validStart, - null, - LedgerId.TESTNET, - true - ); + ScheduleId.fromString("1.2.3"), + AccountId.fromString("4.5.6"), + AccountId.fromString("2.3.4"), + SchedulableTransactionBody.newBuilder() + .setCryptoDelete(CryptoDeleteTransactionBody.newBuilder() + .setDeleteAccountID( + AccountId.fromString("6.6.6").toProtobuf()) + .build()) + .build(), + KeyList.of(unusedPublicKey), + unusedPublicKey, + TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart), + "memo", + validStart, + validStart, + null, + LedgerId.TESTNET, + true); } ScheduleInfo spawnScheduleInfoDeletedExample() { return new ScheduleInfo( - ScheduleId.fromString("1.2.3"), - AccountId.fromString("4.5.6"), - AccountId.fromString("2.3.4"), - SchedulableTransactionBody.newBuilder() - .setCryptoDelete(CryptoDeleteTransactionBody.newBuilder() - .setDeleteAccountID(AccountId.fromString("6.6.6").toProtobuf()).build()).build(), - KeyList.of(unusedPublicKey), - unusedPublicKey, - TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart), - "memo", - validStart, - null, - validStart, - LedgerId.TESTNET, - true - ); + ScheduleId.fromString("1.2.3"), + AccountId.fromString("4.5.6"), + AccountId.fromString("2.3.4"), + SchedulableTransactionBody.newBuilder() + .setCryptoDelete(CryptoDeleteTransactionBody.newBuilder() + .setDeleteAccountID( + AccountId.fromString("6.6.6").toProtobuf()) + .build()) + .build(), + KeyList.of(unusedPublicKey), + unusedPublicKey, + TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart), + "memo", + validStart, + null, + validStart, + LedgerId.TESTNET, + true); } @Test @@ -74,8 +93,9 @@ void shouldSerialize() throws Exception { byte[] scheduleInfoBytes = originalScheduleInfo.toBytes(); var copyScheduleInfo = ScheduleInfo.fromBytes(scheduleInfoBytes); assertThat(copyScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(originalScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(originalScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test @@ -84,7 +104,8 @@ void shouldSerializeDeleted() throws Exception { byte[] scheduleInfoBytes = originalScheduleInfo.toBytes(); var copyScheduleInfo = ScheduleInfo.fromBytes(scheduleInfoBytes); assertThat(copyScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(originalScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(originalScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalScheduleInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleSignTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleSignTransactionTest.java index 6c987f231..aa5149ed1 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleSignTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ScheduleSignTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,23 +12,22 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class ScheduleSignTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -47,19 +43,17 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private ScheduleSignTransaction spawnTestTransaction() { return new ScheduleSignTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setScheduleId(ScheduleId.fromString("0.0.444")) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setScheduleId(ScheduleId.fromString("0.0.444")) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/Snapshot.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/Snapshot.java index 8487204e8..1c39eb6b7 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/Snapshot.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/Snapshot.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; import com.fasterxml.jackson.annotation.JsonAutoDetect; @@ -7,13 +23,11 @@ import com.fasterxml.jackson.core.PrettyPrinter; import com.fasterxml.jackson.core.util.DefaultIndenter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; -import com.fasterxml.jackson.core.util.Separators; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; - -import javax.annotation.Nonnull; import java.io.IOException; import java.io.UncheckedIOException; +import javax.annotation.Nonnull; final class Snapshot { private static final ObjectMapper objectMapper = buildObjectMapper(); @@ -40,8 +54,7 @@ private static ObjectMapper buildObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - objectMapper.setVisibility( - objectMapper + objectMapper.setVisibility(objectMapper .getSerializationConfig() .getDefaultVisibilityChecker() .withFieldVisibility(JsonAutoDetect.Visibility.ANY) @@ -55,18 +68,18 @@ private static ObjectMapper buildObjectMapper() { * Modified copy of {@code io.github.jsonSnapshot.SnapshotMatcher#buildDefaultPrettyPrinter} */ private static PrettyPrinter buildDefaultPrettyPrinter() { - DefaultPrettyPrinter pp = - new DefaultPrettyPrinter() { - @Override - @Nonnull - public DefaultPrettyPrinter createInstance() { - return this; - } - @Override - public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException { - jg.writeRaw(": "); - } - }; + DefaultPrettyPrinter pp = new DefaultPrettyPrinter() { + @Override + @Nonnull + public DefaultPrettyPrinter createInstance() { + return this; + } + + @Override + public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException { + jg.writeRaw(": "); + } + }; DefaultPrettyPrinter.Indenter lfOnlyIndenter = new DefaultIndenter(" ", "\n"); pp.indentArraysWith(lfOnlyIndenter); pp.indentObjectsWith(lfOnlyIndenter); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/StakingInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/StakingInfoTest.java index e4af2fdcd..d291d596f 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/StakingInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/StakingInfoTest.java @@ -1,14 +1,29 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; - -import static org.assertj.core.api.Assertions.assertThat; - public class StakingInfoTest { final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -23,25 +38,11 @@ public static void afterAll() { } StakingInfo spawnStakingInfoAccountExample() { - return new StakingInfo( - true, - validStart, - Hbar.from(5), - Hbar.from(10), - AccountId.fromString("1.2.3"), - null - ); + return new StakingInfo(true, validStart, Hbar.from(5), Hbar.from(10), AccountId.fromString("1.2.3"), null); } StakingInfo spawnStakingInfoNodeExample() { - return new StakingInfo( - true, - validStart, - Hbar.from(5), - Hbar.from(10), - null, - 3L - ); + return new StakingInfo(true, validStart, Hbar.from(5), Hbar.from(10), null, 3L); } @Test @@ -50,8 +51,9 @@ void shouldSerializeAccount() throws Exception { byte[] stakingInfoBytes = originalStakingInfo.toBytes(); var copyStakingInfo = StakingInfo.fromBytes(stakingInfoBytes); assertThat(copyStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(originalStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(originalStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test @@ -60,7 +62,8 @@ void shouldSerializeNode() throws Exception { byte[] stakingInfoBytes = originalStakingInfo.toBytes(); var copyStakingInfo = StakingInfo.fromBytes(stakingInfoBytes); assertThat(copyStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(originalStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(originalStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalStakingInfo.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/SystemDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/SystemDeleteTransactionTest.java index 625e58a5e..fa06da0ce 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/SystemDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/SystemDeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,31 +12,30 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.SystemDeleteTransactionBody; import com.hedera.hashgraph.sdk.proto.TimestampSeconds; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class SystemDeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final FileId testFileId = FileId.fromString("4.2.0"); private static final ContractId testContractId = ContractId.fromString("0.6.9"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -60,11 +56,14 @@ void shouldSerializeFile() { } private SystemDeleteTransaction spawnTestTransactionFile() { - return new SystemDeleteTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setFileId(FileId.fromString("0.0.444")).setExpirationTime(validStart).setMaxTransactionFee(new Hbar(1)) - .freeze().sign(unusedPrivateKey); + return new SystemDeleteTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setFileId(FileId.fromString("0.0.444")) + .setExpirationTime(validStart) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -73,11 +72,14 @@ void shouldSerializeContract() { } private SystemDeleteTransaction spawnTestTransactionContract() { - return new SystemDeleteTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setContractId(ContractId.fromString("0.0.444")).setExpirationTime(validStart) - .setMaxTransactionFee(new Hbar(1)).freeze().sign(unusedPrivateKey); + return new SystemDeleteTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setContractId(ContractId.fromString("0.0.444")) + .setExpirationTime(validStart) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -97,7 +99,8 @@ void shouldBytesFile() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setSystemDelete(SystemDeleteTransactionBody.newBuilder().build()).build(); + .setSystemDelete(SystemDeleteTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -106,30 +109,35 @@ void fromScheduledTransaction() { @Test void constructSystemDeleteTransactionFromTransactionBodyProtobuf() { - var transactionBodyWithFileId = SystemDeleteTransactionBody.newBuilder().setFileID(testFileId.toProtobuf()) - .setExpirationTime(TimestampSeconds.newBuilder().setSeconds(validStart.getEpochSecond())); + var transactionBodyWithFileId = SystemDeleteTransactionBody.newBuilder() + .setFileID(testFileId.toProtobuf()) + .setExpirationTime(TimestampSeconds.newBuilder().setSeconds(validStart.getEpochSecond())); var transactionBodyWithContractId = SystemDeleteTransactionBody.newBuilder() - .setContractID(testContractId.toProtobuf()) - .setExpirationTime(TimestampSeconds.newBuilder().setSeconds(validStart.getEpochSecond())); + .setContractID(testContractId.toProtobuf()) + .setExpirationTime(TimestampSeconds.newBuilder().setSeconds(validStart.getEpochSecond())); - var txWithFileId = TransactionBody.newBuilder().setSystemDelete(transactionBodyWithFileId).build(); + var txWithFileId = TransactionBody.newBuilder() + .setSystemDelete(transactionBodyWithFileId) + .build(); var systemDeleteTransactionWithFileId = new SystemDeleteTransaction(txWithFileId); - var txWithContractId = TransactionBody.newBuilder().setSystemDelete(transactionBodyWithContractId).build(); + var txWithContractId = TransactionBody.newBuilder() + .setSystemDelete(transactionBodyWithContractId) + .build(); var systemDeleteTransactionWithContractId = new SystemDeleteTransaction(txWithContractId); assertNotNull(systemDeleteTransactionWithFileId.getFileId()); assertThat(systemDeleteTransactionWithFileId.getFileId()).isEqualTo(testFileId); assertNull(systemDeleteTransactionWithFileId.getContractId()); - assertThat(systemDeleteTransactionWithFileId.getExpirationTime().getEpochSecond()).isEqualTo( - validStart.getEpochSecond()); + assertThat(systemDeleteTransactionWithFileId.getExpirationTime().getEpochSecond()) + .isEqualTo(validStart.getEpochSecond()); assertNull(systemDeleteTransactionWithContractId.getFileId()); assertNotNull(systemDeleteTransactionWithContractId.getContractId()); assertThat(systemDeleteTransactionWithContractId.getContractId()).isEqualTo(testContractId); - assertThat(systemDeleteTransactionWithContractId.getExpirationTime().getEpochSecond()).isEqualTo( - validStart.getEpochSecond()); + assertThat(systemDeleteTransactionWithContractId.getExpirationTime().getEpochSecond()) + .isEqualTo(validStart.getEpochSecond()); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/SystemUndeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/SystemUndeleteTransactionTest.java index 965d07aef..67c3d46e0 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/SystemUndeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/SystemUndeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.SystemUndeleteTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class SystemUndeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,36 +45,32 @@ public static void afterAll() { @Test void shouldSerializeFile() { - SnapshotMatcher.expect(spawnTestTransactionFile() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransactionFile().toString()).toMatchSnapshot(); } private SystemUndeleteTransaction spawnTestTransactionFile() { return new SystemUndeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setFileId(FileId.fromString("0.0.444")) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setFileId(FileId.fromString("0.0.444")) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test void shouldSerializeContract() { - SnapshotMatcher.expect(spawnTestTransactionContract() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransactionContract().toString()).toMatchSnapshot(); } private SystemUndeleteTransaction spawnTestTransactionContract() { return new SystemUndeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setContractId(ContractId.fromString("0.0.444")) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setContractId(ContractId.fromString("0.0.444")) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -98,8 +90,8 @@ void shouldBytesFile() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setSystemUndelete(SystemUndeleteTransactionBody.newBuilder().build()) - .build(); + .setSystemUndelete(SystemUndeleteTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAirdropTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAirdropTransactionTest.java index e0708b937..dfb380cc1 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAirdropTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAirdropTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static org.assertj.core.api.Assertions.assertThat; @@ -40,7 +37,7 @@ class TokenAirdropTransactionTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); private TokenAirdropTransaction transaction; @@ -62,30 +59,46 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TokenAirdropTransaction spawnTestTransaction() { return new TokenAirdropTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .addTokenTransfer(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5008"), 400) - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5006"), -800, 3) - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5007"), 400, 3) - .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5008"), 1) - .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), -1) - .addNftTransfer(TokenId.fromString("0.0.3").nft(2), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5007")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(1), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5007")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(3), AccountId.fromString("0.0.5008"), AccountId.fromString("0.0.5006")) - .addNftTransfer(TokenId.fromString("0.0.3").nft(4), AccountId.fromString("0.0.5007"), AccountId.fromString("0.0.5006")) - .addNftTransfer(TokenId.fromString("0.0.2").nft(4), AccountId.fromString("0.0.5007"), AccountId.fromString("0.0.5006")) - .addApprovedTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), 123) - .addApprovedNftTransfer(new NftId(TokenId.fromString("0.0.4"), 4), AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(privateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .addTokenTransfer(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5008"), 400) + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5006"), -800, 3) + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.5007"), 400, 3) + .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5008"), 1) + .addTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), -1) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(2), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5007")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(1), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5007")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(3), + AccountId.fromString("0.0.5008"), + AccountId.fromString("0.0.5006")) + .addNftTransfer( + TokenId.fromString("0.0.3").nft(4), + AccountId.fromString("0.0.5007"), + AccountId.fromString("0.0.5006")) + .addNftTransfer( + TokenId.fromString("0.0.2").nft(4), + AccountId.fromString("0.0.5007"), + AccountId.fromString("0.0.5006")) + .addApprovedTokenTransfer(TokenId.fromString("0.0.4"), AccountId.fromString("0.0.5006"), 123) + .addApprovedNftTransfer( + new NftId(TokenId.fromString("0.0.4"), 4), + AccountId.fromString("0.0.5005"), + AccountId.fromString("0.0.5006")) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(privateKey); } @Test @@ -99,8 +112,8 @@ void shouldBytes() throws Exception { void decimalsMustBeConsistent() { assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { new TokenAirdropTransaction() - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.8"), 100, 2) - .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.7"), -100, 3); + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.8"), 100, 2) + .addTokenTransferWithDecimals(TokenId.fromString("0.0.5"), AccountId.fromString("0.0.7"), -100, 3); }); } @@ -117,8 +130,8 @@ void canGetDecimals() { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenAirdrop(TokenAirdropTransactionBody.newBuilder().build()) - .build(); + .setTokenAirdrop(TokenAirdropTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -127,7 +140,8 @@ void fromScheduledTransaction() { @Test void testDefaultMaxTransactionFeeIsSet() { - assertEquals(new Hbar(1), transaction.getDefaultMaxTransactionFee(), "Default max transaction fee should be 1 Hbar"); + assertEquals( + new Hbar(1), transaction.getDefaultMaxTransactionFee(), "Default max transaction fee should be 1 Hbar"); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAssociateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAssociateTransactionTest.java index ae14c4200..b26ea762d 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAssociateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAssociateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,33 +12,31 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenAssociateTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Instant; import java.util.Arrays; import java.util.Collections; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TokenAssociateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final AccountId accountId = AccountId.fromString("1.2.3"); - private static final List tokenIds = List.of(TokenId.fromString("4.5.6"), - TokenId.fromString("7.8.9"), - TokenId.fromString("10.11.12")); + private static final List tokenIds = + List.of(TokenId.fromString("4.5.6"), TokenId.fromString("7.8.9"), TokenId.fromString("10.11.12")); final Instant validStart = Instant.ofEpochSecond(1554158542); @BeforeAll @@ -56,20 +51,18 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TokenAssociateTransaction spawnTestTransaction() { return new TokenAssociateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(AccountId.fromString("0.0.222")) - .setTokenIds(Collections.singletonList(TokenId.fromString("0.0.666"))) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(AccountId.fromString("0.0.222")) + .setTokenIds(Collections.singletonList(TokenId.fromString("0.0.666"))) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -82,8 +75,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenAssociate(TokenAssociateTransactionBody.newBuilder().build()) - .build(); + .setTokenAssociate(TokenAssociateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -93,9 +86,11 @@ void fromScheduledTransaction() { @Test void constructTokenDeleteTransactionFromTransactionBodyProtobuf() { var transactionBody = TokenAssociateTransactionBody.newBuilder() - .addAllTokens(tokenIds.stream().map(TokenId::toProtobuf).toList()) - .setAccount(accountId.toProtobuf()).build(); - var txBody = TransactionBody.newBuilder().setTokenAssociate(transactionBody).build(); + .addAllTokens(tokenIds.stream().map(TokenId::toProtobuf).toList()) + .setAccount(accountId.toProtobuf()) + .build(); + var txBody = + TransactionBody.newBuilder().setTokenAssociate(transactionBody).build(); var tokenAssociateTransaction = new TokenAssociateTransaction(txBody); assertThat(tokenAssociateTransaction.getAccountId()).isEqualTo(accountId); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAssociationTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAssociationTest.java index d2adbfee7..7738095ce 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAssociationTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenAssociationTest.java @@ -1,15 +1,30 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + import com.google.protobuf.InvalidProtocolBufferException; import io.github.jsonSnapshot.SnapshotMatcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; - - public class TokenAssociationTest { private static final AccountId testAccountId = AccountId.fromString("4.2.0"); private static final TokenId testTokenId = TokenId.fromString("0.6.9"); @@ -25,10 +40,7 @@ public static void afterAll() { } TokenAssociation spawnTokenAssociationExample() { - return new TokenAssociation( - TokenId.fromString("1.2.3"), - AccountId.fromString("4.5.6") - ); + return new TokenAssociation(TokenId.fromString("1.2.3"), AccountId.fromString("4.5.6")); } @Test @@ -37,8 +49,9 @@ void shouldSerializeAccount() throws Exception { byte[] tokenAssociationBytes = originalTokenAssociation.toBytes(); var copyTokenAssociation = TokenAssociation.fromBytes(tokenAssociationBytes); assertThat(copyTokenAssociation.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(originalTokenAssociation.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalTokenAssociation.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(originalTokenAssociation.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalTokenAssociation.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test @@ -59,12 +72,9 @@ void toProtobuf() { assertThat(tokenAssociationProtobuf.getAccountId().getRealmNum()).isEqualTo(testAccountId.realm); assertThat(tokenAssociationProtobuf.getAccountId().getAccountNum()).isEqualTo(testAccountId.num); assertTrue(tokenAssociationProtobuf.hasTokenId()); - assertThat(tokenAssociationProtobuf.getTokenId().getShardNum()).isEqualTo( - testTokenId.shard); - assertThat(tokenAssociationProtobuf.getTokenId().getRealmNum()).isEqualTo( - testTokenId.realm); - assertThat(tokenAssociationProtobuf.getTokenId().getTokenNum()).isEqualTo( - testTokenId.num); + assertThat(tokenAssociationProtobuf.getTokenId().getShardNum()).isEqualTo(testTokenId.shard); + assertThat(tokenAssociationProtobuf.getTokenId().getRealmNum()).isEqualTo(testTokenId.realm); + assertThat(tokenAssociationProtobuf.getTokenId().getTokenNum()).isEqualTo(testTokenId.num); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenBurnTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenBurnTransactionTest.java index 300972dec..5fa5b559f 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenBurnTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenBurnTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,29 +12,28 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenBurnTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Instant; import java.util.Arrays; import java.util.Collections; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TokenBurnTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final TokenId testTokenId = TokenId.fromString("4.2.0"); private static final long testAmount = 69L; private static final List testSerials = Collections.singletonList(420L); @@ -59,11 +55,14 @@ void shouldSerializeFungible() { } private TokenBurnTransaction spawnTestTransaction() { - return new TokenBurnTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(testTokenId).setAmount(testAmount).setMaxTransactionFee(new Hbar(1)).freeze() - .sign(unusedPrivateKey); + return new TokenBurnTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(testTokenId) + .setAmount(testAmount) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -72,11 +71,14 @@ void shouldSerializeNft() { } private TokenBurnTransaction spawnTestTransactionNft() { - return new TokenBurnTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(testTokenId).setSerials(testSerials).setMaxTransactionFee(new Hbar(1)).freeze() - .sign(unusedPrivateKey); + return new TokenBurnTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(testTokenId) + .setSerials(testSerials) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -96,7 +98,8 @@ void shouldBytesNft() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenBurn(TokenBurnTransactionBody.newBuilder().build()).build(); + .setTokenBurn(TokenBurnTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -105,8 +108,11 @@ void fromScheduledTransaction() { @Test void constructTokenBurnTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenBurnTransactionBody.newBuilder().setToken(testTokenId.toProtobuf()) - .setAmount(testAmount).addAllSerialNumbers(testSerials).build(); + var transactionBody = TokenBurnTransactionBody.newBuilder() + .setToken(testTokenId.toProtobuf()) + .setAmount(testAmount) + .addAllSerialNumbers(testSerials) + .build(); var tx = TransactionBody.newBuilder().setTokenBurn(transactionBody).build(); var tokenBurnTransaction = new TokenBurnTransaction(tx); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenCancelAirdropTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenCancelAirdropTransactionTest.java index 548e0b5e6..9c25cc105 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenCancelAirdropTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenCancelAirdropTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; @@ -37,7 +34,7 @@ class TokenCancelAirdropTransactionTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); private TokenCancelAirdropTransaction transaction; @@ -53,28 +50,25 @@ public static void afterAll() { private TokenCancelAirdropTransaction spawnTestTransaction() { List pendingAirdropIds = new ArrayList<>(); - pendingAirdropIds.add(new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new TokenId(0, 0, 123))); - pendingAirdropIds.add(new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new NftId(new TokenId(0, 0, 1234), 123))); + pendingAirdropIds.add( + new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), new TokenId(0, 0, 123))); + pendingAirdropIds.add(new PendingAirdropId( + new AccountId(0, 0, 457), new AccountId(0, 0, 456), new NftId(new TokenId(0, 0, 1234), 123))); return new TokenCancelAirdropTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setPendingAirdropIds(pendingAirdropIds) - .freeze() - .sign(privateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setPendingAirdropIds(pendingAirdropIds) + .freeze() + .sign(privateKey); } @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } - @BeforeEach public void setUp() { transaction = new TokenCancelAirdropTransaction(); @@ -88,10 +82,10 @@ void testConstructorSetsDefaultMaxTransactionFee() { @Test void testGetAndSetPendingAirdropIds() { List pendingAirdropIds = new ArrayList<>(); - pendingAirdropIds.add(new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new TokenId(0, 0, 123))); - pendingAirdropIds.add(new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new NftId(new TokenId(0, 0, 1234), 123))); + pendingAirdropIds.add( + new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), new TokenId(0, 0, 123))); + pendingAirdropIds.add(new PendingAirdropId( + new AccountId(0, 0, 457), new AccountId(0, 0, 456), new NftId(new TokenId(0, 0, 1234), 123))); transaction.setPendingAirdropIds(pendingAirdropIds); @@ -106,8 +100,8 @@ void testSetPendingAirdropIdsNullThrowsException() { @Test void testClearPendingAirdropIds() { List pendingAirdropIds = new ArrayList<>(); - PendingAirdropId pendingAirdropId = new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new TokenId(0, 0, 123)); + PendingAirdropId pendingAirdropId = + new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), new TokenId(0, 0, 123)); pendingAirdropIds.add(pendingAirdropId); transaction.setPendingAirdropIds(pendingAirdropIds); @@ -118,10 +112,10 @@ void testClearPendingAirdropIds() { @Test void testAddAllPendingAirdrops() { - PendingAirdropId pendingAirdropId1 = new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new TokenId(0, 0, 123)); - PendingAirdropId pendingAirdropId2 = new PendingAirdropId(new AccountId(0, 0, 458), new AccountId(0, 0, 459), - new TokenId(0, 0, 123)); + PendingAirdropId pendingAirdropId1 = + new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), new TokenId(0, 0, 123)); + PendingAirdropId pendingAirdropId2 = + new PendingAirdropId(new AccountId(0, 0, 458), new AccountId(0, 0, 459), new TokenId(0, 0, 123)); transaction.addPendingAirdrop(pendingAirdropId1); transaction.addPendingAirdrop(pendingAirdropId2); @@ -138,8 +132,8 @@ void testAddAllPendingAirdropsNullThrowsException() { @Test void testBuildTransactionBody() { - PendingAirdropId pendingAirdropId = new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new NftId(new TokenId(0, 0, 1234), 123)); + PendingAirdropId pendingAirdropId = new PendingAirdropId( + new AccountId(0, 0, 457), new AccountId(0, 0, 456), new NftId(new TokenId(0, 0, 1234), 123)); transaction.addPendingAirdrop(pendingAirdropId); TokenCancelAirdropTransactionBody.Builder builder = transaction.build(); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenClaimAirdropTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenClaimAirdropTransactionTest.java index 7445670a4..73fbeff77 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenClaimAirdropTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenClaimAirdropTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; @@ -37,7 +34,7 @@ class TokenClaimAirdropTransactionTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); private TokenClaimAirdropTransaction transaction; @@ -53,28 +50,25 @@ public static void afterAll() { private TokenClaimAirdropTransaction spawnTestTransaction() { List pendingAirdropIds = new ArrayList<>(); - pendingAirdropIds.add(new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new TokenId(0, 0, 123))); - pendingAirdropIds.add(new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new NftId(new TokenId(0, 0, 1234), 123))); + pendingAirdropIds.add( + new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), new TokenId(0, 0, 123))); + pendingAirdropIds.add(new PendingAirdropId( + new AccountId(0, 0, 457), new AccountId(0, 0, 456), new NftId(new TokenId(0, 0, 1234), 123))); return new TokenClaimAirdropTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setPendingAirdropIds(pendingAirdropIds) - .freeze() - .sign(privateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setPendingAirdropIds(pendingAirdropIds) + .freeze() + .sign(privateKey); } @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } - @BeforeEach public void setUp() { transaction = new TokenClaimAirdropTransaction(); @@ -88,10 +82,10 @@ void testConstructorSetsDefaultMaxTransactionFee() { @Test void testGetAndSetPendingAirdropIds() { List pendingAirdropIds = new ArrayList<>(); - pendingAirdropIds.add(new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new TokenId(0, 0, 123))); - pendingAirdropIds.add(new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new NftId(new TokenId(0, 0, 1234), 123))); + pendingAirdropIds.add( + new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), new TokenId(0, 0, 123))); + pendingAirdropIds.add(new PendingAirdropId( + new AccountId(0, 0, 457), new AccountId(0, 0, 456), new NftId(new TokenId(0, 0, 1234), 123))); transaction.setPendingAirdropIds(pendingAirdropIds); @@ -106,8 +100,8 @@ void testSetPendingAirdropIdsNullThrowsException() { @Test void testClearPendingAirdropIds() { List pendingAirdropIds = new ArrayList<>(); - PendingAirdropId pendingAirdropId = new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new TokenId(0, 0, 123)); + PendingAirdropId pendingAirdropId = + new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), new TokenId(0, 0, 123)); pendingAirdropIds.add(pendingAirdropId); transaction.setPendingAirdropIds(pendingAirdropIds); @@ -118,10 +112,10 @@ void testClearPendingAirdropIds() { @Test void testAddAllPendingAirdrops() { - PendingAirdropId pendingAirdropId1 = new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new TokenId(0, 0, 123)); - PendingAirdropId pendingAirdropId2 = new PendingAirdropId(new AccountId(0, 0, 458), new AccountId(0, 0, 459), - new TokenId(0, 0, 123)); + PendingAirdropId pendingAirdropId1 = + new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), new TokenId(0, 0, 123)); + PendingAirdropId pendingAirdropId2 = + new PendingAirdropId(new AccountId(0, 0, 458), new AccountId(0, 0, 459), new TokenId(0, 0, 123)); transaction.addPendingAirdrop(pendingAirdropId1); transaction.addPendingAirdrop(pendingAirdropId2); @@ -138,8 +132,8 @@ void testAddAllPendingAirdropsNullThrowsException() { @Test void testBuildTransactionBody() { - PendingAirdropId pendingAirdropId = new PendingAirdropId(new AccountId(0, 0, 457), new AccountId(0, 0, 456), - new NftId(new TokenId(0, 0, 1234), 123)); + PendingAirdropId pendingAirdropId = new PendingAirdropId( + new AccountId(0, 0, 457), new AccountId(0, 0, 456), new NftId(new TokenId(0, 0, 1234), 123)); transaction.addPendingAirdrop(pendingAirdropId); TokenClaimAirdropTransactionBody.Builder builder = transaction.build(); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenCreateTransactionTest.java index 286c7ea46..4467dde1b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenCreateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenCreateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static org.assertj.core.api.Assertions.assertThat; @@ -40,31 +37,31 @@ public class TokenCreateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final PublicKey testAdminKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11") + .getPublicKey(); private static final PublicKey testKycKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12") + .getPublicKey(); private static final PublicKey testFreezeKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e13") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e13") + .getPublicKey(); private static final PublicKey testWipeKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e14") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e14") + .getPublicKey(); private static final PublicKey testSupplyKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e15") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e15") + .getPublicKey(); private static final PublicKey testFeeScheduleKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e16") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e16") + .getPublicKey(); private static final PublicKey testPauseKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e17") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e17") + .getPublicKey(); private static final PublicKey testMetadataKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e18") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e18") + .getPublicKey(); private static final AccountId testTreasuryAccountId = AccountId.fromString("7.7.7"); private static final AccountId testAutoRenewAccountId = AccountId.fromString("8.8.8"); private static final long testInitialSupply = 30; @@ -76,10 +73,11 @@ public class TokenCreateTransactionTest { private static final String testTokenMemo = "test memo"; private static final Duration testAutoRenewPeriod = Duration.ofHours(10); private static final Instant testExpirationTime = Instant.now(); - private static final List testCustomFees = Collections.singletonList( - new CustomFixedFee().setFeeCollectorAccountId(AccountId.fromString("0.0.543")).setAmount(3) + private static final List testCustomFees = Collections.singletonList(new CustomFixedFee() + .setFeeCollectorAccountId(AccountId.fromString("0.0.543")) + .setAmount(3) .setDenominatingTokenId(TokenId.fromString("4.3.2"))); - private static final byte[] testMetadata = new byte[]{1, 2, 3, 4, 5}; + private static final byte[] testMetadata = new byte[] {1, 2, 3, 4, 5}; final Instant validStart = Instant.ofEpochSecond(1554158542); @BeforeAll @@ -103,17 +101,32 @@ void shouldSerializeNft() { } private TokenCreateTransaction spawnTestTransactionFungible() { - return new TokenCreateTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setInitialSupply(testInitialSupply).setFeeScheduleKey(testFeeScheduleKey).setSupplyKey(testSupplyKey) - .setAdminKey(testAdminKey).setAutoRenewAccountId(testAutoRenewAccountId) - .setAutoRenewPeriod(testAutoRenewPeriod).setDecimals(testDecimals).setFreezeDefault(testFreezeDefault) - .setFreezeKey(testFreezeKey).setWipeKey(testWipeKey).setTokenSymbol(testTokenSymbol).setKycKey(testKycKey) - .setPauseKey(testPauseKey).setMetadataKey(testMetadataKey).setExpirationTime(validStart) - .setTreasuryAccountId(testTreasuryAccountId).setTokenName(testTokenName).setTokenMemo(testTokenMemo) - .setCustomFees(testCustomFees).setMaxTransactionFee(new Hbar(1)).setTokenMetadata(testMetadata).freeze() - .sign(unusedPrivateKey); + return new TokenCreateTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setInitialSupply(testInitialSupply) + .setFeeScheduleKey(testFeeScheduleKey) + .setSupplyKey(testSupplyKey) + .setAdminKey(testAdminKey) + .setAutoRenewAccountId(testAutoRenewAccountId) + .setAutoRenewPeriod(testAutoRenewPeriod) + .setDecimals(testDecimals) + .setFreezeDefault(testFreezeDefault) + .setFreezeKey(testFreezeKey) + .setWipeKey(testWipeKey) + .setTokenSymbol(testTokenSymbol) + .setKycKey(testKycKey) + .setPauseKey(testPauseKey) + .setMetadataKey(testMetadataKey) + .setExpirationTime(validStart) + .setTreasuryAccountId(testTreasuryAccountId) + .setTokenName(testTokenName) + .setTokenMemo(testTokenMemo) + .setCustomFees(testCustomFees) + .setMaxTransactionFee(new Hbar(1)) + .setTokenMetadata(testMetadata) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -124,17 +137,31 @@ void shouldBytesFungible() throws Exception { } private TokenCreateTransaction spawnTestTransactionNft() { - return new TokenCreateTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setFeeScheduleKey(testFeeScheduleKey).setSupplyKey(testSupplyKey).setMaxSupply(testMaxSupply) - .setAdminKey(testAdminKey).setAutoRenewAccountId(testAutoRenewAccountId) - .setAutoRenewPeriod(testAutoRenewPeriod).setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) - .setSupplyType(TokenSupplyType.FINITE).setFreezeKey(testFreezeKey).setWipeKey(testWipeKey) - .setTokenSymbol(testTokenSymbol).setKycKey(testKycKey).setPauseKey(testPauseKey) - .setMetadataKey(testMetadataKey).setExpirationTime(validStart).setTreasuryAccountId(testTreasuryAccountId) - .setTokenName(testTokenName).setTokenMemo(testTokenMemo).setMaxTransactionFee(new Hbar(1)) - .setTokenMetadata(testMetadata).freeze().sign(unusedPrivateKey); + return new TokenCreateTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setFeeScheduleKey(testFeeScheduleKey) + .setSupplyKey(testSupplyKey) + .setMaxSupply(testMaxSupply) + .setAdminKey(testAdminKey) + .setAutoRenewAccountId(testAutoRenewAccountId) + .setAutoRenewPeriod(testAutoRenewPeriod) + .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) + .setSupplyType(TokenSupplyType.FINITE) + .setFreezeKey(testFreezeKey) + .setWipeKey(testWipeKey) + .setTokenSymbol(testTokenSymbol) + .setKycKey(testKycKey) + .setPauseKey(testPauseKey) + .setMetadataKey(testMetadataKey) + .setExpirationTime(validStart) + .setTreasuryAccountId(testTreasuryAccountId) + .setTokenName(testTokenName) + .setTokenMemo(testTokenMemo) + .setMaxTransactionFee(new Hbar(1)) + .setTokenMetadata(testMetadata) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -147,7 +174,8 @@ void shouldBytesNft() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenCreation(TokenCreateTransactionBody.newBuilder().build()).build(); + .setTokenCreation(TokenCreateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -156,19 +184,33 @@ void fromScheduledTransaction() { @Test void constructTokenCreateTransactionFungibleFromTransactionBodyProtobuf() { - var transactionBody = TokenCreateTransactionBody.newBuilder().setInitialSupply(testInitialSupply) - .setFeeScheduleKey(testFeeScheduleKey.toProtobufKey()).setSupplyKey(testSupplyKey.toProtobufKey()) - .setAdminKey(testAdminKey.toProtobufKey()).setAutoRenewAccount(testAutoRenewAccountId.toProtobuf()) - .setAutoRenewPeriod( - com.hedera.hashgraph.sdk.proto.Duration.newBuilder().setSeconds(testAutoRenewPeriod.toSeconds()) - .build()).setExpiry(Timestamp.newBuilder().setSeconds(testExpirationTime.getEpochSecond()).build()) - .setDecimals(testDecimals).setFreezeDefault(testFreezeDefault).setFreezeKey(testFreezeKey.toProtobufKey()) - .setWipeKey(testWipeKey.toProtobufKey()).setSymbol(testTokenSymbol).setKycKey(testKycKey.toProtobufKey()) - .setPauseKey(testPauseKey.toProtobufKey()).setMetadataKey(testMetadataKey.toProtobufKey()) - .setExpiry(Timestamp.newBuilder().setSeconds(testExpirationTime.getEpochSecond())) - .setTreasury(testTreasuryAccountId.toProtobuf()).setName(testTokenName).setMemo(testTokenMemo) - .addCustomFees(Iterables.getLast(testCustomFees).toProtobuf()) - .setMetadata(ByteString.copyFrom(testMetadata)).build(); + var transactionBody = TokenCreateTransactionBody.newBuilder() + .setInitialSupply(testInitialSupply) + .setFeeScheduleKey(testFeeScheduleKey.toProtobufKey()) + .setSupplyKey(testSupplyKey.toProtobufKey()) + .setAdminKey(testAdminKey.toProtobufKey()) + .setAutoRenewAccount(testAutoRenewAccountId.toProtobuf()) + .setAutoRenewPeriod(com.hedera.hashgraph.sdk.proto.Duration.newBuilder() + .setSeconds(testAutoRenewPeriod.toSeconds()) + .build()) + .setExpiry(Timestamp.newBuilder() + .setSeconds(testExpirationTime.getEpochSecond()) + .build()) + .setDecimals(testDecimals) + .setFreezeDefault(testFreezeDefault) + .setFreezeKey(testFreezeKey.toProtobufKey()) + .setWipeKey(testWipeKey.toProtobufKey()) + .setSymbol(testTokenSymbol) + .setKycKey(testKycKey.toProtobufKey()) + .setPauseKey(testPauseKey.toProtobufKey()) + .setMetadataKey(testMetadataKey.toProtobufKey()) + .setExpiry(Timestamp.newBuilder().setSeconds(testExpirationTime.getEpochSecond())) + .setTreasury(testTreasuryAccountId.toProtobuf()) + .setName(testTokenName) + .setMemo(testTokenMemo) + .addCustomFees(Iterables.getLast(testCustomFees).toProtobuf()) + .setMetadata(ByteString.copyFrom(testMetadata)) + .build(); var tx = TransactionBody.newBuilder().setTokenCreation(transactionBody).build(); var tokenCreateTransaction = new TokenCreateTransaction(tx); @@ -186,32 +228,44 @@ void constructTokenCreateTransactionFungibleFromTransactionBodyProtobuf() { assertThat(tokenCreateTransaction.getKycKey()).isEqualTo(testKycKey); assertThat(tokenCreateTransaction.getPauseKey()).isEqualTo(testPauseKey); assertThat(tokenCreateTransaction.getMetadataKey()).isEqualTo(testMetadataKey); - assertThat(tokenCreateTransaction.getExpirationTime().getEpochSecond()).isEqualTo( - testExpirationTime.getEpochSecond()); + assertThat(tokenCreateTransaction.getExpirationTime().getEpochSecond()) + .isEqualTo(testExpirationTime.getEpochSecond()); assertThat(tokenCreateTransaction.getTreasuryAccountId()).isEqualTo(testTreasuryAccountId); assertThat(tokenCreateTransaction.getTokenName()).isEqualTo(testTokenName); assertThat(tokenCreateTransaction.getTokenMemo()).isEqualTo(testTokenMemo); assertThat(tokenCreateTransaction.getTokenType()).isEqualTo(TokenType.FUNGIBLE_COMMON); - assertThat(Iterables.getLast(tokenCreateTransaction.getCustomFees()).toBytes()).isEqualTo( - Iterables.getLast(testCustomFees).toBytes()); + assertThat(Iterables.getLast(tokenCreateTransaction.getCustomFees()).toBytes()) + .isEqualTo(Iterables.getLast(testCustomFees).toBytes()); assertThat(tokenCreateTransaction.getTokenMetadata()).isEqualTo(testMetadata); } @Test void constructTokenCreateTransactionNftFromTransactionBodyProtobuf() { var transactionBody = TokenCreateTransactionBody.newBuilder() - .setFeeScheduleKey(testFeeScheduleKey.toProtobufKey()).setSupplyKey(testSupplyKey.toProtobufKey()) - .setMaxSupply(testMaxSupply).setAdminKey(testAdminKey.toProtobufKey()) - .setAutoRenewAccount(testAutoRenewAccountId.toProtobuf()).setAutoRenewPeriod( - com.hedera.hashgraph.sdk.proto.Duration.newBuilder().setSeconds(testAutoRenewPeriod.toSeconds()) - .build()).setExpiry(Timestamp.newBuilder().setSeconds(testExpirationTime.getEpochSecond()).build()) - .setTokenType(com.hedera.hashgraph.sdk.proto.TokenType.NON_FUNGIBLE_UNIQUE) - .setSupplyType(com.hedera.hashgraph.sdk.proto.TokenSupplyType.FINITE) - .setFreezeKey(testFreezeKey.toProtobufKey()).setWipeKey(testWipeKey.toProtobufKey()) - .setSymbol(testTokenSymbol).setKycKey(testKycKey.toProtobufKey()).setPauseKey(testPauseKey.toProtobufKey()) - .setMetadataKey(testMetadataKey.toProtobufKey()) - .setExpiry(Timestamp.newBuilder().setSeconds(testExpirationTime.getEpochSecond())) - .setTreasury(testTreasuryAccountId.toProtobuf()).setName(testTokenName).setMemo(testTokenMemo).build(); + .setFeeScheduleKey(testFeeScheduleKey.toProtobufKey()) + .setSupplyKey(testSupplyKey.toProtobufKey()) + .setMaxSupply(testMaxSupply) + .setAdminKey(testAdminKey.toProtobufKey()) + .setAutoRenewAccount(testAutoRenewAccountId.toProtobuf()) + .setAutoRenewPeriod(com.hedera.hashgraph.sdk.proto.Duration.newBuilder() + .setSeconds(testAutoRenewPeriod.toSeconds()) + .build()) + .setExpiry(Timestamp.newBuilder() + .setSeconds(testExpirationTime.getEpochSecond()) + .build()) + .setTokenType(com.hedera.hashgraph.sdk.proto.TokenType.NON_FUNGIBLE_UNIQUE) + .setSupplyType(com.hedera.hashgraph.sdk.proto.TokenSupplyType.FINITE) + .setFreezeKey(testFreezeKey.toProtobufKey()) + .setWipeKey(testWipeKey.toProtobufKey()) + .setSymbol(testTokenSymbol) + .setKycKey(testKycKey.toProtobufKey()) + .setPauseKey(testPauseKey.toProtobufKey()) + .setMetadataKey(testMetadataKey.toProtobufKey()) + .setExpiry(Timestamp.newBuilder().setSeconds(testExpirationTime.getEpochSecond())) + .setTreasury(testTreasuryAccountId.toProtobuf()) + .setName(testTokenName) + .setMemo(testTokenMemo) + .build(); var tx = TransactionBody.newBuilder().setTokenCreation(transactionBody).build(); var tokenCreateTransaction = new TokenCreateTransaction(tx); @@ -230,8 +284,8 @@ void constructTokenCreateTransactionNftFromTransactionBodyProtobuf() { assertThat(tokenCreateTransaction.getKycKey()).isEqualTo(testKycKey); assertThat(tokenCreateTransaction.getPauseKey()).isEqualTo(testPauseKey); assertThat(tokenCreateTransaction.getMetadataKey()).isEqualTo(testMetadataKey); - assertThat(tokenCreateTransaction.getExpirationTime().getEpochSecond()).isEqualTo( - testExpirationTime.getEpochSecond()); + assertThat(tokenCreateTransaction.getExpirationTime().getEpochSecond()) + .isEqualTo(testExpirationTime.getEpochSecond()); assertThat(tokenCreateTransaction.getTreasuryAccountId()).isEqualTo(testTreasuryAccountId); assertThat(tokenCreateTransaction.getTokenName()).isEqualTo(testTokenName); assertThat(tokenCreateTransaction.getTokenMemo()).isEqualTo(testTokenMemo); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenDeleteTransactionTest.java index e58b2d053..bea29cc17 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenDeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,27 +12,26 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenDeleteTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class TokenDeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -55,10 +51,13 @@ void shouldSerialize() { } private TokenDeleteTransaction spawnTestTransaction() { - return new TokenDeleteTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(TokenId.fromString("1.2.3")).setMaxTransactionFee(new Hbar(1)).freeze().sign(unusedPrivateKey); + return new TokenDeleteTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(TokenId.fromString("1.2.3")) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -71,7 +70,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenDeletion(TokenDeleteTransactionBody.newBuilder().build()).build(); + .setTokenDeletion(TokenDeleteTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -89,8 +89,11 @@ void constructTokenDeleteTransaction() { void ConstructTokenDeleteTransactionFromTransactionBodyProtobuf() { var tokenId = TokenId.fromString("1.2.3"); - var transactionBody = TokenDeleteTransactionBody.newBuilder().setToken(tokenId.toProtobuf()).build(); - var txBody = TransactionBody.newBuilder().setTokenDeletion(transactionBody).build(); + var transactionBody = TokenDeleteTransactionBody.newBuilder() + .setToken(tokenId.toProtobuf()) + .build(); + var txBody = + TransactionBody.newBuilder().setTokenDeletion(transactionBody).build(); var tokenDeleteTransaction = new TokenDeleteTransaction(txBody); assertThat(tokenDeleteTransaction.getTokenId()).isEqualTo(tokenId); @@ -113,5 +116,4 @@ void getSetTokenIdFrozen() { assertThrows(IllegalStateException.class, () -> tx.setTokenId(tokenId)); } - } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenDissociateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenDissociateTransactionTest.java index 9635c3dfe..f0d982e6f 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenDissociateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenDissociateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,32 +12,31 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenDissociateTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Instant; import java.util.Arrays; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TokenDissociateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final AccountId testAccountId = AccountId.fromString("6.9.0"); - private static final List testTokenIds = Arrays.asList(TokenId.fromString("4.2.0"), - TokenId.fromString("4.2.1"), TokenId.fromString("4.2.2")); + private static final List testTokenIds = + Arrays.asList(TokenId.fromString("4.2.0"), TokenId.fromString("4.2.1"), TokenId.fromString("4.2.2")); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -60,11 +56,14 @@ void shouldSerialize() { } private TokenDissociateTransaction spawnTestTransaction() { - return new TokenDissociateTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(testAccountId).setTokenIds(testTokenIds).setMaxTransactionFee(new Hbar(1)).freeze() - .sign(unusedPrivateKey); + return new TokenDissociateTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(testAccountId) + .setTokenIds(testTokenIds) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -77,7 +76,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenDissociate(TokenDissociateTransactionBody.newBuilder().build()).build(); + .setTokenDissociate(TokenDissociateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -86,10 +86,13 @@ void fromScheduledTransaction() { @Test void constructTokenDissociateTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenDissociateTransactionBody.newBuilder().setAccount(testAccountId.toProtobuf()) - .addAllTokens(testTokenIds.stream().map(TokenId::toProtobuf).toList()).build(); + var transactionBody = TokenDissociateTransactionBody.newBuilder() + .setAccount(testAccountId.toProtobuf()) + .addAllTokens(testTokenIds.stream().map(TokenId::toProtobuf).toList()) + .build(); - var tx = TransactionBody.newBuilder().setTokenDissociate(transactionBody).build(); + var tx = + TransactionBody.newBuilder().setTokenDissociate(transactionBody).build(); var tokenDissociateTransaction = new TokenDissociateTransaction(tx); assertThat(tokenDissociateTransaction.getAccountId()).isEqualTo(testAccountId); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenFeeScheduleUpdateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenFeeScheduleUpdateTransactionTest.java index b7e2bea70..fce766735 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenFeeScheduleUpdateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenFeeScheduleUpdateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,23 +12,22 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenFeeScheduleUpdateTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TokenFeeScheduleUpdateTransactionTest { final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,25 +45,23 @@ public static void afterAll() { private TokenFeeScheduleUpdateTransaction spawnTestTransaction() { var customFees = new ArrayList(); customFees.add(new CustomFixedFee() - .setFeeCollectorAccountId(new AccountId(4322)) - .setDenominatingTokenId(new TokenId(483902)) - .setAmount(10) - ); + .setFeeCollectorAccountId(new AccountId(4322)) + .setDenominatingTokenId(new TokenId(483902)) + .setAmount(10)); customFees.add(new CustomFractionalFee() - .setFeeCollectorAccountId(new AccountId(389042)) - .setNumerator(3) - .setDenominator(7) - .setMin(3) - .setMax(100) - .setAssessmentMethod(FeeAssessmentMethod.EXCLUSIVE) - ); + .setFeeCollectorAccountId(new AccountId(389042)) + .setNumerator(3) + .setDenominator(7) + .setMin(3) + .setMax(100) + .setAssessmentMethod(FeeAssessmentMethod.EXCLUSIVE)); return new TokenFeeScheduleUpdateTransaction() - .setTokenId(new TokenId(8798)) - .setCustomFees(customFees) - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .freeze(); + .setTokenId(new TokenId(8798)) + .setCustomFees(customFees) + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .freeze(); } @Test @@ -82,8 +76,9 @@ void shouldSerialize() throws InvalidProtocolBufferException { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenFeeScheduleUpdate(TokenFeeScheduleUpdateTransactionBody.newBuilder().build()) - .build(); + .setTokenFeeScheduleUpdate( + TokenFeeScheduleUpdateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenFreezeTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenFreezeTransactionTest.java index 017d6cfb2..ecd98f150 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenFreezeTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenFreezeTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenFreezeAccountTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class TokenFreezeTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,20 +45,18 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TokenFreezeTransaction spawnTestTransaction() { return new TokenFreezeTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(AccountId.fromString("0.0.222")) - .setTokenId(TokenId.fromString("6.5.4")) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(AccountId.fromString("0.0.222")) + .setTokenId(TokenId.fromString("6.5.4")) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -75,8 +69,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenFreeze(TokenFreezeAccountTransactionBody.newBuilder().build()) - .build(); + .setTokenFreeze(TokenFreezeAccountTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenGrantKycTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenGrantKycTransactionTest.java index d912ca40a..aed677316 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenGrantKycTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenGrantKycTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,27 +12,26 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenGrantKycTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class TokenGrantKycTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final TokenId testTokenId = TokenId.fromString("4.2.0"); private static final AccountId testAccountId = AccountId.fromString("6.9.0"); @@ -57,11 +53,14 @@ void shouldSerialize() { } private TokenGrantKycTransaction spawnTestTransaction() { - return new TokenGrantKycTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(testAccountId).setTokenId(testTokenId).setMaxTransactionFee(new Hbar(1)).freeze() - .sign(unusedPrivateKey); + return new TokenGrantKycTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(testAccountId) + .setTokenId(testTokenId) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -74,7 +73,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenGrantKyc(TokenGrantKycTransactionBody.newBuilder().build()).build(); + .setTokenGrantKyc(TokenGrantKycTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -83,8 +83,10 @@ void fromScheduledTransaction() { @Test void constructTokenGrantKycTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenGrantKycTransactionBody.newBuilder().setAccount(testAccountId.toProtobuf()) - .setToken(testTokenId.toProtobuf()).build(); + var transactionBody = TokenGrantKycTransactionBody.newBuilder() + .setAccount(testAccountId.toProtobuf()) + .setToken(testTokenId.toProtobuf()) + .build(); var tx = TransactionBody.newBuilder().setTokenGrantKyc(transactionBody).build(); var tokenGrantKycTransaction = new TokenGrantKycTransaction(tx); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenInfoQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenInfoQueryTest.java index 5579b4e35..28f399167 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenInfoQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenInfoQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,18 +12,18 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.QueryHeader; import io.github.jsonSnapshot.SnapshotMatcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class TokenInfoQueryTest { private static final TokenId testTokenId = TokenId.fromString("4.2.0"); @@ -43,9 +40,12 @@ public static void afterAll() { @Test void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); - new TokenInfoQuery().setTokenId(testTokenId).setMaxQueryPayment(Hbar.fromTinybars(100_000)) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + new TokenInfoQuery() + .setTokenId(testTokenId) + .setMaxQueryPayment(Hbar.fromTinybars(100_000)) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenInfoTest.java index 6e0dfa52f..a62a5ae3d 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenInfoTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,57 +12,56 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.InvalidProtocolBufferException; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Duration; import java.time.Instant; import java.util.Arrays; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; // TODO: update this, test deepClone() public class TokenInfoTest { /* - if we will init PrivateKey using method `PrivateKey.fromSeedECDSAsecp256k1(byte[] seed)` (like in C++ SDK, for example) - => we will get public key each time we run tests on different machines - => io.github.jsonSnapshot.SnapshotMatcher will fail tests - => we need to init PrivateKey fromString to get the same key each time - => `toProtobuf()` tests uses getEd25519() method to assert equality - */ + if we will init PrivateKey using method `PrivateKey.fromSeedECDSAsecp256k1(byte[] seed)` (like in C++ SDK, for example) + => we will get public key each time we run tests on different machines + => io.github.jsonSnapshot.SnapshotMatcher will fail tests + => we need to init PrivateKey fromString to get the same key each time + => `toProtobuf()` tests uses getEd25519() method to assert equality + */ private static final PublicKey testAdminKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11") + .getPublicKey(); private static final PublicKey testKycKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12") + .getPublicKey(); private static final PublicKey testFreezeKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e13") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e13") + .getPublicKey(); private static final PublicKey testWipeKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e14") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e14") + .getPublicKey(); private static final PublicKey testSupplyKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e15") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e15") + .getPublicKey(); private static final PublicKey testFeeScheduleKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e16") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e16") + .getPublicKey(); private static final PublicKey testPauseKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e17") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e17") + .getPublicKey(); private static final PublicKey testMetadataKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e18") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e18") + .getPublicKey(); private static final TokenId testTokenId = TokenId.fromString("0.6.9"); private static final AccountId testTreasuryAccountId = AccountId.fromString("7.7.7"); private static final AccountId testAutoRenewAccountId = AccountId.fromString("8.9.0"); @@ -78,10 +74,16 @@ public class TokenInfoTest { private static final Boolean testTokenKycStatus = true; private static final boolean testTokenIsDeleted = false; private static final List testTokenCustomFees = Arrays.asList( - new CustomFixedFee().setFeeCollectorAccountId(new AccountId(4322)).setDenominatingTokenId(new TokenId(483902)) - .setAmount(10), - new CustomFractionalFee().setFeeCollectorAccountId(new AccountId(389042)).setNumerator(3).setDenominator(7) - .setMin(3).setMax(100)); + new CustomFixedFee() + .setFeeCollectorAccountId(new AccountId(4322)) + .setDenominatingTokenId(new TokenId(483902)) + .setAmount(10), + new CustomFractionalFee() + .setFeeCollectorAccountId(new AccountId(389042)) + .setNumerator(3) + .setDenominator(7) + .setMin(3) + .setMax(100)); private static final TokenType testTokenType = TokenType.FUNGIBLE_COMMON; private static final TokenSupplyType testTokenSupplyType = TokenSupplyType.FINITE; private static final long testTokenMaxSupply = 1000000L; @@ -89,7 +91,7 @@ public class TokenInfoTest { private static final LedgerId testTokenLedgerId = LedgerId.MAINNET; private static final Duration testAutoRenewPeriod = Duration.ofHours(10); private static final Instant testExpirationTime = Instant.ofEpochSecond(1554158542); - private static final byte[] testMetadata = new byte[]{1, 2, 3, 4, 5}; + private static final byte[] testMetadata = new byte[] {1, 2, 3, 4, 5}; @BeforeAll public static void beforeAll() { @@ -102,12 +104,35 @@ public static void afterAll() { } private static TokenInfo spawnTokenInfoExample() { - return new TokenInfo(testTokenId, testTokenName, testTokenSymbol, testTokenDecimals, testTokenTotalSupply, - testTreasuryAccountId, testAdminKey, testKycKey, testFreezeKey, testWipeKey, testSupplyKey, - testFeeScheduleKey, testTokenFreezeStatus, testTokenKycStatus, testTokenIsDeleted, testAutoRenewAccountId, - testAutoRenewPeriod, testExpirationTime, testTokenMemo, testTokenCustomFees, testTokenType, - testTokenSupplyType, testTokenMaxSupply, testPauseKey, testTokenPauseStatus, testMetadata, testMetadataKey, - testTokenLedgerId); + return new TokenInfo( + testTokenId, + testTokenName, + testTokenSymbol, + testTokenDecimals, + testTokenTotalSupply, + testTreasuryAccountId, + testAdminKey, + testKycKey, + testFreezeKey, + testWipeKey, + testSupplyKey, + testFeeScheduleKey, + testTokenFreezeStatus, + testTokenKycStatus, + testTokenIsDeleted, + testAutoRenewAccountId, + testAutoRenewPeriod, + testExpirationTime, + testTokenMemo, + testTokenCustomFees, + testTokenType, + testTokenSupplyType, + testTokenMaxSupply, + testPauseKey, + testTokenPauseStatus, + testMetadata, + testMetadataKey, + testTokenLedgerId); } @Test @@ -205,48 +230,51 @@ void toProtobuf() { assertThat(tokenInfoProto.getTokenInfo().getTreasury().getShardNum()).isEqualTo(testTreasuryAccountId.shard); assertThat(tokenInfoProto.getTokenInfo().getTreasury().getRealmNum()).isEqualTo(testTreasuryAccountId.realm); assertThat(tokenInfoProto.getTokenInfo().getTreasury().getAccountNum()).isEqualTo(testTreasuryAccountId.num); - assertThat(tokenInfoProto.getTokenInfo().getAdminKey().getEd25519().toByteArray()).isEqualTo( - testAdminKey.toBytesRaw()); - assertThat(tokenInfoProto.getTokenInfo().getKycKey().getEd25519().toByteArray()).isEqualTo( - testKycKey.toBytesRaw()); - assertThat(tokenInfoProto.getTokenInfo().getFreezeKey().getEd25519().toByteArray()).isEqualTo( - testFreezeKey.toBytesRaw()); - assertThat(tokenInfoProto.getTokenInfo().getWipeKey().getEd25519().toByteArray()).isEqualTo( - testWipeKey.toBytesRaw()); - assertThat(tokenInfoProto.getTokenInfo().getSupplyKey().getEd25519().toByteArray()).isEqualTo( - testSupplyKey.toBytesRaw()); - assertThat(tokenInfoProto.getTokenInfo().getDefaultFreezeStatus()).isEqualTo( - TokenInfo.freezeStatusToProtobuf(testTokenFreezeStatus)); - assertThat(tokenInfoProto.getTokenInfo().getDefaultKycStatus()).isEqualTo( - TokenInfo.kycStatusToProtobuf(testTokenKycStatus)); + assertThat(tokenInfoProto.getTokenInfo().getAdminKey().getEd25519().toByteArray()) + .isEqualTo(testAdminKey.toBytesRaw()); + assertThat(tokenInfoProto.getTokenInfo().getKycKey().getEd25519().toByteArray()) + .isEqualTo(testKycKey.toBytesRaw()); + assertThat(tokenInfoProto.getTokenInfo().getFreezeKey().getEd25519().toByteArray()) + .isEqualTo(testFreezeKey.toBytesRaw()); + assertThat(tokenInfoProto.getTokenInfo().getWipeKey().getEd25519().toByteArray()) + .isEqualTo(testWipeKey.toBytesRaw()); + assertThat(tokenInfoProto.getTokenInfo().getSupplyKey().getEd25519().toByteArray()) + .isEqualTo(testSupplyKey.toBytesRaw()); + assertThat(tokenInfoProto.getTokenInfo().getDefaultFreezeStatus()) + .isEqualTo(TokenInfo.freezeStatusToProtobuf(testTokenFreezeStatus)); + assertThat(tokenInfoProto.getTokenInfo().getDefaultKycStatus()) + .isEqualTo(TokenInfo.kycStatusToProtobuf(testTokenKycStatus)); assertThat(tokenInfoProto.getTokenInfo().getDeleted()).isEqualTo(testTokenIsDeleted); - assertThat(tokenInfoProto.getTokenInfo().getAutoRenewAccount().getShardNum()).isEqualTo( - testAutoRenewAccountId.shard); - assertThat(tokenInfoProto.getTokenInfo().getAutoRenewAccount().getRealmNum()).isEqualTo( - testAutoRenewAccountId.realm); - assertThat(tokenInfoProto.getTokenInfo().getAutoRenewAccount().getAccountNum()).isEqualTo( - testAutoRenewAccountId.num); - assertThat(tokenInfoProto.getTokenInfo().getAutoRenewPeriod().getSeconds()).isEqualTo( - testAutoRenewPeriod.toSeconds()); - assertThat(tokenInfoProto.getTokenInfo().getExpiry().getSeconds()).isEqualTo( - testExpirationTime.getEpochSecond()); + assertThat(tokenInfoProto.getTokenInfo().getAutoRenewAccount().getShardNum()) + .isEqualTo(testAutoRenewAccountId.shard); + assertThat(tokenInfoProto.getTokenInfo().getAutoRenewAccount().getRealmNum()) + .isEqualTo(testAutoRenewAccountId.realm); + assertThat(tokenInfoProto.getTokenInfo().getAutoRenewAccount().getAccountNum()) + .isEqualTo(testAutoRenewAccountId.num); + assertThat(tokenInfoProto.getTokenInfo().getAutoRenewPeriod().getSeconds()) + .isEqualTo(testAutoRenewPeriod.toSeconds()); + assertThat(tokenInfoProto.getTokenInfo().getExpiry().getSeconds()) + .isEqualTo(testExpirationTime.getEpochSecond()); assertThat(tokenInfoProto.getTokenInfo().getMemo()).isEqualTo(testTokenMemo); - assertThat(tokenInfoProto.getTokenInfo().getTokenType()).isEqualTo( - com.hedera.hashgraph.sdk.proto.TokenType.valueOf(testTokenType.name())); - assertThat(tokenInfoProto.getTokenInfo().getSupplyType()).isEqualTo( - com.hedera.hashgraph.sdk.proto.TokenSupplyType.valueOf(testTokenSupplyType.name())); + assertThat(tokenInfoProto.getTokenInfo().getTokenType()) + .isEqualTo(com.hedera.hashgraph.sdk.proto.TokenType.valueOf(testTokenType.name())); + assertThat(tokenInfoProto.getTokenInfo().getSupplyType()) + .isEqualTo(com.hedera.hashgraph.sdk.proto.TokenSupplyType.valueOf(testTokenSupplyType.name())); assertThat(tokenInfoProto.getTokenInfo().getMaxSupply()).isEqualTo(testTokenMaxSupply); - assertThat(tokenInfoProto.getTokenInfo().getFeeScheduleKey().getEd25519().toByteArray()).isEqualTo( - testFeeScheduleKey.toBytesRaw()); + assertThat(tokenInfoProto + .getTokenInfo() + .getFeeScheduleKey() + .getEd25519() + .toByteArray()) + .isEqualTo(testFeeScheduleKey.toBytesRaw()); assertThat(tokenInfoProto.getTokenInfo().getCustomFeesList()).hasSize(testTokenCustomFees.size()); - assertThat(tokenInfoProto.getTokenInfo().getPauseKey().getEd25519().toByteArray()).isEqualTo( - testPauseKey.toBytesRaw()); - assertThat(tokenInfoProto.getTokenInfo().getPauseStatus()).isEqualTo( - TokenInfo.pauseStatusToProtobuf(testTokenPauseStatus)); - assertThat(tokenInfoProto.getTokenInfo().getMetadata().toByteArray()).isEqualTo( - testMetadata); - assertThat(tokenInfoProto.getTokenInfo().getMetadataKey().getEd25519().toByteArray()).isEqualTo( - testMetadataKey.toBytesRaw()); + assertThat(tokenInfoProto.getTokenInfo().getPauseKey().getEd25519().toByteArray()) + .isEqualTo(testPauseKey.toBytesRaw()); + assertThat(tokenInfoProto.getTokenInfo().getPauseStatus()) + .isEqualTo(TokenInfo.pauseStatusToProtobuf(testTokenPauseStatus)); + assertThat(tokenInfoProto.getTokenInfo().getMetadata().toByteArray()).isEqualTo(testMetadata); + assertThat(tokenInfoProto.getTokenInfo().getMetadataKey().getEd25519().toByteArray()) + .isEqualTo(testMetadataKey.toBytesRaw()); assertThat(tokenInfoProto.getTokenInfo().getLedgerId()).isEqualTo(testTokenLedgerId.toByteString()); } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenMintTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenMintTransactionTest.java index fe20d79cd..1fb45e60f 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenMintTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenMintTransactionTest.java @@ -1,29 +1,44 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.google.common.collect.Iterables; import com.google.protobuf.ByteString; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenMintTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Instant; import java.util.Arrays; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TokenMintTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final TokenId testTokenId = TokenId.fromString("4.2.0"); private static final Long testAmount = 10L; - private static final List testMetadataList = List.of(new byte[]{1, 2, 3, 4, 5}); - private static final ByteString testMetadataByteString = ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5}); + private static final List testMetadataList = List.of(new byte[] {1, 2, 3, 4, 5}); + private static final ByteString testMetadataByteString = ByteString.copyFrom(new byte[] {1, 2, 3, 4, 5}); final Instant validStart = Instant.ofEpochSecond(1554158542); @BeforeAll @@ -38,38 +53,34 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } @Test void shouldSerializeMetadata() { - SnapshotMatcher.expect(spawnMetadataTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnMetadataTestTransaction().toString()).toMatchSnapshot(); } private TokenMintTransaction spawnTestTransaction() { return new TokenMintTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(testTokenId) - .setAmount(testAmount) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(testTokenId) + .setAmount(testAmount) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } private TokenMintTransaction spawnMetadataTestTransaction() { return new TokenMintTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(TokenId.fromString("1.2.3")) - .setMetadata(testMetadataList) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(TokenId.fromString("1.2.3")) + .setMetadata(testMetadataList) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -89,8 +100,8 @@ void shouldBytesMetadata() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenMint(TokenMintTransactionBody.newBuilder().build()) - .build(); + .setTokenMint(TokenMintTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -100,18 +111,18 @@ void fromScheduledTransaction() { @Test void constructTokenMintTransactionFromTransactionBodyProtobuf() { var transactionBody = TokenMintTransactionBody.newBuilder() - .setToken(testTokenId.toProtobuf()) - .setAmount(testAmount) - .addMetadata(testMetadataByteString) - .build(); + .setToken(testTokenId.toProtobuf()) + .setAmount(testAmount) + .addMetadata(testMetadataByteString) + .build(); var tx = TransactionBody.newBuilder().setTokenMint(transactionBody).build(); var tokenMintTransaction = new TokenMintTransaction(tx); assertThat(tokenMintTransaction.getTokenId()).isEqualTo(testTokenId); assertThat(tokenMintTransaction.getAmount()).isEqualTo(testAmount); - assertThat(Iterables.getLast(tokenMintTransaction.getMetadata())).isEqualTo( - testMetadataByteString.toByteArray()); + assertThat(Iterables.getLast(tokenMintTransaction.getMetadata())) + .isEqualTo(testMetadataByteString.toByteArray()); } @Test @@ -153,7 +164,7 @@ void getSetMetadataFrozen() { @Test void addMetadata() { var tokenMintTransaction = new TokenMintTransaction().addMetadata(Iterables.getLast(testMetadataList)); - assertThat(Iterables.getLast(tokenMintTransaction.getMetadata())).isEqualTo( - Iterables.getLast(testMetadataList)); + assertThat(Iterables.getLast(tokenMintTransaction.getMetadata())) + .isEqualTo(Iterables.getLast(testMetadataList)); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenNftInfoQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenNftInfoQueryTest.java index d3910563e..24a6d3a9c 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenNftInfoQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenNftInfoQueryTest.java @@ -1,13 +1,29 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.QueryHeader; import io.github.jsonSnapshot.SnapshotMatcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class TokenNftInfoQueryTest { @BeforeAll public static void beforeAll() { @@ -23,22 +39,23 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new TokenNftInfoQuery() - .setNftId(TokenId.fromString("0.0.5005").nft(101)) - .setMaxQueryPayment(Hbar.fromTinybars(100_000)) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setNftId(TokenId.fromString("0.0.5005").nft(101)) + .setMaxQueryPayment(Hbar.fromTinybars(100_000)) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } @Test void propertiesTest() { var tokenId = TokenId.fromString("0.0.5005"); var query = new TokenNftInfoQuery() - .byAccountId(AccountId.fromString("0.0.123")) - .byTokenId(tokenId) - .setStart(5) - .setEnd(8) - .setNftId(tokenId.nft(101)) - .setMaxQueryPayment(Hbar.fromTinybars(100_000)); + .byAccountId(AccountId.fromString("0.0.123")) + .byTokenId(tokenId) + .setStart(5) + .setEnd(8) + .setNftId(tokenId.nft(101)) + .setMaxQueryPayment(Hbar.fromTinybars(100_000)); assertThat(query.getNftId()).hasToString("0.0.5005/101"); assertThat(query.getTokenId()).isEqualTo(tokenId); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenNftInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenNftInfoTest.java index 4d290be15..e572beb60 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenNftInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenNftInfoTest.java @@ -1,18 +1,33 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import javax.annotation.Nullable; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import javax.annotation.Nullable; -import java.time.Instant; - -import static org.assertj.core.api.Assertions.assertThat; - public class TokenNftInfoTest { - final static Instant creationTime = Instant.ofEpochSecond(1554158542); + static final Instant creationTime = Instant.ofEpochSecond(1554158542); @BeforeAll public static void beforeAll() { @@ -26,13 +41,12 @@ public static void afterAll() { private static TokenNftInfo spawnTokenNftInfoExample(@Nullable AccountId spenderAccountId) { return new TokenNftInfo( - TokenId.fromString("1.2.3").nft(4), - AccountId.fromString("5.6.7"), - creationTime, - Hex.decode("deadbeef"), - LedgerId.MAINNET, - spenderAccountId - ); + TokenId.fromString("1.2.3").nft(4), + AccountId.fromString("5.6.7"), + creationTime, + Hex.decode("deadbeef"), + LedgerId.MAINNET, + spenderAccountId); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenPauseTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenPauseTransactionTest.java index 8afd61f51..f37f8cb45 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenPauseTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenPauseTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,27 +12,26 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenPauseTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class TokenPauseTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final TokenId testTokenId = TokenId.fromString("4.2.0"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -50,10 +46,13 @@ public static void afterAll() { } TokenPauseTransaction spawnTestTransaction() { - return new TokenPauseTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(testTokenId).setMaxTransactionFee(new Hbar(1)).freeze().sign(unusedPrivateKey); + return new TokenPauseTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(testTokenId) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -71,7 +70,8 @@ void shouldBytesNft() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenPause(TokenPauseTransactionBody.newBuilder().build()).build(); + .setTokenPause(TokenPauseTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -80,7 +80,9 @@ void fromScheduledTransaction() { @Test void constructTokenPauseTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenPauseTransactionBody.newBuilder().setToken(testTokenId.toProtobuf()).build(); + var transactionBody = TokenPauseTransactionBody.newBuilder() + .setToken(testTokenId.toProtobuf()) + .build(); var tx = TransactionBody.newBuilder().setTokenPause(transactionBody).build(); var tokenPauseTransaction = new TokenPauseTransaction(tx); @@ -99,5 +101,4 @@ void getSetTokenIdFrozen() { var tx = spawnTestTransaction(); assertThrows(IllegalStateException.class, () -> tx.setTokenId(testTokenId)); } - } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRejectTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRejectTransactionTest.java index 6ca229b6f..315a233b8 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRejectTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRejectTransactionTest.java @@ -1,7 +1,4 @@ -/*- - * - * Hedera Java SDK - * +/* * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static org.assertj.core.api.Assertions.assertThat; @@ -37,18 +34,15 @@ public class TokenRejectTransactionTest { private static final PrivateKey TEST_PRIVATE_KEY = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final AccountId TEST_OWNER_ID = AccountId.fromString("0.6.9"); - private static final List TEST_TOKEN_IDS = List.of( - TokenId.fromString("1.2.3"), - TokenId.fromString("4.5.6"), - TokenId.fromString("7.8.9")); + private static final List TEST_TOKEN_IDS = + List.of(TokenId.fromString("1.2.3"), TokenId.fromString("4.5.6"), TokenId.fromString("7.8.9")); - private static final List TEST_NFT_IDS = List.of( - new NftId(TokenId.fromString("4.5.6"), 2), - new NftId(TokenId.fromString("7.8.9"), 3)); + private static final List TEST_NFT_IDS = + List.of(new NftId(TokenId.fromString("4.5.6"), 2), new NftId(TokenId.fromString("7.8.9"), 3)); final Instant TEST_VALID_START = Instant.ofEpochSecond(1554158542); @@ -68,11 +62,15 @@ void shouldSerialize() { } private TokenRejectTransaction spawnTestTransaction() { - return new TokenRejectTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), TEST_VALID_START)) - .setOwnerId(TEST_OWNER_ID).setTokenIds(TEST_TOKEN_IDS).setNftIds(TEST_NFT_IDS) - .setMaxTransactionFee(new Hbar(1)).freeze().sign(TEST_PRIVATE_KEY); + return new TokenRejectTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), TEST_VALID_START)) + .setOwnerId(TEST_OWNER_ID) + .setTokenIds(TEST_TOKEN_IDS) + .setNftIds(TEST_NFT_IDS) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(TEST_PRIVATE_KEY); } @Test @@ -85,7 +83,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenReject(TokenRejectTransactionBody.newBuilder().build()).build(); + .setTokenReject(TokenRejectTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -99,14 +98,19 @@ void constructTokenRejectTransactionFromTransactionBodyProtobuf() { transactionBodyBuilder.setOwner(TEST_OWNER_ID.toProtobuf()); for (TokenId tokenId : TEST_TOKEN_IDS) { - transactionBodyBuilder.addRejections(TokenReference.newBuilder().setFungibleToken(tokenId.toProtobuf()).build()); + transactionBodyBuilder.addRejections(TokenReference.newBuilder() + .setFungibleToken(tokenId.toProtobuf()) + .build()); } for (NftId nftId : TEST_NFT_IDS) { - transactionBodyBuilder.addRejections(TokenReference.newBuilder().setNft(nftId.toProtobuf()).build()); + transactionBodyBuilder.addRejections( + TokenReference.newBuilder().setNft(nftId.toProtobuf()).build()); } - var tx = TransactionBody.newBuilder().setTokenReject(transactionBodyBuilder.build()).build(); + var tx = TransactionBody.newBuilder() + .setTokenReject(transactionBodyBuilder.build()) + .build(); var tokenRejectTransaction = new TokenRejectTransaction(tx); assertThat(tokenRejectTransaction.getOwnerId()).isEqualTo(TEST_OWNER_ID); @@ -114,7 +118,6 @@ void constructTokenRejectTransactionFromTransactionBodyProtobuf() { assertThat(tokenRejectTransaction.getNftIds()).hasSize(TEST_NFT_IDS.size()); } - @Test void getSetOwnerId() { var transaction = new TokenRejectTransaction().setOwnerId(TEST_OWNER_ID); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRelationshipTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRelationshipTest.java index a0e202fb5..39eae955b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRelationshipTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRelationshipTest.java @@ -1,12 +1,28 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.jsonSnapshot.SnapshotMatcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class TokenRelationshipTest { @BeforeAll public static void beforeAll() { @@ -19,15 +35,7 @@ public static void afterAll() { } TokenRelationship spawnTokenRelationshipExample() { - return new TokenRelationship( - TokenId.fromString("1.2.3"), - "ABC", - 55, - true, - true, - 4, - true - ); + return new TokenRelationship(TokenId.fromString("1.2.3"), "ABC", 55, true, true, 4, true); } @Test @@ -36,7 +44,8 @@ void shouldSerializeTokenRelationship() throws Exception { byte[] tokenRelationshipBytes = originalTokenRelationship.toBytes(); var copyTokenRelationship = TokenRelationship.fromBytes(tokenRelationshipBytes); assertThat(copyTokenRelationship.toString().replaceAll("@[A-Za-z0-9]+", "")) - .isEqualTo(originalTokenRelationship.toString().replaceAll("@[A-Za-z0-9]+", "")); - SnapshotMatcher.expect(originalTokenRelationship.toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .isEqualTo(originalTokenRelationship.toString().replaceAll("@[A-Za-z0-9]+", "")); + SnapshotMatcher.expect(originalTokenRelationship.toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRevokeKycTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRevokeKycTransactionTest.java index e8a270028..7137aab24 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRevokeKycTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenRevokeKycTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,27 +12,26 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenRevokeKycTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class TokenRevokeKycTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final TokenId testTokenId = TokenId.fromString("4.2.0"); private static final AccountId testAccountId = AccountId.fromString("6.9.0"); @@ -57,11 +53,14 @@ void shouldSerialize() { } private TokenRevokeKycTransaction spawnTestTransaction() { - return new TokenRevokeKycTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(testAccountId).setTokenId(testTokenId).setMaxTransactionFee(new Hbar(1)).freeze() - .sign(unusedPrivateKey); + return new TokenRevokeKycTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(testAccountId) + .setTokenId(testTokenId) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -74,7 +73,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenRevokeKyc(TokenRevokeKycTransactionBody.newBuilder().build()).build(); + .setTokenRevokeKyc(TokenRevokeKycTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -83,8 +83,10 @@ void fromScheduledTransaction() { @Test void constructTokenRevokeKycTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenRevokeKycTransactionBody.newBuilder().setAccount(testAccountId.toProtobuf()) - .setToken(testTokenId.toProtobuf()).build(); + var transactionBody = TokenRevokeKycTransactionBody.newBuilder() + .setAccount(testAccountId.toProtobuf()) + .setToken(testTokenId.toProtobuf()) + .build(); var tx = TransactionBody.newBuilder().setTokenRevokeKyc(transactionBody).build(); var tokenRevokeKycTransaction = new TokenRevokeKycTransaction(tx); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenSupplyTypeTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenSupplyTypeTest.java index fbfdf4067..15e6a9d29 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenSupplyTypeTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenSupplyTypeTest.java @@ -1,13 +1,29 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.TokenSupplyType; import io.github.jsonSnapshot.SnapshotMatcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class TokenSupplyTypeTest { private final TokenSupplyType tokenSupplyTypeInfinite = TokenSupplyType.INFINITE; private final TokenSupplyType tokenSupplyTypeFinite = TokenSupplyType.FINITE; @@ -25,17 +41,21 @@ public static void afterAll() { @Test void fromProtobuf() { SnapshotMatcher.expect( - com.hedera.hashgraph.sdk.TokenSupplyType.valueOf(tokenSupplyTypeInfinite).toString(), - com.hedera.hashgraph.sdk.TokenSupplyType.valueOf(tokenSupplyTypeFinite).toString()) - .toMatchSnapshot(); + com.hedera.hashgraph.sdk.TokenSupplyType.valueOf(tokenSupplyTypeInfinite) + .toString(), + com.hedera.hashgraph.sdk.TokenSupplyType.valueOf(tokenSupplyTypeFinite) + .toString()) + .toMatchSnapshot(); } @Test void toProtobuf() { SnapshotMatcher.expect( - com.hedera.hashgraph.sdk.TokenSupplyType.valueOf(tokenSupplyTypeInfinite).toProtobuf(), - com.hedera.hashgraph.sdk.TokenSupplyType.valueOf(tokenSupplyTypeFinite).toProtobuf()) - .toMatchSnapshot(); + com.hedera.hashgraph.sdk.TokenSupplyType.valueOf(tokenSupplyTypeInfinite) + .toProtobuf(), + com.hedera.hashgraph.sdk.TokenSupplyType.valueOf(tokenSupplyTypeFinite) + .toProtobuf()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenTypeTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenTypeTest.java index dbc37dba6..a52c0b6a4 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenTypeTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenTypeTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.TokenType; @@ -43,16 +40,20 @@ public static void afterAll() { @Test void fromProtobuf() { SnapshotMatcher.expect( - com.hedera.hashgraph.sdk.TokenType.valueOf(tokenTypeFungible).toString(), - com.hedera.hashgraph.sdk.TokenType.valueOf(tokenTypeNonFungible).toString()) - .toMatchSnapshot(); + com.hedera.hashgraph.sdk.TokenType.valueOf(tokenTypeFungible) + .toString(), + com.hedera.hashgraph.sdk.TokenType.valueOf(tokenTypeNonFungible) + .toString()) + .toMatchSnapshot(); } @Test void toProtobuf() { SnapshotMatcher.expect( - com.hedera.hashgraph.sdk.TokenType.valueOf(tokenTypeFungible).toProtobuf(), - com.hedera.hashgraph.sdk.TokenType.valueOf(tokenTypeNonFungible).toProtobuf()) - .toMatchSnapshot(); + com.hedera.hashgraph.sdk.TokenType.valueOf(tokenTypeFungible) + .toProtobuf(), + com.hedera.hashgraph.sdk.TokenType.valueOf(tokenTypeNonFungible) + .toProtobuf()) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUnfreezeTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUnfreezeTransactionTest.java index de42e6e29..e2ba0d83e 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUnfreezeTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUnfreezeTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenUnfreezeAccountTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class TokenUnfreezeTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,20 +45,18 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TokenUnfreezeTransaction spawnTestTransaction() { return new TokenUnfreezeTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setAccountId(AccountId.fromString("0.0.222")) - .setTokenId(TokenId.fromString("6.5.4")) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setAccountId(AccountId.fromString("0.0.222")) + .setTokenId(TokenId.fromString("6.5.4")) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -75,8 +69,9 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenUnfreeze(TokenUnfreezeAccountTransactionBody.newBuilder().build()) - .build(); + .setTokenUnfreeze( + TokenUnfreezeAccountTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUnpauseTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUnpauseTransactionTest.java index a92dbaefe..66ec66ded 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUnpauseTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUnpauseTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,27 +12,26 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenUnpauseTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class TokenUnpauseTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final TokenId testTokenId = TokenId.fromString("4.2.0"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -51,10 +47,13 @@ public static void afterAll() { } TokenUnpauseTransaction spawnTestTransaction() { - return new TokenUnpauseTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(testTokenId).setMaxTransactionFee(new Hbar(1)).freeze().sign(unusedPrivateKey); + return new TokenUnpauseTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(testTokenId) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -72,7 +71,8 @@ void shouldBytesNft() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenUnpause(TokenUnpauseTransactionBody.newBuilder().build()).build(); + .setTokenUnpause(TokenUnpauseTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -81,7 +81,9 @@ void fromScheduledTransaction() { @Test void constructTokenUnpauseTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenUnpauseTransactionBody.newBuilder().setToken(testTokenId.toProtobuf()).build(); + var transactionBody = TokenUnpauseTransactionBody.newBuilder() + .setToken(testTokenId.toProtobuf()) + .build(); var tx = TransactionBody.newBuilder().setTokenUnpause(transactionBody).build(); var tokenUnpauseTransaction = new TokenUnpauseTransaction(tx); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUpdateNftsTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUpdateNftsTransactionTest.java index 16d45e1d0..ba5a9dda7 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUpdateNftsTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUpdateNftsTransactionTest.java @@ -1,7 +1,4 @@ -/*- - * - * Hedera Java SDK - * +/* * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static org.assertj.core.api.Assertions.assertThat; @@ -37,10 +34,10 @@ public class TokenUpdateNftsTransactionTest { private static final PrivateKey testMetadataKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final TokenId testTokenId = TokenId.fromString("4.2.0"); private static final List testSerialNumbers = Arrays.asList(8L, 9L, 10L); - private static final byte[] testMetadata = new byte[]{1, 2, 3, 4, 5}; + private static final byte[] testMetadata = new byte[] {1, 2, 3, 4, 5}; final Instant validStart = Instant.ofEpochSecond(1554158542); @BeforeAll @@ -59,11 +56,15 @@ void shouldSerialize() { } private TokenUpdateNftsTransaction spawnTestTransaction() { - return new TokenUpdateNftsTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(testTokenId).setMetadata(testMetadata).setSerials(testSerialNumbers) - .setMaxTransactionFee(new Hbar(1)).freeze().sign(testMetadataKey); + return new TokenUpdateNftsTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(testTokenId) + .setMetadata(testMetadata) + .setSerials(testSerialNumbers) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(testMetadataKey); } @Test @@ -76,7 +77,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenUpdateNfts(TokenUpdateNftsTransactionBody.newBuilder().build()).build(); + .setTokenUpdateNfts(TokenUpdateNftsTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -85,11 +87,14 @@ void fromScheduledTransaction() { @Test void constructTokenUpdateTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenUpdateNftsTransactionBody.newBuilder().setToken(testTokenId.toProtobuf()) - .setMetadata(BytesValue.of(ByteString.copyFrom(testMetadata))).addAllSerialNumbers(testSerialNumbers) - .build(); - - var tx = TransactionBody.newBuilder().setTokenUpdateNfts(transactionBody).build(); + var transactionBody = TokenUpdateNftsTransactionBody.newBuilder() + .setToken(testTokenId.toProtobuf()) + .setMetadata(BytesValue.of(ByteString.copyFrom(testMetadata))) + .addAllSerialNumbers(testSerialNumbers) + .build(); + + var tx = + TransactionBody.newBuilder().setTokenUpdateNfts(transactionBody).build(); var tokenUpdateNftsTransaction = new TokenUpdateNftsTransaction(tx); assertThat(tokenUpdateNftsTransaction.getTokenId()).isEqualTo(testTokenId); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUpdateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUpdateTransactionTest.java index bade583e9..515789a1c 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUpdateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenUpdateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import static org.assertj.core.api.Assertions.assertThat; @@ -37,34 +34,33 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; - public class TokenUpdateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final PublicKey testAdminKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11") + .getPublicKey(); private static final PublicKey testKycKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12") + .getPublicKey(); private static final PublicKey testFreezeKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e13") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e13") + .getPublicKey(); private static final PublicKey testWipeKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e14") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e14") + .getPublicKey(); private static final PublicKey testSupplyKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e15") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e15") + .getPublicKey(); private static final PublicKey testFeeScheduleKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e16") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e16") + .getPublicKey(); private static final PublicKey testPauseKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e17") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e17") + .getPublicKey(); private static final PublicKey testMetadataKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e18") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e18") + .getPublicKey(); private static final AccountId testTreasuryAccountId = AccountId.fromString("7.7.7"); private static final AccountId testAutoRenewAccountId = AccountId.fromString("8.8.8"); private static final String testTokenName = "test name"; @@ -73,7 +69,7 @@ public class TokenUpdateTransactionTest { private static final TokenId testTokenId = TokenId.fromString("4.2.0"); private static final Duration testAutoRenewPeriod = Duration.ofHours(10); private static final Instant testExpirationTime = Instant.now(); - private static final byte[] testMetadata = new byte[]{1, 2, 3, 4, 5}; + private static final byte[] testMetadata = new byte[] {1, 2, 3, 4, 5}; final Instant validStart = Instant.ofEpochSecond(1554158542); @BeforeAll @@ -92,16 +88,30 @@ void shouldSerialize() { } private TokenUpdateTransaction spawnTestTransaction() { - return new TokenUpdateTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(testTokenId).setFeeScheduleKey(testFeeScheduleKey).setSupplyKey(testSupplyKey) - .setAdminKey(testAdminKey).setAutoRenewAccountId(testAutoRenewAccountId) - .setAutoRenewPeriod(testAutoRenewPeriod).setFreezeKey(testFreezeKey).setWipeKey(testWipeKey) - .setTokenSymbol(testTokenSymbol).setKycKey(testKycKey).setPauseKey(testPauseKey) - .setMetadataKey(testMetadataKey).setExpirationTime(validStart).setTreasuryAccountId(testTreasuryAccountId) - .setTokenName(testTokenName).setTokenMemo(testTokenMemo).setMaxTransactionFee(new Hbar(1)) - .setTokenMetadata(testMetadata).setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION).freeze().sign(unusedPrivateKey); + return new TokenUpdateTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(testTokenId) + .setFeeScheduleKey(testFeeScheduleKey) + .setSupplyKey(testSupplyKey) + .setAdminKey(testAdminKey) + .setAutoRenewAccountId(testAutoRenewAccountId) + .setAutoRenewPeriod(testAutoRenewPeriod) + .setFreezeKey(testFreezeKey) + .setWipeKey(testWipeKey) + .setTokenSymbol(testTokenSymbol) + .setKycKey(testKycKey) + .setPauseKey(testPauseKey) + .setMetadataKey(testMetadataKey) + .setExpirationTime(validStart) + .setTreasuryAccountId(testTreasuryAccountId) + .setTokenName(testTokenName) + .setTokenMemo(testTokenMemo) + .setMaxTransactionFee(new Hbar(1)) + .setTokenMetadata(testMetadata) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -114,7 +124,8 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenUpdate(TokenUpdateTransactionBody.newBuilder().build()).build(); + .setTokenUpdate(TokenUpdateTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -123,19 +134,30 @@ void fromScheduledTransaction() { @Test void constructTokenUpdateTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenUpdateTransactionBody.newBuilder().setToken(testTokenId.toProtobuf()) - .setName(testTokenName).setSymbol(testTokenSymbol).setTreasury(testTreasuryAccountId.toProtobuf()) - .setAdminKey(testAdminKey.toProtobufKey()).setKycKey(testKycKey.toProtobufKey()) - .setFreezeKey(testFreezeKey.toProtobufKey()).setWipeKey(testWipeKey.toProtobufKey()) - .setSupplyKey(testSupplyKey.toProtobufKey()).setAutoRenewAccount(testAutoRenewAccountId.toProtobuf()) - .setAutoRenewPeriod( - com.hedera.hashgraph.sdk.proto.Duration.newBuilder().setSeconds(testAutoRenewPeriod.toSeconds()) - .build()).setExpiry(Timestamp.newBuilder().setSeconds(testExpirationTime.getEpochSecond()).build()) - .setMemo(StringValue.newBuilder().setValue(testTokenMemo).build()) - .setFeeScheduleKey(testFeeScheduleKey.toProtobufKey()).setPauseKey(testPauseKey.toProtobufKey()) - .setMetadataKey(testMetadataKey.toProtobufKey()) - .setMetadata(BytesValue.of(ByteString.copyFrom(testMetadata))) - .setKeyVerificationMode(com.hedera.hashgraph.sdk.proto.TokenKeyValidation.NO_VALIDATION).build(); + var transactionBody = TokenUpdateTransactionBody.newBuilder() + .setToken(testTokenId.toProtobuf()) + .setName(testTokenName) + .setSymbol(testTokenSymbol) + .setTreasury(testTreasuryAccountId.toProtobuf()) + .setAdminKey(testAdminKey.toProtobufKey()) + .setKycKey(testKycKey.toProtobufKey()) + .setFreezeKey(testFreezeKey.toProtobufKey()) + .setWipeKey(testWipeKey.toProtobufKey()) + .setSupplyKey(testSupplyKey.toProtobufKey()) + .setAutoRenewAccount(testAutoRenewAccountId.toProtobuf()) + .setAutoRenewPeriod(com.hedera.hashgraph.sdk.proto.Duration.newBuilder() + .setSeconds(testAutoRenewPeriod.toSeconds()) + .build()) + .setExpiry(Timestamp.newBuilder() + .setSeconds(testExpirationTime.getEpochSecond()) + .build()) + .setMemo(StringValue.newBuilder().setValue(testTokenMemo).build()) + .setFeeScheduleKey(testFeeScheduleKey.toProtobufKey()) + .setPauseKey(testPauseKey.toProtobufKey()) + .setMetadataKey(testMetadataKey.toProtobufKey()) + .setMetadata(BytesValue.of(ByteString.copyFrom(testMetadata))) + .setKeyVerificationMode(com.hedera.hashgraph.sdk.proto.TokenKeyValidation.NO_VALIDATION) + .build(); var tx = TransactionBody.newBuilder().setTokenUpdate(transactionBody).build(); var tokenUpdateTransaction = new TokenUpdateTransaction(tx); @@ -151,8 +173,8 @@ void constructTokenUpdateTransactionFromTransactionBodyProtobuf() { assertThat(tokenUpdateTransaction.getSupplyKey()).isEqualTo(testSupplyKey); assertThat(tokenUpdateTransaction.getAutoRenewAccountId()).isEqualTo(testAutoRenewAccountId); assertThat(tokenUpdateTransaction.getAutoRenewPeriod().toSeconds()).isEqualTo(testAutoRenewPeriod.toSeconds()); - assertThat(tokenUpdateTransaction.getExpirationTime().getEpochSecond()).isEqualTo( - testExpirationTime.getEpochSecond()); + assertThat(tokenUpdateTransaction.getExpirationTime().getEpochSecond()) + .isEqualTo(testExpirationTime.getEpochSecond()); assertThat(tokenUpdateTransaction.getTokenMemo()).isEqualTo(testTokenMemo); assertThat(tokenUpdateTransaction.getFeeScheduleKey()).isEqualTo(testFeeScheduleKey); assertThat(tokenUpdateTransaction.getPauseKey()).isEqualTo(testPauseKey); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenWipeTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenWipeTransactionTest.java index 5fb777400..547d1bfd0 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenWipeTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TokenWipeTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,30 +12,28 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TokenWipeAccountTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Instant; import java.util.Arrays; import java.util.Collections; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TokenWipeTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final AccountId testAccountId = AccountId.fromString("0.6.9"); private static final TokenId testTokenId = TokenId.fromString("4.2.0"); private static final long testAmount = 4L; @@ -57,41 +52,37 @@ public static void afterAll() { @Test void shouldSerializeFungible() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TokenWipeTransaction spawnTestTransaction() { return new TokenWipeTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(TokenId.fromString("0.0.111")) - .setAccountId(testAccountId) - .setAmount(testAmount) - .setSerials(testSerialNumbers) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(TokenId.fromString("0.0.111")) + .setAccountId(testAccountId) + .setAmount(testAmount) + .setSerials(testSerialNumbers) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test void shouldSerializeNft() { - SnapshotMatcher.expect(spawnTestTransactionNft() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransactionNft().toString()).toMatchSnapshot(); } private TokenWipeTransaction spawnTestTransactionNft() { return new TokenWipeTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTokenId(TokenId.fromString("0.0.111")) - .setAccountId(testAccountId) - .setSerials(Collections.singletonList(444L)) - .setMaxTransactionFee(new Hbar(1)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTokenId(TokenId.fromString("0.0.111")) + .setAccountId(testAccountId) + .setSerials(Collections.singletonList(444L)) + .setMaxTransactionFee(new Hbar(1)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -111,8 +102,8 @@ void shouldBytesNft() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setTokenWipe(TokenWipeAccountTransactionBody.newBuilder().build()) - .build(); + .setTokenWipe(TokenWipeAccountTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -121,9 +112,12 @@ void fromScheduledTransaction() { @Test void constructTokenWipeTransactionFromTransactionBodyProtobuf() { - var transactionBody = TokenWipeAccountTransactionBody.newBuilder().setToken(testTokenId.toProtobuf()) - .setAccount(testAccountId.toProtobuf()).setAmount(testAmount).addAllSerialNumbers(testSerialNumbers) - .build(); + var transactionBody = TokenWipeAccountTransactionBody.newBuilder() + .setToken(testTokenId.toProtobuf()) + .setAccount(testAccountId.toProtobuf()) + .setAmount(testAmount) + .addAllSerialNumbers(testSerialNumbers) + .build(); var txBody = TransactionBody.newBuilder().setTokenWipe(transactionBody).build(); var tokenWipeTransaction = new TokenWipeTransaction(txBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicCreateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicCreateTransactionTest.java index 2528b67d2..f32dd68da 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicCreateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicCreateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +12,25 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.ConsensusCreateTopicTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Duration; import java.time.Instant; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TopicCreateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -50,23 +46,21 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TopicCreateTransaction spawnTestTransaction() { return new TopicCreateTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setSubmitKey(unusedPrivateKey) - .setAdminKey(unusedPrivateKey) - .setAutoRenewAccountId(AccountId.fromString("0.0.5007")) - .setAutoRenewPeriod(Duration.ofHours(24)) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .setTopicMemo("hello memo") - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setSubmitKey(unusedPrivateKey) + .setAdminKey(unusedPrivateKey) + .setAutoRenewAccountId(AccountId.fromString("0.0.5007")) + .setAutoRenewPeriod(Duration.ofHours(24)) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .setTopicMemo("hello memo") + .freeze() + .sign(unusedPrivateKey); } @Test @@ -79,8 +73,9 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setConsensusCreateTopic(ConsensusCreateTopicTransactionBody.newBuilder().build()) - .build(); + .setConsensusCreateTopic( + ConsensusCreateTopicTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicDeleteTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicDeleteTransactionTest.java index 964e8a33d..77500f9ac 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicDeleteTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicDeleteTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,25 +12,24 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.proto.ConsensusDeleteTopicTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - public class TopicDeleteTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -49,19 +45,17 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(spawnTestTransaction() - .toString() - ).toMatchSnapshot(); + SnapshotMatcher.expect(spawnTestTransaction().toString()).toMatchSnapshot(); } private TopicDeleteTransaction spawnTestTransaction() { return new TopicDeleteTransaction() - .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTopicId(TopicId.fromString("0.0.5007")) - .setMaxTransactionFee(Hbar.fromTinybars(100_000)) - .freeze() - .sign(unusedPrivateKey); + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTopicId(TopicId.fromString("0.0.5007")) + .setMaxTransactionFee(Hbar.fromTinybars(100_000)) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -74,8 +68,9 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setConsensusDeleteTopic(ConsensusDeleteTopicTransactionBody.newBuilder().build()) - .build(); + .setConsensusDeleteTopic( + ConsensusDeleteTopicTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicIdTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicIdTest.java index a2d5df673..1c64a04a5 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicIdTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicIdTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.InvalidProtocolBufferException; @@ -49,12 +46,15 @@ void toBytes() throws InvalidProtocolBufferException { @Test void fromBytes() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(TopicId.fromBytes(new TopicId(5005).toBytes()).toString()).toMatchSnapshot(); + SnapshotMatcher.expect(TopicId.fromBytes(new TopicId(5005).toBytes()).toString()) + .toMatchSnapshot(); } @Test void fromSolidityAddress() { - SnapshotMatcher.expect(TokenId.fromSolidityAddress("000000000000000000000000000000000000138D").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(TokenId.fromSolidityAddress("000000000000000000000000000000000000138D") + .toString()) + .toMatchSnapshot(); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicInfoQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicInfoQueryTest.java index 23d2d1642..43261c2b3 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicInfoQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicInfoQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; @@ -40,8 +37,9 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new TopicInfoQuery() - .setTopicId(TopicId.fromString("0.0.5005")) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setTopicId(TopicId.fromString("0.0.5005")) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicInfoTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicInfoTest.java index a75437b51..a4c9ddc96 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicInfoTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicInfoTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.google.protobuf.ByteString; @@ -24,34 +21,31 @@ import com.hedera.hashgraph.sdk.proto.ConsensusGetTopicInfoResponse; import com.hedera.hashgraph.sdk.proto.ConsensusTopicInfo; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Duration; +import java.time.Instant; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Duration; -import java.time.Instant; - - public class TopicInfoTest { private static final PrivateKey privateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final byte[] hash = {2}; private static final ConsensusGetTopicInfoResponse info = ConsensusGetTopicInfoResponse.newBuilder() - .setTopicInfo(ConsensusTopicInfo.newBuilder() - .setMemo("1") - .setRunningHash(ByteString.copyFrom(hash)) - .setSequenceNumber(3) - .setExpirationTime(InstantConverter.toProtobuf(Instant.ofEpochMilli(4))) - .setAutoRenewPeriod(DurationConverter.toProtobuf(Duration.ofDays(5))) - .setAdminKey(privateKey.getPublicKey().toProtobufKey()) - .setSubmitKey(privateKey.getPublicKey().toProtobufKey()) - .setAutoRenewAccount(new AccountId(4).toProtobuf()) - .setLedgerId(LedgerId.TESTNET.toByteString())) - .build(); - + .setTopicInfo(ConsensusTopicInfo.newBuilder() + .setMemo("1") + .setRunningHash(ByteString.copyFrom(hash)) + .setSequenceNumber(3) + .setExpirationTime(InstantConverter.toProtobuf(Instant.ofEpochMilli(4))) + .setAutoRenewPeriod(DurationConverter.toProtobuf(Duration.ofDays(5))) + .setAdminKey(privateKey.getPublicKey().toProtobufKey()) + .setSubmitKey(privateKey.getPublicKey().toProtobufKey()) + .setAutoRenewAccount(new AccountId(4).toProtobuf()) + .setLedgerId(LedgerId.TESTNET.toByteString())) + .build(); @BeforeAll public static void beforeAll() { @@ -65,25 +59,24 @@ public static void afterAll() { @Test void fromProtobuf() throws InvalidProtocolBufferException { - SnapshotMatcher.expect(TopicInfo.fromProtobuf(info).toString()) - .toMatchSnapshot(); + SnapshotMatcher.expect(TopicInfo.fromProtobuf(info).toString()).toMatchSnapshot(); } @Test void toProtobuf() throws InvalidProtocolBufferException { SnapshotMatcher.expect(TopicInfo.fromProtobuf(info).toProtobuf().toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void fromBytes() throws InvalidProtocolBufferException { SnapshotMatcher.expect(TopicInfo.fromBytes(info.toByteArray()).toString()) - .toMatchSnapshot(); + .toMatchSnapshot(); } @Test void toBytes() { SnapshotMatcher.expect(Hex.toHexString(TopicInfo.fromProtobuf(info).toBytes())) - .toMatchSnapshot(); + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicMessageQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicMessageQueryTest.java index 18adba0c1..876a3c0b3 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicMessageQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicMessageQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + import com.google.common.base.Stopwatch; import com.google.common.primitives.Longs; import com.google.common.util.concurrent.Uninterruptibles; @@ -37,16 +37,6 @@ import io.grpc.StatusRuntimeException; import io.grpc.inprocess.InProcessServerBuilder; import io.grpc.stub.StreamObserver; -import org.assertj.core.api.InstanceOfAssertFactories; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; - import java.time.Duration; import java.time.Instant; import java.util.ArrayDeque; @@ -58,19 +48,25 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; class TopicMessageQueryTest { private static final Instant START_TIME = Instant.now(); private Client client; - final private AtomicBoolean complete = new AtomicBoolean(false); - final private List errors = new ArrayList<>(); - final private List received = new ArrayList<>(); - final private ConsensusServiceStub consensusServiceStub = new ConsensusServiceStub(); + private final AtomicBoolean complete = new AtomicBoolean(false); + private final List errors = new ArrayList<>(); + private final List received = new ArrayList<>(); + private final ConsensusServiceStub consensusServiceStub = new ConsensusServiceStub(); private Server server; private TopicMessageQuery topicMessageQuery; @@ -89,10 +85,10 @@ void setup() throws Exception { client = Client.forNetwork(Collections.emptyMap()); client.setMirrorNetwork(List.of("in-process:test")); server = InProcessServerBuilder.forName("test") - .addService(consensusServiceStub) - .directExecutor() - .build() - .start(); + .addService(consensusServiceStub) + .directExecutor() + .build() + .start(); topicMessageQuery = new TopicMessageQuery(); topicMessageQuery.setCompletionHandler(() -> complete.set(true)); topicMessageQuery.setEndTime(START_TIME.plusSeconds(100L)); @@ -118,71 +114,71 @@ void teardown() throws Exception { @SuppressWarnings("NullAway") void setCompletionHandlerNull() { assertThatThrownBy(() -> topicMessageQuery.setCompletionHandler(null)) - .isInstanceOf(NullPointerException.class) - .hasMessage("completionHandler must not be null"); + .isInstanceOf(NullPointerException.class) + .hasMessage("completionHandler must not be null"); } @Test @SuppressWarnings("NullAway") void setEndTimeNull() { assertThatThrownBy(() -> topicMessageQuery.setEndTime(null)) - .isInstanceOf(NullPointerException.class) - .hasMessage("endTime must not be null"); + .isInstanceOf(NullPointerException.class) + .hasMessage("endTime must not be null"); } @Test @SuppressWarnings("NullAway") void setErrorHandlerNull() { assertThatThrownBy(() -> topicMessageQuery.setErrorHandler(null)) - .isInstanceOf(NullPointerException.class) - .hasMessage("errorHandler must not be null"); + .isInstanceOf(NullPointerException.class) + .hasMessage("errorHandler must not be null"); } @Test @SuppressWarnings("NullAway") void setMaxAttemptsNegative() { assertThatThrownBy(() -> topicMessageQuery.setMaxAttempts(-1)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("maxAttempts must be positive"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("maxAttempts must be positive"); } @Test @SuppressWarnings("NullAway") void setMaxBackoffNull() { assertThatThrownBy(() -> topicMessageQuery.setMaxBackoff(null)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("maxBackoff must be at least 500 ms"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("maxBackoff must be at least 500 ms"); } @Test void setMaxBackoffLow() { assertThatThrownBy(() -> topicMessageQuery.setMaxBackoff(Duration.ofMillis(499L))) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("maxBackoff must be at least 500 ms"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("maxBackoff must be at least 500 ms"); } @Test @SuppressWarnings("NullAway") void setRetryHandlerNull() { assertThatThrownBy(() -> topicMessageQuery.setRetryHandler(null)) - .isInstanceOf(NullPointerException.class) - .hasMessage("retryHandler must not be null"); + .isInstanceOf(NullPointerException.class) + .hasMessage("retryHandler must not be null"); } @Test @SuppressWarnings("NullAway") void setStartTimeNull() { assertThatThrownBy(() -> topicMessageQuery.setStartTime(null)) - .isInstanceOf(NullPointerException.class) - .hasMessage("startTime must not be null"); + .isInstanceOf(NullPointerException.class) + .hasMessage("startTime must not be null"); } @Test @SuppressWarnings("NullAway") void setTopicIdNull() { assertThatThrownBy(() -> topicMessageQuery.setTopicId(null)) - .isInstanceOf(NullPointerException.class) - .hasMessage("topicId must not be null"); + .isInstanceOf(NullPointerException.class) + .hasMessage("topicId must not be null"); } @Test @@ -209,21 +205,24 @@ void subscribeChunked() { subscribeToMirror(received::add); - var message = combine(response1.getMessage().toByteArray(), response2.getMessage().toByteArray()); + var message = combine( + response1.getMessage().toByteArray(), response2.getMessage().toByteArray()); assertThat(errors).isEmpty(); assertThat(received) - .hasSize(1) - .first() - .returns(toInstant(response2.getConsensusTimestamp()), t -> t.consensusTimestamp) - .returns(response2.getChunkInfo().getInitialTransactionID(), t -> Objects.requireNonNull(t.transactionId).toProtobuf()) - .returns(message, t -> t.contents) - .returns(response2.getRunningHash().toByteArray(), t -> t.runningHash) - .returns(response2.getSequenceNumber(), t -> t.sequenceNumber) - .extracting(t -> t.chunks) - .asInstanceOf(InstanceOfAssertFactories.ARRAY) - .hasSize(2) - .extracting(c -> ((TopicMessageChunk) c).sequenceNumber) - .contains(1L, 2L); + .hasSize(1) + .first() + .returns(toInstant(response2.getConsensusTimestamp()), t -> t.consensusTimestamp) + .returns( + response2.getChunkInfo().getInitialTransactionID(), + t -> Objects.requireNonNull(t.transactionId).toProtobuf()) + .returns(message, t -> t.contents) + .returns(response2.getRunningHash().toByteArray(), t -> t.runningHash) + .returns(response2.getSequenceNumber(), t -> t.sequenceNumber) + .extracting(t -> t.chunks) + .asInstanceOf(InstanceOfAssertFactories.ARRAY) + .hasSize(2) + .extracting(c -> ((TopicMessageChunk) c).sequenceNumber) + .contains(1L, 2L); } @Test @@ -266,9 +265,11 @@ void retryRecovers(Status.Code code, String description) { ConsensusTopicQuery.Builder request = request(); consensusServiceStub.requests.add(request.build()); - consensusServiceStub.requests.add(request.setConsensusStartTime(toTimestamp(nextTimestamp)).build()); + consensusServiceStub.requests.add( + request.setConsensusStartTime(toTimestamp(nextTimestamp)).build()); consensusServiceStub.responses.add(response); - consensusServiceStub.responses.add(code.toStatus().withDescription(description).asRuntimeException()); + consensusServiceStub.responses.add( + code.toStatus().withDescription(description).asRuntimeException()); consensusServiceStub.responses.add(response(2L)); subscribeToMirror(received::add); @@ -278,25 +279,23 @@ void retryRecovers(Status.Code code, String description) { } @ParameterizedTest(name = "No retry w/ status {0} and description {1}") - @CsvSource({ - "INTERNAL, internal first_stream error", - "INTERNAL, internal error", - "INTERNAL, ", - "INVALID_ARGUMENT, " + @CsvSource({"INTERNAL, internal first_stream error", "INTERNAL, internal error", "INTERNAL, ", "INVALID_ARGUMENT, " }) @Timeout(3) void noRetry(Status.Code code, String description) { consensusServiceStub.requests.add(request().build()); - consensusServiceStub.responses.add(code.toStatus().withDescription(description).asRuntimeException()); + consensusServiceStub.responses.add( + code.toStatus().withDescription(description).asRuntimeException()); subscribeToMirror(received::add); assertThat(received).isEmpty(); - assertThat(errors).hasSize(1) - .first() - .isInstanceOf(StatusRuntimeException.class) - .extracting(t -> ((StatusRuntimeException) t).getStatus().getCode()) - .isEqualTo(code); + assertThat(errors) + .hasSize(1) + .first() + .isInstanceOf(StatusRuntimeException.class) + .extracting(t -> ((StatusRuntimeException) t).getStatus().getCode()) + .isEqualTo(code); } @Test @@ -323,7 +322,9 @@ void retryWithLimit() { topicMessageQuery.setLimit(2); consensusServiceStub.requests.add(request.setLimit(2L).build()); - consensusServiceStub.requests.add(request.setConsensusStartTime(toTimestamp(nextTimestamp)).setLimit(1L).build()); + consensusServiceStub.requests.add(request.setConsensusStartTime(toTimestamp(nextTimestamp)) + .setLimit(1L) + .build()); consensusServiceStub.responses.add(response); consensusServiceStub.responses.add(Status.RESOURCE_EXHAUSTED.asRuntimeException()); consensusServiceStub.responses.add(response(2L)); @@ -346,11 +347,12 @@ void retriesExhausted() { subscribeToMirror(received::add); assertThat(received).isEmpty(); - assertThat(errors).hasSize(1) - .first() - .isInstanceOf(StatusRuntimeException.class) - .extracting(t -> ((StatusRuntimeException) t).getStatus()) - .isEqualTo(Status.RESOURCE_EXHAUSTED); + assertThat(errors) + .hasSize(1) + .first() + .isInstanceOf(StatusRuntimeException.class) + .extracting(t -> ((StatusRuntimeException) t).getStatus()) + .isEqualTo(Status.RESOURCE_EXHAUSTED); } @Test @@ -362,11 +364,11 @@ void errorWhenCallIsCancelled() { subscribeToMirror(received::add); assertThat(errors) - .hasSize(1) - .first() - .isInstanceOf(StatusRuntimeException.class) - .extracting(t -> ((StatusRuntimeException)t).getStatus()) - .isEqualTo(Status.CANCELLED); + .hasSize(1) + .first() + .isInstanceOf(StatusRuntimeException.class) + .extracting(t -> ((StatusRuntimeException) t).getStatus()) + .isEqualTo(Status.CANCELLED); assertThat(received).isEmpty(); } @@ -382,51 +384,52 @@ private void subscribeToMirror(Consumer onNext) { subscriptionHandle.unsubscribe(); } - static private ConsensusTopicQuery.Builder request() { + private static ConsensusTopicQuery.Builder request() { return ConsensusTopicQuery.newBuilder() - .setConsensusEndTime(toTimestamp(START_TIME.plusSeconds(100L))) - .setConsensusStartTime(toTimestamp(START_TIME)) - .setTopicID(TopicID.newBuilder().setTopicNum(1000).build()); + .setConsensusEndTime(toTimestamp(START_TIME.plusSeconds(100L))) + .setConsensusStartTime(toTimestamp(START_TIME)) + .setTopicID(TopicID.newBuilder().setTopicNum(1000).build()); } - static private ConsensusTopicResponse response(long sequenceNumber) { + private static ConsensusTopicResponse response(long sequenceNumber) { return response(sequenceNumber, 0); } - static private ConsensusTopicResponse response(long sequenceNumber, int total) { + private static ConsensusTopicResponse response(long sequenceNumber, int total) { ConsensusTopicResponse.Builder consensusTopicResponseBuilder = ConsensusTopicResponse.newBuilder(); if (total > 0) { var chunkInfo = ConsensusMessageChunkInfo.newBuilder() - .setInitialTransactionID(TransactionID.newBuilder() - .setAccountID(AccountID.newBuilder().setAccountNum(3).build()) - .setTransactionValidStart(toTimestamp(START_TIME)) - .build()) - .setNumber((int) sequenceNumber) - .setTotal(total) - .build(); + .setInitialTransactionID(TransactionID.newBuilder() + .setAccountID( + AccountID.newBuilder().setAccountNum(3).build()) + .setTransactionValidStart(toTimestamp(START_TIME)) + .build()) + .setNumber((int) sequenceNumber) + .setTotal(total) + .build(); consensusTopicResponseBuilder.setChunkInfo(chunkInfo); } var message = ByteString.copyFrom(Longs.toByteArray(sequenceNumber)); return consensusTopicResponseBuilder - .setConsensusTimestamp(toTimestamp(START_TIME.plusSeconds(sequenceNumber))) - .setSequenceNumber(sequenceNumber) - .setMessage(message) - .setRunningHash(message) - .setRunningHashVersion(2L) - .build(); + .setConsensusTimestamp(toTimestamp(START_TIME.plusSeconds(sequenceNumber))) + .setSequenceNumber(sequenceNumber) + .setMessage(message) + .setRunningHash(message) + .setRunningHashVersion(2L) + .build(); } - static private Instant toInstant(Timestamp timestamp) { + private static Instant toInstant(Timestamp timestamp) { return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos()); } - static private Timestamp toTimestamp(Instant instant) { + private static Timestamp toTimestamp(Instant instant) { return Timestamp.newBuilder() - .setSeconds(instant.getEpochSecond()) - .setNanos(instant.getNano()) - .build(); + .setSeconds(instant.getEpochSecond()) + .setNanos(instant.getNano()) + .build(); } private static class ConsensusServiceStub extends ConsensusServiceGrpc.ConsensusServiceImplBase { @@ -435,8 +438,8 @@ private static class ConsensusServiceStub extends ConsensusServiceGrpc.Consensus private final Queue responses = new ArrayDeque<>(); @Override - public void subscribeTopic(ConsensusTopicQuery consensusTopicQuery, - StreamObserver streamObserver) { + public void subscribeTopic( + ConsensusTopicQuery consensusTopicQuery, StreamObserver streamObserver) { var request = requests.poll(); assertThat(request).isNotNull(); assertThat(consensusTopicQuery).isEqualTo(request); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicMessageSubmitTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicMessageSubmitTransactionTest.java index 0ff928f52..d550b213b 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicMessageSubmitTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicMessageSubmitTransactionTest.java @@ -1,23 +1,38 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.google.protobuf.ByteString; import com.hedera.hashgraph.sdk.proto.ConsensusSubmitMessageTransactionBody; import com.hedera.hashgraph.sdk.proto.SchedulableTransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Arrays; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - public class TopicMessageSubmitTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final TopicId testTopicId = new TopicId(0, 6, 9); private static final byte[] testMessageBytes = {0x04, 0x05, 0x06}; private static final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -33,36 +48,47 @@ public static void afterAll() { } private TopicMessageSubmitTransaction spawnTestTransactionString() { - return new TopicMessageSubmitTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTopicId(testTopicId).setMessage(new String(testMessageBytes)).freeze().sign(unusedPrivateKey); + return new TopicMessageSubmitTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTopicId(testTopicId) + .setMessage(new String(testMessageBytes)) + .freeze() + .sign(unusedPrivateKey); } private TopicMessageSubmitTransaction spawnTestTransactionBytes() { - return new TopicMessageSubmitTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTopicId(testTopicId).setMessage(testMessageBytes).freeze().sign(unusedPrivateKey); + return new TopicMessageSubmitTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTopicId(testTopicId) + .setMessage(testMessageBytes) + .freeze() + .sign(unusedPrivateKey); } @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setConsensusSubmitMessage(ConsensusSubmitMessageTransactionBody.newBuilder().build()).build(); + .setConsensusSubmitMessage( + ConsensusSubmitMessageTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); assertThat(tx).isInstanceOf(TopicMessageSubmitTransaction.class); } - @Test void constructTopicMessageSubmitTransactionFromTransactionBodyProtobuf() { - var transactionBody = ConsensusSubmitMessageTransactionBody.newBuilder().setTopicID(testTopicId.toProtobuf()) - .setMessage(ByteString.copyFrom(testMessageBytes)).build(); + var transactionBody = ConsensusSubmitMessageTransactionBody.newBuilder() + .setTopicID(testTopicId.toProtobuf()) + .setMessage(ByteString.copyFrom(testMessageBytes)) + .build(); - var tx = TransactionBody.newBuilder().setConsensusSubmitMessage(transactionBody).build(); + var tx = TransactionBody.newBuilder() + .setConsensusSubmitMessage(transactionBody) + .build(); var topicSubmitMessageTransaction = new TopicMessageSubmitTransaction(tx); assertThat(topicSubmitMessageTransaction.getTopicId()).isEqualTo(testTopicId); @@ -82,20 +108,22 @@ void getSetTopicIdFrozen() { @Test void getSetMessage() { - var topicSubmitMessageTransactionString = new TopicMessageSubmitTransaction().setMessage( - new String(testMessageBytes)); + var topicSubmitMessageTransactionString = + new TopicMessageSubmitTransaction().setMessage(new String(testMessageBytes)); var topicSubmitMessageTransactionBytes = new TopicMessageSubmitTransaction().setMessage(testMessageBytes); - assertThat(topicSubmitMessageTransactionString.getMessage().toByteArray()).isEqualTo(testMessageBytes); - assertThat(topicSubmitMessageTransactionBytes.getMessage().toByteArray()).isEqualTo(testMessageBytes); + assertThat(topicSubmitMessageTransactionString.getMessage().toByteArray()) + .isEqualTo(testMessageBytes); + assertThat(topicSubmitMessageTransactionBytes.getMessage().toByteArray()) + .isEqualTo(testMessageBytes); } @Test void getSetMessageFrozen() { var topicSubmitMessageTransactionString = spawnTestTransactionString(); var topicSubmitMessageTransactionBytes = spawnTestTransactionBytes(); - assertThrows(IllegalStateException.class, - () -> topicSubmitMessageTransactionString.setMessage(testMessageBytes)); - assertThrows(IllegalStateException.class, - () -> topicSubmitMessageTransactionBytes.setMessage(testMessageBytes)); + assertThrows( + IllegalStateException.class, () -> topicSubmitMessageTransactionString.setMessage(testMessageBytes)); + assertThrows( + IllegalStateException.class, () -> topicSubmitMessageTransactionBytes.setMessage(testMessageBytes)); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicUpdateTransactionTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicUpdateTransactionTest.java index 6214b4755..75979fc5d 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicUpdateTransactionTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TopicUpdateTransactionTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + import com.google.protobuf.StringValue; import com.hedera.hashgraph.sdk.proto.ConsensusUpdateTopicTransactionBody; import com.hedera.hashgraph.sdk.proto.CryptoDeleteTransactionBody; @@ -26,26 +26,22 @@ import com.hedera.hashgraph.sdk.proto.Timestamp; import com.hedera.hashgraph.sdk.proto.TransactionBody; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.time.Duration; import java.time.Instant; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TopicUpdateTransactionTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); private static final PublicKey testAdminKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e11") + .getPublicKey(); private static final PublicKey testSubmitKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12") - .getPublicKey(); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e12") + .getPublicKey(); private static final TopicId testTopicId = TopicId.fromString("0.0.5007"); private static final String testTopicMemo = "test memo"; private static final Duration testAutoRenewPeriod = Duration.ofHours(10); @@ -65,11 +61,19 @@ public static void afterAll() { @Test void clearShouldSerialize() { - SnapshotMatcher.expect(new TopicUpdateTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTopicId(testTopicId).clearAdminKey().clearAutoRenewAccountId().clearSubmitKey().clearTopicMemo() - .freeze().sign(unusedPrivateKey).toString()).toMatchSnapshot(); + SnapshotMatcher.expect(new TopicUpdateTransaction() + .setNodeAccountIds( + Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTopicId(testTopicId) + .clearAdminKey() + .clearAutoRenewAccountId() + .clearSubmitKey() + .clearTopicMemo() + .freeze() + .sign(unusedPrivateKey) + .toString()) + .toMatchSnapshot(); } @Test @@ -78,12 +82,18 @@ void setShouldSerialize() { } private TopicUpdateTransaction spawnTestTransaction() { - return new TopicUpdateTransaction().setNodeAccountIds( - Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) - .setTopicId(testTopicId).setAdminKey(testAdminKey).setAutoRenewAccountId(testAutoRenewAccountId) - .setAutoRenewPeriod(testAutoRenewPeriod).setSubmitKey(testSubmitKey).setTopicMemo(testTopicMemo) - .setExpirationTime(validStart).freeze().sign(unusedPrivateKey); + return new TopicUpdateTransaction() + .setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006"))) + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), validStart)) + .setTopicId(testTopicId) + .setAdminKey(testAdminKey) + .setAutoRenewAccountId(testAutoRenewAccountId) + .setAutoRenewPeriod(testAutoRenewPeriod) + .setSubmitKey(testSubmitKey) + .setTopicMemo(testTopicMemo) + .setExpirationTime(validStart) + .freeze() + .sign(unusedPrivateKey); } @Test @@ -96,7 +106,9 @@ void shouldBytes() throws Exception { @Test void fromScheduledTransaction() { var transactionBody = SchedulableTransactionBody.newBuilder() - .setConsensusUpdateTopic(ConsensusUpdateTopicTransactionBody.newBuilder().build()).build(); + .setConsensusUpdateTopic( + ConsensusUpdateTopicTransactionBody.newBuilder().build()) + .build(); var tx = Transaction.fromScheduledTransaction(transactionBody); @@ -105,20 +117,29 @@ void fromScheduledTransaction() { @Test void constructTopicUpdateTransactionFromTransactionBodyProtobuf() { - var transactionBody = ConsensusUpdateTopicTransactionBody.newBuilder().setTopicID(testTopicId.toProtobuf()) - .setMemo(StringValue.newBuilder().setValue(testTopicMemo).build()) - .setExpirationTime(Timestamp.newBuilder().setSeconds(testExpirationTime.getEpochSecond()).build()) - .setAdminKey(testAdminKey.toProtobufKey()).setSubmitKey(testSubmitKey.toProtobufKey()).setAutoRenewPeriod( - com.hedera.hashgraph.sdk.proto.Duration.newBuilder().setSeconds(testAutoRenewPeriod.toSeconds()) - .build()).setAutoRenewAccount(testAutoRenewAccountId.toProtobuf()).build(); - - var tx = TransactionBody.newBuilder().setConsensusUpdateTopic(transactionBody).build(); + var transactionBody = ConsensusUpdateTopicTransactionBody.newBuilder() + .setTopicID(testTopicId.toProtobuf()) + .setMemo(StringValue.newBuilder().setValue(testTopicMemo).build()) + .setExpirationTime(Timestamp.newBuilder() + .setSeconds(testExpirationTime.getEpochSecond()) + .build()) + .setAdminKey(testAdminKey.toProtobufKey()) + .setSubmitKey(testSubmitKey.toProtobufKey()) + .setAutoRenewPeriod(com.hedera.hashgraph.sdk.proto.Duration.newBuilder() + .setSeconds(testAutoRenewPeriod.toSeconds()) + .build()) + .setAutoRenewAccount(testAutoRenewAccountId.toProtobuf()) + .build(); + + var tx = TransactionBody.newBuilder() + .setConsensusUpdateTopic(transactionBody) + .build(); var topicUpdateTransaction = new TopicUpdateTransaction(tx); assertThat(topicUpdateTransaction.getTopicId()).isEqualTo(testTopicId); assertThat(topicUpdateTransaction.getTopicMemo()).isEqualTo(testTopicMemo); - assertThat(topicUpdateTransaction.getExpirationTime().getEpochSecond()).isEqualTo( - testExpirationTime.getEpochSecond()); + assertThat(topicUpdateTransaction.getExpirationTime().getEpochSecond()) + .isEqualTo(testExpirationTime.getEpochSecond()); assertThat(topicUpdateTransaction.getAdminKey()).isEqualTo(testAdminKey); assertThat(topicUpdateTransaction.getSubmitKey()).isEqualTo(testSubmitKey); assertThat(topicUpdateTransaction.getAutoRenewPeriod().toSeconds()).isEqualTo(testAutoRenewPeriod.toSeconds()); diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionIdTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionIdTest.java index 17e212adf..75e4bb3c7 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionIdTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionIdTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,22 +12,21 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.google.protobuf.InvalidProtocolBufferException; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; +import java.util.Objects; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - class TransactionIdTest { @BeforeAll public static void beforeAll() { @@ -44,12 +40,16 @@ public static void afterAll() { @Test void shouldSerialize() { - SnapshotMatcher.expect(TransactionId.fromString("0.0.23847@1588539964.632521325").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(TransactionId.fromString("0.0.23847@1588539964.632521325") + .toString()) + .toMatchSnapshot(); } @Test void shouldSerialize2() { - SnapshotMatcher.expect(TransactionId.fromString("0.0.23847@1588539964.632521325?scheduled/3").toString()).toMatchSnapshot(); + SnapshotMatcher.expect(TransactionId.fromString("0.0.23847@1588539964.632521325?scheduled/3") + .toString()) + .toMatchSnapshot(); } @Test @@ -165,7 +165,6 @@ void compare() { transactionId2 = new TransactionId(null, Instant.ofEpochSecond(1588539965)); assertThat(transactionId1.compareTo(transactionId2)).isEqualTo(-1); - transactionId1 = new TransactionId(null, null); transactionId2 = new TransactionId(null, null); assertThat(transactionId1).isEqualByComparingTo(transactionId2); @@ -173,13 +172,11 @@ void compare() { @Test void shouldFail() { - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> TransactionId.fromString("0.0.23847.1588539964.632521325/4") - ); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> TransactionId.fromString("0.0.23847.1588539964.632521325/4")); - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( - () -> TransactionId.fromString("0.0.23847@1588539964/4") - ); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> TransactionId.fromString("0.0.23847@1588539964/4")); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionReceiptQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionReceiptQueryTest.java index 946b36c97..4874408e5 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionReceiptQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionReceiptQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; - public class TransactionReceiptQueryTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -47,8 +43,9 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); new TransactionReceiptQuery() - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5005"), validStart)) - .onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5005"), validStart)) + .onMakeRequest(builder, QueryHeader.newBuilder().build()); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionReceiptTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionReceiptTest.java index 5e950a62f..36ecb7939 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionReceiptTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionReceiptTest.java @@ -1,21 +1,35 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.hedera.hashgraph.sdk; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.ByteString; import io.github.jsonSnapshot.SnapshotMatcher; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TransactionReceiptTest { - final static Instant time = Instant.ofEpochSecond(1554158542); + static final Instant time = Instant.ofEpochSecond(1554158542); @BeforeAll public static void beforeAll() { @@ -29,24 +43,23 @@ public static void afterAll() { static TransactionReceipt spawnReceiptExample() { return new TransactionReceipt( - null, - Status.SCHEDULE_ALREADY_DELETED, - new ExchangeRate(3, 4, time), - AccountId.fromString("1.2.3"), - FileId.fromString("4.5.6"), - ContractId.fromString("3.2.1"), - TopicId.fromString("9.8.7"), - TokenId.fromString("6.5.4"), - 3L, - ByteString.copyFrom("how now brown cow", StandardCharsets.UTF_8), - 30L, - ScheduleId.fromString("1.1.1"), - TransactionId.withValidStart(AccountId.fromString("3.3.3"), time), - List.of(1L, 2L, 3L), - 1, - new ArrayList<>(), - new ArrayList<>() - ); + null, + Status.SCHEDULE_ALREADY_DELETED, + new ExchangeRate(3, 4, time), + AccountId.fromString("1.2.3"), + FileId.fromString("4.5.6"), + ContractId.fromString("3.2.1"), + TopicId.fromString("9.8.7"), + TokenId.fromString("6.5.4"), + 3L, + ByteString.copyFrom("how now brown cow", StandardCharsets.UTF_8), + 30L, + ScheduleId.fromString("1.1.1"), + TransactionId.withValidStart(AccountId.fromString("3.3.3"), time), + List.of(1L, 2L, 3L), + 1, + new ArrayList<>(), + new ArrayList<>()); } @Test diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordQueryTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordQueryTest.java index 15590be19..64f3cdb74 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordQueryTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordQueryTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; import com.hedera.hashgraph.sdk.proto.QueryHeader; import io.github.jsonSnapshot.SnapshotMatcher; +import java.time.Instant; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.time.Instant; - public class TransactionRecordQueryTest { private static final PrivateKey unusedPrivateKey = PrivateKey.fromString( - "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); + "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"); final Instant validStart = Instant.ofEpochSecond(1554158542); @@ -47,13 +43,14 @@ public static void afterAll() { void shouldSerialize() { var builder = com.hedera.hashgraph.sdk.proto.Query.newBuilder(); spawnQuery().onMakeRequest(builder, QueryHeader.newBuilder().build()); - SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")).toMatchSnapshot(); + SnapshotMatcher.expect(builder.build().toString().replaceAll("@[A-Za-z0-9]+", "")) + .toMatchSnapshot(); } private TransactionRecordQuery spawnQuery() { return new TransactionRecordQuery() - .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5005"), validStart)) - .setIncludeChildren(true) - .setIncludeDuplicates(true); + .setTransactionId(TransactionId.withValidStart(AccountId.fromString("0.0.5005"), validStart)) + .setIncludeChildren(true) + .setIncludeDuplicates(true); } } diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordTest.java index f68ed794f..8299c17f0 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/TransactionRecordTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,31 +12,30 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk; +import static com.hedera.hashgraph.sdk.ContractFunctionResultTest.CALL_RESULT_HEX; +import static com.hedera.hashgraph.sdk.TransactionReceiptTest.spawnReceiptExample; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.protobuf.ByteString; import com.google.protobuf.BytesValue; import io.github.jsonSnapshot.SnapshotMatcher; -import org.bouncycastle.util.encoders.Hex; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; - -import static com.hedera.hashgraph.sdk.ContractFunctionResultTest.CALL_RESULT_HEX; -import static com.hedera.hashgraph.sdk.TransactionReceiptTest.spawnReceiptExample; -import static org.assertj.core.api.Assertions.assertThat; +import javax.annotation.Nullable; +import org.bouncycastle.util.encoders.Hex; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; public class TransactionRecordTest { - final static Instant time = Instant.ofEpochSecond(1554158542); + static final Instant time = Instant.ofEpochSecond(1554158542); private static final byte[] callResult = Hex.decode(CALL_RESULT_HEX); @BeforeAll @@ -54,48 +50,65 @@ public static void afterAll() { private static TransactionRecord spawnRecordExample(@Nullable ByteString prngBytes, @Nullable Integer prngNumber) { return new TransactionRecord( - spawnReceiptExample(), - ByteString.copyFrom("hello", StandardCharsets.UTF_8), - time, - TransactionId.withValidStart(AccountId.fromString("3.3.3"), time), - "memo", - 3000L, - new ContractFunctionResult( - com.hedera.hashgraph.sdk.proto.ContractFunctionResult.newBuilder() - .setContractID(ContractId.fromString("1.2.3").toProtobuf()) - .setContractCallResult(ByteString.copyFrom(callResult)) - .setEvmAddress(BytesValue.newBuilder().setValue(ByteString.copyFrom(Hex.decode("98329e006610472e6B372C080833f6D79ED833cf"))).build()) - .setSenderId(AccountId.fromString("1.2.3").toProtobuf()) - ), - List.of(new Transfer(AccountId.fromString("4.4.4"), Hbar.from(5))), - Map.of(TokenId.fromString("6.6.6"), Map.of(AccountId.fromString("1.1.1"), 4L)), - List.of(new TokenTransfer(TokenId.fromString("8.9.10"), AccountId.fromString("1.2.3"), 4L, 3, true)), - Map.of(TokenId.fromString("4.4.4"), List.of(new TokenNftTransfer(TokenId.fromString("4.4.4"), AccountId.fromString("1.2.3"), AccountId.fromString("3.2.1"), 4L, true))), - ScheduleId.fromString("3.3.3"), - List.of(new AssessedCustomFee(4L, TokenId.fromString("4.5.6"), AccountId.fromString("8.6.5"), List.of(AccountId.fromString("3.3.3")))), - List.of(new TokenAssociation(TokenId.fromString("5.4.3"), AccountId.fromString("8.7.6"))), - PrivateKey.fromStringECDSA("8776c6b831a1b61ac10dac0304a2843de4716f54b1919bb91a2685d0fe3f3048").getPublicKey(), - new ArrayList<>(), - new ArrayList<>(), - time, - ByteString.copyFrom("Some hash", StandardCharsets.UTF_8), - List.of(new Transfer(AccountId.fromString("1.2.3"), Hbar.from(8))), - prngBytes, - prngNumber, - ByteString.copyFrom("0x00", StandardCharsets.UTF_8), - List.of( - new PendingAirdropRecord(new PendingAirdropId(AccountId.fromString("0.0.123"), AccountId.fromString("0.0.124"), NftId.fromString("0.0.5005/1234")), 123), - new PendingAirdropRecord(new PendingAirdropId(AccountId.fromString("0.0.123"), AccountId.fromString("0.0.124"), TokenId.fromString("0.0.12345")), 123) - ) - ); + spawnReceiptExample(), + ByteString.copyFrom("hello", StandardCharsets.UTF_8), + time, + TransactionId.withValidStart(AccountId.fromString("3.3.3"), time), + "memo", + 3000L, + new ContractFunctionResult(com.hedera.hashgraph.sdk.proto.ContractFunctionResult.newBuilder() + .setContractID(ContractId.fromString("1.2.3").toProtobuf()) + .setContractCallResult(ByteString.copyFrom(callResult)) + .setEvmAddress(BytesValue.newBuilder() + .setValue(ByteString.copyFrom(Hex.decode("98329e006610472e6B372C080833f6D79ED833cf"))) + .build()) + .setSenderId(AccountId.fromString("1.2.3").toProtobuf())), + List.of(new Transfer(AccountId.fromString("4.4.4"), Hbar.from(5))), + Map.of(TokenId.fromString("6.6.6"), Map.of(AccountId.fromString("1.1.1"), 4L)), + List.of(new TokenTransfer(TokenId.fromString("8.9.10"), AccountId.fromString("1.2.3"), 4L, 3, true)), + Map.of( + TokenId.fromString("4.4.4"), + List.of(new TokenNftTransfer( + TokenId.fromString("4.4.4"), + AccountId.fromString("1.2.3"), + AccountId.fromString("3.2.1"), + 4L, + true))), + ScheduleId.fromString("3.3.3"), + List.of(new AssessedCustomFee( + 4L, + TokenId.fromString("4.5.6"), + AccountId.fromString("8.6.5"), + List.of(AccountId.fromString("3.3.3")))), + List.of(new TokenAssociation(TokenId.fromString("5.4.3"), AccountId.fromString("8.7.6"))), + PrivateKey.fromStringECDSA("8776c6b831a1b61ac10dac0304a2843de4716f54b1919bb91a2685d0fe3f3048") + .getPublicKey(), + new ArrayList<>(), + new ArrayList<>(), + time, + ByteString.copyFrom("Some hash", StandardCharsets.UTF_8), + List.of(new Transfer(AccountId.fromString("1.2.3"), Hbar.from(8))), + prngBytes, + prngNumber, + ByteString.copyFrom("0x00", StandardCharsets.UTF_8), + List.of( + new PendingAirdropRecord( + new PendingAirdropId( + AccountId.fromString("0.0.123"), + AccountId.fromString("0.0.124"), + NftId.fromString("0.0.5005/1234")), + 123), + new PendingAirdropRecord( + new PendingAirdropId( + AccountId.fromString("0.0.123"), + AccountId.fromString("0.0.124"), + TokenId.fromString("0.0.12345")), + 123))); } @Test void shouldSerialize() throws Exception { - var originalRecord = spawnRecordExample( - ByteString.copyFrom("very random bytes", StandardCharsets.UTF_8), - null - ); + var originalRecord = spawnRecordExample(ByteString.copyFrom("very random bytes", StandardCharsets.UTF_8), null); byte[] recordBytes = originalRecord.toBytes(); var copyRecord = TransactionRecord.fromBytes(recordBytes); assertThat(copyRecord.toString()).isEqualTo(originalRecord.toString()); @@ -104,10 +117,7 @@ void shouldSerialize() throws Exception { @Test void shouldSerialize2() throws Exception { - var originalRecord = spawnRecordExample( - null, - 4 /* chosen by fair dice roll. Guaranteed to be random */ - ); + var originalRecord = spawnRecordExample(null, 4 /* chosen by fair dice roll. Guaranteed to be random */); byte[] recordBytes = originalRecord.toBytes(); var copyRecord = TransactionRecord.fromBytes(recordBytes); assertThat(copyRecord.toString()).isEqualTo(originalRecord.toString()); diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/AccountUpdateIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/AccountUpdateIntegrationTest.java index f2aff5de2..7b71cbb6f 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/AccountUpdateIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/AccountUpdateIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.AccountCreateTransaction; import com.hedera.hashgraph.sdk.AccountInfoQuery; import com.hedera.hashgraph.sdk.AccountUpdateTransaction; @@ -26,33 +26,25 @@ import com.hedera.hashgraph.sdk.PrecheckStatusException; import com.hedera.hashgraph.sdk.PrivateKey; import com.hedera.hashgraph.sdk.Status; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import java.time.Duration; - import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class AccountUpdateIntegrationTest { @Test @DisplayName("Can update account with a new key") void canUpdateAccountWithNewKey() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { var key1 = PrivateKey.generateED25519(); var key2 = PrivateKey.generateED25519(); - var response = new AccountCreateTransaction() - .setKey(key1) - .execute(testEnv.client); + var response = new AccountCreateTransaction().setKey(key1).execute(testEnv.client); var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId); - var info = new AccountInfoQuery() - .setAccountId(accountId) - .execute(testEnv.client); + var info = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client); assertThat(info.accountId).isEqualTo(accountId); assertThat(info.isDeleted).isFalse(); @@ -63,17 +55,15 @@ void canUpdateAccountWithNewKey() throws Exception { assertThat(info.proxyReceived).isEqualTo(Hbar.ZERO); new AccountUpdateTransaction() - .setAccountId(accountId) - .setKey(key2.getPublicKey()) - .freezeWith(testEnv.client) - .sign(key1) - .sign(key2) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId) + .setKey(key2.getPublicKey()) + .freezeWith(testEnv.client) + .sign(key1) + .sign(key2) + .execute(testEnv.client) + .getReceipt(testEnv.client); - info = new AccountInfoQuery() - .setAccountId(accountId) - .execute(testEnv.client); + info = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client); assertThat(info.accountId).isEqualTo(accountId); assertThat(info.isDeleted).isFalse(); @@ -82,7 +72,6 @@ void canUpdateAccountWithNewKey() throws Exception { assertThat(info.autoRenewPeriod).isEqualTo(Duration.ofDays(90)); assertThat(info.proxyAccountId).isNull(); assertThat(info.proxyReceived).isEqualTo(Hbar.ZERO); - } } @@ -91,12 +80,11 @@ void canUpdateAccountWithNewKey() throws Exception { void cannotUpdateAccountWhenAccountIdIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new AccountUpdateTransaction() - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.ACCOUNT_ID_DOES_NOT_EXIST.toString()); - + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new AccountUpdateTransaction().execute(testEnv.client).getReceipt(testEnv.client); + }) + .withMessageContaining(Status.ACCOUNT_ID_DOES_NOT_EXIST.toString()); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ClientIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ClientIntegrationTest.java index f3ae4e580..087f905c9 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ClientIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ClientIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.*; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import java.time.Duration; - import java.util.ArrayList; import java.util.HashMap; import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; public class ClientIntegrationTest { @Test @@ -39,23 +35,19 @@ void testReplaceNodes() throws Exception { network.put("0.testnet.hedera.com:50211", new AccountId(3)); network.put("1.testnet.hedera.com:50211", new AccountId(4)); - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { testEnv.client - .setMaxQueryPayment(new Hbar(2)) - .setRequestTimeout(Duration.ofMinutes(2)) - .setNetwork(network); + .setMaxQueryPayment(new Hbar(2)) + .setRequestTimeout(Duration.ofMinutes(2)) + .setNetwork(network); assertThat(testEnv.operatorId).isNotNull(); // Execute two simple queries so we create a channel for each network node. - new AccountBalanceQuery() - .setAccountId(new AccountId(3)) - .execute(testEnv.client); + new AccountBalanceQuery().setAccountId(new AccountId(3)).execute(testEnv.client); - new AccountBalanceQuery() - .setAccountId(new AccountId(3)) - .execute(testEnv.client); + new AccountBalanceQuery().setAccountId(new AccountId(3)).execute(testEnv.client); network = new HashMap<>(); network.put("1.testnet.hedera.com:50211", new AccountId(4)); @@ -68,7 +60,6 @@ void testReplaceNodes() throws Exception { network.put("35.192.2.25:50211", new AccountId(5)); testEnv.client.setNetwork(network); - } } @@ -79,8 +70,8 @@ void transactionIdNetworkIsVerified() { client.setAutoValidateChecksums(true); new AccountCreateTransaction() - .setTransactionId(TransactionId.generate(AccountId.fromString("0.0.123-esxsf"))) - .execute(client); + .setTransactionId(TransactionId.generate(AccountId.fromString("0.0.123-esxsf"))) + .execute(client); client.close(); }); } @@ -88,23 +79,22 @@ void transactionIdNetworkIsVerified() { @Test @DisplayName("`setMaxNodesPerTransaction()`") void testMaxNodesPerTransaction() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { testEnv.client.setMaxNodesPerTransaction(1); var transaction = new AccountDeleteTransaction() - .setAccountId(testEnv.operatorId) - .freezeWith(testEnv.client); + .setAccountId(testEnv.operatorId) + .freezeWith(testEnv.client); assertThat(transaction.getNodeAccountIds()).isNotNull(); assertThat(transaction.getNodeAccountIds().size()).isEqualTo(1); - } } @Test void ping() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { var network = testEnv.client.getNetwork(); var nodes = new ArrayList<>(network.values()); @@ -119,7 +109,7 @@ void ping() throws Exception { @Test void pingAll() throws Exception { - try(var testEnv = new IntegrationTestEnv()){ + try (var testEnv = new IntegrationTestEnv()) { testEnv.client.setMaxNodeAttempts(1); testEnv.client.pingAll(); @@ -131,16 +121,13 @@ void pingAll() throws Exception { var node = nodes.get(0); - new AccountBalanceQuery() - .setAccountId(node) - .execute(testEnv.client); - + new AccountBalanceQuery().setAccountId(node).execute(testEnv.client); } } @Test void pingAllBadNetwork() throws Exception { - try(var testEnv = new IntegrationTestEnv(3)){ + try (var testEnv = new IntegrationTestEnv(3)) { // Skip if using local node. // Note: this check should be removed once the local node is supporting multiple nodes. @@ -161,28 +148,26 @@ void pingAllBadNetwork() throws Exception { testEnv.client.setNetwork(network); - - assertThatExceptionOfType(MaxAttemptsExceededException.class).isThrownBy(() -> { - testEnv.client.pingAll(); - }).withMessageContaining("exceeded maximum attempts"); + assertThatExceptionOfType(MaxAttemptsExceededException.class) + .isThrownBy(() -> { + testEnv.client.pingAll(); + }) + .withMessageContaining("exceeded maximum attempts"); var nodes = new ArrayList<>(testEnv.client.getNetwork().values()); assertThat(nodes.isEmpty()).isFalse(); var node = nodes.get(0); - new AccountBalanceQuery() - .setAccountId(node) - .execute(testEnv.client); + new AccountBalanceQuery().setAccountId(node).execute(testEnv.client); assertThat(testEnv.client.getNetwork().values().size()).isEqualTo(1); } - } @Test void pingAsync() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { var network = testEnv.client.getNetwork(); var nodes = new ArrayList<>(network.values()); @@ -197,7 +182,7 @@ void pingAsync() throws Exception { @Test void pingAllAsync() throws Exception { - try(var testEnv = new IntegrationTestEnv()){ + try (var testEnv = new IntegrationTestEnv()) { testEnv.client.setMaxNodeAttempts(1); testEnv.client.pingAllAsync().get(); @@ -209,10 +194,7 @@ void pingAllAsync() throws Exception { var node = nodes.get(0); - new AccountBalanceQuery() - .setAccountId(node) - .execute(testEnv.client); - + new AccountBalanceQuery().setAccountId(node).execute(testEnv.client); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractBytecodeIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractBytecodeIntegrationTest.java index 1bbd481bf..8c04b28e8 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractBytecodeIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractBytecodeIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.ContractByteCodeQuery; import com.hedera.hashgraph.sdk.ContractCreateTransaction; import com.hedera.hashgraph.sdk.ContractDeleteTransaction; @@ -29,203 +29,193 @@ import com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException; import com.hedera.hashgraph.sdk.PrecheckStatusException; import com.hedera.hashgraph.sdk.Status; +import java.util.Objects; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - public class ContractBytecodeIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; - - @Test - @DisplayName("Can query contract bytecode") - void canQueryContractBytecode() throws Exception { - try (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); - - response = new ContractCreateTransaction() - .setAdminKey(testEnv.operatorKey) - .setGas(200000) - .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); - - } - } - - @Test - @DisplayName("Can get cost, even with a big max") - void getCostBigMaxQueryContractBytecode() throws Exception { - try (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); - - response = new ContractCreateTransaction() - .setAdminKey(testEnv.operatorKey) - .setGas(200000) - .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); - - } - } - - @Test - @DisplayName("Error, max is smaller than set payment.") - void getCostSmallMaxQueryContractBytecode() throws Exception { - try (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); - - response = new ContractCreateTransaction() - .setAdminKey(testEnv.operatorKey) - .setGas(200000) - .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); - - } - } - - @Test - @DisplayName("Insufficient tx fee error.") - void getCostInsufficientTxFeeQueryContractBytecode() throws Exception { - try (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); - - response = new ContractCreateTransaction() - .setAdminKey(testEnv.operatorKey) - .setGas(200000) - .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")); + private static final String SMART_CONTRACT_BYTECODE = + "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; + + @Test + @DisplayName("Can query contract bytecode") + void canQueryContractBytecode() throws Exception { + try (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); - new ContractDeleteTransaction() - .setTransferAccountId(testEnv.operatorId) - .setContractId(contractId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - } - } - - @Test - @DisplayName("Cannot query contract bytecode when contract ID is not set") - void cannotQueryContractBytecodeWhenContractIDIsNotSet() throws Exception { - try (var testEnv = new IntegrationTestEnv(1)) { - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new ContractByteCodeQuery() - .execute(testEnv.client); - }).withMessageContaining(Status.INVALID_CONTRACT_ID.toString()); - - } - } + response = new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + } + } + + @Test + @DisplayName("Can get cost, even with a big max") + void getCostBigMaxQueryContractBytecode() throws Exception { + try (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); + + response = new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + } + } + + @Test + @DisplayName("Error, max is smaller than set payment.") + void getCostSmallMaxQueryContractBytecode() throws Exception { + try (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); + + response = new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + } + } + + @Test + @DisplayName("Insufficient tx fee error.") + void getCostInsufficientTxFeeQueryContractBytecode() throws Exception { + try (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); + + response = new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + } + } + + @Test + @DisplayName("Cannot query contract bytecode when contract ID is not set") + void cannotQueryContractBytecodeWhenContractIDIsNotSet() throws Exception { + try (var testEnv = new IntegrationTestEnv(1)) { + + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new ContractByteCodeQuery().execute(testEnv.client); + }) + .withMessageContaining(Status.INVALID_CONTRACT_ID.toString()); + } + } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractCallIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractCallIntegrationTest.java index fe9619810..66fc48eb0 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractCallIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractCallIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.ContractCallQuery; import com.hedera.hashgraph.sdk.ContractCreateTransaction; import com.hedera.hashgraph.sdk.ContractDeleteTransaction; @@ -29,16 +29,13 @@ import com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException; import com.hedera.hashgraph.sdk.PrecheckStatusException; import com.hedera.hashgraph.sdk.Status; +import java.util.Objects; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - public class ContractCallIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; + private static final String SMART_CONTRACT_BYTECODE = + "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; @Test @DisplayName("Can call contract function") @@ -46,44 +43,42 @@ void canCallContractFunction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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(200000) - .setFunction("getMessage") - .setQueryPayment(new Hbar(1)); + .setContractId(contractId) + .setGas(200000) + .setFunction("getMessage") + .setQueryPayment(new Hbar(1)); - var result = callQuery - .execute(testEnv.client); + 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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -93,42 +88,41 @@ void cannotCallContractFunctionWhenContractFunctionIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .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) - .setGas(100000) - .execute(testEnv.client); - }).withMessageContaining(Status.CONTRACT_REVERT_EXECUTED.toString()); + var contractId = Objects.requireNonNull(new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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) + .setGas(100000) + .execute(testEnv.client); + }) + .withMessageContaining(Status.CONTRACT_REVERT_EXECUTED.toString()); new ContractDeleteTransaction() - .setTransferAccountId(testEnv.operatorId) - .setContractId(contractId) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -138,42 +132,41 @@ void cannotCallContractFunctionWhenGasIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .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()); + var contractId = Objects.requireNonNull(new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -183,42 +176,41 @@ void cannotCallContractFunctionWhenContractIDIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .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()); + var contractId = Objects.requireNonNull(new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -228,19 +220,19 @@ void getCostBigMaxContractCallFunction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") + .execute(testEnv.client); var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); @@ -250,22 +242,20 @@ void getCostBigMaxContractCallFunction() throws Exception { .setFunction("getMessage") .setQueryPayment(new Hbar(1)); - var result = callQuery - .execute(testEnv.client); + 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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -275,19 +265,19 @@ void getCostSmallMaxContractCallFunction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") + .execute(testEnv.client); var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); @@ -302,16 +292,15 @@ void getCostSmallMaxContractCallFunction() throws Exception { }); new ContractDeleteTransaction() - .setTransferAccountId(testEnv.operatorId) - .setContractId(contractId) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -321,19 +310,19 @@ void getCostInsufficientTxFeeContractCallFunction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") + .execute(testEnv.client); var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); @@ -343,21 +332,22 @@ void getCostInsufficientTxFeeContractCallFunction() throws Exception { .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")); + 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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractCreateIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractCreateIntegrationTest.java index d4e5f2295..e86f1a60f 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractCreateIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractCreateIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.ContractCreateTransaction; import com.hedera.hashgraph.sdk.ContractDeleteTransaction; import com.hedera.hashgraph.sdk.ContractFunctionParameters; @@ -28,17 +28,13 @@ import com.hedera.hashgraph.sdk.PrecheckStatusException; import com.hedera.hashgraph.sdk.ReceiptStatusException; import com.hedera.hashgraph.sdk.Status; +import java.util.Objects; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.as; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - public class ContractCreateIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; + private static final String SMART_CONTRACT_BYTECODE = + "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; @Test @DisplayName("Can create contract") @@ -46,45 +42,44 @@ void canCreateContract() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + 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(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(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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -94,33 +89,31 @@ void canCreateContractWithNoAdminKey() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .setKeys(testEnv.operatorKey) + .setContents(SMART_CONTRACT_BYTECODE) + .execute(testEnv.client); var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); response = new ContractCreateTransaction() - .setGas(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setGas(200000) + .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); + 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(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]"); - } } @@ -130,29 +123,30 @@ void cannotCreateContractWhenGasIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .setKeys(testEnv.operatorKey) + .setContents(SMART_CONTRACT_BYTECODE) + .execute(testEnv.client); var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new ContractCreateTransaction() - .setAdminKey(testEnv.operatorKey) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INSUFFICIENT_GAS.toString()); + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setConstructorParameters( + new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INSUFFICIENT_GAS.toString()); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } - } @Test @@ -161,27 +155,28 @@ void cannotCreateContractWhenConstructorParametersAreNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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()); + 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); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -190,16 +185,18 @@ void cannotCreateContractWhenConstructorParametersAreNotSet() throws Exception { void cannotCreateContractWhenBytecodeFileIdIsNotSet() throws Exception { try (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()); - + 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()); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractDeleteIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractDeleteIntegrationTest.java index c7ec9a1d8..7779824e8 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractDeleteIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractDeleteIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.ContractCreateTransaction; import com.hedera.hashgraph.sdk.ContractDeleteTransaction; import com.hedera.hashgraph.sdk.ContractFunctionParameters; @@ -28,17 +28,13 @@ import com.hedera.hashgraph.sdk.PrecheckStatusException; import com.hedera.hashgraph.sdk.ReceiptStatusException; import com.hedera.hashgraph.sdk.Status; +import java.util.Objects; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.as; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - public class ContractDeleteIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; + private static final String SMART_CONTRACT_BYTECODE = + "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; @Test @DisplayName("Can delete contract with admin key") @@ -46,25 +42,23 @@ void canDeleteContractWithAdminKey() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + var info = new ContractInfoQuery().setContractId(contractId).execute(testEnv.client); assertThat(info.contractId).isEqualTo(contractId); assertThat(info.accountId).isNotNull(); @@ -76,16 +70,15 @@ void canDeleteContractWithAdminKey() throws Exception { assertThat(info.contractMemo).isEqualTo("[e2e::ContractCreateTransaction]"); new ContractDeleteTransaction() - .setTransferAccountId(testEnv.operatorId) - .setContractId(contractId) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -95,25 +88,22 @@ void cannotDeleteContractWhichHasNoAdminKey() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client) - .contractId - ); - - var info = new ContractInfoQuery() - .setContractId(contractId) - .execute(testEnv.client); + .setGas(200000) + .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client) + .contractId); + + var info = new ContractInfoQuery().setContractId(contractId).execute(testEnv.client); assertThat(info.contractId).isEqualTo(contractId); assertThat(info.accountId).isNotNull(); @@ -123,14 +113,15 @@ void cannotDeleteContractWhichHasNoAdminKey() throws Exception { assertThat(info.storage).isEqualTo(128); assertThat(info.contractMemo).isEqualTo("[e2e::ContractCreateTransaction]"); - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new ContractDeleteTransaction() - .setContractId(contractId) - .setTransferAccountId(testEnv.client.getOperatorAccountId()) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.MODIFYING_IMMUTABLE_CONTRACT.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new ContractDeleteTransaction() + .setContractId(contractId) + .setTransferAccountId(testEnv.client.getOperatorAccountId()) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.MODIFYING_IMMUTABLE_CONTRACT.toString()); } } @@ -139,12 +130,11 @@ void cannotDeleteContractWhichHasNoAdminKey() throws Exception { void cannotDeleteContractWhenContractIDIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new ContractDeleteTransaction() - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_CONTRACT_ID.toString()); - + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new ContractDeleteTransaction().execute(testEnv.client).getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_CONTRACT_ID.toString()); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractExecuteIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractExecuteIntegrationTest.java index eaaff2eb9..191b3ac48 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractExecuteIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractExecuteIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +33,8 @@ import org.junit.jupiter.api.Test; public class ContractExecuteIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; + private static final String SMART_CONTRACT_BYTECODE = + "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; @Test @DisplayName("Can execute contract methods") @@ -44,42 +42,41 @@ void canExecuteContractMethods() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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 receipt = new ContractExecuteTransaction() - .setContractId(contractId) - .setGas(100000) - .setFunction("setMessage", new ContractFunctionParameters().addString("new message")) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .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) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -88,14 +85,15 @@ void canExecuteContractMethods() throws Exception { void cannotExecuteContractWhenContractIDIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { - assertThatExceptionOfType(PrecheckStatusException.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()); - + assertThatExceptionOfType(PrecheckStatusException.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()); } } @@ -105,41 +103,42 @@ void cannotExecuteContractWhenContractFunctionParametersAreNotSet() throws Excep try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .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) + var contractId = Objects.requireNonNull(new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.CONTRACT_REVERT_EXECUTED.toString()); + .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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -149,41 +148,42 @@ void cannotExecuteContractWhenGasIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client).contractId); - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new ContractExecuteTransaction() - .setContractId(contractId) - .setFunction("setMessage", new ContractFunctionParameters().addString("new message")) + var contractId = Objects.requireNonNull(new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INSUFFICIENT_GAS.toString()); + .getReceipt(testEnv.client) + .contractId); + + assertThatExceptionOfType(PrecheckStatusException.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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractFunctionParametersIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractFunctionParametersIntegrationTest.java index bd75046aa..dc6f2a15e 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractFunctionParametersIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractFunctionParametersIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2023 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2023-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; import static org.assertj.core.api.Assertions.assertThat; @@ -42,7 +39,8 @@ import org.junit.jupiter.api.Test; public class ContractFunctionParametersIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "60806040523480156200001157600080fd5b5060408051608081018252600491810191825263082d8caf60e31b6060820152818152600160208201529060009081906200004d908262000106565b5060208201518160010155905050620001d2565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200008c57607f821691505b602082108103620000ad57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200010157600081815260208120601f850160051c81016020861015620000dc5750805b601f850160051c820191505b81811015620000fd57828155600101620000e8565b5050505b505050565b81516001600160401b0381111562000122576200012262000061565b6200013a8162000133845462000077565b84620000b3565b602080601f831160018114620001725760008415620001595750858301515b600019600386901b1c1916600185901b178555620000fd565b600085815260208120601f198616915b82811015620001a35788860151825594840194600190910190840162000182565b5085821015620001c25787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b615dfe80620001e26000396000f3fe608060405234801561001057600080fd5b50600436106108355760003560e01c80637f8082f711610437578063c5882dbb11610236578063e2a345291161013b578063f6e877f4116100c3578063fafc3b9911610092578063fafc3b9914611857578063fba1bc4c14611872578063febe099714611887578063ff5f54dd146118a2578063ffb80501146118bd57600080fd5b8063f6e877f4146117d9578063f8293f6e146117ff578063f914c4d214611821578063f962326a1461183c57600080fd5b8063eceda56a1161010a578063eceda56a1461174c578063ef65066114611767578063f0ebb92214611782578063f4e490f51461179d578063f680c24a146117be57600080fd5b8063e2a34529146116d8578063e4b90944146116f3578063e713cda81461170e578063ea945d301461173157600080fd5b8063d79d4d40116101be578063e05e91e01161018d578063e05e91e014611630578063e066de5014611656578063e0cddc551461167c578063e0f53e2414611697578063e1dbb318146116bd57600080fd5b8063d79d4d4014611592578063dade0c0b146115b8578063dbb04ed9146115da578063de9fb4841461160357600080fd5b8063cbd2e6a511610205578063cbd2e6a514611511578063cdb9e4e814611536578063cf7c3dfc1461155c578063d1b10ad714610ada578063d33c57501461157757600080fd5b8063c5882dbb1461148b578063c6c18a1c146114a6578063c7d8b87e146114d0578063cb47cdae146114f657600080fd5b8063a1bda1221161033c578063b5abe7df116102c4578063ba945bdb11610293578063ba945bdb146113dc578063bb6b524314611402578063bd90536a14611428578063be63d0b814611450578063c503772d1461146b57600080fd5b8063b5abe7df14611359578063b834bfe914611374578063b8da8d1614611395578063b989c7ee146113bb57600080fd5b8063aa016e681161030b578063aa016e68146112dc578063aa80ca2e14610c6b578063b2325c35146112f7578063b2db404a14611312578063b4e3e7b11461133357600080fd5b8063a1bda12214611259578063a401d60d1461127a578063a57ebf10146112a0578063a75761f1146112bb57600080fd5b80638f2805e0116103bf57806394cd7c801161038e57806394cd7c80146111b557806398508ba3146111d65780639b1794ae146111f7578063a08b9f671461121d578063a19962341461123e57600080fd5b80638f2805e0146111435780638ff4cfee1461115e578063909c5b2414611179578063923f5edf1461119457600080fd5b806386aba5a71161040657806386aba5a7146110ab578063881c8fb7146110c657806388b1dd37146110ec57806388b7e6f5146111075780638d7f60151461112857600080fd5b80637f8082f714610c6b578063817b24541461107557806381dbe13e14611090578063827147ce1461099a57600080fd5b806338fa6658116106435780635a8fd3b51161054857806370a5cb81116104d05780637ba844771161049f5780637ba8447714610fe25780637d0dc26214610ffd5780637d906c551461101e5780637e281630146110395780637ec32d841461105457600080fd5b806370a5cb8114610f5a57806372a06b4d14610f80578063737b801614610fa1578063796a27ea14610fbc57600080fd5b806369cbe0561161051757806369cbe05614610ecd5780636a54715c14610ee85780636a75c12f14610f095780636a9929db14610f245780636ee8f39c14610f3f57600080fd5b80635a8fd3b514610e4f578063628bc3ef14610e6a57806364e008c114610e8b57806368ef446614610eac57600080fd5b80634bbc9a67116105cb578063545e21131161059a578063545e211314610dd157806355f232a414610dfe57806357890ba914610e1957806357d9c08b14610e3457806359adb2df14610ada57600080fd5b80634bbc9a6714610d655780634e96247314610d80578063501297c214610d9b57806350370d8514610db657600080fd5b80633f396e67116106125780633f396e6714610ce3578063407b899b14610d0b578063435a33a814610d2c57806344e7b03714610af657806348d848d014610d4757600080fd5b806338fa665814610c6b5780633a73007714610c865780633b45e6e014610ca15780633e1a277114610cc257600080fd5b80631e9aa70f116107495780632ef16e8e116106d15780633135d681116106a05780633135d68114610beb57806333520ec314610c0657806333edb89614610c275780633729a2da14610c42578063382d087314610c5057600080fd5b80632ef16e8e14610b6d5780632f47a40d14610b8e5780632f6c1bb414610baf578063309f9ac914610bd057600080fd5b806322937ea91161071857806322937ea914610ada5780632421101f14610af657806324c3c3d214610b1c57806328a30eb714610b375780632a3082ce14610b5257600080fd5b80631e9aa70f14610a6e578063203ae83a14610a8957806321d1730b14610aa45780632234ea0214610abf57600080fd5b8063118b8415116107cc57806312b932a71161079b57806312b932a7146109db57806312cd95a1146109f657806315832ae414610a17578063189cea8e14610a325780631d11456214610a5357600080fd5b8063118b84151461095857806311ec6c9014610979578063126bc8151461099a578063129ed5da146109b557600080fd5b806306ac6fe11161080857806306ac6fe1146108ca57806308123e09146108f05780630a958dc81461091657806310d545531461093757600080fd5b8063017fa10b1461083a578063021d88ab14610868578063037454301461088e5780630577a846146108af575b600080fd5b61084b610848366004611a34565b90565b6040516001600160801b0390911681526020015b60405180910390f35b610876610848366004611a6d565b6040516001600160601b03909116815260200161085f565b61089c610848366004611a9a565b604051600c9190910b815260200161085f565b6108bd610848366004611b35565b60405161085f9190611bd1565b6108d8610848366004611c35565b6040516001600160781b03909116815260200161085f565b6108fe610848366004611c67565b60405166ffffffffffffff909116815260200161085f565b610924610848366004611c94565b60405160049190910b815260200161085f565b610945610848366004611cc1565b60405160119190910b815260200161085f565b610966610848366004611cee565b604051601e9190910b815260200161085f565b610987610848366004611d1b565b60405160139190910b815260200161085f565b6109a8610848366004611da5565b60405161085f9190611e27565b6109c3610848366004611e51565b6040516001600160981b03909116815260200161085f565b6109e9610848366004611e7e565b60405161085f9190611f0a565b610a04610848366004611f57565b60405160129190910b815260200161085f565b610a25610848366004611f83565b60405161085f919061200f565b610a4061084836600461205c565b60405160169190910b815260200161085f565b610a6161084836600461208f565b60405161085f919061211d565b610a7c610848366004612170565b60405161085f91906121fc565b610a97610848366004612237565b60405161085f91906122c3565b610ab261084836600461231b565b60405161085f91906123a7565b610acd6108483660046123fa565b60405161085f9190612486565b610ae86108483660046124c1565b60405190815260200161085f565b610b046108483660046124da565b6040516001600160a01b03909116815260200161085f565b610b2a61084836600461250e565b60405161085f919061259a565b610b456108483660046125db565b60405161085f9190612667565b610b606108483660046126b4565b60405161085f9190612740565b610b7b61084836600461278d565b604051601d9190910b815260200161085f565b610b9c6108483660046127a8565b604051600a9190910b815260200161085f565b610bbd6108483660046127d5565b60405160199190910b815260200161085f565b610bde610848366004612807565b60405161085f9190612893565b610bf96108483660046128eb565b60405161085f9190612977565b610c146108483660046129ca565b604051601a9190910b815260200161085f565b610c356108483660046129f7565b60405161085f9190612a83565b610a61610848366004612abe565b610c5e610848366004612b5e565b60405161085f9190612bea565b610c79610848366004612c25565b60405161085f9190612caa565b610c94610848366004612cfd565b60405161085f9190612d89565b610caf610848366004612de0565b60405160109190910b815260200161085f565b610cd0610848366004612e0d565b604051601c9190910b815260200161085f565b610cf1610848366004612e41565b60405168ffffffffffffffffff909116815260200161085f565b610d19610848366004612e6e565b60405160079190910b815260200161085f565b610d3a610848366004612e89565b60405161085f9190612f15565b610d55610848366004612f60565b604051901515815260200161085f565b610d73610848366004612f7b565b60405161085f9190613007565b610d8e610848366004613058565b60405161085f91906130e4565b610da9610848366004613137565b60405161085f91906131c3565b610dc4610848366004613215565b60405161085f91906132a1565b610de4610ddf3660046132f4565b6118e1565b60408051600093840b81529190920b60208201520161085f565b610e0c61084836600461330f565b60405161085f919061339b565b610e276108483660046133d6565b60405161085f9190613462565b610e426108483660046134b3565b60405161085f919061353f565b610e5d610848366004613593565b60405161085f919061361f565b610e7861084836600461366f565b60405160099190910b815260200161085f565b610e9961084836600461369c565b60405160179190910b815260200161085f565b610eba6108483660046136b7565b60405160149190910b815260200161085f565b610edb6108483660046136e4565b60405161085f9190613770565b610ef66108483660046137ab565b60405160069190910b815260200161085f565b610f176108483660046137d8565b60405161085f9190613864565b610f3261084836600461389f565b60405161085f919061392b565b610f4d610848366004613980565b60405161085f9190613a0c565b610f68610848366004613a67565b6040516001600160681b03909116815260200161085f565b610f8e6108483660046132f4565b60405160009190910b815260200161085f565b610faf610848366004613a99565b60405161085f9190613b25565b610fca610848366004613b66565b6040516001600160d81b03909116815260200161085f565b610ff0610848366004613b96565b60405161085f9190613c22565b61100b610848366004613c73565b604051601b9190910b815260200161085f565b61102c610848366004613ca1565b60405161085f9190613d2d565b611047610848366004613d7c565b60405161085f9190613e08565b611062610848366004613e56565b60405160029190910b815260200161085f565b611083610848366004613e88565b60405161085f9190613f14565b61109e610848366004613f55565b60405161085f9190614005565b6110b9610848366004614067565b60405161085f91906140f3565b6110d461084836600461414b565b6040516001600160b01b03909116815260200161085f565b6110fa610848366004614166565b60405161085f91906141f2565b61111561084836600461422d565b604051600f9190910b815260200161085f565b611136610848366004614248565b60405161085f91906142d4565b611151610848366004614326565b60405161085f91906143b2565b61116c6108483660046143f3565b60405161085f919061447f565b6111876108483660046144ba565b60405161085f919061455d565b6111a26108483660046145b2565b60405160159190910b815260200161085f565b6111c36108483660046145df565b60405160189190910b815260200161085f565b6111e46108483660046145fa565b604051600d9190910b815260200161085f565b61120561084836600461462c565b6040516001600160b81b03909116815260200161085f565b61122b610848366004614647565b604051600b9190910b815260200161085f565b61124c610848366004614662565b60405161085f91906146ee565b61126761084836600461472f565b60405160019190910b815260200161085f565b61128861084836600461474a565b6040516001600160f01b03909116815260200161085f565b6112ae610848366004614765565b60405161085f91906147f1565b6112c961084836600461482c565b60405161ffff909116815260200161085f565b6112ea610848366004614847565b60405161085f91906148d3565b611305610848366004614928565b60405161085f91906149b4565b611320610848366004614a01565b60405160059190910b815260200161085f565b611341610848366004614a1c565b6040516001600160701b03909116815260200161085f565b611367610848366004614a37565b60405161085f9190614ac3565b611382610848366004614b04565b604051600e9190910b815260200161085f565b6113a3610848366004614b1f565b6040516001600160a81b03909116815260200161085f565b6113c9610848366004614b3a565b60405160039190910b815260200161085f565b6113ea610848366004614b55565b6040516001600160881b03909116815260200161085f565b611410610848366004614b70565b6040516001600160c81b03909116815260200161085f565b61143b6114363660046124c1565b6118f9565b6040805192835260208301919091520161085f565b61145e610848366004614b8b565b60405161085f9190614c17565b611479610848366004614c52565b60405160ff909116815260200161085f565b611499610848366004614c6d565b60405161085f9190614cf9565b6114b4610848366004614d34565b6040516affffffffffffffffffffff909116815260200161085f565b6114de610848366004614d4f565b6040516001600160f81b03909116815260200161085f565b611504610848366004614d6a565b60405161085f9190614df6565b61151f610848366004614e31565b60405165ffffffffffff909116815260200161085f565b611544610848366004614e63565b6040516001600160e01b03909116815260200161085f565b61156a610848366004614e7e565b60405161085f9190614f0a565b611585610848366004614f45565b60405161085f9190614fd1565b6115a0610848366004615029565b6040516001600160d01b03909116815260200161085f565b6115cb6115c6366004615044565b611908565b60405161085f9392919061505f565b6115e8610848366004615096565b60405169ffffffffffffffffffff909116815260200161085f565b611616611611366004611c94565b611946565b60408051600493840b81529190920b60208201520161085f565b61163e6108483660046150b1565b6040516001600160401b03909116815260200161085f565b6116646108483660046150e3565b6040516001600160e81b03909116815260200161085f565b61168a6108483660046150fe565b60405161085f919061518a565b6116a56108483660046151c5565b6040516001600160c01b03909116815260200161085f565b6116cb6108483660046151f2565b60405161085f919061527e565b6116e66108483660046152b9565b60405161085f9190615345565b61170161084836600461538d565b60405161085f9190615419565b61171c610848366004615044565b60405163ffffffff909116815260200161085f565b61173f610848366004615454565b60405161085f91906154e0565b61175a61084836600461551b565b60405161085f91906155a7565b6117756108483660046155e2565b60405161085f919061566e565b6117906108483660046156af565b60405161085f919061573b565b6117ab610848366004615776565b60405160089190910b815260200161085f565b6117cc610848366004615791565b60405161085f919061581d565b6117e7610848366004615858565b6040516001600160901b03909116815260200161085f565b61180d610848366004615873565b60405162ffffff909116815260200161085f565b61182f61084836600461588e565b60405161085f919061591a565b61184a61084836600461595b565b60405161085f91906159e7565b611865610848366004615a28565b60405161085f9190615ab4565b61187a611955565b60405161085f9190615af5565b611895610848366004615b27565b60405161085f9190615bb3565b6118b0610848366004615bf4565b60405161085f9190615c80565b6118cb610848366004615cc1565b60405164ffffffffff909116815260200161085f565b600080826118f0816014615cf2565b91509150915091565b600080826118f0816001615d19565b600080606083611919600182615d41565b6040805180820190915260028152614f4b60f01b602082015291945063ffffffff16925090509193909250565b600080826118f0816001615d65565b604080518082019091526060815260006020820152600060405180604001604052908160008201805461198790615d8e565b80601f01602080910402602001604051908101604052809291908181526020018280546119b390615d8e565b8015611a005780601f106119d557610100808354040283529160200191611a00565b820191906000526020600020905b8154815290600101906020018083116119e357829003601f168201915b50505050508152602001600182015481525050905090565b80356001600160801b0381168114611a2f57600080fd5b919050565b600060208284031215611a4657600080fd5b611a4f82611a18565b9392505050565b80356001600160601b0381168114611a2f57600080fd5b600060208284031215611a7f57600080fd5b611a4f82611a56565b8035600c81900b8114611a2f57600080fd5b600060208284031215611aac57600080fd5b611a4f82611a88565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715611af357611af3611ab5565b604052919050565b60006001600160401b03821115611b1457611b14611ab5565b5060051b60200190565b80356001600160f01b0381168114611a2f57600080fd5b60006020808385031215611b4857600080fd5b82356001600160401b03811115611b5e57600080fd5b8301601f81018513611b6f57600080fd5b8035611b82611b7d82611afb565b611acb565b81815260059190911b82018301908381019087831115611ba157600080fd5b928401925b82841015611bc657611bb784611b1e565b82529284019290840190611ba6565b979650505050505050565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160f01b031683529284019291840191600101611bed565b50909695505050505050565b80356001600160781b0381168114611a2f57600080fd5b600060208284031215611c4757600080fd5b611a4f82611c1e565b803566ffffffffffffff81168114611a2f57600080fd5b600060208284031215611c7957600080fd5b611a4f82611c50565b8035600481900b8114611a2f57600080fd5b600060208284031215611ca657600080fd5b611a4f82611c82565b8035601181900b8114611a2f57600080fd5b600060208284031215611cd357600080fd5b611a4f82611caf565b8035601e81900b8114611a2f57600080fd5b600060208284031215611d0057600080fd5b611a4f82611cdc565b8035601381900b8114611a2f57600080fd5b600060208284031215611d2d57600080fd5b611a4f82611d09565b600082601f830112611d4757600080fd5b81356001600160401b03811115611d6057611d60611ab5565b611d73601f8201601f1916602001611acb565b818152846020838601011115611d8857600080fd5b816020850160208301376000918101602001919091529392505050565b600060208284031215611db757600080fd5b81356001600160401b03811115611dcd57600080fd5b611dd984828501611d36565b949350505050565b6000815180845260005b81811015611e0757602081850181015186830182015201611deb565b506000602082860101526020601f19601f83011685010191505092915050565b602081526000611a4f6020830184611de1565b80356001600160981b0381168114611a2f57600080fd5b600060208284031215611e6357600080fd5b611a4f82611e3a565b8035600381900b8114611a2f57600080fd5b60006020808385031215611e9157600080fd5b82356001600160401b03811115611ea757600080fd5b8301601f81018513611eb857600080fd5b8035611ec6611b7d82611afb565b81815260059190911b82018301908381019087831115611ee557600080fd5b928401925b82841015611bc657611efb84611e6c565b82529284019290840190611eea565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160030b83529284019291840191600101611f26565b8035601281900b8114611a2f57600080fd5b600060208284031215611f6957600080fd5b611a4f82611f45565b803560ff81168114611a2f57600080fd5b60006020808385031215611f9657600080fd5b82356001600160401b03811115611fac57600080fd5b8301601f81018513611fbd57600080fd5b8035611fcb611b7d82611afb565b81815260059190911b82018301908381019087831115611fea57600080fd5b928401925b82841015611bc65761200084611f72565b82529284019290840190611fef565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160ff168352928401929184019160010161202b565b8035601681900b8114611a2f57600080fd5b60006020828403121561206e57600080fd5b611a4f8261204a565b6001600160a01b038116811461208c57600080fd5b50565b600060208083850312156120a257600080fd5b82356001600160401b038111156120b857600080fd5b8301601f810185136120c957600080fd5b80356120d7611b7d82611afb565b81815260059190911b820183019083810190878311156120f657600080fd5b928401925b82841015611bc657833561210e81612077565b825292840192908401906120fb565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160a01b031683529284019291840191600101612139565b8035601481900b8114611a2f57600080fd5b6000602080838503121561218357600080fd5b82356001600160401b0381111561219957600080fd5b8301601f810185136121aa57600080fd5b80356121b8611b7d82611afb565b81815260059190911b820183019083810190878311156121d757600080fd5b928401925b82841015611bc6576121ed8461215e565b825292840192908401906121dc565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160140b83529284019291840191600101612218565b6000602080838503121561224a57600080fd5b82356001600160401b0381111561226057600080fd5b8301601f8101851361227157600080fd5b803561227f611b7d82611afb565b81815260059190911b8201830190838101908783111561229e57600080fd5b928401925b82841015611bc6576122b484611c50565b825292840192908401906122a3565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835166ffffffffffffff16835292840192918401916001016122df565b80356001600160f81b0381168114611a2f57600080fd5b6000602080838503121561232e57600080fd5b82356001600160401b0381111561234457600080fd5b8301601f8101851361235557600080fd5b8035612363611b7d82611afb565b81815260059190911b8201830190838101908783111561238257600080fd5b928401925b82841015611bc65761239884612304565b82529284019290840190612387565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160f81b0316835292840192918401916001016123c3565b8035600a81900b8114611a2f57600080fd5b6000602080838503121561240d57600080fd5b82356001600160401b0381111561242357600080fd5b8301601f8101851361243457600080fd5b8035612442611b7d82611afb565b81815260059190911b8201830190838101908783111561246157600080fd5b928401925b82841015611bc657612477846123e8565b82529284019290840190612466565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600a0b835292840192918401916001016124a2565b6000602082840312156124d357600080fd5b5035919050565b6000602082840312156124ec57600080fd5b8135611a4f81612077565b80356001600160c81b0381168114611a2f57600080fd5b6000602080838503121561252157600080fd5b82356001600160401b0381111561253757600080fd5b8301601f8101851361254857600080fd5b8035612556611b7d82611afb565b81815260059190911b8201830190838101908783111561257557600080fd5b928401925b82841015611bc65761258b846124f7565b8252928401929084019061257a565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160c81b0316835292840192918401916001016125b6565b600060208083850312156125ee57600080fd5b82356001600160401b0381111561260457600080fd5b8301601f8101851361261557600080fd5b8035612623611b7d82611afb565b81815260059190911b8201830190838101908783111561264257600080fd5b928401925b82841015611bc65761265884611d09565b82529284019290840190612647565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160130b83529284019291840191600101612683565b8035600b81900b8114611a2f57600080fd5b600060208083850312156126c757600080fd5b82356001600160401b038111156126dd57600080fd5b8301601f810185136126ee57600080fd5b80356126fc611b7d82611afb565b81815260059190911b8201830190838101908783111561271b57600080fd5b928401925b82841015611bc657612731846126a2565b82529284019290840190612720565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600b0b8352928401929184019160010161275c565b8035601d81900b8114611a2f57600080fd5b60006020828403121561279f57600080fd5b611a4f8261277b565b6000602082840312156127ba57600080fd5b611a4f826123e8565b8035601981900b8114611a2f57600080fd5b6000602082840312156127e757600080fd5b611a4f826127c3565b80356001600160c01b0381168114611a2f57600080fd5b6000602080838503121561281a57600080fd5b82356001600160401b0381111561283057600080fd5b8301601f8101851361284157600080fd5b803561284f611b7d82611afb565b81815260059190911b8201830190838101908783111561286e57600080fd5b928401925b82841015611bc657612884846127f0565b82529284019290840190612873565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160c01b0316835292840192918401916001016128af565b80356001600160401b0381168114611a2f57600080fd5b600060208083850312156128fe57600080fd5b82356001600160401b0381111561291457600080fd5b8301601f8101851361292557600080fd5b8035612933611b7d82611afb565b81815260059190911b8201830190838101908783111561295257600080fd5b928401925b82841015611bc657612968846128d4565b82529284019290840190612957565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160401b031683529284019291840191600101612993565b8035601a81900b8114611a2f57600080fd5b6000602082840312156129dc57600080fd5b611a4f826129b8565b8035600d81900b8114611a2f57600080fd5b60006020808385031215612a0a57600080fd5b82356001600160401b03811115612a2057600080fd5b8301601f81018513612a3157600080fd5b8035612a3f611b7d82611afb565b81815260059190911b82018301908381019087831115612a5e57600080fd5b928401925b82841015611bc657612a74846129e5565b82529284019290840190612a63565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600d0b83529284019291840191600101612a9f565b60006020808385031215612ad157600080fd5b82356001600160401b03811115612ae757600080fd5b8301601f81018513612af857600080fd5b8035612b06611b7d82611afb565b81815260059190911b82018301908381019087831115612b2557600080fd5b928401925b82841015611bc6578335612b3d81612077565b82529284019290840190612b2a565b8035600181900b8114611a2f57600080fd5b60006020808385031215612b7157600080fd5b82356001600160401b03811115612b8757600080fd5b8301601f81018513612b9857600080fd5b8035612ba6611b7d82611afb565b81815260059190911b82018301908381019087831115612bc557600080fd5b928401925b82841015611bc657612bdb84612b4c565b82529284019290840190612bca565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600190810b8452938501939285019201612c06565b60006020808385031215612c3857600080fd5b82356001600160401b03811115612c4e57600080fd5b8301601f81018513612c5f57600080fd5b8035612c6d611b7d82611afb565b81815260059190911b82018301908381019087831115612c8c57600080fd5b928401925b82841015611bc657833582529284019290840190612c91565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835183529284019291840191600101612cc6565b80356affffffffffffffffffffff81168114611a2f57600080fd5b60006020808385031215612d1057600080fd5b82356001600160401b03811115612d2657600080fd5b8301601f81018513612d3757600080fd5b8035612d45611b7d82611afb565b81815260059190911b82018301908381019087831115612d6457600080fd5b928401925b82841015611bc657612d7a84612ce2565b82529284019290840190612d69565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516affffffffffffffffffffff1683529284019291840191600101612da5565b8035601081900b8114611a2f57600080fd5b600060208284031215612df257600080fd5b611a4f82612dce565b8035601c81900b8114611a2f57600080fd5b600060208284031215612e1f57600080fd5b611a4f82612dfb565b803568ffffffffffffffffff81168114611a2f57600080fd5b600060208284031215612e5357600080fd5b611a4f82612e28565b8035600781900b8114611a2f57600080fd5b600060208284031215612e8057600080fd5b611a4f82612e5c565b60006020808385031215612e9c57600080fd5b82356001600160401b03811115612eb257600080fd5b8301601f81018513612ec357600080fd5b8035612ed1611b7d82611afb565b81815260059190911b82018301908381019087831115612ef057600080fd5b928401925b82841015611bc657612f06846129b8565b82529284019290840190612ef5565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601a0b83529284019291840191600101612f31565b80358015158114611a2f57600080fd5b600060208284031215612f7257600080fd5b611a4f82612f50565b60006020808385031215612f8e57600080fd5b82356001600160401b03811115612fa457600080fd5b8301601f81018513612fb557600080fd5b8035612fc3611b7d82611afb565b81815260059190911b82018301908381019087831115612fe257600080fd5b928401925b82841015611bc657612ff884612f50565b82529284019290840190612fe7565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351151583529284019291840191600101613023565b80356001600160d81b0381168114611a2f57600080fd5b6000602080838503121561306b57600080fd5b82356001600160401b0381111561308157600080fd5b8301601f8101851361309257600080fd5b80356130a0611b7d82611afb565b81815260059190911b820183019083810190878311156130bf57600080fd5b928401925b82841015611bc6576130d584613041565b825292840192908401906130c4565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160d81b031683529284019291840191600101613100565b8035601581900b8114611a2f57600080fd5b6000602080838503121561314a57600080fd5b82356001600160401b0381111561316057600080fd5b8301601f8101851361317157600080fd5b803561317f611b7d82611afb565b81815260059190911b8201830190838101908783111561319e57600080fd5b928401925b82841015611bc6576131b484613125565b825292840192908401906131a3565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160150b835292840192918401916001016131df565b80356001600160a81b0381168114611a2f57600080fd5b6000602080838503121561322857600080fd5b82356001600160401b0381111561323e57600080fd5b8301601f8101851361324f57600080fd5b803561325d611b7d82611afb565b81815260059190911b8201830190838101908783111561327c57600080fd5b928401925b82841015611bc657613292846131fe565b82529284019290840190613281565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160a81b0316835292840192918401916001016132bd565b8035600081900b8114611a2f57600080fd5b60006020828403121561330657600080fd5b611a4f826132e2565b6000602080838503121561332257600080fd5b82356001600160401b0381111561333857600080fd5b8301601f8101851361334957600080fd5b8035613357611b7d82611afb565b81815260059190911b8201830190838101908783111561337657600080fd5b928401925b82841015611bc65761338c84611caf565b8252928401929084019061337b565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160110b835292840192918401916001016133b7565b600060208083850312156133e957600080fd5b82356001600160401b038111156133ff57600080fd5b8301601f8101851361341057600080fd5b803561341e611b7d82611afb565b81815260059190911b8201830190838101908783111561343d57600080fd5b928401925b82841015611bc6576134538461204a565b82529284019290840190613442565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160160b8352928401929184019160010161347e565b803565ffffffffffff81168114611a2f57600080fd5b600060208083850312156134c657600080fd5b82356001600160401b038111156134dc57600080fd5b8301601f810185136134ed57600080fd5b80356134fb611b7d82611afb565b81815260059190911b8201830190838101908783111561351a57600080fd5b928401925b82841015611bc6576135308461349d565b8252928401929084019061351f565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835165ffffffffffff168352928401929184019160010161355b565b803563ffffffff81168114611a2f57600080fd5b600060208083850312156135a657600080fd5b82356001600160401b038111156135bc57600080fd5b8301601f810185136135cd57600080fd5b80356135db611b7d82611afb565b81815260059190911b820183019083810190878311156135fa57600080fd5b928401925b82841015611bc6576136108461357f565b825292840192908401906135ff565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835163ffffffff168352928401929184019160010161363b565b8035600981900b8114611a2f57600080fd5b60006020828403121561368157600080fd5b611a4f8261365d565b8035601781900b8114611a2f57600080fd5b6000602082840312156136ae57600080fd5b611a4f8261368a565b6000602082840312156136c957600080fd5b611a4f8261215e565b8035600681900b8114611a2f57600080fd5b600060208083850312156136f757600080fd5b82356001600160401b0381111561370d57600080fd5b8301601f8101851361371e57600080fd5b803561372c611b7d82611afb565b81815260059190911b8201830190838101908783111561374b57600080fd5b928401925b82841015611bc657613761846136d2565b82529284019290840190613750565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160060b8352928401929184019160010161378c565b6000602082840312156137bd57600080fd5b611a4f826136d2565b8035600f81900b8114611a2f57600080fd5b600060208083850312156137eb57600080fd5b82356001600160401b0381111561380157600080fd5b8301601f8101851361381257600080fd5b8035613820611b7d82611afb565b81815260059190911b8201830190838101908783111561383f57600080fd5b928401925b82841015611bc657613855846137c6565b82529284019290840190613844565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600f0b83529284019291840191600101613880565b600060208083850312156138b257600080fd5b82356001600160401b038111156138c857600080fd5b8301601f810185136138d957600080fd5b80356138e7611b7d82611afb565b81815260059190911b8201830190838101908783111561390657600080fd5b928401925b82841015611bc65761391c84611cdc565b8252928401929084019061390b565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601e0b83529284019291840191600101613947565b803569ffffffffffffffffffff81168114611a2f57600080fd5b6000602080838503121561399357600080fd5b82356001600160401b038111156139a957600080fd5b8301601f810185136139ba57600080fd5b80356139c8611b7d82611afb565b81815260059190911b820183019083810190878311156139e757600080fd5b928401925b82841015611bc6576139fd84613966565b825292840192908401906139ec565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835169ffffffffffffffffffff1683529284019291840191600101613a28565b80356001600160681b0381168114611a2f57600080fd5b600060208284031215613a7957600080fd5b611a4f82613a50565b80356001600160701b0381168114611a2f57600080fd5b60006020808385031215613aac57600080fd5b82356001600160401b03811115613ac257600080fd5b8301601f81018513613ad357600080fd5b8035613ae1611b7d82611afb565b81815260059190911b82018301908381019087831115613b0057600080fd5b928401925b82841015611bc657613b1684613a82565b82529284019290840190613b05565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160701b031683529284019291840191600101613b41565b600060208284031215613b7857600080fd5b611a4f82613041565b803564ffffffffff81168114611a2f57600080fd5b60006020808385031215613ba957600080fd5b82356001600160401b03811115613bbf57600080fd5b8301601f81018513613bd057600080fd5b8035613bde611b7d82611afb565b81815260059190911b82018301908381019087831115613bfd57600080fd5b928401925b82841015611bc657613c1384613b81565b82529284019290840190613c02565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835164ffffffffff1683529284019291840191600101613c3e565b8035601b81900b8114611a2f57600080fd5b600060208284031215613c8557600080fd5b611a4f82613c61565b803562ffffff81168114611a2f57600080fd5b60006020808385031215613cb457600080fd5b82356001600160401b03811115613cca57600080fd5b8301601f81018513613cdb57600080fd5b8035613ce9611b7d82611afb565b81815260059190911b82018301908381019087831115613d0857600080fd5b928401925b82841015611bc657613d1e84613c8e565b82529284019290840190613d0d565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835162ffffff1683529284019291840191600101613d49565b803561ffff81168114611a2f57600080fd5b60006020808385031215613d8f57600080fd5b82356001600160401b03811115613da557600080fd5b8301601f81018513613db657600080fd5b8035613dc4611b7d82611afb565b81815260059190911b82018301908381019087831115613de357600080fd5b928401925b82841015611bc657613df984613d6a565b82529284019290840190613de8565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835161ffff1683529284019291840191600101613e24565b8035600281900b8114611a2f57600080fd5b600060208284031215613e6857600080fd5b611a4f82613e44565b80356001600160901b0381168114611a2f57600080fd5b60006020808385031215613e9b57600080fd5b82356001600160401b03811115613eb157600080fd5b8301601f81018513613ec257600080fd5b8035613ed0611b7d82611afb565b81815260059190911b82018301908381019087831115613eef57600080fd5b928401925b82841015611bc657613f0584613e71565b82529284019290840190613ef4565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160901b031683529284019291840191600101613f30565b60006020808385031215613f6857600080fd5b82356001600160401b0380821115613f7f57600080fd5b818501915085601f830112613f9357600080fd5b8135613fa1611b7d82611afb565b81815260059190911b83018401908481019088831115613fc057600080fd5b8585015b83811015613ff857803585811115613fdc5760008081fd5b613fea8b89838a0101611d36565b845250918601918601613fc4565b5098975050505050505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561405a57603f19888603018452614048858351611de1565b9450928501929085019060010161402c565b5092979650505050505050565b6000602080838503121561407a57600080fd5b82356001600160401b0381111561409057600080fd5b8301601f810185136140a157600080fd5b80356140af611b7d82611afb565b81815260059190911b820183019083810190878311156140ce57600080fd5b928401925b82841015611bc6576140e484611e3a565b825292840192908401906140d3565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160981b03168352928401929184019160010161410f565b80356001600160b01b0381168114611a2f57600080fd5b60006020828403121561415d57600080fd5b611a4f82614134565b6000602080838503121561417957600080fd5b82356001600160401b0381111561418f57600080fd5b8301601f810185136141a057600080fd5b80356141ae611b7d82611afb565b81815260059190911b820183019083810190878311156141cd57600080fd5b928401925b82841015611bc6576141e384612dce565b825292840192908401906141d2565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160100b8352928401929184019160010161420e565b60006020828403121561423f57600080fd5b611a4f826137c6565b6000602080838503121561425b57600080fd5b82356001600160401b0381111561427157600080fd5b8301601f8101851361428257600080fd5b8035614290611b7d82611afb565b81815260059190911b820183019083810190878311156142af57600080fd5b928401925b82841015611bc6576142c5846127c3565b825292840192908401906142b4565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160190b835292840192918401916001016142f0565b80356001600160881b0381168114611a2f57600080fd5b6000602080838503121561433957600080fd5b82356001600160401b0381111561434f57600080fd5b8301601f8101851361436057600080fd5b803561436e611b7d82611afb565b81815260059190911b8201830190838101908783111561438d57600080fd5b928401925b82841015611bc6576143a38461430f565b82529284019290840190614392565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160881b0316835292840192918401916001016143ce565b6000602080838503121561440657600080fd5b82356001600160401b0381111561441c57600080fd5b8301601f8101851361442d57600080fd5b803561443b611b7d82611afb565b81815260059190911b8201830190838101908783111561445a57600080fd5b928401925b82841015611bc65761447084613c61565b8252928401929084019061445f565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601b0b8352928401929184019160010161449b565b600060208083850312156144cd57600080fd5b82356001600160401b03808211156144e457600080fd5b818501915085601f8301126144f857600080fd5b8135614506611b7d82611afb565b81815260059190911b8301840190848101908883111561452557600080fd5b8585015b83811015613ff8578035858111156145415760008081fd5b61454f8b89838a0101611d36565b845250918601918601614529565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561405a57603f198886030184526145a0858351611de1565b94509285019290850190600101614584565b6000602082840312156145c457600080fd5b611a4f82613125565b8035601881900b8114611a2f57600080fd5b6000602082840312156145f157600080fd5b611a4f826145cd565b60006020828403121561460c57600080fd5b611a4f826129e5565b80356001600160b81b0381168114611a2f57600080fd5b60006020828403121561463e57600080fd5b611a4f82614615565b60006020828403121561465957600080fd5b611a4f826126a2565b6000602080838503121561467557600080fd5b82356001600160401b0381111561468b57600080fd5b8301601f8101851361469c57600080fd5b80356146aa611b7d82611afb565b81815260059190911b820183019083810190878311156146c957600080fd5b928401925b82841015611bc6576146df84614134565b825292840192908401906146ce565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160b01b03168352928401929184019160010161470a565b60006020828403121561474157600080fd5b611a4f82612b4c565b60006020828403121561475c57600080fd5b611a4f82611b1e565b6000602080838503121561477857600080fd5b82356001600160401b0381111561478e57600080fd5b8301601f8101851361479f57600080fd5b80356147ad611b7d82611afb565b81815260059190911b820183019083810190878311156147cc57600080fd5b928401925b82841015611bc6576147e284611a88565b825292840192908401906147d1565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600c0b8352928401929184019160010161480d565b60006020828403121561483e57600080fd5b611a4f82613d6a565b6000602080838503121561485a57600080fd5b82356001600160401b0381111561487057600080fd5b8301601f8101851361488157600080fd5b803561488f611b7d82611afb565b81815260059190911b820183019083810190878311156148ae57600080fd5b928401925b82841015611bc6576148c484612e28565b825292840192908401906148b3565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835168ffffffffffffffffff16835292840192918401916001016148ef565b8035600e81900b8114611a2f57600080fd5b6000602080838503121561493b57600080fd5b82356001600160401b0381111561495157600080fd5b8301601f8101851361496257600080fd5b8035614970611b7d82611afb565b81815260059190911b8201830190838101908783111561498f57600080fd5b928401925b82841015611bc6576149a584614916565b82529284019290840190614994565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600e0b835292840192918401916001016149d0565b8035600581900b8114611a2f57600080fd5b600060208284031215614a1357600080fd5b611a4f826149ef565b600060208284031215614a2e57600080fd5b611a4f82613a82565b60006020808385031215614a4a57600080fd5b82356001600160401b03811115614a6057600080fd5b8301601f81018513614a7157600080fd5b8035614a7f611b7d82611afb565b81815260059190911b82018301908381019087831115614a9e57600080fd5b928401925b82841015611bc657614ab484613a50565b82529284019290840190614aa3565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160681b031683529284019291840191600101614adf565b600060208284031215614b1657600080fd5b611a4f82614916565b600060208284031215614b3157600080fd5b611a4f826131fe565b600060208284031215614b4c57600080fd5b611a4f82611e6c565b600060208284031215614b6757600080fd5b611a4f8261430f565b600060208284031215614b8257600080fd5b611a4f826124f7565b60006020808385031215614b9e57600080fd5b82356001600160401b03811115614bb457600080fd5b8301601f81018513614bc557600080fd5b8035614bd3611b7d82611afb565b81815260059190911b82018301908381019087831115614bf257600080fd5b928401925b82841015611bc657614c08846149ef565b82529284019290840190614bf7565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160050b83529284019291840191600101614c33565b600060208284031215614c6457600080fd5b611a4f82611f72565b60006020808385031215614c8057600080fd5b82356001600160401b03811115614c9657600080fd5b8301601f81018513614ca757600080fd5b8035614cb5611b7d82611afb565b81815260059190911b82018301908381019087831115614cd457600080fd5b928401925b82841015611bc657614cea84611f45565b82529284019290840190614cd9565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160120b83529284019291840191600101614d15565b600060208284031215614d4657600080fd5b611a4f82612ce2565b600060208284031215614d6157600080fd5b611a4f82612304565b60006020808385031215614d7d57600080fd5b82356001600160401b03811115614d9357600080fd5b8301601f81018513614da457600080fd5b8035614db2611b7d82611afb565b81815260059190911b82018301908381019087831115614dd157600080fd5b928401925b82841015611bc657614de7846145cd565b82529284019290840190614dd6565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160180b83529284019291840191600101614e12565b600060208284031215614e4357600080fd5b611a4f8261349d565b80356001600160e01b0381168114611a2f57600080fd5b600060208284031215614e7557600080fd5b611a4f82614e4c565b60006020808385031215614e9157600080fd5b82356001600160401b03811115614ea757600080fd5b8301601f81018513614eb857600080fd5b8035614ec6611b7d82611afb565b81815260059190911b82018301908381019087831115614ee557600080fd5b928401925b82841015611bc657614efb8461365d565b82529284019290840190614eea565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160090b83529284019291840191600101614f26565b60006020808385031215614f5857600080fd5b82356001600160401b03811115614f6e57600080fd5b8301601f81018513614f7f57600080fd5b8035614f8d611b7d82611afb565b81815260059190911b82018301908381019087831115614fac57600080fd5b928401925b82841015611bc657614fc284614e4c565b82529284019290840190614fb1565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160e01b031683529284019291840191600101614fed565b80356001600160d01b0381168114611a2f57600080fd5b60006020828403121561503b57600080fd5b611a4f82615012565b60006020828403121561505657600080fd5b611a4f8261357f565b63ffffffff841681526001600160401b038316602082015260606040820152600061508d6060830184611de1565b95945050505050565b6000602082840312156150a857600080fd5b611a4f82613966565b6000602082840312156150c357600080fd5b611a4f826128d4565b80356001600160e81b0381168114611a2f57600080fd5b6000602082840312156150f557600080fd5b611a4f826150cc565b6000602080838503121561511157600080fd5b82356001600160401b0381111561512757600080fd5b8301601f8101851361513857600080fd5b8035615146611b7d82611afb565b81815260059190911b8201830190838101908783111561516557600080fd5b928401925b82841015611bc65761517b84612dfb565b8252928401929084019061516a565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601c0b835292840192918401916001016151a6565b6000602082840312156151d757600080fd5b611a4f826127f0565b8035600881900b8114611a2f57600080fd5b6000602080838503121561520557600080fd5b82356001600160401b0381111561521b57600080fd5b8301601f8101851361522c57600080fd5b803561523a611b7d82611afb565b81815260059190911b8201830190838101908783111561525957600080fd5b928401925b82841015611bc65761526f846151e0565b8252928401929084019061525e565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160080b8352928401929184019160010161529a565b600060208083850312156152cc57600080fd5b82356001600160401b038111156152e257600080fd5b8301601f810185136152f357600080fd5b8035615301611b7d82611afb565b81815260059190911b8201830190838101908783111561532057600080fd5b928401925b82841015611bc657615336846132e2565b82529284019290840190615325565b602080825282518282018190526000919084820190604085019084805b82811015615380578451820b84529385019392850192600101615362565b5091979650505050505050565b600060208083850312156153a057600080fd5b82356001600160401b038111156153b657600080fd5b8301601f810185136153c757600080fd5b80356153d5611b7d82611afb565b81815260059190911b820183019083810190878311156153f457600080fd5b928401925b82841015611bc65761540a8461277b565b825292840192908401906153f9565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601d0b83529284019291840191600101615435565b6000602080838503121561546757600080fd5b82356001600160401b0381111561547d57600080fd5b8301601f8101851361548e57600080fd5b803561549c611b7d82611afb565b81815260059190911b820183019083810190878311156154bb57600080fd5b928401925b82841015611bc6576154d184611c82565b825292840192908401906154c0565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160040b835292840192918401916001016154fc565b6000602080838503121561552e57600080fd5b82356001600160401b0381111561554457600080fd5b8301601f8101851361555557600080fd5b8035615563611b7d82611afb565b81815260059190911b8201830190838101908783111561558257600080fd5b928401925b82841015611bc65761559884613e44565b82529284019290840190615587565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160020b835292840192918401916001016155c3565b600060208083850312156155f557600080fd5b82356001600160401b0381111561560b57600080fd5b8301601f8101851361561c57600080fd5b803561562a611b7d82611afb565b81815260059190911b8201830190838101908783111561564957600080fd5b928401925b82841015611bc65761565f846150cc565b8252928401929084019061564e565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160e81b03168352928401929184019160010161568a565b600060208083850312156156c257600080fd5b82356001600160401b038111156156d857600080fd5b8301601f810185136156e957600080fd5b80356156f7611b7d82611afb565b81815260059190911b8201830190838101908783111561571657600080fd5b928401925b82841015611bc65761572c8461368a565b8252928401929084019061571b565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160170b83529284019291840191600101615757565b60006020828403121561578857600080fd5b611a4f826151e0565b600060208083850312156157a457600080fd5b82356001600160401b038111156157ba57600080fd5b8301601f810185136157cb57600080fd5b80356157d9611b7d82611afb565b81815260059190911b820183019083810190878311156157f857600080fd5b928401925b82841015611bc65761580e84612e5c565b825292840192908401906157fd565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160070b83529284019291840191600101615839565b60006020828403121561586a57600080fd5b611a4f82613e71565b60006020828403121561588557600080fd5b611a4f82613c8e565b600060208083850312156158a157600080fd5b82356001600160401b038111156158b757600080fd5b8301601f810185136158c857600080fd5b80356158d6611b7d82611afb565b81815260059190911b820183019083810190878311156158f557600080fd5b928401925b82841015611bc65761590b84611a18565b825292840192908401906158fa565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160801b031683529284019291840191600101615936565b6000602080838503121561596e57600080fd5b82356001600160401b0381111561598457600080fd5b8301601f8101851361599557600080fd5b80356159a3611b7d82611afb565b81815260059190911b820183019083810190878311156159c257600080fd5b928401925b82841015611bc6576159d884615012565b825292840192908401906159c7565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160d01b031683529284019291840191600101615a03565b60006020808385031215615a3b57600080fd5b82356001600160401b03811115615a5157600080fd5b8301601f81018513615a6257600080fd5b8035615a70611b7d82611afb565b81815260059190911b82018301908381019087831115615a8f57600080fd5b928401925b82841015611bc657615aa584614615565b82529284019290840190615a94565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160b81b031683529284019291840191600101615ad0565b602081526000825160406020840152615b116060840182611de1565b9050602084015160408401528091505092915050565b60006020808385031215615b3a57600080fd5b82356001600160401b03811115615b5057600080fd5b8301601f81018513615b6157600080fd5b8035615b6f611b7d82611afb565b81815260059190911b82018301908381019087831115615b8e57600080fd5b928401925b82841015611bc657615ba484611c1e565b82529284019290840190615b93565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160781b031683529284019291840191600101615bcf565b60006020808385031215615c0757600080fd5b82356001600160401b03811115615c1d57600080fd5b8301601f81018513615c2e57600080fd5b8035615c3c611b7d82611afb565b81815260059190911b82018301908381019087831115615c5b57600080fd5b928401925b82841015611bc657615c7184611a56565b82529284019290840190615c60565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160601b031683529284019291840191600101615c9c565b600060208284031215615cd357600080fd5b611a4f82613b81565b634e487b7160e01b600052601160045260246000fd5b600081810b9083900b01607f8113607f1982121715615d1357615d13615cdc565b92915050565b8082018281126000831280158216821582161715615d3957615d39615cdc565b505092915050565b63ffffffff828116828216039080821115615d5e57615d5e615cdc565b5092915050565b600481810b9083900b01647fffffffff8113647fffffffff1982121715615d1357615d13615cdc565b600181811c90821680615da257607f821691505b602082108103615dc257634e487b7160e01b600052602260045260246000fd5b5091905056fea2646970667358221220a5b87b6881e1a012e4a59d55c230cfcf3a2342b83efdbfb3c5f5cfa532fc854864736f6c63430008120033"; + private static final String SMART_CONTRACT_BYTECODE = + "60806040523480156200001157600080fd5b5060408051608081018252600491810191825263082d8caf60e31b6060820152818152600160208201529060009081906200004d908262000106565b5060208201518160010155905050620001d2565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200008c57607f821691505b602082108103620000ad57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200010157600081815260208120601f850160051c81016020861015620000dc5750805b601f850160051c820191505b81811015620000fd57828155600101620000e8565b5050505b505050565b81516001600160401b0381111562000122576200012262000061565b6200013a8162000133845462000077565b84620000b3565b602080601f831160018114620001725760008415620001595750858301515b600019600386901b1c1916600185901b178555620000fd565b600085815260208120601f198616915b82811015620001a35788860151825594840194600190910190840162000182565b5085821015620001c25787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b615dfe80620001e26000396000f3fe608060405234801561001057600080fd5b50600436106108355760003560e01c80637f8082f711610437578063c5882dbb11610236578063e2a345291161013b578063f6e877f4116100c3578063fafc3b9911610092578063fafc3b9914611857578063fba1bc4c14611872578063febe099714611887578063ff5f54dd146118a2578063ffb80501146118bd57600080fd5b8063f6e877f4146117d9578063f8293f6e146117ff578063f914c4d214611821578063f962326a1461183c57600080fd5b8063eceda56a1161010a578063eceda56a1461174c578063ef65066114611767578063f0ebb92214611782578063f4e490f51461179d578063f680c24a146117be57600080fd5b8063e2a34529146116d8578063e4b90944146116f3578063e713cda81461170e578063ea945d301461173157600080fd5b8063d79d4d40116101be578063e05e91e01161018d578063e05e91e014611630578063e066de5014611656578063e0cddc551461167c578063e0f53e2414611697578063e1dbb318146116bd57600080fd5b8063d79d4d4014611592578063dade0c0b146115b8578063dbb04ed9146115da578063de9fb4841461160357600080fd5b8063cbd2e6a511610205578063cbd2e6a514611511578063cdb9e4e814611536578063cf7c3dfc1461155c578063d1b10ad714610ada578063d33c57501461157757600080fd5b8063c5882dbb1461148b578063c6c18a1c146114a6578063c7d8b87e146114d0578063cb47cdae146114f657600080fd5b8063a1bda1221161033c578063b5abe7df116102c4578063ba945bdb11610293578063ba945bdb146113dc578063bb6b524314611402578063bd90536a14611428578063be63d0b814611450578063c503772d1461146b57600080fd5b8063b5abe7df14611359578063b834bfe914611374578063b8da8d1614611395578063b989c7ee146113bb57600080fd5b8063aa016e681161030b578063aa016e68146112dc578063aa80ca2e14610c6b578063b2325c35146112f7578063b2db404a14611312578063b4e3e7b11461133357600080fd5b8063a1bda12214611259578063a401d60d1461127a578063a57ebf10146112a0578063a75761f1146112bb57600080fd5b80638f2805e0116103bf57806394cd7c801161038e57806394cd7c80146111b557806398508ba3146111d65780639b1794ae146111f7578063a08b9f671461121d578063a19962341461123e57600080fd5b80638f2805e0146111435780638ff4cfee1461115e578063909c5b2414611179578063923f5edf1461119457600080fd5b806386aba5a71161040657806386aba5a7146110ab578063881c8fb7146110c657806388b1dd37146110ec57806388b7e6f5146111075780638d7f60151461112857600080fd5b80637f8082f714610c6b578063817b24541461107557806381dbe13e14611090578063827147ce1461099a57600080fd5b806338fa6658116106435780635a8fd3b51161054857806370a5cb81116104d05780637ba844771161049f5780637ba8447714610fe25780637d0dc26214610ffd5780637d906c551461101e5780637e281630146110395780637ec32d841461105457600080fd5b806370a5cb8114610f5a57806372a06b4d14610f80578063737b801614610fa1578063796a27ea14610fbc57600080fd5b806369cbe0561161051757806369cbe05614610ecd5780636a54715c14610ee85780636a75c12f14610f095780636a9929db14610f245780636ee8f39c14610f3f57600080fd5b80635a8fd3b514610e4f578063628bc3ef14610e6a57806364e008c114610e8b57806368ef446614610eac57600080fd5b80634bbc9a67116105cb578063545e21131161059a578063545e211314610dd157806355f232a414610dfe57806357890ba914610e1957806357d9c08b14610e3457806359adb2df14610ada57600080fd5b80634bbc9a6714610d655780634e96247314610d80578063501297c214610d9b57806350370d8514610db657600080fd5b80633f396e67116106125780633f396e6714610ce3578063407b899b14610d0b578063435a33a814610d2c57806344e7b03714610af657806348d848d014610d4757600080fd5b806338fa665814610c6b5780633a73007714610c865780633b45e6e014610ca15780633e1a277114610cc257600080fd5b80631e9aa70f116107495780632ef16e8e116106d15780633135d681116106a05780633135d68114610beb57806333520ec314610c0657806333edb89614610c275780633729a2da14610c42578063382d087314610c5057600080fd5b80632ef16e8e14610b6d5780632f47a40d14610b8e5780632f6c1bb414610baf578063309f9ac914610bd057600080fd5b806322937ea91161071857806322937ea914610ada5780632421101f14610af657806324c3c3d214610b1c57806328a30eb714610b375780632a3082ce14610b5257600080fd5b80631e9aa70f14610a6e578063203ae83a14610a8957806321d1730b14610aa45780632234ea0214610abf57600080fd5b8063118b8415116107cc57806312b932a71161079b57806312b932a7146109db57806312cd95a1146109f657806315832ae414610a17578063189cea8e14610a325780631d11456214610a5357600080fd5b8063118b84151461095857806311ec6c9014610979578063126bc8151461099a578063129ed5da146109b557600080fd5b806306ac6fe11161080857806306ac6fe1146108ca57806308123e09146108f05780630a958dc81461091657806310d545531461093757600080fd5b8063017fa10b1461083a578063021d88ab14610868578063037454301461088e5780630577a846146108af575b600080fd5b61084b610848366004611a34565b90565b6040516001600160801b0390911681526020015b60405180910390f35b610876610848366004611a6d565b6040516001600160601b03909116815260200161085f565b61089c610848366004611a9a565b604051600c9190910b815260200161085f565b6108bd610848366004611b35565b60405161085f9190611bd1565b6108d8610848366004611c35565b6040516001600160781b03909116815260200161085f565b6108fe610848366004611c67565b60405166ffffffffffffff909116815260200161085f565b610924610848366004611c94565b60405160049190910b815260200161085f565b610945610848366004611cc1565b60405160119190910b815260200161085f565b610966610848366004611cee565b604051601e9190910b815260200161085f565b610987610848366004611d1b565b60405160139190910b815260200161085f565b6109a8610848366004611da5565b60405161085f9190611e27565b6109c3610848366004611e51565b6040516001600160981b03909116815260200161085f565b6109e9610848366004611e7e565b60405161085f9190611f0a565b610a04610848366004611f57565b60405160129190910b815260200161085f565b610a25610848366004611f83565b60405161085f919061200f565b610a4061084836600461205c565b60405160169190910b815260200161085f565b610a6161084836600461208f565b60405161085f919061211d565b610a7c610848366004612170565b60405161085f91906121fc565b610a97610848366004612237565b60405161085f91906122c3565b610ab261084836600461231b565b60405161085f91906123a7565b610acd6108483660046123fa565b60405161085f9190612486565b610ae86108483660046124c1565b60405190815260200161085f565b610b046108483660046124da565b6040516001600160a01b03909116815260200161085f565b610b2a61084836600461250e565b60405161085f919061259a565b610b456108483660046125db565b60405161085f9190612667565b610b606108483660046126b4565b60405161085f9190612740565b610b7b61084836600461278d565b604051601d9190910b815260200161085f565b610b9c6108483660046127a8565b604051600a9190910b815260200161085f565b610bbd6108483660046127d5565b60405160199190910b815260200161085f565b610bde610848366004612807565b60405161085f9190612893565b610bf96108483660046128eb565b60405161085f9190612977565b610c146108483660046129ca565b604051601a9190910b815260200161085f565b610c356108483660046129f7565b60405161085f9190612a83565b610a61610848366004612abe565b610c5e610848366004612b5e565b60405161085f9190612bea565b610c79610848366004612c25565b60405161085f9190612caa565b610c94610848366004612cfd565b60405161085f9190612d89565b610caf610848366004612de0565b60405160109190910b815260200161085f565b610cd0610848366004612e0d565b604051601c9190910b815260200161085f565b610cf1610848366004612e41565b60405168ffffffffffffffffff909116815260200161085f565b610d19610848366004612e6e565b60405160079190910b815260200161085f565b610d3a610848366004612e89565b60405161085f9190612f15565b610d55610848366004612f60565b604051901515815260200161085f565b610d73610848366004612f7b565b60405161085f9190613007565b610d8e610848366004613058565b60405161085f91906130e4565b610da9610848366004613137565b60405161085f91906131c3565b610dc4610848366004613215565b60405161085f91906132a1565b610de4610ddf3660046132f4565b6118e1565b60408051600093840b81529190920b60208201520161085f565b610e0c61084836600461330f565b60405161085f919061339b565b610e276108483660046133d6565b60405161085f9190613462565b610e426108483660046134b3565b60405161085f919061353f565b610e5d610848366004613593565b60405161085f919061361f565b610e7861084836600461366f565b60405160099190910b815260200161085f565b610e9961084836600461369c565b60405160179190910b815260200161085f565b610eba6108483660046136b7565b60405160149190910b815260200161085f565b610edb6108483660046136e4565b60405161085f9190613770565b610ef66108483660046137ab565b60405160069190910b815260200161085f565b610f176108483660046137d8565b60405161085f9190613864565b610f3261084836600461389f565b60405161085f919061392b565b610f4d610848366004613980565b60405161085f9190613a0c565b610f68610848366004613a67565b6040516001600160681b03909116815260200161085f565b610f8e6108483660046132f4565b60405160009190910b815260200161085f565b610faf610848366004613a99565b60405161085f9190613b25565b610fca610848366004613b66565b6040516001600160d81b03909116815260200161085f565b610ff0610848366004613b96565b60405161085f9190613c22565b61100b610848366004613c73565b604051601b9190910b815260200161085f565b61102c610848366004613ca1565b60405161085f9190613d2d565b611047610848366004613d7c565b60405161085f9190613e08565b611062610848366004613e56565b60405160029190910b815260200161085f565b611083610848366004613e88565b60405161085f9190613f14565b61109e610848366004613f55565b60405161085f9190614005565b6110b9610848366004614067565b60405161085f91906140f3565b6110d461084836600461414b565b6040516001600160b01b03909116815260200161085f565b6110fa610848366004614166565b60405161085f91906141f2565b61111561084836600461422d565b604051600f9190910b815260200161085f565b611136610848366004614248565b60405161085f91906142d4565b611151610848366004614326565b60405161085f91906143b2565b61116c6108483660046143f3565b60405161085f919061447f565b6111876108483660046144ba565b60405161085f919061455d565b6111a26108483660046145b2565b60405160159190910b815260200161085f565b6111c36108483660046145df565b60405160189190910b815260200161085f565b6111e46108483660046145fa565b604051600d9190910b815260200161085f565b61120561084836600461462c565b6040516001600160b81b03909116815260200161085f565b61122b610848366004614647565b604051600b9190910b815260200161085f565b61124c610848366004614662565b60405161085f91906146ee565b61126761084836600461472f565b60405160019190910b815260200161085f565b61128861084836600461474a565b6040516001600160f01b03909116815260200161085f565b6112ae610848366004614765565b60405161085f91906147f1565b6112c961084836600461482c565b60405161ffff909116815260200161085f565b6112ea610848366004614847565b60405161085f91906148d3565b611305610848366004614928565b60405161085f91906149b4565b611320610848366004614a01565b60405160059190910b815260200161085f565b611341610848366004614a1c565b6040516001600160701b03909116815260200161085f565b611367610848366004614a37565b60405161085f9190614ac3565b611382610848366004614b04565b604051600e9190910b815260200161085f565b6113a3610848366004614b1f565b6040516001600160a81b03909116815260200161085f565b6113c9610848366004614b3a565b60405160039190910b815260200161085f565b6113ea610848366004614b55565b6040516001600160881b03909116815260200161085f565b611410610848366004614b70565b6040516001600160c81b03909116815260200161085f565b61143b6114363660046124c1565b6118f9565b6040805192835260208301919091520161085f565b61145e610848366004614b8b565b60405161085f9190614c17565b611479610848366004614c52565b60405160ff909116815260200161085f565b611499610848366004614c6d565b60405161085f9190614cf9565b6114b4610848366004614d34565b6040516affffffffffffffffffffff909116815260200161085f565b6114de610848366004614d4f565b6040516001600160f81b03909116815260200161085f565b611504610848366004614d6a565b60405161085f9190614df6565b61151f610848366004614e31565b60405165ffffffffffff909116815260200161085f565b611544610848366004614e63565b6040516001600160e01b03909116815260200161085f565b61156a610848366004614e7e565b60405161085f9190614f0a565b611585610848366004614f45565b60405161085f9190614fd1565b6115a0610848366004615029565b6040516001600160d01b03909116815260200161085f565b6115cb6115c6366004615044565b611908565b60405161085f9392919061505f565b6115e8610848366004615096565b60405169ffffffffffffffffffff909116815260200161085f565b611616611611366004611c94565b611946565b60408051600493840b81529190920b60208201520161085f565b61163e6108483660046150b1565b6040516001600160401b03909116815260200161085f565b6116646108483660046150e3565b6040516001600160e81b03909116815260200161085f565b61168a6108483660046150fe565b60405161085f919061518a565b6116a56108483660046151c5565b6040516001600160c01b03909116815260200161085f565b6116cb6108483660046151f2565b60405161085f919061527e565b6116e66108483660046152b9565b60405161085f9190615345565b61170161084836600461538d565b60405161085f9190615419565b61171c610848366004615044565b60405163ffffffff909116815260200161085f565b61173f610848366004615454565b60405161085f91906154e0565b61175a61084836600461551b565b60405161085f91906155a7565b6117756108483660046155e2565b60405161085f919061566e565b6117906108483660046156af565b60405161085f919061573b565b6117ab610848366004615776565b60405160089190910b815260200161085f565b6117cc610848366004615791565b60405161085f919061581d565b6117e7610848366004615858565b6040516001600160901b03909116815260200161085f565b61180d610848366004615873565b60405162ffffff909116815260200161085f565b61182f61084836600461588e565b60405161085f919061591a565b61184a61084836600461595b565b60405161085f91906159e7565b611865610848366004615a28565b60405161085f9190615ab4565b61187a611955565b60405161085f9190615af5565b611895610848366004615b27565b60405161085f9190615bb3565b6118b0610848366004615bf4565b60405161085f9190615c80565b6118cb610848366004615cc1565b60405164ffffffffff909116815260200161085f565b600080826118f0816014615cf2565b91509150915091565b600080826118f0816001615d19565b600080606083611919600182615d41565b6040805180820190915260028152614f4b60f01b602082015291945063ffffffff16925090509193909250565b600080826118f0816001615d65565b604080518082019091526060815260006020820152600060405180604001604052908160008201805461198790615d8e565b80601f01602080910402602001604051908101604052809291908181526020018280546119b390615d8e565b8015611a005780601f106119d557610100808354040283529160200191611a00565b820191906000526020600020905b8154815290600101906020018083116119e357829003601f168201915b50505050508152602001600182015481525050905090565b80356001600160801b0381168114611a2f57600080fd5b919050565b600060208284031215611a4657600080fd5b611a4f82611a18565b9392505050565b80356001600160601b0381168114611a2f57600080fd5b600060208284031215611a7f57600080fd5b611a4f82611a56565b8035600c81900b8114611a2f57600080fd5b600060208284031215611aac57600080fd5b611a4f82611a88565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715611af357611af3611ab5565b604052919050565b60006001600160401b03821115611b1457611b14611ab5565b5060051b60200190565b80356001600160f01b0381168114611a2f57600080fd5b60006020808385031215611b4857600080fd5b82356001600160401b03811115611b5e57600080fd5b8301601f81018513611b6f57600080fd5b8035611b82611b7d82611afb565b611acb565b81815260059190911b82018301908381019087831115611ba157600080fd5b928401925b82841015611bc657611bb784611b1e565b82529284019290840190611ba6565b979650505050505050565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160f01b031683529284019291840191600101611bed565b50909695505050505050565b80356001600160781b0381168114611a2f57600080fd5b600060208284031215611c4757600080fd5b611a4f82611c1e565b803566ffffffffffffff81168114611a2f57600080fd5b600060208284031215611c7957600080fd5b611a4f82611c50565b8035600481900b8114611a2f57600080fd5b600060208284031215611ca657600080fd5b611a4f82611c82565b8035601181900b8114611a2f57600080fd5b600060208284031215611cd357600080fd5b611a4f82611caf565b8035601e81900b8114611a2f57600080fd5b600060208284031215611d0057600080fd5b611a4f82611cdc565b8035601381900b8114611a2f57600080fd5b600060208284031215611d2d57600080fd5b611a4f82611d09565b600082601f830112611d4757600080fd5b81356001600160401b03811115611d6057611d60611ab5565b611d73601f8201601f1916602001611acb565b818152846020838601011115611d8857600080fd5b816020850160208301376000918101602001919091529392505050565b600060208284031215611db757600080fd5b81356001600160401b03811115611dcd57600080fd5b611dd984828501611d36565b949350505050565b6000815180845260005b81811015611e0757602081850181015186830182015201611deb565b506000602082860101526020601f19601f83011685010191505092915050565b602081526000611a4f6020830184611de1565b80356001600160981b0381168114611a2f57600080fd5b600060208284031215611e6357600080fd5b611a4f82611e3a565b8035600381900b8114611a2f57600080fd5b60006020808385031215611e9157600080fd5b82356001600160401b03811115611ea757600080fd5b8301601f81018513611eb857600080fd5b8035611ec6611b7d82611afb565b81815260059190911b82018301908381019087831115611ee557600080fd5b928401925b82841015611bc657611efb84611e6c565b82529284019290840190611eea565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160030b83529284019291840191600101611f26565b8035601281900b8114611a2f57600080fd5b600060208284031215611f6957600080fd5b611a4f82611f45565b803560ff81168114611a2f57600080fd5b60006020808385031215611f9657600080fd5b82356001600160401b03811115611fac57600080fd5b8301601f81018513611fbd57600080fd5b8035611fcb611b7d82611afb565b81815260059190911b82018301908381019087831115611fea57600080fd5b928401925b82841015611bc65761200084611f72565b82529284019290840190611fef565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160ff168352928401929184019160010161202b565b8035601681900b8114611a2f57600080fd5b60006020828403121561206e57600080fd5b611a4f8261204a565b6001600160a01b038116811461208c57600080fd5b50565b600060208083850312156120a257600080fd5b82356001600160401b038111156120b857600080fd5b8301601f810185136120c957600080fd5b80356120d7611b7d82611afb565b81815260059190911b820183019083810190878311156120f657600080fd5b928401925b82841015611bc657833561210e81612077565b825292840192908401906120fb565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160a01b031683529284019291840191600101612139565b8035601481900b8114611a2f57600080fd5b6000602080838503121561218357600080fd5b82356001600160401b0381111561219957600080fd5b8301601f810185136121aa57600080fd5b80356121b8611b7d82611afb565b81815260059190911b820183019083810190878311156121d757600080fd5b928401925b82841015611bc6576121ed8461215e565b825292840192908401906121dc565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160140b83529284019291840191600101612218565b6000602080838503121561224a57600080fd5b82356001600160401b0381111561226057600080fd5b8301601f8101851361227157600080fd5b803561227f611b7d82611afb565b81815260059190911b8201830190838101908783111561229e57600080fd5b928401925b82841015611bc6576122b484611c50565b825292840192908401906122a3565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835166ffffffffffffff16835292840192918401916001016122df565b80356001600160f81b0381168114611a2f57600080fd5b6000602080838503121561232e57600080fd5b82356001600160401b0381111561234457600080fd5b8301601f8101851361235557600080fd5b8035612363611b7d82611afb565b81815260059190911b8201830190838101908783111561238257600080fd5b928401925b82841015611bc65761239884612304565b82529284019290840190612387565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160f81b0316835292840192918401916001016123c3565b8035600a81900b8114611a2f57600080fd5b6000602080838503121561240d57600080fd5b82356001600160401b0381111561242357600080fd5b8301601f8101851361243457600080fd5b8035612442611b7d82611afb565b81815260059190911b8201830190838101908783111561246157600080fd5b928401925b82841015611bc657612477846123e8565b82529284019290840190612466565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600a0b835292840192918401916001016124a2565b6000602082840312156124d357600080fd5b5035919050565b6000602082840312156124ec57600080fd5b8135611a4f81612077565b80356001600160c81b0381168114611a2f57600080fd5b6000602080838503121561252157600080fd5b82356001600160401b0381111561253757600080fd5b8301601f8101851361254857600080fd5b8035612556611b7d82611afb565b81815260059190911b8201830190838101908783111561257557600080fd5b928401925b82841015611bc65761258b846124f7565b8252928401929084019061257a565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160c81b0316835292840192918401916001016125b6565b600060208083850312156125ee57600080fd5b82356001600160401b0381111561260457600080fd5b8301601f8101851361261557600080fd5b8035612623611b7d82611afb565b81815260059190911b8201830190838101908783111561264257600080fd5b928401925b82841015611bc65761265884611d09565b82529284019290840190612647565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160130b83529284019291840191600101612683565b8035600b81900b8114611a2f57600080fd5b600060208083850312156126c757600080fd5b82356001600160401b038111156126dd57600080fd5b8301601f810185136126ee57600080fd5b80356126fc611b7d82611afb565b81815260059190911b8201830190838101908783111561271b57600080fd5b928401925b82841015611bc657612731846126a2565b82529284019290840190612720565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600b0b8352928401929184019160010161275c565b8035601d81900b8114611a2f57600080fd5b60006020828403121561279f57600080fd5b611a4f8261277b565b6000602082840312156127ba57600080fd5b611a4f826123e8565b8035601981900b8114611a2f57600080fd5b6000602082840312156127e757600080fd5b611a4f826127c3565b80356001600160c01b0381168114611a2f57600080fd5b6000602080838503121561281a57600080fd5b82356001600160401b0381111561283057600080fd5b8301601f8101851361284157600080fd5b803561284f611b7d82611afb565b81815260059190911b8201830190838101908783111561286e57600080fd5b928401925b82841015611bc657612884846127f0565b82529284019290840190612873565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160c01b0316835292840192918401916001016128af565b80356001600160401b0381168114611a2f57600080fd5b600060208083850312156128fe57600080fd5b82356001600160401b0381111561291457600080fd5b8301601f8101851361292557600080fd5b8035612933611b7d82611afb565b81815260059190911b8201830190838101908783111561295257600080fd5b928401925b82841015611bc657612968846128d4565b82529284019290840190612957565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160401b031683529284019291840191600101612993565b8035601a81900b8114611a2f57600080fd5b6000602082840312156129dc57600080fd5b611a4f826129b8565b8035600d81900b8114611a2f57600080fd5b60006020808385031215612a0a57600080fd5b82356001600160401b03811115612a2057600080fd5b8301601f81018513612a3157600080fd5b8035612a3f611b7d82611afb565b81815260059190911b82018301908381019087831115612a5e57600080fd5b928401925b82841015611bc657612a74846129e5565b82529284019290840190612a63565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600d0b83529284019291840191600101612a9f565b60006020808385031215612ad157600080fd5b82356001600160401b03811115612ae757600080fd5b8301601f81018513612af857600080fd5b8035612b06611b7d82611afb565b81815260059190911b82018301908381019087831115612b2557600080fd5b928401925b82841015611bc6578335612b3d81612077565b82529284019290840190612b2a565b8035600181900b8114611a2f57600080fd5b60006020808385031215612b7157600080fd5b82356001600160401b03811115612b8757600080fd5b8301601f81018513612b9857600080fd5b8035612ba6611b7d82611afb565b81815260059190911b82018301908381019087831115612bc557600080fd5b928401925b82841015611bc657612bdb84612b4c565b82529284019290840190612bca565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600190810b8452938501939285019201612c06565b60006020808385031215612c3857600080fd5b82356001600160401b03811115612c4e57600080fd5b8301601f81018513612c5f57600080fd5b8035612c6d611b7d82611afb565b81815260059190911b82018301908381019087831115612c8c57600080fd5b928401925b82841015611bc657833582529284019290840190612c91565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835183529284019291840191600101612cc6565b80356affffffffffffffffffffff81168114611a2f57600080fd5b60006020808385031215612d1057600080fd5b82356001600160401b03811115612d2657600080fd5b8301601f81018513612d3757600080fd5b8035612d45611b7d82611afb565b81815260059190911b82018301908381019087831115612d6457600080fd5b928401925b82841015611bc657612d7a84612ce2565b82529284019290840190612d69565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516affffffffffffffffffffff1683529284019291840191600101612da5565b8035601081900b8114611a2f57600080fd5b600060208284031215612df257600080fd5b611a4f82612dce565b8035601c81900b8114611a2f57600080fd5b600060208284031215612e1f57600080fd5b611a4f82612dfb565b803568ffffffffffffffffff81168114611a2f57600080fd5b600060208284031215612e5357600080fd5b611a4f82612e28565b8035600781900b8114611a2f57600080fd5b600060208284031215612e8057600080fd5b611a4f82612e5c565b60006020808385031215612e9c57600080fd5b82356001600160401b03811115612eb257600080fd5b8301601f81018513612ec357600080fd5b8035612ed1611b7d82611afb565b81815260059190911b82018301908381019087831115612ef057600080fd5b928401925b82841015611bc657612f06846129b8565b82529284019290840190612ef5565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601a0b83529284019291840191600101612f31565b80358015158114611a2f57600080fd5b600060208284031215612f7257600080fd5b611a4f82612f50565b60006020808385031215612f8e57600080fd5b82356001600160401b03811115612fa457600080fd5b8301601f81018513612fb557600080fd5b8035612fc3611b7d82611afb565b81815260059190911b82018301908381019087831115612fe257600080fd5b928401925b82841015611bc657612ff884612f50565b82529284019290840190612fe7565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351151583529284019291840191600101613023565b80356001600160d81b0381168114611a2f57600080fd5b6000602080838503121561306b57600080fd5b82356001600160401b0381111561308157600080fd5b8301601f8101851361309257600080fd5b80356130a0611b7d82611afb565b81815260059190911b820183019083810190878311156130bf57600080fd5b928401925b82841015611bc6576130d584613041565b825292840192908401906130c4565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160d81b031683529284019291840191600101613100565b8035601581900b8114611a2f57600080fd5b6000602080838503121561314a57600080fd5b82356001600160401b0381111561316057600080fd5b8301601f8101851361317157600080fd5b803561317f611b7d82611afb565b81815260059190911b8201830190838101908783111561319e57600080fd5b928401925b82841015611bc6576131b484613125565b825292840192908401906131a3565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160150b835292840192918401916001016131df565b80356001600160a81b0381168114611a2f57600080fd5b6000602080838503121561322857600080fd5b82356001600160401b0381111561323e57600080fd5b8301601f8101851361324f57600080fd5b803561325d611b7d82611afb565b81815260059190911b8201830190838101908783111561327c57600080fd5b928401925b82841015611bc657613292846131fe565b82529284019290840190613281565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160a81b0316835292840192918401916001016132bd565b8035600081900b8114611a2f57600080fd5b60006020828403121561330657600080fd5b611a4f826132e2565b6000602080838503121561332257600080fd5b82356001600160401b0381111561333857600080fd5b8301601f8101851361334957600080fd5b8035613357611b7d82611afb565b81815260059190911b8201830190838101908783111561337657600080fd5b928401925b82841015611bc65761338c84611caf565b8252928401929084019061337b565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160110b835292840192918401916001016133b7565b600060208083850312156133e957600080fd5b82356001600160401b038111156133ff57600080fd5b8301601f8101851361341057600080fd5b803561341e611b7d82611afb565b81815260059190911b8201830190838101908783111561343d57600080fd5b928401925b82841015611bc6576134538461204a565b82529284019290840190613442565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160160b8352928401929184019160010161347e565b803565ffffffffffff81168114611a2f57600080fd5b600060208083850312156134c657600080fd5b82356001600160401b038111156134dc57600080fd5b8301601f810185136134ed57600080fd5b80356134fb611b7d82611afb565b81815260059190911b8201830190838101908783111561351a57600080fd5b928401925b82841015611bc6576135308461349d565b8252928401929084019061351f565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835165ffffffffffff168352928401929184019160010161355b565b803563ffffffff81168114611a2f57600080fd5b600060208083850312156135a657600080fd5b82356001600160401b038111156135bc57600080fd5b8301601f810185136135cd57600080fd5b80356135db611b7d82611afb565b81815260059190911b820183019083810190878311156135fa57600080fd5b928401925b82841015611bc6576136108461357f565b825292840192908401906135ff565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835163ffffffff168352928401929184019160010161363b565b8035600981900b8114611a2f57600080fd5b60006020828403121561368157600080fd5b611a4f8261365d565b8035601781900b8114611a2f57600080fd5b6000602082840312156136ae57600080fd5b611a4f8261368a565b6000602082840312156136c957600080fd5b611a4f8261215e565b8035600681900b8114611a2f57600080fd5b600060208083850312156136f757600080fd5b82356001600160401b0381111561370d57600080fd5b8301601f8101851361371e57600080fd5b803561372c611b7d82611afb565b81815260059190911b8201830190838101908783111561374b57600080fd5b928401925b82841015611bc657613761846136d2565b82529284019290840190613750565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160060b8352928401929184019160010161378c565b6000602082840312156137bd57600080fd5b611a4f826136d2565b8035600f81900b8114611a2f57600080fd5b600060208083850312156137eb57600080fd5b82356001600160401b0381111561380157600080fd5b8301601f8101851361381257600080fd5b8035613820611b7d82611afb565b81815260059190911b8201830190838101908783111561383f57600080fd5b928401925b82841015611bc657613855846137c6565b82529284019290840190613844565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600f0b83529284019291840191600101613880565b600060208083850312156138b257600080fd5b82356001600160401b038111156138c857600080fd5b8301601f810185136138d957600080fd5b80356138e7611b7d82611afb565b81815260059190911b8201830190838101908783111561390657600080fd5b928401925b82841015611bc65761391c84611cdc565b8252928401929084019061390b565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601e0b83529284019291840191600101613947565b803569ffffffffffffffffffff81168114611a2f57600080fd5b6000602080838503121561399357600080fd5b82356001600160401b038111156139a957600080fd5b8301601f810185136139ba57600080fd5b80356139c8611b7d82611afb565b81815260059190911b820183019083810190878311156139e757600080fd5b928401925b82841015611bc6576139fd84613966565b825292840192908401906139ec565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835169ffffffffffffffffffff1683529284019291840191600101613a28565b80356001600160681b0381168114611a2f57600080fd5b600060208284031215613a7957600080fd5b611a4f82613a50565b80356001600160701b0381168114611a2f57600080fd5b60006020808385031215613aac57600080fd5b82356001600160401b03811115613ac257600080fd5b8301601f81018513613ad357600080fd5b8035613ae1611b7d82611afb565b81815260059190911b82018301908381019087831115613b0057600080fd5b928401925b82841015611bc657613b1684613a82565b82529284019290840190613b05565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160701b031683529284019291840191600101613b41565b600060208284031215613b7857600080fd5b611a4f82613041565b803564ffffffffff81168114611a2f57600080fd5b60006020808385031215613ba957600080fd5b82356001600160401b03811115613bbf57600080fd5b8301601f81018513613bd057600080fd5b8035613bde611b7d82611afb565b81815260059190911b82018301908381019087831115613bfd57600080fd5b928401925b82841015611bc657613c1384613b81565b82529284019290840190613c02565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835164ffffffffff1683529284019291840191600101613c3e565b8035601b81900b8114611a2f57600080fd5b600060208284031215613c8557600080fd5b611a4f82613c61565b803562ffffff81168114611a2f57600080fd5b60006020808385031215613cb457600080fd5b82356001600160401b03811115613cca57600080fd5b8301601f81018513613cdb57600080fd5b8035613ce9611b7d82611afb565b81815260059190911b82018301908381019087831115613d0857600080fd5b928401925b82841015611bc657613d1e84613c8e565b82529284019290840190613d0d565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835162ffffff1683529284019291840191600101613d49565b803561ffff81168114611a2f57600080fd5b60006020808385031215613d8f57600080fd5b82356001600160401b03811115613da557600080fd5b8301601f81018513613db657600080fd5b8035613dc4611b7d82611afb565b81815260059190911b82018301908381019087831115613de357600080fd5b928401925b82841015611bc657613df984613d6a565b82529284019290840190613de8565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835161ffff1683529284019291840191600101613e24565b8035600281900b8114611a2f57600080fd5b600060208284031215613e6857600080fd5b611a4f82613e44565b80356001600160901b0381168114611a2f57600080fd5b60006020808385031215613e9b57600080fd5b82356001600160401b03811115613eb157600080fd5b8301601f81018513613ec257600080fd5b8035613ed0611b7d82611afb565b81815260059190911b82018301908381019087831115613eef57600080fd5b928401925b82841015611bc657613f0584613e71565b82529284019290840190613ef4565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160901b031683529284019291840191600101613f30565b60006020808385031215613f6857600080fd5b82356001600160401b0380821115613f7f57600080fd5b818501915085601f830112613f9357600080fd5b8135613fa1611b7d82611afb565b81815260059190911b83018401908481019088831115613fc057600080fd5b8585015b83811015613ff857803585811115613fdc5760008081fd5b613fea8b89838a0101611d36565b845250918601918601613fc4565b5098975050505050505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561405a57603f19888603018452614048858351611de1565b9450928501929085019060010161402c565b5092979650505050505050565b6000602080838503121561407a57600080fd5b82356001600160401b0381111561409057600080fd5b8301601f810185136140a157600080fd5b80356140af611b7d82611afb565b81815260059190911b820183019083810190878311156140ce57600080fd5b928401925b82841015611bc6576140e484611e3a565b825292840192908401906140d3565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160981b03168352928401929184019160010161410f565b80356001600160b01b0381168114611a2f57600080fd5b60006020828403121561415d57600080fd5b611a4f82614134565b6000602080838503121561417957600080fd5b82356001600160401b0381111561418f57600080fd5b8301601f810185136141a057600080fd5b80356141ae611b7d82611afb565b81815260059190911b820183019083810190878311156141cd57600080fd5b928401925b82841015611bc6576141e384612dce565b825292840192908401906141d2565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160100b8352928401929184019160010161420e565b60006020828403121561423f57600080fd5b611a4f826137c6565b6000602080838503121561425b57600080fd5b82356001600160401b0381111561427157600080fd5b8301601f8101851361428257600080fd5b8035614290611b7d82611afb565b81815260059190911b820183019083810190878311156142af57600080fd5b928401925b82841015611bc6576142c5846127c3565b825292840192908401906142b4565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160190b835292840192918401916001016142f0565b80356001600160881b0381168114611a2f57600080fd5b6000602080838503121561433957600080fd5b82356001600160401b0381111561434f57600080fd5b8301601f8101851361436057600080fd5b803561436e611b7d82611afb565b81815260059190911b8201830190838101908783111561438d57600080fd5b928401925b82841015611bc6576143a38461430f565b82529284019290840190614392565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160881b0316835292840192918401916001016143ce565b6000602080838503121561440657600080fd5b82356001600160401b0381111561441c57600080fd5b8301601f8101851361442d57600080fd5b803561443b611b7d82611afb565b81815260059190911b8201830190838101908783111561445a57600080fd5b928401925b82841015611bc65761447084613c61565b8252928401929084019061445f565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601b0b8352928401929184019160010161449b565b600060208083850312156144cd57600080fd5b82356001600160401b03808211156144e457600080fd5b818501915085601f8301126144f857600080fd5b8135614506611b7d82611afb565b81815260059190911b8301840190848101908883111561452557600080fd5b8585015b83811015613ff8578035858111156145415760008081fd5b61454f8b89838a0101611d36565b845250918601918601614529565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561405a57603f198886030184526145a0858351611de1565b94509285019290850190600101614584565b6000602082840312156145c457600080fd5b611a4f82613125565b8035601881900b8114611a2f57600080fd5b6000602082840312156145f157600080fd5b611a4f826145cd565b60006020828403121561460c57600080fd5b611a4f826129e5565b80356001600160b81b0381168114611a2f57600080fd5b60006020828403121561463e57600080fd5b611a4f82614615565b60006020828403121561465957600080fd5b611a4f826126a2565b6000602080838503121561467557600080fd5b82356001600160401b0381111561468b57600080fd5b8301601f8101851361469c57600080fd5b80356146aa611b7d82611afb565b81815260059190911b820183019083810190878311156146c957600080fd5b928401925b82841015611bc6576146df84614134565b825292840192908401906146ce565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160b01b03168352928401929184019160010161470a565b60006020828403121561474157600080fd5b611a4f82612b4c565b60006020828403121561475c57600080fd5b611a4f82611b1e565b6000602080838503121561477857600080fd5b82356001600160401b0381111561478e57600080fd5b8301601f8101851361479f57600080fd5b80356147ad611b7d82611afb565b81815260059190911b820183019083810190878311156147cc57600080fd5b928401925b82841015611bc6576147e284611a88565b825292840192908401906147d1565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600c0b8352928401929184019160010161480d565b60006020828403121561483e57600080fd5b611a4f82613d6a565b6000602080838503121561485a57600080fd5b82356001600160401b0381111561487057600080fd5b8301601f8101851361488157600080fd5b803561488f611b7d82611afb565b81815260059190911b820183019083810190878311156148ae57600080fd5b928401925b82841015611bc6576148c484612e28565b825292840192908401906148b3565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835168ffffffffffffffffff16835292840192918401916001016148ef565b8035600e81900b8114611a2f57600080fd5b6000602080838503121561493b57600080fd5b82356001600160401b0381111561495157600080fd5b8301601f8101851361496257600080fd5b8035614970611b7d82611afb565b81815260059190911b8201830190838101908783111561498f57600080fd5b928401925b82841015611bc6576149a584614916565b82529284019290840190614994565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351600e0b835292840192918401916001016149d0565b8035600581900b8114611a2f57600080fd5b600060208284031215614a1357600080fd5b611a4f826149ef565b600060208284031215614a2e57600080fd5b611a4f82613a82565b60006020808385031215614a4a57600080fd5b82356001600160401b03811115614a6057600080fd5b8301601f81018513614a7157600080fd5b8035614a7f611b7d82611afb565b81815260059190911b82018301908381019087831115614a9e57600080fd5b928401925b82841015611bc657614ab484613a50565b82529284019290840190614aa3565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160681b031683529284019291840191600101614adf565b600060208284031215614b1657600080fd5b611a4f82614916565b600060208284031215614b3157600080fd5b611a4f826131fe565b600060208284031215614b4c57600080fd5b611a4f82611e6c565b600060208284031215614b6757600080fd5b611a4f8261430f565b600060208284031215614b8257600080fd5b611a4f826124f7565b60006020808385031215614b9e57600080fd5b82356001600160401b03811115614bb457600080fd5b8301601f81018513614bc557600080fd5b8035614bd3611b7d82611afb565b81815260059190911b82018301908381019087831115614bf257600080fd5b928401925b82841015611bc657614c08846149ef565b82529284019290840190614bf7565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160050b83529284019291840191600101614c33565b600060208284031215614c6457600080fd5b611a4f82611f72565b60006020808385031215614c8057600080fd5b82356001600160401b03811115614c9657600080fd5b8301601f81018513614ca757600080fd5b8035614cb5611b7d82611afb565b81815260059190911b82018301908381019087831115614cd457600080fd5b928401925b82841015611bc657614cea84611f45565b82529284019290840190614cd9565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160120b83529284019291840191600101614d15565b600060208284031215614d4657600080fd5b611a4f82612ce2565b600060208284031215614d6157600080fd5b611a4f82612304565b60006020808385031215614d7d57600080fd5b82356001600160401b03811115614d9357600080fd5b8301601f81018513614da457600080fd5b8035614db2611b7d82611afb565b81815260059190911b82018301908381019087831115614dd157600080fd5b928401925b82841015611bc657614de7846145cd565b82529284019290840190614dd6565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160180b83529284019291840191600101614e12565b600060208284031215614e4357600080fd5b611a4f8261349d565b80356001600160e01b0381168114611a2f57600080fd5b600060208284031215614e7557600080fd5b611a4f82614e4c565b60006020808385031215614e9157600080fd5b82356001600160401b03811115614ea757600080fd5b8301601f81018513614eb857600080fd5b8035614ec6611b7d82611afb565b81815260059190911b82018301908381019087831115614ee557600080fd5b928401925b82841015611bc657614efb8461365d565b82529284019290840190614eea565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160090b83529284019291840191600101614f26565b60006020808385031215614f5857600080fd5b82356001600160401b03811115614f6e57600080fd5b8301601f81018513614f7f57600080fd5b8035614f8d611b7d82611afb565b81815260059190911b82018301908381019087831115614fac57600080fd5b928401925b82841015611bc657614fc284614e4c565b82529284019290840190614fb1565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160e01b031683529284019291840191600101614fed565b80356001600160d01b0381168114611a2f57600080fd5b60006020828403121561503b57600080fd5b611a4f82615012565b60006020828403121561505657600080fd5b611a4f8261357f565b63ffffffff841681526001600160401b038316602082015260606040820152600061508d6060830184611de1565b95945050505050565b6000602082840312156150a857600080fd5b611a4f82613966565b6000602082840312156150c357600080fd5b611a4f826128d4565b80356001600160e81b0381168114611a2f57600080fd5b6000602082840312156150f557600080fd5b611a4f826150cc565b6000602080838503121561511157600080fd5b82356001600160401b0381111561512757600080fd5b8301601f8101851361513857600080fd5b8035615146611b7d82611afb565b81815260059190911b8201830190838101908783111561516557600080fd5b928401925b82841015611bc65761517b84612dfb565b8252928401929084019061516a565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601c0b835292840192918401916001016151a6565b6000602082840312156151d757600080fd5b611a4f826127f0565b8035600881900b8114611a2f57600080fd5b6000602080838503121561520557600080fd5b82356001600160401b0381111561521b57600080fd5b8301601f8101851361522c57600080fd5b803561523a611b7d82611afb565b81815260059190911b8201830190838101908783111561525957600080fd5b928401925b82841015611bc65761526f846151e0565b8252928401929084019061525e565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160080b8352928401929184019160010161529a565b600060208083850312156152cc57600080fd5b82356001600160401b038111156152e257600080fd5b8301601f810185136152f357600080fd5b8035615301611b7d82611afb565b81815260059190911b8201830190838101908783111561532057600080fd5b928401925b82841015611bc657615336846132e2565b82529284019290840190615325565b602080825282518282018190526000919084820190604085019084805b82811015615380578451820b84529385019392850192600101615362565b5091979650505050505050565b600060208083850312156153a057600080fd5b82356001600160401b038111156153b657600080fd5b8301601f810185136153c757600080fd5b80356153d5611b7d82611afb565b81815260059190911b820183019083810190878311156153f457600080fd5b928401925b82841015611bc65761540a8461277b565b825292840192908401906153f9565b6020808252825182820181905260009190848201906040850190845b81811015611c12578351601d0b83529284019291840191600101615435565b6000602080838503121561546757600080fd5b82356001600160401b0381111561547d57600080fd5b8301601f8101851361548e57600080fd5b803561549c611b7d82611afb565b81815260059190911b820183019083810190878311156154bb57600080fd5b928401925b82841015611bc6576154d184611c82565b825292840192908401906154c0565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160040b835292840192918401916001016154fc565b6000602080838503121561552e57600080fd5b82356001600160401b0381111561554457600080fd5b8301601f8101851361555557600080fd5b8035615563611b7d82611afb565b81815260059190911b8201830190838101908783111561558257600080fd5b928401925b82841015611bc65761559884613e44565b82529284019290840190615587565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160020b835292840192918401916001016155c3565b600060208083850312156155f557600080fd5b82356001600160401b0381111561560b57600080fd5b8301601f8101851361561c57600080fd5b803561562a611b7d82611afb565b81815260059190911b8201830190838101908783111561564957600080fd5b928401925b82841015611bc65761565f846150cc565b8252928401929084019061564e565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160e81b03168352928401929184019160010161568a565b600060208083850312156156c257600080fd5b82356001600160401b038111156156d857600080fd5b8301601f810185136156e957600080fd5b80356156f7611b7d82611afb565b81815260059190911b8201830190838101908783111561571657600080fd5b928401925b82841015611bc65761572c8461368a565b8252928401929084019061571b565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160170b83529284019291840191600101615757565b60006020828403121561578857600080fd5b611a4f826151e0565b600060208083850312156157a457600080fd5b82356001600160401b038111156157ba57600080fd5b8301601f810185136157cb57600080fd5b80356157d9611b7d82611afb565b81815260059190911b820183019083810190878311156157f857600080fd5b928401925b82841015611bc65761580e84612e5c565b825292840192908401906157fd565b6020808252825182820181905260009190848201906040850190845b81811015611c1257835160070b83529284019291840191600101615839565b60006020828403121561586a57600080fd5b611a4f82613e71565b60006020828403121561588557600080fd5b611a4f82613c8e565b600060208083850312156158a157600080fd5b82356001600160401b038111156158b757600080fd5b8301601f810185136158c857600080fd5b80356158d6611b7d82611afb565b81815260059190911b820183019083810190878311156158f557600080fd5b928401925b82841015611bc65761590b84611a18565b825292840192908401906158fa565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160801b031683529284019291840191600101615936565b6000602080838503121561596e57600080fd5b82356001600160401b0381111561598457600080fd5b8301601f8101851361599557600080fd5b80356159a3611b7d82611afb565b81815260059190911b820183019083810190878311156159c257600080fd5b928401925b82841015611bc6576159d884615012565b825292840192908401906159c7565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160d01b031683529284019291840191600101615a03565b60006020808385031215615a3b57600080fd5b82356001600160401b03811115615a5157600080fd5b8301601f81018513615a6257600080fd5b8035615a70611b7d82611afb565b81815260059190911b82018301908381019087831115615a8f57600080fd5b928401925b82841015611bc657615aa584614615565b82529284019290840190615a94565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160b81b031683529284019291840191600101615ad0565b602081526000825160406020840152615b116060840182611de1565b9050602084015160408401528091505092915050565b60006020808385031215615b3a57600080fd5b82356001600160401b03811115615b5057600080fd5b8301601f81018513615b6157600080fd5b8035615b6f611b7d82611afb565b81815260059190911b82018301908381019087831115615b8e57600080fd5b928401925b82841015611bc657615ba484611c1e565b82529284019290840190615b93565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160781b031683529284019291840191600101615bcf565b60006020808385031215615c0757600080fd5b82356001600160401b03811115615c1d57600080fd5b8301601f81018513615c2e57600080fd5b8035615c3c611b7d82611afb565b81815260059190911b82018301908381019087831115615c5b57600080fd5b928401925b82841015611bc657615c7184611a56565b82529284019290840190615c60565b6020808252825182820181905260009190848201906040850190845b81811015611c125783516001600160601b031683529284019291840191600101615c9c565b600060208284031215615cd357600080fd5b611a4f82613b81565b634e487b7160e01b600052601160045260246000fd5b600081810b9083900b01607f8113607f1982121715615d1357615d13615cdc565b92915050565b8082018281126000831280158216821582161715615d3957615d39615cdc565b505092915050565b63ffffffff828116828216039080821115615d5e57615d5e615cdc565b5092915050565b600481810b9083900b01647fffffffff8113647fffffffff1982121715615d1357615d13615cdc565b600181811c90821680615da257607f821691505b602082108103615dc257634e487b7160e01b600052602260045260246000fd5b5091905056fea2646970667358221220a5b87b6881e1a012e4a59d55c230cfcf3a2342b83efdbfb3c5f5cfa532fc854864736f6c63430008120033"; private static IntegrationTestEnv testEnv; private static FileId fileId; private static ContractId contractId; @@ -55,20 +53,29 @@ public static void beforeAll() throws Exception { fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); - new FileAppendTransaction().setFileId(fileId).setContents(SMART_CONTRACT_BYTECODE).setMaxChunks(31) - .execute(testEnv.client); + new FileAppendTransaction() + .setFileId(fileId) + .setContents(SMART_CONTRACT_BYTECODE) + .setMaxChunks(31) + .execute(testEnv.client); - response = new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(1500000) - .setConstructorParameters(new ContractFunctionParameters()).setBytecodeFileId(fileId) - .execute(testEnv.client); + response = new ContractCreateTransaction() + .setAdminKey(testEnv.operatorKey) + .setGas(1500000) + .setConstructorParameters(new ContractFunctionParameters()) + .setBytecodeFileId(fileId) + .execute(testEnv.client); contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); } @AfterAll public static void afterAll() throws Exception { - new ContractDeleteTransaction().setTransferAccountId(testEnv.operatorId).setContractId(contractId) - .execute(testEnv.client).getReceipt(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); @@ -84,9 +91,12 @@ public void afterEach() throws InterruptedException { @Test @DisplayName("Can receive uint8 min value from contract call") void canCallContractFunctionUint8Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint8", new ContractFunctionParameters().addUint8((byte) 0x0)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint8", new ContractFunctionParameters().addUint8((byte) 0x0)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint8(0)).isEqualTo((byte) 0x0); } @@ -97,9 +107,12 @@ void canCallContractFunctionUint8Max() throws Exception { int uint8Max = 255; byte uint8MaxByte = (byte) uint8Max; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint8", new ContractFunctionParameters().addUint8(uint8MaxByte)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint8", new ContractFunctionParameters().addUint8(uint8MaxByte)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var uint8MaxFromResponse = Byte.toUnsignedInt(response.getUint8(0)); @@ -114,9 +127,12 @@ void canCallContractFunctionUint8Array() throws Exception { byte uint8MaxByte = (byte) uint8Max; byte[] uint8Array = {uint8MinByte, uint8MaxByte}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint8Arr", new ContractFunctionParameters().addUint8Array(uint8Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint8Arr", new ContractFunctionParameters().addUint8Array(uint8Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (int[]) response.getResult("(uint8[])").get(0); @@ -127,9 +143,12 @@ void canCallContractFunctionUint8Array() throws Exception { @Test @DisplayName("Can receive uint16 min value from contract call") void canCallContractFunctionUint16Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint16", new ContractFunctionParameters().addUint16(0)).setQueryPayment(new Hbar(10)) - .execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint16", new ContractFunctionParameters().addUint16(0)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint32(0)).isEqualTo(0); } @@ -140,9 +159,12 @@ void canCallContractFunctionUint16Max() throws Exception { var uint16Max = "65535"; int uint16MaxInt = Integer.parseUnsignedInt(uint16Max); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint16", new ContractFunctionParameters().addUint16(uint16MaxInt)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint16", new ContractFunctionParameters().addUint16(uint16MaxInt)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var uint16MaxIntFromResponse = Integer.toUnsignedString(response.getUint32(0)); @@ -157,9 +179,12 @@ void canCallContractFunctionUint16Array() throws Exception { int uint16MaxInt = Integer.parseUnsignedInt(uint16Max); int[] uint16Array = {uint16MinInt, uint16MaxInt}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint16Arr", new ContractFunctionParameters().addUint16Array(uint16Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint16Arr", new ContractFunctionParameters().addUint16Array(uint16Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (int[]) response.getResult("(uint16[])").get(0); @@ -169,9 +194,12 @@ void canCallContractFunctionUint16Array() throws Exception { @Test @DisplayName("Can receive uint24 min value from contract call") void canCallContractFunctionUint24Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint24", new ContractFunctionParameters().addUint24(0)).setQueryPayment(new Hbar(10)) - .execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint24", new ContractFunctionParameters().addUint24(0)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint32(0)).isEqualTo(0); } @@ -182,9 +210,12 @@ void canCallContractFunctionUint24Max() throws Exception { var uint24Max = "16777215"; int uint24MaxInt = Integer.parseUnsignedInt(uint24Max); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint24", new ContractFunctionParameters().addUint24(uint24MaxInt)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint24", new ContractFunctionParameters().addUint24(uint24MaxInt)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var uint24MaxIntFromResponse = Integer.toUnsignedString(response.getUint32(0)); @@ -199,9 +230,12 @@ void canCallContractFunctionUint24Array() throws Exception { int uint24MaxInt = Integer.parseUnsignedInt(uint24Max); int[] uint24Array = {uint24MinInt, uint24MaxInt}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint24Arr", new ContractFunctionParameters().addUint24Array(uint24Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint24Arr", new ContractFunctionParameters().addUint24Array(uint24Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (int[]) response.getResult("(uint24[])").get(0); @@ -211,9 +245,12 @@ void canCallContractFunctionUint24Array() throws Exception { @Test @DisplayName("Can receive uint32 min value from contract call") void canCallContractFunctionUint32Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint32", new ContractFunctionParameters().addUint32(0)).setQueryPayment(new Hbar(10)) - .execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint32", new ContractFunctionParameters().addUint32(0)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint32(0)).isEqualTo(0); } @@ -224,9 +261,12 @@ void canCallContractFunctionUint32Max() throws Exception { var uint32Max = "4294967295"; int uint32MaxInt = Integer.parseUnsignedInt(uint32Max); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint32", new ContractFunctionParameters().addUint32(uint32MaxInt)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint32", new ContractFunctionParameters().addUint32(uint32MaxInt)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var uint32MaxIntFromResponse = Integer.toUnsignedString(response.getUint32(0)); @@ -241,9 +281,12 @@ void canCallContractFunctionUint32Array() throws Exception { int uint32MaxInt = Integer.parseUnsignedInt(uint32Max); int[] uint32Array = {uint32MinInt, uint32MaxInt}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint32Arr", new ContractFunctionParameters().addUint32Array(uint32Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint32Arr", new ContractFunctionParameters().addUint32Array(uint32Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (long[]) response.getResult("(uint32[])").get(0); @@ -254,9 +297,12 @@ void canCallContractFunctionUint32Array() throws Exception { @Test @DisplayName("Can receive uint40 min value from contract call") void canCallContractFunctionUint40Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint40", new ContractFunctionParameters().addUint40(0)).setQueryPayment(new Hbar(10)) - .execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint40", new ContractFunctionParameters().addUint40(0)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint64(0)).isEqualTo(0); } @@ -267,9 +313,12 @@ void canCallContractFunctionUint40Max() throws Exception { var uint40Max = "109951162777"; long uint40MaxLong = Long.parseUnsignedLong(uint40Max); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint40", new ContractFunctionParameters().addUint40(uint40MaxLong)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint40", new ContractFunctionParameters().addUint40(uint40MaxLong)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var uint64MaxLongFromResponse = Long.toUnsignedString(response.getUint64(0)); @@ -284,9 +333,12 @@ void canCallContractFunctionUint40Array() throws Exception { long uint40MaxLong = Long.parseUnsignedLong(uint40Max); long[] uint40Array = {uint40MinLong, uint40MaxLong}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint40Arr", new ContractFunctionParameters().addUint40Array(uint40Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint40Arr", new ContractFunctionParameters().addUint40Array(uint40Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (long[]) response.getResult("(uint40[])").get(0); @@ -296,9 +348,12 @@ void canCallContractFunctionUint40Array() throws Exception { @Test @DisplayName("Can receive uint48 min value from contract call") void canCallContractFunctionUint48Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint48", new ContractFunctionParameters().addUint48(0)).setQueryPayment(new Hbar(10)) - .execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint48", new ContractFunctionParameters().addUint48(0)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint64(0)).isEqualTo(0); } @@ -309,9 +364,12 @@ void canCallContractFunctionUint48Max() throws Exception { var uint48Max = "281474976710655"; long uint48MaxLong = Long.parseUnsignedLong(uint48Max); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint48", new ContractFunctionParameters().addUint48(uint48MaxLong)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint48", new ContractFunctionParameters().addUint48(uint48MaxLong)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var uint64MaxLongFromResponse = Long.toUnsignedString(response.getUint64(0)); @@ -326,9 +384,12 @@ void canCallContractFunctionUint48Array() throws Exception { long uint48MaxLong = Long.parseUnsignedLong(uint48Max); long[] uint48Array = {uint48MinLong, uint48MaxLong}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint48Arr", new ContractFunctionParameters().addUint48Array(uint48Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint48Arr", new ContractFunctionParameters().addUint48Array(uint48Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (long[]) response.getResult("(uint48[])").get(0); @@ -338,9 +399,12 @@ void canCallContractFunctionUint48Array() throws Exception { @Test @DisplayName("Can receive uint56 min value from contract call") void canCallContractFunctionUint56Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint56", new ContractFunctionParameters().addUint56(0)).setQueryPayment(new Hbar(10)) - .execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint56", new ContractFunctionParameters().addUint56(0)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint64(0)).isEqualTo(0); } @@ -351,9 +415,12 @@ void canCallContractFunctionUint56Max() throws Exception { var uint56Max = "72057594037927935"; long uint56MaxLong = Long.parseUnsignedLong(uint56Max); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint56", new ContractFunctionParameters().addUint56(uint56MaxLong)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint56", new ContractFunctionParameters().addUint56(uint56MaxLong)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var uint64MaxLongFromResponse = Long.toUnsignedString(response.getUint64(0)); @@ -368,9 +435,12 @@ void canCallContractFunctionUint56Array() throws Exception { long uint56MaxLong = Long.parseUnsignedLong(uint56Max); long[] uint56Array = {uint56MinLong, uint56MaxLong}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint56Arr", new ContractFunctionParameters().addUint56Array(uint56Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint56Arr", new ContractFunctionParameters().addUint56Array(uint56Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (long[]) response.getResult("(uint56[])").get(0); @@ -380,9 +450,12 @@ void canCallContractFunctionUint56Array() throws Exception { @Test @DisplayName("Can receive uint64 min value from contract call") void canCallContractFunctionUint64Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint64", new ContractFunctionParameters().addUint64(0)).setQueryPayment(new Hbar(10)) - .execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint64", new ContractFunctionParameters().addUint64(0)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint64(0)).isEqualTo(0); } @@ -393,9 +466,12 @@ void canCallContractFunctionUint64Max() throws Exception { var uint64Max = "9223372036854775807"; long uint64MaxLong = Long.parseUnsignedLong(uint64Max); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint64", new ContractFunctionParameters().addUint64(uint64MaxLong)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint64", new ContractFunctionParameters().addUint64(uint64MaxLong)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var uint64MaxLongFromResponse = Long.toUnsignedString(response.getUint64(0)); @@ -410,9 +486,12 @@ void canCallContractFunctionUint64Array() throws Exception { long uint64MaxLong = Long.parseUnsignedLong(uint64Max); long[] uint64Array = {uint64MinLong, uint64MaxLong}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint64Arr", new ContractFunctionParameters().addUint64Array(uint64Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint64Arr", new ContractFunctionParameters().addUint64Array(uint64Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint64[])").get(0); @@ -423,9 +502,12 @@ void canCallContractFunctionUint64Array() throws Exception { @Test @DisplayName("Can receive uint72 min value from contract call") void canCallContractFunctionUint72Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint72", new ContractFunctionParameters().addUint72(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint72", new ContractFunctionParameters().addUint72(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -435,9 +517,12 @@ void canCallContractFunctionUint72Min() throws Exception { void canCallContractFunctionUint72Max() throws Exception { BigInteger uint72Max = new BigInteger("4722366482869645213695"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint72", new ContractFunctionParameters().addUint72(uint72Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint72", new ContractFunctionParameters().addUint72(uint72Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint72Max); } @@ -449,9 +534,12 @@ void canCallContractFunctionUint72Array() throws Exception { BigInteger uint72Max = new BigInteger("4722366482869645213695"); BigInteger[] uint72Array = {uint72Min, uint72Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint72Arr", new ContractFunctionParameters().addUint72Array(uint72Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint72Arr", new ContractFunctionParameters().addUint72Array(uint72Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint72[])").get(0); @@ -461,9 +549,12 @@ void canCallContractFunctionUint72Array() throws Exception { @Test @DisplayName("Can receive uint80 min value from contract call") void canCallContractFunctionUint80Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint80", new ContractFunctionParameters().addUint80(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint80", new ContractFunctionParameters().addUint80(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -473,9 +564,12 @@ void canCallContractFunctionUint80Min() throws Exception { void canCallContractFunctionUint80Max() throws Exception { BigInteger uint80Max = new BigInteger("1208925819614629174706175"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint80", new ContractFunctionParameters().addUint80(uint80Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint80", new ContractFunctionParameters().addUint80(uint80Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint80Max); } @@ -487,9 +581,12 @@ void canCallContractFunctionUint80Array() throws Exception { BigInteger uint80Max = new BigInteger("1208925819614629174706175"); BigInteger[] uint80Array = {uint80Min, uint80Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint80Arr", new ContractFunctionParameters().addUint80Array(uint80Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint80Arr", new ContractFunctionParameters().addUint80Array(uint80Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint80[])").get(0); @@ -499,9 +596,12 @@ void canCallContractFunctionUint80Array() throws Exception { @Test @DisplayName("Can receive uint88 min value from contract call") void canCallContractFunctionUint88Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint88", new ContractFunctionParameters().addUint88(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint88", new ContractFunctionParameters().addUint88(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -511,9 +611,12 @@ void canCallContractFunctionUint88Min() throws Exception { void canCallContractFunctionUint88Max() throws Exception { BigInteger uint88Max = new BigInteger("309485009821345068724781055"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint88", new ContractFunctionParameters().addUint88(uint88Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint88", new ContractFunctionParameters().addUint88(uint88Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint88Max); } @@ -525,9 +628,12 @@ void canCallContractFunctionUint88Array() throws Exception { BigInteger uint88Max = new BigInteger("309485009821345068724781055"); BigInteger[] uint88Array = {uint88Min, uint88Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint88Arr", new ContractFunctionParameters().addUint88Array(uint88Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint88Arr", new ContractFunctionParameters().addUint88Array(uint88Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint88[])").get(0); @@ -537,9 +643,12 @@ void canCallContractFunctionUint88Array() throws Exception { @Test @DisplayName("Can receive uint96 min value from contract call") void canCallContractFunctionUint96Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint96", new ContractFunctionParameters().addUint96(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint96", new ContractFunctionParameters().addUint96(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -549,9 +658,12 @@ void canCallContractFunctionUint96Min() throws Exception { void canCallContractFunctionUint96Max() throws Exception { BigInteger uint96Max = new BigInteger("79228162514264337593543950335"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint96", new ContractFunctionParameters().addUint96(uint96Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint96", new ContractFunctionParameters().addUint96(uint96Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint96Max); } @@ -563,9 +675,12 @@ void canCallContractFunctionUint96Array() throws Exception { BigInteger uint96Max = new BigInteger("79228162514264337593543950335"); BigInteger[] uint96Array = {uint96Min, uint96Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint96Arr", new ContractFunctionParameters().addUint96Array(uint96Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint96Arr", new ContractFunctionParameters().addUint96Array(uint96Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint96[])").get(0); @@ -575,9 +690,12 @@ void canCallContractFunctionUint96Array() throws Exception { @Test @DisplayName("Can receive uint104 min value from contract call") void canCallContractFunctionUint104Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint104", new ContractFunctionParameters().addUint104(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint104", new ContractFunctionParameters().addUint104(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -587,9 +705,12 @@ void canCallContractFunctionUint104Min() throws Exception { void canCallContractFunctionUint104Max() throws Exception { BigInteger uint104Max = new BigInteger("20282409603651670423947251286015"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint104", new ContractFunctionParameters().addUint104(uint104Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint104", new ContractFunctionParameters().addUint104(uint104Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint104Max); } @@ -601,9 +722,12 @@ void canCallContractFunctionUint104Array() throws Exception { BigInteger uint104Max = new BigInteger("20282409603651670423947251286015"); BigInteger[] uint104Array = {uint104Min, uint104Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint104Arr", new ContractFunctionParameters().addUint104Array(uint104Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint104Arr", new ContractFunctionParameters().addUint104Array(uint104Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint104[])").get(0); @@ -613,9 +737,12 @@ void canCallContractFunctionUint104Array() throws Exception { @Test @DisplayName("Can receive uint112 min value from contract call") void canCallContractFunctionUint112Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint112", new ContractFunctionParameters().addUint112(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint112", new ContractFunctionParameters().addUint112(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -625,9 +752,12 @@ void canCallContractFunctionUint112Min() throws Exception { void canCallContractFunctionUint112Max() throws Exception { BigInteger uint112Max = new BigInteger("5192296858534827628530496329220095"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint112", new ContractFunctionParameters().addUint112(uint112Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint112", new ContractFunctionParameters().addUint112(uint112Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint112Max); } @@ -639,9 +769,12 @@ void canCallContractFunctionUint112Array() throws Exception { BigInteger uint112Max = new BigInteger("5192296858534827628530496329220095"); BigInteger[] uint112Array = {uint112Min, uint112Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint112Arr", new ContractFunctionParameters().addUint112Array(uint112Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint112Arr", new ContractFunctionParameters().addUint112Array(uint112Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint112[])").get(0); @@ -651,9 +784,12 @@ void canCallContractFunctionUint112Array() throws Exception { @Test @DisplayName("Can receive uint120 min value from contract call") void canCallContractFunctionUint120Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint120", new ContractFunctionParameters().addUint120(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint120", new ContractFunctionParameters().addUint120(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -663,9 +799,12 @@ void canCallContractFunctionUint120Min() throws Exception { void canCallContractFunctionUint120Max() throws Exception { BigInteger uint120Max = new BigInteger("1329227995784915872903807060280344575"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint120", new ContractFunctionParameters().addUint120(uint120Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint120", new ContractFunctionParameters().addUint120(uint120Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint120Max); } @@ -677,9 +816,12 @@ void canCallContractFunctionUint120Array() throws Exception { BigInteger uint120Max = new BigInteger("1329227995784915872903807060280344575"); BigInteger[] uint120Array = {uint120Min, uint120Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint120Arr", new ContractFunctionParameters().addUint120Array(uint120Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint120Arr", new ContractFunctionParameters().addUint120Array(uint120Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint120[])").get(0); @@ -689,9 +831,12 @@ void canCallContractFunctionUint120Array() throws Exception { @Test @DisplayName("Can receive uint128 min value from contract call") void canCallContractFunctionUint128Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint128", new ContractFunctionParameters().addUint128(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint128", new ContractFunctionParameters().addUint128(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -701,9 +846,12 @@ void canCallContractFunctionUint128Min() throws Exception { void canCallContractFunctionUint128Max() throws Exception { BigInteger uint128Max = new BigInteger("340282366920938463463374607431768211455"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint128", new ContractFunctionParameters().addUint128(uint128Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint128", new ContractFunctionParameters().addUint128(uint128Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint128Max); } @@ -715,9 +863,12 @@ void canCallContractFunctionUint128Array() throws Exception { BigInteger uint128Max = new BigInteger("340282366920938463463374607431768211455"); BigInteger[] uint128Array = {uint128Min, uint128Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint128Arr", new ContractFunctionParameters().addUint128Array(uint128Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint128Arr", new ContractFunctionParameters().addUint128Array(uint128Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint128[])").get(0); @@ -727,9 +878,12 @@ void canCallContractFunctionUint128Array() throws Exception { @Test @DisplayName("Can receive uint136 min value from contract call") void canCallContractFunctionUint136Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint136", new ContractFunctionParameters().addUint136(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint136", new ContractFunctionParameters().addUint136(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -739,9 +893,12 @@ void canCallContractFunctionUint136Min() throws Exception { void canCallContractFunctionUint136Max() throws Exception { BigInteger uint136Max = new BigInteger("87112285931760246646623899502532662132735"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint136", new ContractFunctionParameters().addUint136(uint136Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint136", new ContractFunctionParameters().addUint136(uint136Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint136Max); } @@ -753,9 +910,12 @@ void canCallContractFunctionUint136Array() throws Exception { BigInteger uint136Max = new BigInteger("87112285931760246646623899502532662132735"); BigInteger[] uint136Array = {uint136Min, uint136Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint136Arr", new ContractFunctionParameters().addUint136Array(uint136Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint136Arr", new ContractFunctionParameters().addUint136Array(uint136Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint136[])").get(0); @@ -765,9 +925,12 @@ void canCallContractFunctionUint136Array() throws Exception { @Test @DisplayName("Can receive uint144 min value from contract call") void canCallContractFunctionUint144Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint144", new ContractFunctionParameters().addUint144(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint144", new ContractFunctionParameters().addUint144(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -777,9 +940,12 @@ void canCallContractFunctionUint144Min() throws Exception { void canCallContractFunctionUint144Max() throws Exception { BigInteger uint144Max = new BigInteger("22300745198530623141535718272648361505980415"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint144", new ContractFunctionParameters().addUint144(uint144Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint144", new ContractFunctionParameters().addUint144(uint144Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint144Max); } @@ -791,9 +957,12 @@ void canCallContractFunctionUint144Array() throws Exception { BigInteger uint144Max = new BigInteger("22300745198530623141535718272648361505980415"); BigInteger[] uint144Array = {uint144Min, uint144Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint144Arr", new ContractFunctionParameters().addUint144Array(uint144Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint144Arr", new ContractFunctionParameters().addUint144Array(uint144Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint144[])").get(0); @@ -803,9 +972,12 @@ void canCallContractFunctionUint144Array() throws Exception { @Test @DisplayName("Can receive uint152 min value from contract call") void canCallContractFunctionUint152Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint152", new ContractFunctionParameters().addUint152(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint152", new ContractFunctionParameters().addUint152(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -815,9 +987,12 @@ void canCallContractFunctionUint152Min() throws Exception { void canCallContractFunctionUint152Max() throws Exception { BigInteger uint152Max = new BigInteger("5708990770823839524233143877797980545530986495"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint152", new ContractFunctionParameters().addUint152(uint152Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint152", new ContractFunctionParameters().addUint152(uint152Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint152Max); } @@ -829,9 +1004,12 @@ void canCallContractFunctionUint152Array() throws Exception { BigInteger uint152Max = new BigInteger("5708990770823839524233143877797980545530986495"); BigInteger[] uint152Array = {uint152Min, uint152Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint152Arr", new ContractFunctionParameters().addUint152Array(uint152Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint152Arr", new ContractFunctionParameters().addUint152Array(uint152Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint152[])").get(0); @@ -841,9 +1019,12 @@ void canCallContractFunctionUint152Array() throws Exception { @Test @DisplayName("Can receive uint160 min value from contract call") void canCallContractFunctionUint160Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint160", new ContractFunctionParameters().addUint160(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint160", new ContractFunctionParameters().addUint160(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -853,9 +1034,12 @@ void canCallContractFunctionUint160Min() throws Exception { void canCallContractFunctionUint160Max() throws Exception { BigInteger uint160Max = new BigInteger("1461501637330902918203684832716283019655932542975"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint160", new ContractFunctionParameters().addUint160(uint160Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint160", new ContractFunctionParameters().addUint160(uint160Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint160Max); } @@ -867,9 +1051,12 @@ void canCallContractFunctionUint160Array() throws Exception { BigInteger uint160Max = new BigInteger("1461501637330902918203684832716283019655932542975"); BigInteger[] uint160Array = {uint160Min, uint160Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint160Arr", new ContractFunctionParameters().addUint160Array(uint160Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint160Arr", new ContractFunctionParameters().addUint160Array(uint160Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint160[])").get(0); @@ -879,9 +1066,12 @@ void canCallContractFunctionUint160Array() throws Exception { @Test @DisplayName("Can receive uint168 min value from contract call") void canCallContractFunctionUint168Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint168", new ContractFunctionParameters().addUint168(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint168", new ContractFunctionParameters().addUint168(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -891,9 +1081,12 @@ void canCallContractFunctionUint168Min() throws Exception { void canCallContractFunctionUint168Max() throws Exception { BigInteger uint168Max = new BigInteger("374144419156711147060143317175368453031918731001855"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint168", new ContractFunctionParameters().addUint168(uint168Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint168", new ContractFunctionParameters().addUint168(uint168Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint168Max); } @@ -905,9 +1098,12 @@ void canCallContractFunctionUint168Array() throws Exception { BigInteger uint168Max = new BigInteger("374144419156711147060143317175368453031918731001855"); BigInteger[] uint168Array = {uint168Min, uint168Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint168Arr", new ContractFunctionParameters().addUint168Array(uint168Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint168Arr", new ContractFunctionParameters().addUint168Array(uint168Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint168[])").get(0); @@ -917,9 +1113,12 @@ void canCallContractFunctionUint168Array() throws Exception { @Test @DisplayName("Can receive uint176 min value from contract call") void canCallContractFunctionUint176Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint176", new ContractFunctionParameters().addUint176(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint176", new ContractFunctionParameters().addUint176(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -929,9 +1128,12 @@ void canCallContractFunctionUint176Min() throws Exception { void canCallContractFunctionUint176Max() throws Exception { BigInteger uint176Max = new BigInteger("95780971304118053647396689196894323976171195136475135"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint176", new ContractFunctionParameters().addUint176(uint176Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint176", new ContractFunctionParameters().addUint176(uint176Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint176Max); } @@ -943,9 +1145,12 @@ void canCallContractFunctionUint176Array() throws Exception { BigInteger uint176Max = new BigInteger("95780971304118053647396689196894323976171195136475135"); BigInteger[] uint176Array = {uint176Min, uint176Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint176Arr", new ContractFunctionParameters().addUint176Array(uint176Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint176Arr", new ContractFunctionParameters().addUint176Array(uint176Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint176[])").get(0); @@ -955,9 +1160,12 @@ void canCallContractFunctionUint176Array() throws Exception { @Test @DisplayName("Can receive uint184 min value from contract call") void canCallContractFunctionUint184Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint184", new ContractFunctionParameters().addUint184(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint184", new ContractFunctionParameters().addUint184(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -967,9 +1175,12 @@ void canCallContractFunctionUint184Min() throws Exception { void canCallContractFunctionUint184Max() throws Exception { BigInteger uint184Max = new BigInteger("24519928653854221733733552434404946937899825954937634815"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint184", new ContractFunctionParameters().addUint184(uint184Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint184", new ContractFunctionParameters().addUint184(uint184Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint184Max); } @@ -981,9 +1192,12 @@ void canCallContractFunctionUint184Array() throws Exception { BigInteger uint184Max = new BigInteger("24519928653854221733733552434404946937899825954937634815"); BigInteger[] uint184Array = {uint184Min, uint184Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint184Arr", new ContractFunctionParameters().addUint184Array(uint184Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint184Arr", new ContractFunctionParameters().addUint184Array(uint184Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint184[])").get(0); @@ -993,9 +1207,12 @@ void canCallContractFunctionUint184Array() throws Exception { @Test @DisplayName("Can receive uint192 min value from contract call") void canCallContractFunctionUint192Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint192", new ContractFunctionParameters().addUint192(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint192", new ContractFunctionParameters().addUint192(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1005,9 +1222,12 @@ void canCallContractFunctionUint192Min() throws Exception { void canCallContractFunctionUint192Max() throws Exception { BigInteger uint192Max = new BigInteger("6277101735386680763835789423207666416102355444464034512895"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint192", new ContractFunctionParameters().addUint192(uint192Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint192", new ContractFunctionParameters().addUint192(uint192Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint192Max); } @@ -1019,9 +1239,12 @@ void canCallContractFunctionUint192Array() throws Exception { BigInteger uint192Max = new BigInteger("6277101735386680763835789423207666416102355444464034512895"); BigInteger[] uint192Array = {uint192Min, uint192Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint192Arr", new ContractFunctionParameters().addUint192Array(uint192Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint192Arr", new ContractFunctionParameters().addUint192Array(uint192Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint192[])").get(0); @@ -1031,9 +1254,12 @@ void canCallContractFunctionUint192Array() throws Exception { @Test @DisplayName("Can receive uint200 min value from contract call") void canCallContractFunctionUint200Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint200", new ContractFunctionParameters().addUint200(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint200", new ContractFunctionParameters().addUint200(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1043,9 +1269,12 @@ void canCallContractFunctionUint200Min() throws Exception { void canCallContractFunctionUint200Max() throws Exception { BigInteger uint200Max = new BigInteger("1606938044258990275541962092341162602522202993782792835301375"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint200", new ContractFunctionParameters().addUint200(uint200Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint200", new ContractFunctionParameters().addUint200(uint200Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint200Max); } @@ -1057,9 +1286,12 @@ void canCallContractFunctionUint200Array() throws Exception { BigInteger uint200Max = new BigInteger("1606938044258990275541962092341162602522202993782792835301375"); BigInteger[] uint200Array = {uint200Min, uint200Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint200Arr", new ContractFunctionParameters().addUint200Array(uint200Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint200Arr", new ContractFunctionParameters().addUint200Array(uint200Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint200[])").get(0); @@ -1069,9 +1301,12 @@ void canCallContractFunctionUint200Array() throws Exception { @Test @DisplayName("Can receive uint208 min value from contract call") void canCallContractFunctionUint208Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint208", new ContractFunctionParameters().addUint208(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint208", new ContractFunctionParameters().addUint208(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1081,9 +1316,12 @@ void canCallContractFunctionUint208Min() throws Exception { void canCallContractFunctionUint208Max() throws Exception { BigInteger uint208Max = new BigInteger("411376139330301510538742295639337626245683966408394965837152255"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint208", new ContractFunctionParameters().addUint208(uint208Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint208", new ContractFunctionParameters().addUint208(uint208Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint208Max); } @@ -1095,9 +1333,12 @@ void canCallContractFunctionUint208Array() throws Exception { BigInteger uint208Max = new BigInteger("411376139330301510538742295639337626245683966408394965837152255"); BigInteger[] uint208Array = {uint208Min, uint208Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint208Arr", new ContractFunctionParameters().addUint208Array(uint208Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint208Arr", new ContractFunctionParameters().addUint208Array(uint208Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint208[])").get(0); @@ -1107,9 +1348,12 @@ void canCallContractFunctionUint208Array() throws Exception { @Test @DisplayName("Can receive uint216 min value from contract call") void canCallContractFunctionUint216Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint216", new ContractFunctionParameters().addUint216(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint216", new ContractFunctionParameters().addUint216(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1119,9 +1363,12 @@ void canCallContractFunctionUint216Min() throws Exception { void canCallContractFunctionUint216Max() throws Exception { BigInteger uint216Max = new BigInteger("105312291668557186697918027683670432318895095400549111254310977535"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint216", new ContractFunctionParameters().addUint216(uint216Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint216", new ContractFunctionParameters().addUint216(uint216Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint216Max); } @@ -1133,9 +1380,12 @@ void canCallContractFunctionUint216Array() throws Exception { BigInteger uint216Max = new BigInteger("105312291668557186697918027683670432318895095400549111254310977535"); BigInteger[] uint216Array = {uint216Min, uint216Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint216Arr", new ContractFunctionParameters().addUint216Array(uint216Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint216Arr", new ContractFunctionParameters().addUint216Array(uint216Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint216[])").get(0); @@ -1145,9 +1395,12 @@ void canCallContractFunctionUint216Array() throws Exception { @Test @DisplayName("Can receive uint224 min value from contract call") void canCallContractFunctionUint224Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint224", new ContractFunctionParameters().addUint224(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint224", new ContractFunctionParameters().addUint224(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1157,9 +1410,12 @@ void canCallContractFunctionUint224Min() throws Exception { void canCallContractFunctionUint224Max() throws Exception { BigInteger uint224Max = new BigInteger("26959946667150639794667015087019630673637144422540572481103610249215"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint224", new ContractFunctionParameters().addUint224(uint224Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint224", new ContractFunctionParameters().addUint224(uint224Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint224Max); } @@ -1171,9 +1427,12 @@ void canCallContractFunctionUint224Array() throws Exception { BigInteger uint224Max = new BigInteger("26959946667150639794667015087019630673637144422540572481103610249215"); BigInteger[] uint224Array = {uint224Min, uint224Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint224Arr", new ContractFunctionParameters().addUint224Array(uint224Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint224Arr", new ContractFunctionParameters().addUint224Array(uint224Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint224[])").get(0); @@ -1183,9 +1442,12 @@ void canCallContractFunctionUint224Array() throws Exception { @Test @DisplayName("Can receive uint232 min value from contract call") void canCallContractFunctionUint232Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint232", new ContractFunctionParameters().addUint232(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint232", new ContractFunctionParameters().addUint232(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1193,12 +1455,15 @@ void canCallContractFunctionUint232Min() throws Exception { @Test @DisplayName("Can receive uint232 max value from contract call") void canCallContractFunctionUint232Max() throws Exception { - BigInteger uint232Max = new BigInteger( - "6901746346790563787434755862277025452451108972170386555162524223799295"); + BigInteger uint232Max = + new BigInteger("6901746346790563787434755862277025452451108972170386555162524223799295"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint232", new ContractFunctionParameters().addUint232(uint232Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint232", new ContractFunctionParameters().addUint232(uint232Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint232Max); } @@ -1207,13 +1472,16 @@ void canCallContractFunctionUint232Max() throws Exception { @DisplayName("Can receive uint232 array value from contract call") void canCallContractFunctionUint232Array() throws Exception { BigInteger uint232Min = BigInteger.ZERO; - BigInteger uint232Max = new BigInteger( - "6901746346790563787434755862277025452451108972170386555162524223799295"); + BigInteger uint232Max = + new BigInteger("6901746346790563787434755862277025452451108972170386555162524223799295"); BigInteger[] uint232Array = {uint232Min, uint232Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint232Arr", new ContractFunctionParameters().addUint232Array(uint232Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint232Arr", new ContractFunctionParameters().addUint232Array(uint232Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint232[])").get(0); @@ -1223,9 +1491,12 @@ void canCallContractFunctionUint232Array() throws Exception { @Test @DisplayName("Can receive uint240 min value from contract call") void canCallContractFunctionUint240Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint240", new ContractFunctionParameters().addUint240(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint240", new ContractFunctionParameters().addUint240(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1233,12 +1504,15 @@ void canCallContractFunctionUint240Min() throws Exception { @Test @DisplayName("Can receive uint240 max value from contract call") void canCallContractFunctionUint240Max() throws Exception { - BigInteger uint240Max = new BigInteger( - "1766847064778384329583297500742918515827483896875618958121606201292619775"); + BigInteger uint240Max = + new BigInteger("1766847064778384329583297500742918515827483896875618958121606201292619775"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint240", new ContractFunctionParameters().addUint240(uint240Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint240", new ContractFunctionParameters().addUint240(uint240Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint240Max); } @@ -1247,13 +1521,16 @@ void canCallContractFunctionUint240Max() throws Exception { @DisplayName("Can receive uint240 array value from contract call") void canCallContractFunctionUint240Array() throws Exception { BigInteger uint240Min = BigInteger.ZERO; - BigInteger uint240Max = new BigInteger( - "1766847064778384329583297500742918515827483896875618958121606201292619775"); + BigInteger uint240Max = + new BigInteger("1766847064778384329583297500742918515827483896875618958121606201292619775"); BigInteger[] uint240Array = {uint240Min, uint240Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint240Arr", new ContractFunctionParameters().addUint240Array(uint240Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint240Arr", new ContractFunctionParameters().addUint240Array(uint240Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint240[])").get(0); @@ -1263,9 +1540,12 @@ void canCallContractFunctionUint240Array() throws Exception { @Test @DisplayName("Can receive uint248 min value from contract call") void canCallContractFunctionUint248Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint248", new ContractFunctionParameters().addUint248(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint248", new ContractFunctionParameters().addUint248(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1273,12 +1553,15 @@ void canCallContractFunctionUint248Min() throws Exception { @Test @DisplayName("Can receive uint248 max value from contract call") void canCallContractFunctionUint248Max() throws Exception { - BigInteger uint248Max = new BigInteger( - "452312848583266388373324160190187140051835877600158453279131187530910662655"); + BigInteger uint248Max = + new BigInteger("452312848583266388373324160190187140051835877600158453279131187530910662655"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint248", new ContractFunctionParameters().addUint248(uint248Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint248", new ContractFunctionParameters().addUint248(uint248Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint248Max); } @@ -1287,13 +1570,16 @@ void canCallContractFunctionUint248Max() throws Exception { @DisplayName("Can receive uint248 array value from contract call") void canCallContractFunctionUint248Array() throws Exception { BigInteger uint248Min = BigInteger.ZERO; - BigInteger uint248Max = new BigInteger( - "452312848583266388373324160190187140051835877600158453279131187530910662655"); + BigInteger uint248Max = + new BigInteger("452312848583266388373324160190187140051835877600158453279131187530910662655"); BigInteger[] uint248Array = {uint248Min, uint248Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint248Arr", new ContractFunctionParameters().addUint248Array(uint248Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint248Arr", new ContractFunctionParameters().addUint248Array(uint248Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint248[])").get(0); @@ -1303,9 +1589,12 @@ void canCallContractFunctionUint248Array() throws Exception { @Test @DisplayName("Can receive uint256 min value from contract call") void canCallContractFunctionUint256Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint256", new ContractFunctionParameters().addUint256(BigInteger.ZERO)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint256", new ContractFunctionParameters().addUint256(BigInteger.ZERO)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(BigInteger.ZERO); } @@ -1315,9 +1604,12 @@ void canCallContractFunctionUint256Min() throws Exception { void canCallContractFunctionUint256Max() throws Exception { BigInteger uint256Max = new BigInteger("2").pow(256).subtract(BigInteger.ONE); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint256", new ContractFunctionParameters().addUint256(uint256Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint256", new ContractFunctionParameters().addUint256(uint256Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint256(0)).isEqualTo(uint256Max); } @@ -1329,9 +1621,12 @@ void canCallContractFunctionUint256Array() throws Exception { BigInteger uint256Max = new BigInteger("2").pow(256).subtract(BigInteger.ONE); BigInteger[] uint256Array = {uint256Min, uint256Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint256Arr", new ContractFunctionParameters().addUint256Array(uint256Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint256Arr", new ContractFunctionParameters().addUint256Array(uint256Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(uint256[])").get(0); @@ -1341,9 +1636,12 @@ void canCallContractFunctionUint256Array() throws Exception { @Test @DisplayName("Can receive int8 min value from contract call") void canCallContractFunctionInt8Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt8", new ContractFunctionParameters().addInt8(Byte.MIN_VALUE)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt8", new ContractFunctionParameters().addInt8(Byte.MIN_VALUE)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt8(0)).isEqualTo(Byte.MIN_VALUE); } @@ -1351,9 +1649,12 @@ void canCallContractFunctionInt8Min() throws Exception { @Test @DisplayName("Can receive int8 max value from contract call") void canCallContractFunctionInt8Max() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt8", new ContractFunctionParameters().addInt8(Byte.MAX_VALUE)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt8", new ContractFunctionParameters().addInt8(Byte.MAX_VALUE)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt8(0)).isEqualTo(Byte.MAX_VALUE); } @@ -1363,9 +1664,12 @@ void canCallContractFunctionInt8Max() throws Exception { void canCallContractFunctionInt8Array() throws Exception { byte[] int8Array = {Byte.MIN_VALUE, Byte.MAX_VALUE}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt8Arr", new ContractFunctionParameters().addInt8Array(int8Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt8Arr", new ContractFunctionParameters().addInt8Array(int8Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (int[]) response.getResult("(int8[])").get(0); @@ -1378,9 +1682,12 @@ void canCallContractFunctionInt8Array() throws Exception { void canCallContractFunctionInt16Min() throws Exception { int int16Min = -32768; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt16", new ContractFunctionParameters().addInt16(int16Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt16", new ContractFunctionParameters().addInt16(int16Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt32(0)).isEqualTo(int16Min); } @@ -1390,9 +1697,12 @@ void canCallContractFunctionInt16Min() throws Exception { void canCallContractFunctionInt16Max() throws Exception { int int16Max = 32767; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt16", new ContractFunctionParameters().addInt16(int16Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt16", new ContractFunctionParameters().addInt16(int16Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt32(0)).isEqualTo(int16Max); } @@ -1404,9 +1714,12 @@ void canCallContractFunctionInt16Array() throws Exception { int int16Max = 32767; int[] int16Array = {int16Min, int16Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt16Arr", new ContractFunctionParameters().addInt16Array(int16Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt16Arr", new ContractFunctionParameters().addInt16Array(int16Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (int[]) response.getResult("(int16[])").get(0); @@ -1418,9 +1731,12 @@ void canCallContractFunctionInt16Array() throws Exception { void canCallContractFunctionInt24Min() throws Exception { int int24Min = -8388608; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt24", new ContractFunctionParameters().addInt24(int24Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt24", new ContractFunctionParameters().addInt24(int24Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt32(0)).isEqualTo(int24Min); } @@ -1430,9 +1746,12 @@ void canCallContractFunctionInt24Min() throws Exception { void canCallContractFunctionInt24Max() throws Exception { int int24Max = 8388607; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt24", new ContractFunctionParameters().addInt24(int24Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt24", new ContractFunctionParameters().addInt24(int24Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt32(0)).isEqualTo(int24Max); } @@ -1444,9 +1763,12 @@ void canCallContractFunctionInt24Array() throws Exception { int int24Max = 8388607; int[] int24Array = {int24Min, int24Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt24Arr", new ContractFunctionParameters().addInt24Array(int24Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt24Arr", new ContractFunctionParameters().addInt24Array(int24Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (int[]) response.getResult("(int24[])").get(0); @@ -1456,9 +1778,12 @@ void canCallContractFunctionInt24Array() throws Exception { @Test @DisplayName("Can receive int32 min value from contract call") void canCallContractFunctionInt32Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt32", new ContractFunctionParameters().addInt32(Integer.MIN_VALUE)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt32", new ContractFunctionParameters().addInt32(Integer.MIN_VALUE)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt32(0)).isEqualTo(Integer.MIN_VALUE); } @@ -1466,9 +1791,12 @@ void canCallContractFunctionInt32Min() throws Exception { @Test @DisplayName("Can receive int32 max value from contract call") void canCallContractFunctionInt32Max() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt32", new ContractFunctionParameters().addInt32(Integer.MAX_VALUE)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt32", new ContractFunctionParameters().addInt32(Integer.MAX_VALUE)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt32(0)).isEqualTo(Integer.MAX_VALUE); } @@ -1480,9 +1808,12 @@ void canCallContractFunctionInt32Array() throws Exception { int int32Max = Integer.MAX_VALUE; int[] int32Array = {int32Min, int32Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt32Arr", new ContractFunctionParameters().addInt32Array(int32Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt32Arr", new ContractFunctionParameters().addInt32Array(int32Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (int[]) response.getResult("(int32[])").get(0); @@ -1494,9 +1825,12 @@ void canCallContractFunctionInt32Array() throws Exception { void canCallContractFunctionInt40Min() throws Exception { long int40Min = -549755813888L; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt40", new ContractFunctionParameters().addInt40(int40Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt40", new ContractFunctionParameters().addInt40(int40Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt64(0)).isEqualTo(int40Min); } @@ -1506,9 +1840,12 @@ void canCallContractFunctionInt40Min() throws Exception { void canCallContractFunctionInt40Max() throws Exception { long int40Max = 549755813887L; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt40", new ContractFunctionParameters().addInt40(int40Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt40", new ContractFunctionParameters().addInt40(int40Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt64(0)).isEqualTo(int40Max); } @@ -1520,9 +1857,12 @@ void canCallContractFunctionInt40Array() throws Exception { long int40Max = 549755813887L; long[] int40Array = {int40Min, int40Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt40Arr", new ContractFunctionParameters().addInt40Array(int40Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt40Arr", new ContractFunctionParameters().addInt40Array(int40Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (long[]) response.getResult("(int40[])").get(0); @@ -1534,9 +1874,12 @@ void canCallContractFunctionInt40Array() throws Exception { void canCallContractFunctionInt48Min() throws Exception { long int48Min = -140737488355328L; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt48", new ContractFunctionParameters().addInt48(int48Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt48", new ContractFunctionParameters().addInt48(int48Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt64(0)).isEqualTo(int48Min); } @@ -1546,9 +1889,12 @@ void canCallContractFunctionInt48Min() throws Exception { void canCallContractFunctionInt48Max() throws Exception { long int48Max = 140737488355327L; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt48", new ContractFunctionParameters().addInt48(int48Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt48", new ContractFunctionParameters().addInt48(int48Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt64(0)).isEqualTo(int48Max); } @@ -1560,9 +1906,12 @@ void canCallContractFunctionInt48Array() throws Exception { long int48Max = 140737488355327L; long[] int48Array = {int48Min, int48Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt48Arr", new ContractFunctionParameters().addInt48Array(int48Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt48Arr", new ContractFunctionParameters().addInt48Array(int48Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (long[]) response.getResult("(int48[])").get(0); @@ -1574,9 +1923,12 @@ void canCallContractFunctionInt48Array() throws Exception { void canCallContractFunctionInt56Min() throws Exception { long int56Min = -36028797018963968L; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt56", new ContractFunctionParameters().addInt56(int56Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt56", new ContractFunctionParameters().addInt56(int56Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt64(0)).isEqualTo(int56Min); } @@ -1586,9 +1938,12 @@ void canCallContractFunctionInt56Min() throws Exception { void canCallContractFunctionInt56Max() throws Exception { long int56Max = 36028797018963967L; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt56", new ContractFunctionParameters().addInt56(int56Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt56", new ContractFunctionParameters().addInt56(int56Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt64(0)).isEqualTo(int56Max); } @@ -1600,9 +1955,12 @@ void canCallContractFunctionInt56Array() throws Exception { long int56Max = 36028797018963967L; long[] int56Array = {int56Min, int56Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt56Arr", new ContractFunctionParameters().addInt56Array(int56Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt56Arr", new ContractFunctionParameters().addInt56Array(int56Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (long[]) response.getResult("(int56[])").get(0); @@ -1612,9 +1970,12 @@ void canCallContractFunctionInt56Array() throws Exception { @Test @DisplayName("Can receive int64 min value from contract call") void canCallContractFunctionInt64Min() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt64", new ContractFunctionParameters().addInt64(Long.MIN_VALUE)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt64", new ContractFunctionParameters().addInt64(Long.MIN_VALUE)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint64(0)).isEqualTo(Long.MIN_VALUE); } @@ -1622,9 +1983,12 @@ void canCallContractFunctionInt64Min() throws Exception { @Test @DisplayName("Can receive int64 max value from contract call") void canCallContractFunctionInt64Max() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnUint64", new ContractFunctionParameters().addUint64(Long.MAX_VALUE)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnUint64", new ContractFunctionParameters().addUint64(Long.MAX_VALUE)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getUint64(0)).isEqualTo(Long.MAX_VALUE); } @@ -1636,9 +2000,12 @@ void canCallContractFunctionInt64Array() throws Exception { long int64Max = Long.MAX_VALUE; long[] int64Array = {int64Min, int64Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt64Arr", new ContractFunctionParameters().addInt64Array(int64Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt64Arr", new ContractFunctionParameters().addInt64Array(int64Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (long[]) response.getResult("(int64[])").get(0); @@ -1650,9 +2017,12 @@ void canCallContractFunctionInt64Array() throws Exception { void canCallContractFunctionInt72Min() throws Exception { BigInteger int72Min = new BigInteger("-2361183241434822606848"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt72", new ContractFunctionParameters().addInt72(int72Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt72", new ContractFunctionParameters().addInt72(int72Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int72Min); } @@ -1662,9 +2032,12 @@ void canCallContractFunctionInt72Min() throws Exception { void canCallContractFunctionInt72Max() throws Exception { BigInteger int72Max = new BigInteger("2361183241434822606847"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt72", new ContractFunctionParameters().addInt72(int72Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt72", new ContractFunctionParameters().addInt72(int72Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int72Max); } @@ -1676,9 +2049,12 @@ void canCallContractFunctionInt72Array() throws Exception { BigInteger int72Max = new BigInteger("2361183241434822606847"); BigInteger[] int72Array = {int72Min, int72Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt72Arr", new ContractFunctionParameters().addInt72Array(int72Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt72Arr", new ContractFunctionParameters().addInt72Array(int72Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int72[])").get(0); @@ -1690,9 +2066,12 @@ void canCallContractFunctionInt72Array() throws Exception { void canCallContractFunctionInt80Min() throws Exception { BigInteger int80Min = new BigInteger("-604462909807314587353088"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt80", new ContractFunctionParameters().addInt80(int80Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt80", new ContractFunctionParameters().addInt80(int80Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int80Min); } @@ -1702,9 +2081,12 @@ void canCallContractFunctionInt80Min() throws Exception { void canCallContractFunctionInt80Max() throws Exception { BigInteger int80Max = new BigInteger("604462909807314587353087"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt80", new ContractFunctionParameters().addInt80(int80Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt80", new ContractFunctionParameters().addInt80(int80Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int80Max); } @@ -1716,9 +2098,12 @@ void canCallContractFunctionInt80Array() throws Exception { BigInteger int80Max = new BigInteger("604462909807314587353087"); BigInteger[] int80Array = {int80Min, int80Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt80Arr", new ContractFunctionParameters().addInt80Array(int80Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt80Arr", new ContractFunctionParameters().addInt80Array(int80Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int80[])").get(0); @@ -1730,9 +2115,12 @@ void canCallContractFunctionInt80Array() throws Exception { void canCallContractFunctionInt88Min() throws Exception { BigInteger int88Min = new BigInteger("-154742504910672534362390528"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt88", new ContractFunctionParameters().addInt88(int88Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt88", new ContractFunctionParameters().addInt88(int88Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int88Min); } @@ -1742,9 +2130,12 @@ void canCallContractFunctionInt88Min() throws Exception { void canCallContractFunctionInt88Max() throws Exception { BigInteger int88Max = new BigInteger("154742504910672534362390527"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt88", new ContractFunctionParameters().addInt88(int88Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt88", new ContractFunctionParameters().addInt88(int88Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int88Max); } @@ -1756,9 +2147,12 @@ void canCallContractFunctionInt88Array() throws Exception { BigInteger int88Max = new BigInteger("154742504910672534362390527"); BigInteger[] int88Array = {int88Min, int88Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt88Arr", new ContractFunctionParameters().addInt88Array(int88Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt88Arr", new ContractFunctionParameters().addInt88Array(int88Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int88[])").get(0); @@ -1770,9 +2164,12 @@ void canCallContractFunctionInt88Array() throws Exception { void canCallContractFunctionInt96Min() throws Exception { BigInteger int96Min = new BigInteger("-39614081257132168796771975168"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt96", new ContractFunctionParameters().addInt96(int96Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt96", new ContractFunctionParameters().addInt96(int96Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int96Min); } @@ -1782,9 +2179,12 @@ void canCallContractFunctionInt96Min() throws Exception { void canCallContractFunctionInt96Max() throws Exception { BigInteger int96Max = new BigInteger("39614081257132168796771975167"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt96", new ContractFunctionParameters().addInt96(int96Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt96", new ContractFunctionParameters().addInt96(int96Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int96Max); } @@ -1796,9 +2196,12 @@ void canCallContractFunctionInt96Array() throws Exception { BigInteger int96Max = new BigInteger("39614081257132168796771975167"); BigInteger[] int96Array = {int96Min, int96Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt96Arr", new ContractFunctionParameters().addInt96Array(int96Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt96Arr", new ContractFunctionParameters().addInt96Array(int96Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int96[])").get(0); @@ -1810,9 +2213,12 @@ void canCallContractFunctionInt96Array() throws Exception { void canCallContractFunctionInt104Min() throws Exception { BigInteger int104Min = new BigInteger("-10141204801825835211973625643008"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt104", new ContractFunctionParameters().addInt104(int104Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt104", new ContractFunctionParameters().addInt104(int104Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int104Min); } @@ -1822,9 +2228,12 @@ void canCallContractFunctionInt104Min() throws Exception { void canCallContractFunctionInt104Max() throws Exception { BigInteger int104Max = new BigInteger("10141204801825835211973625643007"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt104", new ContractFunctionParameters().addInt104(int104Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt104", new ContractFunctionParameters().addInt104(int104Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int104Max); } @@ -1836,9 +2245,12 @@ void canCallContractFunctionInt104Array() throws Exception { BigInteger int104Max = new BigInteger("10141204801825835211973625643007"); BigInteger[] int104Array = {int104Min, int104Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt104Arr", new ContractFunctionParameters().addInt104Array(int104Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt104Arr", new ContractFunctionParameters().addInt104Array(int104Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int104[])").get(0); @@ -1850,9 +2262,12 @@ void canCallContractFunctionInt104Array() throws Exception { void canCallContractFunctionInt112Min() throws Exception { BigInteger int112Min = new BigInteger("-2596148429267413814265248164610048"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt112", new ContractFunctionParameters().addInt112(int112Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt112", new ContractFunctionParameters().addInt112(int112Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int112Min); } @@ -1862,9 +2277,12 @@ void canCallContractFunctionInt112Min() throws Exception { void canCallContractFunctionInt112Max() throws Exception { BigInteger int112Max = new BigInteger("2596148429267413814265248164610047"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt112", new ContractFunctionParameters().addInt112(int112Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt112", new ContractFunctionParameters().addInt112(int112Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int112Max); } @@ -1876,9 +2294,12 @@ void canCallContractFunctionInt112Array() throws Exception { BigInteger int112Max = new BigInteger("2596148429267413814265248164610047"); BigInteger[] int112Array = {int112Min, int112Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt112Arr", new ContractFunctionParameters().addInt112Array(int112Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt112Arr", new ContractFunctionParameters().addInt112Array(int112Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int112[])").get(0); @@ -1890,9 +2311,12 @@ void canCallContractFunctionInt112Array() throws Exception { void canCallContractFunctionInt120Min() throws Exception { BigInteger int120Min = new BigInteger("-664613997892457936451903530140172288"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt120", new ContractFunctionParameters().addInt120(int120Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt120", new ContractFunctionParameters().addInt120(int120Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int120Min); } @@ -1902,9 +2326,12 @@ void canCallContractFunctionInt120Min() throws Exception { void canCallContractFunctionInt120Max() throws Exception { BigInteger int120Max = new BigInteger("664613997892457936451903530140172287"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt120", new ContractFunctionParameters().addInt120(int120Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt120", new ContractFunctionParameters().addInt120(int120Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int120Max); } @@ -1916,9 +2343,12 @@ void canCallContractFunctionInt120Array() throws Exception { BigInteger int120Max = new BigInteger("664613997892457936451903530140172287"); BigInteger[] int120Array = {int120Min, int120Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt120Arr", new ContractFunctionParameters().addInt120Array(int120Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt120Arr", new ContractFunctionParameters().addInt120Array(int120Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int120[])").get(0); @@ -1930,9 +2360,12 @@ void canCallContractFunctionInt120Array() throws Exception { void canCallContractFunctionInt128Min() throws Exception { BigInteger int128Min = new BigInteger("-170141183460469231731687303715884105728"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt128", new ContractFunctionParameters().addInt128(int128Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt128", new ContractFunctionParameters().addInt128(int128Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int128Min); } @@ -1942,9 +2375,12 @@ void canCallContractFunctionInt128Min() throws Exception { void canCallContractFunctionInt128Max() throws Exception { BigInteger int128Max = new BigInteger("170141183460469231731687303715884105727"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt128", new ContractFunctionParameters().addInt128(int128Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt128", new ContractFunctionParameters().addInt128(int128Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int128Max); } @@ -1956,9 +2392,12 @@ void canCallContractFunctionInt128Array() throws Exception { BigInteger int128Max = new BigInteger("170141183460469231731687303715884105727"); BigInteger[] int128Array = {int128Min, int128Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt128Arr", new ContractFunctionParameters().addInt128Array(int128Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt128Arr", new ContractFunctionParameters().addInt128Array(int128Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int128[])").get(0); @@ -1970,9 +2409,12 @@ void canCallContractFunctionInt128Array() throws Exception { void canCallContractFunctionInt136Min() throws Exception { BigInteger int136Min = new BigInteger("-43556142965880123323311949751266331066368"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt136", new ContractFunctionParameters().addInt136(int136Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt136", new ContractFunctionParameters().addInt136(int136Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int136Min); } @@ -1982,9 +2424,12 @@ void canCallContractFunctionInt136Min() throws Exception { void canCallContractFunctionInt136Max() throws Exception { BigInteger int136Max = new BigInteger("43556142965880123323311949751266331066367"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt136", new ContractFunctionParameters().addInt136(int136Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt136", new ContractFunctionParameters().addInt136(int136Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int136Max); } @@ -1996,9 +2441,12 @@ void canCallContractFunctionInt136Array() throws Exception { BigInteger int136Max = new BigInteger("43556142965880123323311949751266331066367"); BigInteger[] int136Array = {int136Min, int136Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt136Arr", new ContractFunctionParameters().addInt136Array(int136Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt136Arr", new ContractFunctionParameters().addInt136Array(int136Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int136[])").get(0); @@ -2010,9 +2458,12 @@ void canCallContractFunctionInt136Array() throws Exception { void canCallContractFunctionInt144Min() throws Exception { BigInteger int144Min = new BigInteger("-11150372599265311570767859136324180752990208"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt144", new ContractFunctionParameters().addInt144(int144Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt144", new ContractFunctionParameters().addInt144(int144Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int144Min); } @@ -2022,9 +2473,12 @@ void canCallContractFunctionInt144Min() throws Exception { void canCallContractFunctionInt144Max() throws Exception { BigInteger int144Max = new BigInteger("11150372599265311570767859136324180752990207"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt144", new ContractFunctionParameters().addInt144(int144Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt144", new ContractFunctionParameters().addInt144(int144Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int144Max); } @@ -2036,9 +2490,12 @@ void canCallContractFunctionInt144Array() throws Exception { BigInteger int144Max = new BigInteger("11150372599265311570767859136324180752990207"); BigInteger[] int144Array = {int144Min, int144Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt144Arr", new ContractFunctionParameters().addInt144Array(int144Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt144Arr", new ContractFunctionParameters().addInt144Array(int144Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int144[])").get(0); @@ -2050,9 +2507,12 @@ void canCallContractFunctionInt144Array() throws Exception { void canCallContractFunctionInt152Min() throws Exception { BigInteger int152Min = new BigInteger("-2854495385411919762116571938898990272765493248"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt152", new ContractFunctionParameters().addInt152(int152Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt152", new ContractFunctionParameters().addInt152(int152Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int152Min); } @@ -2062,9 +2522,12 @@ void canCallContractFunctionInt152Min() throws Exception { void canCallContractFunctionInt152Max() throws Exception { BigInteger int152Max = new BigInteger("2854495385411919762116571938898990272765493247"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt152", new ContractFunctionParameters().addInt152(int152Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt152", new ContractFunctionParameters().addInt152(int152Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int152Max); } @@ -2076,9 +2539,12 @@ void canCallContractFunctionInt152Array() throws Exception { BigInteger int152Max = new BigInteger("2854495385411919762116571938898990272765493247"); BigInteger[] int152Array = {int152Min, int152Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt152Arr", new ContractFunctionParameters().addInt152Array(int152Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt152Arr", new ContractFunctionParameters().addInt152Array(int152Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int152[])").get(0); @@ -2090,9 +2556,12 @@ void canCallContractFunctionInt152Array() throws Exception { void canCallContractFunctionInt160Min() throws Exception { BigInteger int160Min = new BigInteger("-730750818665451459101842416358141509827966271488"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt160", new ContractFunctionParameters().addInt160(int160Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt160", new ContractFunctionParameters().addInt160(int160Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int160Min); } @@ -2102,9 +2571,12 @@ void canCallContractFunctionInt160Min() throws Exception { void canCallContractFunctionInt160Max() throws Exception { BigInteger int160Max = new BigInteger("730750818665451459101842416358141509827966271487"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt160", new ContractFunctionParameters().addInt160(int160Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt160", new ContractFunctionParameters().addInt160(int160Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int160Max); } @@ -2116,9 +2588,12 @@ void canCallContractFunctionInt160Array() throws Exception { BigInteger int160Max = new BigInteger("730750818665451459101842416358141509827966271487"); BigInteger[] int160Array = {int160Min, int160Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt160Arr", new ContractFunctionParameters().addInt160Array(int160Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt160Arr", new ContractFunctionParameters().addInt160Array(int160Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int160[])").get(0); @@ -2130,9 +2605,12 @@ void canCallContractFunctionInt160Array() throws Exception { void canCallContractFunctionInt168Min() throws Exception { BigInteger int168Min = new BigInteger("-187072209578355573530071658587684226515959365500928"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt168", new ContractFunctionParameters().addInt168(int168Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt168", new ContractFunctionParameters().addInt168(int168Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int168Min); } @@ -2142,9 +2620,12 @@ void canCallContractFunctionInt168Min() throws Exception { void canCallContractFunctionInt168Max() throws Exception { BigInteger int168Max = new BigInteger("187072209578355573530071658587684226515959365500927"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt168", new ContractFunctionParameters().addInt168(int168Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt168", new ContractFunctionParameters().addInt168(int168Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int168Max); } @@ -2156,9 +2637,12 @@ void canCallContractFunctionInt168Array() throws Exception { BigInteger int168Max = new BigInteger("187072209578355573530071658587684226515959365500927"); BigInteger[] int168Array = {int168Min, int168Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt168Arr", new ContractFunctionParameters().addInt168Array(int168Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt168Arr", new ContractFunctionParameters().addInt168Array(int168Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int168[])").get(0); @@ -2170,9 +2654,12 @@ void canCallContractFunctionInt168Array() throws Exception { void canCallContractFunctionInt176Min() throws Exception { BigInteger int176Min = new BigInteger("-47890485652059026823698344598447161988085597568237568"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt176", new ContractFunctionParameters().addInt176(int176Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt176", new ContractFunctionParameters().addInt176(int176Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int176Min); } @@ -2182,9 +2669,12 @@ void canCallContractFunctionInt176Min() throws Exception { void canCallContractFunctionInt176Max() throws Exception { BigInteger int176Max = new BigInteger("47890485652059026823698344598447161988085597568237567"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt176", new ContractFunctionParameters().addInt176(int176Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt176", new ContractFunctionParameters().addInt176(int176Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int176Max); } @@ -2196,9 +2686,12 @@ void canCallContractFunctionInt176Array() throws Exception { BigInteger int176Max = new BigInteger("47890485652059026823698344598447161988085597568237567"); BigInteger[] int176Array = {int176Min, int176Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt176Arr", new ContractFunctionParameters().addInt176Array(int176Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt176Arr", new ContractFunctionParameters().addInt176Array(int176Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int176[])").get(0); @@ -2210,9 +2703,12 @@ void canCallContractFunctionInt176Array() throws Exception { void canCallContractFunctionInt184Min() throws Exception { BigInteger int184Min = new BigInteger("-12259964326927110866866776217202473468949912977468817408"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt184", new ContractFunctionParameters().addInt184(int184Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt184", new ContractFunctionParameters().addInt184(int184Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int184Min); } @@ -2222,9 +2718,12 @@ void canCallContractFunctionInt184Min() throws Exception { void canCallContractFunctionInt184Max() throws Exception { BigInteger int184Max = new BigInteger("12259964326927110866866776217202473468949912977468817407"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt184", new ContractFunctionParameters().addInt184(int184Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt184", new ContractFunctionParameters().addInt184(int184Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int184Max); } @@ -2236,9 +2735,12 @@ void canCallContractFunctionInt184Array() throws Exception { BigInteger int184Max = new BigInteger("12259964326927110866866776217202473468949912977468817407"); BigInteger[] int184Array = {int184Min, int184Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt184Arr", new ContractFunctionParameters().addInt184Array(int184Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt184Arr", new ContractFunctionParameters().addInt184Array(int184Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int184[])").get(0); @@ -2250,9 +2752,12 @@ void canCallContractFunctionInt184Array() throws Exception { void canCallContractFunctionInt192Min() throws Exception { BigInteger int192Min = new BigInteger("-3138550867693340381917894711603833208051177722232017256448"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt192", new ContractFunctionParameters().addInt192(int192Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt192", new ContractFunctionParameters().addInt192(int192Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int192Min); } @@ -2262,9 +2767,12 @@ void canCallContractFunctionInt192Min() throws Exception { void canCallContractFunctionInt192Max() throws Exception { BigInteger int192Max = new BigInteger("3138550867693340381917894711603833208051177722232017256447"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt192", new ContractFunctionParameters().addInt192(int192Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt192", new ContractFunctionParameters().addInt192(int192Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int192Max); } @@ -2276,9 +2784,12 @@ void canCallContractFunctionInt192Array() throws Exception { BigInteger int192Max = new BigInteger("3138550867693340381917894711603833208051177722232017256447"); BigInteger[] int192Array = {int192Min, int192Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt192Arr", new ContractFunctionParameters().addInt192Array(int192Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt192Arr", new ContractFunctionParameters().addInt192Array(int192Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int192[])").get(0); @@ -2290,9 +2801,12 @@ void canCallContractFunctionInt192Array() throws Exception { void canCallContractFunctionInt200Min() throws Exception { BigInteger int200Min = new BigInteger("-803469022129495137770981046170581301261101496891396417650688"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt200", new ContractFunctionParameters().addInt200(int200Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt200", new ContractFunctionParameters().addInt200(int200Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int200Min); } @@ -2302,9 +2816,12 @@ void canCallContractFunctionInt200Min() throws Exception { void canCallContractFunctionInt200Max() throws Exception { BigInteger int200Max = new BigInteger("803469022129495137770981046170581301261101496891396417650687"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt200", new ContractFunctionParameters().addInt200(int200Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt200", new ContractFunctionParameters().addInt200(int200Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int200Max); } @@ -2316,9 +2833,12 @@ void canCallContractFunctionInt200Array() throws Exception { BigInteger int200Max = new BigInteger("803469022129495137770981046170581301261101496891396417650687"); BigInteger[] int200Array = {int200Min, int200Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt200Arr", new ContractFunctionParameters().addInt200Array(int200Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt200Arr", new ContractFunctionParameters().addInt200Array(int200Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int200[])").get(0); @@ -2330,9 +2850,12 @@ void canCallContractFunctionInt200Array() throws Exception { void canCallContractFunctionInt208Min() throws Exception { BigInteger int208Min = new BigInteger("-205688069665150755269371147819668813122841983204197482918576128"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt208", new ContractFunctionParameters().addInt208(int208Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt208", new ContractFunctionParameters().addInt208(int208Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int208Min); } @@ -2342,9 +2865,12 @@ void canCallContractFunctionInt208Min() throws Exception { void canCallContractFunctionInt208Max() throws Exception { BigInteger int208Max = new BigInteger("205688069665150755269371147819668813122841983204197482918576127"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt208", new ContractFunctionParameters().addInt208(int208Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt208", new ContractFunctionParameters().addInt208(int208Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int208Max); } @@ -2356,9 +2882,12 @@ void canCallContractFunctionInt208Array() throws Exception { BigInteger int208Max = new BigInteger("205688069665150755269371147819668813122841983204197482918576127"); BigInteger[] int208Array = {int208Min, int208Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt208Arr", new ContractFunctionParameters().addInt208Array(int208Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt208Arr", new ContractFunctionParameters().addInt208Array(int208Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int208[])").get(0); @@ -2370,9 +2899,12 @@ void canCallContractFunctionInt208Array() throws Exception { void canCallContractFunctionInt216Min() throws Exception { BigInteger int216Min = new BigInteger("-52656145834278593348959013841835216159447547700274555627155488768"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt216", new ContractFunctionParameters().addInt216(int216Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt216", new ContractFunctionParameters().addInt216(int216Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int216Min); } @@ -2382,9 +2914,12 @@ void canCallContractFunctionInt216Min() throws Exception { void canCallContractFunctionInt216Max() throws Exception { BigInteger int216Max = new BigInteger("52656145834278593348959013841835216159447547700274555627155488767"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt216", new ContractFunctionParameters().addInt216(int216Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt216", new ContractFunctionParameters().addInt216(int216Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int216Max); } @@ -2396,9 +2931,12 @@ void canCallContractFunctionInt216Array() throws Exception { BigInteger int216Max = new BigInteger("52656145834278593348959013841835216159447547700274555627155488767"); BigInteger[] int216Array = {int216Min, int216Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt216Arr", new ContractFunctionParameters().addInt216Array(int216Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt216Arr", new ContractFunctionParameters().addInt216Array(int216Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int216[])").get(0); @@ -2410,9 +2948,12 @@ void canCallContractFunctionInt216Array() throws Exception { void canCallContractFunctionInt224Min() throws Exception { BigInteger int224Min = new BigInteger("-13479973333575319897333507543509815336818572211270286240551805124608"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt224", new ContractFunctionParameters().addInt224(int224Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt224", new ContractFunctionParameters().addInt224(int224Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int224Min); } @@ -2422,9 +2963,12 @@ void canCallContractFunctionInt224Min() throws Exception { void canCallContractFunctionInt224Max() throws Exception { BigInteger int224Max = new BigInteger("13479973333575319897333507543509815336818572211270286240551805124607"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt224", new ContractFunctionParameters().addInt224(int224Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt224", new ContractFunctionParameters().addInt224(int224Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int224Max); } @@ -2436,9 +2980,12 @@ void canCallContractFunctionInt224Array() throws Exception { BigInteger int224Max = new BigInteger("13479973333575319897333507543509815336818572211270286240551805124607"); BigInteger[] int224Array = {int224Min, int224Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt224Arr", new ContractFunctionParameters().addInt224Array(int224Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt224Arr", new ContractFunctionParameters().addInt224Array(int224Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int224[])").get(0); @@ -2448,12 +2995,15 @@ void canCallContractFunctionInt224Array() throws Exception { @Test @DisplayName("Can receive int232 min value from contract call") void canCallContractFunctionInt232Min() throws Exception { - BigInteger int232Min = new BigInteger( - "-3450873173395281893717377931138512726225554486085193277581262111899648"); + BigInteger int232Min = + new BigInteger("-3450873173395281893717377931138512726225554486085193277581262111899648"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt232", new ContractFunctionParameters().addInt232(int232Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt232", new ContractFunctionParameters().addInt232(int232Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int232Min); } @@ -2463,9 +3013,12 @@ void canCallContractFunctionInt232Min() throws Exception { void canCallContractFunctionInt232Max() throws Exception { BigInteger int232Max = new BigInteger("3450873173395281893717377931138512726225554486085193277581262111899647"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt232", new ContractFunctionParameters().addInt232(int232Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt232", new ContractFunctionParameters().addInt232(int232Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int232Max); } @@ -2473,14 +3026,17 @@ void canCallContractFunctionInt232Max() throws Exception { @Test @DisplayName("Can receive int232 array value from contract call") void canCallContractFunctionInt232Array() throws Exception { - BigInteger int232Min = new BigInteger( - "-3450873173395281893717377931138512726225554486085193277581262111899648"); + BigInteger int232Min = + new BigInteger("-3450873173395281893717377931138512726225554486085193277581262111899648"); BigInteger int232Max = new BigInteger("3450873173395281893717377931138512726225554486085193277581262111899647"); BigInteger[] int232Array = {int232Min, int232Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt232Arr", new ContractFunctionParameters().addInt232Array(int232Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt232Arr", new ContractFunctionParameters().addInt232Array(int232Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int232[])").get(0); @@ -2490,12 +3046,15 @@ void canCallContractFunctionInt232Array() throws Exception { @Test @DisplayName("Can receive int240 min value from contract call") void canCallContractFunctionInt240Min() throws Exception { - BigInteger int240Min = new BigInteger( - "-883423532389192164791648750371459257913741948437809479060803100646309888"); + BigInteger int240Min = + new BigInteger("-883423532389192164791648750371459257913741948437809479060803100646309888"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt240", new ContractFunctionParameters().addInt240(int240Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt240", new ContractFunctionParameters().addInt240(int240Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int240Min); } @@ -2503,12 +3062,15 @@ void canCallContractFunctionInt240Min() throws Exception { @Test @DisplayName("Can receive int240 max value from contract call") void canCallContractFunctionInt240Max() throws Exception { - BigInteger int240Max = new BigInteger( - "883423532389192164791648750371459257913741948437809479060803100646309887"); + BigInteger int240Max = + new BigInteger("883423532389192164791648750371459257913741948437809479060803100646309887"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt240", new ContractFunctionParameters().addInt240(int240Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt240", new ContractFunctionParameters().addInt240(int240Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int240Max); } @@ -2516,15 +3078,18 @@ void canCallContractFunctionInt240Max() throws Exception { @Test @DisplayName("Can receive int240 array value from contract call") void canCallContractFunctionInt240Array() throws Exception { - BigInteger int240Min = new BigInteger( - "-883423532389192164791648750371459257913741948437809479060803100646309888"); - BigInteger int240Max = new BigInteger( - "883423532389192164791648750371459257913741948437809479060803100646309887"); + BigInteger int240Min = + new BigInteger("-883423532389192164791648750371459257913741948437809479060803100646309888"); + BigInteger int240Max = + new BigInteger("883423532389192164791648750371459257913741948437809479060803100646309887"); BigInteger[] int240Array = {int240Min, int240Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt240Arr", new ContractFunctionParameters().addInt240Array(int240Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt240Arr", new ContractFunctionParameters().addInt240Array(int240Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int240[])").get(0); @@ -2534,12 +3099,15 @@ void canCallContractFunctionInt240Array() throws Exception { @Test @DisplayName("Can receive int248 min value from contract call") void canCallContractFunctionInt248Min() throws Exception { - BigInteger int248Min = new BigInteger( - "-226156424291633194186662080095093570025917938800079226639565593765455331328"); + BigInteger int248Min = + new BigInteger("-226156424291633194186662080095093570025917938800079226639565593765455331328"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt248", new ContractFunctionParameters().addInt248(int248Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt248", new ContractFunctionParameters().addInt248(int248Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int248Min); } @@ -2547,12 +3115,15 @@ void canCallContractFunctionInt248Min() throws Exception { @Test @DisplayName("Can receive int248 max value from contract call") void canCallContractFunctionInt248Max() throws Exception { - BigInteger int248Max = new BigInteger( - "226156424291633194186662080095093570025917938800079226639565593765455331327"); + BigInteger int248Max = + new BigInteger("226156424291633194186662080095093570025917938800079226639565593765455331327"); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt248", new ContractFunctionParameters().addInt248(int248Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt248", new ContractFunctionParameters().addInt248(int248Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int248Max); } @@ -2560,15 +3131,18 @@ void canCallContractFunctionInt248Max() throws Exception { @Test @DisplayName("Can receive int248 array value from contract call") void canCallContractFunctionInt248Array() throws Exception { - BigInteger int248Min = new BigInteger( - "-226156424291633194186662080095093570025917938800079226639565593765455331328"); - BigInteger int248Max = new BigInteger( - "226156424291633194186662080095093570025917938800079226639565593765455331327"); + BigInteger int248Min = + new BigInteger("-226156424291633194186662080095093570025917938800079226639565593765455331328"); + BigInteger int248Max = + new BigInteger("226156424291633194186662080095093570025917938800079226639565593765455331327"); BigInteger[] int248Array = {int248Min, int248Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt248Arr", new ContractFunctionParameters().addInt248Array(int248Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt248Arr", new ContractFunctionParameters().addInt248Array(int248Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int248[])").get(0); @@ -2578,11 +3152,15 @@ void canCallContractFunctionInt248Array() throws Exception { @Test @DisplayName("Can receive int256 min value from contract call") void canCallContractFunctionInt256Min() throws Exception { - BigInteger int256Min = new BigInteger("2").pow(256).divide(BigInteger.TWO).negate(); + BigInteger int256Min = + new BigInteger("2").pow(256).divide(BigInteger.TWO).negate(); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt256", new ContractFunctionParameters().addInt256(int256Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt256", new ContractFunctionParameters().addInt256(int256Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int256Min); } @@ -2590,11 +3168,15 @@ void canCallContractFunctionInt256Min() throws Exception { @Test @DisplayName("Can receive int256 max value from contract call") void canCallContractFunctionInt256Max() throws Exception { - BigInteger int256Max = new BigInteger("2").pow(256).subtract(BigInteger.ONE).divide(BigInteger.TWO); + BigInteger int256Max = + new BigInteger("2").pow(256).subtract(BigInteger.ONE).divide(BigInteger.TWO); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt256", new ContractFunctionParameters().addInt256(int256Max)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt256", new ContractFunctionParameters().addInt256(int256Max)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int256Max); } @@ -2602,13 +3184,18 @@ void canCallContractFunctionInt256Max() throws Exception { @Test @DisplayName("Can receive int256 array value from contract call") void canCallContractFunctionInt256Array() throws Exception { - BigInteger int256Min = new BigInteger("2").pow(256).divide(BigInteger.TWO).negate(); - BigInteger int256Max = new BigInteger("2").pow(256).subtract(BigInteger.ONE).divide(BigInteger.TWO); + BigInteger int256Min = + new BigInteger("2").pow(256).divide(BigInteger.TWO).negate(); + BigInteger int256Max = + new BigInteger("2").pow(256).subtract(BigInteger.ONE).divide(BigInteger.TWO); BigInteger[] int256Array = {int256Min, int256Max}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt256Arr", new ContractFunctionParameters().addInt256Array(int256Array)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt256Arr", new ContractFunctionParameters().addInt256Array(int256Array)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (BigInteger[]) response.getResult("(int256[])").get(0); @@ -2618,9 +3205,12 @@ void canCallContractFunctionInt256Array() throws Exception { @Test @DisplayName("Can receive multiple int8 values from contract call") void canCallContractFunctionMultipleInt8() throws Exception { - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnInt8Multiple", new ContractFunctionParameters().addInt8(Byte.MIN_VALUE)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnInt8Multiple", new ContractFunctionParameters().addInt8(Byte.MIN_VALUE)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt8(0)).isEqualTo(Byte.MIN_VALUE); assertThat(response.getInt8(1)).isEqualTo((byte) -108); @@ -2631,9 +3221,12 @@ void canCallContractFunctionMultipleInt8() throws Exception { void canCallContractFunctionMultipleInt40() throws Exception { long int40 = 549755813885L; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnMultipleInt40", new ContractFunctionParameters().addInt40(int40)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnMultipleInt40", new ContractFunctionParameters().addInt40(int40)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt64(0)).isEqualTo(int40); assertThat(response.getInt64(1)).isEqualTo(int40 + 1); @@ -2642,11 +3235,15 @@ void canCallContractFunctionMultipleInt40() throws Exception { @Test @DisplayName("Can receive multiple int256 values from contract call") void canCallContractFunctionMultipleInt256() throws Exception { - BigInteger int256Min = new BigInteger("2").pow(256).divide(BigInteger.TWO).negate(); + BigInteger int256Min = + new BigInteger("2").pow(256).divide(BigInteger.TWO).negate(); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnMultipleInt256", new ContractFunctionParameters().addInt256(int256Min)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnMultipleInt256", new ContractFunctionParameters().addInt256(int256Min)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getInt256(0)).isEqualTo(int256Min); assertThat(response.getInt256(1)).isEqualTo(int256Min.add(BigInteger.ONE)); @@ -2658,9 +3255,12 @@ void canCallContractFunctionMultipleTypes() throws Exception { var uint32Max = "4294967295"; int uint32MaxInt = Integer.parseUnsignedInt(uint32Max); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnMultipleTypeParams", new ContractFunctionParameters().addUint32(uint32MaxInt)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnMultipleTypeParams", new ContractFunctionParameters().addUint32(uint32MaxInt)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(Integer.toUnsignedString(response.getUint32(0))).isEqualTo(uint32Max); assertThat(response.getUint64(1)).isEqualTo(Long.parseUnsignedLong(uint32Max) - 1); @@ -2672,9 +3272,12 @@ void canCallContractFunctionMultipleTypes() throws Exception { void canCallContractFunctionStringType() throws Exception { var testString = "test"; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnString", new ContractFunctionParameters().addString(testString)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnString", new ContractFunctionParameters().addString(testString)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getString(0)).isEqualTo(testString); } @@ -2682,11 +3285,14 @@ void canCallContractFunctionStringType() throws Exception { @Test @DisplayName("Can receive string array value from contract call") void canCallContractFunctionStringArrayType() throws Exception { - var testStringArray = new String[]{"Test1", "Test2"}; + var testStringArray = new String[] {"Test1", "Test2"}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnStringArr", new ContractFunctionParameters().addStringArray(testStringArray)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnStringArr", new ContractFunctionParameters().addStringArray(testStringArray)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getStringArray(0).get(0)).isEqualTo(testStringArray[0]); assertThat(response.getStringArray(0).get(1)).isEqualTo(testStringArray[1]); @@ -2695,11 +3301,14 @@ void canCallContractFunctionStringArrayType() throws Exception { @Test @DisplayName("Can receive string array value from contract call with getResult function") void canCallContractFunctionStringArrayType_getResult() throws Exception { - var testStringArray = new String[]{"Test1", "Test2"}; + var testStringArray = new String[] {"Test1", "Test2"}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnStringArr", new ContractFunctionParameters().addStringArray(testStringArray)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnStringArr", new ContractFunctionParameters().addStringArray(testStringArray)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (String[]) response.getResult("(string[])").get(0); assertThat(responseResult).isEqualTo(testStringArray); @@ -2710,9 +3319,12 @@ void canCallContractFunctionStringArrayType_getResult() throws Exception { void canCallContractFunctionAddressType() throws Exception { var testAddress = "1234567890123456789012345678901234567890"; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnAddress", new ContractFunctionParameters().addAddress(testAddress)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnAddress", new ContractFunctionParameters().addAddress(testAddress)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getAddress(0)).isEqualTo(testAddress); } @@ -2720,17 +3332,22 @@ void canCallContractFunctionAddressType() throws Exception { @Test @DisplayName("Can receive address array value from contract call") void canCallContractFunctionAddressArrayType() throws Exception { - var testAddressArray = new String[]{"1234567890123456789012345678901234567890", - "1234567890123456789012345678901234567891"}; + var testAddressArray = + new String[] {"1234567890123456789012345678901234567890", "1234567890123456789012345678901234567891"}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnAddressArr", new ContractFunctionParameters().addAddressArray(testAddressArray)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnAddressArr", new ContractFunctionParameters().addAddressArray(testAddressArray)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (Address[]) response.getResult("(address[])").get(0); - Address[] testAddressArray_Address = Arrays.stream(testAddressArray).map(addressStr -> "0x" + addressStr) - .map(Address::wrap).toArray(Address[]::new); + Address[] testAddressArray_Address = Arrays.stream(testAddressArray) + .map(addressStr -> "0x" + addressStr) + .map(Address::wrap) + .toArray(Address[]::new); assertThat(responseResult).isEqualTo(testAddressArray_Address); } @@ -2740,9 +3357,12 @@ void canCallContractFunctionAddressArrayType() throws Exception { void canCallContractFunctionBooleanType() throws Exception { var testBoolean = true; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnBoolean", new ContractFunctionParameters().addBool(testBoolean)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnBoolean", new ContractFunctionParameters().addBool(testBoolean)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getBool(0)).isEqualTo(testBoolean); } @@ -2750,11 +3370,14 @@ void canCallContractFunctionBooleanType() throws Exception { @Test @DisplayName("Can receive boolean array value from contract call") void canCallContractFunctionBooleanArrayType() throws Exception { - var testBooleanArray = new boolean[]{true, false}; + var testBooleanArray = new boolean[] {true, false}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnBooleanArr", new ContractFunctionParameters().addBoolArray(testBooleanArray)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnBooleanArr", new ContractFunctionParameters().addBoolArray(testBooleanArray)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (boolean[]) response.getResult("(bool[])").get(0); @@ -2766,9 +3389,12 @@ void canCallContractFunctionBooleanArrayType() throws Exception { void canCallContractFunctionBytesType() throws Exception { var testBytes = "Test".getBytes(); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnBytes", new ContractFunctionParameters().addBytes(testBytes)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnBytes", new ContractFunctionParameters().addBytes(testBytes)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getBytes(0)).isEqualTo(testBytes); } @@ -2776,11 +3402,14 @@ void canCallContractFunctionBytesType() throws Exception { @Test @DisplayName("Can receive bytes array value from contract call") void canCallContractFunctionBytesArrayType() throws Exception { - byte[][] testBytes = new byte[][]{"Test1".getBytes(), "Test2".getBytes()}; + byte[][] testBytes = new byte[][] {"Test1".getBytes(), "Test2".getBytes()}; - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnBytesArr", new ContractFunctionParameters().addBytesArray(testBytes)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnBytesArr", new ContractFunctionParameters().addBytesArray(testBytes)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (byte[][]) response.getResult("(bytes[])").get(0); @@ -2794,9 +3423,12 @@ void canCallContractFunctionBytes32Type() throws Exception { byte[] testBytesLen32 = new byte[32]; System.arraycopy(testBytes, 0, testBytesLen32, 0, testBytes.length); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnBytes32", new ContractFunctionParameters().addBytes32(testBytesLen32)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnBytes32", new ContractFunctionParameters().addBytes32(testBytesLen32)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); assertThat(response.getBytes32(0)).isEqualTo(testBytesLen32); } @@ -2810,9 +3442,12 @@ void canCallContractFunctionBytes32ArrayType() throws Exception { System.arraycopy(testBytes, 0, testBytesLen32[0], 0, testBytes.length); System.arraycopy(testBytes2, 0, testBytesLen32[1], 0, testBytes2.length); - var response = new ContractCallQuery().setContractId(contractId).setGas(1500000) - .setFunction("returnBytes32Arr", new ContractFunctionParameters().addBytes32Array(testBytesLen32)) - .setQueryPayment(new Hbar(10)).execute(testEnv.client); + var response = new ContractCallQuery() + .setContractId(contractId) + .setGas(1500000) + .setFunction("returnBytes32Arr", new ContractFunctionParameters().addBytes32Array(testBytesLen32)) + .setQueryPayment(new Hbar(10)) + .execute(testEnv.client); var responseResult = (byte[][]) response.getResult("(bytes32[])").get(0); diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractInfoIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractInfoIntegrationTest.java index 08435ce46..0d80ee231 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractInfoIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractInfoIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +12,20 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.*; + import com.hedera.hashgraph.sdk.*; +import java.util.Objects; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.*; - public class ContractInfoIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; + private static final String SMART_CONTRACT_BYTECODE = + "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; @Test @DisplayName("Can query contract info") @@ -36,48 +33,47 @@ void canQueryContractInfo() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") + .execute(testEnv.client); var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); assertThat(contractId.hashCode()).isGreaterThan(0); - assertThat(contractId.compareTo(ContractId.fromBytes(contractId.toBytes()))).isZero(); + assertThat(contractId.compareTo(ContractId.fromBytes(contractId.toBytes()))) + .isZero(); - var info = new ContractInfoQuery() - .setContractId(contractId) - .execute(testEnv.client); + 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(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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -87,24 +83,22 @@ void canQueryContractInfoWhenAdminKeyIsNull() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .setKeys(testEnv.operatorKey) + .setContents(SMART_CONTRACT_BYTECODE) + .execute(testEnv.client); var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); response = new ContractCreateTransaction() - .setGas(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setGas(200000) + .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); + var info = new ContractInfoQuery().setContractId(contractId).execute(testEnv.client); assertThat(info.contractId).isEqualTo(contractId); assertThat(info.accountId).isNotNull(); @@ -114,7 +108,6 @@ void canQueryContractInfoWhenAdminKeyIsNull() throws Exception { // assertEquals(info.adminKey, contractId); assertThat(info.storage).isEqualTo(128); assertThat(info.contractMemo).isEqualTo("[e2e::ContractCreateTransaction]"); - } } @@ -123,11 +116,11 @@ void canQueryContractInfoWhenAdminKeyIsNull() throws Exception { void cannotQueryContractInfoWhenContractIDIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new ContractInfoQuery() - .execute(testEnv.client); - }).withMessageContaining(Status.INVALID_CONTRACT_ID.toString()); - + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new ContractInfoQuery().execute(testEnv.client); + }) + .withMessageContaining(Status.INVALID_CONTRACT_ID.toString()); } } @@ -138,42 +131,38 @@ void getCostBigMaxContractInfoFunction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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 infoQuery = new ContractInfoQuery().setContractId(contractId).setMaxQueryPayment(new Hbar(10000)); var cost = infoQuery.getCost(testEnv.client); - var result = infoQuery - .execute(testEnv.client); + var result = infoQuery.execute(testEnv.client); new ContractDeleteTransaction() - .setTransferAccountId(testEnv.operatorId) - .setContractId(contractId) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -183,41 +172,38 @@ void getCostSmallMaxContractInfoFunction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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(Hbar.fromTinybars(1)); + var infoQuery = new ContractInfoQuery().setContractId(contractId).setMaxQueryPayment(Hbar.fromTinybars(1)); assertThatExceptionOfType(MaxQueryPaymentExceededException.class).isThrownBy(() -> { infoQuery.execute(testEnv.client); }); new ContractDeleteTransaction() - .setTransferAccountId(testEnv.operatorId) - .setContractId(contractId) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -227,41 +213,40 @@ void getCostInsufficientTxFeeContractInfoFunction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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(100)); + var infoQuery = new ContractInfoQuery().setContractId(contractId).setMaxQueryPayment(new Hbar(100)); - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - infoQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client); - }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE")); + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + infoQuery.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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractNonceInfoIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractNonceInfoIntegrationTest.java index 5a2b7c236..d110d2bd2 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractNonceInfoIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractNonceInfoIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2023 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2023-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +29,8 @@ import org.junit.jupiter.api.Test; public class ContractNonceInfoIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "6080604052348015600f57600080fd5b50604051601a90603b565b604051809103906000f0801580156035573d6000803e3d6000fd5b50506047565b605c8061009483390190565b603f806100556000396000f3fe6080604052600080fdfea2646970667358221220a20122cbad3457fedcc0600363d6e895f17048f5caa4afdab9e655123737567d64736f6c634300081200336080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea264697066735822122053dfd8835e3dc6fedfb8b4806460b9b7163f8a7248bac510c6d6808d9da9d6d364736f6c63430008120033"; + private static final String SMART_CONTRACT_BYTECODE = + "6080604052348015600f57600080fd5b50604051601a90603b565b604051809103906000f0801580156035573d6000803e3d6000fd5b50506047565b605c8061009483390190565b603f806100556000396000f3fe6080604052600080fdfea2646970667358221220a20122cbad3457fedcc0600363d6e895f17048f5caa4afdab9e655123737567d64736f6c634300081200336080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea264697066735822122053dfd8835e3dc6fedfb8b4806460b9b7163f8a7248bac510c6d6808d9da9d6d364736f6c63430008120033"; @Test @DisplayName("Contract Create of A nonce, which deploys contract B in CONSTRUCTOR") @@ -40,29 +38,36 @@ void canIncrementNonceThroughContractConstructor() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractADeploysContractBInConstructor]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(100000) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractADeploysContractBInConstructor]") + .execute(testEnv.client); var contractFunctionResult = response.getRecord(testEnv.client).contractFunctionResult; ContractId contractA = contractFunctionResult.contractId; ContractId contractB = contractFunctionResult.contractNonces.stream() - .filter(contractNonce -> !contractNonce.contractId.equals(contractA)).findFirst().get().contractId; + .filter(contractNonce -> !contractNonce.contractId.equals(contractA)) + .findFirst() + .get() + .contractId; ContractNonceInfo contractANonceInfo = contractFunctionResult.contractNonces.stream() - .filter(contractNonce -> contractNonce.contractId.equals(contractA)).findFirst().get(); + .filter(contractNonce -> contractNonce.contractId.equals(contractA)) + .findFirst() + .get(); ContractNonceInfo contractBNonceInfo = contractFunctionResult.contractNonces.stream() - .filter(contractNonce -> contractNonce.contractId.equals(contractB)).findFirst().get(); + .filter(contractNonce -> contractNonce.contractId.equals(contractB)) + .findFirst() + .get(); // A.nonce = 2 assertThat(contractANonceInfo.nonce).isEqualTo(2); @@ -74,16 +79,15 @@ void canIncrementNonceThroughContractConstructor() throws Exception { var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); new ContractDeleteTransaction() - .setTransferAccountId(testEnv.operatorId) - .setContractId(contractId) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractUpdateIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractUpdateIntegrationTest.java index 902a231db..784d153c1 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractUpdateIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ContractUpdateIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.ContractCreateTransaction; import com.hedera.hashgraph.sdk.ContractDeleteTransaction; import com.hedera.hashgraph.sdk.ContractFunctionParameters; @@ -29,16 +29,13 @@ import com.hedera.hashgraph.sdk.PrecheckStatusException; import com.hedera.hashgraph.sdk.ReceiptStatusException; import com.hedera.hashgraph.sdk.Status; +import java.util.Objects; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - class ContractUpdateIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; + private static final String SMART_CONTRACT_BYTECODE = + "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; @Test @DisplayName("Can update contract") @@ -46,63 +43,60 @@ void canUpdateContract() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) - .setBytecodeFileId(fileId) - .setContractMemo("[e2e::ContractCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setGas(200000) + .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); + 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(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); + .setContractId(contractId) + .setContractMemo("[e2e::ContractUpdateTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client); - info = new ContractInfoQuery() - .setContractId(contractId) - .execute(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(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); + .setTransferAccountId(testEnv.operatorId) + .setContractId(contractId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -111,13 +105,14 @@ void canUpdateContract() throws Exception { void cannotUpdateContractWhenContractIDIsNotSet() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new ContractUpdateTransaction() - .setContractMemo("[e2e::ContractUpdateTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_CONTRACT_ID.toString()); - + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new ContractUpdateTransaction() + .setContractMemo("[e2e::ContractUpdateTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_CONTRACT_ID.toString()); } } @@ -127,31 +122,30 @@ void cannotUpdateContractThatIsImmutable() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents(SMART_CONTRACT_BYTECODE) - .execute(testEnv.client); + .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(200000) - .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]") + var contractId = Objects.requireNonNull(new ContractCreateTransaction() + .setGas(200000) + .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) + .setBytecodeFileId(fileId) + .setContractMemo("[e2e::ContractCreateTransaction]") .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.MODIFYING_IMMUTABLE_CONTRACT.toString()); - + .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()); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/FileAppendIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/FileAppendIntegrationTest.java index 8a9c6d4b4..b432e4e8e 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/FileAppendIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/FileAppendIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,41 +12,38 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; + import com.hedera.hashgraph.sdk.FileAppendTransaction; import com.hedera.hashgraph.sdk.FileContentsQuery; import com.hedera.hashgraph.sdk.FileCreateTransaction; import com.hedera.hashgraph.sdk.FileDeleteTransaction; import com.hedera.hashgraph.sdk.FileInfoQuery; import com.hedera.hashgraph.sdk.KeyList; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import java.time.Duration; - import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; public class FileAppendIntegrationTest { @Test @DisplayName("Can append to file") void canAppendToFile() throws Exception { // There are potential bugs in FileAppendTransaction which require more than one node to trigger. - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents("[e2e::FileCreateTransaction]") - .execute(testEnv.client); + .setKeys(testEnv.operatorKey) + .setContents("[e2e::FileCreateTransaction]") + .execute(testEnv.client); var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); - var info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); @@ -59,14 +53,12 @@ void canAppendToFile() throws Exception { assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); new FileAppendTransaction() - .setFileId(fileId) - .setContents("[e2e::FileAppendTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setFileId(fileId) + .setContents("[e2e::FileAppendTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client); - info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(56); @@ -76,10 +68,9 @@ void canAppendToFile() throws Exception { assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -87,24 +78,22 @@ void canAppendToFile() throws Exception { @DisplayName("Can append large contents to file") void canAppendLargeContentsToFile() throws Exception { // There are potential bugs in FileAppendTransaction which require more than one node to trigger. - try(var testEnv = new IntegrationTestEnv(2)){ + try (var testEnv = new IntegrationTestEnv(2)) { // Skip if using local node. // Note: this check should be removed once the local node is supporting multiple nodes. testEnv.assumeNotLocalNode(); var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents("[e2e::FileCreateTransaction]") - .execute(testEnv.client); + .setKeys(testEnv.operatorKey) + .setContents("[e2e::FileCreateTransaction]") + .execute(testEnv.client); var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); Thread.sleep(5000); - var info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); @@ -114,20 +103,16 @@ void canAppendLargeContentsToFile() throws Exception { assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); new FileAppendTransaction() - .setFileId(fileId) - .setContents(Contents.BIG_CONTENTS) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setFileId(fileId) + .setContents(Contents.BIG_CONTENTS) + .execute(testEnv.client) + .getReceipt(testEnv.client); - var contents = new FileContentsQuery() - .setFileId(fileId) - .execute(testEnv.client); + var contents = new FileContentsQuery().setFileId(fileId).execute(testEnv.client); assertThat(contents.toStringUtf8()).isEqualTo("[e2e::FileCreateTransaction]" + Contents.BIG_CONTENTS); - info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(13522); @@ -137,10 +122,9 @@ void canAppendLargeContentsToFile() throws Exception { assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -148,24 +132,22 @@ void canAppendLargeContentsToFile() throws Exception { @DisplayName("Can append large contents to file despite TRANSACTION_EXPIRATION response codes") void canAppendLargeContentsToFileDespiteExpiration() throws Exception { // There are potential bugs in FileAppendTransaction which require more than one node to trigger. - try(var testEnv = new IntegrationTestEnv(2)){ + try (var testEnv = new IntegrationTestEnv(2)) { // Skip if using local node. // Note: this check should be removed once the local node is supporting multiple nodes. testEnv.assumeNotLocalNode(); var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents("[e2e::FileCreateTransaction]") - .execute(testEnv.client); + .setKeys(testEnv.operatorKey) + .setContents("[e2e::FileCreateTransaction]") + .execute(testEnv.client); var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); Thread.sleep(5000); - var info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); @@ -175,21 +157,17 @@ void canAppendLargeContentsToFileDespiteExpiration() throws Exception { assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); var appendTx = new FileAppendTransaction() - .setFileId(fileId) - .setContents(Contents.BIG_CONTENTS) - .setTransactionValidDuration(Duration.ofSeconds(25)) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setFileId(fileId) + .setContents(Contents.BIG_CONTENTS) + .setTransactionValidDuration(Duration.ofSeconds(25)) + .execute(testEnv.client) + .getReceipt(testEnv.client); - var contents = new FileContentsQuery() - .setFileId(fileId) - .execute(testEnv.client); + var contents = new FileContentsQuery().setFileId(fileId).execute(testEnv.client); assertThat(contents.toStringUtf8()).isEqualTo("[e2e::FileCreateTransaction]" + Contents.BIG_CONTENTS); - info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(13522); @@ -199,10 +177,9 @@ void canAppendLargeContentsToFileDespiteExpiration() throws Exception { assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/FileUpdateIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/FileUpdateIntegrationTest.java index f41a62f99..49e47c997 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/FileUpdateIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/FileUpdateIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.AccountId; import com.hedera.hashgraph.sdk.FileCreateTransaction; import com.hedera.hashgraph.sdk.FileDeleteTransaction; @@ -30,30 +30,24 @@ import com.hedera.hashgraph.sdk.PrivateKey; import com.hedera.hashgraph.sdk.ReceiptStatusException; import com.hedera.hashgraph.sdk.Status; +import java.util.Objects; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - public class FileUpdateIntegrationTest { @Test @DisplayName("Can update file") void canUpdateFile() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setKeys(testEnv.operatorKey) - .setContents("[e2e::FileCreateTransaction]") - .execute(testEnv.client); + .setKeys(testEnv.operatorKey) + .setContents("[e2e::FileCreateTransaction]") + .execute(testEnv.client); var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); - var info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); @@ -63,14 +57,12 @@ void canUpdateFile() throws Exception { assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); new FileUpdateTransaction() - .setFileId(fileId) - .setContents("[e2e::FileUpdateTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setFileId(fileId) + .setContents("[e2e::FileUpdateTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client); - info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); @@ -80,72 +72,73 @@ void canUpdateFile() throws Exception { assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); new FileDeleteTransaction() - .setFileId(fileId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setFileId(fileId) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @Test @DisplayName("Cannot update immutable file") void cannotUpdateImmutableFile() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { var response = new FileCreateTransaction() - .setContents("[e2e::FileCreateTransaction]") - .execute(testEnv.client); + .setContents("[e2e::FileCreateTransaction]") + .execute(testEnv.client); var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId); - var info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); assertThat(info.isDeleted).isFalse(); assertThat(info.keys).isNull(); - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new FileUpdateTransaction() - .setFileId(fileId) - .setContents("[e2e::FileUpdateTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.UNAUTHORIZED.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new FileUpdateTransaction() + .setFileId(fileId) + .setContents("[e2e::FileUpdateTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.UNAUTHORIZED.toString()); } } @Test @DisplayName("Cannot update file when file ID is not set") void cannotUpdateFileWhenFileIDIsNotSet() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new FileUpdateTransaction() - .setContents("[e2e::FileUpdateTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_FILE_ID.toString()); - + try (var testEnv = new IntegrationTestEnv(1)) { + + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new FileUpdateTransaction() + .setContents("[e2e::FileUpdateTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_FILE_ID.toString()); } } @Test @DisplayName("Can update fee schedule file") void canUpdateFeeScheduleFile() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ - testEnv.client.setOperator(new AccountId(0, 0, 2), PrivateKey.fromString( - "302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137")); + try (var testEnv = new IntegrationTestEnv(1)) { + testEnv.client.setOperator( + new AccountId(0, 0, 2), + PrivateKey.fromString( + "302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137")); var fileId = new FileId(0, 0, 111); var receipt = new FileUpdateTransaction() - .setFileId(fileId) - .setContents("[e2e::FileUpdateTransaction]") - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setFileId(fileId) + .setContents("[e2e::FileUpdateTransaction]") + .execute(testEnv.client) + .getReceipt(testEnv.client); assertThat(receipt.status).isEqualTo(Status.FEE_SCHEDULE_FILE_PART_UPLOADED); } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java index 359d24b99..f49b42f03 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/IntegrationTestEnv.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; import static org.assertj.core.api.Assertions.assertThat; @@ -28,7 +25,6 @@ import com.hedera.hashgraph.sdk.Hbar; import com.hedera.hashgraph.sdk.PrivateKey; import com.hedera.hashgraph.sdk.PublicKey; -import com.hedera.hashgraph.sdk.TokenId; import com.hedera.hashgraph.sdk.TransferTransaction; import java.util.ArrayList; import java.util.Collections; @@ -36,7 +32,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import javax.annotation.Nullable; import org.junit.jupiter.api.Assumptions; public class IntegrationTestEnv implements AutoCloseable { @@ -103,9 +98,7 @@ private static Client createTestEnvClient() throws Exception { var network = new HashMap(); network.put(LOCAL_CONSENSUS_NODE_ENDPOINT, LOCAL_CONSENSUS_NODE_ACCOUNT_ID); - return Client - .forNetwork(network) - .setMirrorNetwork(List.of(LOCAL_MIRROR_NODE_GRPC_ENDPOINT)); + return Client.forNetwork(network).setMirrorNetwork(List.of(LOCAL_MIRROR_NODE_GRPC_ENDPOINT)); } else if (!System.getProperty("CONFIG_FILE").equals("")) { try { return Client.fromConfigFile(System.getProperty("CONFIG_FILE")); @@ -120,11 +113,11 @@ public IntegrationTestEnv useThrowawayAccount(Hbar initialBalance) throws Except var key = PrivateKey.generateED25519(); operatorKey = key.getPublicKey(); operatorId = new AccountCreateTransaction() - .setInitialBalance(initialBalance) - .setKey(key) - .execute(client) - .getReceipt(client) - .accountId; + .setInitialBalance(initialBalance) + .setKey(key) + .execute(client) + .getReceipt(client) + .accountId; client = Client.forNetwork(originalClient.getNetwork()); client.setMirrorNetwork(originalClient.getMirrorNetwork()); @@ -152,16 +145,14 @@ public void assumeNotLocalNode() throws Exception { @Override public void close() throws Exception { if (!operatorId.equals(originalClient.getOperatorAccountId())) { - var hbarsBalance = new AccountBalanceQuery() - .setAccountId(operatorId) - .execute(originalClient) - .hbars; + var hbarsBalance = + new AccountBalanceQuery().setAccountId(operatorId).execute(originalClient).hbars; new TransferTransaction() - .addHbarTransfer(operatorId, hbarsBalance.negated()) - .addHbarTransfer(Objects.requireNonNull(originalClient.getOperatorAccountId()), hbarsBalance) - .freezeWith(originalClient) - .signWithOperator(client) - .execute(originalClient); + .addHbarTransfer(operatorId, hbarsBalance.negated()) + .addHbarTransfer(Objects.requireNonNull(originalClient.getOperatorAccountId()), hbarsBalance) + .freezeWith(originalClient) + .signWithOperator(client) + .execute(originalClient); client.close(); } @@ -182,18 +173,20 @@ public TestEnvNodeGetter(Client client) { public void nextNode(Map outMap) throws Exception { if (nodes.isEmpty()) { throw new IllegalStateException( - "IntegrationTestEnv needs another node, but there aren't enough nodes in client network"); + "IntegrationTestEnv needs another node, but there aren't enough nodes in client network"); } for (; index < nodes.size(); index++) { var node = nodes.get(index); try { new TransferTransaction() - .setNodeAccountIds(Collections.singletonList(node.getValue())) - .setMaxAttempts(1) - .addHbarTransfer(client.getOperatorAccountId(), Hbar.fromTinybars(1).negated()) - .addHbarTransfer(AccountId.fromString("0.0.3"), Hbar.fromTinybars(1)) - .execute(client) - .getReceipt(client); + .setNodeAccountIds(Collections.singletonList(node.getValue())) + .setMaxAttempts(1) + .addHbarTransfer( + client.getOperatorAccountId(), + Hbar.fromTinybars(1).negated()) + .addHbarTransfer(AccountId.fromString("0.0.3"), Hbar.fromTinybars(1)) + .execute(client) + .getReceipt(client); nodes.remove(index); outMap.put(node.getKey(), node.getValue()); return; diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ScheduleCreateIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ScheduleCreateIntegrationTest.java index c871400ba..9fae7b1d1 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ScheduleCreateIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/ScheduleCreateIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2021 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2021-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.AccountBalanceQuery; import com.hedera.hashgraph.sdk.AccountCreateTransaction; import com.hedera.hashgraph.sdk.AccountDeleteTransaction; @@ -40,17 +40,13 @@ import com.hedera.hashgraph.sdk.TransactionReceipt; import com.hedera.hashgraph.sdk.TransactionResponse; import com.hedera.hashgraph.sdk.TransferTransaction; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import java.time.Instant; - import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.Collections; import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; public class ScheduleCreateIntegrationTest { @Test @@ -61,24 +57,19 @@ void canCreateSchedule() throws Exception { var key = PrivateKey.generateED25519(); - var transaction = new AccountCreateTransaction() - .setKey(key) - .setInitialBalance(new Hbar(10)); + var transaction = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10)); var response = new ScheduleCreateTransaction() - .setScheduledTransaction(transaction) - .setAdminKey(testEnv.operatorKey) - .setPayerAccountId(testEnv.operatorId) - .execute(testEnv.client); + .setScheduledTransaction(transaction) + .setAdminKey(testEnv.operatorKey) + .setPayerAccountId(testEnv.operatorId) + .execute(testEnv.client); var scheduleId = Objects.requireNonNull(response.getReceipt(testEnv.client).scheduleId); - var info = new ScheduleInfoQuery() - .setScheduleId(scheduleId) - .execute(testEnv.client); + var info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client); assertThat(info.executedAt).isNotNull(); - } } @@ -90,25 +81,20 @@ void canGetTransactionSchedule() throws Exception { var key = PrivateKey.generateED25519(); - var transaction = new AccountCreateTransaction() - .setKey(key) - .setInitialBalance(new Hbar(10)); + var transaction = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10)); var response = new ScheduleCreateTransaction() - .setScheduledTransaction(transaction) - .setAdminKey(testEnv.operatorKey) - .setPayerAccountId(testEnv.operatorId) - .execute(testEnv.client); + .setScheduledTransaction(transaction) + .setAdminKey(testEnv.operatorKey) + .setPayerAccountId(testEnv.operatorId) + .execute(testEnv.client); var scheduleId = Objects.requireNonNull(response.getReceipt(testEnv.client).scheduleId); - var info = new ScheduleInfoQuery() - .setScheduleId(scheduleId) - .execute(testEnv.client); + var info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client); assertThat(info.executedAt).isNotNull(); assertThat(info.getScheduledTransaction()).isNotNull(); - } } @@ -120,26 +106,20 @@ void canCreateWithSchedule() throws Exception { var key = PrivateKey.generateED25519(); - var transaction = new AccountCreateTransaction() - .setKey(key) - .setInitialBalance(new Hbar(10)); + var transaction = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(10)); var tx = transaction.schedule(); - var response = tx - .setAdminKey(testEnv.operatorKey) - .setPayerAccountId(testEnv.operatorId) - .execute(testEnv.client); + var response = tx.setAdminKey(testEnv.operatorKey) + .setPayerAccountId(testEnv.operatorId) + .execute(testEnv.client); var scheduleId = Objects.requireNonNull(response.getReceipt(testEnv.client).scheduleId); - var info = new ScheduleInfoQuery() - .setScheduleId(scheduleId) - .execute(testEnv.client); + var info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client); assertThat(info.executedAt).isNotNull(); assertThat(info.getScheduledTransaction()).isNotNull(); - } } @@ -160,9 +140,9 @@ void canSignSchedule2() throws Exception { // Creat the account with the `KeyList` TransactionResponse response = new AccountCreateTransaction() - .setKey(keyList) - .setInitialBalance(new Hbar(10)) - .execute(testEnv.client); + .setKey(keyList) + .setInitialBalance(new Hbar(10)) + .execute(testEnv.client); // This will wait for the receipt to become available TransactionReceipt receipt = response.getReceipt(testEnv.client); @@ -175,9 +155,9 @@ void canSignSchedule2() throws Exception { // Create a transfer transaction with 2/3 signatures. TransferTransaction transfer = new TransferTransaction() - .setTransactionId(transactionId) - .addHbarTransfer(accountId, new Hbar(1).negated()) - .addHbarTransfer(testEnv.operatorId, new Hbar(1)); + .setTransactionId(transactionId) + .addHbarTransfer(accountId, new Hbar(1).negated()) + .addHbarTransfer(testEnv.operatorId, new Hbar(1)); // Schedule the transactoin ScheduleCreateTransaction scheduled = transfer.schedule(); @@ -188,137 +168,132 @@ void canSignSchedule2() throws Exception { ScheduleId scheduleId = Objects.requireNonNull(receipt.scheduleId); // Get the schedule info to see if `signatories` is populated with 2/3 signatures - ScheduleInfo info = new ScheduleInfoQuery() - .setScheduleId(scheduleId) - .execute(testEnv.client); + ScheduleInfo info = + new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client); assertThat(info.executedAt).isNull(); // Finally send this last signature to Hedera. This last signature _should_ mean the transaction executes // since all 3 signatures have been provided. - ScheduleSignTransaction signTransaction = new ScheduleSignTransaction() - .setScheduleId(scheduleId) - .freezeWith(testEnv.client); + ScheduleSignTransaction signTransaction = + new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(testEnv.client); - signTransaction.sign(key1).sign(key2).sign(key3).execute(testEnv.client).getReceipt(testEnv.client); + signTransaction + .sign(key1) + .sign(key2) + .sign(key3) + .execute(testEnv.client) + .getReceipt(testEnv.client); - info = new ScheduleInfoQuery() - .setScheduleId(scheduleId) - .execute(testEnv.client); + info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client); assertThat(info.executedAt).isNotNull(); assertThat(scheduleId.getChecksum()).isNull(); assertThat(scheduleId.hashCode()).isNotZero(); - assertThat(scheduleId.compareTo(ScheduleId.fromBytes(scheduleId.toBytes()))).isZero(); + assertThat(scheduleId.compareTo(ScheduleId.fromBytes(scheduleId.toBytes()))) + .isZero(); new AccountDeleteTransaction() - .setAccountId(accountId) - .setTransferAccountId(testEnv.operatorId) - .freezeWith(testEnv.client) - .sign(key1).sign(key2).sign(key3) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setAccountId(accountId) + .setTransferAccountId(testEnv.operatorId) + .freezeWith(testEnv.client) + .sign(key1) + .sign(key2) + .sign(key3) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @Test @DisplayName("Can schedule token transfer") void canScheduleTokenTransfer() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { PrivateKey key = PrivateKey.generateED25519(); var accountId = new AccountCreateTransaction() - .setReceiverSignatureRequired(true) - .setKey(key) - .setInitialBalance(new Hbar(10)) - .freezeWith(testEnv.client) - .sign(key) - .execute(testEnv.client) - .getReceipt(testEnv.client) - .accountId; + .setReceiverSignatureRequired(true) + .setKey(key) + .setInitialBalance(new Hbar(10)) + .freezeWith(testEnv.client) + .sign(key) + .execute(testEnv.client) + .getReceipt(testEnv.client) + .accountId; Objects.requireNonNull(accountId); var tokenId = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setInitialSupply(100) - .setTreasuryAccountId(testEnv.operatorId) - .setAdminKey(testEnv.operatorKey) - .execute(testEnv.client) - .getReceipt(testEnv.client) - .tokenId; + .setTokenName("ffff") + .setTokenSymbol("F") + .setInitialSupply(100) + .setTreasuryAccountId(testEnv.operatorId) + .setAdminKey(testEnv.operatorKey) + .execute(testEnv.client) + .getReceipt(testEnv.client) + .tokenId; Objects.requireNonNull(tokenId); new TokenAssociateTransaction() - .setAccountId(accountId) - .setTokenIds(Collections.singletonList(tokenId)) - .freezeWith(testEnv.client) - .sign(key) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId) + .setTokenIds(Collections.singletonList(tokenId)) + .freezeWith(testEnv.client) + .sign(key) + .execute(testEnv.client) + .getReceipt(testEnv.client); var scheduleId = new TransferTransaction() - .addTokenTransfer(tokenId, testEnv.operatorId, -10) - .addTokenTransfer(tokenId, accountId, 10) - .schedule() - .execute(testEnv.client) - .getReceipt(testEnv.client) - .scheduleId; + .addTokenTransfer(tokenId, testEnv.operatorId, -10) + .addTokenTransfer(tokenId, accountId, 10) + .schedule() + .execute(testEnv.client) + .getReceipt(testEnv.client) + .scheduleId; Objects.requireNonNull(scheduleId); - var balanceQuery1 = new AccountBalanceQuery() - .setAccountId(accountId) - .execute(testEnv.client); + var balanceQuery1 = + new AccountBalanceQuery().setAccountId(accountId).execute(testEnv.client); assertThat(balanceQuery1.tokens.get(tokenId)).isEqualTo(0); new ScheduleSignTransaction() - .setScheduleId(scheduleId) - .freezeWith(testEnv.client) - .sign(key) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setScheduleId(scheduleId) + .freezeWith(testEnv.client) + .sign(key) + .execute(testEnv.client) + .getReceipt(testEnv.client); - var balanceQuery2 = new AccountBalanceQuery() - .setAccountId(accountId) - .execute(testEnv.client); + var balanceQuery2 = + new AccountBalanceQuery().setAccountId(accountId).execute(testEnv.client); assertThat(balanceQuery2.tokens.get(tokenId)).isEqualTo(10); - } } @Test @DisplayName("Cannot schedule two identical transactions") void cannotScheduleTwoTransactions() throws Exception { - try(var testEnv = new IntegrationTestEnv(1)){ + try (var testEnv = new IntegrationTestEnv(1)) { var key = PrivateKey.generateED25519(); var accountId = new AccountCreateTransaction() - .setInitialBalance(new Hbar(10)) - .setKey(key) - .execute(testEnv.client) - .getReceipt(testEnv.client) - .accountId; + .setInitialBalance(new Hbar(10)) + .setKey(key) + .execute(testEnv.client) + .getReceipt(testEnv.client) + .accountId; var transferTx = new TransferTransaction() - .addHbarTransfer(testEnv.operatorId, new Hbar(-10)) - .addHbarTransfer(accountId, new Hbar(10)); + .addHbarTransfer(testEnv.operatorId, new Hbar(-10)) + .addHbarTransfer(accountId, new Hbar(10)); - var scheduleId1 = transferTx.schedule() - .execute(testEnv.client) - .getReceipt(testEnv.client) - .scheduleId; + var scheduleId1 = transferTx.schedule().execute(testEnv.client).getReceipt(testEnv.client).scheduleId; - var info1 = new ScheduleInfoQuery() - .setScheduleId(scheduleId1) - .execute(testEnv.client); + var info1 = new ScheduleInfoQuery().setScheduleId(scheduleId1).execute(testEnv.client); assertThat(info1.executedAt).isNotNull(); @@ -329,12 +304,11 @@ void cannotScheduleTwoTransactions() throws Exception { assertThat(scheduleCreateTx2.toString()).isEqualTo(scheduleCreateTx1.toString()); - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - transferTxFromInfo.schedule() - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining("IDENTICAL_SCHEDULE_ALREADY_CREATED"); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + transferTxFromInfo.schedule().execute(testEnv.client).getReceipt(testEnv.client); + }) + .withMessageContaining("IDENTICAL_SCHEDULE_ALREADY_CREATED"); } } @@ -365,35 +339,32 @@ void canScheduleTopicMessage() throws Exception { assertThat(response.getReceipt(testEnv.client).accountId).isNotNull(); var topicId = Objects.requireNonNull(new TopicCreateTransaction() - .setAdminKey(testEnv.operatorKey) - .setAutoRenewAccountId(testEnv.operatorId) - .setTopicMemo("HCS Topic_") - .setSubmitKey(key2.getPublicKey()) - .execute(testEnv.client) - .getReceipt(testEnv.client) - .topicId - ); + .setAdminKey(testEnv.operatorKey) + .setAutoRenewAccountId(testEnv.operatorId) + .setTopicMemo("HCS Topic_") + .setSubmitKey(key2.getPublicKey()) + .execute(testEnv.client) + .getReceipt(testEnv.client) + .topicId); var transaction = new TopicMessageSubmitTransaction() - .setTopicId(topicId) - .setMessage("scheduled hcs message".getBytes(StandardCharsets.UTF_8)); + .setTopicId(topicId) + .setMessage("scheduled hcs message".getBytes(StandardCharsets.UTF_8)); // create schedule - var scheduledTx = transaction.schedule() - .setAdminKey(testEnv.operatorKey) - .setPayerAccountId(testEnv.operatorId) - .setScheduleMemo("mirror scheduled E2E signature on create and sign_" + Instant.now()); + var scheduledTx = transaction + .schedule() + .setAdminKey(testEnv.operatorKey) + .setPayerAccountId(testEnv.operatorId) + .setScheduleMemo("mirror scheduled E2E signature on create and sign_" + Instant.now()); var scheduled = scheduledTx.freezeWith(testEnv.client); - var scheduleId = Objects.requireNonNull(scheduled - .execute(testEnv.client) - .getReceipt(testEnv.client).scheduleId); + var scheduleId = + Objects.requireNonNull(scheduled.execute(testEnv.client).getReceipt(testEnv.client).scheduleId); // verify schedule has been created and has 1 of 2 signatures - var info = new ScheduleInfoQuery() - .setScheduleId(scheduleId) - .execute(testEnv.client); + var info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client); assertThat(info).isNotNull(); assertThat(info.scheduleId).isEqualTo(scheduleId); @@ -403,21 +374,14 @@ void canScheduleTopicMessage() throws Exception { assertThat(transaction.getTopicId()).isEqualTo(infoTransaction.getTopicId()); assertThat(transaction.getNodeAccountIds()).isEqualTo(infoTransaction.getNodeAccountIds()); - var scheduleSign = new ScheduleSignTransaction() - .setScheduleId(scheduleId) - .freezeWith(testEnv.client); + var scheduleSign = + new ScheduleSignTransaction().setScheduleId(scheduleId).freezeWith(testEnv.client); - scheduleSign - .sign(key2) - .execute(testEnv.client) - .getReceipt(testEnv.client); + scheduleSign.sign(key2).execute(testEnv.client).getReceipt(testEnv.client); - info = new ScheduleInfoQuery() - .setScheduleId(scheduleId) - .execute(testEnv.client); + info = new ScheduleInfoQuery().setScheduleId(scheduleId).execute(testEnv.client); assertThat(info.executedAt).isNotNull(); - } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/SystemIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/SystemIntegrationTest.java index f94f4a675..49c5683e3 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/SystemIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/SystemIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.ContractCreateTransaction; import com.hedera.hashgraph.sdk.ContractFunctionParameters; import com.hedera.hashgraph.sdk.FileCreateTransaction; @@ -26,31 +25,27 @@ import com.hedera.hashgraph.sdk.Status; import com.hedera.hashgraph.sdk.SystemDeleteTransaction; import com.hedera.hashgraph.sdk.SystemUndeleteTransaction; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import java.time.Instant; - import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; public class SystemIntegrationTest { - private static final String SMART_CONTRACT_BYTECODE = "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; + private static final String SMART_CONTRACT_BYTECODE = + "608060405234801561001057600080fd5b506040516104d73803806104d78339818101604052602081101561003357600080fd5b810190808051604051939291908464010000000082111561005357600080fd5b90830190602082018581111561006857600080fd5b825164010000000081118282018810171561008257600080fd5b82525081516020918201929091019080838360005b838110156100af578181015183820152602001610097565b50505050905090810190601f1680156100dc5780820380516001836020036101000a031916815260200191505b506040525050600080546001600160a01b0319163317905550805161010890600190602084019061010f565b50506101aa565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017d565b8280016001018555821561017d579182015b8281111561017d578251825591602001919060010190610162565b5061018992915061018d565b5090565b6101a791905b808211156101895760008155600101610193565b90565b61031e806101b96000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063368b87721461004657806341c0e1b5146100ee578063ce6d41de146100f6575b600080fd5b6100ec6004803603602081101561005c57600080fd5b81019060208101813564010000000081111561007757600080fd5b82018360208201111561008957600080fd5b803590602001918460018302840111640100000000831117156100ab57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610173945050505050565b005b6100ec6101a2565b6100fe6101ba565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610138578181015183820152602001610120565b50505050905090810190601f1680156101655780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000546001600160a01b0316331461018a5761019f565b805161019d906001906020840190610250565b505b50565b6000546001600160a01b03163314156101b85733ff5b565b60018054604080516020601f600260001961010087891615020190951694909404938401819004810282018101909252828152606093909290918301828280156102455780601f1061021a57610100808354040283529160200191610245565b820191906000526020600020905b81548152906001019060200180831161022857829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061029157805160ff19168380011785556102be565b828001600101855582156102be579182015b828111156102be5782518255916020019190600101906102a3565b506102ca9291506102ce565b5090565b61024d91905b808211156102ca57600081556001016102d456fea264697066735822122084964d4c3f6bc912a9d20e14e449721012d625aa3c8a12de41ae5519752fc89064736f6c63430006000033"; @Test @DisplayName("All system transactions are not supported") void allSystemTransactionsAreNotSupported() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { - var fileId = Objects.requireNonNull( - new FileCreateTransaction() + var fileId = Objects.requireNonNull(new FileCreateTransaction() .setContents(SMART_CONTRACT_BYTECODE) .execute(testEnv.client) .getReceipt(testEnv.client) .fileId); - var contractId = Objects.requireNonNull( - new ContractCreateTransaction() + var contractId = Objects.requireNonNull(new ContractCreateTransaction() .setAdminKey(testEnv.operatorKey) .setGas(200000) .setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")) @@ -58,35 +53,39 @@ void allSystemTransactionsAreNotSupported() throws Exception { .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()); + .contractId); - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new SystemDeleteTransaction() - .setFileId(fileId) - .setExpirationTime(Instant.now()) - .execute(testEnv.client); - }).withMessageContaining(Status.NOT_SUPPORTED.toString()); + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new SystemDeleteTransaction() + .setContractId(contractId) + .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 SystemDeleteTransaction() + .setFileId(fileId) + .setExpirationTime(Instant.now()) + .execute(testEnv.client); + }) + .withMessageContaining(Status.NOT_SUPPORTED.toString()); - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new SystemUndeleteTransaction() - .setFileId(fileId) - .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()); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenFeeScheduleUpdateIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenFeeScheduleUpdateIntegrationTest.java index fa544a949..fc246ec16 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenFeeScheduleUpdateIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenFeeScheduleUpdateIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2021 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2021-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.CustomFee; import com.hedera.hashgraph.sdk.CustomFixedFee; import com.hedera.hashgraph.sdk.CustomFractionalFee; @@ -28,42 +28,35 @@ import com.hedera.hashgraph.sdk.TokenCreateTransaction; import com.hedera.hashgraph.sdk.TokenFeeScheduleUpdateTransaction; import com.hedera.hashgraph.sdk.TokenInfoQuery; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import java.util.ArrayList; import java.util.Objects; - -import static org.assertj.core.api.Assertions.as; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class TokenFeeScheduleUpdateIntegrationTest { @Test @DisplayName("Can update token fees") void canUpdateToken() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { var response = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setDecimals(3) - .setInitialSupply(1000000) - .setTreasuryAccountId(testEnv.operatorId) - .setAdminKey(testEnv.operatorKey) - .setFreezeKey(testEnv.operatorKey) - .setWipeKey(testEnv.operatorKey) - .setKycKey(testEnv.operatorKey) - .setSupplyKey(testEnv.operatorKey) - .setFeeScheduleKey(testEnv.operatorKey) - .setFreezeDefault(false) - .execute(testEnv.client); + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(testEnv.operatorId) + .setAdminKey(testEnv.operatorKey) + .setFreezeKey(testEnv.operatorKey) + .setWipeKey(testEnv.operatorKey) + .setKycKey(testEnv.operatorKey) + .setSupplyKey(testEnv.operatorKey) + .setFeeScheduleKey(testEnv.operatorKey) + .setFreezeDefault(false) + .execute(testEnv.client); var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId); - var info = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var info = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(info.tokenId).isEqualTo(tokenId); assertThat(info.name).isEqualTo("ffff"); @@ -88,27 +81,21 @@ void canUpdateToken() throws Exception { assertThat(info.customFees.size()).isEqualTo(0); var customFees = new ArrayList(); - customFees.add(new CustomFixedFee() - .setAmount(10) - .setFeeCollectorAccountId(testEnv.operatorId) - ); + customFees.add(new CustomFixedFee().setAmount(10).setFeeCollectorAccountId(testEnv.operatorId)); customFees.add(new CustomFractionalFee() - .setNumerator(1) - .setDenominator(20) - .setMin(1) - .setMax(10) - .setFeeCollectorAccountId(testEnv.operatorId) - ); + .setNumerator(1) + .setDenominator(20) + .setMin(1) + .setMax(10) + .setFeeCollectorAccountId(testEnv.operatorId)); new TokenFeeScheduleUpdateTransaction() - .setTokenId(tokenId) - .setCustomFees(customFees) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setCustomFees(customFees) + .execute(testEnv.client) + .getReceipt(testEnv.client); - info = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + info = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(info.tokenId).isEqualTo(tokenId); assertThat(info.name).isEqualTo("ffff"); @@ -134,67 +121,63 @@ void canUpdateToken() throws Exception { var fees = info.customFees; assertThat(fees.size()).isEqualTo(2); int fixedCount = 0; - int fractionalCount = 0; - for (var fee : fees) { - if (fee instanceof CustomFixedFee) { - fixedCount++; - var fixed = (CustomFixedFee) fee; - assertThat(fixed.getAmount()).isEqualTo(10); - assertThat(fixed.getFeeCollectorAccountId()).isEqualTo(testEnv.operatorId); - assertThat(fixed.getDenominatingTokenId()).isNull(); - } else if (fee instanceof CustomFractionalFee) { - fractionalCount++; - var fractional = (CustomFractionalFee) fee; - assertThat(fractional.getNumerator()).isEqualTo(1); - assertThat(fractional.getDenominator()).isEqualTo(20); - assertThat(fractional.getMin()).isEqualTo(1); - assertThat(fractional.getMax()).isEqualTo(10); - assertThat(fractional.getFeeCollectorAccountId()).isEqualTo(testEnv.operatorId); + int fractionalCount = 0; + for (var fee : fees) { + if (fee instanceof CustomFixedFee) { + fixedCount++; + var fixed = (CustomFixedFee) fee; + assertThat(fixed.getAmount()).isEqualTo(10); + assertThat(fixed.getFeeCollectorAccountId()).isEqualTo(testEnv.operatorId); + assertThat(fixed.getDenominatingTokenId()).isNull(); + } else if (fee instanceof CustomFractionalFee) { + fractionalCount++; + var fractional = (CustomFractionalFee) fee; + assertThat(fractional.getNumerator()).isEqualTo(1); + assertThat(fractional.getDenominator()).isEqualTo(20); + assertThat(fractional.getMin()).isEqualTo(1); + assertThat(fractional.getMax()).isEqualTo(10); + assertThat(fractional.getFeeCollectorAccountId()).isEqualTo(testEnv.operatorId); + } } - } - assertThat(fixedCount).isEqualTo(1); - assertThat(fractionalCount).isEqualTo(1); - + assertThat(fixedCount).isEqualTo(1); + assertThat(fractionalCount).isEqualTo(1); } } @Test @DisplayName("Cannot update fee schedule with any key other than fee schedule key") void cannotUpdateWithAnyOtherKey() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { var response = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setTreasuryAccountId(testEnv.operatorId) - .setAdminKey(testEnv.operatorKey) - .setFeeScheduleKey(PrivateKey.generate()) - .setFreezeDefault(false) - .execute(testEnv.client); + .setTokenName("ffff") + .setTokenSymbol("F") + .setTreasuryAccountId(testEnv.operatorId) + .setAdminKey(testEnv.operatorKey) + .setFeeScheduleKey(PrivateKey.generate()) + .setFreezeDefault(false) + .execute(testEnv.client); var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId); var customFees = new ArrayList(); - customFees.add(new CustomFixedFee() - .setAmount(10) - .setFeeCollectorAccountId(testEnv.operatorId) - ); + customFees.add(new CustomFixedFee().setAmount(10).setFeeCollectorAccountId(testEnv.operatorId)); customFees.add(new CustomFractionalFee() - .setNumerator(1) - .setDenominator(20) - .setMin(1) - .setMax(10) - .setFeeCollectorAccountId(testEnv.operatorId) - ); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenFeeScheduleUpdateTransaction() - .setTokenId(tokenId) - .setCustomFees(customFees) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + .setNumerator(1) + .setDenominator(20) + .setMin(1) + .setMax(10) + .setFeeCollectorAccountId(testEnv.operatorId)); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenFeeScheduleUpdateTransaction() + .setTokenId(tokenId) + .setCustomFees(customFees) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenNftTransferIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenNftTransferIntegrationTest.java index 0d552b8fa..da797bf94 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenNftTransferIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenNftTransferIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2021 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2021-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.AccountCreateTransaction; import com.hedera.hashgraph.sdk.Hbar; import com.hedera.hashgraph.sdk.PrivateKey; @@ -32,67 +32,63 @@ import com.hedera.hashgraph.sdk.TokenWipeTransaction; import com.hedera.hashgraph.sdk.TransactionResponse; import com.hedera.hashgraph.sdk.TransferTransaction; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - import java.util.ArrayList; import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; class TokenNftTransferIntegrationTest { @Test @DisplayName("Can transfer NFTs") void canTransferNfts() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { var key = PrivateKey.generateED25519(); TransactionResponse response = new AccountCreateTransaction() - .setKey(key) - .setInitialBalance(new Hbar(1)) - .execute(testEnv.client); + .setKey(key) + .setInitialBalance(new Hbar(1)) + .execute(testEnv.client); var accountId = response.getReceipt(testEnv.client).accountId; assertThat(accountId).isNotNull(); response = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) - .setTreasuryAccountId(testEnv.operatorId) - .setAdminKey(testEnv.operatorKey) - .setFreezeKey(testEnv.operatorKey) - .setWipeKey(testEnv.operatorKey) - .setKycKey(testEnv.operatorKey) - .setSupplyKey(testEnv.operatorKey) - .setFreezeDefault(false) - .execute(testEnv.client); + .setTokenName("ffff") + .setTokenSymbol("F") + .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) + .setTreasuryAccountId(testEnv.operatorId) + .setAdminKey(testEnv.operatorKey) + .setFreezeKey(testEnv.operatorKey) + .setWipeKey(testEnv.operatorKey) + .setKycKey(testEnv.operatorKey) + .setSupplyKey(testEnv.operatorKey) + .setFreezeDefault(false) + .execute(testEnv.client); var tokenId = response.getReceipt(testEnv.client).tokenId; assertThat(tokenId).isNotNull(); var mintReceipt = new TokenMintTransaction() - .setTokenId(tokenId) - .setMetadata(NftMetadataGenerator.generate((byte) 10)) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setMetadata(NftMetadataGenerator.generate((byte) 10)) + .execute(testEnv.client) + .getReceipt(testEnv.client); new TokenAssociateTransaction() - .setAccountId(accountId) - .setTokenIds(Collections.singletonList(tokenId)) - .freezeWith(testEnv.client) - .signWithOperator(testEnv.client) - .sign(key) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId) + .setTokenIds(Collections.singletonList(tokenId)) + .freezeWith(testEnv.client) + .signWithOperator(testEnv.client) + .sign(key) + .execute(testEnv.client) + .getReceipt(testEnv.client); new TokenGrantKycTransaction() - .setAccountId(accountId) - .setTokenId(tokenId) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId) + .setTokenId(tokenId) + .execute(testEnv.client) + .getReceipt(testEnv.client); var serialsToTransfer = new ArrayList(mintReceipt.serials.subList(0, 4)); var transfer = new TransferTransaction(); @@ -102,59 +98,58 @@ void canTransferNfts() throws Exception { transfer.execute(testEnv.client).getReceipt(testEnv.client); new TokenWipeTransaction() - .setTokenId(tokenId) - .setAccountId(accountId) - .setSerials(serialsToTransfer) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .setTokenId(tokenId) + .setAccountId(accountId) + .setSerials(serialsToTransfer) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @Test @DisplayName("Cannot transfer NFTs you don't own") void cannotTransferUnownedNfts() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { var key = PrivateKey.generateED25519(); TransactionResponse response = new AccountCreateTransaction() - .setKey(key) - .setInitialBalance(new Hbar(1)) - .execute(testEnv.client); + .setKey(key) + .setInitialBalance(new Hbar(1)) + .execute(testEnv.client); var accountId = response.getReceipt(testEnv.client).accountId; assertThat(accountId).isNotNull(); response = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) - .setTreasuryAccountId(testEnv.operatorId) - .setAdminKey(testEnv.operatorKey) - .setFreezeKey(testEnv.operatorKey) - .setWipeKey(testEnv.operatorKey) - .setSupplyKey(testEnv.operatorKey) - .setFreezeDefault(false) - .execute(testEnv.client); + .setTokenName("ffff") + .setTokenSymbol("F") + .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) + .setTreasuryAccountId(testEnv.operatorId) + .setAdminKey(testEnv.operatorKey) + .setFreezeKey(testEnv.operatorKey) + .setWipeKey(testEnv.operatorKey) + .setSupplyKey(testEnv.operatorKey) + .setFreezeDefault(false) + .execute(testEnv.client); var tokenId = response.getReceipt(testEnv.client).tokenId; assertThat(tokenId).isNotNull(); var mintReceipt = new TokenMintTransaction() - .setTokenId(tokenId) - .setMetadata(NftMetadataGenerator.generate((byte) 10)) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setMetadata(NftMetadataGenerator.generate((byte) 10)) + .execute(testEnv.client) + .getReceipt(testEnv.client); new TokenAssociateTransaction() - .setAccountId(accountId) - .setTokenIds(Collections.singletonList(tokenId)) - .freezeWith(testEnv.client) - .signWithOperator(testEnv.client) - .sign(key) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId) + .setTokenIds(Collections.singletonList(tokenId)) + .freezeWith(testEnv.client) + .signWithOperator(testEnv.client) + .sign(key) + .execute(testEnv.client) + .getReceipt(testEnv.client); var serialsToTransfer = new ArrayList(mintReceipt.serials.subList(0, 4)); var transfer = new TransferTransaction(); @@ -164,10 +159,11 @@ void cannotTransferUnownedNfts() throws Exception { } transfer.freezeWith(testEnv.client).sign(key); - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - transfer.execute(testEnv.client).getReceipt(testEnv.client); - }).withMessageContaining(Status.SENDER_DOES_NOT_OWN_NFT_SERIAL_NO.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + transfer.execute(testEnv.client).getReceipt(testEnv.client); + }) + .withMessageContaining(Status.SENDER_DOES_NOT_OWN_NFT_SERIAL_NO.toString()); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenTransferIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenTransferIntegrationTest.java index 13e52fa8c..b8ef589dc 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenTransferIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenTransferIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + import com.hedera.hashgraph.sdk.AccountCreateTransaction; import com.hedera.hashgraph.sdk.CustomFixedFee; import com.hedera.hashgraph.sdk.Hbar; @@ -27,72 +27,66 @@ import com.hedera.hashgraph.sdk.Status; import com.hedera.hashgraph.sdk.TokenAssociateTransaction; import com.hedera.hashgraph.sdk.TokenCreateTransaction; -import com.hedera.hashgraph.sdk.TokenDeleteTransaction; import com.hedera.hashgraph.sdk.TokenGrantKycTransaction; import com.hedera.hashgraph.sdk.TransactionResponse; import com.hedera.hashgraph.sdk.TransferTransaction; +import java.util.Collections; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - class TokenTransferIntegrationTest { @Test @DisplayName("Can transfer tokens") void tokenTransferTest() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { var key = PrivateKey.generateED25519(); TransactionResponse response = new AccountCreateTransaction() - .setKey(key) - .setInitialBalance(new Hbar(1)) - .execute(testEnv.client); + .setKey(key) + .setInitialBalance(new Hbar(1)) + .execute(testEnv.client); var accountId = response.getReceipt(testEnv.client).accountId; assertThat(accountId).isNotNull(); response = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setDecimals(3) - .setInitialSupply(1000000) - .setTreasuryAccountId(testEnv.operatorId) - .setAdminKey(testEnv.operatorKey) - .setFreezeKey(testEnv.operatorKey) - .setWipeKey(testEnv.operatorKey) - .setKycKey(testEnv.operatorKey) - .setSupplyKey(testEnv.operatorKey) - .setFreezeDefault(false) - .execute(testEnv.client); + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(testEnv.operatorId) + .setAdminKey(testEnv.operatorKey) + .setFreezeKey(testEnv.operatorKey) + .setWipeKey(testEnv.operatorKey) + .setKycKey(testEnv.operatorKey) + .setSupplyKey(testEnv.operatorKey) + .setFreezeDefault(false) + .execute(testEnv.client); var tokenId = response.getReceipt(testEnv.client).tokenId; assertThat(tokenId).isNotNull(); new TokenAssociateTransaction() - .setAccountId(accountId) - .setTokenIds(Collections.singletonList(tokenId)) - .freezeWith(testEnv.client) - .signWithOperator(testEnv.client) - .sign(key) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId) + .setTokenIds(Collections.singletonList(tokenId)) + .freezeWith(testEnv.client) + .signWithOperator(testEnv.client) + .sign(key) + .execute(testEnv.client) + .getReceipt(testEnv.client); new TokenGrantKycTransaction() - .setAccountId(accountId) - .setTokenId(tokenId) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId) + .setTokenId(tokenId) + .execute(testEnv.client) + .getReceipt(testEnv.client); new TransferTransaction() - .addTokenTransfer(tokenId, testEnv.operatorId, -10) - .addTokenTransfer(tokenId, accountId, 10) - .execute(testEnv.client) - .getReceipt(testEnv.client); - + .addTokenTransfer(tokenId, testEnv.operatorId, -10) + .addTokenTransfer(tokenId, accountId, 10) + .execute(testEnv.client) + .getReceipt(testEnv.client); } } @@ -104,69 +98,70 @@ void insufficientBalanceForFee() throws Exception { PrivateKey key1 = PrivateKey.generateED25519(); PrivateKey key2 = PrivateKey.generateED25519(); var accountId1 = new AccountCreateTransaction() - .setKey(key1) - .setInitialBalance(new Hbar(2)) - .execute(testEnv.client) - .getReceipt(testEnv.client) - .accountId; + .setKey(key1) + .setInitialBalance(new Hbar(2)) + .execute(testEnv.client) + .getReceipt(testEnv.client) + .accountId; var accountId2 = new AccountCreateTransaction() - .setKey(key2) - .setInitialBalance(new Hbar(2)) - .execute(testEnv.client) - .getReceipt(testEnv.client) - .accountId; + .setKey(key2) + .setInitialBalance(new Hbar(2)) + .execute(testEnv.client) + .getReceipt(testEnv.client) + .accountId; var tokenId = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setInitialSupply(1) - .setCustomFees(Collections.singletonList(new CustomFixedFee() - .setAmount(5000_000_000L) - .setFeeCollectorAccountId(testEnv.operatorId))) - .setTreasuryAccountId(testEnv.operatorId) - .setAdminKey(testEnv.operatorKey) - .setFeeScheduleKey(testEnv.operatorKey) - .execute(testEnv.client) - .getReceipt(testEnv.client) - .tokenId; + .setTokenName("ffff") + .setTokenSymbol("F") + .setInitialSupply(1) + .setCustomFees(Collections.singletonList( + new CustomFixedFee().setAmount(5000_000_000L).setFeeCollectorAccountId(testEnv.operatorId))) + .setTreasuryAccountId(testEnv.operatorId) + .setAdminKey(testEnv.operatorKey) + .setFeeScheduleKey(testEnv.operatorKey) + .execute(testEnv.client) + .getReceipt(testEnv.client) + .tokenId; new TokenAssociateTransaction() - .setAccountId(accountId1) - .setTokenIds(Collections.singletonList(tokenId)) - .freezeWith(testEnv.client) - .sign(key1) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId1) + .setTokenIds(Collections.singletonList(tokenId)) + .freezeWith(testEnv.client) + .sign(key1) + .execute(testEnv.client) + .getReceipt(testEnv.client); new TokenAssociateTransaction() - .setAccountId(accountId2) - .setTokenIds(Collections.singletonList(tokenId)) - .freezeWith(testEnv.client) - .sign(key2) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setAccountId(accountId2) + .setTokenIds(Collections.singletonList(tokenId)) + .freezeWith(testEnv.client) + .sign(key2) + .execute(testEnv.client) + .getReceipt(testEnv.client); new TransferTransaction() - .addTokenTransfer(tokenId, testEnv.operatorId, -1) - .addTokenTransfer(tokenId, accountId1, 1) - .freezeWith(testEnv.client) - .sign(key1) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TransferTransaction() - .addTokenTransfer(tokenId, accountId1, -1) - .addTokenTransfer(tokenId, accountId2, 1) + .addTokenTransfer(tokenId, testEnv.operatorId, -1) + .addTokenTransfer(tokenId, accountId1, 1) .freezeWith(testEnv.client) .sign(key1) - .sign(key2) .execute(testEnv.client) .getReceipt(testEnv.client); - }).satisfies(error -> assertThat(error.getMessage()).containsAnyOf( - Status.INSUFFICIENT_SENDER_ACCOUNT_BALANCE_FOR_CUSTOM_FEE.toString(), - Status.INSUFFICIENT_PAYER_BALANCE_FOR_CUSTOM_FEE.toString() - )); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TransferTransaction() + .addTokenTransfer(tokenId, accountId1, -1) + .addTokenTransfer(tokenId, accountId2, 1) + .freezeWith(testEnv.client) + .sign(key1) + .sign(key2) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .satisfies(error -> assertThat(error.getMessage()) + .containsAnyOf( + Status.INSUFFICIENT_SENDER_ACCOUNT_BALANCE_FOR_CUSTOM_FEE.toString(), + Status.INSUFFICIENT_PAYER_BALANCE_FOR_CUSTOM_FEE.toString())); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenUpdateIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenUpdateIntegrationTest.java index ba4dbc433..c0085c3f0 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenUpdateIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TokenUpdateIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +12,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; import static org.assertj.core.api.Assertions.assertThat; @@ -42,29 +39,27 @@ class TokenUpdateIntegrationTest { @Test @DisplayName("Can update token") void canUpdateToken() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { var response = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setDecimals(3) - .setInitialSupply(1000000) - .setTreasuryAccountId(testEnv.operatorId) - .setAdminKey(testEnv.operatorKey) - .setFreezeKey(testEnv.operatorKey) - .setWipeKey(testEnv.operatorKey) - .setKycKey(testEnv.operatorKey) - .setSupplyKey(testEnv.operatorKey) - .setPauseKey(testEnv.operatorKey) - .setMetadataKey(testEnv.operatorKey) - .setFreezeDefault(false) - .execute(testEnv.client); + .setTokenName("ffff") + .setTokenSymbol("F") + .setDecimals(3) + .setInitialSupply(1000000) + .setTreasuryAccountId(testEnv.operatorId) + .setAdminKey(testEnv.operatorKey) + .setFreezeKey(testEnv.operatorKey) + .setWipeKey(testEnv.operatorKey) + .setKycKey(testEnv.operatorKey) + .setSupplyKey(testEnv.operatorKey) + .setPauseKey(testEnv.operatorKey) + .setMetadataKey(testEnv.operatorKey) + .setFreezeDefault(false) + .execute(testEnv.client); var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId); - var info = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var info = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(info.tokenId).isEqualTo(tokenId); assertThat(info.name).isEqualTo("ffff"); @@ -87,15 +82,13 @@ void canUpdateToken() throws Exception { assertThat(info.defaultKycStatus).isNotNull().isFalse(); new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenName("aaaa") - .setTokenSymbol("A") - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setTokenName("aaaa") + .setTokenSymbol("A") + .execute(testEnv.client) + .getReceipt(testEnv.client); - info = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + info = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(info.tokenId).isEqualTo(tokenId); assertThat(info.name).isEqualTo("aaaa"); @@ -118,7 +111,6 @@ void canUpdateToken() throws Exception { assertThat(info.defaultFreezeStatus).isFalse(); assertThat(info.defaultKycStatus).isNotNull(); assertThat(info.defaultKycStatus).isFalse(); - } } @@ -128,23 +120,24 @@ void cannotUpdateImmutableToken() throws Exception { try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { var response = new TokenCreateTransaction() - .setTokenName("ffff") - .setTokenSymbol("F") - .setTreasuryAccountId(testEnv.operatorId) - .setFreezeDefault(false) - .execute(testEnv.client); + .setTokenName("ffff") + .setTokenSymbol("F") + .setTreasuryAccountId(testEnv.operatorId) + .setFreezeDefault(false) + .execute(testEnv.client); var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId); - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenName("aaaa") - .setTokenSymbol("A") - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setTokenName("aaaa") + .setTokenSymbol("A") + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); } } @@ -155,13 +148,12 @@ void cannotUpdateImmutableToken() throws Exception { @Test @DisplayName("Can update a fungible token's metadata") void canUpdateFungibleTokenMetadata() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var updatedTokenMetadata = new byte[]{2, 2, 2, 2, 2}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var updatedTokenMetadata = new byte[] {2, 2, 2, 2, 2}; // create a fungible token with metadata - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -173,28 +165,24 @@ void canUpdateFungibleTokenMetadata() throws Exception { .setFreezeDefault(false) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoAfterCreation = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterCreation = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterCreation.metadata).isEqualTo(initialTokenMetadata); // update token's metadata new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(updatedTokenMetadata) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setTokenMetadata(updatedTokenMetadata) + .execute(testEnv.client) + .getReceipt(testEnv.client); - var tokenInfoAfterMetadataUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterMetadataUpdate = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterMetadataUpdate.metadata).isEqualTo(updatedTokenMetadata); - } } @@ -205,13 +193,12 @@ void canUpdateFungibleTokenMetadata() throws Exception { @Test @DisplayName("Can update a non fungible token's metadata") void canUpdateNonFungibleTokenMetadata() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var updatedTokenMetadata = new byte[]{2, 2, 2, 2, 2}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var updatedTokenMetadata = new byte[] {2, 2, 2, 2, 2}; // create a non fungible token with metadata - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -222,28 +209,24 @@ void canUpdateNonFungibleTokenMetadata() throws Exception { .setFreezeDefault(false) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoAfterCreation = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterCreation = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterCreation.metadata).isEqualTo(initialTokenMetadata); // update token's metadata new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(updatedTokenMetadata) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setTokenMetadata(updatedTokenMetadata) + .execute(testEnv.client) + .getReceipt(testEnv.client); - var tokenInfoAfterMetadataUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterMetadataUpdate = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterMetadataUpdate.metadata).isEqualTo(updatedTokenMetadata); - } } @@ -254,14 +237,13 @@ void canUpdateNonFungibleTokenMetadata() throws Exception { @Test @DisplayName("Can update an immutable fungible token's metadata") void canUpdateImmutableFungibleTokenMetadata() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var updatedTokenMetadata = new byte[]{2, 2, 2, 2, 2}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var updatedTokenMetadata = new byte[] {2, 2, 2, 2, 2}; var metadataKey = PrivateKey.generateED25519(); // create a fungible token with metadata and metadata key - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -273,31 +255,28 @@ void canUpdateImmutableFungibleTokenMetadata() throws Exception { .setFreezeDefault(false) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoAfterCreation = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterCreation = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterCreation.metadata).isEqualTo(initialTokenMetadata); - assertThat(tokenInfoAfterCreation.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + assertThat(tokenInfoAfterCreation.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // update token's metadata new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(updatedTokenMetadata) - .freezeWith(testEnv.client) - .sign(metadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setTokenMetadata(updatedTokenMetadata) + .freezeWith(testEnv.client) + .sign(metadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); - var tokenInfoAfterMetadataUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterMetadataUpdate = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterMetadataUpdate.metadata).isEqualTo(updatedTokenMetadata); - } } @@ -308,14 +287,13 @@ void canUpdateImmutableFungibleTokenMetadata() throws Exception { @Test @DisplayName("Can update an immutable non fungible token's metadata") void canUpdateImmutableNonFungibleTokenMetadata() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var updatedTokenMetadata = new byte[]{2, 2, 2, 2, 2}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var updatedTokenMetadata = new byte[] {2, 2, 2, 2, 2}; var metadataKey = PrivateKey.generateED25519(); // create a non fungible token with metadata and metadata key - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -326,31 +304,28 @@ void canUpdateImmutableNonFungibleTokenMetadata() throws Exception { .setFreezeDefault(false) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoAfterCreation = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterCreation = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterCreation.metadata).isEqualTo(initialTokenMetadata); - assertThat(tokenInfoAfterCreation.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + assertThat(tokenInfoAfterCreation.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // update token's metadata new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(updatedTokenMetadata) - .freezeWith(testEnv.client) - .sign(metadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setTokenMetadata(updatedTokenMetadata) + .freezeWith(testEnv.client) + .sign(metadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); - var tokenInfoAfterMetadataUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterMetadataUpdate = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterMetadataUpdate.metadata).isEqualTo(updatedTokenMetadata); - } } @@ -361,12 +336,11 @@ void canUpdateImmutableNonFungibleTokenMetadata() throws Exception { @Test @DisplayName("Cannot update a fungible token with metadata when it is not set") void cannotUpdateFungibleTokenMetadataWhenItsNotSet() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; // create a fungible token with metadata - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -378,28 +352,24 @@ void cannotUpdateFungibleTokenMetadataWhenItsNotSet() throws Exception { .setFreezeDefault(false) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoAfterCreation = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterCreation = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterCreation.metadata).isEqualTo(initialTokenMetadata); // update token, but don't update metadata new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMemo("abc") - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setTokenMemo("abc") + .execute(testEnv.client) + .getReceipt(testEnv.client); - var tokenInfoAfterMemoUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterMemoUpdate = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterMemoUpdate.metadata).isEqualTo(initialTokenMetadata); - } } @@ -410,12 +380,11 @@ void cannotUpdateFungibleTokenMetadataWhenItsNotSet() throws Exception { @Test @DisplayName("Cannot update a non fungible token with metadata when it is not set") void cannotUpdateNonFungibleTokenMetadataWhenItsNotSet() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; // create a non fungible token with metadata - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -426,28 +395,24 @@ void cannotUpdateNonFungibleTokenMetadataWhenItsNotSet() throws Exception { .setFreezeDefault(false) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoAfterCreation = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterCreation = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterCreation.metadata).isEqualTo(initialTokenMetadata); // update token, but don't update metadata new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMemo("abc") - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setTokenMemo("abc") + .execute(testEnv.client) + .getReceipt(testEnv.client); - var tokenInfoAfterMemoUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterMemoUpdate = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterMemoUpdate.metadata).isEqualTo(initialTokenMetadata); - } } @@ -458,13 +423,12 @@ void cannotUpdateNonFungibleTokenMetadataWhenItsNotSet() throws Exception { @Test @DisplayName("Can erase fungible token metadata") void canEraseFungibleTokenMetadata() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var emptyTokenMetadata = new byte[]{}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var emptyTokenMetadata = new byte[] {}; // create a fungible token with metadata - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -476,12 +440,10 @@ void canEraseFungibleTokenMetadata() throws Exception { .setFreezeDefault(false) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoAfterCreation = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterCreation = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterCreation.metadata).isEqualTo(initialTokenMetadata); @@ -492,12 +454,10 @@ void canEraseFungibleTokenMetadata() throws Exception { .execute(testEnv.client) .getReceipt(testEnv.client); - var tokenInfoAfterSettingEmptyMetadata = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterSettingEmptyMetadata = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterSettingEmptyMetadata.metadata).isEqualTo(emptyTokenMetadata); - } } @@ -508,13 +468,12 @@ void canEraseFungibleTokenMetadata() throws Exception { @Test @DisplayName("Can erase non fungible token metadata") void canEraseNonFungibleTokenMetadata() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var emptyTokenMetadata = new byte[]{}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var emptyTokenMetadata = new byte[] {}; // create a non fungible token with metadata - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -525,28 +484,24 @@ void canEraseNonFungibleTokenMetadata() throws Exception { .setFreezeDefault(false) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoAfterCreation = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterCreation = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterCreation.metadata).isEqualTo(initialTokenMetadata); // erase token metadata (update token with empty metadata) new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(emptyTokenMetadata) - .execute(testEnv.client) - .getReceipt(testEnv.client); + .setTokenId(tokenId) + .setTokenMetadata(emptyTokenMetadata) + .execute(testEnv.client) + .getReceipt(testEnv.client); - var tokenInfoAfterSettingEmptyMetadata = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoAfterSettingEmptyMetadata = + new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterSettingEmptyMetadata.metadata).isEqualTo(emptyTokenMetadata); - } } @@ -555,18 +510,18 @@ void canEraseNonFungibleTokenMetadata() throws Exception { * @url https://hips.hedera.com/hip/hip-646 */ @Test - @DisplayName("Cannot update a fungible token with metadata when transaction is not signed with an admin or a metadata key") + @DisplayName( + "Cannot update a fungible token with metadata when transaction is not signed with an admin or a metadata key") void cannotUpdateFungibleTokenMetadataWhenTransactionIsNotSignedWithMetadataKey() throws Exception { try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var updatedTokenMetadata = new byte[]{2, 2, 2, 2, 2}; + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var updatedTokenMetadata = new byte[] {2, 2, 2, 2, 2}; var adminKey = PrivateKey.generateED25519(); var metadataKey = PrivateKey.generateED25519(); // create a fungible token with metadata and metadata key - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -580,17 +535,17 @@ void cannotUpdateFungibleTokenMetadataWhenTransactionIsNotSignedWithMetadataKey( .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(updatedTokenMetadata) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + .tokenId); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setTokenMetadata(updatedTokenMetadata) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } @@ -599,17 +554,17 @@ void cannotUpdateFungibleTokenMetadataWhenTransactionIsNotSignedWithMetadataKey( * @url https://hips.hedera.com/hip/hip-765 */ @Test - @DisplayName("Cannot update a non fungible token with metadata when transaction is not signed with an admin or a metadata key") + @DisplayName( + "Cannot update a non fungible token with metadata when transaction is not signed with an admin or a metadata key") void cannotUpdateNonFungibleTokenMetadataWhenTransactionIsNotSignedWithMetadataKey() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var updatedTokenMetadata = new byte[]{2, 2, 2, 2, 2}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var updatedTokenMetadata = new byte[] {2, 2, 2, 2, 2}; var adminKey = PrivateKey.generateED25519(); var metadataKey = PrivateKey.generateED25519(); // create a non fungible token with metadata and metadata key - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -622,17 +577,17 @@ void cannotUpdateNonFungibleTokenMetadataWhenTransactionIsNotSignedWithMetadataK .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(updatedTokenMetadata) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + .tokenId); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setTokenMetadata(updatedTokenMetadata) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } @@ -643,13 +598,12 @@ void cannotUpdateNonFungibleTokenMetadataWhenTransactionIsNotSignedWithMetadataK @Test @DisplayName("Cannot update a fungible token with metadata when admin and metadata keys are not set") void cannotUpdateFungibleTokenMetadataWhenMetadataKeyNotSet() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var updatedTokenMetadata = new byte[]{2, 2, 2, 2, 2}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var updatedTokenMetadata = new byte[] {2, 2, 2, 2, 2}; // create a fungible token with metadata and without a metadata key and admin key - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -659,17 +613,17 @@ void cannotUpdateFungibleTokenMetadataWhenMetadataKeyNotSet() throws Exception { .setInitialSupply(1000000) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(updatedTokenMetadata) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - + .tokenId); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setTokenMetadata(updatedTokenMetadata) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); } } @@ -680,13 +634,12 @@ void cannotUpdateFungibleTokenMetadataWhenMetadataKeyNotSet() throws Exception { @Test @DisplayName("Cannot update a non fungible token with metadata when admin and metadata keys are not set") void cannotUpdateNonFungibleTokenMetadataWhenMetadataKeyNotSet() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - var initialTokenMetadata = new byte[]{1, 1, 1, 1, 1}; - var updatedTokenMetadata = new byte[]{2, 2, 2, 2, 2}; + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { + var initialTokenMetadata = new byte[] {1, 1, 1, 1, 1}; + var updatedTokenMetadata = new byte[] {2, 2, 2, 2, 2}; // create a non fungible token with metadata and without a metadata key and admin key - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("ffff") .setTokenSymbol("F") .setTokenMetadata(initialTokenMetadata) @@ -695,17 +648,17 @@ void cannotUpdateNonFungibleTokenMetadataWhenMetadataKeyNotSet() throws Exceptio .setSupplyKey(testEnv.operatorKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setTokenMetadata(updatedTokenMetadata) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - + .tokenId); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setTokenMetadata(updatedTokenMetadata) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); } } @@ -714,9 +667,11 @@ void cannotUpdateNonFungibleTokenMetadataWhenMetadataKeyNotSet() throws Exceptio * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Can make a token immutable when updating keys to an empty KeyList, signing with an Admin Key, and setting the key verification mode to NO_VALIDATION") - void canMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithAdminKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Can make a token immutable when updating keys to an empty KeyList, signing with an Admin Key, and setting the key verification mode to NO_VALIDATION") + void canMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithAdminKeyWithKeyVerificationSetToNoValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Admin, Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var adminKey = PrivateKey.generateED25519(); @@ -729,8 +684,7 @@ void canMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithAdminKeyWithK var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -747,45 +701,48 @@ void canMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithAdminKeyWithK .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.adminKey.toString()).isEqualTo(adminKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.adminKey.toString()) + .isEqualTo(adminKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); var emptyKeyList = new KeyList(); // Make a token immutable by removing all of its keys when updating them to an empty KeyList, // signing with an Admin Key, and setting the key verification mode to NO_VALIDATION new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(emptyKeyList) - .setKycKey(emptyKeyList) - .setFreezeKey(emptyKeyList) - .setPauseKey(emptyKeyList) - .setSupplyKey(emptyKeyList) - .setFeeScheduleKey(emptyKeyList) - .setMetadataKey(emptyKeyList) - .setAdminKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(adminKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - var tokenInfoAfterUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + .setTokenId(tokenId) + .setWipeKey(emptyKeyList) + .setKycKey(emptyKeyList) + .setFreezeKey(emptyKeyList) + .setPauseKey(emptyKeyList) + .setSupplyKey(emptyKeyList) + .setFeeScheduleKey(emptyKeyList) + .setMetadataKey(emptyKeyList) + .setAdminKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(adminKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + + var tokenInfoAfterUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterUpdate.adminKey).isNull(); assertThat(tokenInfoAfterUpdate.wipeKey).isNull(); @@ -795,7 +752,6 @@ void canMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithAdminKeyWithK assertThat(tokenInfoAfterUpdate.supplyKey).isNull(); assertThat(tokenInfoAfterUpdate.feeScheduleKey).isNull(); assertThat(tokenInfoAfterUpdate.metadataKey).isNull(); - } } @@ -804,9 +760,12 @@ void canMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithAdminKeyWithK * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Can remove all of token’s lower-privilege keys when updating keys to an empty KeyList, signing with an Admin Key, and setting the key verification mode to FULL_VALIDATION") - void canRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithAdminKeyWithKeyVerificationSetToFullValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Can remove all of token’s lower-privilege keys when updating keys to an empty KeyList, signing with an Admin Key, and setting the key verification mode to FULL_VALIDATION") + void + canRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithAdminKeyWithKeyVerificationSetToFullValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Admin, Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var adminKey = PrivateKey.generateED25519(); @@ -819,8 +778,7 @@ void canRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithAdmi var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -837,44 +795,47 @@ void canRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithAdmi .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.adminKey.toString()).isEqualTo(adminKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.adminKey.toString()) + .isEqualTo(adminKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); var emptyKeyList = new KeyList(); // Remove all of token’s lower-privilege keys when updating them to an empty KeyList, // signing with an Admin Key, and setting the key verification mode to FULL_VALIDATION new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(emptyKeyList) - .setKycKey(emptyKeyList) - .setFreezeKey(emptyKeyList) - .setPauseKey(emptyKeyList) - .setSupplyKey(emptyKeyList) - .setFeeScheduleKey(emptyKeyList) - .setMetadataKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(adminKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - var tokenInfoAfterUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + .setTokenId(tokenId) + .setWipeKey(emptyKeyList) + .setKycKey(emptyKeyList) + .setFreezeKey(emptyKeyList) + .setPauseKey(emptyKeyList) + .setSupplyKey(emptyKeyList) + .setFeeScheduleKey(emptyKeyList) + .setMetadataKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(adminKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + + var tokenInfoAfterUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); assertThat(tokenInfoAfterUpdate.wipeKey).isNull(); assertThat(tokenInfoAfterUpdate.kycKey).isNull(); @@ -883,7 +844,6 @@ void canRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithAdmi assertThat(tokenInfoAfterUpdate.supplyKey).isNull(); assertThat(tokenInfoAfterUpdate.feeScheduleKey).isNull(); assertThat(tokenInfoAfterUpdate.metadataKey).isNull(); - } } @@ -892,9 +852,12 @@ void canRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithAdmi * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Can update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing with an Admin Key, and setting the key verification mode to FULL_VALIDATION, and then revert previous keys") - void canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithAdminKeyWithKeyVerificationSetToFullValidationAndThenRevertPreviousKeys() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Can update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing with an Admin Key, and setting the key verification mode to FULL_VALIDATION, and then revert previous keys") + void + canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithAdminKeyWithKeyVerificationSetToFullValidationAndThenRevertPreviousKeys() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Admin, Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var adminKey = PrivateKey.generateED25519(); @@ -907,8 +870,7 @@ void canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithAdminKeyWithKeyVe var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -925,81 +887,96 @@ void canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithAdminKeyWithKeyVe .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.adminKey.toString()).isEqualTo(adminKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.adminKey.toString()) + .isEqualTo(adminKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Update all of token’s lower-privilege keys to an unusable key (i.e., all-zeros key), // signing with an Admin Key, and setting the key verification mode to FULL_VALIDATION new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(PublicKey.unusableKey()) - .setKycKey(PublicKey.unusableKey()) - .setFreezeKey(PublicKey.unusableKey()) - .setPauseKey(PublicKey.unusableKey()) - .setSupplyKey(PublicKey.unusableKey()) - .setFeeScheduleKey(PublicKey.unusableKey()) - .setMetadataKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(adminKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - var tokenInfoAfterUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoAfterUpdate.wipeKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.kycKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.freezeKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.pauseKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.supplyKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.metadataKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); + .setTokenId(tokenId) + .setWipeKey(PublicKey.unusableKey()) + .setKycKey(PublicKey.unusableKey()) + .setFreezeKey(PublicKey.unusableKey()) + .setPauseKey(PublicKey.unusableKey()) + .setSupplyKey(PublicKey.unusableKey()) + .setFeeScheduleKey(PublicKey.unusableKey()) + .setMetadataKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(adminKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + + var tokenInfoAfterUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoAfterUpdate.wipeKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.kycKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.freezeKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.pauseKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.supplyKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.metadataKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); // Set all lower-privilege keys back by signing with an Admin Key, // and setting key verification mode to NO_VALIDATION new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(wipeKey.getPublicKey()) - .setKycKey(kycKey.getPublicKey()) - .setFreezeKey(freezeKey.getPublicKey()) - .setPauseKey(pauseKey.getPublicKey()) - .setSupplyKey(supplyKey.getPublicKey()) - .setFeeScheduleKey(feeScheduleKey.getPublicKey()) - .setMetadataKey(metadataKey.getPublicKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(adminKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - var tokenInfoAfterRevert = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoAfterRevert.adminKey.toString()).isEqualTo(adminKey.getPublicKey().toString()); - assertThat(tokenInfoAfterRevert.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoAfterRevert.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoAfterRevert.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoAfterRevert.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoAfterRevert.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoAfterRevert.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoAfterRevert.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .setTokenId(tokenId) + .setWipeKey(wipeKey.getPublicKey()) + .setKycKey(kycKey.getPublicKey()) + .setFreezeKey(freezeKey.getPublicKey()) + .setPauseKey(pauseKey.getPublicKey()) + .setSupplyKey(supplyKey.getPublicKey()) + .setFeeScheduleKey(feeScheduleKey.getPublicKey()) + .setMetadataKey(metadataKey.getPublicKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(adminKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + var tokenInfoAfterRevert = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoAfterRevert.adminKey.toString()) + .isEqualTo(adminKey.getPublicKey().toString()); + assertThat(tokenInfoAfterRevert.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoAfterRevert.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoAfterRevert.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoAfterRevert.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoAfterRevert.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoAfterRevert.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoAfterRevert.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); } } @@ -1008,9 +985,12 @@ void canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithAdminKeyWithKeyVe * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Can update all of token’s lower-privilege keys when signing with an Admin Key and new respective lower-privilege key, and setting key verification mode to FULL_VALIDATION") - void canUpdateAllLowerPrivilegeKeysWhenSigningWithAdminKeyAndNewLowerPrivilegeKeyWithKeyVerificationSetToFullValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Can update all of token’s lower-privilege keys when signing with an Admin Key and new respective lower-privilege key, and setting key verification mode to FULL_VALIDATION") + void + canUpdateAllLowerPrivilegeKeysWhenSigningWithAdminKeyAndNewLowerPrivilegeKeyWithKeyVerificationSetToFullValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Admin, Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var adminKey = PrivateKey.generateED25519(); @@ -1032,8 +1012,7 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningWithAdminKeyAndNewLowerPrivilegeKe var newMetadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1050,58 +1029,68 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningWithAdminKeyAndNewLowerPrivilegeKe .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.adminKey.toString()).isEqualTo(adminKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); - - // Update all of token’s lower-privilege keys when signing with an Admin Key and new respective lower-privilege key, + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.adminKey.toString()) + .isEqualTo(adminKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); + + // Update all of token’s lower-privilege keys when signing with an Admin Key and new respective + // lower-privilege key, // and setting key verification mode to FULL_VALIDATION new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(newWipeKey.getPublicKey()) - .setKycKey(newKycKey.getPublicKey()) - .setFreezeKey(newFreezeKey.getPublicKey()) - .setPauseKey(newPauseKey.getPublicKey()) - .setSupplyKey(newSupplyKey.getPublicKey()) - .setFeeScheduleKey(newFeeScheduleKey.getPublicKey()) - .setMetadataKey(newMetadataKey.getPublicKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(adminKey) - .sign(newWipeKey) - .sign(newKycKey) - .sign(newFreezeKey) - .sign(newPauseKey) - .sign(newSupplyKey) - .sign(newFeeScheduleKey) - .sign(newMetadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - var tokenInfoAfterUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoAfterUpdate.wipeKey.toString()).isEqualTo(newWipeKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.kycKey.toString()).isEqualTo(newKycKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.freezeKey.toString()).isEqualTo(newFreezeKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.pauseKey.toString()).isEqualTo(newPauseKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.supplyKey.toString()).isEqualTo(newSupplyKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()).isEqualTo(newFeeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.metadataKey.toString()).isEqualTo(newMetadataKey.getPublicKey().toString()); + .setTokenId(tokenId) + .setWipeKey(newWipeKey.getPublicKey()) + .setKycKey(newKycKey.getPublicKey()) + .setFreezeKey(newFreezeKey.getPublicKey()) + .setPauseKey(newPauseKey.getPublicKey()) + .setSupplyKey(newSupplyKey.getPublicKey()) + .setFeeScheduleKey(newFeeScheduleKey.getPublicKey()) + .setMetadataKey(newMetadataKey.getPublicKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(adminKey) + .sign(newWipeKey) + .sign(newKycKey) + .sign(newFreezeKey) + .sign(newPauseKey) + .sign(newSupplyKey) + .sign(newFeeScheduleKey) + .sign(newMetadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + var tokenInfoAfterUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoAfterUpdate.wipeKey.toString()) + .isEqualTo(newWipeKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.kycKey.toString()) + .isEqualTo(newKycKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.freezeKey.toString()) + .isEqualTo(newFreezeKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.pauseKey.toString()) + .isEqualTo(newPauseKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.supplyKey.toString()) + .isEqualTo(newSupplyKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()) + .isEqualTo(newFeeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.metadataKey.toString()) + .isEqualTo(newMetadataKey.getPublicKey().toString()); } } @@ -1110,9 +1099,12 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningWithAdminKeyAndNewLowerPrivilegeKe * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Cannot make a token immutable when updating keys to an empty KeyList, signing with a key that is different from an Admin Key, and setting the key verification mode to NO_VALIDATION") - void cannotMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithDifferentKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Cannot make a token immutable when updating keys to an empty KeyList, signing with a key that is different from an Admin Key, and setting the key verification mode to NO_VALIDATION") + void + cannotMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithDifferentKeyWithKeyVerificationSetToNoValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Admin, Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var adminKey = PrivateKey.generateED25519(); @@ -1125,8 +1117,7 @@ void cannotMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithDifferentK var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1143,21 +1134,26 @@ void cannotMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithDifferentK .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.adminKey.toString()).isEqualTo(adminKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.adminKey.toString()) + .isEqualTo(adminKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); var emptyKeyList = new KeyList(); @@ -1165,78 +1161,93 @@ void cannotMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithDifferentK // (trying to remove keys one by one to check all errors), // signing with a key that is different from an Admin Key (implicitly with an operator key), // and setting the key verification mode to NO_VALIDATION - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setKycKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFreezeKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setPauseKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setSupplyKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFeeScheduleKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setMetadataKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setAdminKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setWipeKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setKycKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFreezeKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setPauseKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setSupplyKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFeeScheduleKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadataKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setAdminKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } @@ -1245,9 +1256,12 @@ void cannotMakeTokenImmutableWhenUpdatingKeysToEmptyKeyListSigningWithDifferentK * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Cannot make a token immutable when updating keys to an unusable key (i.e. all-zeros key), signing with a key that is different from an Admin Key, and setting the key verification mode to NO_VALIDATION") - void cannotMakeTokenImmutableWhenUpdatingKeysToUnusableKeySigningWithDifferentKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Cannot make a token immutable when updating keys to an unusable key (i.e. all-zeros key), signing with a key that is different from an Admin Key, and setting the key verification mode to NO_VALIDATION") + void + cannotMakeTokenImmutableWhenUpdatingKeysToUnusableKeySigningWithDifferentKeyWithKeyVerificationSetToNoValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Admin, Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var adminKey = PrivateKey.generateED25519(); @@ -1260,8 +1274,7 @@ void cannotMakeTokenImmutableWhenUpdatingKeysToUnusableKeySigningWithDifferentKe var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1278,117 +1291,137 @@ void cannotMakeTokenImmutableWhenUpdatingKeysToUnusableKeySigningWithDifferentKe .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.adminKey.toString()).isEqualTo(adminKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.adminKey.toString()) + .isEqualTo(adminKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Make the token immutable when updating all of its keys to an unusable key (i.e. all-zeros key) // (trying to remove keys one by one to check all errors), // signing with a key that is different from an Admin Key (implicitly with an operator key), // and setting the key verification mode to NO_VALIDATION - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setWipeKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setKycKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFreezeKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setPauseKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setSupplyKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFeeScheduleKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadataKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setAdminKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + } + } - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setKycKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); + /** + * @notice E2E-HIP-540 + * @url https://hips.hedera.com/hip/hip-540 + */ + @Test + @DisplayName( + "Cannot update the Admin Key to an unusable key (i.e. all-zeros key), signing with an Admin Key, and setting the key verification mode to NO_VALIDATION") + void cannotUpdateAdminKeyToUnusableKeySigningWithAdminKeyWithKeyVerificationSetToNoValidation() throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFreezeKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setPauseKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setSupplyKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFeeScheduleKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setMetadataKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setAdminKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - } - } - - /** - * @notice E2E-HIP-540 - * @url https://hips.hedera.com/hip/hip-540 - */ - @Test - @DisplayName("Cannot update the Admin Key to an unusable key (i.e. all-zeros key), signing with an Admin Key, and setting the key verification mode to NO_VALIDATION") - void cannotUpdateAdminKeyToUnusableKeySigningWithAdminKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ - - // Admin and supply keys - var adminKey = PrivateKey.generateED25519(); - var supplyKey = PrivateKey.generateED25519(); + // Admin and supply keys + var adminKey = PrivateKey.generateED25519(); + var supplyKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1399,28 +1432,27 @@ void cannotUpdateAdminKeyToUnusableKeySigningWithAdminKeyWithKeyVerificationSetT .sign(adminKey) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); + .tokenId); - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); - assertThat(tokenInfoBeforeUpdate.adminKey.toString()).isEqualTo(adminKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.adminKey.toString()) + .isEqualTo(adminKey.getPublicKey().toString()); // Update the Admin Key to an unusable key (i.e., all-zeros key), // signing with an Admin Key, and setting the key verification mode to NO_VALIDATION - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setAdminKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(adminKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setAdminKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(adminKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } @@ -1429,9 +1461,12 @@ void cannotUpdateAdminKeyToUnusableKeySigningWithAdminKeyWithKeyVerificationSetT * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Can update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing with a respective lower-privilege key, and setting the key verification mode to NO_VALIDATION") - void canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithRespectiveLowerPrivilegeKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Can update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing with a respective lower-privilege key, and setting the key verification mode to NO_VALIDATION") + void + canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithRespectiveLowerPrivilegeKeyWithKeyVerificationSetToNoValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -1443,8 +1478,7 @@ void canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithRespectiveLowerPr var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1458,57 +1492,65 @@ void canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithRespectiveLowerPr .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Update all of token’s lower-privilege keys to an unusable key (i.e., all-zeros key), // when signing with a respective lower-privilege key, // and setting the key verification mode to NO_VALIDATION new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(PublicKey.unusableKey()) - .setKycKey(PublicKey.unusableKey()) - .setFreezeKey(PublicKey.unusableKey()) - .setPauseKey(PublicKey.unusableKey()) - .setSupplyKey(PublicKey.unusableKey()) - .setFeeScheduleKey(PublicKey.unusableKey()) - .setMetadataKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(wipeKey) - .sign(kycKey) - .sign(freezeKey) - .sign(pauseKey) - .sign(supplyKey) - .sign(feeScheduleKey) - .sign(metadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - var tokenInfoAfterUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoAfterUpdate.wipeKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.kycKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.freezeKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.pauseKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.supplyKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); - assertThat(tokenInfoAfterUpdate.metadataKey.toString()).isEqualTo(PublicKey.unusableKey().toString()); + .setTokenId(tokenId) + .setWipeKey(PublicKey.unusableKey()) + .setKycKey(PublicKey.unusableKey()) + .setFreezeKey(PublicKey.unusableKey()) + .setPauseKey(PublicKey.unusableKey()) + .setSupplyKey(PublicKey.unusableKey()) + .setFeeScheduleKey(PublicKey.unusableKey()) + .setMetadataKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(wipeKey) + .sign(kycKey) + .sign(freezeKey) + .sign(pauseKey) + .sign(supplyKey) + .sign(feeScheduleKey) + .sign(metadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + var tokenInfoAfterUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoAfterUpdate.wipeKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.kycKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.freezeKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.pauseKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.supplyKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); + assertThat(tokenInfoAfterUpdate.metadataKey.toString()) + .isEqualTo(PublicKey.unusableKey().toString()); } } @@ -1517,9 +1559,12 @@ void canUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithRespectiveLowerPr * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Can update all of token’s lower-privilege keys when signing with an old lower-privilege key and with a new lower-privilege key, and setting key verification mode to FULL_VALIDATION") - void canUpdateAllLowerPrivilegeKeysWhenSigningWithOldLowerPrivilegeKeyAndNewLowerPrivilegeKeyWithKeyVerificationSetToFulValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Can update all of token’s lower-privilege keys when signing with an old lower-privilege key and with a new lower-privilege key, and setting key verification mode to FULL_VALIDATION") + void + canUpdateAllLowerPrivilegeKeysWhenSigningWithOldLowerPrivilegeKeyAndNewLowerPrivilegeKeyWithKeyVerificationSetToFulValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -1540,8 +1585,7 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningWithOldLowerPrivilegeKeyAndNewLowe var newMetadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1555,63 +1599,71 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningWithOldLowerPrivilegeKeyAndNewLowe .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Update all of token’s lower-privilege keys when signing with an old respective lower-privilege key, // and setting key verification mode to NO_VALIDATION new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(newWipeKey.getPublicKey()) - .setKycKey(newKycKey.getPublicKey()) - .setFreezeKey(newFreezeKey.getPublicKey()) - .setPauseKey(newPauseKey.getPublicKey()) - .setSupplyKey(newSupplyKey.getPublicKey()) - .setFeeScheduleKey(newFeeScheduleKey.getPublicKey()) - .setMetadataKey(newMetadataKey.getPublicKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(wipeKey) - .sign(newWipeKey) - .sign(kycKey) - .sign(newKycKey) - .sign(freezeKey) - .sign(newFreezeKey) - .sign(pauseKey) - .sign(newPauseKey) - .sign(supplyKey) - .sign(newSupplyKey) - .sign(feeScheduleKey) - .sign(newFeeScheduleKey) - .sign(metadataKey) - .sign(newMetadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - var tokenInfoAfterUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoAfterUpdate.wipeKey.toString()).isEqualTo(newWipeKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.kycKey.toString()).isEqualTo(newKycKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.freezeKey.toString()).isEqualTo(newFreezeKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.pauseKey.toString()).isEqualTo(newPauseKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.supplyKey.toString()).isEqualTo(newSupplyKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()).isEqualTo(newFeeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.metadataKey.toString()).isEqualTo(newMetadataKey.getPublicKey().toString()); + .setTokenId(tokenId) + .setWipeKey(newWipeKey.getPublicKey()) + .setKycKey(newKycKey.getPublicKey()) + .setFreezeKey(newFreezeKey.getPublicKey()) + .setPauseKey(newPauseKey.getPublicKey()) + .setSupplyKey(newSupplyKey.getPublicKey()) + .setFeeScheduleKey(newFeeScheduleKey.getPublicKey()) + .setMetadataKey(newMetadataKey.getPublicKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(wipeKey) + .sign(newWipeKey) + .sign(kycKey) + .sign(newKycKey) + .sign(freezeKey) + .sign(newFreezeKey) + .sign(pauseKey) + .sign(newPauseKey) + .sign(supplyKey) + .sign(newSupplyKey) + .sign(feeScheduleKey) + .sign(newFeeScheduleKey) + .sign(metadataKey) + .sign(newMetadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + var tokenInfoAfterUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoAfterUpdate.wipeKey.toString()) + .isEqualTo(newWipeKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.kycKey.toString()) + .isEqualTo(newKycKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.freezeKey.toString()) + .isEqualTo(newFreezeKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.pauseKey.toString()) + .isEqualTo(newPauseKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.supplyKey.toString()) + .isEqualTo(newSupplyKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()) + .isEqualTo(newFeeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.metadataKey.toString()) + .isEqualTo(newMetadataKey.getPublicKey().toString()); } } @@ -1620,9 +1672,11 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningWithOldLowerPrivilegeKeyAndNewLowe * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Can update all of token’s lower-privilege keys when signing ONLY with an old lower-privilege key, and setting key verification mode to NO_VALIDATION") - void canUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldLowerPrivilegeKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Can update all of token’s lower-privilege keys when signing ONLY with an old lower-privilege key, and setting key verification mode to NO_VALIDATION") + void canUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldLowerPrivilegeKeyWithKeyVerificationSetToNoValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -1643,8 +1697,7 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldLowerPrivilegeKeyWithKe var newMetadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1658,56 +1711,64 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldLowerPrivilegeKeyWithKe .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Update all of token’s lower-privilege keys when signing with an old respective lower-privilege key, // and setting key verification mode to NO_VALIDATION new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(newWipeKey.getPublicKey()) - .setKycKey(newKycKey.getPublicKey()) - .setFreezeKey(newFreezeKey.getPublicKey()) - .setPauseKey(newPauseKey.getPublicKey()) - .setSupplyKey(newSupplyKey.getPublicKey()) - .setFeeScheduleKey(newFeeScheduleKey.getPublicKey()) - .setMetadataKey(newMetadataKey.getPublicKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(wipeKey) - .sign(kycKey) - .sign(freezeKey) - .sign(pauseKey) - .sign(supplyKey) - .sign(feeScheduleKey) - .sign(metadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - - var tokenInfoAfterUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoAfterUpdate.wipeKey.toString()).isEqualTo(newWipeKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.kycKey.toString()).isEqualTo(newKycKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.freezeKey.toString()).isEqualTo(newFreezeKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.pauseKey.toString()).isEqualTo(newPauseKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.supplyKey.toString()).isEqualTo(newSupplyKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()).isEqualTo(newFeeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoAfterUpdate.metadataKey.toString()).isEqualTo(newMetadataKey.getPublicKey().toString()); + .setTokenId(tokenId) + .setWipeKey(newWipeKey.getPublicKey()) + .setKycKey(newKycKey.getPublicKey()) + .setFreezeKey(newFreezeKey.getPublicKey()) + .setPauseKey(newPauseKey.getPublicKey()) + .setSupplyKey(newSupplyKey.getPublicKey()) + .setFeeScheduleKey(newFeeScheduleKey.getPublicKey()) + .setMetadataKey(newMetadataKey.getPublicKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(wipeKey) + .sign(kycKey) + .sign(freezeKey) + .sign(pauseKey) + .sign(supplyKey) + .sign(feeScheduleKey) + .sign(metadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + + var tokenInfoAfterUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + assertThat(tokenInfoAfterUpdate.wipeKey.toString()) + .isEqualTo(newWipeKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.kycKey.toString()) + .isEqualTo(newKycKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.freezeKey.toString()) + .isEqualTo(newFreezeKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.pauseKey.toString()) + .isEqualTo(newPauseKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.supplyKey.toString()) + .isEqualTo(newSupplyKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.feeScheduleKey.toString()) + .isEqualTo(newFeeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoAfterUpdate.metadataKey.toString()) + .isEqualTo(newMetadataKey.getPublicKey().toString()); } } @@ -1716,9 +1777,12 @@ void canUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldLowerPrivilegeKeyWithKe * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Cannot remove all of token’s lower-privilege keys when updating them to an empty KeyList, signing with a respective lower-privilege key, and setting the key verification mode to NO_VALIDATION") - void cannotRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithRespectiveLowerPrivilegeKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Cannot remove all of token’s lower-privilege keys when updating them to an empty KeyList, signing with a respective lower-privilege key, and setting the key verification mode to NO_VALIDATION") + void + cannotRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithRespectiveLowerPrivilegeKeyWithKeyVerificationSetToNoValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -1730,8 +1794,7 @@ void cannotRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithR var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1745,20 +1808,24 @@ void cannotRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithR .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); var emptyKeyList = new KeyList(); @@ -1766,83 +1833,96 @@ void cannotRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithR // when updating them to an empty KeyList (trying to remove keys one by one to check all errors), // signing with a respective lower-privilege key, // and setting the key verification mode to NO_VALIDATION - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(wipeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setKycKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(kycKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFreezeKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(freezeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setPauseKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(pauseKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setSupplyKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(supplyKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFeeScheduleKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(feeScheduleKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setMetadataKey(emptyKeyList) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(metadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setWipeKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(wipeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setKycKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(kycKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFreezeKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(freezeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setPauseKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(pauseKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setSupplyKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(supplyKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFeeScheduleKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(feeScheduleKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadataKey(emptyKeyList) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(metadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.TOKEN_IS_IMMUTABLE.toString()); } } @@ -1851,9 +1931,11 @@ void cannotRemoveAllLowerPrivilegeKeysWhenUpdatingKeysToEmptyKeyListSigningWithR * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Cannot update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing with a key that is different from a respective lower-privilege key, and setting the key verification mode to NO_VALIDATION") - void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithDifferentKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Cannot update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing with a key that is different from a respective lower-privilege key, and setting the key verification mode to NO_VALIDATION") + void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithDifferentKeyWithKeyVerificationSetToNoValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -1865,8 +1947,7 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithDifferentKeyWi var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1880,88 +1961,106 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithDifferentKeyWi .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key) // (trying to remove keys one by one to check all errors), - // signing with a key that is different from a respective lower-privilege key (implicitly with an operator key), + // signing with a key that is different from a respective lower-privilege key (implicitly with an operator + // key), // and setting the key verification mode to NO_VALIDATION - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setKycKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFreezeKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setPauseKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setSupplyKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFeeScheduleKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setMetadataKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setWipeKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setKycKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFreezeKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setPauseKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setSupplyKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFeeScheduleKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadataKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } @@ -1970,9 +2069,12 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithDifferentKeyWi * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Cannot update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing ONLY with an old respective lower-privilege key, and setting the key verification mode to FULL_VALIDATION") - void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningOnlyWithOldRespectiveLowerPrivilegeKeyWithKeyVerificationSetToFullValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Cannot update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing ONLY with an old respective lower-privilege key, and setting the key verification mode to FULL_VALIDATION") + void + cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningOnlyWithOldRespectiveLowerPrivilegeKeyWithKeyVerificationSetToFullValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -1984,8 +2086,7 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningOnlyWithOldRespect var metadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -1999,102 +2100,119 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningOnlyWithOldRespect .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Update all of token’s lower-privilege keys to an unusable key (i.e., all-zeros key) // (trying to remove keys one by one to check all errors), // signing ONLY with an old respective lower-privilege key, // and setting the key verification mode to FULL_VALIDATION - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(wipeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setKycKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(kycKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFreezeKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(freezeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setPauseKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(pauseKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setSupplyKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(supplyKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFeeScheduleKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(feeScheduleKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setMetadataKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(metadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setWipeKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(wipeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setKycKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(kycKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFreezeKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(freezeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setPauseKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(pauseKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setSupplyKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(supplyKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFeeScheduleKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(feeScheduleKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadataKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(metadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } @@ -2103,9 +2221,12 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningOnlyWithOldRespect * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Cannot update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing with an old respective lower-privilege key and new respective lower-privilege key, and setting the key verification mode to FULL_VALIDATION") - void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithOldRespectiveLowerPrivilegeKeyAndNewRespectiveLowerPrivilegeKeyWithKeyVerificationSetToFullValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Cannot update all of token’s lower-privilege keys to an unusable key (i.e. all-zeros key), when signing with an old respective lower-privilege key and new respective lower-privilege key, and setting the key verification mode to FULL_VALIDATION") + void + cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithOldRespectiveLowerPrivilegeKeyAndNewRespectiveLowerPrivilegeKeyWithKeyVerificationSetToFullValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -2126,8 +2247,7 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithOldRespectiveL var newMetadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -2141,109 +2261,126 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithOldRespectiveL .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Update all of token’s lower-privilege keys to an unusable key (i.e., all-zeros key) // (trying to remove keys one by one to check all errors), // signing with an old respective lower-privilege key and new respective lower-privilege key, // and setting the key verification mode to FULL_VALIDATION - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(wipeKey) - .sign(newWipeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setKycKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(kycKey) - .sign(newKycKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFreezeKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(freezeKey) - .sign(newFreezeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setPauseKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(pauseKey) - .sign(newPauseKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setSupplyKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(supplyKey) - .sign(newSupplyKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFeeScheduleKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(feeScheduleKey) - .sign(newFeeScheduleKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setMetadataKey(PublicKey.unusableKey()) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(metadataKey) - .sign(newMetadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setWipeKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(wipeKey) + .sign(newWipeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setKycKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(kycKey) + .sign(newKycKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFreezeKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(freezeKey) + .sign(newFreezeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setPauseKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(pauseKey) + .sign(newPauseKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setSupplyKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(supplyKey) + .sign(newSupplyKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFeeScheduleKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(feeScheduleKey) + .sign(newFeeScheduleKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadataKey(PublicKey.unusableKey()) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(metadataKey) + .sign(newMetadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } @@ -2252,9 +2389,12 @@ void cannotUpdateAllLowerPrivilegeKeysToUnusableKeyWhenSigningWithOldRespectiveL * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Cannot update all of token’s lower-privilege keys, when signing ONLY with an old respective lower-privilege key, and setting the key verification mode to FULL_VALIDATION") - void cannotUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldRespectiveLowerPrivilegeKeyWithKeyVerificationSetToFullValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Cannot update all of token’s lower-privilege keys, when signing ONLY with an old respective lower-privilege key, and setting the key verification mode to FULL_VALIDATION") + void + cannotUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldRespectiveLowerPrivilegeKeyWithKeyVerificationSetToFullValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -2275,8 +2415,7 @@ void cannotUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldRespectiveLowerPrivi var newMetadataKey = PrivateKey.generateED25519(); // Create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -2290,102 +2429,119 @@ void cannotUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldRespectiveLowerPrivi .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // Update all of token’s lower-privilege keys // (trying to update keys one by one to check all errors), // signing ONLY with an old respective lower-privilege key, // and setting the key verification mode to FULL_VALIDATION - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(newWipeKey) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(wipeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setKycKey(newKycKey) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(kycKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFreezeKey(newFreezeKey) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(freezeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setPauseKey(newPauseKey) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(pauseKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setSupplyKey(newSupplyKey) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(supplyKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFeeScheduleKey(newFeeScheduleKey) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(feeScheduleKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - - assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setMetadataKey(newMetadataKey) - .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) - .freezeWith(testEnv.client) - .sign(metadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SIGNATURE.toString()); - + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setWipeKey(newWipeKey) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(wipeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setKycKey(newKycKey) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(kycKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFreezeKey(newFreezeKey) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(freezeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setPauseKey(newPauseKey) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(pauseKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setSupplyKey(newSupplyKey) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(supplyKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFeeScheduleKey(newFeeScheduleKey) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(feeScheduleKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); + + assertThatExceptionOfType(ReceiptStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadataKey(newMetadataKey) + .setKeyVerificationMode(TokenKeyValidation.FULL_VALIDATION) + .freezeWith(testEnv.client) + .sign(metadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SIGNATURE.toString()); } } @@ -2394,9 +2550,12 @@ void cannotUpdateAllLowerPrivilegeKeysWhenSigningOnlyWithOldRespectiveLowerPrivi * @url https://hips.hedera.com/hip/hip-540 */ @Test - @DisplayName("Cannot update all of token’s lower-privilege keys when updating them to a keys with an invalid structure and signing with an old respective lower-privilege and setting key verification mode to NO_VALIDATION") - void cannotUpdateAllLowerPrivilegeKeysWhenUpdatingKeysToStructurallyInvalidKeysSigningOnlyWithOldRespectiveLowerPrivilegeKeyWithKeyVerificationSetToNoValidation() throws Exception { - try(var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()){ + @DisplayName( + "Cannot update all of token’s lower-privilege keys when updating them to a keys with an invalid structure and signing with an old respective lower-privilege and setting key verification mode to NO_VALIDATION") + void + cannotUpdateAllLowerPrivilegeKeysWhenUpdatingKeysToStructurallyInvalidKeysSigningOnlyWithOldRespectiveLowerPrivilegeKeyWithKeyVerificationSetToNoValidation() + throws Exception { + try (var testEnv = new IntegrationTestEnv(1).useThrowawayAccount()) { // Wipe, KYC, Freeze, Pause, Supply, Fee Schedule, Metadata keys var wipeKey = PrivateKey.generateED25519(); @@ -2408,8 +2567,7 @@ void cannotUpdateAllLowerPrivilegeKeysWhenUpdatingKeysToStructurallyInvalidKeysS var metadataKey = PrivateKey.generateED25519(); // create a non-fungible token - var tokenId = Objects.requireNonNull( - new TokenCreateTransaction() + var tokenId = Objects.requireNonNull(new TokenCreateTransaction() .setTokenName("Test NFT") .setTokenSymbol("TNFT") .setTokenType(TokenType.NON_FUNGIBLE_UNIQUE) @@ -2423,105 +2581,123 @@ void cannotUpdateAllLowerPrivilegeKeysWhenUpdatingKeysToStructurallyInvalidKeysS .setMetadataKey(metadataKey.getPublicKey()) .execute(testEnv.client) .getReceipt(testEnv.client) - .tokenId - ); - - var tokenInfoBeforeUpdate = new TokenInfoQuery() - .setTokenId(tokenId) - .execute(testEnv.client); - - assertThat(tokenInfoBeforeUpdate.wipeKey.toString()).isEqualTo(wipeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.kycKey.toString()).isEqualTo(kycKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.freezeKey.toString()).isEqualTo(freezeKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.pauseKey.toString()).isEqualTo(pauseKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.supplyKey.toString()).isEqualTo(supplyKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()).isEqualTo(feeScheduleKey.getPublicKey().toString()); - assertThat(tokenInfoBeforeUpdate.metadataKey.toString()).isEqualTo(metadataKey.getPublicKey().toString()); + .tokenId); + + var tokenInfoBeforeUpdate = new TokenInfoQuery().setTokenId(tokenId).execute(testEnv.client); + + assertThat(tokenInfoBeforeUpdate.wipeKey.toString()) + .isEqualTo(wipeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.kycKey.toString()) + .isEqualTo(kycKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.freezeKey.toString()) + .isEqualTo(freezeKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.pauseKey.toString()) + .isEqualTo(pauseKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.supplyKey.toString()) + .isEqualTo(supplyKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.feeScheduleKey.toString()) + .isEqualTo(feeScheduleKey.getPublicKey().toString()); + assertThat(tokenInfoBeforeUpdate.metadataKey.toString()) + .isEqualTo(metadataKey.getPublicKey().toString()); // This key is truly invalid, as all Ed25519 public keys must be 32 bytes long - var structurallyInvalidKey = PublicKey.fromString("000000000000000000000000000000000000000000000000000000000000000000"); + var structurallyInvalidKey = + PublicKey.fromString("000000000000000000000000000000000000000000000000000000000000000000"); // update all of token’s lower-privilege keys // to a structurally invalid key (trying to update keys one by one to check all errors), // signing with an old respective lower-privilege // and setting key verification mode to NO_VALIDATION - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setWipeKey(structurallyInvalidKey) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(wipeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_WIPE_KEY.toString()); - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setKycKey(structurallyInvalidKey) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(kycKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_KYC_KEY.toString()); - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFreezeKey(structurallyInvalidKey) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(freezeKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_FREEZE_KEY.toString()); - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setPauseKey(structurallyInvalidKey) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(pauseKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_PAUSE_KEY.toString()); - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setSupplyKey(structurallyInvalidKey) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(supplyKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_SUPPLY_KEY.toString()); - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setFeeScheduleKey(structurallyInvalidKey) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(feeScheduleKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_CUSTOM_FEE_SCHEDULE_KEY.toString()); - - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TokenUpdateTransaction() - .setTokenId(tokenId) - .setMetadataKey(structurallyInvalidKey) - .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) - .freezeWith(testEnv.client) - .sign(metadataKey) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_METADATA_KEY.toString()); - + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setWipeKey(structurallyInvalidKey) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(wipeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_WIPE_KEY.toString()); + + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setKycKey(structurallyInvalidKey) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(kycKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_KYC_KEY.toString()); + + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFreezeKey(structurallyInvalidKey) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(freezeKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_FREEZE_KEY.toString()); + + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setPauseKey(structurallyInvalidKey) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(pauseKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_PAUSE_KEY.toString()); + + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setSupplyKey(structurallyInvalidKey) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(supplyKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_SUPPLY_KEY.toString()); + + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setFeeScheduleKey(structurallyInvalidKey) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(feeScheduleKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_CUSTOM_FEE_SCHEDULE_KEY.toString()); + + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TokenUpdateTransaction() + .setTokenId(tokenId) + .setMetadataKey(structurallyInvalidKey) + .setKeyVerificationMode(TokenKeyValidation.NO_VALIDATION) + .freezeWith(testEnv.client) + .sign(metadataKey) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_METADATA_KEY.toString()); } } } diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TopicMessageSubmitIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TopicMessageSubmitIntegrationTest.java index e72953265..bdbb7d03f 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TopicMessageSubmitIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TopicMessageSubmitIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + import com.hedera.hashgraph.sdk.PrecheckStatusException; import com.hedera.hashgraph.sdk.Status; import com.hedera.hashgraph.sdk.TopicCreateTransaction; @@ -26,17 +27,12 @@ import com.hedera.hashgraph.sdk.TopicInfoQuery; import com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction; import com.hedera.hashgraph.sdk.Transaction; +import java.util.Objects; import org.bouncycastle.util.encoders.Hex; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Objects; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNoException; - public class TopicMessageSubmitIntegrationTest { @Test @DisplayName("Can submit a topic message") @@ -50,9 +46,7 @@ void canSubmitATopicMessage() throws Exception { var topicId = Objects.requireNonNull(response.getReceipt(testEnv.client).topicId); - var info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + var info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -65,9 +59,7 @@ void canSubmitATopicMessage() throws Exception { .execute(testEnv.client) .getReceipt(testEnv.client); - info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -78,7 +70,6 @@ void canSubmitATopicMessage() throws Exception { .setTopicId(topicId) .execute(testEnv.client) .getReceipt(testEnv.client); - } } @@ -100,9 +91,7 @@ void canSubmitALargeTopicMessage() { Thread.sleep(5000); - var info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + var info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -119,9 +108,7 @@ void canSubmitALargeTopicMessage() { resp.getReceipt(testEnv.client); } - info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -132,7 +119,6 @@ void canSubmitALargeTopicMessage() { .setTopicId(topicId) .execute(testEnv.client) .getReceipt(testEnv.client); - } }); } @@ -153,19 +139,20 @@ void cannotSubmitMessageWhenTopicIDIsNotSet() { var topicId = Objects.requireNonNull(response.getReceipt(testEnv.client).topicId); - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TopicMessageSubmitTransaction() - .setMessage(Contents.BIG_CONTENTS) - .setMaxChunks(15) - .execute(testEnv.client) - .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_TOPIC_ID.toString()); + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TopicMessageSubmitTransaction() + .setMessage(Contents.BIG_CONTENTS) + .setMaxChunks(15) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_TOPIC_ID.toString()); new TopicDeleteTransaction() .setTopicId(topicId) .execute(testEnv.client) .getReceipt(testEnv.client); - } }); } @@ -180,24 +167,25 @@ void cannotSubmitMessageWhenMessageIsNotSet() { try (var testEnv = new IntegrationTestEnv(1)) { var response = new TopicCreateTransaction() - .setAdminKey(testEnv.operatorKey) - .setTopicMemo("[e2e::TopicCreateTransaction]") - .execute(testEnv.client); + .setAdminKey(testEnv.operatorKey) + .setTopicMemo("[e2e::TopicCreateTransaction]") + .execute(testEnv.client); var topicId = Objects.requireNonNull(response.getReceipt(testEnv.client).topicId); - assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> { - new TopicMessageSubmitTransaction() + assertThatExceptionOfType(PrecheckStatusException.class) + .isThrownBy(() -> { + new TopicMessageSubmitTransaction() + .setTopicId(topicId) + .execute(testEnv.client) + .getReceipt(testEnv.client); + }) + .withMessageContaining(Status.INVALID_TOPIC_MESSAGE.toString()); + + new TopicDeleteTransaction() .setTopicId(topicId) .execute(testEnv.client) .getReceipt(testEnv.client); - }).withMessageContaining(Status.INVALID_TOPIC_MESSAGE.toString()); - - new TopicDeleteTransaction() - .setTopicId(topicId) - .execute(testEnv.client) - .getReceipt(testEnv.client); - } }); } @@ -206,7 +194,8 @@ void cannotSubmitMessageWhenMessageIsNotSet() { @DisplayName("Hex Decode Regression Test") @SuppressWarnings("UnusedVariable") void decodeHexRegressionTest() throws Exception { - String binaryHex = "2ac2010a580a130a0b08d38f8f880610a09be91512041899e11c120218041880c2d72f22020878da01330a0418a5a1201210303030303030313632373633373731351a190a130a0b08d38f8f880610a09be91512041899e11c1001180112660a640a20603edaec5d1c974c92cb5bee7b011310c3b84b13dc048424cd6ef146d6a0d4a41a40b6a08f310ee29923e5868aac074468b2bde05da95a806e2f4a4f452177f129ca0abae7831e595b5beaa1c947e2cb71201642bab33fece5184b04547afc40850a"; + String binaryHex = + "2ac2010a580a130a0b08d38f8f880610a09be91512041899e11c120218041880c2d72f22020878da01330a0418a5a1201210303030303030313632373633373731351a190a130a0b08d38f8f880610a09be91512041899e11c1001180112660a640a20603edaec5d1c974c92cb5bee7b011310c3b84b13dc048424cd6ef146d6a0d4a41a40b6a08f310ee29923e5868aac074468b2bde05da95a806e2f4a4f452177f129ca0abae7831e595b5beaa1c947e2cb71201642bab33fece5184b04547afc40850a"; byte[] transactionBytes = Hex.decode(binaryHex); var transaction = Objects.requireNonNull(Transaction.fromBytes(transactionBytes)); diff --git a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TransactionIntegrationTest.java b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TransactionIntegrationTest.java index ba175b574..2d0122186 100644 --- a/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TransactionIntegrationTest.java +++ b/sdk/src/testIntegration/java/com/hedera/hashgraph/sdk/test/integration/TransactionIntegrationTest.java @@ -1,8 +1,5 @@ -/*- - * - * Hedera Java SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC +/* + * Copyright (C) 2020-2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +12,14 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * */ + package com.hedera.hashgraph.sdk.test.integration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + import com.google.protobuf.ByteString; import com.hedera.hashgraph.sdk.AccountCreateTransaction; import com.hedera.hashgraph.sdk.AccountDeleteTransaction; @@ -50,17 +51,12 @@ import com.hedera.hashgraph.sdk.proto.TransactionID; import com.hedera.hashgraph.sdk.proto.TransactionList; import com.hedera.hashgraph.sdk.proto.TransferList; +import java.util.Arrays; import java.util.Objects; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatNoException; - public class TransactionIntegrationTest { @Test @@ -71,9 +67,9 @@ void transactionHashInTransactionRecordIsEqualToTheDerivedTransactionHash() thro var key = PrivateKey.generateED25519(); var transaction = new AccountCreateTransaction() - .setKey(key) - .freezeWith(testEnv.client) - .signWithOperator(testEnv.client); + .setKey(key) + .freezeWith(testEnv.client) + .signWithOperator(testEnv.client); var expectedHash = transaction.getTransactionHashPerNode(); @@ -92,7 +88,6 @@ var record = response.getRecord(testEnv.client); assertThat(transactionId.getRecord(testEnv.client)).isNotNull(); assertThat(transactionId.getRecordAsync(testEnv.client).get()).isNotNull(); } - } /** @@ -107,22 +102,20 @@ void canSerializeDeserializeCompareFields() throws Exception { var adminKey = PrivateKey.generateECDSA(); var publicKey = adminKey.getPublicKey(); - var accountCreateTransaction = new AccountCreateTransaction() - .setKey(publicKey) - .setInitialBalance(new Hbar(1L)); + var accountCreateTransaction = + new AccountCreateTransaction().setKey(publicKey).setInitialBalance(new Hbar(1L)); var expectedNodeAccountIds = accountCreateTransaction.getNodeAccountIds(); var expectedBalance = new Hbar(1L); var transactionBytesSerialized = accountCreateTransaction.toBytes(); - AccountCreateTransaction accountCreateTransactionDeserialized = (AccountCreateTransaction) Transaction - .fromBytes(transactionBytesSerialized); + AccountCreateTransaction accountCreateTransactionDeserialized = + (AccountCreateTransaction) Transaction.fromBytes(transactionBytesSerialized); assertThat(expectedNodeAccountIds).isEqualTo(accountCreateTransactionDeserialized.getNodeAccountIds()); assertThat(expectedBalance).isEqualTo(accountCreateTransactionDeserialized.getInitialBalance()); - assertThatExceptionOfType(IllegalStateException.class).isThrownBy( - accountCreateTransactionDeserialized::getTransactionId); - + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(accountCreateTransactionDeserialized::getTransactionId); } } @@ -131,7 +124,8 @@ void canSerializeDeserializeCompareFields() throws Exception { * @url https://hips.hedera.com/hip/hip-745 */ @Test - @DisplayName("incomplete transaction with node account ids can be serialized into bytes, deserialized and be equal to the original one") + @DisplayName( + "incomplete transaction with node account ids can be serialized into bytes, deserialized and be equal to the original one") void canSerializeWithNodeAccountIdsDeserializeCompareFields() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { @@ -149,15 +143,16 @@ void canSerializeWithNodeAccountIdsDeserializeCompareFields() throws Exception { var expectedBalance = new Hbar(1L); var transactionBytesSerialized = accountCreateTransaction.toBytes(); - AccountCreateTransaction accountCreateTransactionDeserialized = (AccountCreateTransaction) Transaction - .fromBytes(transactionBytesSerialized); + AccountCreateTransaction accountCreateTransactionDeserialized = + (AccountCreateTransaction) Transaction.fromBytes(transactionBytesSerialized); assertThat(expectedNodeAccountIds.size()) - .isEqualTo(accountCreateTransactionDeserialized.getNodeAccountIds().size()); + .isEqualTo(accountCreateTransactionDeserialized + .getNodeAccountIds() + .size()); assertThat(expectedBalance).isEqualTo(accountCreateTransactionDeserialized.getInitialBalance()); - assertThatExceptionOfType(IllegalStateException.class).isThrownBy( - accountCreateTransactionDeserialized::getTransactionId); - + assertThatExceptionOfType(IllegalStateException.class) + .isThrownBy(accountCreateTransactionDeserialized::getTransactionId); } } @@ -173,18 +168,15 @@ void canSerializeDeserializeAndExecuteIncompleteTransaction() throws Exception { var adminKey = PrivateKey.generateECDSA(); var publicKey = adminKey.getPublicKey(); - var accountCreateTransaction = new AccountCreateTransaction() - .setKey(publicKey) - .setInitialBalance(new Hbar(1L)); + var accountCreateTransaction = + new AccountCreateTransaction().setKey(publicKey).setInitialBalance(new Hbar(1L)); var transactionBytesSerialized = accountCreateTransaction.toBytes(); - AccountCreateTransaction accountCreateTransactionDeserialized = (AccountCreateTransaction) Transaction - .fromBytes( - transactionBytesSerialized); + AccountCreateTransaction accountCreateTransactionDeserialized = + (AccountCreateTransaction) Transaction.fromBytes(transactionBytesSerialized); - var txReceipt = accountCreateTransactionDeserialized - .execute(testEnv.client) - .getReceipt(testEnv.client); + var txReceipt = + accountCreateTransactionDeserialized.execute(testEnv.client).getReceipt(testEnv.client); new AccountDeleteTransaction() .setAccountId(txReceipt.accountId) @@ -192,7 +184,6 @@ void canSerializeDeserializeAndExecuteIncompleteTransaction() throws Exception { .freezeWith(testEnv.client) .sign(adminKey) .execute(testEnv.client); - } } @@ -216,13 +207,11 @@ void canSerializeDeserializeAndExecuteIncompleteTransactionWithNodeAccountIds() .setInitialBalance(new Hbar(1L)); var transactionBytesSerialized = accountCreateTransaction.toBytes(); - AccountCreateTransaction accountCreateTransactionDeserialized = (AccountCreateTransaction) Transaction - .fromBytes( - transactionBytesSerialized); + AccountCreateTransaction accountCreateTransactionDeserialized = + (AccountCreateTransaction) Transaction.fromBytes(transactionBytesSerialized); - var txReceipt = accountCreateTransactionDeserialized - .execute(testEnv.client) - .getReceipt(testEnv.client); + var txReceipt = + accountCreateTransactionDeserialized.execute(testEnv.client).getReceipt(testEnv.client); new AccountDeleteTransaction() .setAccountId(txReceipt.accountId) @@ -230,7 +219,6 @@ void canSerializeDeserializeAndExecuteIncompleteTransactionWithNodeAccountIds() .freezeWith(testEnv.client) .sign(adminKey) .execute(testEnv.client); - } } @@ -246,15 +234,14 @@ void canSerializeDeserializeEditExecuteCompareFields() throws Exception { var adminKey = PrivateKey.generateECDSA(); var publicKey = adminKey.getPublicKey(); - var accountCreateTransaction = new AccountCreateTransaction() - .setKey(publicKey); + var accountCreateTransaction = new AccountCreateTransaction().setKey(publicKey); var expectedBalance = new Hbar(1L); var nodeAccountIds = testEnv.client.getNetwork().values().stream().toList(); var transactionBytesSerialized = accountCreateTransaction.toBytes(); - AccountCreateTransaction accountCreateTransactionDeserialized = (AccountCreateTransaction) Transaction - .fromBytes(transactionBytesSerialized); + AccountCreateTransaction accountCreateTransactionDeserialized = + (AccountCreateTransaction) Transaction.fromBytes(transactionBytesSerialized); var txReceipt = accountCreateTransactionDeserialized .setInitialBalance(new Hbar(1L)) @@ -271,7 +258,6 @@ void canSerializeDeserializeEditExecuteCompareFields() throws Exception { .freezeWith(testEnv.client) .sign(adminKey) .execute(testEnv.client); - } } @@ -280,7 +266,8 @@ void canSerializeDeserializeEditExecuteCompareFields() throws Exception { * @url https://hips.hedera.com/hip/hip-745 */ @Test - @DisplayName("incomplete transaction with node account ids can be serialized into bytes, deserialized, edited and executed") + @DisplayName( + "incomplete transaction with node account ids can be serialized into bytes, deserialized, edited and executed") void canSerializeDeserializeEditExecuteCompareFieldsIncompleteTransactionWithNodeAccountIds() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { @@ -296,8 +283,8 @@ void canSerializeDeserializeEditExecuteCompareFieldsIncompleteTransactionWithNod var expectedBalance = new Hbar(1L); var transactionBytesSerialized = accountCreateTransaction.toBytes(); - AccountCreateTransaction accountCreateTransactionDeserialized = (AccountCreateTransaction) Transaction - .fromBytes(transactionBytesSerialized); + AccountCreateTransaction accountCreateTransactionDeserialized = + (AccountCreateTransaction) Transaction.fromBytes(transactionBytesSerialized); var txReceipt = accountCreateTransactionDeserialized .setInitialBalance(new Hbar(1L)) @@ -313,7 +300,6 @@ void canSerializeDeserializeEditExecuteCompareFieldsIncompleteTransactionWithNod .freezeWith(testEnv.client) .sign(adminKey) .execute(testEnv.client); - } } @@ -348,14 +334,14 @@ void canFreezeSignSerializeDeserializeReserializeAndExecute() throws Exception { .sign(adminKey); var transactionBytesSerialized = accountCreateTransaction.toBytes(); - AccountCreateTransaction accountCreateTransactionDeserialized = (AccountCreateTransaction) Transaction - .fromBytes(transactionBytesSerialized); + AccountCreateTransaction accountCreateTransactionDeserialized = + (AccountCreateTransaction) Transaction.fromBytes(transactionBytesSerialized); var transactionBytesReserialized = accountCreateTransactionDeserialized.toBytes(); assertThat(transactionBytesSerialized).isEqualTo(transactionBytesReserialized); - AccountCreateTransaction accountCreateTransactionReserialized = (AccountCreateTransaction) Transaction - .fromBytes(transactionBytesReserialized); + AccountCreateTransaction accountCreateTransactionReserialized = + (AccountCreateTransaction) Transaction.fromBytes(transactionBytesReserialized); var txResponse = accountCreateTransactionReserialized.execute(testEnv.client); @@ -367,7 +353,6 @@ void canFreezeSignSerializeDeserializeReserializeAndExecute() throws Exception { .freezeWith(testEnv.client) .sign(adminKey) .execute(testEnv.client); - } } @@ -405,10 +390,7 @@ var record = response.getRecord(testEnv.client); var deleteTransaction2 = Transaction.fromBytes(updateBytes); - deleteTransaction2 - .addSignature(key.getPublicKey(), sig1) - .execute(testEnv.client); - + deleteTransaction2.addSignature(key.getPublicKey(), sig1).execute(testEnv.client); } } @@ -417,7 +399,8 @@ var record = response.getRecord(testEnv.client); * @url https://hips.hedera.com/hip/hip-745 */ @Test - @DisplayName("file append chunked transaction can be frozen, signed, serialized into bytes, deserialized and be equal to the original one") + @DisplayName( + "file append chunked transaction can be frozen, signed, serialized into bytes, deserialized and be equal to the original one") void canFreezeSignSerializeDeserializeAndCompareFileAppendChunkedTransaction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { @@ -432,9 +415,7 @@ void canFreezeSignSerializeDeserializeAndCompareFileAppendChunkedTransaction() t Thread.sleep(5000); - var info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); @@ -450,12 +431,11 @@ void canFreezeSignSerializeDeserializeAndCompareFileAppendChunkedTransaction() t .sign(privateKey); var transactionBytesSerialized = fileAppendTransaction.toBytes(); - FileAppendTransaction fileAppendTransactionDeserialized = (FileAppendTransaction) Transaction - .fromBytes(transactionBytesSerialized); + FileAppendTransaction fileAppendTransactionDeserialized = + (FileAppendTransaction) Transaction.fromBytes(transactionBytesSerialized); var transactionBytesReserialized = fileAppendTransactionDeserialized.toBytes(); assertThat(transactionBytesSerialized).isEqualTo(transactionBytesReserialized); - } } @@ -464,7 +444,8 @@ void canFreezeSignSerializeDeserializeAndCompareFileAppendChunkedTransaction() t * @url https://hips.hedera.com/hip/hip-745 */ @Test - @DisplayName("incomplete file append chunked transaction can be serialized into bytes, deserialized, edited and executed") + @DisplayName( + "incomplete file append chunked transaction can be serialized into bytes, deserialized, edited and executed") void canSerializeDeserializeExecuteFileAppendChunkedTransaction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { @@ -477,9 +458,7 @@ void canSerializeDeserializeExecuteFileAppendChunkedTransaction() throws Excepti Thread.sleep(5000); - var info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); @@ -488,27 +467,20 @@ void canSerializeDeserializeExecuteFileAppendChunkedTransaction() throws Excepti assertThat(info.keys.getThreshold()).isNull(); assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey)); - var fileAppendTransaction = new FileAppendTransaction() - .setFileId(fileId) - .setContents(Contents.BIG_CONTENTS); + var fileAppendTransaction = + new FileAppendTransaction().setFileId(fileId).setContents(Contents.BIG_CONTENTS); var transactionBytesSerialized = fileAppendTransaction.toBytes(); - FileAppendTransaction fileAppendTransactionDeserialized = (FileAppendTransaction) Transaction - .fromBytes(transactionBytesSerialized); + FileAppendTransaction fileAppendTransactionDeserialized = + (FileAppendTransaction) Transaction.fromBytes(transactionBytesSerialized); - fileAppendTransactionDeserialized - .execute(testEnv.client) - .getReceipt(testEnv.client); + fileAppendTransactionDeserialized.execute(testEnv.client).getReceipt(testEnv.client); - var contents = new FileContentsQuery() - .setFileId(fileId) - .execute(testEnv.client); + var contents = new FileContentsQuery().setFileId(fileId).execute(testEnv.client); assertThat(contents.toStringUtf8()).isEqualTo("[e2e::FileCreateTransaction]" + Contents.BIG_CONTENTS); - info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(13522); @@ -521,7 +493,6 @@ void canSerializeDeserializeExecuteFileAppendChunkedTransaction() throws Excepti .setFileId(fileId) .execute(testEnv.client) .getReceipt(testEnv.client); - } } @@ -530,7 +501,8 @@ void canSerializeDeserializeExecuteFileAppendChunkedTransaction() throws Excepti * @url https://hips.hedera.com/hip/hip-745 */ @Test - @DisplayName("incomplete file append chunked transaction with node account ids can be serialized into bytes, deserialized, edited and executed") + @DisplayName( + "incomplete file append chunked transaction with node account ids can be serialized into bytes, deserialized, edited and executed") void canSerializeDeserializeExecuteIncompleteFileAppendChunkedTransactionWithNodeAccountIds() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { @@ -545,9 +517,7 @@ void canSerializeDeserializeExecuteIncompleteFileAppendChunkedTransactionWithNod Thread.sleep(5000); - var info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(28); @@ -562,23 +532,19 @@ void canSerializeDeserializeExecuteIncompleteFileAppendChunkedTransactionWithNod .setContents(Contents.BIG_CONTENTS); var transactionBytesSerialized = fileAppendTransaction.toBytes(); - FileAppendTransaction fileAppendTransactionDeserialized = (FileAppendTransaction) Transaction - .fromBytes(transactionBytesSerialized); + FileAppendTransaction fileAppendTransactionDeserialized = + (FileAppendTransaction) Transaction.fromBytes(transactionBytesSerialized); fileAppendTransactionDeserialized .setTransactionId(TransactionId.generate(testEnv.client.getOperatorAccountId())) .execute(testEnv.client) .getReceipt(testEnv.client); - var contents = new FileContentsQuery() - .setFileId(fileId) - .execute(testEnv.client); + var contents = new FileContentsQuery().setFileId(fileId).execute(testEnv.client); assertThat(contents.toStringUtf8()).isEqualTo("[e2e::FileCreateTransaction]" + Contents.BIG_CONTENTS); - info = new FileInfoQuery() - .setFileId(fileId) - .execute(testEnv.client); + info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client); assertThat(info.fileId).isEqualTo(fileId); assertThat(info.size).isEqualTo(13522); @@ -591,7 +557,6 @@ void canSerializeDeserializeExecuteIncompleteFileAppendChunkedTransactionWithNod .setFileId(fileId) .execute(testEnv.client) .getReceipt(testEnv.client); - } } @@ -600,7 +565,8 @@ void canSerializeDeserializeExecuteIncompleteFileAppendChunkedTransactionWithNod * @url https://hips.hedera.com/hip/hip-745 */ @Test - @DisplayName("topic message submit chunked transaction can be frozen, signed, serialized into bytes, deserialized and be equal to the original one") + @DisplayName( + "topic message submit chunked transaction can be frozen, signed, serialized into bytes, deserialized and be equal to the original one") void canFreezeSignSerializeDeserializeAndCompareTopicMessageSubmitChunkedTransaction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { @@ -615,9 +581,7 @@ void canFreezeSignSerializeDeserializeAndCompareTopicMessageSubmitChunkedTransac Thread.sleep(5000); - var info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + var info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -632,8 +596,8 @@ void canFreezeSignSerializeDeserializeAndCompareTopicMessageSubmitChunkedTransac .sign(privateKey); var transactionBytesSerialized = topicMessageSubmitTransaction.toBytes(); - TopicMessageSubmitTransaction fileAppendTransactionDeserialized = (TopicMessageSubmitTransaction) Transaction - .fromBytes(transactionBytesSerialized); + TopicMessageSubmitTransaction fileAppendTransactionDeserialized = + (TopicMessageSubmitTransaction) Transaction.fromBytes(transactionBytesSerialized); var transactionBytesReserialized = fileAppendTransactionDeserialized.toBytes(); assertThat(transactionBytesSerialized).isEqualTo(transactionBytesReserialized); @@ -642,7 +606,6 @@ void canFreezeSignSerializeDeserializeAndCompareTopicMessageSubmitChunkedTransac .setTopicId(topicId) .execute(testEnv.client) .getReceipt(testEnv.client); - } } @@ -651,7 +614,8 @@ void canFreezeSignSerializeDeserializeAndCompareTopicMessageSubmitChunkedTransac * @url https://hips.hedera.com/hip/hip-745 */ @Test - @DisplayName("incomplete topic message submit chunked transaction can be serialized into bytes, deserialized, edited and executed") + @DisplayName( + "incomplete topic message submit chunked transaction can be serialized into bytes, deserialized, edited and executed") void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransaction() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { @@ -664,9 +628,7 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio Thread.sleep(5000); - var info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + var info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -679,8 +641,8 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio .setMessage(Contents.BIG_CONTENTS); var transactionBytesSerialized = topicMessageSubmitTransaction.toBytes(); - TopicMessageSubmitTransaction topicMessageSubmitTransactionDeserialized = (TopicMessageSubmitTransaction) Transaction - .fromBytes(transactionBytesSerialized); + TopicMessageSubmitTransaction topicMessageSubmitTransactionDeserialized = + (TopicMessageSubmitTransaction) Transaction.fromBytes(transactionBytesSerialized); var responses = topicMessageSubmitTransactionDeserialized.executeAll(testEnv.client); @@ -688,9 +650,7 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio resp.getReceipt(testEnv.client); } - info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -701,7 +661,6 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio .setTopicId(topicId) .execute(testEnv.client) .getReceipt(testEnv.client); - } } @@ -710,7 +669,8 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio * @url https://hips.hedera.com/hip/hip-745 */ @Test - @DisplayName("incomplete topic message submit chunked transaction with node account ids can be serialized into bytes, deserialized, edited and executed") + @DisplayName( + "incomplete topic message submit chunked transaction with node account ids can be serialized into bytes, deserialized, edited and executed") void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactionWithNodeAccountIds() throws Exception { try (var testEnv = new IntegrationTestEnv(1)) { @@ -726,9 +686,7 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio Thread.sleep(5000); - var info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + var info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -742,8 +700,8 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio .setMessage(Contents.BIG_CONTENTS); var transactionBytesSerialized = topicMessageSubmitTransaction.toBytes(); - TopicMessageSubmitTransaction topicMessageSubmitTransactionDeserialized = (TopicMessageSubmitTransaction) Transaction - .fromBytes(transactionBytesSerialized); + TopicMessageSubmitTransaction topicMessageSubmitTransactionDeserialized = + (TopicMessageSubmitTransaction) Transaction.fromBytes(transactionBytesSerialized); var responses = topicMessageSubmitTransactionDeserialized.executeAll(testEnv.client); @@ -751,9 +709,7 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio resp.getReceipt(testEnv.client); } - info = new TopicInfoQuery() - .setTopicId(topicId) - .execute(testEnv.client); + info = new TopicInfoQuery().setTopicId(topicId).execute(testEnv.client); assertThat(info.topicId).isEqualTo(topicId); assertThat(info.topicMemo).isEqualTo("[e2e::TopicCreateTransaction]"); @@ -764,7 +720,6 @@ void canSerializeDeserializeExecuteIncompleteTopicMessageSubmitChunkedTransactio .setTopicId(topicId) .execute(testEnv.client) .getReceipt(testEnv.client); - } } @@ -798,32 +753,29 @@ void transactionFromToBytes2() { .build()) .setTransactionFee(200_000_000) .setTransactionValidDuration( - Duration.newBuilder() - .setSeconds(120) - .build()) + Duration.newBuilder().setSeconds(120).build()) .setGenerateRecord(false) .setMemo("") - .setCryptoTransfer( - CryptoTransferTransactionBody.newBuilder() - .setTransfers(TransferList.newBuilder() - .addAccountAmounts(AccountAmount.newBuilder() - .setAccountID(AccountID.newBuilder() - .setAccountNum(47439) - .setRealmNum(0) - .setShardNum(0) - .build()) - .setAmount(10) + .setCryptoTransfer(CryptoTransferTransactionBody.newBuilder() + .setTransfers(TransferList.newBuilder() + .addAccountAmounts(AccountAmount.newBuilder() + .setAccountID(AccountID.newBuilder() + .setAccountNum(47439) + .setRealmNum(0) + .setShardNum(0) .build()) - .addAccountAmounts(AccountAmount.newBuilder() - .setAccountID(AccountID.newBuilder() - .setAccountNum(542348) - .setRealmNum(0) - .setShardNum(0) - .build()) - .setAmount(-10) + .setAmount(10) + .build()) + .addAccountAmounts(AccountAmount.newBuilder() + .setAccountID(AccountID.newBuilder() + .setAccountNum(542348) + .setRealmNum(0) + .setShardNum(0) .build()) + .setAmount(-10) .build()) - .build()); + .build()) + .build()); var bodyBytes = transactionBodyBuilder.build().toByteString(); var key1 = PrivateKey.fromString( @@ -879,14 +831,17 @@ void transactionFromToBytes2() { .addTransactionList(com.hedera.hashgraph.sdk.proto.Transaction.newBuilder() .setSignedTransactionBytes(byts) .build()) - .build().toByteString(); + .build() + .toByteString(); var tx = (TransferTransaction) Transaction.fromBytes(byts.toByteArray()); try (var testEnv = new IntegrationTestEnv(1)) { - assertThat(tx.getHbarTransfers().get(new AccountId(542348)).toTinybars()).isEqualTo(-10); - assertThat(tx.getHbarTransfers().get(new AccountId(47439)).toTinybars()).isEqualTo(10); + assertThat(tx.getHbarTransfers().get(new AccountId(542348)).toTinybars()) + .isEqualTo(-10); + assertThat(tx.getHbarTransfers().get(new AccountId(47439)).toTinybars()) + .isEqualTo(10); assertThat(tx.getNodeAccountIds()).isNotNull(); assertThat(tx.getNodeAccountIds().size()).isEqualTo(1); @@ -907,7 +862,6 @@ void transactionFromToBytes2() { var resp = tx.execute(testEnv.client); resp.getReceipt(testEnv.client); - } }); }