Skip to content

Commit

Permalink
refactor(runtimes): remove deprecated node runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Mar 27, 2023
1 parent a9f4af3 commit 531a629
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 290 deletions.
90 changes: 0 additions & 90 deletions cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
package main

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"io"
"os"
"path/filepath"
"testing"

"github.com/ChainSafe/gossamer/chain/kusama"
Expand All @@ -20,9 +15,7 @@ import (
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/genesis"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/runtime/wasmer"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -838,89 +831,6 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {
require.Equal(t, expected, cfg)
}

func TestGlobalNodeName_WhenNodeAlreadyHasStoredName(t *testing.T) {
// Initialise a node with a random name
globalName := dot.RandomNodeName()
westendDevConfig := dot.WestendDevConfig()
cfg := newTestConfig(t, westendDevConfig)
cfg.Global.Name = globalName

runtimeFilePath, err := runtime.GetRuntime(context.Background(), runtime.NODE_RUNTIME)
require.NoError(t, err)
runtimeData, err := os.ReadFile(runtimeFilePath)
require.NoError(t, err)

fp := utils.GetWestendDevRawGenesisPath(t)

westendDevGenesis, err := genesis.NewGenesisFromJSONRaw(fp)
require.NoError(t, err)

gen := &genesis.Genesis{
Name: "test",
ID: "test",
Bootnodes: []string(nil),
ProtocolID: "/gossamer/test/0",
Genesis: westendDevGenesis.GenesisFields(),
}

gen.Genesis.Raw = map[string]map[string]string{
"top": {
"0x3a636f6465": "0x" + hex.EncodeToString(runtimeData),
"0xcf722c0832b5231d35e29f319ff27389f5032bfc7bfc3ba5ed7839f2042fb99f": "0x0000000000000001",
},
}

genData, err := json.Marshal(gen)
require.NoError(t, err)

genPath := filepath.Join(t.TempDir(), "genesis.json")
err = os.WriteFile(genPath, genData, os.ModePerm)
require.NoError(t, err)

cfg.Core.Roles = common.FullNodeRole
cfg.Core.BabeAuthority = false
cfg.Core.GrandpaAuthority = false
cfg.Init.Genesis = genPath

err = dot.InitNode(cfg)
require.NoError(t, err)

// call another command and test the name
testApp := cli.NewApp()
testApp.Writer = io.Discard

testcases := []struct {
description string
flags []string
values []interface{}
expected string
}{
{
"Test gossamer --roles --basepath",
[]string{"basepath", "roles"},
[]interface{}{cfg.Global.BasePath, "4"},
globalName,
},
{
"Test gossamer --roles",
[]string{"basepath", "roles"},
[]interface{}{cfg.Global.BasePath, "0"},
globalName,
},
}

for _, c := range testcases {
c := c // bypass scopelint false positive
t.Run(c.description, func(t *testing.T) {
ctx, err := newTestContext(c.description, c.flags, c.values)
require.NoError(t, err)
createdCfg, err := createDotConfig(ctx)
require.NoError(t, err)
require.Equal(t, c.expected, createdCfg.Global.Name)
})
}
}

func TestGlobalNodeNamePriorityOrder(t *testing.T) {
polkadotConfig := dot.PolkadotConfig()
cfg, testCfgFile := newTestConfigWithFile(t, polkadotConfig)
Expand Down
10 changes: 0 additions & 10 deletions lib/runtime/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.10 polkadot runtime
POLKADOT_RUNTIME_v0910 = "polkadot_runtime-v9100"
POLKADOT_RUNTIME_FP_v0910 = "polkadot_runtime-v9100.compact.wasm"
Expand Down
6 changes: 0 additions & 6 deletions lib/runtime/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 POLKADOT_RUNTIME_v0925:
runtimeFilename = POLKADOT_RUNTIME_FP_v0925
url = POLKADOT_RUNTIME_URL_v0925
Expand Down
185 changes: 2 additions & 183 deletions lib/runtime/wasmer/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,62 +70,6 @@ func Test_Instance_Version(t *testing.T) {
TransactionVersion: 1,
},
},
"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)
Expand Down Expand Up @@ -220,34 +164,6 @@ func Test_Instance_Version(t *testing.T) {
TransactionVersion: 8,
},
},
"runtime_v0980": {
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,
},
},
"polkadot_v0917": {
instanceBuilder: func(t *testing.T) instanceVersioner {
return NewTestInstance(t, runtime.POLKADOT_RUNTIME_v0917)
Expand Down Expand Up @@ -364,34 +280,6 @@ func TestNodeRuntime_ValidateTransaction(t *testing.T) {
require.NoError(t, err)
}

func TestInstance_GrandpaAuthorities_NodeRuntime(t *testing.T) {
tt := trie.NewEmptyTrie()

value, err := common.HexToBytes("0x0108eea1eabcac7d2c8a6459b7322cf997874482bfc3d2ec7a80888a3a7d714103640100000000000000b64994460e59b30364cad3c92e3df6052f9b0ebbb8f88460c194dc5794d6d7170100000000000000") //nolint:lll
require.NoError(t, err)

key := common.MustHexToBytes(genesis.GrandpaAuthoritiesKeyHex)
tt.Put(key, value)

rt := NewTestInstanceWithTrie(t, runtime.NODE_RUNTIME, tt)

auths, err := rt.GrandpaAuthorities()
require.NoError(t, err)

authABytes, _ := common.HexToBytes("0xeea1eabcac7d2c8a6459b7322cf997874482bfc3d2ec7a80888a3a7d71410364")
authBBytes, _ := common.HexToBytes("0xb64994460e59b30364cad3c92e3df6052f9b0ebbb8f88460c194dc5794d6d717")

authA, _ := ed25519.NewPublicKey(authABytes)
authB, _ := ed25519.NewPublicKey(authBBytes)

expected := []types.Authority{
{Key: authA, Weight: 1},
{Key: authB, Weight: 1},
}

require.Equal(t, expected, auths)
}

func TestInstance_GrandpaAuthorities_PolkadotRuntime(t *testing.T) {
tt := trie.NewEmptyTrie()

Expand Down Expand Up @@ -509,23 +397,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_DevRuntime_NoAuthorities(t *testing.T) {
rt := NewTestInstance(t, runtime.DEV_RUNTIME)
cfg, err := rt.BabeConfiguration()
Expand All @@ -544,58 +415,6 @@ func TestInstance_BabeConfiguration_DevRuntime_NoAuthorities(t *testing.T) {
require.Equal(t, expected, cfg)
}

func TestInstance_BabeConfiguration_NodeRuntime_WithAuthorities(t *testing.T) {
tt := trie.NewEmptyTrie()

randomnessValue, err := common.HexToHash("0x01")
require.NoError(t, err)
key := common.MustHexToBytes(genesis.BABERandomnessKeyHex)
tt.Put(key, randomnessValue[:])

authorityValue, err := common.HexToBytes("0x08eea1eabcac7d2c8a6459b7322cf997874482bfc3d2ec7a80888a3a7d714103640100000000000000b64994460e59b30364cad3c92e3df6052f9b0ebbb8f88460c194dc5794d6d7170100000000000000") //nolint:lll
require.NoError(t, err)

key = common.MustHexToBytes(genesis.BABEAuthoritiesKeyHex)
tt.Put(key, authorityValue)

rt := NewTestInstanceWithTrie(t, runtime.NODE_RUNTIME, tt)

cfg, err := rt.BabeConfiguration()
require.NoError(t, err)

authA, _ := common.HexToHash("0xeea1eabcac7d2c8a6459b7322cf997874482bfc3d2ec7a80888a3a7d71410364")
authB, _ := common.HexToHash("0xb64994460e59b30364cad3c92e3df6052f9b0ebbb8f88460c194dc5794d6d717")

expectedAuthData := []types.AuthorityRaw{
{Key: authA, Weight: 1},
{Key: authB, Weight: 1},
}

expected := &types.BabeConfiguration{
SlotDuration: 3000,
EpochLength: 200,
C1: 1,
C2: 2,
GenesisAuthorities: expectedAuthData,
Randomness: [32]byte{1},
SecondarySlots: 1,
}

require.Equal(t, expected, cfg)
}

func TestInstance_InitializeBlock_NodeRuntime(t *testing.T) {
rt := NewTestInstance(t, runtime.NODE_RUNTIME)

header := &types.Header{
Number: 1,
Digest: types.NewDigest(),
}

err := rt.InitializeBlock(header)
require.NoError(t, err)
}

func TestInstance_InitializeBlock_PolkadotRuntime(t *testing.T) {
rt := NewTestInstance(t, runtime.POLKADOT_RUNTIME)

Expand Down Expand Up @@ -1059,7 +878,7 @@ func TestInstance_DecodeSessionKeys(t *testing.T) {
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)

Expand Down Expand Up @@ -1118,7 +937,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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/wasmer/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 531a629

Please sign in to comment.