Skip to content
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

Add minimal viable Anchor #602

Merged
merged 29 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 25 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
112 changes: 76 additions & 36 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,111 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [16]
node:
- 20
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Use Node ${{ matrix.node }}
- name: "Use Node ${{ matrix.node }}"
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: "yarn"
node-version: "${{ matrix.node }}"
cache: yarn
- name: Setup Anchor & Build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: is github CI smart enough to only run certain tasks if certain files are changed? For example, we should only run anchor tasks if solana files are touched right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not easily. right now it will do all parts of the work flow on each run. we can improve this later. it's not too slow by comparison to how it was before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional runs are pretty hard, but I think there are easier ways to make it less imapctful.

Two things on this if it becomes a pain point:

  • We can use a docker image with rust tools and/or solana tools preinstalled.
  • We can run this setup in parallel while we're doing EVM build, tests, etc, which I suspect will take longer.

uses: metadaoproject/setup-anchor@v2
with:
anchor-version: 0.30.1
solana-cli-version: 1.18.21
node-version: 20.17.0
- name: Create keypair
run: solana-keygen new --no-bip39-passphrase
shell: bash
- name: Make Anchor.toml compatible with runner
run: "sed -i 's:/user/:/runner/:' Anchor.toml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the string user in the Anchor.toml?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might actually be able to delete this. it was trying to get anchor to detect the solana-keygen new command from above. the util can in some environments place the key in a location anchor cant find it, hence this command. but it looks like we don't need that after all and the tests run without it.

shell: bash
- name: Install Cargo toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustc
- name: Install packages
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint
- name: Lint js
shell: bash
run: yarn lint-js
- name: Lint solidity
shell: bash
run: yarn lint-solidity
- name: Lint rust
shell: bash
run: yarn lint-rust
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
node: [16]
node:
- 20
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Use Node ${{ matrix.node }}
- name: "Use Node ${{ matrix.node }}"
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: "yarn"
node-version: "${{ matrix.node }}"
cache: yarn
- name: Setup Anchor & Build
uses: metadaoproject/setup-anchor@v2
with:
anchor-version: 0.30.1
solana-cli-version: 1.18.21
node-version: 20.17.0
- name: Create keypair
run: solana-keygen new --no-bip39-passphrase
shell: bash
- name: Make Anchor.toml compatible with runner
run: "sed -i 's:/user/:/runner/:' Anchor.toml"
shell: bash
- name: Install Cargo toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustc
- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@v2
- name: Install packages
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Test
run: yarn test
- name: Test evm-hardhat
shell: bash
run: yarn test-evm
- name: Test svm
shell: bash
run: yarn test-svm
forge:
name: Forge
runs-on: ubuntu-latest
strategy:
matrix:
node: [16]
node:
- 20
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Use Node ${{ matrix.node }}
- name: "Use Node ${{ matrix.node }}"
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: "yarn"
node-version: "${{ matrix.node }}"
cache: yarn
- name: Setup Anchor & Build
uses: metadaoproject/setup-anchor@v2
with:
anchor-version: 0.30.1
solana-cli-version: 1.18.21
node-version: 20.17.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this break if the node version varies (i.e. 20 resolves to 20.17.1)?

Can we just specify 20 here or does it have to be specific?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will work just fine? the version specified above in the config has 20 set, with no sub versions. I'll try changing this here and see if the workflow still runs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test worked just fine with the node version simply being "20"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect

- name: Install packages
run: yarn install --frozen-lockfile
- name: Install Foundry
Expand All @@ -61,23 +119,5 @@ jobs:
run: forge install
- name: Inspect storage layouts
run: ./scripts/checkStorageLayout.sh
- name: Run forge test
run: forge test --match-path test/foundry/local/**/*.t.sol
solhint:
name: Solhint
runs-on: ubuntu-latest
strategy:
matrix:
node: [16]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: "yarn"
- name: Install packages
run: yarn install --frozen-lockfile
- name: Solhint
run: yarn lint-contracts
- name: Test evm-foundry
run: forge test --match-path test/evm/foundry/local/**/*.t.sol
7 changes: 7 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ jobs:
uses: manovotny/[email protected]

# Setup .npmrc file to publish to npm
- name: Setup Anchor & Build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move the comment above down to above npm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, sorry. I messed that up. have fixed it.

- uses: metadaoproject/setup-anchor@v2
with:
anchor-version: "0.30.1"
solana-cli-version: "1.18.21"
node-version: "20.17.0"
- run: anchor build
- uses: actions/setup-node@v3
with:
node-version: "16.x"
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ storage-layouts/proposed*

# IDE
.idea


.anchor
chrismaree marked this conversation as resolved.
Show resolved Hide resolved
.DS_Store
target
**/*.rs.bk
test-ledger
.yarn
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist
artifacts-zk
cache-zk
lib
target
18 changes: 18 additions & 0 deletions 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]
testacross = "E4dpZS9P24pscXvPngpeUhrR98uZYMfi3VMLnLaYDA6b"

[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 test/svm/**/*.ts"
Loading
Loading