Skip to content

Commit

Permalink
Improve test setup for L2 / anvil (#253)
Browse files Browse the repository at this point in the history
* set the experimental module always when running tests in cli.

* change setupL2 to only need web3 as that is all it uses and we always have web3 where as sometimes we wee needing to create a kit just to pass it to this function
move node experimental setup to the package so its always run and no weird esoteric knowldge is needed to run tests

* kit not required

---------

Co-authored-by: Leszek Stachowski <[email protected]>
  • Loading branch information
aaronmgdr and shazarre committed Jun 17, 2024
1 parent 6c2e47d commit 706e827
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: "nightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9"
# NODE_OPTIONS="--experimental-vm-modules" is needed because @viem/anvil uses dynamic imports
- name: Run tests
run: |
NODE_OPTIONS="--experimental-vm-modules" yarn workspace @celo/celocli test --coverage
yarn workspace @celo/celocli test --coverage
- name: Verify that a new account can be created
run: |
yarn workspace @celo/celocli run celocli account:new
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"lint": "yarn run --top-level eslint -c .eslintrc.js ",
"prepublish": "",
"prepack": "yarn run build && oclif manifest && oclif readme",
"test": "TZ=UTC yarn jest --runInBand --forceExit"
"test": "TZ=UTC NODE_OPTIONS=--experimental-vm-modules yarn jest --runInBand --forceExit"
},
"dependencies": {
"@celo/abis": "11.0.0",
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/src/test-utils/chain-setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { isCel2 } from '@celo/connect'
import { newKitFromWeb3 } from '@celo/contractkit'
import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test'
import Web3 from 'web3'
import { setupL2 } from './chain-setup'

testWithAnvil('chain setup', (web3: Web3) => {
describe('setupL2()', () => {
it('sets up L2 context', async () => {
const kit = newKitFromWeb3(web3)

expect(await isCel2(web3)).toEqual(false)

await setupL2(kit)
await setupL2(web3)

expect(await isCel2(web3)).toEqual(true)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/test-utils/chain-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ export const topUpWithToken = async (
}

// TODO remove this once no longer needed
export const setupL2 = async (kit: ContractKit) => {
export const setupL2 = async (web3: Web3) => {
// Temporarily deploying any bytecode, so it's just there,
// isCel2 should hence return true as it just checks for bytecode existence
await setCode(kit.web3, PROXY_ADMIN_ADDRESS, proxyBytecode)
await setCode(web3, PROXY_ADMIN_ADDRESS, proxyBytecode)
}
2 changes: 1 addition & 1 deletion packages/sdk/contractkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"clean": "yarn run --top-level tsc -b . --clean",
"prepublishOnly": "yarn build",
"docs": "yarn run --top-level typedoc",
"test": "yarn run --top-level jest --runInBand --forceExit",
"test": "NODE_OPTIONS=--experimental-vm-modules yarn run --top-level jest --runInBand --forceExit",
"lint": "yarn run --top-level eslint -c .eslintrc.js "
},
"dependencies": {
Expand Down

0 comments on commit 706e827

Please sign in to comment.