Skip to content

Commit

Permalink
Setup contracts deployment in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
germartinez committed Nov 4, 2021
1 parent 8cdde74 commit 60ed6a1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 30 deletions.
8 changes: 0 additions & 8 deletions packages/safe-core-sdk/contracts/Deps.sol

This file was deleted.

13 changes: 13 additions & 0 deletions packages/safe-core-sdk/contracts/Deps_V1_2_0.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0 <0.9.0;

import { GnosisSafeProxyFactory } from "@gnosis.pm/safe-contracts-v1.2.0/contracts/proxies/GnosisSafeProxyFactory.sol";
import { GnosisSafe } from "@gnosis.pm/safe-contracts-v1.2.0/contracts/GnosisSafe.sol";
import { MultiSend } from "@gnosis.pm/safe-contracts-v1.2.0/contracts/libraries/MultiSend.sol";
import { DailyLimitModule } from "@gnosis.pm/safe-contracts-v1.2.0/contracts/modules/DailyLimitModule.sol";
import { SocialRecoveryModule } from "@gnosis.pm/safe-contracts-v1.2.0/contracts/modules/SocialRecoveryModule.sol";
import { ERC20Mintable } from "openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol";

contract ProxyFactory_SV1_2_0 is GnosisSafeProxyFactory {}
contract GnosisSafe_SV1_2_0 is GnosisSafe {}
contract MultiSend_SV1_2_0 is MultiSend {}
10 changes: 10 additions & 0 deletions packages/safe-core-sdk/contracts/Deps_V1_3_0.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.7.0 <0.9.0;

import { GnosisSafeProxyFactory } from "@gnosis.pm/safe-contracts-v1.3.0/contracts/proxies/GnosisSafeProxyFactory.sol";
import { GnosisSafe } from "@gnosis.pm/safe-contracts-v1.3.0/contracts/GnosisSafe.sol";
import { MultiSend } from "@gnosis.pm/safe-contracts-v1.3.0/contracts/libraries/MultiSend.sol";

contract ProxyFactory_SV1_3_0 is GnosisSafeProxyFactory {}
contract GnosisSafe_SV1_3_0 is GnosisSafe {}
contract MultiSend_SV1_3_0 is MultiSend {}
34 changes: 31 additions & 3 deletions packages/safe-core-sdk/hardhat/deploy/deploy-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

type SafeVersion = 'v1.3.0' | 'v1.2.0' | 'v1.1.1'

export const safeVersion = process.env.SAFE_VERSION as SafeVersion

const gnosisSafeContracts = {
'v1.3.0': { name: 'GnosisSafe_SV1_3_0' },
'v1.2.0': { name: 'GnosisSafe_SV1_2_0' },
'v1.1.1': { name: 'GnosisSafe_SV1_1_1' }
}

const proxyFactoryContracts = {
'v1.3.0': { name: 'ProxyFactory_SV1_3_0' },
'v1.2.0': { name: 'ProxyFactory_SV1_2_0' },
'v1.1.1': { name: 'ProxyFactory_SV1_1_1' }
}

const multiSendContracts = {
'v1.3.0': { name: 'MultiSend_SV1_3_0' },
'v1.2.0': { name: 'MultiSend_SV1_2_0' },
'v1.1.1': { name: 'MultiSend_SV1_1_1' }
}

export const gnosisSafeDeployed = gnosisSafeContracts[safeVersion]
export const proxyFactoryDeployed = proxyFactoryContracts[safeVersion]
export const multiSendDeployed = multiSendContracts[safeVersion]

const deploy: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts } = hre
const { deployer } = await getNamedAccounts()
const { deploy } = deployments

await deploy('GnosisSafe', {
console.log(`Deploying Safe contracts ${safeVersion}`)

await deploy(gnosisSafeDeployed.name, {
from: deployer,
args: [],
log: true,
deterministicDeployment: true
})

await deploy('GnosisSafeProxyFactory', {
await deploy(proxyFactoryDeployed.name, {
from: deployer,
args: [],
log: true,
deterministicDeployment: true
})

await deploy('MultiSend', {
await deploy(multiSendDeployed.name, {
from: deployer,
args: [],
log: true,

This comment has been minimized.

Copy link
@Lipstick93Chels

Lipstick93Chels Nov 2, 2022

True

Expand Down
38 changes: 19 additions & 19 deletions packages/safe-core-sdk/tests/utils/setupContracts.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { AddressZero } from '@ethersproject/constants'
import { deployments, ethers } from 'hardhat'
import { GnosisSafe } from '../../typechain/src/ethers-v5/v1.3.0/GnosisSafe'
import { MultiSend } from '../../typechain/src/ethers-v5/v1.3.0/MultiSend'
import {
gnosisSafeDeployed,
multiSendDeployed,
proxyFactoryDeployed
} from '../../hardhat/deploy/deploy-contracts'
import {
DailyLimitModule,
ERC20Mintable,
SocialRecoveryModule
} from '../../typechain/tests/ethers-v5'

export const getSafeSingleton = async () => {
const SafeDeployment = await deployments.get('GnosisSafe')
const Safe = await ethers.getContractFactory('GnosisSafe')
export const getSafeSingleton = async (): Promise<any> => {
const SafeDeployment = await deployments.get(gnosisSafeDeployed.name)
const Safe = await ethers.getContractFactory(gnosisSafeDeployed.name)
return Safe.attach(SafeDeployment.address)
}

export const getFactory = async () => {
const FactoryDeployment = await deployments.get('GnosisSafeProxyFactory')
const Factory = await ethers.getContractFactory('GnosisSafeProxyFactory')
export const getFactory = async (): Promise<any> => {
const FactoryDeployment = await deployments.get(proxyFactoryDeployed.name)
const Factory = await ethers.getContractFactory(proxyFactoryDeployed.name)
return Factory.attach(FactoryDeployment.address)
}

export const getSafeTemplate = async (): Promise<GnosisSafe> => {
export const getSafeTemplate = async (): Promise<any> => {
const singleton = await getSafeSingleton()
const factory = await getFactory()
const template = await factory.callStatic.createProxy(singleton.address, '0x')
await factory.createProxy(singleton.address, '0x').then((tx: any) => tx.wait())
const Safe = await ethers.getContractFactory('GnosisSafe')
return Safe.attach(template) as GnosisSafe
const Safe = await ethers.getContractFactory(gnosisSafeDeployed.name)
return Safe.attach(template)
}

export const getSafeWithOwners = async (
owners: string[],
threshold?: number
): Promise<GnosisSafe> => {
export const getSafeWithOwners = async (owners: string[], threshold?: number): Promise<any> => {
const template = await getSafeTemplate()
await template.setup(
owners,
Expand All @@ -47,10 +47,10 @@ export const getSafeWithOwners = async (
return template
}

export const getMultiSend = async (): Promise<MultiSend> => {
const MultiSendDeployment = await deployments.get('MultiSend')
const MultiSend = await ethers.getContractFactory('MultiSend')
return MultiSend.attach(MultiSendDeployment.address) as MultiSend
export const getMultiSend = async (): Promise<any> => {
const MultiSendDeployment = await deployments.get(multiSendDeployed.name)
const MultiSend = await ethers.getContractFactory(multiSendDeployed.name)
return MultiSend.attach(MultiSendDeployment.address)
}

export const getDailyLimitModule = async (): Promise<DailyLimitModule> => {
Expand Down

0 comments on commit 60ed6a1

Please sign in to comment.