Browse Source

fixed issues with web preview and having multiple contracts in the same

file
cl-refactor
arkpar 10 years ago
parent
commit
40ef58dfcb
  1. 15
      mix/CodeModel.cpp
  2. 2
      mix/CodeModel.h
  3. 9
      mix/HttpServer.cpp
  4. 8
      mix/HttpServer.h
  5. 16
      mix/MixClient.cpp
  6. 8
      mix/qml/WebPreview.qml
  7. 9
      mix/test/TestService.cpp
  8. 1
      mix/test/TestService.h
  9. 14
      mix/test/qml/TestMain.qml
  10. 17
      mix/test/qml/js/TestDebugger.js
  11. 4
      mix/test/qml/js/TestMiner.js
  12. 28
      mix/test/qml/js/TestProject.js

15
mix/CodeModel.cpp

@ -279,9 +279,22 @@ void CodeModel::runCompilationJob(int _jobId)
QQmlEngine::setObjectOwnership(contract, QQmlEngine::CppOwnership);
result[name] = contract;
CompiledContract* prevContract = nullptr;
// find previous contract by name
for (ContractMap::const_iterator c = m_contractMap.cbegin(); c != m_contractMap.cend(); ++c)
if (c.value()->documentId() == contract->documentId())
if (c.value()->contract()->name() == contract->contract()->name())
prevContract = c.value();
// if not found, try by documentId
if (!prevContract)
{
for (ContractMap::const_iterator c = m_contractMap.cbegin(); c != m_contractMap.cend(); ++c)
if (c.value()->documentId() == contract->documentId())
{
//make sure there are no other contracts in the same source, otherwise it is not a rename
if (!std::any_of(result.begin(),result.end(), [=](ContractMap::const_iterator::value_type _v) { return _v != contract && _v->documentId() == contract->documentId(); }))
prevContract = c.value();
}
}
if (prevContract != nullptr && prevContract->contractInterface() != result[name]->contractInterface())
emit contractInterfaceChanged(name);
if (prevContract == nullptr)

2
mix/CodeModel.h

@ -117,7 +117,7 @@ private:
friend class CodeModel;
};
using ContractMap = QHash<QString, CompiledContract*>;
using ContractMap = QMap<QString, CompiledContract*>; //needs to be sorted
/// Code compilation model. Compiles contracts in background an provides compiled contract data
class CodeModel: public QObject

9
mix/HttpServer.cpp

@ -145,16 +145,23 @@ void HttpServer::readClient()
if (socket->canReadLine())
{
QString hdr = QString(socket->readLine());
QVariantMap headers;
if (hdr.startsWith("POST") || hdr.startsWith("GET"))
{
QUrl url(hdr.split(' ')[1]);
QString l;
do
{
l = socket->readLine();
//collect headers
int colon = l.indexOf(':');
if (colon > 0)
headers[l.left(colon)] = l.right(l.length() - colon - 1);
}
while (!(l.isEmpty() || l == "\r" || l == "\r\n"));
QString content = socket->readAll();
std::unique_ptr<HttpRequest> request(new HttpRequest(this, url, content));
std::unique_ptr<HttpRequest> request(new HttpRequest(this, std::move(url), std::move(content), std::move(headers)));
clientConnected(request.get());
QTextStream os(socket);
os.setAutoDetectUnicode(true);

8
mix/HttpServer.h

@ -25,6 +25,7 @@
#include <QObject>
#include <QTcpServer>
#include <QUrl>
#include <QVariantMap>
#include <QQmlParserStatus>
namespace dev
@ -40,10 +41,12 @@ class HttpRequest: public QObject
Q_PROPERTY(QUrl url MEMBER m_url CONSTANT)
/// Request body contents
Q_PROPERTY(QString content MEMBER m_content CONSTANT)
/// Request HTTP headers
Q_PROPERTY(QVariantMap headers MEMBER m_headers CONSTANT)
private:
HttpRequest(QObject* _parent, QUrl const& _url, QString const& _content):
QObject(_parent), m_url(_url), m_content(_content)
HttpRequest(QObject* _parent, QUrl&& _url, QString&& _content, QVariantMap&& _headers):
QObject(_parent), m_url(_url), m_content(_content), m_headers(_headers)
{
}
@ -60,6 +63,7 @@ private:
QString m_content;
QString m_response;
QString m_responseContentType;
QVariantMap m_headers;
friend class HttpServer;
};

16
mix/MixClient.cpp

@ -251,21 +251,7 @@ void MixClient::mine()
WriteGuard l(x_state);
m_state.commitToMine(bc());
m_state.completeMine<Ethash>(Ethash::Solution());
bc().import(m_state.blockData(), m_stateDB, ImportRequirements::Default & ~ImportRequirements::ValidNonce);
/*
GenericFarm<ProofOfWork> f;
bool completed = false;
f.onSolutionFound([&](ProofOfWork::Solution sol)
{
return completed = m_state.completeMine<ProofOfWork>(sol);
});
f.setWork(m_state.info());
f.startCPU();
while (!completed)
this_thread::sleep_for(chrono::milliseconds(20));
bc().import(m_state.blockData(), m_stateDB);
*/
bc().import(m_state.blockData(), m_state.db(), ImportRequirements::Default & ~ImportRequirements::ValidNonce);
m_state.sync(bc());
m_startState = m_state;
h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter };

