From af4fa99eb83936e583ac67b68bbb7787657c42c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Thu, 29 Aug 2024 19:25:52 +0200 Subject: [PATCH] Update tests in protocol-kit and remove duplicates --- packages/protocol-kit/package.json | 2 +- .../tests/e2e/contractManager.test.ts | 46 ++--- packages/protocol-kit/tests/e2e/core.test.ts | 74 +++---- .../createSafeDeploymentTransaction.test.ts | 59 ++---- .../tests/e2e/createTransaction.test.ts | 128 ++++-------- .../tests/e2e/createTransactionBatch.test.ts | 36 +--- .../e2e/eip1271-contract-signatures.test.ts | 23 +-- .../protocol-kit/tests/e2e/eip1271.test.ts | 23 +-- .../protocol-kit/tests/e2e/erc-20.test.ts | 35 +--- .../protocol-kit/tests/e2e/execution.test.ts | 111 ++++------- .../tests/e2e/fallbackHandlerManager.test.ts | 97 ++++----- .../tests/e2e/getEncodedTransaction.test.ts | 38 +--- .../tests/e2e/guardManager.test.ts | 90 +++------ .../tests/e2e/moduleManager.test.ts | 148 ++++++-------- .../tests/e2e/offChainSignatures.test.ts | 66 ++----- .../tests/e2e/onChainSignatures.test.ts | 58 ++---- .../tests/e2e/ownerManager.test.ts | 187 ++++++++---------- .../protocol-kit/tests/e2e/passkey.test.ts | 24 +-- .../tests/e2e/safeFactory.test.ts | 93 ++++----- .../tests/e2e/safeProvider.test.ts | 48 ++--- .../protocol-kit/tests/e2e/threshold.test.ts | 50 +---- .../tests/e2e/utils/setupContractNetworks.ts | 42 ---- .../tests/e2e/utils/transactions.ts | 12 +- .../tests/e2e/utilsContracts.test.ts | 43 ++-- ...SafeTransactionIntoDeploymentBatch.test.ts | 49 ++--- packages/testing-kit/package.json | 5 + .../src/hardhat/deploy/deploy-contracts.ts | 1 - packages/testing-kit/src/index.ts | 6 + .../e2e => testing-kit/src}/utils/helpers.ts | 0 .../src/utils/setupContractNetworks.ts | 90 +++++++++ .../src}/utils/setupContracts.ts | 48 +++-- .../src}/utils/setupTestNetwork.ts | 3 +- packages/testing-kit/src/utils/setupTests.ts | 80 ++++++++ .../testing-kit/src/utils/transactions.ts | 11 ++ packages/testing-kit/tsconfig.build.json | 3 +- packages/testing-kit/tsconfig.json | 2 +- 36 files changed, 747 insertions(+), 1084 deletions(-) delete mode 100644 packages/protocol-kit/tests/e2e/utils/setupContractNetworks.ts rename packages/{protocol-kit/tests/e2e => testing-kit/src}/utils/helpers.ts (100%) create mode 100644 packages/testing-kit/src/utils/setupContractNetworks.ts rename packages/{protocol-kit/tests/e2e => testing-kit/src}/utils/setupContracts.ts (89%) rename packages/{protocol-kit/tests/e2e => testing-kit/src}/utils/setupTestNetwork.ts (95%) create mode 100644 packages/testing-kit/src/utils/setupTests.ts create mode 100644 packages/testing-kit/src/utils/transactions.ts diff --git a/packages/protocol-kit/package.json b/packages/protocol-kit/package.json index 093d3738a..ba3c90c2e 100644 --- a/packages/protocol-kit/package.json +++ b/packages/protocol-kit/package.json @@ -30,7 +30,7 @@ "test:hardhat:viem:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.1.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'", "test:hardhat:viem:v1.2.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.2.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'", "test:hardhat:viem:v1.3.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.3.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'", - "test:hardhat:viem:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.4.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'", + "test:hardhat:viem:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.4.1 && testing-kit deploy && nyc testing-kit test 'tests/e2e/*.test.*'", "coverage": "nyc report --reporter=lcov", "format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"", "format": "prettier --write \"*/**/*.{js,json,md,ts}\"", diff --git a/packages/protocol-kit/tests/e2e/contractManager.test.ts b/packages/protocol-kit/tests/e2e/contractManager.test.ts index cae664a6f..56d853071 100644 --- a/packages/protocol-kit/tests/e2e/contractManager.test.ts +++ b/packages/protocol-kit/tests/e2e/contractManager.test.ts @@ -1,45 +1,29 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { ContractNetworksConfig, PredictedSafeProps } from '@safe-global/protocol-kit/index' -import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' -import chai from 'chai' -import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' import { + safeVersionDeployed, + setupTests, getCompatibilityFallbackHandler, getCreateCall, getFactory, getMultiSend, getMultiSendCallOnly, getSafeSingleton, - getSafeWithOwners, getSignMessageLib, getSimulateTxAccessor -} from './utils/setupContracts' +} from '@safe-global/testing-kit' +import Safe, { ContractNetworksConfig, PredictedSafeProps } from '@safe-global/protocol-kit/index' +import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' +import chai from 'chai' +import chaiAsPromised from 'chai-as-promised' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' chai.use(chaiAsPromised) describe('Safe contracts manager', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - return { - safe: await getSafeWithOwners([accounts[0].address]), - accounts, - contractNetworks, - chainId, - provider - } - }) + const provider = getEip1193Provider() describe('create', async () => { it('should initialize the SDK with a Safe that is not deployed', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const predictedSafe: PredictedSafeProps = { safeAccountConfig: { owners: [accounts[0].address], @@ -59,7 +43,7 @@ describe('Safe contracts manager', () => { }) it('should fail if the current network is not a default network and no contractNetworks is provided', async () => { - const { safe, provider } = await setupTests() + const { safe } = await setupTests() const safeAddress = safe.address await chai .expect( @@ -72,7 +56,7 @@ describe('Safe contracts manager', () => { }) it('should fail if SafeProxy contract is not deployed on the current network', async () => { - const { contractNetworks, provider } = await setupTests() + const { contractNetworks } = await setupTests() await chai .expect( Safe.init({ @@ -85,8 +69,8 @@ describe('Safe contracts manager', () => { }) it('should fail if MultiSend contract is specified in contractNetworks but not deployed', async () => { - const { safe, chainId, provider } = await setupTests() - const customContractNetworks: ContractNetworksConfig = { + const { safe, chainId } = await setupTests() + const customContractNetworks = { [chainId.toString()]: { safeSingletonAddress: ZERO_ADDRESS, safeSingletonAbi: (await getSafeSingleton()).abi, @@ -113,14 +97,14 @@ describe('Safe contracts manager', () => { Safe.init({ provider, safeAddress, - contractNetworks: customContractNetworks + contractNetworks: customContractNetworks as ContractNetworksConfig }) ) .to.be.rejectedWith('MultiSend contract is not deployed on the current network') }) it('should set the MultiSend contract available on the current network', async () => { - const { safe, chainId, contractNetworks, provider } = await setupTests() + const { safe, chainId, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, diff --git a/packages/protocol-kit/tests/e2e/core.test.ts b/packages/protocol-kit/tests/e2e/core.test.ts index 5182e4bdc..c1f04cd53 100644 --- a/packages/protocol-kit/tests/e2e/core.test.ts +++ b/packages/protocol-kit/tests/e2e/core.test.ts @@ -1,51 +1,29 @@ import { DEFAULT_SAFE_VERSION } from '@safe-global/protocol-kit/contracts/config' -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { + safeVersionDeployed, + setupTests, + itif, + getSafeWithOwners, + waitTransactionReceipt +} from '@safe-global/testing-kit' import Safe, { PredictedSafeProps, SafeFactory } from '@safe-global/protocol-kit/index' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { itif } from './utils/helpers' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' + import { waitSafeTxReceipt } from './utils/transactions' -import { waitTransactionReceipt } from './utils/transactions' import { sameString } from '@safe-global/protocol-kit/utils' chai.use(chaiAsPromised) describe('Safe Info', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - const provider = getEip1193Provider() - return { - chainId, - safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), - provider, - predictedSafe, - accounts, - contractNetworks - } - }) + const provider = getEip1193Provider() describe('connect', async () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to connect a Safe { - const { predictedSafe, safe, contractNetworks, provider } = await setupTests() + const { predictedSafe, safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -62,7 +40,7 @@ describe('Safe Info', () => { ) it('should connect a Safe >=v1.3.0 that is not deployed', async () => { - const { predictedSafe, safe, accounts, contractNetworks, provider } = await setupTests() + const { predictedSafe, safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -80,7 +58,7 @@ describe('Safe Info', () => { }) it('should connect a deployed Safe', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2, account3] = accounts const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -129,7 +107,7 @@ describe('Safe Info', () => { describe('getContractVersion', async () => { it('should return the contract version of a Safe that is not deployed with a custom version configuration', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -140,7 +118,7 @@ describe('Safe Info', () => { }) it('should return the contract version of a Safe that is not deployed with a default version configuration', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeConfig: PredictedSafeProps = { ...predictedSafe, safeDeploymentConfig: {} @@ -155,7 +133,7 @@ describe('Safe Info', () => { }) it('should return the Safe contract version', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -171,7 +149,7 @@ describe('Safe Info', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to return the address of a Safe { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -189,7 +167,7 @@ describe('Safe Info', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return the address of a Safe >=v1.3.0 that is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -210,7 +188,7 @@ describe('Safe Info', () => { ) it('should return the address of a deployed Safe', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -223,7 +201,7 @@ describe('Safe Info', () => { describe('getEip1193Provider', async () => { it('should return the connected SafeProvider', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -243,7 +221,7 @@ describe('Safe Info', () => { describe('getNonce', async () => { it('should return the nonce of a Safe that is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -253,7 +231,7 @@ describe('Safe Info', () => { }) it('should return the Safe nonce', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address @@ -278,7 +256,7 @@ describe('Safe Info', () => { describe('getChainId', async () => { it('should return the chainId of a Safe that is not deployed', async () => { - const { predictedSafe, chainId, contractNetworks, provider } = await setupTests() + const { predictedSafe, chainId, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -288,7 +266,7 @@ describe('Safe Info', () => { }) it('should return the chainId of the current network', async () => { - const { safe, chainId, contractNetworks, provider } = await setupTests() + const { safe, chainId, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -303,7 +281,7 @@ describe('Safe Info', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to return the balance of a Safe { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -320,7 +298,7 @@ describe('Safe Info', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return the balance of a Safe >=v1.3.0 that is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() + const { predictedSafe, accounts, contractNetworks } = await setupTests() const [account1] = accounts const safeSdk = await Safe.init({ provider, @@ -343,7 +321,7 @@ describe('Safe Info', () => { ) it('should return the balance of a deployed Safe', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts const safeAddress = safe.address const safeSdk = await Safe.init({ diff --git a/packages/protocol-kit/tests/e2e/createSafeDeploymentTransaction.test.ts b/packages/protocol-kit/tests/e2e/createSafeDeploymentTransaction.test.ts index 9d27477a2..06ebc6ac5 100644 --- a/packages/protocol-kit/tests/e2e/createSafeDeploymentTransaction.test.ts +++ b/packages/protocol-kit/tests/e2e/createSafeDeploymentTransaction.test.ts @@ -1,50 +1,27 @@ import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' import { keccak256, toHex } from 'viem' -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { + safeVersionDeployed, + setupTests, + itif, + getSafeWithOwners, + getFactory +} from '@safe-global/testing-kit' import Safe, { PREDETERMINED_SALT_NONCE, - PredictedSafeProps, SafeProvider, encodeSetupCallData } from '@safe-global/protocol-kit/index' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners, getFactory } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' -import { itif } from './utils/helpers' chai.use(chaiAsPromised) describe('createSafeDeploymentTransaction', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - - return { - accounts, - contractNetworks, - predictedSafe, - chainId, - provider - } - }) + const provider = getEip1193Provider() itif(safeVersionDeployed == '1.4.1')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe, provider } = await setupTests() + const { contractNetworks, predictedSafe } = await setupTests() const safeSdk = await Safe.init({ provider, @@ -65,7 +42,7 @@ describe('createSafeDeploymentTransaction', () => { }) itif(safeVersionDeployed == '1.3.0')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe, provider } = await setupTests() + const { contractNetworks, predictedSafe } = await setupTests() const safeSdk = await Safe.init({ provider, @@ -86,7 +63,7 @@ describe('createSafeDeploymentTransaction', () => { }) itif(safeVersionDeployed == '1.2.0')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe, provider } = await setupTests() + const { contractNetworks, predictedSafe } = await setupTests() const safeSdk = await Safe.init({ provider, @@ -107,7 +84,7 @@ describe('createSafeDeploymentTransaction', () => { }) itif(safeVersionDeployed == '1.1.1')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe, provider } = await setupTests() + const { contractNetworks, predictedSafe } = await setupTests() const safeSdk = await Safe.init({ provider, @@ -128,7 +105,7 @@ describe('createSafeDeploymentTransaction', () => { }) itif(safeVersionDeployed == '1.0.0')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe, provider } = await setupTests() + const { contractNetworks, predictedSafe } = await setupTests() const safeSdk = await Safe.init({ provider, @@ -149,7 +126,7 @@ describe('createSafeDeploymentTransaction', () => { }) it('should contain the initializer setup call in the deployment data to sets the threshold & owners of the deployed Safe', async () => { - const { contractNetworks, predictedSafe, chainId, provider } = await setupTests() + const { contractNetworks, predictedSafe, chainId } = await setupTests() const safeSdk = await Safe.init({ provider, @@ -180,7 +157,7 @@ describe('createSafeDeploymentTransaction', () => { describe('salt nonce', () => { it('should include the predetermined salt nonce in the Safe deployment data', async () => { - const { contractNetworks, predictedSafe, chainId, provider } = await setupTests() + const { contractNetworks, predictedSafe, chainId } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeSdk = await Safe.init({ @@ -202,7 +179,7 @@ describe('createSafeDeploymentTransaction', () => { }) it('should include the custom salt nonce in the Safe deployment data', async () => { - const { contractNetworks, predictedSafe, provider } = await setupTests() + const { contractNetworks, predictedSafe } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeSdk = await Safe.init({ @@ -222,7 +199,7 @@ describe('createSafeDeploymentTransaction', () => { }) it('should include the salt nonce included in the safeDeploymentConfig in the Safe deployment data', async () => { - const { contractNetworks, predictedSafe, provider } = await setupTests() + const { contractNetworks, predictedSafe } = await setupTests() const customSaltNonce = '123456789' @@ -250,7 +227,7 @@ describe('createSafeDeploymentTransaction', () => { }) it('should throw an error if predicted Safe is not present', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) diff --git a/packages/protocol-kit/tests/e2e/createTransaction.test.ts b/packages/protocol-kit/tests/e2e/createTransaction.test.ts index de7c4caaa..83dd982ef 100644 --- a/packages/protocol-kit/tests/e2e/createTransaction.test.ts +++ b/packages/protocol-kit/tests/e2e/createTransaction.test.ts @@ -1,6 +1,5 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { safeVersionDeployed, setupTests, getERC20Mintable, itif } from '@safe-global/testing-kit' import Safe, { - PredictedSafeProps, SafeTransactionOptionalProps, standardizeSafeTransactionData, SafeContractImplementationType as SafeContract @@ -8,12 +7,7 @@ import Safe, { import { SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { itif } from './utils/helpers' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getERC20Mintable, getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { encodeFunctionData } from 'viem' chai.use(chaiAsPromised) @@ -28,39 +22,13 @@ const BASE_OPTIONS: SafeTransactionOptionalProps = { } describe('Transactions creation', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - return { - erc20Mintable: await getERC20Mintable(), - safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), - accounts, - chainId, - contractNetworks, - predictedSafe, - provider - } - }) + const provider = getEip1193Provider() describe('standardizeSafeTransactionData', async () => { itif(safeVersionDeployed >= '1.3.0')( 'should return a transaction with safeTxGas=0 if safeVersion>=1.3.0 and gasPrice=0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -68,7 +36,7 @@ describe('Transactions creation', () => { contractNetworks }) const txDataPartial: SafeTransactionDataPartial = { - to: account2.address, + to: accounts[1].address, value: '0', data: '0x' } @@ -85,9 +53,7 @@ describe('Transactions creation', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return a transaction with estimated safeTxGas if safeVersion>=1.3.0 and gasPrice>0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -95,7 +61,7 @@ describe('Transactions creation', () => { contractNetworks }) const txDataPartial: SafeTransactionDataPartial = { - to: account2.address, + to: accounts[1].address, value: '0', data: '0x', gasPrice: BASE_OPTIONS.gasPrice @@ -113,9 +79,7 @@ describe('Transactions creation', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return a transaction with defined safeTxGas if safeVersion>=1.3.0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -124,7 +88,7 @@ describe('Transactions creation', () => { }) const safeTxGas = BASE_OPTIONS.safeTxGas const txDataPartial: SafeTransactionDataPartial = { - to: account2.address, + to: accounts[1].address, value: '0', data: '0x', safeTxGas @@ -142,9 +106,7 @@ describe('Transactions creation', () => { itif(safeVersionDeployed < '1.3.0')( 'should return a transaction with estimated safeTxGas if safeVersion<1.3.0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -152,7 +114,7 @@ describe('Transactions creation', () => { contractNetworks }) const txDataPartial: SafeTransactionDataPartial = { - to: account2.address, + to: accounts[1].address, value: '0', data: '0x' } @@ -169,9 +131,7 @@ describe('Transactions creation', () => { itif(safeVersionDeployed < '1.3.0')( 'should return a transaction with defined safeTxGas of 0 if safeVersion<1.3.0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -180,7 +140,7 @@ describe('Transactions creation', () => { }) const safeTxGas = '0' const txDataPartial: SafeTransactionDataPartial = { - to: account2.address, + to: accounts[1].address, value: '0', data: '0x', safeTxGas @@ -198,9 +158,7 @@ describe('Transactions creation', () => { itif(safeVersionDeployed < '1.3.0')( 'should return a transaction with defined safeTxGas if safeVersion<1.3.0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -209,7 +167,7 @@ describe('Transactions creation', () => { }) const safeTxGas = BASE_OPTIONS.safeTxGas const txDataPartial: SafeTransactionDataPartial = { - to: account2.address, + to: accounts[1].address, value: '0', data: '0x', safeTxGas @@ -227,7 +185,7 @@ describe('Transactions creation', () => { describe('createTransaction', async () => { it('should create a single transaction with gasPrice=0', async () => { - const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() + const { predictedSafe, accounts, contractNetworks } = await setupTests() const [, account2] = accounts const safeSdk = await Safe.init({ provider, @@ -248,9 +206,7 @@ describe('Transactions creation', () => { }) it('should create a single transaction with gasPrice=0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -258,7 +214,7 @@ describe('Transactions creation', () => { contractNetworks }) const safeTransactionData = { - to: account2.address, + to: accounts[1].address, value: '500000000000000000', // 0.5 ETH data: '0x' } @@ -266,7 +222,7 @@ describe('Transactions creation', () => { transactions: [safeTransactionData], options: BASE_OPTIONS }) - chai.expect(tx.data.to).to.be.eq(account2.address) + chai.expect(tx.data.to).to.be.eq(accounts[1].address) chai.expect(tx.data.value).to.be.eq('500000000000000000') chai.expect(tx.data.data).to.be.eq('0x') chai.expect(tx.data.baseGas).to.be.eq(BASE_OPTIONS.baseGas) @@ -278,9 +234,7 @@ describe('Transactions creation', () => { }) it('should create a single transaction with gasPrice>0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -288,7 +242,7 @@ describe('Transactions creation', () => { contractNetworks }) const safeTransactionData = { - to: account2.address, + to: accounts[1].address, value: '500000000000000000', // 0.5 ETH data: '0x' } @@ -296,7 +250,7 @@ describe('Transactions creation', () => { transactions: [safeTransactionData], options: BASE_OPTIONS }) - chai.expect(tx.data.to).to.be.eq(account2.address) + chai.expect(tx.data.to).to.be.eq(accounts[1].address) chai.expect(tx.data.value).to.be.eq('500000000000000000') chai.expect(tx.data.data).to.be.eq('0x') chai.expect(tx.data.baseGas).to.be.eq(BASE_OPTIONS.baseGas) @@ -308,9 +262,7 @@ describe('Transactions creation', () => { }) it('should create a single transaction when passing a transaction array with length=1', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -318,20 +270,18 @@ describe('Transactions creation', () => { contractNetworks }) const safeTransactionData = { - to: account2.address, + to: accounts[1].address, value: '500000000000000000', // 0.5 ETH data: '0x' } const tx = await safeSdk.createTransaction({ transactions: [safeTransactionData] }) - chai.expect(tx.data.to).to.be.eq(account2.address) + chai.expect(tx.data.to).to.be.eq(accounts[1].address) chai.expect(tx.data.value).to.be.eq('500000000000000000') chai.expect(tx.data.data).to.be.eq('0x') }) it('should create a single transaction when passing a transaction array with length=1 and options', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -339,13 +289,13 @@ describe('Transactions creation', () => { contractNetworks }) const safeTransactionData = { - to: account2.address, + to: accounts[1].address, value: '500000000000000000', // 0.5 ETH data: '0x' } const options: SafeTransactionOptionalProps = BASE_OPTIONS const tx = await safeSdk.createTransaction({ transactions: [safeTransactionData], options }) - chai.expect(tx.data.to).to.be.eq(account2.address) + chai.expect(tx.data.to).to.be.eq(accounts[1].address) chai.expect(tx.data.value).to.be.eq('500000000000000000') chai.expect(tx.data.data).to.be.eq('0x') chai.expect(tx.data.baseGas).to.be.eq(BASE_OPTIONS.baseGas) @@ -357,9 +307,7 @@ describe('Transactions creation', () => { }) it('should fail when creating a MultiSend transaction passing a transaction array with length=0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -371,9 +319,8 @@ describe('Transactions creation', () => { }) it('should create a MultiSend transaction', async () => { - const { accounts, contractNetworks, erc20Mintable, chainId, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks, chainId } = await setupTests() + const erc20Mintable = await getERC20Mintable() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -387,7 +334,7 @@ describe('Transactions creation', () => { data: encodeFunctionData({ abi: erc20Mintable.abi, functionName: 'transfer', - args: [account2.address, '1100000000000000000'] // 1.1 ERC20 + args: [accounts[1].address, '1100000000000000000'] // 1.1 ERC20 }) }, { @@ -396,7 +343,7 @@ describe('Transactions creation', () => { data: encodeFunctionData({ abi: erc20Mintable.abi, functionName: 'transfer', - args: [account2.address, '100000000000000000'] // 0.1 ERC20 + args: [accounts[1].address, '100000000000000000'] // 0.1 ERC20 }) } ] @@ -407,9 +354,8 @@ describe('Transactions creation', () => { }) it('should create a MultiSend transaction with options', async () => { - const { accounts, contractNetworks, erc20Mintable, chainId, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks, chainId } = await setupTests() + const erc20Mintable = await getERC20Mintable() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -425,7 +371,7 @@ describe('Transactions creation', () => { data: encodeFunctionData({ abi: erc20Mintable.abi, functionName: 'transfer', - args: [account2.address, '1100000000000000000'] // 1.1 ERC20 + args: [accounts[1].address, '1100000000000000000'] // 1.1 ERC20 }) }, { @@ -434,7 +380,7 @@ describe('Transactions creation', () => { data: encodeFunctionData({ abi: erc20Mintable.abi, functionName: 'transfer', - args: [account2.address, '100000000000000000'] // 0.1 ERC20 + args: [accounts[1].address, '100000000000000000'] // 0.1 ERC20 }) } ] @@ -454,7 +400,7 @@ describe('Transactions creation', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to create a transaction if the Safe with version { - const { safe, predictedSafe, contractNetworks, provider } = await setupTests() + const { safe, predictedSafe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, diff --git a/packages/protocol-kit/tests/e2e/createTransactionBatch.test.ts b/packages/protocol-kit/tests/e2e/createTransactionBatch.test.ts index 373cdfdf0..db738b506 100644 --- a/packages/protocol-kit/tests/e2e/createTransactionBatch.test.ts +++ b/packages/protocol-kit/tests/e2e/createTransactionBatch.test.ts @@ -1,12 +1,8 @@ import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { PredictedSafeProps } from '@safe-global/protocol-kit/index' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners, getMultiSendCallOnly } from './utils/setupContracts' +import { setupTests, getMultiSendCallOnly } from '@safe-global/testing-kit' +import Safe from '@safe-global/protocol-kit/index' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { OperationType } from '@safe-global/safe-core-sdk-types' import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' @@ -15,35 +11,9 @@ chai.use(chaiAsPromised) const AMOUNT_TO_TRANSFER = '500000000000000000' // 0.5 ETH describe('createTransactionBatch', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - - return { - accounts, - contractNetworks, - predictedSafe, - chainId - } - }) - it('should return a batch of the provided transactions', async () => { - const { accounts, contractNetworks } = await setupTests() - const [account1] = accounts + const { safe, contractNetworks } = await setupTests() - const safe = await getSafeWithOwners([account1.address]) const provider = getEip1193Provider() const safeAddress = safe.address diff --git a/packages/protocol-kit/tests/e2e/eip1271-contract-signatures.test.ts b/packages/protocol-kit/tests/e2e/eip1271-contract-signatures.test.ts index ff76522f1..58e00b76f 100644 --- a/packages/protocol-kit/tests/e2e/eip1271-contract-signatures.test.ts +++ b/packages/protocol-kit/tests/e2e/eip1271-contract-signatures.test.ts @@ -1,27 +1,24 @@ import Safe, { buildContractSignature, hashSafeMessage } from '@safe-global/protocol-kit/index' -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { + safeVersionDeployed, + setupTests as testingKitSetupTests, + getSafeWithOwners, + itif +} from '@safe-global/testing-kit' import { SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types' import { SigningMethod } from '@safe-global/protocol-kit/types' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' -import { itif } from './utils/helpers' chai.use(chaiAsPromised) describe('The EIP1271 implementation', () => { describe('In the context of a 3/3 Safe account with a 4/4 signer Safe account owner', async () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = await getChainId() - const contractNetworks = await getContractNetworks(BigInt(chainId)) - const fallbackHandlerAddress = contractNetworks[chainId].fallbackHandlerAddress + const setupTests = async () => { + const { chainId, accounts, contractNetworks } = await testingKitSetupTests() + const fallbackHandlerAddress = contractNetworks[Number(chainId)].fallbackHandlerAddress const [account1, account2, account3, account4, account5] = accounts const provider = getEip1193Provider() @@ -63,7 +60,7 @@ describe('The EIP1271 implementation', () => { fallbackHandlerAddress, provider } - }) + } itif(safeVersionDeployed >= '1.3.0')( 'should allow to sign and execute transactions', diff --git a/packages/protocol-kit/tests/e2e/eip1271.test.ts b/packages/protocol-kit/tests/e2e/eip1271.test.ts index 4ffa84d61..8447a6900 100644 --- a/packages/protocol-kit/tests/e2e/eip1271.test.ts +++ b/packages/protocol-kit/tests/e2e/eip1271.test.ts @@ -6,19 +6,19 @@ import Safe, { buildContractSignature, EthSafeSignature } from '@safe-global/protocol-kit/index' -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { + safeVersionDeployed, + setupTests as testingKitSetupTests, + getSafeWithOwners, + itif +} from '@safe-global/testing-kit' import SafeMessage from '@safe-global/protocol-kit/utils/messages/SafeMessage' import { OperationType, SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types' import { SigningMethod } from '@safe-global/protocol-kit/types' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' -import { itif } from './utils/helpers' import semverSatisfies from 'semver/functions/satisfies' import { asHash } from '@safe-global/protocol-kit/utils/types' @@ -42,12 +42,9 @@ const MESSAGE = 'I am the owner of this Safe account' describe('The EIP1271 implementation', () => { describe('In the context of a 2/3 Safe and a 1/1 signer Safe account', async () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = await getChainId() - const contractNetworks = await getContractNetworks(BigInt(chainId)) - const fallbackHandlerAddress = contractNetworks[chainId].fallbackHandlerAddress + const setupTests = async () => { + const { accounts, contractNetworks, chainId } = await testingKitSetupTests() + const fallbackHandlerAddress = contractNetworks[Number(chainId)].fallbackHandlerAddress const [account1, account2] = accounts const provider = getEip1193Provider() @@ -103,7 +100,7 @@ describe('The EIP1271 implementation', () => { safeSdk3, fallbackHandlerAddress } - }) + } itif(safeVersionDeployed >= '1.3.0')( 'should validate on-chain messages (Approved hashes)', diff --git a/packages/protocol-kit/tests/e2e/erc-20.test.ts b/packages/protocol-kit/tests/e2e/erc-20.test.ts index de27538be..0f840a398 100644 --- a/packages/protocol-kit/tests/e2e/erc-20.test.ts +++ b/packages/protocol-kit/tests/e2e/erc-20.test.ts @@ -4,18 +4,12 @@ import Safe, { getERC20Decimals, isGasTokenCompatibleWithHandlePayment } from '@safe-global/protocol-kit/index' -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { safeVersionDeployed, setupTests, itif } from '@safe-global/testing-kit' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' import sinon from 'sinon' import sinonChai from 'sinon-chai' -import { deployments } from 'hardhat' - -import { itif } from './utils/helpers' import { getEip1193Provider } from './utils/setupProvider' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' -import { getAccounts } from './utils/setupTestNetwork' import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' chai.use(sinonChai) @@ -30,26 +24,13 @@ describe('ERC-20 utils', () => { callStub.restore() }) - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - - return { - safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), - contractNetworks, - accounts, - provider - } - }) + const provider = getEip1193Provider() describe('getERC20Decimals', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return the correct decimals for a standard ERC20 token', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address @@ -71,7 +52,7 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return the correct decimals for a non-standard ERC20 token', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address // mock decimals() call @@ -92,7 +73,7 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should throw an error if decimals() fn is not defined', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address // mock decimals() call @@ -115,7 +96,7 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return true if it is the Native token', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -136,7 +117,7 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return true if it is an standard ERC20 token', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address // mock decimals() call @@ -160,7 +141,7 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return false for a non-standard ERC20 token', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address // mock decimals() call diff --git a/packages/protocol-kit/tests/e2e/execution.test.ts b/packages/protocol-kit/tests/e2e/execution.test.ts index 07e4821ce..0daefcca0 100644 --- a/packages/protocol-kit/tests/e2e/execution.test.ts +++ b/packages/protocol-kit/tests/e2e/execution.test.ts @@ -1,41 +1,20 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { getERC20Mintable, safeVersionDeployed, setupTests, itif } from '@safe-global/testing-kit' import Safe, { SigningMethod } from '@safe-global/protocol-kit/index' import { TransactionOptions, MetaTransactionData } from '@safe-global/safe-core-sdk-types' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { itif } from './utils/helpers' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getERC20Mintable, getSafeWithOwners } from './utils/setupContracts' -import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' import { encodeFunctionData } from 'viem' +import { getEip1193Provider } from './utils/setupProvider' chai.use(chaiAsPromised) describe('Transactions execution', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - - return { - erc20Mintable: await getERC20Mintable(), - safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), - accounts, - contractNetworks, - provider - } - }) - + const provider = getEip1193Provider() describe('isValidTransaction', async () => { it('should return false if a transaction will not be executed successfully', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -69,9 +48,8 @@ describe('Transactions execution', () => { }) it('should return true if a transaction will execute successfully', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -98,9 +76,8 @@ describe('Transactions execution', () => { describe('executeTransaction', async () => { it('should fail if there are not enough Ether funds', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -121,9 +98,10 @@ describe('Transactions execution', () => { }) it('should fail if there are not enough signatures (1 missing)', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2, account3] = accounts - const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) + const [, account2] = accounts const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -150,9 +128,9 @@ describe('Transactions execution', () => { }) it('should fail if there are not enough signatures (>1 missing)', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2, account3] = accounts - const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) + const { safe, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -171,9 +149,8 @@ describe('Transactions execution', () => { }) it('should fail if the user tries to execute a transaction that was rejected', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -220,9 +197,8 @@ describe('Transactions execution', () => { }) it('should fail if a user tries to execute a transaction with options: { nonce: }', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -246,9 +222,8 @@ describe('Transactions execution', () => { }) it('should execute a transaction with threshold 1', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -278,15 +253,10 @@ describe('Transactions execution', () => { itif(safeVersionDeployed === '1.0.0')( 'should execute a transaction with threshold >1 and all different kind of signatures and safeVersion===1.0.0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 5, threshold: 5 } + }) const [account1, account2, account3, account4, account5] = accounts - const safe = await getSafeWithOwners([ - account1.address, - account2.address, - account3.address, - account4.address, - account5.address - ]) const safeAddress = safe.address await account1.signer.sendTransaction({ to: safeAddress, @@ -345,16 +315,10 @@ describe('Transactions execution', () => { itif(safeVersionDeployed > '1.0.0')( 'should execute a transaction with threshold >1 and all different kind of signatures and safeVersion>1.0.0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 6, threshold: 6 } + }) const [account1, account2, account3, account4, account5, account6] = accounts - const safe = await getSafeWithOwners([ - account1.address, - account2.address, - account3.address, - account4.address, - account5.address, - account6.address - ]) const safeAddress = safe.address await account1.signer.sendTransaction({ to: safeAddress, @@ -417,7 +381,9 @@ describe('Transactions execution', () => { ) it('should execute a transaction when is not submitted by an owner', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 2, threshold: 2 } + }) const [, account2, account3] = accounts const safeAddress = safe.address const safeSdk1 = await Safe.init({ @@ -455,9 +421,8 @@ describe('Transactions execution', () => { }) it('should execute a transaction with options: { gasLimit }', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -482,9 +447,8 @@ describe('Transactions execution', () => { }) it('should execute a transaction with options: { gasLimit, gasPrice }', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -513,9 +477,8 @@ describe('Transactions execution', () => { }) it('should execute a transaction with options: { maxFeePerGas, maxPriorityFeePerGas }', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -546,9 +509,8 @@ describe('Transactions execution', () => { }) it('should execute a transaction with options: { nonce }', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -576,9 +538,10 @@ describe('Transactions execution', () => { describe('executeTransaction (MultiSend)', async () => { it('should execute a batch transaction with threshold >1', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1, account2, account3] = accounts - const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, @@ -624,9 +587,11 @@ describe('Transactions execution', () => { }) it('should execute a batch transaction with contract calls and threshold >1', async () => { - const { accounts, contractNetworks, erc20Mintable, provider } = await setupTests() - const [account1, account2, account3] = accounts - const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) + const erc20Mintable = await getERC20Mintable() + const [, account2, account3] = accounts const safeAddress = safe.address const safeSdk1 = await Safe.init({ provider, diff --git a/packages/protocol-kit/tests/e2e/fallbackHandlerManager.test.ts b/packages/protocol-kit/tests/e2e/fallbackHandlerManager.test.ts index c1fb48214..b86d698f0 100644 --- a/packages/protocol-kit/tests/e2e/fallbackHandlerManager.test.ts +++ b/packages/protocol-kit/tests/e2e/fallbackHandlerManager.test.ts @@ -1,57 +1,28 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { - PredictedSafeProps, - SafeTransactionOptionalProps -} from '@safe-global/protocol-kit/index' -import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' -import chai from 'chai' -import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { itif } from './utils/helpers' -import { getContractNetworks } from './utils/setupContractNetworks' import { + safeVersionDeployed, + setupTests, getCompatibilityFallbackHandler, getDefaultCallbackHandler, - getSafeWithOwners -} from './utils/setupContracts' + getSafeWithOwners, + itif +} from '@safe-global/testing-kit' +import Safe, { SafeTransactionOptionalProps } from '@safe-global/protocol-kit/index' +import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' +import chai from 'chai' +import chaiAsPromised from 'chai-as-promised' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' chai.use(chaiAsPromised) describe('Fallback handler manager', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - const provider = getEip1193Provider() - - return { - safe: await getSafeWithOwners([accounts[0].address]), - accounts, - contractNetworks, - defaultCallbackHandler: await getDefaultCallbackHandler(), - predictedSafe, - provider - } - }) + const provider = getEip1193Provider() describe('getFallbackHandler', async () => { itif(safeVersionDeployed < '1.1.1')( 'should fail if getting the enabled fallback handler is not supported', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -68,7 +39,7 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -78,7 +49,8 @@ describe('Fallback handler manager', () => { }) itif(safeVersionDeployed >= '1.1.1')('should return the enabled fallback handler', async () => { - const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -100,8 +72,8 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if the Safe with version { - const { predictedSafe, contractNetworks, defaultCallbackHandler, provider } = - await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -119,8 +91,8 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should fail if the Safe with version >=v1.3.0 is not deployed', async () => { - const { predictedSafe, contractNetworks, defaultCallbackHandler, provider } = - await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -134,7 +106,8 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.1.1')( 'should fail if enabling a fallback handler is not supported', async () => { - const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -151,7 +124,7 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should fail if address is invalid', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -165,7 +138,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.1.1')( 'should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -178,7 +151,8 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should fail if address is already enabled', async () => { - const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -195,7 +169,8 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.1.1')( 'should build the transaction with the optional props', async () => { - const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -224,7 +199,8 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should enable a fallback handler', async () => { - const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -246,7 +222,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if the Safe with version { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -264,14 +240,13 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should fail if the Safe with version >=v1.3.0 is not deployed', async () => { - const { predictedSafe, contractNetworks, defaultCallbackHandler, provider } = - await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, contractNetworks }) - const tx = safeSdk.createDisableFallbackHandlerTx(defaultCallbackHandler.address) + const tx = safeSdk.createDisableFallbackHandlerTx() await chai.expect(tx).to.be.rejectedWith('Safe is not deployed') } ) @@ -279,7 +254,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.1.1')( 'should fail if disabling a fallback handler is not supported', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address @@ -300,7 +275,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.1.1')( 'should fail if no fallback handler is enabled', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -321,7 +296,8 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.1.1')( 'should build the transaction with the optional props', async () => { - const { accounts, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address @@ -354,7 +330,8 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should disable an enabled fallback handler', async () => { - const { accounts, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address diff --git a/packages/protocol-kit/tests/e2e/getEncodedTransaction.test.ts b/packages/protocol-kit/tests/e2e/getEncodedTransaction.test.ts index 150a2116c..a19c34668 100644 --- a/packages/protocol-kit/tests/e2e/getEncodedTransaction.test.ts +++ b/packages/protocol-kit/tests/e2e/getEncodedTransaction.test.ts @@ -1,33 +1,15 @@ import Safe from '@safe-global/protocol-kit/index' -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { safeVersionDeployed, setupTests, itif } from '@safe-global/testing-kit' import chai from 'chai' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' -import { itif } from './utils/helpers' describe('getEncodedTransaction', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - - return { - accounts, - contractNetworks, - provider - } - }) + const provider = getEip1193Provider() itif(safeVersionDeployed >= '1.3.0')('should return a transaction encoded', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -54,10 +36,8 @@ describe('getEncodedTransaction', () => { }) itif(safeVersionDeployed <= '1.2.0')('should return a transaction encoded', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -84,10 +64,8 @@ describe('getEncodedTransaction', () => { }) it('should return a signed transaction with the signatures encoded', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeAddress = safe.address const safeSdk = await Safe.init({ diff --git a/packages/protocol-kit/tests/e2e/guardManager.test.ts b/packages/protocol-kit/tests/e2e/guardManager.test.ts index f1c13d026..38cc9ea9f 100644 --- a/packages/protocol-kit/tests/e2e/guardManager.test.ts +++ b/packages/protocol-kit/tests/e2e/guardManager.test.ts @@ -1,52 +1,26 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { - PredictedSafeProps, - SafeTransactionOptionalProps -} from '@safe-global/protocol-kit/index' +import { + safeVersionDeployed, + setupTests, + getDebugTransactionGuard, + itif +} from '@safe-global/testing-kit' +import Safe, { SafeTransactionOptionalProps } from '@safe-global/protocol-kit/index' import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { itif } from './utils/helpers' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getDebugTransactionGuard, getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' chai.use(chaiAsPromised) describe('Safe guard manager', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - return { - debugTransactionGuard: await getDebugTransactionGuard(), - safe: await getSafeWithOwners([accounts[0].address]), - accounts, - contractNetworks, - predictedSafe, - provider - } - }) + const provider = getEip1193Provider() describe('getGuard', async () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if getting the enabled guard is not supported', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -63,7 +37,7 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -75,7 +49,7 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return 0x address when no Safe guard is enabled', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -87,7 +61,8 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should return the enabled Safe guard', async () => { - const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const debugTransactionGuard = await getDebugTransactionGuard() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -106,7 +81,8 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if enabling a Safe guard is not supported', async () => { - const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const debugTransactionGuard = await getDebugTransactionGuard() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -123,9 +99,8 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should fail if the Safe is not deployed', async () => { - const { predictedSafe, debugTransactionGuard, contractNetworks, provider } = - await setupTests() - + const { predictedSafe, contractNetworks } = await setupTests() + const debugTransactionGuard = await getDebugTransactionGuard() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -136,7 +111,7 @@ describe('Safe guard manager', () => { }) itif(safeVersionDeployed >= '1.3.0')('should fail if address is invalid', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -150,7 +125,7 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -164,7 +139,8 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should fail if address is already enabled', async () => { - const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const debugTransactionGuard = await getDebugTransactionGuard() const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -182,7 +158,8 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should build the transaction with the optional props', async () => { - const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const debugTransactionGuard = await getDebugTransactionGuard() const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -209,7 +186,8 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should enable a Safe guard', async () => { - const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const debugTransactionGuard = await getDebugTransactionGuard() const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -229,9 +207,7 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if disabling a Safe guard is not supported', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -248,7 +224,7 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, @@ -260,7 +236,7 @@ describe('Safe guard manager', () => { }) itif(safeVersionDeployed >= '1.3.0')('should fail if no Safe guard is enabled', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -275,9 +251,8 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should build the transaction with the optional props', async () => { - const { accounts, contractNetworks, debugTransactionGuard, provider } = await setupTests() - const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, contractNetworks } = await setupTests() + const debugTransactionGuard = await getDebugTransactionGuard() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -307,9 +282,8 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should disable an enabled Safe guard', async () => { - const { accounts, contractNetworks, debugTransactionGuard, provider } = await setupTests() - const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, contractNetworks } = await setupTests() + const debugTransactionGuard = await getDebugTransactionGuard() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, diff --git a/packages/protocol-kit/tests/e2e/moduleManager.test.ts b/packages/protocol-kit/tests/e2e/moduleManager.test.ts index 79d4cb397..72cceb1d9 100644 --- a/packages/protocol-kit/tests/e2e/moduleManager.test.ts +++ b/packages/protocol-kit/tests/e2e/moduleManager.test.ts @@ -1,60 +1,27 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { - PredictedSafeProps, - SafeTransactionOptionalProps -} from '@safe-global/protocol-kit/index' -import { SENTINEL_ADDRESS, ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' -import chai from 'chai' -import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' import { getDailyLimitModule, getSafeWithOwners, getSocialRecoveryModule, getStateChannelModule, - getWhiteListModule -} from './utils/setupContracts' + getWhiteListModule, + setupTests +} from '@safe-global/testing-kit' +import Safe, { SafeTransactionOptionalProps } from '@safe-global/protocol-kit/index' +import { SENTINEL_ADDRESS, ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' +import chai from 'chai' +import chaiAsPromised from 'chai-as-promised' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' import semverSatisfies from 'semver/functions/satisfies' chai.use(chaiAsPromised) describe('Safe modules manager', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - const provider = getEip1193Provider() - - return { - dailyLimitModule: await getDailyLimitModule(), - socialRecoveryModule: await getSocialRecoveryModule(), - stateChannelModule: await getStateChannelModule(), - whiteListModule: await getWhiteListModule(), - safe: await getSafeWithOwners([accounts[0].address]), - accounts, - contractNetworks, - predictedSafe, - provider - } - }) + const provider = getEip1193Provider() describe('getModules', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -64,8 +31,9 @@ describe('Safe modules manager', () => { }) it('should return all the enabled modules', async () => { - const { safe, dailyLimitModule, socialRecoveryModule, contractNetworks, provider } = - await setupTests() + const { safe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() + const socialRecoveryModule = await getSocialRecoveryModule() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -91,7 +59,7 @@ describe('Safe modules manager', () => { describe('getModulesPaginated', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -103,7 +71,8 @@ describe('Safe modules manager', () => { }) it('should return the enabled modules', async () => { - const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -124,15 +93,11 @@ describe('Safe modules manager', () => { }) it('should constraint returned modules by pageSize', async () => { - const { - safe, - dailyLimitModule, - contractNetworks, - socialRecoveryModule, - stateChannelModule, - whiteListModule, - provider - } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() + const socialRecoveryModule = await getSocialRecoveryModule() + const stateChannelModule = await getStateChannelModule() + const whiteListModule = await getWhiteListModule() const safeAddress = safe.address const dailyLimitsAddress = dailyLimitModule.address const socialRecoveryAddress = socialRecoveryModule.address @@ -192,20 +157,13 @@ describe('Safe modules manager', () => { }) it('should offset the returned modules', async () => { - const { - safe, - dailyLimitModule, - contractNetworks, - socialRecoveryModule, - stateChannelModule, - whiteListModule, - provider - } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address - const dailyLimitsAddress = dailyLimitModule.address - const socialRecoveryAddress = socialRecoveryModule.address - const stateChannelAddress = stateChannelModule.address - const whiteListAddress = whiteListModule.address + const dailyLimitModule = await getDailyLimitModule() + const socialRecoveryModule = await getSocialRecoveryModule() + const stateChannelModule = await getStateChannelModule() + const whiteListModule = await getWhiteListModule() + const safeSdk = await Safe.init({ provider, safeAddress, @@ -214,10 +172,10 @@ describe('Safe modules manager', () => { const currentPageNext = semverSatisfies(await safeSdk.getContractVersion(), '>=1.4.1') const moduleDeployment = [ - dailyLimitsAddress, - socialRecoveryAddress, - stateChannelAddress, - whiteListAddress + dailyLimitModule.address, + socialRecoveryModule.address, + stateChannelModule.address, + whiteListModule.address ].map(async (moduleAddress) => { const txModule = await safeSdk.createEnableModuleTx(moduleAddress) const moduleResponse = await safeSdk.executeTransaction(txModule) @@ -246,7 +204,7 @@ describe('Safe modules manager', () => { }) it('should fail if pageSize is invalid', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -261,7 +219,8 @@ describe('Safe modules manager', () => { describe('isModuleEnabled', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -272,7 +231,8 @@ describe('Safe modules manager', () => { }) it('should return true if a module is enabled', async () => { - const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -289,7 +249,8 @@ describe('Safe modules manager', () => { describe('createEnableModuleTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -300,7 +261,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is invalid', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -312,7 +273,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is equal to sentinel', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -324,7 +285,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -336,7 +297,8 @@ describe('Safe modules manager', () => { }) it('should fail if address is already enabled', async () => { - const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -351,7 +313,8 @@ describe('Safe modules manager', () => { }) it('should build the transaction with the optional props', async () => { - const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -376,7 +339,8 @@ describe('Safe modules manager', () => { }) it('should enable a Safe module', async () => { - const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -395,7 +359,8 @@ describe('Safe modules manager', () => { describe('createDisableModuleTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -406,7 +371,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is invalid', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -418,7 +383,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is equal to sentinel', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -430,7 +395,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -442,7 +407,8 @@ describe('Safe modules manager', () => { }) it('should fail if address is not enabled', async () => { - const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -454,7 +420,8 @@ describe('Safe modules manager', () => { }) it('should build the transaction with the optional props', async () => { - const { dailyLimitModule, accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address @@ -488,8 +455,9 @@ describe('Safe modules manager', () => { }) it('should disable Safe modules', async () => { - const { dailyLimitModule, accounts, socialRecoveryModule, contractNetworks, provider } = - await setupTests() + const { accounts, contractNetworks } = await setupTests() + const dailyLimitModule = await getDailyLimitModule() + const socialRecoveryModule = await getSocialRecoveryModule() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = safe.address diff --git a/packages/protocol-kit/tests/e2e/offChainSignatures.test.ts b/packages/protocol-kit/tests/e2e/offChainSignatures.test.ts index 1746ce278..539784ea1 100644 --- a/packages/protocol-kit/tests/e2e/offChainSignatures.test.ts +++ b/packages/protocol-kit/tests/e2e/offChainSignatures.test.ts @@ -1,46 +1,18 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { PredictedSafeProps, SigningMethod } from '@safe-global/protocol-kit/index' +import { safeVersionDeployed, setupTests, itif } from '@safe-global/testing-kit' +import Safe, { SigningMethod } from '@safe-global/protocol-kit/index' import { SafeMultisigTransactionResponse } from '@safe-global/safe-core-sdk-types' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { itif } from './utils/helpers' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' chai.use(chaiAsPromised) describe('Off-chain signatures', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - const provider = getEip1193Provider() - - return { - safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), - accounts, - contractNetworks, - predictedSafe, - provider - } - }) + const provider = getEip1193Provider() describe('signHash', async () => { it('should sign a transaction hash with the current signer if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -52,7 +24,7 @@ describe('Off-chain signatures', () => { }) it('should sign a transaction hash with the current signer', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -75,7 +47,7 @@ describe('Off-chain signatures', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to sign a transaction if the Safe with version { - const { safe, predictedSafe, contractNetworks, provider } = await setupTests() + const { safe, predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -107,7 +79,7 @@ describe('Off-chain signatures', () => { itif(safeVersionDeployed >= '1.3.0')( 'should sign a transaction with the current signer if the Safe with version >=v1.3.0 is using predicted config', async () => { - const { safe, predictedSafe, contractNetworks, provider } = await setupTests() + const { safe, predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -128,7 +100,7 @@ describe('Off-chain signatures', () => { ) it('should fail if the signature is added by an account that is not an owner', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const account3 = accounts[2] const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -149,7 +121,7 @@ describe('Off-chain signatures', () => { }) it('should ignore duplicated signatures', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -173,7 +145,7 @@ describe('Off-chain signatures', () => { itif(safeVersionDeployed === '1.0.0')( 'should fail if the signature of the current signer is added using eth_sign and safeVersion===1.0.0', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -195,7 +167,7 @@ describe('Off-chain signatures', () => { itif(safeVersionDeployed > '1.0.0')( 'should add the signature of the current signer using eth_sign if safeVersion>1.0.0', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -216,7 +188,7 @@ describe('Off-chain signatures', () => { ) it('should add the signature of the current signer using eth_signTypedData', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -236,7 +208,7 @@ describe('Off-chain signatures', () => { }) it('should add the signature of the current signer using eth_signTypedData_v3', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -256,7 +228,7 @@ describe('Off-chain signatures', () => { }) it('should add the signature of the current signer using eth_signTypedData_v4', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -276,7 +248,7 @@ describe('Off-chain signatures', () => { }) it('should add the signature of the current signer using eth_signTypedData_v4 by default', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeAddress = safe.address const safeSdk = await Safe.init({ provider, @@ -296,7 +268,7 @@ describe('Off-chain signatures', () => { }) it('should sign a transaction received from the Safe Transaction Service', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeAddress = safe.address const safeSdk = await Safe.init({ @@ -304,7 +276,7 @@ describe('Off-chain signatures', () => { safeAddress, contractNetworks }) - const safeServiceTransaction: SafeMultisigTransactionResponse = { + const safeServiceTransaction = { safe: '', to: account2.address, value: '500000000000000000', // 0.5 ETH @@ -352,7 +324,9 @@ describe('Off-chain signatures', () => { trusted: true, signatures: '0x111111222222' } - const signedTx = await safeSdk.signTransaction(safeServiceTransaction) + const signedTx = await safeSdk.signTransaction( + safeServiceTransaction as SafeMultisigTransactionResponse + ) chai.expect(safeServiceTransaction.confirmations?.length).to.be.eq(2) chai.expect(signedTx.signatures.size).to.be.eq(3) const signerAddress = account1.address diff --git a/packages/protocol-kit/tests/e2e/onChainSignatures.test.ts b/packages/protocol-kit/tests/e2e/onChainSignatures.test.ts index 9a6724fc5..d9dba53a1 100644 --- a/packages/protocol-kit/tests/e2e/onChainSignatures.test.ts +++ b/packages/protocol-kit/tests/e2e/onChainSignatures.test.ts @@ -1,45 +1,19 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { PredictedSafeProps } from '@safe-global/protocol-kit/index' +import { setupTests } from '@safe-global/testing-kit' +import Safe from '@safe-global/protocol-kit/index' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' chai.use(chaiAsPromised) describe('On-chain signatures', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - const provider = getEip1193Provider() - - return { - safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), - accounts, - contractNetworks, - predictedSafe, - provider - } - }) - + const provider = getEip1193Provider() describe('approveTransactionHash', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 2, threshold: 2 } + }) const safeSdk1 = await Safe.init({ provider, predictedSafe, @@ -52,7 +26,9 @@ describe('On-chain signatures', () => { }) it('should fail if a transaction hash is approved by an account that is not an owner', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 2, threshold: 2 } + }) const account3 = accounts[2] const safeAddress = safe.address const safeSdk1 = await Safe.init({ @@ -74,7 +50,9 @@ describe('On-chain signatures', () => { }) it('should approve the transaction hash', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 2, threshold: 2 } + }) const [account1] = accounts const safeAddress = safe.address const safeSdk1 = await Safe.init({ @@ -95,7 +73,9 @@ describe('On-chain signatures', () => { }) it('should ignore a duplicated signatures', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 2, threshold: 2 } + }) const [account1] = accounts const safeAddress = safe.address const safeSdk1 = await Safe.init({ @@ -122,7 +102,9 @@ describe('On-chain signatures', () => { describe('getOwnersWhoApprovedTx', async () => { it('should fail if Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 2, threshold: 2 } + }) const safeSdk1 = await Safe.init({ provider, predictedSafe, @@ -134,7 +116,9 @@ describe('On-chain signatures', () => { }) it('should return the list of owners who approved a transaction hash', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 2, threshold: 2 } + }) const [, account2] = accounts const safeAddress = safe.address const safeSdk1 = await Safe.init({ diff --git a/packages/protocol-kit/tests/e2e/ownerManager.test.ts b/packages/protocol-kit/tests/e2e/ownerManager.test.ts index 6c3213b91..ff1694a25 100644 --- a/packages/protocol-kit/tests/e2e/ownerManager.test.ts +++ b/packages/protocol-kit/tests/e2e/ownerManager.test.ts @@ -1,52 +1,20 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { - PredictedSafeProps, - SafeTransactionOptionalProps -} from '@safe-global/protocol-kit/index' +import { setupTests } from '@safe-global/testing-kit' +import Safe, { SafeTransactionOptionalProps } from '@safe-global/protocol-kit/index' import { SENTINEL_ADDRESS, ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' chai.use(chaiAsPromised) describe('Safe owners manager', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - return { - safe: await getSafeWithOwners([ - accounts[0].address, - accounts[1].address, - accounts[2].address - ]), - accounts, - contractNetworks, - predictedSafe, - provider - } - }) - + const provider = getEip1193Provider() describe('getOwners', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const safeSdk = await Safe.init({ provider, predictedSafe, @@ -56,9 +24,10 @@ describe('Safe owners manager', () => { }) it('should return the list of Safe owners', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 2, threshold: 2 } + }) const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address, account2.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -73,7 +42,9 @@ describe('Safe owners manager', () => { describe('isOwner', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() + const { predictedSafe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1] = accounts const safeSdk = await Safe.init({ provider, @@ -84,9 +55,8 @@ describe('Safe owners manager', () => { }) it('should return true if an account is an owner of the connected Safe', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -97,9 +67,8 @@ describe('Safe owners manager', () => { }) it('should return false if an account is not an owner of the connected Safe', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -112,7 +81,9 @@ describe('Safe owners manager', () => { describe('createAddOwnerTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() + const { predictedSafe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [, account2] = accounts const safeSdk = await Safe.init({ provider, @@ -124,9 +95,7 @@ describe('Safe owners manager', () => { }) it('should fail if address is invalid', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -137,9 +106,7 @@ describe('Safe owners manager', () => { }) it('should fail if address is equal to sentinel', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -150,9 +117,7 @@ describe('Safe owners manager', () => { }) it('should fail if address is equal to 0x address', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -163,9 +128,8 @@ describe('Safe owners manager', () => { }) it('should fail if address is already an owner', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -176,9 +140,8 @@ describe('Safe owners manager', () => { }) it('should fail if the threshold is bigger than the number of owners', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -195,9 +158,8 @@ describe('Safe owners manager', () => { }) it('should fail if the threshold is not bigger than 0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -208,9 +170,8 @@ describe('Safe owners manager', () => { }) it('should build the transaction with the optional props', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -234,9 +195,8 @@ describe('Safe owners manager', () => { }) it('should add an owner and keep the same threshold', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -258,9 +218,8 @@ describe('Safe owners manager', () => { }) it('should add an owner and update the threshold', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -286,7 +245,7 @@ describe('Safe owners manager', () => { describe('createRemoveOwnerTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() + const { predictedSafe, accounts, contractNetworks } = await setupTests() const [, account2] = accounts const safeSdk = await Safe.init({ provider, @@ -298,7 +257,9 @@ describe('Safe owners manager', () => { }) it('should fail if address is invalid', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -309,7 +270,9 @@ describe('Safe owners manager', () => { }) it('should fail if address is equal to sentinel', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -320,7 +283,9 @@ describe('Safe owners manager', () => { }) it('should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -331,7 +296,9 @@ describe('Safe owners manager', () => { }) it('should fail if address is not an owner', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [, , , account4] = accounts const safeSdk = await Safe.init({ provider, @@ -343,7 +310,9 @@ describe('Safe owners manager', () => { }) it('should fail if the threshold is bigger than the number of owners', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1] = accounts const safeSdk = await Safe.init({ provider, @@ -361,7 +330,9 @@ describe('Safe owners manager', () => { }) it('should fail if the threshold is not bigger than 0', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1] = accounts const safeSdk = await Safe.init({ provider, @@ -373,7 +344,9 @@ describe('Safe owners manager', () => { }) it('should build the transaction with the optional props', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1] = accounts const safeSdk1 = await Safe.init({ provider, @@ -398,7 +371,9 @@ describe('Safe owners manager', () => { }) it('should remove the first owner of a Safe and decrease the threshold', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1, account2, account3] = accounts const safeSdk1 = await Safe.init({ provider, @@ -431,7 +406,9 @@ describe('Safe owners manager', () => { }) it('should remove any owner of a Safe and decrease the threshold', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1, account2, account3] = accounts const safeSdk1 = await Safe.init({ provider, @@ -465,7 +442,9 @@ describe('Safe owners manager', () => { }) it('should remove an owner and update the threshold', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1, account2, account3] = accounts const safeSdk1 = await Safe.init({ provider, @@ -502,7 +481,7 @@ describe('Safe owners manager', () => { describe('createSwapOwnerTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() + const { predictedSafe, accounts, contractNetworks } = await setupTests() const [account1] = accounts const safeSdk = await Safe.init({ provider, @@ -517,9 +496,8 @@ describe('Safe owners manager', () => { }) it('should fail if old address is invalid', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -533,9 +511,8 @@ describe('Safe owners manager', () => { }) it('should fail if new address is invalid', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -549,9 +526,8 @@ describe('Safe owners manager', () => { }) it('should fail if old address is equal to sentinel', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -565,9 +541,8 @@ describe('Safe owners manager', () => { }) it('should fail if new address is equal to sentinel', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -581,9 +556,8 @@ describe('Safe owners manager', () => { }) it('should fail if old address is equal to 0x address', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2] = accounts const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -597,9 +571,8 @@ describe('Safe owners manager', () => { }) it('should fail if new address is equal to 0x address', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -613,9 +586,8 @@ describe('Safe owners manager', () => { }) it('should fail if old address is not an owner', async () => { - const { accounts, contractNetworks, provider } = await setupTests() - const [account1, account2, , account4] = accounts - const safe = await getSafeWithOwners([account1.address]) + const { safe, accounts, contractNetworks } = await setupTests() + const [, account2, , account4] = accounts const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -629,9 +601,8 @@ describe('Safe owners manager', () => { }) it('should fail if new address is already an owner', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -645,9 +616,8 @@ describe('Safe owners manager', () => { }) it('should build the transaction with the optional props', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -674,9 +644,8 @@ describe('Safe owners manager', () => { }) it('should replace the first owner of a Safe', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts - const safe = await getSafeWithOwners([account1.address]) const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -697,7 +666,9 @@ describe('Safe owners manager', () => { }) it('should replace any owner of a Safe', async () => { - const { safe, accounts, contractNetworks, provider } = await setupTests() + const { safe, accounts, contractNetworks } = await setupTests({ + safeConfig: { numberOfOwners: 3, threshold: 3 } + }) const [account1, account2, account3, account4] = accounts const safeSdk1 = await Safe.init({ provider, diff --git a/packages/protocol-kit/tests/e2e/passkey.test.ts b/packages/protocol-kit/tests/e2e/passkey.test.ts index 89f5f2031..21a072ca7 100644 --- a/packages/protocol-kit/tests/e2e/passkey.test.ts +++ b/packages/protocol-kit/tests/e2e/passkey.test.ts @@ -1,4 +1,11 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { + safeVersionDeployed, + setupTests as testingKitSetupTests, + itif, + describeif, + getWebAuthnContract, + getSafeWithOwners +} from '@safe-global/testing-kit' import { OperationType } from '@safe-global/safe-core-sdk-types' import Safe, { getPasskeyOwnerAddress, @@ -9,18 +16,13 @@ import chai from 'chai' import chaiAsPromised from 'chai-as-promised' import sinon from 'sinon' import sinonChai from 'sinon-chai' -import { deployments } from 'hardhat' import crypto from 'crypto' import { getSafeWebAuthnSignerFactoryContract, getSafeWebAuthnSharedSignerContract } from '@safe-global/protocol-kit/contracts/safeDeploymentContracts' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners, getWebAuthnContract } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' import { waitSafeTxReceipt } from './utils/transactions' -import { getAccounts } from './utils/setupTestNetwork' -import { itif, describeif } from './utils/helpers' import { createMockPasskey, getWebAuthnCredentials, deployPasskeysContract } from './utils/passkeys' chai.use(chaiAsPromised) @@ -43,8 +45,8 @@ Object.defineProperty(global, 'navigator', { }) describe('Passkey', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() + const setupTests = async () => { + const { accounts, chainId, contractNetworks } = await testingKitSetupTests() const webAuthnContract = await getWebAuthnContract() const customVerifierAddress = webAuthnContract.address @@ -52,8 +54,6 @@ describe('Passkey', () => { const passkey1 = { ...(await createMockPasskey('chucknorris')), customVerifierAddress } const passkey2 = { ...(await createMockPasskey('brucelee')), customVerifierAddress } - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) const provider = getEip1193Provider() const safeProvider = await SafeProvider.init(provider) const customContracts = contractNetworks?.[chainId.toString()] @@ -88,7 +88,7 @@ describe('Passkey', () => { return { safeProvider, - accounts: await getAccounts(), + accounts, contractNetworks, predictedSafe, provider, @@ -97,7 +97,7 @@ describe('Passkey', () => { safeWebAuthnSignerFactoryContract, safeWebAuthnSharedSignerContract } - }) + } describe('isOwner', async () => { itif(safeVersionDeployed < '1.3.0')( diff --git a/packages/protocol-kit/tests/e2e/safeFactory.test.ts b/packages/protocol-kit/tests/e2e/safeFactory.test.ts index 88cef595c..f28764185 100644 --- a/packages/protocol-kit/tests/e2e/safeFactory.test.ts +++ b/packages/protocol-kit/tests/e2e/safeFactory.test.ts @@ -1,19 +1,8 @@ import { DEFAULT_SAFE_VERSION } from '@safe-global/protocol-kit/contracts/config' -import { safeVersionDeployed } from '@safe-global/testing-kit' -import { - ContractNetworksConfig, - DeploySafeProps, - SafeAccountConfig, - SafeFactory, - SafeProvider -} from '@safe-global/protocol-kit/index' -import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' -import chai from 'chai' -import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { itif } from './utils/helpers' -import { getContractNetworks } from './utils/setupContractNetworks' import { + safeVersionDeployed, + setupTests, + itif, getCompatibilityFallbackHandler, getCreateCall, getDefaultCallbackHandler, @@ -23,37 +12,31 @@ import { getSafeSingleton, getSignMessageLib, getSimulateTxAccessor -} from './utils/setupContracts' +} from '@safe-global/testing-kit' +import { + ContractNetworksConfig, + DeploySafeProps, + SafeAccountConfig, + SafeFactory, + SafeProvider +} from '@safe-global/protocol-kit/index' +import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' +import chai from 'chai' +import chaiAsPromised from 'chai-as-promised' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' chai.use(chaiAsPromised) describe('SafeProxyFactory', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - - return { - defaultCallbackHandler: await getDefaultCallbackHandler(), - chainId, - accounts, - contractNetworks, - provider - } - }) + const provider = getEip1193Provider() describe('create', async () => { it('should fail if the current network is not a default network and no contractNetworks is provided', async () => { - const { provider } = await setupTests() chai.expect(SafeFactory.init({ provider })).rejectedWith('Invalid SafeProxyFactory contract') }) it('should fail if the contractNetworks provided are not deployed', async () => { - const { chainId, provider } = await setupTests() + const { chainId } = await setupTests() const contractNetworks: ContractNetworksConfig = { [chainId.toString()]: { safeSingletonAddress: ZERO_ADDRESS, @@ -80,7 +63,7 @@ describe('SafeProxyFactory', () => { }) it('should instantiate the SafeProxyFactory', async () => { - const { contractNetworks, provider } = await setupTests() + const { contractNetworks } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeFactory = await SafeFactory.init({ provider, contractNetworks }) const networkId = await safeProvider.getChainId() @@ -92,7 +75,7 @@ describe('SafeProxyFactory', () => { describe('getEip1193Provider', async () => { it('should return the connected SafeProvider', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1] = accounts const safeFactory = await SafeFactory.init({ provider, contractNetworks }) chai.expect(await safeFactory.getSafeProvider().getSignerAddress()).to.be.eq(account1.address) @@ -101,7 +84,7 @@ describe('SafeProxyFactory', () => { describe('getChainId', async () => { it('should return the chainId of the current network', async () => { - const { chainId, contractNetworks, provider } = await setupTests() + const { chainId, contractNetworks } = await setupTests() const safeFactory = await SafeFactory.init({ provider, contractNetworks }) chai.expect(await safeFactory.getChainId()).to.be.eq(chainId) }) @@ -109,7 +92,7 @@ describe('SafeProxyFactory', () => { describe('predictSafeAddress', async () => { it('should fail if there are no owners', async () => { - const { contractNetworks, provider } = await setupTests() + const { contractNetworks } = await setupTests() const safeFactory = await SafeFactory.init({ provider, contractNetworks }) const owners: string[] = [] const threshold = 2 @@ -122,7 +105,7 @@ describe('SafeProxyFactory', () => { }) it('should fail if the threshold is lower than 0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, contractNetworks }) const owners = [account1.address, account2.address] @@ -136,7 +119,7 @@ describe('SafeProxyFactory', () => { }) it('should fail if the threshold is higher than the threshold', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, contractNetworks }) const owners = [account1.address, account2.address] @@ -150,7 +133,7 @@ describe('SafeProxyFactory', () => { }) it('should fail if the saltNonce is lower than 0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -168,7 +151,7 @@ describe('SafeProxyFactory', () => { }) it('should predict a new Safe with saltNonce', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -194,7 +177,7 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed > '1.0.0')( 'should predict a new Safe with the default CompatibilityFallbackHandler', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -222,7 +205,8 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed > '1.0.0')( 'should predict a new Safe with a custom fallback handler', async () => { - const { accounts, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -251,7 +235,7 @@ describe('SafeProxyFactory', () => { describe('deploySafe', async () => { it('should fail if there are no owners', async () => { - const { contractNetworks, provider } = await setupTests() + const { contractNetworks } = await setupTests() const safeFactory = await SafeFactory.init({ provider, contractNetworks }) const owners: string[] = [] const threshold = 2 @@ -263,7 +247,7 @@ describe('SafeProxyFactory', () => { }) it('should fail if the threshold is lower than 0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, contractNetworks }) const owners = [account1.address, account2.address] @@ -276,7 +260,7 @@ describe('SafeProxyFactory', () => { }) it('should fail if the threshold is higher than the threshold', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, contractNetworks }) const owners = [account1.address, account2.address] @@ -289,7 +273,7 @@ describe('SafeProxyFactory', () => { }) it('should fail if the saltNonce is lower than 0', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -309,7 +293,8 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed > '1.0.0')( 'should deploy a new Safe with custom fallback handler', async () => { - const { accounts, contractNetworks, defaultCallbackHandler, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() + const defaultCallbackHandler = await getDefaultCallbackHandler() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -337,7 +322,7 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed > '1.0.0')( 'should deploy a new Safe with the default CompatibilityFallbackHandler', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -358,7 +343,7 @@ describe('SafeProxyFactory', () => { ) it('should deploy a new Safe without saltNonce', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -377,7 +362,7 @@ describe('SafeProxyFactory', () => { }) it('should deploy a new Safe with saltNonce', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, @@ -397,7 +382,7 @@ describe('SafeProxyFactory', () => { }) it('should deploy a new Safe with callback', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts let callbackResult = '' const callback = (txHash: string) => { @@ -422,7 +407,7 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed === DEFAULT_SAFE_VERSION)( 'should deploy last Safe version by default', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, contractNetworks }) const owners = [account1.address, account2.address] @@ -436,7 +421,7 @@ describe('SafeProxyFactory', () => { ) it('should deploy a specific Safe version', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safeFactory = await SafeFactory.init({ provider, diff --git a/packages/protocol-kit/tests/e2e/safeProvider.test.ts b/packages/protocol-kit/tests/e2e/safeProvider.test.ts index 784739dc3..c3a8d3966 100644 --- a/packages/protocol-kit/tests/e2e/safeProvider.test.ts +++ b/packages/protocol-kit/tests/e2e/safeProvider.test.ts @@ -1,10 +1,7 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import { SafeVersion } from '@safe-global/safe-core-sdk-types' -import chai from 'chai' -import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' import { + safeVersionDeployed, + setupTests, + itif, getCompatibilityFallbackHandler, getCreateCall, getFactory, @@ -12,11 +9,12 @@ import { getMultiSendCallOnly, getSafeSingleton, getSignMessageLib -} from './utils/setupContracts' +} from '@safe-global/testing-kit' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' +import chai from 'chai' +import chaiAsPromised from 'chai-as-promised' import { getEip1193Provider, getSafeProviderFromNetwork } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { SafeProvider } from '@safe-global/protocol-kit/index' -import { itif } from './utils/helpers' import sinon from 'sinon' import sinonChai from 'sinon-chai' import { createMockPasskey, getWebAuthnCredentials } from './utils/passkeys' @@ -42,26 +40,12 @@ Object.defineProperty(global, 'navigator', { }) describe('Safe contracts', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - - return { - accounts, - contractNetworks, - chainId, - provider - } - }) + const provider = getEip1193Provider() describe('init', async () => { itif(safeVersionDeployed < '1.3.0')( 'should fail for a passkey signer and Safe { - const { provider } = await setupTests() const passKeySigner = await createMockPasskey('aName') chai @@ -113,7 +97,7 @@ describe('Safe contracts', () => { }) it('should return a Safe contract from the custom addresses', async () => { - const { contractNetworks, chainId, provider } = await setupTests() + const { contractNetworks, chainId } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -141,7 +125,7 @@ describe('Safe contracts', () => { }) it('should return a MultiSend contract from the custom addresses', async () => { - const { contractNetworks, chainId, provider } = await setupTests() + const { contractNetworks, chainId } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -169,7 +153,7 @@ describe('Safe contracts', () => { }) it('should return a MultiSendCallOnly contract from the custom addresses', async () => { - const { contractNetworks, chainId, provider } = await setupTests() + const { contractNetworks, chainId } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -198,7 +182,7 @@ describe('Safe contracts', () => { }) it('should return a CompatibilityFallbackHandler contract from the custom addresses', async () => { - const { contractNetworks, chainId, provider } = await setupTests() + const { contractNetworks, chainId } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -227,7 +211,7 @@ describe('Safe contracts', () => { }) it('should return a SafeProxyFactory contract from the custom addresses', async () => { - const { contractNetworks, chainId, provider } = await setupTests() + const { contractNetworks, chainId } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -255,7 +239,7 @@ describe('Safe contracts', () => { }) it('should return a SignMessageLib contract from the custom addresses', async () => { - const { contractNetworks, chainId, provider } = await setupTests() + const { contractNetworks, chainId } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -283,7 +267,7 @@ describe('Safe contracts', () => { }) it('should return a SafeProxyFactory contract from the custom addresses', async () => { - const { contractNetworks, chainId, provider } = await setupTests() + const { contractNetworks, chainId } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -298,8 +282,6 @@ describe('Safe contracts', () => { }) it('should return an external provider (PublicClient) and signer (WalletClient) when using an EIP1193 provider', async () => { - const { provider } = await setupTests() - const safeProvider = new SafeProvider({ provider }) chai.expect(safeProvider.getExternalProvider()).to.deep.include(publicActions) diff --git a/packages/protocol-kit/tests/e2e/threshold.test.ts b/packages/protocol-kit/tests/e2e/threshold.test.ts index 1a60608bb..df65b235a 100644 --- a/packages/protocol-kit/tests/e2e/threshold.test.ts +++ b/packages/protocol-kit/tests/e2e/threshold.test.ts @@ -1,48 +1,18 @@ -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { - PredictedSafeProps, - SafeTransactionOptionalProps -} from '@safe-global/protocol-kit/index' +import { setupTests, getSafeWithOwners } from '@safe-global/testing-kit' +import Safe, { SafeTransactionOptionalProps } from '@safe-global/protocol-kit/index' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getSafeWithOwners } from './utils/setupContracts' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' import { waitSafeTxReceipt } from './utils/transactions' chai.use(chaiAsPromised) describe('Safe Threshold', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - const provider = getEip1193Provider() - - return { - safe: await getSafeWithOwners([accounts[0].address]), - accounts, - contractNetworks, - predictedSafe, - provider - } - }) + const provider = getEip1193Provider() describe('getThreshold', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -52,7 +22,7 @@ describe('Safe Threshold', () => { }) it('should return the Safe threshold', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -64,7 +34,7 @@ describe('Safe Threshold', () => { describe('createChangeThresholdTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks, provider } = await setupTests() + const { predictedSafe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, predictedSafe, @@ -77,7 +47,7 @@ describe('Safe Threshold', () => { }) it('should fail if the threshold is bigger than the number of owners', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -92,7 +62,7 @@ describe('Safe Threshold', () => { }) it('should fail if the threshold is not bigger than 0', async () => { - const { safe, contractNetworks, provider } = await setupTests() + const { safe, contractNetworks } = await setupTests() const safeSdk = await Safe.init({ provider, safeAddress: safe.address, @@ -105,7 +75,7 @@ describe('Safe Threshold', () => { }) it('should build the transaction with the optional props', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address, account2.address], 1) const safeSdk = await Safe.init({ @@ -133,7 +103,7 @@ describe('Safe Threshold', () => { }) it('should change the threshold', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address, account2.address], 1) const safeSdk = await Safe.init({ diff --git a/packages/protocol-kit/tests/e2e/utils/setupContractNetworks.ts b/packages/protocol-kit/tests/e2e/utils/setupContractNetworks.ts deleted file mode 100644 index b6391af14..000000000 --- a/packages/protocol-kit/tests/e2e/utils/setupContractNetworks.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { ContractNetworksConfig } from '@safe-global/protocol-kit/index' -import { - getCompatibilityFallbackHandler, - getCreateCall, - getFactory, - getMultiSend, - getMultiSendCallOnly, - getSafeSingleton, - getSafeWebAuthnSharedSigner, - getSafeWebAuthnSignerFactory, - getSignMessageLib, - getSimulateTxAccessor -} from './setupContracts' - -export async function getContractNetworks(chainId: bigint): Promise { - return { - [chainId.toString()]: { - safeSingletonAddress: await (await getSafeSingleton()).contract.address, - safeSingletonAbi: (await getSafeSingleton()).abi, - safeProxyFactoryAddress: await (await getFactory()).contract.address, - safeProxyFactoryAbi: (await getFactory()).abi, - multiSendAddress: await (await getMultiSend()).contract.address, - multiSendAbi: (await getMultiSend()).abi, - multiSendCallOnlyAddress: await (await getMultiSendCallOnly()).contract.address, - multiSendCallOnlyAbi: (await getMultiSendCallOnly()).abi, - fallbackHandlerAddress: await (await getCompatibilityFallbackHandler()).contract.address, - fallbackHandlerAbi: (await getCompatibilityFallbackHandler()).abi, - signMessageLibAddress: await (await getSignMessageLib()).contract.address, - signMessageLibAbi: (await getSignMessageLib()).abi, - createCallAddress: await (await getCreateCall()).contract.address, - createCallAbi: (await getCreateCall()).abi, - simulateTxAccessorAddress: await (await getSimulateTxAccessor()).contract.address, - simulateTxAccessorAbi: (await getSimulateTxAccessor()).abi, - safeWebAuthnSignerFactoryAddress: await ( - await getSafeWebAuthnSignerFactory() - ).contract.address, - safeWebAuthnSignerFactoryAbi: (await getSafeWebAuthnSignerFactory()).abi, - safeWebAuthnSharedSignerAddress: await (await getSafeWebAuthnSharedSigner()).contract.address, - safeWebAuthnSharedSignerAbi: (await getSafeWebAuthnSharedSigner()).abi - } - } -} diff --git a/packages/protocol-kit/tests/e2e/utils/transactions.ts b/packages/protocol-kit/tests/e2e/utils/transactions.ts index 3f6ac3ffd..82e4b8b9a 100644 --- a/packages/protocol-kit/tests/e2e/utils/transactions.ts +++ b/packages/protocol-kit/tests/e2e/utils/transactions.ts @@ -1,7 +1,6 @@ -import { GetTransactionReceiptReturnType, Hex, WalletClient, Transport, Chain, Account } from 'viem' +import { GetTransactionReceiptReturnType } from 'viem' import { TransactionResult } from '@safe-global/safe-core-sdk-types' import SafeProvider from '@safe-global/protocol-kit/SafeProvider' -import hre, { viem } from 'hardhat' export async function waitSafeTxReceipt( txResult: TransactionResult @@ -18,12 +17,3 @@ export async function getTransaction( ): Promise { return safeProvider.getTransaction(transactionHash) } - -export async function waitTransactionReceipt(hash: Hex) { - return (await viem.getPublicClient()).waitForTransactionReceipt({ hash }) -} - -export async function getDeployer(): Promise> { - const { deployer } = await hre.getNamedAccounts() - return viem.getWalletClient(deployer) -} diff --git a/packages/protocol-kit/tests/e2e/utilsContracts.test.ts b/packages/protocol-kit/tests/e2e/utilsContracts.test.ts index 47c2468b8..f60263336 100644 --- a/packages/protocol-kit/tests/e2e/utilsContracts.test.ts +++ b/packages/protocol-kit/tests/e2e/utilsContracts.test.ts @@ -1,14 +1,10 @@ import chai from 'chai' -import { deployments } from 'hardhat' -import { getAccounts } from './utils/setupTestNetwork' -import { getContractNetworks } from './utils/setupContractNetworks' -import { getDefaultCallbackHandler } from './utils/setupContracts' import { getEip1193Provider, getSafeProviderFromNetwork } from './utils/setupProvider' import { PREDETERMINED_SALT_NONCE, predictSafeAddress } from '@safe-global/protocol-kit/contracts/utils' -import { safeVersionDeployed } from '@safe-global/testing-kit' +import { safeVersionDeployed, setupTests, itif } from '@safe-global/testing-kit' import { SafeDeploymentConfig, SafeAccountConfig, @@ -17,7 +13,6 @@ import { } from '@safe-global/protocol-kit/types' import Safe, { SafeFactory, DeploySafeProps } from '@safe-global/protocol-kit/index' import SafeProvider from '@safe-global/protocol-kit/SafeProvider' -import { itif } from './utils/helpers' // test util funcion to deploy a safe (needed to check the expected Safe Address) async function deploySafe( @@ -37,25 +32,11 @@ async function deploySafe( } describe('Contract utils', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - const provider = getEip1193Provider() - - return { - defaultCallbackHandler: await getDefaultCallbackHandler(), - chainId, - accounts, - contractNetworks, - provider - } - }) + const provider = getEip1193Provider() describe('predictSafeAddress', () => { it('returns the predicted address of a 1/1 Safe', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // 1/1 Safe const [owner1] = accounts @@ -100,7 +81,7 @@ describe('Contract utils', () => { }) it('returns the predicted address of a 1/2 Safe', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // 1/2 Safe const [owner1, owner2] = accounts @@ -145,7 +126,7 @@ describe('Contract utils', () => { }) it('returns the predicted address of a 2/2 Safe', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // 2/2 Safe const [owner1, owner2] = accounts @@ -190,7 +171,7 @@ describe('Contract utils', () => { }) it('should fail if the provided threshold is invalid (greater than owners length)', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // invalid threshold 3/2 Safe const [owner1, owner2] = accounts @@ -224,7 +205,7 @@ describe('Contract utils', () => { }) it('should fail if the provided threshold is invalid (zero value)', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // invalid threshold 0/2 Safe const [owner1, owner2] = accounts @@ -258,7 +239,7 @@ describe('Contract utils', () => { }) it('should fail if the provided threshold is invalid (negative value)', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // invalid threshold -2/2 Safe const [owner1, owner2] = accounts @@ -292,7 +273,7 @@ describe('Contract utils', () => { }) it('should fail if no owners are present (empty array)', async () => { - const { contractNetworks, chainId, provider } = await setupTests() + const { contractNetworks, chainId } = await setupTests() // invalid owners 1/0 Safe const invalidOwners: string[] = [] @@ -325,7 +306,7 @@ describe('Contract utils', () => { }) it('returns different addresses with different saltNonce value but same Safe config (threshold & owners)', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // 1/2 Safe const [owner1, owner2] = accounts @@ -418,7 +399,7 @@ describe('Contract utils', () => { }) it('returns the same predicted address for multiple calls to predictedSafeAddress with the same config (owners, threshold & saltNonce)', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // 2/2 Safe const [owner1, owner2] = accounts @@ -483,7 +464,7 @@ describe('Contract utils', () => { itif(safeVersionDeployed > '1.0.0')( 'safeDeploymentConfig is an optional parameter', async () => { - const { accounts, contractNetworks, chainId, provider } = await setupTests() + const { accounts, contractNetworks, chainId } = await setupTests() // 1/1 Safe const [owner1] = accounts diff --git a/packages/protocol-kit/tests/e2e/wrapSafeTransactionIntoDeploymentBatch.test.ts b/packages/protocol-kit/tests/e2e/wrapSafeTransactionIntoDeploymentBatch.test.ts index 8a972288f..dd0ce5f96 100644 --- a/packages/protocol-kit/tests/e2e/wrapSafeTransactionIntoDeploymentBatch.test.ts +++ b/packages/protocol-kit/tests/e2e/wrapSafeTransactionIntoDeploymentBatch.test.ts @@ -1,47 +1,24 @@ import chai from 'chai' import chaiAsPromised from 'chai-as-promised' -import { deployments } from 'hardhat' -import { safeVersionDeployed } from '@safe-global/testing-kit' -import Safe, { PredictedSafeProps } from '@safe-global/protocol-kit/index' -import { getContractNetworks } from './utils/setupContractNetworks' -import { itif } from './utils/helpers' -import { getSafeWithOwners, getMultiSendCallOnly } from './utils/setupContracts' +import { + safeVersionDeployed, + setupTests, + itif, + getSafeWithOwners, + getMultiSendCallOnly +} from '@safe-global/testing-kit' +import Safe from '@safe-global/protocol-kit/index' import { getEip1193Provider } from './utils/setupProvider' -import { getAccounts } from './utils/setupTestNetwork' chai.use(chaiAsPromised) const AMOUNT_TO_TRANSFER = '500000000000000000' // 0.5 ETH describe('wrapSafeTransactionIntoDeploymentBatch', () => { - const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => { - await deployments.fixture() - const accounts = await getAccounts() - const chainId = BigInt(await getChainId()) - const contractNetworks = await getContractNetworks(chainId) - - const predictedSafe: PredictedSafeProps = { - safeAccountConfig: { - owners: [accounts[0].address], - threshold: 1 - }, - safeDeploymentConfig: { - safeVersion: safeVersionDeployed - } - } - const provider = getEip1193Provider() - - return { - accounts, - contractNetworks, - predictedSafe, - chainId, - provider - } - }) + const provider = getEip1193Provider() it('should throw an error if the Safe is already deployed', async () => { - const { accounts, contractNetworks, provider } = await setupTests() + const { accounts, contractNetworks } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) @@ -71,7 +48,7 @@ describe('wrapSafeTransactionIntoDeploymentBatch', () => { itif(safeVersionDeployed == '1.4.1')( 'should return a batch transaction with the Safe deployment Transaction and the Safe Transaction', async () => { - const { accounts, contractNetworks, predictedSafe, provider } = await setupTests() + const { accounts, contractNetworks, predictedSafe } = await setupTests() const [, account2] = accounts const safeSdk = await Safe.init({ @@ -105,7 +82,7 @@ describe('wrapSafeTransactionIntoDeploymentBatch', () => { itif(safeVersionDeployed == '1.3.0')( 'should return a batch transaction with the Safe deployment Transaction and the Safe Transaction', async () => { - const { accounts, contractNetworks, predictedSafe, provider } = await setupTests() + const { accounts, contractNetworks, predictedSafe } = await setupTests() const [, account2] = accounts const safeSdk = await Safe.init({ @@ -139,7 +116,7 @@ describe('wrapSafeTransactionIntoDeploymentBatch', () => { itif(safeVersionDeployed >= '1.3.0')( 'should include the custom salt nonce in the Safe deployment data', async () => { - const { accounts, contractNetworks, predictedSafe, provider } = await setupTests() + const { accounts, contractNetworks, predictedSafe } = await setupTests() const [, account2] = accounts const safeSdk = await Safe.init({ diff --git a/packages/testing-kit/package.json b/packages/testing-kit/package.json index 5d144bab6..3d610d620 100644 --- a/packages/testing-kit/package.json +++ b/packages/testing-kit/package.json @@ -36,6 +36,8 @@ ], "homepage": "https://github.com/safe-global/safe-core-sdk#readme", "devDependencies": { + "@types/semver": "^7.5.8", + "@types/mocha": "^10.0.6", "@gnosis.pm/safe-contracts-v1.3.0": "npm:@gnosis.pm/safe-contracts@1.3.0", "@nomicfoundation/hardhat-viem": "^2.0.2", "@openzeppelin/contracts": "^2.5.1", @@ -46,6 +48,9 @@ "hardhat-deploy": "^0.12.4", "tsconfig-paths": "^4.2.0" }, + "dependencies": { + "semver": "^7.6.2" + }, "bin": { "testing-kit": "./dist/bin/testing-kit.js" }, diff --git a/packages/testing-kit/src/hardhat/deploy/deploy-contracts.ts b/packages/testing-kit/src/hardhat/deploy/deploy-contracts.ts index 46547106f..cce7a44ec 100644 --- a/packages/testing-kit/src/hardhat/deploy/deploy-contracts.ts +++ b/packages/testing-kit/src/hardhat/deploy/deploy-contracts.ts @@ -101,7 +101,6 @@ export const safeWebAuthnSharedSignerDeployed = safeWebAuthnSharedSignerContracts[safeVersionDeployed] const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment): Promise => { - //@ts-expect-error - Property 'deployments' does not exist on type 'HardhatRuntimeEnvironment' const { deployments, getNamedAccounts } = hre const { deployer } = await getNamedAccounts() diff --git a/packages/testing-kit/src/index.ts b/packages/testing-kit/src/index.ts index aee0f3194..acdd1a0ed 100644 --- a/packages/testing-kit/src/index.ts +++ b/packages/testing-kit/src/index.ts @@ -1 +1,7 @@ export * from './hardhat/deploy/deploy-contracts' +export * from './utils/helpers' +export * from './utils/setupContracts' +export * from './utils/setupContractNetworks' +export * from './utils/setupTestNetwork' +export * from './utils/setupTests' +export * from './utils/transactions' diff --git a/packages/protocol-kit/tests/e2e/utils/helpers.ts b/packages/testing-kit/src/utils/helpers.ts similarity index 100% rename from packages/protocol-kit/tests/e2e/utils/helpers.ts rename to packages/testing-kit/src/utils/helpers.ts diff --git a/packages/testing-kit/src/utils/setupContractNetworks.ts b/packages/testing-kit/src/utils/setupContractNetworks.ts new file mode 100644 index 000000000..8521b172a --- /dev/null +++ b/packages/testing-kit/src/utils/setupContractNetworks.ts @@ -0,0 +1,90 @@ +import { Abi } from 'viem' +import { + getCompatibilityFallbackHandler, + getCreateCall, + getFactory, + getMultiSend, + getMultiSendCallOnly, + getSafeSingleton, + getSafeWebAuthnSharedSigner, + getSafeWebAuthnSignerFactory, + getSignMessageLib, + getSimulateTxAccessor +} from './setupContracts' + +export type ContractNetworkConfig = { + /** safeSingletonAddress - Address of the Safe Singleton contract deployed on a specific network */ + safeSingletonAddress: string + /** safeSingletonAbi - Abi of the Safe Singleton contract deployed on a specific network */ + safeSingletonAbi?: Abi + /** safeProxyFactoryAddress - Address of the SafeProxyFactory contract deployed on a specific network */ + safeProxyFactoryAddress: string + /** safeProxyFactoryAbi - Abi of the SafeProxyFactory contract deployed on a specific network */ + safeProxyFactoryAbi?: Abi + /** multiSendAddress - Address of the MultiSend contract deployed on a specific network */ + multiSendAddress: string + /** multiSendAbi - Abi of the MultiSend contract deployed on a specific network */ + multiSendAbi?: Abi + /** multiSendCallOnlyAddress - Address of the MultiSendCallOnly contract deployed on a specific network */ + multiSendCallOnlyAddress: string + /** multiSendCallOnlyAbi - Abi of the MultiSendCallOnly contract deployed on a specific network */ + multiSendCallOnlyAbi?: Abi + /** fallbackHandlerAddress - Address of the Fallback Handler contract deployed on a specific network */ + fallbackHandlerAddress: string + /** fallbackHandlerAbi - Abi of the Fallback Handler contract deployed on a specific network */ + fallbackHandlerAbi?: Abi + /** signMessageLibAddress - Address of the SignMessageLib contract deployed on a specific network */ + signMessageLibAddress: string + /** signMessageLibAbi - Abi of the SignMessageLib contract deployed on a specific network */ + signMessageLibAbi?: Abi + /** createCallAddress - Address of the CreateCall contract deployed on a specific network */ + createCallAddress: string + /** createCallAbi - Abi of the CreateCall contract deployed on a specific network */ + createCallAbi?: Abi + /** simulateTxAccessorAddress - Address of the SimulateTxAccessor contract deployed on a specific network */ + simulateTxAccessorAddress: string + /** simulateTxAccessorAbi - Abi of the SimulateTxAccessor contract deployed on a specific network */ + simulateTxAccessorAbi?: Abi + /** safeWebAuthnSignerFactoryAddress - Address of the SafeWebAuthnSignerFactory contract deployed on a specific network */ + safeWebAuthnSignerFactoryAddress: string + /** safeWebAuthnSignerFactoryAbi - Abi of the SafeWebAuthnSignerFactory contract deployed on a specific network */ + safeWebAuthnSignerFactoryAbi?: Abi + /** safeWebAuthnSharedSignerAddress - Address of the SafeWebAuthnSharedSigner contract deployed on a specific network */ + safeWebAuthnSharedSignerAddress: string + /** safeWebAuthnSharedSignerAbi - Abi of the SafeWebAuthnSharedSigner contract deployed on a specific network */ + safeWebAuthnSharedSignerAbi?: Abi +} + +export type ContractNetworksConfig = { + /** id - Network id */ + [id: string]: ContractNetworkConfig +} + +export async function getContractNetworks(chainId: bigint): Promise { + return { + [chainId.toString()]: { + safeSingletonAddress: await (await getSafeSingleton()).contract.address, + safeSingletonAbi: (await getSafeSingleton()).abi, + safeProxyFactoryAddress: await (await getFactory()).contract.address, + safeProxyFactoryAbi: (await getFactory()).abi, + multiSendAddress: await (await getMultiSend()).contract.address, + multiSendAbi: (await getMultiSend()).abi, + multiSendCallOnlyAddress: await (await getMultiSendCallOnly()).contract.address, + multiSendCallOnlyAbi: (await getMultiSendCallOnly()).abi, + fallbackHandlerAddress: await (await getCompatibilityFallbackHandler()).contract.address, + fallbackHandlerAbi: (await getCompatibilityFallbackHandler()).abi, + signMessageLibAddress: await (await getSignMessageLib()).contract.address, + signMessageLibAbi: (await getSignMessageLib()).abi, + createCallAddress: await (await getCreateCall()).contract.address, + createCallAbi: (await getCreateCall()).abi, + simulateTxAccessorAddress: await (await getSimulateTxAccessor()).contract.address, + simulateTxAccessorAbi: (await getSimulateTxAccessor()).abi, + safeWebAuthnSignerFactoryAddress: await ( + await getSafeWebAuthnSignerFactory() + ).contract.address, + safeWebAuthnSignerFactoryAbi: (await getSafeWebAuthnSignerFactory()).abi, + safeWebAuthnSharedSignerAddress: await (await getSafeWebAuthnSharedSigner()).contract.address, + safeWebAuthnSharedSignerAbi: (await getSafeWebAuthnSharedSigner()).abi + } + } +} diff --git a/packages/protocol-kit/tests/e2e/utils/setupContracts.ts b/packages/testing-kit/src/utils/setupContracts.ts similarity index 89% rename from packages/protocol-kit/tests/e2e/utils/setupContracts.ts rename to packages/testing-kit/src/utils/setupContracts.ts index ec536c9e9..389fe9993 100644 --- a/packages/protocol-kit/tests/e2e/utils/setupContracts.ts +++ b/packages/testing-kit/src/utils/setupContracts.ts @@ -1,5 +1,4 @@ -import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants' -import { GetContractReturnType, Abi, WalletClient } from 'viem' +import { GetContractReturnType, Abi, WalletClient, Address, zeroAddress } from 'viem' import { compatibilityFallbackHandlerDeployed, createCallDeployed, @@ -12,17 +11,18 @@ import { safeWebAuthnSignerFactoryDeployed, signMessageLibDeployed, simulateTxAccessorDeployed -} from '@safe-global/testing-kit' +} from '../hardhat/deploy/deploy-contracts' import { deployments, viem } from 'hardhat' import semverSatisfies from 'semver/functions/satisfies' import { getDeployer, waitTransactionReceipt } from './transactions' +const ZERO_ADDRESS: Address = zeroAddress export const getSafeSingleton = async (): Promise<{ contract: GetContractReturnType abi: Abi }> => { const safeDeployment = await deployments.get(safeDeployed.name) - const contract = await viem.getContractAt(safeDeployed.name, safeDeployment.address) + const contract = await viem.getContractAt(safeDeployed.name, safeDeployment.address as Address) return { contract, abi: safeDeployment.abi @@ -35,7 +35,7 @@ export const getFactory = async (): Promise<{ }> => { const factoryDeployment = await deployments.get(proxyFactoryDeployed.name) const factoryAddress = factoryDeployment.address - const contract = await viem.getContractAt(proxyFactoryDeployed.name, factoryAddress, { + const contract = await viem.getContractAt(proxyFactoryDeployed.name, factoryAddress as Address, { client: { wallet: await getDeployer() } }) return { @@ -103,7 +103,7 @@ export const getCompatibilityFallbackHandler = async (): Promise<{ const contract = await viem.getContractAt( compatibilityFallbackHandlerDeployed.name, - compatibilityFallbackHandlerDeploymentAddress + compatibilityFallbackHandlerDeploymentAddress as Address ) return { contract, @@ -117,7 +117,7 @@ export const getMultiSend = async (): Promise<{ }> => { const multiSendDeployment = await deployments.get(multiSendDeployed.name) const multiSendAddress = multiSendDeployment.address - const contract = await viem.getContractAt(multiSendDeployed.name, multiSendAddress) + const contract = await viem.getContractAt(multiSendDeployed.name, multiSendAddress as Address) return { contract, abi: multiSendDeployment.abi @@ -130,7 +130,10 @@ export const getMultiSendCallOnly = async (): Promise<{ }> => { const multiSendCallOnlyDeployment = await deployments.get(multiSendCallOnlyDeployed.name) const multiSendAddress = multiSendCallOnlyDeployment.address - const contract = await viem.getContractAt(multiSendCallOnlyDeployed.name, multiSendAddress) + const contract = await viem.getContractAt( + multiSendCallOnlyDeployed.name, + multiSendAddress as Address + ) return { contract, abi: multiSendCallOnlyDeployment.abi @@ -143,7 +146,10 @@ export const getSignMessageLib = async (): Promise<{ }> => { const signMessageLibDeployment = await deployments.get(signMessageLibDeployed.name) const signMessageLibAddress = signMessageLibDeployment.address - const contract = await viem.getContractAt(signMessageLibDeployed.name, signMessageLibAddress) + const contract = await viem.getContractAt( + signMessageLibDeployed.name, + signMessageLibAddress as Address + ) return { contract, abi: signMessageLibDeployment.abi @@ -156,7 +162,7 @@ export const getCreateCall = async (): Promise<{ }> => { const createCallDeployment = await deployments.get(createCallDeployed.name) const createCallAddress = createCallDeployment.address - const contract = await viem.getContractAt(createCallDeployed.name, createCallAddress) + const contract = await viem.getContractAt(createCallDeployed.name, createCallAddress as Address) return { contract, abi: createCallDeployment.abi @@ -171,7 +177,7 @@ export const getSimulateTxAccessor = async (): Promise<{ const simulateTxAccessorAddress = simulateTxAccessorDeployment.address const contract = await viem.getContractAt( simulateTxAccessorDeployed.name, - simulateTxAccessorAddress + simulateTxAccessorAddress as Address ) return { contract, @@ -189,7 +195,7 @@ export const getSafeWebAuthnSignerFactory = async (): Promise<{ const safeWebAuthnSignerFactoryAddress = safeWebAuthnSignerFactoryDeployment.address const contract = await viem.getContractAt( proxyFactoryDeployed.name, - safeWebAuthnSignerFactoryAddress, + safeWebAuthnSignerFactoryAddress as Address, { client: { wallet: await getDeployer() } } @@ -211,7 +217,7 @@ export const getSafeWebAuthnSharedSigner = async (): Promise<{ return { contract: await viem.getContractAt( safeWebAuthnSharedSignerDeployed.name, - safeWebAuthnSharedSignerDeployment.address + safeWebAuthnSharedSignerDeployment.address as Address ), abi: safeWebAuthnSharedSignerDeployment.abi } @@ -220,37 +226,37 @@ export const getSafeWebAuthnSharedSigner = async (): Promise<{ export const getWebAuthnContract = async (): Promise> => { const webAuthnContractDeployment = await deployments.get('WebAuthnContract') const dailyLimitModuleAddress = webAuthnContractDeployment.address - return await viem.getContractAt('WebAuthnContract', dailyLimitModuleAddress) + return await viem.getContractAt('WebAuthnContract', dailyLimitModuleAddress as Address) } export const getDailyLimitModule = async (): Promise> => { const dailyLimitModuleDeployment = await deployments.get('DailyLimitModule') const dailyLimitModuleAddress = dailyLimitModuleDeployment.address - return await viem.getContractAt('DailyLimitModule', dailyLimitModuleAddress) + return await viem.getContractAt('DailyLimitModule', dailyLimitModuleAddress as Address) } export const getSocialRecoveryModule = async (): Promise> => { const socialRecoveryModuleDeployment = await deployments.get('SocialRecoveryModule') const socialRecoveryModuleAddress = socialRecoveryModuleDeployment.address - return await viem.getContractAt('SocialRecoveryModule', socialRecoveryModuleAddress) + return await viem.getContractAt('SocialRecoveryModule', socialRecoveryModuleAddress as Address) } export const getStateChannelModule = async (): Promise> => { const stateChannelModuleDeployment = await deployments.get('StateChannelModule') const stateChannelModuleAddress = stateChannelModuleDeployment.address - return await viem.getContractAt('StateChannelModule', stateChannelModuleAddress) + return await viem.getContractAt('StateChannelModule', stateChannelModuleAddress as Address) } export const getWhiteListModule = async (): Promise> => { const whiteListModuleDeployment = await deployments.get('WhitelistModule') const whiteListModuleAddress = whiteListModuleDeployment.address - return await viem.getContractAt('WhitelistModule', whiteListModuleAddress) + return await viem.getContractAt('WhitelistModule', whiteListModuleAddress as Address) } export const getERC20Mintable = async (): Promise> => { const eRC20MintableDeployment = await deployments.get('ERC20Mintable') const eRC20MintableAddress = eRC20MintableDeployment.address - return await viem.getContractAt('ERC20Mintable', eRC20MintableAddress, { + return await viem.getContractAt('ERC20Mintable', eRC20MintableAddress as Address, { client: { wallet: await getDeployer() } }) } @@ -261,7 +267,7 @@ export const getDebugTransactionGuard = async (): Promise> => { @@ -270,5 +276,5 @@ export const getDefaultCallbackHandler = async (): Promise address: string } diff --git a/packages/testing-kit/src/utils/setupTests.ts b/packages/testing-kit/src/utils/setupTests.ts new file mode 100644 index 000000000..f301cd7d8 --- /dev/null +++ b/packages/testing-kit/src/utils/setupTests.ts @@ -0,0 +1,80 @@ +import { deployments } from 'hardhat' +import { GetContractReturnType, Abi, WalletClient } from 'viem' + +import { Account, getAccounts } from './setupTestNetwork' +import { ContractNetworksConfig, getContractNetworks } from './setupContractNetworks' +import { getSafeWithOwners } from './setupContracts' +import { safeVersionDeployed } from '../hardhat/deploy/deploy-contracts' +import { SafeVersion } from '@safe-global/safe-core-sdk-types' + +type SetupTestsOptions = { + safeConfig?: { + numberOfOwners: number + threshold?: number + } + predictedSafeConfig?: { + numberOfOwners: number + threshold?: number + } +} + +type SetupTestsReturnType = { + safe: GetContractReturnType + accounts: Account[] + contractNetworks: ContractNetworksConfig + chainId: bigint + predictedSafe: PredictedSafeProps +} + +type SafeAccountConfig = { + owners: string[] + threshold: number +} + +type SafeDeploymentConfig = { + safeVersion?: SafeVersion +} + +type PredictedSafeProps = { + safeAccountConfig: SafeAccountConfig + safeDeploymentConfig?: SafeDeploymentConfig +} + +export const setupTests: (options?: SetupTestsOptions) => Promise = + deployments.createFixture(async ({ deployments, getChainId }, options?: SetupTestsOptions) => { + const { safeConfig, predictedSafeConfig } = options || {} + + await deployments.fixture() + const accounts = await getAccounts() + const chainId = BigInt(await getChainId()) + const contractNetworks = await getContractNetworks(chainId) + const safe = await getSafeWithOwners( + safeConfig + ? [...accounts.slice(0, safeConfig?.numberOfOwners).map((account) => account.address)] + : [accounts[0].address], + safeConfig?.threshold || 1 + ) + const predictedSafe = { + safeAccountConfig: { + owners: predictedSafeConfig + ? [ + ...accounts + .slice(0, predictedSafeConfig?.numberOfOwners) + .map((account) => account.address) + ] + : [accounts[0].address], + threshold: predictedSafeConfig?.threshold || 1 + }, + safeDeploymentConfig: { + safeVersion: safeVersionDeployed + } + } + + return { + safe, + accounts, + contractNetworks, + chainId, + predictedSafe + } + }) diff --git a/packages/testing-kit/src/utils/transactions.ts b/packages/testing-kit/src/utils/transactions.ts new file mode 100644 index 000000000..6e28285c0 --- /dev/null +++ b/packages/testing-kit/src/utils/transactions.ts @@ -0,0 +1,11 @@ +import { Hex, WalletClient, Transport, Chain, Account, Address } from 'viem' +import hre, { viem } from 'hardhat' + +export async function waitTransactionReceipt(hash: Hex) { + return (await viem.getPublicClient()).waitForTransactionReceipt({ hash }) +} + +export async function getDeployer(): Promise> { + const { deployer } = await hre.getNamedAccounts() + return viem.getWalletClient(deployer as Address) +} diff --git a/packages/testing-kit/tsconfig.build.json b/packages/testing-kit/tsconfig.build.json index b40c79f0d..5e4563c61 100644 --- a/packages/testing-kit/tsconfig.build.json +++ b/packages/testing-kit/tsconfig.build.json @@ -4,5 +4,6 @@ "composite": true, "outDir": "dist" }, - "include": ["bin/**/*", "hardhat/**/*", "./src/**/*"] + "include": ["bin/**/*", "src/**/*"], + "files": ["./hardhat.config.ts"] } diff --git a/packages/testing-kit/tsconfig.json b/packages/testing-kit/tsconfig.json index 476c559ca..c35515726 100644 --- a/packages/testing-kit/tsconfig.json +++ b/packages/testing-kit/tsconfig.json @@ -4,5 +4,5 @@ "composite": true, "outDir": "dist" }, - "include": ["./hardhat.config.ts", "bin/**/*", "./src/**/*"] + "include": ["bin/**/*", "src/**/*"] }