From de91e71dce6d8571392f773b2806ea2d0f423fe6 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 18 Feb 2019 15:12:57 +0000 Subject: [PATCH 1/8] Fixes #41 Added alias to LockFundsTransaction --- e2e/infrastructure/TransactionHttp.spec.ts | 10 +++++----- .../transaction/CreateTransactionFromDTO.ts | 4 ++-- src/model/transaction/LockFundsTransaction.ts | 4 +++- test/model/transaction/LockFundsTransaction.spec.ts | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index d66837d356..7a4d7dca17 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -33,7 +33,7 @@ import {CosignatureSignedTransaction} from '../../src/model/transaction/Cosignat import {CosignatureTransaction} from '../../src/model/transaction/CosignatureTransaction'; import {Deadline} from '../../src/model/transaction/Deadline'; import {HashType} from '../../src/model/transaction/HashType'; -import {LockFundsTransaction} from '../../src/model/transaction/LockFundsTransaction'; +import {HashLockTransaction} from '../../src/model/transaction/LockFundsTransaction'; import {ModifyMultisigAccountTransaction} from '../../src/model/transaction/ModifyMultisigAccountTransaction'; import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction'; import {MosaicSupplyChangeTransaction} from '../../src/model/transaction/MosaicSupplyChangeTransaction'; @@ -242,7 +242,7 @@ describe('TransactionHttp', () => { [Cosignatory2Account], ); - const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), + const lockFundsTransaction = HashLockTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10000), signedTransaction, @@ -277,7 +277,7 @@ describe('TransactionHttp', () => { CosignatoryAccount, ); - const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), + const lockFundsTransaction = HashLockTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10000), signedTransaction, @@ -314,7 +314,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction); - const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), + const lockFundsTransaction = HashLockTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10000), signedTransaction, @@ -331,7 +331,7 @@ describe('TransactionHttp', () => { [], ); const signedTransaction = account.sign(aggregateTransaction); - const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), + const lockFundsTransaction = HashLockTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10), signedTransaction, diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 2c64a65e4a..d32e2690a2 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -25,7 +25,7 @@ import {AggregateTransaction} from '../../model/transaction/AggregateTransaction import {AggregateTransactionCosignature} from '../../model/transaction/AggregateTransactionCosignature'; import {AggregateTransactionInfo} from '../../model/transaction/AggregateTransactionInfo'; import {Deadline} from '../../model/transaction/Deadline'; -import {LockFundsTransaction} from '../../model/transaction/LockFundsTransaction'; +import {HashLockTransaction} from '../../model/transaction/LockFundsTransaction'; import {ModifyMultisigAccountTransaction} from '../../model/transaction/ModifyMultisigAccountTransaction'; import {MosaicDefinitionTransaction} from '../../model/transaction/MosaicDefinitionTransaction'; import {MosaicSupplyChangeTransaction} from '../../model/transaction/MosaicSupplyChangeTransaction'; @@ -187,7 +187,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr ); } else if (transactionDTO.type === TransactionType.LOCK) { const networkType = extractNetworkType(transactionDTO.version); - return new LockFundsTransaction( + return new HashLockTransaction( networkType, extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index d4846d7149..35604d4c76 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -31,7 +31,7 @@ import { TransactionType } from './TransactionType'; * * @since 1.0 */ -export class LockFundsTransaction extends Transaction { +class LockFundsTransaction extends Transaction { /** * Aggregate bonded hash. @@ -115,3 +115,5 @@ export class LockFundsTransaction extends Transaction { } } + +export { LockFundsTransaction as HashLockTransaction }; diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index 6bf532dd1b..5dc0b27c59 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -18,7 +18,7 @@ import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {XEM} from '../../../src/model/mosaic/XEM'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; -import {LockFundsTransaction} from '../../../src/model/transaction/LockFundsTransaction'; +import {HashLockTransaction} from '../../../src/model/transaction/LockFundsTransaction'; import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; @@ -32,7 +32,7 @@ describe('LockFundsTransaction', () => { [], ); const signedTransaction = account.sign(aggregateTransaction); - const transaction = LockFundsTransaction.create(Deadline.create(), + const transaction = HashLockTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10), signedTransaction, @@ -51,7 +51,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction); expect(() => { - LockFundsTransaction.create(Deadline.create(), + HashLockTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10), signedTransaction, From b0617d5d4142b4f14526c5c315de2f5ca0314ce1 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 18 Feb 2019 16:02:22 +0000 Subject: [PATCH 2/8] Fixes #41 added alias without renaming current LockFundsTransaction class --- e2e/infrastructure/TransactionHttp.spec.ts | 10 +-- .../transaction/CreateTransactionFromDTO.ts | 4 +- src/model/model.ts | 1 + src/model/transaction/HashLockTransaction.ts | 23 +++++++ src/model/transaction/LockFundsTransaction.ts | 4 +- .../transaction/HashLockTransaction.spec.ts | 61 +++++++++++++++++++ .../transaction/LockFundsTransaction.spec.ts | 6 +- 7 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 src/model/transaction/HashLockTransaction.ts create mode 100644 test/model/transaction/HashLockTransaction.spec.ts diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 7a4d7dca17..d66837d356 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -33,7 +33,7 @@ import {CosignatureSignedTransaction} from '../../src/model/transaction/Cosignat import {CosignatureTransaction} from '../../src/model/transaction/CosignatureTransaction'; import {Deadline} from '../../src/model/transaction/Deadline'; import {HashType} from '../../src/model/transaction/HashType'; -import {HashLockTransaction} from '../../src/model/transaction/LockFundsTransaction'; +import {LockFundsTransaction} from '../../src/model/transaction/LockFundsTransaction'; import {ModifyMultisigAccountTransaction} from '../../src/model/transaction/ModifyMultisigAccountTransaction'; import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction'; import {MosaicSupplyChangeTransaction} from '../../src/model/transaction/MosaicSupplyChangeTransaction'; @@ -242,7 +242,7 @@ describe('TransactionHttp', () => { [Cosignatory2Account], ); - const lockFundsTransaction = HashLockTransaction.create(Deadline.create(), + const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10000), signedTransaction, @@ -277,7 +277,7 @@ describe('TransactionHttp', () => { CosignatoryAccount, ); - const lockFundsTransaction = HashLockTransaction.create(Deadline.create(), + const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10000), signedTransaction, @@ -314,7 +314,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction); - const lockFundsTransaction = HashLockTransaction.create(Deadline.create(), + const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10000), signedTransaction, @@ -331,7 +331,7 @@ describe('TransactionHttp', () => { [], ); const signedTransaction = account.sign(aggregateTransaction); - const lockFundsTransaction = HashLockTransaction.create(Deadline.create(), + const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10), signedTransaction, diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index d32e2690a2..2c64a65e4a 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -25,7 +25,7 @@ import {AggregateTransaction} from '../../model/transaction/AggregateTransaction import {AggregateTransactionCosignature} from '../../model/transaction/AggregateTransactionCosignature'; import {AggregateTransactionInfo} from '../../model/transaction/AggregateTransactionInfo'; import {Deadline} from '../../model/transaction/Deadline'; -import {HashLockTransaction} from '../../model/transaction/LockFundsTransaction'; +import {LockFundsTransaction} from '../../model/transaction/LockFundsTransaction'; import {ModifyMultisigAccountTransaction} from '../../model/transaction/ModifyMultisigAccountTransaction'; import {MosaicDefinitionTransaction} from '../../model/transaction/MosaicDefinitionTransaction'; import {MosaicSupplyChangeTransaction} from '../../model/transaction/MosaicSupplyChangeTransaction'; @@ -187,7 +187,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr ); } else if (transactionDTO.type === TransactionType.LOCK) { const networkType = extractNetworkType(transactionDTO.version); - return new HashLockTransaction( + return new LockFundsTransaction( networkType, extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), diff --git a/src/model/model.ts b/src/model/model.ts index 44ea541032..010f43990b 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -56,6 +56,7 @@ export * from './transaction/AggregateTransactionInfo'; export * from './transaction/CosignatureSignedTransaction'; export * from './transaction/CosignatureTransaction'; export * from './transaction/Deadline'; +export * from './transaction/HashLockTransaction'; export * from './transaction/HashType'; export * from './transaction/InnerTransaction'; export * from './transaction/LockFundsTransaction'; diff --git a/src/model/transaction/HashLockTransaction.ts b/src/model/transaction/HashLockTransaction.ts new file mode 100644 index 0000000000..28ff754601 --- /dev/null +++ b/src/model/transaction/HashLockTransaction.ts @@ -0,0 +1,23 @@ +/* + * Copyright 2018 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 { LockFundsTransaction } from './LockFundsTransaction'; + +/* + * An alias for LockFundsTransaction class + */ +export class HashLockTransaction extends LockFundsTransaction { +} diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 35604d4c76..d4846d7149 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -31,7 +31,7 @@ import { TransactionType } from './TransactionType'; * * @since 1.0 */ -class LockFundsTransaction extends Transaction { +export class LockFundsTransaction extends Transaction { /** * Aggregate bonded hash. @@ -115,5 +115,3 @@ class LockFundsTransaction extends Transaction { } } - -export { LockFundsTransaction as HashLockTransaction }; diff --git a/test/model/transaction/HashLockTransaction.spec.ts b/test/model/transaction/HashLockTransaction.spec.ts new file mode 100644 index 0000000000..04b0246bd9 --- /dev/null +++ b/test/model/transaction/HashLockTransaction.spec.ts @@ -0,0 +1,61 @@ +/* + * Copyright 2018 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 {expect} from 'chai'; +import {NetworkType} from '../../../src/model/blockchain/NetworkType'; +import {XEM} from '../../../src/model/mosaic/XEM'; +import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; +import {Deadline} from '../../../src/model/transaction/Deadline'; +import {HashLockTransaction} from '../../../src/model/transaction/HashLockTransaction'; +import {UInt64} from '../../../src/model/UInt64'; +import {TestingAccount} from '../../conf/conf.spec'; + +describe('HashLockTransaction', () => { + const account = TestingAccount; + it('creation with an aggregate bonded tx', () => { + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(), + [], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = account.sign(aggregateTransaction); + const transaction = HashLockTransaction.create(Deadline.create(), + XEM.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST); + expect(transaction.mosaic.id).to.be.equal(XEM.MOSAIC_ID); + expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); + expect(transaction.hash).to.be.equal(signedTransaction.hash); + }); + + it('should throw exception if it is not a aggregate bonded tx', () => { + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = account.sign(aggregateTransaction); + expect(() => { + HashLockTransaction.create(Deadline.create(), + XEM.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST); + }).to.throw(Error); + }); +}); diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index 5dc0b27c59..6bf532dd1b 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -18,7 +18,7 @@ import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {XEM} from '../../../src/model/mosaic/XEM'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; -import {HashLockTransaction} from '../../../src/model/transaction/LockFundsTransaction'; +import {LockFundsTransaction} from '../../../src/model/transaction/LockFundsTransaction'; import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; @@ -32,7 +32,7 @@ describe('LockFundsTransaction', () => { [], ); const signedTransaction = account.sign(aggregateTransaction); - const transaction = HashLockTransaction.create(Deadline.create(), + const transaction = LockFundsTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10), signedTransaction, @@ -51,7 +51,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction); expect(() => { - HashLockTransaction.create(Deadline.create(), + LockFundsTransaction.create(Deadline.create(), XEM.createRelative(10), UInt64.fromUint(10), signedTransaction, From 4a22a2040e083617c5921839cfb320d02e9c9458 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 18 Feb 2019 15:12:57 +0000 Subject: [PATCH 3/8] Fixes #41 Added alias to LockFundsTransaction --- e2e/infrastructure/TransactionHttp.spec.ts | 2 +- src/infrastructure/transaction/CreateTransactionFromDTO.ts | 4 ++-- src/model/transaction/LockFundsTransaction.ts | 4 +++- test/model/transaction/LockFundsTransaction.spec.ts | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index cbe2d4b796..f6adfa4b83 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -34,7 +34,7 @@ import {CosignatureSignedTransaction} from '../../src/model/transaction/Cosignat import {CosignatureTransaction} from '../../src/model/transaction/CosignatureTransaction'; import {Deadline} from '../../src/model/transaction/Deadline'; import {HashType} from '../../src/model/transaction/HashType'; -import {LockFundsTransaction} from '../../src/model/transaction/LockFundsTransaction'; +import {HashLockTransaction} from '../../src/model/transaction/LockFundsTransaction'; import {ModifyMultisigAccountTransaction} from '../../src/model/transaction/ModifyMultisigAccountTransaction'; import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction'; import {MosaicSupplyChangeTransaction} from '../../src/model/transaction/MosaicSupplyChangeTransaction'; diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index b1f08a632a..305163b13a 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -26,7 +26,7 @@ import {AggregateTransaction} from '../../model/transaction/AggregateTransaction import {AggregateTransactionCosignature} from '../../model/transaction/AggregateTransactionCosignature'; import {AggregateTransactionInfo} from '../../model/transaction/AggregateTransactionInfo'; import {Deadline} from '../../model/transaction/Deadline'; -import {LockFundsTransaction} from '../../model/transaction/LockFundsTransaction'; +import {HashLockTransaction} from '../../model/transaction/LockFundsTransaction'; import {ModifyMultisigAccountTransaction} from '../../model/transaction/ModifyMultisigAccountTransaction'; import {MosaicAliasTransaction} from '../../model/transaction/MosaicAliasTransaction'; import {MosaicDefinitionTransaction} from '../../model/transaction/MosaicDefinitionTransaction'; @@ -188,7 +188,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr ); } else if (transactionDTO.type === TransactionType.LOCK) { const networkType = extractNetworkType(transactionDTO.version); - return new LockFundsTransaction( + return new HashLockTransaction( networkType, extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 7e676b0e48..1c25b8e7ed 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -32,7 +32,7 @@ import { TransactionVersion } from './TransactionVersion'; * * @since 1.0 */ -export class LockFundsTransaction extends Transaction { +class LockFundsTransaction extends Transaction { /** * Aggregate bonded hash. @@ -116,3 +116,5 @@ export class LockFundsTransaction extends Transaction { } } + +export { LockFundsTransaction as HashLockTransaction }; diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index bf475519e9..6440d79734 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -19,7 +19,7 @@ import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; -import {LockFundsTransaction} from '../../../src/model/transaction/LockFundsTransaction'; +import {HashLockTransaction} from '../../../src/model/transaction/LockFundsTransaction'; import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; From 5ee3a7a53254f74c6e632a7a861e6883d053f900 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 18 Feb 2019 16:02:22 +0000 Subject: [PATCH 4/8] Fixes #41 added alias without renaming current LockFundsTransaction class --- e2e/infrastructure/TransactionHttp.spec.ts | 2 +- .../transaction/CreateTransactionFromDTO.ts | 4 +- src/model/model.ts | 1 + src/model/transaction/HashLockTransaction.ts | 23 +++++++ src/model/transaction/LockFundsTransaction.ts | 4 +- .../transaction/HashLockTransaction.spec.ts | 61 +++++++++++++++++++ .../transaction/LockFundsTransaction.spec.ts | 2 +- 7 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 src/model/transaction/HashLockTransaction.ts create mode 100644 test/model/transaction/HashLockTransaction.spec.ts diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index f6adfa4b83..cbe2d4b796 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -34,7 +34,7 @@ import {CosignatureSignedTransaction} from '../../src/model/transaction/Cosignat import {CosignatureTransaction} from '../../src/model/transaction/CosignatureTransaction'; import {Deadline} from '../../src/model/transaction/Deadline'; import {HashType} from '../../src/model/transaction/HashType'; -import {HashLockTransaction} from '../../src/model/transaction/LockFundsTransaction'; +import {LockFundsTransaction} from '../../src/model/transaction/LockFundsTransaction'; import {ModifyMultisigAccountTransaction} from '../../src/model/transaction/ModifyMultisigAccountTransaction'; import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction'; import {MosaicSupplyChangeTransaction} from '../../src/model/transaction/MosaicSupplyChangeTransaction'; diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 305163b13a..b1f08a632a 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -26,7 +26,7 @@ import {AggregateTransaction} from '../../model/transaction/AggregateTransaction import {AggregateTransactionCosignature} from '../../model/transaction/AggregateTransactionCosignature'; import {AggregateTransactionInfo} from '../../model/transaction/AggregateTransactionInfo'; import {Deadline} from '../../model/transaction/Deadline'; -import {HashLockTransaction} from '../../model/transaction/LockFundsTransaction'; +import {LockFundsTransaction} from '../../model/transaction/LockFundsTransaction'; import {ModifyMultisigAccountTransaction} from '../../model/transaction/ModifyMultisigAccountTransaction'; import {MosaicAliasTransaction} from '../../model/transaction/MosaicAliasTransaction'; import {MosaicDefinitionTransaction} from '../../model/transaction/MosaicDefinitionTransaction'; @@ -188,7 +188,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr ); } else if (transactionDTO.type === TransactionType.LOCK) { const networkType = extractNetworkType(transactionDTO.version); - return new HashLockTransaction( + return new LockFundsTransaction( networkType, extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), diff --git a/src/model/model.ts b/src/model/model.ts index ecd0cbbba2..e5c49129e3 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -64,6 +64,7 @@ export * from './transaction/AliasTransaction'; export * from './transaction/CosignatureSignedTransaction'; export * from './transaction/CosignatureTransaction'; export * from './transaction/Deadline'; +export * from './transaction/HashLockTransaction'; export * from './transaction/HashType'; export * from './transaction/InnerTransaction'; export * from './transaction/LockFundsTransaction'; diff --git a/src/model/transaction/HashLockTransaction.ts b/src/model/transaction/HashLockTransaction.ts new file mode 100644 index 0000000000..28ff754601 --- /dev/null +++ b/src/model/transaction/HashLockTransaction.ts @@ -0,0 +1,23 @@ +/* + * Copyright 2018 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 { LockFundsTransaction } from './LockFundsTransaction'; + +/* + * An alias for LockFundsTransaction class + */ +export class HashLockTransaction extends LockFundsTransaction { +} diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 1c25b8e7ed..7e676b0e48 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -32,7 +32,7 @@ import { TransactionVersion } from './TransactionVersion'; * * @since 1.0 */ -class LockFundsTransaction extends Transaction { +export class LockFundsTransaction extends Transaction { /** * Aggregate bonded hash. @@ -116,5 +116,3 @@ class LockFundsTransaction extends Transaction { } } - -export { LockFundsTransaction as HashLockTransaction }; diff --git a/test/model/transaction/HashLockTransaction.spec.ts b/test/model/transaction/HashLockTransaction.spec.ts new file mode 100644 index 0000000000..04b0246bd9 --- /dev/null +++ b/test/model/transaction/HashLockTransaction.spec.ts @@ -0,0 +1,61 @@ +/* + * Copyright 2018 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 {expect} from 'chai'; +import {NetworkType} from '../../../src/model/blockchain/NetworkType'; +import {XEM} from '../../../src/model/mosaic/XEM'; +import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; +import {Deadline} from '../../../src/model/transaction/Deadline'; +import {HashLockTransaction} from '../../../src/model/transaction/HashLockTransaction'; +import {UInt64} from '../../../src/model/UInt64'; +import {TestingAccount} from '../../conf/conf.spec'; + +describe('HashLockTransaction', () => { + const account = TestingAccount; + it('creation with an aggregate bonded tx', () => { + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(), + [], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = account.sign(aggregateTransaction); + const transaction = HashLockTransaction.create(Deadline.create(), + XEM.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST); + expect(transaction.mosaic.id).to.be.equal(XEM.MOSAIC_ID); + expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); + expect(transaction.hash).to.be.equal(signedTransaction.hash); + }); + + it('should throw exception if it is not a aggregate bonded tx', () => { + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = account.sign(aggregateTransaction); + expect(() => { + HashLockTransaction.create(Deadline.create(), + XEM.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST); + }).to.throw(Error); + }); +}); diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index 6440d79734..bf475519e9 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -19,7 +19,7 @@ import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; -import {HashLockTransaction} from '../../../src/model/transaction/LockFundsTransaction'; +import {LockFundsTransaction} from '../../../src/model/transaction/LockFundsTransaction'; import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; From 5c86564c614ee5df6f33fa1b682ebb8078e79f12 Mon Sep 17 00:00:00 2001 From: Greg S Date: Thu, 28 Feb 2019 16:26:03 +0100 Subject: [PATCH 5/8] Fixed MosaicDefinitionTransaction.create() to accept MosaicNonce and MosaicId --- e2e/infrastructure/TransactionHttp.spec.ts | 9 +++++---- .../transaction/MosaicDefinitionTransaction.ts | 18 +++++++++++------- .../transaction/AggregateTransaction.spec.ts | 5 +++-- .../MosaicDefinitionTransaction.spec.ts | 13 +++++++------ 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index cbe2d4b796..de6cd4aaca 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -26,6 +26,7 @@ import {Address} from '../../src/model/account/Address'; import {PublicAccount} from '../../src/model/account/PublicAccount'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import {MosaicId} from '../../src/model/mosaic/MosaicId'; +import {MosaicNonce} from '../../src/model/mosaic/MosaicNonce'; import {MosaicProperties} from '../../src/model/mosaic/MosaicProperties'; import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType'; import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; @@ -151,8 +152,8 @@ describe('TransactionHttp', () => { it('standalone', (done) => { const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), - new Uint8Array([0xE6, 0xDE, 0x84, 0xB8]), - UInt64.fromUint(1), + new MosaicNonce(new Uint8Array([0xE6, 0xDE, 0x84, 0xB8])), // nonce + new MosaicId(UInt64.fromUint(1).toDTO()), // ID MosaicProperties.create({ supplyMutable: true, transferable: true, @@ -170,8 +171,8 @@ describe('TransactionHttp', () => { it('aggregate', (done) => { const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), - new Uint8Array([0xE6, 0xDE, 0x84, 0xB8]), - UInt64.fromUint(1), + new MosaicNonce(new Uint8Array([0xE6, 0xDE, 0x84, 0xB8])), // nonce + new MosaicId(UInt64.fromUint(1).toDTO()), // ID MosaicProperties.create({ supplyMutable: true, transferable: true, diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 7da9d80169..3adaf444a4 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { MosaicCreationTransaction as MosaicDefinitionTransactionLibrary, mosaicId as mosaicIdLibrary, VerifiableTransaction } from 'nem2-library'; +import { + MosaicCreationTransaction as MosaicDefinitionTransactionLibrary, + mosaicId as mosaicIdLibrary, + VerifiableTransaction, +} from 'nem2-library'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -37,23 +41,23 @@ export class MosaicDefinitionTransaction extends Transaction { /** * Create a mosaic creation transaction object * @param deadline - The deadline to include the transaction. - * @param nonce - The mosaic nonce ex: [0xE6, 0xDE, 0x84, 0xB8]. - * @param mosaicId - The mosaic id ex: [481110499, 231112638]. + * @param nonce - The mosaic nonce ex: MosaicNonce.createRandom(). + * @param mosaicId - The mosaic id ex: new MosaicId([481110499, 231112638]). * @param mosaicProperties - The mosaic properties. * @param networkType - The network type. * @returns {MosaicDefinitionTransaction} */ public static create(deadline: Deadline, - nonce: Uint8Array, - mosaicId: UInt64, + nonce: MosaicNonce, + mosaicId: MosaicId, mosaicProperties: MosaicProperties, networkType: NetworkType): MosaicDefinitionTransaction { return new MosaicDefinitionTransaction(networkType, TransactionVersion.MOSAIC_DEFINITION, deadline, new UInt64([0, 0]), - new MosaicNonce(nonce), - new MosaicId(mosaicId.toDTO()), + nonce, + mosaicId, mosaicProperties, ); } diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 480d548410..dadce01227 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -22,6 +22,7 @@ import {Address} from '../../../src/model/account/Address'; import {PublicAccount} from '../../../src/model/account/PublicAccount'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; +import {MosaicNonce} from '../../../src/model/mosaic/MosaicNonce'; import {MosaicProperties} from '../../../src/model/mosaic/MosaicProperties'; import {MosaicSupplyType} from '../../../src/model/mosaic/MosaicSupplyType'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; @@ -98,8 +99,8 @@ describe('AggregateTransaction', () => { it('should createComplete an AggregateTransaction object with MosaicDefinitionTransaction', () => { const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), - new Uint8Array([0xE6, 0xDE, 0x84, 0xB8]), // nonce - UInt64.fromUint(1), // ID + new MosaicNonce(new Uint8Array([0xE6, 0xDE, 0x84, 0xB8])), // nonce + new MosaicId(UInt64.fromUint(1).toDTO()), // ID MosaicProperties.create({ supplyMutable: true, transferable: true, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 7d1e0db358..41799026bc 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -17,6 +17,8 @@ import {expect} from 'chai'; import {Account} from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; +import {MosaicId} from '../../../src/model/mosaic/MosaicId'; +import {MosaicNonce} from '../../../src/model/mosaic/MosaicNonce'; import {MosaicProperties} from '../../../src/model/mosaic/MosaicProperties'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {MosaicDefinitionTransaction} from '../../../src/model/transaction/MosaicDefinitionTransaction'; @@ -34,8 +36,8 @@ describe('MosaicDefinitionTransaction', () => { it('should createComplete an MosaicDefinitionTransaction object and sign it with flags 7', () => { const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), - new Uint8Array([0xE6, 0xDE, 0x84, 0xB8]), - UInt64.fromUint(1), + new MosaicNonce(new Uint8Array([0xE6, 0xDE, 0x84, 0xB8])), // nonce + new MosaicId(UInt64.fromUint(1).toDTO()), // ID MosaicProperties.create({ supplyMutable: true, transferable: true, @@ -64,11 +66,10 @@ describe('MosaicDefinitionTransaction', () => { it('should createComplete an MosaicDefinitionTransaction object and sign it with flags 0', () => { - const nonce = [0xE6, 0xDE, 0x84, 0xB8]; const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), - new Uint8Array(nonce), - UInt64.fromUint(mosaicId(nonce, convert.hexToUint8(account.publicKey))), + new MosaicNonce(new Uint8Array([0xE6, 0xDE, 0x84, 0xB8])), // nonce + new MosaicId(UInt64.fromUint(1).toDTO()), // ID MosaicProperties.create({ supplyMutable: false, transferable: false, @@ -91,7 +92,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8000000000000000001000302E803000000000000'); + )).to.be.equal('E6DE84B8010000000000000001000302E803000000000000'); }); }); From bbf169fab0a1948486ddd051031d64f1ae713bb9 Mon Sep 17 00:00:00 2001 From: Greg S Date: Thu, 28 Feb 2019 16:28:50 +0100 Subject: [PATCH 6/8] v0.10.3-1: Fixed usability of MosaicDefinitionTransaction --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 180cb866b1..cb0e8bffac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nem2-sdk", - "version": "0.10.3-0", + "version": "0.10.3-1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ade9071dc0..050b502036 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nem2-sdk", - "version": "0.10.3-0", + "version": "0.10.3-1", "description": "Reactive Nem2 sdk for typescript and javascript", "scripts": { "pretest": "npm run build", From e602dfa2e1138ea4b38240e26b770734682cb1b3 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 1 Mar 2019 10:42:20 +0000 Subject: [PATCH 7/8] Updated hashlock transaction unit test to remove Xem --- test/model/transaction/HashLockTransaction.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/model/transaction/HashLockTransaction.spec.ts b/test/model/transaction/HashLockTransaction.spec.ts index 04b0246bd9..687463768e 100644 --- a/test/model/transaction/HashLockTransaction.spec.ts +++ b/test/model/transaction/HashLockTransaction.spec.ts @@ -15,12 +15,12 @@ */ import {expect} from 'chai'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; -import {XEM} from '../../../src/model/mosaic/XEM'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashLockTransaction} from '../../../src/model/transaction/HashLockTransaction'; import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; +import { NetworkCurrencyMosaic } from '../../../src/model/model'; describe('HashLockTransaction', () => { const account = TestingAccount; @@ -33,11 +33,11 @@ describe('HashLockTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction); const transaction = HashLockTransaction.create(Deadline.create(), - XEM.createRelative(10), + NetworkCurrencyMosaic.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); - expect(transaction.mosaic.id).to.be.equal(XEM.MOSAIC_ID); + expect(transaction.mosaic.id).to.be.equal(NetworkCurrencyMosaic.NAMESPACE_ID); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); }); @@ -52,7 +52,7 @@ describe('HashLockTransaction', () => { const signedTransaction = account.sign(aggregateTransaction); expect(() => { HashLockTransaction.create(Deadline.create(), - XEM.createRelative(10), + NetworkCurrencyMosaic.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); From 5eca922d071e7d257fa08bcf5af9db77431a2273 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 1 Mar 2019 10:53:07 +0000 Subject: [PATCH 8/8] fixed import on hasl lock transaction test --- test/model/transaction/HashLockTransaction.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/model/transaction/HashLockTransaction.spec.ts b/test/model/transaction/HashLockTransaction.spec.ts index 687463768e..c1d946c9ed 100644 --- a/test/model/transaction/HashLockTransaction.spec.ts +++ b/test/model/transaction/HashLockTransaction.spec.ts @@ -15,12 +15,12 @@ */ import {expect} from 'chai'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; +import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashLockTransaction} from '../../../src/model/transaction/HashLockTransaction'; import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; -import { NetworkCurrencyMosaic } from '../../../src/model/model'; describe('HashLockTransaction', () => { const account = TestingAccount;