From 3f5f65d7328117e92a870a3f14124c68ee03c182 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Thu, 27 Jun 2024 18:29:59 +0300 Subject: [PATCH] convert transaction-utils to anvil (#278) * convert transaction-utils to anvil fix anvil not closing within jest 1 second timeout by setting anvil timeout to 1 second too. * celo-devchain not needed anymore but it was accidentally providing bn types so those must be added * convert transaction-utils to anvil fix anvil not closing within jest 1 second timeout by setting anvil timeout to 1 second too. * celo-devchain not needed anymore but it was accidentally providing bn types so those must be added * why are these in the docs at all * Update packages/dev-utils/src/test-utils.ts Co-authored-by: Leszek Stachowski --------- Co-authored-by: Leszek Stachowski --- .changeset/nervous-starfishes-return.md | 5 +++++ .changeset/wise-weeks-applaud.md | 5 +++++ .github/workflows/ci.yml | 4 ++++ .../modules/test_utils_setup_global.md | 2 +- .../modules/test_utils_teardown_global.md | 2 +- packages/dev-utils/src/anvil-test.ts | 7 ++++--- packages/dev-utils/src/test-utils.ts | 8 ++++---- packages/sdk/transactions-uri/package.json | 6 +++--- .../transactions-uri/src/test-utils/setup.global.ts | 13 +------------ .../src/test-utils/teardown.global.ts | 6 +----- packages/sdk/transactions-uri/src/tx-uri.test.ts | 4 ++-- yarn.lock | 11 ++--------- 12 files changed, 33 insertions(+), 40 deletions(-) create mode 100644 .changeset/nervous-starfishes-return.md create mode 100644 .changeset/wise-weeks-applaud.md diff --git a/.changeset/nervous-starfishes-return.md b/.changeset/nervous-starfishes-return.md new file mode 100644 index 000000000..4c2b9581e --- /dev/null +++ b/.changeset/nervous-starfishes-return.md @@ -0,0 +1,5 @@ +--- +'@celo/dev-utils': patch +--- + +Fix jest force exits,Set default timeout to 1 second diff --git a/.changeset/wise-weeks-applaud.md b/.changeset/wise-weeks-applaud.md new file mode 100644 index 000000000..a93be0c76 --- /dev/null +++ b/.changeset/wise-weeks-applaud.md @@ -0,0 +1,5 @@ +--- +'@celo/transactions-uri': patch +--- + +Bump bn.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06349e7e5..df0106db9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,6 +153,10 @@ jobs: needs: install-dependencies steps: - uses: actions/checkout@v4 + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: ${{ env.SUPPORTED_FOUNDRY_VERSION }} - name: Sync workspace uses: ./.github/actions/sync-workspace with: diff --git a/docs/sdk/transactions-uri/modules/test_utils_setup_global.md b/docs/sdk/transactions-uri/modules/test_utils_setup_global.md index db1477cd4..7a038e610 100644 --- a/docs/sdk/transactions-uri/modules/test_utils_setup_global.md +++ b/docs/sdk/transactions-uri/modules/test_utils_setup_global.md @@ -20,4 +20,4 @@ #### Defined in -[test-utils/setup.global.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/transactions-uri/src/test-utils/setup.global.ts#L10) +[test-utils/setup.global.ts:7](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/transactions-uri/src/test-utils/setup.global.ts#L7) diff --git a/docs/sdk/transactions-uri/modules/test_utils_teardown_global.md b/docs/sdk/transactions-uri/modules/test_utils_teardown_global.md index 275ad823b..c40ef82fa 100644 --- a/docs/sdk/transactions-uri/modules/test_utils_teardown_global.md +++ b/docs/sdk/transactions-uri/modules/test_utils_teardown_global.md @@ -20,4 +20,4 @@ #### Defined in -[test-utils/teardown.global.ts:3](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/transactions-uri/src/test-utils/teardown.global.ts#L3) +[test-utils/teardown.global.ts:1](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/transactions-uri/src/test-utils/teardown.global.ts#L1) diff --git a/packages/dev-utils/src/anvil-test.ts b/packages/dev-utils/src/anvil-test.ts index 27deca931..4e9af6583 100644 --- a/packages/dev-utils/src/anvil-test.ts +++ b/packages/dev-utils/src/anvil-test.ts @@ -29,6 +29,7 @@ export function createInstance(): Anvil { balance: TEST_BALANCE, gasPrice: TEST_GAS_PRICE, gasLimit: TEST_GAS_LIMIT, + stopTimeout: 1000, } instance = createAnvil(options) @@ -41,11 +42,11 @@ export function testWithAnvil(name: string, fn: (web3: Web3) => void) { // for each test case, we start and stop a new anvil instance return testWithWeb3(name, `http://127.0.0.1:${anvil.port}`, fn, { - beforeAll: () => { - return anvil.start() + beforeAll: async () => { + await anvil.start() }, afterAll: async () => { - return anvil.stop() + await anvil.stop() }, }) } diff --git a/packages/dev-utils/src/test-utils.ts b/packages/dev-utils/src/test-utils.ts index c8b14f414..cdcd2c72d 100644 --- a/packages/dev-utils/src/test-utils.ts +++ b/packages/dev-utils/src/test-utils.ts @@ -84,12 +84,12 @@ export function testWithWeb3( if (snapId != null) { await evmRevert(web3, snapId) } + if (hooks?.afterAll) { + // hook must be awaited here or jest doesnt actually wait for it and complains of open handles + await hooks.afterAll() + } }) - if (hooks?.afterAll) { - afterAll(hooks.afterAll) - } - fn(web3) }) } diff --git a/packages/sdk/transactions-uri/package.json b/packages/sdk/transactions-uri/package.json index c0869a51a..00651f42a 100644 --- a/packages/sdk/transactions-uri/package.json +++ b/packages/sdk/transactions-uri/package.json @@ -17,21 +17,21 @@ "build": "yarn run --top-level tsc -b .", "clean": "yarn run --top-level tsc -b . --clean", "docs": "yarn run --top-level typedoc", - "test": "yarn run --top-level jest --runInBand", + "test": "NODE_OPTIONS='--experimental-vm-modules' yarn run --top-level jest --runInBand", "lint": "yarn run --top-level eslint -c .eslintrc.js ", "prepublishOnly": "yarn build" }, "dependencies": { "@celo/base": "^6.1.0-beta.0", "@celo/connect": "^6.0.0-beta.0", + "@types/bn.js": "^5.1.0", "@types/debug": "^4.1.5", "@types/qrcode": "^1.3.4", - "bn.js": "4.11.9", + "bn.js": "^5.1.0", "qrcode": "1.4.4", "web3-eth-abi": "1.10.4" }, "devDependencies": { - "@celo/celo-devchain": "^7.0.0", "@celo/contractkit": "^8.1.0-beta.0", "@celo/dev-utils": "0.0.4-beta.0", "@celo/typescript": "workspace:^", diff --git a/packages/sdk/transactions-uri/src/test-utils/setup.global.ts b/packages/sdk/transactions-uri/src/test-utils/setup.global.ts index 5acd592ee..c301dde4c 100644 --- a/packages/sdk/transactions-uri/src/test-utils/setup.global.ts +++ b/packages/sdk/transactions-uri/src/test-utils/setup.global.ts @@ -1,18 +1,7 @@ -import baseSetup from '@celo/dev-utils/lib/ganache-setup' // Has to import the matchers somewhere so that typescript knows the matchers have been made available import _must_be_imported from '@celo/dev-utils/lib/matchers' -import { waitForPortOpen } from '@celo/dev-utils/lib/network' -import * as path from 'path' // Warning: There should be an unused import of '@celo/dev-utils/lib/matchers' above. // If there is not, then your editor probably deleted it automatically. -export default async function globalSetup() { - const chainDataPath = path.join(path.dirname(require.resolve('@celo/celo-devchain')), '../chains') - // vX refers to core contract release version X - await baseSetup(path.resolve(chainDataPath), 'v11.tar.gz', { - from_targz: true, - }) - await waitForPortOpen('localhost', 8545, 60) - console.log('...ganache started') -} +export default async function globalSetup() {} diff --git a/packages/sdk/transactions-uri/src/test-utils/teardown.global.ts b/packages/sdk/transactions-uri/src/test-utils/teardown.global.ts index aea64f79d..92e0f6e88 100644 --- a/packages/sdk/transactions-uri/src/test-utils/teardown.global.ts +++ b/packages/sdk/transactions-uri/src/test-utils/teardown.global.ts @@ -1,5 +1 @@ -import teardown from '@celo/dev-utils/lib/ganache-teardown' - -export default async function globalTeardown() { - await teardown() -} +export default async function globalTeardown() {} diff --git a/packages/sdk/transactions-uri/src/tx-uri.test.ts b/packages/sdk/transactions-uri/src/tx-uri.test.ts index 8e7236f12..f28007f58 100644 --- a/packages/sdk/transactions-uri/src/tx-uri.test.ts +++ b/packages/sdk/transactions-uri/src/tx-uri.test.ts @@ -1,9 +1,9 @@ import { CeloTx } from '@celo/connect' import { CeloContract, newKitFromWeb3 } from '@celo/contractkit' -import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' +import { testWithAnvil } from '@celo/dev-utils/lib/anvil-test' import { buildUri, parseUri } from './tx-uri' -testWithGanache('URI utils', (web3) => { +testWithAnvil('URI utils', (web3) => { const recipient = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' const value = '100' diff --git a/yarn.lock b/yarn.lock index 6d551decd..71f64a4ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1998,14 +1998,14 @@ __metadata: resolution: "@celo/transactions-uri@workspace:packages/sdk/transactions-uri" dependencies: "@celo/base": "npm:^6.1.0-beta.0" - "@celo/celo-devchain": "npm:^7.0.0" "@celo/connect": "npm:^6.0.0-beta.0" "@celo/contractkit": "npm:^8.1.0-beta.0" "@celo/dev-utils": "npm:0.0.4-beta.0" "@celo/typescript": "workspace:^" + "@types/bn.js": "npm:^5.1.0" "@types/debug": "npm:^4.1.5" "@types/qrcode": "npm:^1.3.4" - bn.js: "npm:4.11.9" + bn.js: "npm:^5.1.0" cross-fetch: "npm:3.1.5" dotenv: "npm:^8.2.0" fetch-mock: "npm:^10.0.7" @@ -7534,13 +7534,6 @@ __metadata: languageName: node linkType: hard -"bn.js@npm:4.11.9": - version: 4.11.9 - resolution: "bn.js@npm:4.11.9" - checksum: c5a2342f0bc3d0bbe53361d57aa51c489589ad2d7c726c1337e9af7f37b6bc2d2d1b63cfb1972a7aacbc053367832037f699f973c81d9c5844af247650968691 - languageName: node - linkType: hard - "bn.js@npm:^4.11.6, bn.js@npm:^4.11.8, bn.js@npm:^4.11.9": version: 4.12.0 resolution: "bn.js@npm:4.12.0"