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 additional tests for HIP-904 #17773

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

Conversation

bubo
Copy link
Contributor

@bubo bubo commented Feb 7, 2025

Description:
Tests from the Airdrop to Contract test plan - 8, 9, 11, 12

Related issue(s):

Fixes #

#16269
#16270
#16272
#16273

Notes for reviewer:

Checklist

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

@bubo bubo added this to the v0.60 milestone Feb 7, 2025
@bubo bubo self-assigned this Feb 7, 2025
@bubo bubo requested review from a team as code owners February 7, 2025 15:54
@bubo bubo changed the title tests: add additional tests for 904 tests: add additional tests for HIP-904 Feb 7, 2025
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.01%. Comparing base (a2f4da1) to head (fb5fc76).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               main   #17773   +/-   ##
=========================================
  Coverage     69.01%   69.01%           
  Complexity    23036    23036           
=========================================
  Files          2654     2654           
  Lines         99652    99652           
  Branches      10284    10284           
=========================================
  Hits          68777    68777           
  Misses        26976    26976           
  Partials       3899     3899           

Impacted file tree graph

Copy link

codacy-production bot commented Feb 7, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a2f4da1) 99435 72515 72.93%
Head commit (fb5fc76) 99435 (+0) 72515 (+0) 72.93% (+0.00%)

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 (#17773) 0 0 ∅ (not applicable)

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

@bubo bubo force-pushed the hip-904-airdrop-from-contract branch from bb18d69 to 425403c Compare February 10, 2025 11:55
@bubo bubo changed the title tests: add additional tests for HIP-904 test: add additional tests for HIP-904 Feb 10, 2025
@bubo bubo closed this Feb 10, 2025
@bubo bubo reopened this Feb 10, 2025
Copy link
Contributor

@stoyanov-st stoyanov-st left a comment

Choose a reason for hiding this comment

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

Good job so far.
Left a few comments for more verifications and one of the tests needs a bit more work to deploy contract with create2

final var hollowAccountKey = "hollowAccountKey";
final AtomicReference<ByteString> hollowAccountAlias = new AtomicReference<>();

return hapiTest(
Copy link
Contributor

Choose a reason for hiding this comment

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

This test only airdrops to a hollow account. You can check Create2OperationSuite to get a reference on how to do the create2 part with a hapi test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually the description and the method name here were wrong, this test does not need create2 contract.

.call("tokenAirdrop", token, sender, receiver, 5L)
.sending(85_000_000L)
.gas(1_500_000L),
receiver.getBalance().andAssert(balance -> balance.hasTokenBalance(token.name(), 0L)),
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also verify the PendingAirdrop from the record

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check is added.

Copy link
Contributor

Choose a reason for hiding this comment

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

also add the including*PendingAirdrop

.via("AirdropTxn"),
receiver.getBalance().andAssert(balance -> balance.hasTokenBalance(token1.name(), 0L)),
receiver.getBalance().andAssert(balance -> balance.hasTokenBalance(token2.name(), 0L)),
getTxnRecord("AirdropTxn").hasChildRecords(recordWith().pendingAirdropsCount(2)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Here also verify the PendingAirdrops apart from the counter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@stoyanov-st stoyanov-st left a comment

Choose a reason for hiding this comment

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

Needs a few more adjustments.
Try to be more explicit in the assertions and add comments if needed, this helps a lot with the reviews and understanding of what is being tested.

getTxnRecord("AirdropTxn").hasChildRecords(recordWith().pendingAirdropsCount(2)),
getTxnRecord("AirdropTxn")
.hasChildRecords(recordWith()
.pendingAirdrops(includingFungiblePendingAirdrop(
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to get the record again, you can just chain the pending checks

.call("tokenAirdrop", token, sender, receiver, 5L)
.sending(85_000_000L)
.gas(1_500_000L),
receiver.getBalance().andAssert(balance -> balance.hasTokenBalance(token.name(), 0L)),
Copy link
Contributor

Choose a reason for hiding this comment

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

also add the including*PendingAirdrop

.sending(85_000_000L)
.gas(1_500_000L)
.via("AirdropTxn"),
getTxnRecord("AirdropTxn").hasChildRecords(recordWith().pendingAirdropsCount(1)),
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

.sending(85_000_000L)
.gas(1_500_000L)
.via("AirdropTxn"),
getTxnRecord("AirdropTxn").hasChildRecords(recordWith().pendingAirdropsCount(1)),
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

.sending(85_000_000L)
.gas(1_500_000L)
.via("AirdropTxn"),
getTxnRecord("AirdropTxn").hasChildRecords(recordWith().pendingAirdropsCount(0)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Use different transaction ids as this might result in race conditions and leaky tests

token.treasury().transferUnitsTo(sender2, 10L, token));
allRunFor(
spec,
airdropContract
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it should be only one airdrop with multiple senders and receivers.
You can check the multiAirdrops() tests in AirdropToContractSystemContractTest

.call("tokenAirdrop", token, sender, receiver, 1L)
.sending(85_000_000L)
.gas(1_500_000L)
.via("AirdropTxn"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Also the transaction ids should be different

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.

2 participants