diff --git a/test/libsolidity/SemanticTest.cpp b/test/libsolidity/SemanticTest.cpp index 51a5a3c9c..004459277 100644 --- a/test/libsolidity/SemanticTest.cpp +++ b/test/libsolidity/SemanticTest.cpp @@ -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 + { + 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 { diff --git a/test/libsolidity/semanticTests/isoltestTesting/balance_other_contract.sol b/test/libsolidity/semanticTests/isoltestTesting/balance_other_contract.sol new file mode 100644 index 000000000..59ad2cd84 --- /dev/null +++ b/test/libsolidity/semanticTests/isoltestTesting/balance_other_contract.sol @@ -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 diff --git a/test/libsolidity/semanticTests/isoltestTesting/balance_with_balance.sol b/test/libsolidity/semanticTests/isoltestTesting/balance_with_balance.sol new file mode 100644 index 000000000..5b6324910 --- /dev/null +++ b/test/libsolidity/semanticTests/isoltestTesting/balance_with_balance.sol @@ -0,0 +1,8 @@ +contract ClientReceipt { + constructor() payable {} +} +// ==== +// compileViaYul: also +// ---- +// constructor(), 1000 wei -> +// balance -> 1000 diff --git a/test/libsolidity/semanticTests/isoltestTesting/balance_with_balance2.sol b/test/libsolidity/semanticTests/isoltestTesting/balance_with_balance2.sol new file mode 100644 index 000000000..f7d62afe5 --- /dev/null +++ b/test/libsolidity/semanticTests/isoltestTesting/balance_with_balance2.sol @@ -0,0 +1,8 @@ +contract ClientReceipt { + constructor() payable {} +} +// ==== +// compileViaYul: also +// ---- +// constructor(), 1 ether -> +// balance -> 1000000000000000000 diff --git a/test/libsolidity/semanticTests/isoltestTesting/balance_without_balance.sol b/test/libsolidity/semanticTests/isoltestTesting/balance_without_balance.sol new file mode 100644 index 000000000..b89977035 --- /dev/null +++ b/test/libsolidity/semanticTests/isoltestTesting/balance_without_balance.sol @@ -0,0 +1,7 @@ +contract ClientReceipt { +} +// ==== +// compileViaYul: also +// ---- +// balance -> 0 +// balance: 0x0000000000000000000000000000000000000000 -> 0 diff --git a/test/libsolidity/semanticTests/builtins/smoke_test.sol b/test/libsolidity/semanticTests/isoltestTesting/smoke_test.sol similarity index 100% rename from test/libsolidity/semanticTests/builtins/smoke_test.sol rename to test/libsolidity/semanticTests/isoltestTesting/smoke_test.sol diff --git a/test/libsolidity/semanticTests/builtins/storage/storage_empty.sol b/test/libsolidity/semanticTests/isoltestTesting/storage/storage_empty.sol similarity index 100% rename from test/libsolidity/semanticTests/builtins/storage/storage_empty.sol rename to test/libsolidity/semanticTests/isoltestTesting/storage/storage_empty.sol diff --git a/test/libsolidity/semanticTests/builtins/storage/storage_nonempty.sol b/test/libsolidity/semanticTests/isoltestTesting/storage/storage_nonempty.sol similarity index 100% rename from test/libsolidity/semanticTests/builtins/storage/storage_nonempty.sol rename to test/libsolidity/semanticTests/isoltestTesting/storage/storage_nonempty.sol diff --git a/test/libsolidity/semanticTests/payable/no_nonpayable_circumvention_by_modifier.sol b/test/libsolidity/semanticTests/payable/no_nonpayable_circumvention_by_modifier.sol index cb456a412..b24ca2291 100644 --- a/test/libsolidity/semanticTests/payable/no_nonpayable_circumvention_by_modifier.sol +++ b/test/libsolidity/semanticTests/payable/no_nonpayable_circumvention_by_modifier.sol @@ -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 diff --git a/test/libsolidity/semanticTests/smoke/constructor.sol b/test/libsolidity/semanticTests/smoke/constructor.sol index 9cf435087..3837fe071 100644 --- a/test/libsolidity/semanticTests/smoke/constructor.sol +++ b/test/libsolidity/semanticTests/smoke/constructor.sol @@ -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 diff --git a/test/libsolidity/semanticTests/smoke/fallback.sol b/test/libsolidity/semanticTests/smoke/fallback.sol index c6aa251cd..f789ed276 100644 --- a/test/libsolidity/semanticTests/smoke/fallback.sol +++ b/test/libsolidity/semanticTests/smoke/fallback.sol @@ -9,8 +9,8 @@ contract A { } } // ==== -// compileViaYul: also // compileToEwasm: also +// compileViaYul: also // ---- // data() -> 0 // ()