|
| 1 | +/* |
| 2 | + * Copyright 2018 NEM |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +import {expect} from 'chai'; |
| 17 | +import {NetworkType} from '../../../src/model/blockchain/NetworkType'; |
| 18 | +import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; |
| 19 | +import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; |
| 20 | +import {Deadline} from '../../../src/model/transaction/Deadline'; |
| 21 | +import {HashLockTransaction} from '../../../src/model/transaction/HashLockTransaction'; |
| 22 | +import {UInt64} from '../../../src/model/UInt64'; |
| 23 | +import {TestingAccount} from '../../conf/conf.spec'; |
| 24 | + |
| 25 | +describe('HashLockTransaction', () => { |
| 26 | + const account = TestingAccount; |
| 27 | + it('creation with an aggregate bonded tx', () => { |
| 28 | + const aggregateTransaction = AggregateTransaction.createBonded( |
| 29 | + Deadline.create(), |
| 30 | + [], |
| 31 | + NetworkType.MIJIN_TEST, |
| 32 | + [], |
| 33 | + ); |
| 34 | + const signedTransaction = account.sign(aggregateTransaction); |
| 35 | + const transaction = HashLockTransaction.create(Deadline.create(), |
| 36 | + NetworkCurrencyMosaic.createRelative(10), |
| 37 | + UInt64.fromUint(10), |
| 38 | + signedTransaction, |
| 39 | + NetworkType.MIJIN_TEST); |
| 40 | + expect(transaction.mosaic.id).to.be.equal(NetworkCurrencyMosaic.NAMESPACE_ID); |
| 41 | + expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); |
| 42 | + expect(transaction.hash).to.be.equal(signedTransaction.hash); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should throw exception if it is not a aggregate bonded tx', () => { |
| 46 | + const aggregateTransaction = AggregateTransaction.createComplete( |
| 47 | + Deadline.create(), |
| 48 | + [], |
| 49 | + NetworkType.MIJIN_TEST, |
| 50 | + [], |
| 51 | + ); |
| 52 | + const signedTransaction = account.sign(aggregateTransaction); |
| 53 | + expect(() => { |
| 54 | + HashLockTransaction.create(Deadline.create(), |
| 55 | + NetworkCurrencyMosaic.createRelative(10), |
| 56 | + UInt64.fromUint(10), |
| 57 | + signedTransaction, |
| 58 | + NetworkType.MIJIN_TEST); |
| 59 | + }).to.throw(Error); |
| 60 | + }); |
| 61 | +}); |
0 commit comments