reusable-tests.yaml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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 && yarn --frozen-lockfile
  63. - run: cd ts/packages/anchor && yarn test
  64. - run: cd ts/packages/anchor && yarn lint
  65. - run: cd examples/tutorial && yarn --frozen-lockfile
  66. - run: cd examples/tutorial && yarn lint
  67. - run: cd tests && yarn --frozen-lockfile
  68. - run: cd tests && yarn lint
  69. - uses: ./.github/actions/git-diff/
  70. setup-anchor-cli:
  71. name: Setup Anchor cli
  72. runs-on: ubuntu-latest
  73. timeout-minutes: 30
  74. steps:
  75. - uses: actions/checkout@v3
  76. - uses: ./.github/actions/setup/
  77. - uses: actions/cache@v3
  78. if: ${{ env.CACHE != 'false' }}
  79. name: Cache Cargo registry + index
  80. id: cache-anchor
  81. with:
  82. path: ${{ env.CARGO_CACHE_PATH }}
  83. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  84. - run: cargo install --path cli anchor-cli --locked --force --debug
  85. if: env.CARGO_PROFILE == 'debug'
  86. - run: cargo install --path cli anchor-cli --locked --force
  87. if: env.CARGO_PROFILE != 'debug'
  88. - run: chmod +x ~/.cargo/bin/anchor
  89. - uses: actions/upload-artifact@v3
  90. with:
  91. name: ${{ env.ANCHOR_BINARY_NAME }}
  92. path: ~/.cargo/bin/anchor
  93. - uses: ./.github/actions/git-diff/
  94. test-examples:
  95. needs: setup-anchor-cli
  96. name: Examples Test
  97. runs-on: ubuntu-latest
  98. timeout-minutes: 30
  99. steps:
  100. - uses: actions/checkout@v3
  101. - uses: actions/download-artifact@v3
  102. with:
  103. name: ${{ env.ANCHOR_BINARY_NAME }}
  104. path: ~/.cargo/bin/
  105. - run: chmod +rwx ~/.cargo/bin/anchor
  106. - uses: ./.github/actions/setup/
  107. - uses: ./.github/actions/setup-solana/
  108. - uses: ./.github/actions/setup-ts/
  109. - uses: actions/cache@v3
  110. if: ${{ env.CACHE != 'false' }}
  111. name: basic-0 cache
  112. id: cache-basic-0
  113. with:
  114. path: ./examples/tutorial/basic-0/target
  115. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-0/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  116. - uses: actions/cache@v3
  117. if: ${{ env.CACHE != 'false' }}
  118. name: basic-1 cache
  119. id: cache-basic-1
  120. with:
  121. path: ./examples/tutorial/basic-1/target
  122. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-1/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  123. - uses: actions/cache@v3
  124. if: ${{ env.CACHE != 'false' }}
  125. name: basic-2 cache
  126. id: cache-basic-2
  127. with:
  128. path: ./examples/tutorial/basic-2/target
  129. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-2/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  130. - uses: actions/cache@v3
  131. if: ${{ env.CACHE != 'false' }}
  132. name: basic-3 cache
  133. id: cache-basic-3
  134. with:
  135. path: ./examples/tutorial/basic-3/target
  136. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-3/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  137. - uses: actions/cache@v3
  138. if: ${{ env.CACHE != 'false' }}
  139. name: basic-4 cache
  140. id: cache-basic-4
  141. with:
  142. path: ./examples/tutorial/basic-4/target
  143. key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-4/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  144. - run: cd examples/tutorial && yarn workspaces run test
  145. - uses: ./.github/actions/git-diff/
  146. setup-client-example:
  147. needs: setup-anchor-cli
  148. name: Setup Client Example Test
  149. runs-on: ubuntu-latest
  150. timeout-minutes: 30
  151. strategy:
  152. fail-fast: false
  153. matrix:
  154. node:
  155. - path: tests/optional/
  156. name: optional.so
  157. - path: tests/events/
  158. name: events.so
  159. - path: examples/tutorial/basic-4/
  160. name: basic_4.so
  161. - path: examples/tutorial/basic-2/
  162. name: basic_2.so
  163. - path: tests/composite/
  164. name: composite.so
  165. steps:
  166. - uses: actions/checkout@v3
  167. - uses: ./.github/actions/setup/
  168. - uses: ./.github/actions/setup-solana/
  169. - uses: actions/download-artifact@v3
  170. with:
  171. name: ${{ env.ANCHOR_BINARY_NAME }}
  172. path: ~/.cargo/bin/
  173. - run: chmod +rwx ~/.cargo/bin/anchor
  174. - run: cd ${{ matrix.node.path }} && anchor build --skip-lint
  175. - uses: actions/upload-artifact@v3
  176. with:
  177. name: ${{ matrix.node.name }}
  178. path: ${{ matrix.node.path }}target/deploy/${{ matrix.node.name }}
  179. - uses: ./.github/actions/git-diff/
  180. test-client-example:
  181. needs: setup-client-example
  182. name: Client Example Test
  183. runs-on: ubuntu-latest
  184. timeout-minutes: 30
  185. steps:
  186. - uses: actions/checkout@v3
  187. - uses: ./.github/actions/setup/
  188. - uses: ./.github/actions/setup-ts/
  189. - uses: actions/download-artifact@v3
  190. with:
  191. name: ${{ env.ANCHOR_BINARY_NAME }}
  192. path: ~/.cargo/bin/
  193. - run: chmod +x ~/.cargo/bin/anchor
  194. - uses: actions/download-artifact@v3
  195. with:
  196. name: optional.so
  197. path: tests/optional/target/deploy/
  198. - uses: actions/download-artifact@v2
  199. with:
  200. name: events.so
  201. path: tests/events/target/deploy/
  202. - uses: actions/download-artifact@v3
  203. with:
  204. name: basic_4.so
  205. path: examples/tutorial/basic-4/target/deploy/
  206. - uses: actions/download-artifact@v3
  207. with:
  208. name: basic_2.so
  209. path: examples/tutorial/basic-2/target/deploy/
  210. - uses: actions/download-artifact@v3
  211. with:
  212. name: composite.so
  213. path: tests/composite/target/deploy/
  214. - uses: actions/cache@v3
  215. if: ${{ env.CACHE != 'false' }}
  216. name: Cache client/example target
  217. id: cache-test-target
  218. with:
  219. path: client/example/target
  220. key: cargo-${{ runner.os }}-client/example-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  221. - uses: ./.github/actions/setup-solana/
  222. - run: cd client/example && ./run-test.sh
  223. - uses: ./.github/actions/git-diff/
  224. test-bpf-upgradeable-state:
  225. needs: setup-anchor-cli
  226. name: Test tests/bpf-upgradeable-state
  227. runs-on: ubuntu-latest
  228. timeout-minutes: 30
  229. steps:
  230. - uses: actions/checkout@v3
  231. - uses: ./.github/actions/setup/
  232. - uses: ./.github/actions/setup-ts/
  233. - uses: ./.github/actions/setup-solana/
  234. - uses: actions/cache@v3
  235. if: ${{ env.CACHE != 'false' }}
  236. name: Cache Cargo registry + index
  237. id: cache-anchor
  238. with:
  239. path: ${{ env.CARGO_CACHE_PATH }}
  240. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  241. - uses: actions/download-artifact@v3
  242. with:
  243. name: ${{ env.ANCHOR_BINARY_NAME }}
  244. path: ~/.cargo/bin/
  245. - run: chmod +x ~/.cargo/bin/anchor
  246. - uses: actions/cache@v3
  247. if: ${{ env.CACHE != 'false' }}
  248. name: Cache tests/bpf-upgradeable-state target
  249. id: cache-test-target
  250. with:
  251. path: tests/bpf-upgradeable-state/target
  252. key: cargo-${{ runner.os }}-tests/bpf-upgradeable-state-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  253. - run: solana-test-validator -r --quiet &
  254. name: start validator
  255. - run: cd tests/bpf-upgradeable-state && yarn --frozen-lockfile
  256. - run: cd tests/bpf-upgradeable-state
  257. - run: cd tests/bpf-upgradeable-state && anchor build --skip-lint
  258. - run: cd tests/bpf-upgradeable-state && solana program deploy --program-id program_with_different_programdata.json target/deploy/bpf_upgradeable_state.so
  259. - 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
  260. - run: cd tests/bpf-upgradeable-state && npx tsc --noEmit
  261. - uses: ./.github/actions/git-diff/
  262. # # this test exists to make sure that anchor
  263. # # checks rent correctly for legacy accounts
  264. # # that don't have to be rent-exempt
  265. # test-misc-non-rent-exempt:
  266. # # the anchor cli is built with a different solana version
  267. # # but that's fine since it's just the cli
  268. # needs: setup-anchor-cli
  269. # name: Test tests/misc/nonRentExempt
  270. # runs-on: ubuntu-latest
  271. # timeout-minutes: 30
  272. # steps:
  273. # - uses: actions/checkout@v3
  274. # - uses: ./.github/actions/setup/
  275. # - uses: ./.github/actions/setup-ts/
  276. # - uses: actions/cache@v3
  277. # name: Cache Solana Tool Suite
  278. # id: cache-solana
  279. # with:
  280. # path: |
  281. # ~/.cache/solana/
  282. # ~/.local/share/solana/
  283. # key: solana-${{ runner.os }}-v0000-1.8.14
  284. # # using an outdated validator but that
  285. # # is ok as long as the test doesn't
  286. # # include newer incompatible features
  287. # - run: sh -c "$(curl -sSfL https://release.solana.com/v1.8.14/install)"
  288. # shell: bash
  289. # - run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
  290. # shell: bash
  291. # - run: solana-keygen new --no-bip39-passphrase
  292. # shell: bash
  293. # - run: solana config set --url localhost
  294. # shell: bash
  295. # - uses: actions/download-artifact@v3
  296. # with:
  297. # name: ${{ env.ANCHOR_BINARY_NAME }}
  298. # path: ~/.cargo/bin/
  299. # - run: chmod +x ~/.cargo/bin/anchor
  300. # - uses: actions/cache@v3
  301. # name: Cache tests/misc target
  302. # id: cache-test-target
  303. # with:
  304. # path: tests/misc/target
  305. # key: cargo-${{ runner.os }}-tests/misc-${{ env.ANCHOR_VERSION }}-1.8.14-${{ hashFiles('**/Cargo.lock') }}
  306. # - run: cd tests/misc && yarn --frozen-lockfile
  307. # - run: cd tests/misc
  308. # - run: cd tests/misc && chmod +x ci.sh && ./ci.sh
  309. # - run: cd tests/misc && anchor test --skip-lint
  310. test-anchor-init:
  311. needs: setup-anchor-cli
  312. name: Test Anchor Init
  313. runs-on: ubuntu-latest
  314. timeout-minutes: 30
  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@v3
  328. with:
  329. name: ${{ env.ANCHOR_BINARY_NAME }}
  330. path: ~/.cargo/bin/
  331. - run: chmod +x ~/.cargo/bin/anchor
  332. # TODO: Re-enable once https://github.com/solana-labs/solana/issues/33504 is resolved
  333. # - run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && yarn link @coral-xyz/anchor && yarn && anchor test && yarn lint:fix
  334. # - uses: ./.github/actions/git-diff/
  335. test-programs:
  336. needs: setup-anchor-cli
  337. name: Test ${{ matrix.node.path }}
  338. runs-on: ubuntu-latest
  339. timeout-minutes: 30
  340. strategy:
  341. fail-fast: false
  342. matrix:
  343. node:
  344. - cmd: cd tests/sysvars && anchor test --skip-lint
  345. path: tests/sysvars
  346. - cmd: cd tests/composite && anchor test --skip-lint
  347. path: tests/composite
  348. - cmd: cd tests/errors && anchor test --skip-lint && npx tsc --noEmit
  349. path: tests/errors
  350. - cmd: cd tests/spl/metadata && anchor test --skip-lint
  351. path: spl/metadata
  352. - cmd: cd tests/spl/token-proxy && anchor test --skip-lint
  353. path: spl/token-proxy
  354. - cmd: cd tests/spl/token-wrapper && anchor test --skip-lint
  355. path: spl/token-wrapper
  356. - cmd: cd tests/spl/transfer-hook && anchor test --skip-lint
  357. path: spl/transfer-hook
  358. - cmd: cd tests/spl/token-extensions && anchor test --skip-lint
  359. path: spl/token-extensions
  360. - cmd: cd tests/multisig && anchor test --skip-lint
  361. path: tests/multisig
  362. # - cmd: cd tests/lockup && anchor test --skip-lint
  363. # path: tests/lockup
  364. # TODO: Remove `1.14.18` installation if/when https://github.com/solana-labs/solana/issues/31960 is solved
  365. # `swap` tests don't work with Solana `1.16.0`, downgrade to `1.14.18`
  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/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. # TODO: Enable when `solang` becomes compatible with the new IDL spec
  431. # - cmd: cd tests/solang && anchor test
  432. # path: tests/solang
  433. steps:
  434. - uses: actions/checkout@v3
  435. - uses: ./.github/actions/setup/
  436. - uses: ./.github/actions/setup-ts/
  437. - uses: ./.github/actions/setup-solana/
  438. - uses: actions/cache@v3
  439. if: ${{ env.CACHE != 'false' }}
  440. name: Cache Cargo registry + index
  441. id: cache-anchor
  442. with:
  443. path: ${{ env.CARGO_CACHE_PATH }}
  444. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  445. - uses: actions/download-artifact@v3
  446. with:
  447. name: ${{ env.ANCHOR_BINARY_NAME }}
  448. path: ~/.cargo/bin/
  449. - run: chmod +x ~/.cargo/bin/anchor
  450. - uses: actions/cache@v3
  451. if: ${{ env.CACHE != 'false' }}
  452. name: Cache ${{ matrix.node.path }} target
  453. id: cache-test-target
  454. with:
  455. path: ${{ matrix.node.path }}/target
  456. key: cargo-${{ runner.os }}-${{ matrix.node.path }}-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  457. - run: ${{ matrix.node.cmd }}
  458. name: ${{ matrix.node.path }} program test
  459. - uses: ./.github/actions/git-diff/