diff --git a/hedera-node/hedera-mono-service/src/main/resources/bootstrap.properties b/hedera-node/hedera-mono-service/src/main/resources/bootstrap.properties index 2715955b13cd..ebe8c80c8d70 100644 --- a/hedera-node/hedera-mono-service/src/main/resources/bootstrap.properties +++ b/hedera-node/hedera-mono-service/src/main/resources/bootstrap.properties @@ -38,7 +38,7 @@ files.throttleDefinitions=123 hedera.firstUserEntity=1001 hedera.realm=0 hedera.shard=0 -ledger.id=0x03 +ledger.id=0x00 ledger.numSystemAccounts=100 ledger.totalTinyBarFloat=5000000000000000000 staking.maxStakeRewarded=5000000000000000000 @@ -76,7 +76,7 @@ contracts.freeStorageTierLimit=100 contracts.itemizeStorageFees=true contracts.keys.legacyActivations=1058134by[1062784] contracts.knownBlockHash= -contracts.localCall.estRetBytes=32 +contracts.localCall.estRetBytes=4096 contracts.maxGasPerSec=15000000 contracts.maxKvPairs.aggregate=500_000_000 contracts.maxKvPairs.individual=163_840 diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/HapiSpecOperation.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/HapiSpecOperation.java index 65a211e40ddb..0b9559cdd4e3 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/HapiSpecOperation.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/HapiSpecOperation.java @@ -116,7 +116,7 @@ public abstract class HapiSpecOperation { protected boolean useRandomNode = false; protected boolean unavailableNode = false; protected Set skipIfAutoScheduling = Collections.emptySet(); - protected Optional expectedLedgerId = Optional.empty(); + protected Optional expectedLedgerId = Optional.empty(); protected Optional hardcodedNumPayerKeys = Optional.empty(); protected Optional sigMapGen = Optional.empty(); protected Optional>> signers = Optional.empty(); diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/HapiQueryOp.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/HapiQueryOp.java index 96604d9e2228..c4017f752dad 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/HapiQueryOp.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/HapiQueryOp.java @@ -30,6 +30,7 @@ import static java.lang.Thread.sleep; import static java.util.stream.Collectors.toList; +import com.google.protobuf.ByteString; import com.hedera.node.app.hapi.utils.fee.SigValueObj; import com.hedera.services.bdd.spec.HapiPropertySource; import com.hedera.services.bdd.spec.HapiSpec; @@ -417,7 +418,7 @@ public T numPayerSigs(int hardcoded) { return self(); } - public T hasExpectedLedgerId(String ledgerId) { + public T hasEncodedLedgerId(ByteString ledgerId) { this.expectedLedgerId = Optional.of(ledgerId); return self(); } diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/consensus/HapiGetTopicInfo.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/consensus/HapiGetTopicInfo.java index a4393d865e54..3bc30cac3037 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/consensus/HapiGetTopicInfo.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/consensus/HapiGetTopicInfo.java @@ -185,7 +185,7 @@ protected void assertExpectationsGiven(HapiSpec spec) { if (hasNoAdminKey) { assertFalse(info.hasAdminKey(), "Should have no admin key!"); } - expectedLedgerId.ifPresent(id -> Assertions.assertEquals(rationalize(id), info.getLedgerId())); + expectedLedgerId.ifPresent(id -> Assertions.assertEquals(id, info.getLedgerId())); } @Override diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/contract/HapiGetContractInfo.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/contract/HapiGetContractInfo.java index e777896ec05d..e84a821bf8b0 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/contract/HapiGetContractInfo.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/contract/HapiGetContractInfo.java @@ -142,7 +142,7 @@ protected void assertExpectationsGiven(HapiSpec spec) throws Throwable { var actualTokenRels = actualInfo.getTokenRelationshipsList(); assertExpectedRels(contract, relationships, actualTokenRels, spec); assertNoUnexpectedRels(contract, absentRelationships, actualTokenRels, spec); - expectedLedgerId.ifPresent(id -> Assertions.assertEquals(rationalize(id), actualInfo.getLedgerId())); + expectedLedgerId.ifPresent(id -> Assertions.assertEquals(id, actualInfo.getLedgerId())); } @Override diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/crypto/HapiGetAccountDetails.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/crypto/HapiGetAccountDetails.java index c93669614b2e..a922dc06a53c 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/crypto/HapiGetAccountDetails.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/crypto/HapiGetAccountDetails.java @@ -201,7 +201,7 @@ protected void assertExpectationsGiven(HapiSpec spec) throws Throwable { } assertEquals(actualCount, usedCount); }); - expectedLedgerId.ifPresent(id -> assertEquals(rationalize(id), details.getLedgerId())); + expectedLedgerId.ifPresent(id -> assertEquals(id, details.getLedgerId())); tokenAssociationsCount.ifPresent(count -> assertEquals(count, details.getTokenRelationshipsCount())); } diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/crypto/HapiGetAccountInfo.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/crypto/HapiGetAccountInfo.java index 2c6c78b17caa..16e9762e2b0a 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/crypto/HapiGetAccountInfo.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/crypto/HapiGetAccountInfo.java @@ -72,6 +72,9 @@ public class HapiGetAccountInfo extends HapiQueryOp { @Nullable private Consumer aliasObserver = null; + @Nullable + private Consumer ledgerIdObserver = null; + private Optional> contractAccountIdObserver = Optional.empty(); private Optional tokenAssociationsCount = Optional.empty(); private boolean assertAliasKeyMatches = false; @@ -139,6 +142,11 @@ public HapiGetAccountInfo exposingAliasTo(Consumer obs) { return this; } + public HapiGetAccountInfo exposingLedgerIdTo(Consumer obs) { + this.ledgerIdObserver = obs; + return this; + } + public HapiGetAccountInfo exposingContractAccountIdTo(Consumer obs) { this.contractAccountIdObserver = Optional.of(obs); return this; @@ -240,7 +248,7 @@ protected void assertExpectationsGiven(HapiSpec spec) throws Throwable { } assertEquals(actualCount, usedCount); }); - expectedLedgerId.ifPresent(id -> assertEquals(rationalize(id), actualInfo.getLedgerId())); + expectedLedgerId.ifPresent(id -> assertEquals(id, actualInfo.getLedgerId())); tokenAssociationsCount.ifPresent(count -> assertEquals(count, actualInfo.getTokenRelationshipsCount())); } @@ -275,6 +283,8 @@ protected void submitWith(HapiSpec spec, Transaction payment) throws Throwable { Optional.ofNullable(aliasObserver) .ifPresent(cb -> cb.accept(infoResponse.getAccountInfo().getAlias().toByteArray())); + Optional.ofNullable(ledgerIdObserver) + .ifPresent(cb -> cb.accept(infoResponse.getAccountInfo().getLedgerId())); contractAccountIdObserver.ifPresent( cb -> cb.accept(infoResponse.getAccountInfo().getContractAccountID())); } diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/file/HapiGetFileInfo.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/file/HapiGetFileInfo.java index 8b95b57a3eac..c5d268592e88 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/file/HapiGetFileInfo.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/file/HapiGetFileInfo.java @@ -163,7 +163,7 @@ protected void assertExpectationsGiven(HapiSpec spec) throws Throwable { expiryTest.ifPresent( p -> Assertions.assertTrue(p.test(actual), String.format("Expiry of %d was not as expected!", actual))); expectedMemo.ifPresent(e -> Assertions.assertEquals(e, info.getMemo())); - expectedLedgerId.ifPresent(id -> Assertions.assertEquals(rationalize(id), info.getLedgerId())); + expectedLedgerId.ifPresent(id -> Assertions.assertEquals(id, info.getLedgerId())); } private Query getFileInfoQuery(HapiSpec spec, Transaction payment, boolean costOnly) { diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/schedule/HapiGetScheduleInfo.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/schedule/HapiGetScheduleInfo.java index b8ebbc65ec20..c85139d7df41 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/schedule/HapiGetScheduleInfo.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/schedule/HapiGetScheduleInfo.java @@ -218,7 +218,7 @@ protected void assertExpectationsGiven(HapiSpec spec) { "Wrong schedule admin key!", registry); - expectedLedgerId.ifPresent(id -> Assertions.assertEquals(rationalize(id), actualInfo.getLedgerId())); + expectedLedgerId.ifPresent(id -> Assertions.assertEquals(id, actualInfo.getLedgerId())); } private void assertTimestampMatches(String txn, int nanoOffset, Timestamp actual, String errMsg, HapiSpec spec) { diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/token/HapiGetTokenInfo.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/token/HapiGetTokenInfo.java index 735e09363651..c65dfc9295eb 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/token/HapiGetTokenInfo.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/token/HapiGetTokenInfo.java @@ -367,7 +367,7 @@ protected void assertExpectationsGiven(HapiSpec spec) { "Wrong token pause key!", registry); - expectedLedgerId.ifPresent(id -> Assertions.assertEquals(rationalize(id), actualInfo.getLedgerId())); + expectedLedgerId.ifPresent(id -> Assertions.assertEquals(id, actualInfo.getLedgerId())); } private void assertFor( diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/token/HapiGetTokenNftInfo.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/token/HapiGetTokenNftInfo.java index 42b3a4b4aaae..0ba2396467f7 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/token/HapiGetTokenNftInfo.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/token/HapiGetTokenNftInfo.java @@ -142,7 +142,7 @@ protected void assertExpectationsGiven(HapiSpec spec) throws Throwable { "Wrong token id!", registry); - expectedLedgerId.ifPresent(id -> assertEquals(rationalize(id), actualInfo.getLedgerId())); + expectedLedgerId.ifPresent(id -> assertEquals(id, actualInfo.getLedgerId())); } private void assertFor( diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/utilops/UtilVerbs.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/utilops/UtilVerbs.java index 3ebd27c6336c..35a27ab4eca5 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/utilops/UtilVerbs.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/utilops/UtilVerbs.java @@ -21,6 +21,7 @@ import static com.hedera.services.bdd.spec.assertions.ContractInfoAsserts.contractWith; import static com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith; import static com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance; +import static com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo; import static com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo; import static com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents; import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord; @@ -140,6 +141,7 @@ import com.hederahashgraph.api.proto.java.Transaction; import com.hederahashgraph.api.proto.java.TransactionBody; import com.hederahashgraph.api.proto.java.TransactionRecord; +import com.swirlds.common.utility.CommonUtils; import edu.umd.cs.findbugs.annotations.NonNull; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -308,6 +310,49 @@ public static CustomSpecAssert withOpContext(CustomSpecAssert.ThrowingConsumer c return new CustomSpecAssert(custom); } + private static final ByteString MAINNET_LEDGER_ID = ByteString.copyFrom(new byte[] {0x00}); + private static final ByteString TESTNET_LEDGER_ID = ByteString.copyFrom(new byte[] {0x01}); + private static final ByteString PREVIEWNET_LEDGER_ID = ByteString.copyFrom(new byte[] {0x02}); + private static final ByteString DEVNET_LEDGER_ID = ByteString.copyFrom(new byte[] {0x03}); + + private static final Set RECOGNIZED_LEDGER_IDS = + Set.of(MAINNET_LEDGER_ID, TESTNET_LEDGER_ID, PREVIEWNET_LEDGER_ID, DEVNET_LEDGER_ID); + + /** + * Returns an operation that uses a {@link com.hedera.services.bdd.spec.queries.crypto.HapiGetAccountInfo} query + * against the {@code 0.0.2} account to look up the ledger id of the target network; and then passes the ledger + * id to the given callback. + * + * @param ledgerIdConsumer the callback to pass the ledger id to + * @return the operation exposing the ledger id to the callback + */ + public static HapiSpecOperation exposeTargetLedgerIdTo(@NonNull final Consumer ledgerIdConsumer) { + return getAccountInfo(GENESIS).payingWith(GENESIS).exposingLedgerIdTo(ledgerId -> { + if (!RECOGNIZED_LEDGER_IDS.contains(ledgerId)) { + Assertions.fail( + "Target network is claiming unrecognized ledger id " + CommonUtils.hex(ledgerId.toByteArray())); + } + ledgerIdConsumer.accept(ledgerId); + }); + } + + /** + * A convenience operation that accepts a factory mapping the target ledger id into a {@link HapiSpecOperation} + * (for example, a query that asserts something about the ledger id); and then, + *
    + *
  1. Looks up the ledger id via {@link UtilVerbs#exposeTargetLedgerIdTo(Consumer)}; and,
  2. + *
  3. Calls the given factory with this id, and runs the resulting {@link HapiSpecOperation}.
  4. + *
+ * + * @param opFn the factory mapping the ledger id into a {@link HapiSpecOperation} + * @return the operation that looks up the ledger id and runs the resulting {@link HapiSpecOperation} + */ + public static HapiSpecOperation withTargetLedgerId(@NonNull final Function opFn) { + final AtomicReference targetLedgerId = new AtomicReference<>(); + return blockingOrder( + exposeTargetLedgerIdTo(targetLedgerId::set), sourcing(() -> opFn.apply(targetLedgerId.get()))); + } + public static BalanceSnapshot balanceSnapshot(String name, String forAccount) { return new BalanceSnapshot(forAccount, name); } diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/consensus/TopicGetInfoSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/consensus/TopicGetInfoSuite.java index c80dc0e12e6a..ba406d403753 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/consensus/TopicGetInfoSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/consensus/TopicGetInfoSuite.java @@ -24,14 +24,18 @@ import static com.hedera.services.bdd.spec.transactions.TxnVerbs.deleteTopic; import static com.hedera.services.bdd.spec.transactions.TxnVerbs.submitMessageTo; import static com.hedera.services.bdd.spec.transactions.TxnVerbs.updateTopic; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.exposeTargetLedgerIdTo; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOPIC_ID; +import com.google.protobuf.ByteString; import com.hedera.services.bdd.junit.HapiTest; import com.hedera.services.bdd.junit.HapiTestSuite; import com.hedera.services.bdd.spec.HapiSpec; import com.hedera.services.bdd.suites.HapiSuite; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -59,6 +63,7 @@ public boolean canRunConcurrent() { @HapiTest private HapiSpec allFieldsSetHappyCase() { // sequenceNumber should be 0 and runningHash should be 48 bytes all 0s. + final AtomicReference targetLedgerId = new AtomicReference<>(); return defaultHapiSpec("AllFieldsSetHappyCase") .given( newKeyNamed("adminKey"), @@ -73,14 +78,15 @@ private HapiSpec allFieldsSetHappyCase() { .via("createTopic")) .when() .then( - getTopicInfo(TEST_TOPIC) - .hasExpectedLedgerId("0x03") + exposeTargetLedgerIdTo(targetLedgerId::set), + sourcing(() -> getTopicInfo(TEST_TOPIC) + .hasEncodedLedgerId(targetLedgerId.get()) .hasMemo(TESTMEMO) .hasAdminKey("adminKey") .hasSubmitKey("submitKey") .hasAutoRenewAccount("autoRenewAccount") .hasSeqNo(0) - .hasRunningHash(new byte[48]), + .hasRunningHash(new byte[48])), getTxnRecord("createTopic").logged(), submitMessageTo(TEST_TOPIC) .blankMemo() @@ -88,26 +94,26 @@ private HapiSpec allFieldsSetHappyCase() { .message(new String("test".getBytes())) .via("submitMessage"), getTxnRecord("submitMessage").logged(), - getTopicInfo(TEST_TOPIC) - .hasExpectedLedgerId("0x03") + sourcing(() -> getTopicInfo(TEST_TOPIC) + .hasEncodedLedgerId(targetLedgerId.get()) .hasMemo(TESTMEMO) .hasAdminKey("adminKey") .hasSubmitKey("submitKey") .hasAutoRenewAccount("autoRenewAccount") .hasSeqNo(1) - .logged(), + .logged()), updateTopic(TEST_TOPIC) .topicMemo("Don't worry about the vase") .via("updateTopic"), getTxnRecord("updateTopic").logged(), - getTopicInfo(TEST_TOPIC) - .hasExpectedLedgerId("0x03") + sourcing(() -> getTopicInfo(TEST_TOPIC) + .hasEncodedLedgerId(targetLedgerId.get()) .hasMemo("Don't worry about the vase") .hasAdminKey("adminKey") .hasSubmitKey("submitKey") .hasAutoRenewAccount("autoRenewAccount") .hasSeqNo(1) - .logged(), + .logged()), deleteTopic(TEST_TOPIC).via("deleteTopic"), getTxnRecord("deleteTopic").logged(), getTopicInfo(TEST_TOPIC) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/hapi/ContractCallSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/hapi/ContractCallSuite.java index 1a82acb144f3..76f5baff2b41 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/hapi/ContractCallSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/hapi/ContractCallSuite.java @@ -1121,11 +1121,7 @@ HapiSpec ocToken() { ctxLog.info("symbol: [{}]", symbol); - Assertions.assertEquals("", symbol, "TokenIssuer's symbol should be fixed value"); // should - // be - // "OCT" - // as - // expected + Assertions.assertEquals("OCT", symbol, "TokenIssuer's symbol should be fixed value"); final var funcDecimals = Function.fromJson(getABIFor(FUNCTION, DECIMALS, contract)); final Integer decimals = getValueFromRegistry(spec, DECIMALS, funcDecimals); diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/hapi/ContractGetInfoSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/hapi/ContractGetInfoSuite.java index 916b146d7c63..0780959313ed 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/hapi/ContractGetInfoSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/hapi/ContractGetInfoSuite.java @@ -22,6 +22,7 @@ import static com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate; import static com.hedera.services.bdd.spec.transactions.TxnVerbs.uploadInitCode; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withTargetLedgerId; import com.hedera.services.bdd.junit.HapiTest; import com.hedera.services.bdd.junit.HapiTestSuite; @@ -68,10 +69,10 @@ private HapiSpec getInfoWorks() { .entityMemo(MEMO) .autoRenewSecs(6999999L)) .when() - .then(getContractInfo(contract) - .hasExpectedLedgerId("0x03") + .then(withTargetLedgerId(ledgerId -> getContractInfo(contract) + .hasEncodedLedgerId(ledgerId) .hasExpectedInfo() - .has(contractWith().memo(MEMO).adminKey("adminKey"))); + .has(contractWith().memo(MEMO).adminKey("adminKey")))); } @HapiTest diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenInfoHTSSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenInfoHTSSuite.java index 01966ac74a41..73e271f1ae96 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenInfoHTSSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenInfoHTSSuite.java @@ -40,6 +40,7 @@ import static com.hedera.services.bdd.spec.transactions.token.CustomFeeSpecs.royaltyFeeWithFallback; import static com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.exposeTargetLedgerIdTo; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext; import static com.hedera.services.bdd.suites.contract.Utils.asAddress; @@ -75,6 +76,7 @@ import java.util.ArrayList; import java.util.List; import java.util.OptionalLong; +import java.util.concurrent.atomic.AtomicReference; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes; @@ -154,6 +156,7 @@ List positiveSpecs() { } private HapiSpec happyPathGetTokenInfo() { + final AtomicReference targetLedgerId = new AtomicReference<>(); return defaultHapiSpec("HappyPathGetTokenInfo") .given( cryptoCreate(TOKEN_TREASURY).balance(0L), @@ -211,7 +214,7 @@ private HapiSpec happyPathGetTokenInfo() { GET_INFORMATION_FOR_TOKEN, HapiParserUtil.asHeadlongAddress( asAddress(spec.registry().getTokenID(PRIMARY_TOKEN_NAME))))))) - .then(withOpContext((spec, opLog) -> { + .then(exposeTargetLedgerIdTo(targetLedgerId::set), withOpContext((spec, opLog) -> { final var getTokenInfoQuery = getTokenInfo(PRIMARY_TOKEN_NAME); allRunFor(spec, getTokenInfoQuery); final var expirySecond = getTokenInfoQuery @@ -240,12 +243,14 @@ private HapiSpec happyPathGetTokenInfo() { MEMO, spec.registry() .getAccountID(TOKEN_TREASURY), - expirySecond)))))); + expirySecond, + targetLedgerId.get())))))); })); } private HapiSpec happyPathGetFungibleTokenInfo() { final int decimals = 1; + final AtomicReference targetLedgerId = new AtomicReference<>(); return defaultHapiSpec("HappyPathGetFungibleTokenInfo") .given( cryptoCreate(TOKEN_TREASURY).balance(0L), @@ -303,7 +308,7 @@ private HapiSpec happyPathGetFungibleTokenInfo() { GET_INFORMATION_FOR_FUNGIBLE_TOKEN, HapiParserUtil.asHeadlongAddress( asAddress(spec.registry().getTokenID(FUNGIBLE_TOKEN_NAME))))))) - .then(withOpContext((spec, opLog) -> { + .then(exposeTargetLedgerIdTo(targetLedgerId::set), withOpContext((spec, opLog) -> { final var getTokenInfoQuery = getTokenInfo(FUNGIBLE_TOKEN_NAME); allRunFor(spec, getTokenInfoQuery); final var expirySecond = getTokenInfoQuery @@ -332,13 +337,15 @@ private HapiSpec happyPathGetFungibleTokenInfo() { MEMO, spec.registry() .getAccountID(TOKEN_TREASURY), - expirySecond)))))); + expirySecond, + targetLedgerId.get())))))); })); } private HapiSpec happyPathGetNonFungibleTokenInfo() { final int maxSupply = 10; final ByteString meta = ByteString.copyFrom(META.getBytes(StandardCharsets.UTF_8)); + final AtomicReference targetLedgerId = new AtomicReference<>(); return defaultHapiSpec("HappyPathGetNonFungibleTokenInfo") .given( cryptoCreate(TOKEN_TREASURY).balance(0L), @@ -406,7 +413,7 @@ private HapiSpec happyPathGetNonFungibleTokenInfo() { HapiParserUtil.asHeadlongAddress( asAddress(spec.registry().getTokenID(NON_FUNGIBLE_TOKEN_NAME))), 1L)))) - .then(withOpContext((spec, opLog) -> { + .then(exposeTargetLedgerIdTo(targetLedgerId::set), withOpContext((spec, opLog) -> { final var getTokenInfoQuery = getTokenInfo(NON_FUNGIBLE_TOKEN_NAME); allRunFor(spec, getTokenInfoQuery); final var expirySecond = getTokenInfoQuery @@ -416,7 +423,8 @@ private HapiSpec happyPathGetNonFungibleTokenInfo() { .getExpiry() .getSeconds(); - final var nftTokenInfo = getTokenNftInfoForCheck(spec, getTokenInfoQuery, meta); + final var nftTokenInfo = + getTokenNftInfoForCheck(spec, getTokenInfoQuery, meta, targetLedgerId.get()); allRunFor( spec, @@ -439,7 +447,8 @@ private HapiSpec happyPathGetNonFungibleTokenInfo() { MEMO, spec.registry() .getAccountID(TOKEN_TREASURY), - expirySecond)) + expirySecond, + targetLedgerId.get())) .withNftTokenInfo(nftTokenInfo))))); })); } @@ -751,7 +760,7 @@ private HapiSpec happyPathGetNonFungibleTokenCustomFees() { } private TokenNftInfo getTokenNftInfoForCheck( - final HapiSpec spec, final HapiGetTokenInfo getTokenInfoQuery, final ByteString meta) { + final HapiSpec spec, final HapiGetTokenInfo getTokenInfoQuery, final ByteString meta, ByteString ledgerId) { final var tokenId = getTokenInfoQuery.getResponse().getTokenGetInfo().getTokenInfo().getTokenId(); @@ -764,7 +773,7 @@ private TokenNftInfo getTokenNftInfoForCheck( final var spenderId = spec.registry().getAccountID(NFT_SPENDER); return TokenNftInfo.newBuilder() - .setLedgerId(fromString("0x03")) + .setLedgerId(ledgerId) .setNftID(NftID.newBuilder() .setTokenID(tokenId) .setSerialNumber(1L) @@ -782,13 +791,14 @@ private TokenInfo getTokenInfoStructForFungibleToken( final String symbol, final String memo, final AccountID treasury, - final long expirySecond) { + final long expirySecond, + ByteString ledgerId) { final var autoRenewAccount = spec.registry().getAccountID(AUTO_RENEW_ACCOUNT); final ArrayList customFees = getExpectedCustomFees(spec); return TokenInfo.newBuilder() - .setLedgerId(fromString("0x03")) + .setLedgerId(ledgerId) .setSupplyTypeValue(TokenSupplyType.FINITE_VALUE) .setExpiry(Timestamp.newBuilder().setSeconds(expirySecond)) .setAutoRenewAccount(autoRenewAccount) @@ -858,11 +868,12 @@ private TokenInfo getTokenInfoStructForNonFungibleToken( final String symbol, final String memo, final AccountID treasury, - final long expirySecond) { + final long expirySecond, + final ByteString ledgerId) { final var autoRenewAccount = spec.registry().getAccountID(AUTO_RENEW_ACCOUNT); return TokenInfo.newBuilder() - .setLedgerId(fromString("0x03")) + .setLedgerId(ledgerId) .setSupplyTypeValue(TokenSupplyType.FINITE_VALUE) .setExpiry(Timestamp.newBuilder().setSeconds(expirySecond)) .setAutoRenewAccount(autoRenewAccount) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenInfoHTSV1SecurityModelSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenInfoHTSV1SecurityModelSuite.java index ab97d94ecb87..ef457dcad4f5 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenInfoHTSV1SecurityModelSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenInfoHTSV1SecurityModelSuite.java @@ -40,6 +40,7 @@ import static com.hedera.services.bdd.spec.transactions.token.CustomFeeSpecs.royaltyFeeWithFallback; import static com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.exposeTargetLedgerIdTo; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.overridingTwo; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext; @@ -78,6 +79,7 @@ import java.util.ArrayList; import java.util.List; import java.util.OptionalLong; +import java.util.concurrent.atomic.AtomicReference; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes; @@ -158,6 +160,7 @@ List positiveSpecs() { private HapiSpec happyPathUpdateTokenInfoAndGetLatestInfo() { final int decimals = 1; + final AtomicReference targetLedgerId = new AtomicReference<>(); return propertyPreservingHapiSpec("happyPathUpdateTokenInfoAndGetLatestInfo") .preserving(CONTRACTS_ALLOW_SYSTEM_USE_OF_HAPI_SIGS, CONTRACTS_MAX_NUM_WITH_HAPI_SIGS_ACCESS) .given( @@ -229,7 +232,7 @@ private HapiSpec happyPathUpdateTokenInfoAndGetLatestInfo() { .payingWith(ACCOUNT) .via(UPDATE_ANG_GET_TOKEN_INFO_TXN) .gas(1_000_000L)))) - .then(withOpContext((spec, opLog) -> { + .then(exposeTargetLedgerIdTo(targetLedgerId::set), withOpContext((spec, opLog) -> { final var getTokenInfoQuery = getTokenInfo(FUNGIBLE_TOKEN_NAME); allRunFor(spec, getTokenInfoQuery); final var expirySecond = getTokenInfoQuery @@ -261,12 +264,14 @@ private HapiSpec happyPathUpdateTokenInfoAndGetLatestInfo() { UPDATE_MEMO, spec.registry() .getAccountID(UPDATED_TREASURY), - expirySecond)))))); + expirySecond, + targetLedgerId.get())))))); })); } private HapiSpec happyPathUpdateFungibleTokenInfoAndGetLatestInfo() { final int decimals = 1; + final AtomicReference targetLedgerId = new AtomicReference<>(); return propertyPreservingHapiSpec("happyPathUpdateFungibleTokenInfoAndGetLatestInfo") .preserving(CONTRACTS_ALLOW_SYSTEM_USE_OF_HAPI_SIGS, CONTRACTS_MAX_NUM_WITH_HAPI_SIGS_ACCESS) .given( @@ -335,7 +340,7 @@ private HapiSpec happyPathUpdateFungibleTokenInfoAndGetLatestInfo() { .payingWith(ACCOUNT) .via(UPDATE_ANG_GET_FUNGIBLE_TOKEN_INFO_TXN) .gas(1_000_000L)))) - .then(withOpContext((spec, opLog) -> { + .then(exposeTargetLedgerIdTo(targetLedgerId::set), withOpContext((spec, opLog) -> { final var getTokenInfoQuery = getTokenInfo(FUNGIBLE_TOKEN_NAME); allRunFor(spec, getTokenInfoQuery); final var expirySecond = getTokenInfoQuery @@ -367,13 +372,15 @@ private HapiSpec happyPathUpdateFungibleTokenInfoAndGetLatestInfo() { UPDATE_MEMO, spec.registry() .getAccountID(UPDATED_TREASURY), - expirySecond)))))); + expirySecond, + targetLedgerId.get())))))); })); } private HapiSpec happyPathUpdateNonFungibleTokenInfoAndGetLatestInfo() { final int maxSupply = 10; final ByteString meta = ByteString.copyFrom(META.getBytes(StandardCharsets.UTF_8)); + final AtomicReference targetLedgerId = new AtomicReference<>(); return propertyPreservingHapiSpec("happyPathUpdateNonFungibleTokenInfoAndGetLatestInfo") .preserving(CONTRACTS_ALLOW_SYSTEM_USE_OF_HAPI_SIGS, CONTRACTS_MAX_NUM_WITH_HAPI_SIGS_ACCESS) .given( @@ -451,7 +458,7 @@ private HapiSpec happyPathUpdateNonFungibleTokenInfoAndGetLatestInfo() { .alsoSigningWithFullPrefix(ADMIN_KEY, UPDATED_TREASURY) .via(UPDATE_ANG_GET_NON_FUNGIBLE_TOKEN_INFO_TXN) .gas(1_000_000L)))) - .then(withOpContext((spec, opLog) -> { + .then(exposeTargetLedgerIdTo(targetLedgerId::set), withOpContext((spec, opLog) -> { final var getTokenInfoQuery = getTokenInfo(NON_FUNGIBLE_TOKEN_NAME); allRunFor(spec, getTokenInfoQuery); final var expirySecond = getTokenInfoQuery @@ -461,8 +468,8 @@ private HapiSpec happyPathUpdateNonFungibleTokenInfoAndGetLatestInfo() { .getExpiry() .getSeconds(); - final var nftTokenInfo = getTokenNftInfoForCheck(spec, getTokenInfoQuery, meta); - + final var nftTokenInfo = + getTokenNftInfoForCheck(spec, getTokenInfoQuery, meta, targetLedgerId.get()); allRunFor( spec, getTxnRecord(UPDATE_ANG_GET_NON_FUNGIBLE_TOKEN_INFO_TXN) @@ -485,7 +492,8 @@ private HapiSpec happyPathUpdateNonFungibleTokenInfoAndGetLatestInfo() { UPDATE_MEMO, spec.registry() .getAccountID(UPDATED_TREASURY), - expirySecond)) + expirySecond, + targetLedgerId.get())) .withNftTokenInfo(nftTokenInfo))))); })); } @@ -608,7 +616,7 @@ private HapiSpec happyPathUpdateTokenKeysAndReadLatestInformation() { } private TokenNftInfo getTokenNftInfoForCheck( - final HapiSpec spec, final HapiGetTokenInfo getTokenInfoQuery, final ByteString meta) { + final HapiSpec spec, final HapiGetTokenInfo getTokenInfoQuery, final ByteString meta, ByteString ledgerId) { final var tokenId = getTokenInfoQuery.getResponse().getTokenGetInfo().getTokenInfo().getTokenId(); @@ -621,7 +629,7 @@ private TokenNftInfo getTokenNftInfoForCheck( final var spenderId = spec.registry().getAccountID(NFT_SPENDER); return TokenNftInfo.newBuilder() - .setLedgerId(fromString("0x03")) + .setLedgerId(ledgerId) .setNftID(NftID.newBuilder() .setTokenID(tokenId) .setSerialNumber(1L) @@ -639,13 +647,14 @@ private TokenInfo getTokenInfoStructForFungibleToken( final String symbol, final String memo, final AccountID treasury, - final long expirySecond) { + final long expirySecond, + ByteString ledgerId) { final var autoRenewAccount = spec.registry().getAccountID(AUTO_RENEW_ACCOUNT); final ArrayList customFees = getExpectedCustomFees(spec); return TokenInfo.newBuilder() - .setLedgerId(fromString("0x03")) + .setLedgerId(ledgerId) .setSupplyTypeValue(TokenSupplyType.FINITE_VALUE) .setExpiry(Timestamp.newBuilder().setSeconds(expirySecond)) .setAutoRenewAccount(autoRenewAccount) @@ -715,11 +724,12 @@ private TokenInfo getTokenInfoStructForNonFungibleToken( final String symbol, final String memo, final AccountID treasury, - final long expirySecond) { + final long expirySecond, + final ByteString ledgerId) { final var autoRenewAccount = spec.registry().getAccountID(AUTO_RENEW_ACCOUNT); return TokenInfo.newBuilder() - .setLedgerId(fromString("0x03")) + .setLedgerId(ledgerId) .setSupplyTypeValue(TokenSupplyType.FINITE_VALUE) .setExpiry(Timestamp.newBuilder().setSeconds(expirySecond)) .setAutoRenewAccount(autoRenewAccount) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/crypto/CryptoTransferSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/crypto/CryptoTransferSuite.java index 662c91273e4d..4ff78d652043 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/crypto/CryptoTransferSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/crypto/CryptoTransferSuite.java @@ -89,6 +89,7 @@ import static com.hedera.services.bdd.spec.utilops.UtilVerbs.usableTxnIdNamed; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.validateChargedUsdWithin; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withTargetLedgerId; import static com.hedera.services.bdd.suites.contract.Utils.aaWith; import static com.hedera.services.bdd.suites.contract.Utils.accountId; import static com.hedera.services.bdd.suites.contract.Utils.captureOneChildCreate2MetaFor; @@ -1822,10 +1823,10 @@ private HapiSpec vanillaTransferSucceeds() { tinyBarsFromTo(PAYER, PAYEE_NO_SIG_REQ, 2_000L)) .via("transferTxn")) .then( - getAccountInfo(PAYER) + withTargetLedgerId(ledgerId -> getAccountInfo(PAYER) .logged() - .hasExpectedLedgerId("0x03") - .has(accountWith().balance(initialBalance - 3_000L)), + .hasEncodedLedgerId(ledgerId) + .has(accountWith().balance(initialBalance - 3_000L))), getAccountInfo(PAYEE_SIG_REQ).has(accountWith().balance(initialBalance + 1_000L)), getAccountDetails(PAYEE_NO_SIG_REQ) .payingWith(GENESIS) diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/file/FileCreateSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/file/FileCreateSuite.java index de28a1f0b5e6..b9d93e8928a9 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/file/FileCreateSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/file/FileCreateSuite.java @@ -33,6 +33,7 @@ import static com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate; import static com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.balanceSnapshot; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withTargetLedgerId; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_NODE_ACCOUNT; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE; @@ -111,7 +112,8 @@ private HapiSpec createWithMemoWorks() { fileCreate("ntb").entityMemo(ZERO_BYTE_MEMO).hasPrecheck(INVALID_ZERO_BYTE_IN_STRING), fileCreate("memorable").entityMemo(memo)) .when() - .then(getFileInfo("memorable").hasExpectedLedgerId("0x03").hasMemo(memo)); + .then(withTargetLedgerId(ledgerId -> + getFileInfo("memorable").hasEncodedLedgerId(ledgerId).hasMemo(memo))); } @HapiTest diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/token/TokenTransactSpecs.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/token/TokenTransactSpecs.java index beb5a178e455..af06e0a5442b 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/token/TokenTransactSpecs.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/token/TokenTransactSpecs.java @@ -63,6 +63,7 @@ import static com.hedera.services.bdd.spec.utilops.UtilVerbs.blockingOrder; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.inParallel; import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed; +import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withTargetLedgerId; import static com.hedera.services.bdd.suites.crypto.AutoAccountCreationSuite.VALID_ALIAS; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_AMOUNT_TRANSFERS_ONLY_ALLOWED_FOR_FUNGIBLE_COMMON; import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_DELETED; @@ -1078,7 +1079,7 @@ public HapiSpec uniqueTokenTxnAccountBalance() { .then( getAccountBalance(TOKEN_TREASURY).hasTokenBalance(A_TOKEN, 0), getAccountBalance(FIRST_USER).hasTokenBalance(A_TOKEN, 1), - getTokenInfo(A_TOKEN).hasExpectedLedgerId("0x03"), + withTargetLedgerId(ledgerId -> getTokenInfo(A_TOKEN).hasEncodedLedgerId(ledgerId)), getTokenNftInfo(A_TOKEN, 1) .hasSerialNum(1) .hasMetadata(copyFromUtf8("memo")) @@ -1114,12 +1115,12 @@ public HapiSpec uniqueTokenTxnAccountBalancesForTreasury() { getAccountBalance(OLD_TREASURY).hasTokenBalance(A_TOKEN, 0), getAccountBalance(NEW_TREASURY).hasTokenBalance(A_TOKEN, 1), getAccountBalance(NEW_TREASURY).hasTokenBalance(B_TOKEN, 1), - getTokenNftInfo(A_TOKEN, 1) - .hasExpectedLedgerId("0x03") + withTargetLedgerId(ledgerId -> getTokenNftInfo(A_TOKEN, 1) + .hasEncodedLedgerId(ledgerId) .hasSerialNum(1) .hasMetadata(copyFromUtf8("memo")) .hasTokenID(A_TOKEN) - .hasAccountID(NEW_TREASURY)); + .hasAccountID(NEW_TREASURY))); } @HapiTest