remix-project mirror
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.
remix-project/libs/remix-debug/test/decoder/decodeInfo.ts

96 lines
6.6 KiB

7 years ago
'use strict'
import tape from 'tape'
import { compile } from 'solc'
import * as astHelper from '../../src/solidity-decoder/astHelper'
import * as decodeInfo from '../../src/solidity-decoder/decodeInfo'
import * as stateDecoder from '../../src/solidity-decoder/stateDecoder'
# This is a combination of 50 commits. # This is the 1st commit message: executors # This is the commit message #2: libs # This is the commit message #3: remixd # This is the commit message #4: add react app # This is the commit message #5: debugging # This is the commit message #6: debug + sol # This is the commit message #7: fixes # This is the commit message #8: tsconfig # This is the commit message #9: ast walker # This is the commit message #10: as walker # This is the commit message #11: remixd etc # This is the commit message #12: commander # This is the commit message #13: remove jest # This is the commit message #14: rm ui files # This is the commit message #15: rm reserved keywords # This is the commit message #16: testrunner # This is the commit message #17: compiler # This is the commit message #18: production build # This is the commit message #19: config # This is the commit message #20: config # This is the commit message #21: web types # This is the commit message #22: update react # This is the commit message #23: add vm # This is the commit message #24: add workers # This is the commit message #25: worker2 # This is the commit message #26: rm react app # This is the commit message #27: remixd # This is the commit message #28: worker fix # This is the commit message #29: fix detection # This is the commit message #30: revert react # This is the commit message #31: rename type # This is the commit message #32: loading handler # This is the commit message #33: remove import # This is the commit message #34: rename # This is the commit message #35: local plugin # This is the commit message #36: etherscan # This is the commit message #37: revert react # This is the commit message #38: port # This is the commit message #39: rm worker # This is the commit message #40: publicpath # This is the commit message #41: fix test # This is the commit message #42: 112 # This is the commit message #43: show version # This is the commit message #44: "axios": "1.1.2", # This is the commit message #45: config # This is the commit message #46: lint # This is the commit message #47: fix build # This is the commit message #48: lint # This is the commit message #49: error on purpose # This is the commit message #50: test error
2 years ago
const contracts = require('./contracts/miscContracts')
const simplecontracts = require('./contracts/simpleContract')
import { compilerInput } from '../helpers/compilerHelper'
import * as util from '../../src/solidity-decoder/types/util'
7 years ago
tape('solidity', function (t) {
t.test('astHelper, decodeInfo', function (st) {
# This is a combination of 50 commits. # This is the 1st commit message: executors # This is the commit message #2: libs # This is the commit message #3: remixd # This is the commit message #4: add react app # This is the commit message #5: debugging # This is the commit message #6: debug + sol # This is the commit message #7: fixes # This is the commit message #8: tsconfig # This is the commit message #9: ast walker # This is the commit message #10: as walker # This is the commit message #11: remixd etc # This is the commit message #12: commander # This is the commit message #13: remove jest # This is the commit message #14: rm ui files # This is the commit message #15: rm reserved keywords # This is the commit message #16: testrunner # This is the commit message #17: compiler # This is the commit message #18: production build # This is the commit message #19: config # This is the commit message #20: config # This is the commit message #21: web types # This is the commit message #22: update react # This is the commit message #23: add vm # This is the commit message #24: add workers # This is the commit message #25: worker2 # This is the commit message #26: rm react app # This is the commit message #27: remixd # This is the commit message #28: worker fix # This is the commit message #29: fix detection # This is the commit message #30: revert react # This is the commit message #31: rename type # This is the commit message #32: loading handler # This is the commit message #33: remove import # This is the commit message #34: rename # This is the commit message #35: local plugin # This is the commit message #36: etherscan # This is the commit message #37: revert react # This is the commit message #38: port # This is the commit message #39: rm worker # This is the commit message #40: publicpath # This is the commit message #41: fix test # This is the commit message #42: 112 # This is the commit message #43: show version # This is the commit message #44: "axios": "1.1.2", # This is the commit message #45: config # This is the commit message #46: lint # This is the commit message #47: fix build # This is the commit message #48: lint # This is the commit message #49: error on purpose # This is the commit message #50: test error
2 years ago
let output = compile(compilerInput(contracts))
7 years ago
output = JSON.parse(output)
# This is a combination of 50 commits. # This is the 1st commit message: executors # This is the commit message #2: libs # This is the commit message #3: remixd # This is the commit message #4: add react app # This is the commit message #5: debugging # This is the commit message #6: debug + sol # This is the commit message #7: fixes # This is the commit message #8: tsconfig # This is the commit message #9: ast walker # This is the commit message #10: as walker # This is the commit message #11: remixd etc # This is the commit message #12: commander # This is the commit message #13: remove jest # This is the commit message #14: rm ui files # This is the commit message #15: rm reserved keywords # This is the commit message #16: testrunner # This is the commit message #17: compiler # This is the commit message #18: production build # This is the commit message #19: config # This is the commit message #20: config # This is the commit message #21: web types # This is the commit message #22: update react # This is the commit message #23: add vm # This is the commit message #24: add workers # This is the commit message #25: worker2 # This is the commit message #26: rm react app # This is the commit message #27: remixd # This is the commit message #28: worker fix # This is the commit message #29: fix detection # This is the commit message #30: revert react # This is the commit message #31: rename type # This is the commit message #32: loading handler # This is the commit message #33: remove import # This is the commit message #34: rename # This is the commit message #35: local plugin # This is the commit message #36: etherscan # This is the commit message #37: revert react # This is the commit message #38: port # This is the commit message #39: rm worker # This is the commit message #40: publicpath # This is the commit message #41: fix test # This is the commit message #42: 112 # This is the commit message #43: show version # This is the commit message #44: "axios": "1.1.2", # This is the commit message #45: config # This is the commit message #46: lint # This is the commit message #47: fix build # This is the commit message #48: lint # This is the commit message #49: error on purpose # This is the commit message #50: test error
2 years ago
let state: any = astHelper.extractStateDefinitions('test.sol:contractUint', output.sources, null)
let states = astHelper.extractStatesDefinitions(output.sources, null)
let stateDef = state.stateDefinitions
let parsedType = decodeInfo.parseType(stateDef[0].typeDescriptions.typeString, states, 'contractUint', util.extractLocationFromAstVariable(stateDef[0]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 1, 'uint8')
4 years ago
parsedType = decodeInfo.parseType(stateDef[1].typeDescriptions.typeString, states, 'contractUint', util.extractLocationFromAstVariable(stateDef[1]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 32, 'uint256')
4 years ago
parsedType = decodeInfo.parseType(stateDef[2].typeDescriptions.typeString, states, 'contractUint', util.extractLocationFromAstVariable(stateDef[2]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 32, 'uint256')
4 years ago
parsedType = decodeInfo.parseType(stateDef[3].typeDescriptions.typeString, states, 'contractUint', util.extractLocationFromAstVariable(stateDef[3]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 16, 'bytes16')
state = astHelper.extractStateDefinitions('test.sol:contractStructAndArray', output.sources, null)
7 years ago
stateDef = state.stateDefinitions
4 years ago
parsedType = decodeInfo.parseType(stateDef[1].typeDescriptions.typeString, states, 'contractStructAndArray', util.extractLocationFromAstVariable(stateDef[1]))
7 years ago
checkDecodeInfo(st, parsedType, 2, 32, 'struct contractStructAndArray.structDef')
4 years ago
parsedType = decodeInfo.parseType(stateDef[2].typeDescriptions.typeString, states, 'contractStructAndArray', util.extractLocationFromAstVariable(stateDef[2]))
7 years ago
checkDecodeInfo(st, parsedType, 6, 32, 'struct contractStructAndArray.structDef[3]')
4 years ago
parsedType = decodeInfo.parseType(stateDef[3].typeDescriptions.typeString, states, 'contractStructAndArray', util.extractLocationFromAstVariable(stateDef[3]))
7 years ago
checkDecodeInfo(st, parsedType, 2, 32, 'bytes12[4]')
state = astHelper.extractStateDefinitions('test.sol:contractArray', output.sources, null)
7 years ago
stateDef = state.stateDefinitions
4 years ago
parsedType = decodeInfo.parseType(stateDef[0].typeDescriptions.typeString, states, 'contractArray', util.extractLocationFromAstVariable(stateDef[0]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 32, 'uint32[5]')
4 years ago
parsedType = decodeInfo.parseType(stateDef[1].typeDescriptions.typeString, states, 'contractArray', util.extractLocationFromAstVariable(stateDef[1]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 32, 'int8[]')
4 years ago
parsedType = decodeInfo.parseType(stateDef[2].typeDescriptions.typeString, states, 'contractArray', util.extractLocationFromAstVariable(stateDef[2]))
7 years ago
checkDecodeInfo(st, parsedType, 4, 32, 'int16[][3][][4]')
state = astHelper.extractStateDefinitions('test.sol:contractEnum', output.sources, null)
7 years ago
stateDef = state.stateDefinitions
parsedType = decodeInfo.parseType(stateDef[1].typeDescriptions.typeString, states, 'contractEnum', null)
7 years ago
checkDecodeInfo(st, parsedType, 1, 2, 'enum')
state = astHelper.extractStateDefinitions('test.sol:contractSmallVariable', output.sources, null)
7 years ago
stateDef = state.stateDefinitions
4 years ago
parsedType = decodeInfo.parseType(stateDef[0].typeDescriptions.typeString, states, 'contractSmallVariable', util.extractLocationFromAstVariable(stateDef[0]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 1, 'int8')
4 years ago
parsedType = decodeInfo.parseType(stateDef[1].typeDescriptions.typeString, states, 'contractSmallVariable', util.extractLocationFromAstVariable(stateDef[1]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 1, 'uint8')
4 years ago
parsedType = decodeInfo.parseType(stateDef[2].typeDescriptions.typeString, states, 'contractSmallVariable', util.extractLocationFromAstVariable(stateDef[2]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 2, 'uint16')
4 years ago
parsedType = decodeInfo.parseType(stateDef[3].typeDescriptions.typeString, states, 'contractSmallVariable', util.extractLocationFromAstVariable(stateDef[3]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 4, 'int32')
4 years ago
parsedType = decodeInfo.parseType(stateDef[4].typeDescriptions.typeString, states, 'contractSmallVariable', util.extractLocationFromAstVariable(stateDef[4]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 32, 'uint256')
4 years ago
parsedType = decodeInfo.parseType(stateDef[5].typeDescriptions.typeString, states, 'contractSmallVariable', util.extractLocationFromAstVariable(stateDef[5]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 2, 'int16')
output = compile(compilerInput(simplecontracts))
7 years ago
output = JSON.parse(output)
state = astHelper.extractStateDefinitions('test.sol:simpleContract', output.sources, null)
states = astHelper.extractStatesDefinitions(output.sources, null)
7 years ago
stateDef = state.stateDefinitions
4 years ago
parsedType = decodeInfo.parseType(stateDef[2].typeDescriptions.typeString, states, 'simpleContract', util.extractLocationFromAstVariable(stateDef[2]))
7 years ago
checkDecodeInfo(st, parsedType, 2, 32, 'struct simpleContract.structDef')
4 years ago
parsedType = decodeInfo.parseType(stateDef[3].typeDescriptions.typeString, states, 'simpleContract', util.extractLocationFromAstVariable(stateDef[3]))
7 years ago
checkDecodeInfo(st, parsedType, 6, 32, 'struct simpleContract.structDef[3]')
4 years ago
parsedType = decodeInfo.parseType(stateDef[4].typeDescriptions.typeString, states, 'simpleContract', util.extractLocationFromAstVariable(stateDef[4]))
7 years ago
checkDecodeInfo(st, parsedType, 1, 1, 'enum')
state = astHelper.extractStateDefinitions('test.sol:test2', output.sources, null)
7 years ago
stateDef = state.stateDefinitions
4 years ago
parsedType = decodeInfo.parseType(stateDef[0].typeDescriptions.typeString, states, 'test1', util.extractLocationFromAstVariable(stateDef[0]))
6 years ago
checkDecodeInfo(st, parsedType, 1, 32, 'struct test1.str')
7 years ago
state = stateDecoder.extractStateVariables('test.sol:test2', output.sources)
6 years ago
checkDecodeInfo(st, parsedType, 1, 32, 'struct test1.str')
7 years ago
st.end()
})
})
function checkDecodeInfo (st, decodeInfo, storageSlots, storageBytes, typeName) {
st.equal(decodeInfo.storageSlots, storageSlots)
st.equal(decodeInfo.storageBytes, storageBytes)
st.equal(decodeInfo.typeName, typeName)
}