Skip to content

Commit

Permalink
Add market event tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilkumarpilli authored and boz committed Jun 18, 2020
1 parent 7a66b69 commit e048e96
Show file tree
Hide file tree
Showing 4 changed files with 490 additions and 11 deletions.
16 changes: 7 additions & 9 deletions x/deployment/types/events_test.go
Expand Up @@ -6,6 +6,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"

"github.com/ovrclk/akash/sdkutil"
)
Expand All @@ -25,15 +26,12 @@ type testEventParsing struct {
func (tep testEventParsing) testMessageType() func(t *testing.T) {
_, err := ParseEvent(tep.msg)
return func(t *testing.T) {
t.Logf("ERR: %v", err)
// expected error doesn't match returned || error returned but not expected
if (tep.expErr != nil && errors.Is(err, tep.expErr)) || (err != nil && tep.expErr == nil) {
// if the error expected is errWildcard to catch untyped errors, don't fail the test, the error was expected.
if errors.Is(tep.expErr, errWildcard) {
t.Errorf("unexpected error: %v exp: %v", err, tep.expErr)
t.Logf("%T %v", errors.Cause(err), err)
t.Logf("%+v", tep)
}
t.Logf("%+v", tep)
// if the error expected is errWildcard to catch untyped errors, don't fail the test, the error was expected.
if errors.Is(tep.expErr, errWildcard) {
require.Error(t, err)
} else {
require.Equal(t, tep.expErr, err)
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions x/market/handler/handler_test.go
Expand Up @@ -271,7 +271,7 @@ func TestCloseOrderWithoutLease(t *testing.T) {
func TestCloseOrderValid(t *testing.T) {
suite := setupTestSuite(t)

_, _, order := suite.createLease()
lid, _, order := suite.createLease()

msg := types.MsgCloseOrder{
OrderID: order.ID(),
Expand All @@ -280,6 +280,15 @@ func TestCloseOrderValid(t *testing.T) {
res, err := suite.handler(suite.ctx, msg)
require.NotNil(t, res)
require.NoError(t, err)

t.Run("ensure event created", func(t *testing.T) {
iev := testutil.ParseMarketEvent(t, res.Events, 5)
require.IsType(t, types.EventLeaseClosed{}, iev)

dev := iev.(types.EventLeaseClosed)

require.Equal(t, lid, dev.ID)
})
}

func TestCloseBidNonExisting(t *testing.T) {
Expand Down Expand Up @@ -315,7 +324,7 @@ func TestCloseBidUnknownLease(t *testing.T) {
func TestCloseBidValid(t *testing.T) {
suite := setupTestSuite(t)

_, bid, _ := suite.createLease()
_, bid, order := suite.createLease()

msg := types.MsgCloseBid{
BidID: bid.ID(),
Expand All @@ -324,6 +333,15 @@ func TestCloseBidValid(t *testing.T) {
res, err := suite.handler(suite.ctx, msg)
require.NotNil(t, res)
require.NoError(t, err)

t.Run("ensure event created", func(t *testing.T) {
iev := testutil.ParseMarketEvent(t, res.Events, 6)
require.IsType(t, types.EventOrderClosed{}, iev)

dev := iev.(types.EventOrderClosed)

require.Equal(t, order.ID(), dev.ID)
})
}

func TestCloseBidNotActiveLease(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions x/market/types/event.go
Expand Up @@ -18,6 +18,9 @@ const (
evActionLeaseCreated = "lease-created"
evActionLeaseClosed = "lease-closed"

evOwnerKey = "owner"
evDSeqKey = "dseq"
evGSeqKey = "gseq"
evOSeqKey = "oseq"
evProviderKey = "provider"
evPriceDenomKey = "price-denom"
Expand Down

0 comments on commit e048e96

Please sign in to comment.