Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve fungible module coverage (system_contract tests) #1782

Merged
merged 24 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper"

cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
Expand Down Expand Up @@ -165,7 +166,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
// Set a gas meter with limit 0 as to prevent an infinite gas meter attack
// during runTx.
newCtx = SetGasMeter(simulate, ctx, 0)
return newCtx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx")
return newCtx, cosmoserrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx")
}

newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas())
Expand All @@ -183,7 +184,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
"out of gas in location: %v; gasWanted: %d, gasUsed: %d",
rType.Descriptor, gasTx.GetGas(), newCtx.GasMeter().GasConsumed())

err = sdkerrors.Wrap(sdkerrors.ErrOutOfGas, log)
err = cosmoserrors.Wrap(sdkerrors.ErrOutOfGas, log)
default:
panic(r)
}
Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"time"

cosmoserrors "cosmossdk.io/errors"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand Down Expand Up @@ -776,10 +777,10 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
// VerifyAddressFormat verifies the address is compatible with ethereum
func VerifyAddressFormat(bz []byte) error {
if len(bz) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "invalid address; cannot be empty")
return cosmoserrors.Wrap(sdkerrors.ErrUnknownAddress, "invalid address; cannot be empty")
}
if len(bz) != AddrLen {
return sdkerrors.Wrapf(
return cosmoserrors.Wrapf(
sdkerrors.ErrUnknownAddress,
"invalid address length; got: %d, expect: %d", len(bz), AddrLen,
)
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [1746](https://github.com/zeta-chain/node/pull/1746) - rename smoke tests to e2e tests
* [1753](https://github.com/zeta-chain/node/pull/1753) - fix gosec errors on usage of rand package
* [1762](https://github.com/zeta-chain/node/pull/1762) - improve coverage for fungibile module
* [1782](https://github.com/zeta-chain/node/pull/1782) - improve coverage for fungibile module system contract

### CI

Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/msg_server_gas_price_voter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"sort"
"strconv"

cosmoserrors "cosmossdk.io/errors"
"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)
Expand All @@ -31,7 +31,7 @@
return nil, observertypes.ErrNotAuthorizedPolicy
}
if chain == nil {
return nil, sdkerrors.Wrap(types.ErrUnsupportedChain, fmt.Sprintf("ChainID : %d ", msg.ChainId))
return nil, cosmoserrors.Wrap(types.ErrUnsupportedChain, fmt.Sprintf("ChainID : %d ", msg.ChainId))

Check warning on line 34 in x/crosschain/keeper/msg_server_gas_price_voter.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/msg_server_gas_price_voter.go#L34

Added line #L34 was not covered by tests
}

gasPrice, isFound := k.GetGasPrice(ctx, chain.ChainId)
Expand Down
9 changes: 4 additions & 5 deletions x/crosschain/keeper/msg_server_vote_inbound_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"context"
"fmt"

errorsmod "cosmossdk.io/errors"
cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observerKeeper "github.com/zeta-chain/zetacore/x/observer/keeper"
Expand Down Expand Up @@ -67,11 +66,11 @@
// GetChainFromChainID makes sure we are getting only supported chains , if a chain support has been turned on using gov proposal, this function returns nil
observationChain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, msg.SenderChainId)
if observationChain == nil {
return nil, sdkerrors.Wrap(types.ErrUnsupportedChain, fmt.Sprintf("ChainID %d, Observation %s", msg.SenderChainId, observationType.String()))
return nil, cosmoserrors.Wrap(types.ErrUnsupportedChain, fmt.Sprintf("ChainID %d, Observation %s", msg.SenderChainId, observationType.String()))

Check warning on line 69 in x/crosschain/keeper/msg_server_vote_inbound_tx.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/msg_server_vote_inbound_tx.go#L69

Added line #L69 was not covered by tests
}
receiverChain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, msg.ReceiverChain)
if receiverChain == nil {
return nil, sdkerrors.Wrap(types.ErrUnsupportedChain, fmt.Sprintf("ChainID %d, Observation %s", msg.ReceiverChain, observationType.String()))
return nil, cosmoserrors.Wrap(types.ErrUnsupportedChain, fmt.Sprintf("ChainID %d, Observation %s", msg.ReceiverChain, observationType.String()))

Check warning on line 73 in x/crosschain/keeper/msg_server_vote_inbound_tx.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/msg_server_vote_inbound_tx.go#L73

Added line #L73 was not covered by tests
}
tssPub := ""
tss, tssFound := k.zetaObserverKeeper.GetTSS(ctx)
Expand All @@ -93,7 +92,7 @@
if isNew {
// Check if the inbound has already been processed.
if k.IsFinalizedInbound(ctx, msg.InTxHash, msg.SenderChainId, msg.EventIndex) {
return nil, errorsmod.Wrap(types.ErrObservedTxAlreadyFinalized, fmt.Sprintf("InTxHash:%s, SenderChainID:%d, EventIndex:%d", msg.InTxHash, msg.SenderChainId, msg.EventIndex))
return nil, cosmoserrors.Wrap(types.ErrObservedTxAlreadyFinalized, fmt.Sprintf("InTxHash:%s, SenderChainID:%d, EventIndex:%d", msg.InTxHash, msg.SenderChainId, msg.EventIndex))
}
observerKeeper.EmitEventBallotCreated(ctx, ballot, msg.InTxHash, observationChain.String())
}
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/keeper/msg_server_vote_inbound_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestKeeper_VoteOnObservedInboundTx(t *testing.T) {
require.NoError(t, err)
}
ballot, _, _ := zk.ObserverKeeper.FindBallot(ctx, msg.Digest(), zk.ObserverKeeper.GetSupportedChainFromChainID(ctx, msg.SenderChainId), observerTypes.ObservationType_InBoundTx)
require.Equal(t, ballot.BallotStatus, observerTypes.BallotStatus_BallotFinalized_SuccessObservation)
require.Equal(t, ballot.BallotStatus, observertypes.BallotStatus_BallotFinalized_SuccessObservation)
cctx, found := k.GetCrossChainTx(ctx, msg.Digest())
require.True(t, found)
require.Equal(t, cctx.CctxStatus.Status, types.CctxStatus_OutboundMined)
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestNoDoubleEventProtections(t *testing.T) {
// Check that the vote passed
ballot, found := zk.ObserverKeeper.GetBallot(ctx, msg.Digest())
require.True(t, found)
require.Equal(t, ballot.BallotStatus, observerTypes.BallotStatus_BallotFinalized_SuccessObservation)
require.Equal(t, ballot.BallotStatus, observertypes.BallotStatus_BallotFinalized_SuccessObservation)
//Perform the SAME event. Except, this time, we resubmit the event.
msg2 := &types.MsgVoteOnObservedInboundTx{
Creator: validatorAddr,
Expand Down
7 changes: 4 additions & 3 deletions x/crosschain/keeper/msg_server_vote_outbound_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"fmt"
"math/big"

cosmoserrors "cosmossdk.io/errors"
"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -81,11 +82,11 @@
// Check if CCTX exists
cctx, found := k.GetCrossChainTx(ctx, msg.CctxHash)
if !found {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("CCTX %s does not exist", msg.CctxHash))
return nil, cosmoserrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("CCTX %s does not exist", msg.CctxHash))

Check warning on line 85 in x/crosschain/keeper/msg_server_vote_outbound_tx.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/msg_server_vote_outbound_tx.go#L85

Added line #L85 was not covered by tests
}

if cctx.GetCurrentOutTxParam().OutboundTxTssNonce != msg.OutTxTssNonce {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("OutTxTssNonce %d does not match CCTX OutTxTssNonce %d", msg.OutTxTssNonce, cctx.GetCurrentOutTxParam().OutboundTxTssNonce))
return nil, cosmoserrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("OutTxTssNonce %d does not match CCTX OutTxTssNonce %d", msg.OutTxTssNonce, cctx.GetCurrentOutTxParam().OutboundTxTssNonce))

Check warning on line 89 in x/crosschain/keeper/msg_server_vote_outbound_tx.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/msg_server_vote_outbound_tx.go#L89

Added line #L89 was not covered by tests
}

ballotIndex := msg.Digest()
Expand Down Expand Up @@ -117,7 +118,7 @@
log.Error().Msgf("VoteOnObservedOutboundTx: Mint mismatch: %s value received vs %s cctx amount",
msg.ValueReceived,
cctx.GetCurrentOutTxParam().Amount)
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("ValueReceived %s does not match sent value %s", msg.ValueReceived, cctx.GetCurrentOutTxParam().Amount))
return nil, cosmoserrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("ValueReceived %s does not match sent value %s", msg.ValueReceived, cctx.GetCurrentOutTxParam().Amount))

