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

feat: remove redundant app code-base from 2 test-cases #56

Merged
merged 7 commits into from
Sep 2, 2022
Merged
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
4 changes: 4 additions & 0 deletions compositions/cluster-k8s/gen-validators.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
runner = "cluster:k8s"
disable_metrics = false

[global.run.test_params]
validator = "80"
persistent-peers = "10"

[[groups]]
id = "validators"
builder = "docker:generic"
Expand Down
4 changes: 4 additions & 0 deletions compositions/local-docker/gen-validators.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
runner = "local:docker"
disable_metrics = false

[global.run.test_params]
validator = "3"
persistent-peers = "3"

[[groups]]
id = "validators"
builder = "docker:generic"
Expand Down
3 changes: 3 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ enabled = true
[[testcases]]
name = "init-val"
instances = { min = 1, max = 100, default = 3 }
[testcases.params]
validator = { type = "int", default = 3}
persistent-peers = { type = "int", default = 3}

[[testcases]]
name = "node-sync"
Expand Down
51 changes: 30 additions & 21 deletions testkit/appkit/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ type ValidatorNode struct {
}

type AppKit struct {
m sync.Mutex
Cmd *cobra.Command
m sync.Mutex
home string
AccountAddress string
ChainId string
Cmd *cobra.Command
}

