reusable-tests.yaml 19 KB

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