From c9e292c0bc22c22c73c026f46dd323fb13cd777e Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 29 Jul 2024 18:27:13 +0300 Subject: [PATCH 01/10] use setSpecialRole function in tests --- .../vm/egldMultiTransfer_test.go | 49 ++- .../vm/esdtImprovements_test.go | 332 +++++++++--------- 2 files changed, 202 insertions(+), 179 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 8638445dacf..d7c06a7901d 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -66,7 +66,9 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -80,12 +82,14 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -94,12 +98,14 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { nftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -108,6 +114,7 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { sftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -132,7 +139,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -241,7 +247,9 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -255,13 +263,15 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -359,7 +369,9 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -373,13 +385,15 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -477,7 +491,9 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -491,13 +507,15 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -686,7 +704,9 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { // issue NFT nftTicker := []byte("EGLD") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -700,13 +720,15 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -723,7 +745,8 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { log.Info("Issue token (after activation of EGLDInMultiTransferFlag)") // should fail issuing token with EGLD ticker - tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e94ba571162..ad17776c87d 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -118,8 +118,10 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -138,7 +140,8 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -152,7 +155,8 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -185,7 +189,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -668,6 +671,42 @@ func getMetaDataFromAcc( return esdtData.TokenMetaData } +func setSpecialRoleTx( + nonce uint64, + sndAddr []byte, + address []byte, + token []byte, + roles [][]byte, +) *transaction.Transaction { + txDataBytes := [][]byte{ + []byte("setSpecialRole"), + []byte(hex.EncodeToString(token)), + []byte(hex.EncodeToString(address)), + } + + for _, role := range roles { + txDataBytes = append(txDataBytes, []byte(hex.EncodeToString(role))) + } + + txDataField := bytes.Join( + txDataBytes, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAddr, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 60_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + func setAddressEsdtRoles( t *testing.T, cs testsChainSimulator.ChainSimulator, @@ -722,8 +761,10 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -789,7 +830,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { esdtMetaData, } - nonce := uint64(3) + nonce = uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -841,7 +882,7 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -853,7 +894,6 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTRecreate), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) @@ -918,6 +958,30 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + + roles := [][]byte{ + []byte(core.ESDTRoleNFTRecreate), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, tokenIDs[i], roles) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } err = cs.GenerateBlocks(10) @@ -1000,7 +1064,7 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -1013,7 +1077,6 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) @@ -1079,6 +1142,32 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + + roles := [][]byte{ + []byte(core.ESDTRoleNFTUpdate), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, tokenIDs[i], roles) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } log.Info("Call ESDTMetaDataUpdate to rewrite the meta data for the nft") @@ -1123,6 +1212,10 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) @@ -1299,145 +1392,10 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { roles = [][]byte{ []byte(core.ESDTRoleModifyCreator), } - setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) - - tx = modifyCreatorTx(0, newCreatorAddress.Bytes, tokenIDs[i]) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) - - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) - - require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) - - nonce++ - } -} - -// ESDTModifyCreator without changing to dynamic type -func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - baseIssuingCost := "1000" - - cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) - defer cs.Close() - - log.Info("Initial setup: Create SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - - addrs := createAddresses(t, cs, false) - - // issue metaESDT - metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) - - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) - - metaESDTTokenID := txResult.Logs.Events[0].Topics[0] - - roles := [][]byte{ - []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), - } - setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) - - log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - - // issue SFT - sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(1, addrs[1].Bytes, sftTicker, baseIssuingCost) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) - - log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - - tokenIDs := [][]byte{ - metaESDTTokenID, - sftTokenID, - } - - sftMetaData := txsFee.GetDefaultMetaData() - sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - esdtMetaData := txsFee.GetDefaultMetaData() - esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tokensMetadata := []*txsFee.MetaData{ - esdtMetaData, - sftMetaData, - } - - nonce := uint64(2) - for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) - + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, newCreatorAddress.Bytes, tokenIDs[i], roles) nonce++ - } - for _, tokenID := range tokenIDs { - tx = updateTokenIDTx(nonce, addrs[1].Bytes, tokenID) - - log.Info("updating token id", "tokenID", tokenID) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) - - nonce++ - } - - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - - log.Info("Call ESDTModifyCreator and check that the creator was modified") - - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - for i := range tokenIDs { - log.Info("Modify creator for token", "tokenID", string(tokenIDs[i])) - - newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) - - roles = [][]byte{ - []byte(core.ESDTRoleModifyCreator), - } - setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) - - log.Info("transfering token id", "tokenID", tokenIDs[i]) - - tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, newCreatorAddress.Bytes, tokenIDs[i]) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1453,8 +1411,6 @@ func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) - - nonce++ } } @@ -1617,7 +1573,13 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { roles = [][]byte{ []byte(core.ESDTRoleModifyCreator), } - setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, newCreatorAddress.Bytes, tokenIDs[i], roles) + nonce++ + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("transfering token id", "tokenID", tokenIDs[i]) @@ -1637,10 +1599,6 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(newCreatorAddress.Bytes) @@ -1671,8 +1629,10 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1682,10 +1642,10 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { metaESDTTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ + []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), - []byte(core.ESDTRoleSetNewURI), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) @@ -1693,7 +1653,8 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1707,7 +1668,8 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1740,14 +1702,33 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + roles := [][]byte{ + []byte(core.ESDTRoleSetNewURI), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, tokenIDs[i], roles) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1799,7 +1780,6 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) @@ -1835,7 +1815,7 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -1849,7 +1829,6 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), - []byte(core.ESDTRoleModifyRoyalties), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) @@ -1915,6 +1894,27 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + + roles := [][]byte{ + []byte(core.ESDTRoleModifyRoyalties), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, tokenIDs[i], roles) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") @@ -3242,7 +3242,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) From e46a815e1a9e7d9013c4a0c9f1ee2a3ac13e9009 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 09:50:29 +0300 Subject: [PATCH 02/10] fix linter issues --- .../chainSimulator/vm/egldMultiTransfer_test.go | 7 ------- .../chainSimulator/vm/esdtImprovements_test.go | 16 ++++------------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index d7c06a7901d..162ce5f4efb 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -82,7 +82,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) - nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -98,7 +97,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { nftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -114,7 +112,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { sftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -263,7 +260,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -385,7 +381,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -507,7 +502,6 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -720,7 +714,6 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ad17776c87d..62d4da6d6fa 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -783,7 +783,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -797,7 +798,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -977,8 +979,6 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1161,10 +1161,6 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1212,10 +1208,6 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) From 2b97908d922372ee2ee190fe982ca756ecb63812 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 09:50:57 +0300 Subject: [PATCH 03/10] fix missing ESDTRoleNFTUpdate role --- vm/systemSmartContracts/esdt.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 5daa2f2eb19..63f612610f3 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -1641,6 +1641,11 @@ func (e *esdt) isSpecialRoleValidForNonFungible(argument string) error { return nil } return vm.ErrInvalidArgument + case core.ESDTRoleNFTUpdate: + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { + return nil + } + return vm.ErrInvalidArgument default: return vm.ErrInvalidArgument } @@ -1666,6 +1671,8 @@ func (e *esdt) isSpecialRoleValidForDynamicNFT(argument string) error { return nil case core.ESDTRoleNFTRecreate: return nil + case core.ESDTRoleNFTUpdate: + return nil default: return vm.ErrInvalidArgument } From 18baf55d275930177af6bfa0640a1489535cc9ee Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 09:57:39 +0300 Subject: [PATCH 04/10] fix nonce var linter --- integrationTests/chainSimulator/vm/egldMultiTransfer_test.go | 3 --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - 2 files changed, 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 162ce5f4efb..caaa6fac41d 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -267,7 +267,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -388,7 +387,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -739,7 +737,6 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { // should fail issuing token with EGLD ticker tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 62d4da6d6fa..6401a67e640 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -832,7 +832,6 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { esdtMetaData, } - nonce = uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) From 01aa23cb09d7ba59dc363a32083fe7ada3f76e72 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 10:01:27 +0300 Subject: [PATCH 05/10] fix linter issue --- integrationTests/chainSimulator/vm/egldMultiTransfer_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index caaa6fac41d..75974fbec35 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -507,7 +507,6 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From c5975d8f5aba796854c353897eae7a93a1bb23d8 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 13:30:57 +0300 Subject: [PATCH 06/10] refactor to use setSpecialRole in all tests --- .../vm/egldMultiTransfer_test.go | 39 +- .../vm/esdtImprovements_test.go | 537 ++++++++++++------ .../chainSimulator/vm/esdtTokens_test.go | 39 +- 3 files changed, 419 insertions(+), 196 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 75974fbec35..52aaa9b7e36 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -2,6 +2,7 @@ package vm import ( "encoding/hex" + "fmt" "math/big" "strings" "testing" @@ -65,7 +66,7 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Nil(t, err) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") nonce := uint64(0) tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) nonce++ @@ -81,7 +82,8 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) + nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -96,7 +98,8 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -111,7 +114,8 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -143,6 +147,10 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -259,7 +267,8 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -267,6 +276,7 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -289,7 +299,8 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { egldValue, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) egldValue = egldValue.Add(egldValue, big.NewInt(13)) - tx = multiESDTNFTTransferWithEGLDTx(2, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -379,7 +390,8 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -387,6 +399,7 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -408,7 +421,8 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { beforeBalanceStr1 := account1.Balance egldValue := oneEGLD.Mul(oneEGLD, big.NewInt(3)) - tx = multiESDTNFTTransferWithEGLDTx(2, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + nonce++ tx.Value = egldValue // invalid value field txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -499,7 +513,8 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -507,6 +522,7 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -550,7 +566,7 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { ) tx = &transaction.Transaction{ - Nonce: 2, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: addrs[0].Bytes, GasLimit: 10_000_000, @@ -710,7 +726,8 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 6401a67e640..bdabac5b2c9 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -134,7 +134,16 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) + nonce++ + + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -149,7 +158,16 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ + + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -164,7 +182,16 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ + + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -225,6 +252,9 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) @@ -287,6 +317,9 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) } else { @@ -710,33 +743,24 @@ func setSpecialRoleTx( func setAddressEsdtRoles( t *testing.T, cs testsChainSimulator.ChainSimulator, + nonce uint64, address dtos.WalletAddress, token []byte, roles [][]byte, ) { - marshaller := cs.GetNodeHandler(0).GetCoreComponents().InternalMarshalizer() - - rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) - rolesKey = append(rolesKey, token...) + tx := setSpecialRoleTx(nonce, address.Bytes, address.Bytes, token, roles) - rolesData := &esdt.ESDTRoles{ - Roles: roles, - } - - rolesDataBytes, err := marshaller.Marshal(rolesData) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) + require.NotNil(t, txResult) - keys := make(map[string]string) - keys[hex.EncodeToString(rolesKey)] = hex.EncodeToString(rolesDataBytes) + fmt.Println(txResult) + if txResult.Logs != nil && len(txResult.Logs.Events) > 0 { + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + } - err = cs.SetStateMultiple([]*dtos.AddressState{ - { - Address: address.Bech32, - Balance: "10000000000000000000000", - Pairs: keys, - }, - }) - require.Nil(t, err) + require.Equal(t, "success", txResult.Status.String()) } // Test scenario #3 @@ -777,7 +801,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) + nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -792,7 +817,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -807,7 +833,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -884,7 +911,9 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -896,13 +925,20 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -910,13 +946,20 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -924,7 +967,13 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -949,7 +998,6 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1064,7 +1112,9 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1077,13 +1127,20 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1091,13 +1148,20 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1105,7 +1169,13 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1130,7 +1200,6 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1243,7 +1312,9 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1256,9 +1327,15 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -1279,7 +1356,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: nonce, SndAddr: addrs[1].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -1290,6 +1367,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1298,13 +1376,20 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[1].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[1].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1312,7 +1397,13 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1337,7 +1428,6 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1419,7 +1509,9 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1432,9 +1524,14 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -1455,7 +1552,7 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: nonce, SndAddr: addrs[1].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -1466,6 +1563,7 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1474,13 +1572,20 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[1].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[1].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1488,7 +1593,13 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1513,7 +1624,6 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1633,12 +1743,16 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { metaESDTTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ - []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -1653,7 +1767,13 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -1668,7 +1788,13 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1807,7 +1933,9 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1819,15 +1947,21 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1835,13 +1969,20 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1849,7 +1990,13 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1874,7 +2021,6 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -2009,7 +2155,9 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { log.Info("Initial setup: Create NFT") nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[1].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[1].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2018,18 +2166,19 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTUpdate), } nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[1], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[1].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[1].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2043,7 +2192,8 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) - tx = changeToDynamicTx(2, addrs[1].Bytes, nftTokenID) + tx = changeToDynamicTx(nonce, addrs[1].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2051,6 +2201,13 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) + roles = [][]byte{ + []byte(core.ESDTRoleNFTUpdate), + } + + setAddressEsdtRoles(t, cs, nonce, addrs[1], nftTokenID, roles) + nonce++ + err = cs.GenerateBlocks(10) require.Nil(t, err) @@ -2058,7 +2215,8 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { log.Info("Step 2. Send the NFT cross shard") - tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -2105,46 +2263,47 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTAddQuantity), } ticker := []byte("TICKER") - tx := issueFn(0, addrs[1].Bytes, ticker, baseIssuingCost) + nonce := uint64(0) + tx := issueFn(nonce, addrs[1].Bytes, ticker, baseIssuingCost) + nonce++ + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) tokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], tokenID, roles) - - setAddressEsdtRoles(t, cs, addrs[0], tokenID, roles) - setAddressEsdtRoles(t, cs, addrs[2], tokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[1], tokenID, roles) + nonce++ log.Info("Issued token id", "tokenID", string(tokenID)) - sftMetaData := txsFee.GetDefaultMetaData() - sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), []byte(hex.EncodeToString(tokenID)), []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity - sftMetaData.Name, + metaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - sftMetaData.Hash, - sftMetaData.Attributes, - sftMetaData.Uris[0], - sftMetaData.Uris[1], - sftMetaData.Uris[2], + metaData.Hash, + metaData.Attributes, + metaData.Uris[0], + metaData.Uris[1], + metaData.Uris[2], }, []byte("@"), ) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: nonce, SndAddr: addrs[1].Bytes, RcvAddr: addrs[1].Bytes, GasLimit: 10_000_000, @@ -2155,6 +2314,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2164,21 +2324,48 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { err = cs.GenerateBlocks(10) require.Nil(t, err) + tx = changeToDynamicTx(nonce, addrs[1].Bytes, tokenID) + nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + roles = [][]byte{ + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, nonce, addrs[1], tokenID, roles) + nonce++ + log.Info("Send to separate shards") - tx = esdtNFTTransferTx(2, addrs[1].Bytes, addrs[2].Bytes, tokenID) + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[0].Bytes, tokenID) + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[0].Bytes, tokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + roles = [][]byte{ + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[0].Bytes, tokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + err = cs.GenerateBlocks(10) require.Nil(t, err) @@ -2231,6 +2418,14 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { log.Info("Step 2. change the sft meta data (differently from the previous one) in the other shard") + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + sftMetaData3 := txsFee.GetDefaultMetaData() sftMetaData3.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) @@ -2270,7 +2465,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) @@ -2283,7 +2477,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) @@ -2325,8 +2518,9 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2337,6 +2531,7 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2349,12 +2544,14 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2418,8 +2615,9 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2430,6 +2628,7 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2442,12 +2641,14 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2562,8 +2763,9 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2574,6 +2776,7 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2586,12 +2789,14 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2678,8 +2883,9 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2690,6 +2896,7 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2702,12 +2909,14 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, sftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, sftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2849,8 +3058,9 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2861,6 +3071,7 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2873,12 +3084,14 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, metaTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, metaTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3018,42 +3231,6 @@ func TestChainSimulator_SFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) } -func TestChainSimulator_FungibleCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - baseIssuingCost := "1000" - cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) - defer cs.Close() - - addrs := createAddresses(t, cs, false) - - log.Info("Initial setup: Create FungibleESDT that will have it's metadata saved to the user account") - - funTicker := []byte("FUNTICKER") - tx := issueTx(0, addrs[0].Bytes, funTicker, baseIssuingCost) - - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - funTokenID := txResult.Logs.Events[0].Topics[0] - - log.Info("Issued FungibleESDT token id", "tokenID", string(funTokenID)) - - metaData := txsFee.GetDefaultMetaData() - metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, funTokenID, metaData, epochForDynamicNFT, addrs[0]) - - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, funTokenID, shardID, metaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, funTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, funTokenID, shardID) -} - func TestChainSimulator_MetaESDTCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -3135,8 +3312,8 @@ func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssu Value: 20, } - activationEpochForSaveToSystemAccount := uint32(2) - activationEpochForDynamicNFT := uint32(4) + activationEpochForSaveToSystemAccount := uint32(4) + activationEpochForDynamicNFT := uint32(6) numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -3161,7 +3338,7 @@ func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssu require.Nil(t, err) require.NotNil(t, cs) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForSaveToSystemAccount) - 1) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForSaveToSystemAccount) - 2) require.Nil(t, err) return cs, int32(activationEpochForDynamicNFT) @@ -3181,9 +3358,9 @@ func createTokenUpdateTokenIDAndTransfer( []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, walletWithRoles, tokenID, roles) + setAddressEsdtRoles(t, cs, 1, walletWithRoles, tokenID, roles) - tx := nftCreateTx(1, originAddress, tokenID, metaData) + tx := nftCreateTx(2, originAddress, tokenID, metaData) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3199,7 +3376,7 @@ func createTokenUpdateTokenIDAndTransfer( err = cs.GenerateBlocksUntilEpochIsReached(epochForDynamicNFT) require.Nil(t, err) - tx = updateTokenIDTx(2, originAddress, tokenID) + tx = updateTokenIDTx(3, originAddress, tokenID) log.Info("updating token id", "tokenID", tokenID) @@ -3213,7 +3390,7 @@ func createTokenUpdateTokenIDAndTransfer( log.Info("transferring token id", "tokenID", tokenID) - tx = esdtNFTTransferTx(3, originAddress, targetAddress, tokenID) + tx = esdtNFTTransferTx(4, originAddress, targetAddress, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -3234,7 +3411,9 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3247,13 +3426,15 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) + nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3261,13 +3442,15 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3275,7 +3458,8 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -3300,7 +3484,6 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -3313,9 +3496,6 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { nonce++ } - err = cs.GenerateBlocks(10) - require.Nil(t, err) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) // meta data should be saved on account, since it is before `OptimizeNFTStoreEnableEpoch` @@ -3445,8 +3625,9 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { []byte("@"), ) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: core.ESDTSCAddress, GasLimit: 100_000_000, @@ -3457,6 +3638,7 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3468,14 +3650,16 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { []byte(core.ESDTRoleTransfer), } nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3513,7 +3697,8 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { log.Info("make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") - tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) + tx = updateTokenIDTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ log.Info("updating token id", "tokenID", nftTokenID) @@ -3533,7 +3718,8 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) - tx = esdtNFTTransferTx(3, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -3619,8 +3805,9 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -3631,6 +3818,7 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3645,14 +3833,16 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { } nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3682,7 +3872,8 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { require.Equal(t, "", result.ReturnMessage) require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) - tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) + tx = updateTokenIDTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ log.Info("updating token id", "tokenID", nftTokenID) @@ -3693,7 +3884,8 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { log.Info("change to dynamic token") - tx = changeToDynamicTx(3, addrs[0].Bytes, nftTokenID) + tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ log.Info("updating token id", "tokenID", nftTokenID) @@ -3711,7 +3903,8 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) - tx = esdtNFTTransferTx(4, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index 00f5e3344f6..7fc9c84037a 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -82,7 +82,9 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { // issue fungible fungibleTicker := []byte("FUNTICKER") - tx := issueTx(0, addrs[0].Bytes, fungibleTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueTx(nonce, addrs[0].Bytes, fungibleTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -90,13 +92,15 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) fungibleTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], fungibleTokenID, roles) + nonce++ log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -104,13 +108,15 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -118,7 +124,8 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -141,7 +148,6 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { sftMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -244,7 +250,9 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -252,14 +260,16 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -309,7 +319,8 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Update token id", "tokenID", nftTokenID) - tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) + tx = updateTokenIDTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -330,7 +341,8 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Transfer token id", "tokenID", nftTokenID) - tx = esdtNFTTransferTx(3, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -351,7 +363,8 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Change to DYNAMIC type") - tx = changeToDynamicTx(4, addrs[0].Bytes, nftTokenID) + tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From 5087af138a816edb591d02bbd52d9bdabe774bde Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 13:31:23 +0300 Subject: [PATCH 07/10] update getAllRolesForTokenType --- .../vm/esdtImprovements_test.go | 2 ++ vm/systemSmartContracts/esdt.go | 33 ++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index bdabac5b2c9..ac9c719f564 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2849,6 +2849,7 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleNFTUpdate), } checkTokenRoles(t, result.ReturnData, expectedRoles) @@ -2969,6 +2970,7 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleNFTUpdate), } checkTokenRoles(t, result.ReturnData, expectedRoles) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 63f612610f3..b7b21b743c0 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -548,9 +548,21 @@ func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.Re func (e *esdt) getAllRolesForTokenType(tokenType string) ([][]byte, error) { switch tokenType { case core.NonFungibleESDT, core.NonFungibleESDTv2, core.DynamicNFTESDT: - nftRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} + nftRoles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + } + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { - nftRoles = append(nftRoles, [][]byte{[]byte(core.ESDTRoleNFTRecreate), []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI)}...) + nftRoles = append(nftRoles, [][]byte{ + []byte(core.ESDTRoleNFTRecreate), + []byte(core.ESDTRoleModifyCreator), + []byte(core.ESDTRoleModifyRoyalties), + []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleNFTUpdate), + }...) } return nftRoles, nil @@ -559,8 +571,21 @@ func (e *esdt) getAllRolesForTokenType(tokenType string) ([][]byte, error) { case core.FungibleESDT: return [][]byte{[]byte(core.ESDTRoleLocalMint), []byte(core.ESDTRoleLocalBurn)}, nil case core.DynamicSFTESDT, core.DynamicMetaESDT: - dynamicRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTAddQuantity), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} - dynamicRoles = append(dynamicRoles, [][]byte{[]byte(core.ESDTRoleNFTRecreate), []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI)}...) + dynamicRoles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleNFTAddQuantity), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + } + + dynamicRoles = append(dynamicRoles, [][]byte{ + []byte(core.ESDTRoleNFTRecreate), + []byte(core.ESDTRoleModifyCreator), + []byte(core.ESDTRoleModifyRoyalties), + []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleNFTUpdate), + }...) return dynamicRoles, nil } From 1521c987f100ccee9dbc88dd26578723ea05e40c Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 14:19:08 +0300 Subject: [PATCH 08/10] fix linter issues --- .../chainSimulator/vm/egldMultiTransfer_test.go | 2 -- .../chainSimulator/vm/esdtImprovements_test.go | 8 -------- 2 files changed, 10 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 52aaa9b7e36..10a10cee5ad 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -300,7 +300,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { egldValue, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) egldValue = egldValue.Add(egldValue, big.NewInt(13)) tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -422,7 +421,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { egldValue := oneEGLD.Mul(oneEGLD, big.NewInt(3)) tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) - nonce++ tx.Value = egldValue // invalid value field txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ac9c719f564..bdd4ac2e2ea 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2216,7 +2216,6 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { log.Info("Step 2. Send the NFT cross shard") tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -2419,7 +2418,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { log.Info("Step 2. change the sft meta data (differently from the previous one) in the other shard") tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID, roles) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2551,7 +2549,6 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2648,7 +2645,6 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2796,7 +2792,6 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2917,7 +2912,6 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, sftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3093,7 +3087,6 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, metaTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3721,7 +3714,6 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) From 06b165bd4bad393b19c25a36d3e77043e1048b65 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 30 Jul 2024 14:52:47 +0300 Subject: [PATCH 09/10] fix - only transfer role for second address --- .../chainSimulator/vm/esdtImprovements_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index bdd4ac2e2ea..fa40135b5e1 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -137,7 +137,8 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) nonce++ - tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, metaESDTTokenID, roles) + rolesTransfer := [][]byte{[]byte(core.ESDTRoleTransfer)} + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, metaESDTTokenID, rolesTransfer) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -161,7 +162,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) nonce++ - tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, rolesTransfer) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -185,7 +186,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) nonce++ - tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, rolesTransfer) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) From 3bb84e73111e5eadc034418d93a1411da211ce0d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 14:59:53 +0300 Subject: [PATCH 10/10] fix linter issues --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - integrationTests/chainSimulator/vm/esdtTokens_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index fa40135b5e1..97acfa79fd2 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3899,7 +3899,6 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index 7fc9c84037a..d12bfcbb550 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -364,7 +364,6 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Change to DYNAMIC type") tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err)