This commit is contained in:
chriseth 2016-06-13 17:10:58 +02:00
parent 603bad34f9
commit 966709b7d7
5 changed files with 42 additions and 12 deletions

View File

@ -85,6 +85,15 @@ RPCSession::TransactionReceipt RPCSession::eth_getTransactionReceipt(string cons
BOOST_REQUIRE(!result.isNull()); BOOST_REQUIRE(!result.isNull());
receipt.gasUsed = result["gasUsed"].asString(); receipt.gasUsed = result["gasUsed"].asString();
receipt.contractAddress = result["contractAddress"].asString(); receipt.contractAddress = result["contractAddress"].asString();
for (auto const& log: result["logs"])
{
LogEntry entry;
entry.address = log["address"].asString();
entry.data = log["data"].asString();
for (auto const& topic: log["topics"])
entry.topics.push_back(topic.asString());
receipt.logEntries.push_back(entry);
}
return receipt; return receipt;
} }
@ -174,10 +183,9 @@ Json::Value RPCSession::rpcCall(string const& _methodName, vector<string> const&
request += "],\"id\":" + to_string(m_rpcSequence) + "}"; request += "],\"id\":" + to_string(m_rpcSequence) + "}";
++m_rpcSequence; ++m_rpcSequence;
//cout << "Request: " << request << endl;
string reply = m_ipcSocket.sendRequest(request); string reply = m_ipcSocket.sendRequest(request);
//cout << "Reply: " << reply << endl;
cout << "Request: " << request << endl;
cout << "Reply: " << reply << endl;
Json::Value result; Json::Value result;
Json::Reader().parse(reply, result, false); Json::Reader().parse(reply, result, false);

View File

@ -59,10 +59,17 @@ public:
std::string toJson() const; std::string toJson() const;
}; };
struct LogEntry {
std::string address;
std::vector<std::string> topics;
std::string data;
};
struct TransactionReceipt struct TransactionReceipt
{ {
std::string gasUsed; std::string gasUsed;
std::string contractAddress; std::string contractAddress;
std::vector<LogEntry> logEntries;
}; };
static RPCSession& instance(std::string const& _path); static RPCSession& instance(std::string const& _path);

View File

@ -1553,7 +1553,7 @@ BOOST_AUTO_TEST_CASE(log0)
"}\n"; "}\n";
compileAndRun(sourceCode); compileAndRun(sourceCode);
callContractFunction("a()"); callContractFunction("a()");
BOOST_CHECK_EQUAL(m_logs.size(), 1); BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 0); BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 0);
@ -1568,7 +1568,7 @@ BOOST_AUTO_TEST_CASE(log1)
"}\n"; "}\n";
compileAndRun(sourceCode); compileAndRun(sourceCode);
callContractFunction("a()"); callContractFunction("a()");
BOOST_CHECK_EQUAL(m_logs.size(), 1); BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 1);
@ -1584,7 +1584,7 @@ BOOST_AUTO_TEST_CASE(log2)
"}\n"; "}\n";
compileAndRun(sourceCode); compileAndRun(sourceCode);
callContractFunction("a()"); callContractFunction("a()");
BOOST_CHECK_EQUAL(m_logs.size(), 1); BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 2); BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 2);
@ -1601,7 +1601,7 @@ BOOST_AUTO_TEST_CASE(log3)
"}\n"; "}\n";
compileAndRun(sourceCode); compileAndRun(sourceCode);
callContractFunction("a()"); callContractFunction("a()");
BOOST_CHECK_EQUAL(m_logs.size(), 1); BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 3); BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 3);
@ -1618,7 +1618,7 @@ BOOST_AUTO_TEST_CASE(log4)
"}\n"; "}\n";
compileAndRun(sourceCode); compileAndRun(sourceCode);
callContractFunction("a()"); callContractFunction("a()");
BOOST_CHECK_EQUAL(m_logs.size(), 1); BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 4); BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 4);
@ -1634,7 +1634,7 @@ BOOST_AUTO_TEST_CASE(log_in_constructor)
" }\n" " }\n"
"}\n"; "}\n";
compileAndRun(sourceCode); compileAndRun(sourceCode);
BOOST_CHECK_EQUAL(m_logs.size(), 1); BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress); BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1))); BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(1)));
BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 1); BOOST_CHECK_EQUAL(m_logs[0].topics.size(), 1);

View File

@ -39,7 +39,6 @@ ExecutionFramework::ExecutionFramework():
if (g_logVerbosity != -1) if (g_logVerbosity != -1)
g_logVerbosity = 0; g_logVerbosity = 0;
cout << "New Framework" << endl;
m_rpc.test_rewindToBlock(0); m_rpc.test_rewindToBlock(0);
} }
@ -69,9 +68,18 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
BOOST_REQUIRE(m_contractAddress); BOOST_REQUIRE(m_contractAddress);
string code = m_rpc.eth_getCode(receipt.contractAddress, "latest"); string code = m_rpc.eth_getCode(receipt.contractAddress, "latest");
BOOST_REQUIRE(code.size() > 2); BOOST_REQUIRE(code.size() > 2);
m_output = asBytes(code); m_output = fromHex(code, WhenError::Throw);
} }
m_gasUsed = u256(receipt.gasUsed); m_gasUsed = u256(receipt.gasUsed);
m_logs.clear(); m_logs.clear();
for (auto const& log: receipt.logEntries)
{
LogEntry entry;
entry.address = Address(log.address);
for (auto const& topic: log.topics)
entry.topics.push_back(h256(topic));
entry.data = fromHex(log.data, WhenError::Throw);
m_logs.push_back(entry);
}
} }

View File

@ -253,6 +253,13 @@ protected:
RPCSession& m_rpc; RPCSession& m_rpc;
struct LogEntry
{
Address address;
std::vector<h256> topics;
bytes data;
};
std::unique_ptr<eth::SealEngineFace> m_sealEngine; std::unique_ptr<eth::SealEngineFace> m_sealEngine;
size_t m_optimizeRuns = 200; size_t m_optimizeRuns = 200;
bool m_optimize = false; bool m_optimize = false;
@ -265,7 +272,7 @@ protected:
u256 const m_gasPrice = 100 * eth::szabo; u256 const m_gasPrice = 100 * eth::szabo;
u256 const m_gas = 100000000; u256 const m_gas = 100000000;
bytes m_output; bytes m_output;
eth::LogEntries m_logs; std::vector<LogEntry> m_logs;
u256 m_gasUsed; u256 m_gasUsed;
}; };