diff --git a/app/lib/dto/BlockDTO.ts b/app/lib/dto/BlockDTO.ts index 40fb747a9dcf7afb5d77672265dfc5ef8db0a70b..e78b5373188bff9c1becd319c94421bea62fcebd 100644 --- a/app/lib/dto/BlockDTO.ts +++ b/app/lib/dto/BlockDTO.ts @@ -47,6 +47,10 @@ export class BlockDTO { return found; } + getRawSigned() { + return this.getRawInnerPart() + this.getSignedPart() + this.signature + "\n" + } + getSignedPart() { return "InnerHash: " + this.inner_hash + "\n" + "Nonce: " + this.nonce + "\n" diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts index 094bcc692f4e1125de7f546f3ebaf7212c477091..0d5c643b248727ab5d916eac0255c467758d9171 100644 --- a/app/lib/dto/ConfDTO.ts +++ b/app/lib/dto/ConfDTO.ts @@ -52,9 +52,11 @@ export class ConfDTO { public port: number, public ipv4: string, public ipv6: string, + public homename: string, + public memory: boolean, ) {} static mock() { - return new ConfDTO("", "", [], [], 0, 0, 0.6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 0, false, 0, 0, 0, 0, 0, { pub:'', sec:'' }, 0, "", "", "", 0, "", "") + return new ConfDTO("", "", [], [], 0, 0, 0.6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 0, false, 0, 0, 0, 0, 0, { pub:'', sec:'' }, 0, "", "", "", 0, "", "", "", true) } } \ No newline at end of file diff --git a/app/modules/prover/lib/prover.ts b/app/modules/prover/lib/prover.ts index 67856f76ad9d8a8fe676bf5a696cd5a1c1f3a4d1..deebb93e12301c2f35fc457c1d2dab5706ac36c5 100644 --- a/app/modules/prover/lib/prover.ts +++ b/app/modules/prover/lib/prover.ts @@ -4,11 +4,11 @@ import * as stream from "stream" export class Prover extends stream.Transform { - private permaProver:PermanentProver + permaProver:PermanentProver constructor(server:any) { super({ objectMode: true }) - this.permaProver = this.permaProver = new PermanentProver(server) + this.permaProver = new PermanentProver(server) } _write(obj:any, enc:any, done:any) { diff --git a/server.ts b/server.ts index 2ea5ac885b4000279a73a9bba01821cbdba1a95c..dd315058800e1b1b32f291e18e4397583a855bed 100644 --- a/server.ts +++ b/server.ts @@ -306,7 +306,7 @@ export class Server extends stream.Duplex implements HookableServer { return archive; } - async importAllDataFromZIP(zipFile:any) { + async importAllDataFromZIP(zipFile:string) { const params = await this.paramsP await this.resetData() const output = unzip.Extract({ path: params.home }); diff --git a/test/integration/branches_revert.js b/test/integration/branches_revert.js index ed00d5e766e5310c5a14553cb226b235e4c79f5f..f5a03a2b94934553499b8264938a51c2b748488f 100644 --- a/test/integration/branches_revert.js +++ b/test/integration/branches_revert.js @@ -32,7 +32,7 @@ describe("Revert root", function() { before(function() { return co(function *() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield cat.createIdentity(); yield toc.createIdentity(); yield toc.cert(cat); diff --git a/test/integration/branches_revert_memberships.js b/test/integration/branches_revert_memberships.js index 4b12f96d8cb87fd2eb42e6b3c9fa885d43e1693e..6132aa45e1a5d479d1bc45aa9af55284cd8347d6 100644 --- a/test/integration/branches_revert_memberships.js +++ b/test/integration/branches_revert_memberships.js @@ -26,7 +26,7 @@ describe("Revert memberships", function() { before(() => co(function*() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield i1.createIdentity(); yield i2.createIdentity(); diff --git a/test/integration/certifier-is-member.js b/test/integration/certifier-is-member.js index 6df098951316067480eec1a18260f3e1c86e268e..87026a463f8def8f80699b366b6c91a9cbed88e2 100644 --- a/test/integration/certifier-is-member.js +++ b/test/integration/certifier-is-member.js @@ -30,7 +30,7 @@ const tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', s describe("Certifier must be a member", function() { before(() => co(function *() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield cat.createIdentity(); yield tac.createIdentity(); yield cat.cert(tac); diff --git a/test/integration/crosschain-test.js b/test/integration/crosschain-test.js index 48abedb0b73dd31010782f3824681e7ecf7d3122..60850a66003a7a3d71cd0581cd2f2bf44fdec234 100644 --- a/test/integration/crosschain-test.js +++ b/test/integration/crosschain-test.js @@ -61,8 +61,8 @@ describe("Crosschain transactions", function() { let btx0, mtx0; // Source transactions for coins before(() => co(function *() { - yield sB.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); - yield sM.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield sB.initDalBmaConnections(); + yield sM.initDalBmaConnections(); // Initialize BETA yield ticB.createIdentity(); @@ -239,13 +239,8 @@ describe("Crosschain transactions", function() { before(function() { return co(function *() { - let server = yield sB.initWithDAL(); - let bmapi = yield bma(server); - yield bmapi.openConnections(); - - server = yield sM.initWithDAL(); - bmapi = yield bma(server); - yield bmapi.openConnections(); + yield sB.initDalBmaConnections(); + yield sM.initDalBmaConnections() // Initialize BETA yield ticB.createIdentity(); diff --git a/test/integration/documents-currency.js b/test/integration/documents-currency.js index bb20ece76db048ef9dac42f676e5781064ebdafd..25331fa528d43b8aec0e009f9fda012c47fdfd8a 100644 --- a/test/integration/documents-currency.js +++ b/test/integration/documents-currency.js @@ -1,176 +1,166 @@ "use strict"; - -const co = require('co'); -const should = require('should'); -const user = require('./tools/user'); -const commit = require('./tools/commit'); -const sync = require('./tools/sync'); -const until = require('./tools/until'); -const toolbox = require('./tools/toolbox'); +Object.defineProperty(exports, "__esModule", { value: true }); +const toolbox_1 = require("./tools/toolbox"); +const co = require('co'); +const should = require('should'); +const user = require('./tools/user'); +const commit = require('./tools/commit'); const Peer = require('../../app/lib/entity/peer'); - -const s1 = toolbox.server({ - currency: 'currency_one', - pair: { - pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', - sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' - } -}); -const s2 = toolbox.server({ - currency: 'currency_two', - pair: { - pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', - sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' - } -}); - -const cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); -const tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); -const toc2 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); -const tic2 = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); - -describe("Document pool currency", function() { - - before(() => co(function*() { - - yield s1.prepareForNetwork(); - yield s2.prepareForNetwork(); - - // Publishing identities - yield cat1.createIdentity(); - yield tac1.createIdentity(); - yield cat1.join(); - yield tac1.join(); - yield toc2.createIdentity(); - yield tic2.createIdentity(); - yield toc2.join(); - yield tic2.join(); - })); - - it('Identity with wrong currency should be rejected', () => co(function*() { - const idtyCat1 = yield s1.lookup2identity(cat1.pub); - idtyCat1.createIdentity(); - try { - yield s2.postIdentity(idtyCat1); - throw "Identity should not have been accepted, since it has an unknown currency name"; - } catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Signature does not match/); - } - })); - - it('Identity absorption with wrong currency should be rejected', () => co(function*() { - try { - const cert = yield toc2.makeCert(cat1, s1); - yield s2.postCert(cert); - throw "Certification should not have been accepted, since it has an unknown currency name"; - } catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Signature does not match/); - } - })); - - it('Certification with wrong currency should be rejected', () => co(function*() { - try { - const cert = yield toc2.makeCert(tic2, null, { - currency: "wrong_currency" - }); - yield s2.postCert(cert); - throw "Certification should not have been accepted, since it has an unknown currency name"; - } catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Wrong signature for certification/); - } - })); - - it('Membership with wrong currency should be rejected', () => co(function*() { - try { - const join = yield toc2.makeMembership('IN', null, { - currency: "wrong_currency" - }); - yield s2.postMembership(join); - throw "Membership should not have been accepted, since it has an unknown currency name"; - } catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/wrong signature for membership/); +const s1 = toolbox_1.NewTestingServer({ + currency: 'currency_one', + pair: { + pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', + sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' } - })); - - it('Revocation with wrong currency should be rejected', () => co(function*() { - try { - const revocation = yield toc2.makeRevocation(null, { - currency: "wrong_currency" - }); - yield s2.postRevocation(revocation); - throw "Revocation should not have been accepted, since it has an unknown currency name"; - } catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Wrong signature for revocation/); - } - })); - - it('Block with wrong currency should be rejected', () => co(function*() { - yield toc2.cert(tic2); - yield tic2.cert(toc2); - yield s2.commit(); - const b2 = yield s2.makeNext({ currency: "wrong_currency" }); - try { - yield s2.postBlock(b2); - throw "Currency should have been rejected"; - } catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Wrong inner hash/); // Because currency is dynamically replaced - } - })); - - it('Transaction with wrong currency should be rejected', () => co(function*() { - try { - yield cat1.cert(tac1); - yield tac1.cert(cat1); - yield s1.commit(); - yield s1.commit(); - const current = yield s1.get('/blockchain/current'); - const tx = cat1.makeTX( - [{ - src: "1500:1:D:DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:1", - unlock: "SIG(0)" - }], - [{ - qty: 1500, - base: 1, - lock: "XHX(8AFC8DF633FC158F9DB4864ABED696C1AA0FE5D617A7B5F7AB8DE7CA2EFCD4CB)" - }], - { - currency: "wrong_currency", - blockstamp: [current.number, current.hash].join('-') - }); - yield s1.postRawTX(tx); - throw "Transaction should not have been accepted, since it has an unknown currency name"; - } catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Signature from a transaction must match/); - } - })); - - it('Peer with wrong currency should be rejected', () => co(function*() { - try { - const peer = yield toc2.makePeer(['BASIC_MERKLED_API localhost 10901'], { - version: 10, - currency: "wrong_currency" - }); - yield s2.postPeer(peer); - throw "Peer should not have been accepted, since it has an unknown currency name"; - } catch (e) { - should.exist(e.error); - e.should.be.an.Object(); - e.error.message.should.match(/Signature from a peer must match/); +}); +const s2 = toolbox_1.NewTestingServer({ + currency: 'currency_two', + pair: { + pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', + sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' } - })); }); +const cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }, { server: s1 }); +const tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE' }, { server: s1 }); +const toc2 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }, { server: s2 }); +const tic2 = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7' }, { server: s2 }); +describe("Document pool currency", function () { + before(() => co(function* () { + yield s1.prepareForNetwork(); + yield s2.prepareForNetwork(); + // Publishing identities + yield cat1.createIdentity(); + yield tac1.createIdentity(); + yield cat1.join(); + yield tac1.join(); + yield toc2.createIdentity(); + yield tic2.createIdentity(); + yield toc2.join(); + yield tic2.join(); + })); + it('Identity with wrong currency should be rejected', () => co(function* () { + const idtyCat1 = yield s1.lookup2identity(cat1.pub); + idtyCat1.createIdentity(); + try { + yield s2.postIdentity(idtyCat1); + throw "Identity should not have been accepted, since it has an unknown currency name"; + } + catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Signature does not match/); + } + })); + it('Identity absorption with wrong currency should be rejected', () => co(function* () { + try { + const cert = yield toc2.makeCert(cat1, s1); + yield s2.postCert(cert); + throw "Certification should not have been accepted, since it has an unknown currency name"; + } + catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Signature does not match/); + } + })); + it('Certification with wrong currency should be rejected', () => co(function* () { + try { + const cert = yield toc2.makeCert(tic2, null, { + currency: "wrong_currency" + }); + yield s2.postCert(cert); + throw "Certification should not have been accepted, since it has an unknown currency name"; + } + catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Wrong signature for certification/); + } + })); + it('Membership with wrong currency should be rejected', () => co(function* () { + try { + const join = yield toc2.makeMembership('IN', null, { + currency: "wrong_currency" + }); + yield s2.postMembership(join); + throw "Membership should not have been accepted, since it has an unknown currency name"; + } + catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/wrong signature for membership/); + } + })); + it('Revocation with wrong currency should be rejected', () => co(function* () { + try { + const revocation = yield toc2.makeRevocation(null, { + currency: "wrong_currency" + }); + yield s2.postRevocation(revocation); + throw "Revocation should not have been accepted, since it has an unknown currency name"; + } + catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Wrong signature for revocation/); + } + })); + it('Block with wrong currency should be rejected', () => co(function* () { + yield toc2.cert(tic2); + yield tic2.cert(toc2); + yield s2.commit(); + const b2 = yield s2.makeNext({ currency: "wrong_currency" }); + try { + yield s2.postBlock(b2); + throw "Currency should have been rejected"; + } + catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Wrong inner hash/); // Because currency is dynamically replaced + } + })); + it('Transaction with wrong currency should be rejected', () => co(function* () { + try { + yield cat1.cert(tac1); + yield tac1.cert(cat1); + yield s1.commit(); + yield s1.commit(); + const current = yield s1.get('/blockchain/current'); + const tx = cat1.makeTX([{ + src: "1500:1:D:DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:1", + unlock: "SIG(0)" + }], [{ + qty: 1500, + base: 1, + lock: "XHX(8AFC8DF633FC158F9DB4864ABED696C1AA0FE5D617A7B5F7AB8DE7CA2EFCD4CB)" + }], { + currency: "wrong_currency", + blockstamp: [current.number, current.hash].join('-') + }); + yield s1.postRawTX(tx); + throw "Transaction should not have been accepted, since it has an unknown currency name"; + } + catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Signature from a transaction must match/); + } + })); + it('Peer with wrong currency should be rejected', () => co(function* () { + try { + const peer = yield toc2.makePeer(['BASIC_MERKLED_API localhost 10901'], { + version: 10, + currency: "wrong_currency" + }); + yield s2.postPeer(peer); + throw "Peer should not have been accepted, since it has an unknown currency name"; + } + catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Signature from a peer must match/); + } + })); +}); +//# sourceMappingURL=documents-currency.js.map \ No newline at end of file diff --git a/test/integration/documents-currency.ts b/test/integration/documents-currency.ts new file mode 100644 index 0000000000000000000000000000000000000000..6c7f9837a255cbd1a6970b3a967a5d869d5a75a8 --- /dev/null +++ b/test/integration/documents-currency.ts @@ -0,0 +1,173 @@ +import {NewTestingServer} from "./tools/toolbox" + +const co = require('co'); +const should = require('should'); +const user = require('./tools/user'); +const commit = require('./tools/commit'); +const Peer = require('../../app/lib/entity/peer'); + +const s1 = NewTestingServer({ + currency: 'currency_one', + pair: { + pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', + sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' + } +}); +const s2 = NewTestingServer({ + currency: 'currency_two', + pair: { + pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', + sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' + } +}); + +const cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); +const tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); +const toc2 = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s2 }); +const tic2 = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s2 }); + +describe("Document pool currency", function() { + + before(() => co(function*() { + + yield s1.prepareForNetwork(); + yield s2.prepareForNetwork(); + + // Publishing identities + yield cat1.createIdentity(); + yield tac1.createIdentity(); + yield cat1.join(); + yield tac1.join(); + yield toc2.createIdentity(); + yield tic2.createIdentity(); + yield toc2.join(); + yield tic2.join(); + })); + + it('Identity with wrong currency should be rejected', () => co(function*() { + const idtyCat1 = yield s1.lookup2identity(cat1.pub); + idtyCat1.createIdentity(); + try { + yield s2.postIdentity(idtyCat1); + throw "Identity should not have been accepted, since it has an unknown currency name"; + } catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Signature does not match/); + } + })); + + it('Identity absorption with wrong currency should be rejected', () => co(function*() { + try { + const cert = yield toc2.makeCert(cat1, s1); + yield s2.postCert(cert); + throw "Certification should not have been accepted, since it has an unknown currency name"; + } catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Signature does not match/); + } + })); + + it('Certification with wrong currency should be rejected', () => co(function*() { + try { + const cert = yield toc2.makeCert(tic2, null, { + currency: "wrong_currency" + }); + yield s2.postCert(cert); + throw "Certification should not have been accepted, since it has an unknown currency name"; + } catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Wrong signature for certification/); + } + })); + + it('Membership with wrong currency should be rejected', () => co(function*() { + try { + const join = yield toc2.makeMembership('IN', null, { + currency: "wrong_currency" + }); + yield s2.postMembership(join); + throw "Membership should not have been accepted, since it has an unknown currency name"; + } catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/wrong signature for membership/); + } + })); + + it('Revocation with wrong currency should be rejected', () => co(function*() { + try { + const revocation = yield toc2.makeRevocation(null, { + currency: "wrong_currency" + }); + yield s2.postRevocation(revocation); + throw "Revocation should not have been accepted, since it has an unknown currency name"; + } catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Wrong signature for revocation/); + } + })); + + it('Block with wrong currency should be rejected', () => co(function*() { + yield toc2.cert(tic2); + yield tic2.cert(toc2); + yield s2.commit(); + const b2 = yield s2.makeNext({ currency: "wrong_currency" }); + try { + yield s2.postBlock(b2); + throw "Currency should have been rejected"; + } catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Wrong inner hash/); // Because currency is dynamically replaced + } + })); + + it('Transaction with wrong currency should be rejected', () => co(function*() { + try { + yield cat1.cert(tac1); + yield tac1.cert(cat1); + yield s1.commit(); + yield s1.commit(); + const current = yield s1.get('/blockchain/current'); + const tx = cat1.makeTX( + [{ + src: "1500:1:D:DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo:1", + unlock: "SIG(0)" + }], + [{ + qty: 1500, + base: 1, + lock: "XHX(8AFC8DF633FC158F9DB4864ABED696C1AA0FE5D617A7B5F7AB8DE7CA2EFCD4CB)" + }], + { + currency: "wrong_currency", + blockstamp: [current.number, current.hash].join('-') + }); + yield s1.postRawTX(tx); + throw "Transaction should not have been accepted, since it has an unknown currency name"; + } catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Signature from a transaction must match/); + } + })); + + it('Peer with wrong currency should be rejected', () => co(function*() { + try { + const peer = yield toc2.makePeer(['BASIC_MERKLED_API localhost 10901'], { + version: 10, + currency: "wrong_currency" + }); + yield s2.postPeer(peer); + throw "Peer should not have been accepted, since it has an unknown currency name"; + } catch (e) { + should.exist(e.error); + e.should.be.an.Object(); + e.error.message.should.match(/Signature from a peer must match/); + } + })); +}); diff --git a/test/integration/identity-implicit-revocation.js b/test/integration/identity-implicit-revocation.js index 72beb50da9d14992558093ccb317b57338603a90..d477a926ef7c0a331d440591875d795d0c0eab39 100644 --- a/test/integration/identity-implicit-revocation.js +++ b/test/integration/identity-implicit-revocation.js @@ -30,7 +30,7 @@ const tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', s describe("Implicit revocation", function() { before(() => co(function *() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield cat.createIdentity(); yield tac.createIdentity(); yield tic.createIdentity(); diff --git a/test/integration/identity-kicking-by-certs.js b/test/integration/identity-kicking-by-certs.js index 6563eae1552e63a00992ad2d1df33fe17b6d0dd8..0f9c14b45c371b353356cdafe2757b68f3ca9d74 100644 --- a/test/integration/identity-kicking-by-certs.js +++ b/test/integration/identity-kicking-by-certs.js @@ -33,7 +33,7 @@ const tuc = user('tuc', { pub: '3conGDUXdrTGbQPMQQhEC4Ubu1MCAnFrAYvUaewbUhtk', s describe("Identities kicking by certs", function() { before(() => co(function *() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield cat.createIdentity(); yield tac.createIdentity(); yield toc.createIdentity(); diff --git a/test/integration/identity-same-pubkey.js b/test/integration/identity-same-pubkey.js index f64e9fc778a27e010082ed1bee15971c6e6ecb0c..251e288c9fef19f03c5c0896bbb6b995006bc2b4 100644 --- a/test/integration/identity-same-pubkey.js +++ b/test/integration/identity-same-pubkey.js @@ -22,7 +22,7 @@ describe("Identities with shared pubkey", function() { before(() => co(function*() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield cat2.createIdentity(); diff --git a/test/integration/peer-outdated.js b/test/integration/peer-outdated.js index 3e5a92dd14dfa3d284a16a0fde220fefba7fd20d..8226959266994addbcf80d768dfeef7edd85c8f8 100644 --- a/test/integration/peer-outdated.js +++ b/test/integration/peer-outdated.js @@ -39,10 +39,7 @@ describe("Peer document expiry", function() { yield [s1, s2].reduce((p, server) => co(function*() { yield p; - yield server.initWithDAL(); - const bmaAPI = yield bma(server); - yield bmaAPI.openConnections(); - server.bma = bmaAPI; + yield server.initDalBmaConnections() require('../../app/modules/router').duniter.methods.routeToNetwork(server); }), Promise.resolve()); diff --git a/test/integration/peers-same-pubkey.js b/test/integration/peers-same-pubkey.js index c021eed69ff95545e9cf64059f16ac51769d5499..96b0c267810c8db162276f63ae185a3a22496977 100644 --- a/test/integration/peers-same-pubkey.js +++ b/test/integration/peers-same-pubkey.js @@ -35,10 +35,7 @@ describe("Peer document", function() { yield [s1, s2, s3].reduce((p, server) => co(function*() { yield p; - yield server.initWithDAL(); - const bmaAPI = yield bma(server); - yield bmaAPI.openConnections(); - server.bma = bmaAPI; + yield server.initDalBmaConnections() require('../../app/modules/router').duniter.methods.routeToNetwork(server); }), Promise.resolve()); diff --git a/test/integration/server-import-export.js b/test/integration/server-import-export.js index d00adeb6ec00c798fefb2ff0f544946dd020b8e6..71436b16cc4a51655d7850f1226620f262256f5a 100644 --- a/test/integration/server-import-export.js +++ b/test/integration/server-import-export.js @@ -29,7 +29,7 @@ describe('Import/Export', () => { const cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 }); const tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 }); - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield cat.createIdentity(); yield tac.createIdentity(); yield cat.cert(tac); diff --git a/test/integration/server-sandbox.js b/test/integration/server-sandbox.js index 24f8581dc596796b8d459a483221a14a4fd014a7..5a3a44936c860cbbe148dc80ef375118738a6774 100644 --- a/test/integration/server-sandbox.js +++ b/test/integration/server-sandbox.js @@ -59,9 +59,9 @@ describe("Sandboxes", function() { before(() => co(function*() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); - yield s2.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); - yield s3.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); + yield s2.initDalBmaConnections(); + yield s3.initDalBmaConnections(); s1.dal.idtyDAL.setSandboxSize(3); s1.dal.msDAL.setSandboxSize(2); s1.dal.txsDAL.setSandboxSize(2); diff --git a/test/integration/tools/toolbox.js b/test/integration/tools/toolbox.js index ff23208633ce400554cddb02d455395a7c726099..c508ed7a32d04b284c38197dc12a2c8e31f959e9 100644 --- a/test/integration/tools/toolbox.js +++ b/test/integration/tools/toolbox.js @@ -1,323 +1,367 @@ "use strict"; - -const _ = require('underscore'); -const co = require('co'); -const rp = require('request-promise'); -const httpTest = require('../tools/http'); -const sync = require('../tools/sync'); -const commit = require('../tools/commit'); -const user = require('../tools/user'); -const until = require('../tools/until'); -const Peer = require('../../../app/lib/entity/peer'); -const Identity = require('../../../app/lib/entity/identity'); -const Block = require('../../../app/lib/entity/block'); -const bma = require('duniter-bma').duniter.methods.bma; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const server_1 = require("../../../server"); +const BlockDTO_1 = require("../../../app/lib/dto/BlockDTO"); +const _ = require('underscore'); +const rp = require('request-promise'); +const httpTest = require('../tools/http'); +const sync = require('../tools/sync'); +const commit = require('../tools/commit'); +const user = require('../tools/user'); +const until = require('../tools/until'); +const Peer = require('../../../app/lib/entity/peer'); +const Identity = require('../../../app/lib/entity/identity'); +const bma = require('duniter-bma').duniter.methods.bma; const multicaster = require('../../../app/lib/streams/multicaster'); -const dtos = require('duniter-bma').duniter.methods.dtos; -const duniter = require('../../../index'); -const logger = require('../../../app/lib/logger').NewLogger('toolbox'); - +const dtos = require('duniter-bma').duniter.methods.dtos; +const logger = require('../../../app/lib/logger').NewLogger('toolbox'); require('duniter-bma').duniter.methods.noLimit(); // Disables the HTTP limiter - const MEMORY_MODE = true; const CURRENCY_NAME = 'duniter_unit_test_currency'; const HOST = '127.0.0.1'; let PORT = 10000; - -module.exports = { - - shouldFail: (promise, message) => co(function*() { +exports.shouldFail = (promise, message = null) => __awaiter(this, void 0, void 0, function* () { try { - yield promise; - throw '{ "message": "Should have thrown an error" }' - } catch(e) { - let err = e - if (typeof e === "string") { - err = JSON.parse(e) - } - err.should.have.property('message').equal(message); - } - }), - - simpleNetworkOf2NodesAnd2Users: (options) => co(function*() { - const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}; - const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}; - - const s1 = module.exports.server(_.extend({ pair: catKeyring }, options || {})); - const s2 = module.exports.server(_.extend({ pair: tacKeyring }, options || {})); - + yield promise; + throw '{ "message": "Should have thrown an error" }'; + } + catch (e) { + let err = e; + if (typeof e === "string") { + err = JSON.parse(e); + } + err.should.have.property('message').equal(message); + } +}); +exports.simpleNetworkOf2NodesAnd2Users = (options) => __awaiter(this, void 0, void 0, function* () { + const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }; + const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE' }; + const s1 = exports.NewTestingServer(_.extend({ pair: catKeyring }, options || {})); + const s2 = exports.NewTestingServer(_.extend({ pair: tacKeyring }, options || {})); const cat = user('cat', catKeyring, { server: s1 }); const tac = user('tac', tacKeyring, { server: s1 }); - - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); - yield s2.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); - + yield s1.initDalBmaConnections(); + yield s2.initDalBmaConnections(); yield s2.sharePeeringWith(s1); - // yield s2.post('/network/peering/peers', yield s1.get('/network/peering')); - // yield s1.submitPeerP(yield s2.get('/network/peering')); - + // await s2.post('/network/peering/peers', await s1.get('/network/peering')); + // await s1.submitPeerP(await s2.get('/network/peering')); yield cat.createIdentity(); yield tac.createIdentity(); yield cat.cert(tac); yield tac.cert(cat); yield cat.join(); yield tac.join(); - // Each server forwards to each other require('../../../app/modules/router').duniter.methods.routeToNetwork(s1); require('../../../app/modules/router').duniter.methods.routeToNetwork(s2); - return { s1, s2, cat, tac }; - }), - - simpleNodeWith2Users: (options) => co(function*() { - - const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}; - const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}; - - const s1 = module.exports.server(_.extend({ pair: catKeyring }, options || {})); - +}); +exports.simpleNodeWith2Users = (options) => __awaiter(this, void 0, void 0, function* () { + const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP' }; + const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE' }; + const s1 = exports.NewTestingServer(_.extend({ pair: catKeyring }, options || {})); const cat = user('cat', catKeyring, { server: s1 }); const tac = user('tac', tacKeyring, { server: s1 }); - - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); - + yield s1.initDalBmaConnections(); yield cat.createIdentity(); yield tac.createIdentity(); yield cat.cert(tac); yield tac.cert(cat); yield cat.join(); yield tac.join(); - return { s1, cat, tac }; - }), - - simpleNodeWith2otherUsers: (options) => co(function*() { - - const ticKeyring = { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}; - const tocKeyring = { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}; - - const s1 = module.exports.server(_.extend({ pair: ticKeyring }, options || {})); - +}); +exports.simpleNodeWith2otherUsers = (options) => __awaiter(this, void 0, void 0, function* () { + const ticKeyring = { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7' }; + const tocKeyring = { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F' }; + const s1 = exports.NewTestingServer(_.extend({ pair: ticKeyring }, options || {})); const tic = user('cat', ticKeyring, { server: s1 }); const toc = user('tac', tocKeyring, { server: s1 }); - - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); - + yield s1.initDalBmaConnections(); yield tic.createIdentity(); yield toc.createIdentity(); yield tic.cert(toc); yield toc.cert(tic); yield tic.join(); yield toc.join(); - return { s1, tic, toc }; - }), - - createUser: (uid, pub, sec, defaultServer) => co(function*() { +}); +exports.createUser = (uid, pub, sec, defaultServer) => __awaiter(this, void 0, void 0, function* () { const keyring = { pub: pub, sec: sec }; return user(uid, keyring, { server: defaultServer }); - }), - - fakeSyncServer: (readBlocksMethod, readParticularBlockMethod, onPeersRequested) => { - +}); +exports.fakeSyncServer = (readBlocksMethod, readParticularBlockMethod, onPeersRequested) => __awaiter(this, void 0, void 0, function* () { const host = HOST; const port = PORT++; - - return co(function*() { - - // Meaningful variables - const NO_HTTP_LOGS = false; - const NO_STATIC_PATH = null; - - // A fake HTTP limiter with no limit at all - const noLimit = { + // Meaningful variables + const NO_HTTP_LOGS = false; + const NO_STATIC_PATH = null; + // A fake HTTP limiter with no limit at all + const noLimit = { canAnswerNow: () => true, - processRequest: () => { /* Does nothing */ } - }; - - const fakeServer = yield require('duniter-bma').duniter.methods.createServersAndListen("Fake Duniter Server", { conf: {} }, [{ - ip: host, - port: port - }], NO_HTTP_LOGS, logger, NO_STATIC_PATH, (app, httpMethods) => { - + processRequest: () => { } + }; + const fakeServer = yield require('duniter-bma').duniter.methods.createServersAndListen("Fake Duniter Server", { conf: {} }, [{ + ip: host, + port: port + }], NO_HTTP_LOGS, logger, NO_STATIC_PATH, (app, httpMethods) => { // Mock BMA method for sync mocking - httpMethods.httpGET('/network/peering', () => { - return co(function*() { + httpMethods.httpGET('/network/peering', () => __awaiter(this, void 0, void 0, function* () { return { - endpoints: [['BASIC_MERKLED_API', host, port].join(' ')] - } - }); - }, dtos.Peer, noLimit); - + endpoints: [['BASIC_MERKLED_API', host, port].join(' ')] + }; + }), dtos.Peer, noLimit); // Mock BMA method for sync mocking httpMethods.httpGET('/network/peering/peers', onPeersRequested, dtos.MerkleOfPeers, noLimit); - // Another mock BMA method for sync mocking httpMethods.httpGET('/blockchain/blocks/:count/:from', (req) => { - - // What do we do on /blockchain/blocks request - let count = parseInt(req.params.count); - let from = parseInt(req.params.from); - - return readBlocksMethod(count, from); - + // What do we do on /blockchain/blocks request + let count = parseInt(req.params.count); + let from = parseInt(req.params.from); + return readBlocksMethod(count, from); }, dtos.Blocks, noLimit); - // Another mock BMA method for sync mocking httpMethods.httpGET('/blockchain/block/:number', (req) => { - - // What do we do on /blockchain/blocks request - let number = parseInt(req.params.number); - - return readParticularBlockMethod(number); - + // What do we do on /blockchain/blocks request + let number = parseInt(req.params.number); + return readParticularBlockMethod(number); }, dtos.Block, noLimit); - }); - - yield fakeServer.openConnections(); - return { + }); + yield fakeServer.openConnections(); + return { host: host, port: port - }; - }); - }, - - /** - * Creates a new memory duniter server for Unit Test purposes. - * @param conf - */ - server: (conf) => { + }; +}); +/** + * Creates a new memory duniter server for Unit Test purposes. + * @param conf + */ +exports.server = (conf) => exports.NewTestingServer(conf); +exports.NewTestingServer = (conf) => { const port = PORT++; const commonConf = { - port: port, - ipv4: HOST, - remoteipv4: HOST, - currency: conf.currency || CURRENCY_NAME, - httpLogs: true, - forksize: 3 + port: port, + ipv4: HOST, + remoteipv4: HOST, + currency: conf.currency || CURRENCY_NAME, + httpLogs: true, + forksize: 3 }; if (conf.sigQty === undefined) { - conf.sigQty = 1; - } - const server = duniter( - '~/.config/duniter/' + (conf.homename || 'dev_unit_tests'), - conf.memory !== undefined ? conf.memory : MEMORY_MODE, - _.extend(conf, commonConf)); - - server.port = port; - server.host = HOST; - - server.url = (uri) => 'http://' + [HOST, port].join(':') + uri; - server.get = (uri) => rp(server.url(uri), { json: true }); - server.post = (uri, obj) => rp(server.url(uri), { method: 'POST', json: true, body: obj }); - - server.expect = (uri, expectations) => typeof expectations == 'function' ? httpTest.expectAnswer(rp(server.url(uri), { json: true }), expectations) : httpTest.expectJSON(rp(server.url(uri), { json: true }), expectations); - server.expectThat = (uri, expectations) => httpTest.expectAnswer(rp(server.url(uri), { json: true }), expectations); - server.expectJSON = (uri, expectations) => httpTest.expectJSON(rp(server.url(uri), { json: true }), expectations); - server.expectError = (uri, code, message) => httpTest.expectError(code, message, rp(server.url(uri), { json: true })); - - server.syncFrom = (otherServer, fromIncuded, toIncluded) => sync(fromIncuded, toIncluded, otherServer, server); - - server.until = (type, count) => until(server, type, count); - - server.commit = (options) => co(function*() { - const raw = yield commit(server)(options); - return JSON.parse(raw); - }); - - server.commitExpectError = (options) => co(function*() { - try { - const raw = yield commit(server)(options); - JSON.parse(raw); - throw { message: 'Commit operation should have thrown an error' }; - } catch (e) { - if (e.statusCode) { - throw JSON.parse(e.error); - } - } - }); - - server.lookup2identity = (search) => co(function*() { - const lookup = yield server.get('/wot/lookup/' + search); - return Identity.statics.fromJSON({ - issuer: lookup.results[0].pubkey, - currency: conf.currency, - uid: lookup.results[0].uids[0].uid, - buid: lookup.results[0].uids[0].meta.timestamp, - sig: lookup.results[0].uids[0].self - }); - }); - - server.readBlock = (number) => co(function*() { - const block = yield server.get('/blockchain/block/' + number); - return Block.statics.fromJSON(block); - }); - - server.makeNext = (overrideProps) => co(function*() { - const block = yield require('../../../app/modules/prover').ProverDependency.duniter.methods.generateAndProveTheNext(server, null, null, overrideProps || {}); - return Block.statics.fromJSON(block); - }); - - server.sharePeeringWith = (otherServer) => co(function*() { - let p = yield server.get('/network/peering'); - yield otherServer.post('/network/peering/peers', { - peer: Peer.statics.peerize(p).getRawSigned() - }); - }); - - server.postIdentity = (idty) => server.post('/wot/add', { - identity: idty.createIdentity() - }); - - server.postCert = (cert) => server.post('/wot/certify', { - cert: cert.getRaw() - }); - - server.postMembership = (ms) => server.post('/blockchain/membership', { - membership: ms.getRawSigned() - }); - - server.postRevocation = (rev) => server.post('/wot/revoke', { - revocation: rev.getRaw() - }); - - server.postBlock = (block) => server.post('/blockchain/block', { - block: block.getRawSigned() - }); - - server.postRawTX = (rawTX) => server.post('/tx/process', { - transaction: rawTX - }); - - server.postPeer = (peer) => server.post('/network/peering/peers', { - peer: peer.getRawSigned() - }); - - server.prepareForNetwork = () => co(function*() { - yield server.initWithDAL(); - const bmaAPI = yield bma(server); - yield bmaAPI.openConnections(); - server.bma = bmaAPI; - require('../../../app/modules/router').duniter.methods.routeToNetwork(server); - // Extra: for /wot/requirements URL - require('../../../app/modules/prover').ProverDependency.duniter.methods.hookServer(server); - }); - - let prover; - server.startBlockComputation = () => { - if (!prover) { - prover = require('../../../app/modules/prover').ProverDependency.duniter.methods.prover(server); - server.permaProver = prover.permaProver; - server.pipe(prover); - } - prover.startService(); - }; - // server.startBlockComputation = () => prover.startService(); - server.stopBlockComputation = () => prover.stopService(); - - server.getMainEndpoint = require('duniter-bma').duniter.methods.getMainEndpoint - - return server; - } + conf.sigQty = 1; + } + const server = new server_1.Server('~/.config/duniter/' + (conf.homename || 'dev_unit_tests'), conf.memory !== undefined ? conf.memory : MEMORY_MODE, _.extend(conf, commonConf)); + return new TestingServer(port, server); }; +class TestingServer { + constructor(port, server) { + this.port = port; + this.server = server; + server.getMainEndpoint = require('duniter-bma').duniter.methods.getMainEndpoint; + } + get BlockchainService() { + return this.server.BlockchainService; + } + get PeeringService() { + return this.server.PeeringService; + } + get conf() { + return this.server.conf; + } + get dal() { + return this.server.dal; + } + get logger() { + return this.server.logger; + } + get home() { + return this.server.home; + } + revert() { + return this.server.revert(); + } + resetHome() { + return this.server.resetHome(); + } + on(event, f) { + return this.server.on(event, f); + } + recomputeSelfPeer() { + return this.server.recomputeSelfPeer(); + } + singleWritePromise(obj) { + return this.server.singleWritePromise(obj); + } + exportAllDataAsZIP() { + return this.server.exportAllDataAsZIP(); + } + unplugFileSystem() { + return this.server.unplugFileSystem(); + } + importAllDataFromZIP(zipFile) { + return this.server.importAllDataFromZIP(zipFile); + } + push(chunk, encoding) { + return this.server.push(chunk, encoding); + } + pipe(writable) { + return this.server.pipe(writable); + } + initDalBmaConnections() { + return __awaiter(this, void 0, void 0, function* () { + yield this.server.initWithDAL(); + const bmapi = yield bma(this.server); + this.bma = bmapi; + const res = yield bmapi.openConnections(); + return res; + }); + } + url(uri) { + return 'http://' + [HOST, this.port].join(':') + uri; + } + get(uri) { + return rp(this.url(uri), { json: true }); + } + post(uri, obj) { + return rp(this.url(uri), { method: 'POST', json: true, body: obj }); + } + expect(uri, expectations) { + return typeof expectations == 'function' ? httpTest.expectAnswer(rp(this.url(uri), { json: true }), expectations) : httpTest.expectJSON(rp(this.url(uri), { json: true }), expectations); + } + expectThat(uri, expectations) { + return httpTest.expectAnswer(rp(this.url(uri), { json: true }), expectations); + } + expectJSON(uri, expectations) { + return httpTest.expectJSON(rp(this.url(uri), { json: true }), expectations); + } + expectError(uri, code, message) { + return httpTest.expectError(code, message, rp(this.url(uri), { json: true })); + } + syncFrom(otherServer, fromIncuded, toIncluded) { + return sync(fromIncuded, toIncluded, otherServer, this.server); + } + until(type, count) { + return until(this.server, type, count); + } + commit(options = null) { + return __awaiter(this, void 0, void 0, function* () { + const raw = yield commit(this.server)(options); + return JSON.parse(raw); + }); + } + commitExpectError(options) { + return __awaiter(this, void 0, void 0, function* () { + try { + const raw = yield commit(this.server)(options); + JSON.parse(raw); + throw { message: 'Commit operation should have thrown an error' }; + } + catch (e) { + if (e.statusCode) { + throw JSON.parse(e.error); + } + } + }); + } + lookup2identity(search) { + return __awaiter(this, void 0, void 0, function* () { + const lookup = yield this.get('/wot/lookup/' + search); + return Identity.statics.fromJSON({ + issuer: lookup.results[0].pubkey, + currency: this.server.conf.currency, + uid: lookup.results[0].uids[0].uid, + buid: lookup.results[0].uids[0].meta.timestamp, + sig: lookup.results[0].uids[0].self + }); + }); + } + readBlock(number) { + return __awaiter(this, void 0, void 0, function* () { + const block = yield this.get('/blockchain/block/' + number); + return BlockDTO_1.BlockDTO.fromJSONObject(block); + }); + } + makeNext(overrideProps) { + return __awaiter(this, void 0, void 0, function* () { + const block = yield require('../../../app/modules/prover').ProverDependency.duniter.methods.generateAndProveTheNext(this.server, null, null, overrideProps || {}); + return BlockDTO_1.BlockDTO.fromJSONObject(block); + }); + } + sharePeeringWith(otherServer) { + return __awaiter(this, void 0, void 0, function* () { + let p = yield this.get('/network/peering'); + yield otherServer.post('/network/peering/peers', { + peer: Peer.statics.peerize(p).getRawSigned() + }); + }); + } + postIdentity(idty) { + return this.post('/wot/add', { + identity: idty.createIdentity() + }); + } + postCert(cert) { + return this.post('/wot/certify', { + cert: cert.getRaw() + }); + } + postMembership(ms) { + return this.post('/blockchain/membership', { + membership: ms.getRawSigned() + }); + } + postRevocation(rev) { + return this.post('/wot/revoke', { + revocation: rev.getRaw() + }); + } + postBlock(block) { + return this.post('/blockchain/block', { + block: block.getRawSigned() + }); + } + postRawTX(rawTX) { + return this.post('/tx/process', { + transaction: rawTX + }); + } + postPeer(peer) { + return this.post('/network/peering/peers', { + peer: peer.getRawSigned() + }); + } + prepareForNetwork() { + return __awaiter(this, void 0, void 0, function* () { + yield this.server.initWithDAL(); + const bmaAPI = yield bma(this.server); + yield bmaAPI.openConnections(); + this.bma = bmaAPI; + require('../../../app/modules/router').duniter.methods.routeToNetwork(this.server); + // Extra: for /wot/requirements URL + require('../../../app/modules/prover').ProverDependency.duniter.methods.hookServer(this.server); + }); + } + startBlockComputation() { + if (!this.prover) { + this.prover = require('../../../app/modules/prover').ProverDependency.duniter.methods.prover(this.server); + this.permaProver = this.prover.permaProver; + this.server.pipe(this.prover); + } + this.prover.startService(); + } + // server.startBlockComputation = () => this.prover.startService(); + stopBlockComputation() { + return this.prover.stopService(); + } +} +exports.TestingServer = TestingServer; +//# sourceMappingURL=toolbox.js.map \ No newline at end of file diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts new file mode 100644 index 0000000000000000000000000000000000000000..c4abd3709535c4bb765f5d3709a6c45fc1ef8c77 --- /dev/null +++ b/test/integration/tools/toolbox.ts @@ -0,0 +1,443 @@ +import {Server} from "../../../server" +import {PermanentProver} from "../../../app/modules/prover/lib/permanentProver" +import {Prover} from "../../../app/modules/prover/lib/prover" +import {BlockDTO} from "../../../app/lib/dto/BlockDTO" +import * as stream from "stream" + +const _ = require('underscore'); +const rp = require('request-promise'); +const httpTest = require('../tools/http'); +const sync = require('../tools/sync'); +const commit = require('../tools/commit'); +const user = require('../tools/user'); +const until = require('../tools/until'); +const Peer = require('../../../app/lib/entity/peer'); +const Identity = require('../../../app/lib/entity/identity'); +const bma = require('duniter-bma').duniter.methods.bma; +const multicaster = require('../../../app/lib/streams/multicaster'); +const dtos = require('duniter-bma').duniter.methods.dtos; +const logger = require('../../../app/lib/logger').NewLogger('toolbox'); + +require('duniter-bma').duniter.methods.noLimit(); // Disables the HTTP limiter + +const MEMORY_MODE = true; +const CURRENCY_NAME = 'duniter_unit_test_currency'; +const HOST = '127.0.0.1'; +let PORT = 10000; + + +export const shouldFail = async (promise:Promise<any>, message:string|null = null) => { + try { + await promise; + throw '{ "message": "Should have thrown an error" }' + } catch(e) { + let err = e + if (typeof e === "string") { + err = JSON.parse(e) + } + err.should.have.property('message').equal(message); + } +} + +export const simpleNetworkOf2NodesAnd2Users = async (options:any) => { + const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}; + const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}; + + const s1 = NewTestingServer(_.extend({ pair: catKeyring }, options || {})); + const s2 = NewTestingServer(_.extend({ pair: tacKeyring }, options || {})); + + const cat = user('cat', catKeyring, { server: s1 }); + const tac = user('tac', tacKeyring, { server: s1 }); + + await s1.initDalBmaConnections() + await s2.initDalBmaConnections() + + await s2.sharePeeringWith(s1); + // await s2.post('/network/peering/peers', await s1.get('/network/peering')); + // await s1.submitPeerP(await s2.get('/network/peering')); + + await cat.createIdentity(); + await tac.createIdentity(); + await cat.cert(tac); + await tac.cert(cat); + await cat.join(); + await tac.join(); + + // Each server forwards to each other + require('../../../app/modules/router').duniter.methods.routeToNetwork(s1); + require('../../../app/modules/router').duniter.methods.routeToNetwork(s2); + + return { s1, s2, cat, tac }; +} + +export const simpleNodeWith2Users = async (options:any) => { + + const catKeyring = { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}; + const tacKeyring = { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}; + + const s1 = NewTestingServer(_.extend({ pair: catKeyring }, options || {})); + + const cat = user('cat', catKeyring, { server: s1 }); + const tac = user('tac', tacKeyring, { server: s1 }); + + await s1.initDalBmaConnections() + + await cat.createIdentity(); + await tac.createIdentity(); + await cat.cert(tac); + await tac.cert(cat); + await cat.join(); + await tac.join(); + + return { s1, cat, tac }; +} + +export const simpleNodeWith2otherUsers = async (options:any) => { + + const ticKeyring = { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}; + const tocKeyring = { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}; + + const s1 = NewTestingServer(_.extend({ pair: ticKeyring }, options || {})); + + const tic = user('cat', ticKeyring, { server: s1 }); + const toc = user('tac', tocKeyring, { server: s1 }); + + await s1.initDalBmaConnections() + + await tic.createIdentity(); + await toc.createIdentity(); + await tic.cert(toc); + await toc.cert(tic); + await tic.join(); + await toc.join(); + + return { s1, tic, toc }; +} + +export const createUser = async (uid:string, pub:string, sec:string, defaultServer:Server) => { + const keyring = { pub: pub, sec: sec }; + return user(uid, keyring, { server: defaultServer }); +} + +export const fakeSyncServer = async (readBlocksMethod:any, readParticularBlockMethod:any, onPeersRequested:any) => { + + const host = HOST; + const port = PORT++; + + // Meaningful variables + const NO_HTTP_LOGS = false; + const NO_STATIC_PATH = null; + + // A fake HTTP limiter with no limit at all + const noLimit = { + canAnswerNow: () => true, + processRequest: () => { /* Does nothing */ } + }; + + const fakeServer = await require('duniter-bma').duniter.methods.createServersAndListen("Fake Duniter Server", { conf: {} }, [{ + ip: host, + port: port + }], NO_HTTP_LOGS, logger, NO_STATIC_PATH, (app:any, httpMethods:any) => { + + // Mock BMA method for sync mocking + httpMethods.httpGET('/network/peering', async () => { + return { + endpoints: [['BASIC_MERKLED_API', host, port].join(' ')] + } + }, dtos.Peer, noLimit); + + // Mock BMA method for sync mocking + httpMethods.httpGET('/network/peering/peers', onPeersRequested, dtos.MerkleOfPeers, noLimit); + + // Another mock BMA method for sync mocking + httpMethods.httpGET('/blockchain/blocks/:count/:from', (req:any) => { + + // What do we do on /blockchain/blocks request + let count = parseInt(req.params.count); + let from = parseInt(req.params.from); + + return readBlocksMethod(count, from); + + }, dtos.Blocks, noLimit); + + // Another mock BMA method for sync mocking + httpMethods.httpGET('/blockchain/block/:number', (req:any) => { + + // What do we do on /blockchain/blocks request + let number = parseInt(req.params.number); + + return readParticularBlockMethod(number); + + }, dtos.Block, noLimit); + }); + + await fakeServer.openConnections(); + return { + host: host, + port: port + }; +} + +/** + * Creates a new memory duniter server for Unit Test purposes. + * @param conf + */ +export const server = (conf:any) => NewTestingServer(conf) + +export const NewTestingServer = (conf:any) => { + const port = PORT++; + const commonConf = { + port: port, + ipv4: HOST, + remoteipv4: HOST, + currency: conf.currency || CURRENCY_NAME, + httpLogs: true, + forksize: 3 + }; + if (conf.sigQty === undefined) { + conf.sigQty = 1; + } + const server = new Server( + '~/.config/duniter/' + (conf.homename || 'dev_unit_tests'), + conf.memory !== undefined ? conf.memory : MEMORY_MODE, + _.extend(conf, commonConf)); + + return new TestingServer(port, server) +} + +export class TestingServer { + + private prover:Prover + private permaProver:PermanentProver + private bma:any + + constructor( + private port:number, + private server:Server) { + + server.getMainEndpoint = require('duniter-bma').duniter.methods.getMainEndpoint + } + + get BlockchainService() { + return this.server.BlockchainService + } + + get PeeringService() { + return this.server.PeeringService + } + + get conf() { + return this.server.conf + } + + get dal() { + return this.server.dal + } + + get logger() { + return this.server.logger + } + + get home() { + return this.server.home + } + + revert() { + return this.server.revert() + } + + resetHome() { + return this.server.resetHome() + } + + on(event:string, f:any) { + return this.server.on(event, f) + } + + recomputeSelfPeer() { + return this.server.recomputeSelfPeer() + } + + singleWritePromise(obj:any) { + return this.server.singleWritePromise(obj) + } + + exportAllDataAsZIP() { + return this.server.exportAllDataAsZIP() + } + + unplugFileSystem() { + return this.server.unplugFileSystem() + } + + importAllDataFromZIP(zipFile:string) { + return this.server.importAllDataFromZIP(zipFile) + } + + push(chunk: any, encoding?: string) { + return this.server.push(chunk, encoding) + } + + pipe(writable:stream.Writable) { + return this.server.pipe(writable) + } + + async initDalBmaConnections() { + await this.server.initWithDAL() + const bmapi = await bma(this.server) + this.bma = bmapi + const res = await bmapi.openConnections() + return res + } + + url(uri:string) { + return 'http://' + [HOST, this.port].join(':') + uri; + } + + get(uri:string) { + return rp(this.url(uri), { json: true }); + } + + post(uri:string, obj:any) { + return rp(this.url(uri), { method: 'POST', json: true, body: obj }); + } + + + expect(uri:string, expectations:any) { + return typeof expectations == 'function' ? httpTest.expectAnswer(rp(this.url(uri), { json: true }), expectations) : httpTest.expectJSON(rp(this.url(uri), { json: true }), expectations); + } + + expectThat(uri:string, expectations:any) { + return httpTest.expectAnswer(rp(this.url(uri), { json: true }), expectations); + } + + expectJSON(uri:string, expectations:any) { + return httpTest.expectJSON(rp(this.url(uri), { json: true }), expectations); + } + + expectError(uri:string, code:number, message:string) { + return httpTest.expectError(code, message, rp(this.url(uri), { json: true })); + } + + + syncFrom(otherServer:Server, fromIncuded:number, toIncluded:number) { + return sync(fromIncuded, toIncluded, otherServer, this.server); + } + + + until(type:string, count:number) { + return until(this.server, type, count); + } + + + async commit(options:any = null) { + const raw = await commit(this.server)(options); + return JSON.parse(raw); + } + + async commitExpectError(options:any) { + try { + const raw = await commit(this.server)(options); + JSON.parse(raw); + throw { message: 'Commit operation should have thrown an error' }; + } catch (e) { + if (e.statusCode) { + throw JSON.parse(e.error); + } + } + } + + async lookup2identity(search:string) { + const lookup = await this.get('/wot/lookup/' + search); + return Identity.statics.fromJSON({ + issuer: lookup.results[0].pubkey, + currency: this.server.conf.currency, + uid: lookup.results[0].uids[0].uid, + buid: lookup.results[0].uids[0].meta.timestamp, + sig: lookup.results[0].uids[0].self + }); + } + + async readBlock(number:number) { + const block = await this.get('/blockchain/block/' + number); + return BlockDTO.fromJSONObject(block) + } + + async makeNext(overrideProps:any) { + const block = await require('../../../app/modules/prover').ProverDependency.duniter.methods.generateAndProveTheNext(this.server, null, null, overrideProps || {}); + return BlockDTO.fromJSONObject(block) + } + + async sharePeeringWith(otherServer:TestingServer) { + let p = await this.get('/network/peering'); + await otherServer.post('/network/peering/peers', { + peer: Peer.statics.peerize(p).getRawSigned() + }); + } + + postIdentity(idty:any) { + return this.post('/wot/add', { + identity: idty.createIdentity() + }) + } + + postCert(cert:any) { + return this.post('/wot/certify', { + cert: cert.getRaw() + }) + } + + postMembership(ms:any) { + return this.post('/blockchain/membership', { + membership: ms.getRawSigned() + }) + } + + postRevocation(rev:any) { + return this.post('/wot/revoke', { + revocation: rev.getRaw() + }) + } + + postBlock(block:BlockDTO) { + return this.post('/blockchain/block', { + block: block.getRawSigned() + }) + } + + postRawTX(rawTX:any) { + return this.post('/tx/process', { + transaction: rawTX + }) + } + + postPeer(peer:any) { + return this.post('/network/peering/peers', { + peer: peer.getRawSigned() + }) + } + + async prepareForNetwork() { + await this.server.initWithDAL(); + const bmaAPI = await bma(this.server); + await bmaAPI.openConnections(); + this.bma = bmaAPI; + require('../../../app/modules/router').duniter.methods.routeToNetwork(this.server); + // Extra: for /wot/requirements URL + require('../../../app/modules/prover').ProverDependency.duniter.methods.hookServer(this.server); + } + + startBlockComputation() { + if (!this.prover) { + this.prover = require('../../../app/modules/prover').ProverDependency.duniter.methods.prover(this.server); + this.permaProver = this.prover.permaProver + this.server.pipe(this.prover); + } + this.prover.startService(); + } + + // server.startBlockComputation = () => this.prover.startService(); + stopBlockComputation() { + return this.prover.stopService(); + } +} \ No newline at end of file diff --git a/test/integration/transactions-chaining.js b/test/integration/transactions-chaining.js index a995064e14ca2a42cfd299aae0308d7961b8f545..7d867158cc85ede461180752933a959712382a83 100644 --- a/test/integration/transactions-chaining.js +++ b/test/integration/transactions-chaining.js @@ -33,7 +33,7 @@ describe("Transaction chaining", function() { before(() => co(function*() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield tic.createIdentity(); yield toc.createIdentity(); yield tic.cert(toc); diff --git a/test/integration/transactions-test.js b/test/integration/transactions-test.js index 2b3bafad657d1d25f580681a99644ac8f5805f0d..aab8f40f6863789f2057a69bc742646e2e1e7427 100644 --- a/test/integration/transactions-test.js +++ b/test/integration/transactions-test.js @@ -36,7 +36,7 @@ describe("Testing transactions", function() { before(() => co(function*() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); // Self certifications yield tic.createIdentity(); yield toc.createIdentity(); diff --git a/test/integration/v1.1-dividend.js b/test/integration/v1.1-dividend.js index f28a622c6df34037f182ffb295ddfbd40de5c627..02516308ecd46104e80756957f93755a81bb6187 100644 --- a/test/integration/v1.1-dividend.js +++ b/test/integration/v1.1-dividend.js @@ -32,7 +32,7 @@ describe("Protocol 1.1 Dividend", function() { before(() => co(function*() { - yield s1.initWithDAL().then(bma).then((bmapi) => bmapi.openConnections()); + yield s1.initDalBmaConnections(); yield cat.createIdentity(); yield tac.createIdentity();