Add msg validation for auction module
Some checks failed
Integration Tests / test-integration (pull_request) Successful in 1m14s
E2E Tests / test-e2e (pull_request) Failing after 2m5s

This commit is contained in:
Prathamesh Musale 2024-03-04 19:10:33 +05:30
parent 91677966f7
commit 03b3bcaf31
6 changed files with 68 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"cosmossdk.io/math"
"github.com/stretchr/testify/suite"
@ -17,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
types "git.vdb.to/cerc-io/laconic2d/x/auction"
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
)
@ -48,8 +48,8 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all
var err error
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
if err != nil && !strings.Contains(err.Error(), "timeout exceeded waiting for block") {
sr.NoError(err)
if err != nil {
e2e.HandleNetworkSetupError(&ets.Suite, ets.network, err)
}
_, err = ets.network.WaitForHeight(1)

View File

@ -2,7 +2,6 @@ package bond
import (
"fmt"
"strings"
"cosmossdk.io/math"
"github.com/stretchr/testify/suite"
@ -15,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
"git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
)
@ -40,8 +40,8 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all
var err error
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
if err != nil && !strings.Contains(err.Error(), "timeout exceeded waiting for block") {
sr.NoError(err)
if err != nil {
e2e.HandleNetworkSetupError(&ets.Suite, ets.network, err)
}
_, err = ets.network.WaitForHeight(1)
@ -121,6 +121,8 @@ func (ets *E2ETestSuite) createBond() string {
sr.NoError(err)
// extract bond id from bonds list
bond := queryResponse.GetBonds()[0]
return bond.GetId()
bonds := queryResponse.GetBonds()
sr.NotEmpty(bonds)
return queryResponse.GetBonds()[0].GetId()
}

View File

@ -3,6 +3,9 @@ package e2e
import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"cosmossdk.io/log"
pruningtypes "cosmossdk.io/store/pruning/types"
@ -16,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/stretchr/testify/suite"
laconicApp "git.vdb.to/cerc-io/laconic2d/app"
auctionmodule "git.vdb.to/cerc-io/laconic2d/x/auction/module"
@ -65,3 +69,40 @@ func NewTestNetworkFixture() network.TestFixture {
),
}
}
func HandleNetworkSetupError(s *suite.Suite, n *network.Network, err error) {
// Allow time extension for a block
// (avoids failure in CI)
if strings.Contains(err.Error(), "timeout exceeded waiting for block") {
// Ensure we cleanup incase any test was abruptly halted (e.g. SIGINT)
trapSignal(n.Cleanup)
return
}
s.Require().NoError(err)
}
// trapSignal traps SIGINT and SIGTERM and calls os.Exit once a signal is received.
func trapSignal(cleanupFunc func()) {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
if cleanupFunc != nil {
cleanupFunc()
}
exitCode := 128
switch sig {
case syscall.SIGINT:
exitCode += int(syscall.SIGINT)
case syscall.SIGTERM:
exitCode += int(syscall.SIGTERM)
}
os.Exit(exitCode)
}()
}

View File

@ -3,7 +3,6 @@ package registry
import (
"fmt"
"path/filepath"
"strings"
"time"
"cosmossdk.io/math"
@ -17,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
@ -57,8 +57,8 @@ func (ets *E2ETestSuite) SetupSuite() {
ets.cfg.GenesisState = genesisState
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
if err != nil && !strings.Contains(err.Error(), "timeout exceeded waiting for block") {
sr.NoError(err)
if err != nil {
e2e.HandleNetworkSetupError(&ets.Suite, ets.network, err)
}
_, err = ets.network.WaitForHeight(2)

View File

@ -287,10 +287,10 @@ func (k Keeper) QueryAuctionsByBidder(ctx sdk.Context, bidderAddress string) ([]
func (k Keeper) CreateAuction(ctx sdk.Context, msg auctiontypes.MsgCreateAuction) (*auctiontypes.Auction, error) {
// TODO: Setup checks
// Might be called from another module directly, always validate.
// err := msg.ValidateBasic()
// if err != nil {
// return nil, err
// }
err := msg.ValidateBasic()
if err != nil {
return nil, err
}
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {

View File

@ -52,6 +52,11 @@ func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreate
// CommitBid is the command for committing a bid
// nolint: all
func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) {
err := msg.ValidateBasic()
if err != nil {
return nil, err
}
ctx := sdk.UnwrapSDKContext(c)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
@ -83,6 +88,11 @@ func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid)
// RevealBid is the command for revealing a bid
// nolint: all
func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) {
err := msg.ValidateBasic()
if err != nil {
return nil, err
}
ctx := sdk.UnwrapSDKContext(c)
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)