Cleaner solution to provide standard sources.

This commit is contained in:
Christian 2015-01-28 13:39:04 +01:00
parent f9109f2eea
commit 77374a46ce
4 changed files with 23 additions and 2 deletions

View File

@ -35,6 +35,8 @@ namespace test
class InterfaceChecker class InterfaceChecker
{ {
public: public:
InterfaceChecker(): m_compilerStack(false) {}
void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString) void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString)
{ {
try try

View File

@ -1862,6 +1862,21 @@ BOOST_AUTO_TEST_CASE(function_modifier_for_constructor)
BOOST_CHECK(callContractFunction("getData()") == encodeArgs(4 | 2)); BOOST_CHECK(callContractFunction("getData()") == encodeArgs(4 | 2));
} }
BOOST_AUTO_TEST_CASE(use_std_lib)
{
char const* sourceCode = R"(
import "mortal";
contract Icarus is mortal { }
)";
u256 amount(130);
u160 address(23);
compileAndRun(sourceCode, amount, "Icarus");
u256 balanceBefore = m_state.balance(m_sender);
BOOST_CHECK(callContractFunction("kill()") == bytes());
BOOST_CHECK(!m_state.addressHasCode(m_contractAddress));
BOOST_CHECK(m_state.balance(m_sender) > balanceBefore);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }

View File

@ -36,6 +36,8 @@ namespace test
class DocumentationChecker class DocumentationChecker
{ {
public: public:
DocumentationChecker(): m_compilerStack(false) {}
void checkNatspec(std::string const& _code, void checkNatspec(std::string const& _code,
std::string const& _expectedDocumentationString, std::string const& _expectedDocumentationString,
bool _userDocumentation) bool _userDocumentation)

View File

@ -45,10 +45,12 @@ public:
bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "")
{ {
dev::solidity::CompilerStack compiler; // add standard sources only if contract name is given
dev::solidity::CompilerStack compiler(!_contractName.empty());
try try
{ {
compiler.compile(_sourceCode, m_optimize); compiler.addSource("", _sourceCode);
compiler.compile(m_optimize);
} }
catch(boost::exception const& _e) catch(boost::exception const& _e)
{ {