Skip to content

Commit 39f7775

Browse files
committed
revert test.ts format
1 parent a141819 commit 39f7775

File tree

1 file changed

+79
-78
lines changed
  • basics/account-data/native/tests

1 file changed

+79
-78
lines changed
Lines changed: 79 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,104 @@
11
import { Buffer } from "node:buffer";
22
import { describe, test } from "node:test";
33
import {
4-
Keypair,
5-
PublicKey,
6-
SystemProgram,
7-
Transaction,
8-
TransactionInstruction,
4+
Keypair,
5+
PublicKey,
6+
SystemProgram,
7+
Transaction,
8+
TransactionInstruction,
99
} from "@solana/web3.js";
1010
import * as borsh from "borsh";
1111
import { start } from "solana-bankrun";
1212

1313
class Assignable {
14-
constructor(properties) {
15-
for (const [key, value] of Object.entries(properties)) {
16-
this[key] = value;
17-
}
18-
}
14+
constructor(properties) {
15+
for (const [key, value] of Object.entries(properties)) {
16+
this[key] = value;
17+
}
18+
}
1919
}
2020

2121
class AddressInfo extends Assignable {
22-
street: string;
23-
city: string;
24-
name: string;
25-
house_number: number;
26-
toBuffer() {
27-
return Buffer.from(borsh.serialize(AddressInfoSchema, this));
28-
}
22+
street: string;
23+
city: string;
24+
name: string;
25+
house_number: number;
26+
toBuffer() {
27+
return Buffer.from(borsh.serialize(AddressInfoSchema, this));
28+
}
2929

30-
static fromBuffer(buffer: Buffer) {
31-
return borsh.deserialize(AddressInfoSchema, AddressInfo, buffer);
32-
}
30+
static fromBuffer(buffer: Buffer) {
31+
return borsh.deserialize(AddressInfoSchema, AddressInfo, buffer);
32+
}
3333
}
3434
const AddressInfoSchema = new Map([
35-
[
36-
AddressInfo,
37-
{
38-
kind: "struct",
39-
fields: [
40-
["name", "string"],
41-
["house_number", "u8"],
42-
["street", "string"],
43-
["city", "string"],
44-
],
45-
},
46-
],
35+
[
36+
AddressInfo,
37+
{
38+
kind: "struct",
39+
fields: [
40+
["name", "string"],
41+
["house_number", "u8"],
42+
["street", "string"],
43+
["city", "string"],
44+
],
45+
},
46+
],
4747
]);
4848

4949
describe("Account Data!", async () => {
50-
const addressInfoAccount = Keypair.generate();
51-
const PROGRAM_ID = PublicKey.unique();
52-
const context = await start(
53-
[{ name: "account_data_native_program", programId: PROGRAM_ID }],
54-
[],
55-
);
56-
const client = context.banksClient;
50+
const addressInfoAccount = Keypair.generate();
51+
const PROGRAM_ID = PublicKey.unique();
52+
const context = await start(
53+
[{ name: "account_data_native_program", programId: PROGRAM_ID }],
54+
[],
55+
);
56+
const client = context.banksClient;
5757

58-
test("Create the address info account", async () => {
59-
const payer = context.payer;
58+
test("Create the address info account", async () => {
59+
const payer = context.payer;
6060

61-
console.log(`Program Address : ${PROGRAM_ID}`);
62-
console.log(`Payer Address : ${payer.publicKey}`);
63-
console.log(`Address Info Acct : ${addressInfoAccount.publicKey}`);
61+
console.log(`Program Address : ${PROGRAM_ID}`);
62+
console.log(`Payer Address : ${payer.publicKey}`);
63+
console.log(`Address Info Acct : ${addressInfoAccount.publicKey}`);
6464

65-
const ix = new TransactionInstruction({
66-
keys: [
67-
{
68-
pubkey: addressInfoAccount.publicKey,
69-
isSigner: true,
70-
isWritable: true,
71-
},
72-
{ pubkey: payer.publicKey, isSigner: true, isWritable: true },
73-
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
74-
],
75-
programId: PROGRAM_ID,
76-
data: new AddressInfo({
77-
name: "Joe C",
78-
house_number: 136,
79-
street: "Mile High Dr.",
80-
city: "Solana Beach",
81-
}).toBuffer(),
82-
});
65+
const ix = new TransactionInstruction({
66+
keys: [
67+
{
68+
pubkey: addressInfoAccount.publicKey,
69+
isSigner: true,
70+
isWritable: true,
71+
},
72+
{ pubkey: payer.publicKey, isSigner: true, isWritable: true },
73+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
74+
],
75+
programId: PROGRAM_ID,
76+
data: new AddressInfo({
77+
name: "Joe C",
78+
house_number: 136,
79+
street: "Mile High Dr.",
80+
city: "Solana Beach",
81+
}).toBuffer(),
82+
});
8383

84-
const blockhash = context.lastBlockhash;
84+
const blockhash = context.lastBlockhash;
8585

86-
const tx = new Transaction();
87-
tx.recentBlockhash = blockhash;
88-
tx.add(ix).sign(payer, addressInfoAccount);
89-
await client.processTransaction(tx);
90-
});
86+
const tx = new Transaction();
87+
tx.recentBlockhash = blockhash;
88+
tx.add(ix).sign(payer, addressInfoAccount);
89+
await client.processTransaction(tx);
90+
});
9191

92-
test("Read the new account's data", async () => {
93-
const accountInfo = await client.getAccount(addressInfoAccount.publicKey);
92+
test("Read the new account's data", async () => {
93+
const accountInfo = await client.getAccount(addressInfoAccount.publicKey);
9494

95-
const readAddressInfo = AddressInfo.fromBuffer(
96-
Buffer.from(accountInfo.data),
97-
);
98-
console.log(`Name : ${readAddressInfo.name}`);
99-
console.log(`House Num: ${readAddressInfo.house_number}`);
100-
console.log(`Street : ${readAddressInfo.street}`);
101-
console.log(`City : ${readAddressInfo.city}`);
102-
});
95+
const readAddressInfo = AddressInfo.fromBuffer(
96+
Buffer.from(accountInfo.data),
97+
);
98+
console.log(`Name : ${readAddressInfo.name}`);
99+
console.log(`House Num: ${readAddressInfo.house_number}`);
100+
console.log(`Street : ${readAddressInfo.street}`);
101+
console.log(`City : ${readAddressInfo.city}`);
102+
});
103103
});
104+

0 commit comments

Comments
 (0)