Skip to content

Commit

Permalink
use assert in x directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Feb 2, 2024
1 parent 481dcfe commit 74f148a
Show file tree
Hide file tree
Showing 106 changed files with 1,308 additions and 1,321 deletions.
44 changes: 22 additions & 22 deletions x/crosschain/client/cli/cli_out_tx_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/testutil/network"
"github.com/zeta-chain/zetacore/testutil/nullify"
Expand All @@ -15,7 +15,7 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty
t.Helper()
cfg := network.DefaultConfig()
state := types.GenesisState{}
require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state))
assert.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state))

for i := 0; i < n; i++ {
outTxTracker := types.OutTxTracker{
Expand All @@ -25,7 +25,7 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty
state.OutTxTrackerList = append(state.OutTxTrackerList, outTxTracker)
}
buf, err := cfg.Codec.MarshalJSON(&state)
require.NoError(t, err)
assert.NoError(t, err)
cfg.GenesisState[types.ModuleName] = buf
//cfg.GenesisState = network.SetupZetaGenesisState(t, cfg.GenesisState, cfg.Codec)
net, err := network.New(t, app.NodeDir, cfg)
Expand Down Expand Up @@ -72,14 +72,14 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowOutTxTracker(), args)
// if tc.err != nil {
// stat, ok := status.FromError(tc.err)
// require.True(t, ok)
// require.ErrorIs(t, stat.Err(), tc.err)
// assert.True(t, ok)
// assert.ErrorIs(t, stat.Err(), tc.err)
// } else {
// require.NoError(t, err)
// assert.NoError(t, err)
// var resp types.QueryGetOutTxTrackerResponse
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// require.NotNil(t, resp.OutTxTracker)
// require.Equal(t,
// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// assert.NotNil(t, resp.OutTxTracker)
// assert.Equal(t,
// nullify.Fill(&tc.obj),
// nullify.Fill(&resp.OutTxTracker),
// )
Expand Down Expand Up @@ -112,11 +112,11 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty
// for i := 0; i < len(objs); i += step {
// args := request(nil, uint64(i), uint64(step), false)
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args)
// require.NoError(t, err)
// assert.NoError(t, err)
// var resp types.QueryAllOutTxTrackerResponse
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// require.LessOrEqual(t, len(resp.OutTxTracker), step)
// require.Subset(t,
// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// assert.LessOrEqual(t, len(resp.OutTxTracker), step)
// assert.Subset(t,
// nullify.Fill(objs),
// nullify.Fill(resp.OutTxTracker),
// )
Expand All @@ -128,11 +128,11 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty
// for i := 0; i < len(objs); i += step {
// args := request(next, 0, uint64(step), false)
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args)
// require.NoError(t, err)
// assert.NoError(t, err)
// var resp types.QueryAllOutTxTrackerResponse
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// require.LessOrEqual(t, len(resp.OutTxTracker), step)
// require.Subset(t,
// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// assert.LessOrEqual(t, len(resp.OutTxTracker), step)
// assert.Subset(t,
// nullify.Fill(objs),
// nullify.Fill(resp.OutTxTracker),
// )
Expand All @@ -142,12 +142,12 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty
// t.Run("Total", func(t *testing.T) {
// args := request(nil, 0, uint64(len(objs)), true)
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args)
// require.NoError(t, err)
// assert.NoError(t, err)
// var resp types.QueryAllOutTxTrackerResponse
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// require.NoError(t, err)
// require.Equal(t, len(objs), int(resp.Pagination.Total))
// require.ElementsMatch(t,
// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// assert.NoError(t, err)
// assert.Equal(t, len(objs), int(resp.Pagination.Total))
// assert.ElementsMatch(t,
// nullify.Fill(objs),
// nullify.Fill(resp.OutTxTracker),
// )
Expand Down
38 changes: 19 additions & 19 deletions x/crosschain/client/integrationtests/cli_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/testutil/network"
Expand Down Expand Up @@ -44,7 +44,7 @@ func WriteToNewTempFile(t testing.TB, s string) *os.File {
fp := TempFile(t)
_, err := fp.WriteString(s)

require.Nil(t, err)
assert.Nil(t, err)

return fp
}
Expand All @@ -54,7 +54,7 @@ func TempFile(t testing.TB) *os.File {
t.Helper()

fp, err := os.CreateTemp(GetTempDir(t), "")
require.NoError(t, err)
assert.NoError(t, err)

return fp
}
Expand All @@ -67,10 +67,10 @@ func GetTempDir(t testing.TB) string {
// https://github.com/cosmos/cosmos-sdk/pull/10341 for
// this change's rationale.
tempdir, err := os.MkdirTemp("", "")
require.NoError(t, err)
assert.NoError(t, err)
t.Cleanup(func() {
err := os.RemoveAll(tempdir)
require.NoError(t, err)
assert.NoError(t, err)
})
return tempdir
}
Expand All @@ -86,11 +86,11 @@ func BuildSignedDeploySystemContract(t testing.TB, val *network.Validator, denom
fmt.Sprintf("--%s=%d", flags.FlagGas, 4000000),
}
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, txArgs)
require.NoError(t, err)
assert.NoError(t, err)
unsignerdTx := WriteToNewTempFile(t, out.String())
res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(),
"--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10))
require.NoError(t, err)
assert.NoError(t, err)
return WriteToNewTempFile(t, res.String())
}

