Merge pull request #709 from ethereum/fixDeployLibrary

Fix deploy library
pull/3094/head
yann300 7 years ago
commit b198f512e8
  1. 4
      remix-debugger/nightwatch.js
  2. 2
      remix-debugger/package.json
  3. 8
      remix-debugger/src/ui/Ethdebugger.js
  4. 1
      remix-lib/package.json
  5. 48
      remix-lib/src/execution/txFormat.js
  6. 70
      remix-lib/test/txFormat.js

@ -62,8 +62,8 @@ module.exports = {
'desiredCapabilities': {
'browserName': 'safari',
'javascriptEnabled': true,
'platform': 'OS X 10.10',
'version': '8.0',
'platform': 'OS X 10.11',
'version': '10.0',
'acceptSslCerts': true,
'build': 'build-' + TRAVIS_JOB_NUMBER,
'tunnel-identifier': 'remix_tests_' + TRAVIS_JOB_NUMBER

@ -56,7 +56,7 @@
"nightwatch_remote_chrome": "nightwatch --config nightwatch.js --env chrome",
"nightwatch_remote_firefox": "nightwatch --config nightwatch.js --env default",
"nightwatch_remote_ie": "nightwatch --config nightwatch.js --env ie",
"nightwatch_remote_parallel": "nightwatch --config nightwatch.js --env ie,safari,chrome,default",
"nightwatch_remote_parallel": "nightwatch --config nightwatch.js --env safari,chrome,default",
"nightwatch_remote_safari": "nightwatch --config nightwatch.js --env safari",
"onchange": "onchange build/app.js -- npm run lint",
"selenium": "selenium-standalone start",

@ -25,7 +25,11 @@ var css = csjs`
margin-left: 10px;
}
`
function Ethdebugger () {
function Ethdebugger (opts) {
this.opts = opts || {}
if (!this.opts.compilationResult) this.opts.compilationResult = () => { return null }
var self = this
this.event = new EventManager()
@ -107,6 +111,7 @@ Ethdebugger.prototype.setCompilationResult = function (compilationResult) {
}
Ethdebugger.prototype.debug = function (tx) {
this.setCompilationResult(this.opts.compilationResult())
if (tx instanceof Object) {
this.txBrowser.load(tx.hash)
} else if (tx instanceof String) {
@ -145,6 +150,7 @@ Ethdebugger.prototype.startDebugging = function (blockNumber, txIndex, tx) {
if (this.traceManager.isLoading) {
return
}
this.setCompilationResult(this.opts.compilationResult())
this.statusMessage = 'Loading trace...'
yo.update(this.view, this.render())
console.log('loading trace...')

@ -14,6 +14,7 @@
],
"main": "./index.js",
"dependencies": {
"async": "^2.1.2",
"babel-preset-es2015": "^6.24.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-eslint": "^7.1.1",

@ -2,6 +2,7 @@
var ethJSABI = require('ethereumjs-abi')
var helper = require('./txHelper')
var executionContext = require('./execution-context')
var asyncJS = require('async')
module.exports = {
@ -99,10 +100,37 @@ module.exports = {
atAddress: function () {},
linkBytecode: function (contract, contracts, udapp, callback, callbackStep) {
if (contract.evm.bytecode.object.indexOf('_') < 0) {
return callback(null, contract.evm.bytecode.object)
}
linkBytecodeStandard: function (contract, contracts, udapp, callback, callbackStep) {
asyncJS.eachOfSeries(contract.evm.bytecode.linkReferences, (libs, file, cbFile) => {
asyncJS.eachOfSeries(contract.evm.bytecode.linkReferences[file], (libRef, libName, cbLibDeployed) => {
var library = contracts[file][libName]
if (library) {
this.deployLibrary(file + ':' + libName, libName, library, contracts, udapp, (error, address) => {
if (error) {
return cbLibDeployed(error)
}
var hexAddress = address.toString('hex')
if (hexAddress.slice(0, 2) === '0x') {
hexAddress = hexAddress.slice(2)
}
contract.evm.bytecode.object = this.linkLibraryStandard(libName, hexAddress, contract)
cbLibDeployed()
}, callbackStep)
} else {
cbLibDeployed('Cannot find compilation data of library ' + libName)
}
}, (error) => {
cbFile(error)
})
}, (error) => {
if (error) {
callbackStep(error)
}
callback(error, contract.evm.bytecode.object)
})
},
linkBytecodeLegacy: function (contract, contracts, udapp, callback, callbackStep) {
var libraryRefMatch = contract.evm.bytecode.object.match(/__([^_]{1,36})__/)
if (!libraryRefMatch) {
return callback('Invalid bytecode format.')
@ -129,12 +157,22 @@ module.exports = {
if (hexAddress.slice(0, 2) === '0x') {
hexAddress = hexAddress.slice(2)
}
contract.evm.bytecode.object = this.linkLibraryStandard(libraryShortName, hexAddress, contract)
contract.evm.bytecode.object = this.linkLibrary(libraryName, hexAddress, contract.evm.bytecode.object)
this.linkBytecode(contract, contracts, udapp, callback, callbackStep)
}, callbackStep)
},
linkBytecode: function (contract, contracts, udapp, callback, callbackStep) {
if (contract.evm.bytecode.object.indexOf('_') < 0) {
return callback(null, contract.evm.bytecode.object)
}
if (contract.evm.bytecode.linkReferences && Object.keys(contract.evm.bytecode.linkReferences).length) {
this.linkBytecodeStandard(contract, contracts, udapp, callback, callbackStep)
} else {
this.linkBytecodeLegacy(contract, contracts, udapp, callback, callbackStep)
}
},
deployLibrary: function (libraryName, libraryShortName, library, contracts, udapp, callback, callbackStep) {
var address = library.address
if (address) {

@ -3,9 +3,10 @@ var tape = require('tape')
var txFormat = require('../src/execution/txFormat')
var compiler = require('solc')
var compilerInput = require('../src/helpers/compilerHelper').compilerInput
var executionContext = require('../src/execution/execution-context')
var context
tape('ContractParameters - (TxFormat.buildData)', function (t) {
tape('ContractParameters - (TxFormat.buildData) - format input parameters', function (t) {
var output = compiler.compileStandardWrapper(compilerInput(uintContract))
output = JSON.parse(output)
var contract = output.contracts['test.sol']['uintContractTest']
@ -30,6 +31,51 @@ function testWithInput (st, params, expected) {
}, () => {})
}
tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) {
executionContext.setContext('vm')
var output = compiler.compileStandardWrapper(compilerInput(deploySimpleLib))
output = JSON.parse(output)
var contract = output.contracts['test.sol']['testContractLinkLibrary']
var fakeDeployedContracts = {
lib1: '0xf7a10e525d4b168f45f74db1b61f63d3e7619e11',
lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2: '0xf7a10e525d4b168f45f74db1b61f63d3e7619e33',
testContractLinkLibrary: '0xf7a10e525d4b168f45f74db1b61f63d3e7619e22'
}
var udapp = { runTx: (param, callback) => {
callback(null, {
result: {
createdAddress: fakeDeployedContracts[param.data.contractName]
}
})
} } // fake
context = { output, contract, udapp }
t.test('(TxFormat.buildData and link library (standard way))', function (st) {
st.plan(6)
testLinkLibrary(st, fakeDeployedContracts)
})
})
function testLinkLibrary (st, fakeDeployedContracts) {
var deployMsg = ['creation of library test.sol:lib1 pending...',
'creation of library test.sol:lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2 pending...']
txFormat.buildData('testContractLinkLibrary', context.contract, context.output.contracts, true, context.contract.abi[0], '', context.udapp
, (error, data) => {
if (error) { return st.fails(error) }
console.log(data)
var linkedbyteCode = data.dataHex
var libReference = context.contract.evm.bytecode.linkReferences['test.sol']['lib1']
st.equal(linkedbyteCode.substr(2 * libReference[0].start, 40), fakeDeployedContracts['lib1'].replace('0x', ''))
st.equal(linkedbyteCode.substr(2 * libReference[1].start, 40), fakeDeployedContracts['lib1'].replace('0x', ''))
libReference = context.contract.evm.bytecode.linkReferences['test.sol']['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2']
st.equal(linkedbyteCode.substr(2 * libReference[0].start, 40), fakeDeployedContracts['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2'].replace('0x', ''))
st.equal(linkedbyteCode.substr(2 * libReference[1].start, 40), fakeDeployedContracts['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2'].replace('0x', ''))
}, (msg) => {
st.equal(msg, deployMsg[0])
deployMsg.shift()
})
}
var uintContract = `contract uintContractTest {
uint _tp;
address _ap;
@ -38,3 +84,25 @@ var uintContract = `contract uintContractTest {
_ap = _a;
}
}`
var deploySimpleLib = `pragma solidity ^0.4.4;
library lib1 {
function getEmpty () {
}
}
library lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2 {
function getEmpty () {
}
}
contract testContractLinkLibrary {
function get () {
lib1.getEmpty();
lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2.getEmpty();
lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2.getEmpty();
lib1.getEmpty();
}
}`

Loading…
Cancel
Save