Skip to content

Commit

Permalink
fix(tests): Add Evmos metadata to integration network and refactor St…
Browse files Browse the repository at this point in the history
…ride and Osmosis Outpost tests (#2069)

* fix: refactor integration testing setup for stride

* fix: refactor testing for stride outpost

* run make format

* CHANGELOG

---------

Co-authored-by: Vvaradinov <Vvaradinov@users.noreply.github.com>
  • Loading branch information
Vvaradinov and Vvaradinov authored Nov 23, 2023
1 parent ca1491f commit 78042ae
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 520 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (cmn-precompile) [#2064](https://github.com/evmos/evmos/pull/2064) Handle all `fallback` and `receive` function cases
- (erc20) [#2066](https://github.com/evmos/evmos/pull/2066) Adjust ERC20 EVM extension allowance behavior to align with standard ERC20 smart contracts.
- (erc20) [#2067](https://github.com/evmos/evmos/pull/2067) Further alignments between ERC20 smart contracts and EVM extension.
- (stride-outpost) [#2069](https://github.com/evmos/evmos/pull/2069) Refactor `osmosis` and `stride` testing.

### Bug Fixes

Expand Down
22 changes: 3 additions & 19 deletions precompiles/bank/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,9 @@ func (s *PrecompileTestSuite) SetupTest() {
s.network = integrationNetwork

// Register EVMOS
evmosMetadata := banktypes.Metadata{
Description: "The native token of Evmos",
Base: bondDenom,
// NOTE: Denom units MUST be increasing
DenomUnits: []*banktypes.DenomUnit{
{
Denom: bondDenom,
Exponent: 0,
Aliases: []string{"aevmos"},
},
{
Denom: "aevmos",
Exponent: 18,
},
},
Name: "Evmos",
Symbol: "EVMOS",
Display: "aevmos",
}
evmosMetadata, found := s.network.App.BankKeeper.GetDenomMetaData(s.network.GetContext(), s.bondDenom)
s.Require().True(found, "expected evmos denom metadata")

tokenPair, err := s.network.App.Erc20Keeper.RegisterCoin(s.network.GetContext(), evmosMetadata)
s.Require().NoError(err, "failed to register coin")

Expand Down
40 changes: 26 additions & 14 deletions precompiles/outposts/stride/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
const receiver = "stride1rhe5leyt5w0mcwd9rpp93zqn99yktsxvyaqgd0"

func (s *PrecompileTestSuite) TestLiquidStakeEvent() {
denomID := s.app.Erc20Keeper.GetDenomMap(s.ctx, utils.BaseDenom)
tokenPair, ok := s.app.Erc20Keeper.GetTokenPair(s.ctx, denomID)
ctx := s.network.GetContext()
stateDB := s.network.GetStateDB()
denomID := s.network.App.Erc20Keeper.GetDenomMap(ctx, utils.BaseDenom)
tokenPair, ok := s.network.App.Erc20Keeper.GetTokenPair(ctx, denomID)
s.Require().True(ok, "expected token pair to be found")

testCases := []struct {
Expand All @@ -26,17 +28,17 @@ func (s *PrecompileTestSuite) TestLiquidStakeEvent() {
{
"success",
func() {
liquidStakeLog := s.stateDB.Logs()[0]
liquidStakeLog := stateDB.Logs()[0]
s.Require().Equal(liquidStakeLog.Address, s.precompile.Address())
// Check event signature matches the one emitted
event := s.precompile.ABI.Events[stride.EventTypeLiquidStake]
s.Require().Equal(event.ID, common.HexToHash(liquidStakeLog.Topics[0].Hex()))
s.Require().Equal(liquidStakeLog.BlockNumber, uint64(s.ctx.BlockHeight()))
s.Require().Equal(liquidStakeLog.BlockNumber, uint64(ctx.BlockHeight()))

var liquidStakeEvent stride.EventLiquidStake
err := cmn.UnpackLog(s.precompile.ABI, &liquidStakeEvent, stride.EventTypeLiquidStake, *liquidStakeLog)
s.Require().NoError(err)
s.Require().Equal(common.BytesToAddress(s.address.Bytes()), liquidStakeEvent.Sender)
s.Require().Equal(common.BytesToAddress(s.keyring.GetAccAddr(0)), liquidStakeEvent.Sender)
s.Require().Equal(common.HexToAddress(tokenPair.Erc20Address), liquidStakeEvent.Token)
s.Require().Equal(big.NewInt(1e18), liquidStakeEvent.Amount)
},
Expand All @@ -47,24 +49,26 @@ func (s *PrecompileTestSuite) TestLiquidStakeEvent() {
s.Run(tc.name, func() {
s.SetupTest()

err := s.precompile.EmitLiquidStakeEvent(s.ctx, s.stateDB, s.address, common.HexToAddress(tokenPair.Erc20Address), big.NewInt(1e18))
err := s.precompile.EmitLiquidStakeEvent(ctx, stateDB, s.keyring.GetAddr(0), common.HexToAddress(tokenPair.Erc20Address), big.NewInt(1e18))
s.Require().NoError(err)
tc.postCheck()
})
}
}

func (s *PrecompileTestSuite) TestRedeemEvent() {
bondDenom := s.app.StakingKeeper.BondDenom(s.ctx)
ctx := s.network.GetContext()
stateDB := s.network.GetStateDB()
bondDenom := s.network.App.StakingKeeper.BondDenom(ctx)
denomTrace := transfertypes.DenomTrace{
Path: fmt.Sprintf("%s/%s", portID, channelID),
BaseDenom: "st" + bondDenom,
}

stEvmos := denomTrace.IBCDenom()

denomID := s.app.Erc20Keeper.GetDenomMap(s.ctx, stEvmos)
tokenPair, ok := s.app.Erc20Keeper.GetTokenPair(s.ctx, denomID)
denomID := s.network.App.Erc20Keeper.GetDenomMap(ctx, stEvmos)
tokenPair, ok := s.network.App.Erc20Keeper.GetTokenPair(ctx, denomID)
s.Require().True(ok, "expected token pair to be found")

testCases := []struct {
Expand All @@ -74,19 +78,19 @@ func (s *PrecompileTestSuite) TestRedeemEvent() {
{
"success",
func() {
redeemLog := s.stateDB.Logs()[0]
redeemLog := stateDB.Logs()[0]
s.Require().Equal(redeemLog.Address, s.precompile.Address())
// Check event signature matches the one emitted
event := s.precompile.ABI.Events[stride.EventTypeRedeemStake]
s.Require().Equal(event.ID, common.HexToHash(redeemLog.Topics[0].Hex()))
s.Require().Equal(redeemLog.BlockNumber, uint64(s.ctx.BlockHeight()))
s.Require().Equal(redeemLog.BlockNumber, uint64(ctx.BlockHeight()))

var redeemEvent stride.EventRedeem
err := cmn.UnpackLog(s.precompile.ABI, &redeemEvent, stride.EventTypeRedeemStake, *redeemLog)
s.Require().NoError(err)
s.Require().Equal(common.BytesToAddress(s.address.Bytes()), redeemEvent.Sender)
s.Require().Equal(common.BytesToAddress(s.keyring.GetAccAddr(0)), redeemEvent.Sender)
s.Require().Equal(common.HexToAddress(tokenPair.Erc20Address), redeemEvent.Token)
s.Require().Equal(s.address, redeemEvent.Receiver)
s.Require().Equal(s.keyring.GetAddr(0), redeemEvent.Receiver)
s.Require().Equal(receiver, redeemEvent.StrideForwarder)
s.Require().Equal(big.NewInt(1e18), redeemEvent.Amount)
},
Expand All @@ -97,7 +101,15 @@ func (s *PrecompileTestSuite) TestRedeemEvent() {
s.Run(tc.name, func() {
s.SetupTest()

err := s.precompile.EmitRedeemStakeEvent(s.ctx, s.stateDB, s.address, common.HexToAddress(tokenPair.Erc20Address), s.address, receiver, big.NewInt(1e18))
err := s.precompile.EmitRedeemStakeEvent(
ctx,
stateDB,
s.keyring.GetAddr(0),
common.HexToAddress(tokenPair.Erc20Address),
s.keyring.GetAddr(0),
receiver,
big.NewInt(1e18),
)
s.Require().NoError(err)
tc.postCheck()
})
Expand Down
73 changes: 33 additions & 40 deletions precompiles/outposts/stride/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,54 @@ package stride_test

import (
"testing"
"time"

"github.com/evmos/evmos/v15/precompiles/outposts/stride"

tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
evmosapp "github.com/evmos/evmos/v15/app"
evmosibc "github.com/evmos/evmos/v15/ibc/testing"
"github.com/evmos/evmos/v15/x/evm/statedb"
evmtypes "github.com/evmos/evmos/v15/x/evm/types"

"github.com/evmos/evmos/v15/testutil/integration/common/grpc"
testkeyring "github.com/evmos/evmos/v15/testutil/integration/evmos/keyring"
"github.com/evmos/evmos/v15/testutil/integration/evmos/network"
"github.com/stretchr/testify/suite"
)

var s *PrecompileTestSuite
var _ *PrecompileTestSuite

type PrecompileTestSuite struct {
suite.Suite

ctx sdk.Context
app *evmosapp.Evmos
address common.Address
differentAddr common.Address
validators []stakingtypes.Validator
valSet *tmtypes.ValidatorSet
ethSigner ethtypes.Signer
privKey cryptotypes.PrivKey
signer keyring.Signer
bondDenom string
network *network.UnitTestNetwork
grpcHandler grpc.Handler
keyring testkeyring.Keyring

precompile *stride.Precompile
stateDB *statedb.StateDB

coordinator *ibctesting.Coordinator
chainA *ibctesting.TestChain
chainB *ibctesting.TestChain
transferPath *evmosibc.Path
queryClientEVM evmtypes.QueryClient

defaultExpirationDuration time.Time

suiteIBCTesting bool
}

func TestPrecompileTestSuite(t *testing.T) {
s = new(PrecompileTestSuite)
suite.Run(t, s)
suite.Run(t, new(PrecompileTestSuite))
}

func (s *PrecompileTestSuite) SetupTest() {
s.DoSetupTest()
keyring := testkeyring.New(2)
network := network.NewUnitTestNetwork(
network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...),
)

precompile, err := stride.NewPrecompile(
portID,
channelID,
network.App.TransferKeeper,
network.App.Erc20Keeper,
network.App.AuthzKeeper,
network.App.StakingKeeper,
)
s.Require().NoError(err, "expected no error during precompile creation")
s.precompile = precompile

grpcHandler := grpc.NewIntegrationHandler(network)

s.network = network
s.grpcHandler = grpcHandler
s.keyring = keyring
s.precompile = precompile

// Register stEvmos Coin as an ERC20 token
s.registerStrideCoinERC20()
}
Loading

0 comments on commit 78042ae

Please sign in to comment.