From 9fa2af0345c16da37b99001bb956bdd73ae68cd5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 18 Jun 2020 21:48:56 +0100 Subject: [PATCH 01/18] Fixed #604 - Modify votingkey transaction --- e2e/infrastructure/TransactionHttp.spec.ts | 4 ++ package-lock.json | 6 +-- package.json | 2 +- .../transaction/CreateTransactionFromDTO.ts | 2 + .../transaction/SerializeTransactionToJSON.ts | 2 + .../transaction/VotingKeyLinkTransaction.ts | 27 ++++++++++++- test/core/utils/TransactionMapping.spec.ts | 24 +++++++++++- .../TransactionMappingWithSignatures.spec.ts | 6 +++ .../SerializeTransactionToJSON.spec.ts | 4 ++ .../VotingKeyLinkTransaction.spec.ts | 39 ++++++++++++++++--- 10 files changed, 104 insertions(+), 12 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 3741f28a9a..a67a1032cc 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -737,6 +737,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, networkType, helper.maxFee, @@ -755,6 +757,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Unlink, networkType, helper.maxFee, diff --git a/package-lock.json b/package-lock.json index 61cb3fbb74..71038a5659 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1307,9 +1307,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.20", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.20.tgz", - "integrity": "sha512-dww9nmGqMyyHF+D53cqxBGppq0rfjG+Jvorfho8BGZ4cOwXTwdUDoD+HTpn6f0ZlBW2w8LlbBPEGNdR9CIeyHQ==" + "version": "0.0.21-alpha-202006182119", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006182119.tgz", + "integrity": "sha512-G3SLZz8S4gmbIiShRsODoN4HQvANHTpxJ3/WLXyIwNHDEdnlzgI1CgI54e/xS0tUHXVMteMGcuIENQBe8G4m6g==" }, "chai": { "version": "4.1.2", diff --git a/package.json b/package.json index afc51611ec..fa7a2df0f1 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.20", + "catbuffer-typescript": "0.0.21-alpha-202006182119", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 45f8cda6c9..e86ab87454 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -491,6 +491,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), transactionDTO.linkedPublicKey, + UInt64.fromNumericString(transactionDTO.startPoint), + UInt64.fromNumericString(transactionDTO.endPoint), transactionDTO.linkAction, transactionDTO.signature, transactionDTO.signerPublicKey diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index a824417044..19bc3ab12f 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -269,6 +269,8 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { const votingKeyLinkTx = transaction as VotingKeyLinkTransaction; return { linkedPublicKey: votingKeyLinkTx.linkedPublicKey, + startPoint: votingKeyLinkTx.startPoint.toString(), + endPoint: votingKeyLinkTx.endPoint.toString(), linkAction: votingKeyLinkTx.linkAction, }; default: diff --git a/src/model/transaction/VotingKeyLinkTransaction.ts b/src/model/transaction/VotingKeyLinkTransaction.ts index d1922d4df8..0303b62744 100644 --- a/src/model/transaction/VotingKeyLinkTransaction.ts +++ b/src/model/transaction/VotingKeyLinkTransaction.ts @@ -36,12 +36,15 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { FinalizationPointDto } from 'catbuffer-typescript/dist/FinalizationPointDto'; export class VotingKeyLinkTransaction extends Transaction { /** * Create a voting key link transaction object * @param deadline - The deadline to include the transaction. * @param linkedPublicKey - The public key for voting (48 bytes). + * @param startPoint - The start finalization point. + * @param endPoint - The end finalization point. * @param linkAction - The account link action. * @param maxFee - (Optional) Max fee defined by the sender * @param signature - (Optional) Transaction signature @@ -51,6 +54,8 @@ export class VotingKeyLinkTransaction extends Transaction { public static create( deadline: Deadline, linkedPublicKey: string, + startPoint: UInt64, + endPoint: UInt64, linkAction: LinkAction, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), @@ -63,6 +68,8 @@ export class VotingKeyLinkTransaction extends Transaction { deadline, maxFee, linkedPublicKey, + startPoint, + endPoint, linkAction, signature, signer, @@ -75,6 +82,8 @@ export class VotingKeyLinkTransaction extends Transaction { * @param deadline * @param maxFee * @param linkedPublicKey + * @param startPoint + * @param endPoint * @param linkAction * @param signature * @param signer @@ -89,6 +98,14 @@ export class VotingKeyLinkTransaction extends Transaction { * The public key of the remote account. */ public readonly linkedPublicKey: string, + /** + * The start finalization point. + */ + public readonly startPoint: UInt64, + /** + * The start finalization point. + */ + public readonly endPoint: UInt64, /** * The account link action. */ @@ -116,6 +133,8 @@ export class VotingKeyLinkTransaction extends Transaction { const transaction = VotingKeyLinkTransaction.create( isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as VotingKeyLinkTransactionBuilder).getDeadline().timestamp), Convert.uint8ToHex(builder.getLinkedPublicKey().votingKey), + new UInt64(builder.getStartPoint().finalizationPoint), + new UInt64(builder.getEndPoint().finalizationPoint), builder.getLinkAction().valueOf(), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as VotingKeyLinkTransactionBuilder).fee.amount), @@ -136,9 +155,11 @@ export class VotingKeyLinkTransaction extends Transaction { // set static byte size fields const bytePublicKey = 48; + const startPoint = 8; + const endPoint = 8; const byteLinkAction = 1; - return byteSize + bytePublicKey + byteLinkAction; + return byteSize + bytePublicKey + startPoint + endPoint + byteLinkAction; } /** @@ -158,6 +179,8 @@ export class VotingKeyLinkTransaction extends Transaction { new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); return transactionBuilder.serialize(); @@ -174,6 +197,8 @@ export class VotingKeyLinkTransaction extends Transaction { this.networkType.valueOf(), TransactionType.VOTING_KEY_LINK.valueOf(), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d9d2dbe3da..8304a30584 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -418,6 +418,8 @@ describe('TransactionMapping - createFromPayload', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -611,12 +613,21 @@ describe('TransactionMapping - createFromPayload', () => { it('should create an VotingKeyLinkTransaction object with link action', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as VotingKeyLinkTransaction; expect(transaction.linkAction).to.be.equal(1); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkedPublicKey).to.be.equal(key); }); @@ -906,11 +917,20 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create VotingKeyLinkTransaction', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const transaction = TransactionMapping.createFromDTO(votingKeyLinkTransaction.toJSON()) as VotingKeyLinkTransaction; expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkAction).to.be.equal(LinkAction.Link); }); it('should create AccountRestrictionAddressTransaction', () => { diff --git a/test/core/utils/TransactionMappingWithSignatures.spec.ts b/test/core/utils/TransactionMappingWithSignatures.spec.ts index d720ff08fd..a1bd933e13 100644 --- a/test/core/utils/TransactionMappingWithSignatures.spec.ts +++ b/test/core/utils/TransactionMappingWithSignatures.spec.ts @@ -499,6 +499,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -767,6 +769,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), key, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, undefined, @@ -779,6 +783,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign expect(transaction.linkAction).to.be.equal(1); expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f9b5e9416..8bb1a5ade8 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -403,6 +403,8 @@ describe('SerializeTransactionToJSON', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -410,6 +412,8 @@ describe('SerializeTransactionToJSON', () => { const json = votingKeyLinkTransaction.toJSON(); expect(json.transaction.linkedPublicKey).to.be.equal(votingKey); + expect(json.transaction.startPoint).to.be.equal('1'); + expect(json.transaction.endPoint.toString()).to.be.equal('3'); expect(json.transaction.linkAction).to.be.equal(LinkAction.Link); }); }); diff --git a/test/model/transaction/VotingKeyLinkTransaction.spec.ts b/test/model/transaction/VotingKeyLinkTransaction.spec.ts index 7cc9755aa9..04f77385f7 100644 --- a/test/model/transaction/VotingKeyLinkTransaction.spec.ts +++ b/test/model/transaction/VotingKeyLinkTransaction.spec.ts @@ -28,6 +28,8 @@ import { Address } from '../../../src/model/account/Address'; describe('VotingKeyLinkTransaction', () => { let account: Account; let votingKey: string; + const startPoint = UInt64.fromUint(1); + const endPoint = UInt64.fromUint(10); const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; @@ -38,18 +40,24 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(0); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should filled maxFee override transaction maxFee', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -57,23 +65,29 @@ describe('VotingKeyLinkTransaction', () => { expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(1); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should create an votingKeyLinkTransaction object with link action', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(1); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000001', ); }); @@ -81,17 +95,21 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(0); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D000', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000000', ); }); @@ -100,11 +118,13 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(Convert.hexToUint8(votingKeyLinkTransaction.serialize()).length).to.be.equal(votingKeyLinkTransaction.size); - expect(votingKeyLinkTransaction.size).to.be.equal(177); + expect(votingKeyLinkTransaction.size).to.be.equal(193); }); }); @@ -112,17 +132,26 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(354); + expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(386); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; }); it('Notify Account', () => { - const tx = VotingKeyLinkTransaction.create(Deadline.create(), account.publicKey, LinkAction.Unlink, NetworkType.MIJIN_TEST); + const tx = VotingKeyLinkTransaction.create( + Deadline.create(), + account.publicKey, + startPoint, + endPoint, + LinkAction.Unlink, + NetworkType.MIJIN_TEST, + ); let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; From cd8a02aa46103008cf25017a0ca7a292c372330e Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 18 Jun 2020 21:48:56 +0100 Subject: [PATCH 02/18] Fixed #604 - Modify votingkey transaction --- e2e/infrastructure/TransactionHttp.spec.ts | 4 ++ package-lock.json | 6 +-- package.json | 2 +- .../transaction/CreateTransactionFromDTO.ts | 2 + .../transaction/SerializeTransactionToJSON.ts | 2 + .../transaction/VotingKeyLinkTransaction.ts | 27 ++++++++++++- test/core/utils/TransactionMapping.spec.ts | 24 +++++++++++- .../TransactionMappingWithSignatures.spec.ts | 6 +++ .../SerializeTransactionToJSON.spec.ts | 4 ++ .../VotingKeyLinkTransaction.spec.ts | 39 ++++++++++++++++--- 10 files changed, 104 insertions(+), 12 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 3741f28a9a..a67a1032cc 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -737,6 +737,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, networkType, helper.maxFee, @@ -755,6 +757,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Unlink, networkType, helper.maxFee, diff --git a/package-lock.json b/package-lock.json index 98479ffa6a..f64d09bd26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1307,9 +1307,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.20", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.20.tgz", - "integrity": "sha512-dww9nmGqMyyHF+D53cqxBGppq0rfjG+Jvorfho8BGZ4cOwXTwdUDoD+HTpn6f0ZlBW2w8LlbBPEGNdR9CIeyHQ==" + "version": "0.0.21-alpha-202006182119", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006182119.tgz", + "integrity": "sha512-G3SLZz8S4gmbIiShRsODoN4HQvANHTpxJ3/WLXyIwNHDEdnlzgI1CgI54e/xS0tUHXVMteMGcuIENQBe8G4m6g==" }, "chai": { "version": "4.1.2", diff --git a/package.json b/package.json index 63bbcc1048..01e1f8772e 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.20", + "catbuffer-typescript": "0.0.21-alpha-202006182119", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 45f8cda6c9..e86ab87454 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -491,6 +491,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), transactionDTO.linkedPublicKey, + UInt64.fromNumericString(transactionDTO.startPoint), + UInt64.fromNumericString(transactionDTO.endPoint), transactionDTO.linkAction, transactionDTO.signature, transactionDTO.signerPublicKey diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index a824417044..19bc3ab12f 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -269,6 +269,8 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { const votingKeyLinkTx = transaction as VotingKeyLinkTransaction; return { linkedPublicKey: votingKeyLinkTx.linkedPublicKey, + startPoint: votingKeyLinkTx.startPoint.toString(), + endPoint: votingKeyLinkTx.endPoint.toString(), linkAction: votingKeyLinkTx.linkAction, }; default: diff --git a/src/model/transaction/VotingKeyLinkTransaction.ts b/src/model/transaction/VotingKeyLinkTransaction.ts index d1922d4df8..0303b62744 100644 --- a/src/model/transaction/VotingKeyLinkTransaction.ts +++ b/src/model/transaction/VotingKeyLinkTransaction.ts @@ -36,12 +36,15 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { FinalizationPointDto } from 'catbuffer-typescript/dist/FinalizationPointDto'; export class VotingKeyLinkTransaction extends Transaction { /** * Create a voting key link transaction object * @param deadline - The deadline to include the transaction. * @param linkedPublicKey - The public key for voting (48 bytes). + * @param startPoint - The start finalization point. + * @param endPoint - The end finalization point. * @param linkAction - The account link action. * @param maxFee - (Optional) Max fee defined by the sender * @param signature - (Optional) Transaction signature @@ -51,6 +54,8 @@ export class VotingKeyLinkTransaction extends Transaction { public static create( deadline: Deadline, linkedPublicKey: string, + startPoint: UInt64, + endPoint: UInt64, linkAction: LinkAction, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), @@ -63,6 +68,8 @@ export class VotingKeyLinkTransaction extends Transaction { deadline, maxFee, linkedPublicKey, + startPoint, + endPoint, linkAction, signature, signer, @@ -75,6 +82,8 @@ export class VotingKeyLinkTransaction extends Transaction { * @param deadline * @param maxFee * @param linkedPublicKey + * @param startPoint + * @param endPoint * @param linkAction * @param signature * @param signer @@ -89,6 +98,14 @@ export class VotingKeyLinkTransaction extends Transaction { * The public key of the remote account. */ public readonly linkedPublicKey: string, + /** + * The start finalization point. + */ + public readonly startPoint: UInt64, + /** + * The start finalization point. + */ + public readonly endPoint: UInt64, /** * The account link action. */ @@ -116,6 +133,8 @@ export class VotingKeyLinkTransaction extends Transaction { const transaction = VotingKeyLinkTransaction.create( isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as VotingKeyLinkTransactionBuilder).getDeadline().timestamp), Convert.uint8ToHex(builder.getLinkedPublicKey().votingKey), + new UInt64(builder.getStartPoint().finalizationPoint), + new UInt64(builder.getEndPoint().finalizationPoint), builder.getLinkAction().valueOf(), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as VotingKeyLinkTransactionBuilder).fee.amount), @@ -136,9 +155,11 @@ export class VotingKeyLinkTransaction extends Transaction { // set static byte size fields const bytePublicKey = 48; + const startPoint = 8; + const endPoint = 8; const byteLinkAction = 1; - return byteSize + bytePublicKey + byteLinkAction; + return byteSize + bytePublicKey + startPoint + endPoint + byteLinkAction; } /** @@ -158,6 +179,8 @@ export class VotingKeyLinkTransaction extends Transaction { new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); return transactionBuilder.serialize(); @@ -174,6 +197,8 @@ export class VotingKeyLinkTransaction extends Transaction { this.networkType.valueOf(), TransactionType.VOTING_KEY_LINK.valueOf(), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d9d2dbe3da..8304a30584 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -418,6 +418,8 @@ describe('TransactionMapping - createFromPayload', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -611,12 +613,21 @@ describe('TransactionMapping - createFromPayload', () => { it('should create an VotingKeyLinkTransaction object with link action', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as VotingKeyLinkTransaction; expect(transaction.linkAction).to.be.equal(1); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkedPublicKey).to.be.equal(key); }); @@ -906,11 +917,20 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create VotingKeyLinkTransaction', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const transaction = TransactionMapping.createFromDTO(votingKeyLinkTransaction.toJSON()) as VotingKeyLinkTransaction; expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkAction).to.be.equal(LinkAction.Link); }); it('should create AccountRestrictionAddressTransaction', () => { diff --git a/test/core/utils/TransactionMappingWithSignatures.spec.ts b/test/core/utils/TransactionMappingWithSignatures.spec.ts index d720ff08fd..a1bd933e13 100644 --- a/test/core/utils/TransactionMappingWithSignatures.spec.ts +++ b/test/core/utils/TransactionMappingWithSignatures.spec.ts @@ -499,6 +499,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -767,6 +769,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), key, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, undefined, @@ -779,6 +783,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign expect(transaction.linkAction).to.be.equal(1); expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f9b5e9416..8bb1a5ade8 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -403,6 +403,8 @@ describe('SerializeTransactionToJSON', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -410,6 +412,8 @@ describe('SerializeTransactionToJSON', () => { const json = votingKeyLinkTransaction.toJSON(); expect(json.transaction.linkedPublicKey).to.be.equal(votingKey); + expect(json.transaction.startPoint).to.be.equal('1'); + expect(json.transaction.endPoint.toString()).to.be.equal('3'); expect(json.transaction.linkAction).to.be.equal(LinkAction.Link); }); }); diff --git a/test/model/transaction/VotingKeyLinkTransaction.spec.ts b/test/model/transaction/VotingKeyLinkTransaction.spec.ts index 7cc9755aa9..04f77385f7 100644 --- a/test/model/transaction/VotingKeyLinkTransaction.spec.ts +++ b/test/model/transaction/VotingKeyLinkTransaction.spec.ts @@ -28,6 +28,8 @@ import { Address } from '../../../src/model/account/Address'; describe('VotingKeyLinkTransaction', () => { let account: Account; let votingKey: string; + const startPoint = UInt64.fromUint(1); + const endPoint = UInt64.fromUint(10); const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; @@ -38,18 +40,24 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(0); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should filled maxFee override transaction maxFee', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -57,23 +65,29 @@ describe('VotingKeyLinkTransaction', () => { expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(1); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should create an votingKeyLinkTransaction object with link action', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(1); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000001', ); }); @@ -81,17 +95,21 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(0); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D000', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000000', ); }); @@ -100,11 +118,13 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(Convert.hexToUint8(votingKeyLinkTransaction.serialize()).length).to.be.equal(votingKeyLinkTransaction.size); - expect(votingKeyLinkTransaction.size).to.be.equal(177); + expect(votingKeyLinkTransaction.size).to.be.equal(193); }); }); @@ -112,17 +132,26 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(354); + expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(386); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; }); it('Notify Account', () => { - const tx = VotingKeyLinkTransaction.create(Deadline.create(), account.publicKey, LinkAction.Unlink, NetworkType.MIJIN_TEST); + const tx = VotingKeyLinkTransaction.create( + Deadline.create(), + account.publicKey, + startPoint, + endPoint, + LinkAction.Unlink, + NetworkType.MIJIN_TEST, + ); let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; From 15dc5c2fb09d222dbb849284fc38e067538d55df Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 18 Jun 2020 21:48:56 +0100 Subject: [PATCH 03/18] Fixed #604 - Modify votingkey transaction --- e2e/infrastructure/TransactionHttp.spec.ts | 4 ++ package-lock.json | 6 +-- package.json | 2 +- .../transaction/CreateTransactionFromDTO.ts | 2 + .../transaction/SerializeTransactionToJSON.ts | 2 + .../transaction/VotingKeyLinkTransaction.ts | 27 ++++++++++++- test/core/utils/TransactionMapping.spec.ts | 24 +++++++++++- .../TransactionMappingWithSignatures.spec.ts | 6 +++ .../SerializeTransactionToJSON.spec.ts | 4 ++ .../VotingKeyLinkTransaction.spec.ts | 39 ++++++++++++++++--- 10 files changed, 104 insertions(+), 12 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 3741f28a9a..a67a1032cc 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -737,6 +737,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, networkType, helper.maxFee, @@ -755,6 +757,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Unlink, networkType, helper.maxFee, diff --git a/package-lock.json b/package-lock.json index 98479ffa6a..f64d09bd26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1307,9 +1307,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.20", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.20.tgz", - "integrity": "sha512-dww9nmGqMyyHF+D53cqxBGppq0rfjG+Jvorfho8BGZ4cOwXTwdUDoD+HTpn6f0ZlBW2w8LlbBPEGNdR9CIeyHQ==" + "version": "0.0.21-alpha-202006182119", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006182119.tgz", + "integrity": "sha512-G3SLZz8S4gmbIiShRsODoN4HQvANHTpxJ3/WLXyIwNHDEdnlzgI1CgI54e/xS0tUHXVMteMGcuIENQBe8G4m6g==" }, "chai": { "version": "4.1.2", diff --git a/package.json b/package.json index 63bbcc1048..01e1f8772e 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.20", + "catbuffer-typescript": "0.0.21-alpha-202006182119", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 45f8cda6c9..e86ab87454 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -491,6 +491,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), transactionDTO.linkedPublicKey, + UInt64.fromNumericString(transactionDTO.startPoint), + UInt64.fromNumericString(transactionDTO.endPoint), transactionDTO.linkAction, transactionDTO.signature, transactionDTO.signerPublicKey diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index a824417044..19bc3ab12f 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -269,6 +269,8 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { const votingKeyLinkTx = transaction as VotingKeyLinkTransaction; return { linkedPublicKey: votingKeyLinkTx.linkedPublicKey, + startPoint: votingKeyLinkTx.startPoint.toString(), + endPoint: votingKeyLinkTx.endPoint.toString(), linkAction: votingKeyLinkTx.linkAction, }; default: diff --git a/src/model/transaction/VotingKeyLinkTransaction.ts b/src/model/transaction/VotingKeyLinkTransaction.ts index d1922d4df8..0303b62744 100644 --- a/src/model/transaction/VotingKeyLinkTransaction.ts +++ b/src/model/transaction/VotingKeyLinkTransaction.ts @@ -36,12 +36,15 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { FinalizationPointDto } from 'catbuffer-typescript/dist/FinalizationPointDto'; export class VotingKeyLinkTransaction extends Transaction { /** * Create a voting key link transaction object * @param deadline - The deadline to include the transaction. * @param linkedPublicKey - The public key for voting (48 bytes). + * @param startPoint - The start finalization point. + * @param endPoint - The end finalization point. * @param linkAction - The account link action. * @param maxFee - (Optional) Max fee defined by the sender * @param signature - (Optional) Transaction signature @@ -51,6 +54,8 @@ export class VotingKeyLinkTransaction extends Transaction { public static create( deadline: Deadline, linkedPublicKey: string, + startPoint: UInt64, + endPoint: UInt64, linkAction: LinkAction, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), @@ -63,6 +68,8 @@ export class VotingKeyLinkTransaction extends Transaction { deadline, maxFee, linkedPublicKey, + startPoint, + endPoint, linkAction, signature, signer, @@ -75,6 +82,8 @@ export class VotingKeyLinkTransaction extends Transaction { * @param deadline * @param maxFee * @param linkedPublicKey + * @param startPoint + * @param endPoint * @param linkAction * @param signature * @param signer @@ -89,6 +98,14 @@ export class VotingKeyLinkTransaction extends Transaction { * The public key of the remote account. */ public readonly linkedPublicKey: string, + /** + * The start finalization point. + */ + public readonly startPoint: UInt64, + /** + * The start finalization point. + */ + public readonly endPoint: UInt64, /** * The account link action. */ @@ -116,6 +133,8 @@ export class VotingKeyLinkTransaction extends Transaction { const transaction = VotingKeyLinkTransaction.create( isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as VotingKeyLinkTransactionBuilder).getDeadline().timestamp), Convert.uint8ToHex(builder.getLinkedPublicKey().votingKey), + new UInt64(builder.getStartPoint().finalizationPoint), + new UInt64(builder.getEndPoint().finalizationPoint), builder.getLinkAction().valueOf(), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as VotingKeyLinkTransactionBuilder).fee.amount), @@ -136,9 +155,11 @@ export class VotingKeyLinkTransaction extends Transaction { // set static byte size fields const bytePublicKey = 48; + const startPoint = 8; + const endPoint = 8; const byteLinkAction = 1; - return byteSize + bytePublicKey + byteLinkAction; + return byteSize + bytePublicKey + startPoint + endPoint + byteLinkAction; } /** @@ -158,6 +179,8 @@ export class VotingKeyLinkTransaction extends Transaction { new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); return transactionBuilder.serialize(); @@ -174,6 +197,8 @@ export class VotingKeyLinkTransaction extends Transaction { this.networkType.valueOf(), TransactionType.VOTING_KEY_LINK.valueOf(), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d9d2dbe3da..8304a30584 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -418,6 +418,8 @@ describe('TransactionMapping - createFromPayload', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -611,12 +613,21 @@ describe('TransactionMapping - createFromPayload', () => { it('should create an VotingKeyLinkTransaction object with link action', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as VotingKeyLinkTransaction; expect(transaction.linkAction).to.be.equal(1); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkedPublicKey).to.be.equal(key); }); @@ -906,11 +917,20 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create VotingKeyLinkTransaction', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const transaction = TransactionMapping.createFromDTO(votingKeyLinkTransaction.toJSON()) as VotingKeyLinkTransaction; expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkAction).to.be.equal(LinkAction.Link); }); it('should create AccountRestrictionAddressTransaction', () => { diff --git a/test/core/utils/TransactionMappingWithSignatures.spec.ts b/test/core/utils/TransactionMappingWithSignatures.spec.ts index d720ff08fd..a1bd933e13 100644 --- a/test/core/utils/TransactionMappingWithSignatures.spec.ts +++ b/test/core/utils/TransactionMappingWithSignatures.spec.ts @@ -499,6 +499,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -767,6 +769,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), key, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, undefined, @@ -779,6 +783,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign expect(transaction.linkAction).to.be.equal(1); expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f9b5e9416..8bb1a5ade8 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -403,6 +403,8 @@ describe('SerializeTransactionToJSON', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -410,6 +412,8 @@ describe('SerializeTransactionToJSON', () => { const json = votingKeyLinkTransaction.toJSON(); expect(json.transaction.linkedPublicKey).to.be.equal(votingKey); + expect(json.transaction.startPoint).to.be.equal('1'); + expect(json.transaction.endPoint.toString()).to.be.equal('3'); expect(json.transaction.linkAction).to.be.equal(LinkAction.Link); }); }); diff --git a/test/model/transaction/VotingKeyLinkTransaction.spec.ts b/test/model/transaction/VotingKeyLinkTransaction.spec.ts index 7cc9755aa9..04f77385f7 100644 --- a/test/model/transaction/VotingKeyLinkTransaction.spec.ts +++ b/test/model/transaction/VotingKeyLinkTransaction.spec.ts @@ -28,6 +28,8 @@ import { Address } from '../../../src/model/account/Address'; describe('VotingKeyLinkTransaction', () => { let account: Account; let votingKey: string; + const startPoint = UInt64.fromUint(1); + const endPoint = UInt64.fromUint(10); const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; @@ -38,18 +40,24 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(0); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should filled maxFee override transaction maxFee', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -57,23 +65,29 @@ describe('VotingKeyLinkTransaction', () => { expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(1); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should create an votingKeyLinkTransaction object with link action', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(1); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000001', ); }); @@ -81,17 +95,21 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(0); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D000', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000000', ); }); @@ -100,11 +118,13 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(Convert.hexToUint8(votingKeyLinkTransaction.serialize()).length).to.be.equal(votingKeyLinkTransaction.size); - expect(votingKeyLinkTransaction.size).to.be.equal(177); + expect(votingKeyLinkTransaction.size).to.be.equal(193); }); }); @@ -112,17 +132,26 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(354); + expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(386); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; }); it('Notify Account', () => { - const tx = VotingKeyLinkTransaction.create(Deadline.create(), account.publicKey, LinkAction.Unlink, NetworkType.MIJIN_TEST); + const tx = VotingKeyLinkTransaction.create( + Deadline.create(), + account.publicKey, + startPoint, + endPoint, + LinkAction.Unlink, + NetworkType.MIJIN_TEST, + ); let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; From 3bed9d1643766b28cf28e9abf1e13da9887b3d4a Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 23 Jun 2020 16:22:07 +0100 Subject: [PATCH 04/18] Updated catbuffer version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index f64d09bd26..a6134f32b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1307,9 +1307,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.21-alpha-202006182119", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006182119.tgz", - "integrity": "sha512-G3SLZz8S4gmbIiShRsODoN4HQvANHTpxJ3/WLXyIwNHDEdnlzgI1CgI54e/xS0tUHXVMteMGcuIENQBe8G4m6g==" + "version": "0.0.21-alpha-202006231534", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006231534.tgz", + "integrity": "sha512-iwMwOi7N1gQQfRkpiZL+dVyzYV3U+IqMM9x3fvi0/0nbf3dMcnATo7K9ifbw8Or14uCmbUrw3zKhQ2EvYwkVlw==" }, "chai": { "version": "4.1.2", diff --git a/package.json b/package.json index 01e1f8772e..d65900441f 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.21-alpha-202006182119", + "catbuffer-typescript": "0.0.21-alpha-202006231534", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", From c6c742297a244083d27f9e638ef3576c55e7118b Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 18 Jun 2020 21:48:56 +0100 Subject: [PATCH 05/18] Fixed #604 - Modify votingkey transaction --- e2e/infrastructure/TransactionHttp.spec.ts | 4 ++ .../transaction/CreateTransactionFromDTO.ts | 2 + .../transaction/SerializeTransactionToJSON.ts | 2 + .../transaction/VotingKeyLinkTransaction.ts | 27 ++++++++++++- test/core/utils/TransactionMapping.spec.ts | 24 +++++++++++- .../TransactionMappingWithSignatures.spec.ts | 6 +++ .../SerializeTransactionToJSON.spec.ts | 4 ++ .../VotingKeyLinkTransaction.spec.ts | 39 ++++++++++++++++--- 8 files changed, 100 insertions(+), 8 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 3741f28a9a..a67a1032cc 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -737,6 +737,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, networkType, helper.maxFee, @@ -755,6 +757,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Unlink, networkType, helper.maxFee, diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 45f8cda6c9..e86ab87454 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -491,6 +491,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), transactionDTO.linkedPublicKey, + UInt64.fromNumericString(transactionDTO.startPoint), + UInt64.fromNumericString(transactionDTO.endPoint), transactionDTO.linkAction, transactionDTO.signature, transactionDTO.signerPublicKey diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index a824417044..19bc3ab12f 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -269,6 +269,8 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { const votingKeyLinkTx = transaction as VotingKeyLinkTransaction; return { linkedPublicKey: votingKeyLinkTx.linkedPublicKey, + startPoint: votingKeyLinkTx.startPoint.toString(), + endPoint: votingKeyLinkTx.endPoint.toString(), linkAction: votingKeyLinkTx.linkAction, }; default: diff --git a/src/model/transaction/VotingKeyLinkTransaction.ts b/src/model/transaction/VotingKeyLinkTransaction.ts index d1922d4df8..0303b62744 100644 --- a/src/model/transaction/VotingKeyLinkTransaction.ts +++ b/src/model/transaction/VotingKeyLinkTransaction.ts @@ -36,12 +36,15 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { FinalizationPointDto } from 'catbuffer-typescript/dist/FinalizationPointDto'; export class VotingKeyLinkTransaction extends Transaction { /** * Create a voting key link transaction object * @param deadline - The deadline to include the transaction. * @param linkedPublicKey - The public key for voting (48 bytes). + * @param startPoint - The start finalization point. + * @param endPoint - The end finalization point. * @param linkAction - The account link action. * @param maxFee - (Optional) Max fee defined by the sender * @param signature - (Optional) Transaction signature @@ -51,6 +54,8 @@ export class VotingKeyLinkTransaction extends Transaction { public static create( deadline: Deadline, linkedPublicKey: string, + startPoint: UInt64, + endPoint: UInt64, linkAction: LinkAction, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), @@ -63,6 +68,8 @@ export class VotingKeyLinkTransaction extends Transaction { deadline, maxFee, linkedPublicKey, + startPoint, + endPoint, linkAction, signature, signer, @@ -75,6 +82,8 @@ export class VotingKeyLinkTransaction extends Transaction { * @param deadline * @param maxFee * @param linkedPublicKey + * @param startPoint + * @param endPoint * @param linkAction * @param signature * @param signer @@ -89,6 +98,14 @@ export class VotingKeyLinkTransaction extends Transaction { * The public key of the remote account. */ public readonly linkedPublicKey: string, + /** + * The start finalization point. + */ + public readonly startPoint: UInt64, + /** + * The start finalization point. + */ + public readonly endPoint: UInt64, /** * The account link action. */ @@ -116,6 +133,8 @@ export class VotingKeyLinkTransaction extends Transaction { const transaction = VotingKeyLinkTransaction.create( isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as VotingKeyLinkTransactionBuilder).getDeadline().timestamp), Convert.uint8ToHex(builder.getLinkedPublicKey().votingKey), + new UInt64(builder.getStartPoint().finalizationPoint), + new UInt64(builder.getEndPoint().finalizationPoint), builder.getLinkAction().valueOf(), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as VotingKeyLinkTransactionBuilder).fee.amount), @@ -136,9 +155,11 @@ export class VotingKeyLinkTransaction extends Transaction { // set static byte size fields const bytePublicKey = 48; + const startPoint = 8; + const endPoint = 8; const byteLinkAction = 1; - return byteSize + bytePublicKey + byteLinkAction; + return byteSize + bytePublicKey + startPoint + endPoint + byteLinkAction; } /** @@ -158,6 +179,8 @@ export class VotingKeyLinkTransaction extends Transaction { new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); return transactionBuilder.serialize(); @@ -174,6 +197,8 @@ export class VotingKeyLinkTransaction extends Transaction { this.networkType.valueOf(), TransactionType.VOTING_KEY_LINK.valueOf(), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d9d2dbe3da..8304a30584 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -418,6 +418,8 @@ describe('TransactionMapping - createFromPayload', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -611,12 +613,21 @@ describe('TransactionMapping - createFromPayload', () => { it('should create an VotingKeyLinkTransaction object with link action', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as VotingKeyLinkTransaction; expect(transaction.linkAction).to.be.equal(1); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkedPublicKey).to.be.equal(key); }); @@ -906,11 +917,20 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create VotingKeyLinkTransaction', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const transaction = TransactionMapping.createFromDTO(votingKeyLinkTransaction.toJSON()) as VotingKeyLinkTransaction; expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkAction).to.be.equal(LinkAction.Link); }); it('should create AccountRestrictionAddressTransaction', () => { diff --git a/test/core/utils/TransactionMappingWithSignatures.spec.ts b/test/core/utils/TransactionMappingWithSignatures.spec.ts index d720ff08fd..a1bd933e13 100644 --- a/test/core/utils/TransactionMappingWithSignatures.spec.ts +++ b/test/core/utils/TransactionMappingWithSignatures.spec.ts @@ -499,6 +499,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -767,6 +769,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), key, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, undefined, @@ -779,6 +783,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign expect(transaction.linkAction).to.be.equal(1); expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f9b5e9416..8bb1a5ade8 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -403,6 +403,8 @@ describe('SerializeTransactionToJSON', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -410,6 +412,8 @@ describe('SerializeTransactionToJSON', () => { const json = votingKeyLinkTransaction.toJSON(); expect(json.transaction.linkedPublicKey).to.be.equal(votingKey); + expect(json.transaction.startPoint).to.be.equal('1'); + expect(json.transaction.endPoint.toString()).to.be.equal('3'); expect(json.transaction.linkAction).to.be.equal(LinkAction.Link); }); }); diff --git a/test/model/transaction/VotingKeyLinkTransaction.spec.ts b/test/model/transaction/VotingKeyLinkTransaction.spec.ts index 7cc9755aa9..04f77385f7 100644 --- a/test/model/transaction/VotingKeyLinkTransaction.spec.ts +++ b/test/model/transaction/VotingKeyLinkTransaction.spec.ts @@ -28,6 +28,8 @@ import { Address } from '../../../src/model/account/Address'; describe('VotingKeyLinkTransaction', () => { let account: Account; let votingKey: string; + const startPoint = UInt64.fromUint(1); + const endPoint = UInt64.fromUint(10); const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; @@ -38,18 +40,24 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(0); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should filled maxFee override transaction maxFee', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -57,23 +65,29 @@ describe('VotingKeyLinkTransaction', () => { expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(1); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should create an votingKeyLinkTransaction object with link action', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(1); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000001', ); }); @@ -81,17 +95,21 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(0); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D000', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000000', ); }); @@ -100,11 +118,13 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(Convert.hexToUint8(votingKeyLinkTransaction.serialize()).length).to.be.equal(votingKeyLinkTransaction.size); - expect(votingKeyLinkTransaction.size).to.be.equal(177); + expect(votingKeyLinkTransaction.size).to.be.equal(193); }); }); @@ -112,17 +132,26 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(354); + expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(386); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; }); it('Notify Account', () => { - const tx = VotingKeyLinkTransaction.create(Deadline.create(), account.publicKey, LinkAction.Unlink, NetworkType.MIJIN_TEST); + const tx = VotingKeyLinkTransaction.create( + Deadline.create(), + account.publicKey, + startPoint, + endPoint, + LinkAction.Unlink, + NetworkType.MIJIN_TEST, + ); let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; From ed584d8331453cf9dc8044eb8041dfb2f4eaafdd Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 23 Jun 2020 16:26:32 +0100 Subject: [PATCH 06/18] Update catbufer version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 48c86d38c8..a6134f32b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1307,9 +1307,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.21-alpha-202006221403", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006221403.tgz", - "integrity": "sha512-2iyyjv4r4RbHs6PasTLvcwPUERgNH9GEUxAlrxho+yj5gbb/ctPoNcbCNAKefFdEEimUoBK1uLyEIVu49vlQZg==" + "version": "0.0.21-alpha-202006231534", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006231534.tgz", + "integrity": "sha512-iwMwOi7N1gQQfRkpiZL+dVyzYV3U+IqMM9x3fvi0/0nbf3dMcnATo7K9ifbw8Or14uCmbUrw3zKhQ2EvYwkVlw==" }, "chai": { "version": "4.1.2", diff --git a/package.json b/package.json index 13da88b060..d65900441f 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.21-alpha-202006221403", + "catbuffer-typescript": "0.0.21-alpha-202006231534", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", From 3061194b973509789169ca52a13f22d959be29b4 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 23 Jun 2020 19:51:37 +0100 Subject: [PATCH 07/18] Updated openAPI version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index a6134f32b5..41b0950075 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6252,9 +6252,9 @@ } }, "symbol-openapi-typescript-node-client": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.9.2.tgz", - "integrity": "sha512-9J/V9C/HrbLzRUUbRPpDQrZkV1qyOYQU6OhD1xjnUCXdAo9VsuBFuUnGot0xnjafbAcqRvgqW83tCcMBhZtg6Q==", + "version": "0.9.3-SNAPSHOT.202006231946", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.9.3-SNAPSHOT.202006231946.tgz", + "integrity": "sha512-PwppbseK9nfQBqRhOS4UB8KEayIR3TmsL/CMwr21vYOii0hWGMH6jOdItVmpcDH5MlPrJqFbJhcucYJIWzV0FA==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index d65900441f..003ec732d0 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.9.2", + "symbol-openapi-typescript-node-client": "0.9.3-SNAPSHOT.202006231946", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" From d66f7b0cbadd264c16cd7be05a7995e75e51ca9d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 24 Jun 2020 12:00:07 +0100 Subject: [PATCH 08/18] Removed requires --- e2e/infrastructure/IntegrationTestHelper.ts | 12 ++++++------ e2e/infrastructure/TransactionHttp.spec.ts | 13 ++++--------- package-lock.json | 9 +++++++++ package.json | 1 + src/core/crypto/Crypto.ts | 7 ++----- src/core/crypto/Utilities.ts | 14 ++++++-------- src/core/format/RawAddress.ts | 4 ++-- src/core/utils/LockHashUtils.ts | 13 ++++++------- src/infrastructure/TransactionHttp.ts | 2 +- test/core/crypto/hkdf.spec.ts | 6 ++---- test/core/utils/Hashes.spec.ts | 7 ++----- test/infrastructure/TransactionHttp.spec.ts | 2 +- test/infrastructure/TransactionStatusHttp.spec.ts | 2 +- .../transaction/HashTypeLengthValidator.spec.ts | 4 +--- .../transaction/SecretLockTransaction.spec.ts | 4 +--- .../transaction/SecretProofTransaction.spec.ts | 4 +--- 16 files changed, 46 insertions(+), 58 deletions(-) diff --git a/e2e/infrastructure/IntegrationTestHelper.ts b/e2e/infrastructure/IntegrationTestHelper.ts index f13403bcfb..244749ceae 100644 --- a/e2e/infrastructure/IntegrationTestHelper.ts +++ b/e2e/infrastructure/IntegrationTestHelper.ts @@ -27,9 +27,11 @@ import { TransactionService } from '../../src/service/TransactionService'; import { NetworkCurrencyPublic } from '../../src/model/mosaic/NetworkCurrencyPublic'; import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; +import * as yaml from 'js-yaml'; +import * as path from 'path'; +import * as fs from 'fs'; export class IntegrationTestHelper { - public readonly yaml = require('js-yaml'); public apiUrl: string; public repositoryFactory: RepositoryFactory; public account: Account; @@ -51,9 +53,7 @@ export class IntegrationTestHelper { start(): Promise { return new Promise((resolve, reject) => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, jsonData) => { + fs.readFile(path.resolve(__dirname, '../conf/network.conf'), (err, jsonData: any) => { if (err) { return reject(err); } @@ -94,7 +94,7 @@ export class IntegrationTestHelper { const bootstrapRoot = process.env.CATAPULT_SERVICE_BOOTSTRAP || path.resolve(__dirname, '../../../../catapult-service-bootstrap'); const bootstrapPath = `${bootstrapRoot}/build/generated-addresses/addresses.yaml`; - require('fs').readFile(bootstrapPath, (error: any, yamlData: any) => { + fs.readFile(bootstrapPath, (error: any, yamlData: any) => { if (error) { console.log( `catapult-service-bootstrap generated address could not be loaded from path ${bootstrapPath}. Ignoring and using accounts from network.conf.`, @@ -102,7 +102,7 @@ export class IntegrationTestHelper { return resolve(this); } else { console.log(`catapult-service-bootstrap generated address loaded from path ${bootstrapPath}.`); - const parsedYaml = this.yaml.safeLoad(yamlData); + const parsedYaml = yaml.safeLoad(yamlData); this.account = this.createAccount(parsedYaml.nemesis_addresses[0]); this.account2 = this.createAccount(parsedYaml.nemesis_addresses[1]); this.account3 = this.createAccount(parsedYaml.nemesis_addresses[2]); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index a67a1032cc..cca164832e 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -76,9 +76,10 @@ import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestric import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag'; import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; import { TransactionStatusRepository } from '../../src/infrastructure/TransactionStatusRepository'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as ripemd160 from 'ripemd160'; +import { sha256 } from 'js-sha256'; +import * as secureRandom from 'secure-random'; +import * as CryptoJS from 'crypto-js'; describe('TransactionHttp', () => { let transactionHash: string; @@ -101,12 +102,6 @@ describe('TransactionHttp', () => { let transactionRepository: TransactionRepository; let transactionStatusRepository: TransactionStatusRepository; let votingKey: string; - // eslint-disable-next-line @typescript-eslint/no-var-requires - const secureRandom = require('secure-random'); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const sha256 = require('js-sha256'); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const ripemd160 = require('ripemd160'); const remoteAccount = Account.generateNewAccount(helper.networkType); diff --git a/package-lock.json b/package-lock.json index 41b0950075..12dc468051 100644 --- a/package-lock.json +++ b/package-lock.json @@ -416,6 +416,15 @@ "@types/request": "*" } }, + "@types/ripemd160": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/ripemd160/-/ripemd160-2.0.0.tgz", + "integrity": "sha512-LD6AO/+8cAa1ghXax9NG9iPDLPUEGB2WWPjd//04KYfXxTwHvlDEfL0NRjrM5z9XWBi6WbKw75Are0rDyn3PSA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/tough-cookie": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.2.tgz", diff --git a/package.json b/package.json index 003ec732d0..20dbd29b7f 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "@types/lodash": "^4.14.85", "@types/long": "^4.0.0", "@types/mocha": "^2.2.44", + "@types/ripemd160": "^2.0.0", "@types/request": "^2.47.0", "@types/request-promise-native": "^1.0.14", "@types/utf8": "^2.1.6", diff --git a/src/core/crypto/Crypto.ts b/src/core/crypto/Crypto.ts index 4db28ca259..3e057f061e 100644 --- a/src/core/crypto/Crypto.ts +++ b/src/core/crypto/Crypto.ts @@ -17,9 +17,8 @@ import { Convert as convert } from '../format/Convert'; import { KeyPair } from './KeyPair'; import * as utility from './Utilities'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as crypto from 'crypto'; +import * as CryptoJS from 'crypto-js'; export class Crypto { /** @@ -183,8 +182,6 @@ export class Crypto { * @return {Uint8Array} */ public static randomBytes = (length: number): any => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const crypto = require('crypto'); return crypto.randomBytes(length); }; } diff --git a/src/core/crypto/Utilities.ts b/src/core/crypto/Utilities.ts index 2064259d14..d9a6898cd0 100644 --- a/src/core/crypto/Utilities.ts +++ b/src/core/crypto/Utilities.ts @@ -16,18 +16,16 @@ import { RawArray as array } from '../format'; import * as nacl from './nacl_catapult'; -// eslint-disable-next-line @typescript-eslint/no-var-requires -export const CryptoJS = require('crypto-js'); +import * as CryptoJS from 'crypto-js'; +import * as hkdf from 'futoin-hkdf'; +import { sha512 } from 'js-sha512'; +import { WordArray } from 'crypto-js'; + export const Key_Size = 32; export const Signature_Size = 64; export const Half_Signature_Size = Signature_Size / 2; export const Hash_Size = 64; export const Half_Hash_Size = Hash_Size / 2; -// eslint-disable-next-line @typescript-eslint/no-var-requires -export const hkdf = require('futoin-hkdf'); -import { sha512 } from 'js-sha512'; -import { WordArray } from 'crypto-js'; - /** * Convert an Uint8Array to WordArray * @@ -88,7 +86,7 @@ export const catapult_crypto = ((): any => { const sharedSecret = catapult_crypto.deriveSharedSecret(privateKey, publicKey); const info = 'catapult'; const hash = 'SHA-256'; - return hkdf(sharedSecret, 32, { salt: new Uint8Array(32), info, hash }); + return hkdf(sharedSecret, 32, { salt: Buffer.from(new Uint8Array(32)), info, hash }); }, deriveSharedSecret: (privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array => { diff --git a/src/core/format/RawAddress.ts b/src/core/format/RawAddress.ts index 65b2586634..81b5cb79f0 100644 --- a/src/core/format/RawAddress.ts +++ b/src/core/format/RawAddress.ts @@ -15,7 +15,7 @@ */ import { sha3_256 } from 'js-sha3'; -import RIPEMD160 = require('ripemd160'); +import * as ripemd160 from 'ripemd160'; import { NetworkType } from '../../model/network/NetworkType'; import { Base32 } from './Base32'; import { Convert } from './Convert'; @@ -83,7 +83,7 @@ export class RawAddress { const publicKeyHash = sha3_256.arrayBuffer(publicKey); // step 2: ripemd160 hash of (1) - const ripemdHash = new RIPEMD160().update(new Buffer(publicKeyHash)).digest(); + const ripemdHash = new ripemd160().update(new Buffer(publicKeyHash)).digest(); // step 3: add network identifier byte in front of (2) const decodedAddress = new Uint8Array(RawAddress.constants.sizes.addressDecoded); diff --git a/src/core/utils/LockHashUtils.ts b/src/core/utils/LockHashUtils.ts index a107c8af47..b424f3c8bd 100644 --- a/src/core/utils/LockHashUtils.ts +++ b/src/core/utils/LockHashUtils.ts @@ -16,13 +16,12 @@ import { sha3_256 } from 'js-sha3'; import { LockHashAlgorithm } from '../../model/transaction/LockHashAlgorithm'; - +import * as ripemd160 from 'ripemd160'; +import { sha256 } from 'js-sha256'; /** * Hash utilities for SecretLock hashing */ export class LockHashUtils { - private static sha256 = require('js-sha256'); - private static ripemd160 = require('ripemd160'); /** * Perform SHA3_256 hash * @param input buffer to be hashed @@ -38,8 +37,8 @@ export class LockHashUtils { * @returns {string} Hash in hexidecimal format */ public static Op_Hash_256(input: Uint8Array): string { - const hash = LockHashUtils.sha256(input, 'hex'); - return LockHashUtils.sha256(Buffer.from(hash, 'hex')).toUpperCase(); + const hash = sha256(input); + return sha256(Buffer.from(hash, 'hex')).toUpperCase(); } /** @@ -48,8 +47,8 @@ export class LockHashUtils { * @returns {string} Hash in hexidecimal format */ public static Op_Hash_160(input: Uint8Array): string { - const sha256Hash = LockHashUtils.sha256(input); - return new LockHashUtils.ripemd160().update(Buffer.from(sha256Hash, 'hex')).digest('hex').toUpperCase(); + const sha256Hash = sha256(input); + return new ripemd160().update(Buffer.from(sha256Hash, 'hex')).digest('hex').toUpperCase(); } /** diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index fe294e9285..a2f8bb1f14 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -37,7 +37,7 @@ import { TransactionRepository } from './TransactionRepository'; import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; import { Page } from './Page'; import { TransactionGroup } from './TransactionGroup'; -import http = require('http'); +import * as http from 'http'; import { DtoMapping } from '../core/utils/DtoMapping'; /** diff --git a/test/core/crypto/hkdf.spec.ts b/test/core/crypto/hkdf.spec.ts index 9bac5305cc..41e55f99ee 100644 --- a/test/core/crypto/hkdf.spec.ts +++ b/test/core/crypto/hkdf.spec.ts @@ -15,9 +15,7 @@ */ import { expect } from 'chai'; import { Convert } from '../../../src/core/format'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const hkdf = require('futoin-hkdf'); +import * as hkdf from 'futoin-hkdf'; describe('hkdf', () => { describe('Example tests', () => { @@ -25,7 +23,7 @@ describe('hkdf', () => { const sharedSecret = 'string-or-buffer'; const hash = 'SHA-256'; const info = 'catapult'; - const sharedKey = hkdf(sharedSecret, 32, { salt: new Uint8Array(32), info, hash }); + const sharedKey = hkdf(sharedSecret, 32, { salt: Buffer.from(new Uint8Array(32)), info, hash }); expect(Convert.uint8ToHex(sharedKey)).equal('E618ACB2558E1721492E4AE3BED3F4D86F26C2B0CE6AD939943A6A540855D23F'); }); }); diff --git a/test/core/utils/Hashes.spec.ts b/test/core/utils/Hashes.spec.ts index 82ae339190..38e9976f7f 100644 --- a/test/core/utils/Hashes.spec.ts +++ b/test/core/utils/Hashes.spec.ts @@ -19,13 +19,10 @@ import { sha3_256 } from 'js-sha3'; import { LockHashUtils } from '../../../src/core/utils/LockHashUtils'; import { LockHashAlgorithm } from '../../../src/model/transaction/LockHashAlgorithm'; import { Convert } from '../../../src/core/format/Convert'; +import * as ripemd160 from 'ripemd160'; +import { sha256 } from 'js-sha256'; describe('Hashes', () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const ripemd160 = require('ripemd160'); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const sha256 = require('js-sha256'); - it('Op_Sha3_256', () => { const secretSeed = Crypto.randomBytes(20); const expected = sha3_256.create().update(secretSeed).hex(); diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 4cb6dd1746..51d2a180a6 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -15,7 +15,7 @@ */ import { expect } from 'chai'; -import http = require('http'); +import * as http from 'http'; import { BlockRoutesApi, TransactionRoutesApi, diff --git a/test/infrastructure/TransactionStatusHttp.spec.ts b/test/infrastructure/TransactionStatusHttp.spec.ts index 801aadb715..00d6603b53 100644 --- a/test/infrastructure/TransactionStatusHttp.spec.ts +++ b/test/infrastructure/TransactionStatusHttp.spec.ts @@ -15,7 +15,7 @@ */ import { expect } from 'chai'; -import http = require('http'); +import * as http from 'http'; import { TransactionGroupEnum, TransactionStatusDTO, diff --git a/test/model/transaction/HashTypeLengthValidator.spec.ts b/test/model/transaction/HashTypeLengthValidator.spec.ts index d56a2f6b8d..e05ec414f2 100644 --- a/test/model/transaction/HashTypeLengthValidator.spec.ts +++ b/test/model/transaction/HashTypeLengthValidator.spec.ts @@ -16,9 +16,7 @@ import { expect } from 'chai'; import { sha3_256, sha3_512 } from 'js-sha3'; import { LockHashAlgorithm, LockHashAlgorithmLengthValidator } from '../../../src/model/transaction/LockHashAlgorithm'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as CryptoJS from 'crypto-js'; describe('LockHashAlgorithmLengthValidator', () => { it('LockHashAlgorithm.SHA3_256 should be exactly 64 chars length', () => { diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 56c7ce6e52..b761fd50d9 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -35,9 +35,7 @@ import { SecretLockTransaction } from '../../../src/model/transaction/SecretLock import { TransactionInfo } from '../../../src/model/transaction/TransactionInfo'; import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as CryptoJS from 'crypto-js'; describe('SecretLockTransaction', () => { let account: Account; diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 7ad17698d2..26f45c2eec 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -33,9 +33,7 @@ import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; import { EmbeddedTransactionBuilder } from 'catbuffer-typescript/dist/EmbeddedTransactionBuilder'; import { TransactionType } from '../../../src/model/transaction/TransactionType'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as CryptoJS from 'crypto-js'; describe('SecretProofTransaction', () => { let account: Account; From 3640ee6829daa591b185061c1514982469a1bf42 Mon Sep 17 00:00:00 2001 From: fboucquez Date: Wed, 24 Jun 2020 15:23:04 -0300 Subject: [PATCH 09/18] typescript-fetch rest client migration --- e2e/infrastructure/AccountHttp.spec.ts | 5 +- e2e/infrastructure/TransactionHttp.spec.ts | 30 +- package-lock.json | 397 +++--------------- package.json | 3 +- src/infrastructure/AccountHttp.ts | 20 +- src/infrastructure/BlockHttp.ts | 18 +- src/infrastructure/ChainHttp.ts | 12 +- src/infrastructure/Http.ts | 99 +++-- src/infrastructure/IListener.ts | 2 +- src/infrastructure/Listener.ts | 8 +- src/infrastructure/MetadataHttp.ts | 12 +- src/infrastructure/MosaicHttp.ts | 30 +- src/infrastructure/MultisigHttp.ts | 12 +- src/infrastructure/NamespaceHttp.ts | 15 +- src/infrastructure/NetworkHttp.ts | 16 +- src/infrastructure/NodeHttp.ts | 12 +- src/infrastructure/ReceiptHttp.ts | 38 +- src/infrastructure/RepositoryCallError.ts | 35 ++ src/infrastructure/RepositoryFactoryConfig.ts | 7 + src/infrastructure/RepositoryFactoryHttp.ts | 34 +- src/infrastructure/RestrictionAccountHttp.ts | 33 +- src/infrastructure/RestrictionMosaicHttp.ts | 82 ++-- src/infrastructure/TransactionHttp.ts | 112 ++--- src/infrastructure/TransactionRepository.ts | 2 +- src/infrastructure/TransactionStatusHttp.ts | 24 +- src/infrastructure/infrastructure.ts | 1 + .../BlockPaginationStreamer.ts | 4 +- .../MosaicPaginationStreamer.ts | 4 +- .../paginationStreamer/PaginationStreamer.ts | 6 +- .../paginationStreamer/Searcher.ts | 2 +- .../TransactionPaginationStreamer.ts | 2 +- .../receipt/CreateReceiptFromDTO.ts | 4 +- .../searchCriteria/BlockSearchCriteria.ts | 2 +- .../searchCriteria/MosaicSearchCriteria.ts | 2 +- .../TransactionSearchCriteria.ts | 4 +- .../transaction/CreateTransactionFromDTO.ts | 6 +- .../CreateTransactionFromPayload.ts | 6 +- .../transaction/SerializeTransactionToJSON.ts | 4 +- src/model/network/NetworkProperties.ts | 2 +- src/model/node/NodeHealth.ts | 2 +- src/model/transaction/TransactionStatus.ts | 2 +- test/core/utils/DtoMapping.spec.ts | 14 +- test/core/utils/EnumMapping.spec.ts | 2 +- test/infrastructure/AccountHttp.spec.ts | 20 +- test/infrastructure/BlockHttp.spec.ts | 44 +- test/infrastructure/ChainHttp.spec.ts | 10 +- test/infrastructure/Listener.spec.ts | 12 +- test/infrastructure/MetadataHttp.spec.ts | 125 ++---- test/infrastructure/MosaicHttp.spec.ts | 39 +- test/infrastructure/MultisigHttp.spec.ts | 21 +- test/infrastructure/NamespaceHttp.spec.ts | 89 ++-- test/infrastructure/NetworkHttp.spec.ts | 267 ++++++------ test/infrastructure/NodeHttp.spec.ts | 66 ++- test/infrastructure/Page.spec.ts | 6 +- test/infrastructure/QueryParams.spec.ts | 2 +- test/infrastructure/ReceiptHttp.spec.ts | 32 +- test/infrastructure/RepositoryFactory.spec.ts | 12 +- .../RestrictionAccountHttp.spec.ts | 26 +- .../RestrictionMosaicHttp.spec.ts | 38 +- test/infrastructure/SearchCriteria.spec.ts | 2 +- .../SerializeTransactionToJSON.spec.ts | 16 +- test/infrastructure/TransactionHttp.spec.ts | 135 +++--- .../TransactionSearchCriteria.spec.ts | 10 +- .../TransactionStatusHttp.spec.ts | 17 +- .../streamer/BlockPaginationStreamer.spec.ts | 2 +- .../streamer/MosaicPaginationStreamer.spec.ts | 2 +- .../streamer/PaginationStreamerTestHelper.ts | 14 +- .../TransactionPaginationStreamer.spec.ts | 2 +- test/model/mosaic/MosaicView.spec.ts | 1 - .../transaction/TransactionStatus.spec.ts | 4 +- .../AggregateTransactionService.spec.ts | 8 +- 71 files changed, 907 insertions(+), 1242 deletions(-) create mode 100644 src/infrastructure/RepositoryCallError.ts diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 9462daa1fc..4cdb323659 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -18,6 +18,7 @@ import { expect } from 'chai'; import { AccountRepository } from '../../src/infrastructure/AccountRepository'; import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; +import { RepositoryCallError } from '../../src/infrastructure/RepositoryCallError'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { PlainMessage } from '../../src/model/message/PlainMessage'; @@ -187,9 +188,9 @@ describe('AccountHttp', () => { return Promise.reject('should fail!'); }, (err) => { - const error = JSON.parse(err.message); + const error: RepositoryCallError = JSON.parse(err.message); expect(error.statusCode).to.be.eq(404); - expect(error.errorDetails.statusMessage).to.be.eq('Not Found'); + expect(error.statusMessage).to.be.eq('Not Found'); return Promise.resolve(); }, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 3741f28a9a..9ca2f39dff 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -1495,11 +1495,37 @@ describe('TransactionHttp', () => { .toPromise(); expect(transactions.data.length).to.be.greaterThan(0); }); - it('should return transaction info given height', async () => { + it('should return transaction info given height all types', async () => { const transactions = await transactionRepository .search({ group: TransactionGroup.Confirmed, height: UInt64.fromUint(1) } as TransactionSearchCriteria) .toPromise(); - expect(transactions.data.length).to.be.greaterThan(0); + + const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; + const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; + const others = transactions.data.filter( + (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, + ).length; + expect(mosaicDefinitions).to.be.greaterThan(0); + expect(namespaceRegistration).to.be.greaterThan(0); + expect(others).to.be.greaterThan(0); + }); + + it('should return transaction info given height and namesapce, mosaic types', async () => { + const transactions = await transactionRepository + .search({ + group: TransactionGroup.Confirmed, + height: UInt64.fromUint(1), + type: [TransactionType.MOSAIC_DEFINITION, TransactionType.NAMESPACE_REGISTRATION], + } as TransactionSearchCriteria) + .toPromise(); + const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; + const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; + const others = transactions.data.filter( + (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, + ).length; + expect(mosaicDefinitions).to.be.greaterThan(0); + expect(namespaceRegistration).to.be.greaterThan(0); + expect(others).to.eq(0); }); }); diff --git a/package-lock.json b/package-lock.json index 48c86d38c8..97348385df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -331,15 +331,11 @@ "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==", "dev": true }, - "@types/bluebird": { - "version": "3.5.32", - "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.32.tgz", - "integrity": "sha512-dIOxFfI0C+jz89g6lQ+TqhGgPQ0MxSnh/E4xuC0blhFtyW269+mPG5QeLgbdwst/LvdP8o1y0o/Gz5EHXLec/g==" - }, "@types/caseless": { "version": "0.12.1", "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.1.tgz", - "integrity": "sha512-FhlMa34NHp9K5MY1Uz8yb+ZvuX0pnvn3jScRSNAb75KHGB8d3rEU6hqMs3Z2vjuytcMfRg6c5CHMc3wtYyD2/A==" + "integrity": "sha512-FhlMa34NHp9K5MY1Uz8yb+ZvuX0pnvn3jScRSNAb75KHGB8d3rEU6hqMs3Z2vjuytcMfRg6c5CHMc3wtYyD2/A==", + "dev": true }, "@types/chai": { "version": "4.1.2", @@ -363,6 +359,7 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.2.1.tgz", "integrity": "sha512-JAMFhOaHIciYVh8fb5/83nmuO/AHwmto+Hq7a9y8FzLDcC1KCU344XDOMEmahnrTFlHjgh4L0WJFczNIX2GxnQ==", + "dev": true, "requires": { "@types/node": "*" } @@ -394,12 +391,14 @@ "@types/node": { "version": "9.6.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-9.6.0.tgz", - "integrity": "sha512-h3YZbOq2+ZoDFI1z8Zx0Ck/xRWkOESVaLdgLdd/c25mMQ1Y2CAkILu9ny5A15S5f32gGcQdaUIZ2jzYr8D7IFg==" + "integrity": "sha512-h3YZbOq2+ZoDFI1z8Zx0Ck/xRWkOESVaLdgLdd/c25mMQ1Y2CAkILu9ny5A15S5f32gGcQdaUIZ2jzYr8D7IFg==", + "dev": true }, "@types/request": { "version": "2.47.0", "resolved": "https://registry.npmjs.org/@types/request/-/request-2.47.0.tgz", "integrity": "sha512-/KXM5oev+nNCLIgBjkwbk8VqxmzI56woD4VUxn95O+YeQ8hJzcSmIZ1IN3WexiqBb6srzDo2bdMbsXxgXNkz5Q==", + "dev": true, "requires": { "@types/caseless": "*", "@types/form-data": "*", @@ -419,7 +418,8 @@ "@types/tough-cookie": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.2.tgz", - "integrity": "sha512-vOVmaruQG5EatOU/jM6yU2uCp3Lz6mK1P5Ztu4iJjfM4SVHU9XYktPUQtKlIXuahqXHdEyUarMrBEwg5Cwu+bA==" + "integrity": "sha512-vOVmaruQG5EatOU/jM6yU2uCp3Lz6mK1P5Ztu4iJjfM4SVHU9XYktPUQtKlIXuahqXHdEyUarMrBEwg5Cwu+bA==", + "dev": true }, "@types/utf8": { "version": "2.1.6", @@ -617,7 +617,8 @@ "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true }, "ansi-styles": { "version": "3.2.1", @@ -884,216 +885,6 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, - "babel-code-frame": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", - "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", - "requires": { - "chalk": "^1.1.3", - "esutils": "^2.0.2", - "js-tokens": "^3.0.2" - }, - "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" - }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - } - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" - } - } - }, - "babel-core": { - "version": "6.26.3", - "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.3.tgz", - "integrity": "sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA==", - "requires": { - "babel-code-frame": "^6.26.0", - "babel-generator": "^6.26.0", - "babel-helpers": "^6.24.1", - "babel-messages": "^6.23.0", - "babel-register": "^6.26.0", - "babel-runtime": "^6.26.0", - "babel-template": "^6.26.0", - "babel-traverse": "^6.26.0", - "babel-types": "^6.26.0", - "babylon": "^6.18.0", - "convert-source-map": "^1.5.1", - "debug": "^2.6.9", - "json5": "^0.5.1", - "lodash": "^4.17.4", - "minimatch": "^3.0.4", - "path-is-absolute": "^1.0.1", - "private": "^0.1.8", - "slash": "^1.0.0", - "source-map": "^0.5.7" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - } - } - }, - "babel-generator": { - "version": "6.26.1", - "resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.1.tgz", - "integrity": "sha512-HyfwY6ApZj7BYTcJURpM5tznulaBvyio7/0d4zFOeMPUmfxkCjHocCuoLa2SAGzBI8AREcH3eP3758F672DppA==", - "requires": { - "babel-messages": "^6.23.0", - "babel-runtime": "^6.26.0", - "babel-types": "^6.26.0", - "detect-indent": "^4.0.0", - "jsesc": "^1.3.0", - "lodash": "^4.17.4", - "source-map": "^0.5.7", - "trim-right": "^1.0.1" - }, - "dependencies": { - "jsesc": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", - "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=" - } - } - }, - "babel-helpers": { - "version": "6.24.1", - "resolved": "https://registry.npmjs.org/babel-helpers/-/babel-helpers-6.24.1.tgz", - "integrity": "sha1-NHHenK7DiOXIUOWX5Yom3fN2ArI=", - "requires": { - "babel-runtime": "^6.22.0", - "babel-template": "^6.24.1" - } - }, - "babel-messages": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-6.23.0.tgz", - "integrity": "sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=", - "requires": { - "babel-runtime": "^6.22.0" - } - }, - "babel-plugin-transform-es2015-block-scoping": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz", - "integrity": "sha1-1w9SmcEwjQXBL0Y4E7CgnnOxiV8=", - "requires": { - "babel-runtime": "^6.26.0", - "babel-template": "^6.26.0", - "babel-traverse": "^6.26.0", - "babel-types": "^6.26.0", - "lodash": "^4.17.4" - } - }, - "babel-register": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-register/-/babel-register-6.26.0.tgz", - "integrity": "sha1-btAhFz4vy0htestFxgCahW9kcHE=", - "requires": { - "babel-core": "^6.26.0", - "babel-runtime": "^6.26.0", - "core-js": "^2.5.0", - "home-or-tmp": "^2.0.0", - "lodash": "^4.17.4", - "mkdirp": "^0.5.1", - "source-map-support": "^0.4.15" - } - }, - "babel-runtime": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", - "requires": { - "core-js": "^2.4.0", - "regenerator-runtime": "^0.11.0" - } - }, - "babel-template": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-template/-/babel-template-6.26.0.tgz", - "integrity": "sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=", - "requires": { - "babel-runtime": "^6.26.0", - "babel-traverse": "^6.26.0", - "babel-types": "^6.26.0", - "babylon": "^6.18.0", - "lodash": "^4.17.4" - } - }, - "babel-traverse": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.26.0.tgz", - "integrity": "sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=", - "requires": { - "babel-code-frame": "^6.26.0", - "babel-messages": "^6.23.0", - "babel-runtime": "^6.26.0", - "babel-types": "^6.26.0", - "babylon": "^6.18.0", - "debug": "^2.6.8", - "globals": "^9.18.0", - "invariant": "^2.2.2", - "lodash": "^4.17.4" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "globals": { - "version": "9.18.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", - "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==" - } - } - }, - "babel-types": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-types/-/babel-types-6.26.0.tgz", - "integrity": "sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=", - "requires": { - "babel-runtime": "^6.26.0", - "esutils": "^2.0.2", - "lodash": "^4.17.4", - "to-fast-properties": "^1.0.3" - }, - "dependencies": { - "to-fast-properties": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", - "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=" - } - } - }, - "babylon": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", - "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==" - }, "bach": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/bach/-/bach-1.2.0.tgz", @@ -1114,7 +905,8 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true }, "base": { "version": "0.11.2", @@ -1203,6 +995,7 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1531,7 +1324,8 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true }, "concat-stream": { "version": "1.6.2", @@ -1549,6 +1343,7 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", "integrity": "sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==", + "dev": true, "requires": { "safe-buffer": "~5.1.1" } @@ -1569,11 +1364,6 @@ "is-plain-object": "^2.0.1" } }, - "core-js": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", - "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" - }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -1781,14 +1571,6 @@ "integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=", "dev": true }, - "detect-indent": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz", - "integrity": "sha1-920GQ1LN9Docts5hnE7jqUdd4gg=", - "requires": { - "repeating": "^2.0.0" - } - }, "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -1917,7 +1699,8 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true }, "eslint": { "version": "6.8.0", @@ -2142,7 +1925,8 @@ "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=" + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", + "dev": true }, "expand-brackets": { "version": "2.1.4", @@ -3382,14 +3166,6 @@ "har-schema": "^2.0.0" } }, - "has-ansi": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", - "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", - "requires": { - "ansi-regex": "^2.0.0" - } - }, "has-flag": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", @@ -3459,15 +3235,6 @@ "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, - "home-or-tmp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz", - "integrity": "sha1-42w/LSyufXRqhX440Y1fMqeILbg=", - "requires": { - "os-homedir": "^1.0.0", - "os-tmpdir": "^1.0.1" - } - }, "homedir-polyfill": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", @@ -3676,14 +3443,6 @@ "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==", "dev": true }, - "invariant": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", - "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", - "requires": { - "loose-envify": "^1.0.0" - } - }, "invert-kv": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", @@ -3792,11 +3551,6 @@ "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", "dev": true }, - "is-finite": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.1.0.tgz", - "integrity": "sha512-cdyMtqX/BOqqNBBiKlIVkytNHm49MtMlYyn1zxzvJKWmFMlGzm+ry5BBfYyeY9YmNKbRSo/o7OX9w9ale0wg3w==" - }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -4056,11 +3810,6 @@ "resolved": "https://registry.npmjs.org/js-sha512/-/js-sha512-0.8.0.tgz", "integrity": "sha512-PWsmefG6Jkodqt+ePTvBZCSMFgN7Clckjd0O7su3I0+BW2QWUTJNzjktHsztGLhncP2h8mcF9V9Y2Ha59pAViQ==" }, - "js-tokens": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", - "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" - }, "js-yaml": { "version": "3.13.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", @@ -4104,11 +3853,6 @@ "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" }, - "json5": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", - "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=" - }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -4245,14 +3989,6 @@ "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" }, - "loose-envify": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", - "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "requires": { - "js-tokens": "^3.0.0 || ^4.0.0" - } - }, "lru-cache": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", @@ -4418,6 +4154,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4452,6 +4189,7 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, "requires": { "minimist": "0.0.8" }, @@ -4459,7 +4197,8 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true } } }, @@ -4516,7 +4255,8 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true }, "mute-stdout": { "version": "1.0.1", @@ -4567,6 +4307,11 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + }, "node-preload": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", @@ -4792,7 +4537,7 @@ }, "which-module": { "version": "2.0.0", - "resolved": "", + "resolved": false, "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, @@ -4989,11 +4734,6 @@ "readable-stream": "^2.0.1" } }, - "os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" - }, "os-locale": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", @@ -5012,7 +4752,8 @@ "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true }, "p-limit": { "version": "2.2.2", @@ -5124,7 +4865,8 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true }, "path-key": { "version": "3.1.1", @@ -5316,11 +5058,6 @@ "integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=", "dev": true }, - "private": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", - "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==" - }, "process-nextick-args": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", @@ -5440,11 +5177,6 @@ "resolve": "^1.1.6" } }, - "regenerator-runtime": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" - }, "regex-not": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz", @@ -5509,14 +5241,6 @@ "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", "dev": true }, - "repeating": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/repeating/-/repeating-2.0.1.tgz", - "integrity": "sha1-UhTFOpJtNVJwdSf7q0FdvAjQbdo=", - "requires": { - "is-finite": "^1.0.0" - } - }, "replace-ext": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.0.tgz", @@ -5676,15 +5400,6 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", "dev": true }, - "rewire": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rewire/-/rewire-3.0.2.tgz", - "integrity": "sha512-ejkkt3qYnsQ38ifc9llAAzuHiGM7kR8N5/mL3aHWgmWwet0OMFcmJB8aTsMV2PBHCWxNVTLCeRfBpEa8X2+1fw==", - "requires": { - "babel-core": "^6.26.0", - "babel-plugin-transform-es2015-block-scoping": "^6.26.0" - } - }, "rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", @@ -5854,11 +5569,6 @@ "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, - "slash": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz", - "integrity": "sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU=" - }, "slice-ansi": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", @@ -5997,7 +5707,8 @@ "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=" + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true }, "source-map-resolve": { "version": "0.5.2", @@ -6012,14 +5723,6 @@ "urix": "^0.1.0" } }, - "source-map-support": { - "version": "0.4.18", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", - "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", - "requires": { - "source-map": "^0.5.6" - } - }, "source-map-url": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz", @@ -6205,6 +5908,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, "requires": { "ansi-regex": "^2.0.0" } @@ -6251,16 +5955,14 @@ "es6-symbol": "^3.1.1" } }, - "symbol-openapi-typescript-node-client": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.9.2.tgz", - "integrity": "sha512-9J/V9C/HrbLzRUUbRPpDQrZkV1qyOYQU6OhD1xjnUCXdAo9VsuBFuUnGot0xnjafbAcqRvgqW83tCcMBhZtg6Q==", - "requires": { - "@types/bluebird": "*", - "@types/request": "*", - "bluebird": "^3.5.0", - "request": "^2.81.0", - "rewire": "^3.0.2" + "symbol-openapi-typescript-fetch-client": { + "version": "0.9.3-SNAPSHOT.202006231707", + "dependencies": { + "typescript": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", + "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==" + } } }, "table": { @@ -6469,11 +6171,6 @@ "resolved": "https://registry.npmjs.org/treeify/-/treeify-1.1.0.tgz", "integrity": "sha512-1m4RA7xVAJrSGrrXGs0L3YTwyvBs2S8PbRHaLZAkFw7JR8oIFwYtysxlBZhYIa7xSyiYJKZ3iGrrk55cGA3i9A==" }, - "trim-right": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", - "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=" - }, "ts-mockito": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/ts-mockito/-/ts-mockito-2.5.0.tgz", diff --git a/package.json b/package.json index 13da88b060..adb13c1414 100644 --- a/package.json +++ b/package.json @@ -92,12 +92,13 @@ "long": "^4.0.0", "merkletreejs": "^0.1.7", "minimist": "^1.2.5", + "node-fetch": "^2.6.0", "request": "^2.88.0", "request-promise-native": "^1.0.5", "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.9.2", + "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006231707", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 3d1bff11d1..21f56fe662 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -15,8 +15,9 @@ */ import { Observable } from 'rxjs'; -import { AccountIds, AccountInfoDTO, AccountRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { AccountInfoDTO, AccountRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { AccountInfo } from '../model/account/AccountInfo'; +import { AccountKey } from '../model/account/AccountKey'; import { ActivityBucket } from '../model/account/ActivityBucket'; import { Address } from '../model/account/Address'; import { Mosaic } from '../model/mosaic/Mosaic'; @@ -24,7 +25,7 @@ import { MosaicId } from '../model/mosaic/MosaicId'; import { UInt64 } from '../model/UInt64'; import { AccountRepository } from './AccountRepository'; import { Http } from './Http'; -import { AccountKey } from '../model/account/AccountKey'; + /** * Account http repository. * @@ -39,12 +40,12 @@ export class AccountHttp extends Http implements AccountRepository { /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.accountRoutesApi = new AccountRoutesApi(url); - this.accountRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.accountRoutesApi = new AccountRoutesApi(this.config()); } /** @@ -62,8 +63,9 @@ export class AccountHttp extends Http implements AccountRepository { * @returns Observable */ public getAccountsInfo(addresses: Address[]): Observable { - const accountIds = new AccountIds(); - accountIds.addresses = addresses.map((address) => address.plain()); + const accountIds = { + addresses: addresses.map((address) => address.plain()), + }; return this.call(this.accountRoutesApi.getAccountsInfo(accountIds), (body) => body.map(this.toAccountInfo)); } diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index 27c0b60cdb..45e67b339c 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -15,7 +15,9 @@ */ import { Observable } from 'rxjs'; -import { BlockInfoDTO, BlockRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { BlockInfoDTO, BlockRoutesApi } from 'symbol-openapi-typescript-fetch-client'; +import { DtoMapping } from '../core/utils/DtoMapping'; +import { Address } from '../model/account/Address'; import { PublicAccount } from '../model/account/PublicAccount'; import { BlockInfo } from '../model/blockchain/BlockInfo'; import { MerklePathItem } from '../model/blockchain/MerklePathItem'; @@ -23,10 +25,8 @@ import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo'; import { UInt64 } from '../model/UInt64'; import { BlockRepository } from './BlockRepository'; import { Http } from './Http'; -import { BlockSearchCriteria } from './searchCriteria/BlockSearchCriteria'; import { Page } from './Page'; -import { Address } from '../model/account/Address'; -import { DtoMapping } from '../core/utils/DtoMapping'; +import { BlockSearchCriteria } from './searchCriteria/BlockSearchCriteria'; /** * Blockchain http repository. @@ -42,12 +42,12 @@ export class BlockHttp extends Http implements BlockRepository { /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.blockRoutesApi = new BlockRoutesApi(url); - this.blockRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.blockRoutesApi = new BlockRoutesApi(this.config()); } /** diff --git a/src/infrastructure/ChainHttp.ts b/src/infrastructure/ChainHttp.ts index 1ff21aec5a..ed33e15425 100644 --- a/src/infrastructure/ChainHttp.ts +++ b/src/infrastructure/ChainHttp.ts @@ -15,7 +15,7 @@ */ import { Observable } from 'rxjs'; -import { ChainRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { ChainRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { BlockchainScore } from '../model/blockchain/BlockchainScore'; import { UInt64 } from '../model/UInt64'; import { ChainRepository } from './ChainRepository'; @@ -35,12 +35,12 @@ export class ChainHttp extends Http implements ChainRepository { /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.chainRoutesApi = new ChainRoutesApi(url); - this.chainRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.chainRoutesApi = new ChainRoutesApi(this.config()); } /** diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index bf3d63fab7..9a5a3d3326 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -14,26 +14,70 @@ * limitations under the License. */ -import * as http from 'http'; -import { from as observableFrom, Observable, of as observableOf, throwError } from 'rxjs'; -import { catchError, map, shareReplay } from 'rxjs/operators'; -import { NodeRoutesApi, Pagination } from 'symbol-openapi-typescript-node-client'; +import { from as observableFrom, Observable, of, of as observableOf, throwError } from 'rxjs'; +import { catchError, flatMap, map } from 'rxjs/operators'; +import { Configuration, NodeRoutesApi, Pagination, querystring } from 'symbol-openapi-typescript-fetch-client'; import { NetworkType } from '../model/network/NetworkType'; -import { QueryParams } from './QueryParams'; import { Page } from './Page'; +import { QueryParams } from './QueryParams'; +import { RepositoryCallError } from './RepositoryCallError'; /** * Http extended by all http services */ export abstract class Http { - protected readonly url: string; - /** * Constructor * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - this.url = url; + protected constructor(protected readonly url: string, protected readonly fetchApi?: any) {} + + public static errorHandling(error: any): Observable { + if (error instanceof Error) { + return throwError(error); + } + const statusCode: number = parseInt(error?.status || error?.statusCode || error?.response?.statusCode || 0); + const statusMessage: string = ( + error?.statusText || + error?.statusMessage || + error?.response?.statusMessage || + 'Unknown Error' + ).toString(); + + const toString = (body: any): string => { + if (!body) { + return ''; + } + if (typeof body === 'string' || body instanceof String) { + return body.toString(); + } + return JSON.stringify(body); + }; + + const getBody = (error: any): Observable => { + const body = error?.response?.body; + if (body) { + return of(toString(body)); + } + if (error.text) { + return observableFrom(error.text()).pipe( + map(toString), + catchError(() => of('')), + ); + } + return of(''); + }; + return getBody(error).pipe( + flatMap((body: string) => { + const formattedError: RepositoryCallError = { + statusCode, + statusMessage, + body, + }; + return throwError(new Error(JSON.stringify(formattedError))); + }), + ); } createNetworkTypeObservable(networkType?: NetworkType | Observable): Observable { @@ -42,12 +86,7 @@ export abstract class Http { } else if (networkType) { return observableOf(networkType as NetworkType); } else { - return observableFrom(new NodeRoutesApi(this.url).getNodeInfo()) - .pipe( - map(({ body }) => body.networkIdentifier), - catchError((error) => throwError(this.errorHandling(error))), - ) - .pipe(shareReplay(1)); + return this.call(new NodeRoutesApi(this.config()).getNodeInfo(), (body) => body.networkIdentifier); } } @@ -59,25 +98,8 @@ export abstract class Http { }; } - errorHandling(error: any): Error { - if (error.response && error.response.statusCode && error.response.body) { - const formattedError = { - statusCode: error.response.statusCode, - errorDetails: { - statusCode: error.response.statusCode, - statusMessage: error.response.statusMessage, - }, - body: error.response.body, - }; - return new Error(JSON.stringify(formattedError)); - } - if (error.code && error.address && error.code === 'ECONNREFUSED') { - return new Error(`Cannot reach node: ${error.address}:${error.port}`); - } - if (error instanceof Error) { - return error; - } - return new Error(error); + public config(): Configuration { + return new Configuration({ basePath: this.url, fetchApi: this.fetchApi, queryParamsStringify: querystring }); } /** @@ -85,13 +107,10 @@ export abstract class Http { * @param remoteCall the remote call * @param mapper the mapper from dto to the model object. */ - protected call( - remoteCall: Promise<{ response: http.IncomingMessage; body: D }>, - mapper: (value: D, index: number) => M, - ): Observable { + protected call(remoteCall: Promise, mapper: (value: D) => M): Observable { return observableFrom(remoteCall).pipe( - map(({ body }, index) => mapper(body, index)), - catchError((error) => throwError(this.errorHandling(error))), + map((body) => mapper(body)), + catchError(Http.errorHandling), ); } diff --git a/src/infrastructure/IListener.ts b/src/infrastructure/IListener.ts index 23a8a16067..75f98c7fd7 100644 --- a/src/infrastructure/IListener.ts +++ b/src/infrastructure/IListener.ts @@ -16,11 +16,11 @@ import { Observable } from 'rxjs'; import { Address } from '../model/account/Address'; +import { NewBlock } from '../model/blockchain/NewBlock'; import { AggregateTransaction } from '../model/transaction/AggregateTransaction'; import { CosignatureSignedTransaction } from '../model/transaction/CosignatureSignedTransaction'; import { Transaction } from '../model/transaction/Transaction'; import { TransactionStatusError } from '../model/transaction/TransactionStatusError'; -import { NewBlock } from '../model/blockchain/NewBlock'; /** * Listener service diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index 0d147fcd4a..ef00670f9b 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -16,21 +16,21 @@ import { Observable, of, OperatorFunction, Subject } from 'rxjs'; import { filter, flatMap, map, share } from 'rxjs/operators'; +import { BlockInfoDTO } from 'symbol-openapi-typescript-fetch-client'; import * as WebSocket from 'ws'; import { Address } from '../model/account/Address'; +import { PublicAccount } from '../model/account/PublicAccount'; +import { NewBlock } from '../model/blockchain/NewBlock'; import { NamespaceName } from '../model/namespace/NamespaceName'; import { AggregateTransaction } from '../model/transaction/AggregateTransaction'; import { CosignatureSignedTransaction } from '../model/transaction/CosignatureSignedTransaction'; import { Deadline } from '../model/transaction/Deadline'; import { Transaction } from '../model/transaction/Transaction'; import { TransactionStatusError } from '../model/transaction/TransactionStatusError'; +import { UInt64 } from '../model/UInt64'; import { IListener } from './IListener'; import { NamespaceRepository } from './NamespaceRepository'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; -import { BlockInfoDTO } from 'symbol-openapi-typescript-node-client'; -import { NewBlock } from '../model/blockchain/NewBlock'; -import { PublicAccount } from '../model/account/PublicAccount'; -import { UInt64 } from '../model/UInt64'; export enum ListenerChannelName { block = 'block', diff --git a/src/infrastructure/MetadataHttp.ts b/src/infrastructure/MetadataHttp.ts index b169afdafa..12deb0ff5a 100644 --- a/src/infrastructure/MetadataHttp.ts +++ b/src/infrastructure/MetadataHttp.ts @@ -15,7 +15,7 @@ */ import { Observable } from 'rxjs'; -import { MetadataDTO, MetadataRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { MetadataDTO, MetadataRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { Convert } from '../core/format/Convert'; import { Address } from '../model/account/Address'; import { Metadata } from '../model/metadata/Metadata'; @@ -42,12 +42,12 @@ export class MetadataHttp extends Http implements MetadataRepository { /** * Constructor - * @param url the url. + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.metadataRoutesApi = new MetadataRoutesApi(url); - this.metadataRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.metadataRoutesApi = new MetadataRoutesApi(this.config()); } /** diff --git a/src/infrastructure/MosaicHttp.ts b/src/infrastructure/MosaicHttp.ts index 00af619adb..dd0df8b5db 100644 --- a/src/infrastructure/MosaicHttp.ts +++ b/src/infrastructure/MosaicHttp.ts @@ -16,6 +16,9 @@ import { Observable } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; +import { MosaicInfoDTO, MosaicRoutesApi } from 'symbol-openapi-typescript-fetch-client'; +import { DtoMapping } from '../core/utils/DtoMapping'; +import { Address } from '../model/account/Address'; import { MosaicFlags } from '../model/mosaic/MosaicFlags'; import { MosaicId } from '../model/mosaic/MosaicId'; import { MosaicInfo } from '../model/mosaic/MosaicInfo'; @@ -23,11 +26,8 @@ import { NetworkType } from '../model/network/NetworkType'; import { UInt64 } from '../model/UInt64'; import { Http } from './Http'; import { MosaicRepository } from './MosaicRepository'; -import { MosaicSearchCriteria } from './searchCriteria/MosaicSearchCriteria'; import { Page } from './Page'; -import { MosaicRoutesApi, MosaicIds, MosaicInfoDTO } from 'symbol-openapi-typescript-node-client'; -import { Address } from '../model/account/Address'; -import { DtoMapping } from '../core/utils/DtoMapping'; +import { MosaicSearchCriteria } from './searchCriteria/MosaicSearchCriteria'; /** * Mosaic http repository. @@ -46,16 +46,17 @@ export class MosaicHttp extends Http implements MosaicRepository { * network type for the mappings. */ private readonly networkTypeObservable: Observable; + /** * Constructor - * @param url - * @param networkType + * @param url Base catapult-rest url + * @param networkType the network type. + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string, networkType?: NetworkType | Observable) { - super(url); - this.mosaicRoutesApi = new MosaicRoutesApi(url); + constructor(url: string, networkType?: NetworkType | Observable, fetchApi?: any) { + super(url, fetchApi); + this.mosaicRoutesApi = new MosaicRoutesApi(this.config()); this.networkTypeObservable = this.createNetworkTypeObservable(networkType); - this.mosaicRoutesApi.useQuerystring = true; } /** @@ -73,9 +74,12 @@ export class MosaicHttp extends Http implements MosaicRepository { * @returns Observable */ public getMosaics(mosaicIds: MosaicId[]): Observable { - const ids = new MosaicIds(); - ids.mosaicIds = mosaicIds.map((id) => id.toHex()); - return this.call(this.mosaicRoutesApi.getMosaics(ids), (body) => body.map((b) => this.toMosaicInfo(b))); + return this.call( + this.mosaicRoutesApi.getMosaics({ + mosaicIds: mosaicIds.map((id) => id.toHex()), + }), + (body) => body.map((b) => this.toMosaicInfo(b)), + ); } /** diff --git a/src/infrastructure/MultisigHttp.ts b/src/infrastructure/MultisigHttp.ts index 063efa824f..7e4063e0da 100644 --- a/src/infrastructure/MultisigHttp.ts +++ b/src/infrastructure/MultisigHttp.ts @@ -15,7 +15,7 @@ */ import { Observable } from 'rxjs'; -import { MultisigAccountInfoDTO, MultisigRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { MultisigAccountInfoDTO, MultisigRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { Address } from '../model/account/Address'; import { MultisigAccountGraphInfo } from '../model/account/MultisigAccountGraphInfo'; import { MultisigAccountInfo } from '../model/account/MultisigAccountInfo'; @@ -36,12 +36,12 @@ export class MultisigHttp extends Http implements MultisigRepository { /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.multisigRoutesApi = new MultisigRoutesApi(url); - this.multisigRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.multisigRoutesApi = new MultisigRoutesApi(this.config()); } /** diff --git a/src/infrastructure/NamespaceHttp.ts b/src/infrastructure/NamespaceHttp.ts index 4e854689dc..8e6486ec0c 100644 --- a/src/infrastructure/NamespaceHttp.ts +++ b/src/infrastructure/NamespaceHttp.ts @@ -15,7 +15,7 @@ */ import { Observable } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; -import { NamespaceDTO, NamespaceInfoDTO, NamespaceRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { NamespaceDTO, NamespaceInfoDTO, NamespaceRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { Convert as convert, RawAddress as AddressLibrary } from '../core/format'; import { AccountNames } from '../model/account/AccountNames'; import { Address } from '../model/account/Address'; @@ -55,14 +55,14 @@ export class NamespaceHttp extends Http implements NamespaceRepository { /** * Constructor - * @param url - * @param networkType + * @param url Base catapult-rest url + * @param networkType the network type. + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string, networkType?: NetworkType | Observable) { - super(url); - this.namespaceRoutesApi = new NamespaceRoutesApi(url); + constructor(url: string, networkType?: NetworkType | Observable, fetchApi?: any) { + super(url, fetchApi); + this.namespaceRoutesApi = new NamespaceRoutesApi(this.config()); this.networkTypeObservable = this.createNetworkTypeObservable(networkType); - this.namespaceRoutesApi.useQuerystring = true; } /** @@ -131,7 +131,6 @@ export class NamespaceHttp extends Http implements NamespaceRepository { address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).ordering, ), (body) => body.namespaces.map((namespaceInfoDTO) => this.toNamespaceInfo(namespaceInfoDTO)), ); diff --git a/src/infrastructure/NetworkHttp.ts b/src/infrastructure/NetworkHttp.ts index 5043f5ac45..12b9fe7473 100644 --- a/src/infrastructure/NetworkHttp.ts +++ b/src/infrastructure/NetworkHttp.ts @@ -16,7 +16,7 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import { NetworkConfigurationDTO, NetworkRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { NetworkConfigurationDTO, NetworkRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { AccountLinkNetworkProperties } from '../model/network/AccountLinkNetworkProperties'; import { AccountRestrictionNetworkProperties } from '../model/network/AccountRestrictionNetworkProperties'; import { AggregateNetworkProperties } from '../model/network/AggregateNetworkProperties'; @@ -37,10 +37,10 @@ import { SecretLockNetworkProperties } from '../model/network/SecretLockNetworkP import { TransactionFees } from '../model/network/TransactionFees'; import { TransferNetworkProperties } from '../model/network/TransferNetworkProperties'; import { NodeInfo } from '../model/node/NodeInfo'; +import { UInt64 } from '../model/UInt64'; import { Http } from './Http'; import { NetworkRepository } from './NetworkRepository'; import { NodeHttp } from './NodeHttp'; -import { UInt64 } from '../model/UInt64'; /** * Network http repository. @@ -57,13 +57,13 @@ export class NetworkHttp extends Http implements NetworkRepository { /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.nodeHttp = new NodeHttp(url); - this.networkRoutesApi = new NetworkRoutesApi(url); - this.networkRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.nodeHttp = new NodeHttp(url, fetchApi); + this.networkRoutesApi = new NetworkRoutesApi(this.config()); } /** diff --git a/src/infrastructure/NodeHttp.ts b/src/infrastructure/NodeHttp.ts index af7dedfa3d..fb5c1234d3 100644 --- a/src/infrastructure/NodeHttp.ts +++ b/src/infrastructure/NodeHttp.ts @@ -15,7 +15,7 @@ */ import { Observable } from 'rxjs'; -import { NodeInfoDTO, NodeRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { NodeInfoDTO, NodeRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { StorageInfo } from '../model/blockchain/StorageInfo'; import { NodeHealth } from '../model/node/NodeHealth'; import { NodeInfo } from '../model/node/NodeInfo'; @@ -39,12 +39,12 @@ export class NodeHttp extends Http implements NodeRepository { /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.nodeRoutesApi = new NodeRoutesApi(url); - this.nodeRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.nodeRoutesApi = new NodeRoutesApi(this.config()); } /** diff --git a/src/infrastructure/ReceiptHttp.ts b/src/infrastructure/ReceiptHttp.ts index 2580e38ae3..5aeb7d0d3e 100644 --- a/src/infrastructure/ReceiptHttp.ts +++ b/src/infrastructure/ReceiptHttp.ts @@ -14,18 +14,16 @@ * limitations under the License. */ -import { from as observableFrom, Observable, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; -import { ReceiptRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { Observable } from 'rxjs'; +import { ReceiptRoutesApi } from 'symbol-openapi-typescript-fetch-client'; +import { DtoMapping } from '../core/utils/DtoMapping'; import { MerklePathItem } from '../model/blockchain/MerklePathItem'; import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo'; -import { NetworkType } from '../model/network/NetworkType'; import { Statement } from '../model/receipt/Statement'; import { UInt64 } from '../model/UInt64'; import { Http } from './Http'; import { CreateStatementFromDTO } from './receipt/CreateReceiptFromDTO'; import { ReceiptRepository } from './ReceiptRepository'; -import { DtoMapping } from '../core/utils/DtoMapping'; /** * Receipt http repository. @@ -41,13 +39,12 @@ export class ReceiptHttp extends Http implements ReceiptRepository { /** * Constructor - * @param url - * @param networkType + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string, networkType?: NetworkType | Observable) { - super(url); - this.receiptRoutesApi = new ReceiptRoutesApi(url); - this.receiptRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.receiptRoutesApi = new ReceiptRoutesApi(this.config()); } /** @@ -61,14 +58,12 @@ export class ReceiptHttp extends Http implements ReceiptRepository { * @return Observable */ public getMerkleReceipts(height: UInt64, hash: string): Observable { - return observableFrom(this.receiptRoutesApi.getMerkleReceipts(height.toString(), hash)).pipe( - map( - ({ body }) => - new MerkleProofInfo( - body.merklePath!.map((payload) => new MerklePathItem(DtoMapping.mapEnum(payload.position), payload.hash)), - ), - ), - catchError((error) => throwError(this.errorHandling(error))), + return this.call( + this.receiptRoutesApi.getMerkleReceipts(height.toString(), hash), + (body) => + new MerkleProofInfo( + body.merklePath!.map((payload) => new MerklePathItem(DtoMapping.mapEnum(payload.position), payload.hash)), + ), ); } @@ -79,9 +74,6 @@ export class ReceiptHttp extends Http implements ReceiptRepository { * @returns Observable */ public getBlockReceipts(height: UInt64): Observable { - return observableFrom(this.receiptRoutesApi.getBlockReceipts(height.toString())).pipe( - map(({ body }) => CreateStatementFromDTO(body)), - catchError((error) => throwError(this.errorHandling(error))), - ); + return this.call(this.receiptRoutesApi.getBlockReceipts(height.toString()), (body) => CreateStatementFromDTO(body)); } } diff --git a/src/infrastructure/RepositoryCallError.ts b/src/infrastructure/RepositoryCallError.ts new file mode 100644 index 0000000000..1721567b6c --- /dev/null +++ b/src/infrastructure/RepositoryCallError.ts @@ -0,0 +1,35 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * When the repository raises an error, the Error's message would be a json string of this format: + */ +export interface RepositoryCallError { + /** + * The http status code if know, other wise 0. + */ + readonly statusCode: number; + + /** + * The status message if known; + */ + readonly statusMessage: string; + + /** + * The rest response body as text. + */ + readonly body: string; +} diff --git a/src/infrastructure/RepositoryFactoryConfig.ts b/src/infrastructure/RepositoryFactoryConfig.ts index d920a08bbd..d8d5f01d8c 100644 --- a/src/infrastructure/RepositoryFactoryConfig.ts +++ b/src/infrastructure/RepositoryFactoryConfig.ts @@ -33,4 +33,11 @@ export interface RepositoryFactoryConfig { * optional injected websocket instance when using listeners in client. */ websocketInjected?: any; + + /** + * optional fetch function to be used when performing rest requests. The default value is: + * 1) window.fetch if running on a browser + * 2) or node-fetch if running on server (window.fetch not found) + */ + fetchApi?: any; } diff --git a/src/infrastructure/RepositoryFactoryHttp.ts b/src/infrastructure/RepositoryFactoryHttp.ts index b17fd83922..8735626a5c 100644 --- a/src/infrastructure/RepositoryFactoryHttp.ts +++ b/src/infrastructure/RepositoryFactoryHttp.ts @@ -40,16 +40,16 @@ import { NodeRepository } from './NodeRepository'; import { ReceiptHttp } from './ReceiptHttp'; import { ReceiptRepository } from './ReceiptRepository'; import { RepositoryFactory } from './RepositoryFactory'; +import { RepositoryFactoryConfig } from './RepositoryFactoryConfig'; import { RestrictionAccountHttp } from './RestrictionAccountHttp'; import { RestrictionAccountRepository } from './RestrictionAccountRepository'; import { RestrictionMosaicHttp } from './RestrictionMosaicHttp'; import { RestrictionMosaicRepository } from './RestrictionMosaicRepository'; import { TransactionHttp } from './TransactionHttp'; import { TransactionRepository } from './TransactionRepository'; -import { RepositoryFactoryConfig } from './RepositoryFactoryConfig'; import { TransactionStatusHttp } from './TransactionStatusHttp'; import { TransactionStatusRepository } from './TransactionStatusRepository'; - +import fetch from 'node-fetch'; /** * Receipt http repository. * @@ -60,6 +60,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory { private readonly generationHash: Observable; private readonly websocketUrl: string; private readonly websocketInjected?: any; + private readonly fetchApi?: any; /** * Constructor @@ -68,6 +69,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory { */ constructor(url: string, configs?: RepositoryFactoryConfig) { this.url = url; + this.fetchApi = configs?.fetchApi || (typeof window !== 'undefined' && window.fetch) || fetch; this.networkType = configs?.networkType ? observableOf(configs.networkType) : this.createNetworkRepository().getNetworkType().pipe(shareReplay(1)); @@ -82,59 +84,59 @@ export class RepositoryFactoryHttp implements RepositoryFactory { } createAccountRepository(): AccountRepository { - return new AccountHttp(this.url); + return new AccountHttp(this.url, this.fetchApi); } createBlockRepository(): BlockRepository { - return new BlockHttp(this.url); + return new BlockHttp(this.url, this.fetchApi); } createChainRepository(): ChainRepository { - return new ChainHttp(this.url); + return new ChainHttp(this.url, this.fetchApi); } createMetadataRepository(): MetadataRepository { - return new MetadataHttp(this.url); + return new MetadataHttp(this.url, this.fetchApi); } createMosaicRepository(): MosaicRepository { - return new MosaicHttp(this.url, this.networkType); + return new MosaicHttp(this.url, this.networkType, this.fetchApi); } createMultisigRepository(): MultisigRepository { - return new MultisigHttp(this.url); + return new MultisigHttp(this.url, this.fetchApi); } createNamespaceRepository(): NamespaceRepository { - return new NamespaceHttp(this.url, this.networkType); + return new NamespaceHttp(this.url, this.networkType, this.fetchApi); } createNetworkRepository(): NetworkRepository { - return new NetworkHttp(this.url); + return new NetworkHttp(this.url, this.fetchApi); } createNodeRepository(): NodeRepository { - return new NodeHttp(this.url); + return new NodeHttp(this.url, this.fetchApi); } createReceiptRepository(): ReceiptRepository { - return new ReceiptHttp(this.url, this.networkType); + return new ReceiptHttp(this.url, this.fetchApi); } createRestrictionAccountRepository(): RestrictionAccountRepository { - return new RestrictionAccountHttp(this.url); + return new RestrictionAccountHttp(this.url, this.fetchApi); } createRestrictionMosaicRepository(): RestrictionMosaicRepository { - return new RestrictionMosaicHttp(this.url); + return new RestrictionMosaicHttp(this.url, this.fetchApi); } createTransactionRepository(): TransactionRepository { - return new TransactionHttp(this.url); + return new TransactionHttp(this.url, this.fetchApi); } createTransactionStatusRepository(): TransactionStatusRepository { - return new TransactionStatusHttp(this.url); + return new TransactionStatusHttp(this.url, this.fetchApi); } getGenerationHash(): Observable { diff --git a/src/infrastructure/RestrictionAccountHttp.ts b/src/infrastructure/RestrictionAccountHttp.ts index 34c22fbf46..4166961744 100644 --- a/src/infrastructure/RestrictionAccountHttp.ts +++ b/src/infrastructure/RestrictionAccountHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { from as observableFrom, Observable, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; -import { RestrictionAccountRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { Observable } from 'rxjs'; +import { RestrictionAccountRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { DtoMapping } from '../core/utils/DtoMapping'; import { Address } from '../model/account/Address'; import { AccountRestriction } from '../model/restriction/AccountRestriction'; @@ -34,14 +33,15 @@ export class RestrictionAccountHttp extends Http implements RestrictionAccountRe * @internal */ private restrictionAccountRoutesApi: RestrictionAccountRoutesApi; + /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.restrictionAccountRoutesApi = new RestrictionAccountRoutesApi(url); - this.restrictionAccountRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.restrictionAccountRoutesApi = new RestrictionAccountRoutesApi(this.config()); } /** @@ -50,9 +50,9 @@ export class RestrictionAccountHttp extends Http implements RestrictionAccountRe * @returns Observable */ public getAccountRestrictions(address: Address): Observable { - return observableFrom(this.restrictionAccountRoutesApi.getAccountRestrictions(address.plain())).pipe( - map(({ body }) => DtoMapping.extractAccountRestrictionFromDto(body).accountRestrictions.restrictions), - catchError((error) => throwError(this.errorHandling(error))), + return this.call( + this.restrictionAccountRoutesApi.getAccountRestrictions(address.plain()), + (body) => DtoMapping.extractAccountRestrictionFromDto(body).accountRestrictions.restrictions, ); } @@ -65,13 +65,10 @@ export class RestrictionAccountHttp extends Http implements RestrictionAccountRe const accountIds = { addresses: addresses.map((address) => address.plain()), }; - return observableFrom(this.restrictionAccountRoutesApi.getAccountRestrictionsFromAccounts(accountIds)).pipe( - map(({ body }) => - body.map((restriction) => { - return DtoMapping.extractAccountRestrictionFromDto(restriction).accountRestrictions; - }), - ), - catchError((error) => throwError(this.errorHandling(error))), + return this.call(this.restrictionAccountRoutesApi.getAccountRestrictionsFromAccounts(accountIds), (body) => + body.map((restriction) => { + return DtoMapping.extractAccountRestrictionFromDto(restriction).accountRestrictions; + }), ); } } diff --git a/src/infrastructure/RestrictionMosaicHttp.ts b/src/infrastructure/RestrictionMosaicHttp.ts index adfe66bae1..33a7d995ad 100644 --- a/src/infrastructure/RestrictionMosaicHttp.ts +++ b/src/infrastructure/RestrictionMosaicHttp.ts @@ -14,9 +14,12 @@ * limitations under the License. */ -import { from as observableFrom, Observable, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; -import { MosaicAddressRestrictionDTO, MosaicGlobalRestrictionDTO, RestrictionMosaicRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { Observable } from 'rxjs'; +import { + MosaicAddressRestrictionDTO, + MosaicGlobalRestrictionDTO, + RestrictionMosaicRoutesApi, +} from 'symbol-openapi-typescript-fetch-client'; import { Address } from '../model/account/Address'; import { MosaicId } from '../model/mosaic/MosaicId'; import { MosaicAddressRestriction } from '../model/restriction/MosaicAddressRestriction'; @@ -38,13 +41,12 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo /** * Constructor - * @param url - * @param networkType + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.restrictionMosaicRoutesApi = new RestrictionMosaicRoutesApi(url); - this.restrictionMosaicRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.restrictionMosaicRoutesApi = new RestrictionMosaicRoutesApi(this.config()); } /** @@ -55,9 +57,8 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo * @returns Observable */ getMosaicAddressRestriction(mosaicId: MosaicId, address: Address): Observable { - return observableFrom(this.restrictionMosaicRoutesApi.getMosaicAddressRestriction(mosaicId.toHex(), address.plain())).pipe( - map(({ body }) => this.toMosaicAddressRestriction(body)), - catchError((error) => throwError(this.errorHandling(error))), + return this.call(this.restrictionMosaicRoutesApi.getMosaicAddressRestriction(mosaicId.toHex(), address.plain()), (body) => + this.toMosaicAddressRestriction(body), ); } @@ -72,30 +73,8 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo const accountIds = { addresses: addresses.map((address) => address.plain()), }; - return observableFrom(this.restrictionMosaicRoutesApi.getMosaicAddressRestrictions(mosaicId.toHex(), accountIds)).pipe( - map(({ body }) => body.map(this.toMosaicAddressRestriction)), - catchError((error) => throwError(this.errorHandling(error))), - ); - } - - /** - * This method maps a MosaicAddressRestrictionDTO from rest to the SDK's MosaicAddressRestriction model object. - * - * @internal - * @param {MosaicAddressRestrictionDTO} dto the MosaicAddressRestrictionDTO object from rest. - * @returns {MosaicAddressRestriction} a MosaicAddressRestriction model - */ - private toMosaicAddressRestriction(dto: MosaicAddressRestrictionDTO): MosaicAddressRestriction { - const restrictionItems = new Map(); - dto.mosaicRestrictionEntry.restrictions.forEach((restriction) => { - restrictionItems.set(restriction.key, restriction.value); - }); - return new MosaicAddressRestriction( - dto.mosaicRestrictionEntry.compositeHash, - dto.mosaicRestrictionEntry.entryType.valueOf(), - new MosaicId(dto.mosaicRestrictionEntry.mosaicId), - Address.createFromEncoded(dto.mosaicRestrictionEntry.targetAddress), - restrictionItems, + return this.call(this.restrictionMosaicRoutesApi.getMosaicAddressRestrictions(mosaicId.toHex(), accountIds), (body) => + body.map(this.toMosaicAddressRestriction), ); } @@ -106,9 +85,8 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo * @returns Observable */ getMosaicGlobalRestriction(mosaicId: MosaicId): Observable { - return observableFrom(this.restrictionMosaicRoutesApi.getMosaicGlobalRestriction(mosaicId.toHex())).pipe( - map(({ body }) => this.toMosaicGlobalRestriction(body)), - catchError((error) => throwError(this.errorHandling(error))), + return this.call(this.restrictionMosaicRoutesApi.getMosaicGlobalRestriction(mosaicId.toHex()), (body) => + this.toMosaicGlobalRestriction(body), ); } @@ -122,9 +100,29 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo const mosaicIdsBody = { mosaicIds: mosaicIds.map((id) => id.toHex()), }; - return observableFrom(this.restrictionMosaicRoutesApi.getMosaicGlobalRestrictions(mosaicIdsBody)).pipe( - map(({ body }) => body.map(this.toMosaicGlobalRestriction)), - catchError((error) => throwError(this.errorHandling(error))), + return this.call(this.restrictionMosaicRoutesApi.getMosaicGlobalRestrictions(mosaicIdsBody), (body) => + body.map(this.toMosaicGlobalRestriction), + ); + } + + /** + * This method maps a MosaicAddressRestrictionDTO from rest to the SDK's MosaicAddressRestriction model object. + * + * @internal + * @param {MosaicAddressRestrictionDTO} dto the MosaicAddressRestrictionDTO object from rest. + * @returns {MosaicAddressRestriction} a MosaicAddressRestriction model + */ + private toMosaicAddressRestriction(dto: MosaicAddressRestrictionDTO): MosaicAddressRestriction { + const restrictionItems = new Map(); + dto.mosaicRestrictionEntry.restrictions.forEach((restriction) => { + restrictionItems.set(restriction.key, restriction.value); + }); + return new MosaicAddressRestriction( + dto.mosaicRestrictionEntry.compositeHash, + dto.mosaicRestrictionEntry.entryType.valueOf(), + new MosaicId(dto.mosaicRestrictionEntry.mosaicId), + Address.createFromEncoded(dto.mosaicRestrictionEntry.targetAddress), + restrictionItems, ); } diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index fe294e9285..7c5e5b92ca 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -14,17 +14,16 @@ * limitations under the License. */ -import { ClientResponse } from 'http'; -import { from as observableFrom, Observable, throwError } from 'rxjs'; -import { catchError, map, mergeMap } from 'rxjs/operators'; +import { Observable } from 'rxjs'; +import { mergeMap } from 'rxjs/operators'; import { BlockInfoDTO, BlockRoutesApi, - TransactionRoutesApi, TransactionInfoDTO, TransactionPage, - Cosignature, -} from 'symbol-openapi-typescript-node-client'; + TransactionRoutesApi, +} from 'symbol-openapi-typescript-fetch-client'; +import { DtoMapping } from '../core/utils/DtoMapping'; import { CosignatureSignedTransaction } from '../model/transaction/CosignatureSignedTransaction'; import { SignedTransaction } from '../model/transaction/SignedTransaction'; import { Transaction } from '../model/transaction/Transaction'; @@ -32,13 +31,11 @@ import { TransactionAnnounceResponse } from '../model/transaction/TransactionAnn import { TransactionInfo } from '../model/transaction/TransactionInfo'; import { TransactionType } from '../model/transaction/TransactionType'; import { Http } from './Http'; -import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; -import { TransactionRepository } from './TransactionRepository'; -import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; import { Page } from './Page'; +import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; +import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; import { TransactionGroup } from './TransactionGroup'; -import http = require('http'); -import { DtoMapping } from '../core/utils/DtoMapping'; +import { TransactionRepository } from './TransactionRepository'; /** * Transaction http repository. @@ -60,14 +57,13 @@ export class TransactionHttp extends Http implements TransactionRepository { /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.transactionRoutesApi = new TransactionRoutesApi(url); - this.blockRoutesApi = new BlockRoutesApi(url); - this.transactionRoutesApi.useQuerystring = true; - this.blockRoutesApi.useQuerystring = true; + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.transactionRoutesApi = new TransactionRoutesApi(this.config()); + this.blockRoutesApi = new BlockRoutesApi(this.config()); } /** @@ -77,10 +73,7 @@ export class TransactionHttp extends Http implements TransactionRepository { * @returns Observable */ public getTransaction(transactionId: string, transactionGroup: TransactionGroup): Observable { - return observableFrom(this.getTransactionByGroup(transactionId, transactionGroup)).pipe( - map(({ body }) => CreateTransactionFromDTO(body)), - catchError((error) => throwError(this.errorHandling(error))), - ); + return this.call(this.getTransactionByGroup(transactionId, transactionGroup), (body) => CreateTransactionFromDTO(body)); } /** @@ -92,13 +85,10 @@ export class TransactionHttp extends Http implements TransactionRepository { const transactionIdsBody = { transactionIds, }; - return observableFrom(this.transactionRoutesApi.getTransactionsById(transactionIdsBody)).pipe( - map(({ body }) => - body.map((transactionDTO) => { - return CreateTransactionFromDTO(transactionDTO); - }), - ), - catchError((error) => throwError(this.errorHandling(error))), + return this.call(this.transactionRoutesApi.getTransactionsById(transactionIdsBody), (body) => + body.map((transactionDTO) => { + return CreateTransactionFromDTO(transactionDTO); + }), ); } @@ -111,9 +101,9 @@ export class TransactionHttp extends Http implements TransactionRepository { if (signedTransaction.type === TransactionType.AGGREGATE_BONDED) { throw new Error("Announcing aggregate bonded transaction should use 'announceAggregateBonded'"); } - return observableFrom(this.transactionRoutesApi.announceTransaction(signedTransaction)).pipe( - map(({ body }) => new TransactionAnnounceResponse(body.message)), - catchError((error) => throwError(this.errorHandling(error))), + return this.call( + this.transactionRoutesApi.announceTransaction(signedTransaction), + (body) => new TransactionAnnounceResponse(body.message), ); } @@ -126,9 +116,9 @@ export class TransactionHttp extends Http implements TransactionRepository { if (signedTransaction.type !== TransactionType.AGGREGATE_BONDED) { throw new Error('Only Transaction Type 0x4241 is allowed for announce aggregate bonded'); } - return observableFrom(this.transactionRoutesApi.announcePartialTransaction(signedTransaction)).pipe( - map(({ body }) => new TransactionAnnounceResponse(body.message)), - catchError((error) => throwError(this.errorHandling(error))), + return this.call( + this.transactionRoutesApi.announcePartialTransaction(signedTransaction), + (body) => new TransactionAnnounceResponse(body.message), ); } @@ -140,14 +130,15 @@ export class TransactionHttp extends Http implements TransactionRepository { public announceAggregateBondedCosignature( cosignatureSignedTransaction: CosignatureSignedTransaction, ): Observable { - const cosignature = new Cosignature(); - cosignature.parentHash = cosignatureSignedTransaction.parentHash; - cosignature.signerPublicKey = cosignatureSignedTransaction.signerPublicKey; - cosignature.signature = cosignatureSignedTransaction.signature; - cosignature.version = cosignatureSignedTransaction.version.toString(); - return observableFrom(this.transactionRoutesApi.announceCosignatureTransaction(cosignature)).pipe( - map(({ body }) => new TransactionAnnounceResponse(body.message)), - catchError((error) => throwError(this.errorHandling(error))), + const cosignature = { + parentHash: cosignatureSignedTransaction.parentHash, + signerPublicKey: cosignatureSignedTransaction.signerPublicKey, + signature: cosignatureSignedTransaction.signature, + version: cosignatureSignedTransaction.version.toString(), + }; + return this.call( + this.transactionRoutesApi.announceCosignatureTransaction(cosignature), + (body) => new TransactionAnnounceResponse(body.message), ); } @@ -157,23 +148,18 @@ export class TransactionHttp extends Http implements TransactionRepository { * @returns Observable */ public getTransactionEffectiveFee(transactionId: string): Observable { - return observableFrom(this.getTransactionByGroup(transactionId, TransactionGroup.Confirmed)).pipe( - mergeMap(({ body }) => { - // parse transaction to take advantage of `size` getter overload - const transaction = CreateTransactionFromDTO(body); - const uintHeight = (transaction.transactionInfo as TransactionInfo).height; - + return this.call(this.getTransactionByGroup(transactionId, TransactionGroup.Confirmed), CreateTransactionFromDTO).pipe( + mergeMap((transaction) => { // now read block details - return observableFrom(this.blockRoutesApi.getBlockByHeight(uintHeight.toString())).pipe( - map((blockResponse: { response: ClientResponse; body: BlockInfoDTO }) => { - const blockDTO = blockResponse.body; + return this.call( + this.blockRoutesApi.getBlockByHeight((transaction.transactionInfo as TransactionInfo).height.toString()), + (blockDTO: BlockInfoDTO) => { // @see https://nemtech.github.io/concepts/transaction.html#fees // effective_fee = feeMultiplier x transaction::size return blockDTO.block.feeMultiplier * transaction.size; - }), + }, ); }), - catchError((error) => throwError(this.errorHandling(error))), ); } @@ -196,13 +182,7 @@ export class TransactionHttp extends Http implements TransactionRepository { * @param transactionGroup - Transaction group. * @returns Promise<{response: http.ClientResponse; body: TransactionInfoDTO;}> */ - private getTransactionByGroup( - transactionId: string, - transactionGroup: TransactionGroup, - ): Promise<{ - response: http.ClientResponse; - body: TransactionInfoDTO; - }> { + private getTransactionByGroup(transactionId: string, transactionGroup: TransactionGroup): Promise { switch (transactionGroup) { case TransactionGroup.Confirmed: return this.transactionRoutesApi.getConfirmedTransaction(transactionId); @@ -216,16 +196,10 @@ export class TransactionHttp extends Http implements TransactionRepository { /** * @internal * Gets a transaction search result - * @param transactionId - Transaction id or hash. - * @param transactionGroup - Transaction group. + * @param criteria - the criteria. * @returns Promise<{response: http.ClientResponse; body: TransactionInfoDTO;}> */ - private searchTransactionByGroup( - criteria: TransactionSearchCriteria, - ): Promise<{ - response: http.ClientResponse; - body: TransactionPage; - }> { + private searchTransactionByGroup(criteria: TransactionSearchCriteria): Promise { switch (criteria.group) { case TransactionGroup.Confirmed: return this.transactionRoutesApi.searchConfirmedTransactions( diff --git a/src/infrastructure/TransactionRepository.ts b/src/infrastructure/TransactionRepository.ts index b5f1702bf3..bdbaa8b98e 100644 --- a/src/infrastructure/TransactionRepository.ts +++ b/src/infrastructure/TransactionRepository.ts @@ -19,8 +19,8 @@ import { CosignatureSignedTransaction } from '../model/transaction/CosignatureSi import { SignedTransaction } from '../model/transaction/SignedTransaction'; import { Transaction } from '../model/transaction/Transaction'; import { TransactionAnnounceResponse } from '../model/transaction/TransactionAnnounceResponse'; -import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; import { Searcher } from './paginationStreamer/Searcher'; +import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; import { TransactionGroup } from './TransactionGroup'; /** diff --git a/src/infrastructure/TransactionStatusHttp.ts b/src/infrastructure/TransactionStatusHttp.ts index 4c245b9cbb..a416386b9c 100644 --- a/src/infrastructure/TransactionStatusHttp.ts +++ b/src/infrastructure/TransactionStatusHttp.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { from as observableFrom, Observable, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; -import { TransactionStatusRoutesApi, TransactionStatusDTO } from 'symbol-openapi-typescript-node-client'; +import { Observable } from 'rxjs'; +import { TransactionStatusDTO, TransactionStatusRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { Deadline } from '../model/transaction/Deadline'; import { TransactionStatus } from '../model/transaction/TransactionStatus'; import { UInt64 } from '../model/UInt64'; @@ -37,11 +36,12 @@ export class TransactionStatusHttp extends Http implements TransactionStatusRepo /** * Constructor - * @param url + * @param url Base catapult-rest url + * @param fetchApi fetch function to be used when performing rest requests. */ - constructor(url: string) { - super(url); - this.transactionStatusRoutesApi = new TransactionStatusRoutesApi(url); + constructor(url: string, fetchApi?: any) { + super(url, fetchApi); + this.transactionStatusRoutesApi = new TransactionStatusRoutesApi(this.config()); } /** @@ -50,10 +50,7 @@ export class TransactionStatusHttp extends Http implements TransactionStatusRepo * @returns Observable */ public getTransactionStatus(transactionHash: string): Observable { - return observableFrom(this.transactionStatusRoutesApi.getTransactionStatus(transactionHash)).pipe( - map(({ body }) => this.toTransactionStatus(body)), - catchError((error) => throwError(this.errorHandling(error))), - ); + return this.call(this.transactionStatusRoutesApi.getTransactionStatus(transactionHash), (body) => this.toTransactionStatus(body)); } /** @@ -65,9 +62,8 @@ export class TransactionStatusHttp extends Http implements TransactionStatusRepo const transactionHashesBody = { hashes: transactionHashes, }; - return observableFrom(this.transactionStatusRoutesApi.getTransactionStatuses(transactionHashesBody)).pipe( - map(({ body }) => body.map(this.toTransactionStatus)), - catchError((error) => throwError(this.errorHandling(error))), + return this.call(this.transactionStatusRoutesApi.getTransactionStatuses(transactionHashesBody), (body) => + body.map(this.toTransactionStatus), ); } diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 319c70002a..d26320de18 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -61,3 +61,4 @@ export * from './TransactionStatusRepository'; export * from './TransactionGroup'; export * from './searchCriteria/BlockOrderBy'; export * from './searchCriteria/Order'; +export * from './RepositoryCallError'; diff --git a/src/infrastructure/paginationStreamer/BlockPaginationStreamer.ts b/src/infrastructure/paginationStreamer/BlockPaginationStreamer.ts index f76f7a57bc..d14575c003 100644 --- a/src/infrastructure/paginationStreamer/BlockPaginationStreamer.ts +++ b/src/infrastructure/paginationStreamer/BlockPaginationStreamer.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { PaginationStreamer } from './PaginationStreamer'; -import { Searcher } from './Searcher'; import { BlockInfo } from '../../model/blockchain/BlockInfo'; import { BlockSearchCriteria } from '../searchCriteria/BlockSearchCriteria'; +import { PaginationStreamer } from './PaginationStreamer'; +import { Searcher } from './Searcher'; /** * A helper object that streams {@link BlockInfo} using the search. diff --git a/src/infrastructure/paginationStreamer/MosaicPaginationStreamer.ts b/src/infrastructure/paginationStreamer/MosaicPaginationStreamer.ts index 45dc0a83b2..082833c507 100644 --- a/src/infrastructure/paginationStreamer/MosaicPaginationStreamer.ts +++ b/src/infrastructure/paginationStreamer/MosaicPaginationStreamer.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { PaginationStreamer } from './PaginationStreamer'; -import { Searcher } from './Searcher'; import { MosaicInfo } from '../../model/mosaic/MosaicInfo'; import { MosaicSearchCriteria } from '../searchCriteria/MosaicSearchCriteria'; +import { PaginationStreamer } from './PaginationStreamer'; +import { Searcher } from './Searcher'; /** * A helper object that streams {@link MosaicInfo} using the search. diff --git a/src/infrastructure/paginationStreamer/PaginationStreamer.ts b/src/infrastructure/paginationStreamer/PaginationStreamer.ts index 3cd62fcabb..0e6745b863 100644 --- a/src/infrastructure/paginationStreamer/PaginationStreamer.ts +++ b/src/infrastructure/paginationStreamer/PaginationStreamer.ts @@ -15,12 +15,12 @@ */ import { concat } from 'rxjs'; -import { SearchCriteria } from '../searchCriteria/SearchCriteria'; -import { Searcher } from './Searcher'; import { Observable } from 'rxjs/internal/Observable'; import { defer } from 'rxjs/internal/observable/defer'; -import { flatMap } from 'rxjs/operators'; import { from } from 'rxjs/internal/observable/from'; +import { flatMap } from 'rxjs/operators'; +import { SearchCriteria } from '../searchCriteria/SearchCriteria'; +import { Searcher } from './Searcher'; /** * Utility helper that stream pages of searches into an Observable. diff --git a/src/infrastructure/paginationStreamer/Searcher.ts b/src/infrastructure/paginationStreamer/Searcher.ts index edad8edb0b..551bf574ba 100644 --- a/src/infrastructure/paginationStreamer/Searcher.ts +++ b/src/infrastructure/paginationStreamer/Searcher.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { SearchCriteria } from '../searchCriteria/SearchCriteria'; import { Observable } from 'rxjs/internal/Observable'; import { Page } from '../Page'; +import { SearchCriteria } from '../searchCriteria/SearchCriteria'; /** * Objects of this interface know how to search symbol objects based on a criteria returning a page of these objects. diff --git a/src/infrastructure/paginationStreamer/TransactionPaginationStreamer.ts b/src/infrastructure/paginationStreamer/TransactionPaginationStreamer.ts index 4532130cd1..28c11c13b9 100644 --- a/src/infrastructure/paginationStreamer/TransactionPaginationStreamer.ts +++ b/src/infrastructure/paginationStreamer/TransactionPaginationStreamer.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { PaginationStreamer } from './PaginationStreamer'; import { Transaction } from '../../model/transaction/Transaction'; import { TransactionSearchCriteria } from '../searchCriteria/TransactionSearchCriteria'; +import { PaginationStreamer } from './PaginationStreamer'; import { Searcher } from './Searcher'; /** diff --git a/src/infrastructure/receipt/CreateReceiptFromDTO.ts b/src/infrastructure/receipt/CreateReceiptFromDTO.ts index 3086f55351..16c885f85a 100644 --- a/src/infrastructure/receipt/CreateReceiptFromDTO.ts +++ b/src/infrastructure/receipt/CreateReceiptFromDTO.ts @@ -16,7 +16,9 @@ import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { Address } from '../../model/account/Address'; +import { UnresolvedAddress } from '../../model/account/UnresolvedAddress'; import { MosaicId } from '../../model/mosaic/MosaicId'; +import { UnresolvedMosaicId } from '../../model/mosaic/UnresolvedMosaicId'; import { NamespaceId } from '../../model/namespace/NamespaceId'; import { ArtifactExpiryReceipt } from '../../model/receipt/ArtifactExpiryReceipt'; import { BalanceChangeReceipt } from '../../model/receipt/BalanceChangeReceipt'; @@ -31,8 +33,6 @@ import { ResolutionType } from '../../model/receipt/ResolutionType'; import { Statement } from '../../model/receipt/Statement'; import { TransactionStatement } from '../../model/receipt/TransactionStatement'; import { UInt64 } from '../../model/UInt64'; -import { UnresolvedAddress } from '../../model/account/UnresolvedAddress'; -import { UnresolvedMosaicId } from '../../model/mosaic/UnresolvedMosaicId'; /** * @interal diff --git a/src/infrastructure/searchCriteria/BlockSearchCriteria.ts b/src/infrastructure/searchCriteria/BlockSearchCriteria.ts index f04fec1e71..0b7f094b6a 100644 --- a/src/infrastructure/searchCriteria/BlockSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/BlockSearchCriteria.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { SearchCriteria } from './SearchCriteria'; import { BlockOrderBy } from './BlockOrderBy'; +import { SearchCriteria } from './SearchCriteria'; /** * Defines the params used to search blocks. With this criteria, you can sort and filter diff --git a/src/infrastructure/searchCriteria/MosaicSearchCriteria.ts b/src/infrastructure/searchCriteria/MosaicSearchCriteria.ts index aa7e989474..350bf607c9 100644 --- a/src/infrastructure/searchCriteria/MosaicSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/MosaicSearchCriteria.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { SearchCriteria } from './SearchCriteria'; import { Address } from '../../model/account/Address'; +import { SearchCriteria } from './SearchCriteria'; /** * Defines the params used to search mosaics. With this criteria, you can sort and filter diff --git a/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts b/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts index 32a1e829a7..32ab02f96c 100644 --- a/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import { SearchCriteria } from './SearchCriteria'; import { Address } from '../../model/account/Address'; -import { UInt64 } from '../../model/UInt64'; import { TransactionType } from '../../model/transaction/TransactionType'; +import { UInt64 } from '../../model/UInt64'; import { TransactionGroup } from '../TransactionGroup'; +import { SearchCriteria } from './SearchCriteria'; /** * Defines the params used to search transactions. With this criteria, you can sort and filter diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 45f8cda6c9..69a4976c81 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -46,6 +46,7 @@ import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSup import { MultisigAccountModificationTransaction } from '../../model/transaction/MultisigAccountModificationTransaction'; import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import { NamespaceRegistrationTransaction } from '../../model/transaction/NamespaceRegistrationTransaction'; +import { NodeKeyLinkTransaction } from '../../model/transaction/NodeKeyLinkTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; import { SignedTransaction } from '../../model/transaction/SignedTransaction'; @@ -53,10 +54,9 @@ import { Transaction } from '../../model/transaction/Transaction'; import { TransactionInfo } from '../../model/transaction/TransactionInfo'; import { TransactionType } from '../../model/transaction/TransactionType'; import { TransferTransaction } from '../../model/transaction/TransferTransaction'; -import { UInt64 } from '../../model/UInt64'; -import { VrfKeyLinkTransaction } from '../../model/transaction/VrfKeyLinkTransaction'; import { VotingKeyLinkTransaction } from '../../model/transaction/VotingKeyLinkTransaction'; -import { NodeKeyLinkTransaction } from '../../model/transaction/NodeKeyLinkTransaction'; +import { VrfKeyLinkTransaction } from '../../model/transaction/VrfKeyLinkTransaction'; +import { UInt64 } from '../../model/UInt64'; /** * Extract recipientAddress value from encoded hexadecimal notation. diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index 603b8332a9..0e6fdb54a6 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -23,6 +23,7 @@ import { AccountMosaicRestrictionTransaction } from '../../model/transaction/Acc import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; +import { InnerTransaction } from '../../model/transaction/InnerTransaction'; import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction'; import { MosaicAddressRestrictionTransaction } from '../../model/transaction/MosaicAddressRestrictionTransaction'; import { MosaicAliasTransaction } from '../../model/transaction/MosaicAliasTransaction'; @@ -33,15 +34,14 @@ import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSup import { MultisigAccountModificationTransaction } from '../../model/transaction/MultisigAccountModificationTransaction'; import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import { NamespaceRegistrationTransaction } from '../../model/transaction/NamespaceRegistrationTransaction'; +import { NodeKeyLinkTransaction } from '../../model/transaction/NodeKeyLinkTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; import { Transaction } from '../../model/transaction/Transaction'; import { TransactionType } from '../../model/transaction/TransactionType'; import { TransferTransaction } from '../../model/transaction/TransferTransaction'; -import { VrfKeyLinkTransaction } from '../../model/transaction/VrfKeyLinkTransaction'; import { VotingKeyLinkTransaction } from '../../model/transaction/VotingKeyLinkTransaction'; -import { NodeKeyLinkTransaction } from '../../model/transaction/NodeKeyLinkTransaction'; -import { InnerTransaction } from '../../model/transaction/InnerTransaction'; +import { VrfKeyLinkTransaction } from '../../model/transaction/VrfKeyLinkTransaction'; /** * @internal diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index a824417044..79c08b35ef 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -32,14 +32,14 @@ import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSup import { MultisigAccountModificationTransaction } from '../../model/transaction/MultisigAccountModificationTransaction'; import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import { NamespaceRegistrationTransaction } from '../../model/transaction/NamespaceRegistrationTransaction'; +import { NodeKeyLinkTransaction } from '../../model/transaction/NodeKeyLinkTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; import { Transaction } from '../../model/transaction/Transaction'; import { TransactionType } from '../../model/transaction/TransactionType'; import { TransferTransaction } from '../../model/transaction/TransferTransaction'; -import { VrfKeyLinkTransaction } from '../../model/transaction/VrfKeyLinkTransaction'; import { VotingKeyLinkTransaction } from '../../model/transaction/VotingKeyLinkTransaction'; -import { NodeKeyLinkTransaction } from '../../model/transaction/NodeKeyLinkTransaction'; +import { VrfKeyLinkTransaction } from '../../model/transaction/VrfKeyLinkTransaction'; /** * @internal diff --git a/src/model/network/NetworkProperties.ts b/src/model/network/NetworkProperties.ts index 3e13fd51d2..12e87d55c2 100644 --- a/src/model/network/NetworkProperties.ts +++ b/src/model/network/NetworkProperties.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { NodeIdentityEqualityStrategy } from 'symbol-openapi-typescript-node-client'; +import { NodeIdentityEqualityStrategy } from 'symbol-openapi-typescript-fetch-client'; /** * Network related configuration properties. diff --git a/src/model/node/NodeHealth.ts b/src/model/node/NodeHealth.ts index 1a4c721ac5..6d94a0bf04 100644 --- a/src/model/node/NodeHealth.ts +++ b/src/model/node/NodeHealth.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { NodeStatusEnum } from 'symbol-openapi-typescript-node-client'; +import { NodeStatusEnum } from 'symbol-openapi-typescript-fetch-client'; /** * The node info structure describes basic information of a node health. diff --git a/src/model/transaction/TransactionStatus.ts b/src/model/transaction/TransactionStatus.ts index 13fe34b56e..b81170a387 100644 --- a/src/model/transaction/TransactionStatus.ts +++ b/src/model/transaction/TransactionStatus.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TransactionGroupEnum, TransactionStatusEnum } from 'symbol-openapi-typescript-node-client'; +import { TransactionGroupEnum, TransactionStatusEnum } from 'symbol-openapi-typescript-fetch-client'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; diff --git a/test/core/utils/DtoMapping.spec.ts b/test/core/utils/DtoMapping.spec.ts index fa1c43c8f9..0ab2994b2e 100644 --- a/test/core/utils/DtoMapping.spec.ts +++ b/test/core/utils/DtoMapping.spec.ts @@ -22,7 +22,7 @@ import { AccountRestrictionsDTO, AccountRestrictionDTO, AccountRestrictionFlagsEnum, -} from 'symbol-openapi-typescript-node-client'; +} from 'symbol-openapi-typescript-fetch-client'; import { DtoMapping } from '../../../src/core/utils/DtoMapping'; describe('DtoMapping', () => { @@ -34,9 +34,9 @@ describe('DtoMapping', () => { const mosaicId = new MosaicId('11F4B1B3AC033DB5'); it('extractRestrictionInfo - Operation', () => { - const restrictionInfo = new AccountRestrictionsInfoDTO(); - const restrictionsDto = new AccountRestrictionsDTO(); - const restriction = new AccountRestrictionDTO(); + const restrictionInfo = {} as AccountRestrictionsInfoDTO; + const restrictionsDto = {} as AccountRestrictionsDTO; + const restriction = {} as AccountRestrictionDTO; restriction.restrictionFlags = AccountRestrictionFlagsEnum.NUMBER_16388; restriction.values = [16724]; restrictionsDto.restrictions = [restriction]; @@ -50,9 +50,9 @@ describe('DtoMapping', () => { it('extractRestrictionInfo - Mosaic', () => { const address = publicAccount.address; - const restrictionInfo = new AccountRestrictionsInfoDTO(); - const restrictionsDto = new AccountRestrictionsDTO(); - const restriction = new AccountRestrictionDTO(); + const restrictionInfo = {} as AccountRestrictionsInfoDTO; + const restrictionsDto = {} as AccountRestrictionsDTO; + const restriction = {} as AccountRestrictionDTO; restriction.restrictionFlags = AccountRestrictionFlagsEnum.NUMBER_2; restriction.values = [mosaicId.toHex()]; restrictionsDto.restrictions = [restriction]; diff --git a/test/core/utils/EnumMapping.spec.ts b/test/core/utils/EnumMapping.spec.ts index c882b4e94d..6ce826b402 100644 --- a/test/core/utils/EnumMapping.spec.ts +++ b/test/core/utils/EnumMapping.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { expect } from 'chai'; -import { Order, PositionEnum, BlockOrderByEnum } from 'symbol-openapi-typescript-node-client'; +import { Order, PositionEnum, BlockOrderByEnum } from 'symbol-openapi-typescript-fetch-client'; import { Order as OrderModel } from '../../../src/infrastructure/searchCriteria/Order'; import { DtoMapping } from '../../../src/core/utils/DtoMapping'; import { BlockOrderBy } from '../../../src/infrastructure/searchCriteria/BlockOrderBy'; diff --git a/test/infrastructure/AccountHttp.spec.ts b/test/infrastructure/AccountHttp.spec.ts index 52c0d0ae9a..c76ebf4c21 100644 --- a/test/infrastructure/AccountHttp.spec.ts +++ b/test/infrastructure/AccountHttp.spec.ts @@ -19,11 +19,12 @@ import { AccountDTO, AccountIds, AccountInfoDTO, + AccountKeyDTO, AccountRoutesApi, AccountTypeEnum, ActivityBucketDTO, Mosaic, -} from 'symbol-openapi-typescript-node-client'; +} from 'symbol-openapi-typescript-fetch-client'; import { deepEqual, instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; import { AccountHttp } from '../../src/infrastructure/AccountHttp'; @@ -31,29 +32,28 @@ import { AccountRepository } from '../../src/infrastructure/AccountRepository'; import { AccountInfo } from '../../src/model/account/AccountInfo'; import { AccountType } from '../../src/model/account/AccountType'; import { Address } from '../../src/model/account/Address'; -import { AccountKeyDTO } from 'symbol-openapi-typescript-node-client'; describe('AccountHttp', () => { const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); - const mosaic = new Mosaic(); + const mosaic = {} as Mosaic; mosaic.amount = '777'; mosaic.id = '941299B2B7E1291C'; - const activityBucketDTO = new ActivityBucketDTO(); + const activityBucketDTO = {} as ActivityBucketDTO; activityBucketDTO.beneficiaryCount = 1; activityBucketDTO.rawScore = '2'; activityBucketDTO.startHeight = '3'; activityBucketDTO.totalFeesPaid = '4'; - const accountDTO = new AccountDTO(); + const accountDTO = {} as AccountDTO; accountDTO.accountType = AccountTypeEnum.NUMBER_1; accountDTO.address = address.encoded(); accountDTO.addressHeight = '111'; accountDTO.importance = '222'; accountDTO.importanceHeight = '333'; accountDTO.publicKeyHeight = '444'; - const accountKeyDto = new AccountKeyDTO(); + const accountKeyDto = {} as AccountKeyDTO; accountKeyDto.key = 'abc'; accountKeyDto.keyType = 1; accountDTO.supplementalAccountKeys = [accountKeyDto]; @@ -62,7 +62,7 @@ describe('AccountHttp', () => { accountDTO.mosaics = [mosaic]; accountDTO.activityBuckets = [activityBucketDTO]; - const accountInfoDto = new AccountInfoDTO(); + const accountInfoDto = {} as AccountInfoDTO; accountInfoDto.account = accountDTO; const url = 'http://someHost'; @@ -101,15 +101,15 @@ describe('AccountHttp', () => { } it('getAccountInfo', async () => { - when(accountRoutesApi.getAccountInfo(address.plain())).thenReturn(Promise.resolve({ response, body: accountInfoDto })); + when(accountRoutesApi.getAccountInfo(address.plain())).thenReturn(Promise.resolve(accountInfoDto)); const accountInfo = await accountRepository.getAccountInfo(address).toPromise(); assertAccountInfo(accountInfo); }); it('getAccountsInfo', async () => { - const accountIds = new AccountIds(); + const accountIds = {} as AccountIds; accountIds.addresses = [address.plain()]; - when(accountRoutesApi.getAccountsInfo(deepEqual(accountIds))).thenReturn(Promise.resolve({ response, body: [accountInfoDto] })); + when(accountRoutesApi.getAccountsInfo(deepEqual(accountIds))).thenReturn(Promise.resolve([accountInfoDto])); const accountInfos = await accountRepository.getAccountsInfo([address]).toPromise(); assertAccountInfo(accountInfos[0]); }); diff --git a/test/infrastructure/BlockHttp.spec.ts b/test/infrastructure/BlockHttp.spec.ts index 77bd4fed07..1551a13998 100644 --- a/test/infrastructure/BlockHttp.spec.ts +++ b/test/infrastructure/BlockHttp.spec.ts @@ -19,27 +19,27 @@ import { BlockDTO, BlockInfoDTO, BlockMetaDTO, + BlockPage, BlockRoutesApi, MerklePathItemDTO, MerkleProofInfoDTO, NetworkTypeEnum, - PositionEnum, Pagination, - BlockPage, -} from 'symbol-openapi-typescript-node-client'; -import { instance, mock, reset, when, deepEqual } from 'ts-mockito'; + PositionEnum, +} from 'symbol-openapi-typescript-fetch-client'; +import { deepEqual, instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; import { BlockHttp } from '../../src/infrastructure/BlockHttp'; import { BlockRepository } from '../../src/infrastructure/BlockRepository'; +import { Address } from '../../src/model/account/Address'; import { BlockInfo } from '../../src/model/blockchain/BlockInfo'; import { MerklePathItem } from '../../src/model/blockchain/MerklePathItem'; -import { UInt64 } from '../../src/model/UInt64'; -import { Address } from '../../src/model/account/Address'; -import { NetworkType } from '../../src/model/network/NetworkType'; import { MerklePosition } from '../../src/model/blockchain/MerklePosition'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { UInt64 } from '../../src/model/UInt64'; describe('BlockHttp', () => { - const blockDTO = new BlockDTO(); + const blockDTO = {} as BlockDTO; blockDTO.version = 1; blockDTO.network = NetworkTypeEnum.NUMBER_152; blockDTO.difficulty = '2'; @@ -54,7 +54,7 @@ describe('BlockHttp', () => { NetworkType.MIJIN_TEST, ).encoded(); - const blockMetaDTO = new BlockMetaDTO(); + const blockMetaDTO = {} as BlockMetaDTO; blockMetaDTO.generationHash = 'abc'; blockMetaDTO.hash = 'aHash'; blockMetaDTO.numStatements = 10; @@ -62,7 +62,7 @@ describe('BlockHttp', () => { blockMetaDTO.totalFee = '30'; blockMetaDTO.stateHashSubCacheMerkleRoots = ['a', 'b', 'c']; - const blockInfoDto = new BlockInfoDTO(); + const blockInfoDto = {} as BlockInfoDTO; blockInfoDto.block = blockDTO; blockInfoDto.meta = blockMetaDTO; @@ -100,19 +100,19 @@ describe('BlockHttp', () => { } it('getBlockInfo', async () => { - when(blockRoutesApi.getBlockByHeight('1')).thenReturn(Promise.resolve({ response, body: blockInfoDto })); + when(blockRoutesApi.getBlockByHeight('1')).thenReturn(Promise.resolve(blockInfoDto)); const blockInfo = await blockRepository.getBlockByHeight(UInt64.fromUint(1)).toPromise(); assertBlockInfo(blockInfo); }); it('searchBlocks', async () => { - const pagination = new Pagination(); + const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 1; pagination.totalEntries = 1; pagination.totalPages = 1; - const body = new BlockPage(); + const body = {} as BlockPage; body.data = [blockInfoDto]; body.pagination = pagination; when( @@ -125,29 +125,19 @@ describe('BlockHttp', () => { undefined, undefined, ), - ).thenReturn( - Promise.resolve({ - response, - body, - }), - ); + ).thenReturn(Promise.resolve(body)); const blockInfos = await blockRepository.search({ signerPublicKey: blockDTO.signerPublicKey }).toPromise(); assertBlockInfo(blockInfos.data[0]); }); it('getMerkleTransaction', async () => { - const merkleProofInfoDTO = new MerkleProofInfoDTO(); - const merklePathItemDTO = new MerklePathItemDTO(); + const merkleProofInfoDTO = {} as MerkleProofInfoDTO; + const merklePathItemDTO = {} as MerklePathItemDTO; merklePathItemDTO.hash = 'bbb'; merklePathItemDTO.position = PositionEnum.Left; merkleProofInfoDTO.merklePath = [merklePathItemDTO]; - when(blockRoutesApi.getMerkleTransaction('2', 'abc')).thenReturn( - Promise.resolve({ - response, - body: merkleProofInfoDTO, - }), - ); + when(blockRoutesApi.getMerkleTransaction('2', 'abc')).thenReturn(Promise.resolve(merkleProofInfoDTO)); const merkleProofInfo = await blockRepository.getMerkleTransaction(UInt64.fromUint(2), 'abc').toPromise(); expect(merkleProofInfo).to.be.not.null; expect(merkleProofInfo.merklePath).to.deep.equals([new MerklePathItem(MerklePosition.Left, 'bbb')]); diff --git a/test/infrastructure/ChainHttp.spec.ts b/test/infrastructure/ChainHttp.spec.ts index d26938e744..431c3584c2 100644 --- a/test/infrastructure/ChainHttp.spec.ts +++ b/test/infrastructure/ChainHttp.spec.ts @@ -15,7 +15,7 @@ */ import { expect } from 'chai'; import * as http from 'http'; -import { ChainRoutesApi, ChainScoreDTO, HeightInfoDTO } from 'symbol-openapi-typescript-node-client'; +import { ChainRoutesApi, ChainScoreDTO, HeightInfoDTO } from 'symbol-openapi-typescript-fetch-client'; import { instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; import { ChainHttp } from '../../src/infrastructure/ChainHttp'; @@ -35,19 +35,19 @@ describe('ChainHttp', () => { }); it('getBlockchainHeight', async () => { - const heightInfoDTO = new HeightInfoDTO(); + const heightInfoDTO = {} as HeightInfoDTO; heightInfoDTO.height = '3'; - when(chainRoutesApi.getChainHeight()).thenReturn(Promise.resolve({ response, body: heightInfoDTO })); + when(chainRoutesApi.getChainHeight()).thenReturn(Promise.resolve(heightInfoDTO)); const heightInfo = await chainRepository.getBlockchainHeight().toPromise(); expect(heightInfo).to.be.not.null; expect(heightInfo.toString()).to.be.equals('3'); }); it('getChainScore', async () => { - const chainScoreDTO = new ChainScoreDTO(); + const chainScoreDTO = {} as ChainScoreDTO; chainScoreDTO.scoreLow = '2'; chainScoreDTO.scoreHigh = '3'; - when(chainRoutesApi.getChainScore()).thenReturn(Promise.resolve({ response, body: chainScoreDTO })); + when(chainRoutesApi.getChainScore()).thenReturn(Promise.resolve(chainScoreDTO)); const chainScore = await chainRepository.getChainScore().toPromise(); expect(chainScore).to.be.not.null; expect(chainScore.scoreLow.toString()).to.be.equals('2'); diff --git a/test/infrastructure/Listener.spec.ts b/test/infrastructure/Listener.spec.ts index a1e6556df3..980a4bf129 100644 --- a/test/infrastructure/Listener.spec.ts +++ b/test/infrastructure/Listener.spec.ts @@ -23,16 +23,16 @@ import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepositor import { Account } from '../../src/model/account/Account'; import { AccountNames } from '../../src/model/account/AccountNames'; import { Address } from '../../src/model/account/Address'; -import { NetworkType } from '../../src/model/network/NetworkType'; -import { TransactionStatusError } from '../../src/model/transaction/TransactionStatusError'; -import { UInt64 } from '../../src/model/UInt64'; import { NewBlock } from '../../src/model/blockchain/NewBlock'; -import { Transaction } from '../../src/model/transaction/Transaction'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; -import { NamespaceName } from '../../src/model/namespace/NamespaceName'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; +import { NamespaceName } from '../../src/model/namespace/NamespaceName'; +import { NetworkType } from '../../src/model/network/NetworkType'; import { Deadline } from '../../src/model/transaction/Deadline'; +import { Transaction } from '../../src/model/transaction/Transaction'; +import { TransactionStatusError } from '../../src/model/transaction/TransactionStatusError'; +import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; +import { UInt64 } from '../../src/model/UInt64'; describe('Listener', () => { const account = Account.createFromPrivateKey( diff --git a/test/infrastructure/MetadataHttp.spec.ts b/test/infrastructure/MetadataHttp.spec.ts index 266aecb203..f17f72a19f 100644 --- a/test/infrastructure/MetadataHttp.spec.ts +++ b/test/infrastructure/MetadataHttp.spec.ts @@ -14,14 +14,14 @@ * limitations under the License. */ import { expect } from 'chai'; -import * as http from 'http'; import { MetadataDTO, MetadataEntriesDTO, MetadataEntryDTO, MetadataRoutesApi, MetadataTypeEnum, -} from 'symbol-openapi-typescript-node-client'; + Order, +} from 'symbol-openapi-typescript-fetch-client'; import { instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; import { MetadataHttp } from '../../src/infrastructure/MetadataHttp'; @@ -32,25 +32,24 @@ import { Metadata } from '../../src/model/metadata/Metadata'; import { MetadataType } from '../../src/model/metadata/MetadataType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; -import { Order } from 'symbol-openapi-typescript-node-client'; -import { MetadataTransactionService } from '../../src/service/MetadataTransactionService'; -import { Deadline } from '../../src/model/transaction/Deadline'; import { NetworkType } from '../../src/model/network/NetworkType'; -import { UInt64 } from '../../src/model/UInt64'; import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; -import { TransactionType } from '../../src/model/transaction/TransactionType'; +import { Deadline } from '../../src/model/transaction/Deadline'; import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetadataTransaction'; +import { TransactionType } from '../../src/model/transaction/TransactionType'; +import { UInt64 } from '../../src/model/UInt64'; +import { MetadataTransactionService } from '../../src/service/MetadataTransactionService'; describe('MetadataHttp', () => { const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const mosaicId = new MosaicId('941299B2B7E1291C'); const namespaceId = new NamespaceId('some.address'); - const metadataDTOMosaic = new MetadataDTO(); + const metadataDTOMosaic = {} as MetadataDTO; metadataDTOMosaic.id = 'aaa'; - const metadataEntryDtoMosaic = new MetadataEntryDTO(); + const metadataEntryDtoMosaic = {} as MetadataEntryDTO; metadataEntryDtoMosaic.compositeHash = '1'; metadataEntryDtoMosaic.metadataType = MetadataTypeEnum.NUMBER_1; metadataEntryDtoMosaic.scopedMetadataKey = '123451234512345A'; @@ -60,10 +59,10 @@ describe('MetadataHttp', () => { metadataEntryDtoMosaic.targetId = '941299B2B7E1291C' as any; metadataDTOMosaic.metadataEntry = metadataEntryDtoMosaic; - const metadataDTOAddress = new MetadataDTO(); + const metadataDTOAddress = {} as MetadataDTO; metadataDTOAddress.id = 'bbb'; - const metadataEntryDtoAddress = new MetadataEntryDTO(); + const metadataEntryDtoAddress = {} as MetadataEntryDTO; metadataEntryDtoAddress.compositeHash = '2'; metadataEntryDtoAddress.metadataType = MetadataTypeEnum.NUMBER_0; metadataEntryDtoAddress.scopedMetadataKey = '123451234512345B'; @@ -73,10 +72,10 @@ describe('MetadataHttp', () => { metadataEntryDtoAddress.targetId = '941299B2B7E1291D' as any; metadataDTOAddress.metadataEntry = metadataEntryDtoAddress; - const metadataDTONamespace = new MetadataDTO(); + const metadataDTONamespace = {} as MetadataDTO; metadataDTONamespace.id = 'ccc'; - const metadataEntryDtoNamespace = new MetadataEntryDTO(); + const metadataEntryDtoNamespace = {} as MetadataEntryDTO; metadataEntryDtoNamespace.compositeHash = '3'; metadataEntryDtoNamespace.metadataType = MetadataTypeEnum.NUMBER_2; metadataEntryDtoNamespace.scopedMetadataKey = '123451234512345C'; @@ -86,17 +85,20 @@ describe('MetadataHttp', () => { metadataEntryDtoNamespace.targetId = '941299B2B7E1291E' as any; metadataDTONamespace.metadataEntry = metadataEntryDtoNamespace; - const metadataEntriesDTO = new MetadataEntriesDTO(); + const metadataEntriesDTO = {} as MetadataEntriesDTO; metadataEntriesDTO.metadataEntries = [metadataDTOMosaic, metadataDTOAddress, metadataDTONamespace]; const url = 'http://someHost'; - const response: http.IncomingMessage = mock(); + const notFoundResponse = { + status: 404, + statusText: 'Not Found', + json: (): Promise => Promise.reject({ theBodyError: 'internal error' }), + }; const metadataRoutesApi: MetadataRoutesApi = mock(); const metadataRepository: MetadataRepository = DtoMapping.assign(new MetadataHttp(url), { metadataRoutesApi: instance(metadataRoutesApi), }); before(() => { - reset(response); reset(metadataRoutesApi); }); @@ -119,12 +121,7 @@ describe('MetadataHttp', () => { } it('getAccountMetadata', async () => { - when(metadataRoutesApi.getAccountMetadata(address.plain(), 1, Order.Desc, 'a')).thenReturn( - Promise.resolve({ - response, - body: metadataEntriesDTO, - }), - ); + when(metadataRoutesApi.getAccountMetadata(address.plain(), 1, Order.Desc, 'a')).thenReturn(Promise.resolve(metadataEntriesDTO)); const metadatas = await metadataRepository .getAccountMetadata( address, @@ -141,12 +138,7 @@ describe('MetadataHttp', () => { }); it('getAccountMetadataByKey', async () => { - when(metadataRoutesApi.getAccountMetadataByKey(address.plain(), 'aaa')).thenReturn( - Promise.resolve({ - response, - body: metadataEntriesDTO, - }), - ); + when(metadataRoutesApi.getAccountMetadataByKey(address.plain(), 'aaa')).thenReturn(Promise.resolve(metadataEntriesDTO)); const metadatas = await metadataRepository.getAccountMetadataByKey(address, 'aaa').toPromise(); assertMetadataInfo(metadatas[0], metadataDTOMosaic); assertMetadataInfo(metadatas[1], metadataDTOAddress); @@ -155,22 +147,14 @@ describe('MetadataHttp', () => { it('getAccountMetadataByKeyAndSender', async () => { when(metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), 'aaa', address.plain())).thenReturn( - Promise.resolve({ - response, - body: metadataDTOMosaic, - }), + Promise.resolve(metadataDTOMosaic), ); const metadata = await metadataRepository.getAccountMetadataByKeyAndSender(address, 'aaa', address).toPromise(); assertMetadataInfo(metadata, metadataDTOMosaic); }); it('getMosaicMetadata', async () => { - when(metadataRoutesApi.getMosaicMetadata(mosaicId.toHex(), 1, 'a', Order.Desc)).thenReturn( - Promise.resolve({ - response, - body: metadataEntriesDTO, - }), - ); + when(metadataRoutesApi.getMosaicMetadata(mosaicId.toHex(), 1, 'a', Order.Desc)).thenReturn(Promise.resolve(metadataEntriesDTO)); const metadatas = await metadataRepository .getMosaicMetadata( mosaicId, @@ -187,12 +171,7 @@ describe('MetadataHttp', () => { }); it('getMosaicMetadataByKey', async () => { - when(metadataRoutesApi.getMosaicMetadataByKey(mosaicId.toHex(), 'aaa')).thenReturn( - Promise.resolve({ - response, - body: metadataEntriesDTO, - }), - ); + when(metadataRoutesApi.getMosaicMetadataByKey(mosaicId.toHex(), 'aaa')).thenReturn(Promise.resolve(metadataEntriesDTO)); const metadatas = await metadataRepository.getMosaicMetadataByKey(mosaicId, 'aaa').toPromise(); assertMetadataInfo(metadatas[0], metadataDTOMosaic); assertMetadataInfo(metadatas[1], metadataDTOAddress); @@ -201,10 +180,7 @@ describe('MetadataHttp', () => { it('getMosaicMetadataByKeyAndSender', async () => { when(metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), 'aaa', address.plain())).thenReturn( - Promise.resolve({ - response, - body: metadataDTOMosaic, - }), + Promise.resolve(metadataDTOMosaic), ); const metadata = await metadataRepository.getMosaicMetadataByKeyAndSender(mosaicId, 'aaa', address).toPromise(); assertMetadataInfo(metadata, metadataDTOMosaic); @@ -212,10 +188,7 @@ describe('MetadataHttp', () => { it('getNamespaceMetadata', async () => { when(metadataRoutesApi.getNamespaceMetadata(namespaceId.toHex(), 2, 'a', Order.Desc)).thenReturn( - Promise.resolve({ - response, - body: metadataEntriesDTO, - }), + Promise.resolve(metadataEntriesDTO), ); const metadatas = await metadataRepository .getNamespaceMetadata( @@ -233,12 +206,7 @@ describe('MetadataHttp', () => { }); it('getNamespaceMetadataByKey', async () => { - when(metadataRoutesApi.getNamespaceMetadataByKey(namespaceId.toHex(), 'bbb')).thenReturn( - Promise.resolve({ - response, - body: metadataEntriesDTO, - }), - ); + when(metadataRoutesApi.getNamespaceMetadataByKey(namespaceId.toHex(), 'bbb')).thenReturn(Promise.resolve(metadataEntriesDTO)); const metadatas = await metadataRepository.getNamespaceMetadataByKey(namespaceId, 'bbb').toPromise(); assertMetadataInfo(metadatas[0], metadataDTOMosaic); assertMetadataInfo(metadatas[1], metadataDTOAddress); @@ -247,22 +215,15 @@ describe('MetadataHttp', () => { it('getNamespaceMetadataByKeyAndSender', async () => { when(metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), 'cccc', address.plain())).thenReturn( - Promise.resolve({ - response, - body: metadataDTOMosaic, - }), + Promise.resolve(metadataDTOMosaic), ); const metadata = await metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, 'cccc', address).toPromise(); assertMetadataInfo(metadata, metadataDTOMosaic); }); it('Address meta no previous value', (done) => { - response.statusCode = 404; when(metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), '85BBEA6CC462B244', address.plain())).thenReturn( - Promise.reject({ - response, - body: undefined, - }), + Promise.reject(notFoundResponse), ); const metadataTransactionService = new MetadataTransactionService(metadataRepository); metadataTransactionService @@ -283,12 +244,8 @@ describe('MetadataHttp', () => { }); it('Mosaic meta no previous value', (done) => { - response.statusCode = 404; when(metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), '85BBEA6CC462B244', address.plain())).thenReturn( - Promise.reject({ - response, - body: undefined, - }), + Promise.reject(notFoundResponse), ); const metadataTransactionService = new MetadataTransactionService(metadataRepository); metadataTransactionService @@ -310,12 +267,8 @@ describe('MetadataHttp', () => { }); it('Namespace meta no previous value', (done) => { - response.statusCode = 404; when(metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), '85BBEA6CC462B244', address.plain())).thenReturn( - Promise.reject({ - response, - body: undefined, - }), + Promise.reject(notFoundResponse), ); const metadataTransactionService = new MetadataTransactionService(metadataRepository); metadataTransactionService @@ -337,12 +290,8 @@ describe('MetadataHttp', () => { }); it('Address meta no previous value Error', async () => { - response.statusCode = 409; when(metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), '85BBEA6CC462B244', address.plain())).thenReturn( - Promise.reject({ - response, - body: undefined, - }), + Promise.reject(notFoundResponse), ); const metadataTransactionService = new MetadataTransactionService(metadataRepository); await metadataTransactionService @@ -360,12 +309,8 @@ describe('MetadataHttp', () => { }); it('Mosaic meta no previous value', async () => { - response.statusCode = 409; when(metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), '85BBEA6CC462B244', address.plain())).thenReturn( - Promise.reject({ - response, - body: undefined, - }), + Promise.reject(notFoundResponse), ); const metadataTransactionService = new MetadataTransactionService(metadataRepository); await metadataTransactionService @@ -384,12 +329,8 @@ describe('MetadataHttp', () => { }); it('Namespace meta no previous value', async () => { - response.statusCode = 409; when(metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), '85BBEA6CC462B244', address.plain())).thenReturn( - Promise.reject({ - response, - body: undefined, - }), + Promise.reject(notFoundResponse), ); const metadataTransactionService = new MetadataTransactionService(metadataRepository); await metadataTransactionService diff --git a/test/infrastructure/MosaicHttp.spec.ts b/test/infrastructure/MosaicHttp.spec.ts index bc14a75efb..e577e1c8e0 100644 --- a/test/infrastructure/MosaicHttp.spec.ts +++ b/test/infrastructure/MosaicHttp.spec.ts @@ -15,16 +15,23 @@ */ import { expect } from 'chai'; import * as http from 'http'; -import { Mosaic, MosaicRoutesApi, MosaicInfoDTO, MosaicDTO, MosaicIds, MosaicPage } from 'symbol-openapi-typescript-node-client'; -import { instance, mock, reset, when, deepEqual } from 'ts-mockito'; +import { + Mosaic, + MosaicDTO, + MosaicIds, + MosaicInfoDTO, + MosaicPage, + MosaicRoutesApi, + Pagination, +} from 'symbol-openapi-typescript-fetch-client'; +import { deepEqual, instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; -import { MosaicRepository } from '../../src/infrastructure/MosaicRepository'; import { MosaicHttp } from '../../src/infrastructure/MosaicHttp'; -import { NetworkType } from '../../src/model/network/NetworkType'; +import { MosaicRepository } from '../../src/infrastructure/MosaicRepository'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicInfo } from '../../src/model/mosaic/MosaicInfo'; -import { PublicAccount } from '../../src/model/account/PublicAccount'; -import { Pagination } from 'symbol-openapi-typescript-node-client'; +import { NetworkType } from '../../src/model/network/NetworkType'; describe('MosaicHttp', () => { const publicAccount = PublicAccount.createFromPublicKey( @@ -33,11 +40,11 @@ describe('MosaicHttp', () => { ); const address = publicAccount.address; const mosaicId = new MosaicId('941299B2B7E1291C'); - const mosaic = new Mosaic(); + const mosaic = {} as Mosaic; mosaic.amount = '777'; mosaic.id = mosaicId.toHex(); - const mosaicDto = new MosaicDTO(); + const mosaicDto = {} as MosaicDTO; mosaicDto.divisibility = 6; mosaicDto.duration = '10'; mosaicDto.flags = 1; @@ -47,7 +54,7 @@ describe('MosaicHttp', () => { mosaicDto.startHeight = '1'; mosaicDto.supply = '100'; - const mosaicInfoDto = new MosaicInfoDTO(); + const mosaicInfoDto = {} as MosaicInfoDTO; mosaicInfoDto.mosaic = mosaicDto; const url = 'http://someHost'; @@ -75,32 +82,32 @@ describe('MosaicHttp', () => { } it('getMosaic', async () => { - when(mosaicRoutesApi.getMosaic(mosaicId.toHex())).thenReturn(Promise.resolve({ response, body: mosaicInfoDto })); + when(mosaicRoutesApi.getMosaic(mosaicId.toHex())).thenReturn(Promise.resolve(mosaicInfoDto)); const mosaicInfo = await mosaicRepository.getMosaic(mosaicId).toPromise(); assertMosaicInfo(mosaicInfo); }); it('getMosaics', async () => { - const mosaicIds = new MosaicIds(); + const mosaicIds = {} as MosaicIds; mosaicIds.mosaicIds = [mosaicId.toHex()]; - when(mosaicRoutesApi.getMosaics(deepEqual(mosaicIds))).thenReturn(Promise.resolve({ response, body: [mosaicInfoDto] })); + when(mosaicRoutesApi.getMosaics(deepEqual(mosaicIds))).thenReturn(Promise.resolve([mosaicInfoDto])); const mosaicInfos = await mosaicRepository.getMosaics([mosaicId]).toPromise(); assertMosaicInfo(mosaicInfos[0]); }); it('searchMosaics', async () => { - const pagination = new Pagination(); + const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 1; pagination.totalEntries = 1; pagination.totalPages = 1; - const body = new MosaicPage(); + const body = {} as MosaicPage; body.data = [mosaicInfoDto]; body.pagination = pagination; when(mosaicRoutesApi.searchMosaics(deepEqual(address.plain()), undefined, undefined, undefined, undefined)).thenReturn( - Promise.resolve({ response, body }), + Promise.resolve(body), ); const mosaicsInfo = await mosaicRepository.search({ ownerAddress: address }).toPromise(); assertMosaicInfo(mosaicsInfo.data[0]); @@ -115,7 +122,7 @@ describe('MosaicHttp', () => { }); it('getMosaics - Error', async () => { - const mosaicIds = new MosaicIds(); + const mosaicIds = {} as MosaicIds; mosaicIds.mosaicIds = [mosaicId.toHex()]; when(mosaicRoutesApi.getMosaics(deepEqual(mosaicIds))).thenReject(new Error('Mocked Error')); await mosaicRepository diff --git a/test/infrastructure/MultisigHttp.spec.ts b/test/infrastructure/MultisigHttp.spec.ts index 2124f5bcee..9c63f1b170 100644 --- a/test/infrastructure/MultisigHttp.spec.ts +++ b/test/infrastructure/MultisigHttp.spec.ts @@ -13,9 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { deepEqual } from 'assert'; import { expect } from 'chai'; import * as http from 'http'; -import { MultisigAccountGraphInfoDTO, MultisigAccountInfoDTO, MultisigDTO, MultisigRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { + MultisigAccountGraphInfoDTO, + MultisigAccountInfoDTO, + MultisigDTO, + MultisigRoutesApi, +} from 'symbol-openapi-typescript-fetch-client'; import { instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; import { MultisigHttp } from '../../src/infrastructure/MultisigHttp'; @@ -23,14 +29,13 @@ import { MultisigRepository } from '../../src/infrastructure/MultisigRepository' import { Account } from '../../src/model/account/Account'; import { MultisigAccountInfo } from '../../src/model/account/MultisigAccountInfo'; import { NetworkType } from '../../src/model/network/NetworkType'; -import { deepEqual } from 'assert'; describe('MultisigHttp', () => { const networkType = NetworkType.MIJIN_TEST; const account = Account.generateNewAccount(networkType); const address = account.address; - const accountInfoDto = new MultisigAccountInfoDTO(); - const multisigDTO = new MultisigDTO(); + const accountInfoDto = {} as MultisigAccountInfoDTO; + const multisigDTO = {} as MultisigDTO; const account1 = Account.generateNewAccount(networkType); const account2 = Account.generateNewAccount(networkType); @@ -69,20 +74,20 @@ describe('MultisigHttp', () => { } it('getMultisigAccountInfo', async () => { - when(multisigRoutesApi.getAccountMultisig(address.plain())).thenReturn(Promise.resolve({ response, body: accountInfoDto })); + when(multisigRoutesApi.getAccountMultisig(address.plain())).thenReturn(Promise.resolve(accountInfoDto)); const accountInfo = await accountRepository.getMultisigAccountInfo(address).toPromise(); assertMultisigInfo(accountInfo); }); it('getMultisigAccountGraphInfo', async () => { - const body = new MultisigAccountGraphInfoDTO(); + const body = {} as MultisigAccountGraphInfoDTO; body.level = 10; body.multisigEntries = [accountInfoDto, accountInfoDto, accountInfoDto]; - const body2 = new MultisigAccountGraphInfoDTO(); + const body2 = {} as MultisigAccountGraphInfoDTO; body2.level = 20; body2.multisigEntries = [accountInfoDto, accountInfoDto]; - when(multisigRoutesApi.getAccountMultisigGraph(address.plain())).thenReturn(Promise.resolve({ response, body: [body, body2] })); + when(multisigRoutesApi.getAccountMultisigGraph(address.plain())).thenReturn(Promise.resolve([body, body2])); const graphInfo = await accountRepository.getMultisigAccountGraphInfo(address).toPromise(); expect(graphInfo.multisigEntries.size).to.be.eq(2); const list10: MultisigAccountInfo[] = graphInfo.multisigEntries.get(10) as MultisigAccountInfo[]; diff --git a/test/infrastructure/NamespaceHttp.spec.ts b/test/infrastructure/NamespaceHttp.spec.ts index fb4a701a10..c8c03f44ba 100644 --- a/test/infrastructure/NamespaceHttp.spec.ts +++ b/test/infrastructure/NamespaceHttp.spec.ts @@ -16,28 +16,27 @@ import { expect } from 'chai'; import * as http from 'http'; import { - NamespaceRoutesApi, AccountNamesDTO, AccountsNamesDTO, - MosaicsNamesDTO, + AliasDTO, + AliasTypeEnum, MosaicNamesDTO, + MosaicsNamesDTO, + NamespaceDTO, + NamespaceInfoDTO, NamespaceMetaDTO, - AliasTypeEnum, NamespaceNameDTO, - NamespacesInfoDTO, - AliasDTO, -} from 'symbol-openapi-typescript-node-client'; -import { instance, mock, reset, when, deepEqual } from 'ts-mockito'; + NamespaceRoutesApi, +} from 'symbol-openapi-typescript-fetch-client'; +import { deepEqual, instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; -import { NetworkType } from '../../src/model/network/NetworkType'; -import { MosaicId } from '../../src/model/mosaic/MosaicId'; -import { PublicAccount } from '../../src/model/account/PublicAccount'; -import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp'; +import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; +import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; -import { NamespaceDTO } from 'symbol-openapi-typescript-node-client'; -import { NamespaceInfoDTO } from 'symbol-openapi-typescript-node-client'; import { NamespaceInfo } from '../../src/model/namespace/NamespaceInfo'; +import { NetworkType } from '../../src/model/network/NetworkType'; describe('NamespaceHttp', () => { const publicAccount = PublicAccount.createFromPublicKey( @@ -47,13 +46,13 @@ describe('NamespaceHttp', () => { const address = publicAccount.address; const mosaicId = new MosaicId('941299B2B7E1291C'); const namespaceId = new NamespaceId('testnamespace'); - const namespaceMetaDto = new NamespaceMetaDTO(); + const namespaceMetaDto = {} as NamespaceMetaDTO; namespaceMetaDto.active = true; namespaceMetaDto.id = '1'; namespaceMetaDto.index = 0; - const namespaceDto = new NamespaceDTO(); - const aliasDtoAddress = new AliasDTO(); + const namespaceDto = {} as NamespaceDTO; + const aliasDtoAddress = {} as AliasDTO; aliasDtoAddress.address = address.encoded(); aliasDtoAddress.type = AliasTypeEnum.NUMBER_2; @@ -66,14 +65,14 @@ describe('NamespaceHttp', () => { namespaceDto.registrationType = 0; namespaceDto.startHeight = '10'; - const namespaceInfoDto = new NamespaceInfoDTO(); + const namespaceInfoDto = {} as NamespaceInfoDTO; namespaceInfoDto.meta = namespaceMetaDto; namespaceInfoDto.namespace = namespaceDto; - const aliasDtoMosaic = new AliasDTO(); + const aliasDtoMosaic = {} as AliasDTO; aliasDtoMosaic.mosaicId = mosaicId.toHex(); aliasDtoMosaic.type = AliasTypeEnum.NUMBER_1; - const namespaceDtoMosaic = new NamespaceDTO(); + const namespaceDtoMosaic = {} as NamespaceDTO; namespaceDtoMosaic.alias = aliasDtoMosaic; namespaceDtoMosaic.depth = 1; namespaceDtoMosaic.endHeight = '12'; @@ -83,7 +82,7 @@ describe('NamespaceHttp', () => { namespaceDtoMosaic.registrationType = 0; namespaceDtoMosaic.startHeight = '10'; - const namespaceInfoDtoMosaic = new NamespaceInfoDTO(); + const namespaceInfoDtoMosaic = {} as NamespaceInfoDTO; namespaceInfoDtoMosaic.meta = namespaceMetaDto; namespaceInfoDtoMosaic.namespace = namespaceDtoMosaic; @@ -115,14 +114,14 @@ describe('NamespaceHttp', () => { }); it('getAccountNames', async () => { - const accountsNamesDto = new AccountsNamesDTO(); - const accountNamesDto = new AccountNamesDTO(); + const accountsNamesDto = {} as AccountsNamesDTO; + const accountNamesDto = {} as AccountNamesDTO; accountNamesDto.address = address.encoded(); accountNamesDto.names = ['name1', 'name2']; accountsNamesDto.accountNames = [accountNamesDto]; when(namespaceRoutesApi.getAccountsNames(deepEqual({ addresses: [address.plain()] }))).thenReturn( - Promise.resolve({ response, body: accountsNamesDto }), + Promise.resolve(accountsNamesDto), ); const accountNames = await namespaceRepository.getAccountsNames([address]).toPromise(); expect(accountNames.length).to.be.greaterThan(0); @@ -131,15 +130,13 @@ describe('NamespaceHttp', () => { }); it('getMosaicNames', async () => { - const mosaicsNamesDto = new MosaicsNamesDTO(); - const mosaicNamesDto = new MosaicNamesDTO(); + const mosaicsNamesDto = {} as MosaicsNamesDTO; + const mosaicNamesDto = {} as MosaicNamesDTO; mosaicNamesDto.mosaicId = mosaicId.toHex(); mosaicNamesDto.names = ['name1', 'name2']; mosaicsNamesDto.mosaicNames = [mosaicNamesDto]; - when(namespaceRoutesApi.getMosaicsNames(deepEqual({ mosaicIds: [mosaicId.toHex()] }))).thenReturn( - Promise.resolve({ response, body: mosaicsNamesDto }), - ); + when(namespaceRoutesApi.getMosaicsNames(deepEqual({ mosaicIds: [mosaicId.toHex()] }))).thenReturn(Promise.resolve(mosaicsNamesDto)); const names = await namespaceRepository.getMosaicsNames([mosaicId]).toPromise(); expect(names.length).to.be.greaterThan(0); expect(names[0].mosaicId.toHex()).to.be.equal(mosaicId.toHex()); @@ -147,25 +144,23 @@ describe('NamespaceHttp', () => { }); it('getNamespace', async () => { - when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( - Promise.resolve({ response, body: namespaceInfoDto }), - ); + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn(Promise.resolve(namespaceInfoDto)); const namespace = await namespaceRepository.getNamespace(namespaceId).toPromise(); assertNamespaceInfo(namespace); }); it('getNamespaceName', async () => { - const namespaceNameParent = new NamespaceNameDTO(); + const namespaceNameParent = {} as NamespaceNameDTO; namespaceNameParent.id = namespaceId.toHex(); namespaceNameParent.name = 'parent'; - const namespaceNameChild = new NamespaceNameDTO(); + const namespaceNameChild = {} as NamespaceNameDTO; namespaceNameChild.id = new NamespaceId('child').toHex(); namespaceNameChild.name = 'child'; namespaceNameChild.parentId = namespaceId.toHex(); when(namespaceRoutesApi.getNamespacesNames(deepEqual({ namespaceIds: [namespaceId.toHex()] }))).thenReturn( - Promise.resolve({ response, body: [namespaceNameParent, namespaceNameChild] }), + Promise.resolve([namespaceNameParent, namespaceNameChild]), ); const namespace = await namespaceRepository.getNamespacesName([namespaceId]).toPromise(); expect(namespace.length).to.be.equal(2); @@ -178,10 +173,8 @@ describe('NamespaceHttp', () => { }); it('getNamespaceFromAccount', async () => { - const namespacesInfoDto = new NamespacesInfoDTO(); - namespacesInfoDto.namespaces = [namespaceInfoDto]; - when(namespaceRoutesApi.getNamespacesFromAccount(deepEqual(address.plain()), undefined, undefined, undefined)).thenReturn( - Promise.resolve({ response, body: namespacesInfoDto }), + when(namespaceRoutesApi.getNamespacesFromAccount(deepEqual(address.plain()), undefined, undefined)).thenReturn( + Promise.resolve({ namespaces: [namespaceInfoDto] }), ); const namespaces = await namespaceRepository.getNamespacesFromAccount(address).toPromise(); @@ -189,10 +182,8 @@ describe('NamespaceHttp', () => { }); it('getNamespaceFromAccounts', async () => { - const namespacesInfoDto = new NamespacesInfoDTO(); - namespacesInfoDto.namespaces = [namespaceInfoDto]; when(namespaceRoutesApi.getNamespacesFromAccounts(deepEqual(deepEqual({ addresses: [address.plain()] })))).thenReturn( - Promise.resolve({ response, body: namespacesInfoDto }), + Promise.resolve({ namespaces: [namespaceInfoDto] }), ); const namespaces = await namespaceRepository.getNamespacesFromAccount(address).toPromise(); @@ -200,27 +191,21 @@ describe('NamespaceHttp', () => { }); it('getLinkedAddress', async () => { - when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( - Promise.resolve({ response, body: namespaceInfoDto }), - ); + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn(Promise.resolve(namespaceInfoDto)); const namespaces = await namespaceRepository.getLinkedAddress(namespaceId).toPromise(); expect(namespaces?.plain()).to.be.equal(address.plain()); }); it('getLinkedMosaicId', async () => { - when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( - Promise.resolve({ response, body: namespaceInfoDtoMosaic }), - ); + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn(Promise.resolve(namespaceInfoDtoMosaic)); const namespaces = await namespaceRepository.getLinkedMosaicId(namespaceId).toPromise(); expect(namespaces?.toHex()).to.be.equal(mosaicId.toHex()); }); it('getLinkedMosaicId - Error', async () => { - when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( - Promise.resolve({ response, body: namespaceInfoDto }), - ); + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn(Promise.resolve(namespaceInfoDto)); await namespaceRepository .getLinkedMosaicId(namespaceId) .toPromise() @@ -228,9 +213,7 @@ describe('NamespaceHttp', () => { }); it('getLinkedAddress - Error', async () => { - when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( - Promise.resolve({ response, body: namespaceInfoDtoMosaic }), - ); + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn(Promise.resolve(namespaceInfoDtoMosaic)); await namespaceRepository .getLinkedAddress(namespaceId) .toPromise() diff --git a/test/infrastructure/NetworkHttp.spec.ts b/test/infrastructure/NetworkHttp.spec.ts index 9a11cbd25c..05ea00398b 100644 --- a/test/infrastructure/NetworkHttp.spec.ts +++ b/test/infrastructure/NetworkHttp.spec.ts @@ -13,38 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { deepEqual } from 'assert'; import { expect } from 'chai'; import * as http from 'http'; import { + NetworkConfigurationDTO, NetworkRoutesApi, NetworkTypeDTO, + NodeIdentityEqualityStrategy, NodeInfoDTO, NodeRoutesApi, + RolesTypeEnum, TransactionFeesDTO, - RentalFeesDTO, - NetworkConfigurationDTO, - NetworkPropertiesDTO, - NodeIdentityEqualityStrategy, - ChainPropertiesDTO, - PluginsPropertiesDTO, - AccountKeyLinkNetworkPropertiesDTO, - AggregateNetworkPropertiesDTO, - HashLockNetworkPropertiesDTO, - SecretLockNetworkPropertiesDTO, - MetadataNetworkPropertiesDTO, - MosaicNetworkPropertiesDTO, - MultisigNetworkPropertiesDTO, - NamespaceNetworkPropertiesDTO, - AccountRestrictionNetworkPropertiesDTO, - MosaicRestrictionNetworkPropertiesDTO, - TransferNetworkPropertiesDTO, -} from 'symbol-openapi-typescript-node-client'; +} from 'symbol-openapi-typescript-fetch-client'; import { instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; import { NetworkHttp } from '../../src/infrastructure/NetworkHttp'; import { NodeHttp } from '../../src/infrastructure/NodeHttp'; import { NetworkType } from '../../src/model/network/NetworkType'; -import { deepEqual } from 'assert'; import * as testResources from '../resource/TestResources'; describe('NetworkHttp', () => { @@ -66,13 +52,14 @@ describe('NetworkHttp', () => { }); it('getTransactionFees', async () => { - const body = new TransactionFeesDTO(); - body.averageFeeMultiplier = 1; - body.highestFeeMultiplier = 2; - body.lowestFeeMultiplier = 3; - body.medianFeeMultiplier = 4; + const body: TransactionFeesDTO = { + averageFeeMultiplier: 1, + highestFeeMultiplier: 2, + lowestFeeMultiplier: 3, + medianFeeMultiplier: 4, + }; - when(networkRoutesApi.getTransactionFees()).thenReturn(Promise.resolve({ response, body })); + when(networkRoutesApi.getTransactionFees()).thenReturn(Promise.resolve(body)); const networkFees = await networkRepository.getTransactionFees().toPromise(); expect(networkFees).to.be.not.null; @@ -83,12 +70,13 @@ describe('NetworkHttp', () => { }); it('getRentalFees', async () => { - const body = new RentalFeesDTO(); - body.effectiveChildNamespaceRentalFee = '1'; - body.effectiveMosaicRentalFee = '2'; - body.effectiveRootNamespaceRentalFeePerBlock = '3'; + const body = { + effectiveChildNamespaceRentalFee: '1', + effectiveMosaicRentalFee: '2', + effectiveRootNamespaceRentalFeePerBlock: '3', + }; - when(networkRoutesApi.getRentalFees()).thenReturn(Promise.resolve({ response, body })); + when(networkRoutesApi.getRentalFees()).thenReturn(Promise.resolve(body)); const rentalFees = await networkRepository.getRentalFees().toPromise(); expect(rentalFees).to.be.not.null; @@ -98,21 +86,30 @@ describe('NetworkHttp', () => { }); it('getNetworkType', async () => { - const body = new NodeInfoDTO(); - body.networkIdentifier = NetworkType.MIJIN_TEST; - - when(nodeRoutesApi.getNodeInfo()).thenReturn(Promise.resolve({ response, body })); + const body: NodeInfoDTO = { + networkIdentifier: NetworkType.MIJIN_TEST, + friendlyName: '', + host: '', + networkGenerationHashSeed: '', + port: 123, + publicKey: '', + version: 456, + roles: RolesTypeEnum.NUMBER_1, + }; + + when(nodeRoutesApi.getNodeInfo()).thenReturn(Promise.resolve(body)); const networkType = await networkRepository.getNetworkType().toPromise(); expect(networkType).to.be.equals(NetworkType.MIJIN_TEST); }); it('getNetworkName', async () => { - const body = new NetworkTypeDTO(); - body.name = 'Some Name'; - body.description = 'Some Description'; + const body: NetworkTypeDTO = { + name: 'Some Name', + description: 'Some Description', + }; - when(networkRoutesApi.getNetworkType()).thenReturn(Promise.resolve({ response, body })); + when(networkRoutesApi.getNetworkType()).thenReturn(Promise.resolve(body)); const networkName = await networkRepository.getNetworkName().toPromise(); expect(networkName.description).to.be.equals(body.description); @@ -120,103 +117,101 @@ describe('NetworkHttp', () => { }); it('getNetworkProperties', async () => { - const body = new NetworkConfigurationDTO(); - - const network = new NetworkPropertiesDTO(); - network.identifier = 'id'; - network.nodeEqualityStrategy = NodeIdentityEqualityStrategy.Host; - network.nemesisSignerPublicKey = 'pubKey'; - network.generationHashSeed = 'genHash'; - network.epochAdjustment = '123456'; - - const chain = new ChainPropertiesDTO(); - chain.blockGenerationTargetTime = '1'; - chain.blockPruneInterval = '1'; - chain.blockTimeSmoothingFactor = '1'; - chain.currencyMosaicId = '1111111111111111'; - chain.defaultDynamicFeeMultiplier = '1'; - chain.enableVerifiableReceipts = true; - chain.enableVerifiableState = true; - chain.harvestBeneficiaryPercentage = '1'; - chain.harvestingMosaicId = '2222222222222222'; - chain.importanceActivityPercentage = '1'; - chain.importanceGrouping = '1'; - chain.initialCurrencyAtomicUnits = '1'; - chain.maxBlockFutureTime = '1'; - chain.maxDifficultyBlocks = '1'; - chain.maxHarvesterBalance = '1'; - chain.maxMosaicAtomicUnits = '1'; - chain.maxRollbackBlocks = '1'; - chain.maxTransactionLifetime = '1'; - chain.maxTransactionsPerBlock = '1'; - chain.minHarvesterBalance = '1'; - chain.totalChainImportance = '1'; - chain.harvestNetworkPercentage = '1'; - chain.harvestNetworkFeeSinkAddress = 'key'; - chain.blockFinalizationInterval = '1'; - chain.minVoterBalance = '1'; - - const plugin = new PluginsPropertiesDTO(); - plugin.accountlink = new AccountKeyLinkNetworkPropertiesDTO(); - plugin.accountlink.dummy = 'dummy'; - - plugin.aggregate = new AggregateNetworkPropertiesDTO(); - plugin.aggregate.enableBondedAggregateSupport = true; - plugin.aggregate.enableStrictCosignatureCheck = true; - plugin.aggregate.maxBondedTransactionLifetime = '1'; - plugin.aggregate.maxCosignaturesPerAggregate = '1'; - plugin.aggregate.maxTransactionsPerAggregate = '1'; - - plugin.lockhash = new HashLockNetworkPropertiesDTO(); - plugin.lockhash.lockedFundsPerAggregate = '1'; - plugin.lockhash.maxHashLockDuration = '1'; - - plugin.locksecret = new SecretLockNetworkPropertiesDTO(); - plugin.locksecret.maxProofSize = '1'; - plugin.locksecret.maxSecretLockDuration = '1'; - plugin.locksecret.minProofSize = '1'; - - plugin.metadata = new MetadataNetworkPropertiesDTO(); - plugin.metadata.maxValueSize = '1'; - - plugin.mosaic = new MosaicNetworkPropertiesDTO(); - plugin.mosaic.maxMosaicDivisibility = '1'; - plugin.mosaic.maxMosaicDuration = '1'; - plugin.mosaic.maxMosaicsPerAccount = '1'; - plugin.mosaic.mosaicRentalFee = '1'; - plugin.mosaic.mosaicRentalFeeSinkAddress = '1'; - - plugin.multisig = new MultisigNetworkPropertiesDTO(); - plugin.multisig.maxCosignatoriesPerAccount = '1'; - plugin.multisig.maxCosignedAccountsPerAccount = '1'; - plugin.multisig.maxMultisigDepth = '1'; - - plugin.namespace = new NamespaceNetworkPropertiesDTO(); - plugin.namespace.childNamespaceRentalFee = '1'; - plugin.namespace.maxChildNamespaces = '1'; - plugin.namespace.maxNameSize = '1'; - plugin.namespace.maxNamespaceDepth = '1'; - plugin.namespace.maxNamespaceDuration = '1'; - plugin.namespace.minNamespaceDuration = '1'; - plugin.namespace.namespaceGracePeriodDuration = '1'; - plugin.namespace.namespaceRentalFeeSinkAddress = '1'; - plugin.namespace.reservedRootNamespaceNames = '1'; - plugin.namespace.rootNamespaceRentalFeePerBlock = '1'; - - plugin.restrictionaccount = new AccountRestrictionNetworkPropertiesDTO(); - plugin.restrictionaccount.maxAccountRestrictionValues = '1'; - - plugin.restrictionmosaic = new MosaicRestrictionNetworkPropertiesDTO(); - plugin.restrictionmosaic.maxMosaicRestrictionValues = '1'; - - plugin.transfer = new TransferNetworkPropertiesDTO(); - plugin.transfer.maxMessageSize = '1'; - - body.chain = chain; - body.network = network; - body.plugins = plugin; - - when(networkRoutesApi.getNetworkProperties()).thenReturn(Promise.resolve({ response, body })); + const body: NetworkConfigurationDTO = { + network: { + identifier: 'public-test', + nodeEqualityStrategy: NodeIdentityEqualityStrategy.PublicKey, + nemesisSignerPublicKey: 'E3F04CA92250B49679EBEF98FAC87C1CECAC7E7491ECBB2307DF1AD65BED57FD', + generationHashSeed: 'AE6488282F9C09457F017BE5EE26387B21EB15CF32D6DA1E9846C25E00828329', + epochAdjustment: '1573430400s', + }, + chain: { + enableVerifiableState: true, + enableVerifiableReceipts: true, + currencyMosaicId: "0x62EF'46FD'6555'A1B9", + harvestingMosaicId: "0x567D'9154'316B'C2AF", + blockFinalizationInterval: 'abc', + blockGenerationTargetTime: '15s', + blockTimeSmoothingFactor: '3000', + importanceGrouping: '1433', + importanceActivityPercentage: '5', + maxRollbackBlocks: '1433', + maxDifficultyBlocks: '60', + defaultDynamicFeeMultiplier: "1'000", + maxTransactionLifetime: '24h', + maxBlockFutureTime: '500ms', + initialCurrencyAtomicUnits: "8'998'999'998'000'000", + maxMosaicAtomicUnits: "9'000'000'000'000'000", + totalChainImportance: "15'000'000", + minHarvesterBalance: '500', + minVoterBalance: '500', + maxHarvesterBalance: "50'000'000'000'000", + harvestBeneficiaryPercentage: '10', + harvestNetworkPercentage: '5', + harvestNetworkFeeSinkAddress: 'FF5563F1C5824EE0CD868799FBE8744B46D5549973FDA499939C952D951494E4', + blockPruneInterval: '360', + maxTransactionsPerBlock: "6'000", + }, + plugins: { + accountlink: { + dummy: 'to trigger plugin load', + }, + aggregate: { + maxTransactionsPerAggregate: "1'000", + maxCosignaturesPerAggregate: '25', + enableStrictCosignatureCheck: false, + enableBondedAggregateSupport: true, + maxBondedTransactionLifetime: '48h', + }, + lockhash: { + lockedFundsPerAggregate: "10'000'000", + maxHashLockDuration: '2d', + }, + locksecret: { + maxSecretLockDuration: '30d', + minProofSize: '1', + maxProofSize: '1000', + }, + metadata: { + maxValueSize: '1024', + }, + mosaic: { + maxMosaicsPerAccount: "1'000", + maxMosaicDuration: '3650d', + maxMosaicDivisibility: '6', + mosaicRentalFeeSinkAddress: '53E140B5947F104CABC2D6FE8BAEDBC30EF9A0609C717D9613DE593EC2A266D3', + mosaicRentalFee: '500', + }, + multisig: { + maxMultisigDepth: '3', + maxCosignatoriesPerAccount: '25', + maxCosignedAccountsPerAccount: '25', + }, + namespace: { + maxNameSize: '64', + maxChildNamespaces: '256', + maxNamespaceDepth: '3', + minNamespaceDuration: '1m', + maxNamespaceDuration: '365d', + namespaceGracePeriodDuration: '30d', + reservedRootNamespaceNames: 'xem, nem, user, account, org, com, biz, net, edu, mil, gov, info', + namespaceRentalFeeSinkAddress: '3E82E1C1E4A75ADAA3CBA8C101C3CD31D9817A2EB966EB3B511FB2ED45B8E262', + rootNamespaceRentalFeePerBlock: '1', + childNamespaceRentalFee: '100', + }, + restrictionaccount: { + maxAccountRestrictionValues: '512', + }, + restrictionmosaic: { + maxMosaicRestrictionValues: '20', + }, + transfer: { + maxMessageSize: '1024', + }, + }, + }; + + when(networkRoutesApi.getNetworkProperties()).thenReturn(Promise.resolve(body)); const networkProperties = await networkRepository.getNetworkProperties().toPromise(); deepEqual(networkProperties.network, body.network); @@ -226,7 +221,7 @@ describe('NetworkHttp', () => { it('getNetworkProperties - using rest json payload', async () => { const body = testResources.getDummyNetworkProperties(); - when(networkRoutesApi.getNetworkProperties()).thenReturn(Promise.resolve({ response, body })); + when(networkRoutesApi.getNetworkProperties()).thenReturn(Promise.resolve(body)); const networkProperties = await networkRepository.getNetworkProperties().toPromise(); deepEqual(networkProperties.network, body.network); deepEqual(networkProperties.chain, body.chain); diff --git a/test/infrastructure/NodeHttp.spec.ts b/test/infrastructure/NodeHttp.spec.ts index 0a55ecebb4..ef9d8c08d5 100644 --- a/test/infrastructure/NodeHttp.spec.ts +++ b/test/infrastructure/NodeHttp.spec.ts @@ -27,7 +27,7 @@ import { ServerDTO, ServerInfoDTO, StorageInfoDTO, -} from 'symbol-openapi-typescript-node-client'; +} from 'symbol-openapi-typescript-fetch-client'; import { instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; import { NodeHttp } from '../../src/infrastructure/NodeHttp'; @@ -45,12 +45,12 @@ describe('NodeHttp', () => { }); it('getNodeHealth', async () => { - const body = new NodeHealthInfoDTO(); - body.status = new NodeHealthDTO(); + const body = {} as NodeHealthInfoDTO; + body.status = {} as NodeHealthDTO; body.status.apiNode = NodeStatusEnum.Down; body.status.db = NodeStatusEnum.Up; - when(nodeRoutesApi.getNodeHealth()).thenReturn(Promise.resolve({ response, body })); + when(nodeRoutesApi.getNodeHealth()).thenReturn(Promise.resolve(body)); const nodeHealth = await nodeRepository.getNodeHealth().toPromise(); expect(nodeHealth).to.be.not.null; @@ -59,12 +59,12 @@ describe('NodeHttp', () => { }); it('getServerInfo', async () => { - const body = new ServerInfoDTO(); - body.serverInfo = new ServerDTO(); + const body = {} as ServerInfoDTO; + body.serverInfo = {} as ServerDTO; body.serverInfo.restVersion = 'Some Rest Version'; body.serverInfo.sdkVersion = 'Some SDK Version'; - when(nodeRoutesApi.getServerInfo()).thenReturn(Promise.resolve({ response, body })); + when(nodeRoutesApi.getServerInfo()).thenReturn(Promise.resolve(body)); const serverInfo = await nodeRepository.getServerInfo().toPromise(); expect(serverInfo).to.be.not.null; @@ -73,7 +73,7 @@ describe('NodeHttp', () => { }); it('getNodeInfo', async () => { - const body = new NodeInfoDTO(); + const body = {} as NodeInfoDTO; body.networkIdentifier = NetworkType.TEST_NET; body.friendlyName = 'Some Friendly name'; body.networkGenerationHashSeed = 'Some Gen Hash'; @@ -83,7 +83,7 @@ describe('NodeHttp', () => { body.roles = RolesTypeEnum.NUMBER_1; body.version = 4567; - when(nodeRoutesApi.getNodeInfo()).thenReturn(Promise.resolve({ response, body })); + when(nodeRoutesApi.getNodeInfo()).thenReturn(Promise.resolve(body)); const nodeInfo = await nodeRepository.getNodeInfo().toPromise(); expect(nodeInfo).to.be.not.null; @@ -91,7 +91,7 @@ describe('NodeHttp', () => { }); it('getNodePeers', async () => { - const body = new NodeInfoDTO(); + const body = {} as NodeInfoDTO; body.networkIdentifier = NetworkType.TEST_NET; body.friendlyName = 'Some Friendly name'; body.networkGenerationHashSeed = 'Some Gen Hash'; @@ -101,7 +101,7 @@ describe('NodeHttp', () => { body.roles = RolesTypeEnum.NUMBER_1; body.version = 4567; - when(nodeRoutesApi.getNodePeers()).thenReturn(Promise.resolve({ response, body: [body] })); + when(nodeRoutesApi.getNodePeers()).thenReturn(Promise.resolve([body])); const nodeInfoList = await nodeRepository.getNodePeers().toPromise(); const nodeInfo = nodeInfoList[0]; @@ -110,12 +110,12 @@ describe('NodeHttp', () => { }); it('getNodeTime', async () => { - const body = new NodeTimeDTO(); - body.communicationTimestamps = new CommunicationTimestampsDTO(); + const body = {} as NodeTimeDTO; + body.communicationTimestamps = {} as CommunicationTimestampsDTO; body.communicationTimestamps.receiveTimestamp = '1111'; body.communicationTimestamps.sendTimestamp = '2222'; - when(nodeRoutesApi.getNodeTime()).thenReturn(Promise.resolve({ response, body })); + when(nodeRoutesApi.getNodeTime()).thenReturn(Promise.resolve(body)); const nodeTime = await nodeRepository.getNodeTime().toPromise(); expect(nodeTime).to.be.not.null; @@ -126,11 +126,11 @@ describe('NodeHttp', () => { }); it('getNodeTim When No Timestamp', async () => { - const body = new NodeTimeDTO(); - body.communicationTimestamps = new CommunicationTimestampsDTO(); + const body = {} as NodeTimeDTO; + body.communicationTimestamps = {} as CommunicationTimestampsDTO; body.communicationTimestamps.receiveTimestamp = '1111'; - when(nodeRoutesApi.getNodeTime()).thenReturn(Promise.resolve({ response, body })); + when(nodeRoutesApi.getNodeTime()).thenReturn(Promise.resolve(body)); try { await nodeRepository.getNodeTime().toPromise(); @@ -140,29 +140,53 @@ describe('NodeHttp', () => { }); it('getStorageInfo', async () => { - const body = new StorageInfoDTO(); + const body = {} as StorageInfoDTO; body.numAccounts = 1; body.numBlocks = 2; body.numTransactions = 3; - when(nodeRoutesApi.getNodeStorage()).thenReturn(Promise.resolve({ response, body })); + when(nodeRoutesApi.getNodeStorage()).thenReturn(Promise.resolve(body)); const storageInfo = await nodeRepository.getStorageInfo().toPromise(); expect(storageInfo).to.deep.equals(body); }); - it('getStorageInfo on Exception', async () => { + it('getStorageInfo on Exception on response body text', async () => { when(nodeRoutesApi.getNodeStorage()).thenReturn( Promise.reject({ response: { statusCode: 500, statusMessage: 'Some Error', body: 'The Body' }, }), ); + try { + await nodeRepository.getStorageInfo().toPromise(); + } catch (e) { + expect(e.message).to.deep.equals('{"statusCode":500,"statusMessage":"Some Error","body":"The Body"}'); + } + }); + + it('getStorageInfo on Exception on response body object', async () => { + when(nodeRoutesApi.getNodeStorage()).thenReturn( + Promise.reject({ + response: { statusCode: 500, statusMessage: 'Some Error', body: { someResponse: 'the body' } }, + }), + ); try { await nodeRepository.getStorageInfo().toPromise(); } catch (e) { expect(e.message).to.deep.equals( - '{"statusCode":500,"errorDetails":{"statusCode":500,"statusMessage":"Some Error"},"body":"The Body"}', + '{"statusCode":500,"statusMessage":"Some Error","body":"{\\"someResponse\\":\\"the body\\"}"}', ); } }); + + it('getStorageInfo on Exception on fetch response text function', async () => { + when(nodeRoutesApi.getNodeStorage()).thenReturn( + Promise.reject({ status: 500, statusText: 'Some Error', text: () => Promise.resolve('Some body text') }), + ); + try { + await nodeRepository.getStorageInfo().toPromise(); + } catch (e) { + expect(e.message).to.deep.equals('{"statusCode":500,"statusMessage":"Some Error","body":"Some body text"}'); + } + }); }); diff --git a/test/infrastructure/Page.spec.ts b/test/infrastructure/Page.spec.ts index 44bd4ae5f1..0894284b74 100644 --- a/test/infrastructure/Page.spec.ts +++ b/test/infrastructure/Page.spec.ts @@ -16,12 +16,12 @@ import { expect } from 'chai'; import { Page } from '../../src/infrastructure/infrastructure'; +import { PlainMessage } from '../../src/model/message/PlainMessage'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { Deadline } from '../../src/model/transaction/Deadline'; import { Transaction } from '../../src/model/transaction/Transaction'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { TestingAccount } from '../conf/conf.spec'; -import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { Deadline } from '../../src/model/transaction/Deadline'; -import { NetworkType } from '../../src/model/network/NetworkType'; describe('Page', () => { it('should create Page', () => { diff --git a/test/infrastructure/QueryParams.spec.ts b/test/infrastructure/QueryParams.spec.ts index 664c0e6c2f..cddad848e9 100644 --- a/test/infrastructure/QueryParams.spec.ts +++ b/test/infrastructure/QueryParams.spec.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { QueryParams } from '../../src/infrastructure/QueryParams'; import { expect } from 'chai'; +import { QueryParams } from '../../src/infrastructure/QueryParams'; import { Order } from '../../src/infrastructure/searchCriteria/Order'; describe('QueryParams', () => { diff --git a/test/infrastructure/ReceiptHttp.spec.ts b/test/infrastructure/ReceiptHttp.spec.ts index 031713a03f..5a4af9c771 100644 --- a/test/infrastructure/ReceiptHttp.spec.ts +++ b/test/infrastructure/ReceiptHttp.spec.ts @@ -16,22 +16,22 @@ import { expect } from 'chai'; import * as http from 'http'; import { - AccountRestrictionsDTO, + AccountRestrictionDTO, AccountRestrictionFlagsEnum, + AccountRestrictionsDTO, AccountRestrictionsInfoDTO, - AccountRestrictionDTO, - ReceiptRoutesApi, - StatementsDTO, - MerkleProofInfoDTO, MerklePathItemDTO, + MerkleProofInfoDTO, PositionEnum, -} from 'symbol-openapi-typescript-node-client'; + ReceiptRoutesApi, + StatementsDTO, +} from 'symbol-openapi-typescript-fetch-client'; import { instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; -import { NetworkType } from '../../src/model/network/NetworkType'; -import { PublicAccount } from '../../src/model/account/PublicAccount'; import { ReceiptHttp } from '../../src/infrastructure/ReceiptHttp'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; import { UInt64 } from '../../src/model/model'; +import { NetworkType } from '../../src/model/network/NetworkType'; describe('ReceiptHttp', () => { const publicAccount = PublicAccount.createFromPublicKey( @@ -46,9 +46,9 @@ describe('ReceiptHttp', () => { receiptRoutesApi: instance(receiptRoutesApi), }); - const restrictionInfo = new AccountRestrictionsInfoDTO(); - const restrictionsDto = new AccountRestrictionsDTO(); - const restriction = new AccountRestrictionDTO(); + const restrictionInfo = {} as AccountRestrictionsInfoDTO; + const restrictionsDto = {} as AccountRestrictionsDTO; + const restriction = {} as AccountRestrictionDTO; restriction.restrictionFlags = AccountRestrictionFlagsEnum.NUMBER_1; restriction.values = [address.encoded()]; restrictionsDto.restrictions = [restriction]; @@ -62,12 +62,12 @@ describe('ReceiptHttp', () => { }); it('getBlockReceipt', async () => { - const statementDto = new StatementsDTO(); + const statementDto = {} as StatementsDTO; statementDto.addressResolutionStatements = []; statementDto.transactionStatements = []; statementDto.mosaicResolutionStatements = []; - when(receiptRoutesApi.getBlockReceipts('1')).thenReturn(Promise.resolve({ response, body: statementDto })); + when(receiptRoutesApi.getBlockReceipts('1')).thenReturn(Promise.resolve(statementDto)); const statement = await receiptRepository.getBlockReceipts(UInt64.fromUint(1)).toPromise(); expect(statement).to.be.not.null; @@ -77,13 +77,13 @@ describe('ReceiptHttp', () => { }); it('getMerkleReceipts', async () => { - const merkleProofInfoDto = new MerkleProofInfoDTO(); - const merklePathDto = new MerklePathItemDTO(); + const merkleProofInfoDto = {} as MerkleProofInfoDTO; + const merklePathDto = {} as MerklePathItemDTO; merklePathDto.hash = 'merkleHash'; merklePathDto.position = PositionEnum.Left; merkleProofInfoDto.merklePath = [merklePathDto]; - when(receiptRoutesApi.getMerkleReceipts('1', 'Hash')).thenReturn(Promise.resolve({ response, body: merkleProofInfoDto })); + when(receiptRoutesApi.getMerkleReceipts('1', 'Hash')).thenReturn(Promise.resolve(merkleProofInfoDto)); const proof = await receiptRepository.getMerkleReceipts(UInt64.fromUint(1), 'Hash').toPromise(); expect(proof).to.be.not.null; diff --git a/test/infrastructure/RepositoryFactory.spec.ts b/test/infrastructure/RepositoryFactory.spec.ts index a8a042a792..7cb716ded4 100644 --- a/test/infrastructure/RepositoryFactory.spec.ts +++ b/test/infrastructure/RepositoryFactory.spec.ts @@ -17,12 +17,6 @@ import { expect } from 'chai'; import { of as observableOf } from 'rxjs'; import { map } from 'rxjs/operators'; import { instance, mock, when } from 'ts-mockito'; -import { NetworkRepository } from '../../src/infrastructure/NetworkRepository'; -import { RepositoryFactoryHttp } from '../../src/infrastructure/RepositoryFactoryHttp'; -import { NetworkType } from '../../src/model/network/NetworkType'; -import { NodeRepository } from '../../src/infrastructure/NodeRepository'; -import { NodeInfo } from '../../src/model/node/NodeInfo'; -import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { AccountHttp } from '../../src/infrastructure/AccountHttp'; import { BlockHttp } from '../../src/infrastructure/BlockHttp'; import { ChainHttp } from '../../src/infrastructure/ChainHttp'; @@ -31,13 +25,19 @@ import { MetadataHttp } from '../../src/infrastructure/MetadataHttp'; import { MosaicHttp } from '../../src/infrastructure/MosaicHttp'; import { MultisigHttp } from '../../src/infrastructure/MultisigHttp'; import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp'; +import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { NetworkHttp } from '../../src/infrastructure/NetworkHttp'; +import { NetworkRepository } from '../../src/infrastructure/NetworkRepository'; import { NodeHttp } from '../../src/infrastructure/NodeHttp'; +import { NodeRepository } from '../../src/infrastructure/NodeRepository'; import { ReceiptHttp } from '../../src/infrastructure/ReceiptHttp'; +import { RepositoryFactoryHttp } from '../../src/infrastructure/RepositoryFactoryHttp'; import { RestrictionAccountHttp } from '../../src/infrastructure/RestrictionAccountHttp'; import { RestrictionMosaicHttp } from '../../src/infrastructure/RestrictionMosaicHttp'; import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; import { TransactionStatusHttp } from '../../src/infrastructure/TransactionStatusHttp'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { NodeInfo } from '../../src/model/node/NodeInfo'; describe('RepositoryFactory', () => { it('Should create repositories', () => { diff --git a/test/infrastructure/RestrictionAccountHttp.spec.ts b/test/infrastructure/RestrictionAccountHttp.spec.ts index db3279cfbf..06b9345cb6 100644 --- a/test/infrastructure/RestrictionAccountHttp.spec.ts +++ b/test/infrastructure/RestrictionAccountHttp.spec.ts @@ -16,18 +16,18 @@ import { expect } from 'chai'; import * as http from 'http'; import { - AccountRestrictionsDTO, + AccountRestrictionDTO, AccountRestrictionFlagsEnum, + AccountRestrictionsDTO, AccountRestrictionsInfoDTO, - AccountRestrictionDTO, -} from 'symbol-openapi-typescript-node-client'; -import { instance, mock, reset, when, deepEqual } from 'ts-mockito'; + RestrictionAccountRoutesApi, +} from 'symbol-openapi-typescript-fetch-client'; +import { deepEqual, instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; -import { NetworkType } from '../../src/model/network/NetworkType'; -import { RestrictionAccountRoutesApi } from 'symbol-openapi-typescript-node-client'; -import { PublicAccount } from '../../src/model/account/PublicAccount'; import { RestrictionAccountHttp } from '../../src/infrastructure/RestrictionAccountHttp'; import { Address } from '../../src/model/account/Address'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; +import { NetworkType } from '../../src/model/network/NetworkType'; import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; describe('RestrictionAccountHttp', () => { @@ -43,9 +43,9 @@ describe('RestrictionAccountHttp', () => { restrictionAccountRoutesApi: instance(restrictionAccountRoutesApi), }); - const restrictionInfo = new AccountRestrictionsInfoDTO(); - const restrictionsDto = new AccountRestrictionsDTO(); - const restriction = new AccountRestrictionDTO(); + const restrictionInfo = {} as AccountRestrictionsInfoDTO; + const restrictionsDto = {} as AccountRestrictionsDTO; + const restriction = {} as AccountRestrictionDTO; restriction.restrictionFlags = AccountRestrictionFlagsEnum.NUMBER_1; restriction.values = [address.encoded()]; restrictionsDto.restrictions = [restriction]; @@ -59,9 +59,7 @@ describe('RestrictionAccountHttp', () => { }); it('getAccountRestrictions', async () => { - when(restrictionAccountRoutesApi.getAccountRestrictions(deepEqual(address.plain()))).thenReturn( - Promise.resolve({ response, body: restrictionInfo }), - ); + when(restrictionAccountRoutesApi.getAccountRestrictions(deepEqual(address.plain()))).thenReturn(Promise.resolve(restrictionInfo)); const restrictions = await restrictionAccountRepository.getAccountRestrictions(address).toPromise(); expect(restrictions).to.be.not.null; @@ -72,7 +70,7 @@ describe('RestrictionAccountHttp', () => { it('getAccountRestrictionsFromAccounts', async () => { when(restrictionAccountRoutesApi.getAccountRestrictionsFromAccounts(deepEqual({ addresses: [address.plain()] }))).thenReturn( - Promise.resolve({ response, body: [restrictionInfo] }), + Promise.resolve([restrictionInfo]), ); const restrictions = await restrictionAccountRepository.getAccountRestrictionsFromAccounts([address]).toPromise(); diff --git a/test/infrastructure/RestrictionMosaicHttp.spec.ts b/test/infrastructure/RestrictionMosaicHttp.spec.ts index 261b57d5b6..09f4d217dc 100644 --- a/test/infrastructure/RestrictionMosaicHttp.spec.ts +++ b/test/infrastructure/RestrictionMosaicHttp.spec.ts @@ -16,23 +16,23 @@ import { expect } from 'chai'; import * as http from 'http'; import { - RestrictionMosaicRoutesApi, MosaicAddressRestrictionDTO, - MosaicAddressRestrictionEntryWrapperDTO, MosaicAddressRestrictionEntryDTO, - MosaicRestrictionEntryTypeEnum, + MosaicAddressRestrictionEntryWrapperDTO, MosaicGlobalRestrictionDTO, MosaicGlobalRestrictionEntryDTO, - MosaicGlobalRestrictionEntryWrapperDTO, MosaicGlobalRestrictionEntryRestrictionDTO, + MosaicGlobalRestrictionEntryWrapperDTO, + MosaicRestrictionEntryTypeEnum, MosaicRestrictionTypeEnum, -} from 'symbol-openapi-typescript-node-client'; -import { instance, mock, reset, when, deepEqual } from 'ts-mockito'; + RestrictionMosaicRoutesApi, +} from 'symbol-openapi-typescript-fetch-client'; +import { deepEqual, instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; -import { NetworkType } from '../../src/model/network/NetworkType'; -import { PublicAccount } from '../../src/model/account/PublicAccount'; import { RestrictionMosaicHttp } from '../../src/infrastructure/RestrictionMosaicHttp'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; +import { NetworkType } from '../../src/model/network/NetworkType'; describe('RestrictionMosaicHttp', () => { const publicAccount = PublicAccount.createFromPublicKey( @@ -48,9 +48,9 @@ describe('RestrictionMosaicHttp', () => { restrictionMosaicRoutesApi: instance(restrictionMosaicRoutesApi), }); - const mosaicAddressRestrictionDto = new MosaicAddressRestrictionDTO(); - const mosaicAddressRestrictionEntryWrapperDto = new MosaicAddressRestrictionEntryWrapperDTO(); - const mosaicAddressRestrictionEntryDto = new MosaicAddressRestrictionEntryDTO(); + const mosaicAddressRestrictionDto = {} as MosaicAddressRestrictionDTO; + const mosaicAddressRestrictionEntryWrapperDto = {} as MosaicAddressRestrictionEntryWrapperDTO; + const mosaicAddressRestrictionEntryDto = {} as MosaicAddressRestrictionEntryDTO; mosaicAddressRestrictionEntryDto.key = 'key'; mosaicAddressRestrictionEntryDto.value = 'value'; @@ -63,10 +63,10 @@ describe('RestrictionMosaicHttp', () => { mosaicAddressRestrictionDto.mosaicRestrictionEntry = mosaicAddressRestrictionEntryWrapperDto; - const mosaicGlobalRestrictionDto = new MosaicGlobalRestrictionDTO(); - const mosaicGlobalRestrictionEntryWrapperDto = new MosaicGlobalRestrictionEntryWrapperDTO(); - const mosaicGlobalRestrictionEntryDto = new MosaicGlobalRestrictionEntryDTO(); - const mosaicGlobalRestrictionEntryRestrictionDto = new MosaicGlobalRestrictionEntryRestrictionDTO(); + const mosaicGlobalRestrictionDto = {} as MosaicGlobalRestrictionDTO; + const mosaicGlobalRestrictionEntryWrapperDto = {} as MosaicGlobalRestrictionEntryWrapperDTO; + const mosaicGlobalRestrictionEntryDto = {} as MosaicGlobalRestrictionEntryDTO; + const mosaicGlobalRestrictionEntryRestrictionDto = {} as MosaicGlobalRestrictionEntryRestrictionDTO; mosaicGlobalRestrictionEntryRestrictionDto.referenceMosaicId = mosaicId.toHex(); mosaicGlobalRestrictionEntryRestrictionDto.restrictionType = MosaicRestrictionTypeEnum.NUMBER_0; mosaicGlobalRestrictionEntryRestrictionDto.restrictionValue = 'value'; @@ -87,7 +87,7 @@ describe('RestrictionMosaicHttp', () => { it('getMosaicAddressRestriction', async () => { when(restrictionMosaicRoutesApi.getMosaicAddressRestriction(mosaicId.toHex(), address.plain())).thenReturn( - Promise.resolve({ response, body: mosaicAddressRestrictionDto }), + Promise.resolve(mosaicAddressRestrictionDto), ); const restrictions = await restrictionMosaicRepository.getMosaicAddressRestriction(mosaicId, address).toPromise(); @@ -102,7 +102,7 @@ describe('RestrictionMosaicHttp', () => { it('getMosaicAddressRestrictions', async () => { when( restrictionMosaicRoutesApi.getMosaicAddressRestrictions(mosaicId.toHex(), deepEqual({ addresses: [address.plain()] })), - ).thenReturn(Promise.resolve({ response, body: [mosaicAddressRestrictionDto] })); + ).thenReturn(Promise.resolve([mosaicAddressRestrictionDto])); const restrictions = await restrictionMosaicRepository.getMosaicAddressRestrictions(mosaicId, [address]).toPromise(); expect(restrictions).to.be.not.null; @@ -115,7 +115,7 @@ describe('RestrictionMosaicHttp', () => { it('getMosaicGlobalRestriction', async () => { when(restrictionMosaicRoutesApi.getMosaicGlobalRestriction(mosaicId.toHex())).thenReturn( - Promise.resolve({ response, body: mosaicGlobalRestrictionDto }), + Promise.resolve(mosaicGlobalRestrictionDto), ); const restrictions = await restrictionMosaicRepository.getMosaicGlobalRestriction(mosaicId).toPromise(); @@ -128,7 +128,7 @@ describe('RestrictionMosaicHttp', () => { it('getMosaicGlobalRestrictions', async () => { when(restrictionMosaicRoutesApi.getMosaicGlobalRestrictions(deepEqual({ mosaicIds: [mosaicId.toHex()] }))).thenReturn( - Promise.resolve({ response, body: [mosaicGlobalRestrictionDto] }), + Promise.resolve([mosaicGlobalRestrictionDto]), ); const restrictions = await restrictionMosaicRepository.getMosaicGlobalRestrictions([mosaicId]).toPromise(); diff --git a/test/infrastructure/SearchCriteria.spec.ts b/test/infrastructure/SearchCriteria.spec.ts index 40369ba9ae..bf81401cc7 100644 --- a/test/infrastructure/SearchCriteria.spec.ts +++ b/test/infrastructure/SearchCriteria.spec.ts @@ -15,8 +15,8 @@ */ import { expect } from 'chai'; -import { SearchCriteria } from '../../src/infrastructure/searchCriteria/SearchCriteria'; import { Order } from '../../src/infrastructure/searchCriteria/Order'; +import { SearchCriteria } from '../../src/infrastructure/searchCriteria/SearchCriteria'; describe('SearchCriteria', () => { it('should create SearchCriteria', () => { diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f9b5e9416..9cba33dbea 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -16,6 +16,7 @@ import { expect } from 'chai'; import { sha3_256 } from 'js-sha3'; +import { Crypto } from '../../src/core/crypto'; import { Convert as convert, Convert } from '../../src/core/format'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; @@ -28,32 +29,31 @@ import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLoca import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { NetworkType } from '../../src/model/network/NetworkType'; +import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; +import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestrictionFlag'; +import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag'; import { AccountKeyLinkTransaction } from '../../src/model/transaction/AccountKeyLinkTransaction'; import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; -import { LockHashAlgorithm } from '../../src/model/transaction/LockHashAlgorithm'; import { LinkAction } from '../../src/model/transaction/LinkAction'; import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTransaction'; +import { LockHashAlgorithm } from '../../src/model/transaction/LockHashAlgorithm'; import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction'; import { MosaicSupplyChangeTransaction } from '../../src/model/transaction/MosaicSupplyChangeTransaction'; import { MultisigAccountModificationTransaction } from '../../src/model/transaction/MultisigAccountModificationTransaction'; import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction'; +import { NodeKeyLinkTransaction } from '../../src/model/transaction/NodeKeyLinkTransaction'; import { SecretLockTransaction } from '../../src/model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../src/model/transaction/SecretProofTransaction'; import { TransactionType } from '../../src/model/transaction/TransactionType'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; -import { UInt64 } from '../../src/model/UInt64'; -import { TestingAccount } from '../conf/conf.spec'; -import { Crypto } from '../../src/core/crypto'; import { VotingKeyLinkTransaction } from '../../src/model/transaction/VotingKeyLinkTransaction'; import { VrfKeyLinkTransaction } from '../../src/model/transaction/VrfKeyLinkTransaction'; -import { NodeKeyLinkTransaction } from '../../src/model/transaction/NodeKeyLinkTransaction'; -import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; -import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestrictionFlag'; -import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag'; +import { UInt64 } from '../../src/model/UInt64'; +import { TestingAccount } from '../conf/conf.spec'; describe('SerializeTransactionToJSON', () => { let account: Account; diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 4cb6dd1746..99eedefa8e 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -15,47 +15,45 @@ */ import { expect } from 'chai'; -import http = require('http'); import { - BlockRoutesApi, - TransactionRoutesApi, - TransactionPage, - TransactionMetaDTO, - Pagination, - TransferTransactionDTO, - NetworkTypeEnum, - TransactionInfoDTO, BlockDTO, - BlockMetaDTO, BlockInfoDTO, - AnnounceTransactionInfoDTO, + BlockMetaDTO, + BlockRoutesApi, Cosignature, -} from 'symbol-openapi-typescript-node-client'; + HTTPQuery, + NetworkTypeEnum, + Pagination, + TransactionInfoDTO, + TransactionMetaDTO, + TransactionPage, + TransactionRoutesApi, + TransferTransactionDTO, +} from 'symbol-openapi-typescript-fetch-client'; import { deepEqual, instance, mock, when } from 'ts-mockito'; +import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; import { Address } from '../../src/model/account/Address'; import { PlainMessage } from '../../src/model/message/PlainMessage'; import { NetworkType } from '../../src/model/network/NetworkType'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; +import { CosignatureSignedTransaction } from '../../src/model/transaction/CosignatureSignedTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; -import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; -import { NIS2_URL, TestingAccount } from '../conf/conf.spec'; import { TransactionType } from '../../src/model/transaction/TransactionType'; -import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; +import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../src/model/UInt64'; -import { CosignatureSignedTransaction } from '../../src/model/transaction/CosignatureSignedTransaction'; +import { NIS2_URL, TestingAccount } from '../conf/conf.spec'; describe('TransactionHttp', () => { const account = TestingAccount; const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; - let clientResponse: http.ClientResponse; let transactionRoutesApi: TransactionRoutesApi; let transactionHttp: TransactionHttp; let blockRoutesApi: BlockRoutesApi; - const cosignature = new Cosignature(); + const cosignature = {} as Cosignature; cosignature.parentHash = 'parentHash'; cosignature.signerPublicKey = 'signerPubKey'; cosignature.signature = 'signature'; @@ -64,7 +62,6 @@ describe('TransactionHttp', () => { before(() => { transactionRoutesApi = mock(); blockRoutesApi = mock(); - clientResponse = mock(); transactionHttp = new TransactionHttp(NIS2_URL); (transactionHttp as object)['transactionRoutesApi'] = instance(transactionRoutesApi); (transactionHttp as object)['blockRoutesApi'] = instance(blockRoutesApi); @@ -93,21 +90,21 @@ describe('TransactionHttp', () => { }); it('Test searchTransaction method', async () => { - const page = new TransactionPage(); - const paginationDto = new Pagination(); + const page = {} as TransactionPage; + const paginationDto = {} as Pagination; paginationDto.pageNumber = 1; paginationDto.pageSize = 1; paginationDto.totalEntries = 1; paginationDto.totalPages = 1; - const transactionInfoDto = new TransactionInfoDTO(); - const metaDto = new TransactionMetaDTO(); + const transactionInfoDto = {} as TransactionInfoDTO; + const metaDto = {} as TransactionMetaDTO; metaDto.hash = 'hash'; metaDto.height = '1'; metaDto.index = 0; metaDto.merkleComponentHash = 'merkleHash'; - const transactionDto = new TransferTransactionDTO(); + const transactionDto = {} as TransferTransactionDTO; transactionDto.deadline = '1'; transactionDto.maxFee = '1'; transactionDto.mosaics = []; @@ -136,7 +133,7 @@ describe('TransactionHttp', () => { undefined, undefined, ), - ).thenReturn(Promise.resolve({ response: instance(clientResponse), body: page })); + ).thenReturn(Promise.resolve(page)); when( transactionRoutesApi.searchPartialTransactions( @@ -151,7 +148,7 @@ describe('TransactionHttp', () => { undefined, undefined, ), - ).thenReturn(Promise.resolve({ response: instance(clientResponse), body: page })); + ).thenReturn(Promise.resolve(page)); when( transactionRoutesApi.searchUnconfirmedTransactions( @@ -166,7 +163,7 @@ describe('TransactionHttp', () => { undefined, undefined, ), - ).thenReturn(Promise.resolve({ response: instance(clientResponse), body: page })); + ).thenReturn(Promise.resolve(page)); let transactions = await transactionHttp.search({ group: TransactionGroup.Confirmed, address: account.address }).toPromise(); @@ -215,14 +212,14 @@ describe('TransactionHttp', () => { }); it('Test getTransaction method', async () => { - const transactionInfoDto = new TransactionInfoDTO(); - const metaDto = new TransactionMetaDTO(); + const transactionInfoDto = {} as TransactionInfoDTO; + const metaDto = {} as TransactionMetaDTO; metaDto.hash = 'hash'; metaDto.height = '1'; metaDto.index = 0; metaDto.merkleComponentHash = 'merkleHash'; - const transactionDto = new TransferTransactionDTO(); + const transactionDto = {} as TransferTransactionDTO; transactionDto.deadline = '1'; transactionDto.maxFee = '1'; transactionDto.mosaics = []; @@ -235,16 +232,10 @@ describe('TransactionHttp', () => { transactionInfoDto.meta = metaDto; transactionInfoDto.transaction = transactionDto; - when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), - ); + when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReturn(Promise.resolve(transactionInfoDto)); - when(transactionRoutesApi.getPartialTransaction(generationHash)).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), - ); - when(transactionRoutesApi.getUnconfirmedTransaction(generationHash)).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), - ); + when(transactionRoutesApi.getPartialTransaction(generationHash)).thenReturn(Promise.resolve(transactionInfoDto)); + when(transactionRoutesApi.getUnconfirmedTransaction(generationHash)).thenReturn(Promise.resolve(transactionInfoDto)); let transaction = await transactionHttp.getTransaction(generationHash, TransactionGroup.Confirmed).toPromise(); @@ -275,14 +266,14 @@ describe('TransactionHttp', () => { }); it('Test getTransactionsById method', async () => { - const transactionInfoDto = new TransactionInfoDTO(); - const metaDto = new TransactionMetaDTO(); + const transactionInfoDto = {} as TransactionInfoDTO; + const metaDto = {} as TransactionMetaDTO; metaDto.hash = 'hash'; metaDto.height = '1'; metaDto.index = 0; metaDto.merkleComponentHash = 'merkleHash'; - const transactionDto = new TransferTransactionDTO(); + const transactionDto = {} as TransferTransactionDTO; transactionDto.deadline = '1'; transactionDto.maxFee = '1'; transactionDto.mosaics = []; @@ -296,7 +287,7 @@ describe('TransactionHttp', () => { transactionInfoDto.transaction = transactionDto; when(transactionRoutesApi.getTransactionsById(deepEqual({ transactionIds: [generationHash] }))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: [transactionInfoDto] }), + Promise.resolve([transactionInfoDto]), ); const transaction = await transactionHttp.getTransactionsById([generationHash]).toPromise(); @@ -311,14 +302,14 @@ describe('TransactionHttp', () => { }); it('Test getEffectiveFees method', async () => { - const transactionInfoDto = new TransactionInfoDTO(); - const metaDto = new TransactionMetaDTO(); + const transactionInfoDto = {} as TransactionInfoDTO; + const metaDto = {} as TransactionMetaDTO; metaDto.hash = 'hash'; metaDto.height = '1'; metaDto.index = 0; metaDto.merkleComponentHash = 'merkleHash'; - const transactionDto = new TransferTransactionDTO(); + const transactionDto = {} as TransferTransactionDTO; transactionDto.deadline = '1'; transactionDto.maxFee = '1'; transactionDto.mosaics = []; @@ -331,7 +322,7 @@ describe('TransactionHttp', () => { transactionInfoDto.meta = metaDto; transactionInfoDto.transaction = transactionDto; - const blockDTO = new BlockDTO(); + const blockDTO = {} as BlockDTO; blockDTO.version = 1; blockDTO.network = NetworkTypeEnum.NUMBER_152; blockDTO.difficulty = '2'; @@ -346,7 +337,7 @@ describe('TransactionHttp', () => { NetworkType.MIJIN_TEST, ).encoded(); - const blockMetaDTO = new BlockMetaDTO(); + const blockMetaDTO = {} as BlockMetaDTO; blockMetaDTO.generationHash = 'abc'; blockMetaDTO.hash = 'aHash'; blockMetaDTO.numStatements = 10; @@ -354,25 +345,19 @@ describe('TransactionHttp', () => { blockMetaDTO.totalFee = '30'; blockMetaDTO.stateHashSubCacheMerkleRoots = ['a', 'b', 'c']; - const blockInfoDto = new BlockInfoDTO(); + const blockInfoDto = {} as BlockInfoDTO; blockInfoDto.block = blockDTO; blockInfoDto.meta = blockMetaDTO; - when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), - ); - when(blockRoutesApi.getBlockByHeight(deepEqual(UInt64.fromUint(1).toString()))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: blockInfoDto }), - ); + when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReturn(Promise.resolve(transactionInfoDto)); + when(blockRoutesApi.getBlockByHeight(deepEqual(UInt64.fromUint(1).toString()))).thenReturn(Promise.resolve(blockInfoDto)); const fees = await transactionHttp.getTransactionEffectiveFee(generationHash).toPromise(); expect(fees).to.be.equal(483); }); it('Test announce', async () => { - const response = new AnnounceTransactionInfoDTO(); - response.message = 'done'; - + const response = { message: 'done' }; const tx = TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), @@ -383,17 +368,14 @@ describe('TransactionHttp', () => { const signedTx = account.sign(tx, generationHash); - when(transactionRoutesApi.announceTransaction(deepEqual(signedTx))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: response }), - ); + when(transactionRoutesApi.announceTransaction(deepEqual(signedTx))).thenReturn(Promise.resolve(response)); const announceResult = await transactionHttp.announce(signedTx).toPromise(); expect(announceResult.message).to.be.equal(response.message); }); it('Test announceAggregateBonded', async () => { - const response = new AnnounceTransactionInfoDTO(); - response.message = 'done'; + const response = { message: 'done' }; const tx = TransferTransaction.create( Deadline.create(), @@ -412,23 +394,18 @@ describe('TransactionHttp', () => { const signedTx = account.sign(aggTx, generationHash); - when(transactionRoutesApi.announcePartialTransaction(deepEqual(signedTx))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: response }), - ); + when(transactionRoutesApi.announcePartialTransaction(deepEqual(signedTx))).thenReturn(Promise.resolve(response)); const announceResult = await transactionHttp.announceAggregateBonded(signedTx).toPromise(); expect(announceResult.message).to.be.equal(response.message); }); it('Test announceAggregateBonded Cosignatures', async () => { - const response = new AnnounceTransactionInfoDTO(); - response.message = 'done'; + const response = { message: 'done' }; const cosignTx = new CosignatureSignedTransaction('parentHash', 'signature', 'signerPubKey'); - when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignature))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: response }), - ); + when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignature))).thenReturn(Promise.resolve(response)); const announceResult = await transactionHttp.announceAggregateBondedCosignature(cosignTx).toPromise(); expect(announceResult.message).to.be.equal(response.message); @@ -488,9 +465,6 @@ describe('TransactionHttp', () => { }); it('announce - Error', async () => { - const response = new AnnounceTransactionInfoDTO(); - response.message = 'done'; - const tx = TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), @@ -509,8 +483,7 @@ describe('TransactionHttp', () => { }); it('announce - Error', async () => { - const response = new AnnounceTransactionInfoDTO(); - response.message = 'done'; + const response = { message: 'done' }; const tx = TransferTransaction.create( Deadline.create(), @@ -528,13 +501,17 @@ describe('TransactionHttp', () => { ); const signedTx = account.sign(aggTx, generationHash); - when(transactionRoutesApi.announceTransaction(deepEqual(signedTx))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: response }), - ); + when(transactionRoutesApi.announceTransaction(deepEqual(signedTx))).thenReturn(Promise.resolve(response)); try { await transactionHttp.announce(signedTx).toPromise(); } catch (error) { expect(error).not.to.be.undefined; } }); + + it('Test fetch querystring', async () => { + const params: HTTPQuery = { type: [TransactionType.NAMESPACE_REGISTRATION.valueOf(), TransactionType.TRANSFER.valueOf()] }; + const query = transactionHttp.config().queryParamsStringify(params); + expect(query).eq('type=16718&type=16724'); + }); }); diff --git a/test/infrastructure/TransactionSearchCriteria.spec.ts b/test/infrastructure/TransactionSearchCriteria.spec.ts index 1b693caa08..0f0f7ec1b0 100644 --- a/test/infrastructure/TransactionSearchCriteria.spec.ts +++ b/test/infrastructure/TransactionSearchCriteria.spec.ts @@ -14,15 +14,15 @@ * limitations under the License. */ +import { deepEqual } from 'assert'; import { expect } from 'chai'; +import { Order } from '../../src/infrastructure/searchCriteria/Order'; import { TransactionSearchCriteria } from '../../src/infrastructure/searchCriteria/TransactionSearchCriteria'; -import { TestingAccount } from '../conf/conf.spec'; -import { deepEqual } from 'assert'; +import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; +import { Address } from '../../src/model/account/Address'; import { TransactionType } from '../../src/model/transaction/TransactionType'; import { UInt64 } from '../../src/model/UInt64'; -import { Address } from '../../src/model/account/Address'; -import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; -import { Order } from '../../src/infrastructure/searchCriteria/Order'; +import { TestingAccount } from '../conf/conf.spec'; describe('TransactionSearchCriteria', () => { const account = TestingAccount; diff --git a/test/infrastructure/TransactionStatusHttp.spec.ts b/test/infrastructure/TransactionStatusHttp.spec.ts index 801aadb715..0e08ae4620 100644 --- a/test/infrastructure/TransactionStatusHttp.spec.ts +++ b/test/infrastructure/TransactionStatusHttp.spec.ts @@ -15,42 +15,37 @@ */ import { expect } from 'chai'; -import http = require('http'); import { TransactionGroupEnum, TransactionStatusDTO, TransactionStatusEnum, TransactionStatusRoutesApi, -} from 'symbol-openapi-typescript-node-client'; +} from 'symbol-openapi-typescript-fetch-client'; import { deepEqual, instance, mock, when } from 'ts-mockito'; +import { TransactionStatusHttp } from '../../src/infrastructure/TransactionStatusHttp'; import { NIS2_URL } from '../conf/conf.spec'; -import { TransactionStatusHttp } from '../../src/infrastructure/TransactionStatusHttp'; describe('TransactionStatusHttp', () => { - let clientResponse: http.ClientResponse; let transactionStatusRoutesApi: TransactionStatusRoutesApi; let transactionStatusHttp: TransactionStatusHttp; before(() => { transactionStatusRoutesApi = mock(); - clientResponse = mock(); transactionStatusHttp = new TransactionStatusHttp(NIS2_URL); (transactionStatusHttp as object)['transactionStatusRoutesApi'] = instance(transactionStatusRoutesApi); }); it('Test getTransactionStatus method', async () => { const hash = 'abc'; - const transactionStatusDTO = new TransactionStatusDTO(); + const transactionStatusDTO = {} as TransactionStatusDTO; transactionStatusDTO.code = TransactionStatusEnum.FailureAccountLinkInconsistentUnlinkData; transactionStatusDTO.deadline = '1234'; transactionStatusDTO.hash = hash; transactionStatusDTO.group = TransactionGroupEnum.Failed; transactionStatusDTO.height = '567'; - when(transactionStatusRoutesApi.getTransactionStatus(deepEqual(hash))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: transactionStatusDTO }), - ); + when(transactionStatusRoutesApi.getTransactionStatus(deepEqual(hash))).thenReturn(Promise.resolve(transactionStatusDTO)); const transactionStatus = await transactionStatusHttp.getTransactionStatus(hash).toPromise(); @@ -62,14 +57,14 @@ describe('TransactionStatusHttp', () => { it('Test getTransactionsStatuses method', async () => { const hash = 'abc'; - const transactionStatusDTO = new TransactionStatusDTO(); + const transactionStatusDTO = {} as TransactionStatusDTO; transactionStatusDTO.code = TransactionStatusEnum.FailureAccountLinkInconsistentUnlinkData; transactionStatusDTO.deadline = '1234'; transactionStatusDTO.hash = hash; transactionStatusDTO.group = TransactionGroupEnum.Failed; transactionStatusDTO.height = '567'; when(transactionStatusRoutesApi.getTransactionStatuses(deepEqual({ hashes: [hash] }))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: [transactionStatusDTO] }), + Promise.resolve([transactionStatusDTO]), ); const transactionStatuses = await transactionStatusHttp.getTransactionStatuses([hash]).toPromise(); diff --git a/test/infrastructure/streamer/BlockPaginationStreamer.spec.ts b/test/infrastructure/streamer/BlockPaginationStreamer.spec.ts index ee164e494b..544ab63b46 100644 --- a/test/infrastructure/streamer/BlockPaginationStreamer.spec.ts +++ b/test/infrastructure/streamer/BlockPaginationStreamer.spec.ts @@ -15,8 +15,8 @@ */ import { instance, mock } from 'ts-mockito'; -import { BlockPaginationStreamer } from '../../../src/infrastructure/paginationStreamer/BlockPaginationStreamer'; import { BlockRepository } from '../../../src/infrastructure/BlockRepository'; +import { BlockPaginationStreamer } from '../../../src/infrastructure/paginationStreamer/BlockPaginationStreamer'; import { PaginationStreamerTestHelper } from './PaginationStreamerTestHelper'; describe('BlockPaginationStreamer', () => { diff --git a/test/infrastructure/streamer/MosaicPaginationStreamer.spec.ts b/test/infrastructure/streamer/MosaicPaginationStreamer.spec.ts index f2dc3b412d..157400a9e4 100644 --- a/test/infrastructure/streamer/MosaicPaginationStreamer.spec.ts +++ b/test/infrastructure/streamer/MosaicPaginationStreamer.spec.ts @@ -15,8 +15,8 @@ */ import { instance, mock } from 'ts-mockito'; -import { MosaicPaginationStreamer } from '../../../src/infrastructure/paginationStreamer/MosaicPaginationStreamer'; import { MosaicRepository } from '../../../src/infrastructure/MosaicRepository'; +import { MosaicPaginationStreamer } from '../../../src/infrastructure/paginationStreamer/MosaicPaginationStreamer'; import { PaginationStreamerTestHelper } from './PaginationStreamerTestHelper'; describe('MosaicPaginationStreamer', () => { diff --git a/test/infrastructure/streamer/PaginationStreamerTestHelper.ts b/test/infrastructure/streamer/PaginationStreamerTestHelper.ts index 35f3e89d4f..9a8113afe6 100644 --- a/test/infrastructure/streamer/PaginationStreamerTestHelper.ts +++ b/test/infrastructure/streamer/PaginationStreamerTestHelper.ts @@ -1,12 +1,12 @@ -import { SearchCriteria } from '../../../src/infrastructure/searchCriteria/SearchCriteria'; -import { PaginationStreamer } from '../../../src/infrastructure/paginationStreamer/PaginationStreamer'; -import { Searcher } from '../../../src/infrastructure/paginationStreamer/Searcher'; -import { Observable } from 'rxjs/internal/Observable'; -import { Page } from '../../../src/infrastructure/Page'; -import { of } from 'rxjs'; -import { when, deepEqual, verify, instance } from 'ts-mockito'; import { expect } from 'chai'; +import { of } from 'rxjs'; +import { Observable } from 'rxjs/internal/Observable'; import { take, toArray } from 'rxjs/operators'; +import { deepEqual, instance, verify, when } from 'ts-mockito'; +import { Page } from '../../../src/infrastructure/Page'; +import { PaginationStreamer } from '../../../src/infrastructure/paginationStreamer/PaginationStreamer'; +import { Searcher } from '../../../src/infrastructure/paginationStreamer/Searcher'; +import { SearchCriteria } from '../../../src/infrastructure/searchCriteria/SearchCriteria'; export class PaginationStreamerTestHelper { constructor( diff --git a/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts b/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts index c44b62120e..415c342246 100644 --- a/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts +++ b/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts @@ -16,9 +16,9 @@ import { instance, mock } from 'ts-mockito'; import { TransactionPaginationStreamer } from '../../../src/infrastructure/paginationStreamer/TransactionPaginationStreamer'; +import { TransactionGroup } from '../../../src/infrastructure/TransactionGroup'; import { TransactionRepository } from '../../../src/infrastructure/TransactionRepository'; import { PaginationStreamerTestHelper } from './PaginationStreamerTestHelper'; -import { TransactionGroup } from '../../../src/infrastructure/TransactionGroup'; describe('TransactionPaginationStreamer', () => { it('basicMultiPageTest', () => { diff --git a/test/model/mosaic/MosaicView.spec.ts b/test/model/mosaic/MosaicView.spec.ts index 89c8e93675..426fab1b7d 100644 --- a/test/model/mosaic/MosaicView.spec.ts +++ b/test/model/mosaic/MosaicView.spec.ts @@ -15,7 +15,6 @@ */ import { expect } from 'chai'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { MosaicFlags } from '../../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { MosaicInfo } from '../../../src/model/mosaic/MosaicInfo'; diff --git a/test/model/transaction/TransactionStatus.spec.ts b/test/model/transaction/TransactionStatus.spec.ts index 22914250cd..9591d844f2 100644 --- a/test/model/transaction/TransactionStatus.spec.ts +++ b/test/model/transaction/TransactionStatus.spec.ts @@ -16,8 +16,8 @@ import { deepEqual } from 'assert'; import { expect } from 'chai'; -import { TransactionStatusEnum } from 'symbol-openapi-typescript-node-client'; -import { TransactionGroupEnum } from 'symbol-openapi-typescript-node-client'; +import { TransactionStatusEnum } from 'symbol-openapi-typescript-fetch-client'; +import { TransactionGroupEnum } from 'symbol-openapi-typescript-fetch-client'; import { Deadline } from '../../../src/model/transaction/Deadline'; import { TransactionStatus } from '../../../src/model/transaction/TransactionStatus'; import { UInt64 } from '../../../src/model/UInt64'; diff --git a/test/service/AggregateTransactionService.spec.ts b/test/service/AggregateTransactionService.spec.ts index 46674dfc73..3d157e7ddf 100644 --- a/test/service/AggregateTransactionService.spec.ts +++ b/test/service/AggregateTransactionService.spec.ts @@ -33,7 +33,7 @@ import { TransferTransaction } from '../../src/model/transaction/TransferTransac import { AggregateTransactionService } from '../../src/service/AggregateTransactionService'; import { RepositoryFactory } from '../../src/infrastructure/RepositoryFactory'; import { NetworkRepository } from '../../src/infrastructure/NetworkRepository'; -import { NetworkConfigurationDTO, PluginsPropertiesDTO, AggregateNetworkPropertiesDTO } from 'symbol-openapi-typescript-node-client'; +import { NetworkConfigurationDTO, PluginsPropertiesDTO, AggregateNetworkPropertiesDTO } from 'symbol-openapi-typescript-fetch-client'; /** * For multi level multisig scenario visit: https://github.com/nemtech/symbol-docs/issues/10 @@ -138,9 +138,9 @@ describe('AggregateTransactionService', () => { } function getNetworkProperties(input: string): NetworkConfigurationDTO { - const body = new NetworkConfigurationDTO(); - const plugin = new PluginsPropertiesDTO(); - plugin.aggregate = new AggregateNetworkPropertiesDTO(); + const body = {} as NetworkConfigurationDTO; + const plugin = {} as PluginsPropertiesDTO; + plugin.aggregate = {} as AggregateNetworkPropertiesDTO; plugin.aggregate.maxCosignaturesPerAggregate = input; body.plugins = plugin; return body; From 932d5fe6204fccbd24fbd688044d3445a7199f32 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 18 Jun 2020 21:48:56 +0100 Subject: [PATCH 10/18] Fixed #604 - Modify votingkey transaction --- e2e/infrastructure/TransactionHttp.spec.ts | 4 ++ .../transaction/CreateTransactionFromDTO.ts | 2 + .../transaction/SerializeTransactionToJSON.ts | 2 + .../transaction/VotingKeyLinkTransaction.ts | 27 ++++++++++++- test/core/utils/TransactionMapping.spec.ts | 24 +++++++++++- .../TransactionMappingWithSignatures.spec.ts | 6 +++ .../SerializeTransactionToJSON.spec.ts | 4 ++ .../VotingKeyLinkTransaction.spec.ts | 39 ++++++++++++++++--- 8 files changed, 100 insertions(+), 8 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 9ca2f39dff..f993e587a8 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -737,6 +737,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, networkType, helper.maxFee, @@ -755,6 +757,8 @@ describe('TransactionHttp', () => { const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Unlink, networkType, helper.maxFee, diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 69a4976c81..5a17e9bfac 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -491,6 +491,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), transactionDTO.linkedPublicKey, + UInt64.fromNumericString(transactionDTO.startPoint), + UInt64.fromNumericString(transactionDTO.endPoint), transactionDTO.linkAction, transactionDTO.signature, transactionDTO.signerPublicKey diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 79c08b35ef..55b4c4ccef 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -269,6 +269,8 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { const votingKeyLinkTx = transaction as VotingKeyLinkTransaction; return { linkedPublicKey: votingKeyLinkTx.linkedPublicKey, + startPoint: votingKeyLinkTx.startPoint.toString(), + endPoint: votingKeyLinkTx.endPoint.toString(), linkAction: votingKeyLinkTx.linkAction, }; default: diff --git a/src/model/transaction/VotingKeyLinkTransaction.ts b/src/model/transaction/VotingKeyLinkTransaction.ts index d1922d4df8..0303b62744 100644 --- a/src/model/transaction/VotingKeyLinkTransaction.ts +++ b/src/model/transaction/VotingKeyLinkTransaction.ts @@ -36,12 +36,15 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { FinalizationPointDto } from 'catbuffer-typescript/dist/FinalizationPointDto'; export class VotingKeyLinkTransaction extends Transaction { /** * Create a voting key link transaction object * @param deadline - The deadline to include the transaction. * @param linkedPublicKey - The public key for voting (48 bytes). + * @param startPoint - The start finalization point. + * @param endPoint - The end finalization point. * @param linkAction - The account link action. * @param maxFee - (Optional) Max fee defined by the sender * @param signature - (Optional) Transaction signature @@ -51,6 +54,8 @@ export class VotingKeyLinkTransaction extends Transaction { public static create( deadline: Deadline, linkedPublicKey: string, + startPoint: UInt64, + endPoint: UInt64, linkAction: LinkAction, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), @@ -63,6 +68,8 @@ export class VotingKeyLinkTransaction extends Transaction { deadline, maxFee, linkedPublicKey, + startPoint, + endPoint, linkAction, signature, signer, @@ -75,6 +82,8 @@ export class VotingKeyLinkTransaction extends Transaction { * @param deadline * @param maxFee * @param linkedPublicKey + * @param startPoint + * @param endPoint * @param linkAction * @param signature * @param signer @@ -89,6 +98,14 @@ export class VotingKeyLinkTransaction extends Transaction { * The public key of the remote account. */ public readonly linkedPublicKey: string, + /** + * The start finalization point. + */ + public readonly startPoint: UInt64, + /** + * The start finalization point. + */ + public readonly endPoint: UInt64, /** * The account link action. */ @@ -116,6 +133,8 @@ export class VotingKeyLinkTransaction extends Transaction { const transaction = VotingKeyLinkTransaction.create( isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as VotingKeyLinkTransactionBuilder).getDeadline().timestamp), Convert.uint8ToHex(builder.getLinkedPublicKey().votingKey), + new UInt64(builder.getStartPoint().finalizationPoint), + new UInt64(builder.getEndPoint().finalizationPoint), builder.getLinkAction().valueOf(), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as VotingKeyLinkTransactionBuilder).fee.amount), @@ -136,9 +155,11 @@ export class VotingKeyLinkTransaction extends Transaction { // set static byte size fields const bytePublicKey = 48; + const startPoint = 8; + const endPoint = 8; const byteLinkAction = 1; - return byteSize + bytePublicKey + byteLinkAction; + return byteSize + bytePublicKey + startPoint + endPoint + byteLinkAction; } /** @@ -158,6 +179,8 @@ export class VotingKeyLinkTransaction extends Transaction { new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); return transactionBuilder.serialize(); @@ -174,6 +197,8 @@ export class VotingKeyLinkTransaction extends Transaction { this.networkType.valueOf(), TransactionType.VOTING_KEY_LINK.valueOf(), new VotingKeyDto(Convert.hexToUint8(this.linkedPublicKey)), + new FinalizationPointDto(this.startPoint.toDTO()), + new FinalizationPointDto(this.endPoint.toDTO()), this.linkAction.valueOf(), ); } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d9d2dbe3da..8304a30584 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -418,6 +418,8 @@ describe('TransactionMapping - createFromPayload', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -611,12 +613,21 @@ describe('TransactionMapping - createFromPayload', () => { it('should create an VotingKeyLinkTransaction object with link action', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as VotingKeyLinkTransaction; expect(transaction.linkAction).to.be.equal(1); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkedPublicKey).to.be.equal(key); }); @@ -906,11 +917,20 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create VotingKeyLinkTransaction', () => { const key = Convert.uint8ToHex(Crypto.randomBytes(48)); - const votingKeyLinkTransaction = VotingKeyLinkTransaction.create(Deadline.create(), key, LinkAction.Link, NetworkType.MIJIN_TEST); + const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + key, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Link, + NetworkType.MIJIN_TEST, + ); const transaction = TransactionMapping.createFromDTO(votingKeyLinkTransaction.toJSON()) as VotingKeyLinkTransaction; expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.linkAction).to.be.equal(LinkAction.Link); }); it('should create AccountRestrictionAddressTransaction', () => { diff --git a/test/core/utils/TransactionMappingWithSignatures.spec.ts b/test/core/utils/TransactionMappingWithSignatures.spec.ts index d720ff08fd..a1bd933e13 100644 --- a/test/core/utils/TransactionMappingWithSignatures.spec.ts +++ b/test/core/utils/TransactionMappingWithSignatures.spec.ts @@ -499,6 +499,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), Convert.uint8ToHex(Crypto.randomBytes(48)), + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -767,6 +769,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), key, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, undefined, @@ -779,6 +783,8 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign expect(transaction.linkAction).to.be.equal(1); expect(transaction.linkedPublicKey).to.be.equal(key); + expect(transaction.startPoint.toString()).to.be.equal('1'); + expect(transaction.endPoint.toString()).to.be.equal('3'); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 9cba33dbea..64efd8c330 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -403,6 +403,8 @@ describe('SerializeTransactionToJSON', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), LinkAction.Link, NetworkType.MIJIN_TEST, ); @@ -410,6 +412,8 @@ describe('SerializeTransactionToJSON', () => { const json = votingKeyLinkTransaction.toJSON(); expect(json.transaction.linkedPublicKey).to.be.equal(votingKey); + expect(json.transaction.startPoint).to.be.equal('1'); + expect(json.transaction.endPoint.toString()).to.be.equal('3'); expect(json.transaction.linkAction).to.be.equal(LinkAction.Link); }); }); diff --git a/test/model/transaction/VotingKeyLinkTransaction.spec.ts b/test/model/transaction/VotingKeyLinkTransaction.spec.ts index 7cc9755aa9..04f77385f7 100644 --- a/test/model/transaction/VotingKeyLinkTransaction.spec.ts +++ b/test/model/transaction/VotingKeyLinkTransaction.spec.ts @@ -28,6 +28,8 @@ import { Address } from '../../../src/model/account/Address'; describe('VotingKeyLinkTransaction', () => { let account: Account; let votingKey: string; + const startPoint = UInt64.fromUint(1); + const endPoint = UInt64.fromUint(10); const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; @@ -38,18 +40,24 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(0); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should filled maxFee override transaction maxFee', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -57,23 +65,29 @@ describe('VotingKeyLinkTransaction', () => { expect(votingKeyLinkTransaction.maxFee.higher).to.be.equal(0); expect(votingKeyLinkTransaction.maxFee.lower).to.be.equal(1); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); }); it('should create an votingKeyLinkTransaction object with link action', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Link, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(1); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000001', ); }); @@ -81,17 +95,21 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(votingKeyLinkTransaction.linkAction).to.be.equal(0); expect(votingKeyLinkTransaction.linkedPublicKey).to.be.equal(votingKey); + expect(votingKeyLinkTransaction.startPoint.toString()).to.be.equal('1'); + expect(votingKeyLinkTransaction.endPoint.toString()).to.be.equal('10'); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D000', + '344B9146A1F8DBBD8AFC830A2AAB7A83692E73AD775159B811355B1D2C0C27120243B10A16D4B5001B2AF0ED456C82D001000000000000000A0000000000000000', ); }); @@ -100,11 +118,13 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ); expect(Convert.hexToUint8(votingKeyLinkTransaction.serialize()).length).to.be.equal(votingKeyLinkTransaction.size); - expect(votingKeyLinkTransaction.size).to.be.equal(177); + expect(votingKeyLinkTransaction.size).to.be.equal(193); }); }); @@ -112,17 +132,26 @@ describe('VotingKeyLinkTransaction', () => { const votingKeyLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), votingKey, + startPoint, + endPoint, LinkAction.Unlink, NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(354); + expect(votingKeyLinkTransaction.maxFee.compact()).to.be.equal(386); const signedTransaction = votingKeyLinkTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; }); it('Notify Account', () => { - const tx = VotingKeyLinkTransaction.create(Deadline.create(), account.publicKey, LinkAction.Unlink, NetworkType.MIJIN_TEST); + const tx = VotingKeyLinkTransaction.create( + Deadline.create(), + account.publicKey, + startPoint, + endPoint, + LinkAction.Unlink, + NetworkType.MIJIN_TEST, + ); let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; From bd91ddde79c1e6dd19263389343c6be7567120f2 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 23 Jun 2020 16:22:07 +0100 Subject: [PATCH 11/18] Updated catbuffer version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 97348385df..bc6e15e6fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1100,9 +1100,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.21-alpha-202006221403", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006221403.tgz", - "integrity": "sha512-2iyyjv4r4RbHs6PasTLvcwPUERgNH9GEUxAlrxho+yj5gbb/ctPoNcbCNAKefFdEEimUoBK1uLyEIVu49vlQZg==" + "version": "0.0.21-alpha-202006231534", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006231534.tgz", + "integrity": "sha512-iwMwOi7N1gQQfRkpiZL+dVyzYV3U+IqMM9x3fvi0/0nbf3dMcnATo7K9ifbw8Or14uCmbUrw3zKhQ2EvYwkVlw==" }, "chai": { "version": "4.1.2", diff --git a/package.json b/package.json index adb13c1414..576812571f 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.21-alpha-202006221403", + "catbuffer-typescript": "0.0.21-alpha-202006231534", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", From ea25cdc84aae896e358cf759231f9db668ad8f33 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 24 Jun 2020 12:00:07 +0100 Subject: [PATCH 12/18] Removed requires --- e2e/infrastructure/IntegrationTestHelper.ts | 12 ++++++------ e2e/infrastructure/TransactionHttp.spec.ts | 13 ++++--------- package-lock.json | 9 +++++++++ package.json | 1 + src/core/crypto/Crypto.ts | 7 ++----- src/core/crypto/Utilities.ts | 14 ++++++-------- src/core/format/RawAddress.ts | 4 ++-- src/core/utils/LockHashUtils.ts | 13 ++++++------- test/core/crypto/hkdf.spec.ts | 6 ++---- test/core/utils/Hashes.spec.ts | 7 ++----- .../transaction/HashTypeLengthValidator.spec.ts | 4 +--- .../transaction/SecretLockTransaction.spec.ts | 4 +--- .../transaction/SecretProofTransaction.spec.ts | 4 +--- 13 files changed, 43 insertions(+), 55 deletions(-) diff --git a/e2e/infrastructure/IntegrationTestHelper.ts b/e2e/infrastructure/IntegrationTestHelper.ts index f13403bcfb..244749ceae 100644 --- a/e2e/infrastructure/IntegrationTestHelper.ts +++ b/e2e/infrastructure/IntegrationTestHelper.ts @@ -27,9 +27,11 @@ import { TransactionService } from '../../src/service/TransactionService'; import { NetworkCurrencyPublic } from '../../src/model/mosaic/NetworkCurrencyPublic'; import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; +import * as yaml from 'js-yaml'; +import * as path from 'path'; +import * as fs from 'fs'; export class IntegrationTestHelper { - public readonly yaml = require('js-yaml'); public apiUrl: string; public repositoryFactory: RepositoryFactory; public account: Account; @@ -51,9 +53,7 @@ export class IntegrationTestHelper { start(): Promise { return new Promise((resolve, reject) => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, jsonData) => { + fs.readFile(path.resolve(__dirname, '../conf/network.conf'), (err, jsonData: any) => { if (err) { return reject(err); } @@ -94,7 +94,7 @@ export class IntegrationTestHelper { const bootstrapRoot = process.env.CATAPULT_SERVICE_BOOTSTRAP || path.resolve(__dirname, '../../../../catapult-service-bootstrap'); const bootstrapPath = `${bootstrapRoot}/build/generated-addresses/addresses.yaml`; - require('fs').readFile(bootstrapPath, (error: any, yamlData: any) => { + fs.readFile(bootstrapPath, (error: any, yamlData: any) => { if (error) { console.log( `catapult-service-bootstrap generated address could not be loaded from path ${bootstrapPath}. Ignoring and using accounts from network.conf.`, @@ -102,7 +102,7 @@ export class IntegrationTestHelper { return resolve(this); } else { console.log(`catapult-service-bootstrap generated address loaded from path ${bootstrapPath}.`); - const parsedYaml = this.yaml.safeLoad(yamlData); + const parsedYaml = yaml.safeLoad(yamlData); this.account = this.createAccount(parsedYaml.nemesis_addresses[0]); this.account2 = this.createAccount(parsedYaml.nemesis_addresses[1]); this.account3 = this.createAccount(parsedYaml.nemesis_addresses[2]); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index f993e587a8..bd508270cf 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -76,9 +76,10 @@ import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestric import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag'; import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; import { TransactionStatusRepository } from '../../src/infrastructure/TransactionStatusRepository'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as ripemd160 from 'ripemd160'; +import { sha256 } from 'js-sha256'; +import * as secureRandom from 'secure-random'; +import * as CryptoJS from 'crypto-js'; describe('TransactionHttp', () => { let transactionHash: string; @@ -101,12 +102,6 @@ describe('TransactionHttp', () => { let transactionRepository: TransactionRepository; let transactionStatusRepository: TransactionStatusRepository; let votingKey: string; - // eslint-disable-next-line @typescript-eslint/no-var-requires - const secureRandom = require('secure-random'); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const sha256 = require('js-sha256'); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const ripemd160 = require('ripemd160'); const remoteAccount = Account.generateNewAccount(helper.networkType); diff --git a/package-lock.json b/package-lock.json index bc6e15e6fe..f4b7a5b864 100644 --- a/package-lock.json +++ b/package-lock.json @@ -415,6 +415,15 @@ "@types/request": "*" } }, + "@types/ripemd160": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/ripemd160/-/ripemd160-2.0.0.tgz", + "integrity": "sha512-LD6AO/+8cAa1ghXax9NG9iPDLPUEGB2WWPjd//04KYfXxTwHvlDEfL0NRjrM5z9XWBi6WbKw75Are0rDyn3PSA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/tough-cookie": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.2.tgz", diff --git a/package.json b/package.json index 576812571f..6b9fa8b865 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "@types/lodash": "^4.14.85", "@types/long": "^4.0.0", "@types/mocha": "^2.2.44", + "@types/ripemd160": "^2.0.0", "@types/request": "^2.47.0", "@types/request-promise-native": "^1.0.14", "@types/utf8": "^2.1.6", diff --git a/src/core/crypto/Crypto.ts b/src/core/crypto/Crypto.ts index 4db28ca259..3e057f061e 100644 --- a/src/core/crypto/Crypto.ts +++ b/src/core/crypto/Crypto.ts @@ -17,9 +17,8 @@ import { Convert as convert } from '../format/Convert'; import { KeyPair } from './KeyPair'; import * as utility from './Utilities'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as crypto from 'crypto'; +import * as CryptoJS from 'crypto-js'; export class Crypto { /** @@ -183,8 +182,6 @@ export class Crypto { * @return {Uint8Array} */ public static randomBytes = (length: number): any => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const crypto = require('crypto'); return crypto.randomBytes(length); }; } diff --git a/src/core/crypto/Utilities.ts b/src/core/crypto/Utilities.ts index 2064259d14..d9a6898cd0 100644 --- a/src/core/crypto/Utilities.ts +++ b/src/core/crypto/Utilities.ts @@ -16,18 +16,16 @@ import { RawArray as array } from '../format'; import * as nacl from './nacl_catapult'; -// eslint-disable-next-line @typescript-eslint/no-var-requires -export const CryptoJS = require('crypto-js'); +import * as CryptoJS from 'crypto-js'; +import * as hkdf from 'futoin-hkdf'; +import { sha512 } from 'js-sha512'; +import { WordArray } from 'crypto-js'; + export const Key_Size = 32; export const Signature_Size = 64; export const Half_Signature_Size = Signature_Size / 2; export const Hash_Size = 64; export const Half_Hash_Size = Hash_Size / 2; -// eslint-disable-next-line @typescript-eslint/no-var-requires -export const hkdf = require('futoin-hkdf'); -import { sha512 } from 'js-sha512'; -import { WordArray } from 'crypto-js'; - /** * Convert an Uint8Array to WordArray * @@ -88,7 +86,7 @@ export const catapult_crypto = ((): any => { const sharedSecret = catapult_crypto.deriveSharedSecret(privateKey, publicKey); const info = 'catapult'; const hash = 'SHA-256'; - return hkdf(sharedSecret, 32, { salt: new Uint8Array(32), info, hash }); + return hkdf(sharedSecret, 32, { salt: Buffer.from(new Uint8Array(32)), info, hash }); }, deriveSharedSecret: (privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array => { diff --git a/src/core/format/RawAddress.ts b/src/core/format/RawAddress.ts index 65b2586634..81b5cb79f0 100644 --- a/src/core/format/RawAddress.ts +++ b/src/core/format/RawAddress.ts @@ -15,7 +15,7 @@ */ import { sha3_256 } from 'js-sha3'; -import RIPEMD160 = require('ripemd160'); +import * as ripemd160 from 'ripemd160'; import { NetworkType } from '../../model/network/NetworkType'; import { Base32 } from './Base32'; import { Convert } from './Convert'; @@ -83,7 +83,7 @@ export class RawAddress { const publicKeyHash = sha3_256.arrayBuffer(publicKey); // step 2: ripemd160 hash of (1) - const ripemdHash = new RIPEMD160().update(new Buffer(publicKeyHash)).digest(); + const ripemdHash = new ripemd160().update(new Buffer(publicKeyHash)).digest(); // step 3: add network identifier byte in front of (2) const decodedAddress = new Uint8Array(RawAddress.constants.sizes.addressDecoded); diff --git a/src/core/utils/LockHashUtils.ts b/src/core/utils/LockHashUtils.ts index a107c8af47..b424f3c8bd 100644 --- a/src/core/utils/LockHashUtils.ts +++ b/src/core/utils/LockHashUtils.ts @@ -16,13 +16,12 @@ import { sha3_256 } from 'js-sha3'; import { LockHashAlgorithm } from '../../model/transaction/LockHashAlgorithm'; - +import * as ripemd160 from 'ripemd160'; +import { sha256 } from 'js-sha256'; /** * Hash utilities for SecretLock hashing */ export class LockHashUtils { - private static sha256 = require('js-sha256'); - private static ripemd160 = require('ripemd160'); /** * Perform SHA3_256 hash * @param input buffer to be hashed @@ -38,8 +37,8 @@ export class LockHashUtils { * @returns {string} Hash in hexidecimal format */ public static Op_Hash_256(input: Uint8Array): string { - const hash = LockHashUtils.sha256(input, 'hex'); - return LockHashUtils.sha256(Buffer.from(hash, 'hex')).toUpperCase(); + const hash = sha256(input); + return sha256(Buffer.from(hash, 'hex')).toUpperCase(); } /** @@ -48,8 +47,8 @@ export class LockHashUtils { * @returns {string} Hash in hexidecimal format */ public static Op_Hash_160(input: Uint8Array): string { - const sha256Hash = LockHashUtils.sha256(input); - return new LockHashUtils.ripemd160().update(Buffer.from(sha256Hash, 'hex')).digest('hex').toUpperCase(); + const sha256Hash = sha256(input); + return new ripemd160().update(Buffer.from(sha256Hash, 'hex')).digest('hex').toUpperCase(); } /** diff --git a/test/core/crypto/hkdf.spec.ts b/test/core/crypto/hkdf.spec.ts index 9bac5305cc..41e55f99ee 100644 --- a/test/core/crypto/hkdf.spec.ts +++ b/test/core/crypto/hkdf.spec.ts @@ -15,9 +15,7 @@ */ import { expect } from 'chai'; import { Convert } from '../../../src/core/format'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const hkdf = require('futoin-hkdf'); +import * as hkdf from 'futoin-hkdf'; describe('hkdf', () => { describe('Example tests', () => { @@ -25,7 +23,7 @@ describe('hkdf', () => { const sharedSecret = 'string-or-buffer'; const hash = 'SHA-256'; const info = 'catapult'; - const sharedKey = hkdf(sharedSecret, 32, { salt: new Uint8Array(32), info, hash }); + const sharedKey = hkdf(sharedSecret, 32, { salt: Buffer.from(new Uint8Array(32)), info, hash }); expect(Convert.uint8ToHex(sharedKey)).equal('E618ACB2558E1721492E4AE3BED3F4D86F26C2B0CE6AD939943A6A540855D23F'); }); }); diff --git a/test/core/utils/Hashes.spec.ts b/test/core/utils/Hashes.spec.ts index 82ae339190..38e9976f7f 100644 --- a/test/core/utils/Hashes.spec.ts +++ b/test/core/utils/Hashes.spec.ts @@ -19,13 +19,10 @@ import { sha3_256 } from 'js-sha3'; import { LockHashUtils } from '../../../src/core/utils/LockHashUtils'; import { LockHashAlgorithm } from '../../../src/model/transaction/LockHashAlgorithm'; import { Convert } from '../../../src/core/format/Convert'; +import * as ripemd160 from 'ripemd160'; +import { sha256 } from 'js-sha256'; describe('Hashes', () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const ripemd160 = require('ripemd160'); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const sha256 = require('js-sha256'); - it('Op_Sha3_256', () => { const secretSeed = Crypto.randomBytes(20); const expected = sha3_256.create().update(secretSeed).hex(); diff --git a/test/model/transaction/HashTypeLengthValidator.spec.ts b/test/model/transaction/HashTypeLengthValidator.spec.ts index d56a2f6b8d..e05ec414f2 100644 --- a/test/model/transaction/HashTypeLengthValidator.spec.ts +++ b/test/model/transaction/HashTypeLengthValidator.spec.ts @@ -16,9 +16,7 @@ import { expect } from 'chai'; import { sha3_256, sha3_512 } from 'js-sha3'; import { LockHashAlgorithm, LockHashAlgorithmLengthValidator } from '../../../src/model/transaction/LockHashAlgorithm'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as CryptoJS from 'crypto-js'; describe('LockHashAlgorithmLengthValidator', () => { it('LockHashAlgorithm.SHA3_256 should be exactly 64 chars length', () => { diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 56c7ce6e52..b761fd50d9 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -35,9 +35,7 @@ import { SecretLockTransaction } from '../../../src/model/transaction/SecretLock import { TransactionInfo } from '../../../src/model/transaction/TransactionInfo'; import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as CryptoJS from 'crypto-js'; describe('SecretLockTransaction', () => { let account: Account; diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 7ad17698d2..26f45c2eec 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -33,9 +33,7 @@ import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; import { EmbeddedTransactionBuilder } from 'catbuffer-typescript/dist/EmbeddedTransactionBuilder'; import { TransactionType } from '../../../src/model/transaction/TransactionType'; - -// eslint-disable-next-line @typescript-eslint/no-var-requires -const CryptoJS = require('crypto-js'); +import * as CryptoJS from 'crypto-js'; describe('SecretProofTransaction', () => { let account: Account; From 26324613b95fd108e5d586af194c654c4e6f43ab Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 24 Jun 2020 21:54:20 +0100 Subject: [PATCH 13/18] Updated accountKeyFlags --- package-lock.json | 13 +++------- package.json | 2 +- src/model/account/AccountKey.ts | 6 ++--- ...countKeyType.ts => AccountKeyTypeFlags.ts} | 19 +++++--------- src/model/model.ts | 2 +- test/infrastructure/AccountHttp.spec.ts | 2 +- test/model/account/AccountKey.spec.ts | 26 ++++++++----------- test/service/AccountService.spec.ts | 4 +-- 8 files changed, 30 insertions(+), 44 deletions(-) rename src/model/account/{AccountKeyType.ts => AccountKeyTypeFlags.ts} (81%) diff --git a/package-lock.json b/package-lock.json index f4b7a5b864..908c9c3e2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4546,7 +4546,7 @@ }, "which-module": { "version": "2.0.0", - "resolved": false, + "resolved": "", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, @@ -5965,14 +5965,9 @@ } }, "symbol-openapi-typescript-fetch-client": { - "version": "0.9.3-SNAPSHOT.202006231707", - "dependencies": { - "typescript": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", - "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==" - } - } + "version": "0.9.3-SNAPSHOT.202006242144", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3-SNAPSHOT.202006242144.tgz", + "integrity": "sha512-3C4FDuft2P+UzX+n+cO2idPiImBSocGvY91o/BAioMnLcJoFTXX5nCJWUSKFT4VgjmlscWLlvxYfBPsH+jdcYw==" }, "table": { "version": "5.4.6", diff --git a/package.json b/package.json index 6b9fa8b865..961b550273 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006231707", + "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006242144", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/model/account/AccountKey.ts b/src/model/account/AccountKey.ts index 0006340b7c..8a7adf4ee9 100644 --- a/src/model/account/AccountKey.ts +++ b/src/model/account/AccountKey.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { AccountKeyType } from './AccountKeyType'; +import { AccountKeyTypeFlags } from './AccountKeyTypeFlags'; /** * Account key @@ -25,9 +25,9 @@ export class AccountKey { */ constructor( /** - * Account key type + * Account key key flags */ - public readonly keyType: AccountKeyType, + public readonly accountKeyFlags: AccountKeyTypeFlags, /** * Key */ diff --git a/src/model/account/AccountKeyType.ts b/src/model/account/AccountKeyTypeFlags.ts similarity index 81% rename from src/model/account/AccountKeyType.ts rename to src/model/account/AccountKeyTypeFlags.ts index d82e006db8..b8464480d8 100644 --- a/src/model/account/AccountKeyType.ts +++ b/src/model/account/AccountKeyTypeFlags.ts @@ -15,9 +15,9 @@ */ /** - * The account key type emu,. + * The account key flags enum,. */ -export enum AccountKeyType { +export enum AccountKeyTypeFlags { /** * Unset key. */ @@ -30,22 +30,17 @@ export enum AccountKeyType { Linked = 0x01, /** - *VRF public key. - */ - VRF = 0x02, - - /** - * Voting public key. + * Node public key on which remote is allowed to harvest. */ - Voting = 0x04, + Node = 0x02, /** - * Node public key on which remote is allowed to harvest. + * VRF public key. */ - Node = 0x08, + VRF = 0x04, /** * All valid keys. */ - All = Linked | VRF | Voting | Node, + All = Linked | VRF | Node, } diff --git a/src/model/model.ts b/src/model/model.ts index b3cb800d28..207e94c0c0 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -28,7 +28,7 @@ export * from './account/MultisigAccountInfo'; export * from './account/PublicAccount'; export * from './account/AccountNames'; export * from './account/AccountInfoResolvedMosaic'; -export * from './account/AccountKeyType'; +export * from './account/AccountKeyTypeFlags'; export * from './account/AccountKey'; export * from './account/UnresolvedAddress'; diff --git a/test/infrastructure/AccountHttp.spec.ts b/test/infrastructure/AccountHttp.spec.ts index c76ebf4c21..dc696aef92 100644 --- a/test/infrastructure/AccountHttp.spec.ts +++ b/test/infrastructure/AccountHttp.spec.ts @@ -86,7 +86,7 @@ describe('AccountHttp', () => { expect(accountInfo.publicKeyHeight.toString()).to.be.equals(accountDTO.publicKeyHeight); expect(accountInfo.publicKey).to.be.equals(accountDTO.publicKey); expect(accountInfo.supplementalAccountKeys[0].key).to.be.equals(accountDTO.supplementalAccountKeys[0].key); - expect(accountInfo.supplementalAccountKeys[0].keyType.valueOf()).to.be.equals( + expect(accountInfo.supplementalAccountKeys[0].accountKeyFlags.valueOf()).to.be.equals( accountDTO.supplementalAccountKeys[0].keyType.valueOf(), ); expect(accountInfo.mosaics.length).to.be.equals(1); diff --git a/test/model/account/AccountKey.spec.ts b/test/model/account/AccountKey.spec.ts index 8040791f0b..8240f0550a 100644 --- a/test/model/account/AccountKey.spec.ts +++ b/test/model/account/AccountKey.spec.ts @@ -17,32 +17,28 @@ import { deepEqual } from 'assert'; import { expect } from 'chai'; import { AccountKey } from '../../../src/model/account/AccountKey'; -import { AccountKeyType } from '../../../src/model/account/AccountKeyType'; +import { AccountKeyTypeFlags } from '../../../src/model/account/AccountKeyTypeFlags'; describe('AccountKey', () => { it('should createComplete an AccountKey object', () => { - let accountKey = new AccountKey(AccountKeyType.Unset, 'abc'); + let accountKey = new AccountKey(AccountKeyTypeFlags.Unset, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyType.Unset.valueOf()); + deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.Unset.valueOf()); - accountKey = new AccountKey(AccountKeyType.Linked, 'abc'); + accountKey = new AccountKey(AccountKeyTypeFlags.Linked, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyType.Linked.valueOf()); + deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.Linked.valueOf()); - accountKey = new AccountKey(AccountKeyType.Node, 'abc'); + accountKey = new AccountKey(AccountKeyTypeFlags.Node, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyType.Node.valueOf()); + deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.Node.valueOf()); - accountKey = new AccountKey(AccountKeyType.VRF, 'abc'); + accountKey = new AccountKey(AccountKeyTypeFlags.VRF, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyType.VRF.valueOf()); + deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.VRF.valueOf()); - accountKey = new AccountKey(AccountKeyType.Voting, 'abc'); + accountKey = new AccountKey(AccountKeyTypeFlags.All, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyType.Voting.valueOf()); - - accountKey = new AccountKey(AccountKeyType.All, 'abc'); - expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyType.All.valueOf()); + deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.All.valueOf()); }); }); diff --git a/test/service/AccountService.spec.ts b/test/service/AccountService.spec.ts index f8cef47ab7..0472081834 100644 --- a/test/service/AccountService.spec.ts +++ b/test/service/AccountService.spec.ts @@ -37,7 +37,7 @@ import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NamespaceName } from '../../src/model/namespace/NamespaceName'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import { AccountKey } from '../../src/model/account/AccountKey'; -import { AccountKeyType } from '../../src/model/account/AccountKeyType'; +import { AccountKeyTypeFlags } from '../../src/model/account/AccountKeyTypeFlags'; describe('AccountService', () => { let accountService: AccountService; @@ -59,7 +59,7 @@ describe('AccountService', () => { account.publicKey, UInt64.fromUint(100), AccountType.Main, - [new AccountKey(AccountKeyType.Linked, '0')], + [new AccountKey(AccountKeyTypeFlags.Linked, '0')], [new ActivityBucket(UInt64.fromUint(0), UInt64.fromUint(1), 1, UInt64.fromUint(1))], mosaics, UInt64.fromUint(100), From 2de54eb9813d84e3ca800f710bd5922372bad0c3 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 24 Jun 2020 23:31:59 +0100 Subject: [PATCH 14/18] SupplementalAccountKeys => SupplementalPublicKeys --- package-lock.json | 6 +++--- package.json | 2 +- src/infrastructure/AccountHttp.ts | 2 +- src/model/account/AccountInfo.ts | 2 +- src/model/account/AccountKey.ts | 4 ++-- test/infrastructure/AccountHttp.spec.ts | 8 ++++---- test/model/account/AccountKey.spec.ts | 10 +++++----- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 908c9c3e2d..db1b56cad3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5965,9 +5965,9 @@ } }, "symbol-openapi-typescript-fetch-client": { - "version": "0.9.3-SNAPSHOT.202006242144", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3-SNAPSHOT.202006242144.tgz", - "integrity": "sha512-3C4FDuft2P+UzX+n+cO2idPiImBSocGvY91o/BAioMnLcJoFTXX5nCJWUSKFT4VgjmlscWLlvxYfBPsH+jdcYw==" + "version": "0.9.3-SNAPSHOT.202006242326", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3-SNAPSHOT.202006242326.tgz", + "integrity": "sha512-sTtrKo6soJ6OPQpPjPRBZPyMurXADT+H1fmM67z+YGyzzDhjfQmVDt0FZRCnazCKo4OntVo1S3Ow4AUF305uiQ==" }, "table": { "version": "5.4.6", diff --git a/package.json b/package.json index 961b550273..69ed2d84f2 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006242144", + "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006242326", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 21f56fe662..0071eb4828 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -83,7 +83,7 @@ export class AccountHttp extends Http implements AccountRepository { dto.account.publicKey, UInt64.fromNumericString(dto.account.publicKeyHeight), dto.account.accountType.valueOf(), - dto.account.supplementalAccountKeys.map((key) => new AccountKey(key.keyType.valueOf(), key.key)), + dto.account.supplementalPublicKeys.map((key) => new AccountKey(key.keyType.valueOf(), key.key)), dto.account.activityBuckets.map((bucket) => { return new ActivityBucket( UInt64.fromNumericString(bucket.startHeight), diff --git a/src/model/account/AccountInfo.ts b/src/model/account/AccountInfo.ts index 69a74e83b1..58f8fcc792 100644 --- a/src/model/account/AccountInfo.ts +++ b/src/model/account/AccountInfo.ts @@ -53,7 +53,7 @@ export class AccountInfo { /** * Account keys */ - public readonly supplementalAccountKeys: AccountKey[], + public readonly supplementalPublicKeys: AccountKey[], /** * Account activity bucket */ diff --git a/src/model/account/AccountKey.ts b/src/model/account/AccountKey.ts index 8a7adf4ee9..9b2947e57f 100644 --- a/src/model/account/AccountKey.ts +++ b/src/model/account/AccountKey.ts @@ -25,9 +25,9 @@ export class AccountKey { */ constructor( /** - * Account key key flags + * Account key key */ - public readonly accountKeyFlags: AccountKeyTypeFlags, + public readonly keyType: AccountKeyTypeFlags, /** * Key */ diff --git a/test/infrastructure/AccountHttp.spec.ts b/test/infrastructure/AccountHttp.spec.ts index dc696aef92..8a8e9fa622 100644 --- a/test/infrastructure/AccountHttp.spec.ts +++ b/test/infrastructure/AccountHttp.spec.ts @@ -56,7 +56,7 @@ describe('AccountHttp', () => { const accountKeyDto = {} as AccountKeyDTO; accountKeyDto.key = 'abc'; accountKeyDto.keyType = 1; - accountDTO.supplementalAccountKeys = [accountKeyDto]; + accountDTO.supplementalPublicKeys = [accountKeyDto]; accountDTO.publicKey = 'AAA'; accountDTO.activityBuckets = []; accountDTO.mosaics = [mosaic]; @@ -85,9 +85,9 @@ describe('AccountHttp', () => { expect(accountInfo.importanceHeight.toString()).to.be.equals(accountDTO.importanceHeight); expect(accountInfo.publicKeyHeight.toString()).to.be.equals(accountDTO.publicKeyHeight); expect(accountInfo.publicKey).to.be.equals(accountDTO.publicKey); - expect(accountInfo.supplementalAccountKeys[0].key).to.be.equals(accountDTO.supplementalAccountKeys[0].key); - expect(accountInfo.supplementalAccountKeys[0].accountKeyFlags.valueOf()).to.be.equals( - accountDTO.supplementalAccountKeys[0].keyType.valueOf(), + expect(accountInfo.supplementalPublicKeys[0].key).to.be.equals(accountDTO.supplementalPublicKeys[0].key); + expect(accountInfo.supplementalPublicKeys[0].keyType.valueOf()).to.be.equals( + accountDTO.supplementalPublicKeys[0].keyType.valueOf(), ); expect(accountInfo.mosaics.length).to.be.equals(1); expect(accountInfo.mosaics[0].id.id.toHex()).to.be.equals(mosaic.id); diff --git a/test/model/account/AccountKey.spec.ts b/test/model/account/AccountKey.spec.ts index 8240f0550a..bc8abc6cf0 100644 --- a/test/model/account/AccountKey.spec.ts +++ b/test/model/account/AccountKey.spec.ts @@ -23,22 +23,22 @@ describe('AccountKey', () => { it('should createComplete an AccountKey object', () => { let accountKey = new AccountKey(AccountKeyTypeFlags.Unset, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.Unset.valueOf()); + deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.Unset.valueOf()); accountKey = new AccountKey(AccountKeyTypeFlags.Linked, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.Linked.valueOf()); + deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.Linked.valueOf()); accountKey = new AccountKey(AccountKeyTypeFlags.Node, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.Node.valueOf()); + deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.Node.valueOf()); accountKey = new AccountKey(AccountKeyTypeFlags.VRF, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.VRF.valueOf()); + deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.VRF.valueOf()); accountKey = new AccountKey(AccountKeyTypeFlags.All, 'abc'); expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.accountKeyFlags.valueOf(), AccountKeyTypeFlags.All.valueOf()); + deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.All.valueOf()); }); }); From a01813944438e7ef808228036b549322e751b201 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 26 Jun 2020 16:27:46 +0100 Subject: [PATCH 15/18] Updated getTransactionsById --- e2e/infrastructure/MetadataHttp.spec.ts | 1 + e2e/infrastructure/TransactionHttp.spec.ts | 2760 +++++++++---------- package-lock.json | 6 +- package.json | 2 +- src/infrastructure/TransactionHttp.ts | 29 +- src/infrastructure/TransactionRepository.ts | 4 +- src/service/TransactionService.ts | 3 +- test/infrastructure/TransactionHttp.spec.ts | 48 +- 8 files changed, 1451 insertions(+), 1402 deletions(-) diff --git a/e2e/infrastructure/MetadataHttp.spec.ts b/e2e/infrastructure/MetadataHttp.spec.ts index 537647622f..4e9cf0ad79 100644 --- a/e2e/infrastructure/MetadataHttp.spec.ts +++ b/e2e/infrastructure/MetadataHttp.spec.ts @@ -264,6 +264,7 @@ describe('MetadataHttp', () => { describe('getNamespaceMetadata', () => { it('should return metadata given a namespaceId', async () => { + await new Promise((resolve) => setTimeout(resolve, 3000)); const metadata = await metadataRepository.getNamespaceMetadata(namespaceId).toPromise(); expect(metadata.length).to.be.greaterThan(0); expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index bd508270cf..1908a7cb4f 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -135,430 +135,632 @@ describe('TransactionHttp', () => { }); }); - describe('MosaicDefinitionTransaction', () => { - it('standalone', () => { - const nonce = MosaicNonce.createRandom(); - mosaicId = MosaicId.createFromNonce(nonce, account.address); - const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( - Deadline.create(), - nonce, - mosaicId, - MosaicFlags.create(true, true, true), - 3, - UInt64.fromUint(1000), - networkType, - helper.maxFee, - ); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - transactionHash = signedTransaction.hash; - - return helper.announce(signedTransaction).then((transaction: MosaicDefinitionTransaction) => { - expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - expect(transaction.nonce, 'Nonce').not.to.be.undefined; - expect(transaction.divisibility, 'Divisibility').not.to.be.undefined; - expect(transaction.duration, 'Duration').not.to.be.undefined; - expect(transaction.flags.supplyMutable, 'SupplyMutable').not.to.be.undefined; - expect(transaction.flags.transferable, 'Transferable').not.to.be.undefined; - expect(transaction.flags.restrictable, 'Restrictable').not.to.be.undefined; - }); - }); - }); - - describe('MosaicDefinitionTransaction', () => { - it('aggregate', () => { - const nonce = MosaicNonce.createRandom(); - const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( - Deadline.create(), - nonce, - MosaicId.createFromNonce(nonce, account.address), - MosaicFlags.create(true, true, true), - 3, - UInt64.fromUint(0), - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [mosaicDefinitionTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('AccountMetadataTransaction', () => { - it('aggregate', () => { - const accountMetadataTransaction = AccountMetadataTransaction.create( - Deadline.create(), - account.address, - UInt64.fromUint(5), - 10, - Convert.uint8ToUtf8(new Uint8Array(10)), - networkType, - helper.maxFee, - ); - - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [accountMetadataTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { - transaction.innerTransactions.forEach((innerTx) => { - expect((innerTx as AccountMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; - expect((innerTx as AccountMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; - expect((innerTx as AccountMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; - expect((innerTx as AccountMetadataTransaction).value, 'Value').not.to.be.undefined; - }); - }); - }); - }); - - describe('MosaicMetadataTransaction', () => { - it('aggregate', () => { - const mosaicMetadataTransaction = MosaicMetadataTransaction.create( - Deadline.create(), - account.address, - UInt64.fromUint(5), - mosaicId, - 10, - Convert.uint8ToUtf8(new Uint8Array(10)), - networkType, - helper.maxFee, - ); - - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [mosaicMetadataTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { - transaction.innerTransactions.forEach((innerTx) => { - expect((innerTx as MosaicMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; - expect((innerTx as MosaicMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; - expect((innerTx as MosaicMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; - expect((innerTx as MosaicMetadataTransaction).value, 'Value').not.to.be.undefined; - expect((innerTx as MosaicMetadataTransaction).targetMosaicId, 'TargetMosaicId').not.to.be.undefined; - }); - }); - }); - }); - - describe('NamespaceRegistrationTransaction', () => { - it('standalone', () => { - const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); - const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( - Deadline.create(), - namespaceName, - UInt64.fromUint(50), - networkType, - helper.maxFee, - ); - addressAlias = new NamespaceId(namespaceName); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { - expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; - expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; - }); - }); - }); - - describe('NamespaceRegistrationTransaction', () => { - it('standalone', () => { - const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); - const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( - Deadline.create(), - namespaceName, - UInt64.fromUint(50), - networkType, - helper.maxFee, - ); - mosaicAlias = new NamespaceId(namespaceName); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { - expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; - expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; - }); - }); - }); - - describe('NamespaceRegistrationTransaction', () => { - it('aggregate', () => { - const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( - Deadline.create(), - 'root-test-namespace-' + Math.floor(Math.random() * 10000), - UInt64.fromUint(5), - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [registerNamespaceTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('NamespaceMetadataTransaction', () => { - it('aggregate', () => { - const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( - Deadline.create(), - account.address, - UInt64.fromUint(5), - addressAlias, - 10, - Convert.uint8ToUtf8(new Uint8Array(10)), - networkType, - helper.maxFee, - ); - - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [namespaceMetadataTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { - transaction.innerTransactions.forEach((innerTx) => { - expect((innerTx as NamespaceMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; - expect((innerTx as NamespaceMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; - expect((innerTx as NamespaceMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; - expect((innerTx as NamespaceMetadataTransaction).value, 'Value').not.to.be.undefined; - expect((innerTx as NamespaceMetadataTransaction).targetNamespaceId, 'TargetNamespaceId').not.to.be.undefined; - }); - }); - }); - }); + // describe('MosaicDefinitionTransaction', () => { + // it('standalone', () => { + // const nonce = MosaicNonce.createRandom(); + // mosaicId = MosaicId.createFromNonce(nonce, account.address); + // const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( + // Deadline.create(), + // nonce, + // mosaicId, + // MosaicFlags.create(true, true, true), + // 3, + // UInt64.fromUint(1000), + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + // transactionHash = signedTransaction.hash; + + // return helper.announce(signedTransaction).then((transaction: MosaicDefinitionTransaction) => { + // expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; + // expect(transaction.nonce, 'Nonce').not.to.be.undefined; + // expect(transaction.divisibility, 'Divisibility').not.to.be.undefined; + // expect(transaction.duration, 'Duration').not.to.be.undefined; + // expect(transaction.flags.supplyMutable, 'SupplyMutable').not.to.be.undefined; + // expect(transaction.flags.transferable, 'Transferable').not.to.be.undefined; + // expect(transaction.flags.restrictable, 'Restrictable').not.to.be.undefined; + // }); + // }); + // }); + + // describe('MosaicDefinitionTransaction', () => { + // it('aggregate', () => { + // const nonce = MosaicNonce.createRandom(); + // const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( + // Deadline.create(), + // nonce, + // MosaicId.createFromNonce(nonce, account.address), + // MosaicFlags.create(true, true, true), + // 3, + // UInt64.fromUint(0), + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [mosaicDefinitionTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('AccountMetadataTransaction', () => { + // it('aggregate', () => { + // const accountMetadataTransaction = AccountMetadataTransaction.create( + // Deadline.create(), + // account.address, + // UInt64.fromUint(5), + // 10, + // Convert.uint8ToUtf8(new Uint8Array(10)), + // networkType, + // helper.maxFee, + // ); + + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [accountMetadataTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { + // transaction.innerTransactions.forEach((innerTx) => { + // expect((innerTx as AccountMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; + // expect((innerTx as AccountMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + // expect((innerTx as AccountMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + // expect((innerTx as AccountMetadataTransaction).value, 'Value').not.to.be.undefined; + // }); + // }); + // }); + // }); + + // describe('MosaicMetadataTransaction', () => { + // it('aggregate', () => { + // const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + // Deadline.create(), + // account.address, + // UInt64.fromUint(5), + // mosaicId, + // 10, + // Convert.uint8ToUtf8(new Uint8Array(10)), + // networkType, + // helper.maxFee, + // ); + + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [mosaicMetadataTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { + // transaction.innerTransactions.forEach((innerTx) => { + // expect((innerTx as MosaicMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; + // expect((innerTx as MosaicMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + // expect((innerTx as MosaicMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + // expect((innerTx as MosaicMetadataTransaction).value, 'Value').not.to.be.undefined; + // expect((innerTx as MosaicMetadataTransaction).targetMosaicId, 'TargetMosaicId').not.to.be.undefined; + // }); + // }); + // }); + // }); + + // describe('NamespaceRegistrationTransaction', () => { + // it('standalone', () => { + // const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); + // const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( + // Deadline.create(), + // namespaceName, + // UInt64.fromUint(50), + // networkType, + // helper.maxFee, + // ); + // addressAlias = new NamespaceId(namespaceName); + // const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { + // expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + // expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; + // expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; + // }); + // }); + // }); + + // describe('NamespaceRegistrationTransaction', () => { + // it('standalone', () => { + // const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); + // const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( + // Deadline.create(), + // namespaceName, + // UInt64.fromUint(50), + // networkType, + // helper.maxFee, + // ); + // mosaicAlias = new NamespaceId(namespaceName); + // const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { + // expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + // expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; + // expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; + // }); + // }); + // }); + + // describe('NamespaceRegistrationTransaction', () => { + // it('aggregate', () => { + // const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( + // Deadline.create(), + // 'root-test-namespace-' + Math.floor(Math.random() * 10000), + // UInt64.fromUint(5), + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [registerNamespaceTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('NamespaceMetadataTransaction', () => { + // it('aggregate', () => { + // const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + // Deadline.create(), + // account.address, + // UInt64.fromUint(5), + // addressAlias, + // 10, + // Convert.uint8ToUtf8(new Uint8Array(10)), + // networkType, + // helper.maxFee, + // ); + + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [namespaceMetadataTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { + // transaction.innerTransactions.forEach((innerTx) => { + // expect((innerTx as NamespaceMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; + // expect((innerTx as NamespaceMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + // expect((innerTx as NamespaceMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + // expect((innerTx as NamespaceMetadataTransaction).value, 'Value').not.to.be.undefined; + // expect((innerTx as NamespaceMetadataTransaction).targetNamespaceId, 'TargetNamespaceId').not.to.be.undefined; + // }); + // }); + // }); + // }); + + // describe('MosaicGlobalRestrictionTransaction', () => { + // it('standalone', () => { + // const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( + // Deadline.create(), + // mosaicId, + // UInt64.fromUint(60641), + // UInt64.fromUint(0), + // MosaicRestrictionType.NONE, + // UInt64.fromUint(0), + // MosaicRestrictionType.GE, + // networkType, + // undefined, + // helper.maxFee, + // ); + // const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + // describe('MosaicGlobalRestrictionTransaction', () => { + // it('aggregate', () => { + // const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( + // Deadline.create(), + // mosaicId, + // UInt64.fromUint(60641), + // UInt64.fromUint(0), + // MosaicRestrictionType.GE, + // UInt64.fromUint(1), + // MosaicRestrictionType.GE, + // networkType, + // undefined, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [mosaicGlobalRestrictionTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('MosaicAddressRestrictionTransaction', () => { + // it('aggregate', () => { + // const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create( + // Deadline.create(), + // mosaicId, + // UInt64.fromUint(60641), + // account3.address, + // UInt64.fromUint(2), + // networkType, + // undefined, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('TransferTransaction', () => { + // it('standalone', () => { + // const transferTransaction = TransferTransaction.create( + // Deadline.create(), + // account2.address, + // [helper.createNetworkCurrency(1, false)], + // PlainMessage.create('test-message'), + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = transferTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + // describe('TransferTransaction', () => { + // it('aggregate', () => { + // const transferTransaction = TransferTransaction.create( + // Deadline.create(), + // account2.address, + // [helper.createNetworkCurrency(1, false)], + // PlainMessage.create('test-message'), + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [transferTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + // describe('AccountRestrictionTransaction - Outgoing Address', () => { + // it('standalone', () => { + // const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + // Deadline.create(), + // AddressRestrictionFlag.BlockOutgoingAddress, + // [account3.address], + // [], + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = addressModification.signWith(account, generationHash); + + // return helper.announce(signedTransaction).then((transaction: AccountAddressRestrictionTransaction) => { + // expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; + // expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; + // }); + // }); + // }); + // describe('AccountRestrictionTransaction - Outgoing Address', () => { + // it('aggregate', () => { + // const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + // Deadline.create(), + // AddressRestrictionFlag.BlockOutgoingAddress, + // [], + // [account3.address], + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [addressModification.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('AccountRestrictionTransaction - Incoming Address', () => { + // it('standalone', () => { + // const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + // Deadline.create(), + // AddressRestrictionFlag.BlockIncomingAddress, + // [account3.address], + // [], + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = addressModification.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + // describe('AccountRestrictionTransaction - Incoming Address', () => { + // it('aggregate', () => { + // const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + // Deadline.create(), + // AddressRestrictionFlag.BlockIncomingAddress, + // [], + // [account3.address], + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [addressModification.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + // describe('AccountRestrictionTransaction - Mosaic', () => { + // it('standalone', () => { + // AccountRestrictionModification.createForMosaic(AccountRestrictionModificationAction.Add, mosaicId); + // const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + // Deadline.create(), + // MosaicRestrictionFlag.BlockMosaic, + // [mosaicId], + // [], + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = addressModification.signWith(account, generationHash); + + // return helper.announce(signedTransaction).then((transaction: AccountMosaicRestrictionTransaction) => { + // expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; + // expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; + // expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; + // }); + // }); + // }); + // describe('AccountRestrictionTransaction - Mosaic', () => { + // it('aggregate', () => { + // const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + // Deadline.create(), + // MosaicRestrictionFlag.BlockMosaic, + // [], + // [mosaicId], + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [addressModification.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('AccountRestrictionTransaction - Outgoing Operation', () => { + // it('standalone', () => { + // AccountRestrictionModification.createForOperation(AccountRestrictionModificationAction.Add, TransactionType.ACCOUNT_KEY_LINK); + // const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + // Deadline.create(), + // OperationRestrictionFlag.BlockOutgoingTransactionType, + // [TransactionType.ACCOUNT_KEY_LINK], + // [], + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = addressModification.signWith(account3, generationHash); + + // return helper.announce(signedTransaction).then((transaction: AccountOperationRestrictionTransaction) => { + // expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; + // expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; + // expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; + // }); + // }); + // }); + // describe('AccountRestrictionTransaction - Outgoing Operation', () => { + // it('aggregate', () => { + // const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + // Deadline.create(), + // OperationRestrictionFlag.BlockOutgoingTransactionType, + // [], + // [TransactionType.ACCOUNT_KEY_LINK], + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [addressModification.toAggregate(account3.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account3, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('AccountKeyLinkTransaction', () => { + // it('standalone', () => { + // const accountLinkTransaction = AccountKeyLinkTransaction.create( + // Deadline.create(), + // remoteAccount.publicKey, + // LinkAction.Link, + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + + // return helper.announce(signedTransaction).then((transaction: AccountKeyLinkTransaction) => { + // expect(transaction.linkedPublicKey, 'linkedPublicKey').not.to.be.undefined; + // expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; + // return signedTransaction; + // }); + // }); + // }); + // describe('AccountKeyLinkTransaction', () => { + // it('aggregate', () => { + // const accountLinkTransaction = AccountKeyLinkTransaction.create( + // Deadline.create(), + // remoteAccount.publicKey, + // LinkAction.Unlink, + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [accountLinkTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('VrfKeyLinkTransaction', () => { + // it('standalone', () => { + // const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( + // Deadline.create(), + // harvestingAccount.publicKey, + // LinkAction.Link, + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = vrfKeyLinkTransaction.signWith(account, generationHash); + + // return helper.announce(signedTransaction).then((transaction: VrfKeyLinkTransaction) => { + // expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; + // expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; + // return signedTransaction; + // }); + // }); + // }); + // describe('VrfKeyLinkTransaction', () => { + // it('aggregate', () => { + // const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( + // Deadline.create(), + // harvestingAccount.publicKey, + // LinkAction.Unlink, + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [vrfKeyLinkTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('NodeKeyLinkTransaction', () => { + // it('standalone', () => { + // const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( + // Deadline.create(), + // harvestingAccount.publicKey, + // LinkAction.Link, + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = nodeKeyLinkTransaction.signWith(account, generationHash); + + // return helper.announce(signedTransaction).then((transaction: NodeKeyLinkTransaction) => { + // expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; + // expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; + // return signedTransaction; + // }); + // }); + // }); + // describe('NodeKeyLinkTransaction', () => { + // it('aggregate', () => { + // const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( + // Deadline.create(), + // harvestingAccount.publicKey, + // LinkAction.Unlink, + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [nodeKeyLinkTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); - describe('MosaicGlobalRestrictionTransaction', () => { + describe('VotingKeyLinkTransaction', () => { it('standalone', () => { - const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( - Deadline.create(), - mosaicId, - UInt64.fromUint(60641), - UInt64.fromUint(0), - MosaicRestrictionType.NONE, - UInt64.fromUint(0), - MosaicRestrictionType.GE, - networkType, - undefined, - helper.maxFee, - ); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - describe('MosaicGlobalRestrictionTransaction', () => { - it('aggregate', () => { - const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( + const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), - mosaicId, - UInt64.fromUint(60641), - UInt64.fromUint(0), - MosaicRestrictionType.GE, + votingKey, UInt64.fromUint(1), - MosaicRestrictionType.GE, - networkType, - undefined, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [mosaicGlobalRestrictionTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('MosaicAddressRestrictionTransaction', () => { - it('aggregate', () => { - const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create( - Deadline.create(), - mosaicId, - UInt64.fromUint(60641), - account3.address, - UInt64.fromUint(2), - networkType, - undefined, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('TransferTransaction', () => { - it('standalone', () => { - const transferTransaction = TransferTransaction.create( - Deadline.create(), - account2.address, - [helper.createNetworkCurrency(1, false)], - PlainMessage.create('test-message'), - networkType, - helper.maxFee, - ); - const signedTransaction = transferTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - describe('TransferTransaction', () => { - it('aggregate', () => { - const transferTransaction = TransferTransaction.create( - Deadline.create(), - account2.address, - [helper.createNetworkCurrency(1, false)], - PlainMessage.create('test-message'), - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [transferTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - describe('AccountRestrictionTransaction - Outgoing Address', () => { - it('standalone', () => { - const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AddressRestrictionFlag.BlockOutgoingAddress, - [account3.address], - [], - networkType, - helper.maxFee, - ); - const signedTransaction = addressModification.signWith(account, generationHash); - - return helper.announce(signedTransaction).then((transaction: AccountAddressRestrictionTransaction) => { - expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; - expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - }); - }); - }); - describe('AccountRestrictionTransaction - Outgoing Address', () => { - it('aggregate', () => { - const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AddressRestrictionFlag.BlockOutgoingAddress, - [], - [account3.address], - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [addressModification.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('AccountRestrictionTransaction - Incoming Address', () => { - it('standalone', () => { - const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AddressRestrictionFlag.BlockIncomingAddress, - [account3.address], - [], - networkType, - helper.maxFee, - ); - const signedTransaction = addressModification.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - describe('AccountRestrictionTransaction - Incoming Address', () => { - it('aggregate', () => { - const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AddressRestrictionFlag.BlockIncomingAddress, - [], - [account3.address], - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [addressModification.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - describe('AccountRestrictionTransaction - Mosaic', () => { - it('standalone', () => { - AccountRestrictionModification.createForMosaic(AccountRestrictionModificationAction.Add, mosaicId); - const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( - Deadline.create(), - MosaicRestrictionFlag.BlockMosaic, - [mosaicId], - [], + UInt64.fromUint(3), + LinkAction.Link, networkType, helper.maxFee, ); - const signedTransaction = addressModification.signWith(account, generationHash); + const signedTransaction = votingLinkTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction).then((transaction: AccountMosaicRestrictionTransaction) => { - expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; - expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; - expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; + return helper.announce(signedTransaction).then((transaction: VotingKeyLinkTransaction) => { + expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; + expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; + return signedTransaction; }); }); }); - describe('AccountRestrictionTransaction - Mosaic', () => { + describe('VotingKeyLinkTransaction', () => { it('aggregate', () => { - const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + const votingLinkTransaction = VotingKeyLinkTransaction.create( Deadline.create(), - MosaicRestrictionFlag.BlockMosaic, - [], - [mosaicId], + votingKey, + UInt64.fromUint(1), + UInt64.fromUint(3), + LinkAction.Unlink, networkType, helper.maxFee, ); const aggregateTransaction = AggregateTransaction.createComplete( Deadline.create(), - [addressModification.toAggregate(account.publicAccount)], + [votingLinkTransaction.toAggregate(account.publicAccount)], networkType, [], helper.maxFee, @@ -568,978 +770,776 @@ describe('TransactionHttp', () => { }); }); - describe('AccountRestrictionTransaction - Outgoing Operation', () => { - it('standalone', () => { - AccountRestrictionModification.createForOperation(AccountRestrictionModificationAction.Add, TransactionType.ACCOUNT_KEY_LINK); - const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( - Deadline.create(), - OperationRestrictionFlag.BlockOutgoingTransactionType, - [TransactionType.ACCOUNT_KEY_LINK], - [], - networkType, - helper.maxFee, - ); - const signedTransaction = addressModification.signWith(account3, generationHash); - - return helper.announce(signedTransaction).then((transaction: AccountOperationRestrictionTransaction) => { - expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; - expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; - expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - }); - }); - }); - describe('AccountRestrictionTransaction - Outgoing Operation', () => { - it('aggregate', () => { - const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( - Deadline.create(), - OperationRestrictionFlag.BlockOutgoingTransactionType, - [], - [TransactionType.ACCOUNT_KEY_LINK], - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [addressModification.toAggregate(account3.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account3, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('AccountKeyLinkTransaction', () => { - it('standalone', () => { - const accountLinkTransaction = AccountKeyLinkTransaction.create( - Deadline.create(), - remoteAccount.publicKey, - LinkAction.Link, - networkType, - helper.maxFee, - ); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); - - return helper.announce(signedTransaction).then((transaction: AccountKeyLinkTransaction) => { - expect(transaction.linkedPublicKey, 'linkedPublicKey').not.to.be.undefined; - expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - return signedTransaction; - }); - }); - }); - describe('AccountKeyLinkTransaction', () => { - it('aggregate', () => { - const accountLinkTransaction = AccountKeyLinkTransaction.create( - Deadline.create(), - remoteAccount.publicKey, - LinkAction.Unlink, - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [accountLinkTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('VrfKeyLinkTransaction', () => { - it('standalone', () => { - const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( - Deadline.create(), - harvestingAccount.publicKey, - LinkAction.Link, - networkType, - helper.maxFee, - ); - const signedTransaction = vrfKeyLinkTransaction.signWith(account, generationHash); - - return helper.announce(signedTransaction).then((transaction: VrfKeyLinkTransaction) => { - expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; - expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - return signedTransaction; - }); - }); - }); - describe('VrfKeyLinkTransaction', () => { - it('aggregate', () => { - const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( - Deadline.create(), - harvestingAccount.publicKey, - LinkAction.Unlink, - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [vrfKeyLinkTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('NodeKeyLinkTransaction', () => { - it('standalone', () => { - const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( - Deadline.create(), - harvestingAccount.publicKey, - LinkAction.Link, - networkType, - helper.maxFee, - ); - const signedTransaction = nodeKeyLinkTransaction.signWith(account, generationHash); - - return helper.announce(signedTransaction).then((transaction: NodeKeyLinkTransaction) => { - expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; - expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - return signedTransaction; - }); - }); - }); - describe('NodeKeyLinkTransaction', () => { - it('aggregate', () => { - const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( - Deadline.create(), - harvestingAccount.publicKey, - LinkAction.Unlink, - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [nodeKeyLinkTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('VotingKeyLinkTransaction', () => { - it('standalone', () => { - const votingLinkTransaction = VotingKeyLinkTransaction.create( - Deadline.create(), - votingKey, - UInt64.fromUint(1), - UInt64.fromUint(3), - LinkAction.Link, - networkType, - helper.maxFee, - ); - const signedTransaction = votingLinkTransaction.signWith(account, generationHash); - - return helper.announce(signedTransaction).then((transaction: VotingKeyLinkTransaction) => { - expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; - expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - return signedTransaction; - }); - }); - }); - describe('VotingKeyLinkTransaction', () => { - it('aggregate', () => { - const votingLinkTransaction = VotingKeyLinkTransaction.create( - Deadline.create(), - votingKey, - UInt64.fromUint(1), - UInt64.fromUint(3), - LinkAction.Unlink, - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [votingLinkTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('AddressAliasTransaction', () => { - it('standalone', () => { - const addressAliasTransaction = AddressAliasTransaction.create( - Deadline.create(), - AliasAction.Link, - addressAlias, - account.address, - networkType, - helper.maxFee, - ); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); - - return helper.announce(signedTransaction).then((transaction: AddressAliasTransaction) => { - expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; - expect(transaction.address, 'Address').not.to.be.undefined; - }); - }); - }); - - describe('Transfer Transaction using address alias', () => { - it('Announce TransferTransaction', () => { - const transferTransaction = TransferTransaction.create( - Deadline.create(), - addressAlias, - [helper.createNetworkCurrency(1, false)], - PlainMessage.create('test-message'), - networkType, - helper.maxFee, - ); - const signedTransaction = transferTransaction.signWith(account, generationHash); - - return helper.announce(signedTransaction); - }); - }); - - describe('AddressAliasTransaction', () => { - it('aggregate', () => { - const addressAliasTransaction = AddressAliasTransaction.create( - Deadline.create(), - AliasAction.Unlink, - addressAlias, - account.address, - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [addressAliasTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('MosaicSupplyChangeTransaction', () => { - it('standalone', () => { - const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( - Deadline.create(), - mosaicId, - MosaicSupplyChangeAction.Increase, - UInt64.fromUint(10), - networkType, - helper.maxFee, - ); - const signedTransaction = mosaicSupplyChangeTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction).then((transaction: MosaicSupplyChangeTransaction) => { - expect(transaction.delta, 'Delta').not.to.be.undefined; - expect(transaction.action, 'Action').not.to.be.undefined; - expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - }); - }); - }); - describe('MosaicSupplyChangeTransaction', () => { - it('aggregate', () => { - const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( - Deadline.create(), - mosaicId, - MosaicSupplyChangeAction.Increase, - UInt64.fromUint(10), - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [mosaicSupplyChangeTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('MosaicAliasTransaction', () => { - it('standalone', () => { - const mosaicAliasTransaction = MosaicAliasTransaction.create( - Deadline.create(), - AliasAction.Link, - mosaicAlias, - mosaicId, - networkType, - helper.maxFee, - ); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); - - return helper.announce(signedTransaction).then((transaction: MosaicAliasTransaction) => { - expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; - expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - }); - }); - }); - - describe('HashLockTransaction - MosaicAlias', () => { - it('standalone', () => { - const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); - const signedTransaction = account.sign(aggregateTransaction, generationHash); - const hashLockTransaction = HashLockTransaction.create( - Deadline.create(), - new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), - UInt64.fromUint(10000), - signedTransaction, - networkType, - helper.maxFee, - ); - const hashLockSignedTransaction = hashLockTransaction.signWith(account, generationHash); - return helper.announce(hashLockSignedTransaction); - }); - }); - - describe('MosaicAliasTransaction', () => { - it('aggregate', () => { - const mosaicAliasTransaction = MosaicAliasTransaction.create( - Deadline.create(), - AliasAction.Unlink, - mosaicAlias, - mosaicId, - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [mosaicAliasTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('LockFundsTransaction', () => { - it('standalone', () => { - const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); - const signedTransaction = account.sign(aggregateTransaction, generationHash); - const lockFundsTransaction = LockFundsTransaction.create( - Deadline.create(), - new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), - UInt64.fromUint(10000), - signedTransaction, - networkType, - helper.maxFee, - ); - - return helper.announce(lockFundsTransaction.signWith(account, generationHash)); - }); - }); - describe('LockFundsTransaction', () => { - it('aggregate', () => { - const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); - const signedTransaction = account.sign(aggregateTransaction, generationHash); - const lockFundsTransaction = LockFundsTransaction.create( - Deadline.create(), - new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), - UInt64.fromUint(10), - signedTransaction, - networkType, - helper.maxFee, - ); - const aggregateLockFundsTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [lockFundsTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - return helper.announce(aggregateLockFundsTransaction.signWith(account, generationHash)); - }); - }); - - describe('Aggregate Complete Transaction', () => { - it('should announce aggregated complete transaction', () => { - const tx = TransferTransaction.create( - Deadline.create(), - account2.address, - [], - PlainMessage.create('Hi'), - networkType, - helper.maxFee, - ); - const aggTx = AggregateTransaction.createComplete( - Deadline.create(), - [tx.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = account.sign(aggTx, generationHash); - return helper.announce(signedTransaction); - }); - }); - - describe('SecretLockTransaction', () => { - it('standalone', () => { - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Sha3_256, - sha3_256.create().update(Crypto.randomBytes(20)).hex(), - account2.address, - networkType, - helper.maxFee, - ); - const signedTransaction = secretLockTransaction.signWith(account, generationHash); - return helper.announce(signedTransaction).then((transaction: SecretLockTransaction) => { - expect(transaction.mosaic, 'Mosaic').not.to.be.undefined; - expect(transaction.duration, 'Duration').not.to.be.undefined; - expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined; - expect(transaction.secret, 'Secret').not.to.be.undefined; - expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; - }); - }); - }); - describe('HashType: Op_Sha3_256', () => { - it('aggregate', () => { - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Sha3_256, - sha3_256.create().update(Crypto.randomBytes(20)).hex(), - account2.address, - networkType, - helper.maxFee, - ); - const aggregateSecretLockTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [secretLockTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); - }); - }); - - describe('HashType: Op_Hash_160', () => { - it('standalone', () => { - const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); - const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Hash_160, - secret, - account2.address, - networkType, - helper.maxFee, - ); - return helper.announce(secretLockTransaction.signWith(account, generationHash)); - }); - }); - describe('HashType: Op_Hash_160', () => { - it('aggregate', () => { - const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); - const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Hash_160, - secret, - account2.address, - networkType, - helper.maxFee, - ); - const aggregateSecretLockTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [secretLockTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); - }); - }); - describe('HashType: Op_Hash_256', () => { - it('standalone', () => { - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Hash_256, - sha3_256.create().update(Crypto.randomBytes(20)).hex(), - account2.address, - networkType, - helper.maxFee, - ); - return helper.announce(secretLockTransaction.signWith(account, generationHash)); - }); - }); - describe('HashType: Op_Hash_256', () => { - it('aggregate', () => { - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Hash_256, - sha3_256.create().update(Crypto.randomBytes(20)).hex(), - account2.address, - networkType, - helper.maxFee, - ); - const aggregateSecretLockTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [secretLockTransaction.toAggregate(account.publicAccount)], - networkType, - [], - helper.maxFee, - ); - - return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); - }); - }); - describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { - it('standalone', () => { - const secretSeed = Crypto.randomBytes(20); - const secret = LockHashUtils.Op_Sha3_256(secretSeed); - const proof = convert.uint8ToHex(secretSeed); - - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(1, ChronoUnit.HOURS), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(11), - LockHashAlgorithm.Op_Sha3_256, - secret, - account2.address, - networkType, - helper.maxFee, - ); - - const signedSecretLockTx = secretLockTransaction.signWith(account, generationHash); - - return helper.announce(signedSecretLockTx).then(() => { - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - LockHashAlgorithm.Op_Sha3_256, - secret, - account2.address, - proof, - networkType, - helper.maxFee, - ); - const signedTx = secretProofTransaction.signWith(account2, generationHash); - return helper.announce(signedTx).then((transaction: SecretProofTransaction) => { - expect(transaction.secret, 'Secret').not.to.be.undefined; - expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; - expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined; - expect(transaction.proof, 'Proof').not.to.be.undefined; - }); - }); - }); - }); - describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { - it('aggregate', () => { - const secretSeed = Crypto.randomBytes(20); - const secret = sha3_256.create().update(secretSeed).hex(); - const proof = convert.uint8ToHex(secretSeed); - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Sha3_256, - secret, - account2.address, - networkType, - helper.maxFee, - ); - - return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - LockHashAlgorithm.Op_Sha3_256, - secret, - account2.address, - proof, - networkType, - helper.maxFee, - ); - const aggregateSecretProofTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [secretProofTransaction.toAggregate(account2.publicAccount)], - networkType, - [], - helper.maxFee, - ); - return helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); - }); - }); - }); - describe('SecretProofTransaction - HashType: Op_Hash_160', () => { - it('standalone', () => { - const randomBytes = secureRandom.randomBuffer(32); - const secretSeed = randomBytes.toString('hex'); - const secret = LockHashUtils.Op_Hash_160(randomBytes); - const proof = secretSeed; - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Hash_160, - secret, - account2.address, - networkType, - helper.maxFee, - ); - - return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - LockHashAlgorithm.Op_Hash_160, - secret, - account2.address, - proof, - networkType, - helper.maxFee, - ); - const signedTx = secretProofTransaction.signWith(account2, generationHash); - return helper.announce(signedTx); - }); - }); - }); - describe('SecretProofTransaction - HashType: Op_Hash_160', () => { - it('aggregate', () => { - const randomBytes = secureRandom.randomBuffer(32); - const secretSeed = randomBytes.toString('hex'); - const hash = sha256(Buffer.from(secretSeed, 'hex')); - const secret = new ripemd160().update(Buffer.from(hash, 'hex')).digest('hex'); - const proof = secretSeed; - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Hash_160, - secret, - account2.address, - networkType, - helper.maxFee, - ); - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - LockHashAlgorithm.Op_Hash_160, - secret, - account2.address, - proof, - networkType, - helper.maxFee, - ); - const aggregateSecretProofTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [secretProofTransaction.toAggregate(account2.publicAccount)], - networkType, - [], - helper.maxFee, - ); - - return helper - .announce(secretLockTransaction.signWith(account, generationHash)) - .then(() => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); - }); - }); - describe('SecretProofTransaction - HashType: Op_Hash_256', () => { - it('standalone', () => { - const randomBytes = secureRandom.randomBuffer(32); - const secretSeed = randomBytes.toString('hex'); - // const secret = sha256(Buffer.from(hash, 'hex')); - const secret = LockHashUtils.Op_Hash_256(randomBytes); - const proof = secretSeed; - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(1, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Hash_256, - secret, - account2.address, - networkType, - helper.maxFee, - ); - - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - LockHashAlgorithm.Op_Hash_256, - secret, - account2.address, - proof, - networkType, - helper.maxFee, - ); - - return helper - .announce(secretLockTransaction.signWith(account, generationHash)) - .then(() => helper.announce(secretProofTransaction.signWith(account2, generationHash))); - }); - }); - describe('SecretProofTransaction - HashType: Op_Hash_256', () => { - it('aggregate', () => { - const randomBytes = secureRandom.randomBuffer(32); - const secretSeed = randomBytes.toString('hex'); - const hash = sha256(Buffer.from(secretSeed, 'hex')); - const secret = sha256(Buffer.from(hash, 'hex')); - const proof = secretSeed; - const secretLockTransaction = SecretLockTransaction.create( - Deadline.create(), - helper.createNetworkCurrency(10, false), - UInt64.fromUint(100), - LockHashAlgorithm.Op_Hash_256, - secret, - account2.address, - networkType, - helper.maxFee, - ); - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - LockHashAlgorithm.Op_Hash_256, - secret, - account2.address, - proof, - networkType, - helper.maxFee, - ); - const aggregateSecretProofTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [secretProofTransaction.toAggregate(account2.publicAccount)], - networkType, - [], - helper.maxFee, - ); - return helper - .announce(secretLockTransaction.signWith(account, generationHash)) - .then(() => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); - }); - }); - - describe('SignTransactionGivenSignatures', () => { - it('Announce cosign signatures given', () => { - /** - * @see https://github.com/nemtech/symbol-sdk-typescript-javascript/issues/112 - */ - // AliceAccount: account - // BobAccount: account - - const sendAmount = helper.createNetworkCurrency(1000); - const backAmount = helper.createNetworkCurrency(1); - - const aliceTransferTransaction = TransferTransaction.create( - Deadline.create(), - account2.address, - [sendAmount], - PlainMessage.create('payout'), - networkType, - helper.maxFee, - ); - const bobTransferTransaction = TransferTransaction.create( - Deadline.create(), - account.address, - [backAmount], - PlainMessage.create('payout'), - networkType, - helper.maxFee, - ); - - // 01. Alice creates the aggregated tx and sign it. Then payload send to Bob - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [aliceTransferTransaction.toAggregate(account.publicAccount), bobTransferTransaction.toAggregate(account2.publicAccount)], - networkType, - [], - helper.maxFee, - ); - - const aliceSignedTransaction = aggregateTransaction.signWith(account, generationHash); - - // 02 Bob cosigns the tx and sends it back to Alice - const signedTxBob = CosignatureTransaction.signTransactionPayload(account2, aliceSignedTransaction.payload, generationHash); - - // 03. Alice collects the cosignatures, recreate, sign, and announces the transaction - const cosignatureSignedTransactions = [ - new CosignatureSignedTransaction(signedTxBob.parentHash, signedTxBob.signature, signedTxBob.signerPublicKey), - ]; - const recreatedTx = TransactionMapping.createFromPayload(aliceSignedTransaction.payload) as AggregateTransaction; - - const signedTransaction = recreatedTx.signTransactionGivenSignatures(account, cosignatureSignedTransactions, generationHash); - - return helper.announce(signedTransaction); - }); - }); - - describe('getTransaction', () => { - it('should return transaction info given transactionHash', async () => { - const transaction = await transactionRepository.getTransaction(transactionHash, TransactionGroup.Confirmed).toPromise(); - expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); - transactionId = transaction.transactionInfo?.id!; - }); - - it('should return transaction info given transactionId', async () => { - const transaction = await transactionRepository.getTransaction(transactionId, TransactionGroup.Confirmed).toPromise(); - expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); - expect(transaction.transactionInfo!.id).to.be.equal(transactionId); - }); - }); - - describe('getTransactionsById', () => { - it('should return transaction info given array of transactionHash', async () => { - const transactions = await transactionRepository.getTransactionsById([transactionHash]).toPromise(); - expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); - expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); - }); - - it('should return transaction info given array of transactionId', async () => { - const transactions = await transactionRepository.getTransactionsById([transactionId]).toPromise(); - expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); - expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); - }); - }); - - describe('getTransactionStatus', () => { - it('should return transaction status given transactionHash', async () => { - await new Promise((resolve) => setTimeout(resolve, 2000)); - const transactionStatus = await transactionStatusRepository.getTransactionStatus(transactionHash).toPromise(); - expect(transactionStatus.group).to.be.equal('confirmed'); - expect(transactionStatus.height!.lower).to.be.greaterThan(0); - expect(transactionStatus.height!.higher).to.be.equal(0); - }); - }); - - describe('getTransactionsStatuses', () => { - it('should return transaction status given array of transactionHash', async () => { - const transactionStatuses = await transactionStatusRepository.getTransactionStatuses([transactionHash]).toPromise(); - expect(transactionStatuses[0].group).to.be.equal('confirmed'); - expect(transactionStatuses[0].height!.lower).to.be.greaterThan(0); - expect(transactionStatuses[0].height!.higher).to.be.equal(0); - }); - }); - - describe('announce', () => { - it('should return success when announce', async () => { - const transferTransaction = TransferTransaction.create( - Deadline.create(), - account2.address, - [helper.createNetworkCurrency(1, false)], - PlainMessage.create('test-message'), - networkType, - helper.maxFee, - ); - const signedTransaction = transferTransaction.signWith(account, generationHash); - const transactionAnnounceResponse = await transactionRepository.announce(signedTransaction).toPromise(); - expect(transactionAnnounceResponse.message).to.be.equal('packet 9 was pushed to the network via /transactions'); - }); - }); - - describe('announceAggregateBonded', () => { - it('should return success when announceAggregateBonded', async () => { - const transferTransaction = TransferTransaction.create( - Deadline.create(), - account2.address, - [helper.createNetworkCurrency(1)], - PlainMessage.create('test-message'), - networkType, - helper.maxFee, - ); - const aggregateTransaction = AggregateTransaction.createBonded( - Deadline.create(2, ChronoUnit.MINUTES), - [transferTransaction.toAggregate(multisigAccount.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(cosignAccount1, generationHash); - const transactionAnnounceResponse = await transactionRepository.announceAggregateBonded(signedTransaction).toPromise(); - expect(transactionAnnounceResponse.message).to.be.equal('packet 500 was pushed to the network via /transactions/partial'); - }); - }); - - describe('announceAggregateBondedCosignature', () => { - it('should return success when announceAggregateBondedCosignature', async () => { - const payload = new CosignatureSignedTransaction('', '', ''); - const transactionAnnounceResponse = await transactionRepository.announceAggregateBondedCosignature(payload).toPromise(); - expect(transactionAnnounceResponse.message).to.be.equal('packet 501 was pushed to the network via /transactions/cosignature'); - }); - }); - - describe('getTransactionEffectiveFee', () => { - it('should return effective paid fee given transactionHash', async () => { - const effectiveFee = await transactionRepository.getTransactionEffectiveFee(transactionHash).toPromise(); - expect(effectiveFee).to.not.be.undefined; - expect(effectiveFee).not.to.be.equal(0); - }); - }); - - describe('searchTransactions', () => { - it('should return transaction info given address', async () => { - const transactions = await transactionRepository - .search({ group: TransactionGroup.Confirmed, address: account.address } as TransactionSearchCriteria) - .toPromise(); - expect(transactions.data.length).to.be.greaterThan(0); - }); - it('should return transaction info given height all types', async () => { - const transactions = await transactionRepository - .search({ group: TransactionGroup.Confirmed, height: UInt64.fromUint(1) } as TransactionSearchCriteria) - .toPromise(); - - const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; - const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; - const others = transactions.data.filter( - (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, - ).length; - expect(mosaicDefinitions).to.be.greaterThan(0); - expect(namespaceRegistration).to.be.greaterThan(0); - expect(others).to.be.greaterThan(0); - }); - - it('should return transaction info given height and namesapce, mosaic types', async () => { - const transactions = await transactionRepository - .search({ - group: TransactionGroup.Confirmed, - height: UInt64.fromUint(1), - type: [TransactionType.MOSAIC_DEFINITION, TransactionType.NAMESPACE_REGISTRATION], - } as TransactionSearchCriteria) - .toPromise(); - const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; - const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; - const others = transactions.data.filter( - (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, - ).length; - expect(mosaicDefinitions).to.be.greaterThan(0); - expect(namespaceRegistration).to.be.greaterThan(0); - expect(others).to.eq(0); - }); - }); - - describe('searchTransactions using steamer', () => { - it('should return transaction info given address', async () => { - const streamer = new TransactionPaginationStreamer(transactionRepository); - const transactionsNoStreamer = await transactionRepository - .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 } as TransactionSearchCriteria) - .toPromise(); - const transactions = await streamer - .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 }) - .pipe(take(10), toArray()) - .toPromise(); - expect(transactions.length).to.be.greaterThan(0); - deepEqual(transactionsNoStreamer.data, transactions); - }); - }); + // describe('AddressAliasTransaction', () => { + // it('standalone', () => { + // const addressAliasTransaction = AddressAliasTransaction.create( + // Deadline.create(), + // AliasAction.Link, + // addressAlias, + // account.address, + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + + // return helper.announce(signedTransaction).then((transaction: AddressAliasTransaction) => { + // expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + // expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; + // expect(transaction.address, 'Address').not.to.be.undefined; + // }); + // }); + // }); + + // describe('Transfer Transaction using address alias', () => { + // it('Announce TransferTransaction', () => { + // const transferTransaction = TransferTransaction.create( + // Deadline.create(), + // addressAlias, + // [helper.createNetworkCurrency(1, false)], + // PlainMessage.create('test-message'), + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = transferTransaction.signWith(account, generationHash); + + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('AddressAliasTransaction', () => { + // it('aggregate', () => { + // const addressAliasTransaction = AddressAliasTransaction.create( + // Deadline.create(), + // AliasAction.Unlink, + // addressAlias, + // account.address, + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [addressAliasTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('MosaicSupplyChangeTransaction', () => { + // it('standalone', () => { + // const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( + // Deadline.create(), + // mosaicId, + // MosaicSupplyChangeAction.Increase, + // UInt64.fromUint(10), + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = mosaicSupplyChangeTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction).then((transaction: MosaicSupplyChangeTransaction) => { + // expect(transaction.delta, 'Delta').not.to.be.undefined; + // expect(transaction.action, 'Action').not.to.be.undefined; + // expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; + // }); + // }); + // }); + // describe('MosaicSupplyChangeTransaction', () => { + // it('aggregate', () => { + // const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( + // Deadline.create(), + // mosaicId, + // MosaicSupplyChangeAction.Increase, + // UInt64.fromUint(10), + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [mosaicSupplyChangeTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('MosaicAliasTransaction', () => { + // it('standalone', () => { + // const mosaicAliasTransaction = MosaicAliasTransaction.create( + // Deadline.create(), + // AliasAction.Link, + // mosaicAlias, + // mosaicId, + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + + // return helper.announce(signedTransaction).then((transaction: MosaicAliasTransaction) => { + // expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + // expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; + // expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; + // }); + // }); + // }); + + // describe('HashLockTransaction - MosaicAlias', () => { + // it('standalone', () => { + // const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); + // const signedTransaction = account.sign(aggregateTransaction, generationHash); + // const hashLockTransaction = HashLockTransaction.create( + // Deadline.create(), + // new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), + // UInt64.fromUint(10000), + // signedTransaction, + // networkType, + // helper.maxFee, + // ); + // const hashLockSignedTransaction = hashLockTransaction.signWith(account, generationHash); + // return helper.announce(hashLockSignedTransaction); + // }); + // }); + + // describe('MosaicAliasTransaction', () => { + // it('aggregate', () => { + // const mosaicAliasTransaction = MosaicAliasTransaction.create( + // Deadline.create(), + // AliasAction.Unlink, + // mosaicAlias, + // mosaicId, + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [mosaicAliasTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('LockFundsTransaction', () => { + // it('standalone', () => { + // const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); + // const signedTransaction = account.sign(aggregateTransaction, generationHash); + // const lockFundsTransaction = LockFundsTransaction.create( + // Deadline.create(), + // new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), + // UInt64.fromUint(10000), + // signedTransaction, + // networkType, + // helper.maxFee, + // ); + + // return helper.announce(lockFundsTransaction.signWith(account, generationHash)); + // }); + // }); + // describe('LockFundsTransaction', () => { + // it('aggregate', () => { + // const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); + // const signedTransaction = account.sign(aggregateTransaction, generationHash); + // const lockFundsTransaction = LockFundsTransaction.create( + // Deadline.create(), + // new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), + // UInt64.fromUint(10), + // signedTransaction, + // networkType, + // helper.maxFee, + // ); + // const aggregateLockFundsTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [lockFundsTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // return helper.announce(aggregateLockFundsTransaction.signWith(account, generationHash)); + // }); + // }); + + // describe('Aggregate Complete Transaction', () => { + // it('should announce aggregated complete transaction', () => { + // const tx = TransferTransaction.create( + // Deadline.create(), + // account2.address, + // [], + // PlainMessage.create('Hi'), + // networkType, + // helper.maxFee, + // ); + // const aggTx = AggregateTransaction.createComplete( + // Deadline.create(), + // [tx.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = account.sign(aggTx, generationHash); + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('SecretLockTransaction', () => { + // it('standalone', () => { + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Sha3_256, + // sha3_256.create().update(Crypto.randomBytes(20)).hex(), + // account2.address, + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = secretLockTransaction.signWith(account, generationHash); + // return helper.announce(signedTransaction).then((transaction: SecretLockTransaction) => { + // expect(transaction.mosaic, 'Mosaic').not.to.be.undefined; + // expect(transaction.duration, 'Duration').not.to.be.undefined; + // expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined; + // expect(transaction.secret, 'Secret').not.to.be.undefined; + // expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; + // }); + // }); + // }); + // describe('HashType: Op_Sha3_256', () => { + // it('aggregate', () => { + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Sha3_256, + // sha3_256.create().update(Crypto.randomBytes(20)).hex(), + // account2.address, + // networkType, + // helper.maxFee, + // ); + // const aggregateSecretLockTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [secretLockTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + // }); + // }); + + // describe('HashType: Op_Hash_160', () => { + // it('standalone', () => { + // const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); + // const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Hash_160, + // secret, + // account2.address, + // networkType, + // helper.maxFee, + // ); + // return helper.announce(secretLockTransaction.signWith(account, generationHash)); + // }); + // }); + // describe('HashType: Op_Hash_160', () => { + // it('aggregate', () => { + // const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); + // const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Hash_160, + // secret, + // account2.address, + // networkType, + // helper.maxFee, + // ); + // const aggregateSecretLockTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [secretLockTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + // }); + // }); + // describe('HashType: Op_Hash_256', () => { + // it('standalone', () => { + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Hash_256, + // sha3_256.create().update(Crypto.randomBytes(20)).hex(), + // account2.address, + // networkType, + // helper.maxFee, + // ); + // return helper.announce(secretLockTransaction.signWith(account, generationHash)); + // }); + // }); + // describe('HashType: Op_Hash_256', () => { + // it('aggregate', () => { + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Hash_256, + // sha3_256.create().update(Crypto.randomBytes(20)).hex(), + // account2.address, + // networkType, + // helper.maxFee, + // ); + // const aggregateSecretLockTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [secretLockTransaction.toAggregate(account.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + + // return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + // }); + // }); + // describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { + // it('standalone', () => { + // const secretSeed = Crypto.randomBytes(20); + // const secret = LockHashUtils.Op_Sha3_256(secretSeed); + // const proof = convert.uint8ToHex(secretSeed); + + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(1, ChronoUnit.HOURS), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(11), + // LockHashAlgorithm.Op_Sha3_256, + // secret, + // account2.address, + // networkType, + // helper.maxFee, + // ); + + // const signedSecretLockTx = secretLockTransaction.signWith(account, generationHash); + + // return helper.announce(signedSecretLockTx).then(() => { + // const secretProofTransaction = SecretProofTransaction.create( + // Deadline.create(), + // LockHashAlgorithm.Op_Sha3_256, + // secret, + // account2.address, + // proof, + // networkType, + // helper.maxFee, + // ); + // const signedTx = secretProofTransaction.signWith(account2, generationHash); + // return helper.announce(signedTx).then((transaction: SecretProofTransaction) => { + // expect(transaction.secret, 'Secret').not.to.be.undefined; + // expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; + // expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined; + // expect(transaction.proof, 'Proof').not.to.be.undefined; + // }); + // }); + // }); + // }); + // describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { + // it('aggregate', () => { + // const secretSeed = Crypto.randomBytes(20); + // const secret = sha3_256.create().update(secretSeed).hex(); + // const proof = convert.uint8ToHex(secretSeed); + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Sha3_256, + // secret, + // account2.address, + // networkType, + // helper.maxFee, + // ); + + // return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { + // const secretProofTransaction = SecretProofTransaction.create( + // Deadline.create(), + // LockHashAlgorithm.Op_Sha3_256, + // secret, + // account2.address, + // proof, + // networkType, + // helper.maxFee, + // ); + // const aggregateSecretProofTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [secretProofTransaction.toAggregate(account2.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // return helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); + // }); + // }); + // }); + // describe('SecretProofTransaction - HashType: Op_Hash_160', () => { + // it('standalone', () => { + // const randomBytes = secureRandom.randomBuffer(32); + // const secretSeed = randomBytes.toString('hex'); + // const secret = LockHashUtils.Op_Hash_160(randomBytes); + // const proof = secretSeed; + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Hash_160, + // secret, + // account2.address, + // networkType, + // helper.maxFee, + // ); + + // return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { + // const secretProofTransaction = SecretProofTransaction.create( + // Deadline.create(), + // LockHashAlgorithm.Op_Hash_160, + // secret, + // account2.address, + // proof, + // networkType, + // helper.maxFee, + // ); + // const signedTx = secretProofTransaction.signWith(account2, generationHash); + // return helper.announce(signedTx); + // }); + // }); + // }); + // describe('SecretProofTransaction - HashType: Op_Hash_160', () => { + // it('aggregate', () => { + // const randomBytes = secureRandom.randomBuffer(32); + // const secretSeed = randomBytes.toString('hex'); + // const hash = sha256(Buffer.from(secretSeed, 'hex')); + // const secret = new ripemd160().update(Buffer.from(hash, 'hex')).digest('hex'); + // const proof = secretSeed; + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Hash_160, + // secret, + // account2.address, + // networkType, + // helper.maxFee, + // ); + // const secretProofTransaction = SecretProofTransaction.create( + // Deadline.create(), + // LockHashAlgorithm.Op_Hash_160, + // secret, + // account2.address, + // proof, + // networkType, + // helper.maxFee, + // ); + // const aggregateSecretProofTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [secretProofTransaction.toAggregate(account2.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + + // return helper + // .announce(secretLockTransaction.signWith(account, generationHash)) + // .then(() => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); + // }); + // }); + // describe('SecretProofTransaction - HashType: Op_Hash_256', () => { + // it('standalone', () => { + // const randomBytes = secureRandom.randomBuffer(32); + // const secretSeed = randomBytes.toString('hex'); + // // const secret = sha256(Buffer.from(hash, 'hex')); + // const secret = LockHashUtils.Op_Hash_256(randomBytes); + // const proof = secretSeed; + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(1, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Hash_256, + // secret, + // account2.address, + // networkType, + // helper.maxFee, + // ); + + // const secretProofTransaction = SecretProofTransaction.create( + // Deadline.create(), + // LockHashAlgorithm.Op_Hash_256, + // secret, + // account2.address, + // proof, + // networkType, + // helper.maxFee, + // ); + + // return helper + // .announce(secretLockTransaction.signWith(account, generationHash)) + // .then(() => helper.announce(secretProofTransaction.signWith(account2, generationHash))); + // }); + // }); + // describe('SecretProofTransaction - HashType: Op_Hash_256', () => { + // it('aggregate', () => { + // const randomBytes = secureRandom.randomBuffer(32); + // const secretSeed = randomBytes.toString('hex'); + // const hash = sha256(Buffer.from(secretSeed, 'hex')); + // const secret = sha256(Buffer.from(hash, 'hex')); + // const proof = secretSeed; + // const secretLockTransaction = SecretLockTransaction.create( + // Deadline.create(), + // helper.createNetworkCurrency(10, false), + // UInt64.fromUint(100), + // LockHashAlgorithm.Op_Hash_256, + // secret, + // account2.address, + // networkType, + // helper.maxFee, + // ); + // const secretProofTransaction = SecretProofTransaction.create( + // Deadline.create(), + // LockHashAlgorithm.Op_Hash_256, + // secret, + // account2.address, + // proof, + // networkType, + // helper.maxFee, + // ); + // const aggregateSecretProofTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [secretProofTransaction.toAggregate(account2.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // return helper + // .announce(secretLockTransaction.signWith(account, generationHash)) + // .then(() => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); + // }); + // }); + + // describe('SignTransactionGivenSignatures', () => { + // it('Announce cosign signatures given', () => { + // /** + // * @see https://github.com/nemtech/symbol-sdk-typescript-javascript/issues/112 + // */ + // // AliceAccount: account + // // BobAccount: account + + // const sendAmount = helper.createNetworkCurrency(1000); + // const backAmount = helper.createNetworkCurrency(1); + + // const aliceTransferTransaction = TransferTransaction.create( + // Deadline.create(), + // account2.address, + // [sendAmount], + // PlainMessage.create('payout'), + // networkType, + // helper.maxFee, + // ); + // const bobTransferTransaction = TransferTransaction.create( + // Deadline.create(), + // account.address, + // [backAmount], + // PlainMessage.create('payout'), + // networkType, + // helper.maxFee, + // ); + + // // 01. Alice creates the aggregated tx and sign it. Then payload send to Bob + // const aggregateTransaction = AggregateTransaction.createComplete( + // Deadline.create(), + // [aliceTransferTransaction.toAggregate(account.publicAccount), bobTransferTransaction.toAggregate(account2.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + + // const aliceSignedTransaction = aggregateTransaction.signWith(account, generationHash); + + // // 02 Bob cosigns the tx and sends it back to Alice + // const signedTxBob = CosignatureTransaction.signTransactionPayload(account2, aliceSignedTransaction.payload, generationHash); + + // // 03. Alice collects the cosignatures, recreate, sign, and announces the transaction + // const cosignatureSignedTransactions = [ + // new CosignatureSignedTransaction(signedTxBob.parentHash, signedTxBob.signature, signedTxBob.signerPublicKey), + // ]; + // const recreatedTx = TransactionMapping.createFromPayload(aliceSignedTransaction.payload) as AggregateTransaction; + + // const signedTransaction = recreatedTx.signTransactionGivenSignatures(account, cosignatureSignedTransactions, generationHash); + + // return helper.announce(signedTransaction); + // }); + // }); + + // describe('getTransaction', () => { + // it('should return transaction info given transactionHash', async () => { + // const transaction = await transactionRepository.getTransaction(transactionHash, TransactionGroup.Confirmed).toPromise(); + // expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); + // transactionId = transaction.transactionInfo?.id!; + // }); + + // it('should return transaction info given transactionId', async () => { + // const transaction = await transactionRepository.getTransaction(transactionId, TransactionGroup.Confirmed).toPromise(); + // expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); + // expect(transaction.transactionInfo!.id).to.be.equal(transactionId); + // }); + // }); + + // describe('getTransactionsById', () => { + // it('should return transaction info given array of transactionHash', async () => { + // const transactions = await transactionRepository.getTransactionsById([transactionHash]).toPromise(); + // expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); + // expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); + // }); + + // it('should return transaction info given array of transactionId', async () => { + // const transactions = await transactionRepository.getTransactionsById([transactionId]).toPromise(); + // expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); + // expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); + // }); + // }); + + // describe('getTransactionStatus', () => { + // it('should return transaction status given transactionHash', async () => { + // await new Promise((resolve) => setTimeout(resolve, 2000)); + // const transactionStatus = await transactionStatusRepository.getTransactionStatus(transactionHash).toPromise(); + // expect(transactionStatus.group).to.be.equal('confirmed'); + // expect(transactionStatus.height!.lower).to.be.greaterThan(0); + // expect(transactionStatus.height!.higher).to.be.equal(0); + // }); + // }); + + // describe('getTransactionsStatuses', () => { + // it('should return transaction status given array of transactionHash', async () => { + // const transactionStatuses = await transactionStatusRepository.getTransactionStatuses([transactionHash]).toPromise(); + // expect(transactionStatuses[0].group).to.be.equal('confirmed'); + // expect(transactionStatuses[0].height!.lower).to.be.greaterThan(0); + // expect(transactionStatuses[0].height!.higher).to.be.equal(0); + // }); + // }); + + // describe('announce', () => { + // it('should return success when announce', async () => { + // const transferTransaction = TransferTransaction.create( + // Deadline.create(), + // account2.address, + // [helper.createNetworkCurrency(1, false)], + // PlainMessage.create('test-message'), + // networkType, + // helper.maxFee, + // ); + // const signedTransaction = transferTransaction.signWith(account, generationHash); + // const transactionAnnounceResponse = await transactionRepository.announce(signedTransaction).toPromise(); + // expect(transactionAnnounceResponse.message).to.be.equal('packet 9 was pushed to the network via /transactions'); + // }); + // }); + + // describe('announceAggregateBonded', () => { + // it('should return success when announceAggregateBonded', async () => { + // const transferTransaction = TransferTransaction.create( + // Deadline.create(), + // account2.address, + // [helper.createNetworkCurrency(1)], + // PlainMessage.create('test-message'), + // networkType, + // helper.maxFee, + // ); + // const aggregateTransaction = AggregateTransaction.createBonded( + // Deadline.create(2, ChronoUnit.MINUTES), + // [transferTransaction.toAggregate(multisigAccount.publicAccount)], + // networkType, + // [], + // helper.maxFee, + // ); + // const signedTransaction = aggregateTransaction.signWith(cosignAccount1, generationHash); + // const transactionAnnounceResponse = await transactionRepository.announceAggregateBonded(signedTransaction).toPromise(); + // expect(transactionAnnounceResponse.message).to.be.equal('packet 256 was pushed to the network via /transactions/partial'); + // }); + // }); + + // describe('announceAggregateBondedCosignature', () => { + // it('should return success when announceAggregateBondedCosignature', async () => { + // const payload = new CosignatureSignedTransaction('', '', ''); + // const transactionAnnounceResponse = await transactionRepository.announceAggregateBondedCosignature(payload).toPromise(); + // expect(transactionAnnounceResponse.message).to.be.equal('packet 257 was pushed to the network via /transactions/cosignature'); + // }); + // }); + + // describe('getTransactionEffectiveFee', () => { + // it('should return effective paid fee given transactionHash', async () => { + // const effectiveFee = await transactionRepository.getTransactionEffectiveFee(transactionHash).toPromise(); + // expect(effectiveFee).to.not.be.undefined; + // expect(effectiveFee).not.to.be.equal(0); + // }); + // }); + + // describe('searchTransactions', () => { + // it('should return transaction info given address', async () => { + // const transactions = await transactionRepository + // .search({ group: TransactionGroup.Confirmed, address: account.address } as TransactionSearchCriteria) + // .toPromise(); + // expect(transactions.data.length).to.be.greaterThan(0); + // }); + // it('should return transaction info given height all types', async () => { + // const transactions = await transactionRepository + // .search({ group: TransactionGroup.Confirmed, height: UInt64.fromUint(1) } as TransactionSearchCriteria) + // .toPromise(); + + // const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; + // const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; + // const others = transactions.data.filter( + // (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, + // ).length; + // expect(mosaicDefinitions).to.be.greaterThan(0); + // expect(namespaceRegistration).to.be.greaterThan(0); + // expect(others).to.be.greaterThan(0); + // }); + + // it('should return transaction info given height and namesapce, mosaic types', async () => { + // const transactions = await transactionRepository + // .search({ + // group: TransactionGroup.Confirmed, + // height: UInt64.fromUint(1), + // type: [TransactionType.MOSAIC_DEFINITION, TransactionType.NAMESPACE_REGISTRATION], + // } as TransactionSearchCriteria) + // .toPromise(); + // const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; + // const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; + // const others = transactions.data.filter( + // (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, + // ).length; + // expect(mosaicDefinitions).to.be.greaterThan(0); + // expect(namespaceRegistration).to.be.greaterThan(0); + // expect(others).to.eq(0); + // }); + // }); + + // describe('searchTransactions using steamer', () => { + // it('should return transaction info given address', async () => { + // const streamer = new TransactionPaginationStreamer(transactionRepository); + // const transactionsNoStreamer = await transactionRepository + // .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 } as TransactionSearchCriteria) + // .toPromise(); + // const transactions = await streamer + // .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 }) + // .pipe(take(10), toArray()) + // .toPromise(); + // expect(transactions.length).to.be.greaterThan(0); + // deepEqual(transactionsNoStreamer.data, transactions); + // }); + // }); }); diff --git a/package-lock.json b/package-lock.json index db1b56cad3..27a42ee052 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5965,9 +5965,9 @@ } }, "symbol-openapi-typescript-fetch-client": { - "version": "0.9.3-SNAPSHOT.202006242326", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3-SNAPSHOT.202006242326.tgz", - "integrity": "sha512-sTtrKo6soJ6OPQpPjPRBZPyMurXADT+H1fmM67z+YGyzzDhjfQmVDt0FZRCnazCKo4OntVo1S3Ow4AUF305uiQ==" + "version": "0.9.3-SNAPSHOT.202006261500", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3-SNAPSHOT.202006261500.tgz", + "integrity": "sha512-Qq8jTeT2fxTTar3bkHSC1mlJ/lzmkmkNNRzzvP999IymfwfB7GNxnguYg8sKWuRQKezM5QlcKhmzwRY1MMD9SQ==" }, "table": { "version": "5.4.6", diff --git a/package.json b/package.json index 69ed2d84f2..5461874bce 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006242326", + "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006261500", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index 7c5e5b92ca..5e63c0c020 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -79,17 +79,34 @@ export class TransactionHttp extends Http implements TransactionRepository { /** * Gets an array of transactions for different transaction ids * @param transactionIds - Array of transactions id and/or hash. + * @param transactionGroup - Transaction group. * @returns Observable */ - public getTransactionsById(transactionIds: string[]): Observable { + public getTransactionsById(transactionIds: string[], transactionGroup: TransactionGroup): Observable { const transactionIdsBody = { transactionIds, }; - return this.call(this.transactionRoutesApi.getTransactionsById(transactionIdsBody), (body) => - body.map((transactionDTO) => { - return CreateTransactionFromDTO(transactionDTO); - }), - ); + + switch (transactionGroup) { + case TransactionGroup.Confirmed: + return this.call(this.transactionRoutesApi.getConfirmedTransactions(transactionIdsBody), (body) => + body.map((transactionDTO) => { + return CreateTransactionFromDTO(transactionDTO); + }), + ); + case TransactionGroup.Unconfirmed: + return this.call(this.transactionRoutesApi.getUnconfirmedTransactions(transactionIdsBody), (body) => + body.map((transactionDTO) => { + return CreateTransactionFromDTO(transactionDTO); + }), + ); + case TransactionGroup.Partial: + return this.call(this.transactionRoutesApi.getPartialTransactions(transactionIdsBody), (body) => + body.map((transactionDTO) => { + return CreateTransactionFromDTO(transactionDTO); + }), + ); + } } /** diff --git a/src/infrastructure/TransactionRepository.ts b/src/infrastructure/TransactionRepository.ts index bdbaa8b98e..b6501fc0d2 100644 --- a/src/infrastructure/TransactionRepository.ts +++ b/src/infrastructure/TransactionRepository.ts @@ -40,10 +40,10 @@ export interface TransactionRepository extends Searcher */ - getTransactionsById(transactionIds: string[]): Observable; - + getTransactionsById(transactionIds: string[], transactionGroup: TransactionGroup): Observable; /** * Gets a transaction's effective paid fee * @param transactionId - Transaction id or hash. diff --git a/src/service/TransactionService.ts b/src/service/TransactionService.ts index 3d2bdbb906..657c00fd09 100644 --- a/src/service/TransactionService.ts +++ b/src/service/TransactionService.ts @@ -36,6 +36,7 @@ import { TransactionStatusError } from '../model/transaction/TransactionStatusEr import { TransactionType } from '../model/transaction/TransactionType'; import { TransferTransaction } from '../model/transaction/TransferTransaction'; import { ITransactionService } from './interfaces/ITransactionService'; +import { TransactionGroup } from '../infrastructure/TransactionGroup'; /** * Transaction Service @@ -54,7 +55,7 @@ export class TransactionService implements ITransactionService { * @returns Observable */ public resolveAliases(transationHashes: string[]): Observable { - return this.transactionRepository.getTransactionsById(transationHashes).pipe( + return this.transactionRepository.getTransactionsById(transationHashes, TransactionGroup.Confirmed).pipe( mergeMap((_) => _), mergeMap((transaction) => this.resolveTransaction(transaction)), toArray(), diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 99eedefa8e..86283ac63d 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -286,19 +286,49 @@ describe('TransactionHttp', () => { transactionInfoDto.meta = metaDto; transactionInfoDto.transaction = transactionDto; - when(transactionRoutesApi.getTransactionsById(deepEqual({ transactionIds: [generationHash] }))).thenReturn( + when(transactionRoutesApi.getConfirmedTransactions(deepEqual({ transactionIds: [generationHash] }))).thenReturn( Promise.resolve([transactionInfoDto]), ); - const transaction = await transactionHttp.getTransactionsById([generationHash]).toPromise(); + const transactionConfirmed = await transactionHttp.getTransactionsById([generationHash], TransactionGroup.Confirmed).toPromise(); - expect(transaction.length).to.be.equal(1); - expect(transaction[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); - expect(((transaction[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + when(transactionRoutesApi.getUnconfirmedTransactions(deepEqual({ transactionIds: [generationHash] }))).thenReturn( + Promise.resolve([transactionInfoDto]), + ); + + const transactionUnconfirmed = await transactionHttp + .getTransactionsById([generationHash], TransactionGroup.Unconfirmed) + .toPromise(); + + when(transactionRoutesApi.getPartialTransactions(deepEqual({ transactionIds: [generationHash] }))).thenReturn( + Promise.resolve([transactionInfoDto]), + ); + + const transactionPartial = await transactionHttp.getTransactionsById([generationHash], TransactionGroup.Partial).toPromise(); + + expect(transactionConfirmed.length).to.be.equal(1); + expect(transactionConfirmed[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transactionConfirmed[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), + ); + expect(transactionConfirmed[0].transactionInfo?.id).to.be.equal('id'); + expect(transactionConfirmed[0].transactionInfo?.hash).to.be.equal('hash'); + + expect(transactionUnconfirmed.length).to.be.equal(1); + expect(transactionUnconfirmed[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transactionUnconfirmed[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), + ); + expect(transactionUnconfirmed[0].transactionInfo?.id).to.be.equal('id'); + expect(transactionUnconfirmed[0].transactionInfo?.hash).to.be.equal('hash'); + + expect(transactionPartial.length).to.be.equal(1); + expect(transactionPartial[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transactionPartial[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), ); - expect(transaction[0].transactionInfo?.id).to.be.equal('id'); - expect(transaction[0].transactionInfo?.hash).to.be.equal('hash'); + expect(transactionPartial[0].transactionInfo?.id).to.be.equal('id'); + expect(transactionPartial[0].transactionInfo?.hash).to.be.equal('hash'); }); it('Test getEffectiveFees method', async () => { @@ -420,11 +450,11 @@ describe('TransactionHttp', () => { }); it('getTransactionById - Error', async () => { - when(transactionRoutesApi.getTransactionsById(deepEqual({ transactionIds: [generationHash] }))).thenReject( + when(transactionRoutesApi.getConfirmedTransactions(deepEqual({ transactionIds: [generationHash] }))).thenReject( new Error('Mocked Error'), ); await transactionHttp - .getTransactionsById([generationHash]) + .getTransactionsById([generationHash], TransactionGroup.Confirmed) .toPromise() .catch((error) => expect(error).not.to.be.undefined); }); From 1d710627e73090091b87b3df5815cd1b7ac98dce Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 26 Jun 2020 18:30:05 +0100 Subject: [PATCH 16/18] Fixed supplemental key dto --- package-lock.json | 6 +- package.json | 2 +- src/infrastructure/AccountHttp.ts | 26 +++++- src/model/account/AccountInfo.ts | 4 +- ...{AccountKey.ts => AccountLinkPublicKey.ts} | 14 +--- src/model/account/AccountLinkVotingKey.ts | 38 +++++++++ src/model/account/SupplementalPublicKeys.ts | 45 ++++++++++ src/model/model.ts | 4 +- test/infrastructure/AccountHttp.spec.ts | 26 ++++-- test/model/account/AccountInfo.spec.ts | 41 +++++++++- test/model/account/AccountKey.spec.ts | 82 +++++++++++++------ test/service/AccountService.spec.ts | 5 +- test/service/MosaicService.spec.ts | 3 +- 13 files changed, 236 insertions(+), 60 deletions(-) rename src/model/account/{AccountKey.ts => AccountLinkPublicKey.ts} (71%) create mode 100644 src/model/account/AccountLinkVotingKey.ts create mode 100644 src/model/account/SupplementalPublicKeys.ts diff --git a/package-lock.json b/package-lock.json index 27a42ee052..12b83f4af2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5965,9 +5965,9 @@ } }, "symbol-openapi-typescript-fetch-client": { - "version": "0.9.3-SNAPSHOT.202006261500", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3-SNAPSHOT.202006261500.tgz", - "integrity": "sha512-Qq8jTeT2fxTTar3bkHSC1mlJ/lzmkmkNNRzzvP999IymfwfB7GNxnguYg8sKWuRQKezM5QlcKhmzwRY1MMD9SQ==" + "version": "0.9.3-SNAPSHOT.202006261816", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3-SNAPSHOT.202006261816.tgz", + "integrity": "sha512-ODaW+wM0W0huxzjQvF2TdzuQm3lraRJumIFcrn+FSl5qB5fan7hOlmAlvCTg2cSE6r8gAUHF/twOJdPNjnp/gQ==" }, "table": { "version": "5.4.6", diff --git a/package.json b/package.json index 5461874bce..f7543320a8 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006261500", + "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006261816", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 0071eb4828..ae7ce99581 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -17,7 +17,6 @@ import { Observable } from 'rxjs'; import { AccountInfoDTO, AccountRoutesApi } from 'symbol-openapi-typescript-fetch-client'; import { AccountInfo } from '../model/account/AccountInfo'; -import { AccountKey } from '../model/account/AccountKey'; import { ActivityBucket } from '../model/account/ActivityBucket'; import { Address } from '../model/account/Address'; import { Mosaic } from '../model/mosaic/Mosaic'; @@ -25,6 +24,9 @@ import { MosaicId } from '../model/mosaic/MosaicId'; import { UInt64 } from '../model/UInt64'; import { AccountRepository } from './AccountRepository'; import { Http } from './Http'; +import { SupplementalPublicKeys } from '../model/account/SupplementalPublicKeys'; +import { AccountLinkPublicKey } from '../model/account/AccountLinkPublicKey'; +import { AccountLinkVotingKey } from '../model/account/AccountLinkVotingKey'; /** * Account http repository. @@ -83,7 +85,27 @@ export class AccountHttp extends Http implements AccountRepository { dto.account.publicKey, UInt64.fromNumericString(dto.account.publicKeyHeight), dto.account.accountType.valueOf(), - dto.account.supplementalPublicKeys.map((key) => new AccountKey(key.keyType.valueOf(), key.key)), + new SupplementalPublicKeys( + dto.account.supplementalPublicKeys.linked + ? new AccountLinkPublicKey(dto.account.supplementalPublicKeys.linked?.publicKey) + : undefined, + dto.account.supplementalPublicKeys.node + ? new AccountLinkPublicKey(dto.account.supplementalPublicKeys.node?.publicKey) + : undefined, + dto.account.supplementalPublicKeys.vrf + ? new AccountLinkPublicKey(dto.account.supplementalPublicKeys.vrf?.publicKey) + : undefined, + dto.account.supplementalPublicKeys.voting + ? dto.account.supplementalPublicKeys.voting?.publicKeys.map( + (v) => + new AccountLinkVotingKey( + v.publicKey, + UInt64.fromNumericString(v.startPoint), + UInt64.fromNumericString(v.endPoint), + ), + ) + : undefined, + ), dto.account.activityBuckets.map((bucket) => { return new ActivityBucket( UInt64.fromNumericString(bucket.startHeight), diff --git a/src/model/account/AccountInfo.ts b/src/model/account/AccountInfo.ts index 58f8fcc792..06d63d95ef 100644 --- a/src/model/account/AccountInfo.ts +++ b/src/model/account/AccountInfo.ts @@ -20,7 +20,7 @@ import { AccountType } from './AccountType'; import { ActivityBucket } from './ActivityBucket'; import { Address } from './Address'; import { PublicAccount } from './PublicAccount'; -import { AccountKey } from './AccountKey'; +import { SupplementalPublicKeys } from './SupplementalPublicKeys'; /** * The account info structure describes basic information for an account. @@ -53,7 +53,7 @@ export class AccountInfo { /** * Account keys */ - public readonly supplementalPublicKeys: AccountKey[], + public readonly supplementalPublicKeys: SupplementalPublicKeys, /** * Account activity bucket */ diff --git a/src/model/account/AccountKey.ts b/src/model/account/AccountLinkPublicKey.ts similarity index 71% rename from src/model/account/AccountKey.ts rename to src/model/account/AccountLinkPublicKey.ts index 9b2947e57f..67f1db97a1 100644 --- a/src/model/account/AccountKey.ts +++ b/src/model/account/AccountLinkPublicKey.ts @@ -1,5 +1,5 @@ /* - * Copyright 2019 NEM + * Copyright 2020 NEM * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,17 @@ * limitations under the License. */ -import { AccountKeyTypeFlags } from './AccountKeyTypeFlags'; - /** * Account key */ -export class AccountKey { +export class AccountLinkPublicKey { /** * */ constructor( /** - * Account key key - */ - public readonly keyType: AccountKeyTypeFlags, - /** - * Key + * public key */ - public readonly key: string, + public readonly publicKey: string, ) {} } diff --git a/src/model/account/AccountLinkVotingKey.ts b/src/model/account/AccountLinkVotingKey.ts new file mode 100644 index 0000000000..1b559688a1 --- /dev/null +++ b/src/model/account/AccountLinkVotingKey.ts @@ -0,0 +1,38 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { UInt64 } from '../UInt64'; +/** + * Account link voting key + */ +export class AccountLinkVotingKey { + /** + * + */ + constructor( + /** + * public key + */ + public readonly publicKey: string, + /** + * Start point + */ + public readonly startPoint: UInt64, + /** + * End point + */ + public readonly endPoint: UInt64, + ) {} +} diff --git a/src/model/account/SupplementalPublicKeys.ts b/src/model/account/SupplementalPublicKeys.ts new file mode 100644 index 0000000000..d22daaf841 --- /dev/null +++ b/src/model/account/SupplementalPublicKeys.ts @@ -0,0 +1,45 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AccountLinkPublicKey } from './AccountLinkPublicKey'; +import { AccountLinkVotingKey } from './AccountLinkVotingKey'; + +/** + * SupplementalPublicKeys + */ +export class SupplementalPublicKeys { + /** + * + */ + constructor( + /** + * Linked keys + */ + public readonly linked?: AccountLinkPublicKey, + /** + * Node linked keys + */ + public readonly node?: AccountLinkPublicKey, + /** + * VRF linked keys + */ + public readonly vrf?: AccountLinkPublicKey, + /** + * Voting linked keys + */ + public readonly voting?: AccountLinkVotingKey[], + ) {} +} diff --git a/src/model/model.ts b/src/model/model.ts index 207e94c0c0..3fabef5fe4 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -29,7 +29,9 @@ export * from './account/PublicAccount'; export * from './account/AccountNames'; export * from './account/AccountInfoResolvedMosaic'; export * from './account/AccountKeyTypeFlags'; -export * from './account/AccountKey'; +export * from './account/AccountLinkPublicKey'; +export * from './account/AccountLinkVotingKey'; +export * from './account/SupplementalPublicKeys'; export * from './account/UnresolvedAddress'; // Blockchain diff --git a/test/infrastructure/AccountHttp.spec.ts b/test/infrastructure/AccountHttp.spec.ts index 8a8e9fa622..7827bc829f 100644 --- a/test/infrastructure/AccountHttp.spec.ts +++ b/test/infrastructure/AccountHttp.spec.ts @@ -19,11 +19,12 @@ import { AccountDTO, AccountIds, AccountInfoDTO, - AccountKeyDTO, AccountRoutesApi, AccountTypeEnum, ActivityBucketDTO, Mosaic, + AccountLinkPublicKeyDTO, + AccountLinkVotingKeyDTO, } from 'symbol-openapi-typescript-fetch-client'; import { deepEqual, instance, mock, reset, when } from 'ts-mockito'; import { DtoMapping } from '../../src/core/utils/DtoMapping'; @@ -53,10 +54,14 @@ describe('AccountHttp', () => { accountDTO.importance = '222'; accountDTO.importanceHeight = '333'; accountDTO.publicKeyHeight = '444'; - const accountKeyDto = {} as AccountKeyDTO; - accountKeyDto.key = 'abc'; - accountKeyDto.keyType = 1; - accountDTO.supplementalPublicKeys = [accountKeyDto]; + const accountKeyDto: AccountLinkPublicKeyDTO = { publicKey: 'abc' }; + const accountVotingKeyDto: AccountLinkVotingKeyDTO = { publicKey: 'abc', startPoint: '1', endPoint: '3' }; + accountDTO.supplementalPublicKeys = { + linked: accountKeyDto, + node: accountKeyDto, + vrf: accountKeyDto, + voting: { publicKeys: [accountVotingKeyDto] }, + }; accountDTO.publicKey = 'AAA'; accountDTO.activityBuckets = []; accountDTO.mosaics = [mosaic]; @@ -85,10 +90,13 @@ describe('AccountHttp', () => { expect(accountInfo.importanceHeight.toString()).to.be.equals(accountDTO.importanceHeight); expect(accountInfo.publicKeyHeight.toString()).to.be.equals(accountDTO.publicKeyHeight); expect(accountInfo.publicKey).to.be.equals(accountDTO.publicKey); - expect(accountInfo.supplementalPublicKeys[0].key).to.be.equals(accountDTO.supplementalPublicKeys[0].key); - expect(accountInfo.supplementalPublicKeys[0].keyType.valueOf()).to.be.equals( - accountDTO.supplementalPublicKeys[0].keyType.valueOf(), - ); + expect(accountInfo.supplementalPublicKeys.linked?.publicKey).to.be.equals('abc'); + expect(accountInfo.supplementalPublicKeys.node?.publicKey).to.be.equals('abc'); + expect(accountInfo.supplementalPublicKeys.vrf?.publicKey).to.be.equals('abc'); + expect(accountInfo.supplementalPublicKeys.voting?.length).to.be.equals(1); + expect(accountInfo.supplementalPublicKeys.voting![0].publicKey).to.be.equals('abc'); + expect(accountInfo.supplementalPublicKeys.voting![0].endPoint.toString()).to.be.equals('3'); + expect(accountInfo.supplementalPublicKeys.voting![0].startPoint.toString()).to.be.equals('1'); expect(accountInfo.mosaics.length).to.be.equals(1); expect(accountInfo.mosaics[0].id.id.toHex()).to.be.equals(mosaic.id); expect(accountInfo.mosaics[0].amount.toString()).to.be.equals(mosaic.amount); diff --git a/test/model/account/AccountInfo.spec.ts b/test/model/account/AccountInfo.spec.ts index c6e33458b1..c1e4e15a41 100644 --- a/test/model/account/AccountInfo.spec.ts +++ b/test/model/account/AccountInfo.spec.ts @@ -24,7 +24,9 @@ import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { NetworkType } from '../../../src/model/network/NetworkType'; import { UInt64 } from '../../../src/model/UInt64'; -import { AccountKey } from '../../../src/model/account/AccountKey'; +import { SupplementalPublicKeys } from '../../../src/model/account/SupplementalPublicKeys'; +import { AccountLinkPublicKey } from '../../../src/model/account/AccountLinkPublicKey'; +import { AccountLinkVotingKey } from '../../../src/model/account/AccountLinkVotingKey'; describe('AccountInfo', () => { it('should createComplete an AccountInfo object', () => { @@ -35,7 +37,20 @@ describe('AccountInfo', () => { importance: new UInt64([405653170, 0]), importanceHeight: new UInt64([6462, 0]), accountType: 0, - supplementalAccountKeys: [{ keyType: 1, key: '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144' }], + supplementalPublicKeys: { + linked: { publicKey: '2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F' }, + node: { publicKey: '2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F' }, + vrf: { publicKey: '2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F' }, + voting: { + publicKeys: [ + { + publicKey: '2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F', + startPoint: '1', + endpoint: '3', + }, + ], + }, + }, activityBucket: [ { startHeight: '1000', @@ -61,7 +76,27 @@ describe('AccountInfo', () => { accountInfoDTO.account.publicKey, accountInfoDTO.account.publicKeyHeight, accountInfoDTO.account.accountType, - accountInfoDTO.account.supplementalAccountKeys.map((key) => new AccountKey(key.keyType.valueOf(), key.key)), + new SupplementalPublicKeys( + accountInfoDTO.account.supplementalPublicKeys.linked + ? new AccountLinkPublicKey(accountInfoDTO.account.supplementalPublicKeys.linked?.publicKey) + : undefined, + accountInfoDTO.account.supplementalPublicKeys.node + ? new AccountLinkPublicKey(accountInfoDTO.account.supplementalPublicKeys.node?.publicKey) + : undefined, + accountInfoDTO.account.supplementalPublicKeys.vrf + ? new AccountLinkPublicKey(accountInfoDTO.account.supplementalPublicKeys.vrf?.publicKey) + : undefined, + accountInfoDTO.account.supplementalPublicKeys.voting + ? accountInfoDTO.account.supplementalPublicKeys.voting?.publicKeys.map( + (v) => + new AccountLinkVotingKey( + v.publicKey, + UInt64.fromNumericString(v.startPoint), + UInt64.fromNumericString(v.startPoint), + ), + ) + : undefined, + ), accountInfoDTO.account.activityBucket.map( (bucket) => new ActivityBucket( diff --git a/test/model/account/AccountKey.spec.ts b/test/model/account/AccountKey.spec.ts index bc8abc6cf0..b32c598519 100644 --- a/test/model/account/AccountKey.spec.ts +++ b/test/model/account/AccountKey.spec.ts @@ -14,31 +14,63 @@ * limitations under the License. */ -import { deepEqual } from 'assert'; import { expect } from 'chai'; -import { AccountKey } from '../../../src/model/account/AccountKey'; -import { AccountKeyTypeFlags } from '../../../src/model/account/AccountKeyTypeFlags'; - -describe('AccountKey', () => { - it('should createComplete an AccountKey object', () => { - let accountKey = new AccountKey(AccountKeyTypeFlags.Unset, 'abc'); - expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.Unset.valueOf()); - - accountKey = new AccountKey(AccountKeyTypeFlags.Linked, 'abc'); - expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.Linked.valueOf()); - - accountKey = new AccountKey(AccountKeyTypeFlags.Node, 'abc'); - expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.Node.valueOf()); - - accountKey = new AccountKey(AccountKeyTypeFlags.VRF, 'abc'); - expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.VRF.valueOf()); - - accountKey = new AccountKey(AccountKeyTypeFlags.All, 'abc'); - expect(accountKey.key).to.be.equal('abc'); - deepEqual(accountKey.keyType.valueOf(), AccountKeyTypeFlags.All.valueOf()); +import { AccountLinkPublicKey } from '../../../src/model/account/AccountLinkPublicKey'; +import { AccountLinkVotingKey } from '../../../src/model/account/AccountLinkVotingKey'; +import { UInt64 } from '../../../src/model/UInt64'; +import { SupplementalPublicKeys } from '../../../src/model/account/SupplementalPublicKeys'; + +describe('AccountLinkPublicKey', () => { + it('should createComplete an AccountLinkPublicKey object', () => { + const accountKey = new AccountLinkPublicKey('abc'); + expect(accountKey.publicKey).to.be.equal('abc'); + }); +}); + +describe('AccountLinkVotingKey', () => { + it('should createComplete an AccountLinkVotingKey object', () => { + const accountKey = new AccountLinkVotingKey('abc', UInt64.fromUint(1), UInt64.fromUint(3)); + expect(accountKey.publicKey).to.be.equal('abc'); + expect(accountKey.startPoint.toString()).to.be.equal('1'); + expect(accountKey.endPoint.toString()).to.be.equal('3'); + }); +}); + +describe('SupplementalPublicKeys', () => { + it('should createComplete an SupplementalPublicKeys object', () => { + let accountKey = new SupplementalPublicKeys(); + expect(accountKey.voting).to.be.undefined; + expect(accountKey.node).to.be.undefined; + expect(accountKey.vrf).to.be.undefined; + expect(accountKey.linked).to.be.undefined; + + accountKey = new SupplementalPublicKeys(new AccountLinkPublicKey('abc')); + expect(accountKey.voting).to.be.undefined; + expect(accountKey.node).to.be.undefined; + expect(accountKey.vrf).to.be.undefined; + expect(accountKey.linked?.publicKey).to.be.eq('abc'); + + accountKey = new SupplementalPublicKeys(undefined, new AccountLinkPublicKey('abc')); + expect(accountKey.voting).to.be.undefined; + expect(accountKey.node?.publicKey).to.be.eq('abc'); + expect(accountKey.vrf).to.be.undefined; + expect(accountKey.linked).to.be.undefined; + + accountKey = new SupplementalPublicKeys(undefined, undefined, new AccountLinkPublicKey('abc')); + expect(accountKey.voting).to.be.undefined; + expect(accountKey.node).to.be.undefined; + expect(accountKey.vrf?.publicKey).to.be.eq('abc'); + expect(accountKey.linked).to.be.undefined; + + accountKey = new SupplementalPublicKeys(undefined, undefined, undefined, [ + new AccountLinkVotingKey('abc', UInt64.fromUint(1), UInt64.fromUint(3)), + ]); + expect(accountKey.voting).not.to.be.undefined; + expect(accountKey.voting![0].publicKey).to.be.eq('abc'); + expect(accountKey.voting![0].startPoint.toString()).to.be.eq('1'); + expect(accountKey.voting![0].endPoint.toString()).to.be.eq('3'); + expect(accountKey.node).to.be.undefined; + expect(accountKey.vrf).to.be.undefined; + expect(accountKey.linked).to.be.undefined; }); }); diff --git a/test/service/AccountService.spec.ts b/test/service/AccountService.spec.ts index 0472081834..f6ca06b726 100644 --- a/test/service/AccountService.spec.ts +++ b/test/service/AccountService.spec.ts @@ -36,8 +36,7 @@ import { MosaicAlias } from '../../src/model/namespace/MosaicAlias'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NamespaceName } from '../../src/model/namespace/NamespaceName'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; -import { AccountKey } from '../../src/model/account/AccountKey'; -import { AccountKeyTypeFlags } from '../../src/model/account/AccountKeyTypeFlags'; +import { SupplementalPublicKeys } from '../../src/model/account/SupplementalPublicKeys'; describe('AccountService', () => { let accountService: AccountService; @@ -59,7 +58,7 @@ describe('AccountService', () => { account.publicKey, UInt64.fromUint(100), AccountType.Main, - [new AccountKey(AccountKeyTypeFlags.Linked, '0')], + new SupplementalPublicKeys(), [new ActivityBucket(UInt64.fromUint(0), UInt64.fromUint(1), 1, UInt64.fromUint(1))], mosaics, UInt64.fromUint(100), diff --git a/test/service/MosaicService.spec.ts b/test/service/MosaicService.spec.ts index e18c6ef709..8c945ea82f 100644 --- a/test/service/MosaicService.spec.ts +++ b/test/service/MosaicService.spec.ts @@ -31,6 +31,7 @@ import { TestingAccount } from '../conf/conf.spec'; import { AccountType } from '../../src/model/account/AccountType'; import { AccountInfo } from '../../src/model/account/AccountInfo'; import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; +import { SupplementalPublicKeys } from '../../src/model/account/SupplementalPublicKeys'; describe('MosaicService', () => { const accountRepositoryMock = mock(); @@ -57,7 +58,7 @@ describe('MosaicService', () => { TestingAccount.publicKey, UInt64.fromUint(1), AccountType.Main, - [], + new SupplementalPublicKeys(), [], isEmptyMosaic ? [] : [new Mosaic(mosaicId, UInt64.fromUint(100))], UInt64.fromUint(1), From 1f8652dad28b9b534748a2356e43296c348353e5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 26 Jun 2020 18:40:02 +0100 Subject: [PATCH 17/18] Fixed e2e test and updated packge verion --- e2e/infrastructure/TransactionHttp.spec.ts | 2762 ++++++++++---------- package-lock.json | 12 +- package.json | 4 +- 3 files changed, 1390 insertions(+), 1388 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 1908a7cb4f..13188b5bf9 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -135,632 +135,430 @@ describe('TransactionHttp', () => { }); }); - // describe('MosaicDefinitionTransaction', () => { - // it('standalone', () => { - // const nonce = MosaicNonce.createRandom(); - // mosaicId = MosaicId.createFromNonce(nonce, account.address); - // const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( - // Deadline.create(), - // nonce, - // mosaicId, - // MosaicFlags.create(true, true, true), - // 3, - // UInt64.fromUint(1000), - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - // transactionHash = signedTransaction.hash; - - // return helper.announce(signedTransaction).then((transaction: MosaicDefinitionTransaction) => { - // expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - // expect(transaction.nonce, 'Nonce').not.to.be.undefined; - // expect(transaction.divisibility, 'Divisibility').not.to.be.undefined; - // expect(transaction.duration, 'Duration').not.to.be.undefined; - // expect(transaction.flags.supplyMutable, 'SupplyMutable').not.to.be.undefined; - // expect(transaction.flags.transferable, 'Transferable').not.to.be.undefined; - // expect(transaction.flags.restrictable, 'Restrictable').not.to.be.undefined; - // }); - // }); - // }); - - // describe('MosaicDefinitionTransaction', () => { - // it('aggregate', () => { - // const nonce = MosaicNonce.createRandom(); - // const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( - // Deadline.create(), - // nonce, - // MosaicId.createFromNonce(nonce, account.address), - // MosaicFlags.create(true, true, true), - // 3, - // UInt64.fromUint(0), - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [mosaicDefinitionTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('AccountMetadataTransaction', () => { - // it('aggregate', () => { - // const accountMetadataTransaction = AccountMetadataTransaction.create( - // Deadline.create(), - // account.address, - // UInt64.fromUint(5), - // 10, - // Convert.uint8ToUtf8(new Uint8Array(10)), - // networkType, - // helper.maxFee, - // ); - - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [accountMetadataTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { - // transaction.innerTransactions.forEach((innerTx) => { - // expect((innerTx as AccountMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; - // expect((innerTx as AccountMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; - // expect((innerTx as AccountMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; - // expect((innerTx as AccountMetadataTransaction).value, 'Value').not.to.be.undefined; - // }); - // }); - // }); - // }); - - // describe('MosaicMetadataTransaction', () => { - // it('aggregate', () => { - // const mosaicMetadataTransaction = MosaicMetadataTransaction.create( - // Deadline.create(), - // account.address, - // UInt64.fromUint(5), - // mosaicId, - // 10, - // Convert.uint8ToUtf8(new Uint8Array(10)), - // networkType, - // helper.maxFee, - // ); - - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [mosaicMetadataTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { - // transaction.innerTransactions.forEach((innerTx) => { - // expect((innerTx as MosaicMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; - // expect((innerTx as MosaicMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; - // expect((innerTx as MosaicMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; - // expect((innerTx as MosaicMetadataTransaction).value, 'Value').not.to.be.undefined; - // expect((innerTx as MosaicMetadataTransaction).targetMosaicId, 'TargetMosaicId').not.to.be.undefined; - // }); - // }); - // }); - // }); - - // describe('NamespaceRegistrationTransaction', () => { - // it('standalone', () => { - // const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); - // const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( - // Deadline.create(), - // namespaceName, - // UInt64.fromUint(50), - // networkType, - // helper.maxFee, - // ); - // addressAlias = new NamespaceId(namespaceName); - // const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { - // expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - // expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; - // expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; - // }); - // }); - // }); - - // describe('NamespaceRegistrationTransaction', () => { - // it('standalone', () => { - // const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); - // const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( - // Deadline.create(), - // namespaceName, - // UInt64.fromUint(50), - // networkType, - // helper.maxFee, - // ); - // mosaicAlias = new NamespaceId(namespaceName); - // const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { - // expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - // expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; - // expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; - // }); - // }); - // }); - - // describe('NamespaceRegistrationTransaction', () => { - // it('aggregate', () => { - // const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( - // Deadline.create(), - // 'root-test-namespace-' + Math.floor(Math.random() * 10000), - // UInt64.fromUint(5), - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [registerNamespaceTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('NamespaceMetadataTransaction', () => { - // it('aggregate', () => { - // const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( - // Deadline.create(), - // account.address, - // UInt64.fromUint(5), - // addressAlias, - // 10, - // Convert.uint8ToUtf8(new Uint8Array(10)), - // networkType, - // helper.maxFee, - // ); - - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [namespaceMetadataTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { - // transaction.innerTransactions.forEach((innerTx) => { - // expect((innerTx as NamespaceMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; - // expect((innerTx as NamespaceMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; - // expect((innerTx as NamespaceMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; - // expect((innerTx as NamespaceMetadataTransaction).value, 'Value').not.to.be.undefined; - // expect((innerTx as NamespaceMetadataTransaction).targetNamespaceId, 'TargetNamespaceId').not.to.be.undefined; - // }); - // }); - // }); - // }); - - // describe('MosaicGlobalRestrictionTransaction', () => { - // it('standalone', () => { - // const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( - // Deadline.create(), - // mosaicId, - // UInt64.fromUint(60641), - // UInt64.fromUint(0), - // MosaicRestrictionType.NONE, - // UInt64.fromUint(0), - // MosaicRestrictionType.GE, - // networkType, - // undefined, - // helper.maxFee, - // ); - // const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - // describe('MosaicGlobalRestrictionTransaction', () => { - // it('aggregate', () => { - // const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( - // Deadline.create(), - // mosaicId, - // UInt64.fromUint(60641), - // UInt64.fromUint(0), - // MosaicRestrictionType.GE, - // UInt64.fromUint(1), - // MosaicRestrictionType.GE, - // networkType, - // undefined, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [mosaicGlobalRestrictionTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('MosaicAddressRestrictionTransaction', () => { - // it('aggregate', () => { - // const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create( - // Deadline.create(), - // mosaicId, - // UInt64.fromUint(60641), - // account3.address, - // UInt64.fromUint(2), - // networkType, - // undefined, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('TransferTransaction', () => { - // it('standalone', () => { - // const transferTransaction = TransferTransaction.create( - // Deadline.create(), - // account2.address, - // [helper.createNetworkCurrency(1, false)], - // PlainMessage.create('test-message'), - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = transferTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - // describe('TransferTransaction', () => { - // it('aggregate', () => { - // const transferTransaction = TransferTransaction.create( - // Deadline.create(), - // account2.address, - // [helper.createNetworkCurrency(1, false)], - // PlainMessage.create('test-message'), - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [transferTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - // describe('AccountRestrictionTransaction - Outgoing Address', () => { - // it('standalone', () => { - // const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - // Deadline.create(), - // AddressRestrictionFlag.BlockOutgoingAddress, - // [account3.address], - // [], - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = addressModification.signWith(account, generationHash); - - // return helper.announce(signedTransaction).then((transaction: AccountAddressRestrictionTransaction) => { - // expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; - // expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - // }); - // }); - // }); - // describe('AccountRestrictionTransaction - Outgoing Address', () => { - // it('aggregate', () => { - // const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - // Deadline.create(), - // AddressRestrictionFlag.BlockOutgoingAddress, - // [], - // [account3.address], - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [addressModification.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('AccountRestrictionTransaction - Incoming Address', () => { - // it('standalone', () => { - // const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - // Deadline.create(), - // AddressRestrictionFlag.BlockIncomingAddress, - // [account3.address], - // [], - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = addressModification.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - // describe('AccountRestrictionTransaction - Incoming Address', () => { - // it('aggregate', () => { - // const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - // Deadline.create(), - // AddressRestrictionFlag.BlockIncomingAddress, - // [], - // [account3.address], - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [addressModification.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - // describe('AccountRestrictionTransaction - Mosaic', () => { - // it('standalone', () => { - // AccountRestrictionModification.createForMosaic(AccountRestrictionModificationAction.Add, mosaicId); - // const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( - // Deadline.create(), - // MosaicRestrictionFlag.BlockMosaic, - // [mosaicId], - // [], - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = addressModification.signWith(account, generationHash); - - // return helper.announce(signedTransaction).then((transaction: AccountMosaicRestrictionTransaction) => { - // expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; - // expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; - // expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - // }); - // }); - // }); - // describe('AccountRestrictionTransaction - Mosaic', () => { - // it('aggregate', () => { - // const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( - // Deadline.create(), - // MosaicRestrictionFlag.BlockMosaic, - // [], - // [mosaicId], - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [addressModification.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('AccountRestrictionTransaction - Outgoing Operation', () => { - // it('standalone', () => { - // AccountRestrictionModification.createForOperation(AccountRestrictionModificationAction.Add, TransactionType.ACCOUNT_KEY_LINK); - // const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( - // Deadline.create(), - // OperationRestrictionFlag.BlockOutgoingTransactionType, - // [TransactionType.ACCOUNT_KEY_LINK], - // [], - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = addressModification.signWith(account3, generationHash); - - // return helper.announce(signedTransaction).then((transaction: AccountOperationRestrictionTransaction) => { - // expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; - // expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; - // expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - // }); - // }); - // }); - // describe('AccountRestrictionTransaction - Outgoing Operation', () => { - // it('aggregate', () => { - // const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( - // Deadline.create(), - // OperationRestrictionFlag.BlockOutgoingTransactionType, - // [], - // [TransactionType.ACCOUNT_KEY_LINK], - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [addressModification.toAggregate(account3.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account3, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('AccountKeyLinkTransaction', () => { - // it('standalone', () => { - // const accountLinkTransaction = AccountKeyLinkTransaction.create( - // Deadline.create(), - // remoteAccount.publicKey, - // LinkAction.Link, - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = accountLinkTransaction.signWith(account, generationHash); - - // return helper.announce(signedTransaction).then((transaction: AccountKeyLinkTransaction) => { - // expect(transaction.linkedPublicKey, 'linkedPublicKey').not.to.be.undefined; - // expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - // return signedTransaction; - // }); - // }); - // }); - // describe('AccountKeyLinkTransaction', () => { - // it('aggregate', () => { - // const accountLinkTransaction = AccountKeyLinkTransaction.create( - // Deadline.create(), - // remoteAccount.publicKey, - // LinkAction.Unlink, - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [accountLinkTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('VrfKeyLinkTransaction', () => { - // it('standalone', () => { - // const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( - // Deadline.create(), - // harvestingAccount.publicKey, - // LinkAction.Link, - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = vrfKeyLinkTransaction.signWith(account, generationHash); - - // return helper.announce(signedTransaction).then((transaction: VrfKeyLinkTransaction) => { - // expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; - // expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - // return signedTransaction; - // }); - // }); - // }); - // describe('VrfKeyLinkTransaction', () => { - // it('aggregate', () => { - // const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( - // Deadline.create(), - // harvestingAccount.publicKey, - // LinkAction.Unlink, - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [vrfKeyLinkTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('NodeKeyLinkTransaction', () => { - // it('standalone', () => { - // const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( - // Deadline.create(), - // harvestingAccount.publicKey, - // LinkAction.Link, - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = nodeKeyLinkTransaction.signWith(account, generationHash); - - // return helper.announce(signedTransaction).then((transaction: NodeKeyLinkTransaction) => { - // expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; - // expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - // return signedTransaction; - // }); - // }); - // }); - // describe('NodeKeyLinkTransaction', () => { - // it('aggregate', () => { - // const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( - // Deadline.create(), - // harvestingAccount.publicKey, - // LinkAction.Unlink, - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [nodeKeyLinkTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); + describe('MosaicDefinitionTransaction', () => { + it('standalone', () => { + const nonce = MosaicNonce.createRandom(); + mosaicId = MosaicId.createFromNonce(nonce, account.address); + const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( + Deadline.create(), + nonce, + mosaicId, + MosaicFlags.create(true, true, true), + 3, + UInt64.fromUint(1000), + networkType, + helper.maxFee, + ); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + transactionHash = signedTransaction.hash; + + return helper.announce(signedTransaction).then((transaction: MosaicDefinitionTransaction) => { + expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; + expect(transaction.nonce, 'Nonce').not.to.be.undefined; + expect(transaction.divisibility, 'Divisibility').not.to.be.undefined; + expect(transaction.duration, 'Duration').not.to.be.undefined; + expect(transaction.flags.supplyMutable, 'SupplyMutable').not.to.be.undefined; + expect(transaction.flags.transferable, 'Transferable').not.to.be.undefined; + expect(transaction.flags.restrictable, 'Restrictable').not.to.be.undefined; + }); + }); + }); - describe('VotingKeyLinkTransaction', () => { + describe('MosaicDefinitionTransaction', () => { + it('aggregate', () => { + const nonce = MosaicNonce.createRandom(); + const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( + Deadline.create(), + nonce, + MosaicId.createFromNonce(nonce, account.address), + MosaicFlags.create(true, true, true), + 3, + UInt64.fromUint(0), + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [mosaicDefinitionTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('AccountMetadataTransaction', () => { + it('aggregate', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.address, + UInt64.fromUint(5), + 10, + Convert.uint8ToUtf8(new Uint8Array(10)), + networkType, + helper.maxFee, + ); + + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [accountMetadataTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as AccountMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).value, 'Value').not.to.be.undefined; + }); + }); + }); + }); + + describe('MosaicMetadataTransaction', () => { + it('aggregate', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.address, + UInt64.fromUint(5), + mosaicId, + 10, + Convert.uint8ToUtf8(new Uint8Array(10)), + networkType, + helper.maxFee, + ); + + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [mosaicMetadataTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as MosaicMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).value, 'Value').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).targetMosaicId, 'TargetMosaicId').not.to.be.undefined; + }); + }); + }); + }); + + describe('NamespaceRegistrationTransaction', () => { it('standalone', () => { - const votingLinkTransaction = VotingKeyLinkTransaction.create( + const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); + const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), - votingKey, - UInt64.fromUint(1), - UInt64.fromUint(3), - LinkAction.Link, + namespaceName, + UInt64.fromUint(50), networkType, helper.maxFee, ); - const signedTransaction = votingLinkTransaction.signWith(account, generationHash); + addressAlias = new NamespaceId(namespaceName); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { + expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; + expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; + }); + }); + }); - return helper.announce(signedTransaction).then((transaction: VotingKeyLinkTransaction) => { - expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; - expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - return signedTransaction; + describe('NamespaceRegistrationTransaction', () => { + it('standalone', () => { + const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); + const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( + Deadline.create(), + namespaceName, + UInt64.fromUint(50), + networkType, + helper.maxFee, + ); + mosaicAlias = new NamespaceId(namespaceName); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { + expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; + expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; }); }); }); - describe('VotingKeyLinkTransaction', () => { + + describe('NamespaceRegistrationTransaction', () => { it('aggregate', () => { - const votingLinkTransaction = VotingKeyLinkTransaction.create( + const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), - votingKey, + 'root-test-namespace-' + Math.floor(Math.random() * 10000), + UInt64.fromUint(5), + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [registerNamespaceTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('NamespaceMetadataTransaction', () => { + it('aggregate', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.address, + UInt64.fromUint(5), + addressAlias, + 10, + Convert.uint8ToUtf8(new Uint8Array(10)), + networkType, + helper.maxFee, + ); + + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [namespaceMetadataTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as NamespaceMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).value, 'Value').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).targetNamespaceId, 'TargetNamespaceId').not.to.be.undefined; + }); + }); + }); + }); + + describe('MosaicGlobalRestrictionTransaction', () => { + it('standalone', () => { + const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( + Deadline.create(), + mosaicId, + UInt64.fromUint(60641), + UInt64.fromUint(0), + MosaicRestrictionType.NONE, + UInt64.fromUint(0), + MosaicRestrictionType.GE, + networkType, + undefined, + helper.maxFee, + ); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + describe('MosaicGlobalRestrictionTransaction', () => { + it('aggregate', () => { + const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( + Deadline.create(), + mosaicId, + UInt64.fromUint(60641), + UInt64.fromUint(0), + MosaicRestrictionType.GE, UInt64.fromUint(1), - UInt64.fromUint(3), - LinkAction.Unlink, + MosaicRestrictionType.GE, networkType, + undefined, helper.maxFee, ); const aggregateTransaction = AggregateTransaction.createComplete( Deadline.create(), - [votingLinkTransaction.toAggregate(account.publicAccount)], + [mosaicGlobalRestrictionTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('MosaicAddressRestrictionTransaction', () => { + it('aggregate', () => { + const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create( + Deadline.create(), + mosaicId, + UInt64.fromUint(60641), + account3.address, + UInt64.fromUint(2), + networkType, + undefined, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('TransferTransaction', () => { + it('standalone', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + [helper.createNetworkCurrency(1, false)], + PlainMessage.create('test-message'), + networkType, + helper.maxFee, + ); + const signedTransaction = transferTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + describe('TransferTransaction', () => { + it('aggregate', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + [helper.createNetworkCurrency(1, false)], + PlainMessage.create('test-message'), + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [transferTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Address', () => { + it('standalone', () => { + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AddressRestrictionFlag.BlockOutgoingAddress, + [account3.address], + [], + networkType, + helper.maxFee, + ); + const signedTransaction = addressModification.signWith(account, generationHash); + + return helper.announce(signedTransaction).then((transaction: AccountAddressRestrictionTransaction) => { + expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; + expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; + }); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Address', () => { + it('aggregate', () => { + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AddressRestrictionFlag.BlockOutgoingAddress, + [], + [account3.address], + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [addressModification.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('AccountRestrictionTransaction - Incoming Address', () => { + it('standalone', () => { + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AddressRestrictionFlag.BlockIncomingAddress, + [account3.address], + [], + networkType, + helper.maxFee, + ); + const signedTransaction = addressModification.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Incoming Address', () => { + it('aggregate', () => { + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AddressRestrictionFlag.BlockIncomingAddress, + [], + [account3.address], + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [addressModification.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Mosaic', () => { + it('standalone', () => { + AccountRestrictionModification.createForMosaic(AccountRestrictionModificationAction.Add, mosaicId); + const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + Deadline.create(), + MosaicRestrictionFlag.BlockMosaic, + [mosaicId], + [], + networkType, + helper.maxFee, + ); + const signedTransaction = addressModification.signWith(account, generationHash); + + return helper.announce(signedTransaction).then((transaction: AccountMosaicRestrictionTransaction) => { + expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; + expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; + expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; + }); + }); + }); + describe('AccountRestrictionTransaction - Mosaic', () => { + it('aggregate', () => { + const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + Deadline.create(), + MosaicRestrictionFlag.BlockMosaic, + [], + [mosaicId], + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [addressModification.toAggregate(account.publicAccount)], networkType, [], helper.maxFee, @@ -770,776 +568,980 @@ describe('TransactionHttp', () => { }); }); - // describe('AddressAliasTransaction', () => { - // it('standalone', () => { - // const addressAliasTransaction = AddressAliasTransaction.create( - // Deadline.create(), - // AliasAction.Link, - // addressAlias, - // account.address, - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = addressAliasTransaction.signWith(account, generationHash); - - // return helper.announce(signedTransaction).then((transaction: AddressAliasTransaction) => { - // expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - // expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; - // expect(transaction.address, 'Address').not.to.be.undefined; - // }); - // }); - // }); - - // describe('Transfer Transaction using address alias', () => { - // it('Announce TransferTransaction', () => { - // const transferTransaction = TransferTransaction.create( - // Deadline.create(), - // addressAlias, - // [helper.createNetworkCurrency(1, false)], - // PlainMessage.create('test-message'), - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = transferTransaction.signWith(account, generationHash); - - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('AddressAliasTransaction', () => { - // it('aggregate', () => { - // const addressAliasTransaction = AddressAliasTransaction.create( - // Deadline.create(), - // AliasAction.Unlink, - // addressAlias, - // account.address, - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [addressAliasTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('MosaicSupplyChangeTransaction', () => { - // it('standalone', () => { - // const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( - // Deadline.create(), - // mosaicId, - // MosaicSupplyChangeAction.Increase, - // UInt64.fromUint(10), - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = mosaicSupplyChangeTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction).then((transaction: MosaicSupplyChangeTransaction) => { - // expect(transaction.delta, 'Delta').not.to.be.undefined; - // expect(transaction.action, 'Action').not.to.be.undefined; - // expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - // }); - // }); - // }); - // describe('MosaicSupplyChangeTransaction', () => { - // it('aggregate', () => { - // const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( - // Deadline.create(), - // mosaicId, - // MosaicSupplyChangeAction.Increase, - // UInt64.fromUint(10), - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [mosaicSupplyChangeTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('MosaicAliasTransaction', () => { - // it('standalone', () => { - // const mosaicAliasTransaction = MosaicAliasTransaction.create( - // Deadline.create(), - // AliasAction.Link, - // mosaicAlias, - // mosaicId, - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); - - // return helper.announce(signedTransaction).then((transaction: MosaicAliasTransaction) => { - // expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - // expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; - // expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - // }); - // }); - // }); - - // describe('HashLockTransaction - MosaicAlias', () => { - // it('standalone', () => { - // const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); - // const signedTransaction = account.sign(aggregateTransaction, generationHash); - // const hashLockTransaction = HashLockTransaction.create( - // Deadline.create(), - // new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), - // UInt64.fromUint(10000), - // signedTransaction, - // networkType, - // helper.maxFee, - // ); - // const hashLockSignedTransaction = hashLockTransaction.signWith(account, generationHash); - // return helper.announce(hashLockSignedTransaction); - // }); - // }); - - // describe('MosaicAliasTransaction', () => { - // it('aggregate', () => { - // const mosaicAliasTransaction = MosaicAliasTransaction.create( - // Deadline.create(), - // AliasAction.Unlink, - // mosaicAlias, - // mosaicId, - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [mosaicAliasTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('LockFundsTransaction', () => { - // it('standalone', () => { - // const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); - // const signedTransaction = account.sign(aggregateTransaction, generationHash); - // const lockFundsTransaction = LockFundsTransaction.create( - // Deadline.create(), - // new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), - // UInt64.fromUint(10000), - // signedTransaction, - // networkType, - // helper.maxFee, - // ); - - // return helper.announce(lockFundsTransaction.signWith(account, generationHash)); - // }); - // }); - // describe('LockFundsTransaction', () => { - // it('aggregate', () => { - // const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); - // const signedTransaction = account.sign(aggregateTransaction, generationHash); - // const lockFundsTransaction = LockFundsTransaction.create( - // Deadline.create(), - // new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), - // UInt64.fromUint(10), - // signedTransaction, - // networkType, - // helper.maxFee, - // ); - // const aggregateLockFundsTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [lockFundsTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // return helper.announce(aggregateLockFundsTransaction.signWith(account, generationHash)); - // }); - // }); - - // describe('Aggregate Complete Transaction', () => { - // it('should announce aggregated complete transaction', () => { - // const tx = TransferTransaction.create( - // Deadline.create(), - // account2.address, - // [], - // PlainMessage.create('Hi'), - // networkType, - // helper.maxFee, - // ); - // const aggTx = AggregateTransaction.createComplete( - // Deadline.create(), - // [tx.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = account.sign(aggTx, generationHash); - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('SecretLockTransaction', () => { - // it('standalone', () => { - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Sha3_256, - // sha3_256.create().update(Crypto.randomBytes(20)).hex(), - // account2.address, - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = secretLockTransaction.signWith(account, generationHash); - // return helper.announce(signedTransaction).then((transaction: SecretLockTransaction) => { - // expect(transaction.mosaic, 'Mosaic').not.to.be.undefined; - // expect(transaction.duration, 'Duration').not.to.be.undefined; - // expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined; - // expect(transaction.secret, 'Secret').not.to.be.undefined; - // expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; - // }); - // }); - // }); - // describe('HashType: Op_Sha3_256', () => { - // it('aggregate', () => { - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Sha3_256, - // sha3_256.create().update(Crypto.randomBytes(20)).hex(), - // account2.address, - // networkType, - // helper.maxFee, - // ); - // const aggregateSecretLockTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [secretLockTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); - // }); - // }); - - // describe('HashType: Op_Hash_160', () => { - // it('standalone', () => { - // const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); - // const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Hash_160, - // secret, - // account2.address, - // networkType, - // helper.maxFee, - // ); - // return helper.announce(secretLockTransaction.signWith(account, generationHash)); - // }); - // }); - // describe('HashType: Op_Hash_160', () => { - // it('aggregate', () => { - // const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); - // const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Hash_160, - // secret, - // account2.address, - // networkType, - // helper.maxFee, - // ); - // const aggregateSecretLockTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [secretLockTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); - // }); - // }); - // describe('HashType: Op_Hash_256', () => { - // it('standalone', () => { - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Hash_256, - // sha3_256.create().update(Crypto.randomBytes(20)).hex(), - // account2.address, - // networkType, - // helper.maxFee, - // ); - // return helper.announce(secretLockTransaction.signWith(account, generationHash)); - // }); - // }); - // describe('HashType: Op_Hash_256', () => { - // it('aggregate', () => { - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Hash_256, - // sha3_256.create().update(Crypto.randomBytes(20)).hex(), - // account2.address, - // networkType, - // helper.maxFee, - // ); - // const aggregateSecretLockTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [secretLockTransaction.toAggregate(account.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - - // return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); - // }); - // }); - // describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { - // it('standalone', () => { - // const secretSeed = Crypto.randomBytes(20); - // const secret = LockHashUtils.Op_Sha3_256(secretSeed); - // const proof = convert.uint8ToHex(secretSeed); - - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(1, ChronoUnit.HOURS), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(11), - // LockHashAlgorithm.Op_Sha3_256, - // secret, - // account2.address, - // networkType, - // helper.maxFee, - // ); - - // const signedSecretLockTx = secretLockTransaction.signWith(account, generationHash); - - // return helper.announce(signedSecretLockTx).then(() => { - // const secretProofTransaction = SecretProofTransaction.create( - // Deadline.create(), - // LockHashAlgorithm.Op_Sha3_256, - // secret, - // account2.address, - // proof, - // networkType, - // helper.maxFee, - // ); - // const signedTx = secretProofTransaction.signWith(account2, generationHash); - // return helper.announce(signedTx).then((transaction: SecretProofTransaction) => { - // expect(transaction.secret, 'Secret').not.to.be.undefined; - // expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; - // expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined; - // expect(transaction.proof, 'Proof').not.to.be.undefined; - // }); - // }); - // }); - // }); - // describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { - // it('aggregate', () => { - // const secretSeed = Crypto.randomBytes(20); - // const secret = sha3_256.create().update(secretSeed).hex(); - // const proof = convert.uint8ToHex(secretSeed); - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Sha3_256, - // secret, - // account2.address, - // networkType, - // helper.maxFee, - // ); - - // return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { - // const secretProofTransaction = SecretProofTransaction.create( - // Deadline.create(), - // LockHashAlgorithm.Op_Sha3_256, - // secret, - // account2.address, - // proof, - // networkType, - // helper.maxFee, - // ); - // const aggregateSecretProofTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [secretProofTransaction.toAggregate(account2.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // return helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); - // }); - // }); - // }); - // describe('SecretProofTransaction - HashType: Op_Hash_160', () => { - // it('standalone', () => { - // const randomBytes = secureRandom.randomBuffer(32); - // const secretSeed = randomBytes.toString('hex'); - // const secret = LockHashUtils.Op_Hash_160(randomBytes); - // const proof = secretSeed; - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Hash_160, - // secret, - // account2.address, - // networkType, - // helper.maxFee, - // ); - - // return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { - // const secretProofTransaction = SecretProofTransaction.create( - // Deadline.create(), - // LockHashAlgorithm.Op_Hash_160, - // secret, - // account2.address, - // proof, - // networkType, - // helper.maxFee, - // ); - // const signedTx = secretProofTransaction.signWith(account2, generationHash); - // return helper.announce(signedTx); - // }); - // }); - // }); - // describe('SecretProofTransaction - HashType: Op_Hash_160', () => { - // it('aggregate', () => { - // const randomBytes = secureRandom.randomBuffer(32); - // const secretSeed = randomBytes.toString('hex'); - // const hash = sha256(Buffer.from(secretSeed, 'hex')); - // const secret = new ripemd160().update(Buffer.from(hash, 'hex')).digest('hex'); - // const proof = secretSeed; - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Hash_160, - // secret, - // account2.address, - // networkType, - // helper.maxFee, - // ); - // const secretProofTransaction = SecretProofTransaction.create( - // Deadline.create(), - // LockHashAlgorithm.Op_Hash_160, - // secret, - // account2.address, - // proof, - // networkType, - // helper.maxFee, - // ); - // const aggregateSecretProofTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [secretProofTransaction.toAggregate(account2.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - - // return helper - // .announce(secretLockTransaction.signWith(account, generationHash)) - // .then(() => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); - // }); - // }); - // describe('SecretProofTransaction - HashType: Op_Hash_256', () => { - // it('standalone', () => { - // const randomBytes = secureRandom.randomBuffer(32); - // const secretSeed = randomBytes.toString('hex'); - // // const secret = sha256(Buffer.from(hash, 'hex')); - // const secret = LockHashUtils.Op_Hash_256(randomBytes); - // const proof = secretSeed; - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(1, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Hash_256, - // secret, - // account2.address, - // networkType, - // helper.maxFee, - // ); - - // const secretProofTransaction = SecretProofTransaction.create( - // Deadline.create(), - // LockHashAlgorithm.Op_Hash_256, - // secret, - // account2.address, - // proof, - // networkType, - // helper.maxFee, - // ); - - // return helper - // .announce(secretLockTransaction.signWith(account, generationHash)) - // .then(() => helper.announce(secretProofTransaction.signWith(account2, generationHash))); - // }); - // }); - // describe('SecretProofTransaction - HashType: Op_Hash_256', () => { - // it('aggregate', () => { - // const randomBytes = secureRandom.randomBuffer(32); - // const secretSeed = randomBytes.toString('hex'); - // const hash = sha256(Buffer.from(secretSeed, 'hex')); - // const secret = sha256(Buffer.from(hash, 'hex')); - // const proof = secretSeed; - // const secretLockTransaction = SecretLockTransaction.create( - // Deadline.create(), - // helper.createNetworkCurrency(10, false), - // UInt64.fromUint(100), - // LockHashAlgorithm.Op_Hash_256, - // secret, - // account2.address, - // networkType, - // helper.maxFee, - // ); - // const secretProofTransaction = SecretProofTransaction.create( - // Deadline.create(), - // LockHashAlgorithm.Op_Hash_256, - // secret, - // account2.address, - // proof, - // networkType, - // helper.maxFee, - // ); - // const aggregateSecretProofTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [secretProofTransaction.toAggregate(account2.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // return helper - // .announce(secretLockTransaction.signWith(account, generationHash)) - // .then(() => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); - // }); - // }); - - // describe('SignTransactionGivenSignatures', () => { - // it('Announce cosign signatures given', () => { - // /** - // * @see https://github.com/nemtech/symbol-sdk-typescript-javascript/issues/112 - // */ - // // AliceAccount: account - // // BobAccount: account - - // const sendAmount = helper.createNetworkCurrency(1000); - // const backAmount = helper.createNetworkCurrency(1); - - // const aliceTransferTransaction = TransferTransaction.create( - // Deadline.create(), - // account2.address, - // [sendAmount], - // PlainMessage.create('payout'), - // networkType, - // helper.maxFee, - // ); - // const bobTransferTransaction = TransferTransaction.create( - // Deadline.create(), - // account.address, - // [backAmount], - // PlainMessage.create('payout'), - // networkType, - // helper.maxFee, - // ); - - // // 01. Alice creates the aggregated tx and sign it. Then payload send to Bob - // const aggregateTransaction = AggregateTransaction.createComplete( - // Deadline.create(), - // [aliceTransferTransaction.toAggregate(account.publicAccount), bobTransferTransaction.toAggregate(account2.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - - // const aliceSignedTransaction = aggregateTransaction.signWith(account, generationHash); - - // // 02 Bob cosigns the tx and sends it back to Alice - // const signedTxBob = CosignatureTransaction.signTransactionPayload(account2, aliceSignedTransaction.payload, generationHash); - - // // 03. Alice collects the cosignatures, recreate, sign, and announces the transaction - // const cosignatureSignedTransactions = [ - // new CosignatureSignedTransaction(signedTxBob.parentHash, signedTxBob.signature, signedTxBob.signerPublicKey), - // ]; - // const recreatedTx = TransactionMapping.createFromPayload(aliceSignedTransaction.payload) as AggregateTransaction; - - // const signedTransaction = recreatedTx.signTransactionGivenSignatures(account, cosignatureSignedTransactions, generationHash); - - // return helper.announce(signedTransaction); - // }); - // }); - - // describe('getTransaction', () => { - // it('should return transaction info given transactionHash', async () => { - // const transaction = await transactionRepository.getTransaction(transactionHash, TransactionGroup.Confirmed).toPromise(); - // expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); - // transactionId = transaction.transactionInfo?.id!; - // }); - - // it('should return transaction info given transactionId', async () => { - // const transaction = await transactionRepository.getTransaction(transactionId, TransactionGroup.Confirmed).toPromise(); - // expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); - // expect(transaction.transactionInfo!.id).to.be.equal(transactionId); - // }); - // }); - - // describe('getTransactionsById', () => { - // it('should return transaction info given array of transactionHash', async () => { - // const transactions = await transactionRepository.getTransactionsById([transactionHash]).toPromise(); - // expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); - // expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); - // }); - - // it('should return transaction info given array of transactionId', async () => { - // const transactions = await transactionRepository.getTransactionsById([transactionId]).toPromise(); - // expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); - // expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); - // }); - // }); - - // describe('getTransactionStatus', () => { - // it('should return transaction status given transactionHash', async () => { - // await new Promise((resolve) => setTimeout(resolve, 2000)); - // const transactionStatus = await transactionStatusRepository.getTransactionStatus(transactionHash).toPromise(); - // expect(transactionStatus.group).to.be.equal('confirmed'); - // expect(transactionStatus.height!.lower).to.be.greaterThan(0); - // expect(transactionStatus.height!.higher).to.be.equal(0); - // }); - // }); - - // describe('getTransactionsStatuses', () => { - // it('should return transaction status given array of transactionHash', async () => { - // const transactionStatuses = await transactionStatusRepository.getTransactionStatuses([transactionHash]).toPromise(); - // expect(transactionStatuses[0].group).to.be.equal('confirmed'); - // expect(transactionStatuses[0].height!.lower).to.be.greaterThan(0); - // expect(transactionStatuses[0].height!.higher).to.be.equal(0); - // }); - // }); - - // describe('announce', () => { - // it('should return success when announce', async () => { - // const transferTransaction = TransferTransaction.create( - // Deadline.create(), - // account2.address, - // [helper.createNetworkCurrency(1, false)], - // PlainMessage.create('test-message'), - // networkType, - // helper.maxFee, - // ); - // const signedTransaction = transferTransaction.signWith(account, generationHash); - // const transactionAnnounceResponse = await transactionRepository.announce(signedTransaction).toPromise(); - // expect(transactionAnnounceResponse.message).to.be.equal('packet 9 was pushed to the network via /transactions'); - // }); - // }); - - // describe('announceAggregateBonded', () => { - // it('should return success when announceAggregateBonded', async () => { - // const transferTransaction = TransferTransaction.create( - // Deadline.create(), - // account2.address, - // [helper.createNetworkCurrency(1)], - // PlainMessage.create('test-message'), - // networkType, - // helper.maxFee, - // ); - // const aggregateTransaction = AggregateTransaction.createBonded( - // Deadline.create(2, ChronoUnit.MINUTES), - // [transferTransaction.toAggregate(multisigAccount.publicAccount)], - // networkType, - // [], - // helper.maxFee, - // ); - // const signedTransaction = aggregateTransaction.signWith(cosignAccount1, generationHash); - // const transactionAnnounceResponse = await transactionRepository.announceAggregateBonded(signedTransaction).toPromise(); - // expect(transactionAnnounceResponse.message).to.be.equal('packet 256 was pushed to the network via /transactions/partial'); - // }); - // }); - - // describe('announceAggregateBondedCosignature', () => { - // it('should return success when announceAggregateBondedCosignature', async () => { - // const payload = new CosignatureSignedTransaction('', '', ''); - // const transactionAnnounceResponse = await transactionRepository.announceAggregateBondedCosignature(payload).toPromise(); - // expect(transactionAnnounceResponse.message).to.be.equal('packet 257 was pushed to the network via /transactions/cosignature'); - // }); - // }); - - // describe('getTransactionEffectiveFee', () => { - // it('should return effective paid fee given transactionHash', async () => { - // const effectiveFee = await transactionRepository.getTransactionEffectiveFee(transactionHash).toPromise(); - // expect(effectiveFee).to.not.be.undefined; - // expect(effectiveFee).not.to.be.equal(0); - // }); - // }); - - // describe('searchTransactions', () => { - // it('should return transaction info given address', async () => { - // const transactions = await transactionRepository - // .search({ group: TransactionGroup.Confirmed, address: account.address } as TransactionSearchCriteria) - // .toPromise(); - // expect(transactions.data.length).to.be.greaterThan(0); - // }); - // it('should return transaction info given height all types', async () => { - // const transactions = await transactionRepository - // .search({ group: TransactionGroup.Confirmed, height: UInt64.fromUint(1) } as TransactionSearchCriteria) - // .toPromise(); - - // const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; - // const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; - // const others = transactions.data.filter( - // (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, - // ).length; - // expect(mosaicDefinitions).to.be.greaterThan(0); - // expect(namespaceRegistration).to.be.greaterThan(0); - // expect(others).to.be.greaterThan(0); - // }); - - // it('should return transaction info given height and namesapce, mosaic types', async () => { - // const transactions = await transactionRepository - // .search({ - // group: TransactionGroup.Confirmed, - // height: UInt64.fromUint(1), - // type: [TransactionType.MOSAIC_DEFINITION, TransactionType.NAMESPACE_REGISTRATION], - // } as TransactionSearchCriteria) - // .toPromise(); - // const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; - // const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; - // const others = transactions.data.filter( - // (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, - // ).length; - // expect(mosaicDefinitions).to.be.greaterThan(0); - // expect(namespaceRegistration).to.be.greaterThan(0); - // expect(others).to.eq(0); - // }); - // }); - - // describe('searchTransactions using steamer', () => { - // it('should return transaction info given address', async () => { - // const streamer = new TransactionPaginationStreamer(transactionRepository); - // const transactionsNoStreamer = await transactionRepository - // .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 } as TransactionSearchCriteria) - // .toPromise(); - // const transactions = await streamer - // .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 }) - // .pipe(take(10), toArray()) - // .toPromise(); - // expect(transactions.length).to.be.greaterThan(0); - // deepEqual(transactionsNoStreamer.data, transactions); - // }); - // }); + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + it('standalone', () => { + AccountRestrictionModification.createForOperation(AccountRestrictionModificationAction.Add, TransactionType.ACCOUNT_KEY_LINK); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + OperationRestrictionFlag.BlockOutgoingTransactionType, + [TransactionType.ACCOUNT_KEY_LINK], + [], + networkType, + helper.maxFee, + ); + const signedTransaction = addressModification.signWith(account3, generationHash); + + return helper.announce(signedTransaction).then((transaction: AccountOperationRestrictionTransaction) => { + expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; + expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; + expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; + }); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + it('aggregate', () => { + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + OperationRestrictionFlag.BlockOutgoingTransactionType, + [], + [TransactionType.ACCOUNT_KEY_LINK], + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [addressModification.toAggregate(account3.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account3, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('AccountKeyLinkTransaction', () => { + it('standalone', () => { + const accountLinkTransaction = AccountKeyLinkTransaction.create( + Deadline.create(), + remoteAccount.publicKey, + LinkAction.Link, + networkType, + helper.maxFee, + ); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + + return helper.announce(signedTransaction).then((transaction: AccountKeyLinkTransaction) => { + expect(transaction.linkedPublicKey, 'linkedPublicKey').not.to.be.undefined; + expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; + return signedTransaction; + }); + }); + }); + describe('AccountKeyLinkTransaction', () => { + it('aggregate', () => { + const accountLinkTransaction = AccountKeyLinkTransaction.create( + Deadline.create(), + remoteAccount.publicKey, + LinkAction.Unlink, + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [accountLinkTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('VrfKeyLinkTransaction', () => { + it('standalone', () => { + const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( + Deadline.create(), + harvestingAccount.publicKey, + LinkAction.Link, + networkType, + helper.maxFee, + ); + const signedTransaction = vrfKeyLinkTransaction.signWith(account, generationHash); + + return helper.announce(signedTransaction).then((transaction: VrfKeyLinkTransaction) => { + expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; + expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; + return signedTransaction; + }); + }); + }); + describe('VrfKeyLinkTransaction', () => { + it('aggregate', () => { + const vrfKeyLinkTransaction = VrfKeyLinkTransaction.create( + Deadline.create(), + harvestingAccount.publicKey, + LinkAction.Unlink, + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [vrfKeyLinkTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('NodeKeyLinkTransaction', () => { + it('standalone', () => { + const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( + Deadline.create(), + harvestingAccount.publicKey, + LinkAction.Link, + networkType, + helper.maxFee, + ); + const signedTransaction = nodeKeyLinkTransaction.signWith(account, generationHash); + + return helper.announce(signedTransaction).then((transaction: NodeKeyLinkTransaction) => { + expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; + expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; + return signedTransaction; + }); + }); + }); + describe('NodeKeyLinkTransaction', () => { + it('aggregate', () => { + const nodeKeyLinkTransaction = NodeKeyLinkTransaction.create( + Deadline.create(), + harvestingAccount.publicKey, + LinkAction.Unlink, + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [nodeKeyLinkTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('VotingKeyLinkTransaction', () => { + it('standalone', () => { + const votingLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + votingKey, + UInt64.fromUint(100), + UInt64.fromUint(300), + LinkAction.Link, + networkType, + helper.maxFee, + ); + const signedTransaction = votingLinkTransaction.signWith(account, generationHash); + + return helper.announce(signedTransaction).then((transaction: VotingKeyLinkTransaction) => { + expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined; + expect(transaction.startPoint, 'StartPoint').not.to.be.undefined; + expect(transaction.endPoint, 'EndPoint').not.to.be.undefined; + expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; + return signedTransaction; + }); + }); + }); + describe('VotingKeyLinkTransaction', () => { + it('aggregate', () => { + const votingLinkTransaction = VotingKeyLinkTransaction.create( + Deadline.create(), + votingKey, + UInt64.fromUint(100), + UInt64.fromUint(300), + LinkAction.Unlink, + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [votingLinkTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('AddressAliasTransaction', () => { + it('standalone', () => { + const addressAliasTransaction = AddressAliasTransaction.create( + Deadline.create(), + AliasAction.Link, + addressAlias, + account.address, + networkType, + helper.maxFee, + ); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + + return helper.announce(signedTransaction).then((transaction: AddressAliasTransaction) => { + expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; + expect(transaction.address, 'Address').not.to.be.undefined; + }); + }); + }); + + describe('Transfer Transaction using address alias', () => { + it('Announce TransferTransaction', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + addressAlias, + [helper.createNetworkCurrency(1, false)], + PlainMessage.create('test-message'), + networkType, + helper.maxFee, + ); + const signedTransaction = transferTransaction.signWith(account, generationHash); + + return helper.announce(signedTransaction); + }); + }); + + describe('AddressAliasTransaction', () => { + it('aggregate', () => { + const addressAliasTransaction = AddressAliasTransaction.create( + Deadline.create(), + AliasAction.Unlink, + addressAlias, + account.address, + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [addressAliasTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('MosaicSupplyChangeTransaction', () => { + it('standalone', () => { + const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( + Deadline.create(), + mosaicId, + MosaicSupplyChangeAction.Increase, + UInt64.fromUint(10), + networkType, + helper.maxFee, + ); + const signedTransaction = mosaicSupplyChangeTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: MosaicSupplyChangeTransaction) => { + expect(transaction.delta, 'Delta').not.to.be.undefined; + expect(transaction.action, 'Action').not.to.be.undefined; + expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; + }); + }); + }); + describe('MosaicSupplyChangeTransaction', () => { + it('aggregate', () => { + const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( + Deadline.create(), + mosaicId, + MosaicSupplyChangeAction.Increase, + UInt64.fromUint(10), + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [mosaicSupplyChangeTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('MosaicAliasTransaction', () => { + it('standalone', () => { + const mosaicAliasTransaction = MosaicAliasTransaction.create( + Deadline.create(), + AliasAction.Link, + mosaicAlias, + mosaicId, + networkType, + helper.maxFee, + ); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + + return helper.announce(signedTransaction).then((transaction: MosaicAliasTransaction) => { + expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; + expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; + }); + }); + }); + + describe('HashLockTransaction - MosaicAlias', () => { + it('standalone', () => { + const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); + const signedTransaction = account.sign(aggregateTransaction, generationHash); + const hashLockTransaction = HashLockTransaction.create( + Deadline.create(), + new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), + UInt64.fromUint(10000), + signedTransaction, + networkType, + helper.maxFee, + ); + const hashLockSignedTransaction = hashLockTransaction.signWith(account, generationHash); + return helper.announce(hashLockSignedTransaction); + }); + }); + + describe('MosaicAliasTransaction', () => { + it('aggregate', () => { + const mosaicAliasTransaction = MosaicAliasTransaction.create( + Deadline.create(), + AliasAction.Unlink, + mosaicAlias, + mosaicId, + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [mosaicAliasTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('LockFundsTransaction', () => { + it('standalone', () => { + const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); + const signedTransaction = account.sign(aggregateTransaction, generationHash); + const lockFundsTransaction = LockFundsTransaction.create( + Deadline.create(), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), + UInt64.fromUint(10000), + signedTransaction, + networkType, + helper.maxFee, + ); + + return helper.announce(lockFundsTransaction.signWith(account, generationHash)); + }); + }); + describe('LockFundsTransaction', () => { + it('aggregate', () => { + const aggregateTransaction = AggregateTransaction.createBonded(Deadline.create(), [], networkType, [], helper.maxFee); + const signedTransaction = account.sign(aggregateTransaction, generationHash); + const lockFundsTransaction = LockFundsTransaction.create( + Deadline.create(), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))), + UInt64.fromUint(10), + signedTransaction, + networkType, + helper.maxFee, + ); + const aggregateLockFundsTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [lockFundsTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + return helper.announce(aggregateLockFundsTransaction.signWith(account, generationHash)); + }); + }); + + describe('Aggregate Complete Transaction', () => { + it('should announce aggregated complete transaction', () => { + const tx = TransferTransaction.create( + Deadline.create(), + account2.address, + [], + PlainMessage.create('Hi'), + networkType, + helper.maxFee, + ); + const aggTx = AggregateTransaction.createComplete( + Deadline.create(), + [tx.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = account.sign(aggTx, generationHash); + return helper.announce(signedTransaction); + }); + }); + + describe('SecretLockTransaction', () => { + it('standalone', () => { + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Sha3_256, + sha3_256.create().update(Crypto.randomBytes(20)).hex(), + account2.address, + networkType, + helper.maxFee, + ); + const signedTransaction = secretLockTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: SecretLockTransaction) => { + expect(transaction.mosaic, 'Mosaic').not.to.be.undefined; + expect(transaction.duration, 'Duration').not.to.be.undefined; + expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined; + expect(transaction.secret, 'Secret').not.to.be.undefined; + expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; + }); + }); + }); + describe('HashType: Op_Sha3_256', () => { + it('aggregate', () => { + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Sha3_256, + sha3_256.create().update(Crypto.randomBytes(20)).hex(), + account2.address, + networkType, + helper.maxFee, + ); + const aggregateSecretLockTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [secretLockTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + }); + }); + + describe('HashType: Op_Hash_160', () => { + it('standalone', () => { + const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); + const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Hash_160, + secret, + account2.address, + networkType, + helper.maxFee, + ); + return helper.announce(secretLockTransaction.signWith(account, generationHash)); + }); + }); + describe('HashType: Op_Hash_160', () => { + it('aggregate', () => { + const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); + const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Hash_160, + secret, + account2.address, + networkType, + helper.maxFee, + ); + const aggregateSecretLockTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [secretLockTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + }); + }); + describe('HashType: Op_Hash_256', () => { + it('standalone', () => { + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Hash_256, + sha3_256.create().update(Crypto.randomBytes(20)).hex(), + account2.address, + networkType, + helper.maxFee, + ); + return helper.announce(secretLockTransaction.signWith(account, generationHash)); + }); + }); + describe('HashType: Op_Hash_256', () => { + it('aggregate', () => { + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Hash_256, + sha3_256.create().update(Crypto.randomBytes(20)).hex(), + account2.address, + networkType, + helper.maxFee, + ); + const aggregateSecretLockTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [secretLockTransaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee, + ); + + return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + }); + }); + describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { + it('standalone', () => { + const secretSeed = Crypto.randomBytes(20); + const secret = LockHashUtils.Op_Sha3_256(secretSeed); + const proof = convert.uint8ToHex(secretSeed); + + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(1, ChronoUnit.HOURS), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(11), + LockHashAlgorithm.Op_Sha3_256, + secret, + account2.address, + networkType, + helper.maxFee, + ); + + const signedSecretLockTx = secretLockTransaction.signWith(account, generationHash); + + return helper.announce(signedSecretLockTx).then(() => { + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + LockHashAlgorithm.Op_Sha3_256, + secret, + account2.address, + proof, + networkType, + helper.maxFee, + ); + const signedTx = secretProofTransaction.signWith(account2, generationHash); + return helper.announce(signedTx).then((transaction: SecretProofTransaction) => { + expect(transaction.secret, 'Secret').not.to.be.undefined; + expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; + expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined; + expect(transaction.proof, 'Proof').not.to.be.undefined; + }); + }); + }); + }); + describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { + it('aggregate', () => { + const secretSeed = Crypto.randomBytes(20); + const secret = sha3_256.create().update(secretSeed).hex(); + const proof = convert.uint8ToHex(secretSeed); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Sha3_256, + secret, + account2.address, + networkType, + helper.maxFee, + ); + + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + LockHashAlgorithm.Op_Sha3_256, + secret, + account2.address, + proof, + networkType, + helper.maxFee, + ); + const aggregateSecretProofTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [secretProofTransaction.toAggregate(account2.publicAccount)], + networkType, + [], + helper.maxFee, + ); + return helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); + }); + }); + }); + describe('SecretProofTransaction - HashType: Op_Hash_160', () => { + it('standalone', () => { + const randomBytes = secureRandom.randomBuffer(32); + const secretSeed = randomBytes.toString('hex'); + const secret = LockHashUtils.Op_Hash_160(randomBytes); + const proof = secretSeed; + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Hash_160, + secret, + account2.address, + networkType, + helper.maxFee, + ); + + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + LockHashAlgorithm.Op_Hash_160, + secret, + account2.address, + proof, + networkType, + helper.maxFee, + ); + const signedTx = secretProofTransaction.signWith(account2, generationHash); + return helper.announce(signedTx); + }); + }); + }); + describe('SecretProofTransaction - HashType: Op_Hash_160', () => { + it('aggregate', () => { + const randomBytes = secureRandom.randomBuffer(32); + const secretSeed = randomBytes.toString('hex'); + const hash = sha256(Buffer.from(secretSeed, 'hex')); + const secret = new ripemd160().update(Buffer.from(hash, 'hex')).digest('hex'); + const proof = secretSeed; + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Hash_160, + secret, + account2.address, + networkType, + helper.maxFee, + ); + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + LockHashAlgorithm.Op_Hash_160, + secret, + account2.address, + proof, + networkType, + helper.maxFee, + ); + const aggregateSecretProofTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [secretProofTransaction.toAggregate(account2.publicAccount)], + networkType, + [], + helper.maxFee, + ); + + return helper + .announce(secretLockTransaction.signWith(account, generationHash)) + .then(() => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); + }); + }); + describe('SecretProofTransaction - HashType: Op_Hash_256', () => { + it('standalone', () => { + const randomBytes = secureRandom.randomBuffer(32); + const secretSeed = randomBytes.toString('hex'); + // const secret = sha256(Buffer.from(hash, 'hex')); + const secret = LockHashUtils.Op_Hash_256(randomBytes); + const proof = secretSeed; + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(1, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Hash_256, + secret, + account2.address, + networkType, + helper.maxFee, + ); + + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + LockHashAlgorithm.Op_Hash_256, + secret, + account2.address, + proof, + networkType, + helper.maxFee, + ); + + return helper + .announce(secretLockTransaction.signWith(account, generationHash)) + .then(() => helper.announce(secretProofTransaction.signWith(account2, generationHash))); + }); + }); + describe('SecretProofTransaction - HashType: Op_Hash_256', () => { + it('aggregate', () => { + const randomBytes = secureRandom.randomBuffer(32); + const secretSeed = randomBytes.toString('hex'); + const hash = sha256(Buffer.from(secretSeed, 'hex')); + const secret = sha256(Buffer.from(hash, 'hex')); + const proof = secretSeed; + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + helper.createNetworkCurrency(10, false), + UInt64.fromUint(100), + LockHashAlgorithm.Op_Hash_256, + secret, + account2.address, + networkType, + helper.maxFee, + ); + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + LockHashAlgorithm.Op_Hash_256, + secret, + account2.address, + proof, + networkType, + helper.maxFee, + ); + const aggregateSecretProofTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [secretProofTransaction.toAggregate(account2.publicAccount)], + networkType, + [], + helper.maxFee, + ); + return helper + .announce(secretLockTransaction.signWith(account, generationHash)) + .then(() => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); + }); + }); + + describe('SignTransactionGivenSignatures', () => { + it('Announce cosign signatures given', () => { + /** + * @see https://github.com/nemtech/symbol-sdk-typescript-javascript/issues/112 + */ + // AliceAccount: account + // BobAccount: account + + const sendAmount = helper.createNetworkCurrency(1000); + const backAmount = helper.createNetworkCurrency(1); + + const aliceTransferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + [sendAmount], + PlainMessage.create('payout'), + networkType, + helper.maxFee, + ); + const bobTransferTransaction = TransferTransaction.create( + Deadline.create(), + account.address, + [backAmount], + PlainMessage.create('payout'), + networkType, + helper.maxFee, + ); + + // 01. Alice creates the aggregated tx and sign it. Then payload send to Bob + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [aliceTransferTransaction.toAggregate(account.publicAccount), bobTransferTransaction.toAggregate(account2.publicAccount)], + networkType, + [], + helper.maxFee, + ); + + const aliceSignedTransaction = aggregateTransaction.signWith(account, generationHash); + + // 02 Bob cosigns the tx and sends it back to Alice + const signedTxBob = CosignatureTransaction.signTransactionPayload(account2, aliceSignedTransaction.payload, generationHash); + + // 03. Alice collects the cosignatures, recreate, sign, and announces the transaction + const cosignatureSignedTransactions = [ + new CosignatureSignedTransaction(signedTxBob.parentHash, signedTxBob.signature, signedTxBob.signerPublicKey), + ]; + const recreatedTx = TransactionMapping.createFromPayload(aliceSignedTransaction.payload) as AggregateTransaction; + + const signedTransaction = recreatedTx.signTransactionGivenSignatures(account, cosignatureSignedTransactions, generationHash); + + return helper.announce(signedTransaction); + }); + }); + + describe('getTransaction', () => { + it('should return transaction info given transactionHash', async () => { + const transaction = await transactionRepository.getTransaction(transactionHash, TransactionGroup.Confirmed).toPromise(); + expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); + transactionId = transaction.transactionInfo?.id!; + }); + + it('should return transaction info given transactionId', async () => { + const transaction = await transactionRepository.getTransaction(transactionId, TransactionGroup.Confirmed).toPromise(); + expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); + expect(transaction.transactionInfo!.id).to.be.equal(transactionId); + }); + }); + + describe('getTransactionsById', () => { + it('should return transaction info given array of transactionHash', async () => { + const transactions = await transactionRepository.getTransactionsById([transactionHash]).toPromise(); + expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); + expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); + }); + + it('should return transaction info given array of transactionId', async () => { + const transactions = await transactionRepository.getTransactionsById([transactionId]).toPromise(); + expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); + expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); + }); + }); + + describe('getTransactionStatus', () => { + it('should return transaction status given transactionHash', async () => { + await new Promise((resolve) => setTimeout(resolve, 2000)); + const transactionStatus = await transactionStatusRepository.getTransactionStatus(transactionHash).toPromise(); + expect(transactionStatus.group).to.be.equal('confirmed'); + expect(transactionStatus.height!.lower).to.be.greaterThan(0); + expect(transactionStatus.height!.higher).to.be.equal(0); + }); + }); + + describe('getTransactionsStatuses', () => { + it('should return transaction status given array of transactionHash', async () => { + const transactionStatuses = await transactionStatusRepository.getTransactionStatuses([transactionHash]).toPromise(); + expect(transactionStatuses[0].group).to.be.equal('confirmed'); + expect(transactionStatuses[0].height!.lower).to.be.greaterThan(0); + expect(transactionStatuses[0].height!.higher).to.be.equal(0); + }); + }); + + describe('announce', () => { + it('should return success when announce', async () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + [helper.createNetworkCurrency(1, false)], + PlainMessage.create('test-message'), + networkType, + helper.maxFee, + ); + const signedTransaction = transferTransaction.signWith(account, generationHash); + const transactionAnnounceResponse = await transactionRepository.announce(signedTransaction).toPromise(); + expect(transactionAnnounceResponse.message).to.be.equal('packet 9 was pushed to the network via /transactions'); + }); + }); + + describe('announceAggregateBonded', () => { + it('should return success when announceAggregateBonded', async () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + [helper.createNetworkCurrency(1)], + PlainMessage.create('test-message'), + networkType, + helper.maxFee, + ); + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(2, ChronoUnit.MINUTES), + [transferTransaction.toAggregate(multisigAccount.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(cosignAccount1, generationHash); + const transactionAnnounceResponse = await transactionRepository.announceAggregateBonded(signedTransaction).toPromise(); + expect(transactionAnnounceResponse.message).to.be.equal('packet 256 was pushed to the network via /transactions/partial'); + }); + }); + + describe('announceAggregateBondedCosignature', () => { + it('should return success when announceAggregateBondedCosignature', async () => { + const payload = new CosignatureSignedTransaction('', '', ''); + const transactionAnnounceResponse = await transactionRepository.announceAggregateBondedCosignature(payload).toPromise(); + expect(transactionAnnounceResponse.message).to.be.equal('packet 257 was pushed to the network via /transactions/cosignature'); + }); + }); + + describe('getTransactionEffectiveFee', () => { + it('should return effective paid fee given transactionHash', async () => { + const effectiveFee = await transactionRepository.getTransactionEffectiveFee(transactionHash).toPromise(); + expect(effectiveFee).to.not.be.undefined; + expect(effectiveFee).not.to.be.equal(0); + }); + }); + + describe('searchTransactions', () => { + it('should return transaction info given address', async () => { + const transactions = await transactionRepository + .search({ group: TransactionGroup.Confirmed, address: account.address } as TransactionSearchCriteria) + .toPromise(); + expect(transactions.data.length).to.be.greaterThan(0); + }); + it('should return transaction info given height all types', async () => { + const transactions = await transactionRepository + .search({ group: TransactionGroup.Confirmed, height: UInt64.fromUint(1) } as TransactionSearchCriteria) + .toPromise(); + + const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; + const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; + const others = transactions.data.filter( + (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, + ).length; + expect(mosaicDefinitions).to.be.greaterThan(0); + expect(namespaceRegistration).to.be.greaterThan(0); + expect(others).to.be.greaterThan(0); + }); + + it('should return transaction info given height and namesapce, mosaic types', async () => { + const transactions = await transactionRepository + .search({ + group: TransactionGroup.Confirmed, + height: UInt64.fromUint(1), + type: [TransactionType.MOSAIC_DEFINITION, TransactionType.NAMESPACE_REGISTRATION], + } as TransactionSearchCriteria) + .toPromise(); + const mosaicDefinitions = transactions.data.filter((t) => t.type == TransactionType.MOSAIC_DEFINITION).length; + const namespaceRegistration = transactions.data.filter((t) => t.type == TransactionType.NAMESPACE_REGISTRATION).length; + const others = transactions.data.filter( + (t) => t.type !== TransactionType.NAMESPACE_REGISTRATION && t.type !== TransactionType.MOSAIC_DEFINITION, + ).length; + expect(mosaicDefinitions).to.be.greaterThan(0); + expect(namespaceRegistration).to.be.greaterThan(0); + expect(others).to.eq(0); + }); + }); + + describe('searchTransactions using steamer', () => { + it('should return transaction info given address', async () => { + const streamer = new TransactionPaginationStreamer(transactionRepository); + const transactionsNoStreamer = await transactionRepository + .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 } as TransactionSearchCriteria) + .toPromise(); + const transactions = await streamer + .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 }) + .pipe(take(10), toArray()) + .toPromise(); + expect(transactions.length).to.be.greaterThan(0); + deepEqual(transactionsNoStreamer.data, transactions); + }); + }); }); diff --git a/package-lock.json b/package-lock.json index 12b83f4af2..ef73fba6d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1109,9 +1109,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.21-alpha-202006231534", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21-alpha-202006231534.tgz", - "integrity": "sha512-iwMwOi7N1gQQfRkpiZL+dVyzYV3U+IqMM9x3fvi0/0nbf3dMcnATo7K9ifbw8Or14uCmbUrw3zKhQ2EvYwkVlw==" + "version": "0.0.21", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.21.tgz", + "integrity": "sha512-fKz6NoojjWOf7eJRZeh3pH6wMkxTXSfH/55yfzaImnhTQeaL6j1xiYElgWDDkKDJe2N4UWUJywRjbfT96I/GJw==" }, "chai": { "version": "4.1.2", @@ -5965,9 +5965,9 @@ } }, "symbol-openapi-typescript-fetch-client": { - "version": "0.9.3-SNAPSHOT.202006261816", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3-SNAPSHOT.202006261816.tgz", - "integrity": "sha512-ODaW+wM0W0huxzjQvF2TdzuQm3lraRJumIFcrn+FSl5qB5fan7hOlmAlvCTg2cSE6r8gAUHF/twOJdPNjnp/gQ==" + "version": "0.9.3", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.3.tgz", + "integrity": "sha512-AGY2PLtyKX36YJuZoqrP53N0dF/askSllGsQ6a7MGpdR2Wg0tPROWhdDNbp6WlJkF/a9lZkGLZE4qfRpnxGjxw==" }, "table": { "version": "5.4.6", diff --git a/package.json b/package.json index f7543320a8..223544a952 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.21-alpha-202006231534", + "catbuffer-typescript": "0.0.21", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", @@ -99,7 +99,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006261816", + "symbol-openapi-typescript-fetch-client": "0.9.3", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" From d2dbc76a5fc863cf15d5ddf3a959f026cf10a0a5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 26 Jun 2020 18:41:15 +0100 Subject: [PATCH 18/18] Fixed transaction http test --- e2e/infrastructure/TransactionHttp.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 13188b5bf9..78c1200af9 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -1403,13 +1403,13 @@ describe('TransactionHttp', () => { describe('getTransactionsById', () => { it('should return transaction info given array of transactionHash', async () => { - const transactions = await transactionRepository.getTransactionsById([transactionHash]).toPromise(); + const transactions = await transactionRepository.getTransactionsById([transactionHash], TransactionGroup.Confirmed).toPromise(); expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); }); it('should return transaction info given array of transactionId', async () => { - const transactions = await transactionRepository.getTransactionsById([transactionId]).toPromise(); + const transactions = await transactionRepository.getTransactionsById([transactionId], TransactionGroup.Confirmed).toPromise(); expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); });