Skip to content

Commit 0c3ad47

Browse files
authored
feat: add counter example pinocchio (#464)
* add counter example pinocchio * Update Cargo.toml
1 parent 5e4b21d commit 0c3ad47

File tree

12 files changed

+1551
-4
lines changed

12 files changed

+1551
-4
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"basics/close-account/pinocchio/program",
1212
"basics/close-account/anchor/programs/close-account",
1313
"basics/counter/native/program",
14+
"basics/counter/pinocchio/program",
1415
"basics/counter/anchor/programs/counter_anchor",
1516
"basics/counter/mpl-stack",
1617
"basics/create-account/native/program",
@@ -71,6 +72,7 @@ spl-token-2022-interface = "2.0.0"
7172
pinocchio = "0.9.2"
7273
pinocchio-log = "0.4.0"
7374
pinocchio-system = "0.4.0"
75+
pinocchio-pubkey = "0.3.0"
7476

7577
# testing
7678
litesvm = "0.8.1"

basics/counter/native/program/tests/test.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ fn test_counter() {
5353
svm.latest_blockhash(),
5454
);
5555

56-
dbg!(&[0].split_at(1));
57-
5856
let _ = svm.send_transaction(tx).is_ok();
5957

6058
let counter_account_data = svm.get_account(&counter_account.pubkey()).unwrap().data;
61-
let couneter = Counter::try_from_slice(&counter_account_data).unwrap();
62-
assert_eq!(couneter.count, 1);
59+
let counter = Counter::try_from_slice(&counter_account_data).unwrap();
60+
assert_eq!(counter.count, 1);
6361
}

basics/counter/pinocchio/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Counter: Solana Pinocchio
2+
3+
This example program is written in Solana using only the Solana toolsuite.
4+
5+
## Setup
6+
7+
1. Build the program with `cargo build-sbf`
8+
2. Run tests + local validator with `yarn test`
9+
10+
## Debugging
11+
12+
1. Start test validator with `yarn start-validator`
13+
2. Start listening to program logs with `solana config set -ul && solana logs`
14+
3. Run tests with `yarn run-tests`
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "counter-solana-pinocchio",
3+
"version": "0.1.0",
4+
"description": "Counter program written using only Solana tooling",
5+
"main": "index.js",
6+
"author": "ngundotra",
7+
"license": "Apache-2.0",
8+
"private": false,
9+
"type": "module",
10+
"scripts": {
11+
"test": "pnpm ts-mocha -p ./tests/tsconfig.test.json -t 1000000 ./tests/counter.test.ts",
12+
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
13+
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
14+
"deploy": "solana program deploy ./program/target/so/program.so"
15+
},
16+
"devDependencies": {
17+
"@types/bn.js": "^5.1.0",
18+
"@types/chai": "^4.3.1",
19+
"@types/mocha": "^9.1.1",
20+
"chai": "^4.3.4",
21+
"mocha": "^9.0.3",
22+
"solana-bankrun": "^0.3.0",
23+
"ts-mocha": "^10.0.0",
24+
"typescript": "^4.3.5"
25+
},
26+
"dependencies": {
27+
"@solana/web3.js": "^1.91.4"
28+
}
29+
}

0 commit comments

Comments
 (0)