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
16cea52a
Unverified
Commit
16cea52a
authored
Nov 12, 2019
by
Iuri Matias
Committed by
GitHub
Nov 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1272 from ethereum/improve_remix_sim4
Implement filters; add more tests; eth_getStorageAt
parents
299b25b8
1a890d28
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
577 additions
and
139 deletions
+577
-139
execution-context.js
remix-lib/src/execution/execution-context.js
+2
-0
logsManager.js
remix-lib/src/execution/logsManager.js
+43
-1
txExecution.js
remix-lib/src/execution/txExecution.js
+1
-1
web3VmProvider.js
remix-lib/src/web3Provider/web3VmProvider.js
+9
-0
README.md
remix-simulator/README.md
+7
-21
ethsim
remix-simulator/bin/ethsim
+3
-1
package.json
remix-simulator/package.json
+1
-1
accounts.js
remix-simulator/src/methods/accounts.js
+9
-6
blocks.js
remix-simulator/src/methods/blocks.js
+21
-2
filters.js
remix-simulator/src/methods/filters.js
+32
-1
transactions.js
remix-simulator/src/methods/transactions.js
+14
-0
txProcess.js
remix-simulator/src/methods/txProcess.js
+2
-2
whisper.js
remix-simulator/src/methods/whisper.js
+0
-15
provider.js
remix-simulator/src/provider.js
+10
-3
server.js
remix-simulator/src/server.js
+6
-1
accounts.js
remix-simulator/test/accounts.js
+27
-3
blocks.js
remix-simulator/test/blocks.js
+305
-35
misc.js
remix-simulator/test/misc.js
+85
-29
whisper.js
remix-simulator/test/whisper.js
+0
-17
No files found.
remix-lib/src/execution/execution-context.js
View file @
16cea52a
...
@@ -115,6 +115,7 @@ function ExecutionContext () {
...
@@ -115,6 +115,7 @@ function ExecutionContext () {
this
.
blockGasLimit
=
this
.
blockGasLimitDefault
this
.
blockGasLimit
=
this
.
blockGasLimitDefault
this
.
customNetWorks
=
{}
this
.
customNetWorks
=
{}
this
.
blocks
=
{}
this
.
blocks
=
{}
this
.
latestBlockNumber
=
0
this
.
txs
=
{}
this
.
txs
=
{}
this
.
init
=
function
(
config
)
{
this
.
init
=
function
(
config
)
{
...
@@ -309,6 +310,7 @@ function ExecutionContext () {
...
@@ -309,6 +310,7 @@ function ExecutionContext () {
self
.
blocks
[
'0x'
+
block
.
hash
().
toString
(
'hex'
)]
=
block
self
.
blocks
[
'0x'
+
block
.
hash
().
toString
(
'hex'
)]
=
block
self
.
blocks
[
blockNumber
]
=
block
self
.
blocks
[
blockNumber
]
=
block
self
.
latestBlockNumber
=
blockNumber
this
.
logsManager
.
checkBlock
(
blockNumber
,
block
,
this
.
web3
())
this
.
logsManager
.
checkBlock
(
blockNumber
,
block
,
this
.
web3
())
}
}
...
...
remix-lib/src/execution/logsManager.js
View file @
16cea52a
...
@@ -6,6 +6,8 @@ class LogsManager {
...
@@ -6,6 +6,8 @@ class LogsManager {
constructor
()
{
constructor
()
{
this
.
notificationCallbacks
=
[]
this
.
notificationCallbacks
=
[]
this
.
subscriptions
=
{}
this
.
subscriptions
=
{}
this
.
filters
=
{}
this
.
filterTracking
=
{}
this
.
oldLogs
=
[]
this
.
oldLogs
=
[]
}
}
...
@@ -66,13 +68,20 @@ class LogsManager {
...
@@ -66,13 +68,20 @@ class LogsManager {
const
subscriptionParams
=
this
.
subscriptions
[
subscriptionId
]
const
subscriptionParams
=
this
.
subscriptions
[
subscriptionId
]
const
[
queryType
,
queryFilter
]
=
subscriptionParams
const
[
queryType
,
queryFilter
]
=
subscriptionParams
if
(
this
.
eventMatchesFilter
(
changeEvent
,
queryType
,
queryFilter
))
{
if
(
this
.
eventMatchesFilter
(
changeEvent
,
queryType
,
queryFilter
||
{
topics
:
[]}
))
{
matchedSubscriptions
.
push
(
subscriptionId
)
matchedSubscriptions
.
push
(
subscriptionId
)
}
}
}
}
return
matchedSubscriptions
return
matchedSubscriptions
}
}
getLogsForSubscription
(
subscriptionId
)
{
const
subscriptionParams
=
this
.
subscriptions
[
subscriptionId
]
const
[
_queryType
,
queryFilter
]
=
subscriptionParams
// eslint-disable-line
return
this
.
getLogsFor
(
queryFilter
)
}
transmit
(
result
)
{
transmit
(
result
)
{
this
.
notificationCallbacks
.
forEach
((
callback
)
=>
{
this
.
notificationCallbacks
.
forEach
((
callback
)
=>
{
if
(
result
.
params
.
result
.
raw
)
{
if
(
result
.
params
.
result
.
raw
)
{
...
@@ -97,6 +106,39 @@ class LogsManager {
...
@@ -97,6 +106,39 @@ class LogsManager {
delete
this
.
subscriptions
[
subscriptionId
]
delete
this
.
subscriptions
[
subscriptionId
]
}
}
newFilter
(
filterType
,
params
)
{
const
filterId
=
'0x'
+
crypto
.
randomBytes
(
16
).
toString
(
'hex'
)
if
(
filterType
===
'block'
||
filterType
===
'pendingTransactions'
)
{
this
.
filters
[
filterId
]
=
{
filterType
}
}
if
(
filterType
===
'filter'
)
{
this
.
filters
[
filterId
]
=
{
filterType
,
params
}
}
this
.
filterTracking
[
filterId
]
=
{}
return
filterId
}
uninstallFilter
(
filterId
)
{
delete
this
.
filters
[
filterId
]
}
getLogsForFilter
(
filterId
,
logsOnly
)
{
const
{
filterType
,
params
}
=
this
.
filter
[
filterId
]
const
tracking
=
this
.
filterTracking
[
filterId
]
if
(
logsOnly
||
filterType
===
'filter'
)
{
return
this
.
getLogsFor
(
params
||
{
topics
:
[]})
}
if
(
filterType
===
'block'
)
{
let
blocks
=
this
.
oldLogs
.
filter
(
x
=>
x
.
type
===
'block'
).
filter
(
x
=>
tracking
.
block
===
undefined
||
x
.
blockNumber
>=
tracking
.
block
)
tracking
.
block
=
blocks
[
blocks
.
length
-
1
]
return
blocks
.
map
(
block
=>
(
'0x'
+
block
.
hash
().
toString
(
'hex'
)))
}
if
(
filterType
===
'pendingTransactions'
)
{
return
[]
}
}
getLogsFor
(
params
)
{
getLogsFor
(
params
)
{
let
results
=
[]
let
results
=
[]
for
(
let
log
of
this
.
oldLogs
)
{
for
(
let
log
of
this
.
oldLogs
)
{
...
...
remix-lib/src/execution/txExecution.js
View file @
16cea52a
...
@@ -43,7 +43,7 @@ module.exports = {
...
@@ -43,7 +43,7 @@ module.exports = {
* @param {Function} finalCallback - last callback.
* @param {Function} finalCallback - last callback.
*/
*/
callFunction
:
function
(
from
,
to
,
data
,
value
,
gasLimit
,
funAbi
,
txRunner
,
callbacks
,
finalCallback
)
{
callFunction
:
function
(
from
,
to
,
data
,
value
,
gasLimit
,
funAbi
,
txRunner
,
callbacks
,
finalCallback
)
{
var
tx
=
{
from
:
from
,
to
:
to
,
data
:
data
,
useCall
:
f
alse
,
value
:
value
,
gasLimit
:
gasLimit
}
var
tx
=
{
from
:
from
,
to
:
to
,
data
:
data
,
useCall
:
f
unAbi
.
constant
,
value
:
value
,
gasLimit
:
gasLimit
}
txRunner
.
rawRun
(
tx
,
callbacks
.
confirmationCb
,
callbacks
.
gasEstimationForceSend
,
callbacks
.
promptCb
,
(
error
,
txResult
)
=>
{
txRunner
.
rawRun
(
tx
,
callbacks
.
confirmationCb
,
callbacks
.
gasEstimationForceSend
,
callbacks
.
promptCb
,
(
error
,
txResult
)
=>
{
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
finalCallback
(
error
,
txResult
)
finalCallback
(
error
,
txResult
)
...
...
remix-lib/src/web3Provider/web3VmProvider.js
View file @
16cea52a
...
@@ -29,6 +29,7 @@ function web3VmProvider () {
...
@@ -29,6 +29,7 @@ function web3VmProvider () {
this
.
providers
=
{
'HttpProvider'
:
function
(
url
)
{}
}
this
.
providers
=
{
'HttpProvider'
:
function
(
url
)
{}
}
this
.
currentProvider
=
{
'host'
:
'vm provider'
}
this
.
currentProvider
=
{
'host'
:
'vm provider'
}
this
.
storageCache
=
{}
this
.
storageCache
=
{}
this
.
lastProcessedStorageTxHash
=
{}
this
.
sha3Preimages
=
{}
this
.
sha3Preimages
=
{}
// util
// util
this
.
sha3
=
function
()
{
return
self
.
web3
.
sha3
.
apply
(
self
.
web3
,
arguments
)
}
this
.
sha3
=
function
()
{
return
self
.
web3
.
sha3
.
apply
(
self
.
web3
,
arguments
)
}
...
@@ -92,6 +93,7 @@ web3VmProvider.prototype.txWillProcess = function (self, data) {
...
@@ -92,6 +93,7 @@ web3VmProvider.prototype.txWillProcess = function (self, data) {
const
account
=
ethutil
.
toBuffer
(
tx
.
to
)
const
account
=
ethutil
.
toBuffer
(
tx
.
to
)
self
.
vm
.
stateManager
.
dumpStorage
(
account
,
function
(
storage
)
{
self
.
vm
.
stateManager
.
dumpStorage
(
account
,
function
(
storage
)
{
self
.
storageCache
[
self
.
processingHash
][
tx
.
to
]
=
storage
self
.
storageCache
[
self
.
processingHash
][
tx
.
to
]
=
storage
self
.
lastProcessedStorageTxHash
[
tx
.
to
]
=
self
.
processingHash
})
})
}
}
this
.
processingIndex
=
0
this
.
processingIndex
=
0
...
@@ -171,12 +173,14 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
...
@@ -171,12 +173,14 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
if
(
step
.
op
===
'CREATE'
)
{
if
(
step
.
op
===
'CREATE'
)
{
this
.
processingAddress
=
traceHelper
.
contractCreationToken
(
this
.
processingIndex
)
this
.
processingAddress
=
traceHelper
.
contractCreationToken
(
this
.
processingIndex
)
this
.
storageCache
[
this
.
processingHash
][
this
.
processingAddress
]
=
{}
this
.
storageCache
[
this
.
processingHash
][
this
.
processingAddress
]
=
{}
this
.
lastProcessedStorageTxHash
[
this
.
processingAddress
]
=
this
.
processingHash
}
else
{
}
else
{
this
.
processingAddress
=
uiutil
.
normalizeHexAddress
(
step
.
stack
[
step
.
stack
.
length
-
2
])
this
.
processingAddress
=
uiutil
.
normalizeHexAddress
(
step
.
stack
[
step
.
stack
.
length
-
2
])
if
(
!
self
.
storageCache
[
self
.
processingHash
][
this
.
processingAddress
])
{
if
(
!
self
.
storageCache
[
self
.
processingHash
][
this
.
processingAddress
])
{
const
account
=
ethutil
.
toBuffer
(
this
.
processingAddress
)
const
account
=
ethutil
.
toBuffer
(
this
.
processingAddress
)
self
.
vm
.
stateManager
.
dumpStorage
(
account
,
function
(
storage
)
{
self
.
vm
.
stateManager
.
dumpStorage
(
account
,
function
(
storage
)
{
self
.
storageCache
[
self
.
processingHash
][
self
.
processingAddress
]
=
storage
self
.
storageCache
[
self
.
processingHash
][
self
.
processingAddress
]
=
storage
self
.
lastProcessedStorageTxHash
[
self
.
processingAddress
]
=
self
.
processingHash
})
})
}
}
}
}
...
@@ -217,6 +221,11 @@ web3VmProvider.prototype.traceTransaction = function (txHash, options, cb) {
...
@@ -217,6 +221,11 @@ web3VmProvider.prototype.traceTransaction = function (txHash, options, cb) {
web3VmProvider
.
prototype
.
storageRangeAt
=
function
(
blockNumber
,
txIndex
,
address
,
start
,
maxLength
,
cb
)
{
// txIndex is the hash in the case of the VM
web3VmProvider
.
prototype
.
storageRangeAt
=
function
(
blockNumber
,
txIndex
,
address
,
start
,
maxLength
,
cb
)
{
// txIndex is the hash in the case of the VM
// we don't use the range params here
// we don't use the range params here
if
(
txIndex
===
'latest'
)
{
txIndex
=
this
.
lastProcessedStorageTxHash
[
address
]
}
if
(
this
.
storageCache
[
txIndex
]
&&
this
.
storageCache
[
txIndex
][
address
])
{
if
(
this
.
storageCache
[
txIndex
]
&&
this
.
storageCache
[
txIndex
][
address
])
{
var
storage
=
this
.
storageCache
[
txIndex
][
address
]
var
storage
=
this
.
storageCache
[
txIndex
][
address
]
return
cb
(
null
,
{
return
cb
(
null
,
{
...
...
remix-simulator/README.md
View file @
16cea52a
...
@@ -16,7 +16,7 @@ Implemented:
...
@@ -16,7 +16,7 @@ Implemented:
*
[
~
]
eth_accounts
*
[
~
]
eth_accounts
*
[
X
]
eth_blockNumber
*
[
X
]
eth_blockNumber
*
[
X
]
eth_getBalance
*
[
X
]
eth_getBalance
*
[
_
]
eth_getStorageAt
*
[
~
]
eth_getStorageAt
*
[
X
]
eth_getTransactionCount
*
[
X
]
eth_getTransactionCount
*
[
X
]
eth_getBlockTransactionCountByHash
*
[
X
]
eth_getBlockTransactionCountByHash
*
[
X
]
eth_getBlockTransactionCountByNumber
*
[
X
]
eth_getBlockTransactionCountByNumber
...
@@ -40,12 +40,12 @@ Implemented:
...
@@ -40,12 +40,12 @@ Implemented:
*
[
X
]
eth_compileSolidity (DEPRECATED)
*
[
X
]
eth_compileSolidity (DEPRECATED)
*
[
X
]
eth_compileLLL (DEPRECATED)
*
[
X
]
eth_compileLLL (DEPRECATED)
*
[
X
]
eth_compileSerpent (DEPRECATED)
*
[
X
]
eth_compileSerpent (DEPRECATED)
*
[
_
]
eth_newFilter
*
[
X
]
eth_newFilter
*
[
_
]
eth_newBlockFilter
*
[
X
]
eth_newBlockFilter
*
[
_
]
eth_newPendingTransactionFilter
*
[
X
]
eth_newPendingTransactionFilter
*
[
_
]
eth_uninstallFilter
*
[
X
]
eth_uninstallFilter
*
[
_
]
eth_getFilterChanges
*
[
~
]
eth_getFilterChanges
*
[
_
]
eth_getFilterLogs
*
[
~
]
eth_getFilterLogs
*
[
X
]
eth_getLogs
*
[
X
]
eth_getLogs
*
[
_
]
eth_getWork
*
[
_
]
eth_getWork
*
[
_
]
eth_submitWork
*
[
_
]
eth_submitWork
...
@@ -55,18 +55,6 @@ Implemented:
...
@@ -55,18 +55,6 @@ Implemented:
*
[
_
]
db_getString
*
[
_
]
db_getString
*
[
_
]
db_putHex
*
[
_
]
db_putHex
*
[
_
]
db_getHex
*
[
_
]
db_getHex
*
[
X
]
shh_version
*
[
_
]
shh_post
*
[
_
]
shh_newIdentity
*
[
_
]
shh_hasIdentity
*
[
_
]
shh_newGroup
*
[
_
]
shh_addToGroup
*
[
_
]
shh_newFilter
*
[
_
]
shh_uninstallFilter
*
[
_
]
shh_getFilterChanges
*
[
_
]
shh_getMessages
*
[
_
]
bzz_hive (stub)
*
[
_
]
bzz_info (stub)
*
[
_
]
debug_traceTransaction
*
[
_
]
debug_traceTransaction
*
[
X
]
eth_subscribe
*
[
X
]
eth_subscribe
*
[
X
]
eth_unsubscribe
*
[
X
]
eth_unsubscribe
...
@@ -79,5 +67,3 @@ Implemented:
...
@@ -79,5 +67,3 @@ Implemented:
*
[
_
]
personal_unlockAccount
*
[
_
]
personal_unlockAccount
*
[
_
]
personal_sendTransaction
*
[
_
]
personal_sendTransaction
*
[
_
]
rpc_modules
*
[
_
]
rpc_modules
*
[
_
]
web3_clientVersion
*
[
_
]
web3_sha3
remix-simulator/bin/ethsim
View file @
16cea52a
...
@@ -24,12 +24,14 @@ program
...
@@ -24,12 +24,14 @@ program
.
option
(
'-b, --ip [host]'
,
'specify host'
)
.
option
(
'-b, --ip [host]'
,
'specify host'
)
.
option
(
'-c, --coinbase [coinbase]'
,
'specify host'
)
.
option
(
'-c, --coinbase [coinbase]'
,
'specify host'
)
.
option
(
'--rpc'
,
'run rpc server only'
)
.
option
(
'--rpc'
,
'run rpc server only'
)
.
option
(
'--details'
,
'display payloads for every requests and their responses'
)
.
parse
(
process
.
argv
)
.
parse
(
process
.
argv
)
const
Server
=
require
(
'../src/server'
)
const
Server
=
require
(
'../src/server'
)
const
server
=
new
Server
({
const
server
=
new
Server
({
coinbase
:
program
.
coinbase
||
"0x0000000000000000000000000000000000000000"
,
coinbase
:
program
.
coinbase
||
"0x0000000000000000000000000000000000000000"
,
rpc
:
program
.
rpc
rpc
:
program
.
rpc
,
logDetails
:
program
.
details
})
})
server
.
start
(
program
.
host
||
'127.0.0.1'
,
program
.
port
||
8545
)
server
.
start
(
program
.
host
||
'127.0.0.1'
,
program
.
port
||
8545
)
remix-simulator/package.json
View file @
16cea52a
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
"remix-lib"
:
"0.4.14"
,
"remix-lib"
:
"0.4.14"
,
"standard"
:
"^10.0.3"
,
"standard"
:
"^10.0.3"
,
"time-stamp"
:
"^2.0.0"
,
"time-stamp"
:
"^2.0.0"
,
"web3"
:
"
^
1.0.0-beta.37"
"web3"
:
"1.0.0-beta.37"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@babel/core"
:
"^7.4.5"
,
"@babel/core"
:
"^7.4.5"
,
...
...
remix-simulator/src/methods/accounts.js
View file @
16cea52a
...
@@ -20,7 +20,7 @@ Accounts.prototype.init = async function () {
...
@@ -20,7 +20,7 @@ Accounts.prototype.init = async function () {
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
account
.
privateKey
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
account
.
privateKey
this
.
accounts
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
{
privateKey
:
Buffer
.
from
(
account
.
privateKey
.
replace
(
'0x'
,
''
),
'hex'
),
nonce
:
0
}
this
.
accounts
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
{
privateKey
:
Buffer
.
from
(
account
.
privateKey
.
replace
(
'0x'
,
''
),
'hex'
),
nonce
:
0
}
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
account
.
address
.
toLowerCase
().
replace
(
'0x'
,
''
),
'hex'
),
(
err
,
account
)
=>
{
executionContext
.
vm
().
stateManager
.
getAccount
(
Buffer
.
from
(
account
.
address
.
replace
(
'0x'
,
''
),
'hex'
),
(
err
,
account
)
=>
{
if
(
err
)
{
if
(
err
)
{
throw
new
Error
(
err
)
throw
new
Error
(
err
)
}
}
...
@@ -61,13 +61,16 @@ Accounts.prototype.eth_getBalance = function (payload, cb) {
...
@@ -61,13 +61,16 @@ Accounts.prototype.eth_getBalance = function (payload, cb) {
}
}
Accounts
.
prototype
.
eth_sign
=
function
(
payload
,
cb
)
{
Accounts
.
prototype
.
eth_sign
=
function
(
payload
,
cb
)
{
le
t
address
=
payload
.
params
[
0
]
cons
t
address
=
payload
.
params
[
0
]
le
t
message
=
payload
.
params
[
1
]
cons
t
message
=
payload
.
params
[
1
]
let
privateKey
=
this
.
accountsKeys
[
address
]
const
privateKey
=
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
address
)]
let
account
=
Web3
.
eth
.
accounts
.
privateKeyToAccount
(
privateKey
)
if
(
!
privateKey
)
{
return
cb
(
new
Error
(
'unknown account'
))
}
const
account
=
this
.
web3
.
eth
.
accounts
.
privateKeyToAccount
(
privateKey
)
le
t
data
=
account
.
sign
(
message
)
cons
t
data
=
account
.
sign
(
message
)
cb
(
null
,
data
.
signature
)
cb
(
null
,
data
.
signature
)
}
}
...
...
remix-simulator/src/methods/blocks.js
View file @
16cea52a
...
@@ -17,12 +17,18 @@ Blocks.prototype.methods = function () {
...
@@ -17,12 +17,18 @@ Blocks.prototype.methods = function () {
eth_getBlockTransactionCountByHash
:
this
.
eth_getBlockTransactionCountByHash
.
bind
(
this
),
eth_getBlockTransactionCountByHash
:
this
.
eth_getBlockTransactionCountByHash
.
bind
(
this
),
eth_getBlockTransactionCountByNumber
:
this
.
eth_getBlockTransactionCountByNumber
.
bind
(
this
),
eth_getBlockTransactionCountByNumber
:
this
.
eth_getBlockTransactionCountByNumber
.
bind
(
this
),
eth_getUncleCountByBlockHash
:
this
.
eth_getUncleCountByBlockHash
.
bind
(
this
),
eth_getUncleCountByBlockHash
:
this
.
eth_getUncleCountByBlockHash
.
bind
(
this
),
eth_getUncleCountByBlockNumber
:
this
.
eth_getUncleCountByBlockNumber
.
bind
(
this
)
eth_getUncleCountByBlockNumber
:
this
.
eth_getUncleCountByBlockNumber
.
bind
(
this
),
eth_getStorageAt
:
this
.
eth_getStorageAt
.
bind
(
this
)
}
}
}
}
Blocks
.
prototype
.
eth_getBlockByNumber
=
function
(
payload
,
cb
)
{
Blocks
.
prototype
.
eth_getBlockByNumber
=
function
(
payload
,
cb
)
{
var
block
=
executionContext
.
blocks
[
payload
.
params
[
0
]]
let
blockIndex
=
payload
.
params
[
0
]
if
(
blockIndex
===
'latest'
)
{
blockIndex
=
executionContext
.
latestBlockNumber
}
const
block
=
executionContext
.
blocks
[
blockIndex
]
if
(
!
block
)
{
if
(
!
block
)
{
return
cb
(
new
Error
(
'block not found'
))
return
cb
(
new
Error
(
'block not found'
))
...
@@ -117,4 +123,17 @@ Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) {
...
@@ -117,4 +123,17 @@ Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) {
cb
(
null
,
0
)
cb
(
null
,
0
)
}
}
Blocks
.
prototype
.
eth_getStorageAt
=
function
(
payload
,
cb
)
{
const
[
address
,
position
,
blockNumber
]
=
payload
.
params
executionContext
.
web3
().
debug
.
storageRangeAt
(
blockNumber
,
'latest'
,
address
.
toLowerCase
(),
position
,
1
,
(
err
,
result
)
=>
{
if
(
err
||
(
result
.
storage
&&
Object
.
values
(
result
.
storage
).
length
===
0
))
{
return
cb
(
err
,
''
)
}
let
value
=
Object
.
values
(
result
.
storage
)[
0
].
value
cb
(
err
,
value
)
})
}
module
.
exports
=
Blocks
module
.
exports
=
Blocks
remix-simulator/src/methods/filters.js
View file @
16cea52a
...
@@ -13,7 +13,6 @@ Filters.prototype.methods = function () {
...
@@ -13,7 +13,6 @@ Filters.prototype.methods = function () {
}
}
}
}
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
Filters
.
prototype
.
eth_getLogs
=
function
(
payload
,
cb
)
{
Filters
.
prototype
.
eth_getLogs
=
function
(
payload
,
cb
)
{
let
results
=
executionContext
.
logsManager
.
getLogsFor
(
payload
.
params
[
0
])
let
results
=
executionContext
.
logsManager
.
getLogsFor
(
payload
.
params
[
0
])
cb
(
null
,
results
)
cb
(
null
,
results
)
...
@@ -29,4 +28,36 @@ Filters.prototype.eth_unsubscribe = function (payload, cb) {
...
@@ -29,4 +28,36 @@ Filters.prototype.eth_unsubscribe = function (payload, cb) {
cb
(
null
,
true
)
cb
(
null
,
true
)
}
}
Filters
.
prototype
.
eth_newFilter
=
function
(
payload
,
cb
)
{
const
filterId
=
executionContext
.
logsManager
.
newFilter
(
'filter'
,
payload
.
params
[
0
])
cb
(
null
,
filterId
)
}
Filters
.
prototype
.
eth_newBlockFilter
=
function
(
payload
,
cb
)
{
const
filterId
=
executionContext
.
logsManager
.
newFilter
(
'block'
)
cb
(
null
,
filterId
)
}
Filters
.
prototype
.
eth_newPendingTransactionFilter
=
function
(
payload
,
cb
)
{
const
filterId
=
executionContext
.
logsManager
.
newFilter
(
'pendingTransactions'
)
cb
(
null
,
filterId
)
}
Filters
.
prototype
.
eth_uninstallfilter
=
function
(
payload
,
cb
)
{
const
result
=
executionContext
.
logsManager
.
uninstallFilter
(
payload
.
params
[
0
])
cb
(
null
,
result
)
}
Filters
.
prototype
.
eth_getFilterChanges
=
function
(
payload
,
cb
)
{
const
filterId
=
payload
.
params
[
0
]
let
results
=
executionContext
.
logsManager
.
getLogsForFilter
(
filterId
)
cb
(
null
,
results
)
}
Filters
.
prototype
.
eth_getFilterLogs
=
function
(
payload
,
cb
)
{
const
filterId
=
payload
.
params
[
0
]
let
results
=
executionContext
.
logsManager
.
getLogsForFilter
(
filterId
,
true
)
cb
(
null
,
results
)
}
module
.
exports
=
Filters
module
.
exports
=
Filters
remix-simulator/src/methods/transactions.js
View file @
16cea52a
...
@@ -53,6 +53,10 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
...
@@ -53,6 +53,10 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
'status'
:
receipt
.
status
'status'
:
receipt
.
status
}
}
if
(
r
.
blockNumber
===
'0x'
)
{
r
.
blockNumber
=
'0x0'
}
cb
(
null
,
r
)
cb
(
null
,
r
)
})
})
}
}
...
@@ -78,6 +82,12 @@ Transactions.prototype.eth_call = function (payload, cb) {
...
@@ -78,6 +82,12 @@ Transactions.prototype.eth_call = function (payload, cb) {
if
(
payload
.
params
&&
payload
.
params
.
length
>
0
&&
payload
.
params
[
0
].
from
)
{
if
(
payload
.
params
&&
payload
.
params
.
length
>
0
&&
payload
.
params
[
0
].
from
)
{
payload
.
params
[
0
].
from
=
ethJSUtil
.
toChecksumAddress
(
payload
.
params
[
0
].
from
)
payload
.
params
[
0
].
from
=
ethJSUtil
.
toChecksumAddress
(
payload
.
params
[
0
].
from
)
}
}
if
(
payload
.
params
&&
payload
.
params
.
length
>
0
&&
payload
.
params
[
0
].
to
)
{
payload
.
params
[
0
].
to
=
ethJSUtil
.
toChecksumAddress
(
payload
.
params
[
0
].
to
)
}
payload
.
params
[
0
].
value
=
undefined
processTx
(
this
.
accounts
,
payload
,
true
,
cb
)
processTx
(
this
.
accounts
,
payload
,
true
,
cb
)
}
}
...
@@ -130,6 +140,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
...
@@ -130,6 +140,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
r
.
value
=
'0x0'
r
.
value
=
'0x0'
}
}
if
(
r
.
blockNumber
===
'0x'
)
{
r
.
blockNumber
=
'0x0'
}
cb
(
null
,
r
)
cb
(
null
,
r
)
})
})
}
}
...
...
remix-simulator/src/methods/txProcess.js
View file @
16cea52a
...
@@ -16,7 +16,7 @@ function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks,
...
@@ -16,7 +16,7 @@ function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks,
return
callback
(
null
,
toReturn
)
return
callback
(
null
,
toReturn
)
}
}
TxExecution
.
callFunction
(
from
,
to
,
data
,
value
,
gasLimit
,
null
,
txRunner
,
callbacks
,
finalCallback
,
true
)
TxExecution
.
callFunction
(
from
,
to
,
data
,
value
,
gasLimit
,
{
constant
:
true
}
,
txRunner
,
callbacks
,
finalCallback
,
true
)
}
}
function
runTx
(
payload
,
from
,
to
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
)
{
function
runTx
(
payload
,
from
,
to
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
)
{
...
@@ -27,7 +27,7 @@ function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, c
...
@@ -27,7 +27,7 @@ function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, c
callback
(
null
,
result
.
transactionHash
)
callback
(
null
,
result
.
transactionHash
)
}
}
TxExecution
.
callFunction
(
from
,
to
,
data
,
value
,
gasLimit
,
null
,
txRunner
,
callbacks
,
finalCallback
,
false
)
TxExecution
.
callFunction
(
from
,
to
,
data
,
value
,
gasLimit
,
{
constant
:
false
}
,
txRunner
,
callbacks
,
finalCallback
,
false
)
}
}
function
createContract
(
payload
,
from
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
)
{
function
createContract
(
payload
,
from
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
)
{
...
...
remix-simulator/src/methods/whisper.js
deleted
100644 → 0
View file @
299b25b8
var
Whisper
=
function
()
{
}
Whisper
.
prototype
.
methods
=
function
()
{
return
{
shh_version
:
this
.
shh_version
.
bind
(
this
)
}
}
Whisper
.
prototype
.
shh_version
=
function
(
payload
,
cb
)
{
cb
(
null
,
5
)
}
module
.
exports
=
Whisper
remix-simulator/src/provider.js
View file @
16cea52a
...
@@ -10,11 +10,11 @@ const Filters = require('./methods/filters.js')
...
@@ -10,11 +10,11 @@ const Filters = require('./methods/filters.js')
const
Misc
=
require
(
'./methods/misc.js'
)
const
Misc
=
require
(
'./methods/misc.js'
)
const
Net
=
require
(
'./methods/net.js'
)
const
Net
=
require
(
'./methods/net.js'
)
const
Transactions
=
require
(
'./methods/transactions.js'
)
const
Transactions
=
require
(
'./methods/transactions.js'
)
const
Whisper
=
require
(
'./methods/whisper.js'
)
const
generateBlock
=
require
(
'./genesis.js'
)
const
generateBlock
=
require
(
'./genesis.js'
)
var
Provider
=
function
(
options
)
{
var
Provider
=
function
(
options
)
{
this
.
options
=
options
||
{}
this
.
Accounts
=
new
Accounts
()
this
.
Accounts
=
new
Accounts
()
this
.
Transactions
=
new
Transactions
()
this
.
Transactions
=
new
Transactions
()
...
@@ -24,10 +24,10 @@ var Provider = function (options) {
...
@@ -24,10 +24,10 @@ var Provider = function (options) {
this
.
methods
=
merge
(
this
.
methods
,
(
new
Misc
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Misc
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Filters
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Filters
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Net
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Net
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
this
.
Transactions
.
methods
()))
this
.
methods
=
merge
(
this
.
methods
,
this
.
Transactions
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Whisper
()).
methods
())
generateBlock
()
generateBlock
()
this
.
init
()
}
}
Provider
.
prototype
.
init
=
async
function
()
{
Provider
.
prototype
.
init
=
async
function
()
{
...
@@ -39,8 +39,15 @@ Provider.prototype.sendAsync = function (payload, callback) {
...
@@ -39,8 +39,15 @@ Provider.prototype.sendAsync = function (payload, callback) {
log
.
info
(
'payload method is '
,
payload
.
method
)
log
.
info
(
'payload method is '
,
payload
.
method
)
let
method
=
this
.
methods
[
payload
.
method
]
let
method
=
this
.
methods
[
payload
.
method
]
if
(
this
.
options
.
logDetails
)
{
log
.
info
(
payload
)
}
if
(
method
)
{
if
(
method
)
{
return
method
.
call
(
method
,
payload
,
(
err
,
result
)
=>
{
return
method
.
call
(
method
,
payload
,
(
err
,
result
)
=>
{
if
(
this
.
options
.
logDetails
)
{
log
.
info
(
err
)
log
.
info
(
result
)
}
if
(
err
)
{
if
(
err
)
{
return
callback
(
err
)
return
callback
(
err
)
}
}
...
...
remix-simulator/src/server.js
View file @
16cea52a
...
@@ -54,7 +54,12 @@ class Server {
...
@@ -54,7 +54,12 @@ class Server {
})
})
}
}
app
.
listen
(
port
,
host
,
()
=>
log
(
'Remix Simulator listening on port '
+
host
+
':'
+
port
))
app
.
listen
(
port
,
host
,
()
=>
{
log
(
'Remix Simulator listening on ws://'
+
host
+
':'
+
port
)
if
(
!
this
.
rpcOnly
)
{
log
(
'http json-rpc is deprecated and disabled by default. To enable it use --rpc'
)
}
})
}
}
}
}
...
...
remix-simulator/test/accounts.js
View file @
16cea52a
...
@@ -10,8 +10,32 @@ describe('Accounts', function () {
...
@@ -10,8 +10,32 @@ describe('Accounts', function () {
web3
.
setProvider
(
provider
)
web3
.
setProvider
(
provider
)
})
})
it
(
'should get a list of accounts'
,
async
function
()
{
describe
(
'eth_getAccounts'
,
()
=>
{
let
accounts
=
await
web3
.
eth
.
getAccounts
()
it
(
'should get a list of accounts'
,
async
function
()
{
assert
.
notEqual
(
accounts
.
length
,
0
)
let
accounts
=
await
web3
.
eth
.
getAccounts
()
assert
.
notEqual
(
accounts
.
length
,
0
)
})
})
describe
(
'eth_getBalance'
,
()
=>
{
it
(
'should get a account balance'
,
async
function
()
{
let
accounts
=
await
web3
.
eth
.
getAccounts
()
let
balance0
=
await
web3
.
eth
.
getBalance
(
accounts
[
0
])
let
balance1
=
await
web3
.
eth
.
getBalance
(
accounts
[
1
])
let
balance2
=
await
web3
.
eth
.
getBalance
(
accounts
[
2
])
assert
.
deepEqual
(
balance0
,
'100000000000000000000'
)
assert
.
deepEqual
(
balance1
,
'100000000000000000000'
)
assert
.
deepEqual
(
balance2
,
'100000000000000000000'
)
})
})
describe
(
'eth_sign'
,
()
=>
{
it
(
'should sign payloads'
,
async
function
()
{
let
accounts
=
await
web3
.
eth
.
getAccounts
()
let
signature
=
await
web3
.
eth
.
sign
(
'Hello world'
,
accounts
[
0
])
assert
.
deepEqual
(
signature
.
length
,
132
)
})
})
})
})
})
remix-simulator/test/blocks.js
View file @
16cea52a
...
@@ -12,40 +12,310 @@ describe('blocks', function () {
...
@@ -12,40 +12,310 @@ describe('blocks', function () {
web3
.
setProvider
(
provider
)
web3
.
setProvider
(
provider
)
})
})
it
(
'should get block given its number'
,
async
function
()
{
describe
(
'eth_getBlockByNumber'
,
()
=>
{
let
block
=
await
web3
.
eth
.
getBlock
(
0
)
it
(
'should get block given its number'
,
async
function
()
{
let
block
=
await
web3
.
eth
.
getBlock
(
0
)
let
expectedBlock
=
{
difficulty
:
'69762765929000'
,
let
expectedBlock
=
{
extraData
:
'0x0'
,
difficulty
:
'69762765929000'
,
gasLimit
:
8000000
,
extraData
:
'0x0'
,
gasUsed
:
0
,
gasLimit
:
8000000
,
hash
:
block
.
hash
.
toString
(
'hex'
),
gasUsed
:
0
,
logsBloom
:
'0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331'
,
hash
:
block
.
hash
.
toString
(
'hex'
),
miner
:
'0x0000000000000000000000000000000000000001'
,
logsBloom
:
'0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331'
,
nonce
:
'0x0000000000000000'
,
miner
:
'0x0000000000000000000000000000000000000001'
,
number
:
0
,
nonce
:
'0x0000000000000000'
,
parentHash
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
number
:
0
,
sha3Uncles
:
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
,
parentHash
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
size
:
163591
,
sha3Uncles
:
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
,
stateRoot
:
'0xa633ca0e8f0ae4e86d4d572b048ea93d84eb4b11e2c988b48cb3a5f6f10b3c68'
,
size
:
163591
,
timestamp
:
block
.
timestamp
,
stateRoot
:
'0x63e1738ea12d4e7d12b71f0f4604706417921eb6a62c407ca5f1d66b9e67f579'
,
totalDifficulty
:
'0'
,
timestamp
:
block
.
timestamp
,
transactions
:
[],
totalDifficulty
:
'0'
,
transactionsRoot
:
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
,
transactions
:
[],
uncles
:
[]
transactionsRoot
:
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
,
}
uncles
:
[]
}
assert
.
deepEqual
(
block
,
expectedBlock
)
})
assert
.
deepEqual
(
block
,
expectedBlock
)
})
it
(
'should get gas price'
,
async
function
()
{
})
let
gasPrice
=
await
web3
.
eth
.
getGasPrice
()
assert
.
equal
(
gasPrice
,
1
)
describe
(
'eth_getGasPrice'
,
()
=>
{
})
it
(
'should get gas price'
,
async
function
()
{
let
gasPrice
=
await
web3
.
eth
.
getGasPrice
()
it
(
'should get coinbase'
,
async
function
()
{
assert
.
equal
(
gasPrice
,
1
)
let
coinbase
=
await
web3
.
eth
.
getCoinbase
()
})
assert
.
equal
(
coinbase
,
'0x0000000000000000000000000000000000000001'
)
})
describe
(
'eth_coinbase'
,
()
=>
{
it
(
'should get coinbase'
,
async
function
()
{
let
coinbase
=
await
web3
.
eth
.
getCoinbase
()
assert
.
equal
(
coinbase
,
'0x0000000000000000000000000000000000000001'
)
})
})
describe
(
'eth_blockNumber'
,
()
=>
{
it
(
'should get current block number'
,
async
function
()
{
let
number
=
await
web3
.
eth
.
getBlockNumber
()
assert
.
equal
(
number
,
0
)
})
})
describe
(
'eth_getBlockByHash'
,
()
=>
{
it
(
'should get block given its hash'
,
async
function
()
{
let
correctBlock
=
await
web3
.
eth
.
getBlock
(
0
)
let
block
=
await
web3
.
eth
.
getBlock
(
correctBlock
.
hash
)
assert
.
deepEqual
(
block
,
correctBlock
)
})
})
describe
(
'eth_getBlockTransactionCountByHash'
,
()
=>
{
it
(
'should get block given its hash'
,
async
function
()
{
let
correctBlock
=
await
web3
.
eth
.
getBlock
(
0
)
let
numberTransactions
=
await
web3
.
eth
.
getBlockTransactionCount
(
correctBlock
.
hash
)
assert
.
deepEqual
(
numberTransactions
,
0
)
})
})
describe
(
'eth_getBlockTransactionCountByNumber'
,
()
=>
{
it
(
'should get block given its hash'
,
async
function
()
{
let
numberTransactions
=
await
web3
.
eth
.
getBlockTransactionCount
(
0
)
assert
.
deepEqual
(
numberTransactions
,
0
)
})
})
describe
(
'eth_getUncleCountByBlockHash'
,
()
=>
{
it
(
'should get block given its hash'
,
async
function
()
{
let
correctBlock
=
await
web3
.
eth
.
getBlock
(
0
)
let
numberTransactions
=
await
(
new
Promise
((
resolve
,
reject
)
=>
{
web3
.
_requestManager
.
send
({
method
:
'eth_getUncleCountByBlockHash'
,
params
:
[
correctBlock
.
hash
]},
(
err
,
numberTransactions
)
=>
{
if
(
err
)
return
reject
(
err
)
resolve
(
numberTransactions
)
})
}))
assert
.
deepEqual
(
numberTransactions
,
correctBlock
.
uncles
.
length
)
})
})
describe
(
'eth_getUncleCountByBlockNumber'
,
()
=>
{
it
(
'should get block given its number'
,
async
function
()
{
let
correctBlock
=
await
web3
.
eth
.
getBlock
(
0
)
let
numberTransactions
=
await
(
new
Promise
((
resolve
,
reject
)
=>
{
web3
.
_requestManager
.
send
({
method
:
'eth_getUncleCountByBlockHash'
,
params
:
[
0
]},
(
err
,
numberTransactions
)
=>
{
if
(
err
)
return
reject
(
err
)
resolve
(
numberTransactions
)
})
}))
assert
.
deepEqual
(
numberTransactions
,
correctBlock
.
uncles
.
length
)
})
})
describe
(
'eth_getStorageAt'
,
()
=>
{
it
(
'should get storage at position at given address'
,
async
function
()
{
let
abi
=
[
{
'constant'
:
false
,
'inputs'
:
[
{
'name'
:
'x'
,
'type'
:
'uint256'
}
],
'name'
:
'set'
,
'outputs'
:
[],
'payable'
:
false
,
'stateMutability'
:
'nonpayable'
,
'type'
:
'function'
},
{
'constant'
:
false
,
'inputs'
:
[
{
'name'
:
'x'
,
'type'
:
'uint256'
}
],
'name'
:
'set2'
,
'outputs'
:
[],
'payable'
:
false
,
'stateMutability'
:
'nonpayable'
,
'type'
:
'function'
},
{
'inputs'
:
[
{
'name'
:
'initialValue'
,
'type'
:
'uint256'
}
],
'payable'
:
false
,
'stateMutability'
:
'nonpayable'
,
'type'
:
'constructor'
},
{
'anonymous'
:
false
,
'inputs'
:
[
{
'indexed'
:
true
,
'name'
:
'value'
,
'type'
:
'uint256'
}
],
'name'
:
'Test'
,
'type'
:
'event'
},
{
'constant'
:
true
,
'inputs'
:
[],
'name'
:
'get'
,
'outputs'
:
[
{
'name'
:
'retVal'
,
'type'
:
'uint256'
}
],
'payable'
:
false
,
'stateMutability'
:
'view'
,
'type'
:
'function'
},
{
'constant'
:
true
,
'inputs'
:
[],
'name'
:
'storedData'
,
'outputs'
:
[
{
'name'
:
''
,
'type'
:
'uint256'
}
],
'payable'
:
false
,
'stateMutability'
:
'view'
,
'type'
:
'function'
}
]
let
code
=
'0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029'
const
contract
=
new
web3
.
eth
.
Contract
(
abi
)
const
accounts
=
await
web3
.
eth
.
getAccounts
()
const
contractInstance
=
await
contract
.
deploy
({
data
:
code
,
arguments
:
[
100
]
}).
send
({
from
:
accounts
[
0
],
gas
:
400000
})
contractInstance
.
currentProvider
=
web3
.
eth
.
currentProvider
contractInstance
.
givenProvider
=
web3
.
eth
.
currentProvider
await
contractInstance
.
methods
.
set
(
100
).
send
({
from
:
accounts
[
0
].
toLowerCase
(),
gas
:
400000
})
let
storage
=
await
web3
.
eth
.
getStorageAt
(
contractInstance
.
options
.
address
,
0
)
assert
.
deepEqual
(
storage
,
'0x64'
)
await
contractInstance
.
methods
.
set
(
200
).
send
({
from
:
accounts
[
0
],
gas
:
400000
})
storage
=
await
web3
.
eth
.
getStorageAt
(
contractInstance
.
options
.
address
,
0
)
assert
.
deepEqual
(
storage
,
'0x64'
)
await
contractInstance
.
methods
.
set
(
200
).
send
({
from
:
accounts
[
0
],
gas
:
400000
})
storage
=
await
web3
.
eth
.
getStorageAt
(
contractInstance
.
options
.
address
,
0
)
assert
.
deepEqual
(
storage
,
'0xc8'
)
})
})
describe
(
'eth_call'
,
()
=>
{
it
(
'should get a value'
,
async
function
()
{
let
abi
=
[
{
'constant'
:
false
,
'inputs'
:
[
{
'name'
:
'x'
,
'type'
:
'uint256'
}
],
'name'
:
'set'
,
'outputs'
:
[],
'payable'
:
false
,
'stateMutability'
:
'nonpayable'
,
'type'
:
'function'
},
{
'constant'
:
false
,
'inputs'
:
[
{
'name'
:
'x'
,
'type'
:
'uint256'
}
],
'name'
:
'set2'
,
'outputs'
:
[],
'payable'
:
false
,
'stateMutability'
:
'nonpayable'
,
'type'
:
'function'
},
{
'inputs'
:
[
{
'name'
:
'initialValue'
,
'type'
:
'uint256'
}
],
'payable'
:
false
,
'stateMutability'
:
'nonpayable'
,
'type'
:
'constructor'
},
{
'anonymous'
:
false
,
'inputs'
:
[
{
'indexed'
:
true
,
'name'
:
'value'
,
'type'
:
'uint256'
}
],
'name'
:
'Test'
,
'type'
:
'event'
},
{
'constant'
:
true
,
'inputs'
:
[],
'name'
:
'get'
,
'outputs'
:
[
{
'name'
:
'retVal'
,
'type'
:
'uint256'
}
],
'payable'
:
false
,
'stateMutability'
:
'view'
,
'type'
:
'function'
},
{
'constant'
:
true
,
'inputs'
:
[],
'name'
:
'storedData'
,
'outputs'
:
[
{
'name'
:
''
,
'type'
:
'uint256'
}
],
'payable'
:
false
,
'stateMutability'
:
'view'
,
'type'
:
'function'
}
]
let
code
=
'0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029'
const
contract
=
new
web3
.
eth
.
Contract
(
abi
)
const
accounts
=
await
web3
.
eth
.
getAccounts
()
const
contractInstance
=
await
contract
.
deploy
({
data
:
code
,
arguments
:
[
100
]
}).
send
({
from
:
accounts
[
0
],
gas
:
400000
})
contractInstance
.
currentProvider
=
web3
.
eth
.
currentProvider
contractInstance
.
givenProvider
=
web3
.
eth
.
currentProvider
let
value
=
await
contractInstance
.
methods
.
get
().
call
({
from
:
accounts
[
0
]
})
assert
.
deepEqual
(
value
,
100
)
})
})
})
})
})
remix-simulator/test/misc.js
View file @
16cea52a
...
@@ -10,47 +10,103 @@ describe('Misc', function () {
...
@@ -10,47 +10,103 @@ describe('Misc', function () {
web3
.
setProvider
(
provider
)
web3
.
setProvider
(
provider
)
})
})
it
(
'should get correct remix simulator version'
,
async
function
(
done
)
{
describe
(
'web3_clientVersion'
,
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'web3_clientVersion'
,
params
:
[]},
(
err
,
version
)
=>
{
it
(
'should get correct remix simulator version'
,
async
function
(
done
)
{
if
(
err
)
{
web3
.
_requestManager
.
send
({
method
:
'web3_clientVersion'
,
params
:
[]
},
(
err
,
version
)
=>
{
throw
new
Error
(
err
)
if
(
err
)
{
}
throw
new
Error
(
err
)
let
remixVersion
=
require
(
'../package.json'
).
version
}
assert
.
equal
(
version
,
'Remix Simulator/'
+
remixVersion
)
let
remixVersion
=
require
(
'../package.json'
).
version
done
()
assert
.
equal
(
version
,
'Remix Simulator/'
+
remixVersion
)
done
()
})
})
})
})
})
it
(
'should get protocol version'
,
async
function
()
{
describe
(
'eth_protocolVersion'
,
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'eth_protocolVersion'
,
params
:
[]},
(
err
,
result
)
=>
{
it
(
'should get protocol version'
,
async
function
()
{
if
(
err
)
{
web3
.
_requestManager
.
send
({
method
:
'eth_protocolVersion'
,
params
:
[]
},
(
err
,
result
)
=>
{
throw
new
Error
(
err
)
if
(
err
)
{
}
throw
new
Error
(
err
)
assert
.
equal
(
result
,
'0x3f'
)
}
assert
.
equal
(
result
,
'0x3f'
)
})
})
})
})
})
it
(
'should get if is syncing'
,
async
function
()
{
describe
(
'eth_syncing'
,
()
=>
{
let
isSyncing
=
await
web3
.
eth
.
isSyncing
()
it
(
'should get if is syncing'
,
async
function
()
{
assert
.
equal
(
isSyncing
,
false
)
let
isSyncing
=
await
web3
.
eth
.
isSyncing
()
assert
.
equal
(
isSyncing
,
false
)
})
})
describe
(
'eth_mining'
,
()
=>
{
it
(
'should get if is mining'
,
async
function
()
{
let
isMining
=
await
web3
.
eth
.
isMining
()
assert
.
equal
(
isMining
,
false
)
})
})
})
it
(
'should get if is mining'
,
async
function
()
{
describe
(
'eth_hashrate'
,
()
=>
{
let
isMining
=
await
web3
.
eth
.
isMining
()
it
(
'should get hashrate'
,
async
function
()
{
assert
.
equal
(
isMining
,
false
)
let
hashrate
=
await
web3
.
eth
.
getHashrate
()
assert
.
equal
(
hashrate
,
0
)
})
})
describe
(
'web3_sha3'
,
()
=>
{
it
(
'should get result of a sha3'
,
async
function
()
{
web3
.
_requestManager
.
send
({
method
:
'web3_sha3'
,
params
:
[
'0x68656c6c6f20776f726c64'
]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
}
assert
.
equal
(
result
,
'0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'
)
})
})
})
})
it
(
'should get hashrate'
,
async
function
()
{
describe
(
'eth_getCompilers'
,
()
=>
{
let
hashrate
=
await
web3
.
eth
.
getHashrate
()
it
(
'should get list of compilers'
,
async
function
()
{
assert
.
equal
(
hashrate
,
0
)
web3
.
_requestManager
.
send
({
method
:
'eth_getCompilers'
,
params
:
[]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
}
assert
.
equal
(
result
,
0
)
})
})
})
describe
(
'eth_compileSolidity'
,
()
=>
{
it
(
'get unsupported result when requesting solidity compiler'
,
async
function
()
{
web3
.
_requestManager
.
send
({
method
:
'eth_compileSolidity'
,
params
:
[]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
}
assert
.
equal
(
result
,
'unsupported'
)
})
})
})
describe
(
'eth_compileLLL'
,
()
=>
{
it
(
'get unsupported result when requesting LLL compiler'
,
async
function
()
{
web3
.
_requestManager
.
send
({
method
:
'eth_compileLLL'
,
params
:
[]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
}
assert
.
equal
(
result
,
'unsupported'
)
})
})
})
})
it
(
'should get result of a sha3'
,
async
function
()
{
describe
(
'eth_compileSerpent'
,
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'web3_sha3'
,
params
:
[
'0x68656c6c6f20776f726c64'
]},
(
err
,
result
)
=>
{
it
(
'get unsupported result when requesting serpent compiler'
,
async
function
()
{
if
(
err
)
{
web3
.
_requestManager
.
send
({
method
:
'eth_compileSerpent'
,
params
:
[]
},
(
err
,
result
)
=>
{
throw
new
Error
(
err
)
if
(
err
)
{
}
throw
new
Error
(
err
)
assert
.
equal
(
result
,
'0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'
)
}
assert
.
equal
(
result
,
'unsupported'
)
})
})
})
})
})
})
})
remix-simulator/test/whisper.js
deleted
100644 → 0
View file @
299b25b8
/* global describe, before, it */
var
Web3
=
require
(
'web3'
)
var
RemixSim
=
require
(
'../index.js'
)
let
web3
=
new
Web3
()
var
assert
=
require
(
'assert'
)
describe
(
'Whisper'
,
function
()
{
before
(
function
()
{
let
provider
=
new
RemixSim
.
Provider
()
web3
.
setProvider
(
provider
)
})
it
(
'should get correct remix simulator version'
,
async
function
()
{
let
version
=
await
web3
.
shh
.
getVersion
()
assert
.
equal
(
version
,
5
)
})
})
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