Skip to content

Commit ed6aa77

Browse files
committed
fix ts strip only error
1 parent e5ab5fa commit ed6aa77

File tree

3 files changed

+97
-52
lines changed
  • basics

3 files changed

+97
-52
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export * from './close';
2-
export * from './create';
1+
export * from "./close";
2+
export * from "./create";
33

4-
export enum MyInstruction {
5-
CreateUser = 0,
6-
CloseUser = 1,
7-
}
4+
export const MyInstruction = {
5+
CreateUser: 0,
6+
CloseUser: 1,
7+
} as const;

basics/favorites/native/tests/test.ts

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { Blockhash, Keypair, PublicKey, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js';
2-
import { BN } from 'bn.js';
3-
import * as borsh from 'borsh';
4-
import { assert, expect } from 'chai';
5-
import { describe, test } from 'mocha';
6-
import { BanksClient, ProgramTestContext, start } from 'solana-bankrun';
1+
import {
2+
Blockhash,
3+
Keypair,
4+
PublicKey,
5+
SystemProgram,
6+
Transaction,
7+
TransactionInstruction,
8+
} from "@solana/web3.js";
9+
import { BN } from "bn.js";
10+
import * as borsh from "borsh";
11+
import { assert, expect } from "chai";
12+
import { describe, test } from "mocha";
13+
import { BanksClient, ProgramTestContext, start } from "solana-bankrun";
714

815
// This is a helper class to assign properties to the class
916
class Assignable {
@@ -14,10 +21,10 @@ class Assignable {
1421
}
1522
}
1623

17-
enum MyInstruction {
18-
CreateFav = 0,
19-
GetFav = 1,
20-
}
24+
const MyInstruction = {
25+
CreateFav: 0,
26+
GetFav: 1,
27+
} as const;
2128

2229
class CreateFav extends Assignable {
2330
number: number;
@@ -33,11 +40,11 @@ class CreateFav extends Assignable {
3340
return borsh.deserialize(
3441
{
3542
struct: {
36-
number: 'u64',
37-
color: 'string',
43+
number: "u64",
44+
color: "string",
3845
hobbies: {
3946
array: {
40-
type: 'string',
47+
type: "string",
4148
},
4249
},
4350
},
@@ -48,12 +55,12 @@ class CreateFav extends Assignable {
4855
}
4956
const CreateNewAccountSchema = {
5057
struct: {
51-
instruction: 'u8',
52-
number: 'u64',
53-
color: 'string',
58+
instruction: "u8",
59+
number: "u64",
60+
color: "string",
5461
hobbies: {
5562
array: {
56-
type: 'string',
63+
type: "string",
5764
},
5865
},
5966
},
@@ -66,11 +73,11 @@ class GetFav extends Assignable {
6673
}
6774
const GetFavSchema = {
6875
struct: {
69-
instruction: 'u8',
76+
instruction: "u8",
7077
},
7178
};
7279

73-
describe('Favorites Solana Native', () => {
80+
describe("Favorites Solana Native", () => {
7481
// Randomly generate the program keypair and load the program to solana-bankrun
7582
const programId = PublicKey.unique();
7683

@@ -80,16 +87,24 @@ describe('Favorites Solana Native', () => {
8087
let blockhash: Blockhash;
8188

8289
beforeEach(async () => {
83-
context = await start([{ name: 'favorites_native', programId }], []);
90+
context = await start([{ name: "favorites_native", programId }], []);
8491
client = context.banksClient;
8592
// Get the payer keypair from the context, this will be used to sign transactions with enough lamports
8693
payer = context.payer;
8794
blockhash = context.lastBlockhash;
8895
});
8996

90-
test('Set the favorite pda and cross-check the updated data', async () => {
91-
const favoritesPda = PublicKey.findProgramAddressSync([Buffer.from('favorite'), payer.publicKey.toBuffer()], programId)[0];
92-
const favData = { instruction: MyInstruction.CreateFav, number: 42, color: 'blue', hobbies: ['coding', 'reading', 'traveling'] };
97+
test("Set the favorite pda and cross-check the updated data", async () => {
98+
const favoritesPda = PublicKey.findProgramAddressSync(
99+
[Buffer.from("favorite"), payer.publicKey.toBuffer()],
100+
programId,
101+
)[0];
102+
const favData = {
103+
instruction: MyInstruction.CreateFav,
104+
number: 42,
105+
color: "blue",
106+
hobbies: ["coding", "reading", "traveling"],
107+
};
93108
const favorites = new CreateFav(favData);
94109

95110
const ix = new TransactionInstruction({
@@ -115,17 +130,27 @@ describe('Favorites Solana Native', () => {
115130

116131
const favoritesData = CreateFav.fromBuffer(data);
117132

118-
console.log('Deserialized data:', favoritesData);
133+
console.log("Deserialized data:", favoritesData);
119134

120-
expect(new BN(favoritesData.number as any, 'le').toNumber()).to.equal(favData.number);
135+
expect(new BN(favoritesData.number as any, "le").toNumber()).to.equal(
136+
favData.number,
137+
);
121138
expect(favoritesData.color).to.equal(favData.color);
122139
expect(favoritesData.hobbies).to.deep.equal(favData.hobbies);
123140
});
124141

125142
test("Check if the test fails if the pda seeds aren't same", async () => {
126143
// We put the wrong seeds knowingly to see if the test fails because of checks
127-
const favoritesPda = PublicKey.findProgramAddressSync([Buffer.from('favorite'), payer.publicKey.toBuffer()], programId)[0];
128-
const favData = { instruction: MyInstruction.CreateFav, number: 42, color: 'blue', hobbies: ['coding', 'reading', 'traveling'] };
144+
const favoritesPda = PublicKey.findProgramAddressSync(
145+
[Buffer.from("favorite"), payer.publicKey.toBuffer()],
146+
programId,
147+
)[0];
148+
const favData = {
149+
instruction: MyInstruction.CreateFav,
150+
number: 42,
151+
color: "blue",
152+
hobbies: ["coding", "reading", "traveling"],
153+
};
129154
const favorites = new CreateFav(favData);
130155

131156
const ix = new TransactionInstruction({
@@ -146,16 +171,24 @@ describe('Favorites Solana Native', () => {
146171
tx.recentBlockhash = blockhash;
147172
try {
148173
await client.processTransaction(tx);
149-
console.error('Expected the test to fail');
174+
console.error("Expected the test to fail");
150175
} catch (_err) {
151176
assert(true);
152177
}
153178
});
154179

155-
test('Get the favorite pda and cross-check the data', async () => {
180+
test("Get the favorite pda and cross-check the data", async () => {
156181
// Creating a new account with payer's pubkey
157-
const favoritesPda = PublicKey.findProgramAddressSync([Buffer.from('favorite'), payer.publicKey.toBuffer()], programId)[0];
158-
const favData = { instruction: MyInstruction.CreateFav, number: 42, color: 'hazel', hobbies: ['singing', 'dancing', 'skydiving'] };
182+
const favoritesPda = PublicKey.findProgramAddressSync(
183+
[Buffer.from("favorite"), payer.publicKey.toBuffer()],
184+
programId,
185+
)[0];
186+
const favData = {
187+
instruction: MyInstruction.CreateFav,
188+
number: 42,
189+
color: "hazel",
190+
hobbies: ["singing", "dancing", "skydiving"],
191+
};
159192
const favorites = new CreateFav(favData);
160193

161194
const ix = new TransactionInstruction({

basics/pda-rent-payer/native/tests/test.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import { Buffer } from 'node:buffer';
2-
import { describe, test } from 'node:test';
3-
import { Keypair, PublicKey, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js';
4-
import * as borsh from 'borsh';
5-
import { start } from 'solana-bankrun';
1+
import { Buffer } from "node:buffer";
2+
import { describe, test } from "node:test";
3+
import {
4+
Keypair,
5+
PublicKey,
6+
SystemProgram,
7+
Transaction,
8+
TransactionInstruction,
9+
} from "@solana/web3.js";
10+
import * as borsh from "borsh";
11+
import { start } from "solana-bankrun";
612

7-
describe('PDA Rent-Payer', async () => {
13+
describe("PDA Rent-Payer", async () => {
814
const PROGRAM_ID = PublicKey.unique();
9-
const context = await start([{ name: 'pda_rent_payer_program', programId: PROGRAM_ID }], []);
15+
const context = await start(
16+
[{ name: "pda_rent_payer_program", programId: PROGRAM_ID }],
17+
[],
18+
);
1019
const client = context.banksClient;
1120
const payer = context.payer;
1221

@@ -32,10 +41,10 @@ describe('PDA Rent-Payer', async () => {
3241
[
3342
InitRentVault,
3443
{
35-
kind: 'struct',
44+
kind: "struct",
3645
fields: [
37-
['instruction', 'u8'],
38-
['fund_lamports', 'u64'],
46+
["instruction", "u8"],
47+
["fund_lamports", "u64"],
3948
],
4049
},
4150
],
@@ -50,19 +59,22 @@ describe('PDA Rent-Payer', async () => {
5059
[
5160
CreateNewAccount,
5261
{
53-
kind: 'struct',
54-
fields: [['instruction', 'u8']],
62+
kind: "struct",
63+
fields: [["instruction", "u8"]],
5564
},
5665
],
5766
]);
5867

5968
function deriveRentVaultPda() {
60-
const pda = PublicKey.findProgramAddressSync([Buffer.from('rent_vault')], PROGRAM_ID);
69+
const pda = PublicKey.findProgramAddressSync(
70+
[Buffer.from("rent_vault")],
71+
PROGRAM_ID,
72+
);
6173
console.log(`PDA: ${pda[0].toBase58()}`);
6274
return pda;
6375
}
6476

65-
test('Initialize the Rent Vault', async () => {
77+
test("Initialize the Rent Vault", async () => {
6678
const blockhash = context.lastBlockhash;
6779
const [rentVaultPda, _] = deriveRentVaultPda();
6880
const ix = new TransactionInstruction({
@@ -85,7 +97,7 @@ describe('PDA Rent-Payer', async () => {
8597
await client.processTransaction(tx);
8698
});
8799

88-
test('Create a new account using the Rent Vault', async () => {
100+
test("Create a new account using the Rent Vault", async () => {
89101
const blockhash = context.lastBlockhash;
90102
const newAccount = Keypair.generate();
91103
const [rentVaultPda, _] = deriveRentVaultPda();

0 commit comments

Comments
 (0)