8
mix/qml/WebPreview.qml

@ -17,6 +17,7 @@ Item {
property string webContent; //for testing
signal javaScriptMessage(var _level, string _sourceId, var _lineNb, string _content)
signal webContentReady
signal ready
function setPreviewUrl(url) {
if (!initialized)
@ -184,8 +185,10 @@ Item {
content = fileIo.readFile(doc.path);
}
if (documentName === urlInput.text.replace(httpServer.url + "/", "")) {
//root page, inject deployment script
var accept = _request.headers["Accept"];
if (accept && accept.indexOf("text/html") >= 0 && !_request.headers["HTTP_X_REQUESTED_WITH"])
{
//navigate to page request, inject deployment script
content = "<script>web3=parent.web3;BigNumber=parent.BigNumber;contracts=parent.contracts;</script>\n" + content;
_request.setResponseContentType("text/html");
}
@ -325,6 +328,7 @@ Item {
webView.runJavaScript("init(\"" + httpServer.url + "/rpc/\")");
if (pendingPageUrl)
setPreviewUrl(pendingPageUrl);
ready();
}
}
}

9
mix/test/TestService.cpp

@ -20,8 +20,9 @@
* Ethereum IDE client.
*/
#include <iostream>
#include "TestService.h"
#include <iostream>
#include <QUuid>
#include <QtTest/QSignalSpy>
#include <QElapsedTimer>
#include <QQuickItem>
@ -177,7 +178,6 @@ void TestService::setTargetWindow(QObject* _window)
window->requestActivate();
}
QWindow* TestService::eventWindow(QObject* _item)
{
QQuickItem* item = qobject_cast<QQuickItem*>(_item);
@ -201,5 +201,10 @@ QWindow* TestService::eventWindow(QObject* _item)
return 0;
}
QString TestService::createUuid() const
{
return QUuid::createUuid().toString();
}
}
}

1
mix/test/TestService.h

@ -41,6 +41,7 @@ public:
void setTargetWindow(QObject* _window);
public slots:
QString createUuid() const;
bool waitForSignal(QObject* _item, QString _signalName, int _timeout);
bool waitForRendering(QObject* _item, int timeout);
bool keyPress(QObject* _item, int _key, int _modifiers, int _delay);

14
mix/test/qml/TestMain.qml

@ -41,7 +41,7 @@ TestCase
var projectDlg = mainApplication.projectModel.newProjectDialog;
wait(30);
projectDlg.projectTitle = "TestProject";
projectDlg.pathFieldText = "/tmp/MixTest"; //TODO: get platform temp path
projectDlg.pathFieldText = "/tmp/MixTest/" + ts.createUuid(); //TODO: get platform temp path
projectDlg.acceptAndClose();
wait(1);
if (!ts.waitForSignal(mainApplication.codeModel, "compilationComplete()", 5000))
@ -82,6 +82,16 @@ TestCase
ts.keyPressChar(mainApplication, "S", Qt.ControlModifier, 200); //Ctrl+S
}
function createHtml(name, c)
{
mainApplication.projectModel.newHtmlFile();
ts.waitForSignal(mainApplication.mainContent.codeEditor, "loadComplete()", 5000);
var doc = mainApplication.projectModel.listModel.get(mainApplication.projectModel.listModel.count - 1);
mainApplication.projectModel.renameDocument(doc.documentId, name);
mainApplication.mainContent.codeEditor.getEditor(doc.documentId).setText(c);
ts.keyPressChar(mainApplication, "S", Qt.ControlModifier, 200); //Ctrl+S
}
function clickElement(el, x, y)
{
if (el.contentItem)
@ -101,5 +111,7 @@ TestCase
function test_miner_selectMiner() { TestMiner.test_selectMiner(); }
function test_miner_mine() { TestMiner.test_mine(); }
function test_project_contractRename() { TestProject.test_contractRename(); }
function test_project_multipleWebPages() { TestProject.test_multipleWebPages(); }
function test_project_multipleContractsSameFile() { TestProject.test_multipleContractsSameFile(); }
}

