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 19, 2020
1 parent 5b3c77e commit f70b86b
Show file tree
Hide file tree
Showing 2 changed files with 32 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
24 changes: 24 additions & 0 deletions test/contract-proxy-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function shouldSupportDifferentTransactions({
fromWei,
getTransactionCount,
getBalance,
getCode,
keccak256,
getGasUsed,
testedTxObjProps,
checkTxObj,
Expand Down Expand Up @@ -323,6 +325,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 All @@ -340,6 +360,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 Expand Up @@ -462,6 +484,8 @@ function shouldWorkWithEthers(ethers, defaultAccount, safeOwner, gnosisSafeProvi
getGasUsed: async ({ transactionResponse }) => (
await transactionResponse.wait()
).gasUsed.toNumber(),
getCode: (address) => signer.provider.getCode(address),
keccak256: (hex) => ethers.utils.keccak256(hex),
testedTxObjProps: 'the TransactionResponse and the hash',
checkTxObj: ({ transactionResponse, hash }) => {
should.exist(transactionResponse);
Expand Down

0 comments on commit f70b86b

Please sign in to comment.