diff --git a/src/blockchain/Blockchain.spec.ts b/src/blockchain/Blockchain.spec.ts index 662c9bd1..a879b738 100644 --- a/src/blockchain/Blockchain.spec.ts +++ b/src/blockchain/Blockchain.spec.ts @@ -61,8 +61,36 @@ describe('chain mocks', () => { ) expect(latestAccumulator.valueOf()).toBe(newAccumulator.valueOf()) }) + it('Should getAccumulatorArray', async () => { + api.query.portablegabi.accumulatorList.mockResolvedValue( + (stringToHex('currAccumulator') as unknown) as Promise + ) + const currAccumulators = await BlockchainMock.getAccumulatorArray( + dummyAddress, + 1, + 4 + ) + expect(Array.isArray(currAccumulators)).toBeTruthy() + expect(currAccumulators.length).toEqual(4) + }) }) describe('Negative tests', () => { + it('Should throw error for swapped indices when requesting accumulator array', async () => { + api.query.portablegabi.accumulatorList.mockResolvedValue( + (stringToHex('currAccumulator') as unknown) as Promise + ) + expect( + BlockchainMock.getAccumulatorArray(dummyAddress, 4, 1) + ).rejects.toThrowError() + }) + it('Should throw error when accumulator array index out is of range', async () => { + api.query.portablegabi.accumulatorList.mockResolvedValue( + (stringToHex('currAccumulator') as unknown) as Promise + ) + expect( + BlockchainMock.getAccumulatorArray(dummyAddress, 999999999) + ).rejects.toThrowError() + }) it('Should throw for empty accumulatorList (maxIndex === -1)', async () => { const accCount = 0 const requestedIndex = 1 diff --git a/src/blockchain/Blockchain.ts b/src/blockchain/Blockchain.ts index 2d11a863..1e2778d6 100644 --- a/src/blockchain/Blockchain.ts +++ b/src/blockchain/Blockchain.ts @@ -145,7 +145,7 @@ export default class Blockchain implements IBlockchainApi { } const endIndex = _endIndex || (await this.getMaxIndex(address)) // create [[address, startIndex], ..., [address, endIndex]] for multi query - const multiQuery = new Array(endIndex - startIndex) + const multiQuery = new Array(endIndex - startIndex + 1) .fill(startIndex) .map((x, i) => [address, x + i])