Skip to content

Commit

Permalink
feat(x/eth): disable eth module (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code authored Oct 31, 2023
1 parent 179c9eb commit e459990
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 190 deletions.
7 changes: 4 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
"github.com/functionx/fx-core/v6/x/erc20"
erc20keeper "github.com/functionx/fx-core/v6/x/erc20/keeper"
erc20types "github.com/functionx/fx-core/v6/x/erc20/types"
ethkeeper "github.com/functionx/fx-core/v6/x/eth/keeper"
ethtypes "github.com/functionx/fx-core/v6/x/eth/types"
fxevmkeeper "github.com/functionx/fx-core/v6/x/evm/keeper"
fxgovkeeper "github.com/functionx/fx-core/v6/x/gov/keeper"
Expand Down Expand Up @@ -446,7 +447,7 @@ func NewAppKeeper(
AddRoute(bsctypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.BscKeeper)).
AddRoute(polygontypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.PolygonKeeper)).
AddRoute(avalanchetypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.AvalancheKeeper)).
AddRoute(ethtypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.EthKeeper)).
AddRoute(ethtypes.ModuleName, ethkeeper.NewModuleHandler(appKeepers.EthKeeper)).
AddRoute(arbitrumtypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.ArbitrumKeeper)).
AddRoute(optimismtypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.OptimismKeeper)).
AddRoute(layer2types.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.Layer2Keeper)).
Expand Down Expand Up @@ -493,8 +494,8 @@ func NewAppKeeper(
)

ibcTransferRouter := fxtypes.NewRouter().
AddRoute(gravitytypes.ModuleName, appKeepers.EthKeeper).
AddRoute(ethtypes.ModuleName, appKeepers.EthKeeper).
AddRoute(gravitytypes.ModuleName, appKeepers.Layer2Keeper).
AddRoute(ethtypes.ModuleName, appKeepers.Layer2Keeper).
AddRoute(bsctypes.ModuleName, appKeepers.BscKeeper).
AddRoute(polygontypes.ModuleName, appKeepers.PolygonKeeper).
AddRoute(trontypes.ModuleName, appKeepers.TronKeeper).
Expand Down
2 changes: 1 addition & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (appKeepers *AppKeepers) EvmPrecompiled() {

// cross chain precompile
transferRouter := fxtypes.NewRouter().
AddRoute(ethtypes.ModuleName, appKeepers.EthKeeper).
// AddRoute(ethtypes.ModuleName, appKeepers.EthKeeper).
AddRoute(bsctypes.ModuleName, appKeepers.BscKeeper).
AddRoute(polygontypes.ModuleName, appKeepers.PolygonKeeper).
AddRoute(trontypes.ModuleName, appKeepers.TronKeeper).
Expand Down
11 changes: 11 additions & 0 deletions x/eth/keeper/keeper_router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package keeper

import crosschainkeeper "github.com/functionx/fx-core/v6/x/crosschain/keeper"

func NewModuleHandler(keeper crosschainkeeper.Keeper) *crosschainkeeper.ModuleHandler {
return &crosschainkeeper.ModuleHandler{
QueryServer: keeper,
MsgServer: NewMsgServerImpl(keeper),
ProposalServer: keeper,
}
}
27 changes: 27 additions & 0 deletions x/eth/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package keeper

import (
"context"

"cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

crosschainkeeper "github.com/functionx/fx-core/v6/x/crosschain/keeper"
crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types"
)

var _ crosschaintypes.MsgServer = MsgServer{}

type MsgServer struct {
crosschainkeeper.MsgServer
}

func NewMsgServerImpl(keeper crosschainkeeper.Keeper) crosschaintypes.MsgServer {
return MsgServer{
MsgServer: crosschainkeeper.MsgServer{Keeper: keeper},
}
}

func (s MsgServer) SendToExternal(_ context.Context, _ *crosschaintypes.MsgSendToExternal) (*crosschaintypes.MsgSendToExternalResponse, error) {
return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "not supported")
}
7 changes: 3 additions & 4 deletions x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
bsctypes "github.com/functionx/fx-core/v6/x/bsc/types"
crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types"
"github.com/functionx/fx-core/v6/x/erc20/types"
ethtypes "github.com/functionx/fx-core/v6/x/eth/types"
"github.com/functionx/fx-core/v6/x/evm/precompiles/crosschain"
)

