Skip to content

Commit

Permalink
Update tests in protocol-kit and remove duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Aug 29, 2024
1 parent e8a2d7f commit af4fa99
Show file tree
Hide file tree
Showing 36 changed files with 747 additions and 1,084 deletions.
2 changes: 1 addition & 1 deletion packages/protocol-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"test:hardhat:viem:v1.1.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.1.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.2.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.2.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.3.0": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.3.0 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.4.1 && testing-kit.js deploy && nyc testing-kit.js test 'tests/e2e/*.test.*'",
"test:hardhat:viem:v1.4.1": "export TEST_NETWORK=hardhat && export ETH_LIB=viem && export SAFE_VERSION=1.4.1 && testing-kit deploy && nyc testing-kit test 'tests/e2e/*.test.*'",
"coverage": "nyc report --reporter=lcov",
"format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"",
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
Expand Down
46 changes: 15 additions & 31 deletions packages/protocol-kit/tests/e2e/contractManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
import { safeVersionDeployed } from '@safe-global/testing-kit'
import Safe, { ContractNetworksConfig, PredictedSafeProps } from '@safe-global/protocol-kit/index'
import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { deployments } from 'hardhat'
import { getContractNetworks } from './utils/setupContractNetworks'
import {
safeVersionDeployed,
setupTests,
getCompatibilityFallbackHandler,
getCreateCall,
getFactory,
getMultiSend,
getMultiSendCallOnly,
getSafeSingleton,
getSafeWithOwners,
getSignMessageLib,
getSimulateTxAccessor
} from './utils/setupContracts'
} from '@safe-global/testing-kit'
import Safe, { ContractNetworksConfig, PredictedSafeProps } from '@safe-global/protocol-kit/index'
import { ZERO_ADDRESS } from '@safe-global/protocol-kit/utils/constants'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { getEip1193Provider } from './utils/setupProvider'
import { getAccounts } from './utils/setupTestNetwork'

chai.use(chaiAsPromised)

