Skip to content

Commit

Permalink
remove foreign coin
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Sep 13, 2023
1 parent f14d311 commit b693cd0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
59 changes: 59 additions & 0 deletions x/fungible/keeper/msg_server_remove_foreign_coin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package keeper_test

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/testutil/sample"
"github.com/zeta-chain/zetacore/x/fungible/keeper"
"github.com/zeta-chain/zetacore/x/fungible/types"
"testing"
)

func TestMsgServer_RemoveForeignCoin(t *testing.T) {
t.Run("can remove a foreign coin", func(t *testing.T) {
k, ctx, sdkk, zk := keepertest.FungibleKeeper(t)
msgServer := keeper.NewMsgServerImpl(*k)
k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName)
admin := sample.AccAddress()
setAdminDeployFungibleCoin(ctx, zk, admin)
chainID := getValidChainID(t)

deploySystemContracts(t, ctx, k, sdkk.EvmKeeper)
zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foo", "foo")

_, found := k.GetForeignCoins(ctx, zrc20.Hex())
require.True(t, found)

_, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(admin, zrc20.Hex()))
require.NoError(t, err)
_, found = k.GetForeignCoins(ctx, zrc20.Hex())
require.False(t, found)
})

t.Run("should fail if not admin", func(t *testing.T) {
k, ctx, sdkk, _ := keepertest.FungibleKeeper(t)
msgServer := keeper.NewMsgServerImpl(*k)
k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName)
chainID := getValidChainID(t)

deploySystemContracts(t, ctx, k, sdkk.EvmKeeper)
zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foo", "foo")

_, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(sample.AccAddress(), zrc20.Hex()))
require.Error(t, err)
require.ErrorIs(t, err, sdkerrors.ErrUnauthorized)
})

t.Run("should fail if not found", func(t *testing.T) {
k, ctx, _, zk := keepertest.FungibleKeeper(t)
msgServer := keeper.NewMsgServerImpl(*k)
k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName)
admin := sample.AccAddress()
setAdminDeployFungibleCoin(ctx, zk, admin)

_, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(admin, sample.EthAddress().Hex()))
require.Error(t, err)
require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest)
})
}
16 changes: 0 additions & 16 deletions x/fungible/keeper/msg_server_test.go

This file was deleted.

0 comments on commit b693cd0

Please sign in to comment.