Skip to content

Commit

Permalink
fix: update e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Dec 1, 2023
1 parent 7e0b6fe commit 9a78160
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 75 deletions.
12 changes: 8 additions & 4 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ After running the `make install` command you should be able to use `seda-chaind

## Testing

To test run all tests:
To run all unit tests:
```bash
make test
make test-unit
```

To see test coverage:
To test run all tests:
```bash
make cover-html
```
```

To run end-to-end tests:
```bash
make test-e2e
```
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,13 @@ TEST_COVERAGE_PROFILE=coverage.txt
UNIT_TEST_TAGS = norace
TEST_RACE_TAGS = ""

# runs all tests
test: test-unit
test-race: test-unit-race

test-unit: ARGS=-timeout=10m -tags='$(UNIT_TEST_TAGS)'
test-unit: TEST_PACKAGES=$(PACKAGES_UNIT)
test-unit-cover: ARGS=-timeout=10m -tags='$(UNIT_TEST_TAGS)' -coverprofile=$(TEST_COVERAGE_PROFILE) -covermode=atomic
test-unit-cover: TEST_PACKAGES=$(PACKAGES_UNIT)
test-unit-race: ARGS=-timeout=10m -race -tags='$(TEST_RACE_TAGS)'
test-unit-race: TEST_PACKAGES=$(PACKAGES_UNIT)
test-e2e: docker-build-e2e
test-e2e: ARGS=-timeout=10m -v
test-e2e: TEST_PACKAGES=$(PACKAGES_E2E)
$(TEST_TARGETS): run-tests
Expand All @@ -214,17 +211,10 @@ cover-html: test-unit-cover
@echo "--> Opening in the browser"
@go tool cover -html=$(TEST_COVERAGE_PROFILE)

.PHONY: cover-html run-tests $(TEST_TARGETS) test test-race


###############################################################################
### Docker ###
###############################################################################

docker-build-e2e:
@docker build -t sedaprotocol/seda-chaind-e2e -f dockerfiles/Dockerfile.e2e .

.PHONY: docker-build-e2e
.PHONY: cover-html run-tests $(TEST_TARGETS) test test-race docker-build-e2e


###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.20"
ARG GO_VERSION="1.21"
ARG RUNNER_IMAGE="alpine:3.17"

# --------------------------------------------------------
Expand Down
11 changes: 2 additions & 9 deletions e2e/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import (

tmrand "github.com/cometbft/cometbft/libs/rand"

evidencetypes "cosmossdk.io/x/evidence/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/sedaprotocol/seda-chain/app"
"github.com/sedaprotocol/seda-chain/app/params"
)