Expand All @@ -112,11 +112,11 @@ func BuildSignedUpdateSystemContract(
}
args := append([]string{systemContractAddress}, txArgs...)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
require.NoError(t, err)
assert.NoError(t, err)
unsignerdTx := WriteToNewTempFile(t, out.String())
res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(),
"--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10))
require.NoError(t, err)
assert.NoError(t, err)
return WriteToNewTempFile(t, res.String())
}

Expand Down Expand Up @@ -145,11 +145,11 @@ func BuildSignedDeployETHZRC20(
"1000000",
}, txArgs...)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
require.NoError(t, err)
assert.NoError(t, err)
unsignerdTx := WriteToNewTempFile(t, out.String())
res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(),
"--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10))
require.NoError(t, err)
assert.NoError(t, err)
return WriteToNewTempFile(t, res.String())
}

Expand All @@ -171,11 +171,11 @@ func BuildSignedGasPriceVote(t testing.TB, val *network.Validator, denom string,
}
args := append(inboundVoterArgs, txArgs...)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
require.NoError(t, err)
assert.NoError(t, err)
unsignerdTx := WriteToNewTempFile(t, out.String())
res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(),
"--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10))
require.NoError(t, err)
assert.NoError(t, err)
return WriteToNewTempFile(t, res.String())
}

Expand All @@ -196,11 +196,11 @@ func BuildSignedTssVote(t testing.TB, val *network.Validator, denom string, acco
}
args := append(inboundVoterArgs, txArgs...)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
require.NoError(t, err)
assert.NoError(t, err)
unsignerdTx := WriteToNewTempFile(t, out.String())
res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(),
"--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10))
require.NoError(t, err)
assert.NoError(t, err)
return WriteToNewTempFile(t, res.String())
}

Expand Down Expand Up @@ -239,12 +239,12 @@ func BuildSignedOutboundVote(
}
args := append(outboundVoterArgs, txArgs...)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
require.NoError(t, err)
assert.NoError(t, err)

unsignerdTx := WriteToNewTempFile(t, out.String())
res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(),
"--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10))
require.NoError(t, err)
assert.NoError(t, err)
return WriteToNewTempFile(t, res.String())
}

