Skip to content

Commit

Permalink
Merge branch 'develop' into jim/up_v2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jmpike authored Jan 16, 2025
2 parents 3c65964 + 5de3497 commit 155111c
Show file tree
Hide file tree
Showing 26 changed files with 925 additions and 277 deletions.
9 changes: 7 additions & 2 deletions cmd/cmdtest/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func (tt *TestCmd) Run(name string, args ...string) {
//
// cli.expect(`Passphrase: {{.InputLine "password"}}`)
func (tt *TestCmd) InputLine(s string) string {
io.WriteString(tt.stdin, s+"\n")
if _, err := io.WriteString(tt.stdin, s+"\n"); err != nil {
tt.Fatalf("Failed to write to stdin: %v", err)
}
return ""
}

Expand Down Expand Up @@ -121,7 +123,10 @@ func (tt *TestCmd) matchExactOutput(want []byte) error {
// Grab any additional buffered output in case of mismatch
// because it might help with debugging.
buf = append(buf, make([]byte, tt.stdout.Buffered())...)
tt.stdout.Read(buf[n:])
if _, err := tt.stdout.Read(buf[n:]); err != nil {
tt.Fatalf("Failed to read buffered output: %v", err)
}

// Find the mismatch position.
for i := 0; i < n; i++ {
if want[i] != buf[i] {
Expand Down
1 change: 1 addition & 0 deletions cmd/sonicd/app/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func initFlags() {
flags.LiveDbCacheFlag,
flags.ArchiveCacheFlag,
flags.StateDbCacheCapacityFlag,
flags.StateDbCheckPointInterval,
}
networkingFlags = []cli.Flag{
flags.BootnodesFlag,
Expand Down
17 changes: 13 additions & 4 deletions cmd/sonicd/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package app

import (
"fmt"
"github.com/Fantom-foundation/lachesis-base/utils/cachescale"
"os"
"strings"
"testing"

"github.com/Fantom-foundation/lachesis-base/utils/cachescale"

"github.com/Fantom-foundation/go-opera/cmd/sonictool/genesis"
"github.com/Fantom-foundation/go-opera/config"
"github.com/Fantom-foundation/go-opera/integration/makefakegenesis"
Expand All @@ -28,7 +29,11 @@ func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) {
futils.ToFtm(1000000000),
futils.ToFtm(5000000),
)
defer genesisStore.Close()
defer func() {
if err := genesisStore.Close(); err != nil {
panic(fmt.Errorf("failed to close genesis store: %v", err))
}
}()

if err := genesis.ImportGenesisStore(genesis.ImportParams{
GenesisStore: genesisStore,
Expand All @@ -37,7 +42,7 @@ func initFakenetDatadir(dataDir string, validatorsNum idx.Validator) {
LiveDbCache: 1, // Set lowest cache
ArchiveCache: 1, // Set lowest cache
}); err != nil {
panic(err)
panic(fmt.Errorf("failed to import genesis store: %v", err))
}
}

Expand Down Expand Up @@ -99,7 +104,11 @@ func exec(t *testing.T, args ...string) *testcli {
}

// Remove the temporary datadir.
tt.Cleanup = func() { os.RemoveAll(tt.Datadir) }
tt.Cleanup = func() {
if err := os.RemoveAll(tt.Datadir); err != nil {
t.Fatalf("failed to remove temporary datadir: %v", err)
}
}
defer func() {
if t.Failed() {
tt.Cleanup()
Expand Down
13 changes: 10 additions & 3 deletions cmd/sonictool/app/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
"fmt"

"github.com/Fantom-foundation/go-opera/config"
"github.com/Fantom-foundation/go-opera/utils/caution"
"github.com/ethereum/go-ethereum/accounts/keystore"

"github.com/ethereum/go-ethereum/crypto"
"gopkg.in/urfave/cli.v1"
)

func accountList(ctx *cli.Context) error {
func accountList(ctx *cli.Context) (err error) {
cfg, err := config.MakeAllConfigs(ctx)
if err != nil {
return err
Expand All @@ -35,6 +36,8 @@ func accountList(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to create the protocol stack: %w", err)
}
defer caution.CloseAndReportError(&err, stack, "failed to close network stack")

var index int
for _, wallet := range stack.AccountManager().Wallets() {
for _, account := range wallet.Accounts() {
Expand Down Expand Up @@ -91,7 +94,7 @@ func accountCreate(ctx *cli.Context) error {

// accountUpdate transitions an account from a previous format to the current
// one, also providing the possibility to change the pass-phrase.
func accountUpdate(ctx *cli.Context) error {
func accountUpdate(ctx *cli.Context) (err error) {
if len(ctx.Args()) == 0 {
return fmt.Errorf("no accounts specified to update")
}
Expand All @@ -104,6 +107,8 @@ func accountUpdate(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to create the protocol stack: %w", err)
}
defer caution.CloseAndReportError(&err, stack, "failed to close network stack")

ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)

for _, addr := range ctx.Args() {
Expand All @@ -122,7 +127,7 @@ func accountUpdate(ctx *cli.Context) error {
return nil
}

func accountImport(ctx *cli.Context) error {
func accountImport(ctx *cli.Context) (err error) {
keyfile := ctx.Args().First()
if len(keyfile) == 0 {
return fmt.Errorf("keyfile must be given as argument")
Expand All @@ -140,6 +145,8 @@ func accountImport(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to create the protocol stack: %w", err)
}
defer caution.CloseAndReportError(&err, stack, "failed to close network stack")

passwordList, err := config.MakePasswordList(ctx)
if err != nil {
return fmt.Errorf("failed to get password list: %w", err)
Expand Down
Loading

0 comments on commit 155111c

Please sign in to comment.