Merge pull request #10873 from ethereum/isoltest-balance

[isoltest] Add support to query balance.
This commit is contained in:
chriseth 2021-04-28 17:01:31 +02:00 committed by GitHub
commit 850c25bf8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 67 additions and 6 deletions

View File

@ -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>
{

View File

@ -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

View File

@ -0,0 +1,8 @@
contract ClientReceipt {
constructor() payable {}
}
// ====
// compileViaYul: also
// ----
// constructor(), 1000 wei ->
// balance -> 1000

View File

@ -0,0 +1,8 @@
contract ClientReceipt {
constructor() payable {}
}
// ====
// compileViaYul: also
// ----
// constructor(), 1 ether ->
// balance -> 1000000000000000000

View File

@ -0,0 +1,7 @@
contract ClientReceipt {
}
// ====
// compileViaYul: also
// ----
// balance -> 0
// balance: 0x0000000000000000000000000000000000000000 -> 0

View File

@ -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

View File

@ -14,7 +14,9 @@ contract C {
// compileViaYul: also
// ----
// constructor(), 2 wei: 3 ->
// gas legacy: 148000
// state() -> 3
// balance() -> 2
// balance -> 2
// update(uint256): 4
// state() -> 4

View File

@ -9,8 +9,8 @@ contract A {
}
}
// ====
// compileViaYul: also
// compileToEwasm: also
// compileViaYul: also
// ----
// data() -> 0
// ()