Skip to content

Commit

Permalink
Merge branch 'MX-15936-move-incoming-header-proc' into MX-15917-force…
Browse files Browse the repository at this point in the history
…-cross-chain-hdr-genesis-at-config-round

# Conflicts:
#	cmd/sovereignnode/chainSimulator/tests/processBlock/incomingHeader_test.go
  • Loading branch information
mariusmihaic committed Oct 18, 2024
2 parents aa14042 + f37a7ef commit 77ac96a
Show file tree
Hide file tree
Showing 31 changed files with 179 additions and 147 deletions.
3 changes: 2 additions & 1 deletion cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/multiversx/mx-chain-go/node"
"github.com/multiversx/mx-chain-go/node/chainSimulator"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/block/sovereign/incomingHeader"
sovereignConfig "github.com/multiversx/mx-chain-go/sovereignnode/config"
"github.com/multiversx/mx-chain-go/sovereignnode/incomingHeader"
sovRunType "github.com/multiversx/mx-chain-go/sovereignnode/runType"
)

Expand Down Expand Up @@ -43,6 +43,7 @@ func NewSovereignChainSimulator(args ArgsSovereignChainSimulator) (chainSimulato
cfg.GeneralConfig.SovereignConfig = *configs.SovereignExtraConfig
cfg.GeneralConfig.VirtualMachine.Execution.WasmVMVersions = []config.WasmVMVersionByEpoch{{StartEpoch: 0, Version: "v1.5"}}
cfg.GeneralConfig.VirtualMachine.Querying.WasmVMVersions = []config.WasmVMVersionByEpoch{{StartEpoch: 0, Version: "v1.5"}}
cfg.SystemSCConfig.ESDTSystemSCConfig.ESDTPrefix = "sov"

if alterConfigs != nil {
alterConfigs(cfg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestSovereignChainSimulator_SmartContract_Adder(t *testing.T) {

addedSum := big.NewInt(10)
addTxData := "add@" + hex.EncodeToString(addedSum.Bytes())
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, deployedContractAddress, chainSim.ZeroValue, addTxData, uint64(10000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, deployedContractAddress, chainSim.ZeroValue, addTxData, uint64(10000000))

res, _, err = nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{
ScAddress: deployedContractAddress,
Expand Down
5 changes: 3 additions & 2 deletions cmd/sovereignnode/chainSimulator/tests/bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestSovereignChainSimulator_DeployBridgeContractsThenIssueAndDeposit(t *tes
expectedESDTSafeAddressBytes, err := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(outGoingSubscribedAddress)
require.Nil(t, err)

bridgeData := DeploySovereignBridgeSetup(t, cs, wallet, esdtSafeWasmPath, feeMarketWasmPath)
bridgeData := deploySovereignBridgeSetup(t, cs, wallet, esdtSafeWasmPath, feeMarketWasmPath)
require.Equal(t, expectedESDTSafeAddressBytes, bridgeData.ESDTSafeAddress)

nonce := GetNonce(t, nodeHandler, wallet.Bech32)
Expand All @@ -116,7 +116,8 @@ func TestSovereignChainSimulator_DeployBridgeContractsThenIssueAndDeposit(t *tes
Amount: amountToDeposit,
})

Deposit(t, cs, wallet.Bytes, &nonce, bridgeData.ESDTSafeAddress, depositTokens, wallet.Bytes, nil)
txResult := Deposit(t, cs, wallet.Bytes, &nonce, bridgeData.ESDTSafeAddress, depositTokens, wallet.Bytes, nil)
chainSim.RequireSuccessfulTransaction(t, txResult)

tokens, _, err := nodeHandler.GetFacadeHandler().GetAllESDTTokens(wallet.Bech32, coreAPI.AccountQueryOptions{})
require.Nil(t, err)
Expand Down
25 changes: 13 additions & 12 deletions cmd/sovereignnode/chainSimulator/tests/bridge/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"encoding/hex"
"testing"

coreAPI "github.com/multiversx/mx-chain-core-go/data/api"
chainSim "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
"github.com/multiversx/mx-chain-go/node/chainSimulator/process"

"github.com/multiversx/mx-chain-core-go/core"
coreAPI "github.com/multiversx/mx-chain-core-go/data/api"
"github.com/multiversx/mx-chain-core-go/data/sovereign"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-sdk-abi-go/abi"
"github.com/stretchr/testify/require"

chainSim "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
"github.com/multiversx/mx-chain-go/node/chainSimulator/process"
)

const (
Expand All @@ -29,14 +30,14 @@ type ArgsBridgeSetup struct {
FeeMarketAddress []byte
}

// DeploySovereignBridgeSetup will deploy all bridge contracts
// deploySovereignBridgeSetup will deploy all bridge contracts
// This function will:
// - deploy esdt-safe contract
// - deploy fee-market contract
// - set the fee-market address inside esdt-safe contract
// - disable fee in fee-market contract
// - unpause esdt-safe contract so deposit operations can start
func DeploySovereignBridgeSetup(
func deploySovereignBridgeSetup(
t *testing.T,
cs chainSim.ChainSimulator,
wallet dtos.WalletAddress,
Expand All @@ -60,11 +61,11 @@ func DeploySovereignBridgeSetup(

setFeeMarketAddressData := "setFeeMarketAddress" +
"@" + hex.EncodeToString(feeMarketAddress)
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, esdtSafeAddress, chainSim.ZeroValue, setFeeMarketAddressData, uint64(10000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, esdtSafeAddress, chainSim.ZeroValue, setFeeMarketAddressData, uint64(10000000))

chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, feeMarketAddress, chainSim.ZeroValue, "disableFee", uint64(10000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, feeMarketAddress, chainSim.ZeroValue, "disableFee", uint64(10000000))

chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, esdtSafeAddress, chainSim.ZeroValue, "unpause", uint64(10000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, esdtSafeAddress, chainSim.ZeroValue, "unpause", uint64(10000000))

return &ArgsBridgeSetup{
ESDTSafeAddress: esdtSafeAddress,
Expand All @@ -90,7 +91,7 @@ func Deposit(
tokens []chainSim.ArgsDepositToken,
receiver []byte,
transferData *sovereign.TransferData,
) {
) *transaction.ApiTransactionResult {
require.True(t, len(tokens) > 0)

args := make([]any, 0)
Expand All @@ -110,7 +111,7 @@ func Deposit(
depositArgs := core.BuiltInFunctionMultiESDTNFTTransfer +
"@" + multiTransferArg

chainSim.SendTransaction(t, cs, sender, nonce, sender, chainSim.ZeroValue, depositArgs, uint64(20000000))
return chainSim.SendTransaction(t, cs, sender, nonce, sender, chainSim.ZeroValue, depositArgs, uint64(20000000))
}

func getTransferDataValue(transferData *sovereign.TransferData) any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestSovereignChainSimulator_NewDelegationSC(t *testing.T) {
"@64"
cost := big.NewInt(0).Mul(chainSim.OneEGLD, big.NewInt(1250))
txResult := chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, vm.DelegationManagerSCAddress, cost, txData, uint64(60000000))
chainSim.RequireSuccessfulTransaction(t, txResult)

secondDelegationSCAddress := txResult.Logs.Events[1].Topics[4]
secondDelegationSCAddressBech32, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Encode(secondDelegationSCAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
apiData "github.com/multiversx/mx-chain-core-go/data/api"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-go/dataRetriever"
chainSim "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator"
"github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking"
"github.com/multiversx/mx-chain-go/node/chainSimulator/process"
"github.com/multiversx/mx-chain-go/process/headerCheck"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
chainSim "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator"
"github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking"
"github.com/multiversx/mx-chain-go/node/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components/api"
"github.com/multiversx/mx-chain-go/node/chainSimulator/process"
"github.com/multiversx/mx-chain-go/process/headerCheck"
sovereignChainSimulator "github.com/multiversx/mx-chain-go/sovereignnode/chainSimulator"
)

Expand Down Expand Up @@ -132,7 +132,7 @@ func TestSovereignChainSimulator_EpochChange(t *testing.T) {
require.Len(t, qualified, 2)
require.Len(t, unqualified, 8)

chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, "data", uint64(10000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, "data", uint64(10000000))

accFeesInEpoch, devFeesInEpoch = getAllFeesInEpoch(nodeHandler)
require.NotEmpty(t, accFeesInEpoch)
Expand Down
82 changes: 82 additions & 0 deletions cmd/sovereignnode/chainSimulator/tests/esdt/issueNft_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package esdt

import (
"math/big"
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/core"
coreAPI "github.com/multiversx/mx-chain-core-go/data/api"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/config"
chainSim "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components/api"
sovereignChainSimulator "github.com/multiversx/mx-chain-go/sovereignnode/chainSimulator"
)

var nftV2Roles = []string{
core.ESDTRoleNFTCreate,
core.ESDTRoleNFTBurn,
core.ESDTRoleNFTUpdateAttributes,
core.ESDTRoleNFTAddURI,
core.ESDTRoleNFTRecreate,
core.ESDTRoleModifyCreator,
core.ESDTRoleModifyRoyalties,
core.ESDTRoleSetNewURI,
core.ESDTRoleNFTUpdate,
}

func TestSovereignChainSimulator_RegisterNftWithPrefix(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
}

cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = issuePrice
},
},
})
require.Nil(t, err)
require.NotNil(t, cs)

defer cs.Close()

nodeHandler := cs.GetNodeHandler(core.SovereignChainShardId)

wallet, err := cs.GenerateAndMintWalletAddress(core.SovereignChainShardId, chainSim.InitialAmount)
require.Nil(t, err)
nonce := uint64(0)

err = cs.GenerateBlocks(1)
require.Nil(t, err)

issueCost, _ := big.NewInt(0).SetString(issuePrice, 10)
nftName := "NFTNAME"
nftTicker := "NFTTICKER"
nftIdentifier := chainSim.RegisterAndSetAllRoles(t, cs, nodeHandler, wallet.Bytes, &nonce, issueCost, nftName, nftTicker, core.NonFungibleESDTv2, 0)

checkAllRoles(t, nodeHandler, wallet.Bech32, nftIdentifier, nftV2Roles)

initialSupply := big.NewInt(1)
createArgs := createNftArgs(nftIdentifier, initialSupply, "NFTNAME #1")
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))

tokens, _, err := nodeHandler.GetFacadeHandler().GetAllESDTTokens(wallet.Bech32, coreAPI.AccountQueryOptions{})
require.Nil(t, err)
require.NotNil(t, tokens)
require.True(t, len(tokens) == 2)
require.Equal(t, initialSupply, tokens[nftIdentifier+"-01"].Value)
}
6 changes: 3 additions & 3 deletions cmd/sovereignnode/chainSimulator/tests/esdt/issueSc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestSovereignChainSimulator_SmartContract_IssueToken(t *testing.T) {
require.Nil(t, err)

issueCost, _ := big.NewInt(0).SetString(issuePrice, 10)
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, deployedContractAddress, issueCost, "issue", uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, deployedContractAddress, issueCost, "issue", uint64(60000000))

account, _, err := nodeHandler.GetFacadeHandler().GetAccount(deployedContractAddressBech32, coreAPI.AccountQueryOptions{})
require.Nil(t, err)
Expand All @@ -90,15 +90,15 @@ func TestSovereignChainSimulator_SmartContract_IssueToken(t *testing.T) {
tokenIdentifier := issuedESDTs[0]

setRolesArgs := "setRoles@" + hex.EncodeToString([]byte(tokenIdentifier))
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, deployedContractAddress, chainSim.ZeroValue, setRolesArgs, uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, deployedContractAddress, chainSim.ZeroValue, setRolesArgs, uint64(60000000))

checkAllRoles(t, nodeHandler, deployedContractAddressBech32, tokenIdentifier, fungibleRoles)

expectedMintedAmount, _ := big.NewInt(0).SetString("123000000000000000000", 10)
mintTxArgs := "mint" +
"@" + hex.EncodeToString([]byte(tokenIdentifier)) +
"@" + hex.EncodeToString(expectedMintedAmount.Bytes())
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, deployedContractAddress, chainSim.ZeroValue, mintTxArgs, uint64(20000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, deployedContractAddress, chainSim.ZeroValue, mintTxArgs, uint64(20000000))

account, _, err = nodeHandler.GetFacadeHandler().GetAccount(deployedContractAddressBech32, coreAPI.AccountQueryOptions{})
require.Nil(t, err)
Expand Down
15 changes: 9 additions & 6 deletions cmd/sovereignnode/chainSimulator/tests/esdt/issueSft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestSovereignChainSimulator_RegisterTwoSfts(t *testing.T) {

initialSupply := big.NewInt(111)
createArgs := createNftArgs(sftIdentifier, initialSupply, "SFTNAME #1")
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))

tokens, _, err := nodeHandler.GetFacadeHandler().GetAllESDTTokens(wallet.Bech32, coreAPI.AccountQueryOptions{})
require.Nil(t, err)
Expand All @@ -85,7 +85,7 @@ func TestSovereignChainSimulator_RegisterTwoSfts(t *testing.T) {

initialSupply = big.NewInt(222)
createArgs = createNftArgs(sftIdentifier, initialSupply, "SFTNAME #2")
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))

tokens, _, err = nodeHandler.GetFacadeHandler().GetAllESDTTokens(wallet.Bech32, coreAPI.AccountQueryOptions{})
require.Nil(t, err)
Expand All @@ -110,6 +110,9 @@ func TestSovereignChainSimulator_IssueTwoSfts(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = issuePrice
},
},
})
require.Nil(t, err)
Expand All @@ -132,13 +135,13 @@ func TestSovereignChainSimulator_IssueTwoSfts(t *testing.T) {
sftIdentifier := chainSim.IssueSemiFungible(t, cs, nodeHandler, wallet.Bytes, &nonce, issueCost, sftName, sftTicker)

setRolesArgs := setSpecialRole(sftIdentifier, wallet.Bytes, sftRoles)
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, vm.ESDTSCAddress, chainSim.ZeroValue, setRolesArgs, uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, vm.ESDTSCAddress, chainSim.ZeroValue, setRolesArgs, uint64(60000000))

