Skip to content

Commit

Permalink
test(e2e): improvements (#17)
Browse files Browse the repository at this point in the history
The main benefit of this change is to print the node logs when no blocks are produced. For that, because the nodes are running in a docker container, the docker API logs is requested.

Also:
- call `t.Run()` appropriately: some calls were irrelevant, like when they are used to execute a command which is a part of a test case.
- rename test cases appropriately
- print a hint "is the docker image up-to-date?" when the node don't produce block, because most of the time it is the reason.
- increase speed by removing some sleeps and reducing the `Eventually` tick parameter
- improve http request error handling by checking the response status, and eventually retry if the status is "Service Unavailable"
- add test on gov param change
- update `/atomone.gov.v1.Params` query so it doesn't return an error if paramType is not provided (see 945497f)
  • Loading branch information
tbruyelle authored Sep 23, 2024
1 parent 1862d11 commit 23ae3ea
Show file tree
Hide file tree
Showing 17 changed files with 505 additions and 446 deletions.
9 changes: 9 additions & 0 deletions tests/e2e/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distribtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
paramsproptypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

Expand All @@ -37,16 +40,22 @@ var (

func init() {
encodingConfig = atomoneparams.MakeEncodingConfig()
sdk.RegisterInterfaces(encodingConfig.InterfaceRegistry)
tx.RegisterInterfaces(encodingConfig.InterfaceRegistry)
banktypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
authtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
authvesting.RegisterInterfaces(encodingConfig.InterfaceRegistry)
stakingtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
slashingtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
evidencetypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
cryptocodec.RegisterInterfaces(encodingConfig.InterfaceRegistry)
feegrant.RegisterInterfaces(encodingConfig.InterfaceRegistry)
govv1types.RegisterInterfaces(encodingConfig.InterfaceRegistry)
govv1beta1types.RegisterInterfaces(encodingConfig.InterfaceRegistry)
paramsproptypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
paramsproptypes.RegisterLegacyAminoCodec(encodingConfig.Amino)
feegrant.RegisterLegacyAminoCodec(encodingConfig.Amino)
slashingtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)

upgradetypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
distribtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/e2e_bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (s *IntegrationTestSuite) testBankTokenTransfer() {
s.Run("send_tokens_between_accounts", func() {
s.Run("send tokens between accounts", func() {
var (
err error
valIdx = 0
Expand Down Expand Up @@ -43,7 +43,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() {
return beforeAliceUAtoneBalance.IsValid() && beforeBobUAtoneBalance.IsValid() && beforeCharlieUAtoneBalance.IsValid()
},
10*time.Second,
5*time.Second,
time.Second,
)

// alice sends tokens to bob
Expand All @@ -64,7 +64,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() {
return decremented && incremented
},
10*time.Second,
5*time.Second,
time.Second,
)

// save the updated account balances of alice and bob
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *IntegrationTestSuite) testBankTokenTransfer() {
return decremented && incremented
},
10*time.Second,
5*time.Second,
time.Second,
)
})
}
92 changes: 47 additions & 45 deletions tests/e2e/e2e_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,51 @@ import (
)

func (s *IntegrationTestSuite) testDistribution() {
chainEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp"))

validatorB := s.chainA.validators[1]
validatorBAddr, _ := validatorB.keyInfo.GetAddress()

valOperAddressA := sdk.ValAddress(validatorBAddr).String()

delegatorAddress, _ := s.chainA.genesisAccounts[2].keyInfo.GetAddress()

newWithdrawalAddress, _ := s.chainA.genesisAccounts[3].keyInfo.GetAddress()
fees := sdk.NewCoin(uatoneDenom, sdk.NewInt(1000))

beforeBalance, err := getSpecificBalance(chainEndpoint, newWithdrawalAddress.String(), uatoneDenom)
s.Require().NoError(err)
if beforeBalance.IsNil() {
beforeBalance = sdk.NewCoin(uatoneDenom, sdk.NewInt(0))
}

s.execSetWithdrawAddress(s.chainA, 0, fees.String(), delegatorAddress.String(), newWithdrawalAddress.String(), atomoneHomePath)

// Verify
s.Require().Eventually(
func() bool {
res, err := queryDelegatorWithdrawalAddress(chainEndpoint, delegatorAddress.String())
s.Require().NoError(err)

return res.WithdrawAddress == newWithdrawalAddress.String()
},
10*time.Second,
5*time.Second,
)

s.execWithdrawReward(s.chainA, 0, delegatorAddress.String(), valOperAddressA, atomoneHomePath)
s.Require().Eventually(
func() bool {
afterBalance, err := getSpecificBalance(chainEndpoint, newWithdrawalAddress.String(), uatoneDenom)
s.Require().NoError(err)

return afterBalance.IsGTE(beforeBalance)
},
10*time.Second,
5*time.Second,
)
s.Run("distribution", func() {
chainEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp"))

validatorB := s.chainA.validators[1]
validatorBAddr, _ := validatorB.keyInfo.GetAddress()

valOperAddressA := sdk.ValAddress(validatorBAddr).String()

delegatorAddress, _ := s.chainA.genesisAccounts[2].keyInfo.GetAddress()

newWithdrawalAddress, _ := s.chainA.genesisAccounts[3].keyInfo.GetAddress()
fees := sdk.NewCoin(uatoneDenom, sdk.NewInt(1000))

beforeBalance, err := getSpecificBalance(chainEndpoint, newWithdrawalAddress.String(), uatoneDenom)
s.Require().NoError(err)
if beforeBalance.IsNil() {
beforeBalance = sdk.NewCoin(uatoneDenom, sdk.NewInt(0))
}

s.execSetWithdrawAddress(s.chainA, 0, fees.String(), delegatorAddress.String(), newWithdrawalAddress.String(), atomoneHomePath)

// Verify
s.Require().Eventually(
func() bool {
res, err := queryDelegatorWithdrawalAddress(chainEndpoint, delegatorAddress.String())
s.Require().NoError(err)

return res.WithdrawAddress == newWithdrawalAddress.String()
},
10*time.Second,
time.Second,
)

s.execWithdrawReward(s.chainA, 0, delegatorAddress.String(), valOperAddressA, atomoneHomePath)
s.Require().Eventually(
func() bool {
afterBalance, err := getSpecificBalance(chainEndpoint, newWithdrawalAddress.String(), uatoneDenom)
s.Require().NoError(err)

return afterBalance.IsGTE(beforeBalance)
},
10*time.Second,
time.Second,
)
})
}

/*
Expand Down Expand Up @@ -84,9 +86,9 @@ func (s *IntegrationTestSuite) fundCommunityPool() {
afterDistPhotonBalance, err := getSpecificBalance(chainAAPIEndpoint, distModuleAddress, tokenAmount.Denom)
s.Require().NoErrorf(err, "Error getting balance: %s", afterDistPhotonBalance)

return afterDistPhotonBalance.Sub(beforeDistUatoneBalance.Add(tokenAmount.Add(standardFees))).IsLT(marginOfErrorForBlockReward)
return beforeDistUatoneBalance.Add(tokenAmount.Add(standardFees)).Sub(afterDistPhotonBalance).IsLT(marginOfErrorForBlockReward)
},
15*time.Second,
5*time.Second,
time.Second,
)
}
4 changes: 2 additions & 2 deletions tests/e2e/e2e_evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
)

func (s *IntegrationTestSuite) testEvidence() {
s.Run("test evidence queries", func() {
func (s *IntegrationTestSuite) testEvidenceQueries() {
s.Run("queries", func() {
var (
valIdx = 0
chain = s.chainA
Expand Down
53 changes: 26 additions & 27 deletions tests/e2e/e2e_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package e2e
import (
"bytes"
"context"
"encoding/json"
"fmt"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/ory/dockertest/v3/docker"

rpchttp "github.com/cometbft/cometbft/rpc/client/http"

"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand Down Expand Up @@ -579,29 +579,22 @@ func (s *IntegrationTestSuite) execRedelegate(c *chain, valIdx int, amount, orig
s.T().Logf("%s successfully redelegated %s from %s to %s", delegatorAddr, amount, originalValOperAddress, newValOperAddress)
}

func (s *IntegrationTestSuite) getLatestBlockHeight(c *chain, valIdx int) int {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
func (s *IntegrationTestSuite) rpcClient(c *chain, valIdx int) *rpchttp.HTTP {
rc, err := rpchttp.New("tcp://"+s.valResources[c.id][valIdx].GetHostPort("26657/tcp"), "/websocket")
s.Require().NoError(err)
return rc
}

type syncInfo struct {
SyncInfo struct {
LatestHeight string `json:"latest_block_height"`
} `json:"SyncInfo"`
}
func (s *IntegrationTestSuite) getLatestBlockHeight(c *chain, valIdx int) int64 {
status, err := s.rpcClient(c, valIdx).Status(context.Background())
s.Require().NoError(err)
return status.SyncInfo.LatestBlockHeight
}

var currentHeight int
atomoneCommand := []string{atomonedBinary, "status"}
s.executeAtomoneTxCommand(ctx, c, atomoneCommand, valIdx, func(stdOut []byte, stdErr []byte) bool {
var (
err error
block syncInfo
)
s.Require().NoError(json.Unmarshal(stdOut, &block))
currentHeight, err = strconv.Atoi(block.SyncInfo.LatestHeight)
s.Require().NoError(err)
return currentHeight > 0
})
return currentHeight
func (s *IntegrationTestSuite) getLatestBlockTime(c *chain, valIdx int) time.Time {
status, err := s.rpcClient(c, valIdx).Status(context.Background())
s.Require().NoError(err)
return status.SyncInfo.LatestBlockTime
}

// func (s *IntegrationTestSuite) verifyBalanceChange(endpoint string, expectedAmount sdk.Coin, recipientAddress string) {
Expand All @@ -613,7 +606,7 @@ func (s *IntegrationTestSuite) getLatestBlockHeight(c *chain, valIdx int) int {
// return afterAtomBalance.IsEqual(expectedAmount)
// },
// 20*time.Second,
// 5*time.Second,
// time.Second,
// )
// }

Expand Down Expand Up @@ -730,7 +723,7 @@ func (s *IntegrationTestSuite) expectErrExecValidation(chain *chain, valIdx int,
return gotErr == expectErr
},
time.Minute,
5*time.Second,
time.Second,
"stdOut: %s, stdErr: %s",
string(stdOut), string(stdErr),
)
Expand All @@ -748,10 +741,16 @@ func (s *IntegrationTestSuite) defaultExecValidation(chain *chain, valIdx int) f
endpoint := fmt.Sprintf("http://%s", s.valResources[chain.id][valIdx].GetHostPort("1317/tcp"))
s.Require().Eventually(
func() bool {
return queryAtomOneTx(endpoint, txResp.TxHash) == nil
err := queryAtomOneTx(endpoint, txResp.TxHash)
if isErrNotFound(err) {
// tx not processed yet, continue
return false
}
s.Require().NoError(err)
return true
},
time.Minute,
5*time.Second,
time.Second,
"stdOut: %s, stdErr: %s",
string(stdOut), string(stdErr),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_feegrant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
//
// */
func (s *IntegrationTestSuite) testFeeGrant() {
s.Run("test fee grant module", func() {
s.Run("fee grant module", func() {
var (
valIdx = 0
c = s.chainA
Expand Down
Loading

0 comments on commit 23ae3ea

Please sign in to comment.