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