@@ -3,7 +3,7 @@ package chainwriter_test
3
3
import (
4
4
"bytes"
5
5
"errors"
6
- "io/ioutil "
6
+ "fmt "
7
7
"math/big"
8
8
"os"
9
9
"reflect"
@@ -27,6 +27,12 @@ import (
27
27
txmMocks "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm/mocks"
28
28
)
29
29
30
+ type Arguments struct {
31
+ LookupTable solana.PublicKey
32
+ Seed1 []byte
33
+ Seed2 []byte
34
+ }
35
+
30
36
func TestChainWriter_GetAddresses (t * testing.T ) {
31
37
ctx := tests .Context (t )
32
38
@@ -87,7 +93,7 @@ func TestChainWriter_GetAddresses(t *testing.T) {
87
93
PublicKey : chainwriter.AccountConstant {Name : "WriteTest" , Address : programID .String ()},
88
94
Seeds : []chainwriter.Seed {
89
95
// extract seed2 for PDA lookup
90
- {Dynamic : chainwriter.AccountLookup {Name : "seed2 " , Location : "seed2 " }},
96
+ {Dynamic : chainwriter.AccountLookup {Name : "Seed2 " , Location : "Seed2 " }},
91
97
},
92
98
IsSigner : derivedTablePdaLookupMeta .IsSigner ,
93
99
IsWritable : derivedTablePdaLookupMeta .IsWritable ,
@@ -107,10 +113,10 @@ func TestChainWriter_GetAddresses(t *testing.T) {
107
113
// correlates to DerivedTable index in account lookup config
108
114
derivedTablePdaLookupMeta .PublicKey = storedPubKeys [0 ]
109
115
110
- args := map [ string ] interface {} {
111
- "lookup_table" : accountLookupMeta .PublicKey . Bytes () ,
112
- "seed1" : seed1 ,
113
- "seed2" : seed2 ,
116
+ args := Arguments {
117
+ LookupTable : accountLookupMeta .PublicKey ,
118
+ Seed1 : seed1 ,
119
+ Seed2 : seed2 ,
114
120
}
115
121
116
122
accountLookupConfig := []chainwriter.Lookup {
@@ -122,7 +128,7 @@ func TestChainWriter_GetAddresses(t *testing.T) {
122
128
},
123
129
chainwriter.AccountLookup {
124
130
Name : "LookupTable" ,
125
- Location : "lookup_table " ,
131
+ Location : "LookupTable " ,
126
132
IsSigner : accountLookupMeta .IsSigner ,
127
133
IsWritable : accountLookupMeta .IsWritable ,
128
134
},
@@ -131,7 +137,7 @@ func TestChainWriter_GetAddresses(t *testing.T) {
131
137
PublicKey : chainwriter.AccountConstant {Name : "WriteTest" , Address : solana .SystemProgramID .String ()},
132
138
Seeds : []chainwriter.Seed {
133
139
// extract seed1 for PDA lookup
134
- {Dynamic : chainwriter.AccountLookup {Name : "seed1 " , Location : "seed1 " }},
140
+ {Dynamic : chainwriter.AccountLookup {Name : "Seed1 " , Location : "Seed1 " }},
135
141
},
136
142
IsSigner : pdaLookupMeta .IsSigner ,
137
143
IsWritable : pdaLookupMeta .IsWritable ,
@@ -177,8 +183,8 @@ func TestChainWriter_GetAddresses(t *testing.T) {
177
183
})
178
184
179
185
t .Run ("resolve addresses for multiple indices from derived lookup table" , func (t * testing.T ) {
180
- args := map [ string ] interface {} {
181
- "seed2" : seed2 ,
186
+ args := Arguments {
187
+ Seed2 : seed2 ,
182
188
}
183
189
184
190
accountLookupConfig := []chainwriter.Lookup {
@@ -202,8 +208,8 @@ func TestChainWriter_GetAddresses(t *testing.T) {
202
208
})
203
209
204
210
t .Run ("resolve all addresses from derived lookup table if indices not specified" , func (t * testing.T ) {
205
- args := map [ string ] interface {} {
206
- "seed2" : seed2 ,
211
+ args := Arguments {
212
+ Seed2 : seed2 ,
207
213
}
208
214
209
215
accountLookupConfig := []chainwriter.Lookup {
@@ -274,7 +280,7 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) {
274
280
PublicKey : chainwriter.AccountConstant {Name : "WriteTest" , Address : programID .String ()},
275
281
Seeds : []chainwriter.Seed {
276
282
// extract seed1 for PDA lookup
277
- {Dynamic : chainwriter.AccountLookup {Name : "seed1 " , Location : "seed1 " }},
283
+ {Dynamic : chainwriter.AccountLookup {Name : "Seed1 " , Location : "Seed1 " }},
278
284
},
279
285
IsSigner : true ,
280
286
IsWritable : true ,
@@ -291,7 +297,7 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) {
291
297
PublicKey : chainwriter.AccountConstant {Name : "UnusedAccount" , Address : unusedProgramID .String ()},
292
298
Seeds : []chainwriter.Seed {
293
299
// extract seed2 for PDA lookup
294
- {Dynamic : chainwriter.AccountLookup {Name : "seed2 " , Location : "seed2 " }},
300
+ {Dynamic : chainwriter.AccountLookup {Name : "Seed2 " , Location : "Seed2 " }},
295
301
},
296
302
IsSigner : true ,
297
303
IsWritable : true ,
@@ -305,9 +311,9 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) {
305
311
StaticLookupTables : []solana.PublicKey {staticLookupTablePubkey1 , staticLookupTablePubkey2 },
306
312
}
307
313
308
- args := map [ string ] interface {} {
309
- "seed1" : seed1 ,
310
- "seed2" : seed2 ,
314
+ args := Arguments {
315
+ Seed1 : seed1 ,
316
+ Seed2 : seed2 ,
311
317
}
312
318
313
319
t .Run ("returns filtered map with only relevant addresses required by account lookup config" , func (t * testing.T ) {
@@ -403,6 +409,7 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
403
409
seed2 := []byte ("seed2" )
404
410
programID := solana .MustPublicKeyFromBase58 ("6AfuXF6HapDUhQfE4nQG9C1SGtA1YjP3icaJyRfU4RyE" )
405
411
derivedTablePda := mustFindPdaProgramAddress (t , [][]byte {seed2 }, programID )
412
+ fmt .Println ("pda:" , derivedTablePda )
406
413
// mock data account response from program
407
414
derivedLookupTablePubkey := mockDataAccountLookupTable (t , rw , derivedTablePda )
408
415
// mock fetch lookup table addresses call
@@ -414,19 +421,14 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
414
421
staticLookupKeys := chainwriter .CreateTestPubKeys (t , 2 )
415
422
mockFetchLookupTableAddresses (t , rw , staticLookupTablePubkey , staticLookupKeys )
416
423
417
- jsonFile , err := os .Open ("testContractIDL.json" )
418
- require .NoError (t , err )
419
-
420
- defer jsonFile .Close ()
421
-
422
- data , err := ioutil .ReadAll (jsonFile )
424
+ data , err := os .ReadFile ("testContractIDL.json" )
423
425
require .NoError (t , err )
424
426
425
427
testContractIDLJson := string (data )
426
428
427
429
cwConfig := chainwriter.ChainWriterConfig {
428
430
Programs : map [string ]chainwriter.ProgramConfig {
429
- "contractReaderInterface " : {
431
+ "contract_reader_interface " : {
430
432
Methods : map [string ]chainwriter.MethodConfig {
431
433
"initializeLookupTable" : {
432
434
FromAddress : admin .String (),
@@ -440,7 +442,7 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
440
442
PublicKey : chainwriter.AccountConstant {Name : "WriteTest" , Address : programID .String ()},
441
443
Seeds : []chainwriter.Seed {
442
444
// extract seed2 for PDA lookup
443
- {Dynamic : chainwriter.AccountLookup {Name : "seed2 " , Location : "seed2 " }},
445
+ {Dynamic : chainwriter.AccountLookup {Name : "Seed2 " , Location : "Seed2 " }},
444
446
},
445
447
IsSigner : false ,
446
448
IsWritable : false ,
@@ -462,7 +464,7 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
462
464
},
463
465
chainwriter.AccountLookup {
464
466
Name : "LookupTable" ,
465
- Location : "lookup_table " ,
467
+ Location : "LookupTable " ,
466
468
IsSigner : false ,
467
469
IsWritable : false ,
468
470
},
@@ -471,7 +473,7 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
471
473
PublicKey : chainwriter.AccountConstant {Name : "WriteTest" , Address : solana .SystemProgramID .String ()},
472
474
Seeds : []chainwriter.Seed {
473
475
// extract seed1 for PDA lookup
474
- {Dynamic : chainwriter.AccountLookup {Name : "seed1 " , Location : "seed1 " }},
476
+ {Dynamic : chainwriter.AccountLookup {Name : "Seed1 " , Location : "Seed1 " }},
475
477
},
476
478
IsSigner : false ,
477
479
IsWritable : false ,
@@ -514,22 +516,24 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
514
516
515
517
t .Run ("fails to encode payload if args with missing values provided" , func (t * testing.T ) {
516
518
txID := uuid .NewString ()
517
- args := map [string ]interface {}{}
518
- submitErr := cw .SubmitTransaction (ctx , "contractReaderInterface" , "initializeLookupTable" , args , txID , programID .String (), nil , nil )
519
+ type InvalidArgs struct {}
520
+ args := InvalidArgs {}
521
+ submitErr := cw .SubmitTransaction (ctx , "contract_reader_interface" , "initializeLookupTable" , args , txID , programID .String (), nil , nil )
519
522
require .Error (t , submitErr )
520
523
})
521
524
522
525
t .Run ("fails if invalid contract name provided" , func (t * testing.T ) {
523
526
txID := uuid .NewString ()
524
- args := map [ string ] interface {} {}
527
+ args := Arguments {}
525
528
submitErr := cw .SubmitTransaction (ctx , "badContract" , "initializeLookupTable" , args , txID , programID .String (), nil , nil )
526
529
require .Error (t , submitErr )
527
530
})
528
531
529
532
t .Run ("fails if invalid method provided" , func (t * testing.T ) {
530
533
txID := uuid .NewString ()
531
- args := map [string ]interface {}{}
532
- submitErr := cw .SubmitTransaction (ctx , "contractReaderInterface" , "badMethod" , args , txID , programID .String (), nil , nil )
534
+
535
+ args := Arguments {}
536
+ submitErr := cw .SubmitTransaction (ctx , "contract_reader_interface" , "badMethod" , args , txID , programID .String (), nil , nil )
533
537
require .Error (t , submitErr )
534
538
})
535
539
@@ -555,13 +559,13 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
555
559
return true
556
560
}), & txID , mock .Anything ).Return (nil ).Once ()
557
561
558
- args := map [string ]interface {}{
559
- "lookupTable" : chainwriter .GetRandomPubKey (t ).Bytes (),
560
- "lookup_table" : account2 .Bytes (),
561
- "seed1" : seed1 ,
562
- "seed2" : seed2 ,
562
+ args := Arguments {
563
+ LookupTable : account2 ,
564
+ Seed1 : seed1 ,
565
+ Seed2 : seed2 ,
563
566
}
564
- submitErr := cw .SubmitTransaction (ctx , "contractReaderInterface" , "initializeLookupTable" , args , txID , programID .String (), nil , nil )
567
+
568
+ submitErr := cw .SubmitTransaction (ctx , "contract_reader_interface" , "initializeLookupTable" , args , txID , programID .String (), nil , nil )
565
569
require .NoError (t , submitErr )
566
570
})
567
571
}
0 commit comments