Skip to content

Commit

Permalink
test fixes 2
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jun 26, 2024
1 parent 65f6cbe commit 672da05
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 9 deletions.
11 changes: 11 additions & 0 deletions testutil/keeper/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/testutil/sample"
"github.com/zeta-chain/zetacore/x/authority/keeper"
"github.com/zeta-chain/zetacore/x/authority/types"
Expand Down Expand Up @@ -79,6 +80,16 @@ func MockCheckAuthorization(m *mock.Mock, msg sdk.Msg, authorizationResult error
m.On("CheckAuthorization", mock.Anything, msg).Return(authorizationResult).Once()
}

// MockGetChainList mocks the GetChainList method of the authority keeper.
func MockGetChainList(m *mock.Mock, chainList []chains.Chain) {
m.On("GetChainList", mock.Anything).Return(chainList).Once()
}

// MockGetChainListEmpty mocks the GetChainList method of the authority keeper.
func MockGetChainListEmpty(m *mock.Mock) {
m.On("GetChainList", mock.Anything).Return([]chains.Chain{})
}

func SetAdminPolicies(ctx sdk.Context, ak *keeper.Keeper) string {
admin := sample.AccAddress()
ak.SetPolicies(ctx, types.Policies{Items: []*types.Policy{
Expand Down
8 changes: 5 additions & 3 deletions x/authority/keeper/grpc_query_chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ func TestKeeper_ChainInfo(t *testing.T) {
t.Run("chain info not found", func(t *testing.T) {
k, ctx := keepertest.AuthorityKeeper(t)

chainInfo, err := k.ChainInfo(ctx, &types.QueryGetChainInfoRequest{})
res, err := k.ChainInfo(ctx, &types.QueryGetChainInfoRequest{})
require.NoError(t, err)
require.Equal(t, chainInfo, types.ChainInfo{
Chains: []chains.Chain{},
require.Equal(t, res, &types.QueryGetChainInfoResponse{
ChainInfo: types.ChainInfo{
Chains: []chains.Chain{},
},
})
})

Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func TestKeeper_ProcessZRC20WithdrawalEvent(t *testing.T) {
ctx = ctx.WithChainID("test_21-1")

err = k.ProcessZRC20WithdrawalEvent(ctx, event, emittingContract, txOrigin.Hex())
require.ErrorContains(t, err, "failed to convert chainID: chain 21 not found")
require.ErrorContains(t, err, "failed to convert chainID")
require.Empty(t, k.GetAllCrossChainTx(ctx))
})

Expand Down
4 changes: 4 additions & 0 deletions x/crosschain/keeper/msg_server_add_outbound_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) {
Nonce: 42,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.AddOutboundTracker(ctx, &msg)
require.NoError(t, err)
tracker, found := k.GetOutboundTracker(ctx, chainID, 42)
Expand Down Expand Up @@ -418,6 +419,7 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) {
Nonce: 42,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.AddOutboundTracker(ctx, &msg)
require.NoError(t, err)
tracker, found := k.GetOutboundTracker(ctx, chainID, 42)
Expand Down Expand Up @@ -500,6 +502,7 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) {
Nonce: 42,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.AddOutboundTracker(ctx, &msg)
require.ErrorIs(t, err, observertypes.ErrTssNotFound)
})
Expand Down Expand Up @@ -541,6 +544,7 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) {
Nonce: 42,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.AddOutboundTracker(ctx, &msg)
require.ErrorIs(t, err, types.ErrTxBodyVerificationFail)
})
Expand Down
5 changes: 5 additions & 0 deletions x/crosschain/keeper/msg_server_migrate_tss_funds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) {
Amount: amount,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.MigrateTssFunds(ctx, &msg)
require.NoError(t, err)
hash := crypto.Keccak256Hash([]byte(indexString))
Expand Down Expand Up @@ -141,6 +142,7 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) {
Amount: amount,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.MigrateTssFunds(ctx, &msg)
require.NoError(t, err)
hash := crypto.Keccak256Hash([]byte(indexString))
Expand Down Expand Up @@ -376,6 +378,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) {
Amount: amount,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.MigrateTssFunds(ctx, &msg)
require.NoError(t, err)
hash := crypto.Keccak256Hash([]byte(indexString))
Expand Down Expand Up @@ -406,6 +409,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) {
Amount: amount,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.MigrateTssFunds(ctx, &msg)
require.ErrorContains(t, err, crosschaintypes.ErrCannotMigrateTssFunds.Error())
hash := crypto.Keccak256Hash([]byte(indexString))
Expand Down Expand Up @@ -507,6 +511,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) {
Amount: amount,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.MigrateTssFunds(ctx, &msg)
require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds)
require.ErrorContains(t, err, "cannot migrate funds while there are pending migrations")
Expand Down
4 changes: 4 additions & 0 deletions x/crosschain/keeper/msg_server_refund_aborted_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) {
RefundAddress: cctx.InboundParams.Sender,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.RefundAbortedCCTX(ctx, &msg)
require.NoError(t, err)

Expand Down Expand Up @@ -160,6 +161,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) {
RefundAddress: cctx.InboundParams.Sender,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.RefundAbortedCCTX(ctx, &msg)
require.NoError(t, err)

Expand Down Expand Up @@ -274,6 +276,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) {
RefundAddress: refundAddress.String(),
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.RefundAbortedCCTX(ctx, &msg)
require.NoError(t, err)

Expand Down Expand Up @@ -325,6 +328,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) {
RefundAddress: cctx.InboundParams.Sender,
}
keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.RefundAbortedCCTX(ctx, &msg)
require.NoError(t, err)

