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
a044b343
Unverified
Commit
a044b343
authored
Sep 04, 2019
by
yann300
Committed by
GitHub
Sep 04, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1281 from ethereum/instanciatAsynceRemixSimulator
Init remix-simulator
parents
5861e612
1f11d3da
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
57 additions
and
37 deletions
+57
-37
execution-context.js
remix-lib/src/execution/execution-context.js
+0
-14
universalDapp.js
remix-lib/src/universalDapp.js
+2
-2
package.json
remix-simulator/package.json
+1
-0
genesis.js
remix-simulator/src/genesis.js
+2
-4
accounts.js
remix-simulator/src/methods/accounts.js
+19
-10
transactions.js
remix-simulator/src/methods/transactions.js
+11
-1
provider.js
remix-simulator/src/provider.js
+7
-1
server.js
remix-simulator/src/server.js
+7
-0
runTestSources.ts
remix-tests/src/runTestSources.ts
+6
-4
testRunner.ts
remix-tests/tests/testRunner.ts
+2
-1
No files found.
remix-lib/src/execution/execution-context.js
View file @
a044b343
...
@@ -238,20 +238,6 @@ function ExecutionContext () {
...
@@ -238,20 +238,6 @@ function ExecutionContext () {
}
}
}
}
this
.
checkpointAndCommit
=
function
(
cb
,
checkpointCount
)
{
// due to issue https://github.com/ethereumjs/ethereumjs-vm/issues/567
if
(
this
.
vm
().
stateManager
.
_checkpointCount
>
(
checkpointCount
||
0
))
{
return
this
.
vm
().
stateManager
.
commit
(()
=>
{
cb
()
})
}
this
.
vm
().
stateManager
.
checkpoint
(()
=>
{
this
.
vm
().
stateManager
.
commit
(()
=>
{
cb
()
})
})
}
this
.
currentblockGasLimit
=
function
()
{
this
.
currentblockGasLimit
=
function
()
{
return
this
.
blockGasLimit
return
this
.
blockGasLimit
}
}
...
...
remix-lib/src/universalDapp.js
View file @
a044b343
const
async
=
require
(
'async'
)
const
async
=
require
(
'async'
)
const
{
BN
,
privateToAddress
,
isValidPrivate
,
stripHexPrefix
}
=
require
(
'ethereumjs-util'
)
const
{
BN
,
privateToAddress
,
isValidPrivate
,
stripHexPrefix
,
toChecksumAddress
}
=
require
(
'ethereumjs-util'
)
const
crypto
=
require
(
'crypto'
)
const
crypto
=
require
(
'crypto'
)
const
{
EventEmitter
}
=
require
(
'events'
)
const
{
EventEmitter
}
=
require
(
'events'
)
...
@@ -121,7 +121,7 @@ module.exports = class UniversalDApp {
...
@@ -121,7 +121,7 @@ module.exports = class UniversalDApp {
})
})
})
})
this
.
accounts
[
'0x'
+
address
.
toString
(
'hex'
)]
=
{
privateKey
,
nonce
:
0
}
this
.
accounts
[
toChecksumAddress
(
'0x'
+
address
.
toString
(
'hex'
)
)]
=
{
privateKey
,
nonce
:
0
}
}
}
}
}
...
...
remix-simulator/package.json
View file @
a044b343
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
"body-parser"
:
"^1.18.2"
,
"body-parser"
:
"^1.18.2"
,
"color-support"
:
"^1.1.3"
,
"color-support"
:
"^1.1.3"
,
"commander"
:
"^2.19.0"
,
"commander"
:
"^2.19.0"
,
"cors"
:
"^2.8.5"
,
"ethereumjs-util"
:
"^5.1.2"
,
"ethereumjs-util"
:
"^5.1.2"
,
"ethereumjs-vm"
:
"3.0.0"
,
"ethereumjs-vm"
:
"3.0.0"
,
"express"
:
"^4.16.3"
,
"express"
:
"^4.16.3"
,
...
...
remix-simulator/src/genesis.js
View file @
a044b343
...
@@ -17,10 +17,8 @@ function generateBlock () {
...
@@ -17,10 +17,8 @@ function generateBlock () {
uncleHeaders
:
[]
uncleHeaders
:
[]
})
})
executionContext
.
checkpointAndCommit
(()
=>
{
executionContext
.
vm
().
runBlock
({
block
:
block
,
generate
:
true
,
skipBlockValidation
:
true
,
skipBalance
:
false
},
function
()
{
executionContext
.
vm
().
runBlock
({
block
:
block
,
generate
:
true
,
skipBlockValidation
:
true
,
skipBalance
:
false
},
function
()
{
executionContext
.
addBlock
(
block
)
executionContext
.
addBlock
(
block
)
})
})
})
}
}
...
...
remix-simulator/src/methods/accounts.js
View file @
a044b343
...
@@ -12,19 +12,28 @@ var Accounts = function () {
...
@@ -12,19 +12,28 @@ var Accounts = function () {
this
.
accountsKeys
=
{}
this
.
accountsKeys
=
{}
executionContext
.
init
({
get
:
()
=>
{
return
true
}})
executionContext
.
init
({
get
:
()
=>
{
return
true
}})
}
for
(
let
_account
of
this
.
accountsList
)
{
Accounts
.
prototype
.
init
=
async
function
()
{
this
.
accountsKeys
[
_account
.
address
.
toLowerCase
()]
=
_account
.
privateKey
let
setBalance
=
(
account
)
=>
{
this
.
accounts
[
_account
.
address
.
toLowerCase
()]
=
{
privateKey
:
Buffer
.
from
(
_account
.
privateKey
.
replace
(
'0x'
,
''
),
'hex'
),
nonce
:
0
}
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
account
.
address
)]
=
account
.
privateKey
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
.
toLowerCase
().
replace
(
'0x'
,
''
),
'hex'
),
(
err
,
account
)
=>
{
if
(
err
)
{
if
(
err
)
{
throw
new
Error
(
err
)
throw
new
Error
(
err
)
}
}
var
balance
=
'0x56BC75E2D63100000'
var
balance
=
'0x56BC75E2D63100000'
account
.
balance
=
balance
||
'0xf00000000000000001'
account
.
balance
=
balance
||
'0xf00000000000000001'
resolve
()
})
})
})
}
}
for
(
let
_account
of
this
.
accountsList
)
{
await
setBalance
(
_account
)
}
}
}
Accounts
.
prototype
.
methods
=
function
()
{
Accounts
.
prototype
.
methods
=
function
()
{
...
@@ -36,7 +45,7 @@ Accounts.prototype.methods = function () {
...
@@ -36,7 +45,7 @@ Accounts.prototype.methods = function () {
}
}
Accounts
.
prototype
.
eth_accounts
=
function
(
payload
,
cb
)
{
Accounts
.
prototype
.
eth_accounts
=
function
(
payload
,
cb
)
{
return
cb
(
null
,
this
.
accountsList
.
map
((
x
)
=>
x
.
address
))
return
cb
(
null
,
this
.
accountsList
.
map
((
x
)
=>
ethJSUtil
.
toChecksumAddress
(
x
.
address
)
))
}
}
Accounts
.
prototype
.
eth_getBalance
=
function
(
payload
,
cb
)
{
Accounts
.
prototype
.
eth_getBalance
=
function
(
payload
,
cb
)
{
...
...
remix-simulator/src/methods/transactions.js
View file @
a044b343
...
@@ -5,7 +5,9 @@ var ethJSUtil = require('ethereumjs-util')
...
@@ -5,7 +5,9 @@ var ethJSUtil = require('ethereumjs-util')
var
processTx
=
require
(
'./txProcess.js'
)
var
processTx
=
require
(
'./txProcess.js'
)
var
BN
=
ethJSUtil
.
BN
var
BN
=
ethJSUtil
.
BN
var
Transactions
=
function
(
accounts
)
{
var
Transactions
=
function
()
{}
Transactions
.
prototype
.
init
=
function
(
accounts
)
{
this
.
accounts
=
accounts
this
.
accounts
=
accounts
}
}
...
@@ -24,6 +26,10 @@ Transactions.prototype.methods = function () {
...
@@ -24,6 +26,10 @@ Transactions.prototype.methods = function () {
}
}
Transactions
.
prototype
.
eth_sendTransaction
=
function
(
payload
,
cb
)
{
Transactions
.
prototype
.
eth_sendTransaction
=
function
(
payload
,
cb
)
{
// from might be lowercased address (web3)
if
(
payload
.
params
&&
payload
.
params
.
length
>
0
&&
payload
.
params
[
0
].
from
)
{
payload
.
params
[
0
].
from
=
ethJSUtil
.
toChecksumAddress
(
payload
.
params
[
0
].
from
)
}
processTx
(
this
.
accounts
,
payload
,
false
,
cb
)
processTx
(
this
.
accounts
,
payload
,
false
,
cb
)
}
}
...
@@ -68,6 +74,10 @@ Transactions.prototype.eth_getCode = function (payload, cb) {
...
@@ -68,6 +74,10 @@ Transactions.prototype.eth_getCode = function (payload, cb) {
}
}
Transactions
.
prototype
.
eth_call
=
function
(
payload
,
cb
)
{
Transactions
.
prototype
.
eth_call
=
function
(
payload
,
cb
)
{
// from might be lowercased address (web3)
if
(
payload
.
params
&&
payload
.
params
.
length
>
0
&&
payload
.
params
[
0
].
from
)
{
payload
.
params
[
0
].
from
=
ethJSUtil
.
toChecksumAddress
(
payload
.
params
[
0
].
from
)
}
processTx
(
this
.
accounts
,
payload
,
true
,
cb
)
processTx
(
this
.
accounts
,
payload
,
true
,
cb
)
}
}
...
...
remix-simulator/src/provider.js
View file @
a044b343
...
@@ -12,18 +12,24 @@ const generateBlock = require('./genesis.js')
...
@@ -12,18 +12,24 @@ const generateBlock = require('./genesis.js')
var
Provider
=
function
(
options
)
{
var
Provider
=
function
(
options
)
{
this
.
Accounts
=
new
Accounts
()
this
.
Accounts
=
new
Accounts
()
this
.
Transactions
=
new
Transactions
()
this
.
methods
=
{}
this
.
methods
=
{}
this
.
methods
=
merge
(
this
.
methods
,
this
.
Accounts
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
this
.
Accounts
.
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Blocks
(
options
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Blocks
(
options
)).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Misc
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Misc
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Net
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Net
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Transactions
(
this
.
Accounts
.
accounts
)).
methods
(
))
this
.
methods
=
merge
(
this
.
methods
,
(
this
.
Transactions
.
methods
()
))
this
.
methods
=
merge
(
this
.
methods
,
(
new
Whisper
()).
methods
())
this
.
methods
=
merge
(
this
.
methods
,
(
new
Whisper
()).
methods
())
generateBlock
()
generateBlock
()
}
}
Provider
.
prototype
.
init
=
async
function
()
{
await
this
.
Accounts
.
init
()
this
.
Transactions
.
init
(
this
.
Accounts
.
accounts
)
}
Provider
.
prototype
.
sendAsync
=
function
(
payload
,
callback
)
{
Provider
.
prototype
.
sendAsync
=
function
(
payload
,
callback
)
{
log
.
info
(
'payload method is '
,
payload
.
method
)
log
.
info
(
'payload method is '
,
payload
.
method
)
...
...
remix-simulator/src/server.js
View file @
a044b343
const
express
=
require
(
'express'
)
const
express
=
require
(
'express'
)
const
cors
=
require
(
'cors'
)
const
bodyParser
=
require
(
'body-parser'
)
const
bodyParser
=
require
(
'body-parser'
)
const
app
=
express
()
const
app
=
express
()
const
expressWs
=
require
(
'express-ws'
)
const
expressWs
=
require
(
'express-ws'
)
...
@@ -8,11 +9,17 @@ const log = require('./utils/logs.js')
...
@@ -8,11 +9,17 @@ const log = require('./utils/logs.js')
class
Server
{
class
Server
{
constructor
(
options
)
{
constructor
(
options
)
{
this
.
provider
=
new
Provider
(
options
)
this
.
provider
=
new
Provider
(
options
)
this
.
provider
.
init
().
then
(()
=>
{
log
(
'Provider initiated'
)
}).
catch
((
error
)
=>
{
log
(
error
)
})
}
}
start
(
host
,
port
)
{
start
(
host
,
port
)
{
expressWs
(
app
)
expressWs
(
app
)
app
.
use
(
cors
())
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}))
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}))
app
.
use
(
bodyParser
.
json
())
app
.
use
(
bodyParser
.
json
())
...
...
remix-tests/src/runTestSources.ts
View file @
a044b343
...
@@ -10,15 +10,17 @@ import Web3 = require('web3')
...
@@ -10,15 +10,17 @@ import Web3 = require('web3')
import
{
Provider
}
from
'remix-simulator'
import
{
Provider
}
from
'remix-simulator'
import
{
FinalResult
}
from
'./types'
import
{
FinalResult
}
from
'./types'
const
createWeb3Provider
=
function
()
{
const
createWeb3Provider
=
async
function
()
{
let
web3
=
new
Web3
()
let
web3
=
new
Web3
()
web3
.
setProvider
(
new
Provider
())
let
provider
=
new
Provider
()
await
provider
.
init
()
web3
.
setProvider
(
provider
)
return
web3
return
web3
}
}
export
function
runTestSources
(
contractSources
,
testCallback
,
resultCallback
,
finalCallback
,
importFileCb
,
opts
)
{
export
async
function
runTestSources
(
contractSources
,
testCallback
,
resultCallback
,
finalCallback
,
importFileCb
,
opts
)
{
opts
=
opts
||
{}
opts
=
opts
||
{}
let
web3
=
opts
.
web3
||
createWeb3Provider
()
let
web3
=
opts
.
web3
||
await
createWeb3Provider
()
let
accounts
=
opts
.
accounts
||
null
let
accounts
=
opts
.
accounts
||
null
async
.
waterfall
([
async
.
waterfall
([
function
getAccountList
(
next
)
{
function
getAccountList
(
next
)
{
...
...
remix-tests/tests/testRunner.ts
View file @
a044b343
...
@@ -11,8 +11,9 @@ import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/in
...
@@ -11,8 +11,9 @@ import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/in
var
provider
=
new
Provider
()
var
provider
=
new
Provider
()
function
compileAndDeploy
(
filename
:
string
,
callback
:
Function
)
{
async
function
compileAndDeploy
(
filename
:
string
,
callback
:
Function
)
{
let
web3
:
Web3
=
new
Web3
()
let
web3
:
Web3
=
new
Web3
()
await
provider
.
init
()
web3
.
setProvider
(
provider
)
web3
.
setProvider
(
provider
)
let
compilationData
:
object
let
compilationData
:
object
let
accounts
:
string
[]
let
accounts
:
string
[]
...
...
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