Skip to content

Commit

Permalink
wip: testing
Browse files Browse the repository at this point in the history
  • Loading branch information
boodyvo committed Oct 19, 2024
1 parent 9dbd8bd commit 9d86411
Show file tree
Hide file tree
Showing 108 changed files with 324 additions and 480 deletions.
32 changes: 22 additions & 10 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"cosmossdk.io/log"
sdkmath "cosmossdk.io/math"
tmdb "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmdb "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand Down Expand Up @@ -129,12 +129,13 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
txBytes, err := encodingConfig.TxConfig.TxEncoder()(stdTx)
require.NoError(t, err)

res := tApp.CheckTx(
abci.RequestCheckTx{
res, err := tApp.CheckTx(
&abci.RequestCheckTx{
Tx: txBytes,
Type: abci.CheckTxType_New,
},
)
require.NoError(t, err)

if tc.expectPass {
require.Zero(t, res.Code, res.Log)
Expand Down Expand Up @@ -172,7 +173,7 @@ func newBep3GenStateMulti(cdc codec.JSONCodec, deputyAddress sdk.AccAddress) app
Active: true,
DeputyAddress: deputyAddress,
FixedFee: sdkmath.NewInt(1000),
MinSwapAmount: sdk.OneInt(),
MinSwapAmount: sdkmath.OneInt(),
MaxSwapAmount: sdkmath.NewInt(1000000000000),
MinBlockLock: bep3types.DefaultMinBlockLock,
MaxBlockLock: bep3types.DefaultMaxBlockLock,
Expand Down Expand Up @@ -255,20 +256,31 @@ func TestAppAnteHandler_RejectMsgsInAuthz(t *testing.T) {
txBytes, err := encodingConfig.TxConfig.TxEncoder()(stdTx)
require.NoError(t, err)

resCheckTx := tApp.CheckTx(
abci.RequestCheckTx{
resCheckTx, err := tApp.CheckTx(
&abci.RequestCheckTx{
Tx: txBytes,
Type: abci.CheckTxType_New,
},
)
require.NoError(t, err)
require.Equal(t, resCheckTx.Code, tc.expectedCode, resCheckTx.Log)

resDeliverTx := tApp.DeliverTx(
abci.RequestDeliverTx{
Tx: txBytes,
//resDeliverTx := tApp.DeliverTx(
// abci.RequestDeliverTx{
// Tx: txBytes,
// },
//)
// TODO(boodyvo): validate if this is the correct way to test deliver tx
resDeliverTx, err := tApp.FinalizeBlock(
&abci.RequestFinalizeBlock{
Txs: [][]byte{txBytes},
},
)
require.Equal(t, resDeliverTx.Code, tc.expectedCode, resDeliverTx.Log)
require.NoError(t, err)
for _, tx := range resDeliverTx.TxResults {
require.Equal(t, tx.Code, tc.expectedCode, tx.Log)
}
//require.Equal(t, resDeliverTx.Code, tc.expectedCode, resDeliverTx.Log)
})
}
}
86 changes: 61 additions & 25 deletions app/ante/eip712_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ func (suite *EIP712TestSuite) createTestEIP712CosmosTxBuilder(
fee := legacytx.NewStdFee(gas, gasAmount)
accNumber := suite.tApp.GetAccountKeeper().GetAccount(suite.ctx, from).GetAccountNumber()

data := eip712.ConstructUntypedEIP712Data(chainId, accNumber, nonce, 0, fee, msgs, "", nil)
// chainID string,
// accnum,
// sequence,
// timeout uint64,
// fee legacytx.StdFee,
// msgs []sdk.Msg,
// memo string,
data := eip712.ConstructUntypedEIP712Data(chainId, accNumber, nonce, 0, fee, msgs, "")
typedData, err := eip712.WrapTxToTypedData(ethChainId, msgs, data, &eip712.FeeDelegationOptions{
FeePayer: from,
}, suite.tApp.GetEvmKeeper().GetParams(suite.ctx))
Expand All @@ -96,7 +103,7 @@ func (suite *EIP712TestSuite) createTestEIP712CosmosTxBuilder(

// Sign typedData
keyringSigner := tests.NewSigner(priv)
signature, pubKey, err := keyringSigner.SignByAddress(from, sigHash)
signature, pubKey, err := keyringSigner.SignByAddress(from, sigHash, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
suite.Require().NoError(err)
signature[crypto.RecoveryIDOffset] += 27 // Transform V from 0/1 to 27/28 according to the yellow paper

Expand Down Expand Up @@ -287,7 +294,7 @@ func (suite *EIP712TestSuite) SetupTest() {
suite.Require().NoError(err)
consAddress := sdk.ConsAddress(consPriv.PubKey().Address())

ctx := tApp.NewContext(false, tmproto.Header{
ctx := tApp.NewContextLegacy(false, tmproto.Header{
Height: tApp.LastBlockHeight() + 1,
ChainID: ChainID,
Time: time.Now().UTC(),
Expand Down Expand Up @@ -322,7 +329,7 @@ func (suite *EIP712TestSuite) SetupTest() {
tApp.GetAccountKeeper().SetAccount(ctx, valAcc)
_, testAddresses := app.GeneratePrivKeyAddressPairs(1)
valAddr := sdk.ValAddress(testAddresses[0].Bytes())
validator, err := stakingtypes.NewValidator(valAddr, consPriv.PubKey(), stakingtypes.Description{})
validator, err := stakingtypes.NewValidator(valAddr.String(), consPriv.PubKey(), stakingtypes.Description{})
suite.Require().NoError(err)
err = tApp.GetStakingKeeper().SetValidatorByConsAddr(ctx, validator)
suite.Require().NoError(err)
Expand Down Expand Up @@ -450,15 +457,21 @@ func (suite *EIP712TestSuite) SetupTest() {
}

func (suite *EIP712TestSuite) Commit() {
_ = suite.tApp.Commit()
_, err := suite.tApp.Commit()
suite.Require().NoError(err)
header := suite.ctx.BlockHeader()
header.Height += 1
suite.tApp.BeginBlock(abci.RequestBeginBlock{
Header: header,
// TODO(boodyvo): validate, as we cannot pass the header in full
suite.tApp.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: header.Height,
//Header: header,
})
//suite.tApp.BeginBlock(abci.RequestBeginBlock{
// Header: header,
//})

// update ctx
suite.ctx = suite.tApp.NewContext(false, header)
suite.ctx = suite.tApp.NewContextLegacy(false, header)
}

func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context) evmutiltypes.InternalEVMAddress {
Expand Down Expand Up @@ -638,24 +651,33 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
txBytes, err := encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx())
suite.Require().NoError(err)

resCheckTx := suite.tApp.CheckTx(
abci.RequestCheckTx{
resCheckTx, err := suite.tApp.CheckTx(
&abci.RequestCheckTx{
Tx: txBytes,
Type: abci.CheckTxType_New,
},
)
suite.Require().NoError(err)
if !tc.failCheckTx {
suite.Require().Equal(resCheckTx.Code, uint32(0), resCheckTx.Log)
} else {
suite.Require().NotEqual(resCheckTx.Code, uint32(0), resCheckTx.Log)
suite.Require().Contains(resCheckTx.Log, tc.errMsg)
}

resDeliverTx := suite.tApp.DeliverTx(
abci.RequestDeliverTx{
Tx: txBytes,
},
)
resDeliverTxs, err := suite.tApp.FinalizeBlock(
&abci.RequestFinalizeBlock{
Txs: [][]byte{txBytes},
})
suite.Require().NoError(err)
//resDeliverTx := suite.tApp.DeliverTx(
// abci.RequestDeliverTx{
// Tx: txBytes,
// },
//)

suite.Require().Len(resDeliverTxs.TxResults, 1)
resDeliverTx := resDeliverTxs.TxResults[0]

if tc.errMsg == "" {
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)
Expand Down Expand Up @@ -720,11 +742,18 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
)
txBytes, err := encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx())
suite.Require().NoError(err)
resDeliverTx := suite.tApp.DeliverTx(
abci.RequestDeliverTx{
Tx: txBytes,
},
)
resDeliverTxs, err := suite.tApp.FinalizeBlock(
&abci.RequestFinalizeBlock{
Txs: [][]byte{txBytes},
})
suite.Require().NoError(err)
suite.Require().Len(resDeliverTxs.TxResults, 1)
resDeliverTx := resDeliverTxs.TxResults[0]
//resDeliverTx := suite.tApp.DeliverTx(
// abci.RequestDeliverTx{
// Tx: txBytes,
// },
//)
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)

// validate hard
Expand Down Expand Up @@ -765,11 +794,18 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
)
txBytes, err = encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx())
suite.Require().NoError(err)
resDeliverTx = suite.tApp.DeliverTx(
abci.RequestDeliverTx{
Tx: txBytes,
},
)
resDeliverTxs, err = suite.tApp.FinalizeBlock(
&abci.RequestFinalizeBlock{
Txs: [][]byte{txBytes},
})
suite.Require().NoError(err)
suite.Require().Len(resDeliverTxs.TxResults, 1)
resDeliverTx = resDeliverTxs.TxResults[0]
//resDeliverTx = suite.tApp.DeliverTx(
// abci.RequestDeliverTx{
// Tx: txBytes,
// },
//)
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)

// validate hard & cdp should be repayed
Expand Down
4 changes: 2 additions & 2 deletions app/ante/min_gas_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestEvmMinGasFilter(t *testing.T) {
tApp := app.NewTestApp()
handler := ante.NewEvmMinGasFilter(tApp.GetEvmKeeper())

ctx := tApp.NewContext(true).WithBlockHeight(1).WithBlockTime(tmtime.Now())
ctx := tApp.NewContextLegacy(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
EvmDenom: "akava",
})
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestEvmMinGasFilter(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctx := tApp.NewContext(true).WithBlockHeight(1).WithBlockTime(tmtime.Now())
ctx := tApp.NewContextLegacy(true, tmproto.Header{Height: 1, Time: tmtime.Now()})

ctx = ctx.WithMinGasPrices(tc.minGasPrices)
mmd := MockAnteHandler{}
Expand Down
11 changes: 10 additions & 1 deletion app/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ func (tApp TestApp) InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(
}

// Initialize the chain
stateBytes, err := json.Marshal(genesisState)
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
//stateBytes, err := json.Marshal(genesisState)
if err != nil {
panic(err)
}
Expand All @@ -377,9 +378,17 @@ func (tApp TestApp) InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(
},
)
fmt.Println("chain initialized")
ctx := tApp.NewContextLegacy(true, tmproto.Header{})
fmt.Println("context for chain", ctx)
fmt.Println("trying to get acounts", tApp.GetAccountKeeper().GetAllAccounts(ctx))
fmt.Println("trying to get auctions", tApp.GetAuctionKeeper().GetAllAuctions(ctx))
fmt.Println("trying to get minter", tApp.GetMintKeeper().GetMinter(ctx))
_, err = tApp.Commit()
fmt.Println("chain committed: ", err)
_, err = tApp.FinalizeBlock(&abci.RequestFinalizeBlock{
// Height: app.LastBlockHeight() + 1,
// Hash: app.LastCommitID().Hash,
// NextValidatorsHash: valSet.Hash(),
Height: tApp.LastBlockHeight() + 1,
Hash: tApp.LastCommitID().Hash,
Time: genTime,
Expand Down
24 changes: 14 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21.0
toolchain go1.21.9

require (
cosmossdk.io/api v0.7.5
cosmossdk.io/core v0.11.1
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.4.1
Expand All @@ -21,15 +22,14 @@ require (
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.10
github.com/cosmos/cosmos-sdk/x/nft v0.1.1
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/iavl v1.2.0
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2
github.com/cosmos/ibc-go/modules/capability v1.0.1
github.com/cosmos/ibc-go/v8 v8.5.1
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.21.0
github.com/evmos/ethermint v0.0.0-00010101000000-000000000000
github.com/go-kit/kit v0.13.0
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.4
Expand Down Expand Up @@ -58,16 +58,16 @@ require (
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/iam v1.1.13 // indirect
cloud.google.com/go/storage v1.43.0 // indirect
cosmossdk.io/api v0.7.5 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/depinject v1.0.0 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
cosmossdk.io/x/feegrant v0.1.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/allegro/bigcache v1.2.1 // indirect
Expand All @@ -90,11 +90,12 @@ require (
github.com/cockroachdb/pebble v1.1.1 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/cosmos/rosetta v0.50.6 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand All @@ -110,7 +111,7 @@ require (
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
Expand All @@ -137,14 +138,15 @@ require (
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/goware/urlx v0.3.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.6 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.3 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
Expand Down Expand Up @@ -235,11 +237,12 @@ require (
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
nhooyr.io/websocket v1.8.10 // indirect
pgregory.net/rapid v1.1.0 // indirect
)

replace (
cosmossdk.io/core/comet => cosmossdk.io/core/comet v0.11.0
// Use the cosmos keyring code
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// Use cometbft fork of tendermint
Expand All @@ -251,7 +254,7 @@ replace (
//github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.47.10-iavl-v1-kava.1
//github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.50.10-test-patch 5f9239e3147358ef034bfc4d19aacb34e5ea2064
//github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.0.0-20241007153930-5f9239e31473
//github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.0.0-20241017192629-758b3de9ca82
//github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.0.0-20241018152705-551d7afde55e
github.com/cosmos/cosmos-sdk => ../cosmos-sdk

//github.com/cosmos/cosmos-sdk/store => cosmossdk.io/store v1.1.1
Expand All @@ -273,7 +276,8 @@ replace (
// first PR
//github.com/evmos/ethermint => github.com/kava-labs/ethermint v0.0.0-20241017145243-770ae9c06817
// second PR
github.com/evmos/ethermint => github.com/kava-labs/ethermint v0.0.0-20241017164116-201b6699fad7
//github.com/evmos/ethermint => github.com/kava-labs/ethermint v0.0.0-20241018210905-a6216604a483
github.com/evmos/ethermint => ../ethermint
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
// Downgraded to avoid bugs in following commits which causes "version does not exist" errors
Expand Down
Loading

0 comments on commit 9d86411

Please sign in to comment.