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
f0a2e6e5
Commit
f0a2e6e5
authored
Mar 15, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tests
parent
05645cb5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
24 deletions
+75
-24
Struct.js
src/solidity/types/Struct.js
+3
-2
mockStorageResolver.js
test/solidity/mockStorageResolver.js
+38
-0
storageDecoder.js
test/solidity/storageDecoder.js
+30
-18
traceManager.js
test/traceManager.js
+4
-4
No files found.
src/solidity/types/Struct.js
View file @
f0a2e6e5
...
...
@@ -10,13 +10,14 @@ class Struct extends RefType {
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
ret
=
{}
this
.
members
.
map
(
async
(
item
,
i
)
=>
{
for
(
var
k
in
this
.
members
)
{
var
item
=
this
.
members
[
k
]
var
globalLocation
=
{
offset
:
location
.
offset
+
item
.
storagelocation
.
offset
,
slot
:
util
.
add
(
location
.
slot
,
item
.
storagelocation
.
slot
)
}
ret
[
item
.
name
]
=
await
item
.
type
.
decodeFromStorage
(
globalLocation
,
storageResolver
)
}
)
}
return
{
value
:
ret
,
type
:
this
.
typeName
...
...
test/solidity/mockStorageResolver.js
0 → 100644
View file @
f0a2e6e5
'use strict'
var
util
=
require
(
'../../babelify-src/helpers/util'
)
class
MockStorageResolver
{
constructor
(
_storage
)
{
this
.
storage
=
{}
for
(
var
k
in
_storage
)
{
var
hashed
=
util
.
sha3
(
k
)
this
.
storage
[
hashed
]
=
{
hashed
:
hashed
,
key
:
k
,
value
:
_storage
[
k
]
}
}
}
storageRange
(
callback
)
{
callback
(
null
,
this
.
storage
)
}
storageSlot
(
slot
,
callback
)
{
var
hashed
=
util
.
sha3
(
slot
)
callback
(
null
,
this
.
storage
[
hashed
])
}
isComplete
(
address
)
{
return
true
}
fromCache
(
address
,
slotKey
)
{
return
this
.
storage
[
slotKey
]
}
toCache
(
address
,
storage
,
complete
)
{
}
}
module
.
exports
=
MockStorageResolver
test/solidity/storageDecoder.js
View file @
f0a2e6e5
...
...
@@ -2,21 +2,27 @@
var
tape
=
require
(
'tape'
)
var
compiler
=
require
(
'solc'
)
var
stateDecoder
=
require
(
'../../src/index'
).
solidity
.
stateDecoder
var
MockStorageResolver
=
require
(
'./mockStorageResolver'
)
tape
(
'solidity'
,
function
(
t
)
{
t
.
test
(
'storage decoder'
,
function
(
st
)
{
testIntStorage
(
st
)
testByteStorage
(
st
)
testStructArrayStorage
(
st
)
testIntStorage
(
st
,
function
()
{
testByteStorage
(
st
,
function
()
{
testStructArrayStorage
(
st
,
function
()
{
st
.
end
()
})
})
})
})
})
function
testIntStorage
(
st
)
{
function
testIntStorage
(
st
,
cb
)
{
var
intStorage
=
require
(
'./contracts/intStorage'
)
var
output
=
compiler
.
compile
(
intStorage
.
contract
,
0
)
var
mockStorageResolver
for
(
var
storage
of
[
intStorage
.
fullStorage
,
shrinkStorage
(
intStorage
.
fullStorage
)])
{
var
decoded
=
stateDecoder
.
solidityState
(
storage
,
output
.
sources
,
'intStorage'
)
mockStorageResolver
=
new
MockStorageResolver
(
storage
)
stateDecoder
.
solidityState
(
mockStorageResolver
,
output
.
sources
,
'intStorage'
).
then
((
decoded
)
=>
{
st
.
equal
(
decoded
[
'ui8'
].
value
,
'130'
)
st
.
equal
(
decoded
[
'ui16'
].
value
,
'456'
)
st
.
equal
(
decoded
[
'ui32'
].
value
,
'4356'
)
...
...
@@ -32,9 +38,11 @@ function testIntStorage (st) {
st
.
equal
(
decoded
[
'i256'
].
value
,
'3434343'
)
st
.
equal
(
decoded
[
'i'
].
value
,
'-32432423423'
)
st
.
equal
(
decoded
[
'ishrink'
].
value
,
'2'
)
})
}
decoded
=
stateDecoder
.
solidityState
({},
output
.
sources
,
'intStorage'
)
mockStorageResolver
=
new
MockStorageResolver
({})
stateDecoder
.
solidityState
(
mockStorageResolver
,
output
.
sources
,
'intStorage'
).
then
((
decoded
)
=>
{
st
.
equal
(
decoded
[
'ui8'
].
value
,
'0'
)
st
.
equal
(
decoded
[
'ui16'
].
value
,
'0'
)
st
.
equal
(
decoded
[
'ui32'
].
value
,
'0'
)
...
...
@@ -50,13 +58,17 @@ function testIntStorage (st) {
st
.
equal
(
decoded
[
'i256'
].
value
,
'0'
)
st
.
equal
(
decoded
[
'i'
].
value
,
'0'
)
st
.
equal
(
decoded
[
'ishrink'
].
value
,
'0'
)
cb
()
})
}
function
testByteStorage
(
st
)
{
function
testByteStorage
(
st
,
cb
)
{
var
byteStorage
=
require
(
'./contracts/byteStorage'
)
var
output
=
compiler
.
compile
(
byteStorage
.
contract
,
0
)
var
mockStorageResolver
for
(
var
storage
of
[
byteStorage
.
storage
,
shrinkStorage
(
byteStorage
.
storage
)])
{
var
decoded
=
stateDecoder
.
solidityState
(
storage
,
output
.
sources
,
'byteStorage'
)
mockStorageResolver
=
new
MockStorageResolver
(
storage
)
stateDecoder
.
solidityState
(
mockStorageResolver
,
output
.
sources
,
'byteStorage'
).
then
((
decoded
)
=>
{
st
.
equal
(
decoded
[
'b1'
].
value
,
false
)
st
.
equal
(
decoded
[
'a1'
].
value
,
'0xFE350F199F244AC9A79038D254400B632A633225'
)
st
.
equal
(
decoded
[
'b2'
].
value
,
true
)
...
...
@@ -99,9 +111,11 @@ function testByteStorage (st) {
st
.
equal
(
decoded
[
'str1'
].
value
,
'short'
)
st
.
equal
(
decoded
[
'str12'
].
value
,
'шеллы'
)
st
.
equal
(
decoded
[
'str2'
].
value
,
'long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long'
)
})
}
decoded
=
stateDecoder
.
solidityState
({},
output
.
sources
,
'byteStorage'
)
mockStorageResolver
=
new
MockStorageResolver
({})
stateDecoder
.
solidityState
(
mockStorageResolver
,
output
.
sources
,
'byteStorage'
).
then
((
decoded
)
=>
{
st
.
equal
(
decoded
[
'b1'
].
value
,
false
)
st
.
equal
(
decoded
[
'a1'
].
value
,
'0x0000000000000000000000000000000000000000'
)
st
.
equal
(
decoded
[
'b2'
].
value
,
false
)
...
...
@@ -146,6 +160,8 @@ function testByteStorage (st) {
st
.
equal
(
decoded
[
'str1'
].
value
,
''
)
st
.
equal
(
decoded
[
'str12'
].
value
,
''
)
st
.
equal
(
decoded
[
'str2'
].
value
,
''
)
cb
()
})
}
function
shrinkStorage
(
storage
)
{
...
...
@@ -158,17 +174,17 @@ function shrinkStorage (storage) {
return
shrinkedStorage
}
function
testStructArrayStorage
(
st
)
{
function
testStructArrayStorage
(
st
,
cb
)
{
var
structArrayStorage
=
require
(
'./contracts/structArrayStorage'
)
var
output
=
compiler
.
compile
(
structArrayStorage
.
contract
,
0
)
var
decoded
=
stateDecoder
.
solidityState
(
structArrayStorage
.
storage
,
output
.
sources
,
'structArrayStorage'
)
var
mockStorageResolver
=
new
MockStorageResolver
(
structArrayStorage
.
storage
)
stateDecoder
.
solidityState
(
mockStorageResolver
,
output
.
sources
,
'structArrayStorage'
).
then
((
decoded
)
=>
{
st
.
equal
(
decoded
[
'intStructDec'
].
value
[
'i8'
].
value
,
'32'
)
st
.
equal
(
decoded
[
'intStructDec'
].
value
[
'i16'
].
value
,
'-54'
)
st
.
equal
(
decoded
[
'intStructDec'
].
value
[
'ui32'
].
value
,
'128'
)
st
.
equal
(
decoded
[
'intStructDec'
].
value
[
'i256'
].
value
,
'-1243565465756'
)
st
.
equal
(
decoded
[
'intStructDec'
].
value
[
'ui16'
].
value
,
'34556'
)
st
.
equal
(
decoded
[
'intStructDec'
].
value
[
'i32'
].
value
,
'-345446546'
)
st
.
equal
(
decoded
[
'i5'
].
length
,
'0x7'
)
st
.
equal
(
decoded
[
'i5'
].
value
[
0
].
value
,
'-2134'
)
st
.
equal
(
decoded
[
'i5'
].
value
[
1
].
value
,
'345'
)
...
...
@@ -177,7 +193,6 @@ function testStructArrayStorage (st) {
st
.
equal
(
decoded
[
'i5'
].
value
[
4
].
value
,
'324'
)
st
.
equal
(
decoded
[
'i5'
].
value
[
5
].
value
,
'-2344'
)
st
.
equal
(
decoded
[
'i5'
].
value
[
6
].
value
,
'3254'
)
st
.
equal
(
decoded
[
'idyn5'
].
length
,
'0x9'
)
st
.
equal
(
decoded
[
'idyn5'
].
value
[
0
].
value
,
'-2134'
)
st
.
equal
(
decoded
[
'idyn5'
].
value
[
1
].
value
,
'345'
)
...
...
@@ -188,16 +203,13 @@ function testStructArrayStorage (st) {
st
.
equal
(
decoded
[
'idyn5'
].
value
[
6
].
value
,
'3254'
)
st
.
equal
(
decoded
[
'idyn5'
].
value
[
7
].
value
,
'-254'
)
st
.
equal
(
decoded
[
'idyn5'
].
value
[
8
].
value
,
'-2354'
)
st
.
equal
(
decoded
[
'dyn1'
].
length
,
'0x4'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
0
].
length
,
'0x1'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
0
].
value
[
0
].
value
,
'3'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
1
].
length
,
'0x3'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
1
].
value
[
0
].
value
,
'12'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
1
].
value
[
1
].
value
,
'-12'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
1
].
value
[
2
].
value
,
'-1234'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
2
].
length
,
'0xa'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
2
].
value
[
0
].
value
,
'1'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
2
].
value
[
1
].
value
,
'12'
)
...
...
@@ -209,11 +221,9 @@ function testStructArrayStorage (st) {
st
.
equal
(
decoded
[
'dyn1'
].
value
[
2
].
value
[
7
].
value
,
'2'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
2
].
value
[
8
].
value
,
'-1'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
2
].
value
[
9
].
value
,
'232432'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
3
].
length
,
'0x2'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
3
].
value
[
0
].
value
,
'232432'
)
st
.
equal
(
decoded
[
'dyn1'
].
value
[
3
].
value
[
0
].
value
,
'232432'
)
st
.
equal
(
decoded
[
'dyn2'
].
length
,
'0x2'
)
st
.
equal
(
decoded
[
'dyn2'
].
value
[
0
].
length
,
'0x4'
)
st
.
equal
(
decoded
[
'dyn2'
].
value
[
0
].
value
[
0
].
value
[
0
].
value
,
'23'
)
...
...
@@ -253,4 +263,6 @@ function testStructArrayStorage (st) {
st
.
equal
(
decoded
[
'arrayStruct'
].
value
[
2
].
value
[
1
].
value
.
str
.
value
,
'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long'
)
st
.
equal
(
decoded
[
'arrayStruct'
].
value
[
2
].
value
[
2
].
value
.
i8
.
value
,
'-34'
)
st
.
equal
(
decoded
[
'arrayStruct'
].
value
[
2
].
value
[
2
].
value
.
str
.
value
,
'test_str_short'
)
cb
()
})
}
test/traceManager.js
View file @
f0a2e6e5
...
...
@@ -53,13 +53,13 @@ tape('TraceManager', function (t) {
st
.
end
()
})
t
.
test
(
'TraceManager.getStorageAt'
,
function
(
st
)
{
var
tx
=
util
.
web3
.
eth
.
getTransaction
(
'0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51'
)
traceManager
.
getStorageAt
(
110
,
tx
,
function
(
error
,
result
)
{
t
.
test
(
'TraceManager.resolveStorage'
,
function
(
st
)
{
traceManager
.
resolveStorage
(
110
,
'0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5'
,
{},
function
(
error
,
result
)
{
if
(
error
)
{
st
.
fail
(
error
)
}
else
{
st
.
ok
(
result
[
'0x00'
]
===
'0x38'
)
console
.
log
(
JSON
.
stringify
(
result
))
st
.
ok
(
result
[
'0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563'
].
value
===
'0x38'
)
st
.
end
()
}
})
...
...
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