Skip to content

Commit 105d9ea

Browse files
committed
fix: fix all broken builds and tests across the repo
Native tests (16/16 passing): - counter/native & escrow/native: add bn.js as explicit dependency. pnpm's strict dependency resolution does not hoist transitive deps (unlike npm), so bn.js from @solana/web3.js is not accessible directly. - All native tests using borsh: migrate from borsh v0.7 class-based API to borsh v2 object schema API. The v0.7 API (Map schemas, Assignable classes, 3-arg deserialize) is incompatible with borsh v1+. Updated 19 test files and 14 package.json files. Introduced a shared borshSerialize(schema, data) helper to replace the repeated Buffer.from(borsh.serialize(...)) pattern. Removed per-schema typed wrappers in favour of exporting schemas directly. - create-account/native: replace litesvm with solana-bankrun. litesvm's native binary crashes with SIGABRT on Linux x64 (LiteSVM/litesvm#171). This was the only native test using litesvm — all others use solana-bankrun, the recommended framework per CONTRIBUTING.md. Anchor builds (39/39 passing): - Set solana_version = "3.1.8" in all 49 Anchor.toml files. Anchor's default BPF toolchain ships rustc 1.79, but anchor-lang 0.32.1's dependency tree requires rustc 1.82+ (indexmap 2.13.0) and Cargo's edition2024 feature. Solana 3.1.8 platform-tools v1.52 (rustc 1.89) resolves both. All projects now use a consistent toolchain version. - allow-block-list-token: bump spl-transfer-hook-interface 0.8.2 -> 2.1.0, spl-tlv-account-resolution 0.8.1 -> 0.11.1, spl-discriminator 0.3 -> 0.5.1. Old SPL versions used solana-program v1, causing type mismatches with anchor-lang 0.32.1's v2 types. litesvm Rust test moved to tests-rs/ because litesvm pins solana-account-info =2.2.1 but anchor-lang 0.32.1 needs >=2.3.0 for AccountInfo::resize(). See tests-rs/README.md. Compression projects (3/3 building): - Rewrite cnft-burn, cnft-vault, cutils from anchor-lang 0.26.0 to 0.32.1. Upgrade to mpl-bubblegum 2.1.1 + spl-account-compression 1.0.0 (both use solana-program v2, matching anchor-lang 0.32.1). cnft-vault: manual invoke_signed rewritten to TransferCpi. cutils verify: raw invoke because spl-account-compression 1.0.0's CPI module is built against anchor-lang 0.31, which has incompatible traits with 0.32.1. Discriminator computed from sha256("global:verify_leaf") rather than hardcoded. Comment documents when this workaround can be removed. Documentation: - README: remove TypeScript/Poseidon references (none exist in repo), Anchor before Native in badges, fix typos. - CONTRIBUTING: remove Steel/Python/Solidity/Poseidon references (none exist in repo), fix markdown, renumber sections.
1 parent 4babc04 commit 105d9ea

138 files changed

Lines changed: 6732 additions & 1558 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To ensure a smooth and effective contribution process, please take a moment to r
1010

1111
We welcome contributions in the form of code, documentation, bug reports, feature requests, and other forms of feedback. Here are some ways you can contribute:
1212

13-
- **Code Contributions:** You can contribute code examples in Rust, Python, or Solidity that demonstrate various Solana program functionalities. You can also contribute improvements to existing examples, such as bug fixes, optimizations, or additional features.
13+
- **Code Contributions:** You can contribute code examples in Rust that demonstrate various Solana program functionalities. You can also contribute improvements to existing examples, such as bug fixes, optimizations, or additional features.
1414

1515
- **Bug Reports, Ideas or Feedback:** If you encounter any issues or have ideas for new examples, please submit a bug report or feature request. Your feedback is valuable and helps us improve the quality and relevance of the examples.
1616

@@ -22,40 +22,13 @@ Specifically for code in this repo:
2222

2323
1. Use pnpm as the default package manager for the project. You can [install pnpm by following the instructions](https://pnpm.io/installation). Commit `pnpm-lock.yaml` to the repository.
2424

25-
2. Solana Programs written for Anchor framework should be in directory (`anchor`)[https://www.anchor-lang.com], Solana Native in (`native`)[https://solana.com/developers/guides/getstarted/intro-to-native-rust], Steel Framework in (`steel`)[https://github.com/regolith-labs/steel], TypeScript in (`poseidon`)[https://github.com/Turbin3/poseidon], respectively.
25+
2. Solana Programs written for the Anchor framework should be in directory [`anchor`](https://www.anchor-lang.com), Solana Native in [`native`](https://solana.com/developers/guides/getstarted/intro-to-native-rust), respectively.
2626
- Project path structure: `/program-examples/category/example-name/<framework_name>`
2727
- Project path structure example for anchor: `/program-examples/category/example-name/anchor`
2828

29-
3. Tests for Solana native programs, steel framework programs, and Anchor should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun)
29+
3. Tests for Anchor and Solana native programs should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun).
3030

31-
4. Steel framework programs must be organized as a Cargo workspace with separate projects for API and program:
32-
- Project path structure: `/program-examples/category/example-name/steel`
33-
- Initialise project using `steel new <name>`
34-
- Must be a Cargo workspace with two separate projects:
35-
- `api`: Contains API-related code
36-
- `program`: Contains the program implementation
37-
- Steel projects should NOT be added in the root [`Cargo.toml` file](https://github.com/solana-developers/program-examples/blob/main/Cargo.toml)
38-
39-
This structure ensures proper organization and separation of concerns.
40-
41-
5. For Steel framework programs:
42-
- Steel CLI is the recommended way to build and test programs:
43-
```bash
44-
# Install Steel CLI (one-time setup)
45-
cargo install steel-cli
46-
47-
# Create a new Steel project
48-
steel new <name>
49-
50-
# Build the program
51-
steel build
52-
53-
# Run tests
54-
steel test
55-
```
56-
- Alternatively, you can use package.json scripts if you need custom build/test configurations as Solana native one described below.
57-
58-
6. For Solana native programs ensure adding these mandatory pnpm run scripts to your `package.json` file for successful CI/CD builds:
31+
4. For Solana native programs ensure adding these mandatory pnpm run scripts to your `package.json` file for successful CI/CD builds:
5932

6033
```json
6134
"scripts": {
@@ -66,35 +39,22 @@ Specifically for code in this repo:
6639
},
6740
```
6841

69-
Alternatively, You can add `steel test` and `steel build` as commands according to your project.
70-
71-
"scripts": {
72-
"test": "steel test",
73-
"build-and-test": "steel build && steel test",
74-
"build": "steel build",
75-
"deploy": "solana program deploy ./program/target/so/program.so"
76-
},
77-
78-
7. Test command for Anchor should execute `pnpm test` instead of `yarn run test` for anchor programs. Replace `yarn` with `pnpm` in `[script]` table inside [Anchor.toml file.](https://www.anchor-lang.com/docs/manifest#scripts-required-for-testing)
42+
5. Test command for Anchor should execute `pnpm test` instead of `yarn run test` for anchor programs. Replace `yarn` with `pnpm` in `[script]` table inside [Anchor.toml file.](https://www.anchor-lang.com/docs/manifest#scripts-required-for-testing)
7943

8044
```
8145
[scripts]
8246
test = "pnpm ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
8347
```
8448

85-
8. TypeScript, JavaScript and JSON files are formatted and linted using
49+
6. TypeScript, JavaScript and JSON files are formatted and linted using
8650
[Biome](https://biomejs.dev/). Execute the following command to format and lint your code at the root of this project before submitting a pull request:
8751

88-
8. Some projects can be ignored from the building and testing process by adding the project name to the `.ghaignore` file.
89-
When removing or updating an example, please ensure that the example is removed from the `.ghaignore` file
90-
and there's a change in that example's directory.
91-
9252
```bash
9353
pnpm fix
9454
```
9555

96-
9. Some projects can be ignored from the building and testing process by adding the project name to the `.gitignore` file.
97-
When removing or updating an example, please ensure that the example is removed from the `.gitignore` file
56+
7. Some projects can be ignored from the building and testing process by adding the project name to the `.ghaignore` file.
57+
When removing or updating an example, please ensure that the example is removed from the `.ghaignore` file
9858
and there's a change in that example's directory.
9959

10060
## Code of Conduct

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Program Examples
22

3-
## Onchain program examples for :anchor: Anchor :crab: Native Rust, and [TS] TypeScript.
3+
## Onchain program examples for :anchor: Anchor and :crab: Native Rust.
44

5-
[![Native](https://github.com/solana-developers/program-examples/actions/workflows/solana-native.yml/badge.svg?event=schedule)](https://github.com/solana-developers/program-examples/actions/workflows/solana-native.yml) [![Anchor](https://github.com/solana-developers/program-examples/actions/workflows/anchor.yml/badge.svg?event=schedule)](https://github.com/solana-developers/program-examples/actions/workflows/anchor.yml)
5+
[![Anchor](https://github.com/solana-developers/program-examples/actions/workflows/anchor.yml/badge.svg?event=schedule)](https://github.com/solana-developers/program-examples/actions/workflows/anchor.yml) [![Native](https://github.com/solana-developers/program-examples/actions/workflows/solana-native.yml/badge.svg?event=schedule)](https://github.com/solana-developers/program-examples/actions/workflows/solana-native.yml)
66

77
This repo contains Solana onchain programs (referred to as 'Smart Contracts' in other blockchains).
88

@@ -175,7 +175,7 @@ Allow two users to swap digital assets with each other, each getting 100% of wha
175175

176176
### Basics - create token mints, mint tokens, and transfer tokens with Token Extensions
177177

178-
Create token mints, mint tokens, and transferr tokens using Token Extensions.
178+
Create token mints, mint tokens, and transfer tokens using Token Extensions.
179179

180180
[anchor](./tokens/token-2022/basics/anchor)
181181

@@ -221,13 +221,13 @@ Create tokens that store their onchain metadata inside the token mint, without n
221221

222222
[anchor](./tokens/token-2022/metadata/anchor)
223223

224-
### Allow a designedated account to close a mint
224+
### Allow a designated account to close a mint
225225

226226
Allow a designated account to close a Mint.
227227

228228
[anchor](./tokens/token-2022/mint-close-authority/anchor) [native](./tokens/token-2022/mint-close-authority/native)
229229

230-
### Usng multiple token extensions
230+
### Using multiple token extensions
231231

232232
Use multiple Token Extensions at once.
233233

basics/account-data/anchor/Anchor.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[toolchain]
2+
solana_version = "3.1.8"
3+
14
[features]
25
seeds = false
36
skip-lint = false

basics/account-data/native/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
},
99
"dependencies": {
1010
"@solana/web3.js": "^1.47.3",
11-
"fs": "^0.0.1-security"
11+
"fs": "^0.0.1-security",
12+
"borsh": "^2.0.0"
1213
},
1314
"devDependencies": {
1415
"@types/bn.js": "^5.1.0",

basics/account-data/native/pnpm-lock.yaml

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

basics/account-data/native/tests/test.ts

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,25 @@ import {
1010
import * as borsh from "borsh";
1111
import { start } from "solana-bankrun";
1212

13-
class Assignable {
14-
constructor(properties) {
15-
for (const [key, value] of Object.entries(properties)) {
16-
this[key] = value;
17-
}
18-
}
19-
}
13+
const AddressInfoSchema = {
14+
struct: {
15+
name: "string",
16+
house_number: "u8",
17+
street: "string",
18+
city: "string",
19+
},
20+
};
2021

21-
class AddressInfo extends Assignable {
22-
street: string;
23-
city: string;
22+
type AddressInfo = {
2423
name: string;
2524
house_number: number;
26-
toBuffer() {
27-
return Buffer.from(borsh.serialize(AddressInfoSchema, this));
28-
}
25+
street: string;
26+
city: string;
27+
};
2928

30-
static fromBuffer(buffer: Buffer) {
31-
return borsh.deserialize(AddressInfoSchema, AddressInfo, buffer);
32-
}
29+
function borshSerialize(schema: borsh.Schema, data: object): Buffer {
30+
return Buffer.from(borsh.serialize(schema, data));
3331
}
34-
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-
],
47-
]);
4832

4933
describe("Account Data!", async () => {
5034
const addressInfoAccount = Keypair.generate();
@@ -73,12 +57,12 @@ describe("Account Data!", async () => {
7357
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
7458
],
7559
programId: PROGRAM_ID,
76-
data: new AddressInfo({
60+
data: borshSerialize(AddressInfoSchema, {
7761
name: "Joe C",
7862
house_number: 136,
7963
street: "Mile High Dr.",
8064
city: "Solana Beach",
81-
}).toBuffer(),
65+
}),
8266
});
8367

8468
const blockhash = context.lastBlockhash;
@@ -92,13 +76,13 @@ describe("Account Data!", async () => {
9276
test("Read the new account's data", async () => {
9377
const accountInfo = await client.getAccount(addressInfoAccount.publicKey);
9478

95-
const readAddressInfo = AddressInfo.fromBuffer(
79+
const readAddressInfo = borsh.deserialize(
80+
AddressInfoSchema,
9681
Buffer.from(accountInfo.data),
97-
);
82+
) as AddressInfo;
9883
console.log(`Name : ${readAddressInfo.name}`);
9984
console.log(`House Num: ${readAddressInfo.house_number}`);
10085
console.log(`Street : ${readAddressInfo.street}`);
10186
console.log(`City : ${readAddressInfo.city}`);
10287
});
10388
});
104-

basics/checking-accounts/anchor/Anchor.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[toolchain]
2+
solana_version = "3.1.8"
3+
14
[features]
25
seeds = false
36
[programs.localnet]

basics/close-account/anchor/Anchor.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[toolchain]
2+
solana_version = "3.1.8"
3+
14
[features]
25
seeds = false
36
skip-lint = false

basics/close-account/native/pnpm-lock.yaml

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

basics/counter/anchor/Anchor.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[toolchain]
2+
solana_version = "3.1.8"
3+
14
[features]
25
seeds = false
36
skip-lint = false

0 commit comments

Comments
 (0)