const (
Expand All @@ -22,16 +18,13 @@ const (
)

var (
encodingConfig params.EncodingConfig
encodingConfig app.EncodingConfig
cdc codec.Codec
txConfig client.TxConfig
)

func init() {
encodingConfig = app.MakeEncodingConfig()
authvesting.RegisterInterfaces(encodingConfig.InterfaceRegistry)
stakingtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
evidencetypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
encodingConfig = app.GetEncodingConfig()
cdc = encodingConfig.Marshaler
txConfig = encodingConfig.TxConfig
}
Expand Down
5 changes: 3 additions & 2 deletions e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/suite"

"cosmossdk.io/math"
evidencetypes "cosmossdk.io/x/evidence/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
Expand Down Expand Up @@ -60,7 +61,7 @@ const (
)

var (
standardFees = sdk.NewCoin(asedaDenom, sdk.NewInt(330000))
standardFees = sdk.NewCoin(asedaDenom, math.NewInt(330000))
proposalCounter = 0
)

Expand Down Expand Up @@ -206,8 +207,8 @@ func (s *IntegrationTestSuite) initGenesis(c *chain) {

createValmsg, err := val.buildCreateValidatorMsg(selfDelegationCoin)
s.Require().NoError(err)
signedTx, err := val.signMsg(createValmsg)

signedTx, err := val.signMsg(createValmsg)
s.Require().NoError(err)

txRaw, err := cdc.MarshalJSON(signedTx)
Expand Down
26 changes: 0 additions & 26 deletions e2e/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package e2e
import (
"encoding/json"
"fmt"
"os"
"time"

"cosmossdk.io/math"
tmtypes "github.com/cometbft/cometbft/types"

"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -22,30 +20,6 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

func getGenDoc(path string) (*tmtypes.GenesisDoc, error) {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config
config.SetRoot(path)

genFile := config.GenesisFile()
doc := &tmtypes.GenesisDoc{}

if _, err := os.Stat(genFile); err != nil {
if !os.IsNotExist(err) {
return nil, err
}
} else {
var err error

doc, err = tmtypes.GenesisDocFromFile(genFile)
if err != nil {
return nil, fmt.Errorf("failed to read genesis doc from file: %w", err)
}
}

return doc, nil
}

func modifyGenesis(path, moniker, amountStr string, addrAll []sdk.AccAddress, globfees string, denom string) error {
serverCtx := server.NewDefaultContext()
config := serverCtx.Config
Expand Down
42 changes: 21 additions & 21 deletions e2e/validator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e

import (
"context"
"encoding/json"
"fmt"
"os"
Expand All @@ -23,7 +24,7 @@ import (
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
txsigning "github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/sedaprotocol/seda-chain/app"
Expand Down Expand Up @@ -72,22 +73,17 @@ func (v *validator) init() error {
config.SetRoot(v.configDir())
config.Moniker = v.moniker

genDoc, err := getGenDoc(v.configDir())
if err != nil {
return err
}

// TO-DO use existing genesis, if exists?
appState, err := json.MarshalIndent(app.ModuleBasics.DefaultGenesis(cdc), "", " ")
if err != nil {
return fmt.Errorf("failed to JSON encode app genesis state: %w", err)
}

genDoc.ChainID = v.chain.id
genDoc.Validators = nil
genDoc.AppState = appState
appGenesis := genutiltypes.NewAppGenesisWithVersion(v.chain.id, appState)

if err = genutil.ExportGenesisFile(genDoc, config.GenesisFile()); err != nil {
return fmt.Errorf("failed to export app genesis state: %w", err)
err = appGenesis.SaveAs(config.GenesisFile())
if err != nil {
return err
}

tmcfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config)
Expand Down Expand Up @@ -223,9 +219,9 @@ func (v *validator) createKey(name string) error {
func (v *validator) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error) {
description := stakingtypes.NewDescription(v.moniker, "", "", "", "")
commissionRates := stakingtypes.CommissionRates{
Rate: sdk.MustNewDecFromStr("0.1"),
MaxRate: sdk.MustNewDecFromStr("0.2"),
MaxChangeRate: sdk.MustNewDecFromStr("0.01"),
Rate: math.LegacyMustNewDecFromStr("0.1"),
MaxRate: math.LegacyMustNewDecFromStr("0.2"),
MaxChangeRate: math.LegacyMustNewDecFromStr("0.01"),
}

valPubKey, err := cryptocodec.FromTmPubKeyInterface(v.consensusKey.PubKey)
Expand All @@ -239,7 +235,7 @@ func (v *validator) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error) {
}

return stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(valAddr),
sdk.ValAddress(valAddr).String(),
valPubKey,
amount,
description,
Expand All @@ -259,10 +255,17 @@ func (v *validator) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) {
txBuilder.SetFeeAmount(sdk.NewCoins())
txBuilder.SetGasLimit(200000)

pk, err := v.keyInfo.GetPubKey()
if err != nil {
return nil, err
}

signerData := authsigning.SignerData{
ChainID: v.chain.id,
AccountNumber: 0,
Sequence: 0,
PubKey: pk,
Address: sdk.AccAddress(pk.Address()).String(),
}

// For SIGN_MODE_DIRECT, calling SetSignatures calls setSignerInfos on
Expand All @@ -273,11 +276,6 @@ func (v *validator) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) {
// Note: This line is not needed for SIGN_MODE_LEGACY_AMINO, but putting it
// also doesn't affect its generated sign bytes, so for code's simplicity
// sake, we put it here.
pk, err := v.keyInfo.GetPubKey()
if err != nil {
return nil, err
}

sig := txsigning.SignatureV2{
PubKey: pk,
Data: &txsigning.SingleSignatureData{
Expand All @@ -291,7 +289,9 @@ func (v *validator) signMsg(msgs ...sdk.Msg) (*sdktx.Tx, error) {
return nil, err
}

bytesToSign, err := encodingConfig.TxConfig.SignModeHandler().GetSignBytes(
bytesToSign, err := authsigning.GetSignBytesAdapter(
context.Background(),
encodingConfig.TxConfig.SignModeHandler(),
txsigning.SignMode_SIGN_MODE_DIRECT,
signerData,
txBuilder.GetTx(),
Expand Down

0 comments on commit 9a78160

Please sign in to comment.