@@ -10,8 +10,10 @@ import (
10
10
"github.com/stretchr/testify/require"
11
11
)
12
12
13
- const TestCreator = "sei1ewxvf5a9wq9zk5nurtl6m9yfxpnhyp7s7uk5sl"
14
- const TestContract = "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m"
13
+ const (
14
+ TestCreator = "sei1ewxvf5a9wq9zk5nurtl6m9yfxpnhyp7s7uk5sl"
15
+ TestContract = "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m"
16
+ )
15
17
16
18
func TestPlaceOrder (t * testing.T ) {
17
19
msg := & types.MsgPlaceOrders {
@@ -48,6 +50,9 @@ func TestPlaceOrder(t *testing.T) {
48
50
require .Equal (t , 2 , len (res .OrderIds ))
49
51
require .Equal (t , uint64 (0 ), res .OrderIds [0 ])
50
52
require .Equal (t , uint64 (1 ), res .OrderIds [1 ])
53
+ // Ensure that contract addr and account is set in the order
54
+ require .Equal (t , msg .Orders [0 ].ContractAddr , TestContract )
55
+ require .Equal (t , msg .Orders [0 ].Account , TestCreator )
51
56
}
52
57
53
58
func TestPlaceInvalidOrder (t * testing.T ) {
@@ -56,6 +61,7 @@ func TestPlaceInvalidOrder(t *testing.T) {
56
61
keeper .SetTickSizeForPair (ctx , TestContract , keepertest .TestPair , * keepertest .TestPair .Ticksize )
57
62
wctx := sdk .WrapSDKContext (ctx )
58
63
64
+ // Empty quantity
59
65
msg := & types.MsgPlaceOrders {
60
66
Creator : TestCreator ,
61
67
ContractAddr : TestContract ,
@@ -75,6 +81,7 @@ func TestPlaceInvalidOrder(t *testing.T) {
75
81
_ , err := server .PlaceOrders (wctx , msg )
76
82
require .NotNil (t , err )
77
83
84
+ // Empty price
78
85
msg = & types.MsgPlaceOrders {
79
86
Creator : TestCreator ,
80
87
ContractAddr : TestContract ,
@@ -93,4 +100,86 @@ func TestPlaceInvalidOrder(t *testing.T) {
93
100
server = msgserver .NewMsgServerImpl (* keeper , nil )
94
101
_ , err = server .PlaceOrders (wctx , msg )
95
102
require .NotNil (t , err )
103
+
104
+ // Negative quantity
105
+ msg = & types.MsgPlaceOrders {
106
+ Creator : TestCreator ,
107
+ ContractAddr : TestContract ,
108
+ Orders : []* types.Order {
109
+ {
110
+ Price : sdk .MustNewDecFromStr ("10" ),
111
+ Quantity : sdk .MustNewDecFromStr ("-1" ),
112
+ Data : "" ,
113
+ PositionDirection : types .PositionDirection_LONG ,
114
+ OrderType : types .OrderType_LIMIT ,
115
+ PriceDenom : keepertest .TestPriceDenom ,
116
+ AssetDenom : keepertest .TestAssetDenom ,
117
+ },
118
+ },
119
+ }
120
+ server = msgserver .NewMsgServerImpl (* keeper , nil )
121
+ _ , err = server .PlaceOrders (wctx , msg )
122
+ require .NotNil (t , err )
123
+
124
+ // Negative price
125
+ msg = & types.MsgPlaceOrders {
126
+ Creator : TestCreator ,
127
+ ContractAddr : TestContract ,
128
+ Orders : []* types.Order {
129
+ {
130
+ Price : sdk .MustNewDecFromStr ("-1" ),
131
+ Quantity : sdk .MustNewDecFromStr ("10" ),
132
+ Data : "" ,
133
+ PositionDirection : types .PositionDirection_LONG ,
134
+ OrderType : types .OrderType_LIMIT ,
135
+ PriceDenom : keepertest .TestPriceDenom ,
136
+ AssetDenom : keepertest .TestAssetDenom ,
137
+ ContractAddr : TestContract ,
138
+ Account : "testaccount" ,
139
+ },
140
+ },
141
+ }
142
+ server = msgserver .NewMsgServerImpl (* keeper , nil )
143
+ _ , err = server .PlaceOrders (wctx , msg )
144
+ require .NotNil (t , err )
145
+
146
+ // Missing contract
147
+ msg = & types.MsgPlaceOrders {
148
+ Creator : TestCreator ,
149
+ ContractAddr : TestContract ,
150
+ Orders : []* types.Order {
151
+ {
152
+ Price : sdk .MustNewDecFromStr ("-1" ),
153
+ Quantity : sdk .MustNewDecFromStr ("10" ),
154
+ Data : "" ,
155
+ PositionDirection : types .PositionDirection_LONG ,
156
+ OrderType : types .OrderType_LIMIT ,
157
+ PriceDenom : keepertest .TestPriceDenom ,
158
+ AssetDenom : keepertest .TestAssetDenom ,
159
+ },
160
+ },
161
+ }
162
+ server = msgserver .NewMsgServerImpl (* keeper , nil )
163
+ _ , err = server .PlaceOrders (wctx , msg )
164
+ require .NotNil (t , err )
165
+
166
+ // Missing account
167
+ msg = & types.MsgPlaceOrders {
168
+ Creator : TestCreator ,
169
+ ContractAddr : TestContract ,
170
+ Orders : []* types.Order {
171
+ {
172
+ Price : sdk .MustNewDecFromStr ("-1" ),
173
+ Quantity : sdk .MustNewDecFromStr ("10" ),
174
+ Data : "" ,
175
+ PositionDirection : types .PositionDirection_LONG ,
176
+ OrderType : types .OrderType_LIMIT ,
177
+ PriceDenom : keepertest .TestPriceDenom ,
178
+ AssetDenom : keepertest .TestAssetDenom ,
179
+ },
180
+ },
181
+ }
182
+ server = msgserver .NewMsgServerImpl (* keeper , nil )
183
+ _ , err = server .PlaceOrders (wctx , msg )
184
+ require .NotNil (t , err )
96
185
}
0 commit comments