Add msg validation for auction module
This commit is contained in:
parent
91677966f7
commit
03b3bcaf31
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"cosmossdk.io/math"
|
"cosmossdk.io/math"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -17,6 +16,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
|
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
|
||||||
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||||
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
|
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
|
||||||
)
|
)
|
||||||
@ -48,8 +48,8 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
||||||
if err != nil && !strings.Contains(err.Error(), "timeout exceeded waiting for block") {
|
if err != nil {
|
||||||
sr.NoError(err)
|
e2e.HandleNetworkSetupError(&ets.Suite, ets.network, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ets.network.WaitForHeight(1)
|
_, err = ets.network.WaitForHeight(1)
|
||||||
|
@ -2,7 +2,6 @@ package bond
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"cosmossdk.io/math"
|
"cosmossdk.io/math"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -15,6 +14,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
|
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
|
||||||
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||||
"git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
|
"git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
|
||||||
)
|
)
|
||||||
@ -40,8 +40,8 @@ func (ets *E2ETestSuite) SetupSuite() { //nolint: all
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
||||||
if err != nil && !strings.Contains(err.Error(), "timeout exceeded waiting for block") {
|
if err != nil {
|
||||||
sr.NoError(err)
|
e2e.HandleNetworkSetupError(&ets.Suite, ets.network, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ets.network.WaitForHeight(1)
|
_, err = ets.network.WaitForHeight(1)
|
||||||
@ -121,6 +121,8 @@ func (ets *E2ETestSuite) createBond() string {
|
|||||||
sr.NoError(err)
|
sr.NoError(err)
|
||||||
|
|
||||||
// extract bond id from bonds list
|
// extract bond id from bonds list
|
||||||
bond := queryResponse.GetBonds()[0]
|
bonds := queryResponse.GetBonds()
|
||||||
return bond.GetId()
|
sr.NotEmpty(bonds)
|
||||||
|
|
||||||
|
return queryResponse.GetBonds()[0].GetId()
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ package e2e
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"cosmossdk.io/log"
|
"cosmossdk.io/log"
|
||||||
pruningtypes "cosmossdk.io/store/pruning/types"
|
pruningtypes "cosmossdk.io/store/pruning/types"
|
||||||
@ -16,6 +19,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/types/module/testutil"
|
"github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
laconicApp "git.vdb.to/cerc-io/laconic2d/app"
|
laconicApp "git.vdb.to/cerc-io/laconic2d/app"
|
||||||
auctionmodule "git.vdb.to/cerc-io/laconic2d/x/auction/module"
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cosmossdk.io/math"
|
"cosmossdk.io/math"
|
||||||
@ -17,6 +16,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
|
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
|
||||||
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||||
bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
|
bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
|
||||||
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
|
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
|
||||||
@ -57,8 +57,8 @@ func (ets *E2ETestSuite) SetupSuite() {
|
|||||||
ets.cfg.GenesisState = genesisState
|
ets.cfg.GenesisState = genesisState
|
||||||
|
|
||||||
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
||||||
if err != nil && !strings.Contains(err.Error(), "timeout exceeded waiting for block") {
|
if err != nil {
|
||||||
sr.NoError(err)
|
e2e.HandleNetworkSetupError(&ets.Suite, ets.network, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ets.network.WaitForHeight(2)
|
_, 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) {
|
func (k Keeper) CreateAuction(ctx sdk.Context, msg auctiontypes.MsgCreateAuction) (*auctiontypes.Auction, error) {
|
||||||
// TODO: Setup checks
|
// TODO: Setup checks
|
||||||
// Might be called from another module directly, always validate.
|
// Might be called from another module directly, always validate.
|
||||||
// err := msg.ValidateBasic()
|
err := msg.ValidateBasic()
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return nil, err
|
return nil, err
|
||||||
// }
|
}
|
||||||
|
|
||||||
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
||||||
if err != nil {
|
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
|
// CommitBid is the command for committing a bid
|
||||||
// nolint: all
|
// nolint: all
|
||||||
func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) {
|
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)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
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
|
// RevealBid is the command for revealing a bid
|
||||||
// nolint: all
|
// nolint: all
|
||||||
func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) {
|
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)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
||||||
|
Loading…
Reference in New Issue
Block a user