Skip to content

Commit

Permalink
Revert "feat(x/eth): disable eth module (#111)"
Browse files Browse the repository at this point in the history
This reverts commit e459990.
  • Loading branch information
zakir-code committed Nov 7, 2023
1 parent a2b6a5d commit 0955a3f
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 55 deletions.
7 changes: 3 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ 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 @@ -447,7 +446,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, ethkeeper.NewModuleHandler(appKeepers.EthKeeper)).
AddRoute(ethtypes.ModuleName, crosschainkeeper.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 @@ -494,8 +493,8 @@ func NewAppKeeper(
)

ibcTransferRouter := fxtypes.NewRouter().
AddRoute(gravitytypes.ModuleName, appKeepers.Layer2Keeper).
AddRoute(ethtypes.ModuleName, appKeepers.Layer2Keeper).
AddRoute(gravitytypes.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
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: 0 additions & 11 deletions x/eth/keeper/keeper_router.go

This file was deleted.

27 changes: 0 additions & 27 deletions x/eth/keeper/msg_server.go

This file was deleted.

7 changes: 4 additions & 3 deletions x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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 @@ -139,7 +140,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 := bsctypes.ModuleName
moduleName := ethtypes.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 @@ -159,7 +160,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 := bsctypes.ModuleName
moduleName := ethtypes.ModuleName

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

Expand Down Expand Up @@ -210,7 +211,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 := bsctypes.ModuleName
moduleName := ethtypes.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: 173 additions & 2 deletions x/evm/precompiles/crosschain/crosschain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,111 @@ 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 @@ -174,7 +279,7 @@ func (suite *PrecompileTestSuite) TestCrossChain() {
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(),
sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))))

moduleName := bsctypes.ModuleName
moduleName := ethtypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)
data, err := crosschain.GetABI().Pack(
"crossChain",
Expand Down Expand Up @@ -326,6 +431,72 @@ 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 @@ -386,7 +557,7 @@ func (suite *PrecompileTestSuite) TestCrossChain() {
helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(),
sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint))))

moduleName := bsctypes.ModuleName
moduleName := ethtypes.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: 3 additions & 2 deletions x/evm/precompiles/crosschain/fip20crosschain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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 @@ -78,7 +79,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 := bsctypes.ModuleName
moduleName := ethtypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

fee := big.NewInt(1)
Expand Down Expand Up @@ -710,7 +711,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 := bsctypes.ModuleName
moduleName := ethtypes.ModuleName
suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom)

fee := big.NewInt(1)
Expand Down
7 changes: 4 additions & 3 deletions x/evm/precompiles/crosschain/increase_bridgefee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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 @@ -154,7 +155,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 := bsctypes.ModuleName
moduleName := ethtypes.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 @@ -174,7 +175,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 := bsctypes.ModuleName
moduleName := ethtypes.ModuleName

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

Expand Down Expand Up @@ -225,7 +226,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 := bsctypes.ModuleName
moduleName := ethtypes.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 {
crosschaintypes.MsgServer
crosschainkeeper.MsgServer
}

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

0 comments on commit 0955a3f

Please sign in to comment.