Skip to content

Commit

Permalink
FIX: Sovereign chain simulator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmihaic committed Oct 8, 2024
1 parent 0fe648c commit a3d3179
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 31 deletions.
13 changes: 3 additions & 10 deletions cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestNewSovereignChainSimulator(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand All @@ -61,7 +60,6 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand Down Expand Up @@ -91,7 +89,6 @@ func TestChainSimulator_SetState(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand All @@ -118,7 +115,6 @@ func TestChainSimulator_SetEntireState(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand All @@ -140,7 +136,7 @@ func TestChainSimulator_SetEntireState(t *testing.T) {
CodeMetadata: "BQY=",
Owner: "erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97",
DeveloperRewards: "5401004999998",
Keys: map[string]string{
Pairs: map[string]string{
"73756d": "0a",
},
}
Expand All @@ -164,7 +160,6 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand All @@ -186,7 +181,7 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) {
CodeMetadata: "BQY=",
Owner: "erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97",
DeveloperRewards: "5401004999998",
Keys: map[string]string{
Pairs: map[string]string{
"73756d": "0a",
},
}
Expand All @@ -210,7 +205,6 @@ func TestChainSimulator_GetAccount(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand All @@ -228,15 +222,14 @@ func TestSimulator_SendTransactions(t *testing.T) {
chainSimulator, err := NewSovereignChainSimulator(ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSim.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ func TestSovereignChainSimulator_SmartContract_Adder(t *testing.T) {
cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand All @@ -56,6 +55,9 @@ func TestSovereignChainSimulator_SmartContract_Adder(t *testing.T) {
require.Nil(t, err)
nonce := uint64(0)

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

initSum := big.NewInt(123)
initArgs := "@" + hex.EncodeToString(initSum.Bytes())
deployedContractAddress := chainSim.DeployContract(t, cs, wallet.Bytes, &nonce, systemScAddress, initArgs, adderWasmPath)
Expand Down
6 changes: 4 additions & 2 deletions cmd/sovereignnode/chainSimulator/tests/bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ func TestSovereignChainSimulator_DeployBridgeContractsThenIssueAndDeposit(t *tes
cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
AlterConfigsFunction: func(cfg *config.Configs) {
// Put every enable epoch on 0
cfg.EpochConfig.EnableEpochs = config.EnableEpochs{
Expand Down Expand Up @@ -89,6 +88,9 @@ func TestSovereignChainSimulator_DeployBridgeContractsThenIssueAndDeposit(t *tes
})
require.Nil(t, err)

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

wallet := dtos.WalletAddress{Bech32: initialAddress, Bytes: initialAddrBytes}

expectedESDTSafeAddressBytes, err := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(outGoingSubscribedAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ func TestSovereignChainSimulator_NewDelegationSC(t *testing.T) {
cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.DelegationSmartContractEnableEpoch = 0
},
Expand All @@ -56,6 +55,9 @@ func TestSovereignChainSimulator_NewDelegationSC(t *testing.T) {
require.Nil(t, err)
nonce := uint64(0)

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

txData := "createNewDelegationContract" +
"@" + hex.EncodeToString(big.NewInt(0).Mul(chainSim.OneEGLD, big.NewInt(100000)).Bytes()) +
"@64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestSovereignChainSimulator_EpochChange(t *testing.T) {
cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
Expand Down
6 changes: 4 additions & 2 deletions cmd/sovereignnode/chainSimulator/tests/esdt/issueSc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ func TestSovereignChainSimulator_SmartContract_IssueToken(t *testing.T) {
cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = issuePrice
},
Expand All @@ -70,6 +69,9 @@ func TestSovereignChainSimulator_SmartContract_IssueToken(t *testing.T) {
require.Nil(t, err)
nonce := uint64(0)

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

deployedContractAddress := chainSim.DeployContract(t, cs, wallet.Bytes, &nonce, systemScAddress, "", issueWasmPath)
deployedContractAddressBech32, err := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Encode(deployedContractAddress)
require.Nil(t, err)
Expand Down
12 changes: 8 additions & 4 deletions cmd/sovereignnode/chainSimulator/tests/esdt/issueSft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ func TestSovereignChainSimulator_RegisterTwoSfts(t *testing.T) {
cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = issuePrice
},
Expand All @@ -58,6 +57,9 @@ func TestSovereignChainSimulator_RegisterTwoSfts(t *testing.T) {
require.Nil(t, err)
nonce := uint64(0)

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

issueCost, _ := big.NewInt(0).SetString(issuePrice, 10)
sftName := "SFTNAME"
sftTicker := "SFTTICKER"
Expand Down Expand Up @@ -100,15 +102,14 @@ func TestSovereignChainSimulator_IssueTwoSfts(t *testing.T) {
cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand All @@ -122,6 +123,9 @@ func TestSovereignChainSimulator_IssueTwoSfts(t *testing.T) {
require.Nil(t, err)
nonce := uint64(0)

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

issueCost, _ := big.NewInt(0).SetString(issuePrice, 10)
sftName := "SFTNAME"
sftTicker := "SFTTICKER"
Expand Down
6 changes: 4 additions & 2 deletions cmd/sovereignnode/chainSimulator/tests/esdt/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ func TestSovereignChainSimulator_IssueFungible(t *testing.T) {
cs, err := sovereignChainSimulator.NewSovereignChainSimulator(sovereignChainSimulator.ArgsSovereignChainSimulator{
SovereignConfigPath: sovereignConfigPath,
ArgsChainSimulator: &chainSimulator.ArgsChainSimulator{
BypassTxSignatureCheck: false,
BypassTxSignatureCheck: true,
TempDir: t.TempDir(),
PathToInitialConfig: defaultPathToInitialConfig,
GenesisTimestamp: time.Now().Unix(),
RoundDurationInMillis: uint64(6000),
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = issuePrice
},
Expand All @@ -65,6 +64,9 @@ func TestSovereignChainSimulator_IssueFungible(t *testing.T) {
wallet, err := cs.GenerateAndMintWalletAddress(core.SovereignChainShardId, chainSim.InitialAmount)
require.Nil(t, err)

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

issueCost, _ := big.NewInt(0).SetString(issuePrice, 10)
supply, _ := big.NewInt(0).SetString("123000000000000000000", 10)
tokenName := "SovereignTkn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestSovereignChainSimulator_NoCrossHeadersReceived(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand Down Expand Up @@ -82,7 +81,6 @@ func TestSovereignChainSimulator_BlockTrackerPoolsCleanup(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestSovereignChainSimulator_IncomingHeader(t *testing.T) {
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 2,
ConsensusGroupSize: 2,
},
})
require.Nil(t, err)
Expand Down
4 changes: 4 additions & 0 deletions integrationTests/chainSimulator/staking/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ func StakeNodes(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator,
stakedBlsKeys = append(stakedBlsKeys, blsKeyBytes)
}

// Set state from CreateStakeTransaction needs an extra generated block to save state
err := cs.GenerateBlocks(1)
require.Nil(t, err)

stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted(txs, MaxNumOfBlockToGenerateWhenExecutingTx)
require.Nil(t, err)
require.NotNil(t, stakeTxs)
Expand Down
4 changes: 1 addition & 3 deletions node/chainSimulator/sovereignChainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package chainSimulator

import (
"fmt"

"github.com/multiversx/mx-chain-go/node/chainSimulator/configs"
)

type sovereignChainSimulator struct {
Expand All @@ -14,7 +12,7 @@ type sovereignChainSimulator struct {
func NewSovereignChainSimulator(args ArgsChainSimulator) (*sovereignChainSimulator, error) {
cs, err := NewBaseChainSimulator(ArgsBaseChainSimulator{
ArgsChainSimulator: args,
ConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize,
ConsensusGroupSize: args.MinNodesPerShard,
MetaChainConsensusGroupSize: 0,
})
if err != nil {
Expand Down

0 comments on commit a3d3179

Please sign in to comment.