diff --git a/cmd/sovereignnode/go.mod b/cmd/sovereignnode/go.mod index b504caec5bd..d9b6e301b20 100644 --- a/cmd/sovereignnode/go.mod +++ b/cmd/sovereignnode/go.mod @@ -6,7 +6,7 @@ go 1.20 require ( github.com/google/gops v0.3.18 - github.com/multiversx/mx-chain-core-go v1.2.24-0.20241111110328-b8a9c02d5583 + github.com/multiversx/mx-chain-core-go v1.2.24-0.20241120082646-16e4df50ab4a github.com/multiversx/mx-chain-go v1.8.4 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-sovereign-bridge-go v0.0.0-20240116102202-4cf6fbbd95a3 @@ -123,7 +123,7 @@ require ( github.com/multiversx/mx-chain-es-indexer-go v1.7.11-0.20241111112929-8f3ff2303ebe // indirect github.com/multiversx/mx-chain-scenario-go v1.4.4 // indirect github.com/multiversx/mx-chain-storage-go v1.0.16 // indirect - github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0 // indirect + github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516 // indirect github.com/multiversx/mx-chain-vm-go v1.5.37 // indirect github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 // indirect github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 // indirect diff --git a/cmd/sovereignnode/go.sum b/cmd/sovereignnode/go.sum index d4fdea9d386..a7bce898353 100644 --- a/cmd/sovereignnode/go.sum +++ b/cmd/sovereignnode/go.sum @@ -385,8 +385,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.1 h1:y4DoQeQOJTaSUsRzczQFazf8JYQmInddypApqA3AkwM= github.com/multiversx/mx-chain-communication-go v1.1.1/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20241111110328-b8a9c02d5583 h1:EEYn25eF4DV1UTcCjOarSH1voitQ+YCnFmbDgJzLqB8= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20241111110328-b8a9c02d5583/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20241120082646-16e4df50ab4a h1:T3h/lce7otuRxiI7UDyYc0hKImyc3U+rdxvgl5nih+4= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20241120082646-16e4df50ab4a/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= github.com/multiversx/mx-chain-es-indexer-go v1.7.11-0.20241111112929-8f3ff2303ebe h1:9S9YOV0+nHBHVcd1fpMC3sSD/jW0MJIEVPstkFBfclI= @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-sovereign-notifier-go v0.0.0-20230929085947-df9b3 github.com/multiversx/mx-chain-sovereign-notifier-go v0.0.0-20230929085947-df9b345f49ac/go.mod h1:syNNd30uEkKsz2V5nXCfv3u+KhkpKVw34+2DsfSuFSE= github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0 h1:WpfFe6ueS+nRIq2RzVaeF1/TJStyYH/YLYPCmN8kdDM= -github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0/go.mod h1:IOE+gYAtTEKZJwUr9ZhOnjdf4vFKrZdZ9RVEyuFsEP4= +github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516 h1:PToP1B7aFkXjQBOF5MDCCvsc+ffWVqqBHtmemfCwVA8= +github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516/go.mod h1:C7KVj6/+TAhxDjgY7oAMO5wSj7WbBYIJ5TCMzmxk2w0= github.com/multiversx/mx-chain-vm-go v1.5.37 h1:Iy3KCvM+DOq1f9UPA7uYK/rI3ZbBOXc2CVNO2/vm5zw= github.com/multiversx/mx-chain-vm-go v1.5.37/go.mod h1:nzLrWeXvfxCIiwj5uNBZq3d7stkXyeY+Fktfr4tTaiY= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= diff --git a/errors/errors.go b/errors/errors.go index e076890ef7f..9dbda39b716 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -785,6 +785,9 @@ var ErrNilFunction = errors.New("nil function") // ErrEmptyBaseToken signals that an empty base token has been provided var ErrEmptyBaseToken = errors.New("empty base token") +// ErrInvalidBaseToken signals that an invalid base token has been provided +var ErrInvalidBaseToken = errors.New("invalid base token") + // ErrNilESDTAsBalanceHandler signals that a nil esdt as balance handler was provided var ErrNilESDTAsBalanceHandler = errors.New("nil esdt as balance handler provided") diff --git a/factory/runType/sovereignRunTypeComponents_test.go b/factory/runType/sovereignRunTypeComponents_test.go index 5627de3d291..dc4babe9171 100644 --- a/factory/runType/sovereignRunTypeComponents_test.go +++ b/factory/runType/sovereignRunTypeComponents_test.go @@ -18,7 +18,7 @@ func createSovRunTypeArgs() runType.ArgsSovereignRunTypeComponents { RunTypeComponentsFactory: rcf, Config: config.SovereignConfig{ GenesisConfig: config.GenesisConfig{ - NativeESDT: "WEGLD", + NativeESDT: "WEGLD-bd4d79", }, }, DataCodec: &sovereign.DataCodecMock{}, diff --git a/go.mod b/go.mod index dc09b74660a..b2d47aceb03 100644 --- a/go.mod +++ b/go.mod @@ -15,13 +15,13 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.1 - github.com/multiversx/mx-chain-core-go v1.2.24-0.20241111110328-b8a9c02d5583 + github.com/multiversx/mx-chain-core-go v1.2.24-0.20241120082646-16e4df50ab4a github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.11-0.20241111112929-8f3ff2303ebe github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0 + github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516 github.com/multiversx/mx-chain-vm-go v1.5.37 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 diff --git a/go.sum b/go.sum index 170aa1e699b..4bb15f27073 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.1 h1:y4DoQeQOJTaSUsRzczQFazf8JYQmInddypApqA3AkwM= github.com/multiversx/mx-chain-communication-go v1.1.1/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20241111110328-b8a9c02d5583 h1:EEYn25eF4DV1UTcCjOarSH1voitQ+YCnFmbDgJzLqB8= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20241111110328-b8a9c02d5583/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20241120082646-16e4df50ab4a h1:T3h/lce7otuRxiI7UDyYc0hKImyc3U+rdxvgl5nih+4= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20241120082646-16e4df50ab4a/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= github.com/multiversx/mx-chain-es-indexer-go v1.7.11-0.20241111112929-8f3ff2303ebe h1:9S9YOV0+nHBHVcd1fpMC3sSD/jW0MJIEVPstkFBfclI= @@ -399,8 +399,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz github.com/multiversx/mx-chain-scenario-go v1.4.4/go.mod h1:kI+TWR3oIEgUkbwkHCPo2CQ3VjIge+ezGTibiSGwMxo= github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= -github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0 h1:WpfFe6ueS+nRIq2RzVaeF1/TJStyYH/YLYPCmN8kdDM= -github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0/go.mod h1:IOE+gYAtTEKZJwUr9ZhOnjdf4vFKrZdZ9RVEyuFsEP4= +github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516 h1:PToP1B7aFkXjQBOF5MDCCvsc+ffWVqqBHtmemfCwVA8= +github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516/go.mod h1:C7KVj6/+TAhxDjgY7oAMO5wSj7WbBYIJ5TCMzmxk2w0= github.com/multiversx/mx-chain-vm-go v1.5.37 h1:Iy3KCvM+DOq1f9UPA7uYK/rI3ZbBOXc2CVNO2/vm5zw= github.com/multiversx/mx-chain-vm-go v1.5.37/go.mod h1:nzLrWeXvfxCIiwj5uNBZq3d7stkXyeY+Fktfr4tTaiY= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= diff --git a/integrationTests/chainSimulator/bridge/bridgeAndTransfer_test.go b/integrationTests/chainSimulator/bridge/bridgeAndTransfer_test.go index 3cbf9e3f481..524e23a4c3b 100644 --- a/integrationTests/chainSimulator/bridge/bridgeAndTransfer_test.go +++ b/integrationTests/chainSimulator/bridge/bridgeAndTransfer_test.go @@ -90,37 +90,37 @@ func TestChainSimulator_ExecuteMintBurnBridgeOpForESDTTokensWithPrefixAndTransfe Type: core.Fungible, }) bridgedInTokens = append(bridgedInTokens, chainSim.ArgsDepositToken{ - Identifier: argsEsdtSafe.ChainPrefix + "-NFTV2-1q2w3e", + Identifier: argsEsdtSafe.ChainPrefix + "-NFTV2-1a2b3c", Nonce: uint64(3), Amount: big.NewInt(1), Type: core.NonFungibleV2, }) //bridgedInTokens = append(bridgedInTokens, chainSim.ArgsDepositToken{ - // Identifier: argsEsdtSafe.ChainPrefix + "-DNFT-ewg43h", + // Identifier: argsEsdtSafe.ChainPrefix + "-DNFT-ead43f", // Nonce: uint64(6), // Amount: big.NewInt(1), // Type: core.DynamicNFT, //}) bridgedInTokens = append(bridgedInTokens, chainSim.ArgsDepositToken{ - Identifier: argsEsdtSafe.ChainPrefix + "-SFT-gthy55", + Identifier: argsEsdtSafe.ChainPrefix + "-SFT-cedd55", Nonce: uint64(52), Amount: big.NewInt(2156), Type: core.SemiFungible, }) //bridgedInTokens = append(bridgedInTokens, chainSim.ArgsDepositToken{ - // Identifier: argsEsdtSafe.ChainPrefix + "-DSFT-h6g4g2", + // Identifier: argsEsdtSafe.ChainPrefix + "-DSFT-f6b4c2", // Nonce: uint64(33), // Amount: big.NewInt(11), // Type: core.DynamicSFT, //}) //bridgedInTokens = append(bridgedInTokens, chainSim.ArgsDepositToken{ - // Identifier: argsEsdtSafe.ChainPrefix + "-META-4g543g", + // Identifier: argsEsdtSafe.ChainPrefix + "-META-4b543b", // Nonce: uint64(57), // Amount: big.NewInt(124000), // Type: core.MetaFungible, //}) //bridgedInTokens = append(bridgedInTokens, chainSim.ArgsDepositToken{ - // Identifier: argsEsdtSafe.ChainPrefix + "-DMETA-gtr4g2", + // Identifier: argsEsdtSafe.ChainPrefix + "-DMETA-4b543b", // Nonce: uint64(31), // Amount: big.NewInt(14326743), // Type: core.DynamicMeta, diff --git a/integrationTests/chainSimulator/bridge/esdtSafe_test.go b/integrationTests/chainSimulator/bridge/esdtSafe_test.go index 25cd95b27c7..2e06e6ccfea 100644 --- a/integrationTests/chainSimulator/bridge/esdtSafe_test.go +++ b/integrationTests/chainSimulator/bridge/esdtSafe_test.go @@ -86,43 +86,43 @@ func TestChainSimulator_ExecuteAndDepositTokensWithPrefix(t *testing.T) { // TODO MX-15942 uncomment dynamic tokens, currently there is no issue function in SC framework for dynamic esdts tokens := make([]chainSim.ArgsDepositToken, 0) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab1-TKN-fasd35", + Identifier: "ab1-TKN-123456", Nonce: uint64(0), Amount: big.NewInt(14556666767), Type: core.Fungible, }) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab1-NFTV2-1ds234", + Identifier: "ab1-NFTV2-1a2b3c", Nonce: uint64(1), Amount: big.NewInt(1), Type: core.NonFungibleV2, }) //tokens = append(tokens, chainSim.ArgsDepositToken{ - // Identifier: "ab2-DNFT-fdfe3r", + // Identifier: "ab2-DNFT-ead43f", // Nonce: uint64(1), // Amount: big.NewInt(1), // Type: core.DynamicNFT, //}) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab2-SFT-gw4fw2", + Identifier: "ab2-SFT-cedd55", Nonce: uint64(1), Amount: big.NewInt(1421), Type: core.SemiFungible, }) //tokens = append(tokens, chainSim.ArgsDepositToken{ - // Identifier: "ab4-DSFT-g43g2s", + // Identifier: "ab4-DSFT-f6b4c2", // Nonce: uint64(1), // Amount: big.NewInt(1534), // Type: core.DynamicSFT, //}) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab5-META-1ds234", + Identifier: "ab5-META-4b543b", Nonce: uint64(1), Amount: big.NewInt(6231), Type: core.MetaFungible, }) //tokens = append(tokens, chainSim.ArgsDepositToken{ - // Identifier: "ab5-DMETA-f23g2f", + // Identifier: "ab5-DMETA-4b543b", // Nonce: uint64(1), // Amount: big.NewInt(162367), // Type: core.DynamicMeta, @@ -392,43 +392,43 @@ func TestChainSimulator_ExecuteWithTransferDataFails(t *testing.T) { // TODO MX-15942 uncomment dynamic tokens, currently there is no issue function in SC framework for dynamic esdts tokens := make([]chainSim.ArgsDepositToken, 0) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab1-TKN-fasd35", + Identifier: "ab1-TKN-123456", Nonce: uint64(0), Amount: big.NewInt(14556666767), Type: core.Fungible, }) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab1-NFTV2-1ds234", + Identifier: "ab1-NFTV2-1a2b3c", Nonce: uint64(1), Amount: big.NewInt(1), Type: core.NonFungibleV2, }) //tokens = append(tokens, chainSim.ArgsDepositToken{ - // Identifier: "ab2-DNFT-fdfe3r", + // Identifier: "ab2-DNFT-ead43f", // Nonce: uint64(1), // Amount: big.NewInt(1), // Type: core.DynamicNFT, //}) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab2-SFT-gw4fw2", + Identifier: "ab2-SFT-cedd55", Nonce: uint64(1), Amount: big.NewInt(1421), Type: core.SemiFungible, }) //tokens = append(tokens, chainSim.ArgsDepositToken{ - // Identifier: "ab4-DSFT-g43g2s", + // Identifier: "ab4-DSFT-f6b4c2", // Nonce: uint64(1), // Amount: big.NewInt(1534), // Type: core.DynamicSFT, //}) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab5-META-1ds234", + Identifier: "ab5-META-4b543b", Nonce: uint64(1), Amount: big.NewInt(6231), Type: core.MetaFungible, }) //tokens = append(tokens, chainSim.ArgsDepositToken{ - // Identifier: "ab5-DMETA-f23g2f", + // Identifier: "ab5-DMETA-4b543b", // Nonce: uint64(1), // Amount: big.NewInt(162367), // Type: core.DynamicMeta, diff --git a/integrationTests/chainSimulator/bridge/executeAndBurn_test.go b/integrationTests/chainSimulator/bridge/executeAndBurn_test.go index ade15c57606..8df109a9449 100644 --- a/integrationTests/chainSimulator/bridge/executeAndBurn_test.go +++ b/integrationTests/chainSimulator/bridge/executeAndBurn_test.go @@ -72,7 +72,7 @@ func TestChainSimulator_ExecuteWithMintMultipleEsdtsAndBurnNftWithDeposit(t *tes nftV2 := sovChainPrefix + "-NFTV2-a1b2c3" nftV2Nonce := uint64(10) - token := sovChainPrefix + "-TKN-1q2w3e" + token := sovChainPrefix + "-TKN-1d2e3a" // TODO MX-15942 add dynamic NFT type for bridge transfer bridgedInTokens := make([]chainSim.ArgsDepositToken, 0) diff --git a/integrationTests/chainSimulator/bridge/simpleEsdt_test.go b/integrationTests/chainSimulator/bridge/simpleEsdt_test.go index 2f73d2edbf9..39694c631c3 100644 --- a/integrationTests/chainSimulator/bridge/simpleEsdt_test.go +++ b/integrationTests/chainSimulator/bridge/simpleEsdt_test.go @@ -29,12 +29,12 @@ func TestSovereignChainSimulator_CreateNftWithManyQuantityShouldFail(t *testing. expectedError := "invalid arguments to process built-in function, invalid quantity for esdt type" - txData := createNftCreateArgs("da2-NFT2-geg42g", uint64(7), big.NewInt(2), core.NonFungibleV2, creatorAddress) + txData := createNftCreateArgs("da2-NFT2-aba42f", uint64(7), big.NewInt(2), core.NonFungibleV2, creatorAddress) expectedFullError := fmt.Sprintf("%s %d (%s)", expectedError, core.NonFungibleV2, core.NonFungibleV2.String()) executeSimpleEsdtOperationWithError(t, txData, expectedFullError) expectedFullError = fmt.Sprintf("%s %d (%s)", expectedError, core.DynamicNFT, core.DynamicNFT.String()) - txData = createNftCreateArgs("da3-NFT3-gew3gr", uint64(7), big.NewInt(2), core.DynamicNFT, creatorAddress) + txData = createNftCreateArgs("da3-NFT3-ffa3bd", uint64(7), big.NewInt(2), core.DynamicNFT, creatorAddress) executeSimpleEsdtOperationWithError(t, txData, expectedFullError) } @@ -46,15 +46,15 @@ func TestSovereignChainSimulator_CreateNftWithInvalidTypeShouldFail(t *testing.T expectedError := "invalid arguments to process built-in function, invalid esdt type" expectedFullError := fmt.Sprintf("%s %d (%s)", expectedError, core.Fungible, core.Fungible.String()) - txData := createNftCreateArgs("da-TKN-ten731", uint64(0), big.NewInt(1), core.Fungible, creatorAddress) + txData := createNftCreateArgs("da-TKN-ade731", uint64(0), big.NewInt(1), core.Fungible, creatorAddress) executeSimpleEsdtOperationWithError(t, txData, expectedFullError) expectedFullError = fmt.Sprintf("%s %d (%s)", expectedError, core.NonFungible, core.NonFungible.String()) - txData = createNftCreateArgs("da-NFT-4g4325", uint64(7), big.NewInt(1), core.NonFungible, creatorAddress) + txData = createNftCreateArgs("da-NFT-4f4325", uint64(7), big.NewInt(1), core.NonFungible, creatorAddress) executeSimpleEsdtOperationWithError(t, txData, expectedFullError) expectedFullError = fmt.Sprintf("%s %d (%s)", expectedError, core.ESDTType(8), core.ESDTType(8).String()) - txData = createNftCreateArgs("da-NFT-ten731", uint64(7), big.NewInt(1), core.ESDTType(8), creatorAddress) + txData = createNftCreateArgs("da-NFT-beb731", uint64(7), big.NewInt(1), core.ESDTType(8), creatorAddress) executeSimpleEsdtOperationWithError(t, txData, expectedFullError) } @@ -175,43 +175,43 @@ func createAllEsdtTypes( ) []chainSim.ArgsDepositToken { tokens := make([]chainSim.ArgsDepositToken, 0) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab1-TKN-fasd35", + Identifier: "ab1-TKN-123456", Nonce: uint64(0), Amount: big.NewInt(14556666767), Type: core.Fungible, }) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab1-NFTV2-1ds234", + Identifier: "ab1-NFTV2-1a2b3c", Nonce: uint64(3), Amount: big.NewInt(1), Type: core.NonFungibleV2, }) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab2-DNFT-fdfe3r", + Identifier: "ab2-DNFT-ead43f", Nonce: uint64(22), Amount: big.NewInt(1), Type: core.DynamicNFT, }) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab2-SFT-gw4fw2", + Identifier: "ab2-SFT-cedd55", Nonce: uint64(345), Amount: big.NewInt(1421), Type: core.SemiFungible, }) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab4-DSFT-g43g2s", + Identifier: "ab4-DSFT-f6b4c2", Nonce: uint64(88), Amount: big.NewInt(1534), Type: core.DynamicSFT, }) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab5-META-1ds234", + Identifier: "ab5-META-4b543b", Nonce: uint64(44), Amount: big.NewInt(6231), Type: core.MetaFungible, }) tokens = append(tokens, chainSim.ArgsDepositToken{ - Identifier: "ab5-DMETA-f23g2f", + Identifier: "ab5-DMETA-4b543b", Nonce: uint64(721), Amount: big.NewInt(162367), Type: core.DynamicMeta, @@ -332,7 +332,7 @@ func TestChainSimulator_CreateTokenAndNFTCollectionSameIdentifierAndMakeTransact require.Equal(t, whiteListedAddress, contractAddressEncoded) // mint Token - tokenIdentifier := "s1-TKN-gdf412" + tokenIdentifier := "s1-TKN-adf412" tokenAmount := big.NewInt(125) args := createLocalMintArgs(tokenIdentifier, tokenAmount) chainSim.SendTransactionWithSuccess(t, cs, initialAddrBytes, &nonce, contractAddress, chainSim.ZeroValue, args, uint64(20000000)) diff --git a/state/accounts/esdtAsBalance.go b/state/accounts/esdtAsBalance.go index ec7694efb09..2ae6356053f 100644 --- a/state/accounts/esdtAsBalance.go +++ b/state/accounts/esdtAsBalance.go @@ -7,9 +7,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/marshal" - "github.com/multiversx/mx-chain-go/errors" logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" + + "github.com/multiversx/mx-chain-go/errors" ) const baseESDTKeyPrefix = core.ProtectedKeyPrefix + core.ESDTKeyIdentifier @@ -29,8 +30,9 @@ func NewESDTAsBalance( if check.IfNil(marshaller) { return nil, errors.ErrNilMarshalizer } - if len(baseTokenID) == 0 { - return nil, errors.ErrEmptyBaseToken + err := validateBaseToken(baseTokenID) + if err != nil { + return nil, err } return &esdtAsBalance{ @@ -39,6 +41,22 @@ func NewESDTAsBalance( }, nil } +func validateBaseToken(baseTokenID string) error { + if len(baseTokenID) == 0 { + return errors.ErrEmptyBaseToken + } + + if _, isValid := esdt.IsValidPrefixedToken(baseTokenID); isValid { + return nil + } + + if vmcommon.ValidateToken([]byte(baseTokenID)) { + return nil + } + + return errors.ErrInvalidBaseToken +} + // GetBalance returns the native esdt balance func (e *esdtAsBalance) GetBalance(accountDataHandler vmcommon.AccountDataHandler) *big.Int { esdtData, err := e.getESDTData(accountDataHandler) diff --git a/state/accounts/esdtAsBalance_test.go b/state/accounts/esdtAsBalance_test.go index ddb6ab918fe..b1751678a64 100644 --- a/state/accounts/esdtAsBalance_test.go +++ b/state/accounts/esdtAsBalance_test.go @@ -7,13 +7,15 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/esdt" + "github.com/stretchr/testify/require" + errorsMx "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/trie" - "github.com/stretchr/testify/require" ) -const baseTokenID = "WEGLD" +const baseTokenID = "WEGLD-bd4d79" +const prefixedBaseTokenID = "sov-ESDT-a1b2c3" func TestNewESDTAsBalance(t *testing.T) { t.Parallel() @@ -23,6 +25,16 @@ func TestNewESDTAsBalance(t *testing.T) { require.Equal(t, errorsMx.ErrEmptyBaseToken, err) require.Nil(t, esdtBalance) }) + t.Run("invalid prefixed base token, should return error", func(t *testing.T) { + esdtBalance, err := NewESDTAsBalance("svn12-ABC-1a2f3f", &marshallerMock.MarshalizerMock{}) + require.Equal(t, errorsMx.ErrInvalidBaseToken, err) + require.Nil(t, esdtBalance) + }) + t.Run("invalid base token, should return error", func(t *testing.T) { + esdtBalance, err := NewESDTAsBalance("MvX-1c4f2a", &marshallerMock.MarshalizerMock{}) + require.Equal(t, errorsMx.ErrInvalidBaseToken, err) + require.Nil(t, esdtBalance) + }) t.Run("nil marshaller, should return error", func(t *testing.T) { esdtBalance, err := NewESDTAsBalance(baseTokenID, nil) require.Equal(t, errorsMx.ErrNilMarshalizer, err) @@ -33,11 +45,21 @@ func TestNewESDTAsBalance(t *testing.T) { require.Nil(t, err) require.False(t, esdtBalance.IsInterfaceNil()) }) + t.Run("prefixed base token, should work", func(t *testing.T) { + esdtBalance, err := NewESDTAsBalance(prefixedBaseTokenID, &marshallerMock.MarshalizerMock{}) + require.Nil(t, err) + require.False(t, esdtBalance.IsInterfaceNil()) + }) } func TestEsdtAsBalance_getESDTData(t *testing.T) { t.Parallel() + testGetEsdtData(t, baseTokenID) + testGetEsdtData(t, prefixedBaseTokenID) +} + +func testGetEsdtData(t *testing.T, baseTokenID string) { t.Run("no value stored in account for esdt, should return empty token", func(t *testing.T) { esdtBalance, _ := NewESDTAsBalance(baseTokenID, &marshallerMock.MarshalizerMock{}) accHandler := &trie.DataTrieTrackerStub{ @@ -103,6 +125,11 @@ func TestEsdtAsBalance_getESDTData(t *testing.T) { func TestEsdtAsBalance_GetBalance(t *testing.T) { t.Parallel() + testGetBalance(t, baseTokenID) + testGetBalance(t, prefixedBaseTokenID) +} + +func testGetBalance(t *testing.T, baseTokenID string) { t.Run("could not load balance, should return 0 value", func(t *testing.T) { marshaller := &marshallerMock.MarshalizerStub{ UnmarshalCalled: func(obj interface{}, buff []byte) error { @@ -133,6 +160,11 @@ func TestEsdtAsBalance_GetBalance(t *testing.T) { func TestEsdtAsBalance_AddToBalance(t *testing.T) { t.Parallel() + testAddToBalance(t, baseTokenID) + testAddToBalance(t, prefixedBaseTokenID) +} + +func testAddToBalance(t *testing.T, baseTokenID string) { currentBalance := &esdt.ESDigitalToken{ Value: big.NewInt(123), } @@ -176,6 +208,11 @@ func TestEsdtAsBalance_AddToBalance(t *testing.T) { func TestEsdtAsBalance_SubFromBalance(t *testing.T) { t.Parallel() + testSubFromBalance(t, baseTokenID) + testSubFromBalance(t, prefixedBaseTokenID) +} + +func testSubFromBalance(t *testing.T, baseTokenID string) { currentBalance := &esdt.ESDigitalToken{ Value: big.NewInt(121), } diff --git a/state/factory/sovereignAccountCreator_test.go b/state/factory/sovereignAccountCreator_test.go index cf010769c27..b9782acaceb 100644 --- a/state/factory/sovereignAccountCreator_test.go +++ b/state/factory/sovereignAccountCreator_test.go @@ -4,11 +4,12 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - "github.com/stretchr/testify/require" ) func createArgsSovAccountCreator() ArgsSovereignAccountCreator { @@ -18,7 +19,7 @@ func createArgsSovAccountCreator() ArgsSovereignAccountCreator { Marshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, }, - BaseTokenID: "WEGLD", + BaseTokenID: "WEGLD-bd4d79", } } @@ -64,7 +65,13 @@ func TestNewSovereignAccountCreator(t *testing.T) { func TestSovereignAccountCreator_CreateAccount(t *testing.T) { t.Parallel() + testCreateAccount(t, "WEGLD-bd4d79") + testCreateAccount(t, "sov-ESDT-a1b2c3") +} + +func testCreateAccount(t *testing.T, baseTokenID string) { args := createArgsSovAccountCreator() + args.BaseTokenID = baseTokenID sovAccCreator, _ := NewSovereignAccountCreator(args) sovAcc, err := sovAccCreator.CreateAccount([]byte("address"))