|
1 | 1 | # Contribution Guidelines |
2 | 2 |
|
3 | | -Thank you for considering contributing to the Solana Program Examples repository. We greatly appreciate your interest and efforts in helping us improve and expand this valuable resource for the Solana developer community. |
4 | | - |
5 | | -We believe that a welcoming and inclusive environment fosters collaboration and encourages participation from developers of all backgrounds and skill levels. |
6 | | - |
7 | | -To ensure a smooth and effective contribution process, please take a moment to review and follow the guidelines outlined below. |
| 3 | +Thank you for considering a contribution to this repository. We welcome new examples, fixes, and improvements from the community. |
8 | 4 |
|
9 | 5 | ## How to Contribute |
10 | 6 |
|
11 | | -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: |
12 | | - |
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. |
| 7 | +- **Code:** Add new examples or improve existing ones (bug fixes, optimizations, additional features). |
| 8 | +- **Bug reports, ideas, feedback:** Open an issue describing what you found or what you'd like to see. |
14 | 9 |
|
15 | | -- **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. |
| 10 | +## Project structure |
16 | 11 |
|
17 | | -## General coding and writing guidelines |
| 12 | +- Each example lives at `category/example-name/<framework>/`, e.g. `basics/counter/anchor/`. |
| 13 | +- Supported frameworks: `anchor`, `quasar`, `pinocchio`, `native`. Use the existing layout as a reference. |
| 14 | +- Tests live alongside the program in a `tests/` directory. |
18 | 15 |
|
19 | | -Please follow the [Contributing and Style Guide from the Developer Content Repo](https://github.com/solana-foundation/developer-content/blob/main/CONTRIBUTING.md). |
| 16 | +## Tooling |
20 | 17 |
|
21 | | -Specifically for code in this repo: |
| 18 | +- **Package manager:** `pnpm`. Commit `pnpm-lock.yaml`. Do not use yarn or npm here. |
| 19 | +- **Formatter / linter:** [Biome](https://biomejs.dev/). Run `pnpm fix` from the repo root before submitting a PR. |
22 | 20 |
|
23 | | -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. |
| 21 | +## Testing |
24 | 22 |
|
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. |
26 | | - - Project path structure: `/program-examples/category/example-name/<framework_name>` |
27 | | - - Project path structure example for anchor: `/program-examples/category/example-name/anchor` |
| 23 | +This repo uses an in-process test runtime — no local validator boot, no `solana-test-validator`, no `anchor test --validator legacy`. |
28 | 24 |
|
29 | | -3. Tests for Anchor and Solana native programs should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun). |
| 25 | +For Anchor and Quasar examples, tests are written in TypeScript and run with `node:test` via `tsx`: |
30 | 26 |
|
31 | | -4. For Solana native programs ensure adding these mandatory pnpm run scripts to your `package.json` file for successful CI/CD builds: |
32 | | - |
33 | | -```json |
34 | | -"scripts": { |
35 | | - "test": "pnpm ts-mocha -p ./tests/tsconfig.test.json -t 1000000 ./tests/realloc.test.ts", |
36 | | - "build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test", |
37 | | - "build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so", |
38 | | - "deploy": "solana program deploy ./program/target/so/program.so" |
39 | | -}, |
| 27 | +```bash |
| 28 | +npx tsx --test --test-reporter=spec tests/*.ts |
40 | 29 | ``` |
41 | 30 |
|
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) |
| 31 | +The conventional `Anchor.toml` `[scripts]` entry is: |
43 | 32 |
|
44 | | -``` |
| 33 | +```toml |
45 | 34 | [scripts] |
46 | | -test = "pnpm ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" |
| 35 | +test = "npx create-codama-clients; npx tsx --test --test-reporter=spec tests/*.ts" |
47 | 36 | ``` |
48 | 37 |
|
49 | | -6. TypeScript, JavaScript and JSON files are formatted and linted using |
50 | | - [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: |
| 38 | +The TypeScript tests use: |
51 | 39 |
|
52 | | -```bash |
53 | | -pnpm fix |
54 | | -``` |
| 40 | +- [`solana-kite`](https://solanakite.org) for the connection, wallet creation, token mint helpers, PDA derivation, and `sendTransactionFromInstructions`. |
| 41 | +- [`@solana/kit`](https://solanakit.com) for the core types (`KeyPairSigner`, `Address`, `lamports`). |
| 42 | +- A [Codama](https://github.com/codama-idl/codama)-generated client (via `npx create-codama-clients`) for invoking the program instructions. Do **not** use `anchor.workspace` or `program.methods.X().rpc()`. |
| 43 | + |
| 44 | +Native and Pinocchio examples may use `litesvm` directly from Rust where appropriate. |
| 45 | + |
| 46 | +## Style |
| 47 | + |
| 48 | +Write American English in prose (e.g. "behavior", "initialize", "favor"). Code identifiers stay as-is. |
| 49 | + |
| 50 | +Other conventions: |
55 | 51 |
|
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 |
58 | | -and there's a change in that example's directory. |
| 52 | +- One H1 per markdown file. |
| 53 | +- Fenced code blocks include a language tag (` ```rust `, ` ```typescript `, ` ```bash `, ` ```toml `). |
| 54 | +- Use full words rather than abbreviations (`transaction`, not `tx` or `txn`; `account`, not `acc`). |
| 55 | +- Prefer `async`/`await` over `.then()`/`.catch()`. |
| 56 | +- Use `Array<T>` rather than `T[]` in TypeScript. |
| 57 | +- Avoid magic numbers — name or explain them. |
| 58 | +- Write "onchain" / "offchain" as single words (no hyphen). |
59 | 59 |
|
60 | | -## Code of Conduct |
| 60 | +## Excluding an example from CI |
61 | 61 |
|
62 | | -We are committed to providing a friendly, safe, and welcoming environment for all contributors, regardless of their background, experience level, or personal characteristics. As a contributor, you are expected to: |
| 62 | +Add the project path to `.ghaignore` to skip it during CI builds. If you remove or replace an example, update `.ghaignore` accordingly. |
63 | 63 |
|
64 | | -Be respectful and inclusive in your interactions with others. |
65 | | -Refrain from engaging in any form of harassment, discrimination, or offensive behavior. Be open to constructive feedback and be willing to learn from others. |
66 | | -Help create a positive and supportive community where everyone feels valued and respected. |
| 64 | +## Code of conduct |
67 | 65 |
|
68 | | -If you encounter any behavior that violates our code of conduct, please report it to the project maintainers immediately. |
| 66 | +Be respectful and inclusive. Constructive feedback only. Report any conduct issues to the maintainers. |
0 commit comments