Skip to content

Commit

Permalink
adjust test setup after build changes
Browse files Browse the repository at this point in the history
  • Loading branch information
frontendphil committed Nov 13, 2024
1 parent 00cd607 commit 2acda8f
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 55 deletions.
10 changes: 5 additions & 5 deletions packages/api-kit/tests/e2e/addSafeOperation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions packages/api-kit/tests/e2e/confirmSafeOperation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
21 changes: 14 additions & 7 deletions packages/protocol-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol-kit/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './passkeys'
export * from './webauthnShim'
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 5 additions & 1 deletion packages/protocol-kit/tests/e2e/passkey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/tests/e2e/safeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol-kit/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"outDir": "dist/src"
"outDir": "dist"
},
"include": ["src/**/*"],
"include": ["src/**/*", "test-utils/**/*"],
"exclude": ["dist", "test"]
}
2 changes: 1 addition & 1 deletion packages/relay-kit/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config = {
},
moduleNameMapper: {
'^@safe-global/protocol-kit/tests/(.*)$': '<rootDir>/../protocol-kit/tests/$1',
'^@safe-global/protocol-kit/(.*)$': '<rootDir>/../protocol-kit/src/$1',
'^@safe-global/relay-kit/test-utils$': '<rootDir>/test-utils',
'^@safe-global/relay-kit/(.*)$': '<rootDir>/src/$1'
},
testTimeout: 20000
Expand Down
28 changes: 20 additions & 8 deletions packages/relay-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/relay-kit/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -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'
7 changes: 2 additions & 5 deletions packages/relay-kit/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 2 additions & 0 deletions packages/testing-kit/bin/testing-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/testing-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 2acda8f

Please sign in to comment.