@@ -23,6 +23,7 @@ import (
23
23
24
24
type InnerAccountArgs struct {
25
25
Accounts []* solana.AccountMeta
26
+ Bitmap uint64
26
27
}
27
28
28
29
type TestAccountArgs struct {
@@ -132,27 +133,29 @@ func TestAccountLookups(t *testing.T) {
132
133
require .Error (t , err )
133
134
})
134
135
135
- t .Run ("AccountLookup works with MetaBool lookups" , func (t * testing.T ) {
136
+ t .Run ("AccountLookup works with MetaBool bitmap lookups" , func (t * testing.T ) {
136
137
accounts := [3 ]* solana.AccountMeta {}
137
138
138
139
for i := 0 ; i < 3 ; i ++ {
139
140
accounts [i ] = & solana.AccountMeta {
140
141
PublicKey : chainwriter .GetRandomPubKey (t ),
141
- IsSigner : i % 2 == 0 ,
142
- IsWritable : (i + 1 )% 2 == 0 ,
142
+ IsSigner : ( i ) % 2 == 0 ,
143
+ IsWritable : (i )% 2 == 0 ,
143
144
}
144
145
}
145
146
146
147
lookupConfig := chainwriter.AccountLookup {
147
148
Name : "InvalidAccount" ,
148
149
Location : "Inner.Accounts.PublicKey" ,
149
- IsSigner : chainwriter.MetaBool {Location : "Inner.Accounts.IsSigner " },
150
- IsWritable : chainwriter.MetaBool {Location : "Inner.Accounts.IsWritable " },
150
+ IsSigner : chainwriter.MetaBool {BitmapLocation : "Inner.Bitmap " },
151
+ IsWritable : chainwriter.MetaBool {BitmapLocation : "Inner.Bitmap " },
151
152
}
152
153
153
154
args := TestAccountArgs {
154
155
Inner : InnerAccountArgs {
155
156
Accounts : accounts [:],
157
+ // should be 101... so {true, false, true}
158
+ Bitmap : 5 ,
156
159
},
157
160
}
158
161
@@ -164,79 +167,10 @@ func TestAccountLookups(t *testing.T) {
164
167
}
165
168
})
166
169
167
- t .Run ("AccountLookup works with MetaBool lookups when a meta field is missing" , func (t * testing.T ) {
168
- accounts := [3 ]* solana.AccountMeta {}
169
-
170
- for i := 0 ; i < 3 ; i ++ {
171
- accounts [i ] = & solana.AccountMeta {
172
- PublicKey : chainwriter .GetRandomPubKey (t ),
173
- IsWritable : true ,
174
- }
175
- }
176
-
177
- lookupConfig := chainwriter.AccountLookup {
178
- Name : "InvalidAccount" ,
179
- Location : "Inner.Accounts.PublicKey" ,
180
- IsSigner : chainwriter.MetaBool {Location : "Inner.Accounts.IsSigner" },
181
- IsWritable : chainwriter.MetaBool {Location : "Inner.Accounts.IsWritable" },
182
- }
183
-
184
- args := TestAccountArgs {
185
- Inner : InnerAccountArgs {
186
- Accounts : accounts [:],
187
- },
188
- }
189
-
190
- result , err := lookupConfig .Resolve (ctx , args , nil , nil )
191
- require .NoError (t , err )
192
-
193
- for i , meta := range result {
194
- require .Equal (t , accounts [i ], meta )
195
- }
196
- })
197
-
198
- t .Run ("AccountLookup works with MetaBool lookups in a different location" , func (t * testing.T ) {
199
- type TestAccountArgsExtended struct {
200
- Inner InnerAccountArgs
201
- ExternalBool bool
202
- }
203
-
204
- accounts := [3 ]* solana.AccountMeta {}
205
-
206
- for i := 0 ; i < 3 ; i ++ {
207
- accounts [i ] = & solana.AccountMeta {
208
- PublicKey : chainwriter .GetRandomPubKey (t ),
209
- IsWritable : true ,
210
- IsSigner : true ,
211
- }
212
- }
213
-
214
- lookupConfig := chainwriter.AccountLookup {
215
- Name : "InvalidAccount" ,
216
- Location : "Inner.Accounts.PublicKey" ,
217
- IsSigner : chainwriter.MetaBool {Location : "ExternalBool" },
218
- IsWritable : chainwriter.MetaBool {Location : "ExternalBool" },
219
- }
220
-
221
- args := TestAccountArgsExtended {
222
- Inner : InnerAccountArgs {
223
- Accounts : accounts [:],
224
- },
225
- ExternalBool : true ,
226
- }
227
-
228
- result , err := lookupConfig .Resolve (ctx , args , nil , nil )
229
- require .NoError (t , err )
230
-
231
- for i , meta := range result {
232
- require .Equal (t , accounts [i ], meta )
233
- }
234
- })
235
-
236
- t .Run ("AccountLookup fails with MetaBool due to an invalid number of Meta lookups" , func (t * testing.T ) {
170
+ t .Run ("AccountLookup fails with MetaBool due to an invalid number of bitmaps" , func (t * testing.T ) {
237
171
type TestAccountArgsExtended struct {
238
- Inner InnerAccountArgs
239
- ExternalBools []bool
172
+ Inner InnerAccountArgs
173
+ Bitmaps []uint64
240
174
}
241
175
242
176
accounts := [3 ]* solana.AccountMeta {}
@@ -252,22 +186,22 @@ func TestAccountLookups(t *testing.T) {
252
186
lookupConfig := chainwriter.AccountLookup {
253
187
Name : "InvalidAccount" ,
254
188
Location : "Inner.Accounts.PublicKey" ,
255
- IsSigner : chainwriter.MetaBool {Location : "ExternalBools " },
256
- IsWritable : chainwriter.MetaBool {Location : "ExternalBools " },
189
+ IsSigner : chainwriter.MetaBool {BitmapLocation : "Bitmaps " },
190
+ IsWritable : chainwriter.MetaBool {BitmapLocation : "Bitmaps " },
257
191
}
258
192
259
193
args := TestAccountArgsExtended {
260
194
Inner : InnerAccountArgs {
261
195
Accounts : accounts [:],
262
196
},
263
- ExternalBools : []bool { true , true },
197
+ Bitmaps : []uint64 { 5 , 3 },
264
198
}
265
199
266
200
_ , err := lookupConfig .Resolve (ctx , args , nil , nil )
267
- require .Contains (t , err .Error (), "boolean array length 2 doesn't match pubkey count 3 for location " )
201
+ require .Contains (t , err .Error (), "bitmap value is not a single value " )
268
202
})
269
203
270
- t .Run ("AccountLookup fails with MetaBool with an Invalid Location " , func (t * testing.T ) {
204
+ t .Run ("AccountLookup fails with MetaBool with an Invalid BitmapLocation " , func (t * testing.T ) {
271
205
accounts := [3 ]* solana.AccountMeta {}
272
206
273
207
for i := 0 ; i < 3 ; i ++ {
@@ -280,8 +214,8 @@ func TestAccountLookups(t *testing.T) {
280
214
lookupConfig := chainwriter.AccountLookup {
281
215
Name : "InvalidAccount" ,
282
216
Location : "Inner.Accounts.PublicKey" ,
283
- IsSigner : chainwriter.MetaBool {Location : "Invalid.IsSigner " },
284
- IsWritable : chainwriter.MetaBool {Location : "Invalid.IsWritable " },
217
+ IsSigner : chainwriter.MetaBool {BitmapLocation : "Invalid.Bitmap " },
218
+ IsWritable : chainwriter.MetaBool {BitmapLocation : "Invalid.Bitmap " },
285
219
}
286
220
287
221
args := TestAccountArgs {
@@ -291,10 +225,10 @@ func TestAccountLookups(t *testing.T) {
291
225
}
292
226
293
227
_ , err := lookupConfig .Resolve (ctx , args , nil , nil )
294
- require .Contains (t , err .Error (), "error reading bools from location" )
228
+ require .Contains (t , err .Error (), "error reading bitmap from location" )
295
229
})
296
230
297
- t .Run ("AccountLookup fails when MetaBool is an invalid type" , func (t * testing.T ) {
231
+ t .Run ("AccountLookup fails when MetaBool Bitmap is an invalid type" , func (t * testing.T ) {
298
232
accounts := [3 ]* solana.AccountMeta {}
299
233
300
234
for i := 0 ; i < 3 ; i ++ {
@@ -307,8 +241,8 @@ func TestAccountLookups(t *testing.T) {
307
241
lookupConfig := chainwriter.AccountLookup {
308
242
Name : "InvalidAccount" ,
309
243
Location : "Inner.Accounts.PublicKey" ,
310
- IsSigner : chainwriter.MetaBool {Location : "Inner" },
311
- IsWritable : chainwriter.MetaBool {Location : "Inner" },
244
+ IsSigner : chainwriter.MetaBool {BitmapLocation : "Inner" },
245
+ IsWritable : chainwriter.MetaBool {BitmapLocation : "Inner" },
312
246
}
313
247
314
248
args := TestAccountArgs {
0 commit comments