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
3c657daa
Commit
3c657daa
authored
Dec 16, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update remix-simulator syntax to use const, let and this
parent
eddc2e38
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
124 additions
and
124 deletions
+124
-124
index.js
remix-simulator/index.js
+1
-1
genesis.js
remix-simulator/src/genesis.js
+5
-5
accounts.js
remix-simulator/src/methods/accounts.js
+5
-5
blocks.js
remix-simulator/src/methods/blocks.js
+1
-1
filters.js
remix-simulator/src/methods/filters.js
+1
-1
misc.js
remix-simulator/src/methods/misc.js
+4
-4
net.js
remix-simulator/src/methods/net.js
+1
-1
transactions.js
remix-simulator/src/methods/transactions.js
+12
-12
txProcess.js
remix-simulator/src/methods/txProcess.js
+7
-7
provider.js
remix-simulator/src/provider.js
+4
-4
logs.js
remix-simulator/src/utils/logs.js
+10
-10
accounts.js
remix-simulator/test/accounts.js
+15
-15
blocks.js
remix-simulator/test/blocks.js
+37
-37
misc.js
remix-simulator/test/misc.js
+21
-21
No files found.
remix-simulator/index.js
View file @
3c657daa
var
Provider
=
require
(
'./src/provider'
)
const
Provider
=
require
(
'./src/provider'
)
module
.
exports
=
{
Provider
:
Provider
...
...
remix-simulator/src/genesis.js
View file @
3c657daa
var
EthJSBlock
=
require
(
'ethereumjs-block'
)
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
BN
=
ethJSUtil
.
BN
const
EthJSBlock
=
require
(
'ethereumjs-block'
)
const
ethJSUtil
=
require
(
'ethereumjs-util'
)
const
BN
=
ethJSUtil
.
BN
function
generateBlock
(
executionContext
)
{
var
block
=
new
EthJSBlock
({
const
block
=
new
EthJSBlock
({
header
:
{
timestamp
:
(
new
Date
().
getTime
()
/
1000
|
0
),
number
:
0
,
...
...
@@ -15,7 +15,7 @@ function generateBlock (executionContext) {
uncleHeaders
:
[]
})
executionContext
.
vm
().
runBlock
({
block
:
block
,
generate
:
true
,
skipBlockValidation
:
true
,
skipBalance
:
false
}).
then
(
function
()
{
executionContext
.
vm
().
runBlock
({
block
:
block
,
generate
:
true
,
skipBlockValidation
:
true
,
skipBalance
:
false
}).
then
(
()
=>
{
executionContext
.
addBlock
(
block
)
})
}
...
...
remix-simulator/src/methods/accounts.js
View file @
3c657daa
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
BN
=
ethJSUtil
.
BN
var
Web3
=
require
(
'web3'
)
const
ethJSUtil
=
require
(
'ethereumjs-util'
)
const
BN
=
ethJSUtil
.
BN
const
Web3
=
require
(
'web3'
)
var
Accounts
=
function
(
executionContext
)
{
const
Accounts
=
function
(
executionContext
)
{
this
.
web3
=
new
Web3
()
this
.
executionContext
=
executionContext
// TODO: make it random and/or use remix-libs
...
...
@@ -23,7 +23,7 @@ Accounts.prototype.init = async function () {
if
(
err
)
{
throw
new
Error
(
err
)
}
var
balance
=
'0x56BC75E2D63100000'
const
balance
=
'0x56BC75E2D63100000'
account
.
balance
=
balance
||
'0xf00000000000000001'
resolve
()
})
...
...
remix-simulator/src/methods/blocks.js
View file @
3c657daa
var
Blocks
=
function
(
executionContext
,
_options
)
{
const
Blocks
=
function
(
executionContext
,
_options
)
{
this
.
executionContext
=
executionContext
const
options
=
_options
||
{}
this
.
coinbase
=
options
.
coinbase
||
'0x0000000000000000000000000000000000000000'
...
...
remix-simulator/src/methods/filters.js
View file @
3c657daa
var
Filters
=
function
(
executionContext
)
{
const
Filters
=
function
(
executionContext
)
{
this
.
executionContext
=
executionContext
}
...
...
remix-simulator/src/methods/misc.js
View file @
3c657daa
var
version
=
require
(
'../../package.json'
).
version
var
web3
=
require
(
'web3'
)
const
version
=
require
(
'../../package.json'
).
version
const
web3
=
require
(
'web3'
)
var
Misc
=
function
()
{
const
Misc
=
function
()
{
}
Misc
.
prototype
.
methods
=
function
()
{
...
...
@@ -41,7 +41,7 @@ Misc.prototype.eth_hashrate = function (payload, cb) {
}
Misc
.
prototype
.
web3_sha3
=
function
(
payload
,
cb
)
{
le
t
str
=
payload
.
params
[
0
]
cons
t
str
=
payload
.
params
[
0
]
cb
(
null
,
web3
.
utils
.
sha3
(
str
))
}
...
...
remix-simulator/src/methods/net.js
View file @
3c657daa
var
Net
=
function
()
{
const
Net
=
function
()
{
}
Net
.
prototype
.
methods
=
function
()
{
...
...
remix-simulator/src/methods/transactions.js
View file @
3c657daa
var
Web3
=
require
(
'web3'
)
var
ethJSUtil
=
require
(
'ethereumjs-util'
)
var
processTx
=
require
(
'./txProcess.js'
)
var
BN
=
ethJSUtil
.
BN
const
Web3
=
require
(
'web3'
)
const
ethJSUtil
=
require
(
'ethereumjs-util'
)
const
processTx
=
require
(
'./txProcess.js'
)
const
BN
=
ethJSUtil
.
BN
var
Transactions
=
function
(
executionContext
)
{
const
Transactions
=
function
(
executionContext
)
{
this
.
executionContext
=
executionContext
}
...
...
@@ -39,9 +39,9 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
return
cb
(
error
)
}
var
txBlock
=
this
.
executionContext
.
txs
[
receipt
.
hash
]
const
txBlock
=
this
.
executionContext
.
txs
[
receipt
.
hash
]
var
r
=
{
const
r
=
{
'transactionHash'
:
receipt
.
hash
,
'transactionIndex'
:
'0x00'
,
'blockHash'
:
'0x'
+
txBlock
.
hash
().
toString
(
'hex'
),
...
...
@@ -111,10 +111,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
return
cb
(
error
)
}
var
txBlock
=
this
.
executionContext
.
txs
[
receipt
.
transactionHash
]
const
txBlock
=
this
.
executionContext
.
txs
[
receipt
.
transactionHash
]
// TODO: params to add later
le
t
r
=
{
cons
t
r
=
{
'blockHash'
:
'0x'
+
txBlock
.
hash
().
toString
(
'hex'
),
'blockNumber'
:
'0x'
+
txBlock
.
header
.
number
.
toString
(
'hex'
),
'from'
:
receipt
.
from
,
...
...
@@ -151,7 +151,7 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
Transactions
.
prototype
.
eth_getTransactionByBlockHashAndIndex
=
function
(
payload
,
cb
)
{
const
txIndex
=
payload
.
params
[
1
]
var
txBlock
=
this
.
executionContext
.
blocks
[
payload
.
params
[
0
]]
const
txBlock
=
this
.
executionContext
.
blocks
[
payload
.
params
[
0
]]
const
txHash
=
'0x'
+
txBlock
.
transactions
[
Web3
.
utils
.
toDecimal
(
txIndex
)].
hash
().
toString
(
'hex'
)
this
.
executionContext
.
web3
().
eth
.
getTransactionReceipt
(
txHash
,
(
error
,
receipt
)
=>
{
...
...
@@ -193,7 +193,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
Transactions
.
prototype
.
eth_getTransactionByBlockNumberAndIndex
=
function
(
payload
,
cb
)
{
const
txIndex
=
payload
.
params
[
1
]
var
txBlock
=
this
.
executionContext
.
blocks
[
payload
.
params
[
0
]]
const
txBlock
=
this
.
executionContext
.
blocks
[
payload
.
params
[
0
]]
const
txHash
=
'0x'
+
txBlock
.
transactions
[
Web3
.
utils
.
toDecimal
(
txIndex
)].
hash
().
toString
(
'hex'
)
this
.
executionContext
.
web3
().
eth
.
getTransactionReceipt
(
txHash
,
(
error
,
receipt
)
=>
{
...
...
@@ -202,7 +202,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
}
// TODO: params to add later
le
t
r
=
{
cons
t
r
=
{
'blockHash'
:
'0x'
+
txBlock
.
hash
().
toString
(
'hex'
),
'blockNumber'
:
'0x'
+
txBlock
.
header
.
number
.
toString
(
'hex'
),
'from'
:
receipt
.
from
,
...
...
remix-simulator/src/methods/txProcess.js
View file @
3c657daa
var
RemixLib
=
require
(
'remix-lib'
)
var
TxExecution
=
RemixLib
.
execution
.
txExecution
var
TxRunner
=
RemixLib
.
execution
.
txRunner
const
RemixLib
=
require
(
'remix-lib'
)
const
TxExecution
=
RemixLib
.
execution
.
txExecution
const
TxRunner
=
RemixLib
.
execution
.
txRunner
function
runCall
(
payload
,
from
,
to
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
)
{
le
t
finalCallback
=
function
(
err
,
result
)
{
cons
t
finalCallback
=
function
(
err
,
result
)
{
if
(
err
)
{
return
callback
(
err
)
}
...
...
@@ -16,7 +16,7 @@ function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks,
}
function
runTx
(
payload
,
from
,
to
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
)
{
le
t
finalCallback
=
function
(
err
,
result
)
{
cons
t
finalCallback
=
function
(
err
,
result
)
{
if
(
err
)
{
return
callback
(
err
)
}
...
...
@@ -27,7 +27,7 @@ function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, c
}
function
createContract
(
payload
,
from
,
data
,
value
,
gasLimit
,
txRunner
,
callbacks
,
callback
)
{
le
t
finalCallback
=
function
(
err
,
result
)
{
cons
t
finalCallback
=
function
(
err
,
result
)
{
if
(
err
)
{
return
callback
(
err
)
}
...
...
@@ -40,7 +40,7 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac
let
txRunnerInstance
function
processTx
(
executionContext
,
accounts
,
payload
,
isCall
,
callback
)
{
le
t
api
=
{
cons
t
api
=
{
logMessage
:
(
msg
)
=>
{
},
logHtmlMessage
:
(
msg
)
=>
{
...
...
remix-simulator/src/provider.js
View file @
3c657daa
var
RemixLib
=
require
(
'remix-lib'
)
var
executionContext
=
RemixLib
.
execution
.
executionContext
const
RemixLib
=
require
(
'remix-lib'
)
const
executionContext
=
RemixLib
.
execution
.
executionContext
const
log
=
require
(
'./utils/logs.js'
)
const
merge
=
require
(
'merge'
)
...
...
@@ -40,7 +40,7 @@ Provider.prototype.init = async function () {
Provider
.
prototype
.
sendAsync
=
function
(
payload
,
callback
)
{
log
.
info
(
'payload method is '
,
payload
.
method
)
le
t
method
=
this
.
methods
[
payload
.
method
]
cons
t
method
=
this
.
methods
[
payload
.
method
]
if
(
this
.
options
.
logDetails
)
{
log
.
info
(
payload
)
}
...
...
@@ -53,7 +53,7 @@ Provider.prototype.sendAsync = function (payload, callback) {
if
(
err
)
{
return
callback
(
err
)
}
le
t
response
=
{
'id'
:
payload
.
id
,
'jsonrpc'
:
'2.0'
,
'result'
:
result
}
cons
t
response
=
{
'id'
:
payload
.
id
,
'jsonrpc'
:
'2.0'
,
'result'
:
result
}
callback
(
null
,
response
)
})
}
...
...
remix-simulator/src/utils/logs.js
View file @
3c657daa
'use strict'
var
gray
=
require
(
'ansi-gray'
)
var
timestamp
=
require
(
'time-stamp'
)
var
supportsColor
=
require
(
'color-support'
)
const
gray
=
require
(
'ansi-gray'
)
const
timestamp
=
require
(
'time-stamp'
)
const
supportsColor
=
require
(
'color-support'
)
function
hasFlag
(
flag
)
{
return
((
typeof
(
process
)
!==
'undefined'
)
&&
(
process
.
argv
.
indexOf
(
'--'
+
flag
)
!==
-
1
))
...
...
@@ -24,7 +24,7 @@ function addColor (str) {
return
str
}
le
t
logger
=
{
cons
t
logger
=
{
stdout
:
function
(
arg
)
{
if
(
typeof
(
process
)
===
'undefined'
||
!
process
.
stdout
)
return
process
.
stdout
.
write
(
arg
)
...
...
@@ -36,40 +36,40 @@ let logger = {
}
function
getTimestamp
()
{
le
t
coloredTimestamp
=
addColor
(
timestamp
(
'HH:mm:ss'
))
cons
t
coloredTimestamp
=
addColor
(
timestamp
(
'HH:mm:ss'
))
return
'['
+
coloredTimestamp
+
']'
}
function
log
()
{
var
time
=
getTimestamp
()
const
time
=
getTimestamp
()
logger
.
stdout
(
time
+
' '
)
console
.
log
.
apply
(
console
,
arguments
)
return
this
}
function
info
()
{
var
time
=
getTimestamp
()
const
time
=
getTimestamp
()
logger
.
stdout
(
time
+
' '
)
console
.
info
.
apply
(
console
,
arguments
)
return
this
}
function
dir
()
{
var
time
=
getTimestamp
()
const
time
=
getTimestamp
()
logger
.
stdout
(
time
+
' '
)
console
.
dir
.
apply
(
console
,
arguments
)
return
this
}
function
warn
()
{
var
time
=
getTimestamp
()
const
time
=
getTimestamp
()
logger
.
stderr
(
time
+
' '
)
console
.
warn
.
apply
(
console
,
arguments
)
return
this
}
function
error
()
{
var
time
=
getTimestamp
()
const
time
=
getTimestamp
()
logger
.
stderr
(
time
+
' '
)
console
.
error
.
apply
(
console
,
arguments
)
return
this
...
...
remix-simulator/test/accounts.js
View file @
3c657daa
/* global describe, before, it */
var
Web3
=
require
(
'web3'
)
var
RemixSim
=
require
(
'../index.js'
)
le
t
web3
=
new
Web3
()
var
assert
=
require
(
'assert'
)
const
Web3
=
require
(
'web3'
)
const
RemixSim
=
require
(
'../index.js'
)
cons
t
web3
=
new
Web3
()
const
assert
=
require
(
'assert'
)
describe
(
'Accounts'
,
function
()
{
describe
(
'Accounts'
,
()
=>
{
before
(
function
()
{
le
t
provider
=
new
RemixSim
.
Provider
()
cons
t
provider
=
new
RemixSim
.
Provider
()
web3
.
setProvider
(
provider
)
})
describe
(
'eth_getAccounts'
,
()
=>
{
it
(
'should get a list of accounts'
,
async
function
()
{
le
t
accounts
=
await
web3
.
eth
.
getAccounts
()
cons
t
accounts
=
await
web3
.
eth
.
getAccounts
()
assert
.
notEqual
(
accounts
.
length
,
0
)
})
})
describe
(
'eth_getBalance'
,
()
=>
{
it
(
'should get a account balance'
,
async
function
()
{
le
t
accounts
=
await
web3
.
eth
.
getAccounts
()
le
t
balance0
=
await
web3
.
eth
.
getBalance
(
accounts
[
0
])
le
t
balance1
=
await
web3
.
eth
.
getBalance
(
accounts
[
1
])
le
t
balance2
=
await
web3
.
eth
.
getBalance
(
accounts
[
2
])
it
(
'should get a account balance'
,
async
()
=>
{
cons
t
accounts
=
await
web3
.
eth
.
getAccounts
()
cons
t
balance0
=
await
web3
.
eth
.
getBalance
(
accounts
[
0
])
cons
t
balance1
=
await
web3
.
eth
.
getBalance
(
accounts
[
1
])
cons
t
balance2
=
await
web3
.
eth
.
getBalance
(
accounts
[
2
])
assert
.
deepEqual
(
balance0
,
'100000000000000000000'
)
assert
.
deepEqual
(
balance1
,
'100000000000000000000'
)
...
...
@@ -31,9 +31,9 @@ describe('Accounts', function () {
})
describe
(
'eth_sign'
,
()
=>
{
it
(
'should sign payloads'
,
async
function
()
{
le
t
accounts
=
await
web3
.
eth
.
getAccounts
()
le
t
signature
=
await
web3
.
eth
.
sign
(
'Hello world'
,
accounts
[
0
])
it
(
'should sign payloads'
,
async
()
=>
{
cons
t
accounts
=
await
web3
.
eth
.
getAccounts
()
cons
t
signature
=
await
web3
.
eth
.
sign
(
'Hello world'
,
accounts
[
0
])
assert
.
deepEqual
(
signature
.
length
,
132
)
})
...
...
remix-simulator/test/blocks.js
View file @
3c657daa
This diff is collapsed.
Click to expand it.
remix-simulator/test/misc.js
View file @
3c657daa
/* global describe, before, it */
var
Web3
=
require
(
'web3'
)
var
RemixSim
=
require
(
'../index.js'
)
le
t
web3
=
new
Web3
()
var
assert
=
require
(
'assert'
)
const
Web3
=
require
(
'web3'
)
const
RemixSim
=
require
(
'../index.js'
)
cons
t
web3
=
new
Web3
()
const
assert
=
require
(
'assert'
)
describe
(
'Misc'
,
function
()
{
before
(
function
()
{
le
t
provider
=
new
RemixSim
.
Provider
()
describe
(
'Misc'
,
()
=>
{
before
(
()
=>
{
cons
t
provider
=
new
RemixSim
.
Provider
()
web3
.
setProvider
(
provider
)
})
describe
(
'web3_clientVersion'
,
()
=>
{
it
(
'should get correct remix simulator version'
,
async
function
(
done
)
{
it
(
'should get correct remix simulator version'
,
async
(
done
)
=>
{
web3
.
_requestManager
.
send
({
method
:
'web3_clientVersion'
,
params
:
[]
},
(
err
,
version
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
}
le
t
remixVersion
=
require
(
'../package.json'
).
version
cons
t
remixVersion
=
require
(
'../package.json'
).
version
assert
.
equal
(
version
,
'Remix Simulator/'
+
remixVersion
)
done
()
})
...
...
@@ -24,7 +24,7 @@ describe('Misc', function () {
})
describe
(
'eth_protocolVersion'
,
()
=>
{
it
(
'should get protocol version'
,
async
function
()
{
it
(
'should get protocol version'
,
async
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'eth_protocolVersion'
,
params
:
[]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
...
...
@@ -35,28 +35,28 @@ describe('Misc', function () {
})
describe
(
'eth_syncing'
,
()
=>
{
it
(
'should get if is syncing'
,
async
function
()
{
le
t
isSyncing
=
await
web3
.
eth
.
isSyncing
()
it
(
'should get if is syncing'
,
async
()
=>
{
cons
t
isSyncing
=
await
web3
.
eth
.
isSyncing
()
assert
.
equal
(
isSyncing
,
false
)
})
})
describe
(
'eth_mining'
,
()
=>
{
it
(
'should get if is mining'
,
async
function
()
{
le
t
isMining
=
await
web3
.
eth
.
isMining
()
it
(
'should get if is mining'
,
async
()
=>
{
cons
t
isMining
=
await
web3
.
eth
.
isMining
()
assert
.
equal
(
isMining
,
false
)
})
})
describe
(
'eth_hashrate'
,
()
=>
{
it
(
'should get hashrate'
,
async
function
()
{
le
t
hashrate
=
await
web3
.
eth
.
getHashrate
()
it
(
'should get hashrate'
,
async
()
=>
{
cons
t
hashrate
=
await
web3
.
eth
.
getHashrate
()
assert
.
equal
(
hashrate
,
0
)
})
})
describe
(
'web3_sha3'
,
()
=>
{
it
(
'should get result of a sha3'
,
async
function
()
{
it
(
'should get result of a sha3'
,
async
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'web3_sha3'
,
params
:
[
'0x68656c6c6f20776f726c64'
]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
...
...
@@ -67,7 +67,7 @@ describe('Misc', function () {
})
describe
(
'eth_getCompilers'
,
()
=>
{
it
(
'should get list of compilers'
,
async
function
()
{
it
(
'should get list of compilers'
,
async
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'eth_getCompilers'
,
params
:
[]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
...
...
@@ -78,7 +78,7 @@ describe('Misc', function () {
})
describe
(
'eth_compileSolidity'
,
()
=>
{
it
(
'get unsupported result when requesting solidity compiler'
,
async
function
()
{
it
(
'get unsupported result when requesting solidity compiler'
,
async
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'eth_compileSolidity'
,
params
:
[]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
...
...
@@ -89,7 +89,7 @@ describe('Misc', function () {
})
describe
(
'eth_compileLLL'
,
()
=>
{
it
(
'get unsupported result when requesting LLL compiler'
,
async
function
()
{
it
(
'get unsupported result when requesting LLL compiler'
,
async
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'eth_compileLLL'
,
params
:
[]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
...
...
@@ -100,7 +100,7 @@ describe('Misc', function () {
})
describe
(
'eth_compileSerpent'
,
()
=>
{
it
(
'get unsupported result when requesting serpent compiler'
,
async
function
()
{
it
(
'get unsupported result when requesting serpent compiler'
,
async
()
=>
{
web3
.
_requestManager
.
send
({
method
:
'eth_compileSerpent'
,
params
:
[]
},
(
err
,
result
)
=>
{
if
(
err
)
{
throw
new
Error
(
err
)
...
...
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