Skip to content

Commit

Permalink
Merge pull request #6250 from multiversx/change-to-dynamic-nft-fix
Browse files Browse the repository at this point in the history
do not allow NFTs to be upgraded to dynamic
  • Loading branch information
BeniaminDrasovean authored Jun 17, 2024
2 parents 1fb4786 + e452e97 commit 74ed822
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
27 changes: 13 additions & 14 deletions integrationTests/chainSimulator/vm/esdtImprovements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ var log = logger.GetOrCreate("integrationTests/chainSimulator/vm")
// Test scenario #1
//
// Initial setup: Create fungible, NFT, SFT and metaESDT tokens
//
// (before the activation of DynamicEsdtFlag)
// (before the activation of DynamicEsdtFlag)
//
// 1.check that the metadata for all tokens is saved on the system account
// 2. wait for DynamicEsdtFlag activation
Expand Down Expand Up @@ -1139,7 +1138,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) {

// Test scenario #6
//
// Initial setup: Create NFT
// Initial setup: Create SFT
//
// Call ESDTModifyCreator and check that the creator was modified
// (The sender must have the ESDTRoleModifyCreator role)
Expand Down Expand Up @@ -1196,10 +1195,10 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) {
err = cs.GenerateBlocks(10)
require.Nil(t, err)

log.Info("Initial setup: Create NFT")
log.Info("Initial setup: Create SFT")

nftTicker := []byte("NFTTICKER")
tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost)
sftTicker := []byte("SFTTICKER")
tx := issueSemiFungibleTx(0, address.Bytes, sftTicker, baseIssuingCost)

txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx)
require.Nil(t, err)
Expand All @@ -1211,15 +1210,15 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) {
[]byte(core.ESDTRoleNFTUpdate),
}

nftTokenID := txResult.Logs.Events[0].Topics[0]
setAddressEsdtRoles(t, cs, address, nftTokenID, roles)
sft := txResult.Logs.Events[0].Topics[0]
setAddressEsdtRoles(t, cs, address, sft, roles)

log.Info("Issued NFT token id", "tokenID", string(nftTokenID))
log.Info("Issued SFT token id", "tokenID", string(sft))

nftMetaData := txsFee.GetDefaultMetaData()
nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes()))

tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData)
tx = nftCreateTx(1, address.Bytes, sft, nftMetaData)

txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx)
require.Nil(t, err)
Expand All @@ -1232,7 +1231,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) {

log.Info("Change to DYNAMIC type")

tx = changeToDynamicTx(2, address.Bytes, nftTokenID)
tx = changeToDynamicTx(2, address.Bytes, sft)

txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx)
require.Nil(t, err)
Expand All @@ -1251,12 +1250,12 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) {
roles = [][]byte{
[]byte(core.ESDTRoleModifyCreator),
}
setAddressEsdtRoles(t, cs, newCreatorAddress, nftTokenID, roles)
setAddressEsdtRoles(t, cs, newCreatorAddress, sft, roles)

txDataField := bytes.Join(
[][]byte{
[]byte(core.ESDTModifyCreator),
[]byte(hex.EncodeToString(nftTokenID)),
[]byte(hex.EncodeToString(sft)),
[]byte(hex.EncodeToString(big.NewInt(1).Bytes())),
},
[]byte("@"),
Expand All @@ -1281,7 +1280,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) {

require.Equal(t, "success", txResult.Status.String())

retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID)
retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sft, shardID)

require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator)
}
Expand Down
20 changes: 18 additions & 2 deletions vm/systemSmartContracts/esdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2349,8 +2349,8 @@ func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.Return
return returnCode
}

if bytes.Equal(token.TokenType, []byte(core.FungibleESDT)) {
e.eei.AddReturnMessage("cannot change fungible tokens to dynamic")
if isNotAllowed(token.TokenType) {
e.eei.AddReturnMessage(fmt.Sprintf("cannot change %s tokens to dynamic", token.TokenType))
return vmcommon.UserError
}
if isDynamicTokenType(token.TokenType) {
Expand Down Expand Up @@ -2384,6 +2384,22 @@ func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.Return
return vmcommon.Ok
}

func isNotAllowed(tokenType []byte) bool {
notAllowedTypes := [][]byte{
[]byte(core.FungibleESDT),
[]byte(core.NonFungibleESDT),
[]byte(core.NonFungibleESDTv2),
}

for _, notAllowedType := range notAllowedTypes {
if bytes.Equal(tokenType, notAllowedType) {
return true
}
}

return false
}

func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, token *ESDTDataV2) {
if !e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) {
return
Expand Down
2 changes: 1 addition & 1 deletion vm/systemSmartContracts/esdt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4784,7 +4784,7 @@ func TestEsdt_ChangeToDynamic(t *testing.T) {
eei.returnMessage = ""
output = e.Execute(vmInput)
assert.Equal(t, vmcommon.UserError, output)
assert.True(t, strings.Contains(eei.returnMessage, "cannot change fungible tokens to dynamic"))
assert.True(t, strings.Contains(eei.returnMessage, "cannot change FungibleESDT tokens to dynamic"))

esdtData.TokenType = []byte(core.DynamicMetaESDT)
_ = e.saveToken(vmInput.Arguments[0], esdtData)
Expand Down

0 comments on commit 74ed822

Please sign in to comment.