From 8146cbdae7f121d2092a305df419d669ec9c27d0 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Wed, 10 May 2017 17:33:53 +0200 Subject: [PATCH 1/3] Check pending request on Node local transactions (#5564) * Check pending request on Node * Linting * Liting * Fix tests --- .../Application/Requests/savedRequests.js | 77 ++++++++----------- .../Requests/savedRequests.spec.js | 34 ++++---- 2 files changed, 47 insertions(+), 64 deletions(-) diff --git a/js/src/views/Application/Requests/savedRequests.js b/js/src/views/Application/Requests/savedRequests.js index 54f1a7a9a..546324a56 100644 --- a/js/src/views/Application/Requests/savedRequests.js +++ b/js/src/views/Application/Requests/savedRequests.js @@ -16,22 +16,11 @@ import store from 'store'; -import { ERROR_CODES } from '~/api/transport/error'; - export const LS_REQUESTS_KEY = '_parity::requests'; export default class SavedRequests { - network = null; - - /** - * Load the network version, and then the related requests - */ load (api) { - return api.net.version() - .then((network) => { - this.network = network; - return this.loadRequests(api); - }) + return this.loadRequests(api) .catch((error) => { console.error(error); return []; @@ -43,28 +32,38 @@ export default class SavedRequests { */ loadRequests (api) { const requests = this._get(); - const promises = Object.values(requests).map((request) => { - const { requestId, transactionHash } = request; - // The request hasn't been signed yet - if (transactionHash) { - return request; - } + return api.parity.localTransactions() + .then((localTransactions) => { + const promises = Object.values(requests).map((request) => { + const { requestId, transactionHash } = request; - return this._requestExists(api, requestId) - .then((exists) => { - if (!exists) { - return null; + if (transactionHash) { + // The transaction might be from an other + // chain + if (!localTransactions[transactionHash]) { + this.remove(requestId); + return null; + } + + return request; } - return request; - }) - .catch(() => { - this.remove(requestId); - }); - }); + // The request hasn't been signed yet + return this._requestExists(api, requestId) + .then((exists) => { + if (!exists) { + this.remove(requestId); + return null; + } - return Promise.all(promises).then((requests) => requests.filter((request) => request)); + return request; + }); + }); + + return Promise.all(promises); + }) + .then((requests) => requests.filter((request) => request)); } save (requestId, requestData) { @@ -86,33 +85,23 @@ export default class SavedRequests { } _get () { - const allRequests = store.get(LS_REQUESTS_KEY) || {}; - - return allRequests[this.network] || {}; + return store.get(LS_REQUESTS_KEY) || {}; } _set (requests = {}) { - const allRequests = store.get(LS_REQUESTS_KEY) || {}; - if (Object.keys(requests).length > 0) { - allRequests[this.network] = requests; - } else { - delete allRequests[this.network]; + return store.set(LS_REQUESTS_KEY, requests); } - return store.set(LS_REQUESTS_KEY, allRequests); + return store.remove(LS_REQUESTS_KEY); } _requestExists (api, requestId) { return api.parity .checkRequest(requestId) .then(() => true) - .catch((error) => { - if (error.code === ERROR_CODES.REQUEST_NOT_FOUND) { - return false; - } - - throw error; + .catch(() => { + return false; }); } } diff --git a/js/src/views/Application/Requests/savedRequests.spec.js b/js/src/views/Application/Requests/savedRequests.spec.js index acf3adc39..8e8362f20 100644 --- a/js/src/views/Application/Requests/savedRequests.spec.js +++ b/js/src/views/Application/Requests/savedRequests.spec.js @@ -19,23 +19,25 @@ import store from 'store'; import SavedRequests, { LS_REQUESTS_KEY } from './savedRequests'; -const NETWORK_ID = 42; const DEFAULT_REQUEST = { requestId: '0x1', transaction: {} }; -const api = createApi(NETWORK_ID); -const api2 = createApi(1); +const SIGNED_REQUEST = { + requestId: '0x2', + transactionHash: '0xabcdef', + transaction: {} +}; + +const api = createApi(); const savedRequests = new SavedRequests(); -function createApi (networkVersion) { +function createApi () { return { parity: { - checkRequest: sinon.stub().resolves() - }, - net: { - version: sinon.stub().resolves(networkVersion) + checkRequest: sinon.stub().resolves(), + localTransactions: sinon.stub().resolves([]) } }; } @@ -43,9 +45,8 @@ function createApi (networkVersion) { describe('views/Application/Requests/savedRequests', () => { beforeEach((done) => { store.set(LS_REQUESTS_KEY, { - [NETWORK_ID]: { - [DEFAULT_REQUEST.requestId]: DEFAULT_REQUEST - } + [DEFAULT_REQUEST.requestId]: DEFAULT_REQUEST, + [SIGNED_REQUEST.requestId]: SIGNED_REQUEST }); savedRequests.load(api) @@ -75,7 +76,7 @@ describe('views/Application/Requests/savedRequests', () => { const requests = savedRequests._get(); - expect(requests).to.deep.equal({}); + expect(requests[DEFAULT_REQUEST.requestId]).to.be.undefined; }); it('saves new requests', () => { @@ -92,14 +93,7 @@ describe('views/Application/Requests/savedRequests', () => { it('loads requests', () => { return savedRequests.load(api) .then((requests) => { - expect(requests[0]).to.deep.equal(DEFAULT_REQUEST); - }); - }); - - it('loads requests from the right network', () => { - return savedRequests.load(api2) - .then((requests) => { - expect(requests).to.deep.equal([]); + expect(requests).to.deep.equal([ DEFAULT_REQUEST ]); }); }); }); From 2b30e0b5e02eff441c677844a28045bcb2268b2b Mon Sep 17 00:00:00 2001 From: GitLab Build Bot Date: Wed, 10 May 2017 15:58:15 +0000 Subject: [PATCH 2/3] [ci skip] js-precompiled 20170510-155435 --- Cargo.lock | 2 +- js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a4c20835..23c75a402 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1781,7 +1781,7 @@ dependencies = [ [[package]] name = "parity-ui-precompiled" version = "1.4.0" -source = "git+https://github.com/paritytech/js-precompiled.git#eef7f1ac0dfc44527ef1925968235c5e69add959" +source = "git+https://github.com/paritytech/js-precompiled.git#d370bad71ec9c573828136f7b64f893173cdacee" dependencies = [ "parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/js/package.json b/js/package.json index c11af4064..33668f445 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "parity.js", - "version": "1.7.73", + "version": "1.7.74", "main": "release/index.js", "jsnext:main": "src/index.js", "author": "Parity Team ", From 28b66d1b58362de0204664a3e8e3bb271a212c59 Mon Sep 17 00:00:00 2001 From: "Denis S. Soldatov aka General-Beck" Date: Wed, 10 May 2017 23:19:08 +0300 Subject: [PATCH 3/3] Update deb-build.sh Ethcore -> Parity Technologies --- scripts/deb-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/deb-build.sh b/scripts/deb-build.sh index 2585f3186..62fdb3cad 100644 --- a/scripts/deb-build.sh +++ b/scripts/deb-build.sh @@ -18,7 +18,7 @@ echo "Version: $version" >> $control echo "Source: parity" >> $control echo "Section: science" >> $control echo "Priority: extra" >> $control -echo "Maintainer: Ethcore " >> $control +echo "Maintainer: Parity Technologies " >> $control echo "Build-Depends: debhelper (>=9)" >> $control echo "Standards-Version: 3.9.5" >> $control echo "Homepage: https://parity.io" >> $control @@ -26,7 +26,7 @@ echo "Vcs-Git: git://github.com/paritytech/parity.git" >> $control echo "Vcs-Browser: https://github.com/paritytech/parity" >> $control echo "Architecture: $1" >> $control echo "Depends: libssl1.0.0 (>=1.0.0)" >> $control -echo "Description: Ethereum network client by Ethcore" >> $control +echo "Description: Ethereum network client by Parity Technologies" >> $control #build .deb package exit