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 Jun 17, 2020
1 parent 25080a8 commit 0645e9e
Show file tree
Hide file tree
Showing 4 changed files with 34 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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export function shouldWorkWithEthers({
signer.provider.getTransactionCount(address)
),
getBalance: (address: Address): Promise<number> => signer.provider.getBalance(address),
getCode: (address: Address): Promise<string> => signer.provider.getCode(address),
keccak256: (hex: string): string => ethers.utils.keccak256(hex),
testedTxObjProps: 'the TransactionResponse and the hash',
checkTxObj:
({ transactionResponse, hash }: { transactionResponse: any; hash: string }): void => {
Expand Down
22 changes: 22 additions & 0 deletions test/transactions/shouldSupportDifferentTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface ShouldSupportDifferentTransactionsProps {
fromWei: any;
getTransactionCount: any;
getBalance: any;
getCode: any;
keccak256: any;
testedTxObjProps: any;
checkTxObj: any;
waitTxReceipt: any;
Expand All @@ -28,6 +30,8 @@ export function shouldSupportDifferentTransactions({
fromWei,
getTransactionCount,
getBalance,
getCode,
keccak256,
testedTxObjProps,
checkTxObj,
waitTxReceipt,
Expand Down Expand Up @@ -290,5 +294,23 @@ export function shouldSupportDifferentTransactions({

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

if (!ownerIsRecognizedContract) {
it('deploys proxy which matches factory specs', async () => {
const cpkFactory = await getContracts().CPKFactory.deployed();
const idPrecompile = `0x${'0'.repeat(39)}4`;
await cpk.execTransactions([{
operation: CPK.Call,
to: idPrecompile,
value: 0,
data: '0x',
}]);
const proxyRuntimeCode = await getCode(cpk.address);
await cpkFactory.proxyRuntimeCode()
.should.eventually.equal(proxyRuntimeCode);
await cpkFactory.proxyRuntimeCodeHash()
.should.eventually.equal(keccak256(proxyRuntimeCode));
});
}
});
}
2 changes: 2 additions & 0 deletions test/web3/shouldWorkWithWeb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export function shouldWorkWithWeb3({
testedTxObjProps: 'the PromiEvent for the transaction and the hash',
getBalance: (address: Address): number => web3Box[0].eth.getBalance(address)
.then((balance: number) => web3Box[0].utils.toBN(balance)),
getCode: (address: Address): Promise<string> => web3Box[0].eth.getCode(address),
keccak256: (hex: string): string => web3Box[0].utils.keccak256(hex),
checkTxObj: ({ promiEvent, hash }: { promiEvent: any; hash: string }): void => {
should.exist(promiEvent);
should.exist(hash);
Expand Down

0 comments on commit 0645e9e

Please sign in to comment.