-
Notifications
You must be signed in to change notification settings - Fork 515
add asm transfer example #527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4f225b7
add asm transfer example
Perelyn-sama 478d34b
Merge branch 'main' into asm/transfer
Perelyn-sama 6faae0a
add asm workflow
Perelyn-sama 4b6a623
Merge branch 'asm/transfer' of https://github.com/solana-developers/p…
Perelyn-sama d81d313
Update solana-asm.yml
Perelyn-sama a9121d4
add Rust unit tests
Perelyn-sama c60fe8a
Merge branch 'main' into asm/transfer
Perelyn-sama 8c65bb9
add ts tests
Perelyn-sama a19c16a
remove unused const
Perelyn-sama 08405ae
clean up
Perelyn-sama 1f563dd
biome fixes
Perelyn-sama d8f4917
update heyAyushh/setup-solana version in ci
Perelyn-sama 1a63781
add continue-on-error
Perelyn-sama 2c2b004
add assert
Perelyn-sama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,267 @@ | ||
| name: ASM | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 0 * * *" | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| branches: | ||
| - main | ||
|
|
||
| env: | ||
| MAX_JOBS: 64 | ||
| MIN_PROJECTS_PER_JOB: 4 | ||
| MIN_PROJECTS_FOR_MATRIX: 4 | ||
|
|
||
| jobs: | ||
| changes: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pull-requests: read | ||
| outputs: | ||
| changed_projects: ${{ steps.analyze.outputs.changed_projects }} | ||
| total_projects: ${{ steps.analyze.outputs.total_projects }} | ||
| matrix: ${{ steps.matrix.outputs.matrix }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: dorny/paths-filter@v3 | ||
| id: changes | ||
| if: github.event_name == 'pull_request' | ||
| with: | ||
| list-files: shell | ||
| filters: | | ||
| asm: | ||
| - added|modified: '**/asm/**' | ||
| workflow: | ||
| - added|modified: '.github/workflows/solana-asm.yml' | ||
| - name: Analyze Changes | ||
| id: analyze | ||
| run: | | ||
| # Generate ignore pattern, excluding comments | ||
| ignore_pattern=$(grep -v '^#' .github/.ghaignore | grep -v '^$' | tr '\n' '|' | sed 's/|$//') | ||
| echo "Ignore pattern: $ignore_pattern" | ||
|
|
||
| function get_projects() { | ||
| find . -type d -name "asm" | grep -vE "$ignore_pattern" | sort | ||
| } | ||
|
|
||
| # Determine which projects to build and test | ||
| if [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then | ||
| projects=$(get_projects) | ||
| elif [[ "${{ steps.changes.outputs.asm }}" == "true" ]]; then | ||
| changed_files=(${{ steps.changes.outputs.asm_files }}) | ||
| projects=$(for file in "${changed_files[@]}"; do dirname "${file}" | grep asm | sed 's#/asm/.*#/asm#g'; done | grep -vE "$ignore_pattern" | sort -u) | ||
| else | ||
| projects="" | ||
| fi | ||
|
|
||
| # Output project information | ||
| if [[ -n "$projects" ]]; then | ||
| echo "Projects to build and test" | ||
| echo "$projects" | ||
| total_projects=$(echo "$projects" | wc -l) | ||
| echo "Total projects: $total_projects" | ||
| echo "total_projects=$total_projects" >> $GITHUB_OUTPUT | ||
| echo "changed_projects=$(echo "$projects" | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "No projects to build and test." | ||
| echo "total_projects=0" >> $GITHUB_OUTPUT | ||
| echo "changed_projects=[]" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Generate matrix | ||
| id: matrix | ||
| run: | | ||
| total_projects=${{ steps.analyze.outputs.total_projects }} | ||
| max_jobs=${{ env.MAX_JOBS }} | ||
| min_projects_per_job=${{ env.MIN_PROJECTS_PER_JOB }} | ||
| min_projects_for_matrix=${{ env.MIN_PROJECTS_FOR_MATRIX }} | ||
|
|
||
| if [ "$total_projects" -lt "$min_projects_for_matrix" ]; then | ||
| echo "matrix=[0]" >> $GITHUB_OUTPUT | ||
| else | ||
| projects_per_job=$(( (total_projects + max_jobs - 1) / max_jobs )) | ||
| projects_per_job=$(( projects_per_job > min_projects_per_job ? projects_per_job : min_projects_per_job )) | ||
| num_jobs=$(( (total_projects + projects_per_job - 1) / projects_per_job )) | ||
|
|
||
| indices=$(seq 0 $(( num_jobs - 1 ))) | ||
| echo "matrix=[$(echo $indices | tr ' ' ',')]" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| build-and-test: | ||
| needs: changes | ||
| if: needs.changes.outputs.total_projects != '0' | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| index: ${{ fromJson(needs.changes.outputs.matrix) }} | ||
| name: build-and-test-group-${{ matrix.index }} | ||
| outputs: | ||
| failed_projects: ${{ steps.set-failed.outputs.failed_projects }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Use Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "lts/*" | ||
| check-latest: true | ||
| - name: Setup build environment | ||
| id: setup | ||
| run: | | ||
| # Create the build and test function | ||
| cat << 'EOF' > build_and_test.sh | ||
| function build_and_test() { | ||
| local project=$1 | ||
| local solana_version=$2 | ||
| echo "Building and Testing $project with Solana $solana_version" | ||
| cd "$project" || return 1 | ||
|
|
||
| # Install dependencies | ||
| if ! pnpm install --frozen-lockfile; then | ||
| echo "::error::pnpm install failed for $project" | ||
| echo "$project: pnpm install failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt | ||
| cd - > /dev/null | ||
| return 1 | ||
| fi | ||
|
|
||
| # Build and Test | ||
| if ! pnpm build-and-test; then | ||
| echo "::error::build-and-test failed for $project" | ||
| echo "$project: build-and-test failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt | ||
| cd - > /dev/null | ||
| return 1 | ||
| fi | ||
|
|
||
| # Run Rust unit tests | ||
| if [ -d "program" ]; then | ||
| echo "Running Rust unit tests for $project" | ||
| if ! cargo test --manifest-path=./program/Cargo.toml; then | ||
| echo "::error::Rust unit tests failed for $project" | ||
| echo "$project: Rust unit tests failed with $solana_version" >> $GITHUB_WORKSPACE/failed_projects.txt | ||
| cd - > /dev/null | ||
| return 1 | ||
| fi | ||
| fi | ||
|
|
||
| echo "Build and tests succeeded for $project with $solana_version version." | ||
| cd - > /dev/null | ||
| return 0 | ||
| } | ||
|
|
||
| function process_projects() { | ||
| local solana_version=$1 | ||
|
|
||
| readarray -t all_projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]?') | ||
| start_index=$(( ${{ matrix.index }} * ${{ env.MIN_PROJECTS_PER_JOB }} )) | ||
| end_index=$(( start_index + ${{ env.MIN_PROJECTS_PER_JOB }} )) | ||
| end_index=$(( end_index > ${{ needs.changes.outputs.total_projects }} ? ${{ needs.changes.outputs.total_projects }} : end_index )) | ||
|
|
||
| echo "Projects to build and test in this job" | ||
| for i in $(seq $start_index $(( end_index - 1 ))); do | ||
| echo "${all_projects[$i]}" | ||
| done | ||
|
|
||
| failed=false | ||
| for i in $(seq $start_index $(( end_index - 1 ))); do | ||
| echo "::group::Building and testing ${all_projects[$i]}" | ||
| if ! build_and_test "${all_projects[$i]}" "$solana_version"; then | ||
| failed=true | ||
| fi | ||
| echo "::endgroup::" | ||
| done | ||
|
|
||
| return $([ "$failed" = true ] && echo 1 || echo 0) | ||
| } | ||
| EOF | ||
|
|
||
| # Make the script executable | ||
| chmod +x build_and_test.sh | ||
|
|
||
| # Install pnpm | ||
| npm install --global pnpm | ||
|
|
||
| # Install sbpf assembler | ||
| cargo install --git https://github.com/blueshift-gg/sbpf.git | ||
| - name: Setup Solana Stable | ||
| uses: heyAyushh/setup-solana@v5.9 | ||
| with: | ||
| solana-cli-version: stable | ||
| - name: Build and Test with Stable | ||
| run: | | ||
| source build_and_test.sh | ||
| solana -V | ||
| rustc -V | ||
| process_projects "stable" | ||
| # continue-on-error because the beta channel may not have a valid release | ||
| # (e.g. v4.0 returns 404 from release.anza.xyz). This is an upstream issue | ||
| # with heyAyushh/setup-solana — beta setup clears the stable install first. | ||
| - name: Setup Solana Beta | ||
| continue-on-error: true | ||
| uses: heyAyushh/setup-solana@v5.9 | ||
| with: | ||
| solana-cli-version: beta | ||
| - name: Build and Test with Beta | ||
| continue-on-error: true | ||
| run: | | ||
| source build_and_test.sh | ||
| solana -V | ||
| rustc -V | ||
| process_projects "beta" | ||
|
|
||
| - name: Set failed projects output | ||
| id: set-failed | ||
| if: failure() | ||
| run: | | ||
| if [ -f "$GITHUB_WORKSPACE/failed_projects.txt" ]; then | ||
| failed_projects=$(cat $GITHUB_WORKSPACE/failed_projects.txt | jq -R -s -c 'split("\n")[:-1]') | ||
| echo "failed_projects=$failed_projects" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "failed_projects=[]" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| summary: | ||
| needs: [changes, build-and-test] | ||
| if: always() | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Create job summary | ||
| run: | | ||
| echo "## ASM Workflow Summary" >> $GITHUB_STEP_SUMMARY | ||
| echo "- Total projects: ${{ needs.changes.outputs.total_projects }}" >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| # List all processed projects | ||
| echo "<details>" >> $GITHUB_STEP_SUMMARY | ||
| echo "<summary>Projects processed (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]' | while read project; do | ||
| echo "- $project" >> $GITHUB_STEP_SUMMARY | ||
| done | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "</details>" >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| # Report build and test results | ||
| if [[ "${{ needs.build-and-test.result }}" == "failure" ]]; then | ||
| echo "## :x: Build or tests failed" >> $GITHUB_STEP_SUMMARY | ||
| echo "<details>" >> $GITHUB_STEP_SUMMARY | ||
| echo "<summary>Failed projects (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| failed_projects='${{ needs.build-and-test.outputs.failed_projects }}' | ||
| if [[ -n "$failed_projects" ]]; then | ||
| echo "$failed_projects" | jq -r '.[]' | while IFS=: read -r project failure_reason; do | ||
| echo "- **$project**" >> $GITHUB_STEP_SUMMARY | ||
| echo " - Failure reason: $failure_reason" >> $GITHUB_STEP_SUMMARY | ||
| done | ||
| else | ||
| echo "No failed projects reported. This might indicate an unexpected error in the workflow." >> $GITHUB_STEP_SUMMARY | ||
| fi | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "</details>" >> $GITHUB_STEP_SUMMARY | ||
| elif [[ "${{ needs.build-and-test.result }}" == "success" ]]; then | ||
| echo "## :white_check_mark: All builds and tests passed" >> $GITHUB_STEP_SUMMARY | ||
| else | ||
| echo "## :warning: Build and test job was skipped or canceled" >> $GITHUB_STEP_SUMMARY | ||
| fi |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| build/**/* | ||
| deploy/**/* | ||
| node_modules | ||
| .sbpf | ||
| .DS_Store | ||
| .vscode | ||
| keypair.json | ||
| package-lock.json | ||
| test-ledger | ||
| yarn.lock | ||
| target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| [package] | ||
| name = "asm" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] | ||
|
|
||
| [dev-dependencies] | ||
| litesvm.workspace = true | ||
| solana-instruction.workspace = true | ||
| solana-address.workspace = true | ||
| solana-keypair.workspace = true | ||
| solana-native-token.workspace = true | ||
| solana-pubkey.workspace = true | ||
| solana-transaction.workspace = true | ||
| solana-system-interface.workspace = true | ||
|
|
||
| [features] | ||
| test-sbf = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # asm | ||
|
|
||
| Created with [sbpf](https://github.com/blueshift-gg/sbpf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This script is for quick building & deploying of the program. | ||
| # It also serves as a reference for the commands used for building & deploying Solana programs. | ||
| # Run this bad boy with "bash cicd.sh" or "./cicd.sh" | ||
|
|
||
| sbpf build --deploy-dir ./tests/fixtures/ | ||
| solana program deploy ./tests/fixtures/transfer-sol-cpi.so | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "type": "module", | ||
| "scripts": { | ||
| "test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/test.ts", | ||
| "build-and-test": "sbpf build --deploy-dir ./tests/fixtures && pnpm test", | ||
| "build": "sbpf build", | ||
| "deploy": "solana program deploy ./program/target/so/program.so" | ||
| }, | ||
| "dependencies": { | ||
| "@solana/web3.js": "^1.47.3", | ||
| "buffer-layout": "^1.2.2", | ||
| "fs": "^0.0.1-security" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/bn.js": "^5.1.0", | ||
| "@types/chai": "^4.3.1", | ||
| "@types/mocha": "^9.1.1", | ||
| "chai": "^4.3.4", | ||
| "mocha": "^9.0.3", | ||
| "solana-bankrun": "^0.3.0", | ||
| "ts-mocha": "^10.0.0", | ||
| "typescript": "^4.3.5" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.