Skip to content

Commit

Permalink
Merge branch 'develop' into add_cancel_mb_event_for_discontinue_and_d…
Browse files Browse the repository at this point in the history
…elete
  • Loading branch information
fynnss authored Aug 3, 2023
2 parents 747c9fa + 3f580f7 commit cc195a9
Show file tree
Hide file tree
Showing 80 changed files with 9,343 additions and 4,184 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Test
name: Build

on:
push:
Expand Down Expand Up @@ -51,7 +51,3 @@ jobs:
- name: Test Build
run: |
make build
- name: Uint Test
run: |
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build/
vendor/
.local
.task
coverage.out
9 changes: 6 additions & 3 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ exclude:
- \.pb\.go$ # excludes all protobuf generated files
- \.pb\.gw\.go$ # excludes all protobuf generated files
- .*_mocks.go$ # excludes all protobuf generated files
- types/.*
- simulation/.*
- testutil/.*
- e2e/.*
- types/.*
- .*/cli/.*
- sdk/.*
- version/.*
- cmd/gnfd/.*
- internal/sequence/.*
- x/types/.*
- .*/simulation/.*
- x/gensp/.*
- .*/module.go
- .*/module_simulation.go

Expand Down
60 changes: 30 additions & 30 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
bz, _ := hex.DecodeString(test.TEST_PUBKEY)
faucetPubKey := &ethsecp256k1.PubKey{Key: bz}
err := suite.app.BankKeeper.SendCoins(suite.ctx, faucetPubKey.Address().Bytes(), acc.GetAddress(), sdk.Coins{sdk.Coin{
Denom: sdk.DefaultBondDenom,
Denom: test.TEST_TOKEN_NAME,
Amount: sdk.NewInt(100000000000000),
}})
if err != nil {
Expand All @@ -53,89 +53,89 @@ func (suite *AnteTestSuite) TestAnteHandler() {
"success - DeliverTx EIP712 signed Cosmos Tx MsgSend",
func() sdk.Tx {
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
return txBuilder.GetTx()
}, true, false, true,
},
{
"success - DeliverTx EIP712 signed Cosmos Tx MsgDelegate",
func() sdk.Tx {
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgDelegate(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgDelegate(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
return txBuilder.GetTx()
}, true, false, true,
},
{
"success - DeliverTx EIP712 signed Cosmos Tx MsgCreateValidator",
func() sdk.Tx {
gas := uint64(2e8)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgCreateValidator(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgCreateValidator(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
return txBuilder.GetTx()
}, true, false, true,
},
{
"success - DeliverTx EIP712 signed Cosmos Tx MsgGrantAllowance",
func() sdk.Tx {
gas := uint64(16e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712GrantAllowance(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712GrantAllowance(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
return txBuilder.GetTx()
}, true, false, true,
},
{
"success - DeliverTx EIP712 signed Cosmos Tx MsgEditValidator",
func() sdk.Tx {
gas := uint64(2e7)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgEditValidator(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgEditValidator(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
return txBuilder.GetTx()
}, true, false, true,
},
{
"success - DeliverTx EIP712 signed Cosmos Tx MsgSubmitProposalV1",
func() sdk.Tx {
gas := uint64(2e8)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSubmitProposalV1(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSubmitProposalV1(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
return txBuilder.GetTx()
}, true, false, true,
},
{
"success - DeliverTx EIP712 signed Cosmos Tx MsgGrant",
func() sdk.Tx {
gas := uint64(16e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgGrant(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgGrant(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
return txBuilder.GetTx()
}, true, false, true,
},
{
"fails - DeliverTx legacy msg MsgSubmitProposal v1beta",
func() sdk.Tx {
gas := uint64(2000000000)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
deposit := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(20)))
txBuilder := suite.CreateTestEIP712SubmitProposal(addr, privKey, "greenfield_9000-1", gas, fee, deposit)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
deposit := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(20)))
txBuilder := suite.CreateTestEIP712SubmitProposal(addr, privKey, test.TEST_CHAIN_ID, gas, fee, deposit)
return txBuilder.GetTx()
}, true, false, false,
},
{
"fails - DeliverTx unregistered msg type MsgSubmitEvidence",
func() sdk.Tx {
gas := uint64(2000000000)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgSubmitEvidence(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712MsgSubmitEvidence(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
return txBuilder.GetTx()
}, true, false, false,
},
{
"fails - DeliverTx EIP712 signed Cosmos Tx with wrong Chain ID",
func() sdk.Tx {
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, "ethermint_9002-1", gas, fee)
return txBuilder.GetTx()
}, true, false, false,
Expand All @@ -144,19 +144,19 @@ func (suite *AnteTestSuite) TestAnteHandler() {
"fails - DeliverTx EIP712 signed Cosmos Tx with different gas fees",
func() sdk.Tx {
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
txBuilder.SetGasLimit(uint64(300000))
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(30))))
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdkmath.NewInt(30))))
return txBuilder.GetTx()
}, true, false, false,
},
{
"fails - DeliverTx EIP712 signed Cosmos Tx with empty signature",
func() sdk.Tx {
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
sigsV2 := signing.SignatureV2{
PubKey: privKey.PubKey(),
}
Expand All @@ -169,8 +169,8 @@ func (suite *AnteTestSuite) TestAnteHandler() {
"fails - DeliverTx EIP712 signed Cosmos Tx with invalid sequence",
func() sdk.Tx {
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
nonce, err := suite.app.AccountKeeper.GetSequence(suite.ctx, addr)
suite.Require().NoError(err)
sigsV2 := signing.SignatureV2{
Expand All @@ -189,8 +189,8 @@ func (suite *AnteTestSuite) TestAnteHandler() {
"fails - DeliverTx EIP712 signed Cosmos Tx with invalid signMode",
func() sdk.Tx {
gas := uint64(12e3)
fee := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, "greenfield_9000-1", gas, fee)
fee := sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewIntFromUint64(gas)))
txBuilder := suite.CreateTestEIP712TxBuilderMsgSend(addr, privKey, test.TEST_CHAIN_ID, gas, fee)
nonce, err := suite.app.AccountKeeper.GetSequence(suite.ctx, addr)
suite.Require().NoError(err)
sigsV2 := signing.SignatureV2{
Expand Down
81 changes: 12 additions & 69 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ante_test

import (
"encoding/hex"
"encoding/json"
"fmt"
"math/big"
Expand All @@ -10,17 +9,11 @@ import (

sdkmath "cosmossdk.io/math"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/eth/ethsecp256k1"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/mock"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand All @@ -43,6 +36,7 @@ import (
"github.com/bnb-chain/greenfield/e2e/core"
"github.com/bnb-chain/greenfield/sdk/client/test"
"github.com/bnb-chain/greenfield/sdk/keys"
"github.com/bnb-chain/greenfield/testutil"
"github.com/bnb-chain/greenfield/testutil/sample"
)

Expand All @@ -61,10 +55,12 @@ func TestAnteTestSuite(t *testing.T) {

func (suite *AnteTestSuite) SetupTest() {
var encCfg params.EncodingConfig
suite.app, encCfg, _ = NewApp(baseapp.SetChainID("greenfield_9000-1"))
logger := log.NewNopLogger()
db := dbm.NewMemDB()
suite.app, encCfg, _ = testutil.NewTestApp(logger, db, nil, true, test.TEST_CHAIN_ID)

suite.ctx = suite.app.NewContext(false, tmproto.Header{Height: 2, ChainID: "greenfield_9000-1", Time: time.Now().UTC()})
suite.ctx = suite.ctx.WithMinGasPrices(sdk.NewDecCoins(sdk.NewDecCoin(sdk.DefaultBondDenom, sdk.OneInt()))) // set to 1 stake
suite.ctx = suite.app.NewUncachedContext(false, tmproto.Header{Height: 2, ChainID: test.TEST_CHAIN_ID, Time: time.Now().UTC()})
suite.ctx = suite.ctx.WithMinGasPrices(sdk.NewDecCoins(sdk.NewDecCoin(test.TEST_TOKEN_NAME, sdk.OneInt()))) // set to 1 stake

infCtx := suite.ctx.WithGasMeter(storetypes.NewInfiniteGasMeter())
err := suite.app.AccountKeeper.SetParams(infCtx, authtypes.DefaultParams())
Expand All @@ -84,13 +80,13 @@ func (suite *AnteTestSuite) SetupTest() {

func (suite *AnteTestSuite) CreateTestEIP712TxBuilderMsgSend(from sdk.AccAddress, priv keys.KeyManager, chainId string, gas uint64, gasAmount sdk.Coins) client.TxBuilder {
recipient := core.GenRandomAddr()
msgSend := banktypes.NewMsgSend(from, recipient, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1))))
msgSend := banktypes.NewMsgSend(from, recipient, sdk.NewCoins(sdk.NewCoin(test.TEST_TOKEN_NAME, sdkmath.NewInt(1))))
return suite.CreateTestEIP712CosmosTxBuilder(from, priv, chainId, gas, gasAmount, msgSend)
}

func (suite *AnteTestSuite) CreateTestEIP712TxBuilderMsgDelegate(from sdk.AccAddress, priv keys.KeyManager, chainId string, gas uint64, gasAmount sdk.Coins) client.TxBuilder {
validator := core.GenRandomAddr()
msgSend := stakingtypes.NewMsgDelegate(from, validator, sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(20)))
msgSend := stakingtypes.NewMsgDelegate(from, validator, sdk.NewCoin(test.TEST_TOKEN_NAME, sdkmath.NewInt(20)))
return suite.CreateTestEIP712CosmosTxBuilder(from, priv, chainId, gas, gasAmount, msgSend)
}

Expand All @@ -100,7 +96,7 @@ func (suite *AnteTestSuite) CreateTestEIP712MsgCreateValidator(from sdk.AccAddre
msgCreate, err := stakingtypes.NewMsgCreateValidator(
from,
privEd.PubKey(),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20)),
sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewInt(20)),
stakingtypes.NewDescription("moniker", "identity", "website", "security_contract", "details"),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
Expand All @@ -124,7 +120,7 @@ func (suite *AnteTestSuite) CreateTestEIP712SubmitProposal(from sdk.AccAddress,
}

func (suite *AnteTestSuite) CreateTestEIP712GrantAllowance(from sdk.AccAddress, priv keys.KeyManager, chainId string, gas uint64, gasAmount sdk.Coins) client.TxBuilder {
spendLimit := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 10))
spendLimit := sdk.NewCoins(sdk.NewInt64Coin(test.TEST_TOKEN_NAME, 10))
threeHours := time.Now().Add(3 * time.Hour)
basic := &feegrant.BasicAllowance{
SpendLimit: spendLimit,
Expand Down Expand Up @@ -173,7 +169,7 @@ func (suite *AnteTestSuite) CreateTestEIP712TxBuilderMsgSubmitProposalV1(from sd
msgCreate, err := stakingtypes.NewMsgCreateValidator(
from,
privEd.PubKey(),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20)),
sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewInt(20)),
stakingtypes.NewDescription("moniker", "indentity", "website", "security_contract", "details"),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
Expand All @@ -187,7 +183,7 @@ func (suite *AnteTestSuite) CreateTestEIP712TxBuilderMsgSubmitProposalV1(from sd
suite.Require().NoError(err)
msgSubmitProposal, err := govtypesv1.NewMsgSubmitProposal(
[]sdk.Msg{msgCreate},
sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(20))},
sdk.Coins{sdk.NewCoin(test.TEST_TOKEN_NAME, sdk.NewInt(20))},
from.String(),
"test", "test", "test",
)
Expand Down Expand Up @@ -265,56 +261,3 @@ func (suite *AnteTestSuite) CreateTestEIP712CosmosTxBuilder(
suite.Require().NoError(err)
return txBuilder
}

func NewApp(options ...func(baseApp *baseapp.BaseApp)) (*app.App, params.EncodingConfig, error) {
// create public key
privVal := mock.NewPV()
pubKey, _ := privVal.GetPubKey()

// create validator set with single validator
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
bz, _ := hex.DecodeString(test.TEST_PUBKEY)
faucetPubKey := &ethsecp256k1.PubKey{Key: bz}

acc := authtypes.NewBaseAccount(faucetPubKey.Address().Bytes(), faucetPubKey, 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
}

logger := log.NewNopLogger()
db := dbm.NewMemDB()
encCfg := app.MakeEncodingConfig()

nApp := app.New(
logger,
db,
nil,
true,
app.DefaultNodeHome,
0,
encCfg,
&app.AppConfig{CrossChain: app.NewDefaultAppConfig().CrossChain},
simtestutil.EmptyAppOptions{},
options...,
)

genesisState := app.NewDefaultGenesisState(encCfg.Marshaler)
genesisState, _ = simtestutil.GenesisStateWithValSet(nApp.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)

stateBytes, _ := json.MarshalIndent(genesisState, "", " ")

// Initialize the chain
nApp.InitChain(
abci.RequestInitChain{
ChainId: "greenfield_9000-1",
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)

return nApp, encCfg, nil
}
8 changes: 8 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ func (app *App) initModules(ctx sdk.Context) {

app.initBridge()
app.initStorage()
app.initGov()
}

func (app *App) initCrossChain() {
Expand All @@ -744,6 +745,13 @@ func (app *App) initStorage() {
storagemodulekeeper.RegisterCrossApps(app.StorageKeeper)
}

func (app *App) initGov() {
err := app.GovKeeper.RegisterCrossChainSyncParamsApp()
if err != nil {
panic(err)
}
}

// Name returns the name of the App
func (app *App) Name() string { return app.BaseApp.Name() }

Expand Down
Loading

0 comments on commit cc195a9

Please sign in to comment.