Skip to content

Commit

Permalink
feat(e2e): add e2e tests for the vesting module (#1738)
Browse files Browse the repository at this point in the history
* e2e vesting account tests

* rollback the `executeDelegate` changes

* fix the vesting accounts addresses

* add tests for Delayed Vesting Account

* fix test values

* fix flag from for periodic account create

* add periodic vesting account tests

* fix vesting account test assertions

* improve code quality

* fix periodic vesting balance

* transfer coins to pay the delegation fee for the permanent locked account

* fix create permanent locked account issue with a workaround

* avoid permanent locked and period tests run at the same time in parallel

* fix tx send logs and add more logs for debug

* fix wait time for vesting account

* debug log before unmarshall

* remove parallelism

* improve the code quality

* revert executeGaiaTxCommand changes

* revert e2e_util_test changes

* add logs for CI debug

* fix vesting test accounts for create vesting account command

* remove unused hdpath for create genesis account

* pass the docker user to the exec command

* fix config dir docker permission

* fix config folder permission from `777` to `755`

* parse chmod stderr

* avoid parse exec error

* remove chmod for the config dir

* debug chmod for keystore

* create wallets before init the chain

* add comment to `HDPath` method

* use the same binary name const

Co-authored-by: billy rennekamp <[email protected]>
  • Loading branch information
Pantani and okwme authored Oct 5, 2022
1 parent e7a13b1 commit 86f8649
Show file tree
Hide file tree
Showing 7 changed files with 745 additions and 35 deletions.
33 changes: 33 additions & 0 deletions tests/e2e/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package e2e

import (
"fmt"
"math/rand"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
)

// HDPath generates an HD path based on the wallet index
func HDPath(index int) string {
return fmt.Sprintf("m/44'/118'/0'/0/%d", index)
}

// PubKey returns a sample account PubKey
func PubKey() crypto.PubKey {
seed := []byte(strconv.Itoa(rand.Int()))
return ed25519.GenPrivKeyFromSecret(seed).PubKey()
}

// AccAddress returns a sample account address
func AccAddress() sdk.AccAddress {
addr := PubKey().Address()
return sdk.AccAddress(addr)
}

// Address returns a sample string account address
func Address() string {
return AccAddress().String()
}
6 changes: 5 additions & 1 deletion tests/e2e/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
gaia "github.com/cosmos/gaia/v8/app"
"github.com/cosmos/gaia/v8/app/params"
Expand Down Expand Up @@ -38,6 +39,7 @@ func init() {
&ed25519.PubKey{},
)

authvesting.RegisterInterfaces(encodingConfig.InterfaceRegistry)
cdc = encodingConfig.Codec
}

Expand All @@ -46,8 +48,10 @@ type chain struct {
dataDir string
id string
validators []*validator
accounts []*account
// initial accounts in genesis
genesisAccounts []*account
genesisAccounts []*account
genesisVestingAccounts map[string]sdk.AccAddress
}

func newChain() (*chain, error) {
Expand Down
88 changes: 88 additions & 0 deletions tests/e2e/e2e_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"path/filepath"
"strconv"
"strings"
"time"
Expand All @@ -21,6 +22,93 @@ import (
"github.com/ory/dockertest/v3/docker"
)

const (
flagFrom = "from"
flagHome = "home"
flagFees = "fees"
flagGas = "gas"
flagOutput = "output"
flagChainID = "chain-id"
flagBroadcastMode = "broadcast-mode"
flagKeyringBackend = "keyring-backend"
)

type flagOption func(map[string]interface{})

// withKeyValue add a new flag to command
func withKeyValue(key string, value interface{}) flagOption {
return func(o map[string]interface{}) {
o[key] = value
}
}

func applyOptions(chainID string, options []flagOption) map[string]interface{} {
opts := map[string]interface{}{
flagKeyringBackend: "test",
flagOutput: "json",
flagGas: "auto",
flagFrom: "alice",
flagBroadcastMode: "sync",
flagChainID: chainID,
flagHome: gaiaHomePath,
flagFees: fees.String(),
}
for _, apply := range options {
apply(opts)
}
return opts
}

func (s *IntegrationTestSuite) execVestingTx(
c *chain,
method string,
args []string,
opt ...flagOption,
) {
opts := applyOptions(c.id, opt)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

s.T().Logf("%s - Executing gaiad %s with %v", c.id, method, args)
gaiaCommand := []string{
gaiadBinary,
"tx",
"vesting",
method,
"-y",
}
gaiaCommand = append(gaiaCommand, args...)

for flag, value := range opts {
gaiaCommand = append(gaiaCommand, fmt.Sprintf("--%s=%v", flag, value))
}

s.executeGaiaTxCommand(ctx, c, gaiaCommand, 0, s.defaultExecValidation(c, 0))
s.T().Logf("successfully %s with %v", method, args)
}

func (s *IntegrationTestSuite) execCreatePermanentLockedAccount(
c *chain,
address,
amount string,
opt ...flagOption,
) {
s.T().Logf("Executing gaiad create a permanent locked vesting account %s", c.id)
s.execVestingTx(c, "create-permanent-locked-account", []string{address, amount}, opt...)
s.T().Logf("successfully created permanent locked vesting account %s with %s", address, amount)
}

func (s *IntegrationTestSuite) execCreatePeriodicVestingAccount(
c *chain,
address string,
opt ...flagOption,
) {
jsonPath := filepath.Join(gaiaHomePath, vestingPeriodFilePath)
s.T().Logf("Executing gaiad create periodic vesting account %s", c.id)
s.execVestingTx(c, "create-periodic-vesting-account", []string{address, jsonPath}, opt...)
s.T().Logf("successfully created periodic vesting account %s with %s", address, jsonPath)
}

func (s *IntegrationTestSuite) execBankSend(c *chain, valIdx int, from, to, amt, fees string, expectErr bool) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
Expand Down
Loading

0 comments on commit 86f8649

Please sign in to comment.