Skip to content

Commit

Permalink
maintenance: cleanup TODOs, add issues numbers to remaining TODOs (Ch…
Browse files Browse the repository at this point in the history
  • Loading branch information
noot authored and timwu20 committed Dec 6, 2021
1 parent d6e3583 commit 165903d
Show file tree
Hide file tree
Showing 114 changed files with 619 additions and 1,435 deletions.
126 changes: 36 additions & 90 deletions cmd/gossamer/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"

"github.com/ChainSafe/gossamer/lib/utils"

"github.com/stretchr/testify/require"
)

// TestAccountGenerate test "gossamer account --generate"
Expand All @@ -29,25 +31,18 @@ func TestAccountGenerate(t *testing.T) {
defer utils.RemoveTestDir(t)
directory := fmt.Sprintf("--basepath=%s", testDir)
err := app.Run([]string{"irrelevant", "account", directory, "--generate=true", "--password=false"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctx, err := newTestContext(
"Test gossamer account --generate",
[]string{"basepath", "generate"},
[]interface{}{testDir, "true"},
)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

command := accountCommand
err = command.Run(ctx)
if err != nil {
t.Fatal(err)
}

// TODO: check contents of data directory - improve cmd account tests
require.NoError(t, err)
}

// TestAccountGeneratePassword test "gossamer account --generate --password"
Expand All @@ -56,25 +51,18 @@ func TestAccountGeneratePassword(t *testing.T) {
defer utils.RemoveTestDir(t)
directory := fmt.Sprintf("--basepath=%s", testDir)
err := app.Run([]string{"irrelevant", "account", directory, "--generate=true", "--password=true"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctx, err := newTestContext(
"Test gossamer account --generate --password",
[]string{"basepath", "generate", "password"},
[]interface{}{testDir, "true", "1234"},
)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

command := accountCommand
err = command.Run(ctx)
if err != nil {
t.Fatal(err)
}

// TODO: check contents of data directory - improve cmd account tests
require.NoError(t, err)
}

// TestAccountGenerateEd25519 test "gossamer account --generate --ed25519"
Expand All @@ -83,25 +71,18 @@ func TestAccountGenerateEd25519(t *testing.T) {
defer utils.RemoveTestDir(t)
directory := fmt.Sprintf("--basepath=%s", testDir)
err := app.Run([]string{"irrelevant", "account", directory, "--generate=true", "--password=false", "--ed25519"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctx, err := newTestContext(
"Test gossamer account --generate --ed25519",
[]string{"basepath", "generate", "ed25519"},
[]interface{}{testDir, "true", "ed25519"},
)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

command := accountCommand
err = command.Run(ctx)
if err != nil {
t.Fatal(err)
}

// TODO: check contents of data directory - improve cmd account tests
require.NoError(t, err)
}

// TestAccountGenerateSr25519 test "gossamer account --generate --ed25519"
Expand All @@ -110,25 +91,18 @@ func TestAccountGenerateSr25519(t *testing.T) {
defer utils.RemoveTestDir(t)
directory := fmt.Sprintf("--basepath=%s", testDir)
err := app.Run([]string{"irrelevant", "account", directory, "--generate=true", "--password=false", "--sr25519"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctx, err := newTestContext(
"Test gossamer account --generate --sr25519",
[]string{"basepath", "generate", "sr25519"},
[]interface{}{testDir, "true", "sr25519"},
)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

command := accountCommand
err = command.Run(ctx)
if err != nil {
t.Fatal(err)
}

// TODO: check contents of data directory - improve cmd account tests
require.NoError(t, err)
}

// TestAccountGenerateSecp256k1 test "gossamer account --generate --ed25519"
Expand All @@ -137,81 +111,60 @@ func TestAccountGenerateSecp256k1(t *testing.T) {
defer utils.RemoveTestDir(t)
directory := fmt.Sprintf("--basepath=%s", testDir)
err := app.Run([]string{"irrelevant", "account", directory, "--generate=true", "--password=false", "--secp256k1"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctx, err := newTestContext(
"Test gossamer account --generate --secp256k1",
[]string{"basepath", "generate", "secp256k1"},
[]interface{}{testDir, "true", "secp256k1"},
)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

command := accountCommand
err = command.Run(ctx)
if err != nil {
t.Fatal(err)
}

// TODO: check contents of data directory - improve cmd account tests
require.NoError(t, err)
}

// TestAccountImport test "gossamer account --import"
func TestAccountImport(t *testing.T) {
testDir := utils.NewTestDir(t)
defer utils.RemoveTestDir(t)
directory := fmt.Sprintf("--basepath=%s", testDir)
// TODO: Add import value for test

err := app.Run([]string{"irrelevant", "account", directory, "--import=./test_inputs/test-key.key"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctx, err := newTestContext(
"Test gossamer account --import=./test_inputs/test-key.key",
[]string{"basepath", "import"},
[]interface{}{"./test_inputs/", "test-key.key"},
)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

command := accountCommand
err = command.Run(ctx)
if err != nil {
t.Fatal(err)
}

// TODO: check contents of data directory - improve cmd account tests
require.NoError(t, err)
}

// TestAccountImport test "gossamer account --import-raw"
func TestAccountImportRaw(t *testing.T) {
testDir := utils.NewTestDir(t)
defer utils.RemoveTestDir(t)
directory := fmt.Sprintf("--basepath=%s", testDir)
// TODO: Add import-raw value for test

err := app.Run([]string{"irrelevant", "account", directory, `--import-raw=0x33a6f3093f158a7109f679410bef1a0c54168145e0cecb4df006c1c2fffb1f09`, "--password=1234"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctx, err := newTestContext(
"Test gossamer account --import-raw=0x33a6f3093f158a7109f679410bef1a0c54168145e0cecb4df006c1c2fffb1f09 --password=1234",
[]string{"import-raw", "password"},
[]interface{}{"0x33a6f3093f158a7109f679410bef1a0c54168145e0cecb4df006c1c2fffb1f09", "1234"},
)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

command := accountCommand
err = command.Run(ctx)
if err != nil {
t.Fatal(err)
}

// TODO: check contents of data directory - improve cmd account tests
require.NoError(t, err)
}

// TestAccountList test "gossamer account --list"
Expand All @@ -220,23 +173,16 @@ func TestAccountList(t *testing.T) {
defer utils.RemoveTestDir(t)
directory := fmt.Sprintf("--basepath=%s", testDir)
err := app.Run([]string{"irrelevant", "account", directory, "--list"})
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ctx, err := newTestContext(
"Test gossamer account --list",
[]string{"basepath", "list"},
[]interface{}{testDir, "true"},
)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

command := accountCommand
err = command.Run(ctx)
if err != nil {
t.Fatal(err)
}

// TODO: check contents of data directory - improve cmd account tests
require.NoError(t, err)
}
3 changes: 0 additions & 3 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,6 @@ func setDotCoreConfig(ctx *cli.Context, tomlCfg ctoml.CoreConfig, cfg *dot.CoreC
cfg.Roles = tomlCfg.Roles
cfg.BabeAuthority = tomlCfg.Roles == types.AuthorityRole
cfg.GrandpaAuthority = tomlCfg.Roles == types.AuthorityRole
cfg.SlotDuration = tomlCfg.SlotDuration
cfg.EpochLength = tomlCfg.EpochLength

// check --roles flag and update node configuration
if roles := ctx.GlobalString(RolesFlag.Name); roles != "" {
Expand Down Expand Up @@ -609,7 +607,6 @@ func setDotCoreConfig(ctx *cli.Context, tomlCfg ctoml.CoreConfig, cfg *dot.CoreC
"core configuration",
"babe-authority", cfg.BabeAuthority,
"grandpa-authority", cfg.GrandpaAuthority,
"epoch-length", cfg.EpochLength,
"wasm-interpreter", cfg.WasmInterpreter,
)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {
Core: testCfg.Core,
Network: dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: []string{}, // TODO: improve cmd tests #687
Bootnodes: []string{},
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Expand Down
2 changes: 0 additions & 2 deletions cmd/gossamer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ func dotConfigToToml(dcfg *dot.Config) *ctoml.Config {
Roles: dcfg.Core.Roles,
BabeAuthority: dcfg.Core.BabeAuthority,
GrandpaAuthority: dcfg.Core.GrandpaAuthority,
EpochLength: dcfg.Core.EpochLength,
SlotDuration: dcfg.Core.SlotDuration,
}

cfg.Network = ctoml.NetworkConfig{
Expand Down
4 changes: 2 additions & 2 deletions cmd/gossamer/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestExportCommand(t *testing.T) {
Core: testCfg.Core,
Network: dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes, // TODO: improve cmd tests #687
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestExportCommand(t *testing.T) {
Core: testCfg.Core,
Network: dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: []string{testBootnode}, // TODO: improve cmd tests #687
Bootnodes: []string{testBootnode},
ProtocolID: testProtocol,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: testCfg.Network.NoMDNS,
Expand Down
2 changes: 2 additions & 0 deletions cmd/gossamer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func gossamerAction(ctx *cli.Context) error {
}

ks := keystore.NewGlobalKeystore()
// load built-in test keys if specified by `cfg.Account.Key`
err = keystore.LoadKeystore(cfg.Account.Key, ks.Acco)
if err != nil {
logger.Error("failed to load account keystore", "error", err)
Expand All @@ -276,6 +277,7 @@ func gossamerAction(ctx *cli.Context) error {
return err
}

// load user keys if specified
err = unlockKeystore(ks.Acco, cfg.Global.BasePath, cfg.Account.Unlock, ctx.String(PasswordFlag.Name))
if err != nil {
logger.Error("failed to unlock keystore", "error", err)
Expand Down
Loading

0 comments on commit 165903d

Please sign in to comment.