From 1b5121e9a250f79ec53f63ecb963710596b91c5f Mon Sep 17 00:00:00 2001 From: Alexandre C Date: Tue, 13 Sep 2022 20:45:20 +0200 Subject: [PATCH] Included a delay before each integration test for the blockchain to process de request --- .../src/test/resources/log4j2-test.properties | 4 ++-- .../src/test/resources/log4j2-test.properties | 4 ++-- .../near/api/rpc/service/AccountServiceTest.java | 13 ++++++++++--- .../near/api/rpc/service/TransferServiceTest.java | 7 +++++++ .../near/api/rpc/service/ft/FTServiceTest.java | 8 +++++++- .../near/api/rpc/service/nft/NFTServiceTest.java | 7 +++++++ .../api/rpc/service/staking/StakingServiceTest.java | 13 ++++++++----- .../src/test/resources/log4j2-test.properties | 6 +++--- 8 files changed, 46 insertions(+), 16 deletions(-) diff --git a/near-java-api-common/src/test/resources/log4j2-test.properties b/near-java-api-common/src/test/resources/log4j2-test.properties index 191afc4d..bd357e51 100644 --- a/near-java-api-common/src/test/resources/log4j2-test.properties +++ b/near-java-api-common/src/test/resources/log4j2-test.properties @@ -1,4 +1,4 @@ -status = info +status = error dest = out name = NearJavaApi @@ -38,4 +38,4 @@ rootLogger.level = info rootLogger.appenderRef.stdout.ref = STDOUT logger.tests.name = com.syntifi.near.api -logger.tests.level = debug \ No newline at end of file +logger.tests.level = info \ No newline at end of file diff --git a/near-java-api-indexer/src/test/resources/log4j2-test.properties b/near-java-api-indexer/src/test/resources/log4j2-test.properties index 191afc4d..bd357e51 100644 --- a/near-java-api-indexer/src/test/resources/log4j2-test.properties +++ b/near-java-api-indexer/src/test/resources/log4j2-test.properties @@ -1,4 +1,4 @@ -status = info +status = error dest = out name = NearJavaApi @@ -38,4 +38,4 @@ rootLogger.level = info rootLogger.appenderRef.stdout.ref = STDOUT logger.tests.name = com.syntifi.near.api -logger.tests.level = debug \ No newline at end of file +logger.tests.level = info \ No newline at end of file diff --git a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/AccountServiceTest.java b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/AccountServiceTest.java index 5cf05128..d3e01625 100644 --- a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/AccountServiceTest.java +++ b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/AccountServiceTest.java @@ -11,6 +11,7 @@ import com.syntifi.near.api.common.model.key.PublicKey; import com.syntifi.near.api.rpc.model.transaction.Status; import com.syntifi.near.api.rpc.model.transaction.TransactionAwait; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,6 +29,12 @@ public class AccountServiceTest extends AbstractKeyTest { private static final Logger LOGGER = LoggerFactory.getLogger(AccountServiceTest.class); + // INFO: There must be a delay for the blockchain to process each call + @BeforeEach + void wait_for_network() throws InterruptedException { + Thread.sleep(5000); + } + @Test void createImplicitAccountFromMnemonic_should_getStatus_SuccessValueStatus() throws GeneralSecurityException, IOException, MnemonicException.MnemonicLengthException { MnemonicCode mnemonicCode = new MnemonicCode(Language.EN); @@ -40,10 +47,10 @@ void createImplicitAccountFromMnemonic_should_getStatus_SuccessValueStatus() thr LOGGER.debug(Hex.encode(newPublicKey.getData())); LOGGER.debug("=============> Privatekey "); LOGGER.debug(Hex.encode(newPrivateKey.getData())); - String signerId = "syntifi-alice.testnet"; + String signerId = "syntifi-bob.testnet"; BigInteger amount = new BigInteger(Formats.parseNearAmount("1"), 10); - PrivateKey privateKey = aliceNearPrivateKey; - PublicKey publicKey = aliceNearPublicKey; + PrivateKey privateKey = bobNearPrivateKey; + PublicKey publicKey = bobNearPublicKey; TransactionAwait transactionAwait = TransferService .sendTransferActionAwait(nearClient, signerId, Hex.encode(newPublicKey.getData()), publicKey, privateKey, amount); diff --git a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/TransferServiceTest.java b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/TransferServiceTest.java index 1c3a6f6a..57ad1708 100644 --- a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/TransferServiceTest.java +++ b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/TransferServiceTest.java @@ -11,6 +11,7 @@ import com.syntifi.near.api.rpc.model.identifier.Finality; import com.syntifi.near.api.rpc.model.transaction.*; import com.syntifi.near.borshj.Borsh; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.math.BigInteger; @@ -26,6 +27,12 @@ public class TransferServiceTest extends AbstractKeyTest { + // INFO: There must be a delay for the blockchain to process each call + @BeforeEach + void wait_for_network() throws InterruptedException { + Thread.sleep(1000); + } + @Test void serializeSignAndDeserializeVerifyTransaction_should_match() throws GeneralSecurityException { String signerId = "syntifi-alice.testnet"; diff --git a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/ft/FTServiceTest.java b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/ft/FTServiceTest.java index b8070d62..4e78ec77 100644 --- a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/ft/FTServiceTest.java +++ b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/ft/FTServiceTest.java @@ -1,6 +1,5 @@ package com.syntifi.near.api.rpc.service.ft; -import com.fasterxml.jackson.databind.JsonNode; import com.syntifi.near.api.common.key.AbstractKeyTest; import com.syntifi.near.api.common.model.key.PrivateKey; import com.syntifi.near.api.common.model.key.PublicKey; @@ -11,6 +10,7 @@ import com.syntifi.near.api.rpc.service.contract.common.FunctionCallResult; import com.syntifi.near.api.rpc.service.contract.ft.FTService; import com.syntifi.near.api.rpc.service.contract.ft.model.FTTokenMetadata; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -28,6 +28,12 @@ public class FTServiceTest extends AbstractKeyTest { private static final FTService service = ContractClient.createClientProxy(FTService.class, new ContractMethodProxyClient()); + // INFO: There must be a delay for the blockchain to process each call + @BeforeEach + void wait_for_network() throws InterruptedException { + Thread.sleep(1000); + } + @Test void testTotalSupply_should_be_greater_than_zero() { String tokenId = "ft.demo.testnet"; diff --git a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/nft/NFTServiceTest.java b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/nft/NFTServiceTest.java index 6c537f8d..db0529e2 100644 --- a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/nft/NFTServiceTest.java +++ b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/nft/NFTServiceTest.java @@ -13,6 +13,7 @@ import com.syntifi.near.api.rpc.service.contract.nft.model.NFTToken; import com.syntifi.near.api.rpc.service.contract.nft.model.NFTTokenList; import com.syntifi.near.api.rpc.service.contract.nft.model.NFTTokenMediaURL; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -29,6 +30,12 @@ public class NFTServiceTest extends AbstractKeyTest { private static final NFTService service = ContractClient.createClientProxy(NFTService.class, new ContractMethodProxyClient()); + // INFO: There must be a delay for the blockchain to process each call + @BeforeEach + void wait_for_network() throws InterruptedException { + Thread.sleep(1000); + } + @Test void callContractFunction_NFTContractFunctionCall_forTotalSupply_return_list() { FunctionCallResult result = service.getTotalSupply(nearClient, diff --git a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/staking/StakingServiceTest.java b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/staking/StakingServiceTest.java index 47066729..b237bc33 100644 --- a/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/staking/StakingServiceTest.java +++ b/near-java-api-rpc/src/test/java/com/syntifi/near/api/rpc/service/staking/StakingServiceTest.java @@ -16,7 +16,7 @@ import com.syntifi.near.api.rpc.service.contract.common.FunctionCallResult; import com.syntifi.near.api.rpc.service.contract.staking.StakingService; import com.syntifi.near.api.rpc.service.contract.staking.model.RewardFee; -import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,10 +24,7 @@ import java.math.BigInteger; import static com.syntifi.near.api.rpc.NearClientTestnetHelper.nearClient; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; class StakingServiceTest extends AbstractKeyTest { @@ -37,6 +34,12 @@ class StakingServiceTest extends AbstractKeyTest { private static final Logger LOGGER = LoggerFactory.getLogger(AccountServiceTest.class); private static final StakingService service = ContractClient.createClientProxy(StakingService.class, new ContractMethodProxyClient()); + // INFO: There must be a delay for the blockchain to process each call + @BeforeEach + void wait_for_network() throws InterruptedException { + Thread.sleep(1000); + } + @Test void testAccountTotalBalance_should_be_bigger_than_zero() { String stakingPool = "stakesstone.pool.f863973.m0"; diff --git a/near-java-api-rpc/src/test/resources/log4j2-test.properties b/near-java-api-rpc/src/test/resources/log4j2-test.properties index 770ed17d..69a90b76 100644 --- a/near-java-api-rpc/src/test/resources/log4j2-test.properties +++ b/near-java-api-rpc/src/test/resources/log4j2-test.properties @@ -1,4 +1,4 @@ -status = info +status = error dest = out name = NearJavaApi @@ -38,7 +38,7 @@ rootLogger.level = info rootLogger.appenderRef.stdout.ref = STDOUT logger.tests.name = com.syntifi.near.api -logger.tests.level = trace +logger.tests.level = info logger.tests-rpc.name = com.googlecode.jsonrpc4j -logger.tests-rpc.level = debug \ No newline at end of file +logger.tests-rpc.level = info \ No newline at end of file