-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmore_test.go
381 lines (310 loc) · 18.1 KB
/
more_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
package serumgo
// NOTE: Special thanks to https://github.com/murlokito for writing and letting me port
// the instruction decoder tests from https://github.com/bmresearch/Solnet.Serum/blob/master/Solnet.Serum.Test/InstructionDecoderTest.cs
// Without him, I wouldn't have caught a few bugs here.
import (
"encoding/base64"
"encoding/binary"
"os"
"testing"
"github.com/davecgh/go-spew/spew"
bin "github.com/gagliardetto/binary"
"github.com/gagliardetto/solana-go"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
SetProgramID(solana.MustPublicKeyFromBase58("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"))
os.Exit(m.Run())
}
func TestInstructionDecode_CancelOrderV2(t *testing.T) {
CancelOrdersAndSettleMsg :=
"AQADDQpz5x/t0hNl7QruhPzk4rIGR/001ey9oRXwI9JjP4d4MZCYjBIPabdFGOFRg4aCuYIvpX0/Up2H0gsFDOvAKxptYTUM2" +
"1S5Es4XParbLdSX6tunfXUP9th1OPASGbtY2PiI2PpWo39ogKOkNY5k/Nfr0Wt/9KEDGrcUmrxuhRiSbi3T/D9J3OFx/jgQJR" +
"Q+s2+9GBNxoSwkDUIUrgnJSVYCOaxQQvf9r8PyaRmnlkSN6BQs0u7SDcCOz4CLebCdaSgViGOph6mtTc/i5/V7k/Malr7/YxBe" +
"zcjPsCTq/LNI8RqttgK/juTyfqv8uSiqbkGWGETaSk2Kb5xsFcNlQQWSbGlLqfiZ41yfAAH/BysfePaWsZCjnts5xkiSRTT14" +
"A0x4LQTafOL58gL65FcTUQQaY0+tE9OQfrFVtgS5kpxhQ8tbgKkevgk0Jq2ncQtcMsoy/okn7fuV7nSVsEnYu+pgdiCRuMX9X" +
"DIP87eCqZqkDn14UiDO4FzWxHK14PVPQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpRT/gXmftFbCh8k/tkXlqLbwa" +
"AlSoCOY59nR43pTxwWwFCgYBAgMEAAUZAAsAAAAAAAAANC/f//////89DAAAAAAAAAoGAQIDBAAFGQALAAAAAAAAADMv3/////" +
"//HgwAAAAAAAAKBgECAwQABRkACwAAAAAAAAAyL9////////4LAAAAAAAACgYBAgMEAAUZAAsAAAAAAAAAMS/f///////eCwAA" +
"AAAAAAoJAQQABgcICQsMBQAFAAAA"
data, err := base64.StdEncoding.DecodeString(CancelOrdersAndSettleMsg)
require.NoError(t, err)
msg := new(solana.Message)
err = msg.UnmarshalWithDecoder(bin.NewBorshDecoder(data))
require.NoError(t, err)
require.Equal(t, 5, len(msg.Instructions))
in := msg.Instructions[1]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*CancelOrderV2)
if !ok {
t.Errorf("the instruction is not a *CancelOrderV2")
}
require.NotNil(t, ix.GetOpenOrdersAccount())
require.NotNil(t, ix.GetOwnerAccount())
require.NotNil(t, ix.GetMarketAccount())
require.NotNil(t, ix.GetBidsAccount())
require.NotNil(t, ix.GetAsksAccount())
require.NotNil(t, ix.GetEventQueueAccount())
require.Equal(t, solana.MustPublicKeyFromBase58("8R6NtLSyVpgG6f8Z9cLKFcuaJtt3mqHypKGsmRixwyJV"), ix.GetOpenOrdersAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetOwnerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("9gpfTc4zsndJSdpnpXQbey16L5jW2GWcKeY3PLixqU4"), ix.GetEventQueueAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("8MyQkxux1NnpNqpBbPeiQHYeDbZvdvs7CHmGpciSMWvs"), ix.GetBidsAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("HjB8zKe9xezDrgqXCSjCb5F7dMC9WMwtZoT7yKYEhZYV"), ix.GetAsksAccount().PublicKey)
require.True(t, ix.Args.Side == SideBid)
orderID, err := decimal.NewFromString("57240246860720736513843")
require.NoError(t, err)
spew.Dump(orderID)
{
dec := bin.NewBorshDecoder(in.Data)
{
got, err := dec.ReadUint8()
require.NoError(t, err)
spew.Dump(got)
require.Equal(t, uint8(0), got)
}
got, err := dec.ReadUint32(binary.LittleEndian)
require.NoError(t, err)
spew.Dump(got)
require.Equal(t, Instruction_CancelOrderV2, got)
{
got, err := dec.ReadUint32(binary.LittleEndian)
require.NoError(t, err)
require.Equal(t, SideBid, Side(got))
spew.Dump(got)
// dec.SkipBytes(3)
}
instructionParamData, err := dec.ReadNBytes(dec.Remaining())
require.NoError(t, err)
spew.Dump([]byte(instructionParamData))
spew.Dump(bin.FormatByteSlice([]byte(instructionParamData)))
oo := orderID.BigInt().FillBytes(make([]byte, 16))
bin.ReverseBytes(oo)
spew.Dump(bin.FormatByteSlice(oo))
require.Equal(t, oo, instructionParamData)
}
require.Equal(t, orderID.BigInt(), ix.Args.OrderId.BigInt())
spew.Dump(ix.Args.OrderId.Hi)
spew.Dump(ix.Args.OrderId.Lo)
require.Equal(t, uint64(18446744073707401011), ix.Args.OrderId.Lo)
require.Equal(t, uint64(3102), ix.Args.OrderId.Hi)
}
func TestInstructionDecode_CreateOpenOrdersNewOrdersAndSettleMsg(t *testing.T) {
CreateOpenOrdersNewOrdersAndSettleMsg :=
"AgAFEApz5x/t0hNl7QruhPzk4rIGR/001ey9oRXwI9JjP4d4bi3T/D9J3OFx/jgQJRQ+s2+9GBNxoSwkDUIUrgnJSVYxkJiME" +
"g9pt0UY4VGDhoK5gi+lfT9SnYfSCwUM68ArGpr33IM/qQm6+EFjv3WCl9+nICT59ibJWro20VS5uUQ9AjmsUEL3/a/D8mkZp5" +
"ZEjegULNLu0g3Ajs+Ai3mwnWltYTUM21S5Es4XParbLdSX6tunfXUP9th1OPASGbtY2PiI2PpWo39ogKOkNY5k/Nfr0Wt/9KE" +
"DGrcUmrxuhRiSDTHgtBNp84vnyAvrkVxNRBBpjT60T05B+sVW2BLmSnEoFYhjqYeprU3P4uf1e5PzGpa+/2MQXs3Iz7Ak6vyz" +
"SPEarbYCv47k8n6r/Lkoqm5BlhhE2kpNim+cbBXDZUEFkmxpS6n4meNcnwAB/wcrH3j2lrGQo57bOcZIkkU09eAAAAAAAAAAA" +
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAan1RcZLFxRIYzJTD1K8X9Y2u4Im6H9ROPb2YoAAAAAhQ8tbgKkevgk0Jq2ncQtcM" +
"soy/okn7fuV7nSVsEnYu8G3fbh12Whk9nL4UbO63msHLSF7V9bN5E6jPWFfv8AqamB2IJG4xf1cMg/zt4KpmqQOfXhSIM7gXN" +
"bEcrXg9U9sKLMetn7/1UUmSgiOvObf6ncpgx9byhg2wueQRNGOvYICwIAATQAAAAAQGlkAQAAAACcDAAAAAAAAIUPLW4CpHr4" +
"JNCatp3ELXDLKMv6JJ+37le50lbBJ2LvDQQBAAIMBQAPAAAADQwCAQMEBQYHAAgJDgwzAAoAAAAAAAAAXQwAAAAAAAAKAAAAA" +
"AAAAEhLMAAAAAAAAQAAAAAAAAABAAAAAAAAAP//DQwCAQMEBQYHAAgJDgwzAAoAAAAAAAAAPQwAAAAAAAAWAAAAAAAAADgsaQ" +
"AAAAAAAQAAAAAAAAABAAAAAAAAAP//DQwCAQMEBQYHAAgJDgwzAAoAAAAAAAAAHgwAAAAAAAAjAAAAAAAAACiqpQAAAAAAAQA" +
"AAAAAAAABAAAAAAAAAP//DQwCAQMEBQYHAAgJDgwzAAoAAAAAAAAA/gsAAAAAAAAvAAAAAAAAAEgr3AAAAAAAAQAAAAAAAAAB" +
"AAAAAAAAAP//DQwCAQMEBQYHAAgJDgwzAAoAAAAAAAAA3gsAAAAAAAA8AAAAAAAAACAjFgEAAAAAAQAAAAAAAAABAAAAAAAAA" +
"P//DQkCAQAICQoHDw4FAAUAAAA="
data, err := base64.StdEncoding.DecodeString(CreateOpenOrdersNewOrdersAndSettleMsg)
require.NoError(t, err)
msg := new(solana.Message)
err = msg.UnmarshalWithDecoder(bin.NewBorshDecoder(data))
require.NoError(t, err)
require.Equal(t, 8, len(msg.Instructions))
{
in := msg.Instructions[1]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*InitOpenOrders)
if !ok {
t.Errorf("the instruction is not a *InitOpenOrders")
}
require.NotNil(t, ix.GetOpenOrdersAccount())
require.NotNil(t, ix.GetOwnerAccount())
require.NotNil(t, ix.GetMarketAccount())
require.Equal(t, solana.MustPublicKeyFromBase58("8R6NtLSyVpgG6f8Z9cLKFcuaJtt3mqHypKGsmRixwyJV"), ix.GetOpenOrdersAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetOwnerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
}
{
in := msg.Instructions[2]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*NewOrderV3)
if !ok {
t.Errorf("the instruction is not a *NewOrderV3")
}
require.Equal(t, solana.MustPublicKeyFromBase58("8R6NtLSyVpgG6f8Z9cLKFcuaJtt3mqHypKGsmRixwyJV"), ix.GetOpenOrdersAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetOwnerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("BRvzjEjphBLVMMq8tEvh4G5o9TTNJ4PSu23CAAdJDKsr"), ix.GetRequestQueueAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("9gpfTc4zsndJSdpnpXQbey16L5jW2GWcKeY3PLixqU4"), ix.GetEventQueueAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("8MyQkxux1NnpNqpBbPeiQHYeDbZvdvs7CHmGpciSMWvs"), ix.GetBidsAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("HjB8zKe9xezDrgqXCSjCb5F7dMC9WMwtZoT7yKYEhZYV"), ix.GetAsksAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("tWQuevB8Rou1HS9a76fjYSQPrDixZMbVzXe2Q1kY5ma"), ix.GetOrderPayerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("3hUMPnn3WNUbhTBoyXH3wHkWyq85MEZx9LWLTdEEaTef"), ix.GetCoinVaultAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("HEArHmgm9mnsj2u98Ldr4iWSwWvPPUUg8L9fwxT1cTyv"), ix.GetPcVaultAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"), ix.GetSplTokenProgramAccount().PublicKey)
require.Equal(t, SideBid, ix.Args.Side)
spew.Dump(ix.Args)
require.Equal(t, uint64(3165), ix.Args.LimitPrice)
require.Equal(t, uint64(10), ix.Args.MaxCoinQty)
require.Equal(t, uint64(3165000), ix.Args.MaxNativePcQtyIncludingFees)
require.Equal(t, SelfTradeBehaviorCancelProvide, ix.Args.SelfTradeBehavior)
require.Equal(t, OrderTypeLimit, ix.Args.OrderType)
}
{
in := msg.Instructions[7]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*SettleFunds)
if !ok {
t.Errorf("the instruction is not a *SettleFunds")
}
require.Equal(t, solana.MustPublicKeyFromBase58("8R6NtLSyVpgG6f8Z9cLKFcuaJtt3mqHypKGsmRixwyJV"), ix.GetOpenOrdersAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetOwnerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("3hUMPnn3WNUbhTBoyXH3wHkWyq85MEZx9LWLTdEEaTef"), ix.GetCoinVaultAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("HEArHmgm9mnsj2u98Ldr4iWSwWvPPUUg8L9fwxT1cTyv"), ix.GetPcVaultAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"), ix.GetSplTokenProgramAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("CQgjkmuDXXJ2WpF6bK9VWZko9T5hwVxAVgvmbV3gkfVe"), ix.GetVaultSignerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("AraQPzSsE31pdzeTe6Dkvu6g8PvreFW429DAYhsfKYRd"), ix.GetCoinWalletAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("tWQuevB8Rou1HS9a76fjYSQPrDixZMbVzXe2Q1kY5ma"), ix.GetPcWalletAccount().PublicKey)
}
}
func TestInstructionDecode_CloseOpenOrdersMsg(t *testing.T) {
CloseOpenOrdersMsg :=
"AQACBApz5x/t0hNl7QruhPzk4rIGR/001ey9oRXwI9JjP4d4bi3T/D9J3OFx/jgQJRQ+s2+9GBNxoSwkDUIUrgnJSVYxkJiME" +
"g9pt0UY4VGDhoK5gi+lfT9SnYfSCwUM68ArGoUPLW4CpHr4JNCatp3ELXDLKMv6JJ+37le50lbBJ2LvRT/gXmftFbCh8k/tkX" +
"lqLbwaAlSoCOY59nR43pTxwWwBAwQBAAACBQAOAAAA"
data, err := base64.StdEncoding.DecodeString(CloseOpenOrdersMsg)
require.NoError(t, err)
msg := new(solana.Message)
err = msg.UnmarshalWithDecoder(bin.NewBorshDecoder(data))
require.NoError(t, err)
require.Equal(t, 1, len(msg.Instructions))
{
in := msg.Instructions[0]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*CloseOpenOrders)
if !ok {
t.Errorf("the instruction is not a *CloseOpenOrders")
}
require.Equal(t, solana.MustPublicKeyFromBase58("8R6NtLSyVpgG6f8Z9cLKFcuaJtt3mqHypKGsmRixwyJV"), ix.GetOpenOrdersAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetOwnerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetDestinationAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
}
}
func TestInstructionDecode_InitOpenOrdersAuthorityMsg(t *testing.T) {
InitOpenOrdersAuthorityMsg :=
"AgEDBgpz5x/t0hNl7QruhPzk4rIGR/001ey9oRXwI9JjP4d43BTiskuLijN0Im9GJbaYltfYM7EWlK4B1p3CrtS9LytnTR0fu" +
"hJxv9yK2x3vBF9FKqGptmtvvRKj5Z2Yt80B+jGQmIwSD2m3RRjhUYOGgrmCL6V9P1Kdh9ILBQzrwCsaBqfVFxksXFEhjMlMPU" +
"rxf1ja7gibof1E49vZigAAAACFDy1uAqR6+CTQmradxC1wyyjL+iSft+5XudJWwSdi7zCsqcBb8R316Oq2E/s6bacxNqaZZYv" +
"YBqQrYp2V4ZVJAQUFAgADBAEFAA8AAAA="
data, err := base64.StdEncoding.DecodeString(InitOpenOrdersAuthorityMsg)
require.NoError(t, err)
msg := new(solana.Message)
err = msg.UnmarshalWithDecoder(bin.NewBorshDecoder(data))
require.NoError(t, err)
require.Equal(t, 1, len(msg.Instructions))
{
in := msg.Instructions[0]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*InitOpenOrders)
if !ok {
t.Errorf("the instruction is not a *InitOpenOrders")
}
require.Equal(t, solana.MustPublicKeyFromBase58("7xFCBA6F9xLg56hCMRBeDboJQUFNE5KHfjXGuFukavau"), ix.GetOpenOrdersAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetOwnerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("Fp7AZKKazcqU4N83opDzEZMTnQ6CtRxT118CGNZpziSe"), ix.GetMarketAuthorityAccount().PublicKey)
}
}
func TestInstructionDecode_CancelByClientIdAndConsumeEventsMsg(t *testing.T) {
CancelByClientIdAndConsumeEventsMsg :=
"AgABCQpz5x/t0hNl7QruhPzk4rIGR/001ey9oRXwI9JjP4d4AN+Ypnsy9CYUTPWS+d6mQ62AG7sIO9zzX4rvqJX0TU0xkJiME" +
"g9pt0UY4VGDhoK5gi+lfT9SnYfSCwUM68ArGm1hNQzbVLkSzhc9qtst1Jfq26d9dQ/22HU48BIZu1jY+IjY+lajf2iAo6Q1jm" +
"T81+vRa3/0oQMatxSavG6FGJICOaxQQvf9r8PyaRmnlkSN6BQs0u7SDcCOz4CLebCdaZJsaUup+JnjXJ8AAf8HKx949paxkKO" +
"e2znGSJJFNPXgDTHgtBNp84vnyAvrkVxNRBBpjT60T05B+sVW2BLmSnGFDy1uAqR6+CTQmradxC1wyyjL+iSft+5XudJWwSdi" +
"7zXpjGB3tXakV2utaBIsepEZdxt2dSrG41gLDbgqbkt4AggGAgMEAQAFDQAMAAAAoIYBAAAAAAAIBQECBQYHBwADAAAA//8="
data, err := base64.StdEncoding.DecodeString(CancelByClientIdAndConsumeEventsMsg)
require.NoError(t, err)
msg := new(solana.Message)
err = msg.UnmarshalWithDecoder(bin.NewBorshDecoder(data))
require.NoError(t, err)
require.Equal(t, 2, len(msg.Instructions))
{
in := msg.Instructions[0]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*CancelOrderByClientIdV2)
if !ok {
t.Errorf("the instruction is not a *CancelOrderByClientIdV2")
}
require.Equal(t, solana.MustPublicKeyFromBase58("14QkUy2jkZU2coqY8mTjL3uGiicTTng1VXrYKK1xk7yW"), ix.GetOpenOrdersAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetOwnerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("8MyQkxux1NnpNqpBbPeiQHYeDbZvdvs7CHmGpciSMWvs"), ix.GetBidsAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("HjB8zKe9xezDrgqXCSjCb5F7dMC9WMwtZoT7yKYEhZYV"), ix.GetAsksAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("9gpfTc4zsndJSdpnpXQbey16L5jW2GWcKeY3PLixqU4"), ix.GetEventQueueAccount().PublicKey)
require.Equal(t, uint64(100000), *ix.ClientOrderId)
}
{
in := msg.Instructions[1]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*ConsumeEvents)
if !ok {
t.Errorf("the instruction is not a *ConsumeEvents")
}
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("9gpfTc4zsndJSdpnpXQbey16L5jW2GWcKeY3PLixqU4"), ix.GetEventQueueAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("AraQPzSsE31pdzeTe6Dkvu6g8PvreFW429DAYhsfKYRd"), ix.GetCoinFeeReceivableAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("tWQuevB8Rou1HS9a76fjYSQPrDixZMbVzXe2Q1kY5ma"), ix.GetPcFeeReceivableAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("14QkUy2jkZU2coqY8mTjL3uGiicTTng1VXrYKK1xk7yW"), ix.GetOpenOrdersAccounts()[0].PublicKey)
}
}
func TestInstructionDecode_PruneMsg(t *testing.T) {
PruneMsg :=
"AgECCApz5x/t0hNl7QruhPzk4rIGR/001ey9oRXwI9JjP4d4uHiJfn+GplTj4talKGCSg9UtU/dYC8VBFhP5wi/VDboxkJiMEg" +
"9pt0UY4VGDhoK5gi+lfT9SnYfSCwUM68ArGm1hNQzbVLkSzhc9qtst1Jfq26d9dQ/22HU48BIZu1jY+IjY+lajf2iAo6Q1jmT8" +
"1+vRa3/0oQMatxSavG6FGJICOaxQQvf9r8PyaRmnlkSN6BQs0u7SDcCOz4CLebCdaQZjqIBBstRlvGKXFTn/swMxl19ZWB2KVy" +
"TAWVJDJv12hQ8tbgKkevgk0Jq2ncQtcMsoy/okn7fuV7nSVsEnYu9gYhiIP+KUcsxGrD3ryAixnmdYImbKDZVmwFIINIPFJgEH" +
"BwIDBAEGAAUHABAAAAD//w=="
data, err := base64.StdEncoding.DecodeString(PruneMsg)
require.NoError(t, err)
msg := new(solana.Message)
err = msg.UnmarshalWithDecoder(bin.NewBorshDecoder(data))
require.NoError(t, err)
require.Equal(t, 1, len(msg.Instructions))
{
in := msg.Instructions[0]
inst, err := DecodeInstruction(in.ResolveInstructionAccounts(msg), in.Data)
require.NoError(t, err)
spew.Dump(inst)
ix, ok := inst.Impl.(*Prune)
if !ok {
t.Errorf("the instruction is not a *Prune")
}
require.Equal(t, solana.MustPublicKeyFromBase58("4LUro5jaPaTurXK737QAxgJywdhABnFAMQkXX4ZyqqaZ"), ix.GetMarketAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("8MyQkxux1NnpNqpBbPeiQHYeDbZvdvs7CHmGpciSMWvs"), ix.GetBidsAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("HjB8zKe9xezDrgqXCSjCb5F7dMC9WMwtZoT7yKYEhZYV"), ix.GetAsksAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("9gpfTc4zsndJSdpnpXQbey16L5jW2GWcKeY3PLixqU4"), ix.GetEventQueueAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("hoakwpFB8UoLnPpLC56gsjpY7XbVwaCuRQRMQzN5TVh"), ix.GetOwnerAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("RwatxRLAiLNqjzBxB8hWXArgtJ7G84zq7xxoYnrUzZB"), ix.GetOpenOrdersAccount().PublicKey)
require.Equal(t, solana.MustPublicKeyFromBase58("DR6cxg8D7dXYhtCfuMqBmQFSTRAgcYXUd9SZK7dFgsD3"), ix.GetPruneAuthorityAccount().PublicKey)
}
}