@@ -4,14 +4,15 @@ import { Anchor } from "../target/types/anchor";
4
4
5
5
describe ( "anchor" , ( ) => {
6
6
// Configure the client to use the local cluster.
7
- anchor . setProvider ( anchor . AnchorProvider . env ( ) ) ;
7
+ const provider = anchor . AnchorProvider . env ( ) ;
8
+ anchor . setProvider ( provider ) ;
8
9
9
10
const program = anchor . workspace . Anchor as Program < Anchor > ;
10
11
const connection = program . provider . connection ;
11
12
const TOKEN_2022_PROGRAM_ID = new anchor . web3 . PublicKey (
12
13
"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
13
14
) ;
14
- const payer = anchor . web3 . Keypair . generate ( ) ;
15
+ const wallet = provider . wallet as anchor . Wallet ;
15
16
const ATA_PROGRAM_ID = new anchor . web3 . PublicKey (
16
17
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
17
18
) ;
@@ -20,14 +21,14 @@ describe("anchor", () => {
20
21
const [ mint ] = anchor . web3 . PublicKey . findProgramAddressSync (
21
22
[
22
23
Buffer . from ( "token-2022-token" ) ,
23
- payer . publicKey . toBytes ( ) ,
24
+ wallet . publicKey . toBytes ( ) ,
24
25
Buffer . from ( tokenName ) ,
25
26
] ,
26
27
program . programId
27
28
) ;
28
29
const [ payerATA ] = anchor . web3 . PublicKey . findProgramAddressSync (
29
30
[
30
- payer . publicKey . toBytes ( ) ,
31
+ wallet . publicKey . toBytes ( ) ,
31
32
TOKEN_2022_PROGRAM_ID . toBytes ( ) ,
32
33
mint . toBytes ( ) ,
33
34
] ,
@@ -47,14 +48,13 @@ describe("anchor", () => {
47
48
48
49
it ( "Create Token-2022 Token" , async ( ) => {
49
50
await connection . requestAirdrop ( receiver . publicKey , 1000000000 ) ;
50
- await connection . requestAirdrop ( payer . publicKey , 1000000000 ) ;
51
+ await connection . requestAirdrop ( wallet . publicKey , 1000000000 ) ;
51
52
const tx = new anchor . web3 . Transaction ( ) ;
52
53
53
54
const ix = await program . methods
54
55
. createToken ( tokenName )
55
56
. accounts ( {
56
- mint : mint ,
57
- signer : payer . publicKey ,
57
+ signer : wallet . publicKey ,
58
58
tokenProgram : TOKEN_2022_PROGRAM_ID ,
59
59
} )
60
60
. instruction ( ) ;
@@ -64,7 +64,7 @@ describe("anchor", () => {
64
64
const sig = await anchor . web3 . sendAndConfirmTransaction (
65
65
program . provider . connection ,
66
66
tx ,
67
- [ payer ]
67
+ [ wallet . payer ]
68
68
) ;
69
69
console . log ( "Your transaction signature" , sig ) ;
70
70
} ) ;
@@ -77,7 +77,7 @@ describe("anchor", () => {
77
77
. accounts ( {
78
78
tokenAccount : payerATA ,
79
79
mint : mint ,
80
- signer : payer . publicKey ,
80
+ signer : wallet . publicKey ,
81
81
tokenProgram : TOKEN_2022_PROGRAM_ID ,
82
82
} )
83
83
. instruction ( ) ;
@@ -87,7 +87,7 @@ describe("anchor", () => {
87
87
const sig = await anchor . web3 . sendAndConfirmTransaction (
88
88
program . provider . connection ,
89
89
tx ,
90
- [ payer ]
90
+ [ wallet . payer ]
91
91
) ;
92
92
console . log ( "Your transaction signature" , sig ) ;
93
93
} ) ;
@@ -124,19 +124,18 @@ describe("anchor", () => {
124
124
. mintToken ( new anchor . BN ( 200000000 ) )
125
125
. accounts ( {
126
126
mint : mint ,
127
- signer : payer . publicKey ,
127
+ signer : wallet . publicKey ,
128
128
receiver : payerATA ,
129
129
tokenProgram : TOKEN_2022_PROGRAM_ID ,
130
130
} )
131
- . signers ( [ payer ] )
132
131
. instruction ( ) ;
133
132
134
133
tx . add ( ix ) ;
135
134
136
135
const sig = await anchor . web3 . sendAndConfirmTransaction (
137
136
program . provider . connection ,
138
137
tx ,
139
- [ payer ]
138
+ [ wallet . payer ]
140
139
) ;
141
140
console . log ( "Your transaction signature" , sig ) ;
142
141
} ) ;
@@ -149,11 +148,10 @@ describe("anchor", () => {
149
148
. transferToken ( new anchor . BN ( 100 ) )
150
149
. accounts ( {
151
150
mint : mint ,
152
- signer : payer . publicKey ,
151
+ signer : wallet . publicKey ,
153
152
from : payerATA ,
154
153
to : receiver . publicKey ,
155
154
tokenProgram : TOKEN_2022_PROGRAM_ID ,
156
- associatedTokenProgram : ATA_PROGRAM_ID ,
157
155
toAta : receiverATA ,
158
156
} )
159
157
. instruction ( ) ;
@@ -163,7 +161,7 @@ describe("anchor", () => {
163
161
const sig = await anchor . web3 . sendAndConfirmTransaction (
164
162
program . provider . connection ,
165
163
tx ,
166
- [ payer ]
164
+ [ wallet . payer ]
167
165
) ;
168
166
console . log ( "Your transaction signature" , sig ) ;
169
167
} ) ;
0 commit comments