Skip to content

Commit

Permalink
rework tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Mar 22, 2024
1 parent ab6279b commit 9516d79
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 100 deletions.
97 changes: 0 additions & 97 deletions token/js/test/e2e-2022/groupMember.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('tokenGroup', async () => {
let mint: Keypair;
let mintAuthority: Keypair;
let updateAuthority: Keypair;
let groupAddress: PublicKey;

before(async () => {
connection = await getConnection();
Expand All @@ -38,7 +37,6 @@ describe('tokenGroup', async () => {

beforeEach(async () => {
mint = Keypair.generate();
groupAddress = PublicKey.unique();

const mintLen = getMintLen(EXTENSIONS);
const lamports = await connection.getMinimumBalanceForRentExemption(mintLen);
Expand All @@ -54,7 +52,7 @@ describe('tokenGroup', async () => {
createInitializeGroupPointerInstruction(
mint.publicKey,
mintAuthority.publicKey,
groupAddress,
mint.publicKey,
TEST_PROGRAM_ID
),
createInitializeMintInstruction(
Expand Down
145 changes: 145 additions & 0 deletions token/js/test/e2e-2022/tokenGroupMember.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { expect } from 'chai';
import type { Connection, Signer } from '@solana/web3.js';
import { PublicKey } from '@solana/web3.js';
import { sendAndConfirmTransaction, Keypair, SystemProgram, Transaction } from '@solana/web3.js';

import {
ExtensionType,
createInitializeMintInstruction,
createInitializeGroupInstruction,
getTokenGroupState,
getMint,
getMintLen,
createInitializeGroupMemberPointerInstruction,
createInitializeGroupPointerInstruction,
getTokenGroupMemberState,
tokenGroupInitializeGroupWithRentTransfer,
tokenGroupMemberInitializeWithRentTransfer,
} from '../../src';
import { TEST_PROGRAM_ID, newAccountWithLamports, getConnection } from '../common';

const TEST_TOKEN_DECIMALS = 2;

describe('tokenGroupMember', async () => {
let connection: Connection;
let payer: Signer;

let groupMint: Keypair;
let groupUpdateAuthority: Keypair;

let memberMint: Keypair;
let memberMintAuthority: Keypair;
let memberUpdateAuthority: Keypair;

before(async () => {
connection = await getConnection();
payer = await newAccountWithLamports(connection, 1000000000);

groupMint = Keypair.generate();
const groupMintAuthority = Keypair.generate();
groupUpdateAuthority = Keypair.generate();

memberMint = Keypair.generate();
memberMintAuthority = Keypair.generate();
memberUpdateAuthority = Keypair.generate();

const groupMintLen = getMintLen([ExtensionType.GroupPointer]);
const groupMintLamports = await connection.getMinimumBalanceForRentExemption(groupMintLen);

const memberMintLen = getMintLen([ExtensionType.GroupMemberPointer]);
const memberMintLamports = await connection.getMinimumBalanceForRentExemption(memberMintLen);

// Create the group mint and initialize the group.
await sendAndConfirmTransaction(
connection,
new Transaction().add(
SystemProgram.createAccount({
fromPubkey: payer.publicKey,
newAccountPubkey: groupMint.publicKey,
space: groupMintLen,
lamports: groupMintLamports,
programId: TEST_PROGRAM_ID,
}),
createInitializeGroupPointerInstruction(
groupMint.publicKey,
groupUpdateAuthority.publicKey,
groupMint.publicKey,
TEST_PROGRAM_ID
),
createInitializeMintInstruction(
groupMint.publicKey,
TEST_TOKEN_DECIMALS,
groupMintAuthority.publicKey,
null,
TEST_PROGRAM_ID
)
),
[payer, groupMint],
undefined
);
await tokenGroupInitializeGroupWithRentTransfer(
connection,
payer,
groupMint.publicKey,
groupMintAuthority.publicKey,
groupUpdateAuthority.publicKey,
3,
[payer, groupMintAuthority],
undefined,
TEST_PROGRAM_ID
);

// Create the member mint.
await sendAndConfirmTransaction(
connection,
new Transaction().add(
SystemProgram.createAccount({
fromPubkey: payer.publicKey,
newAccountPubkey: memberMint.publicKey,
space: memberMintLen,
lamports: memberMintLamports,
programId: TEST_PROGRAM_ID,
}),
createInitializeGroupMemberPointerInstruction(
memberMint.publicKey,
memberUpdateAuthority.publicKey,
memberMint.publicKey,
TEST_PROGRAM_ID
),
createInitializeMintInstruction(
memberMint.publicKey,
TEST_TOKEN_DECIMALS,
memberMintAuthority.publicKey,
null,
TEST_PROGRAM_ID
)
),
[payer, memberMint],
undefined
);
});

it('can initialize a group member', async () => {
const tokenGroupMember = {
mint: memberMint.publicKey,
group: groupMint.publicKey,
memberNumber: 1,
};

await tokenGroupMemberInitializeWithRentTransfer(
connection,
payer,
memberMint.publicKey,
memberMintAuthority.publicKey,
groupMint.publicKey,
groupUpdateAuthority.publicKey,
[memberMintAuthority, groupUpdateAuthority],
undefined,
TEST_PROGRAM_ID
);

const mintInfo = await getMint(connection, memberMint.publicKey, undefined, TEST_PROGRAM_ID);
const member = getTokenGroupMemberState(mintInfo);
expect(member).to.deep.equal(tokenGroupMember);
});
});

0 comments on commit 9516d79

Please sign in to comment.