From c0e8a725699847fbee11abb7650351128318a3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Mon, 22 Apr 2024 22:25:51 +0200 Subject: [PATCH] Simplify provider retrieval in test --- .../tests/e2e/contractManager.test.ts | 19 +-- packages/protocol-kit/tests/e2e/core.test.ts | 57 +++---- .../createSafeDeploymentTransaction.test.ts | 41 ++--- .../tests/e2e/createTransaction.test.ts | 54 +++---- .../e2e/eip1271-contract-signatures.test.ts | 37 ++--- .../protocol-kit/tests/e2e/eip1271.test.ts | 13 +- .../protocol-kit/tests/e2e/erc-20.test.ts | 28 ++-- .../protocol-kit/tests/e2e/execution.test.ts | 145 ++++++------------ .../tests/e2e/fallbackHandlerManager.test.ts | 59 +++---- .../tests/e2e/getEncodedTransaction.test.ts | 14 +- .../tests/e2e/guardManager.test.ts | 55 +++---- .../tests/e2e/moduleManager.test.ts | 94 +++++------- .../tests/e2e/offChainSignatures.test.ts | 50 +++--- .../tests/e2e/onChainSignatures.test.ts | 29 ++-- .../tests/e2e/ownerManager.test.ts | 144 ++++++----------- .../tests/e2e/safeFactory.test.ts | 73 ++++----- .../tests/e2e/safeProvider.test.ts | 26 ++-- .../protocol-kit/tests/e2e/threshold.test.ts | 26 ++-- .../tests/e2e/utilsContracts.test.ts | 35 ++--- ...SafeTransactionIntoDeploymentBatch.test.ts | 19 +-- 20 files changed, 361 insertions(+), 657 deletions(-) diff --git a/packages/protocol-kit/tests/e2e/contractManager.test.ts b/packages/protocol-kit/tests/e2e/contractManager.test.ts index a800b7604..7168ffca9 100644 --- a/packages/protocol-kit/tests/e2e/contractManager.test.ts +++ b/packages/protocol-kit/tests/e2e/contractManager.test.ts @@ -27,18 +27,19 @@ describe('Safe contracts manager', () => { 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 + chainId, + provider } }) describe('create', async () => { it('should initialize the SDK with a Safe that is not deployed', async () => { - const { accounts, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { accounts, contractNetworks, provider } = await setupTests() const predictedSafe: PredictedSafeProps = { safeAccountConfig: { owners: [accounts[0].address], @@ -58,8 +59,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 } = await setupTests() - const provider = getEip1193Provider() + const { safe, provider } = await setupTests() const safeAddress = await safe.getAddress() await chai .expect( @@ -72,8 +72,7 @@ describe('Safe contracts manager', () => { }) it('should fail if SafeProxy contract is not deployed on the current network', async () => { - const { contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, provider } = await setupTests() await chai .expect( Safe.create({ @@ -86,7 +85,7 @@ describe('Safe contracts manager', () => { }) it('should fail if MultiSend contract is specified in contractNetworks but not deployed', async () => { - const { safe, chainId } = await setupTests() + const { safe, chainId, provider } = await setupTests() const customContractNetworks: ContractNetworksConfig = { [chainId.toString()]: { safeSingletonAddress: ZERO_ADDRESS, @@ -108,7 +107,6 @@ describe('Safe contracts manager', () => { } } - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() await chai .expect( @@ -122,8 +120,7 @@ describe('Safe contracts manager', () => { }) it('should set the MultiSend contract available on the current network', async () => { - const { safe, chainId, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, chainId, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, diff --git a/packages/protocol-kit/tests/e2e/core.test.ts b/packages/protocol-kit/tests/e2e/core.test.ts index 4cc58b942..7e53961f3 100644 --- a/packages/protocol-kit/tests/e2e/core.test.ts +++ b/packages/protocol-kit/tests/e2e/core.test.ts @@ -28,9 +28,11 @@ describe('Safe Info', () => { safeVersion: safeVersionDeployed } } + const provider = getEip1193Provider() return { chainId, safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), + provider, predictedSafe, accounts, contractNetworks @@ -41,8 +43,7 @@ describe('Safe Info', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to connect a Safe { - const { predictedSafe, safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -61,9 +62,8 @@ describe('Safe Info', () => { itif(safeVersionDeployed >= '1.3.0')( 'should connect a Safe >=v1.3.0 that is not deployed', async () => { - const { predictedSafe, safe, accounts, contractNetworks } = await setupTests() + const { predictedSafe, safe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -78,9 +78,8 @@ describe('Safe Info', () => { ) it('should connect a deployed Safe', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3] = accounts - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -92,9 +91,7 @@ describe('Safe Info', () => { .expect(await safeSdk.getSafeProvider().getSignerAddress()) .to.be.eq(await account1.signer.getAddress()) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk.connect({ - provider: provider2, signer: account2.address, contractNetworks }) @@ -104,11 +101,9 @@ describe('Safe Info', () => { .to.be.eq(await account2.signer.getAddress()) const safe2 = await getSafeWithOwners([account3.address]) - const provider3 = getEip1193Provider() const safe2Address = await safe2.getAddress() const safeSdk3 = await safeSdk2.connect({ safeAddress: safe2Address, - provider: provider3, signer: account3.address }) chai.expect(await safeSdk3.getAddress()).to.be.eq(safe2Address) @@ -120,8 +115,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 } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -132,8 +126,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 } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeConfig: PredictedSafeProps = { ...predictedSafe, safeDeploymentConfig: {} @@ -148,8 +141,7 @@ describe('Safe Info', () => { }) it('should return the Safe contract version', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -165,8 +157,7 @@ describe('Safe Info', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to return the address of a Safe { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -184,8 +175,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 } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -206,8 +196,7 @@ describe('Safe Info', () => { ) it('should return the address of a deployed Safe', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -220,9 +209,8 @@ describe('Safe Info', () => { describe('getEip1193Provider', async () => { it('should return the connected SafeProvider', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -237,8 +225,7 @@ describe('Safe Info', () => { describe('getNonce', async () => { it('should return the nonce of a Safe that is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -248,9 +235,8 @@ describe('Safe Info', () => { }) it('should return the Safe nonce', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ @@ -274,8 +260,7 @@ describe('Safe Info', () => { describe('getChainId', async () => { it('should return the chainId of a Safe that is not deployed', async () => { - const { predictedSafe, chainId, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, chainId, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -285,8 +270,7 @@ describe('Safe Info', () => { }) it('should return the chainId of the current network', async () => { - const { safe, chainId, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, chainId, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -301,8 +285,7 @@ describe('Safe Info', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to return the balance of a Safe { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -319,9 +302,8 @@ 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 } = await setupTests() + const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -343,9 +325,8 @@ describe('Safe Info', () => { ) it('should return the balance of a deployed Safe', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, diff --git a/packages/protocol-kit/tests/e2e/createSafeDeploymentTransaction.test.ts b/packages/protocol-kit/tests/e2e/createSafeDeploymentTransaction.test.ts index 50c482b19..5c4feb530 100644 --- a/packages/protocol-kit/tests/e2e/createSafeDeploymentTransaction.test.ts +++ b/packages/protocol-kit/tests/e2e/createSafeDeploymentTransaction.test.ts @@ -23,7 +23,7 @@ describe('createSafeDeploymentTransaction', () => { 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], @@ -38,14 +38,13 @@ describe('createSafeDeploymentTransaction', () => { accounts, contractNetworks, predictedSafe, - chainId + chainId, + provider } }) itif(safeVersionDeployed == '1.4.1')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe } = await setupTests() - - const provider = getEip1193Provider() + const { contractNetworks, predictedSafe, provider } = await setupTests() const safeSdk = await Safe.create({ provider, @@ -66,9 +65,7 @@ describe('createSafeDeploymentTransaction', () => { }) itif(safeVersionDeployed == '1.3.0')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe } = await setupTests() - - const provider = getEip1193Provider() + const { contractNetworks, predictedSafe, provider } = await setupTests() const safeSdk = await Safe.create({ provider, @@ -89,9 +86,7 @@ describe('createSafeDeploymentTransaction', () => { }) itif(safeVersionDeployed == '1.2.0')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe } = await setupTests() - - const provider = getEip1193Provider() + const { contractNetworks, predictedSafe, provider } = await setupTests() const safeSdk = await Safe.create({ provider, @@ -112,9 +107,7 @@ describe('createSafeDeploymentTransaction', () => { }) itif(safeVersionDeployed == '1.1.1')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe } = await setupTests() - - const provider = getEip1193Provider() + const { contractNetworks, predictedSafe, provider } = await setupTests() const safeSdk = await Safe.create({ provider, @@ -135,9 +128,7 @@ describe('createSafeDeploymentTransaction', () => { }) itif(safeVersionDeployed == '1.0.0')('should return a Safe deployment transactions', async () => { - const { contractNetworks, predictedSafe } = await setupTests() - - const provider = getEip1193Provider() + const { contractNetworks, predictedSafe, provider } = await setupTests() const safeSdk = await Safe.create({ provider, @@ -158,9 +149,8 @@ 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 } = await setupTests() + const { contractNetworks, predictedSafe, chainId, provider } = await setupTests() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -190,9 +180,8 @@ describe('createSafeDeploymentTransaction', () => { describe('salt nonce', () => { it('should include the predetermined salt nonce in the Safe deployment data', async () => { - const { contractNetworks, predictedSafe, chainId } = await setupTests() + const { contractNetworks, predictedSafe, chainId, provider } = await setupTests() - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const safeSdk = await Safe.create({ provider, @@ -214,9 +203,8 @@ describe('createSafeDeploymentTransaction', () => { }) it('should include the custom salt nonce in the Safe deployment data', async () => { - const { contractNetworks, predictedSafe } = await setupTests() + const { contractNetworks, predictedSafe, provider } = await setupTests() - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const safeSdk = await Safe.create({ provider, @@ -235,9 +223,7 @@ describe('createSafeDeploymentTransaction', () => { }) it('should include the salt nonce included in the safeDeploymentConfig in the Safe deployment data', async () => { - const { contractNetworks, predictedSafe } = await setupTests() - - const provider = getEip1193Provider() + const { contractNetworks, predictedSafe, provider } = await setupTests() const customSaltNonce = '123456789' @@ -265,11 +251,10 @@ describe('createSafeDeploymentTransaction', () => { }) it('should throw an error if predicted Safe is not present', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ diff --git a/packages/protocol-kit/tests/e2e/createTransaction.test.ts b/packages/protocol-kit/tests/e2e/createTransaction.test.ts index 1f20bbcb8..814e796c2 100644 --- a/packages/protocol-kit/tests/e2e/createTransaction.test.ts +++ b/packages/protocol-kit/tests/e2e/createTransaction.test.ts @@ -2,9 +2,10 @@ import { safeVersionDeployed } from '@safe-global/protocol-kit/hardhat/deploy/de import Safe, { PredictedSafeProps, SafeTransactionOptionalProps, - standardizeSafeTransactionData + standardizeSafeTransactionData, + SafeContractImplementationType as SafeContract } from '@safe-global/protocol-kit/index' -import { SafeContract, SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types' +import { SafeTransactionDataPartial } from '@safe-global/safe-core-sdk-types' import chai from 'chai' import chaiAsPromised from 'chai-as-promised' import { deployments } from 'hardhat' @@ -31,6 +32,7 @@ describe('Transactions creation', () => { 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], @@ -46,7 +48,8 @@ describe('Transactions creation', () => { accounts, chainId, contractNetworks, - predictedSafe + predictedSafe, + provider } }) @@ -54,10 +57,9 @@ describe('Transactions creation', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return a transaction with safeTxGas=0 if safeVersion>=1.3.0 and gasPrice=0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -82,10 +84,9 @@ 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 } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -111,10 +112,9 @@ describe('Transactions creation', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return a transaction with defined safeTxGas if safeVersion>=1.3.0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -141,10 +141,9 @@ describe('Transactions creation', () => { itif(safeVersionDeployed < '1.3.0')( 'should return a transaction with estimated safeTxGas if safeVersion<1.3.0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -169,10 +168,9 @@ 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 } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -199,10 +197,9 @@ describe('Transactions creation', () => { itif(safeVersionDeployed < '1.3.0')( 'should return a transaction with defined safeTxGas if safeVersion<1.3.0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -229,9 +226,8 @@ describe('Transactions creation', () => { describe('createTransaction', async () => { it('should create a single transaction with gasPrice=0', async () => { - const { predictedSafe, accounts, contractNetworks } = await setupTests() + const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() const [, account2] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -251,10 +247,9 @@ describe('Transactions creation', () => { }) it('should create a single transaction with gasPrice=0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -282,10 +277,9 @@ describe('Transactions creation', () => { }) it('should create a single transaction with gasPrice>0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -313,10 +307,9 @@ describe('Transactions creation', () => { }) it('should create a single transaction when passing a transaction array with length=1', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -335,10 +328,9 @@ describe('Transactions creation', () => { }) it('should create a single transaction when passing a transaction array with length=1 and options', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -364,10 +356,9 @@ describe('Transactions creation', () => { }) it('should fail when creating a MultiSend transaction passing a transaction array with length=0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -379,10 +370,9 @@ describe('Transactions creation', () => { }) it('should create a MultiSend transaction', async () => { - const { accounts, contractNetworks, erc20Mintable, chainId } = await setupTests() + const { accounts, contractNetworks, erc20Mintable, chainId, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -414,11 +404,10 @@ describe('Transactions creation', () => { }) it('should create a MultiSend transaction with options', async () => { - const { accounts, contractNetworks, erc20Mintable, chainId } = await setupTests() + const { accounts, contractNetworks, erc20Mintable, chainId, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, @@ -460,8 +449,7 @@ describe('Transactions creation', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail to create a transaction if the Safe with version { - const { safe, predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, predictedSafe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, 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 bcb5ff3d6..d11181548 100644 --- a/packages/protocol-kit/tests/e2e/eip1271-contract-signatures.test.ts +++ b/packages/protocol-kit/tests/e2e/eip1271-contract-signatures.test.ts @@ -23,6 +23,7 @@ describe('The EIP1271 implementation', () => { const contractNetworks = await getContractNetworks(BigInt(chainId)) const fallbackHandlerAddress = contractNetworks[chainId].fallbackHandlerAddress const [account1, account2, account3, account4, account5] = accounts + const provider = getEip1193Provider() // Create a 1/1 signer Safe const signerSafe1_1 = await getSafeWithOwners( @@ -59,7 +60,8 @@ describe('The EIP1271 implementation', () => { accounts, contractNetworks, chainId, - fallbackHandlerAddress + fallbackHandlerAddress, + provider } }) @@ -71,20 +73,15 @@ describe('The EIP1271 implementation', () => { accounts, signerSafeAddress1_1, signerSafeAddress2_3, - contractNetworks + contractNetworks, + provider } = await setupTests() // Create adapters and the protocol kit instance const [account1, account2, account3, account4, account5] = accounts - const provider1 = getEip1193Provider() - const provider2 = getEip1193Provider() - const provider3 = getEip1193Provider() - const provider4 = getEip1193Provider() - const provider5 = getEip1193Provider() - let protocolKit = await Safe.create({ - provider: provider1, + provider: provider, safeAddress, contractNetworks }) @@ -103,14 +100,12 @@ describe('The EIP1271 implementation', () => { // EOA signatures tx = await protocolKit.signTransaction(tx) // Owner 1 signature protocolKit = await protocolKit.connect({ - provider: provider2, signer: account2.address }) // Connect another owner tx = await protocolKit.signTransaction(tx) // Owner 2 signature // 1/1 Signer Safe signature protocolKit = await protocolKit.connect({ - provider: provider3, signer: account3.address, safeAddress: signerSafeAddress1_1 }) @@ -130,7 +125,6 @@ describe('The EIP1271 implementation', () => { // 2/3 Signer Safe signature protocolKit = await protocolKit.connect({ - provider: provider4, signer: account4.address, safeAddress: signerSafeAddress2_3 }) @@ -143,7 +137,6 @@ describe('The EIP1271 implementation', () => { safeAddress ) protocolKit = await protocolKit.connect({ - provider: provider5, signer: account5.address }) signerSafeTx2_3 = await protocolKit.signTransaction( @@ -163,7 +156,7 @@ describe('The EIP1271 implementation', () => { value: 1_000_000_000_000_000_000n // 1 ETH }) protocolKit = await protocolKit.connect({ - provider: provider1, + provider: provider, signer: account1.address, safeAddress }) @@ -185,7 +178,8 @@ describe('The EIP1271 implementation', () => { signerSafeAddress1_1, signerSafeAddress2_3, contractNetworks, - chainId + chainId, + provider } = await setupTests() const MESSAGE = { @@ -238,14 +232,8 @@ describe('The EIP1271 implementation', () => { // Create adapters and the protocol kit instance const [account1, account2, account3, account4, account5] = accounts - const provider1 = getEip1193Provider() - const provider2 = getEip1193Provider() - const provider3 = getEip1193Provider() - const provider4 = getEip1193Provider() - const provider5 = getEip1193Provider() - let protocolKit = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) @@ -255,14 +243,12 @@ describe('The EIP1271 implementation', () => { // EOA signatures message = await protocolKit.signMessage(message) // Owner 1 signature protocolKit = await protocolKit.connect({ - provider: provider2, signer: account2.address }) // Connect another owner message = await protocolKit.signMessage(message) // Owner 2 signature // 1/1 Signer Safe signature protocolKit = await protocolKit.connect({ - provider: provider3, signer: account3.address, safeAddress: signerSafeAddress1_1 }) @@ -280,7 +266,6 @@ describe('The EIP1271 implementation', () => { // 2/3 Signer Safe signature protocolKit = await protocolKit.connect({ - provider: provider4, signer: account4.address, safeAddress: signerSafeAddress2_3 }) @@ -291,7 +276,6 @@ describe('The EIP1271 implementation', () => { safeAddress ) protocolKit = await protocolKit.connect({ - provider: provider5, signer: account5.address }) signerSafeMessage2_3 = await protocolKit.signMessage( @@ -307,7 +291,6 @@ describe('The EIP1271 implementation', () => { // Connect the original Safe protocolKit = await protocolKit.connect({ - provider: provider1, signer: account1.address, safeAddress }) diff --git a/packages/protocol-kit/tests/e2e/eip1271.test.ts b/packages/protocol-kit/tests/e2e/eip1271.test.ts index 2c08dbf7a..8e97e5655 100644 --- a/packages/protocol-kit/tests/e2e/eip1271.test.ts +++ b/packages/protocol-kit/tests/e2e/eip1271.test.ts @@ -48,6 +48,7 @@ describe('The EIP1271 implementation', () => { const contractNetworks = await getContractNetworks(BigInt(chainId)) const fallbackHandlerAddress = contractNetworks[chainId].fallbackHandlerAddress const [account1, account2] = accounts + const provider = getEip1193Provider() // Create a 1/2 Safe to sign the messages const signerSafe = await getSafeWithOwners( @@ -65,18 +66,15 @@ describe('The EIP1271 implementation', () => { ) const safeAddress = await safe.getAddress() - // Adapter and Safe instance for owner 1 - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) // Adapter and Safe instance for owner 2 - const provider2 = getEip1193Provider() const safeSdk2 = await Safe.create({ - provider: provider2, + provider, signer: account2.address, safeAddress, contractNetworks @@ -84,7 +82,7 @@ describe('The EIP1271 implementation', () => { // Adapter and Safe instance for owner 3 const safeSdk3 = await Safe.create({ - provider: provider1, + provider, signer: account1.address, safeAddress: signerSafeAddress, contractNetworks @@ -97,9 +95,8 @@ describe('The EIP1271 implementation', () => { signerSafeAddress, accounts, contractNetworks, + provider, chainId, - provider1, - provider2, safeSdk1, safeSdk2, safeSdk3, diff --git a/packages/protocol-kit/tests/e2e/erc-20.test.ts b/packages/protocol-kit/tests/e2e/erc-20.test.ts index e58367c91..82b44fc7f 100644 --- a/packages/protocol-kit/tests/e2e/erc-20.test.ts +++ b/packages/protocol-kit/tests/e2e/erc-20.test.ts @@ -35,11 +35,13 @@ describe('ERC-20 utils', () => { 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 + accounts, + provider } }) @@ -47,12 +49,10 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return the correct decimals for a standard ERC20 token', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() - // mock decimals() call callStub = sinon.stub(SafeProvider.prototype, 'call').returns(Promise.resolve('0x12')) @@ -71,11 +71,9 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return the correct decimals for a non-standard ERC20 token', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() - // mock decimals() call callStub = sinon.stub(SafeProvider.prototype, 'call').returns(Promise.resolve('0x06')) @@ -94,11 +92,9 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should throw an error if decimals() fn is not defined', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() - // mock decimals() call callStub = sinon.stub(SafeProvider.prototype, 'call').returns(Promise.resolve('0x')) @@ -119,11 +115,9 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return true if it is the Native token', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() - const safeSdk = await Safe.create({ provider, safeAddress, @@ -142,11 +136,9 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return true if it is an standard ERC20 token', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() - // mock decimals() call callStub = sinon.stub(SafeProvider.prototype, 'call').returns(Promise.resolve('0x12')) @@ -168,11 +160,9 @@ describe('ERC-20 utils', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return false for a non-standard ERC20 token', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() - // mock decimals() call callStub = sinon.stub(SafeProvider.prototype, 'call').returns(Promise.resolve('0x06')) diff --git a/packages/protocol-kit/tests/e2e/execution.test.ts b/packages/protocol-kit/tests/e2e/execution.test.ts index ea4322f92..9e8e8e998 100644 --- a/packages/protocol-kit/tests/e2e/execution.test.ts +++ b/packages/protocol-kit/tests/e2e/execution.test.ts @@ -23,29 +23,29 @@ describe('Transactions execution', () => { 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 + contractNetworks, + provider } }) describe('isValidTransaction', async () => { it('should return false if a transaction will not be executed successfully', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address, contractNetworks }) @@ -72,11 +72,10 @@ describe('Transactions execution', () => { }) it('should return true if a transaction will execute successfully', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -102,11 +101,10 @@ describe('Transactions execution', () => { describe('executeTransaction', async () => { it('should fail if there are not enough Ether funds', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -126,19 +124,17 @@ describe('Transactions execution', () => { }) it('should fail if there are not enough signatures (1 missing)', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3] = accounts const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, contractNetworks }) - const provider2 = getEip1193Provider() + const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) const safeTransactionData = { @@ -157,11 +153,10 @@ describe('Transactions execution', () => { }) it('should fail if there are not enough signatures (>1 missing)', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3] = accounts const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -179,19 +174,16 @@ describe('Transactions execution', () => { }) it('should fail if the user tries to execute a transaction that was rejected', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address, contractNetworks }) @@ -216,11 +208,10 @@ describe('Transactions execution', () => { }) it('should fail if a user tries to execute a transaction with options: { gas, gasLimit }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -243,11 +234,10 @@ describe('Transactions execution', () => { }) it('should fail if a user tries to execute a transaction with options: { nonce: }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -270,11 +260,10 @@ describe('Transactions execution', () => { }) it('should execute a transaction with threshold 1', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -303,7 +292,7 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'web3' && safeVersionDeployed === '1.0.0')( 'should execute a transaction with threshold >1 and all different kind of signatures with web3 provider and safeVersion===1.0.0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3] = accounts const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) const safeAddress = await safe.getAddress() @@ -311,20 +300,15 @@ describe('Transactions execution', () => { to: safeAddress, value: 1_000_000_000_000_000_000n // 1 ETH }) - const provider1 = getEip1193Provider() - const provider2 = getEip1193Provider() - const provider3 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) const safeInitialBalance = await safeSdk1.getBalance() @@ -356,7 +340,7 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'web3' && safeVersionDeployed > '1.0.0')( 'should execute a transaction with threshold >1 and all different kind of signatures with web3 provider and safeVersion>1.0.0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3, account4] = accounts const safe = await getSafeWithOwners([ account1.address, @@ -369,25 +353,18 @@ describe('Transactions execution', () => { to: safeAddress, value: 1_000_000_000_000_000_000n // 1 ETH }) - const provider1 = getEip1193Provider() - const provider2 = getEip1193Provider() - const provider3 = getEip1193Provider() - const provider4 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) const safeSdk4 = await safeSdk1.connect({ - provider: provider4, signer: account4.address }) const safeInitialBalance = await safeSdk1.getBalance() @@ -422,7 +399,7 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'ethers' && safeVersionDeployed === '1.0.0')( 'should execute a transaction with threshold >1 and all different kind of signatures with ethers provider and safeVersion===1.0.0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3, account4, account5] = accounts const safe = await getSafeWithOwners([ account1.address, @@ -436,30 +413,21 @@ describe('Transactions execution', () => { to: safeAddress, value: 1_000_000_000_000_000_000n // 1 ETH }) - const provider1 = getEip1193Provider() - const provider2 = getEip1193Provider() - const provider3 = getEip1193Provider() - const provider4 = getEip1193Provider() - const provider5 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) const safeSdk4 = await safeSdk1.connect({ - provider: provider4, signer: account4.address }) const safeSdk5 = await safeSdk1.connect({ - provider: provider5, signer: account5.address }) const safeInitialBalance = await safeSdk1.getBalance() @@ -497,7 +465,7 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'ethers' && safeVersionDeployed > '1.0.0')( 'should execute a transaction with threshold >1 and all different kind of signatures with ethers provider and safeVersion>1.0.0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3, account4, account5, account6] = accounts const safe = await getSafeWithOwners([ account1.address, @@ -512,35 +480,24 @@ describe('Transactions execution', () => { to: safeAddress, value: 1_000_000_000_000_000_000n // 1 ETH }) - const provider1 = getEip1193Provider() - const provider2 = getEip1193Provider() - const provider3 = getEip1193Provider() - const provider4 = getEip1193Provider() - const provider5 = getEip1193Provider() - const provider6 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) const safeSdk4 = await safeSdk1.connect({ - provider: provider4, signer: account4.address }) const safeSdk5 = await safeSdk1.connect({ - provider: provider5, signer: account5.address }) const safeSdk6 = await safeSdk1.connect({ - provider: provider6, signer: account6.address }) const safeInitialBalance = await safeSdk1.getBalance() @@ -579,25 +536,22 @@ describe('Transactions execution', () => { ) it('should execute a transaction when is not submitted by an owner', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [, account2, account3] = accounts - const provider1 = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) - const provider3 = getEip1193Provider() + const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) + await account2.signer.sendTransaction({ to: safeAddress, value: 1_000_000_000_000_000_000n // 1 ETH @@ -622,11 +576,10 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'ethers')( 'should execute a transaction with options: { gasLimit }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -653,11 +606,10 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'ethers')( 'should execute a transaction with options: { gasLimit, gasPrice }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -688,11 +640,10 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'ethers')( 'should execute a transaction with options: { maxFeePerGas, maxPriorityFeePerGas }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -725,11 +676,10 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'web3')( 'should execute a transaction with options: { gas }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -756,11 +706,10 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'web3')( 'should execute a transaction with options: { gas, gasPrice }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -791,11 +740,10 @@ describe('Transactions execution', () => { itif(process.env.ETH_LIB === 'web3')( 'should execute a transaction with options: { maxFeePerGas, maxPriorityFeePerGas }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -826,11 +774,10 @@ describe('Transactions execution', () => { ) it('should execute a transaction with options: { nonce }', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk1 = await Safe.create({ provider, safeAddress, @@ -857,24 +804,21 @@ describe('Transactions execution', () => { describe('executeTransaction (MultiSend)', async () => { it('should execute a batch transaction with threshold >1', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3] = accounts const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) const safeAddress = await safe.getAddress() - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) - const provider2 = getEip1193Provider() + const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) - const provider3 = getEip1193Provider() + const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) await account1.signer.sendTransaction({ @@ -908,24 +852,21 @@ describe('Transactions execution', () => { }) it('should execute a batch transaction with contract calls and threshold >1', async () => { - const { accounts, contractNetworks, erc20Mintable } = await setupTests() + const { accounts, contractNetworks, erc20Mintable, provider } = await setupTests() const [account1, account2, account3] = accounts const safe = await getSafeWithOwners([account1.address, account2.address, account3.address]) const safeAddress = await safe.getAddress() - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress, contractNetworks }) - const provider2 = getEip1193Provider() + const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) - const provider3 = getEip1193Provider() + const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) diff --git a/packages/protocol-kit/tests/e2e/fallbackHandlerManager.test.ts b/packages/protocol-kit/tests/e2e/fallbackHandlerManager.test.ts index 145dd168c..421ba1770 100644 --- a/packages/protocol-kit/tests/e2e/fallbackHandlerManager.test.ts +++ b/packages/protocol-kit/tests/e2e/fallbackHandlerManager.test.ts @@ -35,12 +35,15 @@ describe('Fallback handler manager', () => { safeVersion: safeVersionDeployed } } + const provider = getEip1193Provider() + return { safe: await getSafeWithOwners([accounts[0].address]), accounts, contractNetworks, defaultCallbackHandler: await getDefaultCallbackHandler(), - predictedSafe + predictedSafe, + provider } }) @@ -48,9 +51,8 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.1.1')( 'should fail if getting the enabled fallback handler is not supported', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, @@ -66,8 +68,7 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -77,8 +78,7 @@ describe('Fallback handler manager', () => { }) itif(safeVersionDeployed >= '1.1.1')('should return the enabled fallback handler', async () => { - const { safe, contractNetworks, defaultCallbackHandler } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -104,8 +104,8 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if the Safe with version { - const { predictedSafe, contractNetworks, defaultCallbackHandler } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, defaultCallbackHandler, provider } = + await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -123,8 +123,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 } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, defaultCallbackHandler, provider } = + await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -138,8 +138,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.1.1')( 'should fail if enabling a fallback handler is not supported', async () => { - const { safe, contractNetworks, defaultCallbackHandler } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -156,8 +155,7 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should fail if address is invalid', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -171,8 +169,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.1.1')( 'should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -185,8 +182,7 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should fail if address is already enabled', async () => { - const { safe, contractNetworks, defaultCallbackHandler } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -205,8 +201,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.1.1')( 'should build the transaction with the optional props', async () => { - const { safe, contractNetworks, defaultCallbackHandler } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -235,8 +230,7 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should enable a fallback handler', async () => { - const { safe, contractNetworks, defaultCallbackHandler } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -262,8 +256,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if the Safe with version { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -281,8 +274,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 } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, defaultCallbackHandler, provider } = + await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -296,11 +289,10 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed < '1.1.1')( 'should fail if disabling a fallback handler is not supported', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, @@ -318,8 +310,7 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.1.1')( 'should fail if no fallback handler is enabled', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -340,11 +331,10 @@ describe('Fallback handler manager', () => { itif(safeVersionDeployed >= '1.1.1')( 'should build the transaction with the optional props', async () => { - const { accounts, contractNetworks, defaultCallbackHandler } = await setupTests() + const { accounts, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, @@ -378,11 +368,10 @@ describe('Fallback handler manager', () => { ) itif(safeVersionDeployed >= '1.1.1')('should disable an enabled fallback handler', async () => { - const { accounts, contractNetworks, defaultCallbackHandler } = await setupTests() + const { accounts, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, diff --git a/packages/protocol-kit/tests/e2e/getEncodedTransaction.test.ts b/packages/protocol-kit/tests/e2e/getEncodedTransaction.test.ts index c7b133192..8cd49ca9b 100644 --- a/packages/protocol-kit/tests/e2e/getEncodedTransaction.test.ts +++ b/packages/protocol-kit/tests/e2e/getEncodedTransaction.test.ts @@ -14,19 +14,21 @@ describe('getEncodedTransaction', () => { const accounts = await getAccounts() const chainId = BigInt(await getChainId()) const contractNetworks = await getContractNetworks(chainId) + const provider = getEip1193Provider() + return { accounts, - contractNetworks + contractNetworks, + provider } }) itif(safeVersionDeployed >= '1.3.0')('should return a transaction encoded', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, @@ -52,12 +54,11 @@ describe('getEncodedTransaction', () => { }) itif(safeVersionDeployed <= '1.2.0')('should return a transaction encoded', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, @@ -83,12 +84,11 @@ describe('getEncodedTransaction', () => { }) it('should return a signed transaction with the signatures encoded', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, diff --git a/packages/protocol-kit/tests/e2e/guardManager.test.ts b/packages/protocol-kit/tests/e2e/guardManager.test.ts index 022dc64ba..35c04e427 100644 --- a/packages/protocol-kit/tests/e2e/guardManager.test.ts +++ b/packages/protocol-kit/tests/e2e/guardManager.test.ts @@ -22,6 +22,7 @@ describe('Safe guard manager', () => { 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], @@ -36,7 +37,8 @@ describe('Safe guard manager', () => { safe: await getSafeWithOwners([accounts[0].address]), accounts, contractNetworks, - predictedSafe + predictedSafe, + provider } }) @@ -44,8 +46,7 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if getting the enabled guard is not supported', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -62,8 +63,7 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -75,8 +75,7 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should return 0x address when no Safe guard is enabled', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -88,8 +87,7 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should return the enabled Safe guard', async () => { - const { safe, contractNetworks, debugTransactionGuard } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -108,9 +106,7 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if enabling a Safe guard is not supported', async () => { - const { safe, contractNetworks, debugTransactionGuard } = await setupTests() - - const provider = getEip1193Provider() + const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -127,9 +123,9 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should fail if the Safe is not deployed', async () => { - const { predictedSafe, debugTransactionGuard, contractNetworks } = await setupTests() + const { predictedSafe, debugTransactionGuard, contractNetworks, provider } = + await setupTests() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -140,9 +136,7 @@ describe('Safe guard manager', () => { }) itif(safeVersionDeployed >= '1.3.0')('should fail if address is invalid', async () => { - const { safe, contractNetworks } = await setupTests() - - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -156,9 +150,8 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -171,9 +164,8 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should fail if address is already enabled', async () => { - const { safe, contractNetworks, debugTransactionGuard } = await setupTests() + const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -190,9 +182,8 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should build the transaction with the optional props', async () => { - const { safe, contractNetworks, debugTransactionGuard } = await setupTests() + const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -221,9 +212,8 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should enable a Safe guard', async () => { - const { safe, contractNetworks, debugTransactionGuard } = await setupTests() + const { safe, contractNetworks, debugTransactionGuard, provider } = await setupTests() - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -242,10 +232,9 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed < '1.3.0')( 'should fail if disabling a Safe guard is not supported', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -262,9 +251,8 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() + const { predictedSafe, contractNetworks, provider } = await setupTests() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -275,9 +263,8 @@ describe('Safe guard manager', () => { }) itif(safeVersionDeployed >= '1.3.0')('should fail if no Safe guard is enabled', async () => { - const { safe, contractNetworks } = await setupTests() + const { safe, contractNetworks, provider } = await setupTests() - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -291,11 +278,10 @@ describe('Safe guard manager', () => { itif(safeVersionDeployed >= '1.3.0')( 'should build the transaction with the optional props', async () => { - const { accounts, contractNetworks, debugTransactionGuard } = await setupTests() + const { accounts, contractNetworks, debugTransactionGuard, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, @@ -324,11 +310,10 @@ describe('Safe guard manager', () => { ) itif(safeVersionDeployed >= '1.3.0')('should disable an enabled Safe guard', async () => { - const { accounts, contractNetworks, debugTransactionGuard } = await setupTests() + const { accounts, contractNetworks, debugTransactionGuard, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, diff --git a/packages/protocol-kit/tests/e2e/moduleManager.test.ts b/packages/protocol-kit/tests/e2e/moduleManager.test.ts index 65a627bc8..b85355712 100644 --- a/packages/protocol-kit/tests/e2e/moduleManager.test.ts +++ b/packages/protocol-kit/tests/e2e/moduleManager.test.ts @@ -34,20 +34,22 @@ describe('Safe modules manager', () => { safeVersion: safeVersionDeployed } } + const provider = getEip1193Provider() + return { dailyLimitModule: await getDailyLimitModule(), socialRecoveryModule: await getSocialRecoveryModule(), safe: await getSafeWithOwners([accounts[0].address]), accounts, contractNetworks, - predictedSafe + predictedSafe, + provider } }) describe('getModules', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -57,8 +59,8 @@ describe('Safe modules manager', () => { }) it('should return all the enabled modules', async () => { - const { safe, dailyLimitModule, socialRecoveryModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, dailyLimitModule, socialRecoveryModule, contractNetworks, provider } = + await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -86,11 +88,9 @@ describe('Safe modules manager', () => { describe('getModulesPaginated', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks } = await setupTests() - const [account1] = accounts - const ethAdapter = await getEthAdapter(account1.signer) + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ - ethAdapter, + provider, predictedSafe, contractNetworks }) @@ -100,12 +100,10 @@ describe('Safe modules manager', () => { }) it('should return the enabled modules', async () => { - const { safe, accounts, dailyLimitModule, contractNetworks } = await setupTests() - const [account1] = accounts - const ethAdapter = await getEthAdapter(account1.signer) + const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ - ethAdapter, + provider, safeAddress, contractNetworks }) @@ -117,15 +115,13 @@ describe('Safe modules manager', () => { }) it('should constraint returned modules by pageSize', async () => { - const { safe, accounts, dailyLimitModule, contractNetworks, socialRecoveryModule } = + const { safe, dailyLimitModule, contractNetworks, socialRecoveryModule, provider } = await setupTests() - const [account1] = accounts - const ethAdapter = await getEthAdapter(account1.signer) const safeAddress = await safe.getAddress() - const dailyLimitsAddress = await await dailyLimitModule.getAddress() - const socialRecoveryAddress = await await socialRecoveryModule.getAddress() + const dailyLimitsAddress = await dailyLimitModule.getAddress() + const socialRecoveryAddress = await socialRecoveryModule.getAddress() const safeSdk = await Safe.create({ - ethAdapter, + provider, safeAddress, contractNetworks }) @@ -144,15 +140,13 @@ describe('Safe modules manager', () => { }) it('should offset the returned modules', async () => { - const { safe, accounts, dailyLimitModule, contractNetworks, socialRecoveryModule } = + const { safe, dailyLimitModule, contractNetworks, socialRecoveryModule, provider } = await setupTests() - const [account1] = accounts - const ethAdapter = await getEthAdapter(account1.signer) const safeAddress = await safe.getAddress() const dailyLimitsAddress = await await dailyLimitModule.getAddress() const socialRecoveryAddress = await await socialRecoveryModule.getAddress() const safeSdk = await Safe.create({ - ethAdapter, + provider, safeAddress, contractNetworks }) @@ -172,11 +166,9 @@ describe('Safe modules manager', () => { }) it('should fail if pageSize is invalid', async () => { - const { predictedSafe, accounts, contractNetworks } = await setupTests() - const [account1] = accounts - const ethAdapter = await getEthAdapter(account1.signer) + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ - ethAdapter, + provider, predictedSafe, contractNetworks }) @@ -189,8 +181,7 @@ describe('Safe modules manager', () => { describe('isModuleEnabled', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, dailyLimitModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -201,8 +192,7 @@ describe('Safe modules manager', () => { }) it('should return true if a module is enabled', async () => { - const { safe, dailyLimitModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -219,8 +209,7 @@ describe('Safe modules manager', () => { describe('createEnableModuleTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, dailyLimitModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -231,8 +220,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is invalid', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -244,8 +232,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is equal to sentinel', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -257,8 +244,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -270,8 +256,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is already enabled', async () => { - const { safe, dailyLimitModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -286,8 +271,7 @@ describe('Safe modules manager', () => { }) it('should build the transaction with the optional props', async () => { - const { safe, dailyLimitModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -312,8 +296,7 @@ describe('Safe modules manager', () => { }) it('should enable a Safe module', async () => { - const { safe, dailyLimitModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -332,8 +315,7 @@ describe('Safe modules manager', () => { describe('createDisableModuleTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, dailyLimitModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -344,8 +326,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is invalid', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -357,8 +338,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is equal to sentinel', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -370,8 +350,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -383,8 +362,7 @@ describe('Safe modules manager', () => { }) it('should fail if address is not enabled', async () => { - const { safe, dailyLimitModule, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, dailyLimitModule, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -396,11 +374,10 @@ describe('Safe modules manager', () => { }) it('should build the transaction with the optional props', async () => { - const { dailyLimitModule, accounts, contractNetworks } = await setupTests() + const { dailyLimitModule, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, @@ -431,12 +408,11 @@ describe('Safe modules manager', () => { }) it('should disable Safe modules', async () => { - const { dailyLimitModule, accounts, socialRecoveryModule, contractNetworks } = + const { dailyLimitModule, accounts, socialRecoveryModule, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress, diff --git a/packages/protocol-kit/tests/e2e/offChainSignatures.test.ts b/packages/protocol-kit/tests/e2e/offChainSignatures.test.ts index 316bdc7be..ee25bdb90 100644 --- a/packages/protocol-kit/tests/e2e/offChainSignatures.test.ts +++ b/packages/protocol-kit/tests/e2e/offChainSignatures.test.ts @@ -27,18 +27,20 @@ describe('Off-chain signatures', () => { safeVersion: safeVersionDeployed } } + const provider = getEip1193Provider() + return { safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), accounts, contractNetworks, - predictedSafe + predictedSafe, + provider } }) describe('signHash', async () => { it('should sign a transaction hash with the current signer if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -50,8 +52,7 @@ describe('Off-chain signatures', () => { }) it('should sign a transaction hash with the current signer', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -74,8 +75,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 } = await setupTests() - const provider = getEip1193Provider() + const { safe, predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -107,8 +107,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 } = await setupTests() - const provider = getEip1193Provider() + const { safe, predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -129,9 +128,8 @@ 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 } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const account3 = accounts[2] - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -151,8 +149,7 @@ describe('Off-chain signatures', () => { }) it('should ignore duplicated signatures', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -176,8 +173,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 } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -199,8 +195,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 } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -223,8 +218,7 @@ describe('Off-chain signatures', () => { itif(process.env.ETH_LIB === 'ethers')( 'should add the signature of the current signer using eth_signTypedData with ethers provider', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -247,8 +241,7 @@ describe('Off-chain signatures', () => { itif(process.env.ETH_LIB === 'web3')( 'should fail if the signature of the current signer is added using eth_signTypedData with web3 provider', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -270,8 +263,7 @@ describe('Off-chain signatures', () => { itif(process.env.ETH_LIB === 'ethers')( 'should add the signature of the current signer using eth_signTypedData_v3 with ethers provider', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -294,8 +286,7 @@ describe('Off-chain signatures', () => { itif(process.env.ETH_LIB === 'web3')( 'should fail if the signature of the current signer is added using eth_signTypedData_v3 with web3 provider', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -315,8 +306,7 @@ describe('Off-chain signatures', () => { ) it('should add the signature of the current signer using eth_signTypedData_v4', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -336,8 +326,7 @@ describe('Off-chain signatures', () => { }) it('should add the signature of the current signer using eth_signTypedData_v4 by default', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, @@ -357,9 +346,8 @@ describe('Off-chain signatures', () => { }) it('should sign a transaction received from the Safe Transaction Service', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk = await Safe.create({ provider, diff --git a/packages/protocol-kit/tests/e2e/onChainSignatures.test.ts b/packages/protocol-kit/tests/e2e/onChainSignatures.test.ts index 92bf943ef..cfb98b211 100644 --- a/packages/protocol-kit/tests/e2e/onChainSignatures.test.ts +++ b/packages/protocol-kit/tests/e2e/onChainSignatures.test.ts @@ -26,18 +26,20 @@ describe('On-chain signatures', () => { safeVersion: safeVersionDeployed } } + const provider = getEip1193Provider() + return { safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]), accounts, contractNetworks, - predictedSafe + predictedSafe, + provider } }) describe('approveTransactionHash', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk1 = await Safe.create({ provider, predictedSafe, @@ -50,9 +52,8 @@ 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 } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const account3 = accounts[2] - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk1 = await Safe.create({ provider, @@ -73,9 +74,8 @@ describe('On-chain signatures', () => { }) it('should approve the transaction hash', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk1 = await Safe.create({ provider, @@ -95,9 +95,8 @@ describe('On-chain signatures', () => { }) it('should ignore a duplicated signatures', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk1 = await Safe.create({ provider, @@ -123,10 +122,9 @@ describe('On-chain signatures', () => { describe('getOwnersWhoApprovedTx', async () => { it('should fail if Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider1 = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, predictedSafe, contractNetworks }) @@ -136,18 +134,15 @@ describe('On-chain signatures', () => { }) it('should return the list of owners who approved a transaction hash', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [, account2] = accounts - const provider1 = getEip1193Provider() const safeAddress = await safe.getAddress() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress: safeAddress, contractNetworks }) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) const safeTransactionData = { diff --git a/packages/protocol-kit/tests/e2e/ownerManager.test.ts b/packages/protocol-kit/tests/e2e/ownerManager.test.ts index 3074a4779..9cb046b9f 100644 --- a/packages/protocol-kit/tests/e2e/ownerManager.test.ts +++ b/packages/protocol-kit/tests/e2e/ownerManager.test.ts @@ -21,6 +21,7 @@ describe('Safe owners manager', () => { 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], @@ -38,14 +39,14 @@ describe('Safe owners manager', () => { ]), accounts, contractNetworks, - predictedSafe + predictedSafe, + provider } }) describe('getOwners', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -55,10 +56,9 @@ describe('Safe owners manager', () => { }) it('should return the list of Safe owners', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address, account2.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -73,9 +73,8 @@ describe('Safe owners manager', () => { describe('isOwner', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks } = await setupTests() + const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -85,10 +84,9 @@ describe('Safe owners manager', () => { }) it('should return true if an account is an owner of the connected Safe', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -99,10 +97,9 @@ describe('Safe owners manager', () => { }) it('should return false if an account is not an owner of the connected Safe', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -115,9 +112,8 @@ describe('Safe owners manager', () => { describe('createAddOwnerTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks } = await setupTests() + const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() const [, account2] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -128,10 +124,9 @@ describe('Safe owners manager', () => { }) it('should fail if address is invalid', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -142,10 +137,9 @@ describe('Safe owners manager', () => { }) it('should fail if address is equal to sentinel', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -156,10 +150,9 @@ describe('Safe owners manager', () => { }) it('should fail if address is equal to 0x address', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -170,10 +163,9 @@ describe('Safe owners manager', () => { }) it('should fail if address is already an owner', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -184,10 +176,9 @@ describe('Safe owners manager', () => { }) it('should fail if the threshold is bigger than the number of owners', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -204,10 +195,9 @@ describe('Safe owners manager', () => { }) it('should fail if the threshold is not bigger than 0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -218,10 +208,9 @@ describe('Safe owners manager', () => { }) it('should build the transaction with the optional props', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -245,10 +234,9 @@ describe('Safe owners manager', () => { }) it('should add an owner and keep the same threshold', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -270,10 +258,9 @@ describe('Safe owners manager', () => { }) it('should add an owner and update the threshold', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -299,9 +286,8 @@ describe('Safe owners manager', () => { describe('createRemoveOwnerTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks } = await setupTests() + const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() const [, account2] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -312,8 +298,7 @@ describe('Safe owners manager', () => { }) it('should fail if address is invalid', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -324,8 +309,7 @@ describe('Safe owners manager', () => { }) it('should fail if address is equal to sentinel', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -336,8 +320,7 @@ describe('Safe owners manager', () => { }) it('should fail if address is equal to 0x address', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -348,9 +331,8 @@ describe('Safe owners manager', () => { }) it('should fail if address is not an owner', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [, , , account4] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -361,9 +343,8 @@ describe('Safe owners manager', () => { }) it('should fail if the threshold is bigger than the number of owners', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -380,9 +361,8 @@ describe('Safe owners manager', () => { }) it('should fail if the threshold is not bigger than 0', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -393,11 +373,10 @@ describe('Safe owners manager', () => { }) it('should build the transaction with the optional props', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress: await safe.getAddress(), contractNetworks }) @@ -419,22 +398,17 @@ describe('Safe owners manager', () => { }) it('should remove the first owner of a Safe and decrease the threshold', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3] = accounts - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress: await safe.getAddress(), contractNetworks }) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) - const provider3 = getEip1193Provider() const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) const initialThreshold = await safeSdk1.getThreshold() @@ -457,22 +431,17 @@ describe('Safe owners manager', () => { }) it('should remove any owner of a Safe and decrease the threshold', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3] = accounts - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress: await safe.getAddress(), contractNetworks }) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) - const provider3 = getEip1193Provider() const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address, contractNetworks }) @@ -496,22 +465,17 @@ describe('Safe owners manager', () => { }) it('should remove an owner and update the threshold', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3] = accounts - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress: await safe.getAddress(), contractNetworks }) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) - const provider3 = getEip1193Provider() const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) const newThreshold = 1 @@ -538,9 +502,8 @@ describe('Safe owners manager', () => { describe('createSwapOwnerTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, accounts, contractNetworks } = await setupTests() + const { predictedSafe, accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -554,10 +517,9 @@ describe('Safe owners manager', () => { }) it('should fail if old address is invalid', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -571,10 +533,9 @@ describe('Safe owners manager', () => { }) it('should fail if new address is invalid', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -588,10 +549,9 @@ describe('Safe owners manager', () => { }) it('should fail if old address is equal to sentinel', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -605,10 +565,9 @@ describe('Safe owners manager', () => { }) it('should fail if new address is equal to sentinel', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -622,10 +581,9 @@ describe('Safe owners manager', () => { }) it('should fail if old address is equal to 0x address', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -639,10 +597,9 @@ describe('Safe owners manager', () => { }) it('should fail if new address is equal to 0x address', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -656,10 +613,9 @@ describe('Safe owners manager', () => { }) it('should fail if old address is not an owner', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2, , account4] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -673,10 +629,9 @@ describe('Safe owners manager', () => { }) it('should fail if new address is already an owner', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -690,10 +645,9 @@ describe('Safe owners manager', () => { }) it('should build the transaction with the optional props', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -720,10 +674,9 @@ describe('Safe owners manager', () => { }) it('should replace the first owner of a Safe', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -744,22 +697,17 @@ describe('Safe owners manager', () => { }) it('should replace any owner of a Safe', async () => { - const { safe, accounts, contractNetworks } = await setupTests() + const { safe, accounts, contractNetworks, provider } = await setupTests() const [account1, account2, account3, account4] = accounts - const provider1 = getEip1193Provider() const safeSdk1 = await Safe.create({ - provider: provider1, + provider, safeAddress: await safe.getAddress(), contractNetworks }) - const provider2 = getEip1193Provider() const safeSdk2 = await safeSdk1.connect({ - provider: provider2, signer: account2.address }) - const provider3 = getEip1193Provider() const safeSdk3 = await safeSdk1.connect({ - provider: provider3, signer: account3.address }) const initialOwners = await safeSdk1.getOwners() diff --git a/packages/protocol-kit/tests/e2e/safeFactory.test.ts b/packages/protocol-kit/tests/e2e/safeFactory.test.ts index 372c3f7eb..9d476f8e2 100644 --- a/packages/protocol-kit/tests/e2e/safeFactory.test.ts +++ b/packages/protocol-kit/tests/e2e/safeFactory.test.ts @@ -35,25 +35,27 @@ describe('SafeProxyFactory', () => { const accounts = await getAccounts() const chainId = BigInt(await getChainId()) const contractNetworks = await getContractNetworks(chainId) + const provider = getEip1193Provider() + return { defaultCallbackHandler: await getDefaultCallbackHandler(), chainId, accounts, - contractNetworks + contractNetworks, + provider } }) describe('create', async () => { it('should fail if the current network is not a default network and no contractNetworks is provided', async () => { - const provider = getEip1193Provider() + const { provider } = await setupTests() chai .expect(SafeFactory.create({ provider })) .rejectedWith('Invalid SafeProxyFactory contract') }) it('should fail if the contractNetworks provided are not deployed', async () => { - const { chainId } = await setupTests() - const provider = getEip1193Provider() + const { chainId, provider } = await setupTests() const contractNetworks: ContractNetworksConfig = { [chainId.toString()]: { safeSingletonAddress: ZERO_ADDRESS, @@ -80,8 +82,7 @@ describe('SafeProxyFactory', () => { }) it('should instantiate the SafeProxyFactory', async () => { - const { contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, provider } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeFactory = await SafeFactory.create({ provider, contractNetworks }) const networkId = await safeProvider.getChainId() @@ -93,9 +94,8 @@ describe('SafeProxyFactory', () => { describe('getEip1193Provider', async () => { it('should return the connected SafeProvider', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) chai .expect(await safeFactory.getSafeProvider().getSignerAddress()) @@ -105,8 +105,7 @@ describe('SafeProxyFactory', () => { describe('getChainId', async () => { it('should return the chainId of the current network', async () => { - const { chainId, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { chainId, contractNetworks, provider } = await setupTests() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) chai.expect(await safeFactory.getChainId()).to.be.eq(chainId) }) @@ -114,8 +113,7 @@ describe('SafeProxyFactory', () => { describe('predictSafeAddress', async () => { it('should fail if there are no owners', async () => { - const { contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, provider } = await setupTests() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) const owners: string[] = [] const threshold = 2 @@ -128,9 +126,8 @@ describe('SafeProxyFactory', () => { }) it('should fail if the threshold is lower than 0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) const owners = [account1.address, account2.address] const invalidThreshold = 0 @@ -143,9 +140,8 @@ describe('SafeProxyFactory', () => { }) it('should fail if the threshold is higher than the threshold', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) const owners = [account1.address, account2.address] const invalidThreshold = 3 @@ -158,9 +154,8 @@ describe('SafeProxyFactory', () => { }) it('should fail if the saltNonce is lower than 0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -177,9 +172,8 @@ describe('SafeProxyFactory', () => { }) it('should predict a new Safe with saltNonce', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -204,9 +198,8 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed > '1.0.0')( 'should predict a new Safe with the default CompatibilityFallbackHandler', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -233,9 +226,8 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed > '1.0.0')( 'should predict a new Safe with a custom fallback handler', async () => { - const { accounts, contractNetworks, defaultCallbackHandler } = await setupTests() + const { accounts, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -265,8 +257,7 @@ describe('SafeProxyFactory', () => { describe('deploySafe', async () => { it('should fail if there are no owners', async () => { - const { contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, provider } = await setupTests() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) const owners: string[] = [] const threshold = 2 @@ -278,9 +269,8 @@ describe('SafeProxyFactory', () => { }) it('should fail if the threshold is lower than 0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) const owners = [account1.address, account2.address] const threshold = 0 @@ -292,9 +282,8 @@ describe('SafeProxyFactory', () => { }) it('should fail if the threshold is higher than the threshold', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) const owners = [account1.address, account2.address] const threshold = 3 @@ -306,9 +295,8 @@ describe('SafeProxyFactory', () => { }) it('should fail if the saltNonce is lower than 0', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -327,9 +315,8 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed > '1.0.0')( 'should deploy a new Safe with custom fallback handler', async () => { - const { accounts, contractNetworks, defaultCallbackHandler } = await setupTests() + const { accounts, contractNetworks, defaultCallbackHandler, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -356,9 +343,8 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed > '1.0.0')( 'should deploy a new Safe with the default CompatibilityFallbackHandler', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -378,9 +364,8 @@ describe('SafeProxyFactory', () => { ) it('should deploy a new Safe without saltNonce', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -398,9 +383,8 @@ describe('SafeProxyFactory', () => { }) it('should deploy a new Safe with saltNonce', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -419,13 +403,12 @@ describe('SafeProxyFactory', () => { }) it('should deploy a new Safe with callback', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts let callbackResult = '' const callback = (txHash: string) => { callbackResult = txHash } - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, @@ -445,9 +428,8 @@ describe('SafeProxyFactory', () => { itif(safeVersionDeployed === DEFAULT_SAFE_VERSION)( 'should deploy last Safe version by default', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, contractNetworks }) const owners = [account1.address, account2.address] const threshold = 2 @@ -460,9 +442,8 @@ describe('SafeProxyFactory', () => { ) it('should deploy a specific Safe version', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts - const provider = getEip1193Provider() const safeFactory = await SafeFactory.create({ provider, safeVersion: safeVersionDeployed, diff --git a/packages/protocol-kit/tests/e2e/safeProvider.test.ts b/packages/protocol-kit/tests/e2e/safeProvider.test.ts index d8bc6e50b..f63532f67 100644 --- a/packages/protocol-kit/tests/e2e/safeProvider.test.ts +++ b/packages/protocol-kit/tests/e2e/safeProvider.test.ts @@ -24,10 +24,13 @@ describe('Safe contracts', () => { const accounts = await getAccounts() const chainId = BigInt(await getChainId()) const contractNetworks = await getContractNetworks(chainId) + const provider = getEip1193Provider() + return { accounts, contractNetworks, - chainId + chainId, + provider } }) @@ -68,8 +71,7 @@ describe('Safe contracts', () => { }) it('should return a Safe contract from the custom addresses', async () => { - const { contractNetworks, chainId } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, chainId, provider } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -97,8 +99,7 @@ describe('Safe contracts', () => { }) it('should return a MultiSend contract from the custom addresses', async () => { - const { contractNetworks, chainId } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, chainId, provider } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -126,8 +127,7 @@ describe('Safe contracts', () => { }) it('should return a MultiSendCallOnly contract from the custom addresses', async () => { - const { contractNetworks, chainId } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, chainId, provider } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -156,8 +156,7 @@ describe('Safe contracts', () => { }) it('should return a CompatibilityFallbackHandler contract from the custom addresses', async () => { - const { contractNetworks, chainId } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, chainId, provider } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -186,8 +185,7 @@ describe('Safe contracts', () => { }) it('should return a SafeProxyFactory contract from the custom addresses', async () => { - const { contractNetworks, chainId } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, chainId, provider } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -215,8 +213,7 @@ describe('Safe contracts', () => { }) it('should return a SignMessageLib contract from the custom addresses', async () => { - const { contractNetworks, chainId } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, chainId, provider } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] @@ -244,8 +241,7 @@ describe('Safe contracts', () => { }) it('should return a SafeProxyFactory contract from the custom addresses', async () => { - const { contractNetworks, chainId } = await setupTests() - const provider = getEip1193Provider() + const { contractNetworks, chainId, provider } = await setupTests() const safeProvider = new SafeProvider({ provider }) const safeVersion: SafeVersion = '1.3.0' const customContract = contractNetworks[chainId.toString()] diff --git a/packages/protocol-kit/tests/e2e/threshold.test.ts b/packages/protocol-kit/tests/e2e/threshold.test.ts index fb5148798..254f2ad0d 100644 --- a/packages/protocol-kit/tests/e2e/threshold.test.ts +++ b/packages/protocol-kit/tests/e2e/threshold.test.ts @@ -29,18 +29,20 @@ describe('Safe Threshold', () => { safeVersion: safeVersionDeployed } } + const provider = getEip1193Provider() + return { safe: await getSafeWithOwners([accounts[0].address]), accounts, contractNetworks, - predictedSafe + predictedSafe, + provider } }) describe('getThreshold', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -50,8 +52,7 @@ describe('Safe Threshold', () => { }) it('should return the Safe threshold', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -63,8 +64,7 @@ describe('Safe Threshold', () => { describe('createChangeThresholdTx', async () => { it('should fail if the Safe is not deployed', async () => { - const { predictedSafe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { predictedSafe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, predictedSafe, @@ -77,8 +77,7 @@ describe('Safe Threshold', () => { }) it('should fail if the threshold is bigger than the number of owners', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -93,8 +92,7 @@ describe('Safe Threshold', () => { }) it('should fail if the threshold is not bigger than 0', async () => { - const { safe, contractNetworks } = await setupTests() - const provider = getEip1193Provider() + const { safe, contractNetworks, provider } = await setupTests() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -107,10 +105,9 @@ describe('Safe Threshold', () => { }) it('should build the transaction with the optional props', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address, account2.address], 1) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), @@ -136,10 +133,9 @@ describe('Safe Threshold', () => { }) it('should change the threshold', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address, account2.address], 1) - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, safeAddress: await safe.getAddress(), diff --git a/packages/protocol-kit/tests/e2e/utilsContracts.test.ts b/packages/protocol-kit/tests/e2e/utilsContracts.test.ts index 330f95f67..cdd2d9bf3 100644 --- a/packages/protocol-kit/tests/e2e/utilsContracts.test.ts +++ b/packages/protocol-kit/tests/e2e/utilsContracts.test.ts @@ -42,24 +42,26 @@ describe('Contract utils', () => { const accounts = await getAccounts() const chainId = BigInt(await getChainId()) const contractNetworks = await getContractNetworks(chainId) + const provider = getEip1193Provider() + return { defaultCallbackHandler: await getDefaultCallbackHandler(), chainId, accounts, - contractNetworks + contractNetworks, + provider } }) describe('predictSafeAddress', () => { it('returns the predicted address of a 1/1 Safe', async () => { - const { accounts, contractNetworks, chainId } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // 1/1 Safe const [owner1] = accounts const owners = [owner1.address] const threshold = 1 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -98,14 +100,13 @@ describe('Contract utils', () => { }) it('returns the predicted address of a 1/2 Safe', async () => { - const { accounts, contractNetworks, chainId } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // 1/2 Safe const [owner1, owner2] = accounts const owners = [owner1.address, owner2.address] const threshold = 1 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -144,14 +145,13 @@ describe('Contract utils', () => { }) it('returns the predicted address of a 2/2 Safe', async () => { - const { accounts, contractNetworks, chainId } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // 2/2 Safe const [owner1, owner2] = accounts const owners = [owner1.address, owner2.address] const threshold = 2 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -190,14 +190,13 @@ describe('Contract utils', () => { }) it('should fail if the provided threshold is invalid (greater than owners length)', async () => { - const { accounts, contractNetworks, chainId } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // invalid threshold 3/2 Safe const [owner1, owner2] = accounts const owners = [owner1.address, owner2.address] const invalidThreshold = 3 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -225,14 +224,13 @@ describe('Contract utils', () => { }) it('should fail if the provided threshold is invalid (zero value)', async () => { - const { accounts, contractNetworks, chainId } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // invalid threshold 0/2 Safe const [owner1, owner2] = accounts const owners = [owner1.address, owner2.address] const invalidThreshold = 0 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -260,14 +258,13 @@ describe('Contract utils', () => { }) it('should fail if the provided threshold is invalid (negative value)', async () => { - const { accounts, contractNetworks, chainId } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // invalid threshold -2/2 Safe const [owner1, owner2] = accounts const owners = [owner1.address, owner2.address] const invalidThreshold = -2 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -295,13 +292,12 @@ describe('Contract utils', () => { }) it('should fail if no owners are present (empty array)', async () => { - const { contractNetworks, chainId } = await setupTests() + const { contractNetworks, chainId, provider } = await setupTests() // invalid owners 1/0 Safe const invalidOwners: string[] = [] const threshold = 1 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -329,14 +325,13 @@ describe('Contract utils', () => { }) it('returns different addresses with different saltNonce value but same Safe config (threshold & owners)', async () => { - const { accounts, contractNetworks, chainId } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // 1/2 Safe const [owner1, owner2] = accounts const owners = [owner1.address, owner2.address] const threshold = 1 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -423,14 +418,13 @@ 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 } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // 2/2 Safe const [owner1, owner2] = accounts const owners = [owner1.address, owner2.address] const threshold = 2 const safeVersion = safeVersionDeployed - const provider = getEip1193Provider() const safeProvider = new SafeProvider({ provider }) const customContracts = contractNetworks[chainId.toString()] @@ -489,13 +483,12 @@ describe('Contract utils', () => { itif(safeVersionDeployed > '1.0.0')( 'safeDeploymentConfig is an optional parameter', async () => { - const { accounts, contractNetworks, chainId } = await setupTests() + const { accounts, contractNetworks, chainId, provider } = await setupTests() // 1/1 Safe const [owner1] = accounts const owners = [owner1.address] const threshold = 1 - const provider = getEip1193Provider() const customContracts = contractNetworks[chainId.toString()] const safeAccountConfig: SafeAccountConfig = { diff --git a/packages/protocol-kit/tests/e2e/wrapSafeTransactionIntoDeploymentBatch.test.ts b/packages/protocol-kit/tests/e2e/wrapSafeTransactionIntoDeploymentBatch.test.ts index d37acb91b..d1cb7081d 100644 --- a/packages/protocol-kit/tests/e2e/wrapSafeTransactionIntoDeploymentBatch.test.ts +++ b/packages/protocol-kit/tests/e2e/wrapSafeTransactionIntoDeploymentBatch.test.ts @@ -29,22 +29,23 @@ describe('wrapSafeTransactionIntoDeploymentBatch', () => { safeVersion: safeVersionDeployed } } + const provider = getEip1193Provider() return { accounts, contractNetworks, predictedSafe, - chainId + chainId, + provider } }) it('should throw an error if the Safe is already deployed', async () => { - const { accounts, contractNetworks } = await setupTests() + const { accounts, contractNetworks, provider } = await setupTests() const [account1, account2] = accounts const safe = await getSafeWithOwners([account1.address]) const safeAddress = await safe.getAddress() - const provider = getEip1193Provider() const safeSdk = await Safe.create({ provider, @@ -70,11 +71,9 @@ 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 } = await setupTests() + const { accounts, contractNetworks, predictedSafe, provider } = await setupTests() const [, account2] = accounts - const provider = getEip1193Provider() - const safeSdk = await Safe.create({ provider, predictedSafe, @@ -106,11 +105,9 @@ 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 } = await setupTests() + const { accounts, contractNetworks, predictedSafe, provider } = await setupTests() const [, account2] = accounts - const provider = getEip1193Provider() - const safeSdk = await Safe.create({ provider, predictedSafe, @@ -142,11 +139,9 @@ describe('wrapSafeTransactionIntoDeploymentBatch', () => { itif(safeVersionDeployed >= '1.3.0')( 'should include the custom salt nonce in the Safe deployment data', async () => { - const { accounts, contractNetworks, predictedSafe } = await setupTests() + const { accounts, contractNetworks, predictedSafe, provider } = await setupTests() const [, account2] = accounts - const provider = getEip1193Provider() - const safeSdk = await Safe.create({ provider, predictedSafe,