mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'ethereum/develop' into sol_expressionCompiler
Conflicts: libsolidity/Types.cpp
This commit is contained in:
commit
d2a474f7fa
@ -437,12 +437,12 @@ MemTrie::~MemTrie()
|
|||||||
|
|
||||||
h256 MemTrie::hash256() const
|
h256 MemTrie::hash256() const
|
||||||
{
|
{
|
||||||
return m_root ? m_root->hash256() : h256();
|
return m_root ? m_root->hash256() : sha3(dev::rlp(bytesConstRef()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes MemTrie::rlp() const
|
bytes MemTrie::rlp() const
|
||||||
{
|
{
|
||||||
return m_root ? m_root->rlp() : bytes();
|
return m_root ? m_root->rlp() : dev::rlp(bytesConstRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemTrie::debugPrint()
|
void MemTrie::debugPrint()
|
||||||
|
@ -162,7 +162,7 @@ h256 hash256(StringMap const& _s)
|
|||||||
{
|
{
|
||||||
// build patricia tree.
|
// build patricia tree.
|
||||||
if (_s.empty())
|
if (_s.empty())
|
||||||
return h256();
|
return sha3(rlp(""));
|
||||||
HexMap hexMap;
|
HexMap hexMap;
|
||||||
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
|
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
|
||||||
hexMap[asNibbles(i->first)] = i->second;
|
hexMap[asNibbles(i->first)] = i->second;
|
||||||
@ -175,7 +175,7 @@ bytes rlp256(StringMap const& _s)
|
|||||||
{
|
{
|
||||||
// build patricia tree.
|
// build patricia tree.
|
||||||
if (_s.empty())
|
if (_s.empty())
|
||||||
return bytes();
|
return rlp("");
|
||||||
HexMap hexMap;
|
HexMap hexMap;
|
||||||
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
|
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
|
||||||
hexMap[asNibbles(i->first)] = i->second;
|
hexMap[asNibbles(i->first)] = i->second;
|
||||||
@ -188,7 +188,7 @@ h256 hash256(u256Map const& _s)
|
|||||||
{
|
{
|
||||||
// build patricia tree.
|
// build patricia tree.
|
||||||
if (_s.empty())
|
if (_s.empty())
|
||||||
return h256();
|
return sha3(rlp(""));
|
||||||
HexMap hexMap;
|
HexMap hexMap;
|
||||||
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
|
for (auto i = _s.rbegin(); i != _s.rend(); ++i)
|
||||||
hexMap[asNibbles(toBigEndianString(i->first))] = asString(rlp(i->second));
|
hexMap[asNibbles(toBigEndianString(i->first))] = asString(rlp(i->second));
|
||||||
|
@ -341,6 +341,7 @@ BOOST_AUTO_TEST_CASE(eth_keypairs)
|
|||||||
{
|
{
|
||||||
eth::Transaction t;
|
eth::Transaction t;
|
||||||
t.nonce = 0;
|
t.nonce = 0;
|
||||||
|
t.type = eth::Transaction::MessageCall;
|
||||||
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
|
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
|
||||||
t.value = 1000;
|
t.value = 1000;
|
||||||
auto rlp = t.rlp(false);
|
auto rlp = t.rlp(false);
|
||||||
@ -369,6 +370,7 @@ int cryptoTest()
|
|||||||
{
|
{
|
||||||
eth::Transaction t;
|
eth::Transaction t;
|
||||||
t.nonce = 0;
|
t.nonce = 0;
|
||||||
|
t.type = eth::Transaction::MessageCall;
|
||||||
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
|
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
|
||||||
t.value = 1000;
|
t.value = 1000;
|
||||||
auto rlp = t.rlp(false);
|
auto rlp = t.rlp(false);
|
||||||
@ -397,6 +399,7 @@ int cryptoTest()
|
|||||||
Transaction t;
|
Transaction t;
|
||||||
t.nonce = 0;
|
t.nonce = 0;
|
||||||
t.value = 1; // 1 wei.
|
t.value = 1; // 1 wei.
|
||||||
|
t.type = eth::Transaction::MessageCall;
|
||||||
t.receiveAddress = toAddress(sha3("123"));
|
t.receiveAddress = toAddress(sha3("123"));
|
||||||
|
|
||||||
bytes sig64 = toBigEndian(t.vrs.r) + toBigEndian(t.vrs.s);
|
bytes sig64 = toBigEndian(t.vrs.r) + toBigEndian(t.vrs.s);
|
||||||
|
13
genesis.cpp
13
genesis.cpp
@ -35,9 +35,20 @@ namespace js = json_spirit;
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(genesis_tests)
|
BOOST_AUTO_TEST_CASE(genesis_tests)
|
||||||
{
|
{
|
||||||
|
const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
|
||||||
|
string testPath;
|
||||||
|
|
||||||
|
if (ptestPath == NULL)
|
||||||
|
{
|
||||||
|
cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
|
||||||
|
testPath = "../../../tests";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
testPath = ptestPath;
|
||||||
|
|
||||||
cnote << "Testing Genesis block...";
|
cnote << "Testing Genesis block...";
|
||||||
js::mValue v;
|
js::mValue v;
|
||||||
string s = asString(contents("../../../tests/genesishashestest.json"));
|
string s = asString(contents(testPath + "/genesishashestest.json"));
|
||||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'genesishashestest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'genesishashestest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||||
js::read_string(s, v);
|
js::read_string(s, v);
|
||||||
|
|
||||||
|
@ -33,9 +33,20 @@ namespace js = json_spirit;
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(hexPrefix_test)
|
BOOST_AUTO_TEST_CASE(hexPrefix_test)
|
||||||
{
|
{
|
||||||
|
const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
|
||||||
|
string testPath;
|
||||||
|
|
||||||
|
if (ptestPath == NULL)
|
||||||
|
{
|
||||||
|
cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
|
||||||
|
testPath = "../../../tests";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
testPath = ptestPath;
|
||||||
|
|
||||||
cnote << "Testing Hex-Prefix-Encode...";
|
cnote << "Testing Hex-Prefix-Encode...";
|
||||||
js::mValue v;
|
js::mValue v;
|
||||||
string s = asString(contents("../../../tests/hexencodetest.json"));
|
string s = asString(contents(testPath + "/hexencodetest.json"));
|
||||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content from 'hexencodetest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content from 'hexencodetest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||||
js::read_string(s, v);
|
js::read_string(s, v);
|
||||||
for (auto& i: v.get_obj())
|
for (auto& i: v.get_obj())
|
||||||
|
2
main.cpp
2
main.cpp
@ -44,7 +44,7 @@ using namespace dev::eth;
|
|||||||
BOOST_AUTO_TEST_CASE(basic_tests)
|
BOOST_AUTO_TEST_CASE(basic_tests)
|
||||||
{
|
{
|
||||||
/* RLPStream s;
|
/* RLPStream s;
|
||||||
BlockInfo::genesis().fillStream(s, false);
|
BlockInfo::genesis().streamRLP(s, false);
|
||||||
std::cout << RLP(s.out()) << std::endl;
|
std::cout << RLP(s.out()) << std::endl;
|
||||||
std::cout << toHex(s.out()) << std::endl;
|
std::cout << toHex(s.out()) << std::endl;
|
||||||
std::cout << sha3(s.out()) << std::endl;*/
|
std::cout << sha3(s.out()) << std::endl;*/
|
||||||
|
13
rlp.cpp
13
rlp.cpp
@ -61,7 +61,18 @@ namespace dev
|
|||||||
|
|
||||||
static void getRLPTestCases(js::mValue& v)
|
static void getRLPTestCases(js::mValue& v)
|
||||||
{
|
{
|
||||||
string s = asString(contents("../../../tests/rlptest.json"));
|
const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
|
||||||
|
string testPath;
|
||||||
|
|
||||||
|
if (ptestPath == NULL)
|
||||||
|
{
|
||||||
|
cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
|
||||||
|
testPath = "../../../tests";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
testPath = ptestPath;
|
||||||
|
|
||||||
|
string s = asString(contents(testPath + "/rlptest.json"));
|
||||||
BOOST_REQUIRE_MESSAGE( s.length() > 0,
|
BOOST_REQUIRE_MESSAGE( s.length() > 0,
|
||||||
"Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
"Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||||
js::read_string(s, v);
|
js::read_string(s, v);
|
||||||
|
@ -68,6 +68,7 @@ int stateTest()
|
|||||||
Transaction t;
|
Transaction t;
|
||||||
t.nonce = s.transactionsFrom(myMiner.address());
|
t.nonce = s.transactionsFrom(myMiner.address());
|
||||||
t.value = 1000; // 1e3 wei.
|
t.value = 1000; // 1e3 wei.
|
||||||
|
t.type = eth::Transaction::MessageCall;
|
||||||
t.receiveAddress = me.address();
|
t.receiveAddress = me.address();
|
||||||
t.sign(myMiner.secret());
|
t.sign(myMiner.secret());
|
||||||
assert(t.sender() == myMiner.address());
|
assert(t.sender() == myMiner.address());
|
||||||
|
13
trie.cpp
13
trie.cpp
@ -49,9 +49,20 @@ static unsigned fac(unsigned _i)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(trie_tests)
|
BOOST_AUTO_TEST_CASE(trie_tests)
|
||||||
{
|
{
|
||||||
|
const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
|
||||||
|
string testPath;
|
||||||
|
|
||||||
|
if (ptestPath == NULL)
|
||||||
|
{
|
||||||
|
cnote << " could not find environment variable ETHEREUM_TEST_PATH \n";
|
||||||
|
testPath = "../../../tests";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
testPath = ptestPath;
|
||||||
|
|
||||||
cnote << "Testing Trie...";
|
cnote << "Testing Trie...";
|
||||||
js::mValue v;
|
js::mValue v;
|
||||||
string s = asString(contents("../../../tests/trietest.json"));
|
string s = asString(contents(testPath + "/trietest.json"));
|
||||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||||
js::read_string(s, v);
|
js::read_string(s, v);
|
||||||
for (auto& i: v.get_obj())
|
for (auto& i: v.get_obj())
|
||||||
|
67
vm.cpp
67
vm.cpp
@ -20,9 +20,8 @@
|
|||||||
* vm test functions.
|
* vm test functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "vm.h"
|
|
||||||
#include <libdevcore/CommonIO.h>
|
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
#include "vm.h"
|
||||||
|
|
||||||
//#define FILL_TESTS
|
//#define FILL_TESTS
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun
|
|||||||
|
|
||||||
m_s.noteSending(myAddress);
|
m_s.noteSending(myAddress);
|
||||||
m_ms.internal.resize(m_ms.internal.size() + 1);
|
m_ms.internal.resize(m_ms.internal.size() + 1);
|
||||||
auto ret = m_s.create(myAddress, _endowment, gasPrice, _gas, _init, origin, &suicides, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1);
|
auto ret = m_s.create(myAddress, _endowment, gasPrice, _gas, _init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1);
|
||||||
if (!m_ms.internal.back().from)
|
if (!m_ms.internal.back().from)
|
||||||
m_ms.internal.pop_back();
|
m_ms.internal.pop_back();
|
||||||
|
|
||||||
@ -56,14 +55,13 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun
|
|||||||
get<3>(addresses[ret]) = m_s.code(ret);
|
get<3>(addresses[ret]) = m_s.code(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
t.receiveAddress = ret;
|
t.type = eth::Transaction::ContractCreation;
|
||||||
callcreates.push_back(t);
|
callcreates.push_back(t);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, OnOpFunc const&, Address _myAddressOverride, Address _codeAddressOverride)
|
bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, OnOpFunc const&, Address _myAddressOverride, Address _codeAddressOverride)
|
||||||
{
|
{
|
||||||
|
|
||||||
u256 contractgas = 0xffff;
|
u256 contractgas = 0xffff;
|
||||||
|
|
||||||
Transaction t;
|
Transaction t;
|
||||||
@ -71,6 +69,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
|
|||||||
t.gasPrice = gasPrice;
|
t.gasPrice = gasPrice;
|
||||||
t.gas = *_gas;
|
t.gas = *_gas;
|
||||||
t.data = _data.toVector();
|
t.data = _data.toVector();
|
||||||
|
t.type = eth::Transaction::MessageCall;
|
||||||
t.receiveAddress = _receiveAddress;
|
t.receiveAddress = _receiveAddress;
|
||||||
callcreates.push_back(t);
|
callcreates.push_back(t);
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
|
|||||||
if (!m_s.addresses().count(myAddress))
|
if (!m_s.addresses().count(myAddress))
|
||||||
{
|
{
|
||||||
m_ms.internal.resize(m_ms.internal.size() + 1);
|
m_ms.internal.resize(m_ms.internal.size() + 1);
|
||||||
auto na = m_s.createNewAddress(myAddress, myAddress, balance(myAddress), gasPrice, &contractgas, init, origin, &suicides, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1);
|
auto na = m_s.createNewAddress(myAddress, myAddress, balance(myAddress), gasPrice, &contractgas, init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, {}, 1);
|
||||||
if (!m_ms.internal.back().from)
|
if (!m_ms.internal.back().from)
|
||||||
m_ms.internal.pop_back();
|
m_ms.internal.pop_back();
|
||||||
if (na != myAddress)
|
if (na != myAddress)
|
||||||
@ -116,7 +115,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
|
|||||||
{
|
{
|
||||||
m_s.noteSending(myAddress);
|
m_s.noteSending(myAddress);
|
||||||
m_ms.internal.resize(m_ms.internal.size() + 1);
|
m_ms.internal.resize(m_ms.internal.size() + 1);
|
||||||
auto na = m_s.createNewAddress(_codeAddressOverride ? _codeAddressOverride : _receiveAddress, myAddress, balance(_codeAddressOverride ? _codeAddressOverride : _receiveAddress), gasPrice, &contractgas, init, origin, &suicides, &m_ms ? &(m_ms.internal.back()) : nullptr, OnOpFunc(), 1);
|
auto na = m_s.createNewAddress(_codeAddressOverride ? _codeAddressOverride : _receiveAddress, myAddress, balance(_codeAddressOverride ? _codeAddressOverride : _receiveAddress), gasPrice, &contractgas, init, origin, &sub, &m_ms ? &(m_ms.internal.back()) : nullptr, OnOpFunc(), 1);
|
||||||
if (!m_ms.internal.back().from)
|
if (!m_ms.internal.back().from)
|
||||||
m_ms.internal.pop_back();
|
m_ms.internal.pop_back();
|
||||||
|
|
||||||
@ -131,7 +130,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
|
|||||||
|
|
||||||
m_ms.internal.resize(m_ms.internal.size() + 1);
|
m_ms.internal.resize(m_ms.internal.size() + 1);
|
||||||
|
|
||||||
auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &suicides, &(m_ms.internal.back()), OnOpFunc(), 1);
|
auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), simpleTrace<ExtVM>(), 1);
|
||||||
|
|
||||||
if (!m_ms.internal.back().from)
|
if (!m_ms.internal.back().from)
|
||||||
m_ms.internal.pop_back();
|
m_ms.internal.pop_back();
|
||||||
@ -146,12 +145,15 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
|
|||||||
if (!ret)
|
if (!ret)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// TODO: @CJentzsch refund SSTORE stuff.
|
||||||
|
// TODO: @CJentzsch test logs.
|
||||||
|
|
||||||
// do suicides
|
// do suicides
|
||||||
for (auto const& f: suicides)
|
for (auto const& f: sub.suicides)
|
||||||
addresses.erase(f);
|
addresses.erase(f);
|
||||||
|
|
||||||
// get storage
|
// get storage
|
||||||
if ((get<0>(addresses[myAddress]) >= _value) && (suicides.find(_receiveAddress) == suicides.end()))
|
if ((get<0>(addresses[myAddress]) >= _value) && (sub.suicides.find(_receiveAddress) == sub.suicides.end()))
|
||||||
{
|
{
|
||||||
for (auto const& j: m_s.storage(_receiveAddress))
|
for (auto const& j: m_s.storage(_receiveAddress))
|
||||||
{
|
{
|
||||||
@ -384,7 +386,7 @@ mArray FakeExtVM::exportCallCreates()
|
|||||||
for (Transaction const& tx: callcreates)
|
for (Transaction const& tx: callcreates)
|
||||||
{
|
{
|
||||||
mObject o;
|
mObject o;
|
||||||
o["destination"] = toString(tx.receiveAddress);
|
o["destination"] = tx.type == Transaction::ContractCreation ? "" : toString(tx.receiveAddress);
|
||||||
push(o, "gasLimit", tx.gas);
|
push(o, "gasLimit", tx.gas);
|
||||||
push(o, "value", tx.value);
|
push(o, "value", tx.value);
|
||||||
o["data"] = "0x" + toHex(tx.data);
|
o["data"] = "0x" + toHex(tx.data);
|
||||||
@ -403,6 +405,7 @@ void FakeExtVM::importCallCreates(mArray& _callcreates)
|
|||||||
BOOST_REQUIRE(tx.count("destination") > 0);
|
BOOST_REQUIRE(tx.count("destination") > 0);
|
||||||
BOOST_REQUIRE(tx.count("gasLimit") > 0);
|
BOOST_REQUIRE(tx.count("gasLimit") > 0);
|
||||||
Transaction t;
|
Transaction t;
|
||||||
|
t.type = tx["destination"].get_str().empty() ? Transaction::ContractCreation : Transaction::MessageCall;
|
||||||
t.receiveAddress = Address(tx["destination"].get_str());
|
t.receiveAddress = Address(tx["destination"].get_str());
|
||||||
t.value = toInt(tx["value"]);
|
t.value = toInt(tx["value"]);
|
||||||
t.gas = toInt(tx["gasLimit"]);
|
t.gas = toInt(tx["gasLimit"]);
|
||||||
@ -418,8 +421,11 @@ void FakeExtVM::importCallCreates(mArray& _callcreates)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, std::set<Address>* o_suicides, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level)
|
// THIS IS BROKEN AND NEEDS TO BE REMOVED.
|
||||||
|
h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, SubState* o_sub, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level)
|
||||||
{
|
{
|
||||||
|
(void)o_sub;
|
||||||
|
|
||||||
if (!_origin)
|
if (!_origin)
|
||||||
_origin = _sender;
|
_origin = _sender;
|
||||||
|
|
||||||
@ -445,9 +451,7 @@ h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _end
|
|||||||
out = vm.go(evm, _onOp);
|
out = vm.go(evm, _onOp);
|
||||||
if (o_ms)
|
if (o_ms)
|
||||||
o_ms->output = out.toBytes();
|
o_ms->output = out.toBytes();
|
||||||
if (o_suicides)
|
// TODO: deal with evm.sub
|
||||||
for (auto i: evm.suicides)
|
|
||||||
o_suicides->insert(i);
|
|
||||||
}
|
}
|
||||||
catch (OutOfGas const& /*_e*/)
|
catch (OutOfGas const& /*_e*/)
|
||||||
{
|
{
|
||||||
@ -482,8 +486,6 @@ h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _end
|
|||||||
return _newAddress;
|
return _newAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace dev { namespace test {
|
namespace dev { namespace test {
|
||||||
|
|
||||||
void doTests(json_spirit::mValue& v, bool _fillin)
|
void doTests(json_spirit::mValue& v, bool _fillin)
|
||||||
@ -515,7 +517,7 @@ void doTests(json_spirit::mValue& v, bool _fillin)
|
|||||||
VM vm(fev.gas);
|
VM vm(fev.gas);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
output = vm.go(fev).toVector();
|
output = vm.go(fev, fev.simpleTrace<FakeExtVM>()).toVector();
|
||||||
}
|
}
|
||||||
catch (Exception const& _e)
|
catch (Exception const& _e)
|
||||||
{
|
{
|
||||||
@ -751,3 +753,32 @@ BOOST_AUTO_TEST_CASE(vmSystemOperationsTest)
|
|||||||
{
|
{
|
||||||
dev::test::executeTests("vmSystemOperationsTest");
|
dev::test::executeTests("vmSystemOperationsTest");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(userDefinedFile)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (boost::unit_test::framework::master_test_suite().argc == 2)
|
||||||
|
{
|
||||||
|
string filename = boost::unit_test::framework::master_test_suite().argv[1];
|
||||||
|
int currentVerbosity = g_logVerbosity;
|
||||||
|
g_logVerbosity = 12;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cnote << "Testing VM..." << "user defined test";
|
||||||
|
json_spirit::mValue v;
|
||||||
|
string s = asString(contents(filename));
|
||||||
|
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
|
||||||
|
json_spirit::read_string(s, v);
|
||||||
|
dev::test::doTests(v, false);
|
||||||
|
}
|
||||||
|
catch (Exception const& _e)
|
||||||
|
{
|
||||||
|
BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e));
|
||||||
|
}
|
||||||
|
catch (std::exception const& _e)
|
||||||
|
{
|
||||||
|
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
|
||||||
|
}
|
||||||
|
g_logVerbosity = currentVerbosity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
36
vm.h
36
vm.h
@ -28,6 +28,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include "JsonSpiritHeaders.h"
|
#include "JsonSpiritHeaders.h"
|
||||||
#include <libdevcore/Log.h>
|
#include <libdevcore/Log.h>
|
||||||
|
#include <libdevcore/CommonIO.h>
|
||||||
#include <libevmface/Instruction.h>
|
#include <libevmface/Instruction.h>
|
||||||
#include <libevm/ExtVMFace.h>
|
#include <libevm/ExtVMFace.h>
|
||||||
#include <libevm/VM.h>
|
#include <libevm/VM.h>
|
||||||
@ -44,7 +45,7 @@ class FakeState: public eth::State
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Execute a contract-creation transaction.
|
/// Execute a contract-creation transaction.
|
||||||
h160 createNewAddress(Address _newAddress, Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = {}, std::set<Address>* o_suicides = nullptr, eth::Manifest* o_ms = nullptr, eth::OnOpFunc const& _onOp = {}, unsigned _level = 0);
|
h160 createNewAddress(Address _newAddress, Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = {}, eth::SubState* o_sub = nullptr, eth::Manifest* o_ms = nullptr, eth::OnOpFunc const& _onOp = {}, unsigned _level = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FakeExtVM: public eth::ExtVMFace
|
class FakeExtVM: public eth::ExtVMFace
|
||||||
@ -80,6 +81,11 @@ public:
|
|||||||
json_spirit::mArray exportCallCreates();
|
json_spirit::mArray exportCallCreates();
|
||||||
void importCallCreates(json_spirit::mArray& _callcreates);
|
void importCallCreates(json_spirit::mArray& _callcreates);
|
||||||
|
|
||||||
|
template<typename ExtVMType>
|
||||||
|
eth::OnOpFunc simpleTrace();
|
||||||
|
|
||||||
|
FakeState state() const { return m_s; }
|
||||||
|
|
||||||
std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses;
|
std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses;
|
||||||
eth::Transactions callcreates;
|
eth::Transactions callcreates;
|
||||||
bytes thisTxData;
|
bytes thisTxData;
|
||||||
@ -91,4 +97,32 @@ private:
|
|||||||
eth::Manifest m_ms;
|
eth::Manifest m_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename ExtVMType>
|
||||||
|
eth::OnOpFunc FakeExtVM::simpleTrace()
|
||||||
|
{
|
||||||
|
return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt)
|
||||||
|
{
|
||||||
|
ExtVMType const& ext = *(ExtVMType const*)voidExt;
|
||||||
|
eth::VM& vm = *(eth::VM*)voidVM;
|
||||||
|
|
||||||
|
std::ostringstream o;
|
||||||
|
o << std::endl << " STACK" << std::endl;
|
||||||
|
for (auto i: vm.stack())
|
||||||
|
o << (h256)i << std::endl;
|
||||||
|
o << " MEMORY" << std::endl << memDump(vm.memory());
|
||||||
|
o << " STORAGE" << std::endl;
|
||||||
|
for (auto const& i: ext.state().storage(ext.myAddress))
|
||||||
|
o << std::showbase << std::hex << i.first << ": " << i.second << std::endl;
|
||||||
|
dev::LogOutputStream<eth::VMTraceChannel, false>(true) << o.str();
|
||||||
|
dev::LogOutputStream<eth::VMTraceChannel, false>(false) << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]";
|
||||||
|
|
||||||
|
if (eth::VMTraceChannel::verbosity <= g_logVerbosity)
|
||||||
|
{
|
||||||
|
std::ofstream f;
|
||||||
|
f.open("./vmtrace.log", std::ofstream::app);
|
||||||
|
f << o.str();
|
||||||
|
f << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
} } // Namespace Close
|
} } // Namespace Close
|
||||||
|
Loading…
Reference in New Issue
Block a user