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/test/model/transaction/HashLockTransaction.spec.ts b/test/model/transaction/HashLockTransaction.spec.ts new file mode 100644 index 0000000000..c1d946c9ed --- /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 { 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'; + +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(), + NetworkCurrencyMosaic.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST); + 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); + }); + + 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(), + NetworkCurrencyMosaic.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST); + }).to.throw(Error); + }); +});