tests.yaml 17 KB

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