diff --git a/tests/e2e/auction/suite.go b/tests/e2e/auction/suite.go index a5e3c05f..135fb212 100644 --- a/tests/e2e/auction/suite.go +++ b/tests/e2e/auction/suite.go @@ -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) diff --git a/tests/e2e/bond/suite.go b/tests/e2e/bond/suite.go index 68e42c84..3da678ed 100644 --- a/tests/e2e/bond/suite.go +++ b/tests/e2e/bond/suite.go @@ -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() } diff --git a/tests/e2e/common.go b/tests/e2e/common.go index 7a746eb1..70d534e6 100644 --- a/tests/e2e/common.go +++ b/tests/e2e/common.go @@ -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) + }() +} diff --git a/tests/e2e/registry/suite.go b/tests/e2e/registry/suite.go index 9f26531a..8429a426 100644 --- a/tests/e2e/registry/suite.go +++ b/tests/e2e/registry/suite.go @@ -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) diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go index edcb72ba..287146bf 100644 --- a/x/auction/keeper/keeper.go +++ b/x/auction/keeper/keeper.go @@ -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 { diff --git a/x/auction/keeper/msg_server.go b/x/auction/keeper/msg_server.go index b2035a9e..382b1691 100644 --- a/x/auction/keeper/msg_server.go +++ b/x/auction/keeper/msg_server.go @@ -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)