@@ -4496,3 +4496,223 @@ func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNo
44964496 metaData .Nonce = []byte (hex .EncodeToString (big .NewInt (1 ).Bytes ()))
44974497 checkMetaData (t , cs , addrs [1 ].Bytes , tokenID , 1 , metaData )
44984498}
4499+
4500+ func TestChainSimulator_dynamicNFT_updateBeforeCreateOnSameAccountShouldOverwrite (t * testing.T ) {
4501+ t .Parallel ()
4502+
4503+ baseIssuingCost := "1000"
4504+ cs , _ := getTestChainSimulatorWithDynamicNFTEnabled (t , baseIssuingCost )
4505+ defer cs .Close ()
4506+
4507+ addrs := createAddresses (t , cs , true )
4508+
4509+ log .Info ("Register dynamic NFT token" )
4510+
4511+ ticker := []byte ("NFTTICKER" )
4512+ tokenName := []byte ("tokenName" )
4513+
4514+ txDataField := bytes .Join (
4515+ [][]byte {
4516+ []byte ("registerDynamic" ),
4517+ []byte (hex .EncodeToString (tokenName )),
4518+ []byte (hex .EncodeToString (ticker )),
4519+ []byte (hex .EncodeToString ([]byte ("NFT" ))),
4520+ },
4521+ []byte ("@" ),
4522+ )
4523+
4524+ callValue , _ := big .NewInt (0 ).SetString (baseIssuingCost , 10 )
4525+
4526+ shard0Nonce := uint64 (0 )
4527+ tx := & transaction.Transaction {
4528+ Nonce : shard0Nonce ,
4529+ SndAddr : addrs [0 ].Bytes ,
4530+ RcvAddr : vm .ESDTSCAddress ,
4531+ GasLimit : 100_000_000 ,
4532+ GasPrice : minGasPrice ,
4533+ Signature : []byte ("dummySig" ),
4534+ Data : txDataField ,
4535+ Value : callValue ,
4536+ ChainID : []byte (configs .ChainID ),
4537+ Version : 1 ,
4538+ }
4539+ shard0Nonce ++
4540+
4541+ txResult , err := cs .SendTxAndGenerateBlockTilTxIsExecuted (tx , maxNumOfBlockToGenerateWhenExecutingTx )
4542+ require .Nil (t , err )
4543+ require .NotNil (t , txResult )
4544+
4545+ require .Equal (t , "success" , txResult .Status .String ())
4546+
4547+ tokenID := txResult .Logs .Events [0 ].Topics [0 ]
4548+ roles := [][]byte {
4549+ []byte (core .ESDTRoleNFTCreate ),
4550+ []byte (core .ESDTRoleTransfer ),
4551+ []byte (core .ESDTRoleNFTUpdate ),
4552+ }
4553+ setAddressEsdtRoles (t , cs , shard0Nonce , addrs [0 ], tokenID , roles )
4554+ shard0Nonce ++
4555+
4556+ err = cs .GenerateBlocks (10 )
4557+ require .Nil (t , err )
4558+
4559+ log .Info ("update meta data for a token that is not yet created" )
4560+
4561+ newMetaData := & txsFee.MetaData {}
4562+ newMetaData .Nonce = []byte (hex .EncodeToString (big .NewInt (1 ).Bytes ()))
4563+ newMetaData .Name = []byte (hex .EncodeToString ([]byte ("name2" )))
4564+ newMetaData .Hash = []byte (hex .EncodeToString ([]byte ("hash2" )))
4565+ newMetaData .Royalties = []byte (hex .EncodeToString (big .NewInt (15 ).Bytes ()))
4566+
4567+ tx = esdtMetaDataUpdateTx (tokenID , newMetaData , shard0Nonce , addrs [0 ].Bytes )
4568+ shard0Nonce ++
4569+ txResult , err = cs .SendTxAndGenerateBlockTilTxIsExecuted (tx , maxNumOfBlockToGenerateWhenExecutingTx )
4570+ require .Nil (t , err )
4571+ require .NotNil (t , txResult )
4572+ require .Equal (t , "success" , txResult .Status .String ())
4573+
4574+ checkMetaDataNotInAcc (t , cs , core .SystemAccountAddress , tokenID , 1 )
4575+ newMetaData .Attributes = []byte {}
4576+ newMetaData .Uris = [][]byte {}
4577+ checkMetaData (t , cs , addrs [0 ].Bytes , tokenID , 0 , newMetaData )
4578+
4579+ log .Info ("create nft with the same nonce - should overwrite the metadata" )
4580+
4581+ metaData := txsFee .GetDefaultMetaData ()
4582+ metaData .Nonce = []byte (hex .EncodeToString (big .NewInt (1 ).Bytes ()))
4583+
4584+ tx = esdtNftCreateTx (shard0Nonce , addrs [0 ].Bytes , tokenID , metaData , 1 )
4585+ txResult , err = cs .SendTxAndGenerateBlockTilTxIsExecuted (tx , maxNumOfBlockToGenerateWhenExecutingTx )
4586+ require .Nil (t , err )
4587+ require .NotNil (t , txResult )
4588+ require .Equal (t , "success" , txResult .Status .String ())
4589+
4590+ err = cs .GenerateBlocks (10 )
4591+ require .Nil (t , err )
4592+
4593+ checkMetaDataNotInAcc (t , cs , core .SystemAccountAddress , tokenID , 0 )
4594+ checkMetaData (t , cs , addrs [0 ].Bytes , tokenID , 0 , metaData )
4595+ }
4596+
4597+ func TestChainSimulator_dynamicNFT_updateBeforeCreateOnDifferentAccountsShouldMergeMetaDataWhenTransferred (t * testing.T ) {
4598+ t .Parallel ()
4599+
4600+ baseIssuingCost := "1000"
4601+ cs , _ := getTestChainSimulatorWithDynamicNFTEnabled (t , baseIssuingCost )
4602+ defer cs .Close ()
4603+
4604+ addrs := createAddresses (t , cs , true )
4605+
4606+ log .Info ("Register dynamic NFT token" )
4607+
4608+ ticker := []byte ("NFTTICKER" )
4609+ tokenName := []byte ("tokenName" )
4610+
4611+ txDataField := bytes .Join (
4612+ [][]byte {
4613+ []byte ("registerDynamic" ),
4614+ []byte (hex .EncodeToString (tokenName )),
4615+ []byte (hex .EncodeToString (ticker )),
4616+ []byte (hex .EncodeToString ([]byte ("NFT" ))),
4617+ },
4618+ []byte ("@" ),
4619+ )
4620+
4621+ callValue , _ := big .NewInt (0 ).SetString (baseIssuingCost , 10 )
4622+
4623+ shard0Nonce := uint64 (0 )
4624+ tx := & transaction.Transaction {
4625+ Nonce : shard0Nonce ,
4626+ SndAddr : addrs [0 ].Bytes ,
4627+ RcvAddr : vm .ESDTSCAddress ,
4628+ GasLimit : 100_000_000 ,
4629+ GasPrice : minGasPrice ,
4630+ Signature : []byte ("dummySig" ),
4631+ Data : txDataField ,
4632+ Value : callValue ,
4633+ ChainID : []byte (configs .ChainID ),
4634+ Version : 1 ,
4635+ }
4636+ shard0Nonce ++
4637+
4638+ txResult , err := cs .SendTxAndGenerateBlockTilTxIsExecuted (tx , maxNumOfBlockToGenerateWhenExecutingTx )
4639+ require .Nil (t , err )
4640+ require .NotNil (t , txResult )
4641+
4642+ require .Equal (t , "success" , txResult .Status .String ())
4643+
4644+ tokenID := txResult .Logs .Events [0 ].Topics [0 ]
4645+ roles := [][]byte {
4646+ []byte (core .ESDTRoleNFTCreate ),
4647+ []byte (core .ESDTRoleTransfer ),
4648+ []byte (core .ESDTRoleNFTUpdate ),
4649+ }
4650+ setAddressEsdtRoles (t , cs , shard0Nonce , addrs [0 ], tokenID , roles )
4651+ shard0Nonce ++
4652+
4653+ err = cs .GenerateBlocks (10 )
4654+ require .Nil (t , err )
4655+
4656+ log .Info ("transfer update role to another address" )
4657+
4658+ shard0Nonce = transferSpecialRoleToAddr (t , cs , shard0Nonce , tokenID , addrs [0 ].Bytes , addrs [1 ].Bytes , []byte (core .ESDTRoleNFTUpdate ))
4659+
4660+ log .Info ("update meta data for a token that is not yet created" )
4661+
4662+ newMetaData := & txsFee.MetaData {}
4663+ newMetaData .Nonce = []byte (hex .EncodeToString (big .NewInt (1 ).Bytes ()))
4664+ newMetaData .Name = []byte (hex .EncodeToString ([]byte ("name2" )))
4665+ newMetaData .Hash = []byte (hex .EncodeToString ([]byte ("hash2" )))
4666+ newMetaData .Royalties = []byte (hex .EncodeToString (big .NewInt (15 ).Bytes ()))
4667+
4668+ tx = esdtMetaDataUpdateTx (tokenID , newMetaData , 0 , addrs [1 ].Bytes )
4669+ txResult , err = cs .SendTxAndGenerateBlockTilTxIsExecuted (tx , maxNumOfBlockToGenerateWhenExecutingTx )
4670+ require .Nil (t , err )
4671+ require .NotNil (t , txResult )
4672+ require .Equal (t , "success" , txResult .Status .String ())
4673+
4674+ checkMetaDataNotInAcc (t , cs , core .SystemAccountAddress , tokenID , 0 )
4675+ checkMetaDataNotInAcc (t , cs , core .SystemAccountAddress , tokenID , 1 )
4676+ checkMetaDataNotInAcc (t , cs , addrs [0 ].Bytes , tokenID , 0 )
4677+ newMetaData .Attributes = []byte {}
4678+ newMetaData .Uris = [][]byte {}
4679+ checkMetaData (t , cs , addrs [1 ].Bytes , tokenID , 1 , newMetaData )
4680+
4681+ log .Info ("create nft with the same nonce on different account" )
4682+
4683+ metaData := txsFee .GetDefaultMetaData ()
4684+ metaData .Nonce = []byte (hex .EncodeToString (big .NewInt (1 ).Bytes ()))
4685+
4686+ tx = esdtNftCreateTx (shard0Nonce , addrs [0 ].Bytes , tokenID , metaData , 1 )
4687+ shard0Nonce ++
4688+ txResult , err = cs .SendTxAndGenerateBlockTilTxIsExecuted (tx , maxNumOfBlockToGenerateWhenExecutingTx )
4689+ require .Nil (t , err )
4690+ require .NotNil (t , txResult )
4691+ require .Equal (t , "success" , txResult .Status .String ())
4692+
4693+ err = cs .GenerateBlocks (10 )
4694+ require .Nil (t , err )
4695+
4696+ checkMetaDataNotInAcc (t , cs , core .SystemAccountAddress , tokenID , 0 )
4697+ checkMetaDataNotInAcc (t , cs , core .SystemAccountAddress , tokenID , 1 )
4698+ checkMetaData (t , cs , addrs [0 ].Bytes , tokenID , 0 , metaData )
4699+ checkMetaData (t , cs , addrs [1 ].Bytes , tokenID , 1 , newMetaData )
4700+
4701+ log .Info ("transfer dynamic NFT to the updated account" )
4702+
4703+ tx = esdtNFTTransferTx (shard0Nonce , addrs [0 ].Bytes , addrs [1 ].Bytes , tokenID )
4704+ txResult , err = cs .SendTxAndGenerateBlockTilTxIsExecuted (tx , maxNumOfBlockToGenerateWhenExecutingTx )
4705+ require .Nil (t , err )
4706+ require .NotNil (t , txResult )
4707+ require .Equal (t , "success" , txResult .Status .String ())
4708+
4709+ err = cs .GenerateBlocks (10 )
4710+ require .Nil (t , err )
4711+
4712+ checkMetaDataNotInAcc (t , cs , core .SystemAccountAddress , tokenID , 0 )
4713+ checkMetaDataNotInAcc (t , cs , core .SystemAccountAddress , tokenID , 1 )
4714+ checkMetaDataNotInAcc (t , cs , addrs [0 ].Bytes , tokenID , 0 )
4715+ newMetaData .Attributes = metaData .Attributes
4716+ newMetaData .Uris = metaData .Uris
4717+ checkMetaData (t , cs , addrs [1 ].Bytes , tokenID , 1 , newMetaData )
4718+ }
0 commit comments