2
2
#![ feature( type_changing_struct_update) ]
3
3
4
4
use anchor_lang:: prelude:: * ;
5
- use common:: setup:: { TestData , OTHER_CHAIN , OTHER_MANAGER , OTHER_TRANSCEIVER , THIS_CHAIN } ;
5
+ use common:: setup:: { TestData , OTHER_CHAIN } ;
6
6
use example_native_token_transfers:: {
7
- error:: NTTError ,
8
7
instructions:: { RedeemArgs , TransferArgs } ,
9
8
queue:: { inbox:: InboxRateLimit , outbox:: OutboxRateLimit } ,
10
9
} ;
11
10
use ntt_messages:: {
12
11
chain_id:: ChainId , mode:: Mode , ntt:: NativeTokenTransfer , ntt_manager:: NttManagerMessage ,
13
- transceiver:: TransceiverMessage , transceivers:: wormhole:: WormholeTransceiver ,
14
- trimmed_amount:: TrimmedAmount ,
15
12
} ;
16
13
use sdk:: {
17
14
accounts:: { good_ntt, NTTAccounts } ,
18
15
transceivers:: wormhole:: instructions:: receive_message:: ReceiveMessage ,
19
16
} ;
20
- use solana_program:: instruction:: InstructionError ;
21
17
use solana_program_test:: * ;
22
- use solana_sdk:: { signature:: Keypair , signer:: Signer , transaction :: TransactionError } ;
23
- use wormhole_sdk:: { Address , Vaa } ;
18
+ use solana_sdk:: { signature:: Keypair , signer:: Signer } ;
19
+ use wormhole_sdk:: Address ;
24
20
25
21
use crate :: {
26
- common:: submit :: Submittable ,
27
- sdk :: instructions :: transfer :: { approve_token_authority , transfer } ,
28
- } ;
29
- use crate :: {
30
- common :: { query :: GetAccountDataAnchor , setup :: setup } ,
22
+ common:: {
23
+ query :: GetAccountDataAnchor ,
24
+ setup :: { setup , OTHER_TRANSCEIVER } ,
25
+ utils :: make_transfer_message ,
26
+ } ,
31
27
sdk:: {
32
28
instructions:: {
33
- post_vaa:: post_vaa,
34
29
redeem:: { redeem, Redeem } ,
35
30
transfer:: Transfer ,
36
31
} ,
37
32
transceivers:: wormhole:: instructions:: receive_message:: receive_message,
38
33
} ,
39
34
} ;
35
+ use crate :: {
36
+ common:: { submit:: Submittable , utils:: post_vaa_helper} ,
37
+ sdk:: instructions:: transfer:: { approve_token_authority, transfer} ,
38
+ } ;
40
39
41
40
pub mod common;
42
41
pub mod sdk;
@@ -99,58 +98,6 @@ fn init_receive_message_accs(
99
98
}
100
99
}
101
100
102
- async fn post_transfer_vaa (
103
- ctx : & mut ProgramTestContext ,
104
- id : [ u8 ; 32 ] ,
105
- amount : u64 ,
106
- // TODO: this is used for a negative testing of the recipient ntt_manager
107
- // address. this should not be done in the cancel flow tests, but instead a
108
- // dedicated receive transfer test suite
109
- recipient_ntt_manager : Option < & Pubkey > ,
110
- recipient : & Keypair ,
111
- ) -> ( Pubkey , NttManagerMessage < NativeTokenTransfer > ) {
112
- let ntt_manager_message = NttManagerMessage {
113
- id,
114
- sender : [ 4u8 ; 32 ] ,
115
- payload : NativeTokenTransfer {
116
- amount : TrimmedAmount {
117
- amount,
118
- decimals : 9 ,
119
- } ,
120
- source_token : [ 3u8 ; 32 ] ,
121
- to_chain : ChainId { id : THIS_CHAIN } ,
122
- to : recipient. pubkey ( ) . to_bytes ( ) ,
123
- } ,
124
- } ;
125
-
126
- let transceiver_message: TransceiverMessage < WormholeTransceiver , NativeTokenTransfer > =
127
- TransceiverMessage :: new (
128
- OTHER_MANAGER ,
129
- recipient_ntt_manager
130
- . map ( |k| k. to_bytes ( ) )
131
- . unwrap_or_else ( || good_ntt. program ( ) . to_bytes ( ) ) ,
132
- ntt_manager_message. clone ( ) ,
133
- vec ! [ ] ,
134
- ) ;
135
-
136
- let vaa = Vaa {
137
- version : 1 ,
138
- guardian_set_index : 0 ,
139
- signatures : vec ! [ ] ,
140
- timestamp : 123232 ,
141
- nonce : 0 ,
142
- emitter_chain : OTHER_CHAIN . into ( ) ,
143
- emitter_address : Address ( OTHER_TRANSCEIVER ) ,
144
- sequence : 0 ,
145
- consistency_level : 0 ,
146
- payload : transceiver_message,
147
- } ;
148
-
149
- let posted_vaa = post_vaa ( & good_ntt. wormhole ( ) , ctx, vaa) . await ;
150
-
151
- ( posted_vaa, ntt_manager_message)
152
- }
153
-
154
101
async fn outbound_capacity ( ctx : & mut ProgramTestContext ) -> u64 {
155
102
let clock: Clock = ctx. banks_client . get_sysvar ( ) . await . unwrap ( ) ;
156
103
let rate_limit: OutboxRateLimit = ctx
@@ -174,8 +121,24 @@ async fn test_cancel() {
174
121
let recipient = Keypair :: new ( ) ;
175
122
let ( mut ctx, test_data) = setup ( Mode :: Locking ) . await ;
176
123
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 ;
124
+ let msg0 = make_transfer_message ( & good_ntt, [ 0u8 ; 32 ] , 1000 , & recipient. pubkey ( ) ) ;
125
+ let msg1 = make_transfer_message ( & good_ntt, [ 1u8 ; 32 ] , 2000 , & recipient. pubkey ( ) ) ;
126
+ let vaa0 = post_vaa_helper (
127
+ & good_ntt,
128
+ OTHER_CHAIN . into ( ) ,
129
+ Address ( OTHER_TRANSCEIVER ) ,
130
+ msg0. clone ( ) ,
131
+ & mut ctx,
132
+ )
133
+ . await ;
134
+ let vaa1 = post_vaa_helper (
135
+ & good_ntt,
136
+ OTHER_CHAIN . into ( ) ,
137
+ Address ( OTHER_TRANSCEIVER ) ,
138
+ msg1. clone ( ) ,
139
+ & mut ctx,
140
+ )
141
+ . await ;
179
142
180
143
let inbound_limit_before = inbound_capacity ( & mut ctx) . await ;
181
144
let outbound_limit_before = outbound_capacity ( & mut ctx) . await ;
@@ -190,7 +153,12 @@ async fn test_cancel() {
190
153
191
154
redeem (
192
155
& good_ntt,
193
- init_redeem_accs ( & mut ctx, & test_data, OTHER_CHAIN , msg0) ,
156
+ init_redeem_accs (
157
+ & mut ctx,
158
+ & test_data,
159
+ OTHER_CHAIN ,
160
+ msg0. ntt_manager_payload . clone ( ) ,
161
+ ) ,
194
162
RedeemArgs { } ,
195
163
)
196
164
. submit ( & mut ctx)
@@ -241,7 +209,12 @@ async fn test_cancel() {
241
209
242
210
redeem (
243
211
& good_ntt,
244
- init_redeem_accs ( & mut ctx, & test_data, OTHER_CHAIN , msg1) ,
212
+ init_redeem_accs (
213
+ & mut ctx,
214
+ & test_data,
215
+ OTHER_CHAIN ,
216
+ msg1. ntt_manager_payload . clone ( ) ,
217
+ ) ,
245
218
RedeemArgs { } ,
246
219
)
247
220
. submit ( & mut ctx)
@@ -258,44 +231,3 @@ async fn test_cancel() {
258
231
inbound_capacity( & mut ctx) . await
259
232
) ;
260
233
}
261
-
262
- // TODO: this should not live in this file, move to a dedicated receive test suite
263
- #[ tokio:: test]
264
- async fn test_wrong_recipient_ntt_manager ( ) {
265
- let recipient = Keypair :: new ( ) ;
266
- let ( mut ctx, test_data) = setup ( Mode :: Locking ) . await ;
267
-
268
- let ( vaa0, msg0) = post_transfer_vaa (
269
- & mut ctx,
270
- [ 0u8 ; 32 ] ,
271
- 1000 ,
272
- Some ( & Pubkey :: default ( ) ) ,
273
- & recipient,
274
- )
275
- . await ;
276
-
277
- receive_message (
278
- & good_ntt,
279
- init_receive_message_accs ( & mut ctx, vaa0, OTHER_CHAIN , [ 0u8 ; 32 ] ) ,
280
- )
281
- . submit ( & mut ctx)
282
- . await
283
- . unwrap ( ) ;
284
-
285
- let err = redeem (
286
- & good_ntt,
287
- init_redeem_accs ( & mut ctx, & test_data, OTHER_CHAIN , msg0) ,
288
- RedeemArgs { } ,
289
- )
290
- . submit ( & mut ctx)
291
- . await
292
- . unwrap_err ( ) ;
293
-
294
- assert_eq ! (
295
- err. unwrap( ) ,
296
- TransactionError :: InstructionError (
297
- 0 ,
298
- InstructionError :: Custom ( NTTError :: InvalidRecipientNttManager . into( ) )
299
- )
300
- ) ;
301
- }
0 commit comments