-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a9001e
commit 88f2fb2
Showing
7 changed files
with
640 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package txsFee | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
"github.com/multiversx/mx-chain-go/config" | ||
"github.com/multiversx/mx-chain-go/integrationTests/vm" | ||
"github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" | ||
vmcommon "github.com/multiversx/mx-chain-vm-common-go" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestESDTMetaDataRecreate(t *testing.T) { | ||
tokenTypes := getDynamicTokenTypes() | ||
for _, tokenType := range tokenTypes { | ||
testName := "metaDataRecreate for " + tokenType | ||
t.Run(testName, func(t *testing.T) { | ||
runEsdtMetaDataRecreateTest(t, tokenType) | ||
}) | ||
} | ||
} | ||
|
||
func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { | ||
sndAddr := []byte("12345678901234567890123456789012") | ||
token := []byte("tokenId") | ||
roles := [][]byte{[]byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate)} | ||
baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier | ||
key := append([]byte(baseEsdtKeyPrefix), token...) | ||
|
||
testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) | ||
require.Nil(t, err) | ||
defer testContext.Close() | ||
|
||
createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) | ||
createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) | ||
utils.SetESDTRoles(t, testContext.Accounts, sndAddr, token, roles) | ||
|
||
tx := setTokenTypeTx(core.ESDTSCAddress, 100000, token, tokenType) | ||
retCode, err := testContext.TxProcessor.ProcessTransaction(tx) | ||
require.Equal(t, vmcommon.Ok, retCode) | ||
require.Nil(t, err) | ||
|
||
defaultMetaData := getDefaultMetaData() | ||
tx = createTokenTx(sndAddr, sndAddr, 100000, 1, defaultMetaData) | ||
retCode, err = testContext.TxProcessor.ProcessTransaction(tx) | ||
require.Equal(t, vmcommon.Ok, retCode) | ||
require.Nil(t, err) | ||
|
||
// TODO change default metadata | ||
defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) | ||
tx = esdtMetaDataRecreateTx(sndAddr, sndAddr, 100000, defaultMetaData) | ||
retCode, err = testContext.TxProcessor.ProcessTransaction(tx) | ||
require.Equal(t, vmcommon.Ok, retCode) | ||
require.Nil(t, err) | ||
|
||
_, err = testContext.Accounts.Commit() | ||
require.Nil(t, err) | ||
|
||
checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) | ||
} | ||
|
||
func esdtMetaDataRecreateTx( | ||
sndAddr []byte, | ||
rcvAddr []byte, | ||
gasLimit uint64, | ||
metaData *metaData, | ||
) *transaction.Transaction { | ||
txDataField := bytes.Join( | ||
[][]byte{ | ||
[]byte(core.ESDTMetaDataRecreate), | ||
metaData.tokenId, | ||
metaData.nonce, | ||
metaData.name, | ||
metaData.royalties, | ||
metaData.hash, | ||
metaData.attributes, | ||
metaData.uris[0], | ||
metaData.uris[1], | ||
metaData.uris[2], | ||
}, | ||
[]byte("@"), | ||
) | ||
|
||
return &transaction.Transaction{ | ||
Nonce: 1, | ||
SndAddr: sndAddr, | ||
RcvAddr: rcvAddr, | ||
GasLimit: gasLimit, | ||
GasPrice: gasPrice, | ||
|
||
Data: txDataField, | ||
Value: big.NewInt(0), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package txsFee | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/data/transaction" | ||
"github.com/multiversx/mx-chain-go/config" | ||
"github.com/multiversx/mx-chain-go/integrationTests/vm" | ||
"github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" | ||
vmcommon "github.com/multiversx/mx-chain-vm-common-go" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestESDTMetaDataUpdate(t *testing.T) { | ||
tokenTypes := getDynamicTokenTypes() | ||
for _, tokenType := range tokenTypes { | ||
testName := "metaDataUpdate for " + tokenType | ||
t.Run(testName, func(t *testing.T) { | ||
runEsdtMetaDataUpdateTest(t, tokenType) | ||
}) | ||
} | ||
} | ||
|
||
func runEsdtMetaDataUpdateTest(t *testing.T, tokenType string) { | ||
sndAddr := []byte("12345678901234567890123456789012") | ||
token := []byte("tokenId") | ||
roles := [][]byte{[]byte(core.ESDTRoleNFTUpdate), []byte(core.ESDTRoleNFTCreate)} | ||
baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier | ||
key := append([]byte(baseEsdtKeyPrefix), token...) | ||
|
||
testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) | ||
require.Nil(t, err) | ||
defer testContext.Close() | ||
|
||
createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) | ||
createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) | ||
utils.SetESDTRoles(t, testContext.Accounts, sndAddr, token, roles) | ||
|
||
tx := setTokenTypeTx(core.ESDTSCAddress, 100000, token, tokenType) | ||
retCode, err := testContext.TxProcessor.ProcessTransaction(tx) | ||
require.Equal(t, vmcommon.Ok, retCode) | ||
require.Nil(t, err) | ||
|
||
defaultMetaData := getDefaultMetaData() | ||
tx = createTokenTx(sndAddr, sndAddr, 100000, 1, defaultMetaData) | ||
retCode, err = testContext.TxProcessor.ProcessTransaction(tx) | ||
require.Equal(t, vmcommon.Ok, retCode) | ||
require.Nil(t, err) | ||
|
||
// TODO change default metadata | ||
defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) | ||
defaultMetaData.name = []byte(hex.EncodeToString([]byte("newName"))) | ||
defaultMetaData.hash = []byte(hex.EncodeToString([]byte("newHash"))) | ||
defaultMetaData.uris = [][]byte{defaultMetaData.uris[1]} | ||
tx = esdtMetaDataUpdateTx(sndAddr, sndAddr, 100000, defaultMetaData) | ||
retCode, err = testContext.TxProcessor.ProcessTransaction(tx) | ||
require.Equal(t, vmcommon.Ok, retCode) | ||
require.Nil(t, err) | ||
|
||
_, err = testContext.Accounts.Commit() | ||
require.Nil(t, err) | ||
|
||
checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) | ||
} | ||
|
||
func esdtMetaDataUpdateTx( | ||
sndAddr []byte, | ||
rcvAddr []byte, | ||
gasLimit uint64, | ||
metaData *metaData, | ||
) *transaction.Transaction { | ||
txDataField := bytes.Join( | ||
[][]byte{ | ||
[]byte(core.ESDTMetaDataUpdate), | ||
metaData.tokenId, | ||
metaData.nonce, | ||
metaData.name, | ||
metaData.royalties, | ||
metaData.hash, | ||
metaData.attributes, | ||
metaData.uris[0], | ||
}, | ||
[]byte("@"), | ||
) | ||
|
||
return &transaction.Transaction{ | ||
Nonce: 1, | ||
SndAddr: sndAddr, | ||
RcvAddr: rcvAddr, | ||
GasLimit: gasLimit, | ||
GasPrice: gasPrice, | ||
|
||
Data: txDataField, | ||
Value: big.NewInt(0), | ||
} | ||
} |
Oops, something went wrong.