Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial wallet keys #5709

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions node/chainSimulator/chainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components"
"github.com/multiversx/mx-chain-go/node/chainSimulator/configs"
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
"github.com/multiversx/mx-chain-go/node/chainSimulator/process"
"github.com/multiversx/mx-chain-go/node/chainSimulator/testdata"
logger "github.com/multiversx/mx-chain-logger-go"
)

Expand All @@ -19,6 +19,7 @@ type simulator struct {
chanStopNodeProcess chan endProcess.ArgEndProcess
syncedBroadcastNetwork components.SyncedBroadcastNetworkHandler
handlers []ChainHandler
initialWalletKeys *dtos.InitialWalletKeys
nodes map[uint32]process.NodeHandler
numOfShards uint32
}
Expand Down Expand Up @@ -61,13 +62,11 @@ func (s *simulator) createChainHandlers(
apiInterface components.APIConfigurator,
) error {
outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{
NumOfShards: numOfShards,
OriginalConfigsPath: originalConfigPath,
GenesisAddressWithStake: testdata.GenesisAddressWithStake,
GenesisAddressWithBalance: testdata.GenesisAddressWithBalance,
GenesisTimeStamp: genesisTimestamp,
RoundDurationInMillis: roundDurationInMillis,
TempDir: tempDir,
NumOfShards: numOfShards,
OriginalConfigsPath: originalConfigPath,
GenesisTimeStamp: genesisTimestamp,
RoundDurationInMillis: roundDurationInMillis,
TempDir: tempDir,
})
if err != nil {
return err
Expand All @@ -93,6 +92,8 @@ func (s *simulator) createChainHandlers(
s.handlers = append(s.handlers, chainHandler)
}

s.initialWalletKeys = outputConfigs.InitialWallets

log.Info("running the chain simulator with the following parameters",
"number of shards (including meta)", numOfShards+1,
"round per epoch", outputConfigs.Configs.GeneralConfig.EpochStartConfig.RoundsPerEpoch,
Expand Down Expand Up @@ -167,6 +168,11 @@ func (s *simulator) GetRestAPIInterfaces() map[uint32]string {
return resMap
}

// GetInitialWalletKeys will return the initial wallet keys
func (s *simulator) GetInitialWalletKeys() *dtos.InitialWalletKeys {
return s.initialWalletKeys
}

// Close will stop and close the simulator
func (s *simulator) Close() error {
var errorStrings []string
Expand Down
6 changes: 3 additions & 3 deletions node/chainSimulator/chainSimulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components/api"
"github.com/multiversx/mx-chain-go/node/chainSimulator/testdata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -59,15 +58,16 @@ func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) {
facade, err := NewChainSimulatorFacade(chainSimulator)
require.Nil(t, err)

initialAccount, err := facade.GetExistingAccountFromBech32AddressString(testdata.GenesisAddressWithStake)
genesisAddressWithStake := chainSimulator.initialWalletKeys.InitialWalletWithStake.Address
initialAccount, err := facade.GetExistingAccountFromBech32AddressString(genesisAddressWithStake)
require.Nil(t, err)

time.Sleep(time.Second)

err = chainSimulator.GenerateBlocks(80)
require.Nil(t, err)

accountAfterRewards, err := facade.GetExistingAccountFromBech32AddressString(testdata.GenesisAddressWithStake)
accountAfterRewards, err := facade.GetExistingAccountFromBech32AddressString(genesisAddressWithStake)
require.Nil(t, err)

assert.True(t, accountAfterRewards.GetBalance().Cmp(initialAccount.GetBalance()) > 0,
Expand Down
86 changes: 10 additions & 76 deletions node/chainSimulator/components/testOnlyProcessingNode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,26 @@ import (
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/endProcess"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components/api"
"github.com/multiversx/mx-chain-go/node/chainSimulator/configs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
pathTestData = "../testdata/"
pathToConfigFolder = "../../../cmd/node/config/"
pathForMainConfig = "../../../cmd/node/config/config.toml"
pathForEconomicsConfig = "../../../cmd/node/config/economics.toml"
pathForGasSchedules = "../../../cmd/node/config/gasSchedules"
nodesSetupConfig = "../../../cmd/node/config/nodesSetup.json"
pathForPrefsConfig = "../../../cmd/node/config/prefs.toml"
validatorPemFile = "../../../cmd/node/config/testKeys/validatorKey.pem"
pathSystemSCConfig = "../../../cmd/node/config/systemSmartContractsConfig.toml"
)

func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNode {
mainConfig := config.Config{}
err := core.LoadTomlFile(&mainConfig, pathForMainConfig)
assert.Nil(t, err)

economicsConfig := config.EconomicsConfig{}
err = core.LoadTomlFile(&economicsConfig, pathForEconomicsConfig)
assert.Nil(t, err)

gasScheduleName, err := configs.GetLatestGasScheduleFilename(pathForGasSchedules)
assert.Nil(t, err)

prefsConfig := config.Preferences{}
err = core.LoadTomlFile(&prefsConfig, pathForPrefsConfig)
assert.Nil(t, err)

systemSCConfig := config.SystemSmartContractsConfig{}
err = core.LoadTomlFile(&systemSCConfig, pathSystemSCConfig)
assert.Nil(t, err)

workingDir := t.TempDir()

epochConfig := config.EpochConfig{}
err = core.LoadTomlFile(&epochConfig, pathToConfigFolder+"enableEpochs.toml")
assert.Nil(t, err)

ratingConfig := config.RatingsConfig{}
err = core.LoadTomlFile(&ratingConfig, pathToConfigFolder+"ratings.toml")
assert.Nil(t, err)

apiConfig := config.ApiRoutesConfig{}
err = core.LoadTomlFile(&apiConfig, pathToConfigFolder+"api.toml")
assert.Nil(t, err)
outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{
NumOfShards: 3,
OriginalConfigsPath: "../../../cmd/node/config/",
GenesisTimeStamp: 0,
RoundDurationInMillis: 6000,
TempDir: t.TempDir(),
})
require.Nil(t, err)

return ArgsTestOnlyProcessingNode{
Configs: config.Configs{
GeneralConfig: &mainConfig,
EpochConfig: &epochConfig,
RoundConfig: &config.RoundConfig{
RoundActivations: map[string]config.ActivationRoundByName{
"DisableAsyncCallV1": {
Round: "18446744073709551614",
},
},
},
EconomicsConfig: &economicsConfig,
PreferencesConfig: &prefsConfig,
ImportDbConfig: &config.ImportDbConfig{},
FlagsConfig: &config.ContextFlagsConfig{
WorkingDir: workingDir,
Version: "1",
},
ConfigurationPathsHolder: &config.ConfigurationPathsHolder{
GasScheduleDirectoryName: pathToConfigFolder + "gasSchedules",
Genesis: pathToConfigFolder + "genesis.json",
SmartContracts: pathTestData + "genesisSmartContracts.json",
Nodes: nodesSetupConfig,
ValidatorKey: validatorPemFile,
},
SystemSCConfig: &systemSCConfig,
RatingsConfig: &ratingConfig,
ApiRoutesConfig: &apiConfig,
},

GasScheduleFilename: gasScheduleName,
Configs: *outputConfigs.Configs,
GasScheduleFilename: outputConfigs.GasScheduleFilename,
NumShards: 3,

SyncedBroadcastNetwork: NewSyncedBroadcastNetwork(),
Expand Down