Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add revertedAutoCreationRollsBackEvenIfTopLevelSucceeds to LazyCreateThroughPrecompileSuite and enable fuzzy-matching on it #11131

Merged

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,6 @@ public HapiGetTxnRecord assertingNothingAboutHashes() {
return this;
}

public HapiGetTxnRecord hasChildRecordCount(final int count) {
requestChildRecords = true;
childRecordsCount = OptionalInt.of(count);
return this;
}

public HapiGetTxnRecord hasNonStakingChildRecordCount(final int count) {
requestChildRecords = true;
includeStakingRecordsInCount = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getAliasedAccountInfo;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getLiteralAliasAccountInfo;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenNftInfo;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoApproveAllowance;
Expand All @@ -48,8 +49,12 @@
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.ifNotHapiTest;
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.snapshotMode;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.ACCEPTED_MONO_GAS_CALCULATION_DIFFERENCE;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_FUNCTION_PARAMETERS;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMode.FUZZY_MATCH_AGAINST_HAPI_TEST_STREAMS;
import static com.hedera.services.bdd.suites.contract.Utils.asAddress;
import static com.hedera.services.bdd.suites.contract.Utils.headlongFromHexed;
import static com.hedera.services.bdd.suites.contract.Utils.mirrorAddrWith;
Expand Down Expand Up @@ -655,4 +660,62 @@ final HapiSpec htsTransferFromForNFTLazyCreate() {
}))
.then();
}

@HapiTest
final HapiSpec revertedAutoCreationRollsBackEvenIfTopLevelSucceeds() {
return defaultHapiSpec("revertedAutoCreationRollsBackEvenIfTopLevelSucceeds")
.given(
snapshotMode(
FUZZY_MATCH_AGAINST_HAPI_TEST_STREAMS,
NONDETERMINISTIC_FUNCTION_PARAMETERS,
ACCEPTED_MONO_GAS_CALCULATION_DIFFERENCE),
newKeyNamed(ECDSA_KEY).shape(SECP_256K1_SHAPE),
newKeyNamed(MULTI_KEY),
cryptoCreate(OWNER).balance(100 * ONE_HUNDRED_HBARS).maxAutomaticTokenAssociations(5),
tokenCreate(NFT_TOKEN)
.tokenType(TokenType.NON_FUNGIBLE_UNIQUE)
.treasury(OWNER)
.initialSupply(0L)
.supplyKey(MULTI_KEY),
uploadInitCode(AUTO_CREATION_MODES),
contractCreate(AUTO_CREATION_MODES),
mintToken(NFT_TOKEN, List.of(META1, META2)),
cryptoApproveAllowance()
.payingWith(DEFAULT_PAYER)
.addNftAllowance(OWNER, NFT_TOKEN, AUTO_CREATION_MODES, false, List.of(2L))
.via(BASE_APPROVE_TXN)
.signedBy(DEFAULT_PAYER, OWNER)
.fee(ONE_HBAR))
.when(withOpContext((spec, opLog) -> {
final var ecdsaKey = spec.registry().getKey(ECDSA_KEY);
final var tmp = ecdsaKey.getECDSASecp256K1().toByteArray();
final var addressBytes = recoverAddressFromPubKey(tmp);
allRunFor(
spec,
// transfer allowed NFT
contractCall(
AUTO_CREATION_MODES,
"createIndirectlyRevertingAndRecover",
HapiParserUtil.asHeadlongAddress(
asAddress(spec.registry().getTokenID(NFT_TOKEN))),
HapiParserUtil.asHeadlongAddress(
asAddress(spec.registry().getAccountID(OWNER))),
HapiParserUtil.asHeadlongAddress(addressBytes),
2L)
.gas(GAS_TO_OFFER)
.via(TRANSFER_TXN)
.alsoSigningWithFullPrefix(OWNER)
.hasKnownStatus(SUCCESS));
}))
.then(
getTxnRecord(TRANSFER_TXN).hasNonStakingChildRecordCount(1),
childRecordsCheck(
TRANSFER_TXN,
SUCCESS,
recordWith()
.status(REVERTED_SUCCESS)
.contractCallResult(resultWith()
.contractCallResult(
htsPrecompileResult().withStatus(SUCCESS)))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ final HapiSpec prngPrecompileHappyPathWorks() {
.logged()))
.then(getTxnRecord(randomBits)
.andAllChildRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith()
.pseudoRandomBytes()
.contractCallResult(resultWith()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ final HapiSpec autoAccountCreationWorksWhenUsingAliasOfDeletedAccount() {
// HapiCryptoTransfer.tinyBarsFromToWithAlias("payer", "alias",
// ONE_HUNDRED_HBARS)).via(
// "txn2"),
// getTxnRecord("txn2").hasChildRecordCount(1).logged()
// getTxnRecord("txn2").hasNonStakingChildRecordCount(1).logged()
);
}

Expand Down Expand Up @@ -1395,7 +1395,7 @@ final HapiSpec transferHbarsToEVMAddressAlias() {
}))
.then(
getTxnRecord(HBAR_XFER)
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().status(SUCCESS).memo(LAZY_MEMO)),
// and transfers to the 0.0.ECDSA_BYTES alias should succeed.
cryptoTransfer(tinyBarsFromToWithAlias(PARTY, SECP_256K1_SOURCE_KEY, ONE_HBAR))
Expand Down Expand Up @@ -1544,7 +1544,7 @@ final HapiSpec transferFungibleToEVMAddressAlias() {
getHollowAccountInfoAfterTransfers);
}))
.then(getTxnRecord(FT_XFER)
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().status(SUCCESS).memo(LAZY_MEMO)));
}

