mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adding blockhash test in Solidity ExpressionCompiler
This commit is contained in:
parent
933d65e986
commit
ab4178941b
@ -86,13 +86,19 @@ Declaration const& resolveDeclaration(vector<string> const& _namespacedName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _functions = {},
|
bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _functions = {},
|
||||||
vector<vector<string>> _localVariables = {})
|
vector<vector<string>> _localVariables = {}, vector<shared_ptr<MagicVariableDeclaration const>> _globalDeclarations = {})
|
||||||
{
|
{
|
||||||
Parser parser;
|
Parser parser;
|
||||||
ASTPointer<SourceUnit> sourceUnit;
|
ASTPointer<SourceUnit> sourceUnit;
|
||||||
BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode))));
|
BOOST_REQUIRE_NO_THROW(sourceUnit = parser.parse(make_shared<Scanner>(CharStream(_sourceCode))));
|
||||||
NameAndTypeResolver resolver({});
|
|
||||||
|
vector<Declaration const*> declarations;
|
||||||
|
declarations.reserve(_globalDeclarations.size() + 1);
|
||||||
|
for (ASTPointer<Declaration const> const& variable: _globalDeclarations)
|
||||||
|
declarations.push_back(variable.get());
|
||||||
|
NameAndTypeResolver resolver(declarations);
|
||||||
resolver.registerDeclarations(*sourceUnit);
|
resolver.registerDeclarations(*sourceUnit);
|
||||||
|
|
||||||
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
|
for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
|
||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
{
|
{
|
||||||
@ -390,6 +396,21 @@ BOOST_AUTO_TEST_CASE(intermediately_overflowing_literals)
|
|||||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(blockhash)
|
||||||
|
{
|
||||||
|
char const* sourceCode = "contract test {\n"
|
||||||
|
" function f() {\n"
|
||||||
|
" block.blockhash(3);\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n";
|
||||||
|
bytes code = compileFirstExpression(sourceCode, {}, {},
|
||||||
|
{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::BLOCK))});
|
||||||
|
|
||||||
|
bytes expectation({byte(eth::Instruction::PUSH1), 0x03,
|
||||||
|
byte(eth::Instruction::BLOCKHASH)});
|
||||||
|
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#include <libethereum/State.h>
|
#include <libethereum/State.h>
|
||||||
#include <libethereum/Executive.h>
|
#include <libethereum/Executive.h>
|
||||||
#include <libsolidity/CompilerStack.h>
|
#include <libsolidity/CompilerStack.h>
|
||||||
#include "TestHelper.h"
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
@ -129,12 +128,6 @@ public:
|
|||||||
return bytes();
|
return bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
eth::LastHashes setCurrentBlockNumber(u256 _currentBlockNumber)
|
|
||||||
{
|
|
||||||
m_lastHashes = dev::test::lastHashes(_currentBlockNumber);
|
|
||||||
return m_lastHashes;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
@ -153,7 +146,7 @@ private:
|
|||||||
void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0)
|
void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0)
|
||||||
{
|
{
|
||||||
m_state.addBalance(m_sender, _value); // just in case
|
m_state.addBalance(m_sender, _value); // just in case
|
||||||
eth::Executive executive(m_state, m_lastHashes, 0);
|
eth::Executive executive(m_state, eth::LastHashes(), 0);
|
||||||
eth::Transaction t = _isCreation ? eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec())
|
eth::Transaction t = _isCreation ? eth::Transaction(_value, m_gasPrice, m_gas, _data, 0, KeyPair::create().sec())
|
||||||
: eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec());
|
: eth::Transaction(_value, m_gasPrice, m_gas, m_contractAddress, _data, 0, KeyPair::create().sec());
|
||||||
bytes transactionRLP = t.rlp();
|
bytes transactionRLP = t.rlp();
|
||||||
@ -191,7 +184,6 @@ protected:
|
|||||||
u256 const m_gas = 1000000;
|
u256 const m_gas = 1000000;
|
||||||
bytes m_output;
|
bytes m_output;
|
||||||
eth::LogEntries m_logs;
|
eth::LogEntries m_logs;
|
||||||
eth::LastHashes m_lastHashes;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user