-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQS-417 | Fix orderbook order Quantity parsing (#519)
- Loading branch information
1 parent
65036e2
commit 0c663b7
Showing
2 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package orderbookdomain_test | ||
|
||
import ( | ||
"testing" | ||
|
||
orderbookdomain "github.com/osmosis-labs/sqs/domain/orderbook" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOrderStatus(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
order orderbookdomain.Order | ||
percentFilled float64 | ||
expected orderbookdomain.OrderStatus | ||
expectError bool | ||
}{ | ||
{ | ||
name: "Valid quantity, percentFilled = 0", | ||
order: orderbookdomain.Order{Quantity: "100.0"}, | ||
percentFilled: 0, | ||
expected: orderbookdomain.StatusOpen, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Valid quantity, percentFilled = 1", | ||
order: orderbookdomain.Order{Quantity: "100.0"}, | ||
percentFilled: 1, | ||
expected: orderbookdomain.StatusFilled, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Valid quantity, percentFilled < 1", | ||
order: orderbookdomain.Order{Quantity: "100.0"}, | ||
percentFilled: 0.5, | ||
expected: orderbookdomain.StatusPartiallyFilled, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Zero quantity", | ||
order: orderbookdomain.Order{Quantity: "0"}, | ||
percentFilled: 1, | ||
expected: orderbookdomain.StatusFilled, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Invalid quantity string", | ||
order: orderbookdomain.Order{Quantity: "invalid"}, | ||
percentFilled: 1, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "Empty quantity string", | ||
order: orderbookdomain.Order{Quantity: ""}, | ||
percentFilled: 1, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "Out of range quantity string", | ||
order: orderbookdomain.Order{Quantity: "101960000000000000000"}, | ||
expected: orderbookdomain.StatusFilled, | ||
percentFilled: 1, | ||
expectError: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
status, err := tt.order.Status(tt.percentFilled) | ||
if tt.expectError { | ||
assert.Error(t, err) | ||
} | ||
assert.Equal(t, tt.expected, status) | ||
}) | ||
} | ||
} |