Merge pull request #11423 from ethereum/account_builtin

[isoltest] Add account builtin.
This commit is contained in:
Alex Beregszaszi 2021-05-21 13:41:07 +01:00 committed by GitHub
commit f6bb3df747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 4 deletions

View File

@ -241,6 +241,12 @@ public:
return result;
}
util::h160 setAccount(size_t _accountNumber)
{
m_sender = account(_accountNumber);
return m_sender;
}
private:
template <class CppFunction, class... Args>
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)

View File

@ -123,7 +123,7 @@ SemanticTest::SemanticTest(
}
}
map<string, Builtin> SemanticTest::makeBuiltins() const
map<string, Builtin> SemanticTest::makeBuiltins()
{
return {
{
@ -153,7 +153,17 @@ map<string, Builtin> SemanticTest::makeBuiltins() const
soltestAssert(_call.arguments.parameters.empty(), "No arguments expected.");
return toBigEndian(u256(storageEmpty(m_contractAddress) ? 1 : 0));
}
},
{
"account",
[this](FunctionCall const& _call) -> optional<bytes>
{
soltestAssert(_call.arguments.parameters.size() == 1, "Account number expected.");
size_t accountNumber = static_cast<size_t>(stoi(_call.arguments.parameters.at(0).rawString));
// Need to pad it to 32-bytes to workaround limitations in BytesUtils::formatHex.
return toBigEndian(h256(ExecutionFramework::setAccount(accountNumber).asBytes(), h256::AlignRight));
}
},
};
}

View File

@ -80,7 +80,7 @@ public:
private:
TestResult runTest(std::ostream& _stream, std::string const& _linePrefix, bool _formatted, bool _isYulRun, bool _isEwasmRun);
bool checkGasCostExpectation(TestFunctionCall& io_test, bool _compileViaYul) const;
std::map<std::string, Builtin> makeBuiltins() const;
std::map<std::string, Builtin> makeBuiltins();
SourceMap m_sources;
std::size_t m_lineOffset;
std::vector<TestFunctionCall> m_tests;

View File

@ -0,0 +1,48 @@
contract AccountBuiltinTest {
function who_am_i() public returns (address result) {
result = msg.sender;
}
}
// ====
// compileViaYul: also
// ----
// constructor()
// account: 0 -> 0x1212121212121212121212121212120000000012
// who_am_i() -> 0x1212121212121212121212121212120000000012
// balance: 0x1212121212121212121212121212120000000012 -> 1267650600228229401496703205376
// account: 1 -> 0x1212121212121212121212121212120000001012
// who_am_i() -> 0x1212121212121212121212121212120000001012
// balance: 0x1212121212121212121212121212120000001012 -> 1267650600228229401496703205376
// account: 2 -> 0x1212121212121212121212121212120000002012
// who_am_i() -> 0x1212121212121212121212121212120000002012
// balance: 0x1212121212121212121212121212120000002012 -> 1267650600228229401496703205376
// account: 3 -> 0x1212121212121212121212121212120000003012
// who_am_i() -> 0x1212121212121212121212121212120000003012
// balance: 0x1212121212121212121212121212120000003012 -> 1267650600228229401496703205376
// account: 4 -> 0x1212121212121212121212121212120000004012
// who_am_i() -> 0x1212121212121212121212121212120000004012
// balance: 0x1212121212121212121212121212120000004012 -> 1267650600228229401496703205376
// account: 5 -> 0x1212121212121212121212121212120000005012
// who_am_i() -> 0x1212121212121212121212121212120000005012
// balance: 0x1212121212121212121212121212120000005012 -> 1267650600228229401496703205376
// account: 6 -> 0x1212121212121212121212121212120000006012
// who_am_i() -> 0x1212121212121212121212121212120000006012
// balance: 0x1212121212121212121212121212120000006012 -> 1267650600228229401496703205376
// account: 7 -> 0x1212121212121212121212121212120000007012
// who_am_i() -> 0x1212121212121212121212121212120000007012
// balance: 0x1212121212121212121212121212120000007012 -> 1267650600228229401496703205376
// account: 8 -> 0x1212121212121212121212121212120000008012
// who_am_i() -> 0x1212121212121212121212121212120000008012
// balance: 0x1212121212121212121212121212120000008012 -> 1267650600228229401496703205376
// account: 9 -> 0x1212121212121212121212121212120000009012
// who_am_i() -> 0x1212121212121212121212121212120000009012
// balance: 0x1212121212121212121212121212120000009012 -> 1267650600228229401496703205376
// account: 10 -> 0x121212121212121212121212121212000000a012
// who_am_i() -> 0x121212121212121212121212121212000000a012
// balance: 0x121212121212121212121212121212000000a012 -> 0
// account: 11 -> 0x121212121212121212121212121212000000b012
// who_am_i() -> 0x121212121212121212121212121212000000b012
// balance: 0x121212121212121212121212121212000000b012 -> 0
// account: 12 -> 0x121212121212121212121212121212000000c012
// who_am_i() -> 0x121212121212121212121212121212000000c012
// balance: 0x121212121212121212121212121212000000c012 -> 0