From 2acda8fc34a2cce89080e7d4089da31c0bc9abdb Mon Sep 17 00:00:00 2001 From: Philipp Giese Date: Wed, 13 Nov 2024 10:36:35 +0100 Subject: [PATCH] adjust test setup after build changes --- .../tests/e2e/addSafeOperation.test.ts | 10 +++---- .../tests/e2e/confirmSafeOperation.test.ts | 16 +++++------ packages/protocol-kit/package.json | 21 +++++++++----- packages/protocol-kit/test-utils/index.ts | 2 ++ .../e2e/utils => test-utils}/passkeys.ts | 8 ++---- .../e2e/utils => test-utils}/webauthnShim.ts | 0 .../protocol-kit/tests/e2e/passkey.test.ts | 6 +++- .../tests/e2e/safeProvider.test.ts | 2 +- packages/protocol-kit/tsconfig.build.json | 4 +-- packages/relay-kit/jest.config.js | 2 +- packages/relay-kit/package.json | 28 +++++++++++++------ .../src/packs/safe-4337/Safe4337Pack.test.ts | 10 ++++--- .../src/packs/safe-4337/SafeOperation.test.ts | 2 +- .../estimators/PimlicoFeeEstimator.test.ts | 2 +- .../testing-utils => test-utils}/fixtures.ts | 2 +- .../testing-utils => test-utils}/helpers.ts | 4 +-- packages/relay-kit/test-utils/index.ts | 7 +++++ packages/relay-kit/tsconfig.build.json | 7 ++--- packages/testing-kit/bin/testing-kit.js | 2 ++ packages/testing-kit/package.json | 4 +-- 20 files changed, 84 insertions(+), 55 deletions(-) create mode 100644 packages/protocol-kit/test-utils/index.ts rename packages/protocol-kit/{tests/e2e/utils => test-utils}/passkeys.ts (94%) rename packages/protocol-kit/{tests/e2e/utils => test-utils}/webauthnShim.ts (100%) rename packages/relay-kit/{src/packs/safe-4337/testing-utils => test-utils}/fixtures.ts (99%) rename packages/relay-kit/{src/packs/safe-4337/testing-utils => test-utils}/helpers.ts (87%) create mode 100644 packages/relay-kit/test-utils/index.ts diff --git a/packages/api-kit/tests/e2e/addSafeOperation.test.ts b/packages/api-kit/tests/e2e/addSafeOperation.test.ts index 09cb2f33d..e32c6dee0 100644 --- a/packages/api-kit/tests/e2e/addSafeOperation.test.ts +++ b/packages/api-kit/tests/e2e/addSafeOperation.test.ts @@ -6,14 +6,14 @@ import Safe from '@safe-global/protocol-kit' import SafeApiKit from '@safe-global/api-kit/index' import { getAddSafeOperationProps } from '@safe-global/api-kit/utils/safeOperation' import { BundlerClient, Safe4337Pack } from '@safe-global/relay-kit' -import { generateTransferCallData } from '@safe-global/relay-kit/packs/safe-4337/testing-utils/helpers' +// @ts-expect-error crazy hack to get test working +import * as utils from '@safe-global/relay-kit/dist/cjs/src/packs/safe-4337/utils' import { + generateTransferCallData, ENTRYPOINT_ABI, ENTRYPOINT_ADDRESS_V06, RPC_4337_CALLS -} from '@safe-global/relay-kit/packs/safe-4337/constants' -// Needs to be imported from dist folder in order to mock the getEip4337BundlerProvider function -import * as safe4337Utils from '@safe-global/relay-kit/dist/src/packs/safe-4337/utils' +} from '@safe-global/relay-kit/test-utils' import { getKits } from '../utils/setupKits' chai.use(chaiAsPromised) @@ -41,7 +41,7 @@ describe('addSafeOperation', () => { const requestStub = sinon.stub() // Setup mocks for the bundler client before(async () => { - sinon.stub(safe4337Utils, 'getEip4337BundlerProvider').returns({ + sinon.stub(utils, 'getEip4337BundlerProvider').returns({ request: requestStub, readContract: sinon .stub() diff --git a/packages/api-kit/tests/e2e/confirmSafeOperation.test.ts b/packages/api-kit/tests/e2e/confirmSafeOperation.test.ts index 075febbe5..57c750d26 100644 --- a/packages/api-kit/tests/e2e/confirmSafeOperation.test.ts +++ b/packages/api-kit/tests/e2e/confirmSafeOperation.test.ts @@ -3,17 +3,17 @@ import chaiAsPromised from 'chai-as-promised' import sinon from 'sinon' import sinonChai from 'sinon-chai' import { BundlerClient, Safe4337InitOptions, Safe4337Pack } from '@safe-global/relay-kit' -import { generateTransferCallData } from '@safe-global/relay-kit/packs/safe-4337/testing-utils/helpers' +import { + generateTransferCallData, + ENTRYPOINT_ADDRESS_V06, + RPC_4337_CALLS +} from '@safe-global/relay-kit/test-utils' +// @ts-expect-error crazy hack to get test working +import * as utils from '@safe-global/relay-kit/dist/cjs/src/packs/safe-4337/utils' import SafeApiKit from '@safe-global/api-kit/index' import { getAddSafeOperationProps } from '@safe-global/api-kit/utils/safeOperation' import { SafeOperation } from '@safe-global/types-kit' -// Needs to be imported from dist folder in order to mock the getEip4337BundlerProvider function -import * as safe4337Utils from '@safe-global/relay-kit/dist/src/packs/safe-4337/utils' import { getApiKit, getEip1193Provider } from '../utils/setupKits' -import { - ENTRYPOINT_ADDRESS_V06, - RPC_4337_CALLS -} from '@safe-global/relay-kit/packs/safe-4337/constants' chai.use(chaiAsPromised) chai.use(sinonChai) @@ -73,7 +73,7 @@ describe('confirmSafeOperation', () => { const requestStub = sinon.stub() before(async () => { - sinon.stub(safe4337Utils, 'getEip4337BundlerProvider').returns({ + sinon.stub(utils, 'getEip4337BundlerProvider').returns({ request: requestStub } as unknown as BundlerClient) diff --git a/packages/protocol-kit/package.json b/packages/protocol-kit/package.json index 39d3083b2..f131f533c 100644 --- a/packages/protocol-kit/package.json +++ b/packages/protocol-kit/package.json @@ -3,12 +3,19 @@ "version": "5.0.4", "description": "SDK that facilitates the interaction with Safe Smart Accounts", "types": "dist/src/index.d.ts", - "main": "dist/cjs/index.cjs", - "module": "dist/esm/index.mjs", + "main": "dist/cjs/src/index.cjs", + "module": "dist/esm/src/index.mjs", "exports": { - "types": "./dist/src/index.d.ts", - "require": "./dist/cjs/index.cjs", - "import": "./dist/esm/index.mjs" + ".": { + "types": "./dist/src/index.d.ts", + "require": "./dist/cjs/src/index.cjs", + "import": "./dist/esm/src/index.mjs" + }, + "./test-utils": { + "types": "./dist/test-utils/index.d.ts", + "require": "./dist/cjs/test-utils/index.cjs", + "import": "./dist/esm/test-utils/index.mjs" + } }, "keywords": [ "Ethereum", @@ -42,8 +49,8 @@ "format": "prettier --write \"*/**/*.{js,json,md,ts}\"", "unbuild": "rimraf dist artifacts deployments cache .nyc_output *.tsbuildinfo", "build": "yarn unbuild && yarn check-safe-deployments && yarn build:esm && yarn build:cjs && yarn build:types", - "build:esm": "esbuild ./src/index --format=esm --bundle --packages=external --outdir=dist/esm --out-extension:.js=.mjs", - "build:cjs": "esbuild ./src/index --format=cjs --bundle --packages=external --outdir=dist/cjs --out-extension:.js=.cjs", + "build:esm": "esbuild ./src/index ./test-utils/index --format=esm --bundle --packages=external --outdir=dist/esm --out-extension:.js=.mjs", + "build:cjs": "esbuild ./src/index ./test-utils/index --format=cjs --bundle --packages=external --outdir=dist/cjs --out-extension:.js=.cjs", "build:types": "NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json" }, "repository": { diff --git a/packages/protocol-kit/test-utils/index.ts b/packages/protocol-kit/test-utils/index.ts new file mode 100644 index 000000000..cc35fc2ca --- /dev/null +++ b/packages/protocol-kit/test-utils/index.ts @@ -0,0 +1,2 @@ +export * from './passkeys' +export * from './webauthnShim' diff --git a/packages/protocol-kit/tests/e2e/utils/passkeys.ts b/packages/protocol-kit/test-utils/passkeys.ts similarity index 94% rename from packages/protocol-kit/tests/e2e/utils/passkeys.ts rename to packages/protocol-kit/test-utils/passkeys.ts index 0aa1c1bf0..6db62ad92 100644 --- a/packages/protocol-kit/tests/e2e/utils/passkeys.ts +++ b/packages/protocol-kit/test-utils/passkeys.ts @@ -1,11 +1,7 @@ -import { - PasskeyArgType, - PasskeyClient, - extractPasskeyCoordinates -} from '@safe-global/protocol-kit/index' +import { PasskeyArgType, PasskeyClient, extractPasskeyCoordinates } from '../src' +import { asHex } from '../src/utils/types' import { WebAuthnCredentials } from './webauthnShim' import { WalletClient, keccak256, toBytes, Transport, Chain, Account } from 'viem' -import { asHex } from '@safe-global/protocol-kit/utils/types' let singleInstance: WebAuthnCredentials diff --git a/packages/protocol-kit/tests/e2e/utils/webauthnShim.ts b/packages/protocol-kit/test-utils/webauthnShim.ts similarity index 100% rename from packages/protocol-kit/tests/e2e/utils/webauthnShim.ts rename to packages/protocol-kit/test-utils/webauthnShim.ts diff --git a/packages/protocol-kit/tests/e2e/passkey.test.ts b/packages/protocol-kit/tests/e2e/passkey.test.ts index a8ba67645..7be0e1762 100644 --- a/packages/protocol-kit/tests/e2e/passkey.test.ts +++ b/packages/protocol-kit/tests/e2e/passkey.test.ts @@ -23,7 +23,11 @@ import { } from '@safe-global/protocol-kit/contracts/safeDeploymentContracts' import { getEip1193Provider } from './utils/setupProvider' import { waitSafeTxReceipt } from './utils/transactions' -import { createMockPasskey, getWebAuthnCredentials, deployPasskeysContract } from './utils/passkeys' +import { + createMockPasskey, + getWebAuthnCredentials, + deployPasskeysContract +} from '@safe-global/protocol-kit/test-utils' chai.use(chaiAsPromised) chai.use(sinonChai) diff --git a/packages/protocol-kit/tests/e2e/safeProvider.test.ts b/packages/protocol-kit/tests/e2e/safeProvider.test.ts index 089b01ac4..60bd7e67a 100644 --- a/packages/protocol-kit/tests/e2e/safeProvider.test.ts +++ b/packages/protocol-kit/tests/e2e/safeProvider.test.ts @@ -5,7 +5,7 @@ import { getEip1193Provider } from './utils/setupProvider' import { SafeProvider } from '@safe-global/protocol-kit/index' import sinon from 'sinon' import sinonChai from 'sinon-chai' -import { createMockPasskey, getWebAuthnCredentials } from './utils/passkeys' +import { createMockPasskey, getWebAuthnCredentials } from '@safe-global/protocol-kit/test-utils' import { publicActions, walletActions } from 'viem' chai.use(chaiAsPromised) diff --git a/packages/protocol-kit/tsconfig.build.json b/packages/protocol-kit/tsconfig.build.json index 00513d17b..1a132aac0 100644 --- a/packages/protocol-kit/tsconfig.build.json +++ b/packages/protocol-kit/tsconfig.build.json @@ -4,8 +4,8 @@ "declaration": true, "emitDeclarationOnly": true, "declarationMap": true, - "outDir": "dist/src" + "outDir": "dist" }, - "include": ["src/**/*"], + "include": ["src/**/*", "test-utils/**/*"], "exclude": ["dist", "test"] } diff --git a/packages/relay-kit/jest.config.js b/packages/relay-kit/jest.config.js index fdc6f4885..0934a355c 100644 --- a/packages/relay-kit/jest.config.js +++ b/packages/relay-kit/jest.config.js @@ -6,7 +6,7 @@ const config = { }, moduleNameMapper: { '^@safe-global/protocol-kit/tests/(.*)$': '/../protocol-kit/tests/$1', - '^@safe-global/protocol-kit/(.*)$': '/../protocol-kit/src/$1', + '^@safe-global/relay-kit/test-utils$': '/test-utils', '^@safe-global/relay-kit/(.*)$': '/src/$1' }, testTimeout: 20000 diff --git a/packages/relay-kit/package.json b/packages/relay-kit/package.json index b816b6ff4..aaa489dd6 100644 --- a/packages/relay-kit/package.json +++ b/packages/relay-kit/package.json @@ -3,12 +3,24 @@ "version": "3.2.4", "description": "SDK for Safe Smart Accounts with support for ERC-4337 and Relay", "types": "dist/src/index.d.ts", - "main": "dist/cjs/index.cjs", - "module": "dist/esm/index.mjs", + "main": "dist/cjs/src/index.js", + "module": "dist/esm/src/index.js", "exports": { - "types": "./dist/src/index.d.ts", - "require": "./dist/cjs/index.cjs", - "import": "./dist/esm/index.mjs" + ".": { + "types": "./dist/src/index.d.ts", + "require": "./dist/cjs/src/index.js", + "import": "./dist/esm/src/index.js" + }, + "./test-utils": { + "types": "./dist/test-utils/index.d.ts", + "require": "./dist/cjs/test-utils/index.js", + "import": "./dist/esm/test-utils/index.js" + }, + "./dist/cjs/src/packs/safe-4337/utils": { + "types": "./dist/src/packs/safe-4337/utils.d.ts", + "require": "./dist/cjs/src/packs/safe-4337/utils.js", + "import": "./dist/esm/src/packs/safe-4337/utils.js" + } }, "keywords": [ "Ethereum", @@ -26,9 +38,9 @@ "format": "prettier --write \"*/**/*.{js,json,md,ts}\"", "unbuild": "rimraf dist .nyc_output cache", "build": "yarn unbuild && yarn build:esm && yarn build:cjs && yarn build:types", - "build:esm": "esbuild ./src/index --format=esm --bundle --packages=external --outdir=dist/esm --out-extension:.js=.mjs", - "build:cjs": "esbuild ./src/index --format=cjs --bundle --packages=external --outdir=dist/cjs --out-extension:.js=.cjs", - "build:types": "NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json" + "build:esm": "tsc -p tsconfig.build.json --module esnext --outDir dist/esm && tsc-alias -p tsconfig.build.json --outDir dist/esm", + "build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs && tsc-alias -p tsconfig.build.json --outDir dist/cjs", + "build:types": "NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json --declaration --declarationMap --emitDeclarationOnly && tsc-alias -p tsconfig.build.json" }, "repository": { "type": "git", diff --git a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts index 117d32fe8..273151250 100644 --- a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts +++ b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts @@ -2,8 +2,7 @@ import crypto from 'crypto' import dotenv from 'dotenv' import * as viem from 'viem' import Safe, * as protocolKit from '@safe-global/protocol-kit' -import { WebAuthnCredentials } from '@safe-global/protocol-kit/tests/e2e/utils/webauthnShim' -import { createMockPasskey } from '@safe-global/protocol-kit/tests/e2e/utils/passkeys' +import { WebAuthnCredentials, createMockPasskey } from '@safe-global/protocol-kit/test-utils' import { getAddModulesLibDeployment, getSafe4337ModuleDeployment @@ -12,9 +11,12 @@ import { MetaTransactionData, OperationType } from '@safe-global/types-kit' import { Safe4337Pack } from './Safe4337Pack' import EthSafeOperation from './SafeOperation' import * as constants from './constants' -import * as fixtures from './testing-utils/fixtures' -import { createSafe4337Pack, generateTransferCallData } from './testing-utils/helpers' import * as utils from './utils' +import { + fixtures, + createSafe4337Pack, + generateTransferCallData +} from '@safe-global/relay-kit/test-utils' dotenv.config() diff --git a/packages/relay-kit/src/packs/safe-4337/SafeOperation.test.ts b/packages/relay-kit/src/packs/safe-4337/SafeOperation.test.ts index 9ea2645dd..6dd6753ce 100644 --- a/packages/relay-kit/src/packs/safe-4337/SafeOperation.test.ts +++ b/packages/relay-kit/src/packs/safe-4337/SafeOperation.test.ts @@ -1,7 +1,7 @@ import { Hex, encodePacked } from 'viem' import { EthSafeSignature } from '@safe-global/protocol-kit' import EthSafeOperation from './SafeOperation' -import * as fixtures from './testing-utils/fixtures' +import { fixtures } from '@safe-global/relay-kit/test-utils' describe('SafeOperation', () => { it('should create a SafeOperation from an UserOperation', () => { diff --git a/packages/relay-kit/src/packs/safe-4337/estimators/PimlicoFeeEstimator.test.ts b/packages/relay-kit/src/packs/safe-4337/estimators/PimlicoFeeEstimator.test.ts index c6f263ef7..0d5e3d9d0 100644 --- a/packages/relay-kit/src/packs/safe-4337/estimators/PimlicoFeeEstimator.test.ts +++ b/packages/relay-kit/src/packs/safe-4337/estimators/PimlicoFeeEstimator.test.ts @@ -1,5 +1,5 @@ import { PimlicoFeeEstimator } from './PimlicoFeeEstimator' -import * as fixtures from '../testing-utils/fixtures' +import { fixtures } from '@safe-global/relay-kit/test-utils' import * as constants from '../constants' jest.mock('../utils', () => ({ diff --git a/packages/relay-kit/src/packs/safe-4337/testing-utils/fixtures.ts b/packages/relay-kit/test-utils/fixtures.ts similarity index 99% rename from packages/relay-kit/src/packs/safe-4337/testing-utils/fixtures.ts rename to packages/relay-kit/test-utils/fixtures.ts index 706238353..f937a0036 100644 --- a/packages/relay-kit/src/packs/safe-4337/testing-utils/fixtures.ts +++ b/packages/relay-kit/test-utils/fixtures.ts @@ -1,4 +1,4 @@ -import { ENTRYPOINT_ADDRESS_V06, ENTRYPOINT_ADDRESS_V07 } from '../constants' +import { ENTRYPOINT_ADDRESS_V06, ENTRYPOINT_ADDRESS_V07 } from '../src/packs/safe-4337/constants' export const OWNER_1 = '0xFfAC5578BE8AC1B2B9D13b34cAf4A074B96B8A1b' export const OWNER_2 = '0x3059EfD1BCe33be41eeEfd5fb6D520d7fEd54E43' diff --git a/packages/relay-kit/src/packs/safe-4337/testing-utils/helpers.ts b/packages/relay-kit/test-utils/helpers.ts similarity index 87% rename from packages/relay-kit/src/packs/safe-4337/testing-utils/helpers.ts rename to packages/relay-kit/test-utils/helpers.ts index 15f7d29f6..539ca1003 100644 --- a/packages/relay-kit/src/packs/safe-4337/testing-utils/helpers.ts +++ b/packages/relay-kit/test-utils/helpers.ts @@ -1,6 +1,6 @@ import { encodeFunctionData, parseAbi } from 'viem' -import { Safe4337InitOptions } from '../types' -import { Safe4337Pack } from '../Safe4337Pack' +import { Safe4337InitOptions } from '../src/packs/safe-4337/types' +import { Safe4337Pack } from '../src/packs/safe-4337/Safe4337Pack' import * as fixtures from './fixtures' export const generateTransferCallData = (to: string, value: bigint) => { diff --git a/packages/relay-kit/test-utils/index.ts b/packages/relay-kit/test-utils/index.ts new file mode 100644 index 000000000..d9baaeb65 --- /dev/null +++ b/packages/relay-kit/test-utils/index.ts @@ -0,0 +1,7 @@ +export * as fixtures from './fixtures' +export * from './helpers' +export { + ENTRYPOINT_ABI, + ENTRYPOINT_ADDRESS_V06, + RPC_4337_CALLS +} from '../src/packs/safe-4337/constants' diff --git a/packages/relay-kit/tsconfig.build.json b/packages/relay-kit/tsconfig.build.json index fb93df610..a49ad22fa 100644 --- a/packages/relay-kit/tsconfig.build.json +++ b/packages/relay-kit/tsconfig.build.json @@ -1,11 +1,8 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "declarationMap": true, - "outDir": "dist/src" + "outDir": "dist" }, - "include": ["src/**/*"], + "include": ["src/**/*", "test-utils/**/*"], "exclude": ["dist", "src/**/*.test.ts", "src/**/*.test-d.ts"] } diff --git a/packages/testing-kit/bin/testing-kit.js b/packages/testing-kit/bin/testing-kit.js index bbc371e4c..33cb85ff4 100755 --- a/packages/testing-kit/bin/testing-kit.js +++ b/packages/testing-kit/bin/testing-kit.js @@ -37,6 +37,8 @@ if (!fs.existsSync(hardhatConfigPath)) { } try { + process.env.TS_NODE_PROJECT = `${projectRoot}/tsconfig.json` + if (command === 'test' && directory) { execSync(`yarn ${command} ${path.join(projectRoot, directory)}`, { stdio: 'inherit' }) } else { diff --git a/packages/testing-kit/package.json b/packages/testing-kit/package.json index 062dd1cd5..6e61bdb6b 100644 --- a/packages/testing-kit/package.json +++ b/packages/testing-kit/package.json @@ -2,11 +2,11 @@ "name": "@safe-global/testing-kit", "version": "0.1.1", "description": "Helper package providing testing utilities", - "types": "dist/src/index.d.ts", + "types": "dist/src/src/index.d.ts", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", "exports": { - "types": "./dist/src/index.d.ts", + "types": "./dist/src/src/index.d.ts", "require": "./dist/cjs/index.cjs", "import": "./dist/esm/index.mjs" },