Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"scripts": {
"build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
"build:docs": "typedoc",
"test": "ava",
"dev": "vitest",
"test": "vitest run",
"lint": "eslint --ext js,ts,tsx src",
"lint:fix": "eslint --fix --ext js,ts,tsx src",
"format": "prettier --check src test",
Expand Down Expand Up @@ -58,7 +59,6 @@
"yaml": "^2.7.0"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@solana-config/eslint": "^0.2.3",
"@solana/kit": "^6.9.0",
"@solana/kit-plugin-rpc": "^0.11.1",
Expand All @@ -67,26 +67,12 @@
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"ava": "^6.1.3",
"eslint": "^9.39.2",
"prettier": "^3.8.1",
"rimraf": "^5.0.5",
"tsup": "^8.1.2",
"typedoc": "^0.25.12",
"typescript": "^5.9.3"
},
"ava": {
"files": [
"test/**/*.test.ts"
],
"nodeArguments": [
"--no-warnings"
],
"typescript": {
"compile": false,
"rewritePaths": {
"test/": "dist/test/"
}
}
"typescript": "^5.9.3",
"vitest": "^4.0.15"
}
}
1,550 changes: 647 additions & 903 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions clients/js/test/allocate.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { address, generateKeyPairSigner, none, some } from '@solana/kit';
import test from 'ava';
import { expect, it } from 'vitest';
import { ACCOUNT_HEADER_LENGTH, AccountDiscriminator, Buffer, findCanonicalPda, findNonCanonicalPda } from '../src';
import { createDeployedProgram, createTestClient, generateKeyPairSignerWithSol } from './_setup';

