Skip to content

Commit

Permalink
fix(ci): fix cmd/gossamer unit tests (#2560)
Browse files Browse the repository at this point in the history
* re-add gssmr config.toml

* rename files back to old names

* wip

* use raw methods for build spec command

* fix(ci): fix `dot` unit tests  (#2561)

* fix dot tests, remove life runtime

* remove life
  • Loading branch information
timwu20 authored May 26, 2022
1 parent 85ecaf7 commit 0d5ecbc
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 3,309 deletions.
17 changes: 14 additions & 3 deletions chain/dev/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ sync = ""
digest = ""

[init]
genesis = "./chain/dev/dev-spec-raw.json"
genesis = "./chain/dev/genesis-spec.json"

[account]
key = "alice"
key = ""
unlock = ""

[core]
Expand All @@ -37,7 +37,18 @@ enabled = true
ws = true
port = 8545
host = "localhost"
modules = ["system", "author", "chain", "state", "rpc", "grandpa", "offchain", "childstate", "syncstate", "payment"]
modules = [
"system",
"author",
"chain",
"state",
"rpc",
"grandpa",
"offchain",
"childstate",
"syncstate",
"payment",
]
ws-port = 8546

[pprof]
Expand Down
File renamed without changes.
File renamed without changes.
49 changes: 0 additions & 49 deletions chain/gssmr/config-bob.toml

This file was deleted.

20 changes: 15 additions & 5 deletions chain/gssmr/config-alice.toml → chain/gssmr/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[global]
basepath = "~/.gossamer/gssmr-alice"
basepath = "~/.gossamer/gssmr"
log = "info"
metrics-address = "localhost:9876"

Expand All @@ -15,18 +15,17 @@ sync = ""
digest = ""

[init]
genesis = "./chain/gssmr/gssmr-spec-raw.json"
genesis = "./chain/gssmr/genesis-spec.json"

[account]
key = "alice"
key = ""
unlock = ""

[core]
roles = 4
babe-authority = true
grandpa-authority = true
grandpa-interval = 1
babe-lead = true

[network]
port = 7001
Expand All @@ -40,7 +39,18 @@ max-peers = 50
enabled = false
port = 8545
host = "localhost"
modules = ["system", "author", "chain", "state", "rpc", "grandpa", "offchain", "childstate", "syncstate", "payment"]
modules = [
"system",
"author",
"chain",
"state",
"rpc",
"grandpa",
"offchain",
"childstate",
"syncstate",
"payment",
]
ws-port = 8546

[pprof]
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime/life"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/urfave/cli"
Expand Down Expand Up @@ -625,8 +624,6 @@ func setDotCoreConfig(ctx *cli.Context, tomlCfg ctoml.CoreConfig, cfg *dot.CoreC
switch tomlCfg.WasmInterpreter {
case wasmer.Name:
cfg.WasmInterpreter = wasmer.Name
case life.Name:
cfg.WasmInterpreter = life.Name
case "":
cfg.WasmInterpreter = gssmr.DefaultWasmInterpreter
default:
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 @@ -29,7 +29,7 @@ func createGenesisWithRuntime(fp string) (string, error) {
return "", err
}

genesis.Genesis.Runtime["System"]["code"] = fmt.Sprintf("0x%x", runtime)
genesis.Genesis.Runtime["system"]["code"] = fmt.Sprintf("0x%x", runtime)
bz, err := json.MarshalIndent(genesis, "", "\t")
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/import_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func TestCreateGenesisWithRuntime(t *testing.T) {
g := new(genesis.Genesis)
err = json.Unmarshal([]byte(out), g)
require.NoError(t, err)
require.Equal(t, testHex, g.Genesis.Runtime["System"]["code"].(string))
require.Equal(t, testHex, g.Genesis.Runtime["system"]["code"].(string))
}
2 changes: 1 addition & 1 deletion cmd/gossamer/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestBuildSpecCommandWithOutput(t *testing.T) {
buildSpecCommand := runTestGossamer(t,
"build-spec",
"--raw",
"--genesis-spec", utils.GetGssmrGenesisPathTest(t),
"--genesis-spec", utils.GetGssmrGenesisRawPathTest(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.GetGssmrGenesisPathTest(t)
cfg.Init.Genesis = utils.GetGssmrGenesisRawPathTest(t)

err := dot.InitNode(cfg)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions dot/build_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ func TestBuildFromDB(t *testing.T) {
}{
{name: "normal conditions", path: cfg.Global.BasePath,
want: &BuildSpec{genesis: &genesis.Genesis{
Name: "Gossamer",
ID: "gssmr",
Name: "Gossamer Testnet",
ID: "gssmr_test",
Bootnodes: []string{},
ProtocolID: "/gossamer/gssmr/0",
ProtocolID: "gssmr_test",
Genesis: genesis.Fields{
Raw: map[string]map[string]string{},
Runtime: map[string]map[string]interface{}{},
Expand Down
18 changes: 0 additions & 18 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/ChainSafe/gossamer/lib/grandpa"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/runtime/life"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/utils"
)
Expand Down Expand Up @@ -151,23 +150,6 @@ func createRuntime(cfg *Config, ns runtime.NodeStorage, st *state.Service,
if err != nil {
return nil, fmt.Errorf("failed to create runtime executor: %s", err)
}
case life.Name:
rtCfg := &life.Config{
Resolver: new(life.Resolver),
}
rtCfg.Storage = ts
rtCfg.Keystore = ks
rtCfg.LogLvl = cfg.Log.RuntimeLvl
rtCfg.NodeStorage = ns
rtCfg.Network = net
rtCfg.Role = cfg.Core.Roles
rtCfg.CodeHash = codeHash

// create runtime executor
rt, err = life.NewInstance(code, rtCfg)
if err != nil {
return nil, fmt.Errorf("failed to create runtime executor: %s", err)
}
default:
return nil, fmt.Errorf("%w: %s", ErrWasmInterpreterName, cfg.Core.WasmInterpreter)
}
Expand Down
13 changes: 0 additions & 13 deletions dot/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ChainSafe/gossamer/lib/grandpa"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/runtime/life"
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -467,9 +466,6 @@ func Test_createRuntime(t *testing.T) {
t.Parallel()
cfg := NewTestConfig(t)

cfgLife := NewTestConfig(t)
cfgLife.Core.WasmInterpreter = life.Name

type args struct {
cfg *Config
ns runtime.NodeStorage
Expand All @@ -489,15 +485,6 @@ func Test_createRuntime(t *testing.T) {
expectedType: &wasmer.Instance{},
err: nil,
},
{
name: "wasmer life",
args: args{
cfg: cfgLife,
ns: runtime.NodeStorage{},
},
expectedType: &life.Instance{},
err: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions dot/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
func newTestGenesisFile(t *testing.T, cfg *Config) (filename string) {
t.Helper()

fp := utils.GetGssmrGenesisPathTest(t)

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

Expand Down Expand Up @@ -64,7 +63,7 @@ func TestCreateJSONRawFile(t *testing.T) {
bs: &BuildSpec{genesis: NewTestGenesis(t)},
fp: filepath.Join(t.TempDir(), "/test.json"),
},
expectedHash: "23356cdb5d3537d39b735726707216c9e329c7b8a2c8a41b25da0f5f936b3caa",
expectedHash: "6453fb6118dab594944a7ed68111fdccc3a68253c9d71ac05f27aa2359507c85",
},
}
for _, tt := range tests {
Expand Down
Loading

0 comments on commit 0d5ecbc

Please sign in to comment.