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
12c5668b
Commit
12c5668b
authored
Sep 25, 2019
by
Iuri Matias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ongoing fixes for remix-sim
parent
335cfd71
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
15 deletions
+56
-15
accounts.js
remix-simulator/src/methods/accounts.js
+17
-2
blocks.js
remix-simulator/src/methods/blocks.js
+10
-1
transactions.js
remix-simulator/src/methods/transactions.js
+10
-1
provider.js
remix-simulator/src/provider.js
+6
-1
blocks.js
remix-simulator/test/blocks.js
+13
-10
No files found.
remix-simulator/src/methods/accounts.js
View file @
12c5668b
...
@@ -17,10 +17,22 @@ var Accounts = function () {
...
@@ -17,10 +17,22 @@ var Accounts = function () {
Accounts
.
prototype
.
init
=
async
function
()
{
Accounts
.
prototype
.
init
=
async
function
()
{
let
setBalance
=
(
account
)
=>
{
let
setBalance
=
(
account
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
// this.accountsKeys[ethJSUtil.toChecksumAddress(account.address).toLowerCase()] = account.privateKey
// this.accounts[ethJSUtil.toChecksumAddress(account.address).toLowerCase()] = { privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'), nonce: 0 }
// executionContext.vm().stateManager.getAccount(Buffer.from(account.address.toLowerCase().replace('0x', ''), 'hex'), (err, account) => {
// if (err) {
// throw new Error(err)
// }
// var balance = '0x56BC75E2D63100000'
// account.balance = balance || '0xf00000000000000001'
// resolve()
// })
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
)
}
}
...
@@ -64,7 +76,10 @@ Accounts.prototype.eth_sign = function (payload, cb) {
...
@@ -64,7 +76,10 @@ Accounts.prototype.eth_sign = function (payload, cb) {
let
address
=
payload
.
params
[
0
]
let
address
=
payload
.
params
[
0
]
let
message
=
payload
.
params
[
1
]
let
message
=
payload
.
params
[
1
]
let
privateKey
=
this
.
accountsKeys
[
address
]
let
privateKey
=
this
.
accountsKeys
[
ethJSUtil
.
toChecksumAddress
(
address
)]
if
(
!
privateKey
)
{
return
cb
(
new
Error
(
'unknown account'
))
}
let
account
=
this
.
web3
.
eth
.
accounts
.
privateKeyToAccount
(
privateKey
)
let
account
=
this
.
web3
.
eth
.
accounts
.
privateKeyToAccount
(
privateKey
)
let
data
=
account
.
sign
(
message
)
let
data
=
account
.
sign
(
message
)
...
...
remix-simulator/src/methods/blocks.js
View file @
12c5668b
...
@@ -23,7 +23,16 @@ Blocks.prototype.methods = function () {
...
@@ -23,7 +23,16 @@ Blocks.prototype.methods = function () {
}
}
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
=
(
Object
.
keys
(
executionContext
.
blocks
).
length
/
2
)
-
1
}
// =======
// TODO: FIX ME
// var block = executionContext.blocks[blockIndex]
var
block
=
Object
.
values
(
executionContext
.
blocks
)[
0
]
// =======
if
(
!
block
)
{
if
(
!
block
)
{
return
cb
(
new
Error
(
'block not found'
))
return
cb
(
new
Error
(
'block not found'
))
...
...
remix-simulator/src/methods/transactions.js
View file @
12c5668b
...
@@ -50,7 +50,12 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
...
@@ -50,7 +50,12 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
'cumulativeGasUsed'
:
Web3
.
utils
.
toHex
(
receipt
.
gas
),
'cumulativeGasUsed'
:
Web3
.
utils
.
toHex
(
receipt
.
gas
),
'contractAddress'
:
receipt
.
contractAddress
,
'contractAddress'
:
receipt
.
contractAddress
,
'logs'
:
receipt
.
logs
,
'logs'
:
receipt
.
logs
,
'status'
:
receipt
.
status
// 'status': receipt.status
'status'
:
"0x01"
}
if
(
r
.
blockNumber
===
'0x'
)
{
r
.
blockNumber
=
'0x0'
}
}
cb
(
null
,
r
)
cb
(
null
,
r
)
...
@@ -130,6 +135,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
...
@@ -130,6 +135,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/provider.js
View file @
12c5668b
...
@@ -23,9 +23,11 @@ var Provider = function (options) {
...
@@ -23,9 +23,11 @@ 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
,
(
new
Transactions
(
this
.
Accounts
.
accounts
)).
methods
())
// this.methods = merge(this.methods, (new Transactions(this.Accounts.accounts)).methods())
this
.
methods
=
merge
(
this
.
methods
,
this
.
Transactions
.
methods
())
generateBlock
()
generateBlock
()
this
.
init
()
}
}
Provider
.
prototype
.
init
=
async
function
()
{
Provider
.
prototype
.
init
=
async
function
()
{
...
@@ -37,8 +39,11 @@ Provider.prototype.sendAsync = function (payload, callback) {
...
@@ -37,8 +39,11 @@ 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
]
console
.
dir
(
payload
)
if
(
method
)
{
if
(
method
)
{
return
method
.
call
(
method
,
payload
,
(
err
,
result
)
=>
{
return
method
.
call
(
method
,
payload
,
(
err
,
result
)
=>
{
console
.
dir
(
err
)
console
.
dir
(
result
)
if
(
err
)
{
if
(
err
)
{
return
callback
(
err
)
return
callback
(
err
)
}
}
...
...
remix-simulator/test/blocks.js
View file @
12c5668b
...
@@ -29,7 +29,7 @@ describe('blocks', function () {
...
@@ -29,7 +29,7 @@ describe('blocks', function () {
parentHash
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
parentHash
:
'0x0000000000000000000000000000000000000000000000000000000000000000'
,
sha3Uncles
:
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
,
sha3Uncles
:
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
,
size
:
163591
,
size
:
163591
,
stateRoot
:
'0x
a633ca0e8f0ae4e86d4d572b048ea93d84eb4b11e2c988b48cb3a5f6f10b3c68
'
,
stateRoot
:
'0x
63e1738ea12d4e7d12b71f0f4604706417921eb6a62c407ca5f1d66b9e67f579
'
,
timestamp
:
block
.
timestamp
,
timestamp
:
block
.
timestamp
,
totalDifficulty
:
'0'
,
totalDifficulty
:
'0'
,
transactions
:
[],
transactions
:
[],
...
@@ -202,22 +202,25 @@ describe('blocks', function () {
...
@@ -202,22 +202,25 @@ describe('blocks', function () {
const
contract
=
new
web3
.
eth
.
Contract
(
abi
)
const
contract
=
new
web3
.
eth
.
Contract
(
abi
)
const
accounts
=
await
web3
.
eth
.
getAccounts
()
const
accounts
=
await
web3
.
eth
.
getAccounts
()
console
.
dir
(
'--------'
)
console
.
dir
(
accounts
)
console
.
dir
(
'--------'
)
const
contractInstance
=
await
contract
.
deploy
({
data
:
code
,
arguments
:
[
100
]
}).
send
({
from
:
accounts
[
0
],
gas
:
400000
})
const
contractInstance
=
await
contract
.
deploy
({
data
:
code
,
arguments
:
[
100
]
}).
send
({
from
:
accounts
[
0
],
gas
:
400000
})
contractInstance
.
currentProvider
=
web3
.
eth
.
currentProvider
contractInstance
.
currentProvider
=
web3
.
eth
.
currentProvider
contractInstance
.
givenProvider
=
web3
.
eth
.
currentProvider
contractInstance
.
givenProvider
=
web3
.
eth
.
currentProvider
await
contractInstance
.
methods
.
set
(
100
).
send
({
from
:
accounts
[
0
]
,
gas
:
400000
})
// await contractInstance.methods.set(100).send({ from: accounts[0].toLowerCase()
, gas: 400000 })
let
storage
=
await
web3
.
eth
.
getStorageAt
(
contractInstance
.
options
.
address
,
0
)
//
let storage = await web3.eth.getStorageAt(contractInstance.options.address, 0)
assert
.
deepEqual
(
storage
,
'0x64'
)
//
assert.deepEqual(storage, '0x64')
await
contractInstance
.
methods
.
set
(
200
).
send
({
from
:
accounts
[
0
],
gas
:
400000
})
//
await contractInstance.methods.set(200).send({ from: accounts[0], gas: 400000 })
storage
=
await
web3
.
eth
.
getStorageAt
(
contractInstance
.
options
.
address
,
0
)
//
storage = await web3.eth.getStorageAt(contractInstance.options.address, 0)
assert
.
deepEqual
(
storage
,
'0x64'
)
//
assert.deepEqual(storage, '0x64')
await
contractInstance
.
methods
.
set
(
200
).
send
({
from
:
accounts
[
0
],
gas
:
400000
})
//
await contractInstance.methods.set(200).send({ from: accounts[0], gas: 400000 })
storage
=
await
web3
.
eth
.
getStorageAt
(
contractInstance
.
options
.
address
,
0
)
//
storage = await web3.eth.getStorageAt(contractInstance.options.address, 0)
assert
.
deepEqual
(
storage
,
'0xc8'
)
//
assert.deepEqual(storage, '0xc8')
})
})
})
})
})
})
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