-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace createMintWithSingleToken with more generic helper
- Loading branch information
1 parent
1eb4988
commit 5f04d11
Showing
4 changed files
with
196 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import { | ||
generateSigner, | ||
none, | ||
publicKey, | ||
some, | ||
transactionBuilder, | ||
} from '@metaplex-foundation/umi'; | ||
import test from 'ava'; | ||
import { | ||
createMintWithAssociatedToken, | ||
fetchMint, | ||
fetchToken, | ||
findAssociatedTokenPda, | ||
Mint, | ||
Token, | ||
TokenState, | ||
} from '../src'; | ||
import { createUmi } from './_setup'; | ||
|
||
test('it can create a new mint and token account with no tokens', async (t) => { | ||
// Given a mint address and an owner address. | ||
const umi = await createUmi(); | ||
const mint = generateSigner(umi); | ||
const owner = generateSigner(umi).publicKey; | ||
|
||
// When we create a new mint and token account without specifying an amount. | ||
await transactionBuilder(umi) | ||
.add(createMintWithAssociatedToken(umi, { mint, owner })) | ||
.sendAndConfirm(); | ||
|
||
// Then it created a new mint account with a supply of 0. | ||
const mintAccount = await fetchMint(umi, mint.publicKey); | ||
t.like(mintAccount, <Mint>{ | ||
publicKey: publicKey(mint), | ||
mintAuthority: some(publicKey(umi.identity)), | ||
supply: 0n, | ||
decimals: 0, | ||
isInitialized: true, | ||
freezeAuthority: some(publicKey(umi.identity)), | ||
}); | ||
|
||
// And a new associated token account with no tokens. | ||
const ata = findAssociatedTokenPda(umi, { mint: mint.publicKey, owner }); | ||
const tokenAccount = await fetchToken(umi, ata); | ||
t.like(tokenAccount, <Token>{ | ||
publicKey: publicKey(ata), | ||
mint: publicKey(mint), | ||
owner: publicKey(owner), | ||
amount: 0n, | ||
delegate: none(), | ||
state: TokenState.Initialized, | ||
isNative: none(), | ||
delegatedAmount: 0n, | ||
closeAuthority: none(), | ||
}); | ||
}); | ||
|
||
test('it can create a new mint and token account with a single token', async (t) => { | ||
// Given a mint address and an owner address. | ||
const umi = await createUmi(); | ||
const mint = generateSigner(umi); | ||
const owner = generateSigner(umi).publicKey; | ||
|
||
// When we create a new mint and token account with a single token. | ||
await transactionBuilder(umi) | ||
.add(createMintWithAssociatedToken(umi, { mint, owner, amount: 1 })) | ||
.sendAndConfirm(); | ||
|
||
// Then it created a new mint account with a supply of 1. | ||
const mintAccount = await fetchMint(umi, mint.publicKey); | ||
t.like(mintAccount, <Mint>{ | ||
publicKey: publicKey(mint), | ||
mintAuthority: some(publicKey(umi.identity)), | ||
supply: 1n, | ||
decimals: 0, | ||
isInitialized: true, | ||
freezeAuthority: some(publicKey(umi.identity)), | ||
}); | ||
|
||
// And a new associated token account with one token. | ||
const ata = findAssociatedTokenPda(umi, { mint: mint.publicKey, owner }); | ||
const tokenAccount = await fetchToken(umi, ata); | ||
t.like(tokenAccount, <Token>{ | ||
publicKey: publicKey(ata), | ||
mint: publicKey(mint), | ||
owner: publicKey(owner), | ||
amount: 1n, | ||
delegate: none(), | ||
state: TokenState.Initialized, | ||
isNative: none(), | ||
delegatedAmount: 0n, | ||
closeAuthority: none(), | ||
}); | ||
}); | ||
|
||
test('it can create a new mint and token account with many tokens', async (t) => { | ||
// Given a mint address and an owner address. | ||
const umi = await createUmi(); | ||
const mint = generateSigner(umi); | ||
const owner = generateSigner(umi).publicKey; | ||
|
||
// When we create a new mint and token account with 42 tokens. | ||
await transactionBuilder(umi) | ||
.add(createMintWithAssociatedToken(umi, { mint, owner, amount: 42 })) | ||
.sendAndConfirm(); | ||
|
||
// Then it created a new mint account with a supply of 42. | ||
const mintAccount = await fetchMint(umi, mint.publicKey); | ||
t.like(mintAccount, <Mint>{ | ||
publicKey: publicKey(mint), | ||
mintAuthority: some(publicKey(umi.identity)), | ||
supply: 42n, | ||
decimals: 0, | ||
isInitialized: true, | ||
freezeAuthority: some(publicKey(umi.identity)), | ||
}); | ||
|
||
// And a new associated token account with 42 tokens. | ||
const ata = findAssociatedTokenPda(umi, { mint: mint.publicKey, owner }); | ||
const tokenAccount = await fetchToken(umi, ata); | ||
t.like(tokenAccount, <Token>{ | ||
publicKey: publicKey(ata), | ||
mint: publicKey(mint), | ||
owner: publicKey(owner), | ||
amount: 42n, | ||
delegate: none(), | ||
state: TokenState.Initialized, | ||
isNative: none(), | ||
delegatedAmount: 0n, | ||
closeAuthority: none(), | ||
}); | ||
}); | ||
|
||
test('it can create a new mint and token account with decimals', async (t) => { | ||
// Given a mint address and an owner address. | ||
const umi = await createUmi(); | ||
const mint = generateSigner(umi); | ||
const owner = generateSigner(umi).publicKey; | ||
|
||
// When we create a new mint and token account with 42 tokens and one decimal. | ||
await transactionBuilder(umi) | ||
.add( | ||
createMintWithAssociatedToken(umi, { | ||
mint, | ||
owner, | ||
amount: 42, | ||
decimals: 1, | ||
}) | ||
) | ||
.sendAndConfirm(); | ||
|
||
// Then it created a new mint account with a supply of 42 and one decimal. | ||
const mintAccount = await fetchMint(umi, mint.publicKey); | ||
t.like(mintAccount, <Mint>{ | ||
publicKey: publicKey(mint), | ||
mintAuthority: some(publicKey(umi.identity)), | ||
supply: 42n, | ||
decimals: 1, | ||
isInitialized: true, | ||
freezeAuthority: some(publicKey(umi.identity)), | ||
}); | ||
|
||
// And a new associated token account with 42 tokens. | ||
const ata = findAssociatedTokenPda(umi, { mint: mint.publicKey, owner }); | ||
const tokenAccount = await fetchToken(umi, ata); | ||
t.like(tokenAccount, <Token>{ | ||
publicKey: publicKey(ata), | ||
mint: publicKey(mint), | ||
owner: publicKey(owner), | ||
amount: 42n, | ||
delegate: none(), | ||
state: TokenState.Initialized, | ||
isNative: none(), | ||
delegatedAmount: 0n, | ||
closeAuthority: none(), | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.