@@ -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,44 +51,111 @@ 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
+ it ( "Initialize mint" , async ( ) => {
65
+ const extensions = [ spl . ExtensionType . TransferHook ] ;
66
+ const mintLen = spl . getMintLen ( extensions ) ;
67
+ const lamports = await connection . getMinimumBalanceForRentExemption (
68
+ mintLen
69
+ ) ;
70
+
71
+ const transaction = new Transaction ( ) . add (
72
+ SystemProgram . createAccount ( {
73
+ fromPubkey : payer . publicKey ,
74
+ newAccountPubkey : mint . publicKey ,
75
+ space : mintLen ,
76
+ lamports,
77
+ programId : spl . TOKEN_2022_PROGRAM_ID ,
78
+ } ) ,
79
+ spl . createInitializeTransferHookInstruction (
80
+ mint . publicKey ,
81
+ owner . publicKey ,
82
+ dummyTransferHook . programId ,
83
+ spl . TOKEN_2022_PROGRAM_ID
84
+ ) ,
85
+ spl . createInitializeMintInstruction (
86
+ mint . publicKey ,
87
+ 9 ,
88
+ owner . publicKey ,
89
+ null ,
90
+ spl . TOKEN_2022_PROGRAM_ID
91
+ )
92
+ ) ;
52
93
53
- before ( async ( ) => {
54
- // airdrop some tokens to payer
55
- mint = await spl . createMint ( connection , payer , owner . publicKey , null , 9 ) ;
94
+ await sendAndConfirmTransaction ( connection , transaction , [ payer , mint ] ) ;
56
95
57
96
tokenAccount = await spl . createAssociatedTokenAccount (
58
97
connection ,
59
98
payer ,
60
- mint ,
61
- user . publicKey
99
+ mint . publicKey ,
100
+ user . publicKey ,
101
+ undefined ,
102
+ spl . TOKEN_2022_PROGRAM_ID ,
103
+ spl . ASSOCIATED_TOKEN_PROGRAM_ID
62
104
) ;
105
+
63
106
await spl . mintTo (
64
107
connection ,
65
108
payer ,
66
- mint ,
109
+ mint . publicKey ,
67
110
tokenAccount ,
68
111
owner ,
69
- BigInt ( 10000000 )
112
+ BigInt ( 10000000 ) ,
113
+ undefined ,
114
+ undefined ,
115
+ spl . TOKEN_2022_PROGRAM_ID
70
116
) ;
71
117
} ) ;
72
118
119
+ it ( "Create ExtraAccountMetaList Account" , async ( ) => {
120
+ const initializeExtraAccountMetaListInstruction =
121
+ await dummyTransferHook . methods
122
+ . initializeExtraAccountMetaList ( )
123
+ . accountsStrict ( {
124
+ payer : payer . publicKey ,
125
+ mint : mint . publicKey ,
126
+ extraAccountMetaList : extraAccountMetaListPDA ,
127
+ tokenProgram : spl . TOKEN_2022_PROGRAM_ID ,
128
+ associatedTokenProgram : spl . ASSOCIATED_TOKEN_PROGRAM_ID ,
129
+ systemProgram : SystemProgram . programId ,
130
+ } )
131
+ . instruction ( ) ;
132
+
133
+ const transaction = new Transaction ( ) . add (
134
+ initializeExtraAccountMetaListInstruction
135
+ ) ;
136
+
137
+ await sendAndConfirmTransaction ( connection , transaction , [ payer ] ) ;
138
+ } ) ;
139
+
73
140
describe ( "Locking" , ( ) => {
74
141
before ( async ( ) => {
75
142
await spl . setAuthority (
76
143
connection ,
77
144
payer ,
78
- mint ,
145
+ mint . publicKey ,
79
146
owner ,
80
- 0 , // mint
81
- ntt . tokenAuthorityAddress ( )
147
+ spl . AuthorityType . MintTokens ,
148
+ ntt . tokenAuthorityAddress ( ) ,
149
+ [ ] ,
150
+ undefined ,
151
+ spl . TOKEN_2022_PROGRAM_ID
82
152
) ;
83
153
84
154
await ntt . initialize ( {
85
155
payer,
86
156
owner : payer ,
87
157
chain : "solana" ,
88
- mint,
158
+ mint : mint . publicKey ,
89
159
outboundLimit : new BN ( 1000000 ) ,
90
160
mode : "locking" ,
91
161
} ) ;
0 commit comments