reusable-tests.yaml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. name: Reusable Tests
  2. on:
  3. workflow_call:
  4. inputs:
  5. cache:
  6. required: true
  7. type: boolean
  8. solana_cli_version:
  9. required: true
  10. type: string
  11. node_version:
  12. required: true
  13. type: string
  14. cargo_profile:
  15. required: true
  16. type: string
  17. anchor_binary_name:
  18. required: true
  19. type: string
  20. env:
  21. CACHE: ${{ inputs.cache }}
  22. SOLANA_CLI_VERSION: ${{ inputs.solana_cli_version }}
  23. NODE_VERSION: ${{ inputs.node_version }}
  24. CARGO_PROFILE: ${{ inputs.cargo_profile }}
  25. ANCHOR_BINARY_NAME: ${{ inputs.anchor_binary_name }}
  26. CARGO_CACHE_PATH: |
  27. ~/.cargo/bin/
  28. ~/.cargo/registry/index/
  29. ~/.cargo/registry/cache/
  30. ~/.cargo/git/db/
  31. ./target/
  32. jobs:
  33. test-core:
  34. name: Core Tests
  35. runs-on: ubuntu-latest
  36. timeout-minutes: 30
  37. steps:
  38. - uses: actions/checkout@v3
  39. - uses: ./.github/actions/setup/
  40. - uses: actions/setup-node@v3
  41. with:
  42. node-version: ${{ env.NODE_VERSION }}
  43. - uses: actions/cache@v3
  44. if: ${{ env.CACHE != 'false' }}
  45. name: Cache Cargo registry + index
  46. id: cache-cargo-build
  47. with:
  48. path: ${{ env.CARGO_CACHE_PATH }}
  49. key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
  50. - run: cargo build
  51. - run: cargo fmt -- --check
  52. - run: cargo clippy --all-targets -- -D warnings
  53. - run: cargo test --workspace --exclude avm
  54. # using singlethreaded testing for avm so that tests that change files do not conflict with each other
  55. - run: cargo test --package avm -- --test-threads=1
  56. # Init local borsh package
  57. - run: cd ts/packages/borsh && yarn --frozen-lockfile && yarn build
  58. - run: cd ts/packages/anchor-errors && yarn --frozen-lockfile && yarn build
  59. - run: cd ts/packages/anchor && yarn --frozen-lockfile
  60. - run: cd ts/packages/anchor && yarn test
  61. - run: cd ts/packages/anchor && yarn lint
  62. - run: cd examples/tutorial && yarn --frozen-lockfile
  63. - run: cd examples/tutorial && yarn lint
  64. - run: cd tests && yarn --frozen-lockfile
  65. - run: cd tests && yarn lint
  66. - uses: ./.github/actions/git-diff/
  67. setup-anchor-cli:
  68. name: Setup Anchor cli
  69. runs-on: ubuntu-latest
  70. timeout-minutes: 30
  71. steps:
  72. - uses: actions/checkout@v3
  73. - uses: ./.github/actions/setup/
  74. - uses: actions/cache@v3
  75. if: ${{ env.CACHE != 'false' }}
  76. name: Cache Cargo registry + index
  77. id: cache-anchor
  78. with:
  79. path: ${{ env.CARGO_CACHE_PATH }}
  80. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  81. - run: cargo install --path cli anchor-cli --locked --force --debug
  82. if: env.CARGO_PROFILE == 'debug'
  83. - run: cargo install --path cli anchor-cli --locked --force
  84. if: env.CARGO_PROFILE != 'debug'
  85. - run: chmod +x ~/.cargo/bin/anchor
  86. - uses: actions/upload-artifact@v4
  87. with:
  88. name: ${{ env.ANCHOR_BINARY_NAME }}
  89. path: ~/.cargo/bin/anchor
  90. - uses: ./.github/actions/git-diff/
  91. test-examples:
  92. needs: setup-anchor-cli
  93. name: Examples Test
  94. runs-on: ubuntu-latest
  95. timeout-minutes: 30
  96. steps:
  97. - uses: actions/checkout@v3
  98. - uses: actions/download-artifact@v4
  99. with:
  100. name: ${{ env.ANCHOR_BINARY_NAME }}
  101. path: ~/.cargo/bin/
  102. - run: chmod +rwx ~/.cargo/bin/anchor
  103. - uses: ./.github/actions/setup/
  104. - uses: ./.github/actions/setup-solana/
  105. - uses: ./.github/actions/setup-ts/
  106. - uses: actions/cache@v3
  107. if: ${{ env.CACHE != 'false' }}
  108. name: basic-0 cache
  109. id: cache-basic-0
  110. with:
  111. path: ./examples/tutorial/basic-0/target
  112. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-0/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  113. - uses: actions/cache@v3
  114. if: ${{ env.CACHE != 'false' }}
  115. name: basic-1 cache
  116. id: cache-basic-1
  117. with:
  118. path: ./examples/tutorial/basic-1/target
  119. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-1/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  120. - uses: actions/cache@v3
  121. if: ${{ env.CACHE != 'false' }}
  122. name: basic-2 cache
  123. id: cache-basic-2
  124. with:
  125. path: ./examples/tutorial/basic-2/target
  126. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-2/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  127. - uses: actions/cache@v3
  128. if: ${{ env.CACHE != 'false' }}
  129. name: basic-3 cache
  130. id: cache-basic-3
  131. with:
  132. path: ./examples/tutorial/basic-3/target
  133. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-3/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  134. - uses: actions/cache@v3
  135. if: ${{ env.CACHE != 'false' }}
  136. name: basic-4 cache
  137. id: cache-basic-4
  138. with:
  139. path: ./examples/tutorial/basic-4/target
  140. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-4/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  141. - run: cd examples/tutorial && yarn workspaces run test
  142. - uses: ./.github/actions/git-diff/
  143. setup-client-example:
  144. needs: setup-anchor-cli
  145. name: Setup Client Example Test
  146. runs-on: ubuntu-latest
  147. timeout-minutes: 30
  148. strategy:
  149. fail-fast: false
  150. matrix:
  151. node:
  152. - path: tests/optional/
  153. name: optional.so
  154. - path: tests/events/
  155. name: events.so
  156. - path: examples/tutorial/basic-4/
  157. name: basic_4.so
  158. - path: examples/tutorial/basic-2/
  159. name: basic_2.so
  160. - path: tests/composite/
  161. name: composite.so
  162. steps:
  163. - uses: actions/checkout@v3
  164. - uses: ./.github/actions/setup/
  165. - uses: ./.github/actions/setup-solana/
  166. - uses: actions/download-artifact@v4
  167. with:
  168. name: ${{ env.ANCHOR_BINARY_NAME }}
  169. path: ~/.cargo/bin/
  170. - run: chmod +rwx ~/.cargo/bin/anchor
  171. - run: cd ${{ matrix.node.path }} && anchor build --skip-lint
  172. - uses: actions/upload-artifact@v4
  173. with:
  174. name: ${{ matrix.node.name }}
  175. path: ${{ matrix.node.path }}target/deploy/${{ matrix.node.name }}
  176. - uses: ./.github/actions/git-diff/
  177. test-client-example:
  178. needs: setup-client-example
  179. name: Client Example Test
  180. runs-on: ubuntu-latest
  181. timeout-minutes: 30
  182. steps:
  183. - uses: actions/checkout@v3
  184. - uses: ./.github/actions/setup/
  185. - uses: ./.github/actions/setup-ts/
  186. - uses: actions/download-artifact@v4
  187. with:
  188. name: ${{ env.ANCHOR_BINARY_NAME }}
  189. path: ~/.cargo/bin/
  190. - run: chmod +x ~/.cargo/bin/anchor
  191. - uses: actions/download-artifact@v4
  192. with:
  193. name: optional.so
  194. path: tests/optional/target/deploy/
  195. - uses: actions/download-artifact@v4
  196. with:
  197. name: events.so
  198. path: tests/events/target/deploy/
  199. - uses: actions/download-artifact@v4
  200. with:
  201. name: basic_4.so
  202. path: examples/tutorial/basic-4/target/deploy/
  203. - uses: actions/download-artifact@v4
  204. with:
  205. name: basic_2.so
  206. path: examples/tutorial/basic-2/target/deploy/
  207. - uses: actions/download-artifact@v4
  208. with:
  209. name: composite.so
  210. path: tests/composite/target/deploy/
  211. - uses: actions/cache@v3
  212. if: ${{ env.CACHE != 'false' }}
  213. name: Cache client/example target
  214. id: cache-test-target
  215. with:
  216. path: client/example/target
  217. key: cargo-${{ runner.os }}-client/example-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  218. - uses: ./.github/actions/setup-solana/
  219. - run: cd client/example && ./run-test.sh
  220. - uses: ./.github/actions/git-diff/
  221. test-bpf-upgradeable-state:
  222. needs: setup-anchor-cli
  223. name: Test tests/bpf-upgradeable-state
  224. runs-on: ubuntu-latest
  225. timeout-minutes: 30
  226. steps:
  227. - uses: actions/checkout@v3
  228. - uses: ./.github/actions/setup/
  229. - uses: ./.github/actions/setup-ts/
  230. - uses: ./.github/actions/setup-solana/
  231. - uses: actions/cache@v3
  232. if: ${{ env.CACHE != 'false' }}
  233. name: Cache Cargo registry + index
  234. id: cache-anchor
  235. with:
  236. path: ${{ env.CARGO_CACHE_PATH }}
  237. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  238. - uses: actions/download-artifact@v4
  239. with:
  240. name: ${{ env.ANCHOR_BINARY_NAME }}
  241. path: ~/.cargo/bin/
  242. - run: chmod +x ~/.cargo/bin/anchor
  243. - uses: actions/cache@v3
  244. if: ${{ env.CACHE != 'false' }}
  245. name: Cache tests/bpf-upgradeable-state target
  246. id: cache-test-target
  247. with:
  248. path: tests/bpf-upgradeable-state/target
  249. key: cargo-${{ runner.os }}-tests/bpf-upgradeable-state-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  250. - run: solana-test-validator -r --quiet &
  251. name: start validator
  252. - run: cd tests/bpf-upgradeable-state && yarn --frozen-lockfile
  253. - run: cd tests/bpf-upgradeable-state
  254. - run: cd tests/bpf-upgradeable-state && anchor build --skip-lint
  255. - run: cd tests/bpf-upgradeable-state && solana program deploy --program-id program_with_different_programdata.json target/deploy/bpf_upgradeable_state.so
  256. - run: cd tests/bpf-upgradeable-state && cp bpf_upgradeable_state-keypair.json target/deploy/bpf_upgradeable_state-keypair.json && anchor test --skip-local-validator --skip-build --skip-lint
  257. - run: cd tests/bpf-upgradeable-state && npx tsc --noEmit
  258. - uses: ./.github/actions/git-diff/
  259. # # this test exists to make sure that anchor
  260. # # checks rent correctly for legacy accounts
  261. # # that don't have to be rent-exempt
  262. # test-misc-non-rent-exempt:
  263. # # the anchor cli is built with a different solana version
  264. # # but that's fine since it's just the cli
  265. # needs: setup-anchor-cli
  266. # name: Test tests/misc/nonRentExempt
  267. # runs-on: ubuntu-latest
  268. # timeout-minutes: 30
  269. # steps:
  270. # - uses: actions/checkout@v3
  271. # - uses: ./.github/actions/setup/
  272. # - uses: ./.github/actions/setup-ts/
  273. # - uses: actions/cache@v3
  274. # name: Cache Solana Tool Suite
  275. # id: cache-solana
  276. # with:
  277. # path: |
  278. # ~/.cache/solana/
  279. # ~/.local/share/solana/
  280. # key: solana-${{ runner.os }}-v0000-1.8.14
  281. # # using an outdated validator but that
  282. # # is ok as long as the test doesn't
  283. # # include newer incompatible features
  284. # - run: sh -c "$(curl -sSfL https://release.solana.com/v1.8.14/install)"
  285. # shell: bash
  286. # - run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
  287. # shell: bash
  288. # - run: solana-keygen new --no-bip39-passphrase
  289. # shell: bash
  290. # - run: solana config set --url localhost
  291. # shell: bash
  292. # - uses: actions/download-artifact@v4
  293. # with:
  294. # name: ${{ env.ANCHOR_BINARY_NAME }}
  295. # path: ~/.cargo/bin/
  296. # - run: chmod +x ~/.cargo/bin/anchor
  297. # - uses: actions/cache@v3
  298. # name: Cache tests/misc target
  299. # id: cache-test-target
  300. # with:
  301. # path: tests/misc/target
  302. # key: cargo-${{ runner.os }}-tests/misc-${{ env.ANCHOR_VERSION }}-1.8.14-${{ hashFiles('**/Cargo.lock') }}
  303. # - run: cd tests/misc && yarn --frozen-lockfile
  304. # - run: cd tests/misc
  305. # - run: cd tests/misc && chmod +x ci.sh && ./ci.sh
  306. # - run: cd tests/misc && anchor test --skip-lint
  307. test-anchor-init:
  308. needs: setup-anchor-cli
  309. name: Test Anchor Init
  310. runs-on: ubuntu-latest
  311. timeout-minutes: 30
  312. strategy:
  313. matrix:
  314. template: [mocha, jest, rust, mollusk]
  315. steps:
  316. - uses: actions/checkout@v3
  317. - uses: ./.github/actions/setup/
  318. - uses: ./.github/actions/setup-ts/
  319. - uses: ./.github/actions/setup-solana/
  320. - uses: actions/cache@v3
  321. if: ${{ env.CACHE != 'false' }}
  322. name: Cache Cargo registry + index
  323. id: cache-anchor
  324. with:
  325. path: ${{ env.CARGO_CACHE_PATH }}
  326. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  327. - uses: actions/download-artifact@v4
  328. with:
  329. name: ${{ env.ANCHOR_BINARY_NAME }}
  330. path: ~/.cargo/bin/
  331. - run: chmod +x ~/.cargo/bin/anchor
  332. - run: cd "$(mktemp -d)" && anchor init --test-template ${{ matrix.template }} hello-anchor-${{ matrix.template }} && cd hello-anchor-${{ matrix.template }} && yarn link @coral-xyz/anchor && yarn && anchor test && yarn lint:fix
  333. - uses: ./.github/actions/git-diff/
  334. test-programs:
  335. needs: setup-anchor-cli
  336. name: Test ${{ matrix.node.path }}
  337. runs-on: ubuntu-latest
  338. timeout-minutes: 30
  339. strategy:
  340. fail-fast: false
  341. matrix:
  342. node:
  343. - cmd: cd tests/sysvars && anchor test --skip-lint
  344. path: tests/sysvars
  345. - cmd: cd tests/composite && anchor test --skip-lint
  346. path: tests/composite
  347. - cmd: cd tests/errors && anchor test --skip-lint && npx tsc --noEmit
  348. path: tests/errors
  349. - cmd: cd tests/spl/metadata && anchor test --skip-lint
  350. path: spl/metadata
  351. - cmd: cd tests/spl/token-proxy && anchor test --skip-lint
  352. path: spl/token-proxy
  353. - cmd: cd tests/spl/token-wrapper && anchor test --skip-lint
  354. path: spl/token-wrapper
  355. - cmd: cd tests/spl/transfer-hook && anchor test --skip-lint
  356. path: spl/transfer-hook
  357. - cmd: cd tests/spl/token-extensions && anchor test --skip-lint
  358. path: spl/token-extensions
  359. - cmd: cd tests/multisig && anchor test --skip-lint
  360. path: tests/multisig
  361. # - cmd: cd tests/lockup && anchor test --skip-lint
  362. # path: tests/lockup
  363. # TODO: Re-enable after making it work with Solana v2
  364. # - cmd: cd tests/swap && anchor test --skip-lint
  365. # path: tests/swap
  366. - cmd: cd tests/escrow && anchor test --skip-lint && npx tsc --noEmit
  367. path: tests/escrow
  368. - cmd: cd tests/pyth && anchor test --skip-lint && npx tsc --noEmit
  369. path: tests/pyth
  370. - cmd: cd tests/realloc && anchor test --skip-lint && npx tsc --noEmit
  371. path: tests/realloc
  372. - cmd: cd tests/system-accounts && anchor test --skip-lint
  373. path: tests/system-accounts
  374. - cmd: cd tests/misc && anchor test --skip-lint && npx tsc --noEmit
  375. path: tests/misc
  376. - cmd: cd tests/events && anchor test --skip-lint
  377. path: tests/events
  378. - cmd: cd tests/cashiers-check && anchor test --skip-lint
  379. path: tests/cashiers-check
  380. - cmd: cd tests/declare-id && anchor test --skip-lint && npx tsc --noEmit
  381. path: tests/declare-id
  382. - cmd: cd tests/declare-program && anchor test --skip-lint
  383. path: tests/declare-program
  384. - cmd: cd tests/typescript && anchor test --skip-lint && npx tsc --noEmit
  385. path: tests/typescript
  386. # zero-copy tests cause `/usr/bin/ld: final link failed: No space left on device`
  387. # on GitHub runners. It is likely caused by `cargo test-sbf` since all other tests
  388. # don't have this problem.
  389. # TODO: Find a fix.
  390. # - cmd: cd tests/zero-copy && anchor test --skip-lint && cd programs/zero-copy && cargo test-sbf
  391. # path: tests/zero-copy
  392. - cmd: cd tests/chat && anchor test --skip-lint
  393. path: tests/chat
  394. - cmd: cd tests/ido-pool && anchor test --skip-lint
  395. path: tests/ido-pool
  396. # - cmd: cd tests/cfo && anchor run test-with-build && cd deps/stake && git checkout Cargo.lock && cd ../swap && git checkout Cargo.lock
  397. # path: tests/cfo
  398. - cmd: cd tests/auction-house && anchor test --skip-lint
  399. path: tests/auction-house
  400. - cmd: cd tests/floats && anchor test --skip-lint && npx tsc --noEmit
  401. path: tests/floats
  402. - cmd: cd tests/safety-checks && anchor run test
  403. path: tests/safety-checks
  404. - cmd: cd tests/custom-coder && anchor test --skip-lint && npx tsc --noEmit
  405. path: tests/custom-coder
  406. - cmd: cd tests/custom-discriminator && anchor test
  407. path: tests/custom-discriminator
  408. - cmd: cd tests/validator-clone && anchor test --skip-lint && npx tsc --noEmit
  409. path: tests/validator-clone
  410. - cmd: cd tests/cpi-returns && anchor test --skip-lint && npx tsc --noEmit
  411. path: tests/cpi-returns
  412. - cmd: cd tests/multiple-suites && anchor test --skip-lint && npx tsc --noEmit
  413. path: tests/multiple-suites
  414. - cmd: cd tests/multiple-suites-run-single && anchor test --skip-lint --run tests/should-run && npx tsc --noEmit
  415. path: tests/multiple-suites-run-single
  416. - cmd: cd tests/optional && anchor test --skip-lint && npx tsc --noEmit
  417. path: tests/optional
  418. - cmd: cd tests/pda-derivation && anchor test --skip-lint && npx tsc --noEmit
  419. path: tests/pda-derivation
  420. - cmd: cd tests/relations-derivation && anchor test --skip-lint && npx tsc --noEmit
  421. path: tests/relations-derivation
  422. - cmd: cd tests/anchor-cli-idl && ./test.sh
  423. path: tests/anchor-cli-idl
  424. - cmd: cd tests/anchor-cli-account && anchor test --skip-lint
  425. path: tests/anchor-cli-account
  426. - cmd: cd tests/bench && anchor test --skip-lint
  427. path: tests/bench
  428. - cmd: cd tests/idl && ./test.sh
  429. path: tests/idl
  430. - cmd: cd tests/lazy-account && anchor test
  431. path: tests/lazy-account
  432. # TODO: Enable when `solang` becomes compatible with the new IDL spec
  433. # - cmd: cd tests/solang && anchor test
  434. # path: tests/solang
  435. steps:
  436. - uses: actions/checkout@v3
  437. - uses: ./.github/actions/setup/
  438. - uses: ./.github/actions/setup-ts/
  439. - uses: ./.github/actions/setup-solana/
  440. - uses: actions/cache@v3
  441. if: ${{ env.CACHE != 'false' }}
  442. name: Cache Cargo registry + index
  443. id: cache-anchor
  444. with:
  445. path: ${{ env.CARGO_CACHE_PATH }}
  446. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  447. - uses: actions/download-artifact@v4
  448. with:
  449. name: ${{ env.ANCHOR_BINARY_NAME }}
  450. path: ~/.cargo/bin/
  451. - run: chmod +x ~/.cargo/bin/anchor
  452. - uses: actions/cache@v3
  453. if: ${{ env.CACHE != 'false' }}
  454. name: Cache ${{ matrix.node.path }} target
  455. id: cache-test-target
  456. with:
  457. path: ${{ matrix.node.path }}/target
  458. key: cargo-${{ runner.os }}-${{ matrix.node.path }}-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  459. - run: ${{ matrix.node.cmd }}
  460. name: ${{ matrix.node.path }} program test
  461. - uses: ./.github/actions/git-diff/