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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [main]

env:
JS_PACKAGES: "['clients-js-legacy']"
JS_PACKAGES: "['clients-js', 'clients-js-legacy']"
SBPF_PROGRAM_PACKAGES: "['program']"
RUST_PACKAGES: "['program']"
WASM_PACKAGES: "['program']"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ on:
package-path:
description: Path to directory with package to release
required: true
default: 'clients/js-legacy'
default: "clients/js"
type: choice
options:
- clients/js
- clients/js-legacy
level:
description: Version level
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ clippy-%:
--deny=clippy::manual_let_else \
--deny=clippy::used_underscore_binding $(ARGS)

format-check-js-%:
cd $(call make-path,$*) && pnpm install && pnpm format $(ARGS)

format-check-%:
cargo $(nightly) fmt --check --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)

Expand Down Expand Up @@ -73,20 +76,17 @@ build-doc-%:
test-doc-%:
cargo $(nightly) test --doc --all-features --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)

test-js-%:
make restart-test-validator
cd $(call make-path,$*) && pnpm install && pnpm build && pnpm test $(ARGS)
make stop-test-validator

test-%:
SBF_OUT_DIR=$(PWD)/target/deploy cargo $(nightly) test --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)

format-check-js-%:
cd $(call make-path,$*) && pnpm install && pnpm format $(ARGS)

lint-js-%:
cd $(call make-path,$*) && pnpm install && pnpm lint $(ARGS)

test-js-%:
make restart-test-validator
cd $(call make-path,$*) && pnpm install && pnpm build && pnpm test $(ARGS)
make stop-test-validator

build-js-%:
cd $(call make-path,$*) && pnpm install && pnpm build

Expand Down
17 changes: 17 additions & 0 deletions clients/js/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
extends: ["@solana/eslint-config-solana"],
ignorePatterns: [".eslintrc.cjs", "tsup.config.ts", "env-shim.ts"],
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
sourceType: "module",
},
rules: {
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/sort-type-constituents": "off",
"prefer-destructuring": "off",
"simple-import-sort/imports": "off",
"sort-keys-fix/sort-keys-fix": "off",
"typescript-sort-keys/interface": "off",
},
};
10 changes: 10 additions & 0 deletions clients/js/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"useTabs": false,
"tabWidth": 2,
"arrowParens": "always",
"printWidth": 80
}

26 changes: 13 additions & 13 deletions clients/js/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import {
KeyPairSigner,
Rpc,
TransactionSigner,
} from "@solana/kit";
} from '@solana/kit';
import {
getCreateAccountInstruction,
getTransferSolInstruction,
} from "@solana-program/system";
} from '@solana-program/system';
import {
getCloseAccountInstruction,
getInitializeInstruction,
getReallocateInstruction,
getSetAuthorityInstruction,
getWriteInstruction,
SPL_RECORD_PROGRAM_ADDRESS,
} from "./generated";
import { RECORD_META_DATA_SIZE } from "./constants";
} from './generated';
import { RECORD_META_DATA_SIZE } from './constants';

export interface CreateRecordArgs {
rpc: Rpc<GetMinimumBalanceForRentExemptionApi>;
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function createRecord({
recordAccount: recordSigner.address,
authority,
},
{ programAddress: programId },
{ programAddress: programId }
);

return {
Expand Down Expand Up @@ -95,7 +95,7 @@ export function createWriteInstruction(args: WriteRecordArgs): Instruction {
offset: BigInt(args.offset),
data: args.data,
},
{ programAddress: args.programId },
{ programAddress: args.programId }
);
}

Expand Down Expand Up @@ -134,7 +134,7 @@ export async function reallocateRecord({
source: payer,
destination: recordAccount,
amount: lamportsNeeded,
}),
})
);
}

Expand All @@ -145,8 +145,8 @@ export async function reallocateRecord({
authority,
dataLength: BigInt(newDataLength),
},
{ programAddress: programId },
),
{ programAddress: programId }
)
);

return ixs;
Expand All @@ -160,15 +160,15 @@ export interface SetAuthorityArgs {
}

export function createSetAuthorityInstruction(
args: SetAuthorityArgs,
args: SetAuthorityArgs
): Instruction {
return getSetAuthorityInstruction(
{
recordAccount: args.recordAccount,
authority: args.authority,
newAuthority: args.newAuthority,
},
{ programAddress: args.programId },
{ programAddress: args.programId }
);
}

Expand All @@ -180,14 +180,14 @@ export interface CloseRecordArgs {
}

export function createCloseRecordInstruction(
args: CloseRecordArgs,
args: CloseRecordArgs
): Instruction {
return getCloseAccountInstruction(
{
recordAccount: args.recordAccount,
authority: args.authority,
receiver: args.receiver,
},
{ programAddress: args.programId },
{ programAddress: args.programId }
);
}
6 changes: 3 additions & 3 deletions clients/js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./constants";
export * from "./generated";
export * from "./actions";
export * from './constants';
export * from './generated';
export * from './actions';
20 changes: 10 additions & 10 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@ import {
setTransactionMessageFeePayerSigner,
setTransactionMessageLifetimeUsingBlockhash,
signTransactionMessageWithSigners,
} from "@solana/kit";
} from '@solana/kit';

export type Client = {
rpc: Rpc<SolanaRpcApi>;
rpcSubscriptions: RpcSubscriptions<SolanaRpcSubscriptionsApi>;
};

export const createDefaultSolanaClient = (): Client => {
const rpc = createSolanaRpc("http://127.0.0.1:8899");
const rpcSubscriptions = createSolanaRpcSubscriptions("ws://127.0.0.1:8900");
const rpc = createSolanaRpc('http://127.0.0.1:8899');
const rpcSubscriptions = createSolanaRpcSubscriptions('ws://127.0.0.1:8900');
return { rpc, rpcSubscriptions };
};

