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

fix: Enable NFT Airdrop to distribute multiple serials #17413

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

stoyanov-st
Copy link
Contributor

Description:

This PR fixes the limit of one NFT serial Airdropped with a single transaction.
WIth this logic we can now distribute a NFT to multiple receivers.
The configured limits for airdrops are still applied here.

Related issue(s):

Fixes #17409

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@stoyanov-st stoyanov-st added this to the v0.59 milestone Jan 16, 2025
@stoyanov-st stoyanov-st self-assigned this Jan 16, 2025
@stoyanov-st stoyanov-st requested review from a team and tinker-michaelj as code owners January 16, 2025 16:08
Copy link

codacy-production bot commented Jan 16, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.23% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (79f9327) 96710 70241 72.63%
Head commit (f3c676c) 97698 (+988) 71185 (+944) 72.86% (+0.23%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#17413) 16 16 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Copy link
Member

@david-bakin-sl david-bakin-sl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd like to see a test with multiple airdrops where one or more (but not all, and not the first in the list) fail.

@@ -492,4 +492,108 @@ public Stream<DynamicTest> failToUpdateNFTsMetadata(
.andAssert(txn ->
txn.hasKnownStatuses(CONTRACT_REVERT_EXECUTED, INVALID_TOKEN_NFT_SERIAL_NUMBER)));
}

@HapiTest
@Order(12)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: What is it about airdrops, or this suite, that these tests must be @OrderedInIsolation? Each individual test looks like it is getting new accounts and tokens injected (or at least that's what I assume those annotations on test method parameters are) so how do they interfere with each other?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we have new tokens and accounts injected the naming logic of the specs is the same e.g. if we have receiver1 used in 2 separate tests getting the balance would most likely result in a race condition (and it did before adding the ordering) as we are accessing them by the name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something we could suggest to improve the bdd framework that could make it easier to write tests that didn't have this constraint? Becuase of course @Ordered reduces parallelism in test runs making them take more wall clock time, and @OrderedInIsolation is worse. If the framework could be improved multiple suites, including this one, could benefit, and CI runs would be faster.

Copy link
Contributor Author

@stoyanov-st stoyanov-st Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to spend some time to brainstorm this to come up with a solution and adapt all affected suites


@HapiTest
@Order(12)
@DisplayName("Distribute NFTs to multiple accounts")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also a test w/ multiple airdrops but one or more fail? (I'm not even sure what the behavior of that should be, must be in the HIP though ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we have such tests done or incoming with future PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I would have thought this was a natural place for them, but ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the test

Signed-off-by: Stanimir Stoyanov <[email protected]>
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.99%. Comparing base (79f9327) to head (f3c676c).
Report is 21 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #17413      +/-   ##
============================================
+ Coverage     68.69%   68.99%   +0.29%     
- Complexity    22520    22771     +251     
============================================
  Files          2605     2619      +14     
  Lines         96927    98272    +1345     
  Branches      10101    10184      +83     
============================================
+ Hits          66586    67800    +1214     
- Misses        26535    26644     +109     
- Partials       3806     3828      +22     
Files with missing lines Coverage Δ
...temcontracts/hts/airdrops/TokenAirdropDecoder.java 100.00% <100.00%> (ø)

... and 146 files with indirect coverage changes

Impacted file tree graph

.serialNumber(serial)
.isApproval(isApproval)
.build());
final var nftTransfersList = new ArrayList<NftTransfer>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to create a unit test for this? I realize the method is private but it seems we can maybe create tuples that have more than one not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the test.

lukelee-sl
lukelee-sl previously approved these changes Jan 21, 2025
Copy link
Member

@lukelee-sl lukelee-sl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a comment on an additional test if possible.

Signed-off-by: Stanimir Stoyanov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Airdropping an NFT with multiple serials in one TokenTransferList only sends the first serial
3 participants