Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dot): use tempDir in tests as base path to avoid creating dot/~ #3363

Merged
merged 5 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 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 Down
6 changes: 2 additions & 4 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 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 @@ -163,7 +162,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 @@ -205,12 +205,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 @@ -222,12 +221,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 @@ -238,12 +236,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 @@ -256,12 +253,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 @@ -288,12 +284,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 @@ -323,12 +318,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 @@ -361,15 +355,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 @@ -410,15 +403,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 @@ -451,14 +443,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
Loading