mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
A few more tests.
This commit is contained in:
parent
94dd6d0671
commit
aa7e4e02bb
@ -1,23 +1,29 @@
|
|||||||
contract Test {
|
contract C {
|
||||||
uint256 x;
|
function f() external returns (uint256 x) {
|
||||||
|
|
||||||
function test() public returns (uint256) {
|
|
||||||
uint256 a = myGetX();
|
|
||||||
x = 5;
|
|
||||||
uint256 b = myGetX();
|
|
||||||
assembly {
|
assembly {
|
||||||
log0(0, 64)
|
mstore(0, 0x42)
|
||||||
|
}
|
||||||
|
assembly {
|
||||||
|
x := mload(0)
|
||||||
}
|
}
|
||||||
return a + b + myGetX();
|
|
||||||
}
|
}
|
||||||
|
function g() external returns (bool) {
|
||||||
function myGetX() internal view returns (uint256) {
|
uint initialFreeMemoryPointer;
|
||||||
assembly {
|
assembly {
|
||||||
mstore(1, 0x123456789abcdef)
|
initialFreeMemoryPointer := mload(0x40)
|
||||||
}
|
}
|
||||||
return x;
|
assembly {
|
||||||
|
let ptr := mload(0x40)
|
||||||
|
mstore(0x40, add(ptr, 0x20))
|
||||||
|
}
|
||||||
|
uint finalFreeMemoryPointer;
|
||||||
|
assembly {
|
||||||
|
finalFreeMemoryPointer := mload(0x40)
|
||||||
|
}
|
||||||
|
assert(initialFreeMemoryPointer != finalFreeMemoryPointer);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
// test() -> 10
|
// f() -> 0x42
|
||||||
// ~ emit <anonymous>: 0x0123456789abcd, 0xef00000000000000000000000000000000000000000000000000000000000000
|
// g() -> true
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
contract Test {
|
||||||
|
uint256 x;
|
||||||
|
|
||||||
|
function test() public returns (uint256) {
|
||||||
|
uint256 a = myGetX();
|
||||||
|
x = 5;
|
||||||
|
uint256 b = myGetX();
|
||||||
|
assembly {
|
||||||
|
log0(0, 64)
|
||||||
|
}
|
||||||
|
return a + b + myGetX();
|
||||||
|
}
|
||||||
|
|
||||||
|
function myGetX() internal view returns (uint256) {
|
||||||
|
assembly {
|
||||||
|
mstore(1, 0x123456789abcdef)
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 10
|
||||||
|
// ~ emit <anonymous>: 0x0123456789abcd, 0xef00000000000000000000000000000000000000000000000000000000000000
|
Loading…
Reference in New Issue
Block a user