Skip to content

Add k6 test for fungible token lifecycle #11507

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

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

Conversation

nickeynikolovv
Copy link
Contributor

@nickeynikolovv nickeynikolovv commented Jul 3, 2025

This PR adds a k6 test that covers the lifecycle of a fungible token. The contract function that

  1. Create token
  2. Associate token
  3. GrantKyC
  4. transfer from treasury to acc1
  5. freeze / unfreeze
  6. transfer from acc1 to acc2
  7. wipe token amount from an account
  8. pause / unpause

The detailed contract function is:

function tokenLifecycle(address acc1, address acc2, address treasury) public payable {
        IHederaTokenService.TokenKey[] memory keys = new IHederaTokenService.TokenKey[](5);
        keys[0] = getSingleKey(KeyType.ADMIN, KeyType.PAUSE, KeyValueType.INHERIT_ACCOUNT_KEY, bytes(""));
        keys[1] = getSingleKey(KeyType.KYC, KeyValueType.INHERIT_ACCOUNT_KEY, bytes(""));
        keys[2] = getSingleKey(KeyType.FREEZE, KeyValueType.INHERIT_ACCOUNT_KEY, bytes(""));
        keys[3] = getSingleKey(KeyType.WIPE, KeyValueType.INHERIT_ACCOUNT_KEY, bytes(""));
        keys[4] = getSingleKey(KeyType.SUPPLY, KeyValueType.INHERIT_ACCOUNT_KEY, bytes(""));
        IHederaTokenService.Expiry memory expiry = IHederaTokenService.Expiry(0, treasury, 8000000);
        IHederaTokenService.HederaToken memory token = IHederaTokenService.HederaToken("TKN", "TK", treasury, "memo", true, 1000000, false, keys, expiry);
        (int code, address tokenAddr) = HederaTokenService.createFungibleToken(token, 1000000, 8);
        require(code == HederaResponseCodes.SUCCESS, "Token creation failed");

        require(HederaTokenService.associateToken(acc1, tokenAddr) == 22, "Token Associate of failed for acc1");
        require(HederaTokenService.associateToken(acc2, tokenAddr) == 22, "Token Associate failed for acc1");
        require(HederaTokenService.grantTokenKyc(tokenAddr, acc1) == 22, "GrantKyc failed for acc1");
        require(HederaTokenService.grantTokenKyc(tokenAddr, acc2) == 22, "GrantKyC failed for acc2");
        require(HederaTokenService.transferToken(tokenAddr, treasury, acc1, 100) == 22, "Transfer token failed from treasury to acc1");
        require(HederaTokenService.freezeToken(tokenAddr, acc1) == 22, "Freeze token failed for acc1");
        require(HederaTokenService.unfreezeToken(tokenAddr, acc1) == 22, "Unfreeze token failed for acc1");
        require(HederaTokenService.transferToken(tokenAddr, acc1, acc2, 50) == 22, "Transfer token failed from acc1 to acc2");
        require(HederaTokenService.wipeTokenAccount(tokenAddr, acc2, 10) == 22, "Wipe token failed for acc2");
        require(HederaTokenService.pauseToken(tokenAddr) == 22, "Pause token failed");
        require(HederaTokenService.unpauseToken(tokenAddr) == 22, "Unpause token failed");
    }

Related issue(s):

Fixes #10624

Notes for reviewer:
Changes in the deploy branch for mainnet config will be done in a separate PR.

There are following complex scenarios that will be added and the contract will be updated in stages. Therefore to avoid new contract deploy on mainnet on each PR those tests will be disabled from the flag RUN_COMPLEX_TESTS until the contract is fully ready and deployed once at the end.

Checklist

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

@nickeynikolovv nickeynikolovv self-assigned this Jul 3, 2025
@nickeynikolovv nickeynikolovv requested a review from a team as a code owner July 3, 2025 11:43
@nickeynikolovv nickeynikolovv requested a review from nirbosl July 3, 2025 11:43
@nickeynikolovv nickeynikolovv added test Test infrastructure, automated tests required, etc web3 Area: Web3 API labels Jul 3, 2025
@lfdt-bot
Copy link

lfdt-bot commented Jul 3, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

Copy link

codacy-production bot commented Jul 3, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for b06f49b1
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (b06f49b) Report Missing Report Missing Report Missing
Head commit (dd9977b) 59355 36153 60.91%

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 (#11507) 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

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
xin-hedera
xin-hedera previously approved these changes Jul 3, 2025
Copy link
Contributor

@xin-hedera xin-hedera left a comment

Choose a reason for hiding this comment

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

LGTM

@steven-sheehy steven-sheehy added this to the 0.134.0 milestone Jul 3, 2025
Copy link
Contributor

@steven-sheehy steven-sheehy left a comment

Choose a reason for hiding this comment

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

We need to also check the solidity file in somewhere and link to it in the k6 README.

Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
@steven-sheehy
Copy link
Contributor

steven-sheehy commented Jul 4, 2025

From my previous comment:

and link to it in the k6 README.

We should have a section in the README that describes and links to the source of various k6 tests so that we can reproduce k6 data easily. It doesn't have to be for every existing test but at least the one you added in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature performance test Test infrastructure, automated tests required, etc web3 Area: Web3 API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add k6 tests for FT complex functions
5 participants