reusable-tests.yaml 19 KB

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