Skip to content

Commit

Permalink
fix: Enable fuzzy matching for HRCPrecompileSuite (#11032)
Browse files Browse the repository at this point in the history
Signed-off-by: Stanimir Stoyanov <stanimir.stoyanov@limechain.tech>
Signed-off-by: Timo Brandstätter <timo@swirldslabs.com>
  • Loading branch information
stoyanov-st authored and timo0 committed Feb 16, 2024
1 parent 6745028 commit 70d7a81
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public void finalizeChildRecord(@NonNull final ChildFinalizeContext context, fin
// set an empty transfer list even if there are no hbar changes but the parent record succeeded
// to be compatible with mono-service
recordBuilder.transferList(TransferList.DEFAULT);
} else if (recordBuilder.status() != ResponseCodeEnum.SUCCESS) {
// set null to transfer list if the child record failed to be compatible with mono-service
recordBuilder.transferList(null);
}

// Declare the top-level token transfer list, which list will include BOTH fungible and non-fungible token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package com.hedera.node.app.service.token.impl.test.handlers;

import static com.hedera.hapi.node.base.ResponseCodeEnum.FAIL_INVALID;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS;
import static com.hedera.node.app.service.token.impl.handlers.BaseTokenHandler.asToken;
import static com.hedera.node.app.spi.fixtures.workflows.ExceptionConditions.responseCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mock.Strictness.LENIENT;
import static org.mockito.Mockito.atMostOnce;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -162,9 +164,12 @@ void handleHbarAccountBalanceDoesntChange() {
context = mockContext();

given(context.configuration()).willReturn(configuration);
given(recordBuilder.status()).willReturn(SUCCESS);
subject.finalizeChildRecord(context, HederaFunctionality.CRYPTO_DELETE);

verify(recordBuilder).status();
BDDMockito.verify(recordBuilder, atMostOnce()).status();
BDDMockito.verify(recordBuilder, atMostOnce()).transferList(TransferList.DEFAULT);
BDDMockito.verifyNoMoreInteractions(recordBuilder);
}

@Test
Expand Down Expand Up @@ -315,10 +320,14 @@ void handleFungibleTransferTokenBalancesDontChange() {
writableTokenRelStore.put(tokenRel.copyBuilder().frozen(true).build());
context = mockContext();
given(context.configuration()).willReturn(configuration);
given(recordBuilder.status()).willReturn(SUCCESS);

subject.finalizeChildRecord(context, HederaFunctionality.CRYPTO_DELETE);

verify(recordBuilder).status();
BDDMockito.verify(recordBuilder, atMostOnce()).status();
BDDMockito.verify(recordBuilder, atMostOnce()).transferList(TransferList.DEFAULT);
BDDMockito.verifyNoMoreInteractions(recordBuilder);
}

@Test
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.overriding;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_ETHEREUM_DATA;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_FUNCTION_PARAMETERS;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_NONCE;
import static com.hedera.services.bdd.spec.utilops.records.SnapshotMatchMode.NONDETERMINISTIC_TRANSACTION_FEES;
import static com.hedera.services.bdd.suites.contract.Utils.asHexedAddress;
import static com.hedera.services.bdd.suites.contract.Utils.asToken;
import static com.hedera.services.bdd.suites.contract.Utils.getABIFor;
Expand All @@ -57,7 +61,7 @@
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Tag;

@HapiTestSuite
@HapiTestSuite(fuzzyMatch = true)
@Tag(SMART_CONTRACT)
public class HRCPrecompileSuite extends HapiSuite {

Expand Down Expand Up @@ -106,7 +110,7 @@ final HapiSpec hrcNftAndFungibleTokenAssociateFromEOA() {
final AtomicReference<String> fungibleTokenNum = new AtomicReference<>();
final AtomicReference<String> nonfungibleTokenNum = new AtomicReference<>();

return defaultHapiSpec("hrcNftAndFungibleTokenAssociateFromEOA")
return defaultHapiSpec("hrcNftAndFungibleTokenAssociateFromEOA", NONDETERMINISTIC_FUNCTION_PARAMETERS)
.given(
newKeyNamed(MULTI_KEY),
cryptoCreate(ACCOUNT).balance(100 * ONE_HUNDRED_HBARS),
Expand Down Expand Up @@ -215,7 +219,11 @@ final HapiSpec hrcNftAndFungibleTokenAssociateFromEOA() {

@HapiTest
final HapiSpec hrcNFTAndFungibleTokenAssociateFromContract() {
return defaultHapiSpec("hrcNFTAndFungibleTokenAssociateFromContract")
return defaultHapiSpec(
"hrcNFTAndFungibleTokenAssociateFromContract",
NONDETERMINISTIC_TRANSACTION_FEES,
NONDETERMINISTIC_FUNCTION_PARAMETERS,
NONDETERMINISTIC_NONCE)
.given(
newKeyNamed(MULTI_KEY),
cryptoCreate(ACCOUNT).balance(100 * ONE_HUNDRED_HBARS),
Expand Down Expand Up @@ -324,7 +332,10 @@ final HapiSpec hrcNFTAndFungibleTokenAssociateFromContract() {
final HapiSpec hrcTokenAssociateFromSameEOATwiceShouldFail() {
final AtomicReference<String> fungibleTokenNum = new AtomicReference<>();

return defaultHapiSpec("hrcTokenAssociateFromSameEOATwiceShouldFail")
return defaultHapiSpec(
"hrcTokenAssociateFromSameEOATwiceShouldFail",
NONDETERMINISTIC_FUNCTION_PARAMETERS,
NONDETERMINISTIC_NONCE)
.given(
newKeyNamed(MULTI_KEY),
newKeyNamed(RANDOM_KEY),
Expand Down Expand Up @@ -390,7 +401,7 @@ final HapiSpec hrcTokenAssociateFromSameEOATwiceShouldFail() {
final HapiSpec hrcTokenDissociateWhenNotAssociatedShouldFail() {
final AtomicReference<String> fungibleTokenNum = new AtomicReference<>();

return defaultHapiSpec("hrcTokenDissociateWhenNotAssociatedShouldFail")
return defaultHapiSpec("hrcTokenDissociateWhenNotAssociatedShouldFail", NONDETERMINISTIC_TRANSACTION_FEES)
.given(
newKeyNamed(MULTI_KEY),
newKeyNamed(RANDOM_KEY),
Expand Down Expand Up @@ -438,7 +449,10 @@ final HapiSpec hrcTokenDissociateWhenNotAssociatedShouldFail() {
final HapiSpec hrcTokenDissociateWhenBalanceNotZeroShouldFail() {
final AtomicReference<String> fungibleTokenNum = new AtomicReference<>();

return defaultHapiSpec("hrcTokenDissociateWhenBalanceNotZeroShouldFail")
return defaultHapiSpec(
"hrcTokenDissociateWhenBalanceNotZeroShouldFail",
NONDETERMINISTIC_FUNCTION_PARAMETERS,
NONDETERMINISTIC_ETHEREUM_DATA)
.given(
newKeyNamed(MULTI_KEY),
newKeyNamed(RANDOM_KEY),
Expand Down Expand Up @@ -508,7 +522,10 @@ final HapiSpec hrcTooManyTokenAssociateShouldFail() {
final AtomicReference<String> fungibleTokenNum2 = new AtomicReference<>();
final AtomicReference<String> fungibleTokenNum3 = new AtomicReference<>();

return defaultHapiSpec("hrcTooManyTokenAssociateShouldFail")
return defaultHapiSpec(
"hrcTooManyTokenAssociateShouldFail",
NONDETERMINISTIC_FUNCTION_PARAMETERS,
NONDETERMINISTIC_TRANSACTION_FEES)
.given(
overriding("tokens.maxPerAccount", "2"),
overriding("entities.limitTokenAssociations", "true"),
Expand Down

0 comments on commit 70d7a81

Please sign in to comment.