17
mix/test/qml/js/TestDebugger.js

@ -123,8 +123,7 @@ function test_arrayParametersAndStorage()
transactionDialog.acceptAndClose();
mainApplication.projectModel.stateDialog.acceptAndClose();
mainApplication.mainContent.startQuickDebugging();
if (!ts.waitForSignal(mainApplication.clientModel, "debugDataReady(QObject*)", 5000))
fail("Error running transaction");
waitForExecution();
//debug setM
mainApplication.clientModel.debugRecord(3);
mainApplication.mainContent.rightPane.debugSlider.value = mainApplication.mainContent.rightPane.debugSlider.maximumValue;
@ -158,8 +157,7 @@ function test_solidityDebugging()
"}");
mainApplication.mainContent.startQuickDebugging();
if (!ts.waitForSignal(mainApplication.clientModel, "debugDataReady(QObject*)", 5000))
fail("Error running transaction");
waitForExecution();
tryCompare(mainApplication.mainContent.rightPane.debugSlider, "maximumValue", 20);
tryCompare(mainApplication.mainContent.rightPane.debugSlider, "value", 0);
@ -191,8 +189,7 @@ function test_vmDebugging()
"}");
mainApplication.mainContent.startQuickDebugging();
if (!ts.waitForSignal(mainApplication.clientModel, "debugDataReady(QObject*)", 5000))
fail("Error running transaction");
waitForExecution();
mainApplication.mainContent.rightPane.assemblyMode = !mainApplication.mainContent.rightPane.assemblyMode;
tryCompare(mainApplication.mainContent.rightPane.debugSlider, "maximumValue", 41);
@ -225,12 +222,7 @@ function test_ctrTypeAsParam()
" }\r " +
"}");
mainApplication.projectModel.stateListModel.editState(0); //C1 ctor already added
mainApplication.projectModel.stateDialog.model.addTransaction();
var transactionDialog = mainApplication.projectModel.stateDialog.transactionDialog;
ts.waitForRendering(transactionDialog, 3000);
transactionDialog.selectContract("C2");
transactionDialog.selectFunction("C2");
transactionDialog.acceptAndClose();
mainApplication.projectModel.stateDialog.model.addTransaction();
transactionDialog = mainApplication.projectModel.stateDialog.transactionDialog;
ts.waitForRendering(transactionDialog, 3000);
@ -241,8 +233,7 @@ function test_ctrTypeAsParam()
transactionDialog.acceptAndClose();
mainApplication.projectModel.stateDialog.acceptAndClose();
mainApplication.mainContent.startQuickDebugging();
if (!ts.waitForSignal(mainApplication.clientModel, "debugDataReady(QObject*)", 5000))
fail("Error running transaction");
waitForExecution();
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(4), "returned", "(159)");
}

4
mix/test/qml/js/TestMiner.js

@ -25,6 +25,10 @@ function test_mine()
waitForExecution();
mainApplication.clientModel.mine();
waitForMining();
wait(1000); //there need to be at least 1 sec diff between block times
mainApplication.clientModel.mine();
waitForMining();
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(3), "contract", " - Block - ");
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(4), "contract", " - Block - ");
}

28
mix/test/qml/js/TestProject.js

@ -16,3 +16,31 @@ function test_contractRename()
transactionDialog.close();
mainApplication.projectModel.stateDialog.close();
}
function test_multipleWebPages()
{
newProject();
editHtml("<html><body><a href=\"page1.html\">page1</a></body></html>");
createHtml("page1.html", "<html><body><div id='queryres'>Fail</div></body><script>if (web3) document.getElementById('queryres').innerText='OK'</script></html>");
clickElement(mainApplication.mainContent.webView.webView, 1, 1);
ts.typeString("\t\r");
wait(300); //TODO: use a signal in qt 5.5
mainApplication.mainContent.webView.getContent();
ts.waitForSignal(mainApplication.mainContent.webView, "webContentReady()", 5000);
var body = mainApplication.mainContent.webView.webContent;
verify(body.indexOf("<div id=\"queryres\">OK</div>") != -1, "Web content not updated")
}
function test_multipleContractsSameFile()
{
newProject();
editContract(
"contract C1 {}\r" +
"contract C2 {}\r" +
"contract C3 {}\r");
waitForExecution();
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel, "count", 5);
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(2), "contract", "C1");
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(3), "contract", "C2");
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(4), "contract", "C3");
}

Loading…
Cancel
Save