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.
89 lines
2.9 KiB
89 lines
2.9 KiB
8 years ago
|
'use strict'
|
||
|
var tape = require('tape')
|
||
|
var compiler = require('solc')
|
||
|
var intLocal = require('./contracts/intLocal')
|
||
8 years ago
|
var miscLocal = require('./contracts/miscLocal')
|
||
8 years ago
|
var structArrayLocal = require('./contracts/structArrayLocal')
|
||
8 years ago
|
var VM = require('ethereumjs-vm')
|
||
|
var utileth = require('ethereumjs-util')
|
||
7 years ago
|
var remixLib = require('remix-lib')
|
||
|
var Web3Providers = remixLib.vm.Web3Providers
|
||
|
var global = remixLib.global
|
||
8 years ago
|
var intLocalTest = require('./localsTests/int')
|
||
8 years ago
|
var miscLocalTest = require('./localsTests/misc')
|
||
8 years ago
|
var misc2LocalTest = require('./localsTests/misc2')
|
||
8 years ago
|
var structArrayLocalTest = require('./localsTests/structArray')
|
||
8 years ago
|
|
||
|
tape('solidity', function (t) {
|
||
8 years ago
|
t.test('local decoder', function (st) {
|
||
8 years ago
|
var privateKey = new Buffer('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex')
|
||
|
var address = utileth.privateToAddress(privateKey)
|
||
|
var vm = initVM(st, address)
|
||
8 years ago
|
test(st, vm, privateKey)
|
||
8 years ago
|
})
|
||
|
})
|
||
|
|
||
8 years ago
|
/*
|
||
|
Init VM / Send Transaction
|
||
|
*/
|
||
8 years ago
|
function initVM (st, address) {
|
||
|
var vm = new VM({
|
||
|
enableHomestead: true,
|
||
|
activatePrecompiles: true
|
||
|
})
|
||
|
vm.stateManager.putAccountBalance(address, 'f00000000000000001', function cb () {})
|
||
|
var web3Providers = new Web3Providers()
|
||
|
web3Providers.addVM('VM', vm)
|
||
|
web3Providers.get('VM', function (error, obj) {
|
||
|
if (error) {
|
||
|
var mes = 'provider TEST not defined'
|
||
|
console.log(mes)
|
||
|
st.fail(mes)
|
||
|
} else {
|
||
7 years ago
|
global.web3 = obj
|
||
8 years ago
|
st.end()
|
||
|
}
|
||
|
})
|
||
|
return vm
|
||
|
}
|
||
|
|
||
8 years ago
|
function test (st, vm, privateKey) {
|
||
7 years ago
|
var output = compiler.compileStandardWrapper(compilerInput(intLocal.contract))
|
||
7 years ago
|
output = JSON.parse(output)
|
||
|
intLocalTest(st, vm, privateKey, output.contracts['test.sol']['intLocal'].evm.bytecode.object, output, function () {
|
||
7 years ago
|
output = compiler.compileStandardWrapper(compilerInput(miscLocal.contract))
|
||
7 years ago
|
output = JSON.parse(output)
|
||
|
miscLocalTest(st, vm, privateKey, output.contracts['test.sol']['miscLocal'].evm.bytecode.object, output, function () {
|
||
7 years ago
|
output = compiler.compileStandardWrapper(compilerInput(miscLocal.contract))
|
||
7 years ago
|
output = JSON.parse(output)
|
||
|
misc2LocalTest(st, vm, privateKey, output.contracts['test.sol']['miscLocal2'].evm.bytecode.object, output, function () {
|
||
7 years ago
|
output = compiler.compileStandardWrapper(compilerInput(structArrayLocal.contract))
|
||
7 years ago
|
output = JSON.parse(output)
|
||
|
structArrayLocalTest(st, vm, privateKey, output.contracts['test.sol']['structArrayLocal'].evm.bytecode.object, output, function () {})
|
||
8 years ago
|
})
|
||
8 years ago
|
})
|
||
8 years ago
|
})
|
||
|
}
|
||
7 years ago
|
|
||
|
function compilerInput (contracts) {
|
||
|
return JSON.stringify({
|
||
|
language: 'Solidity',
|
||
|
sources: {
|
||
|
'test.sol': {
|
||
|
content: contracts
|
||
|
}
|
||
|
},
|
||
|
settings: {
|
||
|
optimizer: {
|
||
|
enabled: false,
|
||
|
runs: 500
|
||
|
}
|
||
|
},
|
||
|
outputSelection: {
|
||
|
'*': {
|
||
|
'*': [ 'metadata', 'evm.bytecode', 'abi', 'legacyAST', 'metadata', 'evm.assembly', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|