Skip to content

Conversation

nickeynikolovv
Copy link
Contributor

@nickeynikolovv nickeynikolovv commented Jul 7, 2025

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

Create token
Associate token
GrantKyC
Mint
transfer from treasury to acc1
freeze / unfreeze
transfer from acc1 to acc2
wipe token amount from an account
pause / unpause

The detailed contract function is:

   function nftLifecycle(address acc1, address acc2, address treasury, bytes[] memory metadata) 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.HederaToken memory token = IHederaTokenService.HederaToken(
            "NFT", "NFT", treasury, "memo", false, 0, false, keys, IHederaTokenService.Expiry(0, treasury, 8000000)
        );
        (int code, address tokenAddr) = HederaTokenService.createNonFungibleToken(token);
        require(code == HederaResponseCodes.SUCCESS, "NFT creation failed");

        require(HederaTokenService.associateToken(acc1, tokenAddr) == 22, "Associate failed for acc1");
        require(HederaTokenService.associateToken(acc2, tokenAddr) == 22, "Associate failed for acc2");
        require(HederaTokenService.grantTokenKyc(tokenAddr, acc1) == 22, "KYC failed for acc1");
        require(HederaTokenService.grantTokenKyc(tokenAddr, acc2) == 22, "KYC failed for acc2");

        (int mintResponse, , int64[] memory serials) =
                            HederaTokenService.mintToken(tokenAddr, 0, metadata);

        int64 firstSerial = serials[0];

        require(HederaTokenService.transferNFT(tokenAddr, treasury, acc1, firstSerial) == 22, "NFT transfer to acc1 failed");
        require(HederaTokenService.freezeToken(tokenAddr, acc1) == 22, "Freeze failed for acc1");
        require(HederaTokenService.unfreezeToken(tokenAddr, acc1) == 22, "Unfreeze failed for acc1");
        require(HederaTokenService.transferNFT(tokenAddr, acc1, acc2, firstSerial) == 22, "NFT transfer to acc2 failed");
        require(HederaTokenService.wipeTokenAccountNFT(tokenAddr, acc2, serials) == 22, "Wipe failed for acc2");
        require(HederaTokenService.pauseToken(tokenAddr) == 22, "Pause failed");
        require(HederaTokenService.unpauseToken(tokenAddr) == 22, "Unpause failed");
    }

Related issue(s):

Fixes #11470

Notes for reviewer:
Can be merged after the one for Fungible token

Checklist

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

Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
@nickeynikolovv nickeynikolovv self-assigned this Jul 7, 2025
@nickeynikolovv nickeynikolovv requested a review from a team as a code owner July 7, 2025 12:08
@nickeynikolovv nickeynikolovv added the enhancement Type: New feature label Jul 7, 2025
@nickeynikolovv nickeynikolovv requested a review from nirbosl July 7, 2025 12:08
@nickeynikolovv nickeynikolovv added performance test Test infrastructure, automated tests required, etc web3 Area: Web3 API labels Jul 7, 2025
@lfdt-bot
Copy link

lfdt-bot commented Jul 7, 2025

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

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

Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Signed-off-by: Nikolay Nikolov <[email protected]>
Base automatically changed from add-k6-for-complex-scanario-tokenLifecycle to main July 7, 2025 15:48
@steven-sheehy steven-sheehy added this to the 0.134.0 milestone Jul 7, 2025
Signed-off-by: Nikolay Nikolov <[email protected]>
# Conflicts:
#	test/src/test/resources/solidity/artifacts/contracts/ComplexFunctions.sol/ComplexFunctions.json
#	test/src/test/resources/solidity/contracts/ComplexFunctions.sol
#	tools/k6/README.md
#	tools/k6/src/web3/test/index.js
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-32.98% (target: -1.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c97b449) 35982 33793 93.92%
Head commit (23f929a) 59410 (+23428) 36205 (+2412) 60.94% (-32.98%)

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

Copy link
Contributor

@IvanKavaldzhiev IvanKavaldzhiev 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 merged commit c5a1d7d into main Jul 8, 2025
31 of 33 checks passed
@steven-sheehy steven-sheehy deleted the add-k6-for-complex-scanario-NFTLifecycle branch July 8, 2025 14:20
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 NFT complex operations
6 participants