Expand Down
8 changes: 4 additions & 4 deletions x/crosschain/keeper/msg_server_vote_inbound_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func TestKeeper_VoteInbound(t *testing.T) {
to, from := int64(1337), int64(101)
supportedChains := zk.ObserverKeeper.GetSupportedChains(ctx)
for _, chain := range supportedChains {
if chains.IsEVMChain(chain.ChainId) {
if chains.IsEVMChain(chain.ChainId, []chains.Chain{}) {
from = chain.ChainId
}
if chains.IsZetaChain(chain.ChainId) {
if chains.IsZetaChain(chain.ChainId, []chains.Chain{}) {
to = chain.ChainId
}
}
Expand Down Expand Up @@ -201,10 +201,10 @@ func TestKeeper_VoteInbound(t *testing.T) {
to, from := int64(1337), int64(101)
supportedChains := zk.ObserverKeeper.GetSupportedChains(ctx)
for _, chain := range supportedChains {
if chains.IsEVMChain(chain.ChainId) {
if chains.IsEVMChain(chain.ChainId, []chains.Chain{}) {
from = chain.ChainId
}
if chains.IsZetaChain(chain.ChainId) {
if chains.IsZetaChain(chain.ChainId, []chains.Chain{}) {
to = chain.ChainId
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) {
1000000,
)
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
res, err := msgServer.DeployFungibleCoinZRC20(ctx, msg)
require.NoError(t, err)
gasAddress := res.Address
Expand Down Expand Up @@ -174,6 +175,7 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) {
1000000,
)
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, msg)
require.Error(t, err)
require.ErrorIs(t, err, observertypes.ErrSupportedChains)
Expand Down Expand Up @@ -203,6 +205,7 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) {
1000000,
)
keepertest.MockCheckAuthorization(&authorityMock.Mock, deployMsg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)

// Attempt to deploy the same gas token twice should result in error
_, err := keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg)
Expand Down
2 changes: 2 additions & 0 deletions x/fungible/keeper/msg_server_remove_foreign_coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestMsgServer_RemoveForeignCoin(t *testing.T) {

msg := types.NewMsgRemoveForeignCoin(admin, zrc20.Hex())
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.RemoveForeignCoin(ctx, msg)
require.NoError(t, err)
_, found = k.GetForeignCoins(ctx, zrc20.Hex())
Expand All @@ -59,6 +60,7 @@ func TestMsgServer_RemoveForeignCoin(t *testing.T) {

msg := types.NewMsgRemoveForeignCoin(admin, zrc20.Hex())
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, authoritytypes.ErrUnauthorized)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err := msgServer.RemoveForeignCoin(ctx, msg)
require.Error(t, err)
require.ErrorIs(t, err, authoritytypes.ErrUnauthorized)
Expand Down
2 changes: 2 additions & 0 deletions x/fungible/keeper/msg_server_update_contract_bytecode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) {
codeHash,
)
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateContractBytecode(ctx, msg)
require.NoError(t, err)

Expand Down Expand Up @@ -147,6 +148,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) {
codeHash,
)
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateContractBytecode(ctx, msg)
require.NoError(t, err)
balance, err = k.BalanceOfZRC4(ctx, zrc20, addr1)
Expand Down
4 changes: 4 additions & 0 deletions x/fungible/keeper/msg_server_update_system_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestKeeper_UpdateSystemContract(t *testing.T) {
// can update the system contract
msg := types.NewMsgUpdateSystemContract(admin, newSystemContract.Hex())
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateSystemContract(ctx, msg)
require.NoError(t, err)

Expand Down Expand Up @@ -245,6 +246,7 @@ func TestKeeper_UpdateSystemContract(t *testing.T) {
// can't update the system contract
msg := types.NewMsgUpdateSystemContract(admin, newSystemContract.Hex())
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateSystemContract(ctx, msg)
require.ErrorIs(t, err, types.ErrContractCall)

Expand All @@ -255,6 +257,7 @@ func TestKeeper_UpdateSystemContract(t *testing.T) {
// can't update the system contract
msg = types.NewMsgUpdateSystemContract(admin, newSystemContract.Hex())
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateSystemContract(ctx, msg)
require.ErrorIs(t, err, types.ErrContractCall)

Expand All @@ -265,6 +268,7 @@ func TestKeeper_UpdateSystemContract(t *testing.T) {
// can't update the system contract
msg = types.NewMsgUpdateSystemContract(admin, newSystemContract.Hex())
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateSystemContract(ctx, msg)
require.ErrorIs(t, err, types.ErrContractCall)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) {
math.NewUint(42),
)
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateZRC20WithdrawFee(ctx, msg)
require.NoError(t, err)

Expand All @@ -68,6 +69,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) {
math.Uint{},
)
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateZRC20WithdrawFee(ctx, msg)
require.NoError(t, err)
protocolFee, err = k.QueryProtocolFlatFee(ctx, zrc20Addr)
Expand All @@ -85,6 +87,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) {
math.NewUint(44),
)
keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil)
keepertest.MockGetChainListEmpty(&authorityMock.Mock)
_, err = msgServer.UpdateZRC20WithdrawFee(ctx, msg)
require.NoError(t, err)
protocolFee, err = k.QueryProtocolFlatFee(ctx, zrc20Addr)
Expand Down
5 changes: 4 additions & 1 deletion zetaclient/chains/evm/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,10 @@ func (ob *Observer) BuildInboundVoteMsgForDepositedEvent(
func (ob *Observer) BuildInboundVoteMsgForZetaSentEvent(
event *zetaconnector.ZetaConnectorNonEthZetaSent,
) *types.MsgVoteInbound {
destChain := chains.GetChainFromChainID(event.DestinationChainId.Int64(), ob.ZetacoreContext().GetAdditionalChains())
destChain := chains.GetChainFromChainID(
event.DestinationChainId.Int64(),
ob.ZetacoreContext().GetAdditionalChains(),
)
if destChain == nil {
ob.Logger().Inbound.Warn().Msgf("chain id not supported %d", event.DestinationChainId.Int64())
return nil
Expand Down

0 comments on commit 672da05

Please sign in to comment.