|
| 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 | + |
| 17 | +import {expect} from 'chai'; |
| 18 | +import {BlockHttp} from '../../src/infrastructure/BlockHttp'; |
| 19 | +import {QueryParams} from '../../src/infrastructure/QueryParams'; |
| 20 | + |
| 21 | +describe('BlockHttp', () => { |
| 22 | + let blockHttp: BlockHttp; |
| 23 | + let blockReceiptHash = ''; |
| 24 | + let blockTransactionHash = ''; |
| 25 | + before((done) => { |
| 26 | + const path = require('path'); |
| 27 | + require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { |
| 28 | + if (err) { |
| 29 | + throw err; |
| 30 | + } |
| 31 | + const json = JSON.parse(data); |
| 32 | + blockHttp = new BlockHttp(json.apiUrl); |
| 33 | + done(); |
| 34 | + }); |
| 35 | + }); |
| 36 | + describe('getBlockByHeight', () => { |
| 37 | + it('should return block info given height', (done) => { |
| 38 | + blockHttp.getBlockByHeight(1) |
| 39 | + .subscribe((blockInfo) => { |
| 40 | + blockReceiptHash = blockInfo.blockReceiptsHash; |
| 41 | + blockTransactionHash = blockInfo.blockTransactionsHash; |
| 42 | + expect(blockInfo.height.lower).to.be.equal(1); |
| 43 | + expect(blockInfo.height.higher).to.be.equal(0); |
| 44 | + expect(blockInfo.timestamp.lower).to.be.equal(0); |
| 45 | + expect(blockInfo.timestamp.higher).to.be.equal(0); |
| 46 | + done(); |
| 47 | + }); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('getBlockTransactions', () => { |
| 52 | + let nextId: string; |
| 53 | + let firstId: string; |
| 54 | + |
| 55 | + it('should return block transactions data given height', (done) => { |
| 56 | + blockHttp.getBlockTransactions(1) |
| 57 | + .subscribe((transactions) => { |
| 58 | + nextId = transactions[0].transactionInfo!.id; |
| 59 | + firstId = transactions[1].transactionInfo!.id; |
| 60 | + expect(transactions.length).to.be.greaterThan(0); |
| 61 | + done(); |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should return block transactions data given height with paginated transactionId', (done) => { |
| 66 | + blockHttp.getBlockTransactions(1, new QueryParams(10, nextId)) |
| 67 | + .subscribe((transactions) => { |
| 68 | + expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); |
| 69 | + expect(transactions.length).to.be.greaterThan(0); |
| 70 | + done(); |
| 71 | + }); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + describe('getBlocksByHeightWithLimit', () => { |
| 76 | + it('should return block info given height and limit', (done) => { |
| 77 | + blockHttp.getBlocksByHeightWithLimit(1, 50) |
| 78 | + .subscribe((blocksInfo) => { |
| 79 | + expect(blocksInfo.length).to.be.greaterThan(0); |
| 80 | + done(); |
| 81 | + }); |
| 82 | + }); |
| 83 | + }); |
| 84 | + describe('getMerkleReceipts', () => { |
| 85 | + it('should return Merkle Receipts', (done) => { |
| 86 | + blockHttp.getMerkleReceipts(1, blockReceiptHash) |
| 87 | + .subscribe((merkleReceipts) => { |
| 88 | + expect(merkleReceipts.type).not.to.be.null; |
| 89 | + expect(merkleReceipts.payload).not.to.be.null; |
| 90 | + done(); |
| 91 | + }); |
| 92 | + }); |
| 93 | + }); |
| 94 | + describe('getMerkleTransaction', () => { |
| 95 | + it('should return Merkle Transaction', (done) => { |
| 96 | + blockHttp.getMerkleTransaction(1, blockTransactionHash) |
| 97 | + .subscribe((merkleTransactionss) => { |
| 98 | + expect(merkleTransactionss.type).not.to.be.null; |
| 99 | + expect(merkleTransactionss.payload).not.to.be.null; |
| 100 | + done(); |
| 101 | + }); |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + // describe('getBlockReceipts', () => { |
| 106 | + // it('should return block receipts', (done) => { |
| 107 | + // blockHttp.(1, '') |
| 108 | + // .subscribe((merkleTransactionss) => { |
| 109 | + // expect(merkleTransactionss.type).not.to.be.null; |
| 110 | + // expect(merkleTransactionss.payload).not.to.be.null; |
| 111 | + // done(); |
| 112 | + // }); |
| 113 | + // }); |
| 114 | + // }); |
| 115 | +}); |
0 commit comments