func New() *AppKit {
func New(path, chainId string) *AppKit {
return &AppKit{
Cmd: appcmd.NewRootCmd(),
home: path,
ChainId: chainId,
Cmd: appcmd.NewRootCmd(),
}
}

Expand Down Expand Up @@ -64,50 +69,54 @@ func (ak *AppKit) execCmd(args []string) (output string, err error) {
return output, nil
}

func (ak *AppKit) InitChain(moniker string, chainId string, home string) (string, error) {
return ak.execCmd([]string{"init", moniker, "--chain-id", chainId, "--home", home})
func (ak *AppKit) GetHomePath() string {
return ak.home
}

func (ak *AppKit) CreateKey(name string, krbackend string, home string) (string, error) {
_, err := ak.execCmd([]string{"keys", "add", name, "--keyring-backend", krbackend, "--home", home, "--keyring-dir", home})
func (ak *AppKit) InitChain(moniker string) (string, error) {
return ak.execCmd([]string{"init", moniker, "--chain-id", ak.ChainId, "--home", ak.home})
}

func (ak *AppKit) CreateKey(name, krbackend, krpath string) (string, error) {
_, err := ak.execCmd([]string{"keys", "add", name, "--keyring-backend", krbackend, "--home", ak.home, "--keyring-dir", krpath})
if err != nil {
return "", err
}
return ak.execCmd([]string{"keys", "show", name, "-a", "--keyring-backend", krbackend, "--home", home, "--keyring-dir", home})
return ak.execCmd([]string{"keys", "show", name, "-a", "--keyring-backend", krbackend, "--home", ak.home, "--keyring-dir", krpath})
}

func (ak *AppKit) AddGenAccount(addr string, amount string, home string) (string, error) {
return ak.execCmd([]string{"add-genesis-account", addr, amount, "--home", home})
func (ak *AppKit) AddGenAccount(addr, amount string) (string, error) {
return ak.execCmd([]string{"add-genesis-account", addr, amount, "--home", ak.home})
}

func (ak *AppKit) SignGenTx(accName string, amount string, krbackend string, chainId string, home string) (string, error) {
return ak.execCmd([]string{"gentx", accName, amount, "--keyring-backend", krbackend, "--chain-id", chainId, "--home", home, "--keyring-dir", home})
func (ak *AppKit) SignGenTx(accName, amount, krbackend, krpath string) (string, error) {
return ak.execCmd([]string{"gentx", accName, amount, "--keyring-backend", krbackend, "--chain-id", ak.ChainId, "--home", ak.home, "--keyring-dir", krpath})
}

func (ak *AppKit) CollectGenTxs(home string) (string, error) {
return ak.execCmd([]string{"collect-gentxs", "--home", home})
func (ak *AppKit) CollectGenTxs() (string, error) {
return ak.execCmd([]string{"collect-gentxs", "--home", ak.home})
}

func (ak *AppKit) GetNodeId(home string) (string, error) {
return ak.execCmd([]string{"tendermint", "show-node-id", "--home", home})
func (ak *AppKit) GetNodeId() (string, error) {
return ak.execCmd([]string{"tendermint", "show-node-id", "--home", ak.home})
}

func (ak *AppKit) StartNode(home, loglvl string) error {
func (ak *AppKit) StartNode(loglvl string) error {
ak.Cmd.ResetFlags()

ak.Cmd.SetErr(os.Stdout)
ak.Cmd.SetArgs([]string{"start", "--home", home, "--log_level", loglvl, "--log_format", "plain"})
ak.Cmd.SetArgs([]string{"start", "--home", ak.home, "--log_level", loglvl, "--log_format", "plain"})

return svrcmd.Execute(ak.Cmd, appcmd.EnvPrefix, app.DefaultNodeHome)
}

func (ak *AppKit) PayForData(accAdr string, msg int, krbackend, chainId, home string) error {
func (ak *AppKit) PayForData(accAdr string, msg int, krbackend, krpath string) error {
ak.Cmd.ResetFlags()
ak.Cmd.SetArgs([]string{
"tx", "payment", "payForData", fmt.Sprint(msg),
"--from", accAdr, "-b", "block", "-y", "--gas", "1000000000",
"--fees", "100000000000utia",
"--keyring-backend", krbackend, "--chain-id", chainId, "--home", home, "--keyring-dir", home,
"--keyring-backend", krbackend, "--chain-id", ak.ChainId, "--home", ak.home, "--keyring-dir", krpath,
})

return svrcmd.Execute(ak.Cmd, appcmd.EnvPrefix, app.DefaultNodeHome)
Expand Down
6 changes: 3 additions & 3 deletions tests/app-sync/run_seeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func RunSeed(runenv *runtime.RunEnv, initCtx *run.InitContext) error {
home := fmt.Sprintf("/.celestia-app-%d", initCtx.GroupSeq)
runenv.RecordMessage(home)

cmd := appkit.New()
cmd := appkit.New(home, "tia-test")

nodeId, err := cmd.GetNodeId(home)
nodeId, err := cmd.GetNodeId()
if err != nil {
return err
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func RunSeed(runenv *runtime.RunEnv, initCtx *run.InitContext) error {
return err
}

go cmd.StartNode(home, "info")
go cmd.StartNode("info")

// // wait for a new block to be produced
time.Sleep(1 * time.Minute)
Expand Down
85 changes: 85 additions & 0 deletions tests/app-sync/run_validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package appsync

import (
"context"
"net"
"time"

"github.com/celestiaorg/test-infra/testkit/appkit"
"github.com/celestiaorg/test-infra/tests/common"

"github.com/testground/sdk-go/network"
"github.com/testground/sdk-go/run"
"github.com/testground/sdk-go/runtime"
)

func RunValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*4)
defer cancel()

syncclient := initCtx.SyncClient
netclient := network.NewClient(syncclient, runenv)

netclient.MustWaitNetworkInitialized(ctx)

config := network.Config{
Network: "default",
Enable: true,
Default: network.LinkShape{
Bandwidth: 5 << 26, // 320Mib
},
CallbackState: "network-configured",
RoutingPolicy: network.AllowAll,
}

config.IPv4 = runenv.TestSubnet

// using the assigned `GlobalSequencer` id per each of instance
// to fill in the last 2 octects of the new IP address for the instance
ipC := byte((initCtx.GlobalSeq >> 8) + 1)
ipD := byte(initCtx.GlobalSeq)
config.IPv4.IP = append(config.IPv4.IP[0:2:2], ipC, ipD)

err := netclient.ConfigureNetwork(ctx, &config)
if err != nil {
return err
}

appcmd, err := common.BuildValidator(ctx, runenv, initCtx)
if err != nil {
return err
}

runenv.RecordMessage("starting........")
go appcmd.StartNode("info")

// // wait for a new block to be produced
time.Sleep(1 * time.Minute)

// If all 3 validators submit pfd - it will take too long to produce a new block
for i := 0; i < 10; i++ {
runenv.RecordMessage("Submitting PFD with 90k bytes random data")
err = appcmd.PayForData(
appcmd.AccountAddress,
50000,
"test",
appcmd.GetHomePath(),
)
if err != nil {
runenv.RecordFailure(err)
return err
}

s, err := appkit.GetLatestsBlockSize(net.ParseIP("127.0.0.1"))
if err != nil {
runenv.RecordMessage("err in last size call, %s", err.Error())
}

runenv.RecordMessage("latest size on iteration %d of the block is - %d", i, s)
}

time.Sleep(30 * time.Second)
runenv.RecordSuccess()

return nil
}
16 changes: 16 additions & 0 deletions tests/common/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Package common is a helper around redundant creation of App or Node part

In order to eliminate the boilerplate code of creating a validators' set,
please use `common.BuildValidator`. This Func does:
- InitChain
- Add-Gen-Account
- Collect-GenTxs
- Add-Persistent-Peers
In addition, the func returns initialized cobra cmd, so you can continue
operating with the validator

appcmd, err := common.BuildValidator(ctx, runenv, initCtx)
appcmd.PayForData(...)
*/
package common
Loading