Skip to content

Commit

Permalink
fix: fuzzy match records with mono-service for ContractMintHTSSuite
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Lebedev <nikita.lebedev@limechain.tech>
  • Loading branch information
thenswan authored Dec 6, 2023
1 parent ebe2039 commit 337d7fd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ public void revertChildrenOf(@NonNull final SingleTransactionRecordBuilderImpl r
followingChildRemoved = true;
} else {
if (child.reversingBehavior() == ReversingBehavior.REVERSIBLE && SUCCESSES.contains(child.status())) {
child.tokenTransferLists().clear();
child.status(ResponseCodeEnum.REVERTED_SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.transfer;

import static com.hedera.node.app.spi.HapiUtils.ACCOUNT_ID_COMPARATOR;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;

Expand All @@ -35,6 +36,7 @@
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -316,9 +318,14 @@ private TokenTransferList sendingUnitsFromTo(
@NonNull final AccountID to,
final long amount,
final IsApproval isApproval) {
final var accountAmounts = new ArrayList<AccountAmount>();
accountAmounts.add(credit(to, amount));
accountAmounts.add(debit(from, amount, isApproval));
accountAmounts.sort(Comparator.comparing(AccountAmount::accountID, ACCOUNT_ID_COMPARATOR));

return TokenTransferList.newBuilder()
.token(tokenId)
.transfers(credit(to, amount), debit(from, amount, isApproval))
.transfers(accountAmounts)
.build();
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public enum SnapshotMatchMode {
* Allows for non-deterministic function parameters.
*/
NONDETERMINISTIC_FUNCTION_PARAMETERS,
/**
* Allows for non-deterministic constructor parameters.
*/
NONDETERMINISTIC_CONSTRUCTOR_PARAMETERS,
/**
* Allows for non-deterministic amounts.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.EXPECT_STREAMLINED_INGEST_RECORDS;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.FULLY_NONDETERMINISTIC;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.HIGHLY_NON_DETERMINISTIC_FEES;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_CONSTRUCTOR_PARAMETERS;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_CONTRACT_CALL_RESULTS;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_FUNCTION_PARAMETERS;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_TRANSACTION_FEES;
Expand Down Expand Up @@ -736,6 +737,8 @@ private boolean shouldSkip(@NonNull final String expectedName, @NonNull final Cl
// It is unlikely we have _any_ tests with nondeterministic logs but deterministic
// call results, so we just use the same match mode for both
return matchModes.contains(NONDETERMINISTIC_CONTRACT_CALL_RESULTS);
} else if ("constructorParameters".equals(expectedName)) {
return matchModes.contains(NONDETERMINISTIC_CONSTRUCTOR_PARAMETERS);
} else if ("gas".equals(expectedName) || "gasUsed".equals(expectedName)) {
return matchModes.contains(ACCEPTED_MONO_GAS_CALCULATION_DIFFERENCE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck;
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.spec.utilops.records.SnapshotMatchMode.ACCEPTED_MONO_GAS_CALCULATION_DIFFERENCE;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_CONSTRUCTOR_PARAMETERS;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_FUNCTION_PARAMETERS;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_TRANSACTION_FEES;
import static com.hedera.services.bdd.suites.contract.Utils.asAddress;
import static com.hedera.services.bdd.suites.contract.Utils.assertTxnRecordHasNoTraceabilityEnrichedContractFnResult;
import static com.hedera.services.bdd.suites.contract.Utils.expectedPrecompileGasFor;
Expand Down Expand Up @@ -117,7 +121,10 @@ List<HapiSpec> positiveSpecs() {
private HapiSpec transferNftAfterNestedMint() {
final var nestedTransferTxn = "nestedTransferTxn";

return defaultHapiSpec("TransferNftAfterNestedMint")
return defaultHapiSpec(
"TransferNftAfterNestedMint",
NONDETERMINISTIC_CONSTRUCTOR_PARAMETERS,
NONDETERMINISTIC_FUNCTION_PARAMETERS)
.given(
newKeyNamed(MULTI_KEY),
cryptoCreate(ACCOUNT).balance(ONE_HUNDRED_HBARS),
Expand Down Expand Up @@ -216,7 +223,12 @@ private HapiSpec transferNftAfterNestedMint() {
private HapiSpec rollbackOnFailedMintAfterFungibleTransfer() {
final var failedMintTxn = "failedMintTxn";

return defaultHapiSpec("RollbackOnFailedMintAfterFungibleTransfer")
return defaultHapiSpec(
"RollbackOnFailedMintAfterFungibleTransfer",
ACCEPTED_MONO_GAS_CALCULATION_DIFFERENCE,
NONDETERMINISTIC_CONSTRUCTOR_PARAMETERS,
NONDETERMINISTIC_FUNCTION_PARAMETERS,
NONDETERMINISTIC_TRANSACTION_FEES)
.given(
newKeyNamed(MULTI_KEY),
cryptoCreate(ACCOUNT).balance(5 * ONE_HUNDRED_HBARS),
Expand Down

0 comments on commit 337d7fd

Please sign in to comment.