@ -0,0 +1,103 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
/** @file NatspecHandler.cpp
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
#include "NatspecHandler.h" |
|||
#include <string> |
|||
#include <boost/filesystem.hpp> |
|||
|
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/CommonData.h> |
|||
#include <libdevcore/Exceptions.h> |
|||
#include <libdevcore/Log.h> |
|||
#include <libdevcrypto/SHA3.h> |
|||
#include <libethereum/Defaults.h> |
|||
|
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
using namespace std; |
|||
|
|||
NatspecHandler::NatspecHandler() |
|||
{ |
|||
string path = Defaults::dbPath(); |
|||
boost::filesystem::create_directories(path); |
|||
ldb::Options o; |
|||
o.create_if_missing = true; |
|||
ldb::DB::Open(o, path + "/natspec", &m_db); |
|||
} |
|||
|
|||
NatspecHandler::~NatspecHandler() |
|||
{ |
|||
delete m_db; |
|||
} |
|||
|
|||
void NatspecHandler::add(dev::h256 const& _contractHash, string const& _doc) |
|||
{ |
|||
bytes k = _contractHash.asBytes(); |
|||
string v = _doc; |
|||
m_db->Put(m_writeOptions, ldb::Slice((char const*)k.data(), k.size()), ldb::Slice((char const*)v.data(), v.size())); |
|||
} |
|||
|
|||
string NatspecHandler::retrieve(dev::h256 const& _contractHash) const |
|||
{ |
|||
bytes k = _contractHash.asBytes(); |
|||
string ret; |
|||
m_db->Get(m_readOptions, ldb::Slice((char const*)k.data(), k.size()), &ret); |
|||
return ret; |
|||
} |
|||
|
|||
string NatspecHandler::getUserNotice(string const& json, dev::bytes const& _transactionData) |
|||
{ |
|||
Json::Value natspec; |
|||
Json::Value userNotice; |
|||
string retStr; |
|||
m_reader.parse(json, natspec); |
|||
bytes transactionFunctionPart(_transactionData.begin(), _transactionData.begin() + 4); |
|||
FixedHash<4> transactionFunctionHash(transactionFunctionPart); |
|||
|
|||
Json::Value methods = natspec["methods"]; |
|||
for (Json::ValueIterator it = methods.begin(); it != methods.end(); ++it) |
|||
{ |
|||
Json::Value keyValue = it.key(); |
|||
if (!keyValue.isString()) |
|||
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Illegal Natspec JSON detected")); |
|||
|
|||
string functionSig = keyValue.asString(); |
|||
FixedHash<4> functionHash(dev::sha3(functionSig)); |
|||
|
|||
if (functionHash == transactionFunctionHash) |
|||
{ |
|||
Json::Value val = (*it)["notice"]; |
|||
if (!val.isString()) |
|||
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Illegal Natspec JSON detected")); |
|||
return val.asString(); |
|||
} |
|||
} |
|||
|
|||
// not found
|
|||
return string(); |
|||
} |
|||
|
|||
string NatspecHandler::getUserNotice(dev::h256 const& _contractHash, dev::bytes const& _transactionData) |
|||
{ |
|||
return getUserNotice(retrieve(_contractHash), _transactionData); |
|||
} |
|||
|
|||
|
@ -0,0 +1,58 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
/** @file NatspecHandler.h
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#pragma warning(push) |
|||
#pragma warning(disable: 4100 4267) |
|||
#include <leveldb/db.h> |
|||
#pragma warning(pop) |
|||
#include <jsoncpp/json/json.h> |
|||
#include <libdevcore/FixedHash.h> |
|||
|
|||
namespace ldb = leveldb; |
|||
|
|||
class NatspecHandler |
|||
{ |
|||
public: |
|||
NatspecHandler(); |
|||
~NatspecHandler(); |
|||
|
|||
/// Stores locally in a levelDB a key value pair of contract code hash to natspec documentation
|
|||
void add(dev::h256 const& _contractHash, std::string const& _doc); |
|||
/// Retrieves the natspec documentation as a string given a contract code hash
|
|||
std::string retrieve(dev::h256 const& _contractHash) const; |
|||
|
|||
/// Given a json natspec string and the transaction data return the user notice
|
|||
std::string getUserNotice(std::string const& json, const dev::bytes& _transactionData); |
|||
/// Given a contract code hash and the transaction's data retrieve the natspec documention's
|
|||
/// user notice for that transaction.
|
|||
/// @returns The user notice or an empty string if no natspec for the contract exists
|
|||
/// or if the existing natspec does not document the @c _methodName
|
|||
std::string getUserNotice(dev::h256 const& _contractHash, dev::bytes const& _transactionDacta); |
|||
|
|||
private: |
|||
ldb::ReadOptions m_readOptions; |
|||
ldb::WriteOptions m_writeOptions; |
|||
ldb::DB* m_db; |
|||
Json::Reader m_reader; |
|||
}; |
@ -0,0 +1,77 @@ |
|||
<!doctype> |
|||
<html> |
|||
|
|||
<head> |
|||
<script type="text/javascript" src="js/es6-promise/promise.min.js"></script> |
|||
<script type="text/javascript" src="../dist/ethereum.js"></script> |
|||
<script type="text/javascript"> |
|||
|
|||
var web3 = require('web3'); |
|||
web3.setProvider(new web3.providers.AutoProvider()); |
|||
|
|||
// solidity source code |
|||
var source = "" + |
|||
"contract test {\n" + |
|||
" /// @notice Will multiplty `a` by 7. \n" + |
|||
" function multiply(uint a) returns(uint d) {\n" + |
|||
" return a * 7;\n" + |
|||
" }\n" + |
|||
"}\n"; |
|||
|
|||
// contract description, this will be autogenerated somehow |
|||
var desc = [{ |
|||
"name": "multiply", |
|||
"inputs": [ |
|||
{ |
|||
"name": "a", |
|||
"type": "uint256" |
|||
} |
|||
], |
|||
"outputs": [ |
|||
{ |
|||
"name": "d", |
|||
"type": "uint256" |
|||
} |
|||
] |
|||
}]; |
|||
|
|||
var contract; |
|||
|
|||
function createExampleContract() { |
|||
// hide create button |
|||
document.getElementById('create').style.visibility = 'hidden'; |
|||
document.getElementById('source').innerText = source; |
|||
|
|||
// create contract |
|||
web3.eth.transact({code: web3.eth.solidity(source)}).then(function (address) { |
|||
contract = web3.contract(address, desc); |
|||
document.getElementById('call').style.visibility = 'visible'; |
|||
}); |
|||
} |
|||
|
|||
function callExampleContract() { |
|||
// this should be generated by ethereum |
|||
var param = parseInt(document.getElementById('value').value); |
|||
|
|||
// call the contract |
|||
contract.multiply(param).transact().then(function(res) { |
|||
document.getElementById('result').innerText = res[0]; |
|||
}); |
|||
} |
|||
|
|||
</script> |
|||
</head> |
|||
<body> |
|||
<h1>contract</h1> |
|||
<div id="source"></div> |
|||
<div id='create'> |
|||
<button type="button" onClick="createExampleContract();">create example contract</button> |
|||
</div> |
|||
<div id='call' style='visibility: hidden;'> |
|||
<input type="number" id="value"></input> |
|||
<button type="button" onClick="callExampleContract()">Call Contract</button> |
|||
</div> |
|||
<div id="result"></div> |
|||
</body> |
|||
</html> |
|||
|
@ -1,94 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file ConstantCompilationControl.cpp
|
|||
* @author Yann yann@ethdev.com |
|||
* @date 2014 |
|||
* Ethereum IDE client. |
|||
*/ |
|||
|
|||
#include <QQmlContext> |
|||
#include <QQuickItem> |
|||
#include <QtCore/QFileInfo> |
|||
#include <QApplication> |
|||
#include <QQmlApplicationEngine> |
|||
#include <QtCore/QtCore> |
|||
#include <QDebug> |
|||
#include "ConstantCompilationControl.h" |
|||
#include "QContractDefinition.h" |
|||
#include "AppContext.h" |
|||
#include "CodeModel.h" |
|||
|
|||
using namespace dev::mix; |
|||
|
|||
|
|||
ConstantCompilationControl::ConstantCompilationControl(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::Tab) |
|||
{ |
|||
connect(_context->codeModel(), &CodeModel::compilationComplete, this, &ConstantCompilationControl::update); |
|||
connect(_context->codeModel(), &CodeModel::compilationComplete, this, &ConstantCompilationControl::update); |
|||
} |
|||
|
|||
QString ConstantCompilationControl::contentUrl() const |
|||
{ |
|||
return QStringLiteral("qrc:/qml/BasicContent.qml"); |
|||
} |
|||
|
|||
QString ConstantCompilationControl::title() const |
|||
{ |
|||
return QApplication::tr("compiler"); |
|||
} |
|||
|
|||
void ConstantCompilationControl::start() const |
|||
{ |
|||
} |
|||
|
|||
void ConstantCompilationControl::update() |
|||
{ |
|||
auto result = m_ctx->codeModel()->code(); |
|||
|
|||
QObject* status = m_view->findChild<QObject*>("status", Qt::FindChildrenRecursively); |
|||
QObject* content = m_view->findChild<QObject*>("content", Qt::FindChildrenRecursively); |
|||
if (result->successful()) |
|||
{ |
|||
status->setProperty("text", "succeeded"); |
|||
status->setProperty("color", "green"); |
|||
content->setProperty("text", result->assemblyCode()); |
|||
} |
|||
else |
|||
{ |
|||
status->setProperty("text", "failure"); |
|||
status->setProperty("color", "red"); |
|||
content->setProperty("text", result->compilerMessage()); |
|||
} |
|||
} |
|||
|
|||
void ConstantCompilationControl::resetOutPut() |
|||
{ |
|||
QObject* status = m_view->findChild<QObject*>("status", Qt::FindChildrenRecursively); |
|||
QObject* content = m_view->findChild<QObject*>("content", Qt::FindChildrenRecursively); |
|||
status->setProperty("text", ""); |
|||
content->setProperty("text", ""); |
|||
} |
|||
|
|||
|
|||
void ConstantCompilationControl::displayError(QString const& _error) |
|||
{ |
|||
QObject* status = m_view->findChild<QObject*>("status", Qt::FindChildrenRecursively); |
|||
QObject* content = m_view->findChild<QObject*>("content", Qt::FindChildrenRecursively); |
|||
status->setProperty("text", "failure"); |
|||
status->setProperty("color", "red"); |
|||
content->setProperty("text", _error); |
|||
} |
@ -0,0 +1,66 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file ConstantCompilationControl.cpp
|
|||
* @author Yann yann@ethdev.com |
|||
* @date 2014 |
|||
* Ethereum IDE client. |
|||
*/ |
|||
|
|||
#include <QQmlContext> |
|||
#include <QQuickItem> |
|||
#include <QtCore/QFileInfo> |
|||
#include <QApplication> |
|||
#include <QQmlApplicationEngine> |
|||
#include <QtCore/QtCore> |
|||
#include <QDebug> |
|||
#include "StatusPane.h" |
|||
#include "QContractDefinition.h" |
|||
#include "AppContext.h" |
|||
#include "CodeModel.h" |
|||
|
|||
using namespace dev::mix; |
|||
|
|||
StatusPane::StatusPane(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::HeaderView) |
|||
{ |
|||
connect(_context->codeModel(), &CodeModel::compilationComplete, this, &StatusPane::update); |
|||
_context->appEngine()->rootContext()->setContextProperty("statusPane", this); |
|||
} |
|||
|
|||
QString StatusPane::contentUrl() const |
|||
{ |
|||
return QStringLiteral("qrc:/qml/StatusPane.qml"); |
|||
} |
|||
|
|||
QString StatusPane::title() const |
|||
{ |
|||
return QApplication::tr("compiler"); |
|||
} |
|||
|
|||
void StatusPane::start() const |
|||
{ |
|||
} |
|||
|
|||
CompilationResult* StatusPane::result() const |
|||
{ |
|||
return m_ctx->codeModel()->code(); |
|||
} |
|||
|
|||
void StatusPane::update() |
|||
{ |
|||
QObject* ctrl = m_view->findChild<QObject*>("statusPane", Qt::FindChildrenRecursively); |
|||
QMetaObject::invokeMethod(ctrl, "updateStatus"); |
|||
} |
@ -0,0 +1,35 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
|
|||
RowLayout { |
|||
property string titleStr |
|||
width: parent.width |
|||
height: parent.height / 4 |
|||
|
|||
function update(_value) |
|||
{ |
|||
currentStepValue.text = _value; |
|||
} |
|||
|
|||
Rectangle { |
|||
width: parent.width / 2 |
|||
height: parent.height |
|||
color: "#e5e5e5" |
|||
Text |
|||
{ |
|||
id: title |
|||
font.pixelSize: 12 |
|||
anchors.centerIn: parent |
|||
color: "#a2a2a2" |
|||
font.family: "Sans Serif" |
|||
text: titleStr |
|||
} |
|||
} |
|||
Text |
|||
{ |
|||
font.pixelSize: 13 |
|||
id: currentStepValue |
|||
} |
|||
} |
@ -0,0 +1,83 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
|
|||
ColumnLayout { |
|||
property string title |
|||
property variant listModel; |
|||
property bool collapsible; |
|||
property Component itemDelegate |
|||
spacing: 0 |
|||
RowLayout { |
|||
height: 25 |
|||
id: header |
|||
Image { |
|||
source: "qrc:/qml/img/opentriangleindicator.png" |
|||
width: 15 |
|||
sourceSize.width: 15 |
|||
id: storageImgArrow |
|||
visible: collapsible |
|||
} |
|||
|
|||
Text { |
|||
anchors.left: storageImgArrow.right |
|||
color: "#8b8b8b" |
|||
text: title |
|||
id: storageListTitle |
|||
} |
|||
|
|||
MouseArea |
|||
{ |
|||
enabled: collapsible |
|||
anchors.fill: parent |
|||
onClicked: { |
|||
if (storageContainer.state == "collapsed") |
|||
storageContainer.state = ""; |
|||
else |
|||
storageContainer.state = "collapsed"; |
|||
} |
|||
} |
|||
} |
|||
|
|||
RowLayout |
|||
{ |
|||
height: parent.height - header.height |
|||
clip: true |
|||
Rectangle |
|||
{ |
|||
height: parent.height |
|||
border.width: 3 |
|||
border.color: "#deddd9" |
|||
Layout.fillWidth: true |
|||
states: [ |
|||
State { |
|||
name: "collapsed" |
|||
PropertyChanges { |
|||
target: storageContainer.parent |
|||
height: 0 |
|||
visible: false |
|||
} |
|||
PropertyChanges { |
|||
target: storageImgArrow |
|||
source: "qrc:/qml/img/closedtriangleindicator.png" |
|||
} |
|||
} |
|||
] |
|||
id: storageContainer |
|||
width: parent.width |
|||
ListView { |
|||
clip: true; |
|||
anchors.top: parent.top |
|||
anchors.left: parent.left |
|||
anchors.topMargin: 3 |
|||
anchors.leftMargin: 3 |
|||
width: parent.width - 3 |
|||
height: parent.height - 6 |
|||
id: storageList |
|||
model: listModel |
|||
delegate: itemDelegate |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,71 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
|
|||
Rectangle { |
|||
anchors.fill: parent |
|||
RowLayout |
|||
{ |
|||
id: row; |
|||
anchors.fill: parent |
|||
spacing: 2 |
|||
Rectangle |
|||
{ |
|||
id: firstCol; |
|||
color: "#f7f7f7" |
|||
Layout.fillWidth: true |
|||
Layout.minimumWidth: 35 |
|||
Layout.preferredWidth: 35 |
|||
Layout.maximumWidth: 35 |
|||
Layout.minimumHeight: parent.height |
|||
Text { |
|||
anchors.centerIn: parent |
|||
anchors.leftMargin: 5 |
|||
color: "#8b8b8b" |
|||
text: modelData[0] |
|||
font.pointSize: 9; |
|||
} |
|||
} |
|||
|
|||
Rectangle |
|||
{ |
|||
anchors.left: firstCol.right |
|||
Layout.fillWidth: true |
|||
Layout.minimumWidth: 90 |
|||
Layout.preferredWidth: 90 |
|||
Layout.maximumWidth: 90 |
|||
Layout.minimumHeight: parent.height |
|||
Text { |
|||
anchors.left: parent.left |
|||
anchors.leftMargin: 7 |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
color: "#8b8b8b" |
|||
text: modelData[1] |
|||
font.pointSize: 9 |
|||
} |
|||
} |
|||
|
|||
Rectangle |
|||
{ |
|||
Layout.fillWidth: true |
|||
Layout.minimumWidth: 50 |
|||
Layout.minimumHeight: parent.height |
|||
Text { |
|||
anchors.left: parent.left |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
color: "#ededed" |
|||
font.bold: true |
|||
text: modelData[2] |
|||
font.pointSize: 10 |
|||
} |
|||
} |
|||
} |
|||
|
|||
Rectangle { |
|||
width: parent.width; |
|||
height: 1; |
|||
color: "#cccccc" |
|||
anchors.bottom: parent.bottom |
|||
} |
|||
} |
@ -0,0 +1,116 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Layouts 1.1 |
|||
import "js/ErrorLocationFormater.js" as ErrorLocationFormater |
|||
|
|||
Rectangle { |
|||
id: statusHeader |
|||
objectName: "statusPane" |
|||
|
|||
function updateStatus() |
|||
{ |
|||
if (statusPane.result.successful) |
|||
{ |
|||
status.state = ""; |
|||
status.text = qsTr("Compile without errors."); |
|||
logslink.visible = false; |
|||
} |
|||
else |
|||
{ |
|||
status.state = "error"; |
|||
var errorInfo = ErrorLocationFormater.extractErrorInfo(statusPane.result.compilerMessage, true); |
|||
status.text = errorInfo.errorLocation + " " + errorInfo.errorDetail; |
|||
logslink.visible = true; |
|||
} |
|||
debugRunActionIcon.enabled = statusPane.result.successful; |
|||
} |
|||
|
|||
color: "transparent" |
|||
anchors.fill: parent |
|||
Rectangle { |
|||
id: statusContainer |
|||
anchors.horizontalCenter: parent.horizontalCenter |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
radius: 3 |
|||
width: 500 |
|||
height: 30 |
|||
color: "#fcfbfc" |
|||
RowLayout { |
|||
anchors.horizontalCenter: parent.horizontalCenter |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
spacing: 5 |
|||
|
|||
Text { |
|||
font.pointSize: 10 |
|||
height: 9 |
|||
font.family: "sans serif" |
|||
objectName: "status" |
|||
id: status |
|||
states:[ |
|||
State { |
|||
name: "error" |
|||
PropertyChanges { |
|||
target: status |
|||
color: "red" |
|||
} |
|||
PropertyChanges { |
|||
target: statusContainer |
|||
color: "#fffcd5" |
|||
} |
|||
} |
|||
] |
|||
} |
|||
|
|||
Text { |
|||
visible: false |
|||
font.pointSize: 9 |
|||
height: 9 |
|||
text: qsTr("See log.") |
|||
font.family: "Monospace" |
|||
objectName: "status" |
|||
id: logslink |
|||
color: "#8c8a74" |
|||
MouseArea { |
|||
anchors.fill: parent |
|||
onClicked: { |
|||
mainContent.ensureRightView(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
Rectangle |
|||
{ |
|||
color: "transparent" |
|||
width: 100 |
|||
height: parent.height |
|||
anchors.top: statusHeader.top |
|||
anchors.right: statusHeader.right |
|||
RowLayout |
|||
{ |
|||
anchors.fill: parent |
|||
Rectangle { |
|||
color: "transparent" |
|||
anchors.fill: parent |
|||
Button |
|||
{ |
|||
anchors.right: parent.right |
|||
anchors.rightMargin: 7 |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
id: debugImg |
|||
iconSource: "qrc:/qml/img/bugiconinactive.png" |
|||
action: debugRunActionIcon |
|||
} |
|||
Action { |
|||
id: debugRunActionIcon |
|||
onTriggered: { |
|||
mainContent.ensureRightView(); |
|||
clientModel.debugDeployment(); |
|||
} |
|||
enabled: false |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
|
|||
|
|||
Rectangle { |
|||
id: buttonActionContainer |
|||
property string disableStateImg |
|||
property string enabledStateImg |
|||
signal clicked |
|||
|
|||
function enabled(state) |
|||
{ |
|||
buttonAction.enabled = state; |
|||
if (state) |
|||
debugImg.iconSource = enabledStateImg; |
|||
else |
|||
debugImg.iconSource = disableStateImg; |
|||
} |
|||
|
|||
color: "transparent" |
|||
Button |
|||
{ |
|||
anchors.fill: parent |
|||
id: debugImg |
|||
iconSource: enabledStateImg |
|||
action: buttonAction |
|||
width: buttonActionContainer.width - 3 |
|||
height: buttonActionContainer.height |
|||
} |
|||
|
|||
Action { |
|||
id: buttonAction |
|||
onTriggered: { |
|||
buttonActionContainer.clicked(); |
|||
} |
|||
} |
|||
} |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 422 B |
After Width: | Height: | Size: 762 B |
After Width: | Height: | Size: 678 B |
After Width: | Height: | Size: 785 B |
After Width: | Height: | Size: 695 B |
After Width: | Height: | Size: 700 B |
After Width: | Height: | Size: 634 B |
After Width: | Height: | Size: 674 B |
After Width: | Height: | Size: 580 B |
After Width: | Height: | Size: 692 B |
After Width: | Height: | Size: 532 B |
After Width: | Height: | Size: 717 B |
After Width: | Height: | Size: 425 B |
@ -0,0 +1,27 @@ |
|||
function formatLocation(raw, shortMessage) |
|||
{ |
|||
var splitted = raw.split(':'); |
|||
if (!shortMessage) |
|||
return qsTr("Error in line ") + splitted[1] + ", " + qsTr("character ") + splitted[2]; |
|||
else |
|||
return "L" + splitted[1] + "," + "C" + splitted[2]; |
|||
} |
|||
|
|||
function extractErrorInfo(raw, shortMessage) |
|||
{ |
|||
var _return = {}; |
|||
var detail = raw.split('\n')[0]; |
|||
var reg = detail.match(/:\d+:\d+:/g); |
|||
if (reg !== null) |
|||
{ |
|||
_return.errorLocation = ErrorLocationFormater.formatLocation(reg[0], shortMessage); |
|||
_return.errorDetail = detail.replace(reg[0], ""); |
|||
} |
|||
else |
|||
{ |
|||
_return.errorLocation = ""; |
|||
_return.errorDetail = detail; |
|||
} |
|||
_return.errorLine = raw.split('\n')[1]; |
|||
return _return; |
|||
} |
@ -0,0 +1,297 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file checkRandomTest.cpp
|
|||
* @author Christoph Jentzsch <jentzsch.simulationsoftware@gmail.com> |
|||
* @date 2015 |
|||
* Check a random test and return 0/1 for success or failure. To be used for efficiency in the random test simulation. |
|||
*/ |
|||
|
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/Exceptions.h> |
|||
#include <libdevcore/Log.h> |
|||
#include <libevm/VMFactory.h> |
|||
#include "vm.h" |
|||
#pragma GCC diagnostic ignored "-Wunused-parameter" |
|||
|
|||
using namespace std; |
|||
using namespace json_spirit; |
|||
using namespace dev::test; |
|||
using namespace dev; |
|||
|
|||
bool doVMTest(mValue& v); |
|||
|
|||
int main(int argc, char *argv[]) |
|||
{ |
|||
g_logVerbosity = 0; |
|||
bool ret = false; |
|||
|
|||
try |
|||
{ |
|||
mValue v; |
|||
string s; |
|||
for (int i = 1; i < argc; ++i) |
|||
s += argv[i]; |
|||
if (asserts(s.length() > 0)) |
|||
{ |
|||
cout << "Content of argument is empty\n"; |
|||
return 1; |
|||
} |
|||
read_string(s, v); |
|||
ret = doVMTest(v); |
|||
} |
|||
catch (Exception const& _e) |
|||
{ |
|||
cout << "Failed test with Exception: " << diagnostic_information(_e) << endl; |
|||
ret = false; |
|||
} |
|||
catch (std::exception const& _e) |
|||
{ |
|||
cout << "Failed test with Exception: " << _e.what() << endl; |
|||
ret = false; |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
bool doVMTest(mValue& v) |
|||
{ |
|||
eth::VMFactory::setKind(eth::VMKind::JIT); |
|||
|
|||
for (auto& i: v.get_obj()) |
|||
{ |
|||
cnote << i.first; |
|||
mObject& o = i.second.get_obj(); |
|||
|
|||
assert(o.count("env") > 0); |
|||
assert(o.count("pre") > 0); |
|||
assert(o.count("exec") > 0); |
|||
|
|||
FakeExtVM fev; |
|||
fev.importEnv(o["env"].get_obj()); |
|||
fev.importState(o["pre"].get_obj()); |
|||
|
|||
fev.importExec(o["exec"].get_obj()); |
|||
if (fev.code.empty()) |
|||
{ |
|||
fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); |
|||
fev.code = fev.thisTxCode; |
|||
} |
|||
|
|||
bytes output; |
|||
u256 gas; |
|||
bool vmExceptionOccured = false; |
|||
try |
|||
{ |
|||
auto vm = eth::VMFactory::create(fev.gas); |
|||
output = vm->go(fev, fev.simpleTrace()).toBytes(); |
|||
gas = vm->gas(); |
|||
} |
|||
catch (eth::VMException) |
|||
{ |
|||
cnote << "Safe VM Exception"; |
|||
vmExceptionOccured = true; |
|||
} |
|||
catch (Exception const& _e) |
|||
{ |
|||
cnote << "VM did throw an exception: " << diagnostic_information(_e); |
|||
cnote << "Failed VM Test with Exception: " << _e.what(); |
|||
return 1; |
|||
} |
|||
catch (std::exception const& _e) |
|||
{ |
|||
cnote << "VM did throw an exception: " << _e.what(); |
|||
cnote << "Failed VM Test with Exception: " << _e.what(); |
|||
return 1; |
|||
} |
|||
|
|||
// delete null entries in storage for the sake of comparison
|
|||
for (auto &a: fev.addresses) |
|||
{ |
|||
vector<u256> keystoDelete; |
|||
for (auto &s: get<2>(a.second)) |
|||
{ |
|||
if (s.second == 0) |
|||
keystoDelete.push_back(s.first); |
|||
} |
|||
for (auto const key: keystoDelete ) |
|||
{ |
|||
get<2>(a.second).erase(key); |
|||
} |
|||
} |
|||
|
|||
if (o.count("post") > 0) // No exceptions expected
|
|||
{ |
|||
if (asserts(!vmExceptionOccured) || asserts(o.count("post") > 0) || asserts(o.count("callcreates") > 0) || asserts(o.count("out") > 0) || asserts(o.count("gas") > 0) || asserts(o.count("logs") > 0)) |
|||
return 1; |
|||
|
|||
dev::test::FakeExtVM test; |
|||
test.importState(o["post"].get_obj()); |
|||
test.importCallCreates(o["callcreates"].get_array()); |
|||
test.sub.logs = importLog(o["logs"].get_array()); |
|||
|
|||
//checkOutput(output, o);
|
|||
int j = 0; |
|||
if (o["out"].type() == array_type) |
|||
for (auto const& d: o["out"].get_array()) |
|||
{ |
|||
if (asserts(output[j] == toInt(d))) |
|||
{ |
|||
cout << "Output byte [" << j << "] different!"; |
|||
return 1; |
|||
} |
|||
++j; |
|||
} |
|||
else if (o["out"].get_str().find("0x") == 0) |
|||
{ |
|||
if (asserts(output == fromHex(o["out"].get_str().substr(2)))) |
|||
return 1; |
|||
} |
|||
else |
|||
{ |
|||
if (asserts(output == fromHex(o["out"].get_str()))) |
|||
return 1; |
|||
} |
|||
|
|||
if (asserts(toInt(o["gas"]) == gas)) |
|||
return 1; |
|||
|
|||
auto& expectedAddrs = test.addresses; |
|||
auto& resultAddrs = fev.addresses; |
|||
for (auto&& expectedPair : expectedAddrs) |
|||
{ |
|||
auto& expectedAddr = expectedPair.first; |
|||
auto resultAddrIt = resultAddrs.find(expectedAddr); |
|||
if (resultAddrIt == resultAddrs.end()) |
|||
{ |
|||
cout << "Missing expected address " << expectedAddr; |
|||
return 1; |
|||
} |
|||
else |
|||
{ |
|||
auto& expectedState = expectedPair.second; |
|||
auto& resultState = resultAddrIt->second; |
|||
if (asserts(std::get<0>(expectedState) == std::get<0>(resultState))) |
|||
{ |
|||
cout << expectedAddr << ": incorrect balance " << std::get<0>(resultState) << ", expected " << std::get<0>(expectedState); |
|||
return 1; |
|||
} |
|||
if (asserts(std::get<1>(expectedState) == std::get<1>(resultState))) |
|||
{ |
|||
cout << expectedAddr << ": incorrect txCount " << std::get<1>(resultState) << ", expected " << std::get<1>(expectedState); |
|||
return 1; |
|||
} |
|||
if (asserts(std::get<3>(expectedState) == std::get<3>(resultState))) |
|||
{ |
|||
cout << expectedAddr << ": incorrect code"; |
|||
return 1; |
|||
} |
|||
|
|||
//checkStorage(std::get<2>(expectedState), std::get<2>(resultState), expectedAddr);
|
|||
for (auto&& expectedStorePair : std::get<2>(expectedState)) |
|||
{ |
|||
auto& expectedStoreKey = expectedStorePair.first; |
|||
auto resultStoreIt = std::get<2>(resultState).find(expectedStoreKey); |
|||
if (resultStoreIt == std::get<2>(resultState).end()) |
|||
{ |
|||
cout << expectedAddr << ": missing store key " << expectedStoreKey << endl; |
|||
return 1; |
|||
} |
|||
else |
|||
{ |
|||
auto& expectedStoreValue = expectedStorePair.second; |
|||
auto& resultStoreValue = resultStoreIt->second; |
|||
if (asserts(expectedStoreValue == resultStoreValue)) |
|||
{ |
|||
cout << expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue << endl; |
|||
return 1; |
|||
} |
|||
} |
|||
} |
|||
if (assertsEqual(std::get<2>(resultState).size(), std::get<2>(expectedState).size())) |
|||
return 1; |
|||
for (auto&& resultStorePair: std::get<2>(resultState)) |
|||
{ |
|||
if (!std::get<2>(expectedState).count(resultStorePair.first)) |
|||
{ |
|||
cout << expectedAddr << ": unexpected store key " << resultStorePair.first << endl; |
|||
return 1; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
//checkAddresses<std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes> > >(test.addresses, fev.addresses);
|
|||
for (auto& resultPair : fev.addresses) |
|||
{ |
|||
auto& resultAddr = resultPair.first; |
|||
auto expectedAddrIt = test.addresses.find(resultAddr); |
|||
if (expectedAddrIt == test.addresses.end()) |
|||
{ |
|||
cout << "Missing result address " << resultAddr << endl; |
|||
return 1; |
|||
} |
|||
} |
|||
if (asserts(test.addresses == fev.addresses)) |
|||
return 1; |
|||
|
|||
if (asserts(test.callcreates == fev.callcreates)) |
|||
return 1; |
|||
|
|||
//checkCallCreates(fev.callcreates, test.callcreates);
|
|||
{ |
|||
if (assertsEqual(test.callcreates.size(), fev.callcreates.size())) |
|||
return 1; |
|||
|
|||
for (size_t i = 0; i < test.callcreates.size(); ++i) |
|||
{ |
|||
if (asserts(test.callcreates[i].data() == fev.callcreates[i].data())) |
|||
return 1; |
|||
if (asserts(test.callcreates[i].receiveAddress() == fev.callcreates[i].receiveAddress())) |
|||
return 1; |
|||
if (asserts(test.callcreates[i].gas() == fev.callcreates[i].gas())) |
|||
return 1; |
|||
if (asserts(test.callcreates[i].value() == fev.callcreates[i].value())) |
|||
return 1; |
|||
} |
|||
} |
|||
|
|||
//checkLog(fev.sub.logs, test.sub.logs);
|
|||
{ |
|||
if (assertsEqual(fev.sub.logs.size(), test.sub.logs.size())) |
|||
return 1; |
|||
|
|||
for (size_t i = 0; i < fev.sub.logs.size(); ++i) |
|||
{ |
|||
if (assertsEqual(fev.sub.logs[i].address, test.sub.logs[i].address)) |
|||
return 1; |
|||
if (assertsEqual(fev.sub.logs[i].topics, test.sub.logs[i].topics)) |
|||
return 1; |
|||
if (asserts(fev.sub.logs[i].data == test.sub.logs[i].data)) |
|||
return 1; |
|||
} |
|||
} |
|||
|
|||
} |
|||
else // Exception expected
|
|||
{ |
|||
if (asserts(vmExceptionOccured)) |
|||
return 1; |
|||
} |
|||
} |
|||
// test passed
|
|||
return 0; |
|||
} |
|||
|