Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .github/workflows/rust-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:

jobs:
test-rust:
name: ${{ matrix.example }}
name: ${{ matrix.package && format('{0}/{1}', matrix.example, matrix.package) || matrix.example }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -30,6 +30,17 @@ jobs:
- counter/pinocchio
- account-comparison
- zk-id
include:
- example: basic-operations/native
package: native-program-burn
- example: basic-operations/native
package: native-program-create
- example: basic-operations/native
package: native-program-update
- example: basic-operations/native
package: native-program-close
- example: basic-operations/native
package: native-program-reinit
steps:
- uses: actions/checkout@v4

Expand All @@ -48,4 +59,9 @@ jobs:

- name: Build and test
working-directory: ${{ matrix.example }}
run: cargo test-sbf
run: |
if [ -n "${{ matrix.package }}" ]; then
cargo test-sbf -p ${{ matrix.package }}
else
cargo test-sbf
fi
10 changes: 8 additions & 2 deletions .github/workflows/typescript-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
matrix:
example:
- counter/anchor
- basic-operations/anchor/burn
- basic-operations/anchor/create
- basic-operations/anchor/update
- basic-operations/anchor/close
- basic-operations/anchor/reinit
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -54,8 +59,9 @@ jobs:
- name: Start test validator
working-directory: ${{ matrix.example }}
run: |
PROGRAM_ID=$(grep -A 1 "\[programs.localnet\]" Anchor.toml | grep "counter" | sed 's/.*"\(.*\)".*/\1/')
light test-validator --sbf-program "$PROGRAM_ID" ./target/deploy/counter.so &
PROGRAM_NAME=$(grep -A 10 '\[programs.localnet\]' Anchor.toml | grep '=' | head -1 | cut -d' ' -f1)
PROGRAM_ID=$(grep -A 10 '\[programs.localnet\]' Anchor.toml | grep '=' | head -1 | sed 's/.*"\(.*\)".*/\1/')
light test-validator --sbf-program "$PROGRAM_ID" ./target/deploy/${PROGRAM_NAME}.so &
sleep 10

- name: Run TypeScript tests
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Required versions:
- **Rust**: 1.90.0 or later
- **Solana CLI**: 2.3.11
- **Anchor CLI**: 0.31.1
- **Zk compression CLI**: 0.27.0 or later
- **Zk compression CLI**: 0.27.1-alpha.2 or later
- **Node.js**: 23.5.0 or later

Install the Light CLI:
Expand Down
7 changes: 7 additions & 0 deletions basic-operations/anchor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.anchor
.DS_Store
target
**/*.rs.bk
node_modules
test-ledger
.yarn
82 changes: 82 additions & 0 deletions basic-operations/anchor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Basic Operations - Anchor Programs

Standalone Anchor programs for compressed accounts.

## Structure

Each operation is an independent Anchor project:

- **create** - Initialize a new compressed account
- **update** - Modify data in an existing compressed account
- **close** - Clear account data while preserving address
- **reinit** - Reinitialize a closed account
- **burn** - Permanently delete a compressed account

Each project contains its own workspace, program, and tests.

## Build

Navigate to a specific project directory and build:

```bash
cd create/ # or update/, close/, reinit/, burn/
anchor build
```

## Test

### Requirements

- light cli version 0.27.1-alpha.2+ (install via `npm install -g @lightprotocol/[email protected]`)
- solana cli version 2.1.16+
- anchor version 0.31.1+
- Node.js and npm

### Running Tests

#### Rust Tests

```bash
cd create/ # or update/, close/, reinit/, burn/
cargo test-sbf
```

#### TypeScript Tests

1. Build the program and sync the program ID:

```bash
cd create/ # or update/, close/, reinit/, burn/
anchor build && anchor keys sync && anchor build
```

2. Start the test validator with the program deployed:

```bash
light test-validator --sbf-program "<PROGRAM_ID>" ./target/deploy/<program_name>.so
```

NOTE: Replace `<PROGRAM_ID>` with the ID from `Anchor.toml` and `<program_name>` with `create`, `update`, `close`, `reinit`, or `burn`.

3. Install dependencies and run tests:

```bash
npm install
anchor test --skip-local-validator --skip-build --skip-deploy
```

The TypeScript tests demonstrate client-side interaction with compressed accounts using `@lightprotocol/stateless.js`.

`light test-validator` spawns the following background processes:

1. solana test validator `http://127.0.0.1:8899`
2. prover server `http://127.0.0.1:3001`
3. photon indexer `http://127.0.0.1:8784`

You can kill these background processes with `lsof -i:<port>` and `kill <pid>`.

## Disclaimer

This reference implementation is not audited.

The Light Protocol programs are audited and deployed on Solana devnet and mainnet.
7 changes: 7 additions & 0 deletions basic-operations/anchor/burn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.anchor
.DS_Store
target
**/*.rs.bk
node_modules
test-ledger
.yarn
18 changes: 18 additions & 0 deletions basic-operations/anchor/burn/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[toolchain]

[features]
resolution = true
skip-lint = false

[programs.localnet]
burn = "BJhPWQnD31mdo6739Mac1gLuSsbbwTmpgjHsW6shf6WA"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
Loading