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
25da05dc
Commit
25da05dc
authored
Nov 14, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests
parent
a8a81f1e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
64 deletions
+108
-64
contracts.js
test/solidity/contracts.js
+1
-63
decodeInfo.js
test/solidity/decodeInfo.js
+63
-0
storageLocation.js
test/solidity/storageLocation.js
+42
-0
tests.js
test/tests.js
+2
-1
No files found.
test/
decodeInfo
.js
→
test/
solidity/contracts
.js
View file @
25da05dc
'use strict'
var
tape
=
require
(
'tape'
)
var
compiler
=
require
(
'solc'
)
var
index
=
require
(
'../src/index'
)
tape
(
'solidity'
,
function
(
t
)
{
t
.
test
(
'astHelper, decodeInfo'
,
function
(
st
)
{
var
output
=
compiler
.
compile
(
contracts
,
0
)
var
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractUint'
,
output
.
sources
)
var
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
0
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
1
,
'uint8'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
2
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
32
,
'uint256'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
3
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
32
,
'uint256'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
4
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
16
,
'bytes16'
)
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractStructAndArray'
,
output
.
sources
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
1
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
64
,
'struct structDef storage ref'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
2
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
192
,
'struct structDef storage ref[3] storage ref'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
3
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
64
,
'bytes12[4] storage ref'
)
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractArray'
,
output
.
sources
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
0
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
4
*
5
,
'uint32[5] storage ref'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
1
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
32
,
'int8[] storage ref'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
2
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
4
*
32
,
'int16[] storage ref[3] storage ref[] storage ref[4] storage ref'
)
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractEnum'
,
output
.
sources
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
1
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
2
,
'enum enumDef'
)
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractSmallVariable'
,
output
.
sources
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
0
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
1
,
'int8'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
1
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
1
,
'uint8'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
2
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
2
,
'uint16'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
3
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
4
,
'int32'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
4
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
32
,
'uint256'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
5
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
2
,
'int16'
)
st
.
end
()
})
})
function
checkDecodeInfo
(
st
,
decodeInfo
,
freeSlot
,
storageBytes
,
typeName
,
name
)
{
st
.
equal
(
decodeInfo
.
needsFreeStorageSlot
,
freeSlot
)
st
.
equal
(
decodeInfo
.
storageBytes
,
storageBytes
)
st
.
equal
(
decodeInfo
.
typeName
,
typeName
)
}
var
contracts
=
`
module
.
exports
=
`
contract baseContract {
uint8 u;
}
...
...
test/solidity/decodeInfo.js
0 → 100644
View file @
25da05dc
'use strict'
var
tape
=
require
(
'tape'
)
var
compiler
=
require
(
'solc'
)
var
index
=
require
(
'../../src/index'
)
var
contracts
=
require
(
'./contracts'
)
tape
(
'solidity'
,
function
(
t
)
{
t
.
test
(
'astHelper, decodeInfo'
,
function
(
st
)
{
var
output
=
compiler
.
compile
(
contracts
,
0
)
var
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractUint'
,
output
.
sources
)
var
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
0
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
1
,
'uint'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
2
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
32
,
'uint'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
3
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
32
,
'uint'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
4
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
16
,
'bytesX'
)
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractStructAndArray'
,
output
.
sources
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
1
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
64
,
'struct'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
2
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
192
,
'array'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
3
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
64
,
'array'
)
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractArray'
,
output
.
sources
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
0
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
4
*
5
,
'array'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
1
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
32
,
'array'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
2
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
true
,
4
*
32
,
'array'
)
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractEnum'
,
output
.
sources
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
1
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
2
,
'enum'
)
stateDec
=
index
.
solidity
.
astHelper
.
extractStateVariables
(
'contractSmallVariable'
,
output
.
sources
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
0
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
1
,
'int'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
1
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
1
,
'uint'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
2
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
2
,
'uint'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
3
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
4
,
'int'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
4
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
32
,
'uint'
)
decodeInfo
=
index
.
solidity
.
decodeInfo
.
decode
(
stateDec
[
5
].
attributes
.
type
,
stateDec
)
checkDecodeInfo
(
st
,
decodeInfo
,
false
,
2
,
'int'
)
st
.
end
()
})
})
function
checkDecodeInfo
(
st
,
decodeInfo
,
freeSlot
,
storageBytes
,
typeName
,
name
)
{
st
.
equal
(
decodeInfo
.
needsFreeStorageSlot
,
freeSlot
)
st
.
equal
(
decodeInfo
.
storageBytes
,
storageBytes
)
st
.
equal
(
decodeInfo
.
typeName
,
typeName
)
}
test/solidity/storageLocation.js
0 → 100644
View file @
25da05dc
'use strict'
var
tape
=
require
(
'tape'
)
var
compiler
=
require
(
'solc'
)
var
index
=
require
(
'../../src/index'
)
var
contracts
=
require
(
'./contracts'
)
tape
(
'solidity'
,
function
(
t
)
{
t
.
test
(
'astHelper, decodeInfo'
,
function
(
st
)
{
var
output
=
compiler
.
compile
(
contracts
,
0
)
var
stateDec
=
index
.
solidity
.
stateDecoder
.
extractStateVariables
(
'contractUint'
,
output
.
sources
)
checkLocation
(
st
,
stateDec
[
0
].
location
,
0
,
0
)
checkLocation
(
st
,
stateDec
[
1
].
location
,
1
,
0
)
checkLocation
(
st
,
stateDec
[
2
].
location
,
2
,
0
)
checkLocation
(
st
,
stateDec
[
3
].
location
,
3
,
0
)
stateDec
=
index
.
solidity
.
stateDecoder
.
extractStateVariables
(
'contractStructAndArray'
,
output
.
sources
)
checkLocation
(
st
,
stateDec
[
0
].
location
,
0
,
0
)
checkLocation
(
st
,
stateDec
[
1
].
location
,
2
,
0
)
checkLocation
(
st
,
stateDec
[
2
].
location
,
8
,
0
)
stateDec
=
index
.
solidity
.
stateDecoder
.
extractStateVariables
(
'contractArray'
,
output
.
sources
)
checkLocation
(
st
,
stateDec
[
0
].
location
,
0
,
0
)
checkLocation
(
st
,
stateDec
[
1
].
location
,
1
,
0
)
checkLocation
(
st
,
stateDec
[
2
].
location
,
2
,
0
)
stateDec
=
index
.
solidity
.
stateDecoder
.
extractStateVariables
(
'contractSmallVariable'
,
output
.
sources
)
checkLocation
(
st
,
stateDec
[
0
].
location
,
0
,
0
)
checkLocation
(
st
,
stateDec
[
1
].
location
,
0
,
1
)
checkLocation
(
st
,
stateDec
[
2
].
location
,
0
,
2
)
checkLocation
(
st
,
stateDec
[
3
].
location
,
0
,
4
)
checkLocation
(
st
,
stateDec
[
4
].
location
,
1
,
0
)
checkLocation
(
st
,
stateDec
[
5
].
location
,
2
,
0
)
st
.
end
()
})
})
function
checkLocation
(
st
,
location
,
slot
,
offset
)
{
st
.
equal
(
location
.
offset
,
offset
)
st
.
equal
(
location
.
slot
,
slot
)
}
test/tests.js
View file @
25da05dc
...
...
@@ -7,4 +7,5 @@ require('./astwalker.js')
require
(
'./disassembler.js'
)
require
(
'./eventManager.js'
)
require
(
'./sourceMappingDecoder.js'
)
require
(
'./decodeInfo.js'
)
require
(
'./solidity/decodeInfo.js'
)
require
(
'./solidity/storageLocation.js'
)
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