reusable-tests.yaml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. - run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && 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/token-proxy && anchor test --skip-lint
  350. path: spl/token-proxy
  351. - cmd: cd tests/spl/token-wrapper && anchor test --skip-lint
  352. path: spl/token-wrapper
  353. - cmd: cd tests/multisig && anchor test --skip-lint
  354. path: tests/multisig
  355. # - cmd: cd tests/lockup && anchor test --skip-lint
  356. # path: tests/lockup
  357. # TODO: Remove `1.14.18` installation if/when https://github.com/solana-labs/solana/issues/31960 is solved
  358. # `swap` tests don't work with Solana `1.16.0`, downgrade to `1.14.18`
  359. - 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
  360. path: tests/swap
  361. - cmd: cd tests/escrow && anchor test --skip-lint && npx tsc --noEmit
  362. path: tests/escrow
  363. - cmd: cd tests/pyth && anchor test --skip-lint && npx tsc --noEmit
  364. path: tests/pyth
  365. - cmd: cd tests/realloc && anchor test --skip-lint && npx tsc --noEmit
  366. path: tests/realloc
  367. - cmd: cd tests/system-accounts && anchor test --skip-lint
  368. path: tests/system-accounts
  369. - cmd: cd tests/misc && anchor test --skip-lint && npx tsc --noEmit
  370. path: tests/misc
  371. - cmd: cd tests/events && anchor test --skip-lint
  372. path: tests/events
  373. - cmd: cd tests/cashiers-check && anchor test --skip-lint
  374. path: tests/cashiers-check
  375. - cmd: cd tests/declare-id && anchor test --skip-lint && npx tsc --noEmit
  376. path: tests/declare-id
  377. - cmd: cd tests/typescript && anchor test --skip-lint && npx tsc --noEmit
  378. path: tests/typescript
  379. - 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
  380. path: tests/zero-copy
  381. - cmd: cd tests/chat && anchor test --skip-lint
  382. path: tests/chat
  383. - cmd: cd tests/ido-pool && anchor test --skip-lint
  384. path: tests/ido-pool
  385. # - cmd: cd tests/cfo && anchor run test-with-build && cd deps/stake && git checkout Cargo.lock && cd ../swap && git checkout Cargo.lock
  386. # path: tests/cfo
  387. # TODO: Remove `1.14.18` installation if/when https://github.com/solana-labs/solana/issues/31960 is solved
  388. # `auction-house` tests don't work with Solana `1.16.0`, downgrade to `1.14.18`
  389. - cmd: cd tests/auction-house && solana-install init 1.14.18 && yarn --frozen-lockfile && anchor test --skip-lint && git checkout Cargo.lock
  390. path: tests/auction-house
  391. - cmd: cd tests/floats && yarn --frozen-lockfile && anchor test --skip-lint && npx tsc --noEmit
  392. path: tests/floats
  393. - cmd: cd tests/safety-checks && anchor run test
  394. path: tests/safety-checks
  395. - cmd: cd tests/custom-coder && anchor test --skip-lint && npx tsc --noEmit
  396. path: tests/custom-coder
  397. - cmd: cd tests/validator-clone && anchor test --skip-lint && npx tsc --noEmit
  398. path: tests/validator-clone
  399. - cmd: cd tests/cpi-returns && anchor test --skip-lint && npx tsc --noEmit
  400. path: tests/cpi-returns
  401. - cmd: cd tests/multiple-suites && anchor test --skip-lint && npx tsc --noEmit
  402. path: tests/multiple-suites
  403. - cmd: cd tests/multiple-suites-run-single && anchor test --skip-lint --run tests/should-run && npx tsc --noEmit
  404. path: tests/multiple-suites-run-single
  405. - cmd: cd tests/optional && anchor test --skip-lint && npx tsc --noEmit
  406. path: tests/optional
  407. - cmd: cd tests/pda-derivation && anchor test --skip-lint && npx tsc --noEmit
  408. path: tests/pda-derivation
  409. - cmd: cd tests/relations-derivation && anchor test --skip-lint && npx tsc --noEmit
  410. path: tests/relations-derivation
  411. - cmd: cd tests/anchor-cli-idl && ./test.sh
  412. path: tests/anchor-cli-idl
  413. - cmd: cd tests/anchor-cli-account && anchor test --skip-lint
  414. path: tests/anchor-cli-account
  415. - cmd: cd tests/bench && anchor test --skip-lint
  416. path: tests/bench
  417. - cmd: cd tests/idl && ./test.sh
  418. path: tests/idl
  419. - cmd: cd tests/solang && anchor test
  420. path: tests/solang
  421. steps:
  422. - uses: actions/checkout@v3
  423. - uses: ./.github/actions/setup/
  424. - uses: ./.github/actions/setup-ts/
  425. - uses: ./.github/actions/setup-solana/
  426. - uses: actions/cache@v3
  427. if: ${{ env.CACHE != 'false' }}
  428. name: Cache Cargo registry + index
  429. id: cache-anchor
  430. with:
  431. path: ${{ env.CARGO_CACHE_PATH }}
  432. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  433. - uses: actions/download-artifact@v3
  434. with:
  435. name: ${{ env.ANCHOR_BINARY_NAME }}
  436. path: ~/.cargo/bin/
  437. - run: chmod +x ~/.cargo/bin/anchor
  438. - uses: actions/cache@v3
  439. if: ${{ env.CACHE != 'false' }}
  440. name: Cache ${{ matrix.node.path }} target
  441. id: cache-test-target
  442. with:
  443. path: ${{ matrix.node.path }}/target
  444. key: cargo-${{ runner.os }}-${{ matrix.node.path }}-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  445. - run: ${{ matrix.node.cmd }}
  446. name: ${{ matrix.node.path }} program test
  447. - uses: ./.github/actions/git-diff/