-
Notifications
You must be signed in to change notification settings - Fork 128
Add k6 test for NFT token lifecycle #11534
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e16bdd2
Add k6 test for fungible token lifecycle
nickeynikolovv 6d297b5
update README.md
nickeynikolovv 941e668
nit: fix typo
nickeynikolovv 09eef6d
spotless
nickeynikolovv 69b5592
add solidity and json file for the contract
nickeynikolovv 0b69d57
nit:rename
nickeynikolovv dd9977b
spotless
nickeynikolovv 1ad73b9
add test details in readme
nickeynikolovv e757ad2
update readme
nickeynikolovv 72099d3
nit: remove unneeded row
nickeynikolovv c85f723
spotless
nickeynikolovv 4d49b93
fix comments
nickeynikolovv 9818bb8
spotless and a nit fix
nickeynikolovv e5aeac9
nit - add some spacing
nickeynikolovv 013f5b5
nit - fix typo
nickeynikolovv 25351f9
add complex test for nft lifecycle
nickeynikolovv 0048d48
spotless
nickeynikolovv 01675b9
nit: comment fix
nickeynikolovv 350a21e
nit: description update
nickeynikolovv 3b5db13
comments fixes
nickeynikolovv 23f929a
Merge branch 'main' into add-k6-for-complex-scanario-NFTLifecycle
nickeynikolovv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
178 changes: 178 additions & 0 deletions
178
...rc/test/resources/solidity/artifacts/contracts/ComplexFunctions.sol/ComplexFunctions.json
Large diffs are not rendered by default.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
test/src/test/resources/solidity/contracts/ComplexFunctions.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "./HederaTokenService.sol"; | ||
import "./HederaResponseCodes.sol"; | ||
import "./ExpiryHelper.sol"; | ||
import "./KeyHelper.sol"; | ||
|
||
contract ComplexFunctions is HederaTokenService, ExpiryHelper, KeyHelper { | ||
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 acc2"); | ||
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"); | ||
} | ||
|
||
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"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tools/k6/src/web3/test/complex-functions/contractCallComplexFunctionsNFTLifecycle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {PrecompileModificationTestTemplate} from '../commonPrecompileModificationFunctionsTemplate.js'; | ||
import {ContractCallTestScenarioBuilder} from '../common.js'; | ||
|
||
const contract = __ENV.COMPLEX_FUNCTIONS_CONTRACT_ADDRESS; | ||
const firstReceiver = __ENV.RECEIVER_ADDRESS; | ||
const secondReceiver = __ENV.SPENDER_ADDRESS; | ||
const payer = __ENV.PAYER_ACCOUNT; | ||
const treasury = '0'.repeat(24) + payer; // Pad with 24 zeros to convert payer account from 20 to 32 bytes treasury account | ||
const runMode = __ENV.RUN_WITH_VARIABLES; | ||
const metadata = | ||
'0000000000000000000000000000000000000000000000000000000000000080' + | ||
'0000000000000000000000000000000000000000000000000000000000000001' + | ||
'0000000000000000000000000000000000000000000000000000000000000020' + | ||
'0000000000000000000000000000000000000000000000000000000000000001' + | ||
'0200000000000000000000000000000000000000000000000000000000000000'; | ||
|
||
/* | ||
This test covers the full lifecycle of a Non-Fungible Token | ||
1. Token Creation | ||
2. Associate token | ||
3. GrantTokenKyc | ||
4. Mint token to treasury | ||
5. Transfer token from treasury to account1 | ||
6. Freeze / Unfreeze token | ||
7. Transfer token from account1 to account2 | ||
8. Wipe amount 10 token from account2 | ||
9. Pause / Unpause token | ||
*/ | ||
const selector = '0xb046226e'; //nftLifecycle(address firstReceiver,address secondReceiver ,address treasury, bytes[] memory metadata) | ||
const testName = 'contractCallComplexFunctionsNFTLifecycle'; | ||
|
||
//If RUN_WITH_VARIABLES=true will run tests with __ENV variables | ||
const {options, run} = | ||
runMode === 'false' | ||
? new PrecompileModificationTestTemplate(testName, false) | ||
: new ContractCallTestScenarioBuilder() | ||
.name(testName) | ||
.selector(selector) | ||
.args([firstReceiver, secondReceiver, treasury, metadata]) | ||
.from(payer) | ||
.value(933333333) // Value is needed because the first operation in the contract call is token create | ||
Check warning on line 43 in tools/k6/src/web3/test/complex-functions/contractCallComplexFunctionsNFTLifecycle.js
|
||
.to(contract) | ||
.block('latest') | ||
.build(); | ||
|
||
export {options, run}; |
41 changes: 41 additions & 0 deletions
41
tools/k6/src/web3/test/complex-functions/contractCallComplexFunctionsTokenLifecycle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {PrecompileModificationTestTemplate} from '../commonPrecompileModificationFunctionsTemplate.js'; | ||
import {ContractCallTestScenarioBuilder} from '../common.js'; | ||
|
||
const contract = __ENV.COMPLEX_FUNCTIONS_CONTRACT_ADDRESS; | ||
const firstReceiver = __ENV.RECEIVER_ADDRESS; | ||
const secondReceiver = __ENV.SPENDER_ADDRESS; | ||
const payer = __ENV.PAYER_ACCOUNT; | ||
const treasury = '0'.repeat(24) + payer; // Pad with 24 zeros to convert payer account from 20 to 32 bytes treasury account | ||
const runMode = __ENV.RUN_WITH_VARIABLES; | ||
|
||
/* | ||
This test covers the full lifecycle of a Fungible Token | ||
1. Token Creation | ||
2. Associate token | ||
3. GrantTokenKyc | ||
4. Transfer token from treasury to account1 | ||
5. Freeze / Unfreeze token | ||
6. Transfer token from account1 to account2 | ||
7. Wipe amount 10 token from account2 | ||
8. Pause / Unpause token | ||
*/ | ||
const selector = '0x8acb1e70'; //tokenLifecycle(address firstReceiver,address secondReceiver ,address treasury) | ||
const testName = 'contractCallComplexFunctionsTokenLifecycle'; | ||
|
||
//If RUN_WITH_VARIABLES=true will run tests with __ENV variables | ||
const {options, run} = | ||
runMode === 'false' | ||
? new PrecompileModificationTestTemplate(testName, false) | ||
: new ContractCallTestScenarioBuilder() | ||
.name(testName) | ||
.selector(selector) | ||
.args([firstReceiver, secondReceiver, treasury]) | ||
.from(payer) | ||
.value(933333333) // Value is needed because the first operation in the contract call is token create | ||
.to(contract) | ||
.block('latest') | ||
.build(); | ||
|
||
export {options, run}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.