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
29c4f59c
Unverified
Commit
29c4f59c
authored
May 04, 2020
by
yann300
Committed by
GitHub
May 04, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1471 from ethereum/yann300-patch-3
Enable remix-debug tests
parents
de2f2cd2
da5a16aa
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
440 additions
and
311 deletions
+440
-311
Mapping.js
remix-debug/src/solidity-decoder/types/Mapping.js
+0
-1
debugger.js
remix-debug/test/debugger.js
+283
-0
mappingStorage.js
remix-debug/test/decoder/contracts/mappingStorage.js
+0
-2
structArrayStorage.js
remix-debug/test/decoder/contracts/structArrayStorage.js
+108
-97
int.js
remix-debug/test/decoder/localsTests/int.js
+7
-6
misc2.js
remix-debug/test/decoder/localsTests/misc2.js
+1
-1
structArray.js
remix-debug/test/decoder/localsTests/structArray.js
+1
-1
vmCall.js
remix-debug/test/decoder/vmCall.js
+27
-9
tests.js
remix-debug/test/tests.js
+7
-190
vmCall.js
remix-debug/test/vmCall.js
+6
-4
No files found.
remix-debug/src/solidity-decoder/types/Mapping.js
View file @
29c4f59c
...
...
@@ -57,7 +57,6 @@ class Mapping extends RefType {
slot
:
mapLocation
}
ret
[
i
]
=
await
this
.
valueType
.
decodeFromStorage
(
globalLocation
,
storageResolver
)
console
.
log
(
'global location'
,
globalLocation
,
i
,
ret
[
i
])
}
return
ret
}
...
...
remix-debug/test/debugger.js
0 → 100644
View file @
29c4f59c
var
tape
=
require
(
'tape'
)
var
remixLib
=
require
(
'remix-lib'
)
var
compilerInput
=
remixLib
.
helpers
.
compiler
.
compilerInput
var
vmCall
=
require
(
'./vmCall'
)
var
Debugger
=
require
(
'../src/Ethdebugger'
)
var
compiler
=
require
(
'solc'
)
var
ballot
=
`pragma solidity >=0.4.22 <0.7.0;
/**
* @title Ballot
* @dev Implements voting process along with vote delegation
*/
contract Ballot {
struct Voter {
uint weight; // weight is accumulated by delegation
bool voted; // if true, that person already voted
address delegate; // person delegated to
uint vote; // index of the voted proposal
}
struct Proposal {
// If you can limit the length to a certain number of bytes,
// always use one of bytes1 to bytes32 because they are much cheaper
bytes32 name; // short name (up to 32 bytes)
uint voteCount; // number of accumulated votes
}
address public chairperson;
mapping(address => Voter) public voters;
Proposal[] public proposals;
/**
* @dev Create a new ballot to choose one of 'proposalNames'.
* @param proposalNames names of proposals
*/
constructor(bytes32[] memory proposalNames) public {
uint p = 45;
chairperson = msg.sender;
address addressLocal = msg.sender; // copy of state variable
voters[chairperson].weight = 1;
for (uint i = 0; i < proposalNames.length; i++) {
// 'Proposal({...})' creates a temporary
// Proposal object and 'proposals.push(...)'
// appends it to the end of 'proposals'.
proposals.push(Proposal({
name: proposalNames[i],
voteCount: 0
}));
}
Proposal[] storage proposalsLocals = proposals; // copy of state variable
}
/**
* @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'.
* @param voter address of voter
*/
function giveRightToVote(address voter) public {
require(
msg.sender == chairperson,
"Only chairperson can give right to vote."
);
require(
!voters[voter].voted,
"The voter already voted."
);
require(voters[voter].weight == 0);
voters[voter].weight = 1;
}
/**
* @dev Delegate your vote to the voter 'to'.
* @param to address to which vote is delegated
*/
function delegate(address to) public {
Voter storage sender = voters[msg.sender];
require(!sender.voted, "You already voted.");
require(to != msg.sender, "Self-delegation is disallowed.");
while (voters[to].delegate != address(0)) {
to = voters[to].delegate;
// We found a loop in the delegation, not allowed.
require(to != msg.sender, "Found loop in delegation.");
}
sender.voted = true;
sender.delegate = to;
Voter storage delegate_ = voters[to];
if (delegate_.voted) {
// If the delegate already voted,
// directly add to the number of votes
proposals[delegate_.vote].voteCount += sender.weight;
} else {
// If the delegate did not vote yet,
// add to her weight.
delegate_.weight += sender.weight;
}
}
/**
* @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'.
* @param proposal index of proposal in the proposals array
*/
function vote(uint proposal) public {
Voter storage sender = voters[msg.sender];
require(sender.weight != 0, "Has no right to vote");
require(!sender.voted, "Already voted.");
sender.voted = true;
sender.vote = proposal;
// If 'proposal' is out of the range of the array,
// this will throw automatically and revert all
// changes.
proposals[proposal].voteCount += sender.weight;
}
/**
* @dev Computes the winning proposal taking all previous votes into account.
* @return winningProposal_ index of winning proposal in the proposals array
*/
function winningProposal() public view
returns (uint winningProposal_)
{
uint winningVoteCount = 0;
for (uint p = 0; p < proposals.length; p++) {
if (proposals[p].voteCount > winningVoteCount) {
winningVoteCount = proposals[p].voteCount;
winningProposal_ = p;
}
}
}
/**
* @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then
* @return winnerName_ the name of the winner
*/
function winnerName() public view
returns (bytes32 winnerName_)
{
winnerName_ = proposals[winningProposal()].name;
}
}
`
var
BreakpointManager
=
remixLib
.
code
.
BreakpointManager
var
privateKey
=
Buffer
.
from
(
'dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'
,
'hex'
)
var
vm
=
vmCall
.
initVM
(
privateKey
)
var
output
=
compiler
.
compile
(
compilerInput
(
ballot
))
output
=
JSON
.
parse
(
output
)
var
web3VM
=
new
remixLib
.
vm
.
Web3VMProvider
()
web3VM
.
setVM
(
vm
)
const
param
=
'0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000148656c6c6f20576f726c64210000000000000000000000000000000000000000'
vmCall
.
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
output
.
contracts
[
'test.sol'
][
'Ballot'
].
evm
.
bytecode
.
object
+
param
,
(
error
,
txHash
)
=>
{
console
.
log
(
error
,
txHash
)
if
(
error
)
{
throw
error
}
else
{
web3VM
.
eth
.
getTransaction
(
txHash
,
(
error
,
tx
)
=>
{
if
(
error
)
{
throw
error
}
else
{
var
debugManager
=
new
Debugger
({
compilationResult
:
function
()
{
return
{
data
:
output
}
},
web3
:
web3VM
})
debugManager
.
callTree
.
event
.
register
(
'callTreeReady'
,
()
=>
{
testDebugging
(
debugManager
)
})
debugManager
.
callTree
.
event
.
register
(
'callTreeNotReady'
,
(
error
)
=>
{
console
.
error
(
error
)
throw
error
})
debugManager
.
callTree
.
event
.
register
(
'callTreeBuildFailed'
,
(
error
)
=>
{
console
.
error
(
error
)
throw
error
})
debugManager
.
debug
(
tx
)
}
})
}
})
function
testDebugging
(
debugManager
)
{
// stack
tape
(
'traceManager.getStackAt 4'
,
(
t
)
=>
{
t
.
plan
(
1
)
debugManager
.
traceManager
.
getStackAt
(
4
,
(
error
,
callstack
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
t
.
equal
(
JSON
.
stringify
(
callstack
),
JSON
.
stringify
([
'0x0000000000000000000000000000000000000000000000000000000000000000'
]))
})
})
tape
(
'traceManager.getStackAt 41'
,
(
t
)
=>
{
t
.
plan
(
1
)
debugManager
.
traceManager
.
getStackAt
(
41
,
(
error
,
callstack
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
t
.
equal
(
JSON
.
stringify
(
callstack
),
JSON
.
stringify
([
'0x0000000000000000000000000000000000000000000000000000000000000080'
,
'0x0000000000000000000000000000000000000000000000000000000000000020'
,
'0x0000000000000000000000000000000000000000000000000000000000000080'
,
'0x00000000000000000000000000000000000000000000000000000000000000e0'
,
'0x00000000000000000000000000000000000000000000000000000000000000e0'
]))
})
})
// storage
tape
(
'traceManager.getCurrentCalledAddressAt'
,
(
t
)
=>
{
t
.
plan
(
1
)
debugManager
.
traceManager
.
getCurrentCalledAddressAt
(
38
,
(
error
,
address
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
console
.
log
(
address
)
var
storageView
=
debugManager
.
storageViewAt
(
196
,
address
)
storageView
.
storageRange
((
error
,
storage
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
t
.
equal
(
JSON
.
stringify
(
storage
),
JSON
.
stringify
({
'0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563'
:
{
key
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
value
:
'0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db'
}
}))
})
})
})
tape
(
'traceManager.decodeStateAt'
,
(
t
)
=>
{
t
.
plan
(
7
)
debugManager
.
extractStateAt
(
312
,
(
error
,
state
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
debugManager
.
decodeStateAt
(
312
,
state
,
(
error
,
decodedState
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
console
.
log
(
decodedState
)
t
.
equal
(
decodedState
[
'chairperson'
].
value
,
'0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB'
)
t
.
equal
(
decodedState
[
'chairperson'
].
type
,
'address'
)
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
].
type
,
'struct Ballot.Proposal'
)
t
.
equal
(
decodedState
[
'proposals'
].
length
,
'0x1'
)
t
.
equal
(
decodedState
[
'proposals'
].
type
,
'struct Ballot.Proposal[]'
)
})
})
})
tape
(
'traceManager.decodeLocalsAt'
,
(
t
)
=>
{
t
.
plan
(
1
)
const
tested
=
JSON
.
parse
(
'{"proposalNames":{"value":[{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"}],"length":"0x1","type":"bytes32[]"},"p":{"value":"45","type":"uint256"},"addressLocal":{"value":"0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB","type":"address"},"i":{"value":"2","type":"uint256"},"proposalsLocals":{"value":[{"value":{"name":{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"},"voteCount":{"value":"0","type":"uint256"}},"type":"struct Ballot.Proposal"}],"length":"0x1","type":"struct Ballot.Proposal[]"}}'
)
debugManager
.
traceManager
.
getCurrentCalledAddressAt
(
330
,
(
error
,
address
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
debugManager
.
sourceLocationFromVMTraceIndex
(
address
,
330
,
(
error
,
location
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
debugManager
.
decodeLocalsAt
(
330
,
location
,
(
error
,
decodedlocals
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
t
.
equal
(
JSON
.
stringify
(
decodedlocals
),
JSON
.
stringify
(
tested
))
})
})
})
})
tape
(
'breakPointManager'
,
(
t
)
=>
{
t
.
plan
(
2
)
var
sourceMappingDecoder
=
new
remixLib
.
SourceMappingDecoder
()
var
breakPointManager
=
new
BreakpointManager
(
debugManager
,
(
rawLocation
)
=>
{
return
sourceMappingDecoder
.
convertOffsetToLineColumn
(
rawLocation
,
sourceMappingDecoder
.
getLinebreakPositions
(
ballot
))
})
breakPointManager
.
add
({
fileName
:
'test.sol'
,
row
:
38
})
breakPointManager
.
event
.
register
(
'breakpointHit'
,
function
(
sourceLocation
,
step
)
{
console
.
log
(
'breakpointHit'
)
t
.
equal
(
JSON
.
stringify
(
sourceLocation
),
JSON
.
stringify
({
start
:
1153
,
length
:
6
,
file
:
0
,
jump
:
'-'
}))
t
.
equal
(
step
,
212
)
})
breakPointManager
.
event
.
register
(
'noBreakpointHit'
,
function
()
{
t
.
end
(
'noBreakpointHit'
)
console
.
log
(
'noBreakpointHit'
)
})
breakPointManager
.
jumpNextBreakpoint
(
0
,
true
)
})
}
remix-debug/test/decoder/contracts/mappingStorage.js
View file @
29c4f59c
module
.
exports
=
{
contract
:
`
pragma solidity ^0.5.0;
contract SimpleMappingState {
uint _num;
mapping(string => uint) _iBreakSolidityState;
...
...
remix-debug/test/decoder/contracts/structArrayStorage.js
View file @
29c4f59c
...
...
@@ -41,103 +41,114 @@ module.exports = {
i5[5] = -2344;
i5[6] = 3254;
idyn5.length = 9;
idyn5[0] = -2134;
idyn5[1] = 345;
idyn5[2] = -3246;
idyn5[3] = 4357;
idyn5[4] = 324;
idyn5[5] = -2344;
idyn5[6] = 3254;
idyn5[7] = -254;
idyn5[8] = -2354;
dyn1[0].length = 1;
dyn1[1].length = 3;
dyn1[2].length = 10;
dyn1[3].length = 2;
dyn1[0][0] = 3;
dyn1[1][0] = 12;
dyn1[1][1] = -12;
dyn1[1][2] = -1234;
dyn1[2][0] = 1;
dyn1[2][1] = 12;
dyn1[2][2] = 1235;
dyn1[2][3] = -12;
dyn1[2][4] = -123456;
dyn1[2][5] = -23435435;
dyn1[2][6] = 543543;
dyn1[2][7] = 2;
dyn1[2][8] = -1;
dyn1[2][9] = 232432;
dyn1[3][0] = 232432;
dyn1[3][1] = 232432;
dyn2.length = 2;
dyn2[0][0].length = 3;
dyn2[0][1].length = 3;
dyn2[0][2].length = 3;
dyn2[0][3].length = 3;
dyn2[1][0].length = 3;
dyn2[1][1].length = 3;
dyn2[1][2].length = 3;
dyn2[1][3].length = 3;
dyn2[0][0][0] = 23;
dyn2[0][0][1] = -23;
dyn2[0][0][2] = -28;
dyn2[0][1][0] = 23;
dyn2[0][1][1] = -23;
dyn2[0][1][2] = -28;
dyn2[0][2][0] = 23;
dyn2[0][2][1] = -23;
dyn2[0][2][2] = -28;
dyn2[0][3][0] = 23;
dyn2[0][3][1] = -23;
dyn2[0][3][2] = -28;
dyn2[1][0][0] = 23;
dyn2[1][0][1] = -23;
dyn2[1][0][2] = -28;
dyn2[1][1][0] = 23;
dyn2[1][1][1] = -23;
dyn2[1][1][2] = -28;
dyn2[1][2][0] = 23;
dyn2[1][2][1] = -23;
dyn2[1][2][2] = -28;
dyn2[1][3][0] = 23;
dyn2[1][3][1] = -23;
dyn2[1][3][2] = -28;
arrayStruct[0].length = 2;
arrayStruct[1].length = 1;
arrayStruct[2].length = 3;
arrayStruct[0][0].i8 = 34;
arrayStruct[0][0].str = 'test_str_short';
arrayStruct[0][1].i8 = -123;
arrayStruct[0][1].str = 'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long';
arrayStruct[1][0].i8 = 50;
arrayStruct[1][0].str = 'test_str_short';
arrayStruct[2][0].i8 = 60;
arrayStruct[2][0].str = 'test_str_short';
arrayStruct[2][1].i8 = 84;
arrayStruct[2][1].str = 'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long';
arrayStruct[2][2].i8 = -34;
arrayStruct[2][2].str = 'test_str_short';
idyn5.push(-2134);
idyn5.push(345);
idyn5.push(-3246);
idyn5.push(4357);
idyn5.push(324);
idyn5.push(-2344);
idyn5.push(3254);
idyn5.push(-254);
idyn5.push(-2354);
dyn1[0].push(3);
dyn1[1].push(12);
dyn1[1].push(-12);
dyn1[1].push(-1234);
dyn1[2].push(1);
dyn1[2].push(12);
dyn1[2].push(1235);
dyn1[2].push(-12);
dyn1[2].push(-123456);
dyn1[2].push(-23435435);
dyn1[2].push(543543);
dyn1[2].push(2);
dyn1[2].push(-1);
dyn1[2].push(232432);
dyn1[3].push(232432);
dyn1[3].push(232432);
int32[][4] memory e1;
e1[0] = new int32[](3);
e1[1] = new int32[](3);
e1[2] = new int32[](3);
e1[3] = new int32[](3);
e1[0][0] = 23;
e1[0][1] = -23;
e1[0][2] = -28;
e1[1][0] = 23;
e1[1][1] = -23;
e1[1][2] = -28;
e1[2][0] = 23;
e1[2][1] = -23;
e1[2][2] = -28;
e1[3][0] = 23;
e1[3][1] = -23;
e1[3][2] = -28;
dyn2.push(e1);
int32[][4] memory e2;
e2[0] = new int32[](3);
e2[1] = new int32[](3);
e2[2] = new int32[](3);
e2[3] = new int32[](3);
e2[0][0] = 23;
e2[0][1] = -23;
e2[0][2] = -28;
e2[1][0] = 23;
e2[1][1] = -23;
e2[1][2] = -28;
e2[2][0] = 23;
e2[2][1] = -23;
e2[2][2] = -28;
e2[3][0] = 23;
e2[3][1] = -23;
e2[3][2] = -28;
dyn2.push(e2);
simpleStruct memory s1;
s1.i8 = 34;
s1.str = 'test_str_short';
simpleStruct memory s2;
s1.i8 = -123;
s1.str = 'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long';
arrayStruct[0].push(s1);
arrayStruct[0].push(s2);
simpleStruct memory s3;
s3.i8 = 50;
s3.str = 'test_str_short';
arrayStruct[1].push(s3);
simpleStruct memory s4;
s4.i8 = 60;
s4.str = 'test_str_short';
simpleStruct memory s5;
s5.i8 = 84;
s5.str = 'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long';
simpleStruct memory s6;
s5.i8 = -34;
s5.str = 'test_str_short';
arrayStruct[2].push(s4);
arrayStruct[2].push(s5);
arrayStruct[2].push(s6);
}
}
`
,
...
...
remix-debug/test/decoder/localsTests/int.js
View file @
29c4f59c
...
...
@@ -37,13 +37,14 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
})
callTree
.
event
.
register
(
'callTreeReady'
,
(
scopes
,
scopeStarts
)
=>
{
try
{
console
.
log
(
scopeStarts
)
st
.
equals
(
scopeStarts
[
0
],
''
)
st
.
equals
(
scopeStarts
[
13
],
'1'
)
st
.
equals
(
scopeStarts
[
10
3
],
'2'
)
st
.
equals
(
scopeStarts
[
11
6
],
'2.1'
)
st
.
equals
(
scopeStarts
[
13
5
],
'3'
)
st
.
equals
(
scopeStarts
[
1
51
],
'4'
)
st
.
equals
(
scopeStarts
[
1
64
],
'4.1'
)
st
.
equals
(
scopeStarts
[
10
1
],
'2'
)
st
.
equals
(
scopeStarts
[
11
3
],
'2.1'
)
st
.
equals
(
scopeStarts
[
13
1
],
'3'
)
st
.
equals
(
scopeStarts
[
1
46
],
'4'
)
st
.
equals
(
scopeStarts
[
1
58
],
'4.1'
)
st
.
equals
(
scopes
[
''
].
locals
[
'ui8'
].
type
.
typeName
,
'uint8'
)
st
.
equals
(
scopes
[
''
].
locals
[
'ui16'
].
type
.
typeName
,
'uint16'
)
st
.
equals
(
scopes
[
''
].
locals
[
'ui32'
].
type
.
typeName
,
'uint32'
)
...
...
@@ -87,7 +88,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
st
.
equals
(
locals
[
'ishrink'
].
value
,
'2'
)
})
helper
.
decodeLocals
(
st
,
1
71
,
traceManager
,
callTree
,
function
(
locals
)
{
helper
.
decodeLocals
(
st
,
1
05
,
traceManager
,
callTree
,
function
(
locals
)
{
try
{
st
.
equals
(
locals
[
'ui8'
].
value
,
'123'
)
st
.
equals
(
Object
.
keys
(
locals
).
length
,
1
)
...
...
remix-debug/test/decoder/localsTests/misc2.js
View file @
29c4f59c
...
...
@@ -31,7 +31,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
st
.
fail
(
error
)
})
callTree
.
event
.
register
(
'callTreeReady'
,
(
scopes
,
scopeStarts
)
=>
{
helper
.
decodeLocals
(
st
,
51
,
traceManager
,
callTree
,
function
(
locals
)
{
helper
.
decodeLocals
(
st
,
49
,
traceManager
,
callTree
,
function
(
locals
)
{
try
{
st
.
equals
(
locals
[
'dynbytes'
].
value
,
'0x64796e616d69636279746573'
)
st
.
equals
(
locals
[
'smallstring'
].
value
,
'test_test_test'
)
...
...
remix-debug/test/decoder/localsTests/structArray.js
View file @
29c4f59c
...
...
@@ -31,7 +31,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
st
.
fail
(
error
)
})
callTree
.
event
.
register
(
'callTreeReady'
,
(
scopes
,
scopeStarts
)
=>
{
helper
.
decodeLocals
(
st
,
1
699
,
traceManager
,
callTree
,
function
(
locals
)
{
helper
.
decodeLocals
(
st
,
1
587
,
traceManager
,
callTree
,
function
(
locals
)
{
try
{
st
.
equals
(
locals
[
'bytesSimple'
].
length
,
'0x14'
)
st
.
equals
(
locals
[
'bytesSimple'
].
value
,
'0x746573745f7375706572'
)
...
...
remix-debug/test/decoder/vmCall.js
View file @
29c4f59c
...
...
@@ -4,6 +4,7 @@ var Tx = require('ethereumjs-tx').Transaction
var
Block
=
require
(
'ethereumjs-block'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
var
remixLib
=
require
(
'remix-lib'
)
var
EthJSVM
=
require
(
'ethereumjs-vm'
).
default
function
sendTx
(
vm
,
from
,
to
,
value
,
data
,
cb
)
{
var
tx
=
new
Tx
({
...
...
@@ -23,24 +24,41 @@ function sendTx (vm, from, to, value, data, cb) {
transactions
:
[],
uncleHeaders
:
[]
})
vm
.
runTx
({
block
:
block
,
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
},
function
(
error
,
result
)
{
try
{
vm
.
runTx
({
block
:
block
,
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
}).
then
(
function
(
result
)
{
setTimeout
(()
=>
{
cb
(
error
,
utileth
.
bufferToHex
(
tx
.
hash
()))
cb
(
null
,
utileth
.
bufferToHex
(
tx
.
hash
()))
},
500
)
}).
catch
((
error
)
=>
{
console
.
error
(
error
)
cb
(
error
)
})
}
catch
(
e
)
{
console
.
error
(
e
)
}
}
function
createVm
(
hardfork
)
{
// const stateManager = new StateManagerCommonStorageDump({})
// stateManager.checkpoint(() => {})
const
vm
=
new
EthJSVM
({
activatePrecompiles
:
true
,
hardfork
})
vm
.
blockchain
.
validate
=
false
const
web3vm
=
new
remixLib
.
vm
.
Web3VMProvider
()
web3vm
.
setVM
(
vm
)
return
{
vm
,
web3vm
,
stateManager
:
vm
.
stateManager
}
}
/*
Init VM / Send Transaction
*/
function
initVM
(
st
,
privateKey
)
{
var
VM
=
require
(
'ethereumjs-vm'
).
default
var
Web3Providers
=
remixLib
.
vm
.
Web3Providers
var
VM
=
createVm
(
'muirGlacier'
)
const
vm
=
VM
.
vm
var
address
=
utileth
.
privateToAddress
(
privateKey
)
var
vm
=
new
VM
({
enableHomestead
:
true
,
activatePrecompiles
:
true
})
vm
.
stateManager
.
getAccount
(
address
,
(
error
,
account
)
=>
{
if
(
error
)
return
console
.
log
(
error
)
...
...
@@ -50,7 +68,7 @@ function initVM (st, privateKey) {
})
})
var
web3Providers
=
new
Web3Providers
()
var
web3Providers
=
new
remixLib
.
vm
.
Web3Providers
()
web3Providers
.
addVM
(
'VM'
,
vm
)
web3Providers
.
get
(
'VM'
,
function
(
error
,
obj
)
{
if
(
error
)
{
...
...
remix-debug/test/tests.js
View file @
29c4f59c
// 'use strict'
// var tape = require('tape')
// var remixLib = require('remix-lib')
// var compilerInput = remixLib.helpers.compiler.compilerInput
// var vmCall = require('./vmCall')
// var Debugger = require('../src/Ethdebugger')
// var compiler = require('solc')
//
// require('./decoder/decodeInfo.js')
// require('./decoder/storageLocation.js')
// require('./decoder/storageDecoder.js')
// require('./decoder/localDecoder.js')
//
// var BreakpointManager = remixLib.code.BreakpointManager
//
// tape('debug contract', function (t) {
// t.plan(12)
// var privateKey = Buffer.from('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex')
// var vm = vmCall.initVM(t, privateKey)
// var output = compiler.compile(compilerInput(ballot))
// output = JSON.parse(output)
// var web3VM = new remixLib.vm.Web3VMProvider()
// web3VM.setVM(vm)
// vmCall.sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['Ballot'].evm.bytecode.object, (error, txHash) => {
// if (error) {
// t.end(error)
// } else {
// web3VM.eth.getTransaction(txHash, (error, tx) => {
// if (error) {
// t.end(error)
// } else {
// var debugManager = new Debugger({
// compilationResult: function () {
// return output
// }
// })
//
// debugManager.addProvider('web3vmprovider', web3VM)
// debugManager.switchProvider('web3vmprovider')
//
// debugManager.callTree.event.register('callTreeReady', () => {
// testDebugging(t, debugManager)
// })
//
// debugManager.debug(tx)
// }
// })
// }
// })
// })
//
//
// function testDebugging (t, debugManager) {
// // stack
// debugManager.traceManager.getStackAt(4, (error, callstack) => {
// if (error) return t.end(error)
// t.equal(JSON.stringify(callstack), JSON.stringify([ '0x0000000000000000000000000000000000000000000000000000000000000000' ]))
// })
//
// debugManager.traceManager.getStackAt(41, (error, callstack) => {
// if (error) return t.end(error)
//
// /*
// t.equal(JSON.stringify(callstack), JSON.stringify(['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000001', '0x000000000000000000000000000000000000000000000000000000000000002d']))
// */
// })
//
// // storage
// debugManager.traceManager.getCurrentCalledAddressAt(38, (error, address) => {
// if (error) return t.end(error)
// var storageView = debugManager.storageViewAt(38, address)
// storageView.storageRange((error, storage) => {
// if (error) return t.end(error)
// t.equal(JSON.stringify(storage), JSON.stringify({ '0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563': { key: '0x0000000000000000000000000000000000000000000000000000000000000000', value: '0x0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db' } }))
// })
// })
//
// debugManager.extractStateAt(116, (error, state) => {
// if (error) return t.end(error)
// debugManager.decodeStateAt(116, state, (error, decodedState) => {
// if (error) return t.end(error)
// t.equal(decodedState['chairperson'].value, '0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB')
// t.equal(decodedState['chairperson'].type, 'address')
// 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].type, 'struct Ballot.Proposal')
// t.equal(decodedState['proposals'].length, '0x1')
// t.equal(decodedState['proposals'].type, 'struct Ballot.Proposal[]')
// })
// })
//
// debugManager.traceManager.getCurrentCalledAddressAt(104, (error, address) => {
// if (error) return t.end(error)
// debugManager.sourceLocationFromVMTraceIndex(address, 104, (error, location) => {
// if (error) return t.end(error)
// debugManager.decodeLocalsAt(104, location, (error, decodedlocals) => {
// 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[]'}}))
// })
// })
// })
//
// var sourceMappingDecoder = new remixLib.SourceMappingDecoder()
// var breakPointManager = new BreakpointManager(debugManager, (rawLocation) => {
// return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot))
// })
//
// breakPointManager.add({fileName: 'test.sol', row: 23})
//
// breakPointManager.event.register('breakpointHit', function (sourceLocation, step) {
// console.log('breakpointHit')
// t.equal(JSON.stringify(sourceLocation), JSON.stringify({ start: 587, length: 1, file: 0, jump: '-' }))
// t.equal(step, 74)
// })
//
// breakPointManager.event.register('noBreakpointHit', function () {
// t.end('noBreakpointHit')
// console.log('noBreakpointHit')
// })
// breakPointManager.jumpNextBreakpoint(0, true)
// }
//
// var ballot = `pragma solidity ^0.5.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.
// constructor() public {
// uint p = 45;
// chairperson = msg.sender;
// address addressLocal = msg.sender; // copy of state variable
// voters[chairperson].weight = 1;
// proposals.length = 1;
// Proposal[] storage proposalsLocals = proposals; // copy of state variable
// }
//
// /// Give $(toVoter) the right to vote on this ballot.
// /// May only be called by $(chairperson).
// function giveRightToVote(address toVoter) public {
// if (msg.sender != chairperson || voters[toVoter].voted) return;
// voters[toVoter].weight = 1;
// }
//
// /// Delegate your vote to the voter $(to).
// function delegate(address to) public {
// Voter storage 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 storage delegateTo = voters[to];
// if (delegateTo.voted)
// proposals[delegateTo.vote].voteCount += sender.weight;
// else
// delegateTo.weight += sender.weight;
// }
//
// /// Give a single vote to proposal $(toProposal).
// function vote(uint8 toProposal) public {
// Voter storage sender = voters[msg.sender];
// if (sender.voted || toProposal >= proposals.length) return;
// sender.voted = true;
// sender.vote = toProposal;
// proposals[toProposal].voteCount += sender.weight;
// }
//
// function winningProposal() public view returns (uint8 _winningProposal) {
// uint256 winningVoteCount = 0;
// for (uint8 prop = 0; prop < proposals.length; prop++)
// if (proposals[prop].voteCount > winningVoteCount) {
// winningVoteCount = proposals[prop].voteCount;
// _winningProposal = prop;
// }
// }
// }`
'use strict'
require
(
'./decoder/decodeInfo.js'
)
require
(
'./decoder/storageLocation.js'
)
require
(
'./decoder/storageDecoder.js'
)
require
(
'./decoder/localDecoder.js'
)
require
(
'./debugger.js'
)
remix-debug/test/vmCall.js
View file @
29c4f59c
...
...
@@ -23,17 +23,20 @@ function sendTx (vm, from, to, value, data, cb) {
transactions
:
[],
uncleHeaders
:
[]
})
vm
.
runTx
({
block
:
block
,
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
}
,
function
(
error
,
result
)
{
vm
.
runTx
({
block
:
block
,
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
}
).
then
(
function
(
result
)
{
setTimeout
(()
=>
{
cb
(
error
,
utileth
.
bufferToHex
(
tx
.
hash
()))
cb
(
null
,
utileth
.
bufferToHex
(
tx
.
hash
()))
},
500
)
}).
catch
((
error
)
=>
{
console
.
error
(
error
)
cb
(
error
)
})
}
/*
Init VM / Send Transaction
*/
function
initVM
(
st
,
privateKey
)
{
function
initVM
(
privateKey
)
{
var
VM
=
require
(
'ethereumjs-vm'
).
default
var
Web3Providers
=
remixLib
.
vm
.
Web3Providers
var
address
=
utileth
.
privateToAddress
(
privateKey
)
...
...
@@ -56,7 +59,6 @@ function initVM (st, privateKey) {
if
(
error
)
{
var
mes
=
'provider TEST not defined'
console
.
log
(
mes
)
st
.
fail
(
mes
)
}
else
{
vm
.
web3
=
obj
}
...
...
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