Skip to content

Commit

Permalink
Merge pull request #6350 from multiversx/esdt-improvements-integratio…
Browse files Browse the repository at this point in the history
…n-tests-p4

Fix missing role + Use setSpecialRole function in tests
  • Loading branch information
sstanculeanu authored Jul 31, 2024
2 parents c7616eb + 3bb84e7 commit b6f3e88
Show file tree
Hide file tree
Showing 4 changed files with 629 additions and 380 deletions.
75 changes: 51 additions & 24 deletions integrationTests/chainSimulator/vm/egldMultiTransfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vm

import (
"encoding/hex"
"fmt"
"math/big"
"strings"
"testing"
Expand Down Expand Up @@ -65,8 +66,10 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) {
require.Nil(t, err)

// 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)
Expand All @@ -79,35 +82,40 @@ 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))

// 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)
require.NotNil(t, txResult)
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)
require.NotNil(t, txResult)
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))

Expand All @@ -132,14 +140,17 @@ 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])

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++
Expand Down Expand Up @@ -241,7 +252,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)
Expand All @@ -254,14 +267,16 @@ 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))

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)
Expand All @@ -284,7 +299,7 @@ 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)

txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx)
require.Nil(t, err)
Expand Down Expand Up @@ -359,7 +374,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)
Expand All @@ -372,14 +389,16 @@ 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))

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)
Expand All @@ -401,7 +420,7 @@ 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)
tx.Value = egldValue // invalid value field

txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx)
Expand Down Expand Up @@ -477,7 +496,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)
Expand All @@ -490,14 +511,16 @@ 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))

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)
Expand Down Expand Up @@ -541,7 +564,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,
Expand Down Expand Up @@ -686,7 +709,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)
Expand All @@ -699,14 +724,16 @@ 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))

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)
Expand All @@ -723,7 +750,7 @@ 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)

txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx)
require.Nil(t, err)
Expand Down
Loading

0 comments on commit b6f3e88

Please sign in to comment.