1- import { Buffer } from "node:buffer" ;
2- import { describe , test } from "node:test" ;
3- import { PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata" ;
4- import {
5- ASSOCIATED_TOKEN_PROGRAM_ID ,
6- TOKEN_PROGRAM_ID ,
7- getAssociatedTokenAddressSync ,
8- } from "@solana/spl-token" ;
9- import {
10- Keypair ,
11- PublicKey ,
12- SYSVAR_RENT_PUBKEY ,
13- SystemProgram ,
14- Transaction ,
15- TransactionInstruction ,
16- } from "@solana/web3.js" ;
17- import { start } from "solana-bankrun" ;
18- import { InitArgs , CreateTokenArgs , MintToArgs } from "./instructions" ;
19-
20- describe ( "PDA MINT AUTHORITY" , async ( ) => {
21- const PROGRAM_ID = new PublicKey (
22- "z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35" ,
23- ) ;
1+ import { Buffer } from 'node:buffer' ;
2+ import { describe , test } from 'node:test' ;
3+ import { PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID } from '@metaplex-foundation/mpl-token-metadata' ;
4+ import { ASSOCIATED_TOKEN_PROGRAM_ID , TOKEN_PROGRAM_ID , getAssociatedTokenAddressSync } from '@solana/spl-token' ;
5+ import { Keypair , PublicKey , SYSVAR_RENT_PUBKEY , SystemProgram , Transaction , TransactionInstruction } from '@solana/web3.js' ;
6+ import { start } from 'solana-bankrun' ;
7+ import { CreateTokenArgs , InitArgs , MintToArgs } from './instructions' ;
8+
9+ describe ( 'PDA MINT AUTHORITY' , async ( ) => {
10+ const PROGRAM_ID = new PublicKey ( 'z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35' ) ;
2411 const context = await start (
2512 [
26- { name : " pda_mint_authority_program" , programId : PROGRAM_ID } ,
27- { name : " token_metadata" , programId : TOKEN_METADATA_PROGRAM_ID } ,
13+ { name : ' pda_mint_authority_program' , programId : PROGRAM_ID } ,
14+ { name : ' token_metadata' , programId : TOKEN_METADATA_PROGRAM_ID } ,
2815 ] ,
2916 [ ] ,
3017 ) ;
3118 const client = context . banksClient ;
3219 const payer = context . payer ;
3320
3421 const mintKeypair : Keypair = Keypair . generate ( ) ;
35- const mintAuthorityPublicKey = PublicKey . findProgramAddressSync (
36- [ Buffer . from ( "mint_authority" ) ] ,
37- PROGRAM_ID ,
38- ) [ 0 ] ;
22+ const mintAuthorityPublicKey = PublicKey . findProgramAddressSync ( [ Buffer . from ( 'mint_authority' ) ] , PROGRAM_ID ) [ 0 ] ;
3923
40- test ( " Init mind authority PDA!" , async ( ) => {
24+ test ( ' Init mint authority PDA!' , async ( ) => {
4125 const metadataPDA = PublicKey . findProgramAddressSync (
42- [
43- Buffer . from ( "metadata" ) ,
44- TOKEN_METADATA_PROGRAM_ID . toBuffer ( ) ,
45- mintKeypair . publicKey . toBuffer ( ) ,
46- ] ,
26+ [ Buffer . from ( 'metadata' ) , TOKEN_METADATA_PROGRAM_ID . toBuffer ( ) , mintKeypair . publicKey . toBuffer ( ) ] ,
4727 TOKEN_METADATA_PROGRAM_ID ,
4828 ) [ 0 ] ;
4929
@@ -66,26 +46,22 @@ describe("PDA MINT AUTHORITY", async () => {
6646
6747 await client . processTransaction ( tx ) ;
6848
69- console . log ( " Success!" ) ;
49+ console . log ( ' Success!' ) ;
7050 console . log ( ` Mint Address: ${ mintKeypair . publicKey } ` ) ;
7151 } ) ;
7252
73- test ( " Create a SPL Token with PDA!" , async ( ) => {
53+ test ( ' Create a SPL Token with PDA!' , async ( ) => {
7454 const metadataPDA = PublicKey . findProgramAddressSync (
75- [
76- Buffer . from ( "metadata" ) ,
77- TOKEN_METADATA_PROGRAM_ID . toBuffer ( ) ,
78- mintKeypair . publicKey . toBuffer ( ) ,
79- ] ,
55+ [ Buffer . from ( 'metadata' ) , TOKEN_METADATA_PROGRAM_ID . toBuffer ( ) , mintKeypair . publicKey . toBuffer ( ) ] ,
8056 TOKEN_METADATA_PROGRAM_ID ,
8157 ) [ 0 ] ;
8258
8359 // SPL Token default = 9 decimals
8460 //
8561 const createArgs = new CreateTokenArgs (
86- " Solana Gold" ,
87- " GOLDSOL" ,
88- " https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json" ,
62+ ' Solana Gold' ,
63+ ' GOLDSOL' ,
64+ ' https://raw.githubusercontent.com/solana-developers/program-examples/new-examples/tokens/tokens/.assets/spl-token.json' ,
8965 ) ;
9066
9167 const createTokenIx = new TransactionInstruction ( {
@@ -118,15 +94,12 @@ describe("PDA MINT AUTHORITY", async () => {
11894
11995 await client . processTransaction ( tx ) ;
12096
121- console . log ( " Success!" ) ;
97+ console . log ( ' Success!' ) ;
12298 console . log ( ` Mint Address: ${ mintKeypair . publicKey } ` ) ;
12399 } ) ;
124100
125- test ( "Mint some tokens to your wallet with PDA!" , async ( ) => {
126- const associatedTokenAccountAddress = getAssociatedTokenAddressSync (
127- mintKeypair . publicKey ,
128- payer . publicKey ,
129- ) ;
101+ test ( 'Mint some tokens to your wallet with PDA!' , async ( ) => {
102+ const associatedTokenAccountAddress = getAssociatedTokenAddressSync ( mintKeypair . publicKey , payer . publicKey ) ;
130103
131104 const mintArgs = new MintToArgs ( 100 ) ;
132105
@@ -163,7 +136,7 @@ describe("PDA MINT AUTHORITY", async () => {
163136
164137 await client . processTransaction ( tx ) ;
165138
166- console . log ( " Success!" ) ;
139+ console . log ( ' Success!' ) ;
167140 console . log ( ` ATA Address: ${ associatedTokenAccountAddress } ` ) ;
168141 } ) ;
169142} ) ;
0 commit comments