Expand Down Expand Up @@ -140,7 +139,7 @@ func (suite *PrecompileTestSuite) TestCancelSendToExternal() {
{
name: "ok - fip20 contract + evm token",
prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) {
moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName
pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom)
suite.Require().True(found)
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), pair.GetDenom())
Expand All @@ -160,7 +159,7 @@ func (suite *PrecompileTestSuite) TestCancelSendToExternal() {
{
name: "ok - address + evm token",
prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) {
moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName

suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

Expand Down Expand Up @@ -211,7 +210,7 @@ func (suite *PrecompileTestSuite) TestCancelSendToExternal() {
{
name: "ok - address + wrapper origin token",
prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) {
moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName
pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom)
suite.Require().True(found)

Expand Down
2 changes: 1 addition & 1 deletion x/evm/precompiles/crosschain/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (suite *PrecompileTestSuite) CrossChainKeepers() map[string]CrossChainKeepe
cck := value.Field(i).Interface().(CrossChainKeeper)
if chainName == "bridge-eth" {
// keepers["gravity"] = cck
keepers["eth"] = cck
// keepers["eth"] = cck
} else {
keepers[chainName] = cck
}
Expand Down
175 changes: 2 additions & 173 deletions x/evm/precompiles/crosschain/crosschain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,111 +114,6 @@ func (suite *PrecompileTestSuite) TestCrossChain() {
},
result: true,
},
{
name: "ok - address - origin token",
malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) {
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(),
sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))))

balance := suite.app.BankKeeper.GetBalance(suite.ctx, signer.AccAddress(), fxtypes.DefaultDenom)
suite.Require().Equal(randMint.String(), balance.Amount.BigInt().String())
moduleName := ethtypes.ModuleName

suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

data, err := crosschain.GetABI().Pack(
"crossChain",
common.HexToAddress(fxtypes.EmptyEvmAddress),
helpers.GenerateAddressByModule(moduleName),
randMint,
big.NewInt(0),
fxtypes.MustStrToByte32(moduleName),
"",
)
suite.Require().NoError(err)

pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom)
suite.Require().True(found)

return data, &pair, randMint, moduleName, nil
},
result: true,
},
{
name: "ok - address - origin erc20 token",
malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) {
moduleName := ethtypes.ModuleName
denomAddr := helpers.GenerateAddress().String()
alias := fmt.Sprintf("%s%s", moduleName, denomAddr)

suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, denomAddr, alias)

token, err := suite.DeployContract(signer.Address())
suite.Require().NoError(err)

suite.MintERC20Token(signer, token, signer.Address(), randMint)
balOf := suite.BalanceOf(token, signer.Address())
suite.Require().Equal(randMint.String(), balOf.String())

pair, err := suite.app.Erc20Keeper.RegisterNativeERC20(suite.ctx, token, alias)
suite.Require().NoError(err)

suite.ERC20Approve(signer, token, crosschain.GetAddress(), randMint)

data, err := crosschain.GetABI().Pack(
"crossChain",
pair.GetERC20Contract(),
helpers.GenerateAddressByModule(moduleName),
randMint,
big.NewInt(0),
fxtypes.MustStrToByte32(moduleName),
"",
)
suite.Require().NoError(err)

return data, pair, big.NewInt(0), moduleName, nil
},
result: true,
},
{
name: "ok - address - wrapper origin token",
malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) {
pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom)
suite.Require().True(found)

moduleName := ethtypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

coin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(), sdk.NewCoins(coin))

balance := suite.app.BankKeeper.GetBalance(suite.ctx, signer.AccAddress(), fxtypes.DefaultDenom)
suite.Require().Equal(randMint.String(), balance.Amount.BigInt().String())

_, err := suite.app.Erc20Keeper.ConvertCoin(sdk.WrapSDKContext(suite.ctx), &types.MsgConvertCoin{
Coin: coin,
Receiver: signer.Address().Hex(),
Sender: signer.AccAddress().String(),
})
suite.Require().NoError(err)

suite.ERC20Approve(signer, pair.GetERC20Contract(), crosschain.GetAddress(), randMint)

data, err := crosschain.GetABI().Pack(
"crossChain",
pair.GetERC20Contract(),
helpers.GenerateAddressByModule(moduleName),
randMint,
big.NewInt(0),
fxtypes.MustStrToByte32(moduleName),
"",
)
suite.Require().NoError(err)

return data, &pair, big.NewInt(0), moduleName, nil
},
result: true,
},
{
name: "ok - ibc token",
malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) {
Expand Down Expand Up @@ -279,7 +174,7 @@ func (suite *PrecompileTestSuite) TestCrossChain() {
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(),
sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))))

moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)
data, err := crosschain.GetABI().Pack(
"crossChain",
Expand Down Expand Up @@ -431,72 +326,6 @@ func (suite *PrecompileTestSuite) TestCrossChain() {
},
result: true,
},
{
name: "contract - ok - origin token",
malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) {
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(),
sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))))

