Add msg validation for auction module
This commit is contained in:
parent
91677966f7
commit
03b3bcaf31
@ -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)
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
}()
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user