Skip to content

Commit

Permalink
Simplify provider retrieval in test
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Apr 22, 2024
1 parent 753ce90 commit c0e8a72
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 657 deletions.
19 changes: 8 additions & 11 deletions packages/protocol-kit/tests/e2e/contractManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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(
Expand All @@ -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({
Expand All @@ -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,
Expand All @@ -108,7 +107,6 @@ describe('Safe contracts manager', () => {
}
}

const provider = getEip1193Provider()
const safeAddress = await safe.getAddress()
await chai
.expect(
Expand All @@ -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,
Expand Down
57 changes: 19 additions & 38 deletions packages/protocol-kit/tests/e2e/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,8 +43,7 @@ describe('Safe Info', () => {
itif(safeVersionDeployed < '1.3.0')(
'should fail to connect a Safe <v1.3.0 that is not deployed',
async () => {
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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
})
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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: {}
Expand All @@ -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,
Expand All @@ -165,8 +157,7 @@ describe('Safe Info', () => {
itif(safeVersionDeployed < '1.3.0')(
'should fail to 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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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({
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -301,8 +285,7 @@ describe('Safe Info', () => {
itif(safeVersionDeployed < '1.3.0')(
'should fail to return the balance 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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Loading

0 comments on commit c0e8a72

Please sign in to comment.