Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Rewrite the legacy token tests without @solana/spl-token
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Jun 14, 2024
1 parent 341c8b8 commit 9ecc35e
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 98 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"@solana/web3.js": "workspace:*",
"@wallet-standard/base": "pre",
"conventional-changelog-conventionalcommits": ">= 8.0.0",
"jsdom": "^22",
Expand Down
138 changes: 55 additions & 83 deletions packages/library-legacy/test/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4919,90 +4919,61 @@ describe('Connection', function () {
const connection = new Connection(url, 'confirmed');
const newAccount = PublicKey.unique();

let payerKeypair = new Keypair();
let testTokenMintPubkey: PublicKey;
let testOwnerKeypair: Keypair;
let testTokenAccountPubkey: PublicKey;
let testSignature: TransactionSignature;
const payerPublicKey = new PublicKey(
'6bffFjUMnnk3tXFJAS8pp9tz6m7oJAd27vm9rKqnLtVv',
);
const testTokenMintPubkey = new PublicKey(
'7MbpdfJa5xqwexkp6WUvkYHTPo4VgxYACDBNFWYLwCdo',
);
const testOwnerKeypair = Keypair.fromSecretKey(
new Uint8Array([
153, 120, 247, 45, 160, 119, 144, 219, 220, 209, 73, 91, 210, 102, 31,
136, 155, 12, 68, 27, 226, 215, 61, 214, 10, 245, 247, 180, 236, 63,
100, 202, 140, 247, 112, 54, 120, 32, 168, 118, 72, 115, 190, 34, 171,
126, 15, 119, 252, 173, 50, 173, 8, 10, 96, 239, 21, 32, 94, 67, 37,
43, 145, 249,
]),
);
const testTokenAccountPubkey = new PublicKey(
'EryTMgfSEabo5Fc7dN5z3nBQKzfHUJRpHAMnXdCrTq4S',
);
let selfTransferSignature: TransactionSignature;

// Setup token mints and accounts for token tests
before(async function () {
this.timeout(30 * 1000);

await connection.confirmTransaction(
await connection.requestAirdrop(payerKeypair.publicKey, 100000000000),
);

const mintOwnerKeypair = new Keypair();
const accountOwnerKeypair = new Keypair();
const mintPubkey = await splToken.createMint(
connection as any,
payerKeypair,
mintOwnerKeypair.publicKey,
null, // freeze authority
2, // decimals
);

const tokenAccountPubkey = await splToken.createAccount(
connection as any,
payerKeypair,
mintPubkey,
accountOwnerKeypair.publicKey,
);

await splToken.mintTo(
connection as any,
payerKeypair,
mintPubkey,
tokenAccountPubkey,
mintOwnerKeypair,
11111,
);

const mintPubkey2 = await splToken.createMint(
connection as any,
payerKeypair,
mintOwnerKeypair.publicKey,
null, // freeze authority
2, // decimals
);

const tokenAccountPubkey2 = await splToken.createAccount(
connection as any,
payerKeypair,
mintPubkey2,
accountOwnerKeypair.publicKey,
);

await splToken.mintTo(
connection as any,
payerKeypair,
mintPubkey2,
tokenAccountPubkey2,
mintOwnerKeypair,
100,
);

const tokenAccountDestPubkey = await splToken.createAccount(
connection as any,
payerKeypair,
mintPubkey,
accountOwnerKeypair.publicKey,
new Keypair() as any,
const selfTransferTransaction = new Transaction().add(
new TransactionInstruction({
keys: [
{
pubkey: testTokenAccountPubkey,
isSigner: false,
isWritable: true,
},
{
pubkey: testTokenAccountPubkey,
isSigner: false,
isWritable: true,
},
{
pubkey: testOwnerKeypair.publicKey,
isSigner: true,
isWritable: false,
},
],
programId: new PublicKey(
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
),
data: Buffer.from([3, 1, 0, 0, 0, 0, 0, 0, 0]),
}),
);

testSignature = await splToken.transfer(
connection as any,
payerKeypair,
tokenAccountPubkey,
tokenAccountDestPubkey,
accountOwnerKeypair,
1,
selfTransferSignature = await sendAndConfirmTransaction(
connection,
selfTransferTransaction,
[testOwnerKeypair],
);

testTokenMintPubkey = mintPubkey as PublicKey;
testOwnerKeypair = accountOwnerKeypair;
testTokenAccountPubkey = tokenAccountPubkey as PublicKey;
});

it('get token supply', async () => {
Expand All @@ -5020,7 +4991,7 @@ describe('Connection', function () {
await connection.getTokenLargestAccounts(testTokenMintPubkey)
).value;

expect(largestAccounts).to.have.length(2);
expect(largestAccounts).to.have.length(1);
const largestAccount = largestAccounts[0];
expect(largestAccount.address.equals(testTokenAccountPubkey)).to.be
.true;
Expand All @@ -5033,14 +5004,15 @@ describe('Connection', function () {
});

it('get confirmed token transaction', async () => {
const parsedTx =
await connection.getParsedConfirmedTransaction(testSignature);
const parsedTx = await connection.getParsedConfirmedTransaction(
selfTransferSignature,
);
if (parsedTx === null) {
expect(parsedTx).not.to.be.null;
return;
}
const {signatures, message} = parsedTx.transaction;
expect(signatures[0]).to.eq(testSignature);
expect(signatures[0]).to.eq(selfTransferSignature);
const ix = message.instructions[0];
if ('parsed' in ix) {
expect(ix.program).to.eq('spl-token');
Expand Down Expand Up @@ -5089,7 +5061,7 @@ describe('Connection', function () {
await connection.getMultipleParsedAccounts([
testTokenAccountPubkey,
testTokenMintPubkey,
payerKeypair.publicKey,
payerPublicKey,
newAccount,
])
).value;
Expand Down Expand Up @@ -5175,14 +5147,14 @@ describe('Connection', function () {
mint: testTokenMintPubkey,
})
).value;
expect(accountsWithMintFilter).to.have.length(2);
expect(accountsWithMintFilter).to.have.length(1);

const accountsWithProgramFilter = (
await connection.getTokenAccountsByOwner(testOwnerKeypair.publicKey, {
programId: TOKEN_PROGRAM_ID,
})
).value;
expect(accountsWithProgramFilter).to.have.length(3);
expect(accountsWithProgramFilter).to.have.length(1);

const noAccounts = (
await connection.getTokenAccountsByOwner(newAccount, {
Expand Down
62 changes: 48 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions scripts/fixtures/legacy-token-test-mint-account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pubkey": "7MbpdfJa5xqwexkp6WUvkYHTPo4VgxYACDBNFWYLwCdo",
"account": {
"lamports": 1461600,
"data": [
"AQAAAHcJbkUYh4l63GiAnsWEYIXJ+GFRCPDM7Llpzw531Qu8ZysAAAAAAAACAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0,
"space": 82
}
}
11 changes: 11 additions & 0 deletions scripts/fixtures/legacy-token-test-payer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"pubkey": "6bffFjUMnnk3tXFJAS8pp9tz6m7oJAd27vm9rKqnLtVv",
"account": {
"lamports": 10000000000,
"data": ["", "base64"],
"owner": "11111111111111111111111111111111",
"executable": false,
"rentEpoch": 0,
"space": 0
}
}
14 changes: 14 additions & 0 deletions scripts/fixtures/legacy-token-test-token-account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pubkey": "EryTMgfSEabo5Fc7dN5z3nBQKzfHUJRpHAMnXdCrTq4S",
"account": {
"lamports": 2039280,
"data": [
"Xm0cOPd0hEH7bBdAi+cMVTdGREX7rlH2xK4VEXbE7SKM93A2eCCodkhzviKrfg93/K0yrQgKYO8VIF5DJSuR+WYrAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0,
"space": 165
}
}
Loading

0 comments on commit 9ecc35e

Please sign in to comment.