Skip to content

Commit

Permalink
Add proxy runtime code and extcodehash accessors to factory
Browse files Browse the repository at this point in the history
  • Loading branch information
cag committed Mar 24, 2020
1 parent 0d74c39 commit 7556ff0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contracts/CPKFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ contract CPKFactory {
return type(Proxy).creationCode;
}

function proxyRuntimeCode() external pure returns (bytes memory) {
return type(Proxy).runtimeCode;
}

function proxyRuntimeCodeHash() external pure returns (bytes32 digest) {
return keccak256(type(Proxy).runtimeCode);
}

function createProxyAndExecTransaction(
address masterCopy,
uint256 saltNonce,
Expand Down
2 changes: 2 additions & 0 deletions test/ethers/shouldWorkWithEthers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function shouldWorkWithEthers(ethers, defaultAccount, safeOwner, gnosisSafeProvi
fromWei: (amount) => Number(ethers.utils.formatUnits(amount.toString(), 'ether')),
getTransactionCount: signer.provider.getTransactionCount.bind(signer.provider),
getBalance: signer.provider.getBalance.bind(signer.provider),
getCode: (address) => signer.provider.getCode(address),
keccak256: (hex) => ethers.utils.keccak256(hex),
getGasUsed: async ({ transactionResponse }) => (
await transactionResponse.wait()
).gasUsed.toNumber(),
Expand Down
21 changes: 21 additions & 0 deletions test/transactions/shouldSupportDifferentTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const makeConditionalTokensIdHelpers = require('@gnosis.pm/conditional-tokens-co
const Multistep = artifacts.require('Multistep');
const ConditionalTokens = artifacts.require('ConditionalTokens');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const CPKFactory = artifacts.require('CPKFactory');

const CPK = require('../..');

Expand All @@ -15,6 +16,8 @@ function shouldSupportDifferentTransactions({
fromWei,
getTransactionCount,
getBalance,
getCode,
keccak256,
getGasUsed,
testedTxObjProps,
checkTxObj,
Expand Down Expand Up @@ -300,6 +303,24 @@ function shouldSupportDifferentTransactions({

gasCosts.should.be.equal(gasPrice * gasUsed);
});

if (!ownerIsRecognizedContract) {
it('deploys proxy which matches factory specs', async () => {
const cpkFactory = await CPKFactory.deployed();
const idPrecompile = `0x${'0'.repeat(39)}4`;
await cpk.execTransactions([{
operation: CPK.CALL,
to: idPrecompile,
value: 0,
data: '0x',
}], { gasLimit: defaultGasLimit });
const proxyRuntimeCode = await getCode(cpk.address);
await cpkFactory.proxyRuntimeCode()
.should.eventually.equal(proxyRuntimeCode);
await cpkFactory.proxyRuntimeCodeHash()
.should.eventually.equal(keccak256(proxyRuntimeCode));
});
}
});
}

Expand Down
2 changes: 2 additions & 0 deletions test/web3/shouldWorkWithWeb3.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function shouldWorkWithWeb3(Web3, defaultAccount, safeOwner, gnosisSafeProviderB
testedTxObjProps: 'the PromiEvent for the transaction and the hash',
getBalance: (address) => web3Box[0].eth.getBalance(address)
.then((balance) => web3Box[0].utils.toBN(balance)),
getCode: (address) => web3Box[0].eth.getCode(address),
keccak256: (hex) => web3Box[0].utils.keccak256(hex),
getGasUsed: ({ promiEvent }) => new Promise(
(resolve, reject) => promiEvent
.on('confirmation', (confNumber, receipt) => resolve(receipt.gasUsed))
Expand Down

0 comments on commit 7556ff0

Please sign in to comment.