Skip to content

[isoltest] Add support to query balance. #10873

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

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/libsolidity/SemanticTest.cpp
Original file line number Diff line number Diff line change
@@ -125,6 +125,17 @@ void SemanticTest::initializeBuiltins()
{
return util::toBigEndian(u256(0x1234));
};
soltestAssert(m_builtins.count("balance") == 0, "");
m_builtins["balance"] = [this](FunctionCall const& _call) -> std::optional<bytes>
{
soltestAssert(_call.arguments.parameters.size() <= 1, "Account address expected.");
h160 address;
if (_call.arguments.parameters.size() == 1)
address = h160(_call.arguments.parameters.at(0).rawString);
else
address = m_contractAddress;
return util::toBigEndian(SolidityExecutionFramework::balanceAt(address));
};
soltestAssert(m_builtins.count("storageEmpty") == 0, "");
m_builtins["storageEmpty"] = [this](FunctionCall const& _call) -> std::optional<bytes>
{
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
contract Other {
constructor() payable {
}
function getAddress() public returns (address) {
return address(this);
}
}
contract ClientReceipt {
Other other;
constructor() payable {
other = new Other{value:500}();
}
function getAddress() public returns (address) {
return other.getAddress();
}
}
// ====
// compileViaYul: also
// ----
// constructor(), 2000 wei ->
// gas irOptimized: 191881
// gas legacy: 235167
// gas legacyOptimized: 180756
// balance -> 1500
// gas irOptimized: 191881
// gas legacy: 235167
// gas legacyOptimized: 180756
// getAddress() -> 0xf01f7809444bd9a93a854361c6fae3f23d9e23db
// balance: 0xf01f7809444bd9a93a854361c6fae3f23d9e23db -> 500
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract ClientReceipt {
constructor() payable {}
}
// ====
// compileViaYul: also
// ----
// constructor(), 1000 wei ->
// balance -> 1000
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract ClientReceipt {
constructor() payable {}
}
// ====
// compileViaYul: also
// ----
// constructor(), 1 ether ->
// balance -> 1000000000000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
contract ClientReceipt {
}
// ====
// compileViaYul: also
// ----
// balance -> 0
// balance: 0x0000000000000000000000000000000000000000 -> 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the wei/ether suffix works on the returned value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Original file line number Diff line number Diff line change
@@ -8,14 +8,10 @@ contract C {
function msgvalue() internal returns (uint) {
return msg.value;
}
// TODO: remove this helper function once isoltest supports balance checking
function balance() external returns (uint) {
return address(this).balance;
}
}
// ====
// compileViaYul: also
// compileToEwasm: also
// ----
// f(), 27 wei -> FAILURE
// balance() -> 0
// balance -> 0
2 changes: 2 additions & 0 deletions test/libsolidity/semanticTests/smoke/constructor.sol
Original file line number Diff line number Diff line change
@@ -14,7 +14,9 @@ contract C {
// compileViaYul: also
// ----
// constructor(), 2 wei: 3 ->
// gas legacy: 148000
// state() -> 3
// balance() -> 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove the balance() function from this contract.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use both.

// balance -> 2
// update(uint256): 4
// state() -> 4
2 changes: 1 addition & 1 deletion test/libsolidity/semanticTests/smoke/fallback.sol
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ contract A {
}
}
// ====
// compileViaYul: also
// compileToEwasm: also
// compileViaYul: also
// ----
// data() -> 0
// ()