Skip to content

Commit

Permalink
fix: block parsing with encrypted transaction (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrolland committed Mar 19, 2020
1 parent 48bb362 commit de86f43
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/data-access/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ function parseBlock(data: string): DataAccessTypes.IBlock {
}

// check the transactions format
if (maybeBlock.transactions.some((tx: any) => !tx.data)) {
if (!maybeBlock.transactions.every((tx: any) => tx.data || (tx.encryptedData && tx.hash))) {
throw new Error(`Transactions do not follow the block standard`);
}

// check if channelIds are well formatted
// check that all the channel ids are hashes
if (
Expand Down
2 changes: 1 addition & 1 deletion packages/data-access/src/data-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export default class DataAccess implements DataAccessTypes.IDataAccess {
const resultRead = await this.storage.read(location);

return {
block: JSON.parse(resultRead.content),
block: Block.parseBlock(resultRead.content),
location,
meta: resultRead.meta,
};
Expand Down
6 changes: 3 additions & 3 deletions packages/request-node/test/getTransactionsByChannelId.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as httpStatus from 'http-status-codes';
import * as request from 'supertest';
import requestNode from '../src/requestNode';

const channelId = '0xchannelId1';
const anotherChannelId = '0xanotherChannelId1';
const nonExistentChannelId = 'NonExistentTopic';
const channelId = '01aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab';
const anotherChannelId = '01bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc';
const nonExistentChannelId = '01cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccd';
const transactionData = {
data: 'this is sample data for a transaction to test getTransactionsByChannelId',
};
Expand Down

0 comments on commit de86f43

Please sign in to comment.