@@ -13,7 +13,10 @@ use ntt_messages::{
13
13
transceiver:: TransceiverMessage , transceivers:: wormhole:: WormholeTransceiver ,
14
14
trimmed_amount:: TrimmedAmount ,
15
15
} ;
16
- use sdk:: transceivers:: wormhole:: instructions:: receive_message:: ReceiveMessage ;
16
+ use sdk:: {
17
+ accounts:: { good_ntt, NTTAccounts } ,
18
+ transceivers:: wormhole:: instructions:: receive_message:: ReceiveMessage ,
19
+ } ;
17
20
use solana_program:: instruction:: InstructionError ;
18
21
use solana_program_test:: * ;
19
22
use solana_sdk:: { signature:: Keypair , signer:: Signer , transaction:: TransactionError } ;
@@ -47,7 +50,7 @@ fn init_transfer_accs_args(
47
50
) -> ( Transfer , TransferArgs ) {
48
51
let accs = Transfer {
49
52
payer : ctx. payer . pubkey ( ) ,
50
- peer : test_data . ntt . peer ( OTHER_CHAIN ) ,
53
+ peer : good_ntt . peer ( OTHER_CHAIN ) ,
51
54
mint : test_data. mint ,
52
55
from : test_data. user_token_account ,
53
56
from_authority : test_data. user . pubkey ( ) ,
@@ -72,27 +75,24 @@ fn init_redeem_accs(
72
75
) -> Redeem {
73
76
Redeem {
74
77
payer : ctx. payer . pubkey ( ) ,
75
- peer : test_data. ntt . peer ( chain_id) ,
76
- transceiver : test_data. ntt . program ,
77
- transceiver_message : test_data
78
- . ntt
79
- . transceiver_message ( chain_id, ntt_manager_message. id ) ,
80
- inbox_item : test_data. ntt . inbox_item ( chain_id, ntt_manager_message) ,
81
- inbox_rate_limit : test_data. ntt . inbox_rate_limit ( chain_id) ,
78
+ peer : good_ntt. peer ( chain_id) ,
79
+ transceiver : good_ntt. program ( ) ,
80
+ transceiver_message : good_ntt. transceiver_message ( chain_id, ntt_manager_message. id ) ,
81
+ inbox_item : good_ntt. inbox_item ( chain_id, ntt_manager_message) ,
82
+ inbox_rate_limit : good_ntt. inbox_rate_limit ( chain_id) ,
82
83
mint : test_data. mint ,
83
84
}
84
85
}
85
86
86
87
fn init_receive_message_accs (
87
88
ctx : & mut ProgramTestContext ,
88
- test_data : & TestData ,
89
89
vaa : Pubkey ,
90
90
chain_id : u16 ,
91
91
id : [ u8 ; 32 ] ,
92
92
) -> ReceiveMessage {
93
93
ReceiveMessage {
94
94
payer : ctx. payer . pubkey ( ) ,
95
- peer : test_data . ntt . transceiver_peer ( chain_id) ,
95
+ peer : good_ntt . transceiver_peer ( chain_id) ,
96
96
vaa,
97
97
chain_id,
98
98
id,
@@ -101,7 +101,6 @@ fn init_receive_message_accs(
101
101
102
102
async fn post_transfer_vaa (
103
103
ctx : & mut ProgramTestContext ,
104
- test_data : & TestData ,
105
104
id : [ u8 ; 32 ] ,
106
105
amount : u64 ,
107
106
// TODO: this is used for a negative testing of the recipient ntt_manager
@@ -129,7 +128,7 @@ async fn post_transfer_vaa(
129
128
OTHER_MANAGER ,
130
129
recipient_ntt_manager
131
130
. map ( |k| k. to_bytes ( ) )
132
- . unwrap_or_else ( || test_data . ntt . program . to_bytes ( ) ) ,
131
+ . unwrap_or_else ( || good_ntt . program ( ) . to_bytes ( ) ) ,
133
132
ntt_manager_message. clone ( ) ,
134
133
vec ! [ ] ,
135
134
) ;
@@ -147,24 +146,24 @@ async fn post_transfer_vaa(
147
146
payload : transceiver_message,
148
147
} ;
149
148
150
- let posted_vaa = post_vaa ( & test_data . ntt . wormhole , ctx, vaa) . await ;
149
+ let posted_vaa = post_vaa ( & good_ntt . wormhole ( ) , ctx, vaa) . await ;
151
150
152
151
( posted_vaa, ntt_manager_message)
153
152
}
154
153
155
- async fn outbound_capacity ( ctx : & mut ProgramTestContext , test_data : & TestData ) -> u64 {
154
+ async fn outbound_capacity ( ctx : & mut ProgramTestContext ) -> u64 {
156
155
let clock: Clock = ctx. banks_client . get_sysvar ( ) . await . unwrap ( ) ;
157
156
let rate_limit: OutboxRateLimit = ctx
158
- . get_account_data_anchor ( test_data . ntt . outbox_rate_limit ( ) )
157
+ . get_account_data_anchor ( good_ntt . outbox_rate_limit ( ) )
159
158
. await ;
160
159
161
160
rate_limit. rate_limit . capacity_at ( clock. unix_timestamp )
162
161
}
163
162
164
- async fn inbound_capacity ( ctx : & mut ProgramTestContext , test_data : & TestData ) -> u64 {
163
+ async fn inbound_capacity ( ctx : & mut ProgramTestContext ) -> u64 {
165
164
let clock: Clock = ctx. banks_client . get_sysvar ( ) . await . unwrap ( ) ;
166
165
let rate_limit: InboxRateLimit = ctx
167
- . get_account_data_anchor ( test_data . ntt . inbox_rate_limit ( OTHER_CHAIN ) )
166
+ . get_account_data_anchor ( good_ntt . inbox_rate_limit ( OTHER_CHAIN ) )
168
167
. await ;
169
168
170
169
rate_limit. rate_limit . capacity_at ( clock. unix_timestamp )
@@ -175,39 +174,34 @@ async fn test_cancel() {
175
174
let recipient = Keypair :: new ( ) ;
176
175
let ( mut ctx, test_data) = setup ( Mode :: Locking ) . await ;
177
176
178
- let ( vaa0, msg0) =
179
- post_transfer_vaa ( & mut ctx, & test_data, [ 0u8 ; 32 ] , 1000 , None , & recipient) . await ;
180
- let ( vaa1, msg1) =
181
- post_transfer_vaa ( & mut ctx, & test_data, [ 1u8 ; 32 ] , 2000 , None , & recipient) . await ;
177
+ let ( vaa0, msg0) = post_transfer_vaa ( & mut ctx, [ 0u8 ; 32 ] , 1000 , None , & recipient) . await ;
178
+ let ( vaa1, msg1) = post_transfer_vaa ( & mut ctx, [ 1u8 ; 32 ] , 2000 , None , & recipient) . await ;
182
179
183
- let inbound_limit_before = inbound_capacity ( & mut ctx, & test_data ) . await ;
184
- let outbound_limit_before = outbound_capacity ( & mut ctx, & test_data ) . await ;
180
+ let inbound_limit_before = inbound_capacity ( & mut ctx) . await ;
181
+ let outbound_limit_before = outbound_capacity ( & mut ctx) . await ;
185
182
186
183
receive_message (
187
- & test_data . ntt ,
188
- init_receive_message_accs ( & mut ctx, & test_data , vaa0, OTHER_CHAIN , [ 0u8 ; 32 ] ) ,
184
+ & good_ntt ,
185
+ init_receive_message_accs ( & mut ctx, vaa0, OTHER_CHAIN , [ 0u8 ; 32 ] ) ,
189
186
)
190
187
. submit ( & mut ctx)
191
188
. await
192
189
. unwrap ( ) ;
193
190
194
191
redeem (
195
- & test_data . ntt ,
192
+ & good_ntt ,
196
193
init_redeem_accs ( & mut ctx, & test_data, OTHER_CHAIN , msg0) ,
197
194
RedeemArgs { } ,
198
195
)
199
196
. submit ( & mut ctx)
200
197
. await
201
198
. unwrap ( ) ;
202
199
203
- assert_eq ! (
204
- outbound_limit_before,
205
- outbound_capacity( & mut ctx, & test_data) . await
206
- ) ;
200
+ assert_eq ! ( outbound_limit_before, outbound_capacity( & mut ctx) . await ) ;
207
201
208
202
assert_eq ! (
209
203
inbound_limit_before - 1000 ,
210
- inbound_capacity( & mut ctx, & test_data ) . await
204
+ inbound_capacity( & mut ctx) . await
211
205
) ;
212
206
213
207
let outbox_item = Keypair :: new ( ) ;
@@ -216,40 +210,37 @@ async fn test_cancel() {
216
210
init_transfer_accs_args ( & mut ctx, & test_data, outbox_item. pubkey ( ) , 7000 , true ) ;
217
211
218
212
approve_token_authority (
219
- & test_data . ntt ,
213
+ & good_ntt ,
220
214
& test_data. user_token_account ,
221
215
& test_data. user . pubkey ( ) ,
222
216
& args,
223
217
)
224
218
. submit_with_signers ( & [ & test_data. user ] , & mut ctx)
225
219
. await
226
220
. unwrap ( ) ;
227
- transfer ( & test_data . ntt , accs, args, Mode :: Locking )
221
+ transfer ( & good_ntt , accs, args, Mode :: Locking )
228
222
. submit_with_signers ( & [ & outbox_item] , & mut ctx)
229
223
. await
230
224
. unwrap ( ) ;
231
225
232
226
assert_eq ! (
233
227
outbound_limit_before - 7000 ,
234
- outbound_capacity( & mut ctx, & test_data ) . await
228
+ outbound_capacity( & mut ctx) . await
235
229
) ;
236
230
237
231
// fully replenished
238
- assert_eq ! (
239
- inbound_limit_before,
240
- inbound_capacity( & mut ctx, & test_data) . await
241
- ) ;
232
+ assert_eq ! ( inbound_limit_before, inbound_capacity( & mut ctx) . await ) ;
242
233
243
234
receive_message (
244
- & test_data . ntt ,
245
- init_receive_message_accs ( & mut ctx, & test_data , vaa1, OTHER_CHAIN , [ 1u8 ; 32 ] ) ,
235
+ & good_ntt ,
236
+ init_receive_message_accs ( & mut ctx, vaa1, OTHER_CHAIN , [ 1u8 ; 32 ] ) ,
246
237
)
247
238
. submit ( & mut ctx)
248
239
. await
249
240
. unwrap ( ) ;
250
241
251
242
redeem (
252
- & test_data . ntt ,
243
+ & good_ntt ,
253
244
init_redeem_accs ( & mut ctx, & test_data, OTHER_CHAIN , msg1) ,
254
245
RedeemArgs { } ,
255
246
)
@@ -259,12 +250,12 @@ async fn test_cancel() {
259
250
260
251
assert_eq ! (
261
252
outbound_limit_before - 5000 ,
262
- outbound_capacity( & mut ctx, & test_data ) . await
253
+ outbound_capacity( & mut ctx) . await
263
254
) ;
264
255
265
256
assert_eq ! (
266
257
inbound_limit_before - 2000 ,
267
- inbound_capacity( & mut ctx, & test_data ) . await
258
+ inbound_capacity( & mut ctx) . await
268
259
) ;
269
260
}
270
261
@@ -276,7 +267,6 @@ async fn test_wrong_recipient_ntt_manager() {
276
267
277
268
let ( vaa0, msg0) = post_transfer_vaa (
278
269
& mut ctx,
279
- & test_data,
280
270
[ 0u8 ; 32 ] ,
281
271
1000 ,
282
272
Some ( & Pubkey :: default ( ) ) ,
@@ -285,15 +275,15 @@ async fn test_wrong_recipient_ntt_manager() {
285
275
. await ;
286
276
287
277
receive_message (
288
- & test_data . ntt ,
289
- init_receive_message_accs ( & mut ctx, & test_data , vaa0, OTHER_CHAIN , [ 0u8 ; 32 ] ) ,
278
+ & good_ntt ,
279
+ init_receive_message_accs ( & mut ctx, vaa0, OTHER_CHAIN , [ 0u8 ; 32 ] ) ,
290
280
)
291
281
. submit ( & mut ctx)
292
282
. await
293
283
. unwrap ( ) ;
294
284
295
285
let err = redeem (
296
- & test_data . ntt ,
286
+ & good_ntt ,
297
287
init_redeem_accs ( & mut ctx, & test_data, OTHER_CHAIN , msg0) ,
298
288
RedeemArgs { } ,
299
289
)
0 commit comments