Check warning on line 121 in x/crosschain/keeper/msg_server_vote_outbound_tx.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/msg_server_vote_outbound_tx.go#L121

Added line #L121 was not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func setupZRC20Pool(
)
require.NoError(t, err)

// approve the router to spend the zeta
// approve the router to spend the zrc20
err = k.CallZRC20Approve(
ctx,
types.ModuleAddressEVM,
Expand Down
5 changes: 3 additions & 2 deletions x/crosschain/types/message_add_to_out_tx_tracker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/zeta-chain/zetacore/common"
Expand Down Expand Up @@ -54,10 +55,10 @@
func (msg *MsgAddToOutTxTracker) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if msg.ChainId < 0 {
return sdkerrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.ChainId)
return cosmoserrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.ChainId)

Check warning on line 61 in x/crosschain/types/message_add_to_out_tx_tracker.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_add_to_out_tx_tracker.go#L61

Added line #L61 was not covered by tests
}
return nil
}
5 changes: 3 additions & 2 deletions x/crosschain/types/message_gas_price_voter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/zeta-chain/zetacore/common"
Expand Down Expand Up @@ -42,10 +43,10 @@
func (msg *MsgGasPriceVoter) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)

Check warning on line 46 in x/crosschain/types/message_gas_price_voter.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_gas_price_voter.go#L46