checkAllRoles(t, nodeHandler, wallet.Bech32, sftIdentifier, sftRoles)

initialSupply := big.NewInt(100)
createArgs := createNftArgs(sftIdentifier, initialSupply, "SFTNAME #1")
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))

tokens, _, err := nodeHandler.GetFacadeHandler().GetAllESDTTokens(wallet.Bech32, coreAPI.AccountQueryOptions{})
require.Nil(t, err)
Expand All @@ -151,13 +154,13 @@ func TestSovereignChainSimulator_IssueTwoSfts(t *testing.T) {
sftIdentifier = chainSim.IssueSemiFungible(t, cs, nodeHandler, wallet.Bytes, &nonce, issueCost, sftName, sftTicker)

setRolesArgs = setSpecialRole(sftIdentifier, wallet.Bytes, sftRoles)
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, vm.ESDTSCAddress, chainSim.ZeroValue, setRolesArgs, uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, vm.ESDTSCAddress, chainSim.ZeroValue, setRolesArgs, uint64(60000000))

checkAllRoles(t, nodeHandler, wallet.Bech32, sftIdentifier, sftRoles)

initialSupply = big.NewInt(200)
createArgs = createNftArgs(sftIdentifier, initialSupply, "SFTNAME2 #1")
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, wallet.Bytes, chainSim.ZeroValue, createArgs, uint64(60000000))

tokens, _, err = nodeHandler.GetFacadeHandler().GetAllESDTTokens(wallet.Bech32, coreAPI.AccountQueryOptions{})
require.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sovereignnode/chainSimulator/tests/esdt/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestSovereignChainSimulator_IssueFungible(t *testing.T) {
require.Equal(t, supply, esdtSupply)

setRolesArgs := setSpecialRole(tokenIdentifier, wallet.Bytes, fungibleRoles)
chainSim.SendTransaction(t, cs, wallet.Bytes, &nonce, vm.ESDTSCAddress, chainSim.ZeroValue, setRolesArgs, uint64(60000000))
chainSim.SendTransactionWithSuccess(t, cs, wallet.Bytes, &nonce, vm.ESDTSCAddress, chainSim.ZeroValue, setRolesArgs, uint64(60000000))

checkAllRoles(t, nodeHandler, wallet.Bech32, tokenIdentifier, fungibleRoles)
}
Loading

0 comments on commit 77ac96a

Please sign in to comment.