Skip to content

Commit

Permalink
Add integration tests for sonictool.
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisPH3 committed Dec 19, 2024
1 parent 4846231 commit 1cc2285
Show file tree
Hide file tree
Showing 6 changed files with 585 additions and 10 deletions.
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
8 changes: 4 additions & 4 deletions cmd/sonictool/app/sign_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package app

import (
"fmt"
"os"

"github.com/Fantom-foundation/go-opera/cmd/sonictool/genesis"
ogenesis "github.com/Fantom-foundation/go-opera/opera/genesis"
"github.com/Fantom-foundation/go-opera/opera/genesisstore"
"github.com/Fantom-foundation/go-opera/utils/prompt"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"gopkg.in/urfave/cli.v1"
"os"
)

func signGenesis(ctx *cli.Context) error {
Expand Down Expand Up @@ -36,9 +38,7 @@ func signGenesis(ctx *cli.Context) error {
log.Info("Hash to sign", "hash", hexutil.Encode(hash))
log.Info("Raw data", "rawdata", hexutil.Encode([]byte(rawData)))

fmt.Printf("Signature (hex): ")
var signatureString string
_, err = fmt.Scanln(&signatureString)
signatureString, err := prompt.UserPrompt.PromptInput("Signature (hex): ")
if err != nil {
return fmt.Errorf("failed to read signature: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions config/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package config

import (
"fmt"

"github.com/Fantom-foundation/go-opera/utils/prompt"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/console/prompt"
"github.com/ethereum/go-ethereum/log"
)

Expand Down Expand Up @@ -84,12 +85,12 @@ func GetPassPhrase(msg string, confirmation bool, i int, passwords []string) (st
if msg != "" {
fmt.Println(msg)
}
password, err := prompt.Stdin.PromptPassword("Passphrase: ")
password, err := prompt.UserPrompt.PromptPassword("Passphrase: ")
if err != nil {
return "", fmt.Errorf("failed to read passphrase: %v", err)
}
if confirmation {
confirm, err := prompt.Stdin.PromptPassword("Repeat passphrase: ")
confirm, err := prompt.UserPrompt.PromptPassword("Repeat passphrase: ")
if err != nil {
return "", fmt.Errorf("failed to read passphrase confirmation: %v", err)
}
Expand Down
Loading

0 comments on commit 1cc2285

Please sign in to comment.