Expand Down Expand Up @@ -274,11 +274,11 @@ func BuildSignedInboundVote(t testing.TB, val *network.Validator, denom string,
}
args := append(inboundVoterArgs, txArgs...)
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
require.NoError(t, err)
assert.NoError(t, err)
unsignerdTx := WriteToNewTempFile(t, out.String())
res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(),
"--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10))
require.NoError(t, err)
assert.NoError(t, err)
return WriteToNewTempFile(t, res.String())
}

Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package crosschain_test
import (
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/testutil/nullify"
"github.com/zeta-chain/zetacore/testutil/sample"
Expand Down Expand Up @@ -46,10 +46,10 @@ func TestGenesis(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
crosschain.InitGenesis(ctx, *k, genesisState)
got := crosschain.ExportGenesis(ctx, *k)
require.NotNil(t, got)
assert.NotNil(t, got)

// Compare genesis after init and export
nullify.Fill(&genesisState)
nullify.Fill(got)
require.Equal(t, genesisState, *got)
assert.Equal(t, genesisState, *got)
}
22 changes: 11 additions & 11 deletions x/crosschain/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"cosmossdk.io/math"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
testkeeper "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
Expand Down Expand Up @@ -268,8 +268,8 @@ func TestKeeper_CheckAndUpdateCctxGasPrice(t *testing.T) {

// ensure median gas price is set
medianGasPrice, isFound := k.GetMedianGasPriceInUint(ctx, chainID)
require.True(t, isFound)
require.True(t, medianGasPrice.Equal(math.NewUint(tc.medianGasPrice)))
assert.True(t, isFound)
assert.True(t, medianGasPrice.Equal(math.NewUint(tc.medianGasPrice)))
}

// set block timestamp
Expand All @@ -285,23 +285,23 @@ func TestKeeper_CheckAndUpdateCctxGasPrice(t *testing.T) {
gasPriceIncrease, feesPaid, err := k.CheckAndUpdateCctxGasPrice(ctx, tc.cctx, tc.flags)

if tc.isError {
require.Error(t, err)
assert.Error(t, err)
return
}
require.NoError(t, err)
assert.NoError(t, err)

// check values
require.True(t, gasPriceIncrease.Equal(tc.expectedGasPriceIncrease), "expected %s, got %s", tc.expectedGasPriceIncrease.String(), gasPriceIncrease.String())
require.True(t, feesPaid.Equal(tc.expectedAdditionalFees), "expected %s, got %s", tc.expectedAdditionalFees.String(), feesPaid.String())
assert.True(t, gasPriceIncrease.Equal(tc.expectedGasPriceIncrease), "expected %s, got %s", tc.expectedGasPriceIncrease.String(), gasPriceIncrease.String())
assert.True(t, feesPaid.Equal(tc.expectedAdditionalFees), "expected %s, got %s", tc.expectedAdditionalFees.String(), feesPaid.String())

// check cctx
if !tc.expectedGasPriceIncrease.IsZero() {
cctx, found := k.GetCrossChainTx(ctx, tc.cctx.Index)
require.True(t, found)
assert.True(t, found)
newGasPrice, err := cctx.GetCurrentOutTxParam().GetGasPrice()
require.NoError(t, err)
require.EqualValues(t, tc.expectedGasPriceIncrease.AddUint64(previousGasPrice).Uint64(), newGasPrice, "%d - %d", tc.expectedGasPriceIncrease.Uint64(), previousGasPrice)
require.EqualValues(t, tc.blockTimestamp.Unix(), cctx.CctxStatus.LastUpdateTimestamp)
assert.NoError(t, err)
assert.EqualValues(t, tc.expectedGasPriceIncrease.AddUint64(previousGasPrice).Uint64(), newGasPrice, "%d - %d", tc.expectedGasPriceIncrease.Uint64(), previousGasPrice)
assert.EqualValues(t, tc.blockTimestamp.Unix(), cctx.CctxStatus.LastUpdateTimestamp)
}
})
}
Expand Down
18 changes: 8 additions & 10 deletions x/crosschain/keeper/cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import (

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/testutil/sample"
"github.com/zeta-chain/zetacore/x/crosschain/keeper"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"

"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
)
Expand Down Expand Up @@ -188,9 +186,9 @@ func TestSendQuerySingle(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
response, err := keeper.Cctx(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
assert.ErrorIs(t, err, tc.err)
} else {
require.Equal(t, tc.response, response)
assert.Equal(t, tc.response, response)
}
})
}
Expand All @@ -216,7 +214,7 @@ func TestSendQueryPaginated(t *testing.T) {
step := 2
for i := 0; i < len(msgs); i += step {
resp, err := keeper.CctxAll(wctx, request(nil, uint64(i), uint64(step), false))
require.NoError(t, err)
assert.NoError(t, err)
for j := i; j < len(msgs) && j < i+step; j++ {
assert.Equal(t, &msgs[j], resp.CrossChainTx[j-i])
}
Expand All @@ -227,7 +225,7 @@ func TestSendQueryPaginated(t *testing.T) {
var next []byte
for i := 0; i < len(msgs); i += step {
resp, err := keeper.CctxAll(wctx, request(next, 0, uint64(step), false))
require.NoError(t, err)
assert.NoError(t, err)
for j := i; j < len(msgs) && j < i+step; j++ {
assert.Equal(t, &msgs[j], resp.CrossChainTx[j-i])
}
Expand All @@ -236,11 +234,11 @@ func TestSendQueryPaginated(t *testing.T) {
})
t.Run("Total", func(t *testing.T) {
resp, err := keeper.CctxAll(wctx, request(nil, 0, 0, true))
require.NoError(t, err)
require.Equal(t, len(msgs), int(resp.Pagination.Total))
assert.NoError(t, err)
assert.Equal(t, len(msgs), int(resp.Pagination.Total))
})
t.Run("InvalidRequest", func(t *testing.T) {
_, err := keeper.CctxAll(wctx, nil)
require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request"))
assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request"))
})
}
Loading

0 comments on commit 74f148a

Please sign in to comment.