moduleName := ethtypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

data, err := fxtypes.MustABIJson(testcontract.CrossChainTestMetaData.ABI).Pack(
"crossChain",
common.HexToAddress(fxtypes.EmptyEvmAddress),
helpers.GenerateAddressByModule(moduleName),
randMint,
big.NewInt(0),
fxtypes.MustStrToByte32(moduleName),
"",
)
suite.Require().NoError(err)

pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom)
suite.Require().True(found)

return data, &pair, randMint, moduleName, nil
},
result: true,
},
{
name: "contract - ok - address - wrapper origin token",
malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) {
pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom)
suite.Require().True(found)

moduleName := ethtypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

coin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(), sdk.NewCoins(coin))

balance := suite.app.BankKeeper.GetBalance(suite.ctx, signer.AccAddress(), fxtypes.DefaultDenom)
suite.Require().Equal(randMint.String(), balance.Amount.BigInt().String())

_, err := suite.app.Erc20Keeper.ConvertCoin(sdk.WrapSDKContext(suite.ctx), &types.MsgConvertCoin{
Coin: coin,
Receiver: signer.Address().Hex(),
Sender: signer.AccAddress().String(),
})
suite.Require().NoError(err)

suite.ERC20Approve(signer, pair.GetERC20Contract(), suite.crosschain, randMint)

data, err := fxtypes.MustABIJson(testcontract.CrossChainTestMetaData.ABI).Pack(
"crossChain",
pair.GetERC20Contract(),
helpers.GenerateAddressByModule(moduleName),
randMint,
big.NewInt(0),
fxtypes.MustStrToByte32(moduleName),
"",
)
suite.Require().NoError(err)

return data, &pair, big.NewInt(0), moduleName, nil
},
result: true,
},
{
name: "contract - ok - ibc token",
malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) {
Expand Down Expand Up @@ -557,7 +386,7 @@ func (suite *PrecompileTestSuite) TestCrossChain() {
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(),
sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))))

moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)
data, err := fxtypes.MustABIJson(testcontract.CrossChainTestMetaData.ABI).Pack(
"crossChain",
Expand Down
5 changes: 2 additions & 3 deletions x/evm/precompiles/crosschain/fip20crosschain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
bsctypes "github.com/functionx/fx-core/v6/x/bsc/types"
crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types"
"github.com/functionx/fx-core/v6/x/erc20/types"
ethtypes "github.com/functionx/fx-core/v6/x/eth/types"
"github.com/functionx/fx-core/v6/x/evm/precompiles/crosschain"
)

Expand Down Expand Up @@ -79,7 +78,7 @@ func (suite *PrecompileTestSuite) TestFIP20CrossChain() {
coin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress().Bytes(), sdk.NewCoins(coin))

moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

fee := big.NewInt(1)
Expand Down Expand Up @@ -711,7 +710,7 @@ func (suite *PrecompileTestSuite) TestFIP20CrossChainIBC() {
coin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress().Bytes(), sdk.NewCoins(coin))

moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

fee := big.NewInt(1)
Expand Down
7 changes: 3 additions & 4 deletions x/evm/precompiles/crosschain/increase_bridgefee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
bsctypes "github.com/functionx/fx-core/v6/x/bsc/types"
crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types"
"github.com/functionx/fx-core/v6/x/erc20/types"
ethtypes "github.com/functionx/fx-core/v6/x/eth/types"
"github.com/functionx/fx-core/v6/x/evm/precompiles/crosschain"
)

Expand Down Expand Up @@ -155,7 +154,7 @@ func (suite *PrecompileTestSuite) TestIncreaseBridgeFee() {
{
name: "ok - fip20 contract + evm token",
prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) {
moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName
pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom)
suite.Require().True(found)
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), pair.GetDenom())
Expand All @@ -175,7 +174,7 @@ func (suite *PrecompileTestSuite) TestIncreaseBridgeFee() {
{
name: "ok - address + evm token",
prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) {
moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName

suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

Expand Down Expand Up @@ -226,7 +225,7 @@ func (suite *PrecompileTestSuite) TestIncreaseBridgeFee() {
{
name: "ok - address + wrapper origin token",
prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) {
moduleName := ethtypes.ModuleName
moduleName := bsctypes.ModuleName
pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom)
suite.Require().True(found)

Expand Down
2 changes: 1 addition & 1 deletion x/gravity/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type msgServer struct {
crosschainkeeper.MsgServer
crosschaintypes.MsgServer
}

func NewMsgServerImpl(keeper crosschainkeeper.Keeper) types.MsgServer {
Expand Down

0 comments on commit e459990

Please sign in to comment.