Expand Down Expand Up @@ -1679,7 +1679,7 @@ final HapiSpec cannotAutoCreateWithTxnToLongZero() {
.then(withOpContext((spec, opLog) -> {
getTxnRecord("failedTxn").logged();
getTxnRecord("passedTxn")
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(
recordWith().status(SUCCESS).memo(LAZY_MEMO).alias(evmAddress.get()));
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ final HapiSpec secondOrderRewardSituationsWork() {
.andAllChildRecords()
.countStakingRecords()
.stakingFeeExempted()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO))
.hasPaidStakingRewards(List.of()),

Expand All @@ -372,7 +372,7 @@ final HapiSpec secondOrderRewardSituationsWork() {
.logged(),
getTxnRecord("endOfStakingPeriodXfer")
.andAllChildRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.countStakingRecords()
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO)),
getAccountInfo(ALICE)
Expand All @@ -396,7 +396,7 @@ final HapiSpec secondOrderRewardSituationsWork() {
getTxnRecord("expectNoReward")
.andAllChildRecords()
.countStakingRecords()
.hasChildRecordCount(0)
.hasNonStakingChildRecordCount(0)
.hasStakingFeesPaid()
// .hasPaidStakingRewards(List.of())
.logged());
Expand All @@ -423,15 +423,15 @@ final HapiSpec pendingRewardsPaidBeforeStakedToMeUpdates() {
.andAllChildRecords()
.countStakingRecords()
.stakingFeeExempted()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO)),
// alice - 100, carol - 100
/* --- third period reward eligible from period 2--- */
waitUntilStartOfNextStakingPeriod(STAKING_PERIOD_MINS),
cryptoUpdate(CAROL).newStakedAccountId(ALICE).via("stakedIdUpdate"),
getTxnRecord("stakedIdUpdate")
.andAllChildRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.countStakingRecords()
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO))
.hasPaidStakingRewardsCount(2)
Expand Down Expand Up @@ -537,7 +537,7 @@ final HapiSpec stakingMetadataUpdateIsRewardOpportunity() {
getTxnRecord(FIRST_TXN)
.andAllChildRecords()
.countStakingRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO))
.hasPaidStakingRewards(List.of()),

Expand All @@ -552,7 +552,7 @@ final HapiSpec stakingMetadataUpdateIsRewardOpportunity() {
.logged()
.andAllChildRecords()
.countStakingRecords()
// .hasChildRecordCount(1)
// .hasNonStakingChildRecordCount(1)
//
// .hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO))
.hasPaidStakingRewards(List.of(Pair.of(PAYABLE_CONTRACT, 333333300L))),
Expand All @@ -563,7 +563,7 @@ final HapiSpec stakingMetadataUpdateIsRewardOpportunity() {
getTxnRecord("samePeriodTxn")
.andAllChildRecords()
.countStakingRecords()
.hasChildRecordCount(0)
.hasNonStakingChildRecordCount(0)
.hasPaidStakingRewards(List.of()),
waitUntilStartOfNextStakingPeriod(STAKING_PERIOD_MINS),
waitUntilStartOfNextStakingPeriod(STAKING_PERIOD_MINS),
Expand All @@ -576,7 +576,7 @@ final HapiSpec stakingMetadataUpdateIsRewardOpportunity() {
getTxnRecord("contractRewardTxn")
.andAllChildRecords()
.countStakingRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO))
.logged()
// .hasPaidStakingRewards(List.of(Pair.of(PAYABLE_CONTRACT,
Expand All @@ -600,25 +600,25 @@ final HapiSpec endOfStakingPeriodRecTest() {
getTxnRecord("trigger")
.logged()
.countStakingRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO)),
waitUntilStartOfNextStakingPeriod(STAKING_PERIOD_MINS),
cryptoTransfer(tinyBarsFromTo("a1", "a2", ONE_HBAR)).via("transfer"),
getTxnRecord("transfer")
.countStakingRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO))
.logged(),
cryptoTransfer(tinyBarsFromTo("a1", "a2", ONE_HBAR)).via("noEndOfStakingPeriodRecord"),
getTxnRecord("noEndOfStakingPeriodRecord")
.countStakingRecords()
.hasChildRecordCount(0)
.hasNonStakingChildRecordCount(0)
.logged(),
waitUntilStartOfNextStakingPeriod(STAKING_PERIOD_MINS),
cryptoTransfer(tinyBarsFromTo("a1", "a2", ONE_HBAR)).via("transfer1"),
getTxnRecord("transfer1")
.countStakingRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO))
.logged());
}
Expand All @@ -641,7 +641,7 @@ final HapiSpec rewardsOfDeletedAreRedirectedToBeneficiary() {
getTxnRecord(deletion)
.andAllChildRecords()
.countStakingRecords()
.hasChildRecordCount(1)
.hasNonStakingChildRecordCount(1)
.hasChildRecords(recordWith().memo(END_OF_STAKING_PERIOD_CALCULATIONS_MEMO))
.hasPaidStakingRewards(List.of(Pair.of(bob, 3333333000000L)))
.logged());
Expand Down