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
eae7f2d0
Commit
eae7f2d0
authored
Sep 29, 2021
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor and fix remix-debug tests
parent
00c12168
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
157 additions
and
236 deletions
+157
-236
package.json
libs/remix-debug/package.json
+1
-0
debugger.ts
libs/remix-debug/test/debugger.ts
+12
-13
localDecoder.ts
libs/remix-debug/test/decoder/localDecoder.ts
+9
-10
calldata.ts
libs/remix-debug/test/decoder/localsTests/calldata.ts
+12
-9
int.ts
libs/remix-debug/test/decoder/localsTests/int.ts
+8
-8
misc.ts
libs/remix-debug/test/decoder/localsTests/misc.ts
+8
-8
misc2.ts
libs/remix-debug/test/decoder/localsTests/misc2.ts
+7
-7
structArray.ts
libs/remix-debug/test/decoder/localsTests/structArray.ts
+7
-7
mapping.ts
libs/remix-debug/test/decoder/stateTests/mapping.ts
+22
-17
vmCall.ts
libs/remix-debug/test/decoder/vmCall.ts
+0
-76
tests.ts
libs/remix-debug/test/tests.ts
+1
-1
vmCall.ts
libs/remix-debug/test/vmCall.ts
+36
-47
web3VmProvider.ts
libs/remix-lib/src/web3Provider/web3VmProvider.ts
+5
-0
vm-context.ts
libs/remix-simulator/src/vm-context.ts
+29
-33
No files found.
libs/remix-debug/package.json
View file @
eae7f2d0
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
"@ethereumjs/vm"
:
"^5.5.0"
,
"@ethereumjs/vm"
:
"^5.5.0"
,
"@remix-project/remix-astwalker"
:
"^0.0.37"
,
"@remix-project/remix-astwalker"
:
"^0.0.37"
,
"@remix-project/remix-lib"
:
"^0.5.7"
,
"@remix-project/remix-lib"
:
"^0.5.7"
,
"@remix-project/remix-simulator"
:
"^0.2.7"
,
"async"
:
"^2.6.2"
,
"async"
:
"^2.6.2"
,
"commander"
:
"^2.19.0"
,
"commander"
:
"^2.19.0"
,
"deep-equal"
:
"^1.0.1"
,
"deep-equal"
:
"^1.0.1"
,
...
...
libs/remix-debug/test/debugger.ts
View file @
eae7f2d0
...
@@ -7,7 +7,6 @@ import { BreakpointManager } from '../src/code/breakpointManager'
...
@@ -7,7 +7,6 @@ import { BreakpointManager } from '../src/code/breakpointManager'
var
compiler
=
require
(
'solc'
)
var
compiler
=
require
(
'solc'
)
var
vmCall
=
require
(
'./vmCall'
)
var
vmCall
=
require
(
'./vmCall'
)
var
remixLib
=
require
(
'@remix-project/remix-lib'
)
var
ballot
=
`pragma solidity >=0.4.22 <0.8.0;
var
ballot
=
`pragma solidity >=0.4.22 <0.8.0;
...
@@ -151,19 +150,17 @@ contract Ballot {
...
@@ -151,19 +150,17 @@ contract Ballot {
`
;
`
;
(
async
()
=>
{
(
async
()
=>
{
var
privateKey
=
Buffer
.
from
(
'dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'
,
'hex'
)
var
privateKey
=
Buffer
.
from
(
'503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb'
,
'hex'
)
var
vm
=
await
vmCall
.
initVM
(
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
()
web3VM
.
setVM
(
vm
)
const
param
=
'0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000148656c6c6f20576f726c64210000000000000000000000000000000000000000'
const
param
=
'0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000148656c6c6f20576f726c64210000000000000000000000000000000000000000'
vmCall
.
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
output
.
contracts
[
'test.sol'
][
'Ballot'
].
evm
.
bytecode
.
object
+
param
,
(
error
,
txHash
)
=>
{
const
web3
=
await
vmCall
.
getWeb3
()
console
.
log
(
error
,
txHash
)
vmCall
.
sendTx
(
web3
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
output
.
contracts
[
'test.sol'
][
'Ballot'
].
evm
.
bytecode
.
object
+
param
,
(
error
,
hash
)
=>
{
console
.
log
(
error
,
hash
)
if
(
error
)
{
if
(
error
)
{
throw
error
throw
error
}
else
{
}
else
{
web3
VM
.
eth
.
getTransaction
(
txH
ash
,
(
error
,
tx
)
=>
{
web3
.
eth
.
getTransaction
(
h
ash
,
(
error
,
tx
)
=>
{
if
(
error
)
{
if
(
error
)
{
throw
error
throw
error
}
else
{
}
else
{
...
@@ -171,7 +168,7 @@ contract Ballot {
...
@@ -171,7 +168,7 @@ contract Ballot {
compilationResult
:
function
()
{
compilationResult
:
function
()
{
return
{
data
:
output
}
return
{
data
:
output
}
},
},
web3
:
web3
VM
web3
:
web3
})
})
debugManager
.
callTree
.
event
.
register
(
'callTreeReady'
,
()
=>
{
debugManager
.
callTree
.
event
.
register
(
'callTreeReady'
,
()
=>
{
...
@@ -230,7 +227,7 @@ function testDebugging (debugManager) {
...
@@ -230,7 +227,7 @@ function testDebugging (debugManager) {
var
storageView
=
debugManager
.
storageViewAt
(
196
,
address
)
var
storageView
=
debugManager
.
storageViewAt
(
196
,
address
)
storageView
.
storageRange
().
then
((
storage
)
=>
{
storageView
.
storageRange
().
then
((
storage
)
=>
{
t
.
equal
(
JSON
.
stringify
(
storage
),
JSON
.
stringify
({
'0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563'
:
{
key
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
value
:
'0x000000000000000000000000
4b0897b0513fdc7c541b6d9d7e929c4e5364d2db
'
}
}))
t
.
equal
(
JSON
.
stringify
(
storage
),
JSON
.
stringify
({
'0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563'
:
{
key
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
value
:
'0x000000000000000000000000
5b38da6a701c568545dcfcb03fcb875f56beddc4
'
}
}))
}).
catch
((
error
)
=>
{
}).
catch
((
error
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
if
(
error
)
return
t
.
end
(
error
)
})
})
...
@@ -245,7 +242,7 @@ function testDebugging (debugManager) {
...
@@ -245,7 +242,7 @@ function testDebugging (debugManager) {
const
state
=
await
debugManager
.
extractStateAt
(
312
)
const
state
=
await
debugManager
.
extractStateAt
(
312
)
const
decodedState
=
await
debugManager
.
decodeStateAt
(
312
,
state
)
const
decodedState
=
await
debugManager
.
decodeStateAt
(
312
,
state
)
console
.
log
(
decodedState
)
console
.
log
(
decodedState
)
t
.
equal
(
decodedState
[
'chairperson'
].
value
,
'0x
4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB
'
)
t
.
equal
(
decodedState
[
'chairperson'
].
value
,
'0x
5B38DA6A701C568545DCFCB03FCB875F56BEDDC4
'
)
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'
)
...
@@ -259,13 +256,15 @@ function testDebugging (debugManager) {
...
@@ -259,13 +256,15 @@ function testDebugging (debugManager) {
tape
(
'traceManager.decodeLocalsAt'
,
async
(
t
)
=>
{
tape
(
'traceManager.decodeLocalsAt'
,
async
(
t
)
=>
{
t
.
plan
(
1
)
t
.
plan
(
1
)
const
tested
=
JSON
.
parse
(
'{"proposalNames":{"value":[{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"}],"length":"0x1","type":"bytes32[]","cursor":1,"hasNext":false},"p":{"value":"45","type":"uint256"},"addressLocal":{"value":"0x
4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB
","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[]"}}'
)
const
tested
=
JSON
.
parse
(
'{"proposalNames":{"value":[{"value":"0x48656C6C6F20576F726C64210000000000000000000000000000000000000000","type":"bytes32"}],"length":"0x1","type":"bytes32[]","cursor":1,"hasNext":false},"p":{"value":"45","type":"uint256"},"addressLocal":{"value":"0x
5B38DA6A701C568545DCFCB03FCB875F56BEDDC4
","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[]"}}'
)
try
{
try
{
const
address
=
debugManager
.
traceManager
.
getCurrentCalledAddressAt
(
327
)
const
address
=
debugManager
.
traceManager
.
getCurrentCalledAddressAt
(
327
)
const
location
=
await
debugManager
.
sourceLocationFromVMTraceIndex
(
address
,
327
)
const
location
=
await
debugManager
.
sourceLocationFromVMTraceIndex
(
address
,
327
)
debugManager
.
decodeLocalsAt
(
327
,
location
,
(
error
,
decodedlocals
)
=>
{
debugManager
.
decodeLocalsAt
(
327
,
location
,
(
error
,
decodedlocals
)
=>
{
if
(
error
)
return
t
.
end
(
error
)
if
(
error
)
return
t
.
end
(
error
)
t
.
ok
(
deepequal
(
decodedlocals
,
tested
),
`locals does not match. expected:
${
JSON
.
stringify
(
tested
)}
- current:
${
decodedlocals
}
`
)
const
res
=
deepequal
(
decodedlocals
,
tested
)
console
.
log
(
res
)
t
.
ok
(
res
,
`test if locals does match. expected:
${
JSON
.
stringify
(
tested
)}
- current:
${
JSON
.
stringify
(
decodedlocals
)}
`
)
})
})
}
catch
(
error
)
{
}
catch
(
error
)
{
return
t
.
end
(
error
)
return
t
.
end
(
error
)
...
...
libs/remix-debug/test/decoder/localDecoder.ts
View file @
eae7f2d0
...
@@ -5,7 +5,7 @@ var intLocal = require('./contracts/intLocal')
...
@@ -5,7 +5,7 @@ var intLocal = require('./contracts/intLocal')
var
miscLocal
=
require
(
'./contracts/miscLocal'
)
var
miscLocal
=
require
(
'./contracts/miscLocal'
)
var
structArrayLocal
=
require
(
'./contracts/structArrayLocal'
)
var
structArrayLocal
=
require
(
'./contracts/structArrayLocal'
)
var
calldataLocal
=
require
(
'./contracts/calldata'
)
var
calldataLocal
=
require
(
'./contracts/calldata'
)
var
vmCall
=
require
(
'./vmCall'
)
var
vmCall
=
require
(
'.
.
/vmCall'
)
var
intLocalTest
=
require
(
'./localsTests/int'
)
var
intLocalTest
=
require
(
'./localsTests/int'
)
var
miscLocalTest
=
require
(
'./localsTests/misc'
)
var
miscLocalTest
=
require
(
'./localsTests/misc'
)
var
misc2LocalTest
=
require
(
'./localsTests/misc2'
)
var
misc2LocalTest
=
require
(
'./localsTests/misc2'
)
...
@@ -15,29 +15,28 @@ var compilerInput = require('../helpers/compilerHelper').compilerInput
...
@@ -15,29 +15,28 @@ var compilerInput = require('../helpers/compilerHelper').compilerInput
tape
(
'solidity'
,
function
(
t
)
{
tape
(
'solidity'
,
function
(
t
)
{
t
.
test
(
'local decoder'
,
async
function
(
st
)
{
t
.
test
(
'local decoder'
,
async
function
(
st
)
{
var
privateKey
=
Buffer
.
from
(
'dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'
,
'hex'
)
var
privateKey
=
Buffer
.
from
(
'503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb'
,
'hex'
)
var
vm
=
await
vmCall
.
initVM
(
st
,
privateKey
)
await
test
(
st
,
privateKey
)
await
test
(
st
,
vm
,
privateKey
)
})
})
})
})
async
function
test
(
st
,
vm
,
privateKey
)
{
async
function
test
(
st
,
privateKey
)
{
var
output
=
compiler
.
compile
(
compilerInput
(
intLocal
.
contract
))
var
output
=
compiler
.
compile
(
compilerInput
(
intLocal
.
contract
))
output
=
JSON
.
parse
(
output
)
output
=
JSON
.
parse
(
output
)
await
intLocalTest
(
st
,
vm
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'intLocal'
].
evm
.
bytecode
.
object
,
output
)
await
intLocalTest
(
st
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'intLocal'
].
evm
.
bytecode
.
object
,
output
)
output
=
compiler
.
compile
(
compilerInput
(
miscLocal
.
contract
))
output
=
compiler
.
compile
(
compilerInput
(
miscLocal
.
contract
))
output
=
JSON
.
parse
(
output
)
output
=
JSON
.
parse
(
output
)
await
miscLocalTest
(
st
,
vm
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'miscLocal'
].
evm
.
bytecode
.
object
,
output
)
await
miscLocalTest
(
st
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'miscLocal'
].
evm
.
bytecode
.
object
,
output
)
output
=
compiler
.
compile
(
compilerInput
(
miscLocal
.
contract
))
output
=
compiler
.
compile
(
compilerInput
(
miscLocal
.
contract
))
output
=
JSON
.
parse
(
output
)
output
=
JSON
.
parse
(
output
)
await
misc2LocalTest
(
st
,
vm
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'miscLocal2'
].
evm
.
bytecode
.
object
,
output
)
await
misc2LocalTest
(
st
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'miscLocal2'
].
evm
.
bytecode
.
object
,
output
)
output
=
compiler
.
compile
(
compilerInput
(
structArrayLocal
.
contract
))
output
=
compiler
.
compile
(
compilerInput
(
structArrayLocal
.
contract
))
output
=
JSON
.
parse
(
output
)
output
=
JSON
.
parse
(
output
)
await
structArrayLocalTest
(
st
,
vm
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'structArrayLocal'
].
evm
.
bytecode
.
object
,
output
)
await
structArrayLocalTest
(
st
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'structArrayLocal'
].
evm
.
bytecode
.
object
,
output
)
output
=
compiler
.
compile
(
compilerInput
(
calldataLocal
.
contract
))
output
=
compiler
.
compile
(
compilerInput
(
calldataLocal
.
contract
))
output
=
JSON
.
parse
(
output
)
output
=
JSON
.
parse
(
output
)
await
calldataLocalTest
(
st
,
vm
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'calldataLocal'
].
evm
.
bytecode
.
object
,
output
)
await
calldataLocalTest
(
st
,
privateKey
,
output
.
contracts
[
'test.sol'
][
'calldataLocal'
].
evm
.
bytecode
.
object
,
output
)
st
.
end
()
st
.
end
()
}
}
libs/remix-debug/test/decoder/localsTests/calldata.ts
View file @
eae7f2d0
'use strict'
'use strict'
import
deepequal
from
'deep-equal'
import
deepequal
from
'deep-equal'
import
{
sendTx
}
from
'
../vmCall'
import
*
as
vmCall
from
'../
../vmCall'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
import
{
SolidityProxy
}
from
'../../../src/solidity-decoder/solidityProxy'
import
{
SolidityProxy
}
from
'../../../src/solidity-decoder/solidityProxy'
...
@@ -9,23 +9,26 @@ import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree
...
@@ -9,23 +9,26 @@ import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree
import
{
EventManager
}
from
'../../../src/eventManager'
import
{
EventManager
}
from
'../../../src/eventManager'
import
*
as
helper
from
'./helper'
import
*
as
helper
from
'./helper'
module
.
exports
=
async
function
(
st
,
vm
,
privateKey
,
contractBytecode
,
compilationResult
)
{
module
.
exports
=
async
function
(
st
,
privateKey
,
contractBytecode
,
compilationResult
)
{
let
txHash
let
txHash
let
web3
try
{
try
{
let
data
=
await
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
)
web3
=
await
(
vmCall
as
any
).
getWeb3
()
const
to
=
(
data
as
any
).
result
.
createdAddress
.
toString
()
let
hash
=
await
(
vmCall
as
any
).
sendTx
(
web3
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
)
const
receipt
=
await
web3
.
eth
.
getTransactionReceipt
(
hash
)
const
to
=
receipt
.
contractAddress
console
.
log
(
'to'
,
to
)
// call to level11
// call to level11
data
=
await
sendTx
(
vm
,
{
nonce
:
1
,
privateKey
:
privateKey
},
to
,
0
,
'a372a595000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015400000000000000000000000000000000000000000000000000000000000000'
)
txHash
=
await
(
vmCall
as
any
).
sendTx
(
web3
,
{
nonce
:
1
,
privateKey
:
privateKey
},
to
,
0
,
'a372a595000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015400000000000000000000000000000000000000000000000000000000000000'
)
txHash
=
(
data
as
any
).
hash
}
catch
(
e
)
{
}
catch
(
e
)
{
return
st
.
fail
(
e
)
return
st
.
fail
(
e
)
}
}
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
((
resolve
)
=>
{
vm
.
web3
.
eth
.
getTransaction
(
txHash
,
function
(
error
,
tx
)
{
web3
.
eth
.
getTransaction
(
txHash
,
function
(
error
,
tx
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
var
traceManager
=
new
TraceManager
({
web3
:
vm
.
web3
})
var
traceManager
=
new
TraceManager
({
web3
})
var
codeManager
=
new
CodeManager
(
traceManager
)
var
codeManager
=
new
CodeManager
(
traceManager
)
codeManager
.
clear
()
codeManager
.
clear
()
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
...
...
libs/remix-debug/test/decoder/localsTests/int.ts
View file @
eae7f2d0
'use strict'
'use strict'
import
{
sendTx
}
from
'
../vmCall'
import
*
as
vmCall
from
'../
../vmCall'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
import
{
contractCreationToken
}
from
'../../../src/trace/traceHelper'
import
{
contractCreationToken
}
from
'../../../src/trace/traceHelper'
...
@@ -9,19 +9,19 @@ import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree
...
@@ -9,19 +9,19 @@ import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree
import
{
EventManager
}
from
'../../../src/eventManager'
import
{
EventManager
}
from
'../../../src/eventManager'
import
*
as
helper
from
'./helper'
import
*
as
helper
from
'./helper'
module
.
exports
=
function
(
st
,
vm
,
privateKey
,
contractBytecode
,
compilationResult
)
{
module
.
exports
=
function
(
st
,
privateKey
,
contractBytecode
,
compilationResult
)
{
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
(
async
(
resolve
)
=>
{
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
,
function
(
error
,
data
)
{
let
web3
=
await
(
vmCall
as
any
).
getWeb3
();
(
vmCall
as
any
).
sendTx
(
web3
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
,
function
(
error
,
hash
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
const
txHash
=
data
.
hash
web3
.
eth
.
getTransaction
(
hash
,
function
(
error
,
tx
)
{
vm
.
web3
.
eth
.
getTransaction
(
txHash
,
function
(
error
,
tx
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
tx
.
to
=
contractCreationToken
(
'0'
)
tx
.
to
=
contractCreationToken
(
'0'
)
var
traceManager
=
new
TraceManager
({
web3
:
vm
.
web3
})
var
traceManager
=
new
TraceManager
({
web3
})
var
codeManager
=
new
CodeManager
(
traceManager
)
var
codeManager
=
new
CodeManager
(
traceManager
)
codeManager
.
clear
()
codeManager
.
clear
()
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
...
@@ -125,6 +125,6 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
...
@@ -125,6 +125,6 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
})
})
})
})
})
})
})
})
}
}
libs/remix-debug/test/decoder/localsTests/misc.ts
View file @
eae7f2d0
'use strict'
'use strict'
import
{
sendTx
}
from
'
../vmCall'
import
*
as
vmCall
from
'../
../vmCall'
import
{
contractCreationToken
}
from
'../../../src/trace/traceHelper'
import
{
contractCreationToken
}
from
'../../../src/trace/traceHelper'
import
{
SolidityProxy
}
from
'../../../src/solidity-decoder/solidityProxy'
import
{
SolidityProxy
}
from
'../../../src/solidity-decoder/solidityProxy'
import
{
InternalCallTree
}
from
'../../../src/solidity-decoder/internalCallTree'
import
{
InternalCallTree
}
from
'../../../src/solidity-decoder/internalCallTree'
...
@@ -8,19 +8,19 @@ import * as helper from './helper'
...
@@ -8,19 +8,19 @@ import * as helper from './helper'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
module
.
exports
=
function
(
st
,
vm
,
privateKey
,
contractBytecode
,
compilationResult
)
{
module
.
exports
=
function
(
st
,
privateKey
,
contractBytecode
,
compilationResult
)
{
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
(
async
(
resolve
)
=>
{
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
,
function
(
error
,
data
)
{
const
web3
=
await
(
vmCall
as
any
).
getWeb3
();
(
vmCall
as
any
).
sendTx
(
web3
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
,
function
(
error
,
hash
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
const
txHash
=
data
.
hash
web3
.
eth
.
getTransaction
(
hash
,
function
(
error
,
tx
)
{
vm
.
web3
.
eth
.
getTransaction
(
txHash
,
function
(
error
,
tx
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
tx
.
to
=
contractCreationToken
(
'0'
)
tx
.
to
=
contractCreationToken
(
'0'
)
var
traceManager
=
new
TraceManager
({
web3
:
vm
.
web3
})
var
traceManager
=
new
TraceManager
({
web3
})
var
codeManager
=
new
CodeManager
(
traceManager
)
var
codeManager
=
new
CodeManager
(
traceManager
)
codeManager
.
clear
()
codeManager
.
clear
()
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
...
@@ -36,7 +36,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
...
@@ -36,7 +36,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
st
.
equals
(
locals
[
'boolFalse'
].
value
,
false
)
st
.
equals
(
locals
[
'boolFalse'
].
value
,
false
)
st
.
equals
(
locals
[
'boolTrue'
].
value
,
true
)
st
.
equals
(
locals
[
'boolTrue'
].
value
,
true
)
st
.
equals
(
locals
[
'testEnum'
].
value
,
'three'
)
st
.
equals
(
locals
[
'testEnum'
].
value
,
'three'
)
st
.
equals
(
locals
[
'sender'
].
value
,
'0x
4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB
'
)
st
.
equals
(
locals
[
'sender'
].
value
,
'0x
5B38DA6A701C568545DCFCB03FCB875F56BEDDC4
'
)
st
.
equals
(
locals
[
'_bytes1'
].
value
,
'0x99'
)
st
.
equals
(
locals
[
'_bytes1'
].
value
,
'0x99'
)
st
.
equals
(
locals
[
'__bytes1'
].
value
,
'0x99'
)
st
.
equals
(
locals
[
'__bytes1'
].
value
,
'0x99'
)
st
.
equals
(
locals
[
'__bytes2'
].
value
,
'0x99AB'
)
st
.
equals
(
locals
[
'__bytes2'
].
value
,
'0x99AB'
)
...
...
libs/remix-debug/test/decoder/localsTests/misc2.ts
View file @
eae7f2d0
'use strict'
'use strict'
import
{
sendTx
}
from
'
../vmCall'
import
*
as
vmCall
from
'../
../vmCall'
import
{
contractCreationToken
}
from
'../../../src/trace/traceHelper'
import
{
contractCreationToken
}
from
'../../../src/trace/traceHelper'
import
{
SolidityProxy
}
from
'../../../src/solidity-decoder/solidityProxy'
import
{
SolidityProxy
}
from
'../../../src/solidity-decoder/solidityProxy'
import
{
InternalCallTree
}
from
'../../../src/solidity-decoder/internalCallTree'
import
{
InternalCallTree
}
from
'../../../src/solidity-decoder/internalCallTree'
...
@@ -8,19 +8,19 @@ import * as helper from './helper'
...
@@ -8,19 +8,19 @@ import * as helper from './helper'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
module
.
exports
=
function
(
st
,
vm
,
privateKey
,
contractBytecode
,
compilationResult
)
{
module
.
exports
=
function
(
st
,
privateKey
,
contractBytecode
,
compilationResult
)
{
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
(
async
(
resolve
)
=>
{
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
,
function
(
error
,
data
)
{
const
web3
=
await
(
vmCall
as
any
).
getWeb3
();
(
vmCall
as
any
).
sendTx
(
web3
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
,
function
(
error
,
hash
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
const
txHash
=
data
.
hash
web3
.
eth
.
getTransaction
(
hash
,
function
(
error
,
tx
)
{
vm
.
web3
.
eth
.
getTransaction
(
txHash
,
function
(
error
,
tx
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
tx
.
to
=
contractCreationToken
(
'0'
)
tx
.
to
=
contractCreationToken
(
'0'
)
var
traceManager
=
new
TraceManager
({
web3
:
vm
.
web3
})
var
traceManager
=
new
TraceManager
({
web3
})
var
codeManager
=
new
CodeManager
(
traceManager
)
var
codeManager
=
new
CodeManager
(
traceManager
)
codeManager
.
clear
()
codeManager
.
clear
()
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
...
...
libs/remix-debug/test/decoder/localsTests/structArray.ts
View file @
eae7f2d0
'use strict'
'use strict'
import
{
sendTx
}
from
'
../vmCall'
import
*
as
vmCall
from
'../
../vmCall'
import
{
contractCreationToken
}
from
'../../../src/trace/traceHelper'
import
{
contractCreationToken
}
from
'../../../src/trace/traceHelper'
import
{
SolidityProxy
}
from
'../../../src/solidity-decoder/solidityProxy'
import
{
SolidityProxy
}
from
'../../../src/solidity-decoder/solidityProxy'
import
{
InternalCallTree
}
from
'../../../src/solidity-decoder/internalCallTree'
import
{
InternalCallTree
}
from
'../../../src/solidity-decoder/internalCallTree'
...
@@ -8,19 +8,19 @@ import * as helper from './helper'
...
@@ -8,19 +8,19 @@ import * as helper from './helper'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
import
{
CodeManager
}
from
'../../../src/code/codeManager'
module
.
exports
=
function
(
st
,
vm
,
privateKey
,
contractBytecode
,
compilationResult
)
{
module
.
exports
=
function
(
st
,
privateKey
,
contractBytecode
,
compilationResult
)
{
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
(
async
(
resolve
)
=>
{
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
,
function
(
error
,
data
)
{
const
web3
=
await
(
vmCall
as
any
).
getWeb3
();
(
vmCall
as
any
).
sendTx
(
web3
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
contractBytecode
,
function
(
error
,
hash
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
const
txHash
=
data
.
hash
web3
.
eth
.
getTransaction
(
hash
,
function
(
error
,
tx
)
{
vm
.
web3
.
eth
.
getTransaction
(
txHash
,
function
(
error
,
tx
)
{
if
(
error
)
{
if
(
error
)
{
return
st
.
fail
(
error
)
return
st
.
fail
(
error
)
}
}
tx
.
to
=
contractCreationToken
(
'0'
)
tx
.
to
=
contractCreationToken
(
'0'
)
var
traceManager
=
new
TraceManager
({
web3
:
vm
.
web3
})
var
traceManager
=
new
TraceManager
({
web3
})
var
codeManager
=
new
CodeManager
(
traceManager
)
var
codeManager
=
new
CodeManager
(
traceManager
)
codeManager
.
clear
()
codeManager
.
clear
()
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
var
solidityProxy
=
new
SolidityProxy
({
getCurrentCalledAddressAt
:
traceManager
.
getCurrentCalledAddressAt
.
bind
(
traceManager
),
getCode
:
codeManager
.
getCode
.
bind
(
codeManager
)
})
...
...
libs/remix-debug/test/decoder/stateTests/mapping.ts
View file @
eae7f2d0
...
@@ -2,57 +2,62 @@ import { compilerInput } from '../../helpers/compilerHelper'
...
@@ -2,57 +2,62 @@ import { compilerInput } from '../../helpers/compilerHelper'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
TraceManager
}
from
'../../../src/trace/traceManager'
import
{
compile
}
from
'solc'
import
{
compile
}
from
'solc'
import
*
as
stateDecoder
from
'../../../src/solidity-decoder/stateDecoder'
import
*
as
stateDecoder
from
'../../../src/solidity-decoder/stateDecoder'
import
{
sendTx
,
initVM
}
from
'
../vmCall'
import
*
as
vmCall
from
'../
../vmCall'
import
{
StorageResolver
}
from
'../../../src/storage/storageResolver'
import
{
StorageResolver
}
from
'../../../src/storage/storageResolver'
import
{
StorageViewer
}
from
'../../../src/storage/storageViewer'
import
{
StorageViewer
}
from
'../../../src/storage/storageViewer'
import
{
Address
,
bufferToHex
}
from
'ethereumjs-util'
module
.
exports
=
async
function
testMappingStorage
(
st
,
cb
)
{
module
.
exports
=
async
function
testMappingStorage
(
st
,
cb
)
{
console
.
log
(
'start testMappingStorage'
)
var
mappingStorage
=
require
(
'../contracts/mappingStorage'
)
var
mappingStorage
=
require
(
'../contracts/mappingStorage'
)
var
privateKey
=
Buffer
.
from
(
'dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'
,
'hex'
)
var
privateKey
=
Buffer
.
from
(
'503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb'
,
'hex'
)
var
vm
=
await
initVM
(
st
,
privateKey
)
var
output
=
compile
(
compilerInput
(
mappingStorage
.
contract
))
var
output
=
compile
(
compilerInput
(
mappingStorage
.
contract
))
output
=
JSON
.
parse
(
output
)
output
=
JSON
.
parse
(
output
);
sendTx
(
vm
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
output
.
contracts
[
'test.sol'
][
'SimpleMappingState'
].
evm
.
bytecode
.
object
,
function
(
error
,
data
)
{
console
.
log
(
'BYTECODE'
,
output
.
contracts
[
'test.sol'
][
'SimpleMappingState'
].
evm
.
bytecode
.
object
);
const
web3
=
await
(
vmCall
as
any
).
getWeb3
();
(
vmCall
as
any
).
sendTx
(
web3
,
{
nonce
:
0
,
privateKey
:
privateKey
},
null
,
0
,
output
.
contracts
[
'test.sol'
][
'SimpleMappingState'
].
evm
.
bytecode
.
object
,
function
(
error
,
hash
)
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
st
.
end
(
error
)
st
.
end
(
error
)
}
else
{
}
else
{
const
txHash
=
data
.
hash
web3
.
eth
.
getTransactionReceipt
(
hash
,
(
error
,
tx
)
=>
{
vm
.
web3
.
eth
.
getTransaction
(
txHash
,
(
error
,
tx
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
st
.
end
(
error
)
st
.
end
(
error
)
}
else
{
}
else
{
testMapping
(
st
,
vm
,
privateKey
,
tx
.
contractAddress
,
output
,
cb
)
// const storage = await this.vm.stateManager.dumpStorage(data.to)
console
.
log
(
tx
);
// (vmCall as any).web3().eth.getCode(tx.contractAddress).then((code) => console.log('code:', code))
// (vmCall as any).web3().debug.traceTransaction(hash).then((code) => console.log('trace:', code))
testMapping
(
st
,
privateKey
,
tx
.
contractAddress
,
output
,
web3
,
cb
)
// st.end()
}
}
})
})
}
}
})
})
}
}
function
testMapping
(
st
,
vm
,
privateKey
,
contractAddress
,
output
,
cb
)
{
function
testMapping
(
st
,
privateKey
,
contractAddress
,
output
,
web3
,
cb
)
{
sendTx
(
vm
,
{
nonce
:
1
,
privateKey
:
privateKey
},
contractAddress
,
0
,
'2fd0a83a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001074686973206973206120737472696e6700000000000000000000000000000000'
,
(
vmCall
as
any
).
sendTx
(
web3
,
{
nonce
:
1
,
privateKey
:
privateKey
},
contractAddress
,
0
,
'2fd0a83a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001074686973206973206120737472696e6700000000000000000000000000000000'
,
function
(
error
,
data
)
{
function
(
error
,
hash
)
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
st
.
end
(
error
)
st
.
end
(
error
)
}
else
{
}
else
{
const
txHash
=
data
.
hash
web3
.
eth
.
getTransaction
(
hash
,
(
error
,
tx
)
=>
{
vm
.
web3
.
eth
.
getTransaction
(
txHash
,
(
error
,
tx
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
st
.
end
(
error
)
st
.
end
(
error
)
}
else
{
}
else
{
var
traceManager
=
new
TraceManager
({
web3
:
vm
.
web3
})
var
traceManager
=
new
TraceManager
({
web3
})
traceManager
.
resolveTrace
(
tx
).
then
(()
=>
{
traceManager
.
resolveTrace
(
tx
).
then
(()
=>
{
var
storageViewer
=
new
StorageViewer
({
var
storageViewer
=
new
StorageViewer
({
stepIndex
:
268
,
stepIndex
:
268
,
tx
:
tx
,
tx
:
tx
,
address
:
contractAddress
address
:
contractAddress
},
new
StorageResolver
({
web3
:
vm
.
web3
}),
traceManager
)
},
new
StorageResolver
({
web3
}),
traceManager
)
var
stateVars
=
stateDecoder
.
extractStateVariables
(
'SimpleMappingState'
,
output
.
sources
)
var
stateVars
=
stateDecoder
.
extractStateVariables
(
'SimpleMappingState'
,
output
.
sources
)
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
stateDecoder
.
decodeState
(
stateVars
,
storageViewer
).
then
((
result
)
=>
{
console
.
log
(
'ok'
,
JSON
.
stringify
(
result
))
st
.
equal
(
result
[
'_num'
].
value
,
'1'
)
st
.
equal
(
result
[
'_num'
].
value
,
'1'
)
st
.
equal
(
result
[
'_num'
].
type
,
'uint256'
)
st
.
equal
(
result
[
'_num'
].
type
,
'uint256'
)
st
.
equal
(
result
[
'_iBreakSolidityState'
].
type
,
'mapping(string => uint256)'
)
st
.
equal
(
result
[
'_iBreakSolidityState'
].
type
,
'mapping(string => uint256)'
)
...
...
libs/remix-debug/test/decoder/vmCall.ts
deleted
100644 → 0
View file @
00c12168
'use strict'
import
{
Transaction
as
Tx
}
from
'@ethereumjs/tx'
import
{
Block
}
from
'@ethereumjs/block'
import
{
BN
,
bufferToHex
,
Address
}
from
'ethereumjs-util'
import
{
vm
as
remixlibVM
}
from
'@remix-project/remix-lib'
import
VM
from
'@ethereumjs/vm'
import
Common
from
'@ethereumjs/common'
export
function
sendTx
(
vm
,
from
,
to
,
value
,
data
,
cb
?)
{
cb
=
cb
||
(()
=>
{})
return
new
Promise
((
resolve
,
reject
)
=>
{
var
tx
=
new
Tx
({
nonce
:
new
BN
(
from
.
nonce
++
),
// gasPrice: new BN(1),
gasLimit
:
new
BN
(
3000000
,
10
),
to
:
to
,
value
:
new
BN
(
value
,
10
),
data
:
Buffer
.
from
(
data
,
'hex'
)
})
tx
=
tx
.
sign
(
from
.
privateKey
)
var
block
=
Block
.
fromBlockData
({
header
:
{
timestamp
:
new
Date
().
getTime
()
/
1000
|
0
,
number
:
0
}
})
// still using default common
try
{
vm
.
runTx
({
block
:
block
,
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
}).
then
(
function
(
result
)
{
setTimeout
(()
=>
{
const
hash
=
bufferToHex
(
tx
.
hash
())
cb
(
null
,
{
hash
,
result
})
resolve
({
hash
,
result
})
},
500
)
}).
catch
((
error
)
=>
{
console
.
error
(
error
)
cb
(
error
)
reject
(
error
)
})
}
catch
(
e
)
{
console
.
error
(
e
)
}
})
}
async
function
createVm
(
hardfork
)
{
const
common
=
new
Common
({
chain
:
'mainnet'
,
hardfork
})
const
vm
=
new
VM
({
common
})
await
vm
.
init
()
return
{
vm
,
stateManager
:
vm
.
stateManager
}
}
/*
Init VM / Send Transaction
*/
export
async
function
initVM
(
st
,
privateKey
)
{
var
VM
=
await
createVm
(
'berlin'
)
const
vm
=
VM
.
vm
var
address
=
Address
.
fromPrivateKey
(
privateKey
)
try
{
let
account
=
await
vm
.
stateManager
.
getAccount
(
address
)
account
.
balance
=
new
BN
(
'f00000000000000001'
,
16
)
await
vm
.
stateManager
.
putAccount
(
address
,
account
)
}
catch
(
error
)
{
console
.
log
(
error
)
}
var
web3Provider
=
new
remixlibVM
.
Web3VMProvider
()
web3Provider
.
setVM
(
vm
)
vm
.
web3
=
web3Provider
return
vm
}
libs/remix-debug/test/tests.ts
View file @
eae7f2d0
'use strict'
'use strict'
require
(
'./vmCall'
)
require
(
'./traceManager'
)
require
(
'./traceManager'
)
require
(
'./codeManager'
)
require
(
'./codeManager'
)
require
(
'./disassembler'
)
require
(
'./disassembler'
)
...
...
libs/remix-debug/test/vmCall.ts
View file @
eae7f2d0
'use strict'
'use strict'
import
{
Block
}
from
'@ethereumjs/block'
import
{
Block
}
from
'@ethereumjs/block'
import
{
Transaction
}
from
'@ethereumjs/tx'
import
VM
from
'@ethereumjs/vm'
import
VM
from
'@ethereumjs/vm'
import
{
rlp
,
keccak
,
bufferToHex
}
from
'ethereumjs-util'
import
{
extendWeb3
}
from
'../src/init'
var
utileth
=
require
(
'ethereumjs-util'
)
var
utileth
=
require
(
'ethereumjs-util'
)
var
Tx
=
require
(
'@ethereumjs/tx'
).
Transaction
var
Tx
=
require
(
'@ethereumjs/tx'
).
Transaction
var
BN
=
require
(
'ethereumjs-util'
).
BN
var
BN
=
require
(
'ethereumjs-util'
).
BN
var
remixLib
=
require
(
'@remix-project/remix-lib'
)
var
remixLib
=
require
(
'@remix-project/remix-lib'
)
const
{
Provider
,
extend
}
=
require
(
'@remix-project/remix-simulator'
)
const
Web3
=
require
(
'web3'
)
function
sendTx
(
vm
,
from
,
to
,
value
,
data
,
cb
)
{
var
tx
=
new
Tx
({
nonce
:
new
BN
(
from
.
nonce
++
),
// gasPrice: new BN(1),
gasLimit
:
new
BN
(
3000000
,
10
),
to
:
to
,
value
:
new
BN
(
value
,
10
),
data
:
Buffer
.
from
(
data
,
'hex'
)
})
tx
=
tx
.
sign
(
from
.
privateKey
)
var
block
=
Block
.
fromBlockData
({
async
function
getWeb3
()
{
header
:
{
const
remixSimulatorProvider
=
new
Provider
({
fork
:
'berlin'
})
timestamp
:
new
Date
().
getTime
()
/
1000
|
0
,
await
remixSimulatorProvider
.
init
()
number
:
0
await
remixSimulatorProvider
.
Accounts
.
resetAccounts
()
}
const
web3
=
new
Web3
(
remixSimulatorProvider
)
})
// still using default common
extendWeb3
(
web3
)
vm
.
runTx
({
block
:
block
,
tx
:
tx
,
skipBalance
:
true
,
skipNonce
:
true
}).
then
(
function
(
result
)
{
return
web3
setTimeout
(()
=>
{
cb
(
null
,
utileth
.
bufferToHex
(
tx
.
hash
()))
},
500
)
}).
catch
((
error
)
=>
{
console
.
error
(
error
)
cb
(
error
)
})
}
}
/*
async
function
sendTx
(
web3
,
from
,
to
,
value
,
data
,
cb
)
{
Init VM / Send Transaction
*/
async
function
initVM
(
privateKey
)
{
var
address
=
utileth
.
Address
.
fromPrivateKey
(
privateKey
)
var
vm
=
new
VM
({
activatePrecompiles
:
true
})
await
vm
.
init
()
try
{
try
{
let
account
=
await
vm
.
stateManager
.
getAccount
(
address
)
cb
=
cb
||
(()
=>
{})
account
.
balance
=
new
BN
(
'f00000000000000001'
,
16
)
console
.
log
(
'TX'
,
{
await
vm
.
stateManager
.
putAccount
(
address
,
account
)
from
:
utileth
.
Address
.
fromPrivateKey
(
from
.
privateKey
).
toString
(
'hex'
),
}
catch
(
error
)
{
to
,
console
.
log
(
error
)
value
,
}
data
,
gas
:
7000000
var
web3Provider
=
new
remixLib
.
vm
.
Web3VMProvider
()
})
web3Provider
.
setVM
(
vm
)
const
receipt
=
await
web3
.
eth
.
sendTransaction
({
vm
.
web3
=
web3Provider
from
:
utileth
.
Address
.
fromPrivateKey
(
from
.
privateKey
).
toString
(
'hex'
),
return
vm
to
,
value
,
data
,
gas
:
7000000
})
console
.
log
(
'end tx'
)
cb
(
null
,
receipt
.
transactionHash
)
return
receipt
.
transactionHash
}
catch
(
e
)
{
cb
(
e
)
}
}
}
module
.
exports
=
{
module
.
exports
=
{
sendTx
:
sendTx
,
sendTx
,
initVM
:
initVM
getWeb3
}
}
libs/remix-lib/src/web3Provider/web3VmProvider.ts
View file @
eae7f2d0
...
@@ -107,6 +107,7 @@ export class Web3VmProvider {
...
@@ -107,6 +107,7 @@ export class Web3VmProvider {
async
txWillProcess
(
data
)
{
async
txWillProcess
(
data
)
{
this
.
incr
++
this
.
incr
++
this
.
processingHash
=
bufferToHex
(
data
.
hash
())
this
.
processingHash
=
bufferToHex
(
data
.
hash
())
this
.
vmTraces
[
this
.
processingHash
]
=
{
this
.
vmTraces
[
this
.
processingHash
]
=
{
gas
:
'0x0'
,
gas
:
'0x0'
,
return
:
'0x0'
,
return
:
'0x0'
,
...
@@ -114,19 +115,23 @@ export class Web3VmProvider {
...
@@ -114,19 +115,23 @@ export class Web3VmProvider {
}
}
const
tx
=
{}
const
tx
=
{}
tx
[
'hash'
]
=
this
.
processingHash
tx
[
'hash'
]
=
this
.
processingHash
tx
[
'from'
]
=
toChecksumAddress
(
data
.
getSenderAddress
().
toString
())
tx
[
'from'
]
=
toChecksumAddress
(
data
.
getSenderAddress
().
toString
())
if
(
data
.
to
)
{
if
(
data
.
to
)
{
tx
[
'to'
]
=
toChecksumAddress
(
data
.
to
.
toString
())
tx
[
'to'
]
=
toChecksumAddress
(
data
.
to
.
toString
())
}
}
this
.
processingAddress
=
tx
[
'to'
]
this
.
processingAddress
=
tx
[
'to'
]
tx
[
'input'
]
=
bufferToHex
(
data
.
data
)
tx
[
'input'
]
=
bufferToHex
(
data
.
data
)
tx
[
'gas'
]
=
data
.
gasLimit
.
toString
(
10
)
tx
[
'gas'
]
=
data
.
gasLimit
.
toString
(
10
)
if
(
data
.
value
)
{
if
(
data
.
value
)
{
tx
[
'value'
]
=
data
.
value
.
toString
(
10
)
tx
[
'value'
]
=
data
.
value
.
toString
(
10
)
}
}
this
.
txs
[
this
.
processingHash
]
=
tx
this
.
txs
[
this
.
processingHash
]
=
tx
this
.
txsReceipt
[
this
.
processingHash
]
=
tx
this
.
txsReceipt
[
this
.
processingHash
]
=
tx
this
.
storageCache
[
this
.
processingHash
]
=
{}
this
.
storageCache
[
this
.
processingHash
]
=
{}
if
(
data
.
to
)
{
if
(
data
.
to
)
{
try
{
try
{
// dumpStorage throws error as 'Missing Node in DB'
// dumpStorage throws error as 'Missing Node in DB'
...
...
libs/remix-simulator/src/vm-context.ts
View file @
eae7f2d0
...
@@ -24,31 +24,27 @@ class StateManagerCommonStorageDump extends StateManager {
...
@@ -24,31 +24,27 @@ class StateManagerCommonStorageDump extends StateManager {
return
super
.
putContractStorage
(
address
,
key
,
value
)
return
super
.
putContractStorage
(
address
,
key
,
value
)
}
}
async
dumpStorage
(
address
)
{
async
dumpStorage
(
address
):
Promise
<
StorageDump
>
{
let
trie
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
this
.
_getStorageTrie
(
address
)
trie
=
await
this
.
_getStorageTrie
(
address
)
.
then
((
trie
)
=>
{
}
catch
(
e
)
{
const
storage
=
{}
console
.
log
(
e
)
const
stream
=
trie
.
createReadStream
()
throw
e
}
stream
.
on
(
'data'
,
(
val
)
=>
{
return
new
Promise
<
StorageDump
>
((
resolve
,
reject
)
=>
{
const
value
=
rlp
.
decode
(
val
.
value
)
try
{
storage
[
'0x'
+
val
.
key
.
toString
(
'hex'
)]
=
{
const
storage
=
{}
key
:
this
.
keyHashes
[
val
.
key
.
toString
(
'hex'
)],
const
stream
=
trie
.
createReadStream
()
value
:
'0x'
+
value
.
toString
(
'hex'
)
stream
.
on
(
'data'
,
(
val
)
=>
{
}
const
value
=
rlp
.
decode
(
val
.
value
)
})
storage
[
'0x'
+
val
.
key
.
toString
(
'hex'
)]
=
{
stream
.
on
(
'end'
,
()
=>
{
key
:
this
.
keyHashes
[
val
.
key
.
toString
(
'hex'
)],
resolve
(
storage
)
value
:
'0x'
+
value
.
toString
(
'hex'
)
})
}
})
})
stream
.
on
(
'end'
,
function
()
{
.
catch
((
e
)
=>
{
re
solve
(
storag
e
)
re
ject
(
e
)
})
})
}
catch
(
e
)
{
reject
(
e
)
}
})
})
}
}
...
@@ -60,18 +56,18 @@ class StateManagerCommonStorageDump extends StateManager {
...
@@ -60,18 +56,18 @@ class StateManagerCommonStorageDump extends StateManager {
}
}
async
setStateRoot
(
stateRoot
)
{
async
setStateRoot
(
stateRoot
)
{
await
this
.
_cache
.
flush
()
console
.
log
(
'setstateroot'
,
stateRoot
.
toString
(
'hex'
))
if
(
this
.
_checkpointCount
!==
0
)
{
if
(
stateRoot
===
this
.
_trie
.
EMPTY_TRIE_ROOT
)
{
throw
new
Error
(
'Cannot set state root with uncommitted checkpoints'
)
this
.
_trie
.
root
=
stateRoot
this
.
_cache
.
clear
()
this
.
_storageTries
=
{}
return
}
}
const
hasRoot
=
await
this
.
_trie
.
checkRoot
(
stateRoot
)
await
this
.
_cache
.
flush
()
if
(
!
hasRoot
)
{
throw
new
Error
(
'State trie does not contain state root'
)
if
(
!
stateRoot
.
equals
(
this
.
_trie
.
EMPTY_TRIE_ROOT
))
{
const
hasRoot
=
await
this
.
_trie
.
checkRoot
(
stateRoot
)
if
(
!
hasRoot
)
{
throw
new
Error
(
'State trie does not contain state root'
)
}
}
}
this
.
_trie
.
root
=
stateRoot
this
.
_trie
.
root
=
stateRoot
...
...
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