-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement delegate_call #80
base: main
Are you sure you want to change the base?
Changes from 1 commit
64390a2
2dd478c
5636824
9f85c92
fb6b7ac
d96aba0
678f6ce
c0fd2be
240854c
cf25a1e
5e50bd0
c200791
d7e2334
b00ceb7
ecf5336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8; | ||
|
||
/* runner.json | ||
{ | ||
"differential": true, | ||
"actions": [ | ||
{ | ||
"Upload": { | ||
"code": { | ||
"Solidity": { | ||
"contract": "Logic" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"Instantiate": { | ||
"code": { | ||
"Solidity": { | ||
"contract": "Tester" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"Call": { | ||
"dest": { | ||
"Instantiated": 0 | ||
}, | ||
"value": 123, | ||
"data": "6466414b0000000000000000000000000000000000000000000000000000000000000020" | ||
} | ||
} | ||
] | ||
} | ||
*/ | ||
|
||
contract Logic { | ||
// NOTE: storage layout must be the same as contract Tester | ||
uint256 public num; | ||
address public sender; | ||
uint256 public value; | ||
|
||
event DidSetVars(); | ||
|
||
function setVars(uint256 _num) public payable returns (uint256) { | ||
num = _num * 2; | ||
sender = msg.sender; | ||
value = msg.value; | ||
emit DidSetVars(); | ||
return _num; | ||
} | ||
} | ||
|
||
contract Tester { | ||
uint256 public num; | ||
address public sender; | ||
uint256 public value; | ||
|
||
function setVars(uint256 _num) public payable returns (bool, bytes memory) { | ||
Logic impl = new Logic(); | ||
|
||
// Tester's storage is set, Logic is not modified. | ||
(bool success, bytes memory data) = address(impl).delegatecall( | ||
abi.encodeWithSignature("setVars(uint256)", _num) | ||
); | ||
|
||
assert(success); | ||
assert(impl.num() == 0); | ||
assert(impl.sender() == address(0)); | ||
assert(impl.value() == 0); | ||
assert(this.num() == _num * 2); | ||
assert(this.sender() == msg.sender); | ||
assert(this.value() == msg.value); | ||
|
||
return (success, data); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ test_spec!(call, "Caller", "Call.sol"); | |
test_spec!(transfer, "Transfer", "Transfer.sol"); | ||
test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol"); | ||
test_spec!(immutables, "Immutables", "Immutables.sol"); | ||
test_spec!(delegate, "Delegate", "Delegate.sol"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could use some better test coverage, i.e. calling into non-existent accounts, plain accounts, recursively into self (from runtime code and the constructor). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will add more cases |
||
|
||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> { | ||
vec![Instantiate { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing this is irrelevant here? Keeping the fixtures as concise as possible eases debugging them :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just making sure emitted event belongs to caller and not callee