Skip to content

Commit aa7e4e0

Browse files
committed
A few more tests.
1 parent 94dd6d0 commit aa7e4e0

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed
Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
contract Test {
2-
uint256 x;
3-
4-
function test() public returns (uint256) {
5-
uint256 a = myGetX();
6-
x = 5;
7-
uint256 b = myGetX();
1+
contract C {
2+
function f() external returns (uint256 x) {
83
assembly {
9-
log0(0, 64)
4+
mstore(0, 0x42)
5+
}
6+
assembly {
7+
x := mload(0)
108
}
11-
return a + b + myGetX();
129
}
13-
14-
function myGetX() internal view returns (uint256) {
10+
function g() external returns (bool) {
11+
uint initialFreeMemoryPointer;
12+
assembly {
13+
initialFreeMemoryPointer := mload(0x40)
14+
}
15+
assembly {
16+
let ptr := mload(0x40)
17+
mstore(0x40, add(ptr, 0x20))
18+
}
19+
uint finalFreeMemoryPointer;
1520
assembly {
16-
mstore(1, 0x123456789abcdef)
21+
finalFreeMemoryPointer := mload(0x40)
1722
}
18-
return x;
23+
assert(initialFreeMemoryPointer != finalFreeMemoryPointer);
24+
return true;
1925
}
2026
}
2127
// ----
22-
// test() -> 10
23-
// ~ emit <anonymous>: 0x0123456789abcd, 0xef00000000000000000000000000000000000000000000000000000000000000
28+
// f() -> 0x42
29+
// g() -> true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
contract Test {
2+
uint256 x;
3+
4+
function test() public returns (uint256) {
5+
uint256 a = myGetX();
6+
x = 5;
7+
uint256 b = myGetX();
8+
assembly {
9+
log0(0, 64)
10+
}
11+
return a + b + myGetX();
12+
}
13+
14+
function myGetX() internal view returns (uint256) {
15+
assembly {
16+
mstore(1, 0x123456789abcdef)
17+
}
18+
return x;
19+
}
20+
}
21+
// ----
22+
// test() -> 10
23+
// ~ emit <anonymous>: 0x0123456789abcd, 0xef00000000000000000000000000000000000000000000000000000000000000

0 commit comments

Comments
 (0)