tests.yaml 17 KB

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