fix ipfs upload

pull/1/head
yann300 5 years ago
parent a756977b62
commit 91c78bf915
  1. 4
      src/app/tabs/compile-tab.js
  2. 18
      src/lib/publishOnIpfs.js
  3. 18
      src/lib/publishOnSwarm.js
  4. 37
      test-browser/tests/publishContract.js

@ -239,11 +239,11 @@ class CompileTab extends ViewPlugin {
${selectEl} ${selectEl}
</div> </div>
<article class="px-2 mt-2 pb-0"> <article class="px-2 mt-2 pb-0">
<button class="btn btn-secondary btn-block" title="Publish on Swarm" onclick="${() => { this.publish('swarm') }}"> <button id="publishOnSwarm" class="btn btn-secondary btn-block" title="Publish on Swarm" onclick="${() => { this.publish('swarm') }}">
<span>Publish on Swarm</span> <span>Publish on Swarm</span>
<img id="swarmLogo" class="${css.storageLogo} ml-2" src="${swarmImg}"> <img id="swarmLogo" class="${css.storageLogo} ml-2" src="${swarmImg}">
</button> </button>
<button class="btn btn-secondary btn-block" title="Publish on Ipfs" onclick="${() => { this.publish('ipfs') }}"> <button id="publishOnIpfs" class="btn btn-secondary btn-block" title="Publish on Ipfs" onclick="${() => { this.publish('ipfs') }}">
<span>Publish on Ipfs</span> <span>Publish on Ipfs</span>
<img id="ipfsLogo" class="${css.storageLogo} ml-2" src="${ipfsImg}"> <img id="ipfsLogo" class="${css.storageLogo} ml-2" src="${ipfsImg}">
</button> </button>

@ -27,11 +27,21 @@ module.exports = (contract, fileManager, cb, ipfsVerifiedPublishCallBack) => {
async.eachSeries(Object.keys(metadata.sources), function (fileName, cb) { async.eachSeries(Object.keys(metadata.sources), function (fileName, cb) {
// find hash // find hash
var hash let hash = null
try { try {
hash = metadata.sources[fileName].urls[1].match('dweb:/ipfs/(.+)')[1] // we try extract the hash defined in the metadata.json
// in order to check if the hash that we get after publishing is the same as the one located in metadata.json
// if it's not the same, we throw "hash mismatch between solidity bytecode and uploaded content"
// if we don't find the hash in the metadata.json, the check is not done.
//
// TODO: refactor this with publishOnSwarm
if (metadata.sources[fileName].urls) {
metadata.sources[fileName].urls.forEach(url => {
if (url.includes('ipfs')) hash = url.match('dweb:/ipfs/(.+)')[1]
})
}
} catch (e) { } catch (e) {
return cb('Metadata inconsistency') return cb('Error while extracting the hash from metadata.json')
} }
fileManager.fileProviderOf(fileName).get(fileName, (error, content) => { fileManager.fileProviderOf(fileName).get(fileName, (error, content) => {
@ -94,7 +104,7 @@ module.exports = (contract, fileManager, cb, ipfsVerifiedPublishCallBack) => {
async function ipfsVerifiedPublish (content, expectedHash, cb) { async function ipfsVerifiedPublish (content, expectedHash, cb) {
try { try {
const results = await severalGatewaysPush(content) const results = await severalGatewaysPush(content)
if (results !== expectedHash) { if (expectedHash && results !== expectedHash) {
cb(null, { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'dweb:/ipfs/' + results, hash: results }) cb(null, { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'dweb:/ipfs/' + results, hash: results })
} else { } else {
cb(null, { message: 'ok', url: 'dweb:/ipfs/' + results, hash: results }) cb(null, { message: 'ok', url: 'dweb:/ipfs/' + results, hash: results })

@ -20,11 +20,21 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => {
async.eachSeries(Object.keys(metadata.sources), function (fileName, cb) { async.eachSeries(Object.keys(metadata.sources), function (fileName, cb) {
// find hash // find hash
var hash let hash = null
try { try {
hash = metadata.sources[fileName].urls[0].match('(bzzr|bzz-raw)://(.+)')[1] // we try extract the hash defined in the metadata.json
// in order to check if the hash that we get after publishing is the same as the one located in metadata.json
// if it's not the same, we throw "hash mismatch between solidity bytecode and uploaded content"
// if we don't find the hash in the metadata.json, the check is not done.
//
// TODO: refactor this with publishOnIpfs
if (metadata.sources[fileName].urls) {
metadata.sources[fileName].urls.forEach(url => {
if (url.includes('bzz')) hash = url.match('(bzzr|bzz-raw)://(.+)')[1]
})
}
} catch (e) { } catch (e) {
return cb('Metadata inconsistency') return cb('Error while extracting the hash from metadata.json')
} }
fileManager.fileProviderOf(fileName).get(fileName, (error, content) => { fileManager.fileProviderOf(fileName).get(fileName, (error, content) => {
@ -90,7 +100,7 @@ function swarmVerifiedPublish (content, expectedHash, cb) {
swarmgw.put(content, function (err, ret) { swarmgw.put(content, function (err, ret) {
if (err) { if (err) {
cb(err) cb(err)
} else if (ret !== expectedHash) { } else if (expectedHash && ret !== expectedHash) {
cb(null, { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz-raw://' + ret, hash: ret }) cb(null, { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz-raw://' + ret, hash: ret })
} else { } else {
cb(null, { message: 'ok', url: 'bzz-raw://' + ret, hash: ret }) cb(null, { message: 'ok', url: 'bzz-raw://' + ret, hash: ret })

@ -0,0 +1,37 @@
'use strict'
var init = require('../helpers/init')
var sauce = require('./sauce')
module.exports = {
before: function (browser, done) {
init(browser, done)
},
'@sources': function () {
return []
},
'Publish on IPFS': function (browser) {
browser
.waitForElementVisible('#icon-panel', 10000)
.clickLaunchIcon('fileExplorers')
.switchFile('browser/3_Ballot.sol')
.verifyContracts(['Ballot'])
.click('#publishOnIpfs')
.getModalBody((value, done) => {
if (value.indexOf('Metadata published successfully.') === -1) browser.assert.fail('ipfs deploy failed', '', '')
if (value.indexOf('dweb:/ipfs') === -1) browser.assert.fail('ipfs deploy failed', '', '')
done()
})
.modalFooterOKClick()
},
'Publish on Swarm': function (browser) {
browser
.click('#publishOnSwarm')
.getModalBody((value, done) => {
if (value.indexOf('Metadata published successfully.') === -1) browser.assert.fail('swarm deploy failed', '', '')
if (value.indexOf('bzz') === -1) browser.assert.fail('swarm deploy failed', '', '')
done()
})
.end()
},
tearDown: sauce
}
Loading…
Cancel
Save