Skip to content

Commit

Permalink
style: prettier formatting standard
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfrosty committed Apr 7, 2023
1 parent 951a345 commit b7fae5c
Show file tree
Hide file tree
Showing 77 changed files with 2,617 additions and 7,038 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ test-ledger/
*/**/test-ledger/
*/**/node_modules/
*/**/yarn.lock
*/**/package-lock.json
*/**/yarn-error.log
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"trailingComma": "all",
"tabWidth": 2,
"useTabs": true,
"semi": true,
"singleQuote": false,
"proseWrap": "always",
"printWidth": 80
}
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Web3 Examples

### :space_invader: Welcome, Solana Developer. :space_invader:

Are you just starting out on Solana? Stuck on something?

Or maybe you're in a hackathon right now, building an absolutely *epic* dApp.

Take a look at this awesome collection of examples in Typescript using Solana's `web3.js` (and Anchor); for your cloning & running pleasure.

### :large_blue_diamond: TypeScript. :large_orange_diamond: JavaScript. :cyclone: Web3.
### :space_invader: Welcome, Solana Developer. :space_invader:

Are you just starting out on Solana? Stuck on something?

Or maybe you're in a hackathon right now, building an absolutely _epic_ dApp.

Take a look at this awesome collection of examples in Typescript using Solana's
`web3.js` (and Anchor); for your cloning & running pleasure.

### :large_blue_diamond: TypeScript. :large_orange_diamond: JavaScript. :cyclone: Web3.
29 changes: 15 additions & 14 deletions address-lookup-tables/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"scripts": {
"test": "yarn run ts-mocha -p ./tests/tsconfig.json -t 1000000 ./tests/test.ts"
},
"dependencies": {
"@solana/web3.js": "1.63.1"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1",
"chai": "^4.3.6",
"mocha": "^10.0.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.8.3"
}
"scripts": {
"test": "yarn run ts-mocha -p ./tests/tsconfig.json -t 1000000 ./tests/test.ts"
},
"license": "MIT",
"dependencies": {
"@solana/web3.js": "1.63.1"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1",
"chai": "^4.3.6",
"mocha": "^10.0.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.8.3"
}
}
241 changes: 124 additions & 117 deletions address-lookup-tables/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,128 @@
import {
AddressLookupTableProgram,
Connection,
Keypair,
PublicKey,
SystemProgram,
TransactionInstruction,
} from '@solana/web3.js';
AddressLookupTableProgram,
Connection,
Keypair,
PublicKey,
SystemProgram,
TransactionInstruction,
} from "@solana/web3.js";
import {
createKeypairFromFile,
printAddressLookupTable,
printBalances,
sendTransactionV0,
sendTransactionV0WithLookupTable,
} from './util';

createKeypairFromFile,
printAddressLookupTable,
printBalances,
sendTransactionV0,
sendTransactionV0WithLookupTable,
} from "./util";

describe("Address Lookup Tables!", () => {

const connection = new Connection(
`https://api.devnet.solana.com`,
'confirmed'
);
const payer = createKeypairFromFile(
require('os').homedir() + '/.config/solana/id.json'
);

let lookupTablePubkey: PublicKey;
const testAccountOne = Keypair.generate();
const testAccountTwo = Keypair.generate();

it("Create an Address Lookup Table", async () => {

let ix: TransactionInstruction;
[ix, lookupTablePubkey] = AddressLookupTableProgram.createLookupTable({
authority: payer.publicKey,
payer: payer.publicKey,
recentSlot: await connection.getSlot(),
});

await sendTransactionV0(connection, [ix], payer);

console.log("Pubkeys from generated keypairs:")
console.log(` Test Account #1: ${testAccountOne.publicKey}`);
console.log(` Test Account #2: ${testAccountTwo.publicKey}`);
await printAddressLookupTable(connection, lookupTablePubkey);
});

it("Add some addresses to the ALT", async () => {

const ix = AddressLookupTableProgram.extendLookupTable({
addresses: [
testAccountOne.publicKey,
testAccountTwo.publicKey
],
authority: payer.publicKey,
lookupTable: lookupTablePubkey,
payer: payer.publicKey,
});

await sendTransactionV0(connection, [ix], payer);

await printAddressLookupTable(connection, lookupTablePubkey);
});

it("Fund the first test account", async () => {

const ix = SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: testAccountOne.publicKey,
lamports: 100000000,
});

await sendTransactionV0(connection, [ix], payer);

await printBalances(
connection, "After", testAccountOne.publicKey, testAccountTwo.publicKey
);
});

