diff --git a/examples/src/main/java/AccountAliasExample.java b/examples/src/main/java/AccountAliasExample.java index 77317c7b7..4191c19e9 100644 --- a/examples/src/main/java/AccountAliasExample.java +++ b/examples/src/main/java/AccountAliasExample.java @@ -113,10 +113,6 @@ public static void main(String[] args) .execute(client) .getReceipt(client); - // `AccountBalanceQuery` and `AccountInfoQuery` also query the mirror node. - // Wait until the mirror node is updated with the new data. - Thread.sleep(5000); - AccountBalance balance = new AccountBalanceQuery() .setAccountId(aliasAccountId) .execute(client); diff --git a/examples/src/main/java/AccountAllowanceExample.java b/examples/src/main/java/AccountAllowanceExample.java index 780aef2f3..79ec36e0a 100644 --- a/examples/src/main/java/AccountAllowanceExample.java +++ b/examples/src/main/java/AccountAllowanceExample.java @@ -111,11 +111,7 @@ private AccountAllowanceExample() printBalances(); } - private void printBalances() throws PrecheckStatusException, TimeoutException, InterruptedException { - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - + private void printBalances() throws PrecheckStatusException, TimeoutException { System.out.println( "Alice's balance: " + new AccountBalanceQuery().setAccountId(aliceId).execute(client).hbars @@ -130,8 +126,7 @@ private void printBalances() throws PrecheckStatusException, TimeoutException, I ); } - private void demonstrateAllowances() - throws PrecheckStatusException, TimeoutException, ReceiptStatusException, InterruptedException { + private void demonstrateAllowances() throws PrecheckStatusException, TimeoutException, ReceiptStatusException { System.out.println("Approving an allowance of 2 Hbar with owner Alice and spender Bob"); new AccountAllowanceApproveTransaction() diff --git a/examples/src/main/java/AccountCreateWithHtsExample.java b/examples/src/main/java/AccountCreateWithHtsExample.java index 87d9f4c2a..67c3192bd 100644 --- a/examples/src/main/java/AccountCreateWithHtsExample.java +++ b/examples/src/main/java/AccountCreateWithHtsExample.java @@ -142,11 +142,6 @@ public static void main(String[] args) throws Exception { System.out.println("Current owner account id: " + nftOwnerAccountId); // Step 6 - Show the new account ID owns the NFT - - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - String accountId = new AccountInfoQuery() .setAccountId(aliasAccountId) .execute(client) @@ -213,11 +208,6 @@ public static void main(String[] args) throws Exception { tokenTransferSubmit.getReceipt(client); // Step 4 - Return the new account ID in the child record - - // `AccountBalanceQuery` and `AccountInfoQuery` also query the mirror node. - // Wait until the mirror node is updated with the new data. - Thread.sleep(5000); - String accountId2 = new AccountInfoQuery() .setAccountId(aliasAccountId2) .execute(client) diff --git a/examples/src/main/java/AutoCreateAccountTransferTransactionExample.java b/examples/src/main/java/AutoCreateAccountTransferTransactionExample.java index a40d90a56..0514bc0b3 100644 --- a/examples/src/main/java/AutoCreateAccountTransferTransactionExample.java +++ b/examples/src/main/java/AutoCreateAccountTransferTransactionExample.java @@ -104,10 +104,6 @@ public static void main(String[] args) throws Exception { - The alias property of the account does not have the public address - Referred to as a hollow account */ - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountInfo accountInfo = new AccountInfoQuery() .setAccountId(newAccountId) .execute(client); diff --git a/examples/src/main/java/CreateAccountThresholdKeyExample.java b/examples/src/main/java/CreateAccountThresholdKeyExample.java index cabf01e00..cbddfef45 100644 --- a/examples/src/main/java/CreateAccountThresholdKeyExample.java +++ b/examples/src/main/java/CreateAccountThresholdKeyExample.java @@ -103,10 +103,6 @@ public static void main(String[] args) // (important!) wait for the transfer to go to consensus transferTransactionResponse.getReceipt(client); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - Hbar balanceAfter = new AccountBalanceQuery() .setAccountId(newAccountId) .execute(client) diff --git a/examples/src/main/java/CreateAccountWithAliasAndReceiverSignatureRequiredExample.java b/examples/src/main/java/CreateAccountWithAliasAndReceiverSignatureRequiredExample.java index 34da6b460..4916faa86 100644 --- a/examples/src/main/java/CreateAccountWithAliasAndReceiverSignatureRequiredExample.java +++ b/examples/src/main/java/CreateAccountWithAliasAndReceiverSignatureRequiredExample.java @@ -77,10 +77,6 @@ public static void main(String[] args) * Step 6 * Get the `AccountInfo` and show that the account has contractAccountId */ - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountInfo accountInfo = new AccountInfoQuery() .setAccountId(newAccountId) .execute(client); diff --git a/examples/src/main/java/CreateAccountWithAliasExample.java b/examples/src/main/java/CreateAccountWithAliasExample.java index b6890d994..e4e49def1 100644 --- a/examples/src/main/java/CreateAccountWithAliasExample.java +++ b/examples/src/main/java/CreateAccountWithAliasExample.java @@ -78,10 +78,6 @@ public static void main(String[] args) throws Exception { * Step 6 * Get the `AccountInfo` and show that the account has contractAccountId */ - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountInfo accountInfo = new AccountInfoQuery() .setAccountId(newAccountId) .execute(client); diff --git a/examples/src/main/java/CustomFeesExample.java b/examples/src/main/java/CustomFeesExample.java index d60b11acf..ce7d6ec97 100644 --- a/examples/src/main/java/CustomFeesExample.java +++ b/examples/src/main/java/CustomFeesExample.java @@ -179,10 +179,6 @@ public static void main(String[] args) .execute(client) .getReceipt(client); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - Hbar aliceHbar1 = new AccountBalanceQuery() .setAccountId(aliceId) .execute(client) @@ -197,10 +193,6 @@ public static void main(String[] args) .execute(client) .getRecord(client); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - Hbar aliceHbar2 = new AccountBalanceQuery() .setAccountId(aliceId) .execute(client) @@ -259,10 +251,6 @@ public static void main(String[] args) .execute(client) .getRecord(client); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - Map aliceTokens4 = new AccountBalanceQuery() .setAccountId(aliceId) .execute(client) @@ -297,10 +285,6 @@ public static void main(String[] args) .execute(client) .getReceipt(client); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - // wipe token on created accounts Map charlieTokensBeforeWipe = new AccountBalanceQuery() .setAccountId(charlieId) diff --git a/examples/src/main/java/ExemptCustomFeesExample.java b/examples/src/main/java/ExemptCustomFeesExample.java index c42a098c2..17d99728a 100644 --- a/examples/src/main/java/ExemptCustomFeesExample.java +++ b/examples/src/main/java/ExemptCustomFeesExample.java @@ -172,10 +172,6 @@ public static void main(String[] args) throws TimeoutException, PrecheckStatusEx * of the token that was created was not charged a custom fee in the transfer */ - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - Long firstAccountBalanceAfter = new AccountBalanceQuery() .setAccountId(firstAccountId) .execute(client) diff --git a/examples/src/main/java/MultiAppTransferExample.java b/examples/src/main/java/MultiAppTransferExample.java index 7f3966114..072ea95e5 100644 --- a/examples/src/main/java/MultiAppTransferExample.java +++ b/examples/src/main/java/MultiAppTransferExample.java @@ -63,8 +63,7 @@ public final class MultiAppTransferExample { private MultiAppTransferExample() { } - public static void main(String[] args) - throws ReceiptStatusException, TimeoutException, PrecheckStatusException, InvalidProtocolBufferException, InterruptedException { + public static void main(String[] args) throws ReceiptStatusException, TimeoutException, PrecheckStatusException, InvalidProtocolBufferException { // the exchange creates an account for the user to transfer funds to AccountId exchangeAccountId = new AccountCreateTransaction() // the exchange only accepts transfers that it validates through a side channel (e.g. REST API) @@ -121,10 +120,6 @@ public static void main(String[] args) // (important!) wait for consensus by querying for the receipt transactionResponse.getReceipt(client); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - Hbar senderBalanceAfter = new AccountBalanceQuery() .setAccountId(userAccountId) .execute(client) diff --git a/examples/src/main/java/ScheduledTransactionMultiSigThresholdExample.java b/examples/src/main/java/ScheduledTransactionMultiSigThresholdExample.java index 5d0feae0a..34a980e96 100644 --- a/examples/src/main/java/ScheduledTransactionMultiSigThresholdExample.java +++ b/examples/src/main/java/ScheduledTransactionMultiSigThresholdExample.java @@ -91,10 +91,6 @@ public static void main(String[] args) System.out.println("3-of-4 multi-sig account ID: " + multiSigAccountId); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountBalance balance = new AccountBalanceQuery() .setAccountId(multiSigAccountId) .execute(client); diff --git a/examples/src/main/java/ScheduledTransferExample.java b/examples/src/main/java/ScheduledTransferExample.java index c16f7c32b..645501db5 100644 --- a/examples/src/main/java/ScheduledTransferExample.java +++ b/examples/src/main/java/ScheduledTransferExample.java @@ -101,10 +101,6 @@ public static void main(String[] args) System.out.println("Alice's ID: " + client.getOperatorAccountId()); System.out.println("Bob's ID: " + bobsId); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountBalance bobsInitialBalance = new AccountBalanceQuery() .setAccountId(bobsId) .execute(client); @@ -145,9 +141,6 @@ public static void main(String[] args) * Bob's balance should be unchanged. The transfer has been scheduled, but it hasn't been executed yet * because it requires Bob's signature. */ - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); AccountBalance bobsBalanceAfterSchedule = new AccountBalanceQuery() .setAccountId(bobsId) .execute(client); @@ -186,10 +179,6 @@ public static void main(String[] args) .execute(client) .getReceipt(client); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountBalance balanceAfterSigning = new AccountBalanceQuery() .setAccountId(bobsId) .execute(client); diff --git a/examples/src/main/java/StakingExample.java b/examples/src/main/java/StakingExample.java index 71671235f..c6e7825e4 100644 --- a/examples/src/main/java/StakingExample.java +++ b/examples/src/main/java/StakingExample.java @@ -85,11 +85,6 @@ public static void main(String[] args) // Query the account info, it should show the staked account ID // to be 0.0.3 just like what we set it to - - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountInfo info = new AccountInfoQuery() .setAccountId(newAccountId) .execute(client); diff --git a/examples/src/main/java/StakingWithUpdateExample.java b/examples/src/main/java/StakingWithUpdateExample.java index e39de6411..9023052e6 100644 --- a/examples/src/main/java/StakingWithUpdateExample.java +++ b/examples/src/main/java/StakingWithUpdateExample.java @@ -86,11 +86,6 @@ public static void main(String[] args) // Query the account info, it should show the staked account ID // to be 0.0.3 just like what we set it to - - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountInfo info = new AccountInfoQuery() .setAccountId(newAccountId) .execute(client); @@ -109,11 +104,6 @@ public static void main(String[] args) // Query the account info, it should show the staked account ID // to be 0.0.3 just like what we set it to - - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - info = new AccountInfoQuery() .setAccountId(newAccountId) .execute(client); diff --git a/examples/src/main/java/TransactionSerializationExample.java b/examples/src/main/java/TransactionSerializationExample.java index 892939a3e..71018e8f3 100644 --- a/examples/src/main/java/TransactionSerializationExample.java +++ b/examples/src/main/java/TransactionSerializationExample.java @@ -64,10 +64,6 @@ public static void main(String[] args) throws Exception { System.out.println("transferred " + amount + "..."); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - Hbar senderBalanceAfter = new AccountBalanceQuery() .setAccountId(OPERATOR_ID) .execute(client) diff --git a/examples/src/main/java/TransferCryptoExample.java b/examples/src/main/java/TransferCryptoExample.java index d585ac014..d6401d01c 100644 --- a/examples/src/main/java/TransferCryptoExample.java +++ b/examples/src/main/java/TransferCryptoExample.java @@ -82,10 +82,6 @@ public static void main(String[] args) System.out.println("transferred " + amount + "..."); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - Hbar senderBalanceAfter = new AccountBalanceQuery() .setAccountId(OPERATOR_ID) .execute(client) diff --git a/examples/src/main/java/TransferUsingEvmAddressExample.java b/examples/src/main/java/TransferUsingEvmAddressExample.java index 7d8abd5bc..20d50bf14 100644 --- a/examples/src/main/java/TransferUsingEvmAddressExample.java +++ b/examples/src/main/java/TransferUsingEvmAddressExample.java @@ -90,10 +90,6 @@ public static void main(String[] args) throws PrecheckStatusException, TimeoutEx * Step 6 * Get the `AccountInfo` on the new account and show it is a hollow account by not having a public key */ - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountInfo accountInfo = new AccountInfoQuery() .setAccountId(newAccountId) .execute(client); @@ -124,10 +120,6 @@ public static void main(String[] args) throws PrecheckStatusException, TimeoutEx * Step 9 * Get the `AccountInfo` of the account and show the account is now a complete account by returning the public key on the account */ - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountInfo accountInfo2 = new AccountInfoQuery() .setAccountId(newAccountId) .execute(client); diff --git a/examples/src/main/java/UpdateAccountPublicKeyExample.java b/examples/src/main/java/UpdateAccountPublicKeyExample.java index 4360d51b7..c6e1b6ca7 100644 --- a/examples/src/main/java/UpdateAccountPublicKeyExample.java +++ b/examples/src/main/java/UpdateAccountPublicKeyExample.java @@ -92,10 +92,6 @@ public static void main(String[] args) // Now we fetch the account information to check if the key was changed System.out.println(" :: getAccount and check our current key"); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - AccountInfo info = new AccountInfoQuery() .setAccountId(accountId) .execute(client); diff --git a/sdk/build.gradle b/sdk/build.gradle index 38a16a17b..56bdfed06 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -51,7 +51,6 @@ dependencies { testImplementation "io.github.json-snapshot:json-snapshot:1.0.17" testImplementation "org.junit.jupiter:junit-jupiter-engine:5.10.0" testImplementation "org.junit.jupiter:junit-jupiter-params:5.10.0" - testImplementation "org.wiremock:wiremock-standalone:3.4.2" testRuntimeOnly "org.slf4j:slf4j-simple:2.0.9" testRuntimeOnly "io.grpc:grpc-netty-shaded:1.57.2" diff --git a/sdk/src/integrationTest/java/AccountBalanceIntegrationTest.java b/sdk/src/integrationTest/java/AccountBalanceIntegrationTest.java index 094892de4..afa41433c 100644 --- a/sdk/src/integrationTest/java/AccountBalanceIntegrationTest.java +++ b/sdk/src/integrationTest/java/AccountBalanceIntegrationTest.java @@ -225,10 +225,6 @@ void canFetchTokenBalancesForClientOperator() throws Exception { var tokenId = Objects.requireNonNull(response.getReceipt(testEnv.client).tokenId); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var query = new AccountBalanceQuery(); var balance = query .setAccountId(testEnv.operatorId) diff --git a/sdk/src/integrationTest/java/AccountCreateIntegrationTest.java b/sdk/src/integrationTest/java/AccountCreateIntegrationTest.java index 9657e530d..c93b198df 100644 --- a/sdk/src/integrationTest/java/AccountCreateIntegrationTest.java +++ b/sdk/src/integrationTest/java/AccountCreateIntegrationTest.java @@ -24,10 +24,6 @@ void canCreateAccountWithOnlyInitialBalanceAndKey() throws Exception { var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); @@ -56,10 +52,6 @@ void canCreateAccountWithNoInitialBalance() throws Exception { var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); @@ -103,10 +95,6 @@ void canCreateWithAliasKey() throws Exception { .execute(testEnv.client) .getReceipt(testEnv.client); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(aliasId) .execute(testEnv.client); @@ -132,10 +120,6 @@ void managesExpiration() throws Exception { var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); @@ -177,10 +161,6 @@ void createAccountWithAliasFromAdminKey() throws Exception { assertThat(accountId).isNotNull(); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); @@ -220,10 +200,6 @@ void createAccountWithAliasFromAdminKeyWithReceiverSigRequired() throws Exceptio assertThat(accountId).isNotNull(); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); @@ -289,10 +265,6 @@ void createAccountWithAlias() throws Exception { assertThat(accountId).isNotNull(); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); @@ -362,10 +334,6 @@ void createAccountWithAliasWithReceiverSigRequired() throws Exception { assertThat(accountId).isNotNull(); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); diff --git a/sdk/src/integrationTest/java/AccountDeleteIntegrationTest.java b/sdk/src/integrationTest/java/AccountDeleteIntegrationTest.java index 45caa502d..165716715 100644 --- a/sdk/src/integrationTest/java/AccountDeleteIntegrationTest.java +++ b/sdk/src/integrationTest/java/AccountDeleteIntegrationTest.java @@ -30,10 +30,6 @@ void canDeleteAccount() throws Exception { var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); diff --git a/sdk/src/integrationTest/java/AccountInfoIntegrationTest.java b/sdk/src/integrationTest/java/AccountInfoIntegrationTest.java index 96010885c..0e5d435e0 100644 --- a/sdk/src/integrationTest/java/AccountInfoIntegrationTest.java +++ b/sdk/src/integrationTest/java/AccountInfoIntegrationTest.java @@ -4,11 +4,13 @@ import com.hedera.hashgraph.sdk.Hbar; import com.hedera.hashgraph.sdk.PrecheckStatusException; import com.hedera.hashgraph.sdk.PrivateKey; +import com.hedera.hashgraph.sdk.PublicKey; import com.hedera.hashgraph.sdk.Transaction; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.as; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/sdk/src/integrationTest/java/AccountUpdateIntegrationTest.java b/sdk/src/integrationTest/java/AccountUpdateIntegrationTest.java index 1c166c706..92bf25fa9 100644 --- a/sdk/src/integrationTest/java/AccountUpdateIntegrationTest.java +++ b/sdk/src/integrationTest/java/AccountUpdateIntegrationTest.java @@ -30,10 +30,6 @@ void canUpdateAccountWithNewKey() throws Exception { var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - @Var var info = new AccountInfoQuery() .setAccountId(accountId) .execute(testEnv.client); diff --git a/sdk/src/integrationTest/java/AutomaticAssociationTest.java b/sdk/src/integrationTest/java/AutomaticAssociationTest.java index 2b11629a1..fd6bdcf1f 100644 --- a/sdk/src/integrationTest/java/AutomaticAssociationTest.java +++ b/sdk/src/integrationTest/java/AutomaticAssociationTest.java @@ -1,6 +1,3 @@ -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; @@ -9,10 +6,15 @@ import com.hedera.hashgraph.sdk.TokenCreateTransaction; import com.hedera.hashgraph.sdk.TokenDeleteTransaction; import com.hedera.hashgraph.sdk.TransferTransaction; -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 AutomaticAssociationTest { @Test @DisplayName("Tokens automatically become associated") @@ -30,10 +32,6 @@ void autoAssociateTest() throws Exception { Objects.requireNonNull(accountId); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var accountInfo1 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client); assertThat(accountInfo1.maxAutomaticTokenAssociations).isEqualTo(1); @@ -74,10 +72,6 @@ void autoAssociateTest() throws Exception { assertThat(transferRecord.automaticTokenAssociations.get(0).accountId).isEqualTo(accountId); assertThat(transferRecord.automaticTokenAssociations.get(0).tokenId).isEqualTo(tokenId1); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var accountInfo2 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client); assertThat(accountInfo2.tokenRelationships.size()).isEqualTo(1); @@ -99,10 +93,6 @@ void autoAssociateTest() throws Exception { .execute(testEnv.client) .getReceipt(testEnv.client); - // `AccountInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var accountInfo3 = new AccountInfoQuery().setAccountId(accountId).execute(testEnv.client); assertThat(accountInfo3.maxAutomaticTokenAssociations).isEqualTo(2); diff --git a/sdk/src/integrationTest/java/ContractCreateIntegrationTest.java b/sdk/src/integrationTest/java/ContractCreateIntegrationTest.java index e77d901a8..cdf8b402e 100644 --- a/sdk/src/integrationTest/java/ContractCreateIntegrationTest.java +++ b/sdk/src/integrationTest/java/ContractCreateIntegrationTest.java @@ -1,6 +1,3 @@ -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - import com.google.errorprone.annotations.Var; import com.hedera.hashgraph.sdk.ContractCreateTransaction; import com.hedera.hashgraph.sdk.ContractDeleteTransaction; @@ -11,10 +8,15 @@ 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"; @@ -40,10 +42,6 @@ void canCreateContract() throws Exception { var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); @@ -91,10 +89,6 @@ void canCreateContractWithNoAdminKey() throws Exception { var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); diff --git a/sdk/src/integrationTest/java/ContractDeleteIntegrationTest.java b/sdk/src/integrationTest/java/ContractDeleteIntegrationTest.java index c89d91165..9864daed4 100644 --- a/sdk/src/integrationTest/java/ContractDeleteIntegrationTest.java +++ b/sdk/src/integrationTest/java/ContractDeleteIntegrationTest.java @@ -1,6 +1,3 @@ -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - import com.google.errorprone.annotations.Var; import com.hedera.hashgraph.sdk.ContractCreateTransaction; import com.hedera.hashgraph.sdk.ContractDeleteTransaction; @@ -11,10 +8,15 @@ 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"; @@ -40,10 +42,6 @@ void canDeleteContractWithAdminKey() throws Exception { var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); @@ -92,10 +90,6 @@ void cannotDeleteContractWhichHasNoAdminKey() throws Exception { .contractId ); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); diff --git a/sdk/src/integrationTest/java/ContractIdPopulationIntegrationTest.java b/sdk/src/integrationTest/java/ContractIdPopulationIntegrationTest.java index df7f9364a..2e7163f7f 100644 --- a/sdk/src/integrationTest/java/ContractIdPopulationIntegrationTest.java +++ b/sdk/src/integrationTest/java/ContractIdPopulationIntegrationTest.java @@ -37,15 +37,12 @@ void canPopulateContractIdNumSync() throws Exception { var contractId = Objects.requireNonNull(receipt.contractId); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); var idMirror = ContractId.fromEvmAddress(0, 0, info.contractAccountId); + Thread.sleep(5000); var newContractId = idMirror.populateContractNum(testEnv.client); @@ -79,15 +76,12 @@ void canPopulateContractIdNumAsync() throws Exception { var contractId = Objects.requireNonNull(receipt.contractId); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); var idMirror = ContractId.fromEvmAddress(0, 0, info.contractAccountId); + Thread.sleep(5000); var newContractId = idMirror.populateContractNumAsync(testEnv.client).get(); diff --git a/sdk/src/integrationTest/java/ContractInfoIntegrationTest.java b/sdk/src/integrationTest/java/ContractInfoIntegrationTest.java index c7e063969..00c107325 100644 --- a/sdk/src/integrationTest/java/ContractInfoIntegrationTest.java +++ b/sdk/src/integrationTest/java/ContractInfoIntegrationTest.java @@ -35,10 +35,6 @@ void canQueryContractInfo() throws Exception { assertThat(contractId.hashCode()).isGreaterThan(0); assertThat(contractId.compareTo(ContractId.fromBytes(contractId.toBytes()))).isZero(); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); @@ -86,10 +82,6 @@ void canQueryContractInfoWhenAdminKeyIsNull() throws Exception { var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); @@ -148,10 +140,6 @@ void getCostBigMaxContractInfoFunction() throws Exception { var cost = infoQuery.getCost(testEnv.client); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var result = infoQuery .execute(testEnv.client); diff --git a/sdk/src/integrationTest/java/ContractUpdateIntegrationTest.java b/sdk/src/integrationTest/java/ContractUpdateIntegrationTest.java index a296c5b2d..51e27a4d9 100644 --- a/sdk/src/integrationTest/java/ContractUpdateIntegrationTest.java +++ b/sdk/src/integrationTest/java/ContractUpdateIntegrationTest.java @@ -42,10 +42,6 @@ void canUpdateContract() throws Exception { var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId); - // `ContractInfoQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - @Var var info = new ContractInfoQuery() .setContractId(contractId) .execute(testEnv.client); diff --git a/sdk/src/integrationTest/java/IntegrationTestEnv.java b/sdk/src/integrationTest/java/IntegrationTestEnv.java index 779522584..66902d735 100644 --- a/sdk/src/integrationTest/java/IntegrationTestEnv.java +++ b/sdk/src/integrationTest/java/IntegrationTestEnv.java @@ -139,10 +139,6 @@ public void close( } if (!operatorId.equals(originalClient.getOperatorAccountId())) { - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var hbarsBalance = new AccountBalanceQuery() .setAccountId(operatorId) .execute(originalClient) @@ -160,10 +156,6 @@ public void close( } public void wipeAccountHbars(AccountId newAccountId, PrivateKey newAccountKey) throws Exception { - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var hbarsBalance = new AccountBalanceQuery() .setAccountId(newAccountId) .execute(originalClient) diff --git a/sdk/src/integrationTest/java/ScheduleCreateIntegrationTest.java b/sdk/src/integrationTest/java/ScheduleCreateIntegrationTest.java index dd2e4866e..0717c538d 100644 --- a/sdk/src/integrationTest/java/ScheduleCreateIntegrationTest.java +++ b/sdk/src/integrationTest/java/ScheduleCreateIntegrationTest.java @@ -252,10 +252,6 @@ void canScheduleTokenTransfer() throws Exception { Objects.requireNonNull(scheduleId); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var balanceQuery1 = new AccountBalanceQuery() .setAccountId(accountId) .execute(testEnv.client); @@ -269,10 +265,6 @@ void canScheduleTokenTransfer() throws Exception { .execute(testEnv.client) .getReceipt(testEnv.client); - // `AccountBalanceQuery` also queries the mirror node. - // Wait until the mirror node updates with the new data. - Thread.sleep(5000); - var balanceQuery2 = new AccountBalanceQuery() .setAccountId(accountId) .execute(testEnv.client); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountBalanceQuery.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountBalanceQuery.java index 1d5dac161..a103a54ba 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountBalanceQuery.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountBalanceQuery.java @@ -24,15 +24,14 @@ import com.hedera.hashgraph.sdk.proto.QueryHeader; import com.hedera.hashgraph.sdk.proto.Response; import com.hedera.hashgraph.sdk.proto.ResponseHeader; -import com.hedera.hashgraph.sdk.proto.TokenBalance; import io.grpc.MethodDescriptor; -import java.util.List; -import java.util.Objects; + import javax.annotation.Nullable; +import java.util.Objects; /** - * Get the balance of a Hedera™ crypto-currency account. This returns only the balance, so it is a smaller and faster - * reply than {@link AccountInfoQuery}. + * Get the balance of a Hedera™ crypto-currency account. This returns only the balance, so it is a + * smaller and faster reply than {@link AccountInfoQuery}. * *

