@@ -16,14 +16,17 @@ import {
16
16
serializePayload ,
17
17
deserializePayload ,
18
18
} from "@wormhole-foundation/sdk-definitions" ;
19
- import { NttMessage , postVaa , NTT , nttMessageLayout } from "../ts/sdk" ;
19
+ import { postVaa , NTT , nttMessageLayout } from "../ts/sdk" ;
20
+ import { WormholeTransceiverMessage } from "../ts/sdk/nttLayout" ;
21
+
20
22
import {
21
- NativeTokenTransfer ,
22
- TransceiverMessage ,
23
- WormholeTransceiverMessage ,
24
- nativeTokenTransferLayout ,
25
- nttManagerMessageLayout ,
26
- } from "../ts/sdk/nttLayout" ;
23
+ PublicKey ,
24
+ SystemProgram ,
25
+ Transaction ,
26
+ sendAndConfirmTransaction ,
27
+ } from "@solana/web3.js" ;
28
+
29
+ import { DummyTransferHook } from "../target/types/dummy_transfer_hook" ;
27
30
28
31
export const GUARDIAN_KEY =
29
32
"cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0" ;
@@ -48,25 +51,78 @@ describe("example-native-token-transfers", () => {
48
51
const user = anchor . web3 . Keypair . generate ( ) ;
49
52
let tokenAccount : anchor . web3 . PublicKey ;
50
53
51
- let mint : anchor . web3 . PublicKey ;
54
+ const mint = anchor . web3 . Keypair . generate ( ) ;
55
+
56
+ const dummyTransferHook = anchor . workspace
57
+ . DummyTransferHook as anchor . Program < DummyTransferHook > ;
58
+
59
+ const [ extraAccountMetaListPDA ] = PublicKey . findProgramAddressSync (
60
+ [ Buffer . from ( "extra-account-metas" ) , mint . publicKey . toBuffer ( ) ] ,
61
+ dummyTransferHook . programId
62
+ ) ;
63
+
64
+ const [ counterPDA ] = PublicKey . findProgramAddressSync (
65
+ [ Buffer . from ( "counter" ) ] ,
66
+ dummyTransferHook . programId
67
+ ) ;
68
+
69
+ async function counterValue ( ) : Promise < anchor . BN > {
70
+ const counter = await dummyTransferHook . account . counter . fetch ( counterPDA ) ;
71
+ return counter . count
72
+ }
73
+
74
+ it ( "Initialize mint" , async ( ) => {
75
+ const extensions = [ spl . ExtensionType . TransferHook ] ;
76
+ const mintLen = spl . getMintLen ( extensions ) ;
77
+ const lamports = await connection . getMinimumBalanceForRentExemption (
78
+ mintLen
79
+ ) ;
80
+
81
+ const transaction = new Transaction ( ) . add (
82
+ SystemProgram . createAccount ( {
83
+ fromPubkey : payer . publicKey ,
84
+ newAccountPubkey : mint . publicKey ,
85
+ space : mintLen ,
86
+ lamports,
87
+ programId : spl . TOKEN_2022_PROGRAM_ID ,
88
+ } ) ,
89
+ spl . createInitializeTransferHookInstruction (
90
+ mint . publicKey ,
91
+ owner . publicKey ,
92
+ dummyTransferHook . programId ,
93
+ spl . TOKEN_2022_PROGRAM_ID
94
+ ) ,
95
+ spl . createInitializeMintInstruction (
96
+ mint . publicKey ,
97
+ 9 ,
98
+ owner . publicKey ,
99
+ null ,
100
+ spl . TOKEN_2022_PROGRAM_ID
101
+ )
102
+ ) ;
52
103
53
- before ( async ( ) => {
54
- // airdrop some tokens to payer
55
- mint = await spl . createMint ( connection , payer , owner . publicKey , null , 9 ) ;
104
+ await sendAndConfirmTransaction ( connection , transaction , [ payer , mint ] ) ;
56
105
57
106
tokenAccount = await spl . createAssociatedTokenAccount (
58
107
connection ,
59
108
payer ,
60
- mint ,
61
- user . publicKey
109
+ mint . publicKey ,
110
+ user . publicKey ,
111
+ undefined ,
112
+ spl . TOKEN_2022_PROGRAM_ID ,
113
+ spl . ASSOCIATED_TOKEN_PROGRAM_ID
62
114
) ;
115
+
63
116
await spl . mintTo (
64
117
connection ,
65
118
payer ,
66
- mint ,
119
+ mint . publicKey ,
67
120
tokenAccount ,
68
121
owner ,
69
- BigInt ( 10000000 )
122
+ BigInt ( 10000000 ) ,
123
+ undefined ,
124
+ undefined ,
125
+ spl . TOKEN_2022_PROGRAM_ID
70
126
) ;
71
127
} ) ;
72
128
@@ -75,22 +131,47 @@ describe("example-native-token-transfers", () => {
75
131
expect ( version ) . to . equal ( "1.0.0" ) ;
76
132
} ) ;
77
133
134
+ it ( "Create ExtraAccountMetaList Account" , async ( ) => {
135
+ const initializeExtraAccountMetaListInstruction =
136
+ await dummyTransferHook . methods
137
+ . initializeExtraAccountMetaList ( )
138
+ . accountsStrict ( {
139
+ payer : payer . publicKey ,
140
+ mint : mint . publicKey ,
141
+ counter : counterPDA ,
142
+ extraAccountMetaList : extraAccountMetaListPDA ,
143
+ tokenProgram : spl . TOKEN_2022_PROGRAM_ID ,
144
+ associatedTokenProgram : spl . ASSOCIATED_TOKEN_PROGRAM_ID ,
145
+ systemProgram : SystemProgram . programId ,
146
+ } )
147
+ . instruction ( ) ;
148
+
149
+ const transaction = new Transaction ( ) . add (
150
+ initializeExtraAccountMetaListInstruction
151
+ ) ;
152
+
153
+ await sendAndConfirmTransaction ( connection , transaction , [ payer ] ) ;
154
+ } ) ;
155
+
78
156
describe ( "Locking" , ( ) => {
79
157
before ( async ( ) => {
80
158
await spl . setAuthority (
81
159
connection ,
82
160
payer ,
83
- mint ,
161
+ mint . publicKey ,
84
162
owner ,
85
- 0 , // mint
86
- ntt . tokenAuthorityAddress ( )
163
+ spl . AuthorityType . MintTokens ,
164
+ ntt . tokenAuthorityAddress ( ) ,
165
+ [ ] ,
166
+ undefined ,
167
+ spl . TOKEN_2022_PROGRAM_ID
87
168
) ;
88
169
89
170
await ntt . initialize ( {
90
171
payer,
91
172
owner : payer ,
92
173
chain : "solana" ,
93
- mint,
174
+ mint : mint . publicKey ,
94
175
outboundLimit : new BN ( 1000000 ) ,
95
176
mode : "locking" ,
96
177
} ) ;
@@ -173,6 +254,7 @@ describe("example-native-token-transfers", () => {
173
254
174
255
// TODO: assert other stuff in the message
175
256
// console.log(nttManagerMessage);
257
+ expect ( ( await counterValue ( ) ) . toString ( ) ) . to . be . eq ( "1" )
176
258
} ) ;
177
259
178
260
it ( "Can receive tokens" , async ( ) => {
@@ -230,6 +312,8 @@ describe("example-native-token-transfers", () => {
230
312
} ) ;
231
313
232
314
expect ( released ) . to . equal ( true ) ;
315
+
316
+ expect ( ( await counterValue ( ) ) . toString ( ) ) . to . be . eq ( "2" )
233
317
} ) ;
234
318
} ) ;
235
319
0 commit comments