Skip to content

Commit

Permalink
Merge pull request #6630 from multiversx/merge-feat-sovereign-into-fe…
Browse files Browse the repository at this point in the history
…at-sync-main-headers

Merge feat sovereign into feat sync main headers
  • Loading branch information
mariusmihaic authored Nov 25, 2024
2 parents 624ae44 + 397fa02 commit 910d464
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 54 deletions.
4 changes: 2 additions & 2 deletions cmd/sovereignnode/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions cmd/sovereignnode/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
3 changes: 3 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion factory/runType/sovereignRunTypeComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func createSovRunTypeArgs() runType.ArgsSovereignRunTypeComponents {
RunTypeComponentsFactory: rcf,
Config: config.SovereignConfig{
GenesisConfig: config.GenesisConfig{
NativeESDT: "WEGLD",
NativeESDT: "WEGLD-bd4d79",
},
},
DataCodec: &sovereign.DataCodecMock{},
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
12 changes: 6 additions & 6 deletions integrationTests/chainSimulator/bridge/bridgeAndTransfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions integrationTests/chainSimulator/bridge/esdtSafe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions integrationTests/chainSimulator/bridge/simpleEsdt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
24 changes: 21 additions & 3 deletions state/accounts/esdtAsBalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 910d464

Please sign in to comment.