Added line #L46 was not covered by tests
}
if msg.ChainId < 0 {
return sdkerrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.ChainId)
return cosmoserrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.ChainId)

Check warning on line 49 in x/crosschain/types/message_gas_price_voter.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_gas_price_voter.go#L49

Added line #L49 was not covered by tests
}
return nil
}
5 changes: 3 additions & 2 deletions x/crosschain/types/message_remove_from_out_tx_tracker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -41,10 +42,10 @@
func (msg *MsgRemoveFromOutTxTracker) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)

Check warning on line 45 in x/crosschain/types/message_remove_from_out_tx_tracker.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_remove_from_out_tx_tracker.go#L45

Added line #L45 was not covered by tests
}
if msg.ChainId < 0 {
return sdkerrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.ChainId)
return cosmoserrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.ChainId)

Check warning on line 48 in x/crosschain/types/message_remove_from_out_tx_tracker.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_remove_from_out_tx_tracker.go#L48

Added line #L48 was not covered by tests
}
return nil
}
3 changes: 2 additions & 1 deletion x/crosschain/types/message_tss_voter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"fmt"

cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/zeta-chain/zetacore/common"
Expand Down Expand Up @@ -43,7 +44,7 @@
func (msg *MsgCreateTSSVoter) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)

Check warning on line 47 in x/crosschain/types/message_tss_voter.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_tss_voter.go#L47

Added line #L47 was not covered by tests
}
return nil
}
Expand Down
9 changes: 5 additions & 4 deletions x/crosschain/types/message_vote_on_observed_inbound_tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
cosmoserrors "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -74,19 +75,19 @@ func (msg *MsgVoteOnObservedInboundTx) GetSignBytes() []byte {
func (msg *MsgVoteOnObservedInboundTx) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s): %s", err, msg.Creator)
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s): %s", err, msg.Creator)
}

if msg.SenderChainId < 0 {
return sdkerrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.SenderChainId)
return cosmoserrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.SenderChainId)
}

if msg.ReceiverChain < 0 {
return sdkerrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.ReceiverChain)
return cosmoserrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.ReceiverChain)
}

if len(msg.Message) > MaxMessageLength {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "message is too long: %d", len(msg.Message))
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "message is too long: %d", len(msg.Message))
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions x/crosschain/types/message_vote_on_observed_outbound_tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
cosmoserrors "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -64,10 +65,10 @@ func (msg *MsgVoteOnObservedOutboundTx) GetSignBytes() []byte {
func (msg *MsgVoteOnObservedOutboundTx) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if msg.OutTxChain < 0 {
return sdkerrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.OutTxChain)
return cosmoserrors.Wrapf(ErrInvalidChainID, "chain id (%d)", msg.OutTxChain)
}

return nil
Expand Down
9 changes: 5 additions & 4 deletions x/crosschain/types/message_whitelist_erc20.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
ethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -49,17 +50,17 @@
func (msg *MsgWhitelistERC20) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)