export const generateKeyPairSignerWithSol = async (
client: Client,
putativeLamports: bigint = 1_000_000_000n,
putativeLamports: bigint = 1_000_000_000n
) => {
const signer = await generateKeyPairSigner();
await airdropFactory(client)({
recipientAddress: signer.address,
lamports: lamports(putativeLamports),
commitment: "confirmed",
commitment: 'confirmed',
});
return signer;
};

export const createDefaultTransaction = async (
client: Client,
feePayer: TransactionSigner,
feePayer: TransactionSigner
) => {
const { value: latestBlockhash } = await client.rpc
.getLatestBlockhash()
.send();
return pipe(
createTransactionMessage({ version: 0 }),
(tx) => setTransactionMessageFeePayerSigner(feePayer, tx),
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx)
);
};

Expand All @@ -68,7 +68,7 @@ export const signAndSendTransaction = async (
transactionMessage: BaseTransactionMessage &
TransactionMessageWithFeePayer &
TransactionMessageWithBlockhashLifetime,
commitment: Commitment = "confirmed",
commitment: Commitment = 'confirmed'
) => {
const signedTransaction =
await signTransactionMessageWithSigners(transactionMessage);
Expand All @@ -83,12 +83,12 @@ export const signAndSendTransaction = async (
export const sendAndConfirmInstructions = async (
client: Client,
payer: TransactionSigner,
instructions: Instruction[],
instructions: Instruction[]
) => {
const signature = await pipe(
await createDefaultTransaction(client, payer),
(tx) => appendTransactionMessageInstructions(instructions, tx),
(tx) => signAndSendTransaction(client, tx),
(tx) => signAndSendTransaction(client, tx)
);
return signature;
};
18 changes: 9 additions & 9 deletions clients/js/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "ava";
import { generateKeyPairSigner } from "@solana/kit";
import test from 'ava';
import { generateKeyPairSigner } from '@solana/kit';
import {
fetchRecordData,
createRecord,
Expand All @@ -8,14 +8,14 @@ import {
createSetAuthorityInstruction,
createCloseRecordInstruction,
RECORD_META_DATA_SIZE,
} from "../src";
} from '../src';
import {
createDefaultSolanaClient,
generateKeyPairSignerWithSol,
sendAndConfirmInstructions,
} from "./_setup";
} from './_setup';

test("basic instructions flow", async (t) => {
test('basic instructions flow', async (t) => {
const client = createDefaultSolanaClient();
const payer = await generateKeyPairSignerWithSol(client);

Expand Down Expand Up @@ -54,13 +54,13 @@ test("basic instructions flow", async (t) => {

// Verify Reallocate
let rawAccount = await client.rpc
.getAccountInfo(recordAccount.address, { encoding: "base64" })
.getAccountInfo(recordAccount.address, { encoding: 'base64' })
.send();
// Ensure RECORD_META_DATA_SIZE is defined (it is 33n), convert to Number for subarray
const offset = Number(RECORD_META_DATA_SIZE);

let actualData = rawAccount.value?.data?.[0]
? Buffer.from(rawAccount.value.data[0], "base64").subarray(offset)
? Buffer.from(rawAccount.value.data[0], 'base64').subarray(offset)
: new Uint8Array([]);

t.deepEqual(actualData, Buffer.from([0, 0, 0, 0, 0]));
Expand All @@ -77,10 +77,10 @@ test("basic instructions flow", async (t) => {

// Verify Write
rawAccount = await client.rpc
.getAccountInfo(recordAccount.address, { encoding: "base64" })
.getAccountInfo(recordAccount.address, { encoding: 'base64' })
.send();
actualData = rawAccount.value?.data?.[0]
? Buffer.from(rawAccount.value.data[0], "base64").subarray(offset)
? Buffer.from(rawAccount.value.data[0], 'base64').subarray(offset)
: new Uint8Array([]);
t.deepEqual(actualData, Buffer.from([0, 1, 2, 3, 4]));

Expand Down
14 changes: 7 additions & 7 deletions clients/js/test/longRecord.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import test from "ava";
import { generateKeyPairSigner } from "@solana/kit";
import test from 'ava';
import { generateKeyPairSigner } from '@solana/kit';
import {
createRecord,
createWriteInstruction,
RECORD_META_DATA_SIZE,
RECORD_CHUNK_SIZE_PRE_INITIALIZE,
RECORD_CHUNK_SIZE_POST_INITIALIZE,
} from "../src";
} from '../src';
import {
createDefaultSolanaClient,
generateKeyPairSignerWithSol,
sendAndConfirmInstructions,
} from "./_setup";
} from './_setup';

test("long record data flow", async (t) => {
test('long record data flow', async (t) => {
const client = createDefaultSolanaClient();
const payer = await generateKeyPairSignerWithSol(client);
const recordAuthority = await generateKeyPairSigner();
Expand Down Expand Up @@ -67,12 +67,12 @@ test("long record data flow", async (t) => {

// 3. Verify Data
const rawAccount = await client.rpc
.getAccountInfo(recordAccount.address, { encoding: "base64" })
.getAccountInfo(recordAccount.address, { encoding: 'base64' })
.send();

const headerSize = Number(RECORD_META_DATA_SIZE);
const actualData = rawAccount.value?.data?.[0]
? Buffer.from(rawAccount.value.data[0], "base64").subarray(headerSize)
? Buffer.from(rawAccount.value.data[0], 'base64').subarray(headerSize)
: new Uint8Array([]);

t.deepEqual(actualData, Buffer.from(recordData));
Expand Down