Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
e748b239
Commit
e748b239
authored
Nov 20, 2018
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comment test for now (needs to be rewriten with new api)
parent
8c14aba2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
190 additions
and
190 deletions
+190
-190
tests.js
remix-debug/test/tests.js
+190
-190
No files found.
remix-debug/test/tests.js
View file @
e748b239
'use strict'
//
'use strict'
var
tape
=
require
(
'tape'
)
//
var tape = require('tape')
var
remixLib
=
require
(
'remix-lib'
)
//
var remixLib = require('remix-lib')
var
compilerInput
=
remixLib
.
helpers
.
compiler
.
compilerInput
//
var compilerInput = remixLib.helpers.compiler.compilerInput
var
vmCall
=
require
(
'./vmCall'
)
//
var vmCall = require('./vmCall')
var
Debugger
=
require
(
'../src/Ethdebugger'
)
//
var Debugger = require('../src/Ethdebugger')
var
compiler
=
require
(
'solc'
)
//
var compiler = require('solc')
//
require
(
'./decoder/decodeInfo.js'
)
//
require('./decoder/decodeInfo.js')
require
(
'./decoder/storageLocation.js'
)
//
require('./decoder/storageLocation.js')
require
(
'./decoder/storageDecoder.js'
)
//
require('./decoder/storageDecoder.js')
require
(
'./decoder/localDecoder.js'
)
//
require('./decoder/localDecoder.js')
//
var
BreakpointManager
=
remixLib
.
code
.
BreakpointManager
//
var BreakpointManager = remixLib.code.BreakpointManager
//
tape
(
'debug contract'
,
function
(
t
)
{
//
tape('debug contract', function (t) {
t
.
plan
(
12
)
//
t.plan(12)
var
privateKey
=
Buffer
.
from
(
'dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'
,
'hex'
)
//
var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex')
var
vm
=
vmCall
.
initVM
(
t
,
privateKey
)
//
var vm = vmCall.initVM(t, privateKey)
var
output
=
compiler
.
compile
(
compilerInput
(
ballot
))
//
var output = compiler.compile(compilerInput(ballot))
output
=
JSON
.
parse
(
output
)
//
output = JSON.parse(output)
var
web3VM
=
new
remixLib
.
vm
.
Web3VMProvider
()
//
var web3VM = new remixLib.vm.Web3VMProvider()
web3VM
.
setVM
(
vm
)
//
web3VM.setVM(vm)
vmCall
.
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
output
.
contracts
[
'test.sol'
][
'Ballot'
].
evm
.
bytecode
.
object
,
(
error
,
txHash
)
=>
{
//
vmCall.sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['Ballot'].evm.bytecode.object, (error, txHash) => {
if
(
error
)
{
//
if (error) {
t
.
end
(
error
)
//
t.end(error)
}
else
{
//
} else {
web3VM
.
eth
.
getTransaction
(
txHash
,
(
error
,
tx
)
=>
{
//
web3VM.eth.getTransaction(txHash, (error, tx) => {
if
(
error
)
{
//
if (error) {
t
.
end
(
error
)
//
t.end(error)
}
else
{
//
} else {
var
debugManager
=
new
Debugger
({
//
var debugManager = new Debugger({
compilationResult
:
function
()
{
//
compilationResult: function () {
return
output
//
return output
}
//
}
})
//
})
//
debugManager
.
addProvider
(
'web3vmprovider'
,
web3VM
)
//
debugManager.addProvider('web3vmprovider', web3VM)
debugManager
.
switchProvider
(
'web3vmprovider'
)
//
debugManager.switchProvider('web3vmprovider')
//
debugManager
.
callTree
.
event
.
register
(
'callTreeReady'
,
()
=>
{
//
debugManager.callTree.event.register('callTreeReady', () => {
testDebugging
(
t
,
debugManager
)
//
testDebugging(t, debugManager)
})
//
})
//
debugManager
.
debug
(
tx
)
//
debugManager.debug(tx)
}
//
}
})
//
})
}
//
}
})
//
})
})
//
})
//
//
function
testDebugging
(
t
,
debugManager
)
{
//
function testDebugging (t, debugManager) {
// stack
//
// stack
debugManager
.
traceManager
.
getStackAt
(
4
,
(
error
,
callstack
)
=>
{
//
debugManager.traceManager.getStackAt(4, (error, callstack) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
t
.
equal
(
JSON
.
stringify
(
callstack
),
JSON
.
stringify
([
'0x0000000000000000000000000000000000000000000000000000000000000000'
]))
//
t.equal(JSON.stringify(callstack), JSON.stringify([ '0x0000000000000000000000000000000000000000000000000000000000000000' ]))
})
//
})
//
debugManager
.
traceManager
.
getStackAt
(
41
,
(
error
,
callstack
)
=>
{
//
debugManager.traceManager.getStackAt(41, (error, callstack) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
//
/*
//
/*
t.equal(JSON.stringify(callstack), JSON.stringify(['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000001', '0x000000000000000000000000000000000000000000000000000000000000002d']))
//
t.equal(JSON.stringify(callstack), JSON.stringify(['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000001', '0x000000000000000000000000000000000000000000000000000000000000002d']))
*/
//
*/
})
//
})
//
// storage
//
// storage
debugManager
.
traceManager
.
getCurrentCalledAddressAt
(
38
,
(
error
,
address
)
=>
{
//
debugManager.traceManager.getCurrentCalledAddressAt(38, (error, address) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
var
storageView
=
debugManager
.
storageViewAt
(
38
,
address
)
//
var storageView = debugManager.storageViewAt(38, address)
storageView
.
storageRange
((
error
,
storage
)
=>
{
//
storageView.storageRange((error, storage) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
t
.
equal
(
JSON
.
stringify
(
storage
),
JSON
.
stringify
({
'0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563'
:
{
key
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
value
:
'0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db'
}
}))
//
t.equal(JSON.stringify(storage), JSON.stringify({ '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563': { key: '0x0000000000000000000000000000000000000000000000000000000000000000', value: '0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db' } }))
})
//
})
})
//
})
//
debugManager
.
extractStateAt
(
116
,
(
error
,
state
)
=>
{
//
debugManager.extractStateAt(116, (error, state) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
debugManager
.
decodeStateAt
(
116
,
state
,
(
error
,
decodedState
)
=>
{
//
debugManager.decodeStateAt(116, state, (error, decodedState) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
t
.
equal
(
decodedState
[
'chairperson'
].
value
,
'0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB'
)
//
t.equal(decodedState['chairperson'].value, '0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB')
t
.
equal
(
decodedState
[
'chairperson'
].
type
,
'address'
)
//
t.equal(decodedState['chairperson'].type, 'address')
t
.
equal
(
decodedState
[
'proposals'
].
value
[
0
].
value
.
voteCount
.
value
,
'0'
)
//
t.equal(decodedState['proposals'].value[0].value.voteCount.value, '0')
t
.
equal
(
decodedState
[
'proposals'
].
value
[
0
].
value
.
voteCount
.
type
,
'uint256'
)
//
t.equal(decodedState['proposals'].value[0].value.voteCount.type, 'uint256')
t
.
equal
(
decodedState
[
'proposals'
].
value
[
0
].
type
,
'struct Ballot.Proposal'
)
//
t.equal(decodedState['proposals'].value[0].type, 'struct Ballot.Proposal')
t
.
equal
(
decodedState
[
'proposals'
].
length
,
'0x1'
)
//
t.equal(decodedState['proposals'].length, '0x1')
t
.
equal
(
decodedState
[
'proposals'
].
type
,
'struct Ballot.Proposal[]'
)
//
t.equal(decodedState['proposals'].type, 'struct Ballot.Proposal[]')
})
//
})
})
//
})
//
debugManager
.
traceManager
.
getCurrentCalledAddressAt
(
104
,
(
error
,
address
)
=>
{
//
debugManager.traceManager.getCurrentCalledAddressAt(104, (error, address) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
debugManager
.
sourceLocationFromVMTraceIndex
(
address
,
104
,
(
error
,
location
)
=>
{
//
debugManager.sourceLocationFromVMTraceIndex(address, 104, (error, location) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
debugManager
.
decodeLocalsAt
(
104
,
location
,
(
error
,
decodedlocals
)
=>
{
//
debugManager.decodeLocalsAt(104, location, (error, decodedlocals) => {
if
(
error
)
return
t
.
end
(
error
)
//
if (error) return t.end(error)
t
.
equal
(
JSON
.
stringify
(
decodedlocals
),
JSON
.
stringify
({
'p'
:
{
'value'
:
'45'
,
'type'
:
'uint256'
},
'addressLocal'
:
{
'value'
:
'0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB'
,
'type'
:
'address'
},
'proposalsLocals'
:
{
'value'
:
[{
'value'
:
{
'voteCount'
:
{
'value'
:
'0'
,
'type'
:
'uint256'
}},
'type'
:
'struct Ballot.Proposal'
}],
'length'
:
'0x1'
,
'type'
:
'struct Ballot.Proposal[]'
}}))
//
t.equal(JSON.stringify(decodedlocals), JSON.stringify({'p': {'value': '45', 'type': 'uint256'}, 'addressLocal': {'value': '0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB', 'type': 'address'}, 'proposalsLocals': {'value': [{'value': {'voteCount': {'value': '0', 'type': 'uint256'}}, 'type': 'struct Ballot.Proposal'}], 'length': '0x1', 'type': 'struct Ballot.Proposal[]'}}))
})
//
})
})
//
})
})
//
})
//
var
sourceMappingDecoder
=
new
remixLib
.
SourceMappingDecoder
()
//
var sourceMappingDecoder = new remixLib.SourceMappingDecoder()
var
breakPointManager
=
new
BreakpointManager
(
debugManager
,
(
rawLocation
)
=>
{
//
var breakPointManager = new BreakpointManager(debugManager, (rawLocation) => {
return
sourceMappingDecoder
.
convertOffsetToLineColumn
(
rawLocation
,
sourceMappingDecoder
.
getLinebreakPositions
(
ballot
))
//
return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot))
})
//
})
//
breakPointManager
.
add
({
fileName
:
'test.sol'
,
row
:
23
})
//
breakPointManager.add({fileName: 'test.sol', row: 23})
//
breakPointManager
.
event
.
register
(
'breakpointHit'
,
function
(
sourceLocation
,
step
)
{
//
breakPointManager.event.register('breakpointHit', function (sourceLocation, step) {
console
.
log
(
'breakpointHit'
)
//
console.log('breakpointHit')
t
.
equal
(
JSON
.
stringify
(
sourceLocation
),
JSON
.
stringify
({
start
:
587
,
length
:
1
,
file
:
0
,
jump
:
'-'
}))
//
t.equal(JSON.stringify(sourceLocation), JSON.stringify({ start: 587, length: 1, file: 0, jump: '-' }))
t
.
equal
(
step
,
74
)
//
t.equal(step, 74)
})
//
})
//
breakPointManager
.
event
.
register
(
'noBreakpointHit'
,
function
()
{
//
breakPointManager.event.register('noBreakpointHit', function () {
t
.
end
(
'noBreakpointHit'
)
//
t.end('noBreakpointHit')
console
.
log
(
'noBreakpointHit'
)
//
console.log('noBreakpointHit')
})
//
})
breakPointManager
.
jumpNextBreakpoint
(
0
,
true
)
//
breakPointManager.jumpNextBreakpoint(0, true)
}
//
}
//
var
ballot
=
`pragma solidity ^0.5.0;
//
var ballot = `pragma solidity ^0.5.0;
contract Ballot {
//
contract Ballot {
//
struct Voter {
//
struct Voter {
uint weight;
//
uint weight;
bool voted;
//
bool voted;
uint8 vote;
//
uint8 vote;
address delegate;
//
address delegate;
}
//
}
struct Proposal {
//
struct Proposal {
uint voteCount;
//
uint voteCount;
}
//
}
//
address chairperson;
//
address chairperson;
mapping(address => Voter) voters;
//
mapping(address => Voter) voters;
Proposal[] proposals;
//
Proposal[] proposals;
//
/// Create a new ballot with $(_numProposals) different proposals.
//
/// Create a new ballot with $(_numProposals) different proposals.
constructor() public {
//
constructor() public {
uint p = 45;
//
uint p = 45;
chairperson = msg.sender;
//
chairperson = msg.sender;
address addressLocal = msg.sender; // copy of state variable
//
address addressLocal = msg.sender; // copy of state variable
voters[chairperson].weight = 1;
//
voters[chairperson].weight = 1;
proposals.length = 1;
//
proposals.length = 1;
Proposal[] storage proposalsLocals = proposals; // copy of state variable
//
Proposal[] storage proposalsLocals = proposals; // copy of state variable
}
//
}
//
/// Give $(toVoter) the right to vote on this ballot.
//
/// Give $(toVoter) the right to vote on this ballot.
/// May only be called by $(chairperson).
//
/// May only be called by $(chairperson).
function giveRightToVote(address toVoter) public {
//
function giveRightToVote(address toVoter) public {
if (msg.sender != chairperson || voters[toVoter].voted) return;
//
if (msg.sender != chairperson || voters[toVoter].voted) return;
voters[toVoter].weight = 1;
//
voters[toVoter].weight = 1;
}
//
}
//
/// Delegate your vote to the voter $(to).
//
/// Delegate your vote to the voter $(to).
function delegate(address to) public {
//
function delegate(address to) public {
Voter storage sender = voters[msg.sender]; // assigns reference
//
Voter storage sender = voters[msg.sender]; // assigns reference
if (sender.voted) return;
//
if (sender.voted) return;
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
//
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
to = voters[to].delegate;
//
to = voters[to].delegate;
if (to == msg.sender) return;
//
if (to == msg.sender) return;
sender.voted = true;
//
sender.voted = true;
sender.delegate = to;
//
sender.delegate = to;
Voter storage delegateTo = voters[to];
//
Voter storage delegateTo = voters[to];
if (delegateTo.voted)
//
if (delegateTo.voted)
proposals[delegateTo.vote].voteCount += sender.weight;
//
proposals[delegateTo.vote].voteCount += sender.weight;
else
//
else
delegateTo.weight += sender.weight;
//
delegateTo.weight += sender.weight;
}
//
}
//
/// Give a single vote to proposal $(toProposal).
//
/// Give a single vote to proposal $(toProposal).
function vote(uint8 toProposal) public {
//
function vote(uint8 toProposal) public {
Voter storage sender = voters[msg.sender];
//
Voter storage sender = voters[msg.sender];
if (sender.voted || toProposal >= proposals.length) return;
//
if (sender.voted || toProposal >= proposals.length) return;
sender.voted = true;
//
sender.voted = true;
sender.vote = toProposal;
//
sender.vote = toProposal;
proposals[toProposal].voteCount += sender.weight;
//
proposals[toProposal].voteCount += sender.weight;
}
//
}
//
function winningProposal() public view returns (uint8 _winningProposal) {
//
function winningProposal() public view returns (uint8 _winningProposal) {
uint256 winningVoteCount = 0;
//
uint256 winningVoteCount = 0;
for (uint8 prop = 0; prop < proposals.length; prop++)
//
for (uint8 prop = 0; prop < proposals.length; prop++)
if (proposals[prop].voteCount > winningVoteCount) {
//
if (proposals[prop].voteCount > winningVoteCount) {
winningVoteCount = proposals[prop].voteCount;
//
winningVoteCount = proposals[prop].voteCount;
_winningProposal = prop;
//
_winningProposal = prop;
}
//
}
}
//
}
}`
//
}`
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment