diff --git a/chain/resources.go b/chain/resources.go new file mode 100644 index 0000000000..94bc434580 --- /dev/null +++ b/chain/resources.go @@ -0,0 +1,10 @@ +// Copyright 2023 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only +package chain + +import "embed" + +// DefaultConfigTomlFiles is the embedded file system containing the default toml configurations. +// +//go:embed */*.toml +var DefaultConfigTomlFiles embed.FS diff --git a/cmd/gossamer/config.go b/cmd/gossamer/config.go index 59af93aaf7..01009ce741 100644 --- a/cmd/gossamer/config.go +++ b/cmd/gossamer/config.go @@ -26,10 +26,10 @@ import ( var ( // DefaultCfg is the default configuration for the node. DefaultCfg = dot.PolkadotConfig - defaultKusamaConfigPath = "./chain/kusama/config.toml" - defaultPolkadotConfigPath = "./chain/polkadot/config.toml" - defaultWestendDevConfigPath = "./chain/westend-dev/config.toml" - defaultWestendConfigPath = "./chain/westend/config.toml" + defaultKusamaConfigPath = "kusama/config.toml" + defaultPolkadotConfigPath = "polkadot/config.toml" + defaultWestendDevConfigPath = "westend-dev/config.toml" + defaultWestendConfigPath = "westend/config.toml" ) // loadConfigFile loads a default config file if --chain is specified, a specific @@ -37,7 +37,7 @@ var ( func loadConfigFile(ctx *cli.Context, cfg *ctoml.Config) (err error) { cfgPath := ctx.String(ConfigFlag.Name) if cfgPath == "" { - return loadConfig(cfg, defaultPolkadotConfigPath) + return loadConfigFromResource(cfg, defaultPolkadotConfigPath) } logger.Info("loading toml configuration from " + cfgPath + "...") @@ -48,7 +48,7 @@ func loadConfigFile(ctx *cli.Context, cfg *ctoml.Config) (err error) { "overwriting default configuration with id " + cfg.Global.ID + " with toml configuration values from " + cfgPath) } - return loadConfig(cfg, cfgPath) + return loadConfigFromFile(cfg, cfgPath) } func setupConfigFromChain(ctx *cli.Context) (*ctoml.Config, *dot.Config, error) { @@ -68,22 +68,22 @@ func setupConfigFromChain(ctx *cli.Context) (*ctoml.Config, *dot.Config, error) logger.Info("loading toml configuration from " + defaultKusamaConfigPath + "...") tomlCfg = &ctoml.Config{} cfg = dot.KusamaConfig() - err = loadConfig(tomlCfg, defaultKusamaConfigPath) + err = loadConfigFromResource(tomlCfg, defaultKusamaConfigPath) case "polkadot": logger.Info("loading toml configuration from " + defaultPolkadotConfigPath + "...") tomlCfg = &ctoml.Config{} cfg = dot.PolkadotConfig() - err = loadConfig(tomlCfg, defaultPolkadotConfigPath) + err = loadConfigFromResource(tomlCfg, defaultPolkadotConfigPath) case "westend-dev": logger.Info("loading toml configuration from " + defaultWestendDevConfigPath + "...") tomlCfg = &ctoml.Config{} cfg = dot.WestendDevConfig() - err = loadConfig(tomlCfg, defaultWestendDevConfigPath) + err = loadConfigFromResource(tomlCfg, defaultWestendDevConfigPath) case "westend": logger.Info("loading toml configuration from " + defaultWestendConfigPath + "...") tomlCfg = &ctoml.Config{} cfg = dot.WestendConfig() - err = loadConfig(tomlCfg, defaultWestendConfigPath) + err = loadConfigFromResource(tomlCfg, defaultWestendConfigPath) default: logger.Info("loading chain config from " + id + "...") fileInfo, err := os.Stat(id) diff --git a/cmd/gossamer/config_test.go b/cmd/gossamer/config_test.go index f3fd944716..b69f482045 100644 --- a/cmd/gossamer/config_test.go +++ b/cmd/gossamer/config_test.go @@ -845,7 +845,7 @@ func TestGlobalNodeName_WhenNodeAlreadyHasStoredName(t *testing.T) { cfg := newTestConfig(t, westendDevConfig) cfg.Global.Name = globalName - runtimeFilePath, err := runtime.GetRuntime(context.Background(), runtime.NODE_RUNTIME) + runtimeFilePath, err := runtime.GetRuntime(context.Background(), runtime.WESTEND_RUNTIME_v0929) require.NoError(t, err) runtimeData, err := os.ReadFile(runtimeFilePath) require.NoError(t, err) diff --git a/cmd/gossamer/export_test.go b/cmd/gossamer/export_test.go index d713ffc465..117ce0a06c 100644 --- a/cmd/gossamer/export_test.go +++ b/cmd/gossamer/export_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/ChainSafe/gossamer/dot" - ctoml "github.com/ChainSafe/gossamer/dot/config/toml" "github.com/ChainSafe/gossamer/internal/log" "github.com/stretchr/testify/require" @@ -165,7 +164,7 @@ func TestExportCommand(t *testing.T) { config := ctx.String(ConfigFlag.Name) cfg := new(ctoml.Config) - err = loadConfig(cfg, config) + err = loadConfigFromFile(cfg, config) require.NoError(t, err) require.Equal(t, dotConfigToToml(c.expected), cfg) diff --git a/cmd/gossamer/main_test.go b/cmd/gossamer/main_test.go index 72a5115035..161d06a2f0 100644 --- a/cmd/gossamer/main_test.go +++ b/cmd/gossamer/main_test.go @@ -192,6 +192,8 @@ func runTestGossamer(t *testing.T, args ...string) *testgossamer { return tt } +var testWestendDevConfigPath string + func TestMain(m *testing.M) { if reexec.Init() { return @@ -202,10 +204,7 @@ func TestMain(m *testing.M) { panic(err) } - defaultKusamaConfigPath = filepath.Join(rootPath, "./chain/kusama/config.toml") - defaultPolkadotConfigPath = filepath.Join(rootPath, "./chain/polkadot/config.toml") - defaultWestendDevConfigPath = filepath.Join(rootPath, "./chain/westend-dev/config.toml") - + testWestendDevConfigPath = filepath.Join(rootPath, "./chain/westend-dev/config.toml") os.Exit(m.Run()) } @@ -234,7 +233,7 @@ func TestInitCommand_RenameNodeWhenCalled(t *testing.T) { "--basepath", tempDir, "--genesis", genesisPath, "--name", nodeName, - "--config", defaultWestendDevConfigPath, + "--config", testWestendDevConfigPath, "--force", ) @@ -249,7 +248,7 @@ func TestInitCommand_RenameNodeWhenCalled(t *testing.T) { "init", "--basepath", tempDir, "--genesis", genesisPath, - "--config", defaultWestendDevConfigPath, + "--config", testWestendDevConfigPath, "--force", ) diff --git a/cmd/gossamer/toml_config.go b/cmd/gossamer/toml_config.go index e683a80640..eb719f8f5d 100644 --- a/cmd/gossamer/toml_config.go +++ b/cmd/gossamer/toml_config.go @@ -11,25 +11,35 @@ import ( "reflect" "unicode" - "github.com/naoina/toml" - + "github.com/ChainSafe/gossamer/chain" ctoml "github.com/ChainSafe/gossamer/dot/config/toml" + "github.com/naoina/toml" ) -// loadConfig loads the values from the toml configuration file into the provided configuration -func loadConfig(cfg *ctoml.Config, fp string) error { +func loadConfigFromResource(cfg *ctoml.Config, resourcePath string) error { + file, err := chain.DefaultConfigTomlFiles.Open(resourcePath) + if err != nil { + return fmt.Errorf("opening toml configuration file: %w", err) + } + return loadConfig(cfg, file) +} + +func loadConfigFromFile(cfg *ctoml.Config, fp string) error { fp, err := filepath.Abs(fp) if err != nil { logger.Errorf("failed to create absolute path for toml configuration file: %s", err) return err } - file, err := os.Open(filepath.Clean(fp)) if err != nil { logger.Errorf("failed to open toml configuration file: %s", err) return err } + return loadConfig(cfg, file) +} +// loadConfig loads the values from the toml configuration file into the provided configuration +func loadConfig(cfg *ctoml.Config, file fs.File) (err error) { var tomlSettings = toml.Config{ NormFieldName: func(rt reflect.Type, key string) string { return key diff --git a/cmd/gossamer/toml_config_test.go b/cmd/gossamer/toml_config_test.go index 77bc7233c7..2081c45456 100644 --- a/cmd/gossamer/toml_config_test.go +++ b/cmd/gossamer/toml_config_test.go @@ -25,7 +25,7 @@ func TestLoadConfig(t *testing.T) { err := dot.InitNode(cfg) require.NoError(t, err) - err = loadConfig(dotConfigToToml(cfg), cfgFile) + err = loadConfigFromFile(dotConfigToToml(cfg), cfgFile) require.NoError(t, err) } @@ -43,7 +43,7 @@ func TestLoadConfigWestendDev(t *testing.T) { projectRootPath := utils.GetProjectRootPathTest(t) configPath := filepath.Join(projectRootPath, "./chain/westend-dev/config.toml") - err = loadConfig(dotConfigToToml(cfg), configPath) + err = loadConfigFromFile(dotConfigToToml(cfg), configPath) require.NoError(t, err) } @@ -60,6 +60,6 @@ func TestLoadConfigKusama(t *testing.T) { projectRootPath := utils.GetProjectRootPathTest(t) kusamaConfigPath := filepath.Join(projectRootPath, "./chain/kusama/config.toml") - err = loadConfig(dotConfigToToml(cfg), kusamaConfigPath) + err = loadConfigFromFile(dotConfigToToml(cfg), kusamaConfigPath) require.NoError(t, err) } diff --git a/dot/core/service_integration_test.go b/dot/core/service_integration_test.go index a1dbb6e743..56a0a8f14a 100644 --- a/dot/core/service_integration_test.go +++ b/dot/core/service_integration_test.go @@ -288,7 +288,7 @@ func TestHandleChainReorg_WithReorg_Transactions(t *testing.T) { t.Skip() // need to update this test to use a valid transaction cfg := &Config{ - Runtime: wasmer.NewTestInstance(t, runtime.NODE_RUNTIME), + Runtime: wasmer.NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929), } s := NewTestService(t, cfg) diff --git a/dot/node_integration_test.go b/dot/node_integration_test.go index e5cb2b3ae7..3afd95f0c9 100644 --- a/dot/node_integration_test.go +++ b/dot/node_integration_test.go @@ -458,7 +458,7 @@ func TestNode_PersistGlobalName_WhenInitialize(t *testing.T) { // newTestGenesisAndRuntime create a new test runtime and a new test genesis // file with the test runtime stored in raw data and returns the genesis file func newTestGenesisAndRuntime(t *testing.T) (filename string) { - runtimeFilePath, err := runtime.GetRuntime(context.Background(), runtime.NODE_RUNTIME) + runtimeFilePath, err := runtime.GetRuntime(context.Background(), runtime.WESTEND_RUNTIME_v0929) require.NoError(t, err) runtimeData, err := os.ReadFile(runtimeFilePath) require.NoError(t, err) diff --git a/dot/rpc/modules/dev_integration_test.go b/dot/rpc/modules/dev_integration_test.go index 42083e1a07..b8d365a3e8 100644 --- a/dot/rpc/modules/dev_integration_test.go +++ b/dot/rpc/modules/dev_integration_test.go @@ -57,7 +57,7 @@ func newBABEService(t *testing.T) *babe.Service { bs, es := newState(t) tt := trie.NewEmptyTrie() - rt := wasmer.NewTestInstanceWithTrie(t, runtime.NODE_RUNTIME, tt) + rt := wasmer.NewTestInstanceWithTrie(t, runtime.WESTEND_RUNTIME_v0929, tt) bs.StoreRuntime(bs.GenesisHash(), rt) tt.Put( common.MustHexToBytes("0x886726f904d8372fdabb7707870c2fad"), diff --git a/dot/rpc/modules/state_integration_test.go b/dot/rpc/modules/state_integration_test.go index 2cf8383310..7b7c2e5455 100644 --- a/dot/rpc/modules/state_integration_test.go +++ b/dot/rpc/modules/state_integration_test.go @@ -28,29 +28,35 @@ const ( ) func TestStateModule_GetRuntimeVersion(t *testing.T) { - // expected results based on responses from prior tests + /* expected results based on responses from prior tests + We can get this data from polkadot runtime release source code + https://github.com/paritytech/polkadot/blob/v0.9.29/runtime/westend/src/lib.rs#L105-L117 + */ expected := StateRuntimeVersionResponse{ - SpecName: "node", - ImplName: "substrate-node", - AuthoringVersion: 10, - SpecVersion: 264, + SpecName: "westend", + ImplName: "parity-westend", + AuthoringVersion: 2, + SpecVersion: 9290, ImplVersion: 0, Apis: []interface{}{ - []interface{}{"0xdf6acb689907609b", uint32(3)}, + []interface{}{"0xdf6acb689907609b", uint32(4)}, []interface{}{"0x37e397fc7c91f5e4", uint32(1)}, - []interface{}{"0x40fe3ad401f8959a", uint32(4)}, - []interface{}{"0xd2bc9897eed08f15", uint32(2)}, + []interface{}{"0x40fe3ad401f8959a", uint32(6)}, + []interface{}{"0xd2bc9897eed08f15", uint32(3)}, []interface{}{"0xf78b278be53f454c", uint32(2)}, - []interface{}{"0xed99c5acb25eedf5", uint32(2)}, + []interface{}{"0xaf2c0297a23e6d3d", uint32(2)}, + []interface{}{"0x49eaaf1b548a0cb0", uint32(1)}, + []interface{}{"0x91d5df18b0d2cf58", uint32(1)}, + []interface{}{"0xed99c5acb25eedf5", uint32(3)}, []interface{}{"0xcbca25e39f142387", uint32(2)}, []interface{}{"0x687ad44ad37f03c2", uint32(1)}, + []interface{}{"0xab3c0572291feb8b", uint32(1)}, []interface{}{"0xbc9d89904f5b923f", uint32(1)}, - []interface{}{"0x68b66ba122c93fa7", uint32(1)}, []interface{}{"0x37c8bb1350a9a2a8", uint32(1)}, - []interface{}{"0x91d5df18b0d2cf58", uint32(1)}, - []interface{}{"0xab3c0572291feb8b", uint32(1)}, + []interface{}{"0xf3ff14d5ab527059", uint32(1)}, + []interface{}{"0x17a6bc0d0062aeb3", uint32(1)}, }, - TransactionVersion: 2, + TransactionVersion: 12, } sm, hash, _ := setupStateModule(t) diff --git a/dot/rpc/modules/system_integration_test.go b/dot/rpc/modules/system_integration_test.go index 3f2be61d69..aab4313fb3 100644 --- a/dot/rpc/modules/system_integration_test.go +++ b/dot/rpc/modules/system_integration_test.go @@ -354,7 +354,7 @@ func setupSystemModule(t *testing.T) *SystemModule { func newCoreService(t *testing.T, srvc *state.Service) *core.Service { // setup service tt := trie.NewEmptyTrie() - rt := wasmer.NewTestInstanceWithTrie(t, runtime.NODE_RUNTIME, tt) + rt := wasmer.NewTestInstanceWithTrie(t, runtime.WESTEND_RUNTIME_v0929, tt) ks := keystore.NewGlobalKeystore() t.Cleanup(func() { rt.Stop() diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 242b017295..c4ea384d3c 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -5,16 +5,6 @@ package runtime //nolint:revive const ( - // v0.9 substrate runtime - NODE_RUNTIME = "node_runtime" - NODE_RUNTIME_FP = "node_runtime.compact.wasm" - NODE_RUNTIME_URL = "https://github.com/noot/substrate/blob/noot/v0.9/target/debug/wbuild/node-runtime/node_runtime.compact.wasm?raw=true" //nolint:lll - - // v0.9.8 substrate runtime - NODE_RUNTIME_v098 = "node_runtime-v0.9.8" - NODE_RUNTIME_FP_v098 = "node_runtime-v0.9.8.compact.wasm" - NODE_RUNTIME_URL_v098 = "https://github.com/noot/substrate/blob/noot/v0.9.8/target/debug/wbuild/node-runtime/node_runtime.compact.wasm?raw=true" //nolint:lll - // v0.9 test API wasm HOST_API_TEST_RUNTIME = "hostapi_runtime" HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" diff --git a/lib/runtime/test_helpers.go b/lib/runtime/test_helpers.go index c44baf30e7..7ece8ea0d4 100644 --- a/lib/runtime/test_helpers.go +++ b/lib/runtime/test_helpers.go @@ -74,12 +74,6 @@ func GetRuntime(ctx context.Context, runtime string) ( var runtimeFilename, url string switch runtime { - case NODE_RUNTIME: - runtimeFilename = NODE_RUNTIME_FP - url = NODE_RUNTIME_URL - case NODE_RUNTIME_v098: - runtimeFilename = NODE_RUNTIME_FP_v098 - url = NODE_RUNTIME_URL_v098 case HOST_API_TEST_RUNTIME: runtimeFilename = HOST_API_TEST_RUNTIME_FP url = HOST_API_TEST_RUNTIME_URL diff --git a/lib/runtime/wasmer/exports_test.go b/lib/runtime/wasmer/exports_test.go index 3c16218a81..ab4bda60b8 100644 --- a/lib/runtime/wasmer/exports_test.go +++ b/lib/runtime/wasmer/exports_test.go @@ -43,62 +43,6 @@ func Test_Instance_Version(t *testing.T) { instanceBuilder func(t *testing.T) instanceVersioner expectedVersion runtime.Version }{ - "node_v098": { - instanceBuilder: func(t *testing.T) instanceVersioner { - return NewTestInstance(t, runtime.NODE_RUNTIME_v098) - }, - expectedVersion: runtime.Version{ - SpecName: []byte("node"), - ImplName: []byte("substrate-node"), - AuthoringVersion: 10, - SpecVersion: 267, - ImplVersion: 0, - APIItems: []runtime.APIItem{ - {Name: [8]uint8{0xdf, 0x6a, 0xcb, 0x68, 0x99, 0x7, 0x60, 0x9b}, Ver: 0x3}, - {Name: [8]uint8{0x37, 0xe3, 0x97, 0xfc, 0x7c, 0x91, 0xf5, 0xe4}, Ver: 0x1}, - {Name: [8]uint8{0x40, 0xfe, 0x3a, 0xd4, 0x1, 0xf8, 0x95, 0x9a}, Ver: 0x5}, - {Name: [8]uint8{0xd2, 0xbc, 0x98, 0x97, 0xee, 0xd0, 0x8f, 0x15}, Ver: 0x2}, - {Name: [8]uint8{0xf7, 0x8b, 0x27, 0x8b, 0xe5, 0x3f, 0x45, 0x4c}, Ver: 0x2}, - {Name: [8]uint8{0xed, 0x99, 0xc5, 0xac, 0xb2, 0x5e, 0xed, 0xf5}, Ver: 0x2}, - {Name: [8]uint8{0xcb, 0xca, 0x25, 0xe3, 0x9f, 0x14, 0x23, 0x87}, Ver: 0x2}, - {Name: [8]uint8{0x68, 0x7a, 0xd4, 0x4a, 0xd3, 0x7f, 0x3, 0xc2}, Ver: 0x1}, - {Name: [8]uint8{0xbc, 0x9d, 0x89, 0x90, 0x4f, 0x5b, 0x92, 0x3f}, Ver: 0x1}, - {Name: [8]uint8{0x68, 0xb6, 0x6b, 0xa1, 0x22, 0xc9, 0x3f, 0xa7}, Ver: 0x1}, - {Name: [8]uint8{0x37, 0xc8, 0xbb, 0x13, 0x50, 0xa9, 0xa2, 0xa8}, Ver: 0x1}, - {Name: [8]uint8{0x91, 0xd5, 0xdf, 0x18, 0xb0, 0xd2, 0xcf, 0x58}, Ver: 0x1}, - {Name: [8]uint8{0xab, 0x3c, 0x5, 0x72, 0x29, 0x1f, 0xeb, 0x8b}, Ver: 0x1}, - }, - TransactionVersion: 2, - }, - }, - "node": { - instanceBuilder: func(t *testing.T) instanceVersioner { - return NewTestInstance(t, runtime.NODE_RUNTIME) - }, - expectedVersion: runtime.Version{ - SpecName: []byte("node"), - ImplName: []byte("substrate-node"), - AuthoringVersion: 10, - SpecVersion: 264, - ImplVersion: 0, - APIItems: []runtime.APIItem{ - {Name: [8]uint8{0xdf, 0x6a, 0xcb, 0x68, 0x99, 0x7, 0x60, 0x9b}, Ver: 0x3}, - {Name: [8]uint8{0x37, 0xe3, 0x97, 0xfc, 0x7c, 0x91, 0xf5, 0xe4}, Ver: 0x1}, - {Name: [8]uint8{0x40, 0xfe, 0x3a, 0xd4, 0x1, 0xf8, 0x95, 0x9a}, Ver: 0x4}, - {Name: [8]uint8{0xd2, 0xbc, 0x98, 0x97, 0xee, 0xd0, 0x8f, 0x15}, Ver: 0x2}, - {Name: [8]uint8{0xf7, 0x8b, 0x27, 0x8b, 0xe5, 0x3f, 0x45, 0x4c}, Ver: 0x2}, - {Name: [8]uint8{0xed, 0x99, 0xc5, 0xac, 0xb2, 0x5e, 0xed, 0xf5}, Ver: 0x2}, - {Name: [8]uint8{0xcb, 0xca, 0x25, 0xe3, 0x9f, 0x14, 0x23, 0x87}, Ver: 0x2}, - {Name: [8]uint8{0x68, 0x7a, 0xd4, 0x4a, 0xd3, 0x7f, 0x3, 0xc2}, Ver: 0x1}, - {Name: [8]uint8{0xbc, 0x9d, 0x89, 0x90, 0x4f, 0x5b, 0x92, 0x3f}, Ver: 0x1}, - {Name: [8]uint8{0x68, 0xb6, 0x6b, 0xa1, 0x22, 0xc9, 0x3f, 0xa7}, Ver: 0x1}, - {Name: [8]uint8{0x37, 0xc8, 0xbb, 0x13, 0x50, 0xa9, 0xa2, 0xa8}, Ver: 0x1}, - {Name: [8]uint8{0x91, 0xd5, 0xdf, 0x18, 0xb0, 0xd2, 0xcf, 0x58}, Ver: 0x1}, - {Name: [8]uint8{0xab, 0x3c, 0x5, 0x72, 0x29, 0x1f, 0xeb, 0x8b}, Ver: 0x1}, - }, - TransactionVersion: 2, - }, - }, "kusama": { instanceBuilder: func(t *testing.T) instanceVersioner { genesisPath := utils.GetKusamaGenesisPath(t) @@ -168,32 +112,35 @@ func Test_Instance_Version(t *testing.T) { TransactionVersion: 14, }, }, - "runtime_v0980": { + "westend_v0929": { instanceBuilder: func(t *testing.T) instanceVersioner { - return NewTestInstance(t, runtime.NODE_RUNTIME_v098) + return NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929) }, expectedVersion: runtime.Version{ - SpecName: []byte("node"), - ImplName: []byte("substrate-node"), - AuthoringVersion: 10, - SpecVersion: 267, + SpecName: []byte("westend"), + ImplName: []byte("parity-westend"), + AuthoringVersion: 2, + SpecVersion: 9290, ImplVersion: 0, APIItems: []runtime.APIItem{ - {Name: [8]uint8{0xdf, 0x6a, 0xcb, 0x68, 0x99, 0x7, 0x60, 0x9b}, Ver: 0x3}, + {Name: [8]uint8{0xdf, 0x6a, 0xcb, 0x68, 0x99, 0x7, 0x60, 0x9b}, Ver: 0x4}, {Name: [8]uint8{0x37, 0xe3, 0x97, 0xfc, 0x7c, 0x91, 0xf5, 0xe4}, Ver: 0x1}, - {Name: [8]uint8{0x40, 0xfe, 0x3a, 0xd4, 0x1, 0xf8, 0x95, 0x9a}, Ver: 0x5}, - {Name: [8]uint8{0xd2, 0xbc, 0x98, 0x97, 0xee, 0xd0, 0x8f, 0x15}, Ver: 0x2}, + {Name: [8]uint8{0x40, 0xfe, 0x3a, 0xd4, 0x1, 0xf8, 0x95, 0x9a}, Ver: 0x6}, + {Name: [8]uint8{0xd2, 0xbc, 0x98, 0x97, 0xee, 0xd0, 0x8f, 0x15}, Ver: 0x3}, {Name: [8]uint8{0xf7, 0x8b, 0x27, 0x8b, 0xe5, 0x3f, 0x45, 0x4c}, Ver: 0x2}, - {Name: [8]uint8{0xed, 0x99, 0xc5, 0xac, 0xb2, 0x5e, 0xed, 0xf5}, Ver: 0x2}, + {Name: [8]uint8{0xaf, 0x2c, 0x2, 0x97, 0xa2, 0x3e, 0x6d, 0x3d}, Ver: 0x2}, + {Name: [8]uint8{0x49, 0xea, 0xaf, 0x1b, 0x54, 0x8a, 0xc, 0xb0}, Ver: 0x1}, + {Name: [8]uint8{0x91, 0xd5, 0xdf, 0x18, 0xb0, 0xd2, 0xcf, 0x58}, Ver: 0x1}, + {Name: [8]uint8{0xed, 0x99, 0xc5, 0xac, 0xb2, 0x5e, 0xed, 0xf5}, Ver: 0x3}, {Name: [8]uint8{0xcb, 0xca, 0x25, 0xe3, 0x9f, 0x14, 0x23, 0x87}, Ver: 0x2}, {Name: [8]uint8{0x68, 0x7a, 0xd4, 0x4a, 0xd3, 0x7f, 0x3, 0xc2}, Ver: 0x1}, + {Name: [8]uint8{0xab, 0x3c, 0x5, 0x72, 0x29, 0x1f, 0xeb, 0x8b}, Ver: 0x1}, {Name: [8]uint8{0xbc, 0x9d, 0x89, 0x90, 0x4f, 0x5b, 0x92, 0x3f}, Ver: 0x1}, - {Name: [8]uint8{0x68, 0xb6, 0x6b, 0xa1, 0x22, 0xc9, 0x3f, 0xa7}, Ver: 0x1}, {Name: [8]uint8{0x37, 0xc8, 0xbb, 0x13, 0x50, 0xa9, 0xa2, 0xa8}, Ver: 0x1}, - {Name: [8]uint8{0x91, 0xd5, 0xdf, 0x18, 0xb0, 0xd2, 0xcf, 0x58}, Ver: 0x1}, - {Name: [8]uint8{0xab, 0x3c, 0x5, 0x72, 0x29, 0x1f, 0xeb, 0x8b}, Ver: 0x1}, + {Name: [8]uint8{0xf3, 0xff, 0x14, 0xd5, 0xab, 0x52, 0x70, 0x59}, Ver: 0x1}, + {Name: [8]uint8{0x17, 0xa6, 0xbc, 0xd, 0x0, 0x62, 0xae, 0xb3}, Ver: 0x1}, }, - TransactionVersion: 2, + TransactionVersion: 12, }, }, } @@ -292,7 +239,7 @@ func TestInstance_GrandpaAuthorities_NodeRuntime(t *testing.T) { key := common.MustHexToBytes(genesis.GrandpaAuthoritiesKeyHex) tt.Put(key, value) - rt := NewTestInstanceWithTrie(t, runtime.NODE_RUNTIME, tt) + rt := NewTestInstanceWithTrie(t, runtime.WESTEND_RUNTIME_v0929, tt) auths, err := rt.GrandpaAuthorities() require.NoError(t, err) @@ -428,23 +375,6 @@ func TestInstance_BabeSubmitReportEquivocationUnsignedExtrinsic(t *testing.T) { } } -func TestInstance_BabeConfiguration_NodeRuntime_NoAuthorities(t *testing.T) { - rt := NewTestInstance(t, runtime.NODE_RUNTIME) - cfg, err := rt.BabeConfiguration() - require.NoError(t, err) - - expected := &types.BabeConfiguration{ - SlotDuration: 3000, - EpochLength: 200, - C1: 1, - C2: 2, - GenesisAuthorities: nil, - Randomness: [32]byte{}, - SecondarySlots: 1, - } - require.Equal(t, expected, cfg) -} - func TestInstance_BabeConfiguration_WestendRuntime_NoAuthorities(t *testing.T) { rt := NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929) cfg, err := rt.BabeConfiguration() @@ -459,11 +389,10 @@ func TestInstance_BabeConfiguration_WestendRuntime_NoAuthorities(t *testing.T) { Randomness: [32]byte{}, SecondarySlots: 2, } - require.Equal(t, expected, cfg) } -func TestInstance_BabeConfiguration_NodeRuntime_WithAuthorities(t *testing.T) { +func TestInstance_BabeConfiguration_WestendRuntime_WithAuthorities(t *testing.T) { tt := trie.NewEmptyTrie() randomnessValue, err := common.HexToHash("0x01") @@ -477,7 +406,7 @@ func TestInstance_BabeConfiguration_NodeRuntime_WithAuthorities(t *testing.T) { key = common.MustHexToBytes(genesis.BABEAuthoritiesKeyHex) tt.Put(key, authorityValue) - rt := NewTestInstanceWithTrie(t, runtime.NODE_RUNTIME, tt) + rt := NewTestInstanceWithTrie(t, runtime.WESTEND_RUNTIME_v0929, tt) cfg, err := rt.BabeConfiguration() require.NoError(t, err) @@ -491,20 +420,20 @@ func TestInstance_BabeConfiguration_NodeRuntime_WithAuthorities(t *testing.T) { } expected := &types.BabeConfiguration{ - SlotDuration: 3000, - EpochLength: 200, + SlotDuration: 6000, + EpochLength: 600, C1: 1, - C2: 2, + C2: 4, GenesisAuthorities: expectedAuthData, Randomness: [32]byte{1}, - SecondarySlots: 1, + SecondarySlots: 2, } require.Equal(t, expected, cfg) } func TestInstance_InitializeBlock_NodeRuntime(t *testing.T) { - rt := NewTestInstance(t, runtime.NODE_RUNTIME) + rt := NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929) header := &types.Header{ Number: 1, @@ -971,14 +900,14 @@ func TestInstance_ExecuteBlock_PolkadotBlock1089328(t *testing.T) { } func TestInstance_DecodeSessionKeys(t *testing.T) { - keys := "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d34309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc38520426026" //nolint:lll + keys := "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d34309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc38520426026" //nolint:lll pubkeys, err := common.HexToBytes(keys) require.NoError(t, err) pukeysBytes, err := scale.Marshal(pubkeys) require.NoError(t, err) - instance := NewTestInstance(t, runtime.NODE_RUNTIME_v098) + instance := NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929) decoded, err := instance.DecodeSessionKeys(pukeysBytes) require.NoError(t, err) @@ -990,7 +919,8 @@ func TestInstance_DecodeSessionKeys(t *testing.T) { err = scale.Unmarshal(decoded, &decodedKeys) require.NoError(t, err) - require.Len(t, *decodedKeys, 4) + require.NotNil(t, decodedKeys) + require.Len(t, *decodedKeys, 6) } func TestInstance_PaymentQueryInfo(t *testing.T) { @@ -1004,11 +934,11 @@ func TestInstance_PaymentQueryInfo(t *testing.T) { // Was made with @polkadot/api on https://github.com/danforbes/polkadot-js-scripts/tree/create-signed-tx ext: "0xd1018400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01bc2b6e35929aabd5b8bc4e5b0168c9bee59e2bb9d6098769f6683ecf73e44c776652d947a270d59f3d37eb9f9c8c17ec1b4cc473f2f9928ffdeef0f3abd43e85d502000000012844616e20466f72626573", //nolint:lll expect: &types.RuntimeDispatchInfo{ - Weight: 1973000, + Weight: 0, Class: 0, PartialFee: &scale.Uint128{ Upper: 0, - Lower: uint64(1180126973000), + Lower: uint64(12800000000), }, }, }, @@ -1037,7 +967,7 @@ func TestInstance_PaymentQueryInfo(t *testing.T) { require.NoError(t, err) } - ins := NewTestInstance(t, runtime.NODE_RUNTIME) + ins := NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929) info, err := ins.PaymentQueryInfo(extBytes) if test.errMessage != "" { diff --git a/lib/runtime/wasmer/instance_test.go b/lib/runtime/wasmer/instance_test.go index 6dfe88bd03..546cca7f83 100644 --- a/lib/runtime/wasmer/instance_test.go +++ b/lib/runtime/wasmer/instance_test.go @@ -16,7 +16,7 @@ import ( // test used for ensuring runtime exec calls can me made concurrently func TestConcurrentRuntimeCalls(t *testing.T) { - instance := NewTestInstance(t, runtime.NODE_RUNTIME) + instance := NewTestInstance(t, runtime.WESTEND_RUNTIME_v0929) // execute 2 concurrent calls to the runtime go func() { diff --git a/lib/utils/utils.go b/lib/utils/utils.go index 3920676327..d94d3e4152 100644 --- a/lib/utils/utils.go +++ b/lib/utils/utils.go @@ -191,14 +191,14 @@ var ( ErrFindProjectRoot = errors.New("cannot find project root") ) -// GetProjectRootPath finds the root of the project where `go.mod` is -// and returns it as an absolute path. +// GetProjectRootPath finds the root of the project where directory `cmd` +// and subdirectory `gossamer` is and returns it as an absolute path. func GetProjectRootPath() (rootPath string, err error) { _, fullpath, _, _ := runtime.Caller(0) rootPath = path.Dir(fullpath) - const directoryToFind = "chain" - const subPathsToFind = "westend-dev,westend-local,kusama,polkadot" + const directoryToFind = "cmd" + const subPathsToFind = "gossamer" subPaths := strings.Split(subPathsToFind, ",")