diff --git a/app/app.go b/app/app.go index ccd07b956c..973601bbc9 100644 --- a/app/app.go +++ b/app/app.go @@ -402,7 +402,7 @@ func New( app.AccountKeeper, app.BankKeeper, app.ZetaObserverKeeper, - app.FungibleKeeper, + &app.FungibleKeeper, ) app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper, group.Config{ MaxExecutionPeriod: 2 * time.Hour, // Two hours. diff --git a/testutil/keeper/zetacore.go b/testutil/keeper/crosschain.go similarity index 67% rename from testutil/keeper/zetacore.go rename to testutil/keeper/crosschain.go index 480104ef27..b5c66023e9 100644 --- a/testutil/keeper/zetacore.go +++ b/testutil/keeper/crosschain.go @@ -1,9 +1,6 @@ package keeper import ( - authkeeper2 "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper2 "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "github.com/zeta-chain/zetacore/x/crosschain/keeper" "testing" "github.com/cosmos/cosmos-sdk/codec" @@ -11,19 +8,22 @@ import ( "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" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + paramstypes "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" - "github.com/zeta-chain/zetacore/x/crosschain/types" - fungibleKeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" - zetaobserverKeeper "github.com/zeta-chain/zetacore/x/observer/keeper" - typesparams "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/zeta-chain/zetacore/x/crosschain/keeper" + "github.com/zeta-chain/zetacore/x/crosschain/types" + fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" + observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper" ) -func ZetacoreKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { +func CrosschainKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { storeKey := sdk.NewKVStoreKey(types.StoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) @@ -36,17 +36,17 @@ func ZetacoreKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { registry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(registry) - paramsSubspace := typesparams.NewSubspace(cdc, + paramsSubspace := paramstypes.NewSubspace(cdc, types.Amino, storeKey, memStoreKey, "ZetacoreParams", ) - bankkeeper := bankkeeper2.BaseKeeper{} - authkeeper := authkeeper2.AccountKeeper{} - zetaobserverKeeper := zetaobserverKeeper.Keeper{} - fungibleKeeper := fungibleKeeper.Keeper{} + bankKeeper := bankkeeper.BaseKeeper{} + authKeeper := authkeeper.AccountKeeper{} + observerKeeper := observerkeeper.Keeper{} + fungibleKeeper := fungiblekeeper.Keeper{} k := keeper.NewKeeper( codec.NewProtoCodec(registry), @@ -54,10 +54,10 @@ func ZetacoreKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { memStoreKey, stakingkeeper.Keeper{}, // custom paramsSubspace, - authkeeper, - bankkeeper, - zetaobserverKeeper, - fungibleKeeper, + authKeeper, + bankKeeper, + observerKeeper, + &fungibleKeeper, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/crosschain/genesis_test.go b/x/crosschain/genesis_test.go index 39dc4bd12b..1bfad7bdd0 100644 --- a/x/crosschain/genesis_test.go +++ b/x/crosschain/genesis_test.go @@ -1,12 +1,12 @@ package crosschain_test import ( - "github.com/zeta-chain/zetacore/x/crosschain" "testing" "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" + "github.com/zeta-chain/zetacore/x/crosschain" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -33,7 +33,7 @@ func TestGenesis(t *testing.T) { //}, } - k, ctx := keepertest.ZetacoreKeeper(t) + k, ctx := keepertest.CrosschainKeeper(t) crosschain.InitGenesis(ctx, *k, genesisState) got := crosschain.ExportGenesis(ctx, *k) require.NotNil(t, got) diff --git a/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go b/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go index c8efaf967a..f9fa2f597e 100644 --- a/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go @@ -19,7 +19,7 @@ import ( var _ = strconv.IntSize func TestInTxHashToCctxQuerySingle(t *testing.T) { - keeper, ctx := keepertest.ZetacoreKeeper(t) + keeper, ctx := keepertest.CrosschainKeeper(t) wctx := sdk.WrapSDKContext(ctx) msgs := createNInTxHashToCctx(keeper, ctx, 2) for _, tc := range []struct { @@ -70,7 +70,7 @@ func TestInTxHashToCctxQuerySingle(t *testing.T) { } func TestInTxHashToCctxQueryPaginated(t *testing.T) { - keeper, ctx := keepertest.ZetacoreKeeper(t) + keeper, ctx := keepertest.CrosschainKeeper(t) wctx := sdk.WrapSDKContext(ctx) msgs := createNInTxHashToCctx(keeper, ctx, 5) diff --git a/x/crosschain/keeper/in_tx_hash_to_cctx_test.go b/x/crosschain/keeper/in_tx_hash_to_cctx_test.go index e1784d1c35..3c8113b7ce 100644 --- a/x/crosschain/keeper/in_tx_hash_to_cctx_test.go +++ b/x/crosschain/keeper/in_tx_hash_to_cctx_test.go @@ -26,7 +26,7 @@ func createNInTxHashToCctx(keeper *keeper.Keeper, ctx sdk.Context, n int) []type } func TestInTxHashToCctxGet(t *testing.T) { - keeper, ctx := keepertest.ZetacoreKeeper(t) + keeper, ctx := keepertest.CrosschainKeeper(t) items := createNInTxHashToCctx(keeper, ctx, 10) for _, item := range items { rst, found := keeper.GetInTxHashToCctx(ctx, @@ -40,7 +40,7 @@ func TestInTxHashToCctxGet(t *testing.T) { } } func TestInTxHashToCctxRemove(t *testing.T) { - keeper, ctx := keepertest.ZetacoreKeeper(t) + keeper, ctx := keepertest.CrosschainKeeper(t) items := createNInTxHashToCctx(keeper, ctx, 10) for _, item := range items { keeper.RemoveInTxHashToCctx(ctx, @@ -54,7 +54,7 @@ func TestInTxHashToCctxRemove(t *testing.T) { } func TestInTxHashToCctxGetAll(t *testing.T) { - keeper, ctx := keepertest.ZetacoreKeeper(t) + keeper, ctx := keepertest.CrosschainKeeper(t) items := createNInTxHashToCctx(keeper, ctx, 10) require.ElementsMatch(t, nullify.Fill(items), diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index dd81b8f0c3..81218c877b 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -4,7 +4,6 @@ import ( "fmt" storetypes "github.com/cosmos/cosmos-sdk/store/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - fungibleModuleKeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" "github.com/tendermint/tendermint/libs/log" @@ -24,7 +23,7 @@ type ( authKeeper types.AccountKeeper bankKeeper types.BankKeeper zetaObserverKeeper types.ZetaObserverKeeper - fungibleKeeper fungibleModuleKeeper.Keeper + fungibleKeeper types.FungibleKeeper } ) @@ -37,7 +36,7 @@ func NewKeeper( authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, zetaObserverKeeper types.ZetaObserverKeeper, - fungibleKeeper fungibleModuleKeeper.Keeper, + fungibleKeeper types.FungibleKeeper, ) *Keeper { // ensure governance module account is set // FIXME: enable this check! (disabled for now to avoid unit test panic) diff --git a/x/crosschain/keeper/keeper_out_tx_tracker_test.go b/x/crosschain/keeper/keeper_out_tx_tracker_test.go index cc6db0be4c..9267871da6 100644 --- a/x/crosschain/keeper/keeper_out_tx_tracker_test.go +++ b/x/crosschain/keeper/keeper_out_tx_tracker_test.go @@ -30,7 +30,7 @@ func createNOutTxTracker(keeper *keeper.Keeper, ctx sdk.Context, n int) []types. } func TestOutTxTrackerGet(t *testing.T) { - keeper, ctx := keepertest.ZetacoreKeeper(t) + keeper, ctx := keepertest.CrosschainKeeper(t) items := createNOutTxTracker(keeper, ctx, 10) for _, item := range items { rst, found := keeper.GetOutTxTracker(ctx, @@ -45,7 +45,7 @@ func TestOutTxTrackerGet(t *testing.T) { } } func TestOutTxTrackerRemove(t *testing.T) { - k, ctx := keepertest.ZetacoreKeeper(t) + k, ctx := keepertest.CrosschainKeeper(t) items := createNOutTxTracker(k, ctx, 10) for _, item := range items { k.RemoveOutTxTracker(ctx, @@ -61,7 +61,7 @@ func TestOutTxTrackerRemove(t *testing.T) { } func TestOutTxTrackerGetAll(t *testing.T) { - keeper, ctx := keepertest.ZetacoreKeeper(t) + keeper, ctx := keepertest.CrosschainKeeper(t) items := createNOutTxTracker(keeper, ctx, 10) require.ElementsMatch(t, nullify.Fill(items), diff --git a/x/crosschain/keeper/keeper_test.go b/x/crosschain/keeper/keeper_test.go index 98014a4e27..d7ad574eb2 100644 --- a/x/crosschain/keeper/keeper_test.go +++ b/x/crosschain/keeper/keeper_test.go @@ -1,10 +1,6 @@ package keeper import ( - authkeeper2 "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper2 "github.com/cosmos/cosmos-sdk/x/bank/keeper" - fungibleKeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" - "github.com/zeta-chain/zetacore/x/observer/keeper" "testing" "github.com/cosmos/cosmos-sdk/codec" @@ -12,14 +8,18 @@ import ( "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" + 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" - "github.com/zeta-chain/zetacore/x/crosschain/types" - typesparams "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/zeta-chain/zetacore/x/crosschain/types" + fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" + "github.com/zeta-chain/zetacore/x/observer/keeper" ) func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { @@ -41,10 +41,10 @@ func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { memStoreKey, "ZetacoreParams", ) - bankkeeper := bankkeeper2.BaseKeeper{} - authkeeper := authkeeper2.AccountKeeper{} - zetaobserverKeeper := keeper.Keeper{} - fungibleKeeper := fungibleKeeper.Keeper{} + bankKeeper := bankkeeper.BaseKeeper{} + authKeeper := authkeeper.AccountKeeper{} + observerKeeper := keeper.Keeper{} + fungibleKeeper := fungiblekeeper.Keeper{} k := NewKeeper( codec.NewProtoCodec(registry), @@ -52,10 +52,10 @@ func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { memStoreKey, stakingkeeper.Keeper{}, // custom paramsSubspace, - authkeeper, - bankkeeper, - zetaobserverKeeper, - fungibleKeeper, + authKeeper, + bankKeeper, + observerKeeper, + &fungibleKeeper, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/crosschain/types/expected_keepers.go b/x/crosschain/types/expected_keepers.go index 1f0fa50b6c..319c76bd36 100644 --- a/x/crosschain/types/expected_keepers.go +++ b/x/crosschain/types/expected_keepers.go @@ -1,10 +1,16 @@ package types import ( + "math/big" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + eth "github.com/ethereum/go-ethereum/common" + evmtypes "github.com/evmos/ethermint/x/evm/types" "github.com/zeta-chain/zetacore/common" + + fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types" zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -54,8 +60,47 @@ type ZetaObserverKeeper interface { SetKeygen(ctx sdk.Context, keygen zetaObserverTypes.Keygen) SetPermissionFlags(ctx sdk.Context, permissionFlags zetaObserverTypes.PermissionFlags) SetLastObserverCount(ctx sdk.Context, lbc *zetaObserverTypes.LastObserverCount) - AddVoteToBallot(ctx sdk.Context, ballot zetaObserverTypes.Ballot, address string, observationType zetaObserverTypes.VoteType) (zetaObserverTypes.Ballot, error) + AddVoteToBallot( + ctx sdk.Context, + ballot zetaObserverTypes.Ballot, + address string, + observationType zetaObserverTypes.VoteType, + ) (zetaObserverTypes.Ballot, error) CheckIfFinalizingVote(ctx sdk.Context, ballot zetaObserverTypes.Ballot) (zetaObserverTypes.Ballot, bool) IsAuthorized(ctx sdk.Context, address string, chain *common.Chain) (bool, error) - FindBallot(ctx sdk.Context, index string, chain *common.Chain, observationType zetaObserverTypes.ObservationType) (ballot zetaObserverTypes.Ballot, isNew bool, err error) + FindBallot( + ctx sdk.Context, + index string, + chain *common.Chain, + observationType zetaObserverTypes.ObservationType, + ) (ballot zetaObserverTypes.Ballot, isNew bool, err error) +} + +type FungibleKeeper interface { + GetForeignCoins(ctx sdk.Context, zrc20Addr string) (val fungibletypes.ForeignCoins, found bool) + GetAllForeignCoinsForChain(ctx sdk.Context, foreignChainID int64) (list []fungibletypes.ForeignCoins) + GetSystemContract(ctx sdk.Context) (val fungibletypes.SystemContract, found bool) + QuerySystemContractGasCoinZRC20(ctx sdk.Context, chainID *big.Int) (eth.Address, error) + QueryUniswapv2RouterGetAmountsIn(ctx sdk.Context, amountOut *big.Int, outZRC4 eth.Address) (*big.Int, error) + SetGasPrice(ctx sdk.Context, chainID *big.Int, gasPrice *big.Int) (uint64, error) + DepositCoinZeta(ctx sdk.Context, to eth.Address, amount *big.Int) error + ZRC20DepositAndCallContract( + ctx sdk.Context, + to eth.Address, + amount *big.Int, + senderChain *common.Chain, + message string, + contract eth.Address, + data []byte, + coinType common.CoinType, + asset string, + ) (*evmtypes.MsgEthereumTxResponse, error) + CallUniswapv2RouterSwapExactETHForToken( + ctx sdk.Context, + sender eth.Address, + to eth.Address, + amountIn *big.Int, + outZRC4 eth.Address, + ) ([]*big.Int, error) + CallZRC20Burn(ctx sdk.Context, sender eth.Address, zrc20address eth.Address, amount *big.Int) error }