mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove standard contracts
This commit is contained in:
parent
64cec9793a
commit
e00f802f72
@ -42,26 +42,8 @@ using namespace std;
|
|||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
const map<string, string> StandardSources = map<string, string>{
|
CompilerStack::CompilerStack(ReadFileCallback const& _readFile):
|
||||||
{"coin", R"(import "CoinReg";import "Config";import "configUser";contract coin is configUser{function coin(bytes3 name, uint denom) {CoinReg(Config(configAddr()).lookup(3)).register(name, denom);}})"},
|
m_readFile(_readFile), m_parseSuccessful(false) {}
|
||||||
{"Coin", R"(contract Coin{function isApprovedFor(address _target,address _proxy)constant returns(bool _r){}function isApproved(address _proxy)constant returns(bool _r){}function sendCoinFrom(address _from,uint256 _val,address _to){}function coinBalanceOf(address _a)constant returns(uint256 _r){}function sendCoin(uint256 _val,address _to){}function coinBalance()constant returns(uint256 _r){}function approve(address _a){}})"},
|
|
||||||
{"CoinReg", R"(contract CoinReg{function count()constant returns(uint256 r){}function info(uint256 i)constant returns(address addr,bytes3 name,uint256 denom){}function register(bytes3 name,uint256 denom){}function unregister(){}})"},
|
|
||||||
{"configUser", R"(contract configUser{function configAddr()constant returns(address a){ return 0xc6d9d2cd449a754c494264e1809c50e34d64562b;}})"},
|
|
||||||
{"Config", R"(contract Config{function lookup(uint256 service)constant returns(address a){}function kill(){}function unregister(uint256 id){}function register(uint256 id,address service){}})"},
|
|
||||||
{"mortal", R"(import "owned";contract mortal is owned {function kill() { if (msg.sender == owner) suicide(owner); }})"},
|
|
||||||
{"named", R"(import "Config";import "NameReg";import "configUser";contract named is configUser {function named(bytes32 name) {NameReg(Config(configAddr()).lookup(1)).register(name);}})"},
|
|
||||||
{"NameReg", R"(contract NameReg{function register(bytes32 name){}function addressOf(bytes32 name)constant returns(address addr){}function unregister(){}function nameOf(address addr)constant returns(bytes32 name){}})"},
|
|
||||||
{"owned", R"(contract owned{function owned(){owner = msg.sender;}modifier onlyowner(){if(msg.sender==owner)_}address owner;})"},
|
|
||||||
{"service", R"(import "Config";import "configUser";contract service is configUser{function service(uint _n){Config(configAddr()).register(_n, this);}})"},
|
|
||||||
{"std", R"(import "owned";import "mortal";import "Config";import "configUser";import "NameReg";import "named";)"}
|
|
||||||
};
|
|
||||||
|
|
||||||
CompilerStack::CompilerStack(bool _addStandardSources, ReadFileCallback const& _readFile):
|
|
||||||
m_readFile(_readFile), m_parseSuccessful(false)
|
|
||||||
{
|
|
||||||
if (_addStandardSources)
|
|
||||||
addSources(StandardSources, true); // add them as libraries
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompilerStack::setRemappings(vector<string> const& _remappings)
|
void CompilerStack::setRemappings(vector<string> const& _remappings)
|
||||||
{
|
{
|
||||||
@ -81,7 +63,7 @@ void CompilerStack::setRemappings(vector<string> const& _remappings)
|
|||||||
swap(m_remappings, remappings);
|
swap(m_remappings, remappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerStack::reset(bool _keepSources, bool _addStandardSources)
|
void CompilerStack::reset(bool _keepSources)
|
||||||
{
|
{
|
||||||
m_parseSuccessful = false;
|
m_parseSuccessful = false;
|
||||||
if (_keepSources)
|
if (_keepSources)
|
||||||
@ -90,8 +72,6 @@ void CompilerStack::reset(bool _keepSources, bool _addStandardSources)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_sources.clear();
|
m_sources.clear();
|
||||||
if (_addStandardSources)
|
|
||||||
addSources(StandardSources, true);
|
|
||||||
}
|
}
|
||||||
m_globalContext.reset();
|
m_globalContext.reset();
|
||||||
m_sourceOrder.clear();
|
m_sourceOrder.clear();
|
||||||
@ -616,10 +596,9 @@ CompilerStack::Contract const& CompilerStack::contract(string const& _contractNa
|
|||||||
if (_contractName.empty())
|
if (_contractName.empty())
|
||||||
// try to find some user-supplied contract
|
// try to find some user-supplied contract
|
||||||
for (auto const& it: m_sources)
|
for (auto const& it: m_sources)
|
||||||
if (!StandardSources.count(it.first))
|
for (ASTPointer<ASTNode> const& node: it.second.ast->nodes())
|
||||||
for (ASTPointer<ASTNode> const& node: it.second.ast->nodes())
|
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
|
||||||
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
|
contractName = contract->name();
|
||||||
contractName = contract->name();
|
|
||||||
auto it = m_contracts.find(contractName);
|
auto it = m_contracts.find(contractName);
|
||||||
if (it == m_contracts.end())
|
if (it == m_contracts.end())
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Contract " + _contractName + " not found."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Contract " + _contractName + " not found."));
|
||||||
|
@ -85,14 +85,13 @@ public:
|
|||||||
|
|
||||||
/// Creates a new compiler stack.
|
/// Creates a new compiler stack.
|
||||||
/// @param _readFile callback to used to read files for import statements. Should return
|
/// @param _readFile callback to used to read files for import statements. Should return
|
||||||
/// @param _addStandardSources Adds standard sources if @a _addStandardSources.
|
explicit CompilerStack(ReadFileCallback const& _readFile = ReadFileCallback());
|
||||||
explicit CompilerStack(bool _addStandardSources = true, ReadFileCallback const& _readFile = ReadFileCallback());
|
|
||||||
|
|
||||||
/// Sets path remappings in the format "context:prefix=target"
|
/// Sets path remappings in the format "context:prefix=target"
|
||||||
void setRemappings(std::vector<std::string> const& _remappings);
|
void setRemappings(std::vector<std::string> const& _remappings);
|
||||||
|
|
||||||
/// Resets the compiler to a state where the sources are not parsed or even removed.
|
/// Resets the compiler to a state where the sources are not parsed or even removed.
|
||||||
void reset(bool _keepSources = false, bool _addStandardSources = true);
|
void reset(bool _keepSources = false);
|
||||||
|
|
||||||
/// Adds a source object (e.g. file) to the parser. After this, parse has to be called again.
|
/// Adds a source object (e.g. file) to the parser. After this, parse has to be called again.
|
||||||
/// @returns true if a source object by the name already existed and was replaced.
|
/// @returns true if a source object by the name already existed and was replaced.
|
||||||
|
@ -560,7 +560,7 @@ bool CommandLineInterface::processInput()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
m_compiler.reset(new CompilerStack(m_args.count(g_argAddStandard) > 0, fileReader));
|
m_compiler.reset(new CompilerStack(fileReader));
|
||||||
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); };
|
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); };
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -159,7 +159,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
CompilerStack compiler(true, readCallback);
|
CompilerStack compiler(readCallback);
|
||||||
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return compiler.scanner(_sourceName); };
|
auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return compiler.scanner(_sourceName); };
|
||||||
bool success = false;
|
bool success = false;
|
||||||
try
|
try
|
||||||
|
@ -231,7 +231,7 @@ protected:
|
|||||||
if (!s_compiledRegistrar)
|
if (!s_compiledRegistrar)
|
||||||
{
|
{
|
||||||
m_optimize = true;
|
m_optimize = true;
|
||||||
m_compiler.reset(false, m_addStandardSources);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", registrarCode);
|
m_compiler.addSource("", registrarCode);
|
||||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
||||||
s_compiledRegistrar.reset(new bytes(m_compiler.object("GlobalRegistrar").bytecode));
|
s_compiledRegistrar.reset(new bytes(m_compiler.object("GlobalRegistrar").bytecode));
|
||||||
|
@ -132,7 +132,7 @@ protected:
|
|||||||
if (!s_compiledRegistrar)
|
if (!s_compiledRegistrar)
|
||||||
{
|
{
|
||||||
m_optimize = true;
|
m_optimize = true;
|
||||||
m_compiler.reset(false, m_addStandardSources);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", registrarCode);
|
m_compiler.addSource("", registrarCode);
|
||||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
||||||
s_compiledRegistrar.reset(new bytes(m_compiler.object("FixedFeeRegistrar").bytecode));
|
s_compiledRegistrar.reset(new bytes(m_compiler.object("FixedFeeRegistrar").bytecode));
|
||||||
|
@ -446,7 +446,7 @@ protected:
|
|||||||
if (!s_compiledWallet)
|
if (!s_compiledWallet)
|
||||||
{
|
{
|
||||||
m_optimize = true;
|
m_optimize = true;
|
||||||
m_compiler.reset(false, m_addStandardSources);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", walletCode);
|
m_compiler.addSource("", walletCode);
|
||||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
||||||
s_compiledWallet.reset(new bytes(m_compiler.object("Wallet").bytecode));
|
s_compiledWallet.reset(new bytes(m_compiler.object("Wallet").bytecode));
|
||||||
|
@ -35,7 +35,7 @@ namespace test
|
|||||||
class JSONInterfaceChecker
|
class JSONInterfaceChecker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JSONInterfaceChecker(): m_compilerStack(false) {}
|
JSONInterfaceChecker(): m_compilerStack() {}
|
||||||
|
|
||||||
void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString)
|
void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString)
|
||||||
{
|
{
|
||||||
|
@ -2458,21 +2458,6 @@ 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 { }
|
|
||||||
)";
|
|
||||||
m_addStandardSources = true;
|
|
||||||
u256 amount(130 * ether);
|
|
||||||
compileAndRun(sourceCode, amount, "Icarus");
|
|
||||||
u256 balanceBefore = balanceAt(m_sender);
|
|
||||||
BOOST_CHECK(callContractFunction("kill()") == bytes());
|
|
||||||
BOOST_CHECK(!addressHasCode(m_contractAddress));
|
|
||||||
BOOST_CHECK(balanceAt(m_sender) > balanceBefore);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack)
|
BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
@ -67,7 +67,7 @@ public:
|
|||||||
std::map<std::string, Address> const& _libraryAddresses = std::map<std::string, Address>()
|
std::map<std::string, Address> const& _libraryAddresses = std::map<std::string, Address>()
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
m_compiler.reset(false, m_addStandardSources);
|
m_compiler.reset(false);
|
||||||
m_compiler.addSource("", _sourceCode);
|
m_compiler.addSource("", _sourceCode);
|
||||||
if (!m_compiler.compile(m_optimize, m_optimizeRuns))
|
if (!m_compiler.compile(m_optimize, m_optimizeRuns))
|
||||||
{
|
{
|
||||||
@ -290,7 +290,6 @@ protected:
|
|||||||
|
|
||||||
size_t m_optimizeRuns = 200;
|
size_t m_optimizeRuns = 200;
|
||||||
bool m_optimize = false;
|
bool m_optimize = false;
|
||||||
bool m_addStandardSources = false;
|
|
||||||
dev::solidity::CompilerStack m_compiler;
|
dev::solidity::CompilerStack m_compiler;
|
||||||
Address m_sender;
|
Address m_sender;
|
||||||
Address m_contractAddress;
|
Address m_contractAddress;
|
||||||
|
@ -37,7 +37,7 @@ namespace test
|
|||||||
class DocumentationChecker
|
class DocumentationChecker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DocumentationChecker(): m_compilerStack(false) {}
|
DocumentationChecker(): m_compilerStack() {}
|
||||||
|
|
||||||
void checkNatspec(
|
void checkNatspec(
|
||||||
std::string const& _code,
|
std::string const& _code,
|
||||||
|
Loading…
Reference in New Issue
Block a user