commit
d1acbc3459
@ -0,0 +1,7 @@ |
||||
/** |
||||
* This script is injected by NightWatch just before starting test |
||||
* |
||||
*/ |
||||
console.log('applying test mode') |
||||
document.getElementById('input').editor.setBehavioursEnabled(false) // disable bracket auto-match (i.e. automatic injection of closing brackets and other things), so we can enter raw source code.
|
||||
console.log('test mode applied') |
@ -1,25 +1,26 @@ |
||||
'use strict' |
||||
|
||||
module.exports = { |
||||
checkCompiledContracts: function (browser, compiled, callback) { |
||||
browser.execute(function () { |
||||
var contracts = document.querySelectorAll('.udapp .contract') |
||||
var ret = [] |
||||
for (var k in contracts) { |
||||
var el = contracts[k] |
||||
if (el.querySelector) { |
||||
ret.push({ |
||||
name: el.querySelector('.title').innerText.replace(el.querySelector('.size').innerText, '').replace(/(\t)|(\r)|(\n)/g, '') // IE/firefox add \r\n
|
||||
}) |
||||
} |
||||
} |
||||
return ret |
||||
}, [''], function (result) { |
||||
browser.assert.equal(result.value.length, compiled.length) |
||||
result.value.map(function (item, i) { |
||||
browser.assert.equal(item.name, compiled[i]) |
||||
checkCompiledContracts: checkCompiledContracts, |
||||
testContracts: testContracts |
||||
} |
||||
|
||||
function checkCompiledContracts (browser, compiled, callback) { |
||||
browser.elements('css selector', '.udapp .contract .title', function (elements) { |
||||
elements.value.map(function (item, i) { |
||||
browser.elementIdText(item.ELEMENT, function (text) { |
||||
browser.assert.equal(text.value.split('\n')[0], compiled[i]) |
||||
}) |
||||
callback() |
||||
}) |
||||
} |
||||
callback() |
||||
}) |
||||
} |
||||
|
||||
function testContracts (browser, contractCode, compiledContractNames, callback) { |
||||
browser |
||||
.clearValue('#input textarea') |
||||
.click('.newFile') |
||||
.setValue('#input textarea', contractCode, function () {}) |
||||
.waitForElementPresent('.contract .create', 2000) |
||||
checkCompiledContracts(browser, compiledContractNames, callback) |
||||
} |
||||
|
@ -0,0 +1,7 @@ |
||||
module.exports = function (browser, callback) { |
||||
browser |
||||
.url('http://127.0.0.1:8080/#version=builtin') |
||||
.injectScript('test-browser/helpers/applytestmode.js', function () { |
||||
callback() |
||||
}) |
||||
} |
@ -1,79 +0,0 @@ |
||||
'use strict' |
||||
|
||||
module.exports = { |
||||
'testSimpleContract': { |
||||
'sources': { |
||||
'Untitled': 'contract test1 {} contract test2 {}' |
||||
} |
||||
}, |
||||
'ballot': { |
||||
'sources': { |
||||
'Untitled': `pragma solidity ^0.4.0
|
||||
contract Ballot { |
||||
|
||||
struct Voter { |
||||
uint weight |
||||
bool voted |
||||
uint8 vote |
||||
address delegate |
||||
} |
||||
struct Proposal { |
||||
uint voteCount |
||||
} |
||||
|
||||
address chairperson |
||||
mapping(address => Voter) voters |
||||
Proposal[] proposals |
||||
|
||||
/// Create a new ballot with $(_numProposals) different proposals.
|
||||
function Ballot(uint8 _numProposals) { |
||||
chairperson = msg.sender |
||||
voters[chairperson].weight = 1 |
||||
proposals.length = _numProposals |
||||
} |
||||
|
||||
/// Give $(voter) the right to vote on this ballot.
|
||||
/// May only be called by $(chairperson).
|
||||
function giveRightToVote(address voter) { |
||||
if (msg.sender != chairperson || voters[voter].voted) return |
||||
voters[voter].weight = 1 |
||||
} |
||||
|
||||
/// Delegate your vote to the voter $(to).
|
||||
function delegate(address to) { |
||||
Voter sender = voters[msg.sender] // assigns reference
|
||||
if (sender.voted) return |
||||
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) |
||||
to = voters[to].delegate |
||||
if (to == msg.sender) return |
||||
sender.voted = true |
||||
sender.delegate = to |
||||
Voter delegate = voters[to] |
||||
if (delegate.voted) |
||||
proposals[delegate.vote].voteCount += sender.weight |
||||
else |
||||
delegate.weight += sender.weight |
||||
} |
||||
|
||||
/// Give a single vote to proposal $(proposal).
|
||||
function vote(uint8 proposal) { |
||||
Voter sender = voters[msg.sender] |
||||
if (sender.voted || proposal >= proposals.length) return |
||||
sender.voted = true |
||||
sender.vote = proposal |
||||
proposals[proposal].voteCount += sender.weight |
||||
} |
||||
|
||||
function winningProposal() constant returns (uint8 winningProposal) { |
||||
uint256 winningVoteCount = 0 |
||||
for (uint8 proposal = 0; proposal < proposals.length; proposal++) |
||||
if (proposals[proposal].voteCount > winningVoteCount) { |
||||
winningVoteCount = proposals[proposal].voteCount |
||||
winningProposal = proposal |
||||
} |
||||
} |
||||
} |
||||
` |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue