Skip to content

Commit

Permalink
Fix tests to reflect potential real config with V1 factory as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cag committed Jan 6, 2021
1 parent 4f849c1 commit d92fc7f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
54 changes: 54 additions & 0 deletions contracts/solc-0.5/CPKFactoryV1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
pragma solidity >=0.5.0 <0.7.0;

import { Enum } from "@gnosis.pm/safe-contracts/contracts/common/Enum.sol";
import { GnosisSafeProxy } from "@gnosis.pm/safe-contracts/contracts/proxies/GnosisSafeProxy.sol";
import { GnosisSafe } from "@gnosis.pm/safe-contracts/contracts/GnosisSafe.sol";

contract CPKFactoryV1 {
event ProxyCreation(GnosisSafeProxy proxy);

function proxyCreationCode() external pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
}

function createProxyAndExecTransaction(
address masterCopy,
uint256 saltNonce,
address fallbackHandler,
address to,
uint256 value,
bytes calldata data,
Enum.Operation operation
)
external
returns (bool execTransactionSuccess)
{
GnosisSafe proxy;
bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, abi.encode(masterCopy));
bytes32 salt = keccak256(abi.encode(msg.sender, saltNonce));
// solium-disable-next-line security/no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(address(proxy) != address(0), "create2 call failed");

{
address[] memory tmp = new address[](1);
tmp[0] = address(this);
proxy.setup(tmp, 1, address(0), "", fallbackHandler, address(0), 0, address(0));
}

execTransactionSuccess = proxy.execTransaction(to, value, data, operation, 0, 0, 0, address(0), address(0),
abi.encodePacked(uint(address(this)), uint(0), uint8(1)));

proxy.execTransaction(
address(proxy), 0,
abi.encodeWithSignature("swapOwner(address,address,address)", address(1), address(this), msg.sender),
Enum.Operation.Call,
0, 0, 0, address(0), address(0),
abi.encodePacked(uint(address(this)), uint(0), uint8(1))
);

emit ProxyCreation(GnosisSafeProxy(address(proxy)));
}
}
2 changes: 2 additions & 0 deletions migrations-ts/1-deploy-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module.exports = async function(deployer: Truffle.Deployer, network: string) {
].map(deploy));
}

await deployer.deploy(artifacts.require('CPKFactoryV1'));

await deployer.deploy(
artifacts.require('CPKFactory'),
artifacts.require('GnosisSafeProxyFactory').address,
Expand Down
7 changes: 3 additions & 4 deletions test/ethers/shouldWorkWithEthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function shouldWorkWithEthers({
let networks: NetworksConfig

before('obtain addresses from artifacts', async () => {
const { gnosisSafe, gnosisSafe2, cpkFactory, multiSend, defaultCallbackHandler } = contracts
const { gnosisSafe, gnosisSafe2, cpkFactory, cpkFactoryV1, multiSend, defaultCallbackHandler } = contracts

networks = {
[(await signer.provider.getNetwork()).chainId]: {
Expand All @@ -136,12 +136,11 @@ export function shouldWorkWithEthers({
initialImplAddress: await cpkFactory.proxyImplSetter(),
},
{
// TODO: Use v1 addr
proxyFactoryAddress: cpkFactory.address,
proxyFactoryAddress: cpkFactoryV1.address,
initialImplAddress: gnosisSafe.address,
},
{
proxyFactoryAddress: cpkFactory.address,
proxyFactoryAddress: cpkFactoryV1.address,
initialImplAddress: gnosisSafe2.address,
},
],
Expand Down
12 changes: 12 additions & 0 deletions test/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const TruffleContract = require('@truffle/contract')
import Web3Maj1Min3 from 'web3-1-3'
import ConditionalTokensJson from '../../build/contracts/ConditionalTokens.json'
import CPKFactoryJson from '../../build/contracts/CPKFactory.json'
import CPKFactoryV1Json from '../../build/contracts/CPKFactoryV1.json'
import DailyLimitModuleJson from '../../build/contracts/DailyLimitModule.json'
import DefaultCallbackHandlerJson from '../../build/contracts/DefaultCallbackHandler.json'
import ERC20MintableJson from '../../build/contracts/ERC20Mintable.json'
Expand All @@ -13,6 +14,7 @@ import MultistepJson from '../../build/contracts/Multistep.json'
import { Address } from '../../src/utils/basicTypes'

let CPKFactory: any
let CPKFactoryV1: any
let GnosisSafe: any
let GnosisSafe2: any
let GnosisSafeProxyFactory: any
Expand All @@ -24,6 +26,7 @@ let ConditionalTokens: any
let DailyLimitModule: any

let cpkFactory: any
let cpkFactoryV1: any
let gnosisSafe: any
let gnosisSafe2: any
let gnosisSafeProxyFactory: any
Expand All @@ -36,6 +39,7 @@ let dailyLimitModule: any

export interface TestContractInstances {
cpkFactory: any
cpkFactoryV1: any
gnosisSafe: any
gnosisSafe2: any
gnosisSafeProxyFactory: any
Expand All @@ -49,6 +53,7 @@ export interface TestContractInstances {

export interface TestContracts {
CPKFactory: any
CPKFactoryV1: any
GnosisSafe: any
GnosisSafe2: any
GnosisSafeProxyFactory: any
Expand All @@ -68,6 +73,11 @@ export const initializeContracts = async (safeOwner: Address): Promise<void> =>
CPKFactory.defaults({ from: safeOwner })
cpkFactory = await CPKFactory.deployed()

CPKFactoryV1 = TruffleContract(CPKFactoryV1Json)
CPKFactoryV1.setProvider(provider)
CPKFactoryV1.defaults({ from: safeOwner })
cpkFactoryV1 = await CPKFactoryV1.deployed()

GnosisSafe = TruffleContract(GnosisSafeJson)
GnosisSafe.setProvider(provider)
GnosisSafe.defaults({ from: safeOwner })
Expand Down Expand Up @@ -116,6 +126,7 @@ export const initializeContracts = async (safeOwner: Address): Promise<void> =>

export const getContracts = (): TestContracts => ({
CPKFactory,
CPKFactoryV1,
GnosisSafe,
GnosisSafe2,
GnosisSafeProxyFactory,
Expand All @@ -129,6 +140,7 @@ export const getContracts = (): TestContracts => ({

export const getContractInstances = (): TestContractInstances => ({
cpkFactory,
cpkFactoryV1,
gnosisSafe,
gnosisSafe2,
gnosisSafeProxyFactory,
Expand Down
7 changes: 3 additions & 4 deletions test/web3/shouldWorkWithWeb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function shouldWorkWithWeb3({
let networks: NetworksConfig

before('obtain addresses from artifacts', async () => {
const { gnosisSafe, gnosisSafe2, cpkFactory, multiSend, defaultCallbackHandler } = contracts
const { gnosisSafe, gnosisSafe2, cpkFactory, cpkFactoryV1, multiSend, defaultCallbackHandler } = contracts

networks = {
[await ueb3.eth.net.getId()]: {
Expand All @@ -124,12 +124,11 @@ export function shouldWorkWithWeb3({
initialImplAddress: await cpkFactory.proxyImplSetter(),
},
{
// TODO: Use v1 addr
proxyFactoryAddress: cpkFactory.address,
proxyFactoryAddress: cpkFactoryV1.address,
initialImplAddress: gnosisSafe.address,
},
{
proxyFactoryAddress: cpkFactory.address,
proxyFactoryAddress: cpkFactoryV1.address,
initialImplAddress: gnosisSafe2.address,
},
],
Expand Down

0 comments on commit d92fc7f

Please sign in to comment.