Skip to content

Commit f70b86b

Browse files
committed
Add proxy runtime code and extcodehash accessors to factory
1 parent 5b3c77e commit f70b86b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

contracts/CPKFactory.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ contract CPKFactory {
1111
return type(Proxy).creationCode;
1212
}
1313

14+
function proxyRuntimeCode() external pure returns (bytes memory) {
15+
return type(Proxy).runtimeCode;
16+
}
17+
18+
function proxyRuntimeCodeHash() external pure returns (bytes32 digest) {
19+
return keccak256(type(Proxy).runtimeCode);
20+
}
21+
1422
function createProxyAndExecTransaction(
1523
address masterCopy,
1624
uint256 saltNonce,

test/contract-proxy-kit.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function shouldSupportDifferentTransactions({
3838
fromWei,
3939
getTransactionCount,
4040
getBalance,
41+
getCode,
42+
keccak256,
4143
getGasUsed,
4244
testedTxObjProps,
4345
checkTxObj,
@@ -323,6 +325,24 @@ function shouldSupportDifferentTransactions({
323325

324326
gasCosts.should.be.equal(gasPrice * gasUsed);
325327
});
328+
329+
if (!ownerIsRecognizedContract) {
330+
it('deploys proxy which matches factory specs', async () => {
331+
const cpkFactory = await CPKFactory.deployed();
332+
const idPrecompile = `0x${'0'.repeat(39)}4`;
333+
await cpk.execTransactions([{
334+
operation: CPK.CALL,
335+
to: idPrecompile,
336+
value: 0,
337+
data: '0x',
338+
}], { gasLimit: defaultGasLimit });
339+
const proxyRuntimeCode = await getCode(cpk.address);
340+
await cpkFactory.proxyRuntimeCode()
341+
.should.eventually.equal(proxyRuntimeCode);
342+
await cpkFactory.proxyRuntimeCodeHash()
343+
.should.eventually.equal(keccak256(proxyRuntimeCode));
344+
});
345+
}
326346
});
327347
}
328348

@@ -340,6 +360,8 @@ function shouldWorkWithWeb3(Web3, defaultAccount, safeOwner, gnosisSafeProviderB
340360
testedTxObjProps: 'the PromiEvent for the transaction and the hash',
341361
getBalance: (address) => web3Box[0].eth.getBalance(address)
342362
.then((balance) => web3Box[0].utils.toBN(balance)),
363+
getCode: (address) => web3Box[0].eth.getCode(address),
364+
keccak256: (hex) => web3Box[0].utils.keccak256(hex),
343365
getGasUsed: ({ promiEvent }) => new Promise(
344366
(resolve, reject) => promiEvent
345367
.on('confirmation', (confNumber, receipt) => resolve(receipt.gasUsed))
@@ -462,6 +484,8 @@ function shouldWorkWithEthers(ethers, defaultAccount, safeOwner, gnosisSafeProvi
462484
getGasUsed: async ({ transactionResponse }) => (
463485
await transactionResponse.wait()
464486
).gasUsed.toNumber(),
487+
getCode: (address) => signer.provider.getCode(address),
488+
keccak256: (hex) => ethers.utils.keccak256(hex),
465489
testedTxObjProps: 'the TransactionResponse and the hash',
466490
checkTxObj: ({ transactionResponse, hash }) => {
467491
should.exist(transactionResponse);

0 commit comments

Comments
 (0)