reusable-tests.yaml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. test-anchor-init:
  307. needs: setup-anchor-cli
  308. name: Test Anchor Init
  309. runs-on: ubuntu-latest
  310. timeout-minutes: 30
  311. steps:
  312. - uses: actions/checkout@v3
  313. - uses: ./.github/actions/setup/
  314. - uses: ./.github/actions/setup-ts/
  315. - uses: ./.github/actions/setup-solana/
  316. - uses: actions/cache@v3
  317. if: ${{ env.CACHE != 'false' }}
  318. name: Cache Cargo registry + index
  319. id: cache-anchor
  320. with:
  321. path: ${{ env.CARGO_CACHE_PATH }}
  322. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  323. - uses: actions/download-artifact@v3
  324. with:
  325. name: ${{ env.ANCHOR_BINARY_NAME }}
  326. path: ~/.cargo/bin/
  327. - run: chmod +x ~/.cargo/bin/anchor
  328. - run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && yarn link @coral-xyz/anchor && yarn && anchor test && yarn lint:fix
  329. - uses: ./.github/actions/git-diff/
  330. test-programs:
  331. needs: setup-anchor-cli
  332. name: Test ${{ matrix.node.path }}
  333. runs-on: ubuntu-latest
  334. timeout-minutes: 30
  335. strategy:
  336. fail-fast: false
  337. matrix:
  338. node:
  339. - cmd: cd tests/sysvars && anchor test --skip-lint
  340. path: tests/sysvars
  341. - cmd: cd tests/composite && anchor test --skip-lint
  342. path: tests/composite
  343. - cmd: cd tests/errors && anchor test --skip-lint && npx tsc --noEmit
  344. path: tests/errors
  345. - cmd: cd tests/spl/token-proxy && anchor test --skip-lint
  346. path: spl/token-proxy
  347. - cmd: cd tests/spl/token-wrapper && anchor test --skip-lint
  348. path: spl/token-wrapper
  349. - cmd: cd tests/multisig && anchor test --skip-lint
  350. path: tests/multisig
  351. # - cmd: cd tests/lockup && anchor test --skip-lint
  352. # path: tests/lockup
  353. # TODO: Remove `1.14.18` installation if/when https://github.com/solana-labs/solana/issues/31960 is solved
  354. # `swap` tests don't work with Solana `1.16.0`, downgrade to `1.14.18`
  355. - 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
  356. path: tests/swap
  357. - cmd: cd tests/escrow && anchor test --skip-lint && npx tsc --noEmit
  358. path: tests/escrow
  359. - cmd: cd tests/pyth && anchor test --skip-lint && npx tsc --noEmit
  360. path: tests/pyth
  361. - cmd: cd tests/realloc && anchor test --skip-lint && npx tsc --noEmit
  362. path: tests/realloc
  363. - cmd: cd tests/system-accounts && anchor test --skip-lint
  364. path: tests/system-accounts
  365. - cmd: cd tests/misc && anchor test --skip-lint && npx tsc --noEmit
  366. path: tests/misc
  367. - cmd: cd tests/events && anchor test --skip-lint
  368. path: tests/events
  369. - cmd: cd tests/cashiers-check && anchor test --skip-lint
  370. path: tests/cashiers-check
  371. - cmd: cd tests/declare-id && anchor test --skip-lint && npx tsc --noEmit
  372. path: tests/declare-id
  373. - cmd: cd tests/typescript && anchor test --skip-lint && npx tsc --noEmit
  374. path: tests/typescript
  375. - 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
  376. path: tests/zero-copy
  377. - cmd: cd tests/chat && anchor test --skip-lint
  378. path: tests/chat
  379. - cmd: cd tests/ido-pool && anchor test --skip-lint
  380. path: tests/ido-pool
  381. # - cmd: cd tests/cfo && anchor run test-with-build && cd deps/stake && git checkout Cargo.lock && cd ../swap && git checkout Cargo.lock
  382. # path: tests/cfo
  383. # TODO: Remove `1.14.18` installation if/when https://github.com/solana-labs/solana/issues/31960 is solved
  384. # `auction-house` tests don't work with Solana `1.16.0`, downgrade to `1.14.18`
  385. - cmd: cd tests/auction-house && solana-install init 1.14.18 && yarn --frozen-lockfile && anchor test --skip-lint && git checkout Cargo.lock
  386. path: tests/auction-house
  387. - cmd: cd tests/floats && yarn --frozen-lockfile && anchor test --skip-lint && npx tsc --noEmit
  388. path: tests/floats
  389. - cmd: cd tests/safety-checks && anchor run test
  390. path: tests/safety-checks
  391. - cmd: cd tests/custom-coder && anchor test --skip-lint && npx tsc --noEmit
  392. path: tests/custom-coder
  393. - cmd: cd tests/validator-clone && anchor test --skip-lint && npx tsc --noEmit
  394. path: tests/validator-clone
  395. - cmd: cd tests/cpi-returns && anchor test --skip-lint && npx tsc --noEmit
  396. path: tests/cpi-returns
  397. - cmd: cd tests/multiple-suites && anchor test --skip-lint && npx tsc --noEmit
  398. path: tests/multiple-suites
  399. - cmd: cd tests/multiple-suites-run-single && anchor test --skip-lint --run tests/should-run && npx tsc --noEmit
  400. path: tests/multiple-suites-run-single
  401. - cmd: cd tests/optional && anchor test --skip-lint && npx tsc --noEmit
  402. path: tests/optional
  403. - cmd: cd tests/pda-derivation && anchor test --skip-lint && npx tsc --noEmit
  404. path: tests/pda-derivation
  405. - cmd: cd tests/relations-derivation && anchor test --skip-lint && npx tsc --noEmit
  406. path: tests/relations-derivation
  407. - cmd: cd tests/anchor-cli-idl && ./test.sh
  408. path: tests/anchor-cli-idl
  409. - cmd: cd tests/anchor-cli-account && anchor test --skip-lint
  410. path: tests/anchor-cli-account
  411. - cmd: cd tests/bench && anchor test --skip-lint
  412. path: tests/bench
  413. - cmd: cd tests/idl && ./test.sh
  414. path: tests/idl
  415. steps:
  416. - uses: actions/checkout@v3
  417. - uses: ./.github/actions/setup/
  418. - uses: ./.github/actions/setup-ts/
  419. - uses: ./.github/actions/setup-solana/
  420. - uses: actions/cache@v3
  421. if: ${{ env.CACHE != 'false' }}
  422. name: Cache Cargo registry + index
  423. id: cache-anchor
  424. with:
  425. path: ${{ env.CARGO_CACHE_PATH }}
  426. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  427. - uses: actions/download-artifact@v3
  428. with:
  429. name: ${{ env.ANCHOR_BINARY_NAME }}
  430. path: ~/.cargo/bin/
  431. - run: chmod +x ~/.cargo/bin/anchor
  432. - uses: actions/cache@v3
  433. if: ${{ env.CACHE != 'false' }}
  434. name: Cache ${{ matrix.node.path }} target
  435. id: cache-test-target
  436. with:
  437. path: ${{ matrix.node.path }}/target
  438. key: cargo-${{ runner.os }}-${{ matrix.node.path }}-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  439. - run: ${{ matrix.node.cmd }}
  440. name: ${{ matrix.node.path }} program test
  441. - uses: ./.github/actions/git-diff/