test('it allocates a canonical PDA buffer', async t => {
it('allocates a canonical PDA buffer', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -25,7 +25,7 @@ test('it allocates a canonical PDA buffer', async t => {

// Then we expect the following buffer account to be created.
const bufferAccount = await client.programMetadata.accounts.buffer.fetch(buffer);
t.like(bufferAccount.data, <Buffer>{
expect(bufferAccount.data).toMatchObject(<Buffer>{
discriminator: AccountDiscriminator.Buffer,
program: some(program),
authority: some(authority.address),
Expand All @@ -35,7 +35,7 @@ test('it allocates a canonical PDA buffer', async t => {
});
});

test('it allocates a non-canonical PDA buffer', async t => {
it('allocates a non-canonical PDA buffer', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -57,7 +57,7 @@ test('it allocates a non-canonical PDA buffer', async t => {

// Then we expect the following buffer account to be created.
const bufferAccount = await client.programMetadata.accounts.buffer.fetch(buffer);
t.like(bufferAccount.data, <Buffer>{
expect(bufferAccount.data).toMatchObject(<Buffer>{
discriminator: AccountDiscriminator.Buffer,
program: some(program),
authority: some(authority.address),
Expand All @@ -67,7 +67,7 @@ test('it allocates a non-canonical PDA buffer', async t => {
});
});

test('it allocates a keypair buffer', async t => {
it('allocates a keypair buffer', async () => {
// Given the following payer and buffer keypairs.
const client = await createTestClient();
const [payer, buffer] = await Promise.all([generateKeyPairSignerWithSol(client), generateKeyPairSigner()]);
Expand All @@ -84,7 +84,7 @@ test('it allocates a keypair buffer', async t => {

// Then we expect the following buffer account to be created.
const bufferAccount = await client.programMetadata.accounts.buffer.fetch(buffer.address);
t.like(bufferAccount.data, <Buffer>{
expect(bufferAccount.data).toMatchObject(<Buffer>{
discriminator: AccountDiscriminator.Buffer,
program: none(),
authority: some(buffer.address),
Expand Down
43 changes: 22 additions & 21 deletions clients/js/test/close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
isSolanaError,
SOLANA_ERROR__INSTRUCTION_ERROR__INCORRECT_AUTHORITY,
} from '@solana/kit';
import test from 'ava';
import { expect, it, test } from 'vitest';
import { Compression, DataSource, Encoding, findCanonicalPda, findNonCanonicalPda, Format } from '../src';
import { createDeployedProgram, createTestClient, generateKeyPairSignerWithSol } from './_setup';

test('it can close canonical metadata accounts', async t => {
it('can close canonical metadata accounts', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -36,10 +36,10 @@ test('it can close canonical metadata accounts', async t => {

// Then we expect the metadata account to no longer exist.
const account = await client.programMetadata.accounts.metadata.fetchMaybe(metadata);
t.false(account.exists);
expect(account.exists).toBe(false);
});

test('the set authority of a canonical metadata can close the account', async t => {
test('the set authority of a canonical metadata can close the account', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const [authority, explicitAuthority] = await Promise.all([
Expand Down Expand Up @@ -81,10 +81,10 @@ test('the set authority of a canonical metadata can close the account', async t

// Then we expect the metadata account to no longer exist.
const account = await client.programMetadata.accounts.metadata.fetchMaybe(metadata);
t.false(account.exists);
expect(account.exists).toBe(false);
});

test('the current upgrade authority of program can close its canonical metadata account even when an authority is set on the account', async t => {
test('the current upgrade authority of program can close its canonical metadata account even when an authority is set on the account', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const [authority, explicitAuthority] = await Promise.all([
Expand Down Expand Up @@ -128,10 +128,10 @@ test('the current upgrade authority of program can close its canonical metadata

// Then we expect the metadata account to no longer exist.
const account = await client.programMetadata.accounts.metadata.fetchMaybe(metadata);
t.false(account.exists);
expect(account.exists).toBe(false);
});

test('it can close non-canonical metadata accounts', async t => {
it('can close non-canonical metadata accounts', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -157,10 +157,10 @@ test('it can close non-canonical metadata accounts', async t => {

// Then we expect the metadata account to no longer exist.
const account = await client.programMetadata.accounts.metadata.fetchMaybe(metadata);
t.false(account.exists);
expect(account.exists).toBe(false);
});

test('it can close canonical buffers', async t => {
it('can close canonical buffers', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -185,10 +185,10 @@ test('it can close canonical buffers', async t => {

// Then we expect the buffer account to no longer exist.
const account = await client.programMetadata.accounts.buffer.fetchMaybe(buffer);
t.false(account.exists);
expect(account.exists).toBe(false);
});

test('it can close non-canonical buffers', async t => {
it('can close non-canonical buffers', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -212,10 +212,10 @@ test('it can close non-canonical buffers', async t => {

// Then we expect the buffer account to no longer exist.
const account = await client.programMetadata.accounts.buffer.fetchMaybe(buffer);
t.false(account.exists);
expect(account.exists).toBe(false);
});

test('it can close keypair buffers', async t => {
it('can close keypair buffers', async () => {
// Given the following payer.
const client = await createTestClient();
const payer = await generateKeyPairSignerWithSol(client);
Expand All @@ -233,10 +233,10 @@ test('it can close keypair buffers', async t => {

// Then we expect the buffer account to no longer exist.
const account = await client.programMetadata.accounts.buffer.fetchMaybe(buffer.address);
t.false(account.exists);
expect(account.exists).toBe(false);
});

test('it cannot close a keypair buffer with a different authority set using the buffer keypair', async t => {
it('cannot close a keypair buffer with a different authority set using the buffer keypair', async () => {
// Given the following payer.
const client = await createTestClient();
const payer = await generateKeyPairSignerWithSol(client);
Expand All @@ -259,12 +259,13 @@ test('it cannot close a keypair buffer with a different authority set using the
.sendTransaction();

// Then we expect a program error.
const error = await t.throwsAsync(promise);
t.true(isSolanaError(error));
t.true(isSolanaError(error.cause, SOLANA_ERROR__INSTRUCTION_ERROR__INCORRECT_AUTHORITY));
const error = await promise.catch((e: unknown) => e);
expect(isSolanaError(error)).toBe(true);
if (!isSolanaError(error)) return;
expect(isSolanaError(error.cause, SOLANA_ERROR__INSTRUCTION_ERROR__INCORRECT_AUTHORITY)).toBe(true);
});

test('it can close a keypair buffer with its authority', async t => {
it('can close a keypair buffer with its authority', async () => {
// Given the following payer.
const client = await createTestClient();
const payer = await generateKeyPairSignerWithSol(client);
Expand All @@ -288,5 +289,5 @@ test('it can close a keypair buffer with its authority', async t => {

// Then we expect the buffer account to no longer exist.
const account = await client.programMetadata.accounts.buffer.fetchMaybe(buffer.address);
t.false(account.exists);
expect(account.exists).toBe(false);
});
38 changes: 19 additions & 19 deletions clients/js/test/createMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { address, generateKeyPairSigner, getUtf8Encoder, none, some } from '@solana/kit';
import test from 'ava';
import { expect, it } from 'vitest';
import {
AccountDiscriminator,
Compression,
Expand All @@ -12,7 +12,7 @@ import {
} from '../src';
import { createDeployedProgram, createTestClient, generateKeyPairSignerWithSol } from './_setup';

test('it creates a canonical metadata account', async t => {
it('creates a canonical metadata account', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -35,7 +35,7 @@ test('it creates a canonical metadata account', async t => {
// Then we expect the following metadata account to be created.
const [metadata] = await findCanonicalPda({ program, seed: 'idl' });
const account = await client.programMetadata.accounts.metadata.fetch(metadata);
t.like(account.data, <Metadata>{
expect(account.data).toMatchObject(<Metadata>{
discriminator: AccountDiscriminator.Metadata,
program,
authority: none(),
Expand All @@ -51,7 +51,7 @@ test('it creates a canonical metadata account', async t => {
});
});

test('it creates a canonical metadata account with data larger than a transaction size', async t => {
it('creates a canonical metadata account with data larger than a transaction size', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -74,7 +74,7 @@ test('it creates a canonical metadata account with data larger than a transactio
// Then we expect the following metadata account to be created.
const [metadata] = await findCanonicalPda({ program, seed: 'idl' });
const account = await client.programMetadata.accounts.metadata.fetch(metadata);
t.like(account.data, <Metadata>{
expect(account.data).toMatchObject(<Metadata>{
discriminator: AccountDiscriminator.Metadata,
program,
authority: none(),
Expand All @@ -90,7 +90,7 @@ test('it creates a canonical metadata account with data larger than a transactio
});
});

test('it creates a canonical metadata account using an existing buffer', async t => {
it('creates a canonical metadata account using an existing buffer', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand Down Expand Up @@ -119,7 +119,7 @@ test('it creates a canonical metadata account using an existing buffer', async t
// Then we expect the following metadata account to be created.
const [metadata] = await findCanonicalPda({ program, seed: 'idl' });
const account = await client.programMetadata.accounts.metadata.fetch(metadata);
t.like(account.data, <Metadata>{
expect(account.data).toMatchObject(<Metadata>{
discriminator: AccountDiscriminator.Metadata,
program,
authority: none(),
Expand All @@ -135,7 +135,7 @@ test('it creates a canonical metadata account using an existing buffer', async t
});
});

test('it creates a non-canonical metadata account', async t => {
it('creates a non-canonical metadata account', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -157,7 +157,7 @@ test('it creates a non-canonical metadata account', async t => {
// Then we expect the following metadata account to be created.
const [metadata] = await findNonCanonicalPda({ program, authority: authority.address, seed: 'idl' });
const account = await client.programMetadata.accounts.metadata.fetch(metadata);
t.like(account.data, <Metadata>{
expect(account.data).toMatchObject(<Metadata>{
discriminator: AccountDiscriminator.Metadata,
program,
authority: some(authority.address),
Expand All @@ -173,7 +173,7 @@ test('it creates a non-canonical metadata account', async t => {
});
});

test('it creates a non-canonical metadata account with data larger than a transaction size', async t => {
it('creates a non-canonical metadata account with data larger than a transaction size', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -195,7 +195,7 @@ test('it creates a non-canonical metadata account with data larger than a transa
// Then we expect the following metadata account to be created.
const [metadata] = await findNonCanonicalPda({ program, authority: authority.address, seed: 'idl' });
const account = await client.programMetadata.accounts.metadata.fetch(metadata);
t.like(account.data, <Metadata>{
expect(account.data).toMatchObject(<Metadata>{
discriminator: AccountDiscriminator.Metadata,
program,
authority: some(authority.address),
Expand All @@ -211,7 +211,7 @@ test('it creates a non-canonical metadata account with data larger than a transa
});
});

test('it creates a non-canonical metadata account using an existing buffer', async t => {
it('creates a non-canonical metadata account using an existing buffer', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand Down Expand Up @@ -239,7 +239,7 @@ test('it creates a non-canonical metadata account using an existing buffer', asy
// Then we expect the following metadata account to be created.
const [metadata] = await findNonCanonicalPda({ program, authority: authority.address, seed: 'idl' });
const account = await client.programMetadata.accounts.metadata.fetch(metadata);
t.like(account.data, <Metadata>{
expect(account.data).toMatchObject(<Metadata>{
discriminator: AccountDiscriminator.Metadata,
program,
authority: some(authority.address),
Expand All @@ -255,7 +255,7 @@ test('it creates a non-canonical metadata account using an existing buffer', asy
});
});

test('it cannot create a metadata account if no data or buffer is provided', async t => {
it('cannot create a metadata account if no data or buffer is provided', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand All @@ -273,12 +273,12 @@ test('it cannot create a metadata account if no data or buffer is provided', asy
});

// Then we expect the following error to be thrown.
await t.throwsAsync(promise, {
message: 'Either `buffer` or `data` must be provided to create a new metadata account.',
});
await expect(promise).rejects.toThrow(
'Either `buffer` or `data` must be provided to create a new metadata account.',
);
});

test('it can close an existing buffer after using it to create a new metadata account', async t => {
it('can close an existing buffer after using it to create a new metadata account', async () => {
// Given the following authority and deployed program.
const client = await createTestClient();
const authority = await generateKeyPairSignerWithSol(client);
Expand Down Expand Up @@ -306,5 +306,5 @@ test('it can close an existing buffer after using it to create a new metadata ac

// Then we expect the buffer account to no longer exist.
const bufferAccount = await client.programMetadata.accounts.buffer.fetchMaybe(buffer.address);
t.false(bufferAccount.exists);
expect(bufferAccount.exists).toBe(false);
});
Loading
Loading