Skip to content

Commit b5c2555

Browse files
committed
Fixed receipt serializer and updated block e2e test
1 parent 25199cc commit b5c2555

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

e2e/infrastructure/BlockHttp.spec.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import {assert, expect} from 'chai';
18+
import { mergeMap } from 'rxjs/operators';
1819
import {BlockHttp} from '../../src/infrastructure/BlockHttp';
1920
import { Listener, ReceiptHttp, TransactionHttp } from '../../src/infrastructure/infrastructure';
2021
import {QueryParams} from '../../src/infrastructure/QueryParams';
@@ -24,6 +25,7 @@ import { PlainMessage } from '../../src/model/message/PlainMessage';
2425
import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic';
2526
import { Deadline } from '../../src/model/transaction/Deadline';
2627
import { Transaction } from '../../src/model/transaction/Transaction';
28+
import { TransactionInfo } from '../../src/model/transaction/TransactionInfo';
2729
import { TransferTransaction } from '../../src/model/transaction/TransferTransaction';
2830

2931
describe('BlockHttp', () => {
@@ -144,17 +146,28 @@ describe('BlockHttp', () => {
144146
});
145147
describe('getMerkleReceipts', () => {
146148
it('should return Merkle Receipts', (done) => {
147-
receiptHttp.getMerkleReceipts(chainHeight, blockReceiptHash)
148-
.subscribe((merkleReceipts) => {
149-
expect(merkleReceipts.merklePath).not.to.be.null;
150-
done();
151-
});
149+
receiptHttp.getBlockReceipts(chainHeight).pipe(
150+
mergeMap((_) => {
151+
return receiptHttp.getMerkleReceipts(chainHeight, _.transactionStatements[0].generateHash());
152+
}))
153+
.subscribe((merkleReceipts) => {
154+
expect(merkleReceipts.merklePath).not.to.be.null;
155+
done();
156+
});
152157
});
153158
});
154159
describe('getMerkleTransaction', () => {
155160
it('should return Merkle Transaction', (done) => {
156-
blockHttp.getMerkleTransaction(chainHeight, blockTransactionHash)
157-
.subscribe((merkleTransactionss) => {
161+
blockHttp.getBlockTransactions(chainHeight).pipe(
162+
mergeMap((_) => {
163+
const hash = (_[0].transactionInfo as TransactionInfo).hash;
164+
if (hash) {
165+
return blockHttp.getMerkleTransaction(chainHeight, hash);
166+
}
167+
// If reaching this line, something is not right
168+
throw new Error('Tansacation hash is undefined');
169+
}))
170+
.subscribe((merkleTransactionss) => {
158171
expect(merkleTransactionss.merklePath).not.to.be.null;
159172
done();
160173
});

src/model/receipt/BalanceChangeReceipt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export class BalanceChangeReceipt extends Receipt {
6565
const buffer = new Uint8Array(52);
6666
buffer.set(GeneratorUtils.uintToBuffer(ReceiptVersion.BALANCE_CHANGE, 2));
6767
buffer.set(GeneratorUtils.uintToBuffer(this.type, 2), 2);
68-
buffer.set(Convert.hexToUint8(this.targetPublicAccount.publicKey), 4);
69-
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.mosaicId.toHex()).toDTO()), 36);
70-
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.amount.toHex()).toDTO()), 44);
68+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.mosaicId.toHex()).toDTO()), 4);
69+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.amount.toHex()).toDTO()), 12);
70+
buffer.set(Convert.hexToUint8(this.targetPublicAccount.publicKey), 20);
7171
return buffer;
7272
}
7373
}

src/model/receipt/BalanceTransferReceipt.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export class BalanceTransferReceipt extends Receipt {
7474
const buffer = new Uint8Array(52 + recipient.length);
7575
buffer.set(GeneratorUtils.uintToBuffer(ReceiptVersion.BALANCE_TRANSFER, 2));
7676
buffer.set(GeneratorUtils.uintToBuffer(this.type, 2), 2);
77-
buffer.set(Convert.hexToUint8(this.sender.publicKey), 4);
78-
buffer.set(recipient, 36);
79-
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.mosaicId.toHex()).toDTO()), 36 + recipient.length);
80-
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.amount.toHex()).toDTO()), 44 + recipient.length);
77+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.mosaicId.toHex()).toDTO()), 4);
78+
buffer.set(GeneratorUtils.uint64ToBuffer(UInt64.fromHex(this.amount.toHex()).toDTO()), 12);
79+
buffer.set(Convert.hexToUint8(this.sender.publicKey), 20);
80+
buffer.set(recipient, 52);
8181
return buffer;
8282
}
8383

0 commit comments

Comments
 (0)