Skip to content

Commit

Permalink
Merge pull request #132 from SigmaGmbH/refactor/integration-test
Browse files Browse the repository at this point in the history
Integration tests in vesting module for different types of validators
  • Loading branch information
MikkySnow authored Aug 20, 2024
2 parents da29da2 + 2934dd8 commit b5ef77c
Show file tree
Hide file tree
Showing 7 changed files with 1,549 additions and 811 deletions.
8 changes: 4 additions & 4 deletions x/compliance/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -62,9 +63,8 @@ func (suite *KeeperTestSuite) Setup(t *testing.T) {
address := common.BytesToAddress(priv.PubKey().Address().Bytes())

// consensus key
privCons, err := ethsecp256k1.GenerateKey()
require.NoError(t, err)
consAddress := sdk.ConsAddress(privCons.PubKey().Address())
pks := simtestutil.CreateTestPubKeys(1)
consAddress := sdk.ConsAddress(pks[0].Address())

header := testutil.NewHeader(
1, time.Now().UTC(), chainID, consAddress, nil, nil,
Expand All @@ -86,7 +86,7 @@ func (suite *KeeperTestSuite) Setup(t *testing.T) {

// Set Validator
valAddr := sdk.ValAddress(address.Bytes())
validator, err := stakingtypes.NewValidator(valAddr, privCons.PubKey(), stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(valAddr, pks[0], stakingtypes.Description{})
require.NoError(t, err)
validator = stakingkeeper.TestingUpdateValidator(&suite.app.StakingKeeper, suite.ctx, validator, true)
err = suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, validator.GetOperator())
Expand Down
42 changes: 17 additions & 25 deletions x/evm/handler_test.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package evm_test

import (
"errors"
"math/big"
"testing"
"time"

sdkmath "cosmossdk.io/math"
"github.com/gogo/protobuf/proto"

"cosmossdk.io/simapp"
"github.com/SigmaGmbH/librustgo"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmjson "github.com/cometbft/cometbft/libs/json"

"cosmossdk.io/simapp"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/cometbft/cometbft/version"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

feemarkettypes "swisstronik/x/feemarket/types"

"errors"

stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"

"swisstronik/app"
"swisstronik/crypto/ethsecp256k1"
"swisstronik/tests"
Expand All @@ -40,13 +39,7 @@ import (
"swisstronik/x/evm"
"swisstronik/x/evm/keeper"
"swisstronik/x/evm/types"

"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"

"github.com/SigmaGmbH/librustgo"
"github.com/cometbft/cometbft/version"
feemarkettypes "swisstronik/x/feemarket/types"
)

type EvmTestSuite struct {
Expand Down Expand Up @@ -79,9 +72,8 @@ func (suite *EvmTestSuite) DoSetupTest(t require.TestingT) {
suite.signer = tests.NewTestSigner(priv)
suite.from = address
// consensus key
priv, err = ethsecp256k1.GenerateKey()
require.NoError(t, err)
consAddress := sdk.ConsAddress(priv.PubKey().Address())
pks := simtestutil.CreateTestPubKeys(1)
consAddress := sdk.ConsAddress(pks[0].Address())

suite.app = app.Setup(func(app *app.App, genesis simapp.GenesisState) simapp.GenesisState {
if suite.dynamicTxFee {
Expand Down Expand Up @@ -161,7 +153,7 @@ func (suite *EvmTestSuite) DoSetupTest(t require.TestingT) {
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

valAddr := sdk.ValAddress(address.Bytes())
validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(valAddr, pks[0], stakingtypes.Description{})
require.NoError(t, err)

err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
Expand Down
36 changes: 16 additions & 20 deletions x/evm/keeper/keeper_sgxvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ import (
"math/big"
"time"

"github.com/SigmaGmbH/librustgo"

feemarkettypes "swisstronik/x/feemarket/types"

sdkmath "cosmossdk.io/math"
"cosmossdk.io/simapp"
"github.com/SigmaGmbH/librustgo"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmjson "github.com/cometbft/cometbft/libs/json"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/cometbft/cometbft/version"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"

"swisstronik/app"
Expand All @@ -30,18 +38,7 @@ import (
evmcommontypes "swisstronik/types"
"swisstronik/x/evm/types"
evmtypes "swisstronik/x/evm/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/cometbft/cometbft/version"
feemarkettypes "swisstronik/x/feemarket/types"
)

func (suite *KeeperTestSuite) SetupSGXVMTest() {
Expand Down Expand Up @@ -76,9 +73,8 @@ func (suite *KeeperTestSuite) SetupSGXVMAppWithT(t require.TestingT) {
suite.signer = tests.NewTestSigner(priv)

// consensus key
priv, err = ethsecp256k1.GenerateKey()
require.NoError(t, err)
suite.consAddress = sdk.ConsAddress(priv.PubKey().Address())
pks := simtestutil.CreateTestPubKeys(1)
suite.consAddress = sdk.ConsAddress(pks[0].Address())

suite.app = app.Setup(func(app *app.App, genesis simapp.GenesisState) simapp.GenesisState {
feemarketGenesis := feemarkettypes.DefaultGenesisState()
Expand Down Expand Up @@ -171,7 +167,7 @@ func (suite *KeeperTestSuite) SetupSGXVMAppWithT(t require.TestingT) {
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

valAddr := sdk.ValAddress(suite.address.Bytes())
validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(valAddr, pks[0], stakingtypes.Description{})
require.NoError(t, err)
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
require.NoError(t, err)
Expand Down
59 changes: 26 additions & 33 deletions x/evm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,48 @@ import (
"testing"
"time"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

sdkmath "cosmossdk.io/math"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

feemarkettypes "swisstronik/x/feemarket/types"

"cosmossdk.io/simapp"
"github.com/SigmaGmbH/librustgo"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmjson "github.com/cometbft/cometbft/libs/json"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/cometbft/cometbft/version"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"swisstronik/app"
"swisstronik/crypto/ethsecp256k1"
"swisstronik/encoding"
"swisstronik/server/config"
"swisstronik/tests"
evmcommontypes "swisstronik/types"
evmtypes "swisstronik/x/evm/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"

"swisstronik/utils"

"github.com/SigmaGmbH/librustgo"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/cometbft/cometbft/version"
evmtypes "swisstronik/x/evm/types"
feemarkettypes "swisstronik/x/feemarket/types"
)

type KeeperTestSuite struct {
Expand Down Expand Up @@ -141,9 +135,8 @@ func (suite *KeeperTestSuite) SetupAppWithT(t require.TestingT, chainID string)
suite.signer = tests.NewTestSigner(priv)

// consensus key
priv, err = ethsecp256k1.GenerateKey()
require.NoError(t, err)
suite.consAddress = sdk.ConsAddress(priv.PubKey().Address())
pks := simtestutil.CreateTestPubKeys(1)
suite.consAddress = sdk.ConsAddress(pks[0].Address())

suite.app = app.Setup(func(app *app.App, genesis simapp.GenesisState) simapp.GenesisState {
feemarketGenesis := feemarkettypes.DefaultGenesisState()
Expand Down Expand Up @@ -239,7 +232,7 @@ func (suite *KeeperTestSuite) SetupAppWithT(t require.TestingT, chainID string)
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

valAddr := sdk.ValAddress(suite.address.Bytes())
validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(valAddr, pks[0], stakingtypes.Description{})
require.NoError(t, err)
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
require.NoError(t, err)
Expand Down
36 changes: 16 additions & 20 deletions x/feemarket/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@ import (
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/cometbft/cometbft/version"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"swisstronik/app"
"swisstronik/crypto/ethsecp256k1"
Expand All @@ -29,16 +36,6 @@ import (
"swisstronik/utils"
evmtypes "swisstronik/x/evm/types"
"swisstronik/x/feemarket/types"

"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
"github.com/cometbft/cometbft/version"
)

type KeeperTestSuite struct {
Expand Down Expand Up @@ -86,9 +83,8 @@ func (suite *KeeperTestSuite) SetupApp() {
suite.signer = tests.NewTestSigner(priv)

// consensus key
priv, err = ethsecp256k1.GenerateKey()
require.NoError(t, err)
suite.consAddress = sdk.ConsAddress(priv.PubKey().Address())
pks := simtestutil.CreateTestPubKeys(1)
suite.consAddress = sdk.ConsAddress(pks[0].Address())

suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{
Height: 1,
Expand Down Expand Up @@ -126,7 +122,7 @@ func (suite *KeeperTestSuite) SetupApp() {
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

valAddr := sdk.ValAddress(suite.address.Bytes())
validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(valAddr, pks[0], stakingtypes.Description{})
require.NoError(t, err)
validator = stakingkeeper.TestingUpdateValidator(&suite.app.StakingKeeper, suite.ctx, validator, true)
err = suite.app.StakingKeeper.Hooks().AfterValidatorCreated(suite.ctx, validator.GetOperator())
Expand Down
Loading

0 comments on commit b5ef77c

Please sign in to comment.