You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.6 KiB
59 lines
2.6 KiB
8 years ago
|
'use strict'
|
||
|
var tape = require('tape')
|
||
|
var compiler = require('solc')
|
||
6 years ago
|
var stateDecoder = require('../../src/solidity-decoder/stateDecoder')
|
||
8 years ago
|
var contracts = require('./contracts/miscContracts')
|
||
4 years ago
|
var compilerInput = require('../helpers/compilerHelper').compilerInput
|
||
8 years ago
|
|
||
|
tape('solidity', function (t) {
|
||
8 years ago
|
t.test('storage location', function (st) {
|
||
6 years ago
|
var output = compiler.compile(compilerInput(contracts))
|
||
7 years ago
|
output = JSON.parse(output)
|
||
7 years ago
|
var stateDec = stateDecoder.extractStateVariables('contractUint', output.sources)
|
||
8 years ago
|
checkLocation(st, stateDec[0].storagelocation, 0, 0)
|
||
|
checkLocation(st, stateDec[1].storagelocation, 1, 0)
|
||
|
checkLocation(st, stateDec[2].storagelocation, 2, 0)
|
||
|
checkLocation(st, stateDec[3].storagelocation, 3, 0)
|
||
8 years ago
|
|
||
7 years ago
|
stateDec = stateDecoder.extractStateVariables('contractStructAndArray', output.sources)
|
||
8 years ago
|
checkLocation(st, stateDec[0].storagelocation, 0, 0)
|
||
|
checkLocation(st, stateDec[1].storagelocation, 2, 0)
|
||
|
checkLocation(st, stateDec[2].storagelocation, 8, 0)
|
||
8 years ago
|
|
||
7 years ago
|
stateDec = stateDecoder.extractStateVariables('contractArray', output.sources)
|
||
8 years ago
|
checkLocation(st, stateDec[0].storagelocation, 0, 0)
|
||
|
checkLocation(st, stateDec[1].storagelocation, 1, 0)
|
||
|
checkLocation(st, stateDec[2].storagelocation, 2, 0)
|
||
8 years ago
|
|
||
7 years ago
|
stateDec = stateDecoder.extractStateVariables('contractSmallVariable', output.sources)
|
||
8 years ago
|
checkLocation(st, stateDec[0].storagelocation, 0, 0)
|
||
|
checkLocation(st, stateDec[1].storagelocation, 0, 1)
|
||
|
checkLocation(st, stateDec[2].storagelocation, 0, 2)
|
||
|
checkLocation(st, stateDec[3].storagelocation, 0, 4)
|
||
|
checkLocation(st, stateDec[4].storagelocation, 1, 0)
|
||
|
checkLocation(st, stateDec[5].storagelocation, 2, 0)
|
||
8 years ago
|
|
||
7 years ago
|
stateDec = stateDecoder.extractStateVariables('testSimpleStorage', output.sources)
|
||
8 years ago
|
checkLocation(st, stateDec[0].storagelocation, 0, 0)
|
||
|
checkLocation(st, stateDec[1].storagelocation, 1, 0)
|
||
|
checkLocation(st, stateDec[2].storagelocation, 2, 0)
|
||
|
checkLocation(st, stateDec[3].storagelocation, 3, 0)
|
||
|
checkLocation(st, stateDec[4].storagelocation, 4, 0)
|
||
|
checkLocation(st, stateDec[5].storagelocation, 8, 0)
|
||
|
checkLocation(st, stateDec[6].storagelocation, 9, 0)
|
||
|
checkLocation(st, stateDec[8].storagelocation, 17, 0)
|
||
|
checkLocation(st, stateDec[9].storagelocation, 17, 4)
|
||
|
checkLocation(st, stateDec[10].storagelocation, 17, 6)
|
||
|
checkLocation(st, stateDec[11].storagelocation, 17, 7)
|
||
|
checkLocation(st, stateDec[12].storagelocation, 18, 0)
|
||
|
checkLocation(st, stateDec[13].storagelocation, 21, 0)
|
||
8 years ago
|
|
||
8 years ago
|
st.end()
|
||
|
})
|
||
|
})
|
||
|
|
||
|
function checkLocation (st, location, slot, offset) {
|
||
|
st.equal(location.offset, offset)
|
||
|
st.equal(location.slot, slot)
|
||
|
}
|