@@ -6,10 +6,13 @@ import (
6
6
"testing"
7
7
8
8
"github.com/ethereum/go-ethereum/common"
9
+ ag_binary "github.com/gagliardetto/binary"
9
10
"github.com/gagliardetto/solana-go"
10
11
"github.com/gagliardetto/solana-go/rpc"
11
12
"github.com/google/go-cmp/cmp"
13
+ "github.com/google/go-cmp/cmp/cmpopts"
12
14
cselectors "github.com/smartcontractkit/chain-selectors"
15
+ bindings "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/mcm"
13
16
"github.com/stretchr/testify/require"
14
17
15
18
"github.com/smartcontractkit/mcms/sdk/solana/mocks"
@@ -23,9 +26,36 @@ func Test_NewConfigurer(t *testing.T) {
23
26
auth := solana .MustPrivateKeyFromBase58 ("DmPfeHBC8Brf8s5qQXi25bmJ996v6BHRtaLc6AH51yFGSqQpUMy1oHkbbXobPNBdgGH2F29PAmoq9ZZua4K9vCc" )
24
27
chainSelector := types .ChainSelector (cselectors .SOLANA_DEVNET .Selector )
25
28
26
- configurer := NewConfigurer (client , auth , chainSelector )
29
+ tests := []struct {
30
+ name string
31
+ constructorFn func () * Configurer
32
+ wantSkipTransaction bool
33
+ }{
34
+ {
35
+ name : "standard args" ,
36
+ constructorFn : func () * Configurer {
37
+ return NewConfigurer (client , auth , chainSelector )
38
+ },
39
+ wantSkipTransaction : false ,
40
+ },
41
+ {
42
+ name : "skip transaction option" ,
43
+ constructorFn : func () * Configurer {
44
+ return NewConfigurer (client , auth , chainSelector , WithDoNotSendInstructionsOnChain ())
45
+ },
46
+ wantSkipTransaction : true ,
47
+ },
48
+ }
27
49
28
- require .NotNil (t , configurer )
50
+ for _ , tt := range tests {
51
+ t .Run (tt .name , func (t * testing.T ) {
52
+ t .Parallel ()
53
+ configurer := tt .constructorFn ()
54
+
55
+ require .NotNil (t , configurer )
56
+ require .Equal (t , tt .wantSkipTransaction , configurer .skipSend )
57
+ })
58
+ }
29
59
}
30
60
31
61
func TestConfigurer_SetConfig (t * testing.T ) {
@@ -39,14 +69,18 @@ func TestConfigurer_SetConfig(t *testing.T) {
39
69
clearRoot := false
40
70
41
71
tests := []struct {
42
- name string
43
- mcmConfig * types.Config
44
- setup func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient )
45
- want string
46
- wantErr string
72
+ name string
73
+ auth solana.PrivateKey
74
+ options []configurerOption
75
+ mcmConfig * types.Config
76
+ setup func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient )
77
+ wantHash string
78
+ wantInstructions []solana.Instruction
79
+ wantErr string
47
80
}{
48
81
{
49
- name : "success" ,
82
+ name : "success - send instructions" ,
83
+ auth : auth ,
50
84
mcmConfig : defaultMcmConfig ,
51
85
setup : func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient ) {
52
86
t .Helper ()
@@ -62,16 +96,38 @@ func TestConfigurer_SetConfig(t *testing.T) {
62
96
mockSolanaTransaction (t , mockJSONRPCClient , 13 , 23 ,
63
97
"52f3VmvW7m9uTQu3PtyibgxnAvEuXDmm9umuHherGjS4pzRR7QXRDKnZhh6b95P7pQxzTgvE1muMNKYEY7YWsS3G" , nil , nil )
64
98
},
65
- want : "52f3VmvW7m9uTQu3PtyibgxnAvEuXDmm9umuHherGjS4pzRR7QXRDKnZhh6b95P7pQxzTgvE1muMNKYEY7YWsS3G" ,
99
+ wantHash : "52f3VmvW7m9uTQu3PtyibgxnAvEuXDmm9umuHherGjS4pzRR7QXRDKnZhh6b95P7pQxzTgvE1muMNKYEY7YWsS3G" ,
100
+ wantInstructions : []solana.Instruction {
101
+ bindings .NewInitSignersInstructionBuilder ().Build (),
102
+ bindings .NewAppendSignersInstructionBuilder ().Build (),
103
+ bindings .NewFinalizeSignersInstructionBuilder ().Build (),
104
+ bindings .NewSetConfigInstructionBuilder ().Build (),
105
+ },
106
+ },
107
+ {
108
+ name : "success - do not send instructions" ,
109
+ auth : auth ,
110
+ options : []configurerOption {WithDoNotSendInstructionsOnChain ()},
111
+ mcmConfig : defaultMcmConfig ,
112
+ setup : func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient ) { t .Helper () },
113
+ wantHash : "" ,
114
+ wantInstructions : []solana.Instruction {
115
+ bindings .NewInitSignersInstructionBuilder ().Build (),
116
+ bindings .NewAppendSignersInstructionBuilder ().Build (),
117
+ bindings .NewFinalizeSignersInstructionBuilder ().Build (),
118
+ bindings .NewSetConfigInstructionBuilder ().Build (),
119
+ },
66
120
},
67
121
{
68
122
name : "failure: too many signers" ,
123
+ auth : auth ,
69
124
mcmConfig : & types.Config {Quorum : 1 , Signers : generateSigners (t , 181 )},
70
125
setup : func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient ) { t .Helper () },
71
126
wantErr : "too many signers (max 180)" ,
72
127
},
73
128
{
74
129
name : "failure: initialize signers error" ,
130
+ auth : auth ,
75
131
mcmConfig : defaultMcmConfig ,
76
132
setup : func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient ) {
77
133
t .Helper ()
@@ -80,10 +136,11 @@ func TestConfigurer_SetConfig(t *testing.T) {
80
136
"4PQcRHQJT4cRQZooAhZMAP9ZXJsAka9DeKvXeYvXAvPpHb4Qkc5rmTSHDA2SZSh9aKPBguBx4kmcyHHbkytoAiRr" ,
81
137
nil , fmt .Errorf ("initialize signers error" ))
82
138
},
83
- wantErr : "unable to initialize signers : unable to send instruction: initialize signers error" ,
139
+ wantErr : "unable to set config: unable to send instruction 0 - initSigners : unable to send instruction: initialize signers error" ,
84
140
},
85
141
{
86
142
name : "failure: append signers error" ,
143
+ auth : auth ,
87
144
mcmConfig : defaultMcmConfig ,
88
145
setup : func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient ) {
89
146
t .Helper ()
@@ -97,10 +154,11 @@ func TestConfigurer_SetConfig(t *testing.T) {
97
154
"7D9XEYRnCn1D5JFrrYMPUaHfog7Vnj5rbPdj7kbULa4hKq7GsnA7Q8KNQfLEgfCawBsW4dcH2MQAp4km1dnjr6V" ,
98
155
nil , fmt .Errorf ("append signers error" ))
99
156
},
100
- wantErr : "unable to append signers (0) : unable to send instruction: append signers error" ,
157
+ wantErr : "unable to set config: unable to send instruction 1 - appendSigners0 : unable to send instruction: append signers error" ,
101
158
},
102
159
{
103
160
name : "failure: finalize signers error" ,
161
+ auth : auth ,
104
162
mcmConfig : defaultMcmConfig ,
105
163
setup : func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient ) {
106
164
t .Helper ()
@@ -116,10 +174,11 @@ func TestConfigurer_SetConfig(t *testing.T) {
116
174
"2iEeniu3QUgXNsjau8r7fZ7XLb2g1F3q9VJJKvRyyFz4hHgVvhGkLgSUdmRumfXKWv8spJ9ihudGFyPZsPGdp4Ya" ,
117
175
nil , fmt .Errorf ("finalize signers error" ))
118
176
},
119
- wantErr : "unable to finalize signers : unable to send instruction: finalize signers error" ,
177
+ wantErr : "unable to set config: unable to send instruction 2 - finalizeSigners : unable to send instruction: finalize signers error" ,
120
178
},
121
179
{
122
180
name : "failure: set config error" ,
181
+ auth : auth ,
123
182
mcmConfig : & types.Config {Quorum : 1 , Signers : []common.Address {common .HexToAddress ("0x1" )}},
124
183
setup : func (t * testing.T , configurer * Configurer , mockJSONRPCClient * mocks.JSONRPCClient ) {
125
184
t .Helper ()
@@ -137,21 +196,23 @@ func TestConfigurer_SetConfig(t *testing.T) {
137
196
"52f3VmvW7m9uTQu3PtyibgxnAvEuXDmm9umuHherGjS4pzRR7QXRDKnZhh6b95P7pQxzTgvE1muMNKYEY7YWsS3G" ,
138
197
nil , fmt .Errorf ("set config error" ))
139
198
},
140
- wantErr : "unable to set config: unable to send instruction: set config error" ,
199
+ wantErr : "unable to set config: unable to send instruction 3 - setConfig: unable to send instruction : set config error" ,
141
200
},
142
201
}
143
202
for _ , tt := range tests {
144
203
t .Run (tt .name , func (t * testing.T ) {
145
204
t .Parallel ()
146
205
147
- configurer , mockJSONRPCClient := newTestConfigurer (t , auth , chainSelector )
206
+ configurer , mockJSONRPCClient := newTestConfigurer (t , tt . auth , chainSelector , tt . options ... )
148
207
tt .setup (t , configurer , mockJSONRPCClient )
149
208
150
209
got , err := configurer .SetConfig (ctx , ContractAddress (testMCMProgramID , testPDASeed ), tt .mcmConfig , clearRoot )
151
210
152
211
if tt .wantErr == "" {
153
212
require .NoError (t , err )
154
- require .Empty (t , cmp .Diff (tt .want , got .Hash ))
213
+ require .Empty (t , cmp .Diff (tt .wantHash , got .Hash ))
214
+ require .Empty (t , cmp .Diff (tt .wantInstructions , got .RawData .([]solana.Instruction ),
215
+ cmpopts .IgnoreFields (ag_binary.BaseVariant {}, "Impl" )))
155
216
} else {
156
217
require .ErrorContains (t , err , tt .wantErr )
157
218
}
@@ -161,11 +222,13 @@ func TestConfigurer_SetConfig(t *testing.T) {
161
222
162
223
// ----- helpers -----
163
224
164
- func newTestConfigurer (t * testing.T , auth solana.PrivateKey , chainSelector types.ChainSelector ) (* Configurer , * mocks.JSONRPCClient ) {
225
+ func newTestConfigurer (
226
+ t * testing.T , auth solana.PrivateKey , chainSelector types.ChainSelector , options ... configurerOption ,
227
+ ) (* Configurer , * mocks.JSONRPCClient ) {
165
228
t .Helper ()
166
229
167
230
mockJSONRPCClient := mocks .NewJSONRPCClient (t )
168
231
client := rpc .NewWithCustomRPCClient (mockJSONRPCClient )
169
232
170
- return NewConfigurer (client , auth , chainSelector ), mockJSONRPCClient
233
+ return NewConfigurer (client , auth , chainSelector , options ... ), mockJSONRPCClient
171
234
}
0 commit comments