Skip to content

Commit

Permalink
chore(utils): replace all the unneeded spec usage for `westend-(dev|l…
Browse files Browse the repository at this point in the history
…ocal)` runtime (#3014)

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
  • Loading branch information
EclesioMeloJunior and qdm12 authored Jan 12, 2023
1 parent 841636e commit 07892b1
Show file tree
Hide file tree
Showing 34 changed files with 69 additions and 121 deletions.
2 changes: 1 addition & 1 deletion cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ func TestGlobalNodeName_WhenNodeAlreadyHasStoredName(t *testing.T) {
runtimeData, err := os.ReadFile(runtimeFilePath)
require.NoError(t, err)

fp := utils.GetGssmrGenesisRawPathTest(t)
fp := utils.GetWestendDevRawGenesisPath(t)

gssmrGen, err := genesis.NewGenesisFromJSONRaw(fp)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/import_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func createGenesisWithRuntime(fp string) (string, error) {
return "", err
}

genesisPath, err := utils.GetGssmrGenesisPath()
genesisPath, err := utils.GetGssmrGenesisRawPath()
if err != nil {
return "", fmt.Errorf("cannot find gssmr genesis path: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gossamer/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestInvalidCommand(t *testing.T) {
}

func TestInitCommand_RenameNodeWhenCalled(t *testing.T) {
genesisPath := utils.GetGssmrGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)

tempDir := t.TempDir()

Expand Down Expand Up @@ -268,7 +268,7 @@ func TestBuildSpecCommandWithOutput(t *testing.T) {
buildSpecCommand := runTestGossamer(t,
"build-spec",
"--raw",
"--genesis-spec", utils.GetGssmrGenesisRawPathTest(t),
"--genesis-spec", utils.GetWestendDevRawGenesisPath(t),
"--output", tmpOutputfile)

time.Sleep(5 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/toml_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestLoadConfigGssmr(t *testing.T) {
require.NotNil(t, cfg)

cfg.Global.BasePath = t.TempDir()
cfg.Init.Genesis = utils.GetGssmrGenesisRawPathTest(t)
cfg.Init.Genesis = utils.GetWestendDevRawGenesisPath(t)

err := dot.InitNode(cfg)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions dot/build_spec_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const codeHex = "0x3a636f6465"

func TestWriteGenesisSpecFile_Integration(t *testing.T) {
cfg := NewTestConfig(t)
cfg.Init.Genesis = utils.GetGssmrGenesisRawPathTest(t)
cfg.Init.Genesis = utils.GetWestendDevRawGenesisPath(t)

expected, err := genesis.NewGenesisFromJSONRaw(cfg.Init.Genesis)
require.NoError(t, err)
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestWriteGenesisSpecFile_Integration(t *testing.T) {
func TestBuildFromDB_Integration(t *testing.T) {
// setup expected
cfg := NewTestConfig(t)
cfg.Init.Genesis = utils.GetGssmrGenesisRawPathTest(t)
cfg.Init.Genesis = utils.GetWestendDevRawGenesisPath(t)
expected, err := genesis.NewGenesisFromJSONRaw(cfg.Init.Genesis)
require.NoError(t, err)
// initialise node (initialise state database and load genesis data)
Expand Down
8 changes: 4 additions & 4 deletions dot/build_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestBuildSpec_ToJSON(t *testing.T) {
func TestBuildFromDB(t *testing.T) {
// initialise node (initialise state database and load genesis data)
cfg := NewTestConfig(t)
cfg.Init.Genesis = utils.GetGssmrGenesisRawPathTest(t)
cfg.Init.Genesis = utils.GetWestendDevRawGenesisPath(t)
builder := nodeBuilder{}
err := builder.initNode(cfg)
require.NoError(t, err)
Expand All @@ -136,10 +136,10 @@ func TestBuildFromDB(t *testing.T) {
}{
{name: "normal conditions", path: cfg.Global.BasePath,
want: &BuildSpec{genesis: &genesis.Genesis{
Name: "Gossamer Testnet",
ID: "gssmr_test",
Name: "Development",
ID: "westend_dev",
Bootnodes: []string{},
ProtocolID: "gssmr_test",
ProtocolID: "dot",
Genesis: genesis.Fields{
Raw: map[string]map[string]string{},
Runtime: map[string]map[string]interface{}{},
Expand Down
4 changes: 1 addition & 3 deletions dot/core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) (
func getGssmrRuntimeCode(t *testing.T) (code []byte) {
t.Helper()

path, err := utils.GetGssmrGenesisRawPath()
require.NoError(t, err)

path := utils.GetWestendDevRawGenesisPath(t)
gssmrGenesis, err := genesis.NewGenesisFromJSONRaw(path)
require.NoError(t, err)

Expand Down
6 changes: 2 additions & 4 deletions dot/core/service_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ func TestMaintainTransactionPoolLatestTxnQueue_EmptyBlock(t *testing.T) {
keyring, err := keystore.NewSr25519Keyring()
require.NoError(t, err)
alicePub := common.MustHexToBytes(keyring.Alice().Public().Hex())
genesisFilePath, err := utils.GetGssmrGenesisRawPath()
require.NoError(t, err)
genesisFilePath := utils.GetWestendDevRawGenesisPath(t)

ctrl := gomock.NewController(t)
service, encExt := createTestService(t, genesisFilePath, alicePub, accountInfo, ctrl)
Expand Down Expand Up @@ -411,8 +410,7 @@ func TestMaintainTransactionPoolLatestTxnQueue_BlockWithExtrinsics(t *testing.T)
keyring, err := keystore.NewSr25519Keyring()
require.NoError(t, err)
alicePub := common.MustHexToBytes(keyring.Alice().Public().Hex())
genesisFilePath, err := utils.GetGssmrGenesisRawPath()
require.NoError(t, err)
genesisFilePath := utils.GetWestendDevRawGenesisPath(t)

ctrl := gomock.NewController(t)
service, encodedExtrinsic := createTestService(t, genesisFilePath, alicePub, accountInfo, ctrl)
Expand Down
2 changes: 1 addition & 1 deletion dot/digest/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) (
gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) {
t.Helper()

genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)
genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath)
require.NoError(t, err)
gen = *genesisPtr
Expand Down
2 changes: 1 addition & 1 deletion dot/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) (
gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) {
t.Helper()

genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)
genPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath)
require.NoError(t, err)
gen = *genPtr
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) (
gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) {
t.Helper()

genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)
genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath)
require.NoError(t, err)
gen = *genesisPtr
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/sync_state_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestSyncStateModule(t *testing.T) {
fp := utils.GetGssmrGenesisRawPathTest(t)
fp := utils.GetWestendDevRawGenesisPath(t)

data, err := ioutil.ReadFile(filepath.Clean(fp))
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion dot/state/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) (
gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) {
t.Helper()

genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)
genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath)
require.NoError(t, err)
gen = *genesisPtr
Expand Down
2 changes: 1 addition & 1 deletion dot/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
func NewTestGenesisRawFile(t *testing.T, cfg *Config) (filename string) {
filename = filepath.Join(t.TempDir(), "genesis.json")

fp := utils.GetGssmrGenesisRawPathTest(t)
fp := utils.GetWestendDevRawGenesisPath(t)

gssmrGen, err := genesis.NewGenesisFromJSONRaw(fp)
require.NoError(t, err)
Expand Down
9 changes: 4 additions & 5 deletions dot/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
func newTestGenesisFile(t *testing.T, cfg *Config) (filename string) {
t.Helper()

fp := utils.GetGssmrV3SubstrateGenesisPathTest(t)
gssmrGen, err := genesis.NewGenesisFromJSON(fp, 0)
fp := utils.GetWestendDevRawGenesisPath(t)
gssmrGen, err := genesis.NewGenesisFromJSONRaw(fp)
require.NoError(t, err)

gen := &genesis.Genesis{
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestCreateJSONRawFile(t *testing.T) {
bs: &BuildSpec{genesis: NewTestGenesis(t)},
fp: filepath.Join(t.TempDir(), "/test.json"),
},
expectedHash: "9e61b166bdee6ae5da7f7fe65eb7e3888f715c34cb817575d1fbd268bc3f0d66",
expectedHash: "f7f1b82c0ba16b20e36bfb462d7899af2c76728918f639f5c5ef0e91ff3e7077",
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -235,8 +235,7 @@ func NewTestConfig(t *testing.T) *Config {

// NewTestGenesis returns a test genesis instance using "gssmr" raw data
func NewTestGenesis(t *testing.T) *genesis.Genesis {
fp, err := utils.GetGssmrGenesisRawPath()
require.NoError(t, err)
fp := utils.GetWestendDevRawGenesisPath(t)

gssmrGen, err := genesis.NewGenesisFromJSONRaw(fp)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions lib/babe/epoch_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestService_getLatestEpochData_epochData(t *testing.T) {
require.NoError(t, err)

data := &types.EpochData{
Authorities: auths[:3],
Authorities: auths,
Randomness: [types.RandomnessLength]byte{99, 88, 77},
}
err = epochState.SetEpochData(1, data)
Expand All @@ -205,7 +205,7 @@ func TestService_getLatestEpochData_configData(t *testing.T) {
require.NoError(t, err)

data := &types.EpochData{
Authorities: auths[:3],
Authorities: auths,
Randomness: [types.RandomnessLength]byte{99, 88, 77},
}
err = epochState.SetEpochData(7, data)
Expand Down
2 changes: 1 addition & 1 deletion lib/babe/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) (
gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) {
t.Helper()

genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)
genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath)
require.NoError(t, err)
gen = *genesisPtr
Expand Down
2 changes: 1 addition & 1 deletion lib/grandpa/helpers_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func newTestGenesisWithTrieAndHeader(t *testing.T) (
gen genesis.Genesis, genesisTrie trie.Trie, genesisHeader types.Header) {
t.Helper()

genesisPath := utils.GetGssmrV3SubstrateGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)
genesisPtr, err := genesis.NewGenesisFromJSONRaw(genesisPath)
assert.NoError(t, err)
gen = *genesisPtr
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func TestInstance_ExecuteBlock_NodeRuntime(t *testing.T) {

func TestInstance_ExecuteBlock_GossamerRuntime(t *testing.T) {
t.Skip() // TODO: this fails with "syscall frame is no longer valid" (#1026)
genesisPath := utils.GetGssmrGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)
gen := genesisFromRawJSON(t, genesisPath)
genTrie, err := NewTrieFromGenesis(gen)
require.NoError(t, err)
Expand Down Expand Up @@ -556,7 +556,7 @@ func TestInstance_ExecuteBlock_GossamerRuntime(t *testing.T) {

func TestInstance_ApplyExtrinsic_GossamerRuntime(t *testing.T) {
t.Skip() // TODO: this fails with "syscall frame is no longer valid" (#1026)
genesisPath := utils.GetGssmrGenesisRawPathTest(t)
genesisPath := utils.GetWestendDevRawGenesisPath(t)
gen := genesisFromRawJSON(t, genesisPath)
genTrie, err := NewTrieFromGenesis(gen)
require.NoError(t, err)
Expand Down
70 changes: 11 additions & 59 deletions lib/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,41 +148,14 @@ func KeystoreFilepaths(basepath string) ([]string, error) {
return keys, nil
}

// GetGssmrGenesisRawPathTest gets the gssmr raw genesis path
// and fails the test if it cannot find it.
func GetGssmrGenesisRawPathTest(t *testing.T) string {
t.Helper()
path, err := GetGssmrGenesisRawPath()
require.NoError(t, err)
return path
}

// GetGssmrGenesisRawPath gets the gssmr raw genesis path
// and returns an error if it cannot find it.
func GetGssmrGenesisRawPath() (path string, err error) {
rootPath, err := GetProjectRootPath()
if err != nil {
return "", err
}
return filepath.Join(rootPath, "./chain/gssmr/genesis.json"), nil
}

// GetGssmrGenesisPathTest gets the gssmr genesis path
// and fails the test if it cannot find it.
func GetGssmrGenesisPathTest(t *testing.T) string {
t.Helper()
path, err := GetGssmrGenesisPath()
require.NoError(t, err)
return path
}

// GetGssmrV3SubstrateGenesisPathTest gets the v3 substrate gssmr genesis path
// and fails the test if it cannot find it.
func GetGssmrV3SubstrateGenesisPathTest(t *testing.T) string {
t.Helper()
path, err := GetGssmrV3SubstrateGenesisPath()
require.NoError(t, err)
return path
return filepath.Join(rootPath, "./chain/gssmr/genesis-spec.json"), nil
}

// GetGssmrV3SubstrateGenesisRawPathTest gets the v3 substrate gssmr raw genesis path
Expand All @@ -204,53 +177,32 @@ func GetGssmrV3SubstrateGenesisRawPath() (path string, err error) {
return filepath.Join(rootPath, "./chain/gssmr-v3substrate/genesis.json"), nil
}

// GetDevGenesisPath gets the dev genesis path
func GetDevGenesisPath(t *testing.T) string {
return filepath.Join(GetProjectRootPathTest(t), "./chain/dev/genesis.json")
}

// GetDevV3SubstrateGenesisPath gets the v3 substrate dev genesis path
func GetDevV3SubstrateGenesisPath(t *testing.T) string {
return filepath.Join(GetProjectRootPathTest(t), "./chain/dev-v3substrate/genesis.json")
}

// GetDevGenesisSpecPathTest gets the dev genesis spec path
func GetDevGenesisSpecPathTest(t *testing.T) string {
return filepath.Join(GetProjectRootPathTest(t), "./chain/dev/genesis-spec.json")
}

// GetGssmrGenesisPath gets the gssmr genesis path
// and returns an error if it cannot find it.
func GetGssmrGenesisPath() (path string, err error) {
rootPath, err := GetProjectRootPath()
if err != nil {
return "", err
}
return filepath.Join(rootPath, "./chain/gssmr/genesis-spec.json"), nil
}

// GetGssmrV3SubstrateGenesisPath gets the v3 substrate gssmr genesis path
// and returns an error if it cannot find it.
func GetGssmrV3SubstrateGenesisPath() (path string, err error) {
rootPath, err := GetProjectRootPath()
if err != nil {
return "", err
}
return filepath.Join(rootPath, "./chain/gssmr-v3substrate/genesis-spec.json"), nil
// GetWestendDevRawGenesisPath gets the westend-dev genesis raw path
func GetWestendDevRawGenesisPath(t *testing.T) string {
t.Helper()
return filepath.Join(GetProjectRootPathTest(t), "./chain/westend-dev/westend-dev-spec-raw.json")
}

// GetWestendDevGenesisPath gets the westend-dev genesis path
func GetWestendDevGenesisPath(t *testing.T) string {
return filepath.Join(GetProjectRootPathTest(t), "./chain/westend-dev/westend-dev-spec-raw.json")
// GetWestendLocalRawGenesisPath gets the westend-local genesis raw path
func GetWestendLocalRawGenesisPath(t *testing.T) string {
t.Helper()
return filepath.Join(GetProjectRootPathTest(t), "./chain/westend-local/westend-local-spec-raw.json")
}

// GetKusamaGenesisPath gets the Kusama genesis path
func GetKusamaGenesisPath(t *testing.T) string {
t.Helper()
return filepath.Join(GetProjectRootPathTest(t), "./chain/kusama/genesis.json")
}

// GetPolkadotGenesisPath gets the Polkadot genesis path
func GetPolkadotGenesisPath(t *testing.T) string {
t.Helper()
return filepath.Join(GetProjectRootPathTest(t), "./chain/polkadot/genesis.json")
}

Expand Down
2 changes: 1 addition & 1 deletion tests/rpc/rpc_01-system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestSystemRPC(t *testing.T) { //nolint:tparallel

const numberOfNodes = 3

genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
genesisPath := libutils.GetWestendLocalRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
nodes := node.MakeNodes(t, numberOfNodes, tomlConfig)
Expand Down
4 changes: 2 additions & 2 deletions tests/rpc/rpc_02-author_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// TODO: add test against latest dev runtime
// See https://github.com/ChainSafe/gossamer/issues/2705
func TestAuthorSubmitExtrinsic(t *testing.T) {
genesisPath := libutils.GetWestendDevGenesisPath(t)
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Account.Key = "alice"
tomlConfig.Init.Genesis = genesisPath
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestAuthorSubmitExtrinsic(t *testing.T) {
}

func TestAuthorRPC(t *testing.T) { //nolint:tparallel
genesisPath := libutils.GetGssmrGenesisRawPathTest(t)
genesisPath := libutils.GetWestendDevRawGenesisPath(t)
tomlConfig := config.Default()
tomlConfig.Init.Genesis = genesisPath
tomlConfig.Core.BABELead = true
Expand Down
Loading

0 comments on commit 07892b1

Please sign in to comment.