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

Add integration tests for sonictool. #381

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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
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
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ func MakeAllConfigsFromFile(ctx *cli.Context, configFile string) (*Config, error
cfg.OperaStore.EVM.Cache.StateDbCapacity = ctx.GlobalInt(flags.StateDbCacheCapacityFlag.Name)
}

if ctx.IsSet(flags.StateDbCheckPointInterval.Name) {
cfg.OperaStore.EVM.StateDb.CheckpointInterval = ctx.GlobalInt(flags.StateDbCheckPointInterval.Name)
}

return &cfg, nil
}

Expand Down
11 changes: 9 additions & 2 deletions config/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,14 @@ var (
Name: "statedb.livecache",
Usage: fmt.Sprintf("Size of live db cache in bytes. Leaving this blank (which is generally recommended),"+
"or setting this to <1 will automatically allocate cache size depending on how much cache you use with %s."+
"Setting this value to <=2000 will result in pre-confugired cache capacity of 2KB", CacheFlag.Name),
"Setting this value to <=2000 will result in pre-configured cache capacity of 2KB", CacheFlag.Name),
Value: 0,
}
ArchiveCacheFlag = cli.IntFlag{
Name: "statedb.archivecache",
Usage: fmt.Sprintf("Size of archive cache in bytes. Leaving this blank (which is generally recommended),"+
"or setting this to <1 will automatically allocate cache size depending on how much cache you use with %s."+
"Setting this value to <=2000 will result in pre-confugired cache capacity of 2KB", CacheFlag.Name),
"Setting this value to <=2000 will result in pre-configured cache capacity of 2KB", CacheFlag.Name),
Value: 0,
}
StateDbCacheCapacityFlag = cli.IntFlag{
Expand All @@ -372,4 +372,11 @@ var (
"is recommended. Setting this to <1 will automatically set the cache capacity to a DB defined default value.",
Value: 0,
}
StateDbCheckPointInterval = cli.IntFlag{
Name: "statedb.checkpointinterval",
Hidden: true, // Intended for testing
Usage: "The number of blocks after which a db healing checkpoint will be created. " +
"Setting this to <1 will automatically set the value to a DB defined default.",
Value: 0,
}
)
43 changes: 24 additions & 19 deletions tests/integration_test_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ import (
// integration test networks can also be used for automated integration and
// regression tests for client code.
type IntegrationTestNet struct {
directory string
done <-chan struct{}
validator Account
httpPort int
wsPort int
directory string
done <-chan struct{}
validator Account
httpPort int
wsPort int
extraArguments []string
}

func isPortFree(host string, port int) bool {
Expand Down Expand Up @@ -91,13 +92,11 @@ func getFreePort() (int, error) {
// The node serving the network is started in the same process as the caller. This
// is intended to facilitate debugging of client code in the context of a running
// node.
func StartIntegrationTestNet(directory string) (*IntegrationTestNet, error) {
return startIntegrationTestNet(directory, []string{
"genesis", "fake", "1",
})
func StartIntegrationTestNet(directory string, extraArguments ...string) (*IntegrationTestNet, error) {
return startIntegrationTestNet(directory, []string{"genesis", "fake", "1"}, extraArguments)
}

func StartIntegrationTestNetFromJsonGenesis(directory string) (*IntegrationTestNet, error) {
func StartIntegrationTestNetFromJsonGenesis(directory string, extraArguments ...string) (*IntegrationTestNet, error) {
jsonGenesis := makefakegenesis.GenesisJson{
Rules: opera.FakeNetRules(),
BlockZeroTime: time.Now(),
Expand Down Expand Up @@ -181,16 +180,18 @@ func StartIntegrationTestNetFromJsonGenesis(directory string) (*IntegrationTestN
if err != nil {
return nil, fmt.Errorf("failed to write genesis.json file: %w", err)
}
return startIntegrationTestNet(directory, []string{
"genesis", "json", "--experimental", jsonFile,
})
return startIntegrationTestNet(directory,
[]string{"genesis", "json", "--experimental", jsonFile},
extraArguments,
)
}

func startIntegrationTestNet(directory string, args []string) (*IntegrationTestNet, error) {
func startIntegrationTestNet(directory string, sonicToolArguments []string, extraArguments []string) (*IntegrationTestNet, error) {
// start the fakenet sonic node
result := &IntegrationTestNet{
directory: directory,
validator: Account{evmcore.FakeKey(1)},
directory: directory,
validator: Account{evmcore.FakeKey(1)},
extraArguments: extraArguments,
}

// initialize the data directory for the single node on the test network
Expand All @@ -202,7 +203,7 @@ func startIntegrationTestNet(directory string, args []string) (*IntegrationTestN
"--statedb.livecache", "1",
"--statedb.archivecache", "1",
"--statedb.cache", "1024",
}, args...)
}, sonicToolArguments...)
if err := sonictool.Run(); err != nil {
os.Args = originalArgs
return nil, fmt.Errorf("failed to initialize the test network: %w", err)
Expand Down Expand Up @@ -247,7 +248,7 @@ func (n *IntegrationTestNet) start() error {

// start the fakenet sonic node
// equivalent to running `sonicd ...` but in this local process
os.Args = []string{
os.Args = append([]string{
"sonicd",

// data storage options
Expand All @@ -274,7 +275,11 @@ func (n *IntegrationTestNet) start() error {
"--statedb.livecache", "1",
"--statedb.archivecache", "1",
"--statedb.cache", "1024",
}
},

// append extra arguments
n.extraArguments...,
)

err := sonicd.Run()
if err != nil {
Expand Down
Loading
Loading