Check warning on line 53 in x/crosschain/types/message_whitelist_erc20.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_whitelist_erc20.go#L53

Added line #L53 was not covered by tests
}
// check if the system contract address is valid
if ethcommon.HexToAddress(msg.Erc20Address) == (ethcommon.Address{}) {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid ERC20 contract address (%s)", msg.Erc20Address)
return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid ERC20 contract address (%s)", msg.Erc20Address)

Check warning on line 57 in x/crosschain/types/message_whitelist_erc20.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_whitelist_erc20.go#L57

Added line #L57 was not covered by tests
}
if msg.Decimals > 128 {
return sdkerrors.Wrapf(types.ErrInvalidDecimals, "invalid decimals (%d)", msg.Decimals)
return cosmoserrors.Wrapf(types.ErrInvalidDecimals, "invalid decimals (%d)", msg.Decimals)

Check warning on line 60 in x/crosschain/types/message_whitelist_erc20.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_whitelist_erc20.go#L60

Added line #L60 was not covered by tests
}
if msg.GasLimit <= 0 {
return sdkerrors.Wrapf(types.ErrInvalidGasLimit, "invalid gas limit (%d)", msg.GasLimit)
return cosmoserrors.Wrapf(types.ErrInvalidGasLimit, "invalid gas limit (%d)", msg.GasLimit)

Check warning on line 63 in x/crosschain/types/message_whitelist_erc20.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/types/message_whitelist_erc20.go#L63

Added line #L63 was not covered by tests
}
return nil
}
2 changes: 1 addition & 1 deletion x/fungible/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@

zrc4ABI, err := zrc20.ZRC20MetaData.GetAbi()
if err != nil {
return types.ZRC20Data{}, sdkerrors.Wrapf(
return types.ZRC20Data{}, cosmoserrors.Wrapf(

Check warning on line 435 in x/fungible/keeper/evm.go

View check run for this annotation

Codecov / codecov/patch

x/fungible/keeper/evm.go#L435

Added line #L435 was not covered by tests
types.ErrABIUnpack, "failed to get ABI: %s", err.Error(),
)
}
Expand Down
51 changes: 51 additions & 0 deletions x/fungible/keeper/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,57 @@ func deploySystemContracts(
return
}

type SystemContractDeployConfig struct {
DeployWZeta bool
DeployUniswapV2Factory bool
DeployUniswapV2Router bool
}

// deploySystemContractsConfigurable deploys the system contracts and returns their addresses
// while having a possibility to skip some deployments to test different scenarios
func deploySystemContractsConfigurable(
t *testing.T,
ctx sdk.Context,
k *fungiblekeeper.Keeper,
evmk types.EVMKeeper,
config *SystemContractDeployConfig,
) (wzeta, uniswapV2Factory, uniswapV2Router, connector, systemContract common.Address) {
var err error

if config.DeployWZeta {
wzeta, err = k.DeployWZETA(ctx)
require.NoError(t, err)
require.NotEmpty(t, wzeta)
assertContractDeployment(t, evmk, ctx, wzeta)
}

if config.DeployUniswapV2Factory {
uniswapV2Factory, err = k.DeployUniswapV2Factory(ctx)
require.NoError(t, err)
require.NotEmpty(t, uniswapV2Factory)
assertContractDeployment(t, evmk, ctx, uniswapV2Factory)
}

if config.DeployUniswapV2Router {
uniswapV2Router, err = k.DeployUniswapV2Router02(ctx, uniswapV2Factory, wzeta)
require.NoError(t, err)
require.NotEmpty(t, uniswapV2Router)
assertContractDeployment(t, evmk, ctx, uniswapV2Router)
}

connector, err = k.DeployConnectorZEVM(ctx, wzeta)
require.NoError(t, err)
require.NotEmpty(t, connector)
assertContractDeployment(t, evmk, ctx, connector)

systemContract, err = k.DeploySystemContract(ctx, wzeta, uniswapV2Factory, uniswapV2Router)
require.NoError(t, err)
require.NotEmpty(t, systemContract)
assertContractDeployment(t, evmk, ctx, systemContract)

return
}

// assertExampleBarValue asserts value Bar of the contract Example, used to test onCrossChainCall
func assertExampleBarValue(
t *testing.T,
Expand Down
Loading
Loading