Skip to content

Commit 5c90b12

Browse files
aarltchriseth
authored andcommitted
[isoltest] Add support to query balance.
1 parent 5c02837 commit 5c90b12

11 files changed

+69
-10
lines changed

test/libsolidity/SemanticTest.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ void SemanticTest::initializeBuiltins()
125125
{
126126
return util::toBigEndian(u256(0x1234));
127127
};
128+
soltestAssert(m_builtins.count("balance") == 0, "");
129+
m_builtins["balance"] = [this](FunctionCall const& _call) -> std::optional<bytes>
130+
{
131+
soltestAssert(_call.arguments.parameters.size() <= 1, "Account address expected.");
132+
h160 address;
133+
if (_call.arguments.parameters.size() == 1)
134+
address = h160(_call.arguments.parameters.at(0).rawString);
135+
else
136+
address = m_contractAddress;
137+
return util::toBigEndian(SolidityExecutionFramework::balanceAt(address));
138+
};
128139
soltestAssert(m_builtins.count("storageEmpty") == 0, "");
129140
m_builtins["storageEmpty"] = [this](FunctionCall const& _call) -> std::optional<bytes>
130141
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
contract Other {
2+
constructor() payable {
3+
}
4+
function getAddress() public returns (address) {
5+
return address(this);
6+
}
7+
}
8+
contract ClientReceipt {
9+
Other other;
10+
constructor() payable {
11+
other = new Other{value:500}();
12+
}
13+
function getAddress() public returns (address) {
14+
return other.getAddress();
15+
}
16+
}
17+
// ====
18+
// compileViaYul: also
19+
// ----
20+
// constructor(), 2000 wei ->
21+
// gas irOptimized: 191881
22+
// gas legacy: 235167
23+
// gas legacyOptimized: 180756
24+
// balance -> 1500
25+
// gas irOptimized: 191881
26+
// gas legacy: 235167
27+
// gas legacyOptimized: 180756
28+
// getAddress() -> 0xf01f7809444bd9a93a854361c6fae3f23d9e23db
29+
// balance: 0xf01f7809444bd9a93a854361c6fae3f23d9e23db -> 500
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
contract ClientReceipt {
2+
constructor() payable {}
3+
}
4+
// ====
5+
// compileViaYul: also
6+
// ----
7+
// constructor(), 1000 wei ->
8+
// balance -> 1000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
contract ClientReceipt {
2+
constructor() payable {}
3+
}
4+
// ====
5+
// compileViaYul: also
6+
// ----
7+
// constructor(), 1 ether ->
8+
// balance -> 1000000000000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
contract ClientReceipt {
2+
}
3+
// ====
4+
// compileViaYul: also
5+
// ----
6+
// balance -> 0
7+
// balance: 0x0000000000000000000000000000000000000000 -> 0

test/libsolidity/semanticTests/payable/no_nonpayable_circumvention_by_modifier.sol

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ contract C {
88
function msgvalue() internal returns (uint) {
99
return msg.value;
1010
}
11-
// TODO: remove this helper function once isoltest supports balance checking
12-
function balance() external returns (uint) {
13-
return address(this).balance;
14-
}
1511
}
1612
// ====
1713
// compileViaYul: also
1814
// compileToEwasm: also
1915
// ----
2016
// f(), 27 wei -> FAILURE
21-
// balance() -> 0
17+
// balance -> 0

test/libsolidity/semanticTests/smoke/constructor.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ contract C {
1515
// ----
1616
// constructor(), 2 wei: 3 ->
1717
// state() -> 3
18-
// balance() -> 2
18+
// balance -> 2
1919
// update(uint256): 4
2020
// state() -> 4

test/libsolidity/semanticTests/smoke/fallback.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ contract A {
99
}
1010
}
1111
// ====
12-
// compileViaYul: also
1312
// compileToEwasm: also
13+
// compileViaYul: also
1414
// ----
1515
// data() -> 0
1616
// ()
1717
// data() -> 1
1818
// (): hex"42ef"
1919
// data() -> 2
2020
// externalData() -> 0x20, 2, left(0x42ef)
21-
// balance() -> 0
21+
// balance -> 0
2222
// (), 1 wei
23-
// balance() -> 1
23+
// balance -> 1
2424
// (), 2 wei: hex"fefe"
25-
// balance() -> 2
25+
// balance -> 3
2626
// externalData() -> 0x20, 2, left(0xfefe)

0 commit comments

Comments
 (0)