mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[isoltest] Add account builtin.
Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
This commit is contained in:
parent
13388e283e
commit
799106acfe
@ -241,6 +241,12 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::h160 setAccount(size_t _accountNumber)
|
||||||
|
{
|
||||||
|
m_sender = account(_accountNumber);
|
||||||
|
return m_sender;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <class CppFunction, class... Args>
|
template <class CppFunction, class... Args>
|
||||||
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)
|
auto callCppAndEncodeResult(CppFunction const& _cppFunction, Args const&... _arguments)
|
||||||
|
@ -123,7 +123,7 @@ SemanticTest::SemanticTest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, Builtin> SemanticTest::makeBuiltins() const
|
map<string, Builtin> SemanticTest::makeBuiltins()
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
@ -151,9 +151,19 @@ map<string, Builtin> SemanticTest::makeBuiltins() const
|
|||||||
[this](FunctionCall const& _call) -> optional<bytes>
|
[this](FunctionCall const& _call) -> optional<bytes>
|
||||||
{
|
{
|
||||||
soltestAssert(_call.arguments.parameters.empty(), "No arguments expected.");
|
soltestAssert(_call.arguments.parameters.empty(), "No arguments expected.");
|
||||||
return toBigEndian(u256(storageEmpty(m_contractAddress) ? 1 : 0));
|
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));
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
TestResult runTest(std::ostream& _stream, std::string const& _linePrefix, bool _formatted, bool _isYulRun, bool _isEwasmRun);
|
TestResult runTest(std::ostream& _stream, std::string const& _linePrefix, bool _formatted, bool _isYulRun, bool _isEwasmRun);
|
||||||
bool checkGasCostExpectation(TestFunctionCall& io_test, bool _compileViaYul) const;
|
bool checkGasCostExpectation(TestFunctionCall& io_test, bool _compileViaYul) const;
|
||||||
std::map<std::string, Builtin> makeBuiltins() const;
|
std::map<std::string, Builtin> makeBuiltins();
|
||||||
SourceMap m_sources;
|
SourceMap m_sources;
|
||||||
std::size_t m_lineOffset;
|
std::size_t m_lineOffset;
|
||||||
std::vector<TestFunctionCall> m_tests;
|
std::vector<TestFunctionCall> m_tests;
|
||||||
|
48
test/libsolidity/semanticTests/isoltestTesting/account.sol
Normal file
48
test/libsolidity/semanticTests/isoltestTesting/account.sol
Normal 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
|
Loading…
Reference in New Issue
Block a user