This query is free. */ @@ -75,7 +74,7 @@ public AccountBalanceQuery setAccountId(AccountId accountId) { /** * Extract the contract id. * - * @return the contract id + * @return the contract id */ @Nullable public ContractId getContractId() { @@ -128,20 +127,7 @@ void onMakeRequest(com.hedera.hashgraph.sdk.proto.Query.Builder queryBuilder, Qu @Override AccountBalance mapResponse(Response response, AccountId nodeId, com.hedera.hashgraph.sdk.proto.Query request) { - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forNetwork(this.mirrorNetworkNodes, this.ledgerId); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - - AccountId accountIdFromConsensusNode = AccountId.fromProtobuf(response.getCryptogetAccountBalance().getAccountID()); - List tokenBalanceList = mirrorNodeService - .getTokenBalancesForAccount(String.valueOf(accountIdFromConsensusNode.num)); - - var protobufFromConsensusNode = response.getCryptogetAccountBalance(); - var protobufUpdatedByMirrorNode = protobufFromConsensusNode.toBuilder() - .clearTokenBalances() - .addAllTokenBalances(tokenBalanceList) - .build(); - - return AccountBalance.fromProtobuf(protobufUpdatedByMirrorNode); + return AccountBalance.fromProtobuf(response.getCryptogetAccountBalance()); } @Override diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountId.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountId.java index a6ac3f5c2..5fb2a6fb2 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountId.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountId.java @@ -307,19 +307,8 @@ AccountID toProtobuf() { * @param client * @return populated AccountId instance */ - public AccountId populateAccountNum(Client client) { - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forClient(client); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - var accountNumFromMirrorNode = mirrorNodeService.getAccountNum(evmAddress.toString()); - - return new AccountId( - this.shard, - this.realm, - accountNumFromMirrorNode, - this.checksum, - this.aliasKey, - this.evmAddress - ); + public AccountId populateAccountNum(Client client) throws InterruptedException, ExecutionException { + return populateAccountNumAsync(client).get(); } /** @@ -334,10 +323,7 @@ public AccountId populateAccountNum(Client client) { */ @Deprecated public CompletableFuture populateAccountNumAsync(Client client) { - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forClient(client); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - - return CompletableFuture.supplyAsync(() -> mirrorNodeService.getAccountNum(evmAddress.toString())) + return EntityIdHelper.getAccountNumFromMirrorNodeAsync(client, evmAddress.toString()) .thenApply(accountNumFromMirrorNode -> new AccountId( this.shard, @@ -345,11 +331,9 @@ public CompletableFuture populateAccountNumAsync(Client client) { accountNumFromMirrorNode, this.checksum, this.aliasKey, - this.evmAddress) - ); + this.evmAddress)); } - /** * Populates `evmAddress` field of the `AccountId` extracted from the Mirror Node. * Sync version @@ -357,19 +341,8 @@ public CompletableFuture populateAccountNumAsync(Client client) { * @param client * @return populated AccountId instance */ - public AccountId populateAccountEvmAddress(Client client) { - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forClient(client); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - var evmAddressFromMirrorNode = mirrorNodeService.getAccountEvmAddress(num); - - return new AccountId( - this.shard, - this.realm, - this.num, - this.checksum, - this.aliasKey, - evmAddressFromMirrorNode - ); + public AccountId populateAccountEvmAddress(Client client) throws ExecutionException, InterruptedException { + return populateAccountEvmAddressAsync(client).get(); } /** @@ -382,10 +355,7 @@ public AccountId populateAccountEvmAddress(Client client) { */ @Deprecated public CompletableFuture populateAccountEvmAddressAsync(Client client) { - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forClient(client); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - - return CompletableFuture.supplyAsync(() -> mirrorNodeService.getAccountEvmAddress(num)) + return EntityIdHelper.getEvmAddressFromMirrorNodeAsync(client, num) .thenApply(evmAddressFromMirrorNode -> new AccountId( this.shard, diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountInfoQuery.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountInfoQuery.java index fe7b2442b..df2cd226f 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountInfoQuery.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/AccountInfoQuery.java @@ -24,9 +24,7 @@ import com.hedera.hashgraph.sdk.proto.QueryHeader; import com.hedera.hashgraph.sdk.proto.Response; import com.hedera.hashgraph.sdk.proto.ResponseHeader; -import com.hedera.hashgraph.sdk.proto.TokenRelationship; import io.grpc.MethodDescriptor; -import java.util.List; import java.util.Objects; import java.util.concurrent.CompletableFuture; import javax.annotation.Nullable; @@ -98,20 +96,7 @@ QueryHeader mapRequestHeader(com.hedera.hashgraph.sdk.proto.Query request) { @Override AccountInfo mapResponse(Response response, AccountId nodeId, com.hedera.hashgraph.sdk.proto.Query request) { - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forNetwork(this.mirrorNetworkNodes, this.ledgerId); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - - AccountId accountIdFromConsensusNode = AccountId.fromProtobuf(response.getCryptoGetInfo().getAccountInfo().getAccountID()); - List tokenRelationships = mirrorNodeService - .getTokenRelationshipsForAccount(String.valueOf(accountIdFromConsensusNode.num)); - - var protobufFromConsensusNode = response.getCryptoGetInfo().getAccountInfo(); - var protobufUpdatedByMirrorNode = protobufFromConsensusNode.toBuilder() - .clearTokenRelationships() - .addAllTokenRelationships(tokenRelationships) - .build(); - - return AccountInfo.fromProtobuf(protobufUpdatedByMirrorNode); + return AccountInfo.fromProtobuf(response.getCryptoGetInfo().getAccountInfo()); } @Override diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractId.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractId.java index 8ef46c229..ef261f6e2 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractId.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractId.java @@ -226,14 +226,8 @@ ContractID toProtobuf() { * @param client * @return populated ContractId instance */ - public ContractId populateContractNum(Client client) { - EvmAddress address = new EvmAddress(this.evmAddress); - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forClient(client); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - - var contractNum = mirrorNodeService.getContractNum(address.toString()); - - return new ContractId(this.shard, this.realm, contractNum, checksum); + public ContractId populateContractNum(Client client) throws InterruptedException, ExecutionException { + return populateContractNumAsync(client).get(); } /** @@ -249,10 +243,8 @@ public ContractId populateContractNum(Client client) { @Deprecated public CompletableFuture populateContractNumAsync(Client client) { EvmAddress address = new EvmAddress(this.evmAddress); - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forClient(client); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - return CompletableFuture.supplyAsync(() -> mirrorNodeService.getContractNum(address.toString())) + return EntityIdHelper.getContractNumFromMirrorNodeAsync(client, address.toString()) .thenApply(contractNumFromMirrorNode -> new ContractId(this.shard, this.realm, contractNumFromMirrorNode, checksum)); } diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractInfoQuery.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractInfoQuery.java index 9af89d7e0..f56239ee4 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractInfoQuery.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/ContractInfoQuery.java @@ -24,9 +24,7 @@ import com.hedera.hashgraph.sdk.proto.Response; import com.hedera.hashgraph.sdk.proto.ResponseHeader; import com.hedera.hashgraph.sdk.proto.SmartContractServiceGrpc; -import com.hedera.hashgraph.sdk.proto.TokenRelationship; import io.grpc.MethodDescriptor; -import java.util.List; import java.util.Objects; import java.util.concurrent.CompletableFuture; import javax.annotation.Nullable; @@ -106,20 +104,7 @@ QueryHeader mapRequestHeader(com.hedera.hashgraph.sdk.proto.Query request) { @Override ContractInfo mapResponse(Response response, AccountId nodeId, com.hedera.hashgraph.sdk.proto.Query request) { - MirrorNodeGateway mirrorNodeGateway = MirrorNodeGateway.forNetwork(this.mirrorNetworkNodes, this.ledgerId); - MirrorNodeService mirrorNodeService = new MirrorNodeService(mirrorNodeGateway); - - ContractId contractIdFromConsensusNode = ContractId.fromProtobuf(response.getContractGetInfo().getContractInfo().getContractID()); - List tokenRelationships = mirrorNodeService - .getTokenRelationshipsForAccount(String.valueOf(contractIdFromConsensusNode.num)); - - var protobufFromConsensusNode = response.getContractGetInfo().getContractInfo(); - var protobufUpdatedByMirrorNode = protobufFromConsensusNode.toBuilder() - .clearTokenRelationships() - .addAllTokenRelationships(tokenRelationships) - .build(); - - return ContractInfo.fromProtobuf(protobufUpdatedByMirrorNode); + return ContractInfo.fromProtobuf(response.getContractGetInfo().getContractInfo()); } @Override 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 dcb503da0..0c8e13ca1 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/EntityIdHelper.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/EntityIdHelper.java @@ -20,9 +20,19 @@ package com.hedera.hashgraph.sdk; import com.google.errorprone.annotations.Var; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.nio.ByteBuffer; +import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; import java.util.regex.Pattern; import javax.annotation.Nullable; import org.bouncycastle.util.encoders.DecoderException; @@ -45,6 +55,8 @@ class EntityIdHelper { 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. */ @@ -270,6 +282,99 @@ public static boolean isLongZeroAddress(byte[] address) { return true; } + /** + * Get AccountId num from mirror node using evm address. + * + * @param client + * @param evmAddress + * @return + * @throws IOException + * @throws InterruptedException + */ + public static CompletableFuture getAccountNumFromMirrorNodeAsync(Client client, String evmAddress) { + String apiEndpoint = "/accounts/" + evmAddress; + return performQueryToMirrorNodeAsync(client, apiEndpoint) + .thenApply(response -> + parseNumFromMirrorNodeResponse(response, "account")); + } + + /** + * Get EvmAddress from mirror node using account num. + * + * @param client + * @param num + * @return + * @throws IOException + * @throws InterruptedException + */ + public static CompletableFuture getEvmAddressFromMirrorNodeAsync(Client client, long num) { + String apiEndpoint = "/accounts/" + num; + return performQueryToMirrorNodeAsync(client, apiEndpoint) + .thenApply(response -> + EvmAddress.fromString(parseEvmAddressFromMirrorNodeResponse(response, "evm_address"))); + } + + /** + * Get ContractId num from mirror node using evm address. + * + * @param client + * @param evmAddress + * @return + * @throws IOException + * @throws InterruptedException + */ + public static CompletableFuture getContractNumFromMirrorNodeAsync(Client client, String evmAddress) { + String apiEndpoint = "/contracts/" + evmAddress; + + CompletableFuture responseFuture = performQueryToMirrorNodeAsync(client, apiEndpoint); + + 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(); + + if (mirrorUrl.isEmpty()) { + return CompletableFuture.failedFuture(new IllegalArgumentException("Mirror URL not found")); + } + + String apiUrl = "https://" + mirrorUrl.get() + "/api/v1" + apiEndpoint; + + if (client.getLedgerId() == null) { + apiUrl = "http://" + mirrorUrl.get() + ":5551/api/v1" + apiEndpoint; + } + + HttpClient httpClient = HttpClient.newHttpClient(); + HttpRequest httpRequest = HttpRequest.newBuilder() + .timeout(MIRROR_NODE_CONNECTION_TIMEOUT) + .uri(URI.create(apiUrl)) + .build(); + + return httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()) + .thenApply(HttpResponse::body); + } + + private static long parseNumFromMirrorNodeResponse(String responseBody, String memberName) { + JsonParser jsonParser = new JsonParser(); + JsonObject jsonObject = jsonParser.parse(responseBody).getAsJsonObject(); + + String num = jsonObject.get(memberName).getAsString(); + + return Long.parseLong(num.substring(num.lastIndexOf(".") + 1)); + } + + private static String parseEvmAddressFromMirrorNodeResponse(String responseBody, String memberName) { + JsonParser jsonParser = new JsonParser(); + JsonObject jsonObject = jsonParser.parse(responseBody).getAsJsonObject(); + + String evmAddress = jsonObject.get(memberName).getAsString(); + + return evmAddress.substring(evmAddress.lastIndexOf(".") + 1); + } + @FunctionalInterface interface WithIdNums { R apply(long shard, long realm, long num, @Nullable String checksum); diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/Executable.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/Executable.java index 21e76419c..18461cab0 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/Executable.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/Executable.java @@ -91,16 +91,6 @@ abstract class Executable nodes = new LockableList<>(); - /** - * List of mirror network nodes with which execution will be attempted. - */ - protected List mirrorNetworkNodes = new ArrayList<>(); - - /** - * Current LedgerId of the network with which execution will be attempted. - */ - protected LedgerId ledgerId; - /** * Indicates if the request has been attempted to be sent to all nodes */ @@ -347,9 +337,6 @@ void mergeFromClient(Client client) { if (grpcDeadline == null) { grpcDeadline = client.getGrpcDeadline(); } - - this.mirrorNetworkNodes = client.getMirrorNetwork(); - this.ledgerId = client.getLedgerId(); } private void delay(long delay) { diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeGateway.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeGateway.java deleted file mode 100644 index 1c5dbb7d1..000000000 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeGateway.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * - * Hedera Java SDK - * - * 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 com.hedera.hashgraph.sdk.MirrorNodeRouter.ACCOUNTS_ROUTE; -import static com.hedera.hashgraph.sdk.MirrorNodeRouter.ACCOUNT_TOKENS_ROUTE; -import static com.hedera.hashgraph.sdk.MirrorNodeRouter.CONTRACTS_ROUTE; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import java.io.IOException; -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.time.Duration; -import java.util.List; - -class MirrorNodeGateway { - - private final HttpClient httpClient = HttpClient.newHttpClient(); - - private final String mirrorNodeUrl; - - static final Duration MIRROR_NODE_CONNECTION_TIMEOUT = Duration.ofSeconds(30); - - private MirrorNodeGateway(String mirrorNodeUrl) { - this.mirrorNodeUrl = mirrorNodeUrl; - } - - static MirrorNodeGateway forClient(Client client) { - final String mirrorNodeUrl = MirrorNodeRouter.getMirrorNodeUrl(client.getMirrorNetwork(), - client.getLedgerId()); - - return new MirrorNodeGateway(mirrorNodeUrl); - } - - static MirrorNodeGateway forNetwork(List mirrorNetwork, LedgerId ledgerId) { - final String mirrorNodeUrl = MirrorNodeRouter.getMirrorNodeUrl(mirrorNetwork, ledgerId); - - return new MirrorNodeGateway(mirrorNodeUrl); - } - - JsonObject getAccountInfo(String idOrAliasOrEvmAddress) throws IOException, InterruptedException { - var fullApiUrl = MirrorNodeRouter.buildApiUrl(mirrorNodeUrl, ACCOUNTS_ROUTE, idOrAliasOrEvmAddress); - - var responseBody = performQueryToMirrorNode(fullApiUrl); - - return JsonParser.parseString(responseBody).getAsJsonObject(); - } - - JsonObject getContractInfo(String contractIdOrAddress) throws IOException, InterruptedException { - var fullApiUrl = MirrorNodeRouter.buildApiUrl(mirrorNodeUrl, CONTRACTS_ROUTE, contractIdOrAddress); - - var responseBody = performQueryToMirrorNode(fullApiUrl); - - return JsonParser.parseString(responseBody).getAsJsonObject(); - } - - JsonObject getAccountTokens(String idOrAliasOrEvmAddress) throws IOException, InterruptedException { - var fullApiUrl = MirrorNodeRouter.buildApiUrl(mirrorNodeUrl, ACCOUNT_TOKENS_ROUTE, idOrAliasOrEvmAddress); - - var responseBody = performQueryToMirrorNode(fullApiUrl); - - return JsonParser.parseString(responseBody).getAsJsonObject(); - } - - private String performQueryToMirrorNode(String apiUrl) throws IOException, InterruptedException { - HttpRequest httpRequest = HttpRequest.newBuilder() - .timeout(MIRROR_NODE_CONNECTION_TIMEOUT) - .uri(URI.create(apiUrl)) - .build(); - - return httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()).body(); - } -} diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeRouter.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeRouter.java deleted file mode 100644 index 858895537..000000000 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeRouter.java +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * - * Hedera Java SDK - * - * 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 java.util.List; -import java.util.Map; -import java.util.Optional; - -class MirrorNodeRouter { - - private static final String API_VERSION = "/api/v1"; - - // refactor me - static String LOCAL_NODE_PORT = "5551"; - - static final String ACCOUNTS_ROUTE = "accounts"; - - static final String CONTRACTS_ROUTE = "contracts"; - - static final String ACCOUNT_TOKENS_ROUTE = "account_tokens"; - - private static final Map routes = Map.of( - ACCOUNTS_ROUTE, "/accounts/%s", - CONTRACTS_ROUTE, "/contracts/%s", - ACCOUNT_TOKENS_ROUTE, "/accounts/%s/tokens" - ); - - private MirrorNodeRouter() { - } - - static String getMirrorNodeUrl(List mirrorNetwork, LedgerId ledgerId) { - Optional mirrorNodeAddress = mirrorNetwork.stream() - .map(address -> address.substring(0, address.indexOf(":"))) - .findFirst(); - - if (mirrorNodeAddress.isEmpty()) { - throw new IllegalArgumentException("Mirror address not found"); - } - - String fullMirrorNodeUrl; - - if (ledgerId != null) { - fullMirrorNodeUrl = "https://" + mirrorNodeAddress.get(); - } else { - // local node case - fullMirrorNodeUrl = "http://" + mirrorNodeAddress.get() + ":" + LOCAL_NODE_PORT; - } - - return fullMirrorNodeUrl; - } - - static String buildApiUrl(String mirrorNodeUrl, String route, String id) { - return mirrorNodeUrl + API_VERSION + String.format(routes.get(route), id); - } -} diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeService.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeService.java deleted file mode 100644 index 7b0c006b0..000000000 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/MirrorNodeService.java +++ /dev/null @@ -1,205 +0,0 @@ -/*- - * - * Hedera Java SDK - * - * 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.gson.JsonArray; -import com.google.gson.JsonObject; -import com.hedera.hashgraph.sdk.proto.TokenBalance; -import com.hedera.hashgraph.sdk.proto.TokenFreezeStatus; -import com.hedera.hashgraph.sdk.proto.TokenKycStatus; -import com.hedera.hashgraph.sdk.proto.TokenRelationship; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collectors; - -class MirrorNodeService { - - private final MirrorNodeGateway mirrorNodeGateway; - - MirrorNodeService(MirrorNodeGateway mirrorNodeGateway) { - this.mirrorNodeGateway = mirrorNodeGateway; - } - - /** - * Retrieves the account number from the mirror node using the specified EVM address. - * - * @param evmAddress the EVM address for which the account number is to be retrieved - * @return the account number as a Long - * @throws RuntimeException if an error occurs while processing the mirror node query - */ - Long getAccountNum(String evmAddress) { - JsonObject accountInfoResponse = null; - - try { - accountInfoResponse = mirrorNodeGateway.getAccountInfo(evmAddress); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } catch (IOException e) { - throw new RuntimeException("Error, while processing getAccountInfo mirror node query", e); - } - - String num = accountInfoResponse.get("account").getAsString(); - - return Long.parseLong(num.substring(num.lastIndexOf(".") + 1)); - } - - /** - * Retrieves the Ethereum Virtual Machine (EVM) address for an account using the specified account number. - * This method retrieves the account information from the mirror node and extracts the EVM address. - * - * @param num the account number for which the EVM address is to be retrieved - * @return the EVM address as an instance of EvmAddress - * @throws RuntimeException if an error occurs while processing the mirror node query - */ - EvmAddress getAccountEvmAddress(long num) { - JsonObject accountInfoResponse = null; - - try { - accountInfoResponse = mirrorNodeGateway.getAccountInfo(String.valueOf(num)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } catch (IOException e) { - throw new RuntimeException("Error, while processing getAccountInfo mirror node query", e); - } - - String evmAddressString = accountInfoResponse.get("evm_address").getAsString(); - - return EvmAddress.fromString( - evmAddressString.substring(evmAddressString.lastIndexOf(".") + 1)); - } - - /** - * Retrieves the contract number from the mirror node using the specified EVM address. - * - * @param evmAddress the EVM address for which the contract number is to be retrieved - * @return the contract number as a Long - * @throws RuntimeException if an error occurs while processing the mirror node query - */ - Long getContractNum(String evmAddress) { - JsonObject accountInfoResponse = null; - - try { - accountInfoResponse = mirrorNodeGateway.getContractInfo(evmAddress); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } catch (IOException e) { - throw new RuntimeException("Error, while processing getContractInfo mirror node query", e); - } - - String num = accountInfoResponse.get("contract_id").getAsString(); - - return Long.parseLong(num.substring(num.lastIndexOf(".") + 1)); - } - - /** - * Retrieves the balances of tokens for an account (as a protobuf). - * - * @param idOrAliasOrEvmAddress the ID, alias, or EVM address of the account - * @return a list of TokenBalance (as a protobuf) objects representing the token balances of the account - * @throws RuntimeException if an error occurs while processing the mirror node query - */ - List getTokenBalancesForAccount(String idOrAliasOrEvmAddress) { - JsonObject accountTokensResponse = null; - - try { - accountTokensResponse = mirrorNodeGateway.getAccountTokens(idOrAliasOrEvmAddress); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } catch (IOException e) { - throw new RuntimeException("Error, while processing getAccountTokens mirror node query", e); - } - - JsonArray tokens = accountTokensResponse.get("tokens").getAsJsonArray(); - - List tokenBalanceList = tokens.asList().stream().map(jsonElement -> { - var jsonObject = jsonElement.getAsJsonObject(); - var tokenId = jsonObject.get("token_id").getAsString(); - var tokenBalance = jsonObject.get("balance").getAsLong(); - var decimals = jsonObject.get("decimals").getAsInt(); - - return TokenBalance.newBuilder().setTokenId(TokenId.fromString(tokenId).toProtobuf()) - .setBalance(tokenBalance) - .setDecimals(decimals) - .build(); - }).collect(Collectors.toList()); - - return tokenBalanceList; - } - - /** - * Retrieves the token relationships for an account (as a protobuf). - * - * @param idOrAliasOrEvmAddress the ID, alias, or EVM address of the account - * @return a list of TokenRelationship (as a protobuf) objects representing the token relationships of the account - * @throws RuntimeException if an error occurs while processing the mirror node query - */ - List getTokenRelationshipsForAccount(String idOrAliasOrEvmAddress) { - JsonObject accountTokensResponse = null; - - try { - accountTokensResponse = mirrorNodeGateway.getAccountTokens(idOrAliasOrEvmAddress); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } catch (IOException e) { - throw new RuntimeException("Error, while processing getAccountTokens mirror node query", e); - } - - JsonArray tokens = accountTokensResponse.get("tokens").getAsJsonArray(); - - List tokenRelationships = tokens.asList().stream().map(jsonElement -> { - var jsonObject = jsonElement.getAsJsonObject(); - var tokenId = jsonObject.get("token_id").getAsString(); - var balance = jsonObject.get("balance").getAsLong(); - var kycStatus = jsonObject.get("kyc_status").getAsString(); - var freezeStatus = jsonObject.get("freeze_status").getAsString(); - var decimals = jsonObject.get("decimals").getAsInt(); - var automaticAssociation = jsonObject.get("automatic_association").getAsBoolean(); - - return TokenRelationship.newBuilder() - .setTokenId(TokenId.fromString(tokenId).toProtobuf()) - .setBalance(balance) - .setKycStatus(getTokenKycStatusFromString(kycStatus)) - .setFreezeStatus(getTokenFreezeStatusFromString(freezeStatus)) - .setDecimals(decimals) - .setAutomaticAssociation(automaticAssociation) - .build(); - }).collect(Collectors.toList()); - - return tokenRelationships; - } - - private TokenKycStatus getTokenKycStatusFromString(String tokenKycStatusString) { - return switch (tokenKycStatusString) { - case "NOT_APPLICABLE" -> TokenKycStatus.KycNotApplicable; - case "GRANTED" -> TokenKycStatus.Granted; - case "REVOKED" -> TokenKycStatus.Revoked; - default -> throw new IllegalArgumentException("Invalid token KYC status: " + tokenKycStatusString); - }; - } - - private TokenFreezeStatus getTokenFreezeStatusFromString(String tokenFreezeStatusString) { - return switch (tokenFreezeStatusString) { - case "NOT_APPLICABLE" -> TokenFreezeStatus.FreezeNotApplicable; - case "FROZEN" -> TokenFreezeStatus.Frozen; - case "UNFROZEN" -> TokenFreezeStatus.Unfrozen; - default -> throw new IllegalArgumentException("Invalid token freeze status: " + tokenFreezeStatusString); - }; - } -} diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenRelationship.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenRelationship.java index ee7bb5208..af0aab319 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenRelationship.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TokenRelationship.java @@ -23,6 +23,7 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.TokenFreezeStatus; import com.hedera.hashgraph.sdk.proto.TokenKycStatus; + import javax.annotation.Nullable; /** diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java index 229e68f59..bf7517f4d 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/ClientTest.java @@ -276,7 +276,7 @@ void forNameReturnsCorrectNetwork() { .hasMessageEndingWith("Name must be one-of `mainnet`, `testnet`, or `previewnet`"); } - @ParameterizedTest + @ParameterizedTest @CsvSource({ "onClient", "onQuery" diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/Mocker.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/Mocker.java index 2d04b88e7..4322d8dd6 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/Mocker.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/Mocker.java @@ -106,20 +106,15 @@ public class Mocker implements AutoCloseable { } } - try { - this.client = Client.forNetwork(network) - .setMirrorNetwork(List.of("127.0.0.1:5552")) - .setOperator(new AccountId(1800), PRIVATE_KEY) - .setMinBackoff(Duration.ofMillis(0)) - .setMaxBackoff(Duration.ofMillis(0)) - .setNodeMinBackoff(Duration.ofMillis(0)) - .setNodeMaxBackoff(Duration.ofMillis(0)) - .setMinNodeReadmitTime(Duration.ofMillis(0)) - .setMaxNodeReadmitTime(Duration.ofMillis(0)) - .setLogger(new Logger(LogLevel.SILENT)); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } + this.client = Client.forNetwork(network) + .setOperator(new AccountId(1800), PRIVATE_KEY) + .setMinBackoff(Duration.ofMillis(0)) + .setMaxBackoff(Duration.ofMillis(0)) + .setNodeMinBackoff(Duration.ofMillis(0)) + .setNodeMaxBackoff(Duration.ofMillis(0)) + .setMinNodeReadmitTime(Duration.ofMillis(0)) + .setMaxNodeReadmitTime(Duration.ofMillis(0)) + .setLogger(new Logger(LogLevel.SILENT)); } public static Mocker withResponses(List> responses) { diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java index c3db31388..9048440f6 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java @@ -19,11 +19,6 @@ */ package com.hedera.hashgraph.sdk; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; - -import com.github.tomakehurst.wiremock.WireMockServer; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import com.hedera.hashgraph.sdk.proto.AccountID; @@ -57,6 +52,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Objects; import java.util.concurrent.TimeoutException; import java.util.function.Supplier; @@ -80,13 +76,9 @@ void testSucceedsWithCorrectHbars() throws PrecheckStatusException, TimeoutExcep var responses = List.of(responses1); try (var mocker = Mocker.withResponses(responses)) { - var httpMockServer = setupHttpMockServer(); - var balance = new AccountBalanceQuery().setAccountId(new AccountId(10)).execute(mocker.client); Assertions.assertEquals(balance.hbars, Hbar.fromTinybars(100)); - - httpMockServer.stop(); } } @@ -259,8 +251,6 @@ void accountInfoFlowFunctions() throws Throwable { ); } - var httpMockServer = setupHttpMockServer(); - Assertions.assertTrue( AccountInfoFlow.verifyTransactionSignature(server.client, accountId, properlySignedTx) ); @@ -300,7 +290,6 @@ void accountInfoFlowFunctions() throws Throwable { Assertions.assertEquals(accountId, AccountId.fromProtobuf(queryRequest.getCryptoGetInfo().getAccountID())); } server.close(); - httpMockServer.stop(); } @Test @@ -707,26 +696,5 @@ public void createContract(Transaction request, StreamObserver(); network.put("in-process:" + name + "[0]", AccountId.fromString("1.1.1")); network.put("in-process:" + name + "[1]", AccountId.fromString("2.2.2")); - try { - client = Client.forNetwork(network) - .setMirrorNetwork(List.of("127.0.0.1:5552")) - .setNodeMinBackoff(Duration.ofMillis(500)) - .setNodeMaxBackoff(Duration.ofMillis(500)) - .setOperator(AccountId.fromString("2.2.2"), PrivateKey.generate()); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } + client = Client.forNetwork(network) + .setNodeMinBackoff(Duration.ofMillis(500)) + .setNodeMaxBackoff(Duration.ofMillis(500)) + .setOperator(AccountId.fromString("2.2.2"), PrivateKey.generate()); } public void close() throws TimeoutException, InterruptedException {