Skip to content

Commit 96168a1

Browse files
committed
Add test for selfdestruct
Also drop less useful EndToEndTest
1 parent 2201526 commit 96168a1

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

test/libsolidity/SolidityEndToEndTest.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -912,29 +912,6 @@ BOOST_AUTO_TEST_CASE(transfer_ether)
912912
)
913913
}
914914

915-
BOOST_AUTO_TEST_CASE(selfdestruct)
916-
{
917-
char const* sourceCode = R"(
918-
contract test {
919-
constructor() payable {}
920-
function a(address payable receiver) public returns (uint ret) {
921-
selfdestruct(receiver);
922-
return 10;
923-
}
924-
}
925-
)";
926-
u256 amount(130);
927-
h160 address(23);
928-
ALSO_VIA_YUL(
929-
DISABLE_EWASM_TESTRUN()
930-
931-
compileAndRun(sourceCode, amount);
932-
ABI_CHECK(callContractFunction("a(address)", address), bytes());
933-
BOOST_CHECK(!addressHasCode(m_contractAddress));
934-
BOOST_CHECK_EQUAL(balanceAt(address), amount);
935-
)
936-
}
937-
938915
BOOST_AUTO_TEST_CASE(keccak256)
939916
{
940917
char const* sourceCode = R"(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
contract C {
2+
event Terminated();
3+
4+
constructor() payable {
5+
}
6+
7+
function terminate() external {
8+
emit Terminated();
9+
selfdestruct(payable(msg.sender));
10+
// Execution stops here, so the second one is not executed.
11+
selfdestruct(payable(msg.sender));
12+
emit Terminated();
13+
}
14+
}
15+
16+
contract D {
17+
C public c;
18+
19+
constructor() payable {
20+
c = new C{value: 1 ether}();
21+
}
22+
23+
function f() external {
24+
c.terminate();
25+
}
26+
27+
function exists() external returns (bool) {
28+
return address(c).code.length != 0;
29+
}
30+
}
31+
// ----
32+
// constructor(), 1 ether ->
33+
// gas irOptimized: 188203
34+
// gas legacy: 261114
35+
// gas legacyOptimized: 181602
36+
// c() -> 0x137aa4dfc0911524504fcd4d98501f179bc13b4a
37+
// balance: 0x137aa4dfc0911524504fcd4d98501f179bc13b4a -> 1000000000000000000
38+
// balance -> 0
39+
// exists() -> true
40+
// f() ->
41+
// ~ emit Terminated() from 0x137aa4dfc0911524504fcd4d98501f179bc13b4a
42+
// balance: 0x137aa4dfc0911524504fcd4d98501f179bc13b4a -> 0
43+
// ~ emit Terminated() from 0x137aa4dfc0911524504fcd4d98501f179bc13b4a
44+
// balance -> 1000000000000000000
45+
// ~ emit Terminated() from 0x137aa4dfc0911524504fcd4d98501f179bc13b4a
46+
// exists() -> false

0 commit comments

Comments
 (0)