Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
Browse files Browse the repository at this point in the history
…t-zetaclient-banned-addresses
  • Loading branch information
ws4charlie committed Feb 23, 2024
2 parents d7f7c82 + f15eb49 commit 371fd33
Show file tree
Hide file tree
Showing 58 changed files with 1,906 additions and 653 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: PR Testing

on:
push:
branches:
- develop
pull_request:
branches:
- develop
Expand Down
5 changes: 3 additions & 2 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper"

cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
Expand Down Expand Up @@ -165,7 +166,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
// Set a gas meter with limit 0 as to prevent an infinite gas meter attack
// during runTx.
newCtx = SetGasMeter(simulate, ctx, 0)
return newCtx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx")
return newCtx, cosmoserrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx")
}

newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas())
Expand All @@ -183,7 +184,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
"out of gas in location: %v; gasWanted: %d, gasUsed: %d",
rType.Descriptor, gasTx.GetGas(), newCtx.GasMeter().GasConsumed())

err = sdkerrors.Wrap(sdkerrors.ErrOutOfGas, log)
err = cosmoserrors.Wrap(sdkerrors.ErrOutOfGas, log)
default:
panic(r)
}
Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"time"

cosmoserrors "cosmossdk.io/errors"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand Down Expand Up @@ -776,10 +777,10 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
// VerifyAddressFormat verifies the address is compatible with ethereum
func VerifyAddressFormat(bz []byte) error {
if len(bz) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "invalid address; cannot be empty")
return cosmoserrors.Wrap(sdkerrors.ErrUnknownAddress, "invalid address; cannot be empty")
}
if len(bz) != AddrLen {
return sdkerrors.Wrapf(
return cosmoserrors.Wrapf(
sdkerrors.ErrUnknownAddress,
"invalid address length; got: %d, expect: %d", len(bz), AddrLen,
)
Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Unreleased

### Tests

* [1767](https://github.com/zeta-chain/node/pull/1767) - add unit tests for emissions module begin blocker

## Version: v13.0.0

* `zetaclientd start` : 2 inputs required from stdin
Expand Down Expand Up @@ -42,7 +48,9 @@
* [1584](https://github.com/zeta-chain/node/pull/1584) - allow to run E2E tests on any networks
* [1746](https://github.com/zeta-chain/node/pull/1746) - rename smoke tests to e2e tests
* [1753](https://github.com/zeta-chain/node/pull/1753) - fix gosec errors on usage of rand package

* [1762](https://github.com/zeta-chain/node/pull/1762) - improve coverage for fungibile module
* [1782](https://github.com/zeta-chain/node/pull/1782) - improve coverage for fungibile module system contract

### CI

Expand Down
102 changes: 75 additions & 27 deletions testutil/keeper/emissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,105 @@ package keeper
import (
"testing"

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
emissionsmocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/emissions"
"github.com/zeta-chain/zetacore/x/emissions/keeper"
"github.com/zeta-chain/zetacore/x/emissions/types"
observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper"
)

func EmissionsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
type EmissionMockOptions struct {
UseBankMock bool
UseStakingMock bool
UseObserverMock bool
UseAccountMock bool
}

func EmissionsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) {
return EmissionKeeperWithMockOptions(t, EmissionMockOptions{
UseBankMock: false,
UseStakingMock: false,
UseObserverMock: false,
})
}
func EmissionKeeperWithMockOptions(
t testing.TB,
mockOptions EmissionMockOptions,
) (*keeper.Keeper, sdk.Context, SDKKeepers, ZetaKeepers) {
SetConfig(false)
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

// Initialize local store
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
cdc := NewCodec()

// Create regular keepers
sdkKeepers := NewSDKKeepers(cdc, db, stateStore)

// Create zeta keepers
observerKeeperTmp := initObserverKeeper(
cdc,
db,
stateStore,
sdkKeepers.StakingKeeper,
sdkKeepers.SlashingKeeper,
sdkKeepers.ParamsKeeper,
)

zetaKeepers := ZetaKeepers{
ObserverKeeper: observerKeeperTmp,
}
var observerKeeper types.ObserverKeeper = observerKeeperTmp

// Create the fungible keeper
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
ctx := NewContext(stateStore)

// Initialize modules genesis
sdkKeepers.InitGenesis(ctx)
zetaKeepers.InitGenesis(ctx)

// Add a proposer to the context
ctx = sdkKeepers.InitBlockProposer(t, ctx)

// Initialize mocks for mocked keepers
var authKeeper types.AccountKeeper = sdkKeepers.AuthKeeper
var bankKeeper types.BankKeeper = sdkKeepers.BankKeeper
var stakingKeeper types.StakingKeeper = sdkKeepers.StakingKeeper
if mockOptions.UseAccountMock {
authKeeper = emissionsmocks.NewEmissionAccountKeeper(t)
}
if mockOptions.UseBankMock {
bankKeeper = emissionsmocks.NewEmissionBankKeeper(t)
}
if mockOptions.UseStakingMock {
stakingKeeper = emissionsmocks.NewEmissionStakingKeeper(t)
}
if mockOptions.UseObserverMock {
observerKeeper = emissionsmocks.NewEmissionObserverKeeper(t)
}

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"EmissionsParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
sdkKeepers.ParamsKeeper.Subspace(types.ModuleName),
authtypes.FeeCollectorName,
bankkeeper.BaseKeeper{},
stakingkeeper.Keeper{},
observerkeeper.Keeper{},
authkeeper.AccountKeeper{},
bankKeeper,
stakingKeeper,
observerKeeper,
authKeeper,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
k.SetParams(ctx, types.DefaultParams())
return k, ctx

return k, ctx, sdkKeepers, zetaKeepers
}
24 changes: 12 additions & 12 deletions testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
emissionsmodule "github.com/zeta-chain/zetacore/x/emissions"
emissionskeeper "github.com/zeta-chain/zetacore/x/emissions/keeper"
types2 "github.com/zeta-chain/zetacore/x/emissions/types"
emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types"
fungiblemodule "github.com/zeta-chain/zetacore/x/fungible"
fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper"
fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types"
Expand Down Expand Up @@ -98,16 +98,16 @@ type ZetaKeepers struct {
}

var moduleAccountPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
types2.ModuleName: nil,
types2.UndistributedObserverRewardsPool: nil,
types2.UndistributedTssRewardsPool: nil,
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionstypes.ModuleName: {authtypes.Minter},
emissionstypes.UndistributedObserverRewardsPool: nil,
emissionstypes.UndistributedTssRewardsPool: nil,
}

// ModuleAccountAddrs returns all the app's module account addresses.
Expand Down Expand Up @@ -375,7 +375,7 @@ func (zk ZetaKeepers) InitGenesis(ctx sdk.Context) {
crosschainmodule.InitGenesis(ctx, *zk.CrosschainKeeper, *crosschaintypes.DefaultGenesis())
}
if zk.EmissionsKeeper != nil {
emissionsmodule.InitGenesis(ctx, *zk.EmissionsKeeper, *types2.DefaultGenesis())
emissionsmodule.InitGenesis(ctx, *zk.EmissionsKeeper, *emissionstypes.DefaultGenesis())
}
if zk.FungibleKeeper != nil {
fungiblemodule.InitGenesis(ctx, *zk.FungibleKeeper, *fungibletypes.DefaultGenesis())
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/bank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/fungible.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/staking.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions testutil/keeper/mocks/emissions/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 371fd33

Please sign in to comment.