Skip to content

Commit

Permalink
Merge branch 'feat/parachain' into ed/integrateValidationProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmack authored Jul 14, 2023
2 parents 9668a7b + 4389c37 commit f44ddc0
Show file tree
Hide file tree
Showing 38 changed files with 1,808 additions and 1,102 deletions.
2 changes: 1 addition & 1 deletion cmd/gossamer/commands/import_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func createGenesisWithRuntime(fp string, genesisSpecFilePath string) (string, er
return "", err
}

chainSpec.Genesis.Runtime["system"]["code"] = fmt.Sprintf("0x%x", runtime)
chainSpec.Genesis.Runtime.System.Code = fmt.Sprintf("0x%x", runtime)
jsonSpec, err := json.MarshalIndent(chainSpec, "", "\t")
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/commands/import_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,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)
}
2 changes: 1 addition & 1 deletion dot/build_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func BuildFromDB(path string) (*BuildSpec, error) {
},
}
tmpGen.Genesis.Raw = make(map[string]map[string]string)
tmpGen.Genesis.Runtime = make(map[string]map[string]interface{})
tmpGen.Genesis.Runtime = new(genesis.Runtime)

config := state.Config{
Path: path,
Expand Down
8 changes: 3 additions & 5 deletions dot/build_spec_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"path/filepath"
"testing"

westenddev "github.com/ChainSafe/gossamer/chain/westend-dev"

"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/stretchr/testify/require"
Expand All @@ -22,7 +20,7 @@ import (
const codeHex = "0x3a636f6465"

func TestWriteGenesisSpecFile_Integration(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)
config.ChainSpec = utils.GetWestendDevRawGenesisPath(t)

expected, err := genesis.NewGenesisFromJSONRaw(config.ChainSpec)
Expand Down Expand Up @@ -61,7 +59,7 @@ func TestWriteGenesisSpecFile_Integration(t *testing.T) {

func TestBuildFromDB_Integration(t *testing.T) {
// setup expected
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)
config.ChainSpec = utils.GetWestendDevRawGenesisPath(t)
expected, err := genesis.NewGenesisFromJSONRaw(config.ChainSpec)
require.NoError(t, err)
Expand All @@ -77,5 +75,5 @@ func TestBuildFromDB_Integration(t *testing.T) {
err = json.Unmarshal(res, &jGen)
require.NoError(t, err)

require.Equal(t, expected.Genesis.Raw["top"][codeHex], jGen.Genesis.Runtime["system"]["code"])
require.Equal(t, expected.Genesis.Raw["top"][codeHex], jGen.Genesis.Runtime.System.Code)
}
23 changes: 13 additions & 10 deletions dot/build_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"strings"
"testing"

westenddev "github.com/ChainSafe/gossamer/chain/westend-dev"

"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -124,9 +122,9 @@ func TestBuildSpec_ToJSON(t *testing.T) {

func TestBuildFromDB(t *testing.T) {
// initialise node (initialise state database and load genesis data)
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

config.ChainSpec = utils.GetWestendDevRawGenesisPath(t)
config.BasePath = t.TempDir()
builder := nodeBuilder{}
err := builder.initNode(config)
require.NoError(t, err)
Expand All @@ -145,7 +143,7 @@ func TestBuildFromDB(t *testing.T) {
ProtocolID: "dot",
Genesis: genesis.Fields{
Raw: map[string]map[string]string{},
Runtime: map[string]map[string]interface{}{},
Runtime: new(genesis.Runtime),
},
}}},
{name: "invalid_db_path", path: t.TempDir(),
Expand All @@ -162,7 +160,7 @@ func TestBuildFromDB(t *testing.T) {
}
if tt.want != nil {
got.genesis.Genesis.Raw = map[string]map[string]string{}
got.genesis.Genesis.Runtime = map[string]map[string]interface{}{}
got.genesis.Genesis.Runtime = new(genesis.Runtime)
assert.Equal(t, tt.want, got)
}
})
Expand All @@ -173,9 +171,10 @@ func TestBuildFromGenesis(t *testing.T) {
rawGenesis := genesis.Genesis{
Name: "test",
Genesis: genesis.Fields{
Runtime: map[string]map[string]interface{}{
"System": {
"code": "mocktestcode",
Raw: map[string]map[string]string{},
Runtime: &genesis.Runtime{
System: &genesis.System{
Code: "mocktestcode",
},
},
},
Expand Down Expand Up @@ -210,7 +209,11 @@ func TestBuildFromGenesis(t *testing.T) {
Raw: map[string]map[string]string{"top" +
"": {"0x26aa394eea5630e07c48ae0c9558cef7c21aab032aaa6e946ca50ad39ab66603": "0x01",
"0x3a636f6465": "mocktestcode"}},
Runtime: map[string]map[string]interface{}{"System": {"code": "mocktestcode"}},
Runtime: &genesis.Runtime{
System: &genesis.System{
Code: "mocktestcode",
},
},
},
}},
},
Expand Down
19 changes: 5 additions & 14 deletions dot/import_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ package dot

import (
"errors"
"os"
"testing"

westend_dev "github.com/ChainSafe/gossamer/chain/westend-dev"

"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/internal/log"
Expand Down Expand Up @@ -84,10 +81,7 @@ func TestNewHeaderFromFile(t *testing.T) {
}

func TestImportState_Integration(t *testing.T) {
basepath := os.TempDir()

config := westend_dev.DefaultConfig()
config.BasePath = basepath
config := DefaultTestWestendDevConfig(t)

genFile := NewTestGenesisRawFile(t, config)

Expand All @@ -99,11 +93,11 @@ func TestImportState_Integration(t *testing.T) {
headerFP := setupHeaderFile(t)

const firstSlot = uint64(262493679)
err = ImportState(basepath, stateFP, headerFP, firstSlot)
err = ImportState(config.BasePath, stateFP, headerFP, firstSlot)
require.NoError(t, err)
// confirm data is imported into db
stateConfig := state.Config{
Path: basepath,
Path: config.BasePath,
LogLevel: log.Info,
}
srv := state.NewService(stateConfig)
Expand All @@ -119,10 +113,7 @@ func TestImportState_Integration(t *testing.T) {
func TestImportState(t *testing.T) {
t.Parallel()

basepath := t.TempDir()

config := westend_dev.DefaultConfig()
config.BasePath = basepath
config := DefaultTestWestendDevConfig(t)

config.ChainSpec = NewTestGenesisRawFile(t, config)
nodeInstance := nodeBuilder{}
Expand Down Expand Up @@ -150,7 +141,7 @@ func TestImportState(t *testing.T) {
{
name: "working_example",
args: args{
basepath: basepath,
basepath: config.BasePath,
stateFP: stateFP,
headerFP: headerFP,
firstSlot: 262493679,
Expand Down
33 changes: 12 additions & 21 deletions dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"testing"

"github.com/ChainSafe/gossamer/chain/westend"
westenddev "github.com/ChainSafe/gossamer/chain/westend-dev"

cfg "github.com/ChainSafe/gossamer/config"
"github.com/ChainSafe/gossamer/dot/core"
Expand Down Expand Up @@ -169,7 +168,8 @@ func TestNewNode(t *testing.T) {
}

func Test_nodeBuilder_loadRuntime(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

type args struct {
config *cfg.Config
ns *runtime.NodeStorage
Expand Down Expand Up @@ -211,12 +211,11 @@ func Test_nodeBuilder_loadRuntime(t *testing.T) {
}

func TestInitNode_Integration(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

genFile := NewTestGenesisRawFile(t, config)

config.ChainSpec = genFile
config.BasePath = t.TempDir()

err := InitNode(config)
require.NoError(t, err)
Expand All @@ -228,12 +227,11 @@ func TestInitNode_Integration(t *testing.T) {
}

func TestInitNode_GenesisSpec(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

genFile := newTestGenesisFile(t, config)
genFile := NewTestGenesisRawFile(t, config)

config.ChainSpec = genFile
config.BasePath = t.TempDir()

err := InitNode(config)
require.NoError(t, err)
Expand All @@ -244,12 +242,11 @@ func TestInitNode_GenesisSpec(t *testing.T) {
}

func TestNodeInitializedIntegration(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

genFile := NewTestGenesisRawFile(t, config)

config.ChainSpec = genFile
config.BasePath = t.TempDir()

result := IsNodeInitialised(config.BasePath)
require.False(t, result)
Expand All @@ -262,12 +259,11 @@ func TestNodeInitializedIntegration(t *testing.T) {
}

func TestNewNodeIntegration(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

genFile := NewTestGenesisRawFile(t, config)

config.ChainSpec = genFile
config.BasePath = t.TempDir()

err := InitNode(config)
require.NoError(t, err)
Expand All @@ -294,12 +290,11 @@ func TestNewNodeIntegration(t *testing.T) {
}

func TestNewNode_Authority(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

genFile := NewTestGenesisRawFile(t, config)

config.ChainSpec = genFile
config.BasePath = t.TempDir()

err := InitNode(config)
require.NoError(t, err)
Expand Down Expand Up @@ -329,12 +324,11 @@ func TestNewNode_Authority(t *testing.T) {
}

func TestStartStopNode(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

genFile := NewTestGenesisRawFile(t, config)

config.ChainSpec = genFile
config.BasePath = t.TempDir()
config.Core.GrandpaAuthority = false
config.Core.BabeAuthority = false

Expand Down Expand Up @@ -367,15 +361,14 @@ func TestStartStopNode(t *testing.T) {
}

func TestInitNode_LoadStorageRoot(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

genPath := newTestGenesisAndRuntime(t)

config.Core.Role = common.FullNodeRole
config.Core.BabeAuthority = false
config.Core.GrandpaAuthority = false
config.ChainSpec = genPath
config.BasePath = t.TempDir()

gen, err := genesis.NewGenesisFromJSONRaw(genPath)
require.NoError(t, err)
Expand Down Expand Up @@ -416,15 +409,14 @@ func balanceKey(t *testing.T, publicKey [32]byte) (storageTrieKey []byte) {
}

func TestInitNode_LoadBalances(t *testing.T) {
config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)

genPath := newTestGenesisAndRuntime(t)

config.Core.Role = common.FullNodeRole
config.Core.BabeAuthority = false
config.Core.GrandpaAuthority = false
config.ChainSpec = genPath
config.BasePath = t.TempDir()

err := InitNode(config)
require.NoError(t, err)
Expand Down Expand Up @@ -457,14 +449,13 @@ func TestInitNode_LoadBalances(t *testing.T) {
func TestNode_PersistGlobalName_WhenInitialize(t *testing.T) {
globalName := RandomNodeName()

config := westenddev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)
config.Name = globalName

config.Core.Role = common.FullNodeRole
config.Core.BabeAuthority = false
config.Core.GrandpaAuthority = false
config.ChainSpec = newTestGenesisAndRuntime(t)
config.BasePath = t.TempDir()

err := InitNode(config)
require.NoError(t, err)
Expand Down
15 changes: 10 additions & 5 deletions dot/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
"time"

westend_dev "github.com/ChainSafe/gossamer/chain/westend-dev"
westenddev "github.com/ChainSafe/gossamer/chain/westend-dev"
cfg "github.com/ChainSafe/gossamer/config"

"github.com/ChainSafe/gossamer/dot/network"
Expand All @@ -27,10 +27,16 @@ import (
"github.com/stretchr/testify/require"
)

func DefaultTestWestendDevConfig(t *testing.T) *cfg.Config {
config := westenddev.DefaultConfig()
config.BasePath = t.TempDir()

return config
}

func TestInitNode(t *testing.T) {
config := westend_dev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)
config.ChainSpec = NewTestGenesisRawFile(t, config)
config.BasePath = t.TempDir()
tests := []struct {
name string
config *cfg.Config
Expand Down Expand Up @@ -129,10 +135,9 @@ func setConfigTestDefaults(t *testing.T, cfg *network.Config) {
}

func TestNodeInitialized(t *testing.T) {
config := westend_dev.DefaultConfig()
config := DefaultTestWestendDevConfig(t)
genFile := NewTestGenesisRawFile(t, config)
config.ChainSpec = genFile
config.BasePath = t.TempDir()

nodeInstance := nodeBuilder{}
err := nodeInstance.initNode(config)
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/sync_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewStateSync(gData *genesis.Data, storageAPI StorageAPI) (SyncStateAPI, err
},
}
tmpGen.Genesis.Raw = make(map[string]map[string]string)
tmpGen.Genesis.Runtime = make(map[string]map[string]interface{})
tmpGen.Genesis.Runtime = new(genesis.Runtime)

// set genesis fields data
ent, err := storageAPI.Entries(nil)
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/sync_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestNewStateSync(t *testing.T) {
ProtocolID: "",
Genesis: genesis.Fields{
Raw: map[string]map[string]string{},
Runtime: map[string]map[string]interface{}{},
Runtime: new(genesis.Runtime),
},
},
},
Expand Down
Loading

0 comments on commit f44ddc0

Please sign in to comment.