Skip to content

Commit

Permalink
Move off-chain-updates tests to its own package (#1655)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanChou authored Jun 10, 2024
1 parent aefa183 commit bf90e52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
22 changes: 11 additions & 11 deletions protocol/indexer/off_chain_updates/off_chain_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func CreateOrderPlaceMessage(
return msgsender.Message{}, false
}

update, err := newOrderPlaceMessage(order)
update, err := NewOrderPlaceMessage(order)
if err != nil {
log.ErrorLogWithError(
ctx,
Expand Down Expand Up @@ -92,7 +92,7 @@ func CreateOrderReplaceMessage(
return msgsender.Message{}, false
}

update, err := newOrderReplaceMessage(order)
update, err := NewOrderReplaceMessage(order)
if err != nil {
log.ErrorLogWithError(
ctx,
Expand Down Expand Up @@ -139,7 +139,7 @@ func CreateOrderUpdateMessage(
return msgsender.Message{}, false
}

update, err := newOrderUpdateMessage(orderId, totalFilled)
update, err := NewOrderUpdateMessage(orderId, totalFilled)
if err != nil {
log.ErrorLogWithError(
ctx,
Expand Down Expand Up @@ -192,7 +192,7 @@ func CreateOrderRemoveMessageWithReason(
return msgsender.Message{}, false
}

update, err := newOrderRemoveMessage(orderId, reason, removalStatus)
update, err := NewOrderRemoveMessage(orderId, reason, removalStatus)
if err != nil {
log.ErrorLogWithError(
ctx,
Expand Down Expand Up @@ -284,9 +284,9 @@ func CreateOrderRemoveMessageWithDefaultReason(
return CreateOrderRemoveMessageWithReason(ctx, orderId, reason, removalStatus)
}

// newOrderPlaceMessage returns an `OffChainUpdate` struct populated with an `OrderPlace` struct
// NewOrderPlaceMessage returns an `OffChainUpdate` struct populated with an `OrderPlace` struct
// as the `UpdateMessage` parameter, encoded as a byte slice.
func newOrderPlaceMessage(
func NewOrderPlaceMessage(
order clobtypes.Order,
) ([]byte, error) {
indexerOrder := v1.OrderToIndexerOrder(order)
Expand All @@ -302,10 +302,10 @@ func newOrderPlaceMessage(
return proto.Marshal(&update)
}

// newOrderPlaceMessage returns an `OffChainUpdate` struct populated with an `OrderRemove`
// NewOrderRemoveMessage returns an `OffChainUpdate` struct populated with an `OrderRemove`
// struct as the `UpdateMessage` parameter, encoded as a byte slice.
// The `OrderRemove` struct is instantiated with the given orderId, reason and status parameters.
func newOrderRemoveMessage(
func NewOrderRemoveMessage(
orderId clobtypes.OrderId,
reason sharedtypes.OrderRemovalReason,
status ocutypes.OrderRemoveV1_OrderRemovalStatus,
Expand All @@ -326,7 +326,7 @@ func newOrderRemoveMessage(
// NewOrderUpdateMessage returns an `OffChainUpdate` struct populated with an `OrderUpdate`
// struct as the `UpdateMessage` parameter, encoded as a byte slice.
// The `OrderUpdate` struct is instantiated with the given orderId and totalFilled parameters.
func newOrderUpdateMessage(
func NewOrderUpdateMessage(
orderId clobtypes.OrderId,
totalFilled satypes.BaseQuantums,
) ([]byte, error) {
Expand All @@ -342,9 +342,9 @@ func newOrderUpdateMessage(
return proto.Marshal(&update)
}

// newOrderReplaceMessage returns an `OffChainUpdate` struct populated with an `OrderReplace` struct
// NewOrderReplaceMessage returns an `OffChainUpdate` struct populated with an `OrderReplace` struct
// as the `UpdateMessage` parameter, encoded as a byte slice.
func newOrderReplaceMessage(
func NewOrderReplaceMessage(
order clobtypes.Order,
) ([]byte, error) {
indexerOrder := v1.OrderToIndexerOrder(order)
Expand Down
29 changes: 15 additions & 14 deletions protocol/indexer/off_chain_updates/off_chain_updates_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package off_chain_updates
package off_chain_updates_test

import (
"testing"
Expand All @@ -7,6 +7,7 @@ import (

"github.com/cosmos/gogoproto/proto"
"github.com/dydxprotocol/v4-chain/protocol/indexer/msgsender"
ocu "github.com/dydxprotocol/v4-chain/protocol/indexer/off_chain_updates"
ocutypes "github.com/dydxprotocol/v4-chain/protocol/indexer/off_chain_updates/types"
v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1"
sharedtypes "github.com/dydxprotocol/v4-chain/protocol/indexer/shared/types"
Expand Down Expand Up @@ -73,7 +74,7 @@ var (

func TestCreateOrderPlaceMessage(t *testing.T) {
ctx, _, _ := sdk.NewSdkContextWithMultistore()
actualMessage, success := CreateOrderPlaceMessage(
actualMessage, success := ocu.CreateOrderPlaceMessage(
ctx,
order,
)
Expand All @@ -90,7 +91,7 @@ func TestCreateOrderPlaceMessage(t *testing.T) {

func TestCreateOrderReplaceMessage(t *testing.T) {
ctx, _, _ := sdk.NewSdkContextWithMultistore()
actualMessage, success := CreateOrderReplaceMessage(
actualMessage, success := ocu.CreateOrderReplaceMessage(
ctx,
order,
)
Expand All @@ -108,7 +109,7 @@ func TestCreateOrderReplaceMessage(t *testing.T) {
func TestCreateOrderUpdateMessage(t *testing.T) {
ctx, _, _ := sdk.NewSdkContextWithMultistore()

actualMessage, success := CreateOrderUpdateMessage(ctx, order.OrderId, totalFilledAmount)
actualMessage, success := ocu.CreateOrderUpdateMessage(ctx, order.OrderId, totalFilledAmount)
require.True(t, success)

updateBytes, err := proto.Marshal(&offchainUpdateOrderUpdate)
Expand All @@ -123,7 +124,7 @@ func TestCreateOrderUpdateMessage(t *testing.T) {
func TestCreateOrderRemoveWithReason(t *testing.T) {
ctx, _, _ := sdk.NewSdkContextWithMultistore()

actualMessage, success := CreateOrderRemoveMessage(
actualMessage, success := ocu.CreateOrderRemoveMessage(
ctx,
order.OrderId,
orderStatus,
Expand All @@ -150,7 +151,7 @@ func TestCreateOrderRemoveMessageWithDefaultReason_HappyPath(t *testing.T) {
defaultRemovalReason,
"defaultRemovalReason must be different than expectedMessage's removal reason for test to "+
"be valid & useful.")
actualMessage, success := CreateOrderRemoveMessageWithDefaultReason(
actualMessage, success := ocu.CreateOrderRemoveMessageWithDefaultReason(
ctx,
order.OrderId,
orderStatus,
Expand All @@ -171,7 +172,7 @@ func TestCreateOrderRemoveMessageWithDefaultReason_HappyPath(t *testing.T) {

func TestCreateOrderRemoveMessageWithDefaultReason_DefaultReasonReturned(t *testing.T) {
ctx, _, _ := sdk.NewSdkContextWithMultistore()
actualMessage, success := CreateOrderRemoveMessageWithDefaultReason(
actualMessage, success := ocu.CreateOrderRemoveMessageWithDefaultReason(
ctx,
order.OrderId,
clobtypes.Success,
Expand All @@ -197,7 +198,7 @@ func TestCreateOrderRemoveMessageWithDefaultReason_InvalidDefault(t *testing.T)
t,
"Invalid parameter: defaultRemovalReason cannot be OrderRemove_ORDER_REMOVAL_REASON_UNSPECIFIED",
func() {
CreateOrderRemoveMessageWithDefaultReason(
ocu.CreateOrderRemoveMessageWithDefaultReason(
ctx,
order.OrderId,
clobtypes.Success,
Expand All @@ -212,7 +213,7 @@ func TestCreateOrderRemoveMessageWithDefaultReason_InvalidDefault(t *testing.T)
func TestCreateOrderRemoveWithReasonMessage(t *testing.T) {
ctx, _, _ := sdk.NewSdkContextWithMultistore()

actualMessage, success := CreateOrderRemoveMessageWithReason(
actualMessage, success := ocu.CreateOrderRemoveMessageWithReason(
ctx,
order.OrderId,
reason,
Expand All @@ -230,7 +231,7 @@ func TestCreateOrderRemoveWithReasonMessage(t *testing.T) {
}

func TestNewOrderPlaceMessage(t *testing.T) {
actualUpdateBytes, err := newOrderPlaceMessage(
actualUpdateBytes, err := ocu.NewOrderPlaceMessage(
order,
)
require.NoError(
Expand All @@ -254,7 +255,7 @@ func TestNewOrderPlaceMessage(t *testing.T) {
}

func TestNewOrderUpdateMessage(t *testing.T) {
actualUpdateBytes, err := newOrderUpdateMessage(order.OrderId, totalFilledAmount)
actualUpdateBytes, err := ocu.NewOrderUpdateMessage(order.OrderId, totalFilledAmount)
require.NoError(
t,
err,
Expand All @@ -276,7 +277,7 @@ func TestNewOrderUpdateMessage(t *testing.T) {
}

func TestNewOrderRemoveMessage(t *testing.T) {
actualUpdateBytes, err := newOrderRemoveMessage(order.OrderId, reason, status)
actualUpdateBytes, err := ocu.NewOrderRemoveMessage(order.OrderId, reason, status)
require.NoError(
t,
err,
Expand Down Expand Up @@ -313,7 +314,7 @@ func TestGetOrderIdHash(t *testing.T) {
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
hash, err := GetOrderIdHash(tc.orderId)
hash, err := ocu.GetOrderIdHash(tc.orderId)
require.NoError(t, err)
require.Equal(t, tc.expectedHash, hash)
})
Expand Down Expand Up @@ -395,7 +396,7 @@ func TestShouldSendOrderRemovalOnReplay(t *testing.T) {
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
shouldSend := ShouldSendOrderRemovalOnReplay(tc.orderError)
shouldSend := ocu.ShouldSendOrderRemovalOnReplay(tc.orderError)
require.Equal(t, tc.expected, shouldSend)
})
}
Expand Down

0 comments on commit bf90e52

Please sign in to comment.