tests.yaml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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/optional/
  135. name: optional.so
  136. - path: tests/events/
  137. name: events.so
  138. - path: examples/tutorial/basic-4/
  139. name: basic_4.so
  140. - path: examples/tutorial/basic-2/
  141. name: basic_2.so
  142. - path: tests/composite/
  143. name: composite.so
  144. steps:
  145. - uses: actions/checkout@v3
  146. - uses: ./.github/actions/setup/
  147. - uses: ./.github/actions/setup-solana/
  148. - uses: actions/download-artifact@v3
  149. with:
  150. name: anchor-binary
  151. path: ~/.cargo/bin/
  152. - run: chmod +rwx ~/.cargo/bin/anchor
  153. - run: cd ${{ matrix.node.path }} && anchor build --skip-lint
  154. - uses: actions/upload-artifact@v3
  155. with:
  156. name: ${{ matrix.node.name }}
  157. path: ${{ matrix.node.path }}target/deploy/${{ matrix.node.name }}
  158. - uses: ./.github/actions/git-diff/
  159. test-client-example:
  160. needs: setup-client-example
  161. name: Client Example Test
  162. runs-on: ubuntu-latest
  163. timeout-minutes: 30
  164. steps:
  165. - uses: actions/checkout@v3
  166. - uses: ./.github/actions/setup/
  167. - uses: ./.github/actions/setup-ts/
  168. - uses: actions/download-artifact@v3
  169. with:
  170. name: anchor-binary
  171. path: ~/.cargo/bin/
  172. - run: chmod +x ~/.cargo/bin/anchor
  173. - uses: actions/download-artifact@v3
  174. with:
  175. name: optional.so
  176. path: tests/optional/target/deploy/
  177. - uses: actions/download-artifact@v2
  178. with:
  179. name: events.so
  180. path: tests/events/target/deploy/
  181. - uses: actions/download-artifact@v3
  182. with:
  183. name: basic_4.so
  184. path: examples/tutorial/basic-4/target/deploy/
  185. - uses: actions/download-artifact@v3
  186. with:
  187. name: basic_2.so
  188. path: examples/tutorial/basic-2/target/deploy/
  189. - uses: actions/download-artifact@v3
  190. with:
  191. name: composite.so
  192. path: tests/composite/target/deploy/
  193. - uses: actions/cache@v3
  194. name: Cache client/example target
  195. id: cache-test-target
  196. with:
  197. path: client/example/target
  198. key: cargo-${{ runner.os }}-client/example-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  199. - uses: ./.github/actions/setup-solana/
  200. - run: cd client/example && ./run-test.sh
  201. - uses: ./.github/actions/git-diff/
  202. test-bpf-upgradeable-state:
  203. needs: setup-anchor-cli
  204. name: Test tests/bpf-upgradeable-state
  205. runs-on: ubuntu-latest
  206. timeout-minutes: 30
  207. steps:
  208. - uses: actions/checkout@v3
  209. - uses: ./.github/actions/setup/
  210. - uses: ./.github/actions/setup-ts/
  211. - uses: ./.github/actions/setup-solana/
  212. - uses: actions/cache@v3
  213. name: Cache Cargo registry + index
  214. id: cache-anchor
  215. with:
  216. path: |
  217. ~/.cargo/bin/
  218. ~/.cargo/registry/index/
  219. ~/.cargo/registry/cache/
  220. ~/.cargo/git/db/
  221. ./target/
  222. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  223. - uses: actions/download-artifact@v3
  224. with:
  225. name: anchor-binary
  226. path: ~/.cargo/bin/
  227. - run: chmod +x ~/.cargo/bin/anchor
  228. - uses: actions/cache@v3
  229. name: Cache tests/bpf-upgradeable-state target
  230. id: cache-test-target
  231. with:
  232. path: tests/bpf-upgradeable-state/target
  233. key: cargo-${{ runner.os }}-tests/bpf-upgradeable-state-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  234. - run: solana-test-validator -r --quiet &
  235. name: start validator
  236. - run: cd tests/bpf-upgradeable-state && yarn --frozen-lockfile
  237. - run: cd tests/bpf-upgradeable-state
  238. - run: cd tests/bpf-upgradeable-state && anchor build --skip-lint
  239. - run: cd tests/bpf-upgradeable-state && solana program deploy --program-id program_with_different_programdata.json target/deploy/bpf_upgradeable_state.so
  240. - 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
  241. - run: cd tests/bpf-upgradeable-state && npx tsc --noEmit
  242. - uses: ./.github/actions/git-diff/
  243. # # this test exists to make sure that anchor
  244. # # checks rent correctly for legacy accounts
  245. # # that don't have to be rent-exempt
  246. # test-misc-non-rent-exempt:
  247. # # the anchor cli is built with a different solana version
  248. # # but that's fine since it's just the cli
  249. # needs: setup-anchor-cli
  250. # name: Test tests/misc/nonRentExempt
  251. # runs-on: ubuntu-latest
  252. # timeout-minutes: 30
  253. # steps:
  254. # - uses: actions/checkout@v3
  255. # - uses: ./.github/actions/setup/
  256. # - uses: ./.github/actions/setup-ts/
  257. # - uses: actions/cache@v3
  258. # name: Cache Solana Tool Suite
  259. # id: cache-solana
  260. # with:
  261. # path: |
  262. # ~/.cache/solana/
  263. # ~/.local/share/solana/
  264. # key: solana-${{ runner.os }}-v0000-1.8.14
  265. # # using an outdated validator but that
  266. # # is ok as long as the test doesn't
  267. # # include newer incompatible features
  268. # - run: sh -c "$(curl -sSfL https://release.solana.com/v1.8.14/install)"
  269. # shell: bash
  270. # - run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
  271. # shell: bash
  272. # - run: solana-keygen new --no-bip39-passphrase
  273. # shell: bash
  274. # - run: solana config set --url localhost
  275. # shell: bash
  276. # - uses: actions/download-artifact@v3
  277. # with:
  278. # name: anchor-binary
  279. # path: ~/.cargo/bin/
  280. # - run: chmod +x ~/.cargo/bin/anchor
  281. # - uses: actions/cache@v3
  282. # name: Cache tests/misc target
  283. # id: cache-test-target
  284. # with:
  285. # path: tests/misc/target
  286. # key: cargo-${{ runner.os }}-tests/misc-${{ env.ANCHOR_VERSION }}-1.8.14-${{ hashFiles('**/Cargo.lock') }}
  287. # - run: cd tests/misc && yarn --frozen-lockfile
  288. # - run: cd tests/misc
  289. # - run: cd tests/misc && chmod +x ci.sh && ./ci.sh
  290. # - run: cd tests/misc && anchor test --skip-lint
  291. test-anchor-init:
  292. needs: setup-anchor-cli
  293. name: Test Anchor Init
  294. runs-on: ubuntu-latest
  295. timeout-minutes: 30
  296. steps:
  297. - uses: actions/checkout@v3
  298. - uses: ./.github/actions/setup/
  299. - uses: ./.github/actions/setup-ts/
  300. - uses: ./.github/actions/setup-solana/
  301. - uses: actions/cache@v3
  302. name: Cache Cargo registry + index
  303. id: cache-anchor
  304. with:
  305. path: |
  306. ~/.cargo/bin/
  307. ~/.cargo/registry/index/
  308. ~/.cargo/registry/cache/
  309. ~/.cargo/git/db/
  310. ./target/
  311. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  312. - uses: actions/download-artifact@v3
  313. with:
  314. name: anchor-binary
  315. path: ~/.cargo/bin/
  316. - run: chmod +x ~/.cargo/bin/anchor
  317. - run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && yarn link @coral-xyz/anchor && yarn && anchor test && yarn lint:fix
  318. - uses: ./.github/actions/git-diff/
  319. test-programs:
  320. needs: setup-anchor-cli
  321. name: Test ${{ matrix.node.path }}
  322. runs-on: ubuntu-latest
  323. timeout-minutes: 30
  324. strategy:
  325. fail-fast: false
  326. matrix:
  327. node:
  328. - cmd: cd tests/sysvars && anchor test --skip-lint
  329. path: tests/sysvars
  330. - cmd: cd tests/composite && anchor test --skip-lint
  331. path: tests/composite
  332. - cmd: cd tests/errors && anchor test --skip-lint && npx tsc --noEmit
  333. path: tests/errors
  334. - cmd: cd tests/spl/token-proxy && anchor test --skip-lint
  335. path: spl/token-proxy
  336. - cmd: cd tests/multisig && anchor test --skip-lint
  337. path: tests/multisig
  338. - cmd: cd tests/interface && anchor test --skip-lint
  339. path: tests/interface
  340. - cmd: cd tests/lockup && anchor test --skip-lint
  341. path: tests/lockup
  342. - cmd: cd tests/swap/deps/openbook-dex/dex && cargo build-bpf -- --locked && cd ../../../ && anchor test --skip-lint
  343. path: tests/swap
  344. - cmd: cd tests/escrow && anchor test --skip-lint && npx tsc --noEmit
  345. path: tests/escrow
  346. - cmd: cd tests/pyth && anchor test --skip-lint && npx tsc --noEmit
  347. path: tests/pyth
  348. - cmd: cd tests/realloc && anchor test --skip-lint && npx tsc --noEmit
  349. path: tests/realloc
  350. - cmd: cd tests/system-accounts && anchor test --skip-lint
  351. path: tests/system-accounts
  352. - cmd: cd tests/misc && anchor test --skip-lint && npx tsc --noEmit
  353. path: tests/misc
  354. - cmd: cd tests/events && anchor test --skip-lint
  355. path: tests/events
  356. - cmd: cd tests/cashiers-check && anchor test --skip-lint
  357. path: tests/cashiers-check
  358. - cmd: cd tests/declare-id && anchor test --skip-lint && npx tsc --noEmit
  359. path: tests/declare-id
  360. - cmd: cd tests/typescript && anchor test --skip-lint && npx tsc --noEmit
  361. path: tests/typescript
  362. - cmd: cd tests/zero-copy && anchor test --skip-lint && cd programs/zero-copy && cargo test-bpf
  363. path: tests/zero-copy
  364. - cmd: cd tests/chat && anchor test --skip-lint
  365. path: tests/chat
  366. - cmd: cd tests/ido-pool && anchor test --skip-lint
  367. path: tests/ido-pool
  368. # - cmd: cd tests/cfo && anchor run test-with-build && cd deps/stake && git checkout Cargo.lock && cd ../swap && git checkout Cargo.lock
  369. # path: tests/cfo
  370. - cmd: cd tests/auction-house && yarn --frozen-lockfile && anchor test --skip-lint && git checkout Cargo.lock
  371. path: tests/auction-house
  372. - cmd: cd tests/floats && yarn --frozen-lockfile && anchor test --skip-lint && npx tsc --noEmit
  373. path: tests/floats
  374. - cmd: cd tests/safety-checks && anchor run test
  375. path: tests/safety-checks
  376. - cmd: cd tests/custom-coder && anchor test --skip-lint && npx tsc --noEmit
  377. path: tests/custom-coder
  378. - cmd: cd tests/validator-clone && anchor test --skip-lint && npx tsc --noEmit
  379. path: tests/validator-clone
  380. - cmd: cd tests/cpi-returns && anchor test --skip-lint && npx tsc --noEmit
  381. path: tests/cpi-returns
  382. - cmd: cd tests/multiple-suites && anchor test --skip-lint && npx tsc --noEmit
  383. path: tests/multiple-suites
  384. - cmd: cd tests/multiple-suites-run-single && anchor test --skip-lint --run tests/should-run && npx tsc --noEmit
  385. path: tests/multiple-suites-run-single
  386. - cmd: cd tests/optional && anchor test --skip-lint && npx tsc --noEmit
  387. path: tests/optional
  388. - cmd: cd tests/pda-derivation && anchor test --skip-lint && npx tsc --noEmit
  389. path: tests/pda-derivation
  390. - cmd: cd tests/relations-derivation && anchor test --skip-lint && npx tsc --noEmit
  391. path: tests/relations-derivation
  392. - cmd: cd tests/anchor-cli-idl && ./test.sh
  393. path: tests/anchor-cli-idl
  394. - cmd: cd tests/anchor-cli-account && anchor test --skip-lint
  395. path: tests/anchor-cli-account
  396. steps:
  397. - uses: actions/checkout@v3
  398. - uses: ./.github/actions/setup/
  399. - uses: ./.github/actions/setup-ts/
  400. - uses: ./.github/actions/setup-solana/
  401. - uses: actions/cache@v3
  402. name: Cache Cargo registry + index
  403. id: cache-anchor
  404. with:
  405. path: |
  406. ~/.cargo/bin/
  407. ~/.cargo/registry/index/
  408. ~/.cargo/registry/cache/
  409. ~/.cargo/git/db/
  410. ./target/
  411. key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
  412. - uses: actions/download-artifact@v3
  413. with:
  414. name: anchor-binary
  415. path: ~/.cargo/bin/
  416. - run: chmod +x ~/.cargo/bin/anchor
  417. - uses: actions/cache@v3
  418. name: Cache ${{ matrix.node.path }} target
  419. id: cache-test-target
  420. with:
  421. path: ${{ matrix.node.path }}/target
  422. key: cargo-${{ runner.os }}-${{ matrix.node.path }}-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
  423. - run: ${{ matrix.node.cmd }}
  424. name: ${{ matrix.node.path }} program test
  425. - uses: ./.github/actions/git-diff/