Gav Wood
10 years ago
55 changed files with 1922 additions and 1064 deletions
@ -0,0 +1,90 @@ |
|||
var prettyPrint = (function () { |
|||
function pp(object, indent) { |
|||
try { |
|||
JSON.stringify(object, null, 2); |
|||
} catch (e) { |
|||
return pp(e, indent); |
|||
} |
|||
|
|||
var str = ""; |
|||
if(object instanceof Array) { |
|||
str += "["; |
|||
for(var i = 0, l = object.length; i < l; i++) { |
|||
str += pp(object[i], indent); |
|||
if(i < l-1) { |
|||
str += ", "; |
|||
} |
|||
} |
|||
str += " ]"; |
|||
} else if (object instanceof Error) { |
|||
str += "\e[31m" + "Error:\e[0m " + object.message; |
|||
} else if (isBigNumber(object)) { |
|||
str += "\e[32m'" + object.toString(10) + "'"; |
|||
} else if(typeof(object) === "object") { |
|||
str += "{\n"; |
|||
indent += " "; |
|||
var last = getFields(object).pop() |
|||
getFields(object).forEach(function (k) { |
|||
str += indent + k + ": "; |
|||
try { |
|||
str += pp(object[k], indent); |
|||
} catch (e) { |
|||
str += pp(e, indent); |
|||
} |
|||
if(k !== last) { |
|||
str += ","; |
|||
} |
|||
str += "\n"; |
|||
}); |
|||
str += indent.substr(2, indent.length) + "}"; |
|||
} else if(typeof(object) === "string") { |
|||
str += "\e[32m'" + object + "'"; |
|||
} else if(typeof(object) === "undefined") { |
|||
str += "\e[1m\e[30m" + object; |
|||
} else if(typeof(object) === "number") { |
|||
str += "\e[31m" + object; |
|||
} else if(typeof(object) === "function") { |
|||
str += "\e[35m[Function]"; |
|||
} else { |
|||
str += object; |
|||
} |
|||
str += "\e[0m"; |
|||
return str; |
|||
} |
|||
var redundantFields = [ |
|||
'valueOf', |
|||
'toString', |
|||
'toLocaleString', |
|||
'hasOwnProperty', |
|||
'isPrototypeOf', |
|||
'propertyIsEnumerable', |
|||
'constructor', |
|||
'__defineGetter__', |
|||
'__defineSetter__', |
|||
'__lookupGetter__', |
|||
'__lookupSetter__', |
|||
'__proto__' |
|||
]; |
|||
var getFields = function (object) { |
|||
var result = Object.getOwnPropertyNames(object); |
|||
if (object.constructor && object.constructor.prototype) { |
|||
result = result.concat(Object.getOwnPropertyNames(object.constructor.prototype)); |
|||
} |
|||
return result.filter(function (field) { |
|||
return redundantFields.indexOf(field) === -1; |
|||
}); |
|||
}; |
|||
var isBigNumber = function (object) { |
|||
return typeof BigNumber !== 'undefined' && object instanceof BigNumber; |
|||
}; |
|||
function prettyPrintI(/* */) { |
|||
var args = arguments; |
|||
var ret = ""; |
|||
for (var i = 0, l = args.length; i < l; i++) { |
|||
ret += pp(args[i], "") + "\n"; |
|||
} |
|||
return ret; |
|||
} |
|||
return prettyPrintI; |
|||
})(); |
|||
|
@ -0,0 +1,106 @@ |
|||
var ansi2html = (function(){ |
|||
|
|||
function ansi2htmlI(str) { |
|||
// this lib do not support \e
|
|||
str = str.replace(/e\[/g, '['); |
|||
// nor line breaks
|
|||
str = '<div>' + str.replace(/\n/g, '</div><div>') + '</div>'; |
|||
var props = {} |
|||
, open = false |
|||
|
|||
var stylemap = |
|||
{ bold: "font-weight" |
|||
, underline: "text-decoration" |
|||
, color: "color" |
|||
, background: "background" |
|||
} |
|||
|
|||
function style() { |
|||
var key, val, style = [] |
|||
for (var key in props) { |
|||
val = props[key] |
|||
if (!val) continue |
|||
if (val == true) { |
|||
style.push(stylemap[key] + ':' + key) |
|||
} else { |
|||
style.push(stylemap[key] + ':' + val) |
|||
} |
|||
} |
|||
return style.join(';') |
|||
} |
|||
|
|||
|
|||
function tag(code) { |
|||
var i |
|||
, tag = '' |
|||
, n = ansi2htmlI.table[code] |
|||
|
|||
if (open) tag += '</span>' |
|||
open = false |
|||
|
|||
if (n) { |
|||
for (i in n) props[i] = n[i] |
|||
tag += '<span style="' + style() + '">' |
|||
open = true |
|||
} else { |
|||
props = {} |
|||
} |
|||
|
|||
return tag |
|||
} |
|||
|
|||
return str.replace(/\[(\d+;)?(\d+)*m/g, function(match, b1, b2) { |
|||
var i, code, res = '' |
|||
if (b2 == '' || b2 == null) b2 = '0' |
|||
for (i = 1; i < arguments.length - 2; i++) { |
|||
if (!arguments[i]) continue |
|||
code = parseInt(arguments[i]) |
|||
res += tag(code) |
|||
} |
|||
return res |
|||
}) + tag() |
|||
} |
|||
|
|||
/* not implemented: |
|||
* italic |
|||
* blink |
|||
* invert |
|||
* strikethrough |
|||
*/ |
|||
ansi2htmlI.table = |
|||
{ 0: null |
|||
, 1: { bold: true } |
|||
, 3: { italic: true } |
|||
, 4: { underline: true } |
|||
, 5: { blink: true } |
|||
, 6: { blink: true } |
|||
, 7: { invert: true } |
|||
, 9: { strikethrough: true } |
|||
, 23: { italic: false } |
|||
, 24: { underline: false } |
|||
, 25: { blink: false } |
|||
, 27: { invert: false } |
|||
, 29: { strikethrough: false } |
|||
, 30: { color: 'black' } |
|||
, 31: { color: 'red' } |
|||
, 32: { color: 'green' } |
|||
, 33: { color: 'yellow' } |
|||
, 34: { color: 'blue' } |
|||
, 35: { color: 'magenta' } |
|||
, 36: { color: 'cyan' } |
|||
, 37: { color: 'white' } |
|||
, 39: { color: null } |
|||
, 40: { background: 'black' } |
|||
, 41: { background: 'red' } |
|||
, 42: { background: 'green' } |
|||
, 43: { background: 'yellow' } |
|||
, 44: { background: 'blue' } |
|||
, 45: { background: 'magenta' } |
|||
, 46: { background: 'cyan' } |
|||
, 47: { background: 'white' } |
|||
, 49: { background: null } |
|||
} |
|||
|
|||
return ansi2htmlI; |
|||
})(); |
|||
|
@ -0,0 +1,140 @@ |
|||
function test_defaultTransactionSequence() |
|||
{ |
|||
newProject(); |
|||
editContract( |
|||
"contract Contract {\r" + |
|||
" function Contract() {\r" + |
|||
" uint x = 69;\r" + |
|||
" uint y = 5;\r" + |
|||
" for (uint i = 0; i < y; ++i) {\r" + |
|||
" x += 42;\r" + |
|||
" z += x;\r" + |
|||
" }\r" + |
|||
" }\r" + |
|||
" uint z;\r" + |
|||
"}\r" |
|||
); |
|||
if (!ts.waitForSignal(mainApplication.clientModel, "runComplete()", 5000)) |
|||
fail("Error running transaction"); |
|||
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel, "count", 3); |
|||
} |
|||
|
|||
function test_transactionWithParameter() |
|||
{ |
|||
newProject(); |
|||
editContract( |
|||
"contract Contract {\r" + |
|||
" function setZ(uint256 x) {\r" + |
|||
" z = x;\r" + |
|||
" }\r" + |
|||
" function getZ() returns(uint256) {\r" + |
|||
" return z;\r" + |
|||
" }\r" + |
|||
" uint z;\r" + |
|||
"}\r" |
|||
); |
|||
mainApplication.projectModel.stateListModel.editState(0); |
|||
mainApplication.projectModel.stateDialog.model.addTransaction(); |
|||
var transactionDialog = mainApplication.projectModel.stateDialog.transactionDialog; |
|||
ts.waitForRendering(transactionDialog, 3000); |
|||
transactionDialog.selectFunction("setZ"); |
|||
clickElement(transactionDialog, 140, 300); |
|||
ts.typeString("442", transactionDialog); |
|||
transactionDialog.acceptAndClose(); |
|||
mainApplication.projectModel.stateDialog.model.addTransaction(); |
|||
ts.waitForRendering(transactionDialog, 3000); |
|||
transactionDialog.selectFunction("getZ"); |
|||
transactionDialog.acceptAndClose(); |
|||
mainApplication.projectModel.stateDialog.acceptAndClose(); |
|||
mainApplication.mainContent.startQuickDebugging(); |
|||
if (!ts.waitForSignal(mainApplication.clientModel, "runComplete()", 5000)) |
|||
fail("Error running transaction"); |
|||
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel, "count", 5); |
|||
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(4), "returned", "(442)"); |
|||
} |
|||
|
|||
function test_constructorParameters() |
|||
{ |
|||
newProject(); |
|||
editContract( |
|||
"contract Contract {\r" + |
|||
" function Contract(uint256 x) {\r" + |
|||
" z = x;\r" + |
|||
" }\r" + |
|||
" function getZ() returns(uint256) {\r" + |
|||
" return z;\r" + |
|||
" }\r" + |
|||
" uint z;\r" + |
|||
"}\r" |
|||
); |
|||
mainApplication.projectModel.stateListModel.editState(0); |
|||
mainApplication.projectModel.stateDialog.model.editTransaction(2); |
|||
var transactionDialog = mainApplication.projectModel.stateDialog.transactionDialog; |
|||
ts.waitForRendering(transactionDialog, 3000); |
|||
clickElement(transactionDialog, 140, 300); |
|||
ts.typeString("442", transactionDialog); |
|||
transactionDialog.acceptAndClose(); |
|||
mainApplication.projectModel.stateDialog.model.addTransaction(); |
|||
ts.waitForRendering(transactionDialog, 3000); |
|||
transactionDialog.selectFunction("getZ"); |
|||
transactionDialog.acceptAndClose(); |
|||
mainApplication.projectModel.stateDialog.acceptAndClose(); |
|||
mainApplication.mainContent.startQuickDebugging(); |
|||
if (!ts.waitForSignal(mainApplication.clientModel, "runComplete()", 5000)) |
|||
fail("Error running transaction"); |
|||
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel, "count", 4); |
|||
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel.get(3), "returned", "(442)"); |
|||
} |
|||
|
|||
function test_arrayParametersAndStorage() |
|||
{ |
|||
newProject(); |
|||
editContract( |
|||
" contract ArrayTest {\r" + |
|||
" function setM(uint256[] x) external\r" + |
|||
" {\r" + |
|||
" m = x;\r" + |
|||
" s = 5;\r" + |
|||
" }\r" + |
|||
" \r" + |
|||
" function setMV(uint72[5] x) external\r" + |
|||
" {\r" + |
|||
" mv = x;\r" + |
|||
" s = 42;\r" + |
|||
" }\r" + |
|||
" \r" + |
|||
" uint256[] m;\r" + |
|||
" uint72[5] mv;\r" + |
|||
" uint256 s;\r" + |
|||
" }\r"); |
|||
|
|||
mainApplication.projectModel.stateListModel.editState(0); |
|||
mainApplication.projectModel.stateDialog.model.addTransaction(); |
|||
var transactionDialog = mainApplication.projectModel.stateDialog.transactionDialog; |
|||
ts.waitForRendering(transactionDialog, 3000); |
|||
transactionDialog.selectFunction("setM"); |
|||
clickElement(transactionDialog, 140, 300); |
|||
ts.typeString("4,5,6,2,10", transactionDialog); |
|||
transactionDialog.acceptAndClose(); |
|||
mainApplication.projectModel.stateDialog.model.addTransaction(); |
|||
ts.waitForRendering(transactionDialog, 3000); |
|||
transactionDialog.selectFunction("setMV"); |
|||
clickElement(transactionDialog, 140, 300); |
|||
ts.typeString("13,35,1,4", transactionDialog); |
|||
transactionDialog.acceptAndClose(); |
|||
mainApplication.projectModel.stateDialog.acceptAndClose(); |
|||
mainApplication.mainContent.startQuickDebugging(); |
|||
if (!ts.waitForSignal(mainApplication.clientModel, "debugDataReady(QObject*)", 5000)) |
|||
fail("Error running transaction"); |
|||
//debug setM
|
|||
mainApplication.clientModel.debugRecord(3); |
|||
mainApplication.mainContent.rightPane.debugSlider.value = mainApplication.mainContent.rightPane.debugSlider.maximumValue; |
|||
tryCompare(mainApplication.mainContent.rightPane.solStorage.item.value, "m", ["4","5","6","2","10"]); |
|||
tryCompare(mainApplication.mainContent.rightPane.solStorage.item.value, "s", "5"); |
|||
//debug setMV
|
|||
mainApplication.clientModel.debugRecord(4); |
|||
mainApplication.mainContent.rightPane.debugSlider.value = mainApplication.mainContent.rightPane.debugSlider.maximumValue - 1; |
|||
tryCompare(mainApplication.mainContent.rightPane.solStorage.item.value, "mv", ["13","35","1","4","0"]); |
|||
tryCompare(mainApplication.mainContent.rightPane.solStorage.item.value, "s", "42"); |
|||
tryCompare(mainApplication.mainContent.rightPane.solCallStack.listModel, 0, "setMV"); |
|||
} |
@ -0,0 +1,71 @@ |
|||
//Test case to cover Mix tutorial
|
|||
|
|||
function test_tutorial() |
|||
{ |
|||
newProject(); |
|||
editContract( |
|||
"contract Rating {\r" + |
|||
" function setRating(bytes32 _key, uint256 _value) {\r" + |
|||
" ratings[_key] = _value;\r" + |
|||
" }\r" + |
|||
" mapping (bytes32 => uint256) public ratings;\r" + |
|||
"}\r" |
|||
); |
|||
editHtml( |
|||
"<!doctype>\r" + |
|||
"<html>\r" + |
|||
"<head>\r" + |
|||
"<script type='text/javascript'>\r" + |
|||
"function getRating() {\r" + |
|||
" var param = document.getElementById('query').value;\r" + |
|||
" var res = contracts['Rating'].contract.ratings(param);\r" + |
|||
" document.getElementById('queryres').innerText = res;\r" + |
|||
"}\r" + |
|||
"function setRating() {\r" + |
|||
" var key = document.getElementById('key').value;\r" + |
|||
" var value = parseInt(document.getElementById('value').value);\r" + |
|||
" var res = contracts['Rating'].contract.setRating(key, value);\r" + |
|||
"}\r" + |
|||
"</script>\r" + |
|||
"</head>\r" + |
|||
"<body bgcolor='#E6E6FA'>\r" + |
|||
" <h1>Ratings</h1>\r" + |
|||
" <div>\r" + |
|||
" Store:\r" + |
|||
" <input type='string' id='key'>\r" + |
|||
" <input type='number' id='value'>\r" + |
|||
" <button onclick='setRating()'>Save</button>\r" + |
|||
" </div>\r" + |
|||
" <div>\r" + |
|||
" Query:\r" + |
|||
" <input type='string' id='query' onkeyup='getRating()'>\r" + |
|||
" <div id='queryres'></div>\r" + |
|||
" </div>\r" + |
|||
"</body>\r" + |
|||
"</html>\r" |
|||
); |
|||
|
|||
mainApplication.projectModel.stateListModel.editState(0); |
|||
mainApplication.projectModel.stateDialog.model.addTransaction(); |
|||
var transactionDialog = mainApplication.projectModel.stateDialog.transactionDialog; |
|||
ts.waitForRendering(transactionDialog, 3000); |
|||
transactionDialog.selectFunction("setRating"); |
|||
clickElement(transactionDialog, 200, 310); |
|||
ts.typeString("Titanic", transactionDialog); |
|||
clickElement(transactionDialog, 200, 330); |
|||
ts.typeString("2", transactionDialog); |
|||
transactionDialog.acceptAndClose(); |
|||
mainApplication.projectModel.stateDialog.acceptAndClose(); |
|||
mainApplication.mainContent.startQuickDebugging(); |
|||
if (!ts.waitForSignal(mainApplication.clientModel, "debugDataReady(QObject*)", 5000)) |
|||
fail("Error running transaction"); |
|||
wait(1); |
|||
clickElement(mainApplication.mainContent.webView.webView, 1, 1); |
|||
ts.typeString("\t\t\t\t"); |
|||
ts.typeString("Titanic"); |
|||
tryCompare(mainApplication.mainContent.rightPane.transactionLog.callModel, "count", 8); //wait for 8 calls
|
|||
mainApplication.mainContent.webView.getContent(); |
|||
ts.waitForSignal(mainApplication.mainContent.webView, "webContentReady()", 5000); |
|||
var body = mainApplication.mainContent.webView.webContent; |
|||
verify(body.indexOf("<div id=\"queryres\">2</div>") != -1, "Web content not updated") |
|||
} |
Loading…
Reference in new issue