@@ -50,6 +50,7 @@ describe("example-native-token-transfers", () => {
50
50
} ) ;
51
51
const user = anchor . web3 . Keypair . generate ( ) ;
52
52
let tokenAccount : anchor . web3 . PublicKey ;
53
+ const recoveryTokenAccount = anchor . web3 . Keypair . generate ( ) ;
53
54
54
55
const mint = anchor . web3 . Keypair . generate ( ) ;
55
56
@@ -113,6 +114,16 @@ describe("example-native-token-transfers", () => {
113
114
spl . ASSOCIATED_TOKEN_PROGRAM_ID
114
115
) ;
115
116
117
+ await spl . createAccount (
118
+ connection ,
119
+ payer ,
120
+ mint . publicKey ,
121
+ payer . publicKey ,
122
+ recoveryTokenAccount ,
123
+ undefined ,
124
+ spl . TOKEN_2022_PROGRAM_ID
125
+ ) ;
126
+
116
127
await spl . mintTo (
117
128
connection ,
118
129
payer ,
@@ -154,6 +165,14 @@ describe("example-native-token-transfers", () => {
154
165
} ) ;
155
166
156
167
describe ( "Locking" , ( ) => {
168
+ const guardians = new MockGuardians ( 0 , [ GUARDIAN_KEY ] ) ;
169
+
170
+ const emitter = new MockEmitter (
171
+ Buffer . from ( "transceiver" . padStart ( 32 , "\0" ) ) . toString ( "hex" ) ,
172
+ toChainId ( "ethereum" ) ,
173
+ Number ( 0 ) // sequence
174
+ ) ;
175
+
157
176
before ( async ( ) => {
158
177
await spl . setAuthority (
159
178
connection ,
@@ -173,7 +192,7 @@ describe("example-native-token-transfers", () => {
173
192
chain : "solana" ,
174
193
mint : mint . publicKey ,
175
194
outboundLimit : new BN ( 1000000 ) ,
176
- mode : "locking " ,
195
+ mode : "burning " ,
177
196
} ) ;
178
197
179
198
await ntt . registerTransceiver ( {
@@ -233,39 +252,18 @@ describe("example-native-token-transfers", () => {
233
252
messageData . message . payload
234
253
) ;
235
254
236
- // assert theat amount is what we expect
255
+ // assert that amount is what we expect
237
256
expect (
238
257
transceiverMessage . nttManagerPayload . payload . trimmedAmount
239
258
) . to . deep . equal ( { amount : 10000n , decimals : 8 } ) ;
240
259
// get from balance
241
260
const balance = await connection . getTokenAccountBalance ( tokenAccount ) ;
242
261
expect ( balance . value . amount ) . to . equal ( "9900000" ) ;
243
262
244
- // grab logs
245
- // await connection.confirmTransaction(redeemTx, 'confirmed');
246
- // const tx = await anchor.getProvider().connection.getParsedTransaction(redeemTx, {
247
- // commitment: "confirmed",
248
- // });
249
- // console.log(tx);
250
-
251
- // const log = tx.meta.logMessages[1];
252
- // const message = log.substring(log.indexOf(':') + 1);
253
- // console.log(message);
254
-
255
- // TODO: assert other stuff in the message
256
- // console.log(nttManagerMessage);
257
263
expect ( ( await counterValue ( ) ) . toString ( ) ) . to . be . eq ( "1" )
258
264
} ) ;
259
265
260
266
it ( "Can receive tokens" , async ( ) => {
261
- const emitter = new MockEmitter (
262
- Buffer . from ( "transceiver" . padStart ( 32 , "\0" ) ) . toString ( "hex" ) ,
263
- toChainId ( "ethereum" ) ,
264
- Number ( 0 ) // sequence
265
- ) ;
266
-
267
- const guardians = new MockGuardians ( 0 , [ GUARDIAN_KEY ] ) ;
268
-
269
267
const sendingTransceiverMessage : WormholeTransceiverMessage <
270
268
typeof nttMessageLayout
271
269
> = {
@@ -280,7 +278,7 @@ describe("example-native-token-transfers", () => {
280
278
sender : new UniversalAddress ( "FACE" . padStart ( 64 , "0" ) ) ,
281
279
payload : {
282
280
trimmedAmount : {
283
- amount : 10000n ,
281
+ amount : 5000n ,
284
282
decimals : 8 ,
285
283
} ,
286
284
sourceToken : new UniversalAddress ( "FAFA" . padStart ( 64 , "0" ) ) ,
@@ -315,6 +313,95 @@ describe("example-native-token-transfers", () => {
315
313
316
314
expect ( ( await counterValue ( ) ) . toString ( ) ) . to . be . eq ( "2" )
317
315
} ) ;
316
+
317
+ describe ( "Recovery" , ( ) => {
318
+ it ( "Can initialize recovery account" , async ( ) => {
319
+ await ntt . initializeRecoveryAccount ( {
320
+ payer,
321
+ owner : payer ,
322
+ recoveryTokenAccount : tokenAccount ,
323
+ } ) ;
324
+
325
+ const recoveryAccount = await ntt . getRecoveryAccount ( ) ;
326
+
327
+ expect ( recoveryAccount ?. toBase58 ( ) ) . to . equal ( tokenAccount . toBase58 ( ) ) ;
328
+ } ) ;
329
+
330
+ it ( "Can update recovery account" , async ( ) => {
331
+ await ntt . updateRecoveryAddress ( {
332
+ // payer,
333
+ owner : payer ,
334
+ newRecoveryAccount : recoveryTokenAccount . publicKey ,
335
+ } ) ;
336
+
337
+ const recoveryAccount = await ntt . getRecoveryAccount ( ) ;
338
+
339
+ expect ( recoveryAccount ?. toBase58 ( ) ) . to . equal (
340
+ recoveryTokenAccount . publicKey . toBase58 ( )
341
+ ) ;
342
+ } ) ;
343
+
344
+ it ( "Owner can recover transfers" , async ( ) => {
345
+ const sendingTransceiverMessage : WormholeTransceiverMessage <
346
+ typeof nttMessageLayout
347
+ > = {
348
+ sourceNttManager : new UniversalAddress (
349
+ encoding . bytes . encode ( "nttManager" . padStart ( 32 , "\0" ) )
350
+ ) ,
351
+ recipientNttManager : new UniversalAddress (
352
+ ntt . program . programId . toBytes ( )
353
+ ) ,
354
+ nttManagerPayload : {
355
+ id : encoding . bytes . encode ( "sequence2" . padEnd ( 32 , "0" ) ) ,
356
+ sender : new UniversalAddress ( "FACE" . padStart ( 64 , "0" ) ) ,
357
+ payload : {
358
+ trimmedAmount : {
359
+ amount : 5000n ,
360
+ decimals : 8 ,
361
+ } ,
362
+ sourceToken : new UniversalAddress ( "FAFA" . padStart ( 64 , "0" ) ) ,
363
+ recipientAddress : new UniversalAddress ( user . publicKey . toBytes ( ) ) ,
364
+ recipientChain : "Solana" ,
365
+ } ,
366
+ } ,
367
+ transceiverPayload : { forSpecializedRelayer : false } ,
368
+ } as const ;
369
+
370
+ const serialized = serializePayload (
371
+ "Ntt:WormholeTransfer" ,
372
+ sendingTransceiverMessage
373
+ ) ;
374
+
375
+ const published = emitter . publishMessage (
376
+ 0 , // nonce
377
+ Buffer . from ( serialized ) ,
378
+ 0 // consistency level
379
+ ) ;
380
+
381
+ const vaaBuf = guardians . addSignatures ( published , [ 0 ] ) ;
382
+
383
+ await postVaa ( connection , payer , vaaBuf , ntt . wormholeId ) ;
384
+
385
+ const released = await ntt . redeem ( {
386
+ payer,
387
+ vaa : vaaBuf ,
388
+ recover : payer ,
389
+ } ) ;
390
+
391
+ expect ( released ) . to . equal ( true ) ;
392
+
393
+ const account = await spl . getAccount (
394
+ connection ,
395
+ recoveryTokenAccount . publicKey ,
396
+ undefined ,
397
+ spl . TOKEN_2022_PROGRAM_ID
398
+ ) ;
399
+
400
+ expect ( account . amount ) . to . equal ( BigInt ( 50000 ) ) ;
401
+
402
+ expect ( ( await counterValue ( ) ) . toString ( ) ) . to . be . eq ( "3" )
403
+ } ) ;
404
+ } ) ;
318
405
} ) ;
319
406
320
407
// describe('Burning', () => {
0 commit comments