it("Send a transaction WITHOUT using the ALT", async () => {

await printBalances(
connection, "Before", testAccountOne.publicKey, testAccountTwo.publicKey
);

const ix = SystemProgram.transfer({
fromPubkey: testAccountOne.publicKey,
toPubkey: testAccountTwo.publicKey,
lamports: 20000000,
});

await sendTransactionV0(connection, [ix], testAccountOne);

await printBalances(
connection, "After", testAccountOne.publicKey, testAccountTwo.publicKey
);
});

it("Now send that same transaction using the ALT", async () => {

await printBalances(
connection, "Before", payer.publicKey, testAccountOne.publicKey
);

const ix = SystemProgram.transfer({
fromPubkey: testAccountOne.publicKey,
toPubkey: testAccountTwo.publicKey,
lamports: 20000000,
});

await sendTransactionV0WithLookupTable(
connection, [ix], testAccountOne, lookupTablePubkey
);

await printBalances(
connection, "After", testAccountOne.publicKey, testAccountTwo.publicKey
);
});
});

const connection = new Connection(
`https://api.devnet.solana.com`,
"confirmed",
);
const payer = createKeypairFromFile(
require("os").homedir() + "/.config/solana/id.json",
);

let lookupTablePubkey: PublicKey;
const testAccountOne = Keypair.generate();
const testAccountTwo = Keypair.generate();

it("Create an Address Lookup Table", async () => {
let ix: TransactionInstruction;
[ix, lookupTablePubkey] = AddressLookupTableProgram.createLookupTable({
authority: payer.publicKey,
payer: payer.publicKey,
recentSlot: await connection.getSlot(),
});

await sendTransactionV0(connection, [ix], payer);

console.log("Pubkeys from generated keypairs:");
console.log(` Test Account #1: ${testAccountOne.publicKey}`);
console.log(` Test Account #2: ${testAccountTwo.publicKey}`);
await printAddressLookupTable(connection, lookupTablePubkey);
});

it("Add some addresses to the ALT", async () => {
const ix = AddressLookupTableProgram.extendLookupTable({
addresses: [testAccountOne.publicKey, testAccountTwo.publicKey],
authority: payer.publicKey,
lookupTable: lookupTablePubkey,
payer: payer.publicKey,
});

await sendTransactionV0(connection, [ix], payer);

await printAddressLookupTable(connection, lookupTablePubkey);
});

it("Fund the first test account", async () => {
const ix = SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: testAccountOne.publicKey,
lamports: 100000000,
});

await sendTransactionV0(connection, [ix], payer);

await printBalances(
connection,
"After",
testAccountOne.publicKey,
testAccountTwo.publicKey,
);
});

it("Send a transaction WITHOUT using the ALT", async () => {
await printBalances(
connection,
"Before",
testAccountOne.publicKey,
testAccountTwo.publicKey,
);

const ix = SystemProgram.transfer({
fromPubkey: testAccountOne.publicKey,
toPubkey: testAccountTwo.publicKey,
lamports: 20000000,
});

await sendTransactionV0(connection, [ix], testAccountOne);

await printBalances(
connection,
"After",
testAccountOne.publicKey,
testAccountTwo.publicKey,
);
});

it("Now send that same transaction using the ALT", async () => {
await printBalances(
connection,
"Before",
payer.publicKey,
testAccountOne.publicKey,
);

const ix = SystemProgram.transfer({
fromPubkey: testAccountOne.publicKey,
toPubkey: testAccountTwo.publicKey,
lamports: 20000000,
});

await sendTransactionV0WithLookupTable(
connection,
[ix],
testAccountOne,
lookupTablePubkey,
);

await printBalances(
connection,
"After",
testAccountOne.publicKey,
testAccountTwo.publicKey,
);
});
});
14 changes: 6 additions & 8 deletions address-lookup-tables/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
"compilerOptions": {
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
}
Loading

0 comments on commit b7fae5c

Please sign in to comment.