describe('Safe contracts manager', () => {
const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => {
await deployments.fixture()
const accounts = await getAccounts()
const chainId = BigInt(await getChainId())
const contractNetworks = await getContractNetworks(chainId)
const provider = getEip1193Provider()
return {
safe: await getSafeWithOwners([accounts[0].address]),
accounts,
contractNetworks,
chainId,
provider
}
})
const provider = getEip1193Provider()

describe('create', async () => {
it('should initialize the SDK with a Safe that is not deployed', async () => {
const { accounts, contractNetworks, provider } = await setupTests()
const { accounts, contractNetworks } = await setupTests()
const predictedSafe: PredictedSafeProps = {
safeAccountConfig: {
owners: [accounts[0].address],
Expand All @@ -59,7 +43,7 @@ describe('Safe contracts manager', () => {
})

it('should fail if the current network is not a default network and no contractNetworks is provided', async () => {
const { safe, provider } = await setupTests()
const { safe } = await setupTests()
const safeAddress = safe.address
await chai
.expect(
Expand All @@ -72,7 +56,7 @@ describe('Safe contracts manager', () => {
})

it('should fail if SafeProxy contract is not deployed on the current network', async () => {
const { contractNetworks, provider } = await setupTests()
const { contractNetworks } = await setupTests()
await chai
.expect(
Safe.init({
Expand All @@ -85,8 +69,8 @@ describe('Safe contracts manager', () => {
})

it('should fail if MultiSend contract is specified in contractNetworks but not deployed', async () => {
const { safe, chainId, provider } = await setupTests()
const customContractNetworks: ContractNetworksConfig = {
const { safe, chainId } = await setupTests()
const customContractNetworks = {
[chainId.toString()]: {
safeSingletonAddress: ZERO_ADDRESS,
safeSingletonAbi: (await getSafeSingleton()).abi,
Expand All @@ -113,14 +97,14 @@ describe('Safe contracts manager', () => {
Safe.init({
provider,
safeAddress,
contractNetworks: customContractNetworks
contractNetworks: customContractNetworks as ContractNetworksConfig
})
)
.to.be.rejectedWith('MultiSend contract is not deployed on the current network')
})

it('should set the MultiSend contract available on the current network', async () => {
const { safe, chainId, contractNetworks, provider } = await setupTests()
const { safe, chainId, contractNetworks } = await setupTests()
const safeAddress = safe.address
const safeSdk = await Safe.init({
provider,
Expand Down
74 changes: 26 additions & 48 deletions packages/protocol-kit/tests/e2e/core.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,29 @@
import { DEFAULT_SAFE_VERSION } from '@safe-global/protocol-kit/contracts/config'
import { safeVersionDeployed } from '@safe-global/testing-kit'
import {
safeVersionDeployed,
setupTests,
itif,
getSafeWithOwners,
waitTransactionReceipt
} from '@safe-global/testing-kit'
import Safe, { PredictedSafeProps, SafeFactory } from '@safe-global/protocol-kit/index'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { deployments } from 'hardhat'
import { itif } from './utils/helpers'
import { getContractNetworks } from './utils/setupContractNetworks'
import { getSafeWithOwners } from './utils/setupContracts'
import { getEip1193Provider } from './utils/setupProvider'
import { getAccounts } from './utils/setupTestNetwork'

import { waitSafeTxReceipt } from './utils/transactions'
import { waitTransactionReceipt } from './utils/transactions'
import { sameString } from '@safe-global/protocol-kit/utils'

chai.use(chaiAsPromised)

describe('Safe Info', () => {
const setupTests = deployments.createFixture(async ({ deployments, getChainId }) => {
await deployments.fixture()
const accounts = await getAccounts()
const chainId = BigInt(await getChainId())
const contractNetworks = await getContractNetworks(chainId)
const predictedSafe: PredictedSafeProps = {
safeAccountConfig: {
owners: [accounts[0].address],
threshold: 1
},
safeDeploymentConfig: {
safeVersion: safeVersionDeployed
}
}
const provider = getEip1193Provider()
return {
chainId,
safe: await getSafeWithOwners([accounts[0].address, accounts[1].address]),
provider,
predictedSafe,
accounts,
contractNetworks
}
})
const provider = getEip1193Provider()

describe('connect', async () => {
itif(safeVersionDeployed < '1.3.0')(
'should fail to connect a Safe <v1.3.0 that is not deployed',
async () => {
const { predictedSafe, safe, contractNetworks, provider } = await setupTests()
const { predictedSafe, safe, contractNetworks } = await setupTests()
const safeAddress = safe.address
const safeSdk = await Safe.init({
provider,
Expand All @@ -62,7 +40,7 @@ describe('Safe Info', () => {
)

it('should connect a Safe >=v1.3.0 that is not deployed', async () => {
const { predictedSafe, safe, accounts, contractNetworks, provider } = await setupTests()
const { predictedSafe, safe, accounts, contractNetworks } = await setupTests()
const [account1] = accounts
const safeAddress = safe.address
const safeSdk = await Safe.init({
Expand All @@ -80,7 +58,7 @@ describe('Safe Info', () => {
})

it('should connect a deployed Safe', async () => {
const { safe, accounts, contractNetworks, provider } = await setupTests()
const { safe, accounts, contractNetworks } = await setupTests()
const [account1, account2, account3] = accounts
const safeAddress = safe.address
const safeSdk = await Safe.init({
Expand Down Expand Up @@ -129,7 +107,7 @@ describe('Safe Info', () => {

describe('getContractVersion', async () => {
it('should return the contract version of a Safe that is not deployed with a custom version configuration', async () => {
const { predictedSafe, contractNetworks, provider } = await setupTests()
const { predictedSafe, contractNetworks } = await setupTests()
const safeSdk = await Safe.init({
provider,
predictedSafe,
Expand All @@ -140,7 +118,7 @@ describe('Safe Info', () => {
})

it('should return the contract version of a Safe that is not deployed with a default version configuration', async () => {
const { predictedSafe, contractNetworks, provider } = await setupTests()
const { predictedSafe, contractNetworks } = await setupTests()
const safeConfig: PredictedSafeProps = {
...predictedSafe,
safeDeploymentConfig: {}
Expand All @@ -155,7 +133,7 @@ describe('Safe Info', () => {
})

it('should return the Safe contract version', async () => {
const { safe, contractNetworks, provider } = await setupTests()
const { safe, contractNetworks } = await setupTests()
const safeAddress = safe.address
const safeSdk = await Safe.init({
provider,
Expand All @@ -171,7 +149,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, provider } = await setupTests()
const { predictedSafe, contractNetworks } = await setupTests()
const safeSdk = await Safe.init({
provider,
predictedSafe,
Expand All @@ -189,7 +167,7 @@ describe('Safe Info', () => {
itif(safeVersionDeployed >= '1.3.0')(
'should return the address of a Safe >=v1.3.0 that is not deployed',
async () => {
const { predictedSafe, contractNetworks, provider } = await setupTests()
const { predictedSafe, contractNetworks } = await setupTests()
const safeSdk = await Safe.init({
provider,
predictedSafe,
Expand All @@ -210,7 +188,7 @@ describe('Safe Info', () => {
)

it('should return the address of a deployed Safe', async () => {
const { safe, contractNetworks, provider } = await setupTests()
const { safe, contractNetworks } = await setupTests()
const safeAddress = safe.address
const safeSdk = await Safe.init({
provider,
Expand All @@ -223,7 +201,7 @@ describe('Safe Info', () => {

describe('getEip1193Provider', async () => {
it('should return the connected SafeProvider', async () => {
const { safe, accounts, contractNetworks, provider } = await setupTests()
const { safe, accounts, contractNetworks } = await setupTests()
const [account1] = accounts
const safeAddress = safe.address
const safeSdk = await Safe.init({
Expand All @@ -243,7 +221,7 @@ describe('Safe Info', () => {

describe('getNonce', async () => {
it('should return the nonce of a Safe that is not deployed', async () => {
const { predictedSafe, contractNetworks, provider } = await setupTests()
const { predictedSafe, contractNetworks } = await setupTests()
const safeSdk = await Safe.init({
provider,
predictedSafe,
Expand All @@ -253,7 +231,7 @@ describe('Safe Info', () => {
})

it('should return the Safe nonce', async () => {
const { accounts, contractNetworks, provider } = await setupTests()
const { accounts, contractNetworks } = await setupTests()
const [account1, account2] = accounts
const safe = await getSafeWithOwners([account1.address])
const safeAddress = safe.address
Expand All @@ -278,7 +256,7 @@ describe('Safe Info', () => {

describe('getChainId', async () => {
it('should return the chainId of a Safe that is not deployed', async () => {
const { predictedSafe, chainId, contractNetworks, provider } = await setupTests()
const { predictedSafe, chainId, contractNetworks } = await setupTests()
const safeSdk = await Safe.init({
provider,
predictedSafe,
Expand All @@ -288,7 +266,7 @@ describe('Safe Info', () => {
})

it('should return the chainId of the current network', async () => {
const { safe, chainId, contractNetworks, provider } = await setupTests()
const { safe, chainId, contractNetworks } = await setupTests()
const safeAddress = safe.address
const safeSdk = await Safe.init({
provider,
Expand All @@ -303,7 +281,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, provider } = await setupTests()
const { predictedSafe, contractNetworks } = await setupTests()
const safeSdk = await Safe.init({
provider,
predictedSafe,
Expand All @@ -320,7 +298,7 @@ describe('Safe Info', () => {
itif(safeVersionDeployed >= '1.3.0')(
'should return the balance of a Safe >=v1.3.0 that is not deployed',
async () => {
const { predictedSafe, accounts, contractNetworks, provider } = await setupTests()
const { predictedSafe, accounts, contractNetworks } = await setupTests()
const [account1] = accounts
const safeSdk = await Safe.init({
provider,
Expand All @@ -343,7 +321,7 @@ describe('Safe Info', () => {
)

it('should return the balance of a deployed Safe', async () => {
const { safe, accounts, contractNetworks, provider } = await setupTests()
const { safe, accounts, contractNetworks } = await setupTests()
const [account1] = accounts
const safeAddress = safe.address
const safeSdk = await Safe.init({
Expand Down
Loading

0 comments on commit af4fa99

Please sign in to comment.