Skip to content

Commit e4f7720

Browse files
committed
Fixed aggregate size bug
1 parent ea56cbe commit e4f7720

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

src/core/crypto/MerkleHashBuilder.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,23 @@ export class MerkleHashBuilder {
2323
signSchema: SignSchema;
2424
length: number;
2525

26+
/**
27+
* Constructor
28+
* @param hasherFactory Hasher (SHA3_256)
29+
* @param signSchema Sign schema
30+
* @param length Hash size
31+
*/
2632
constructor(hasherFactory: any, signSchema: SignSchema = SignSchema.SHA3, length: number = 32) {
2733
this.hasherFactory = hasherFactory;
2834
this.signSchema = signSchema;
2935
this.length = length;
3036
}
3137

32-
hash(hashes: Uint8Array[]): Uint8Array {
38+
/** @internal
39+
* Hash inner transactions
40+
* @param hashes Inner transaction hashes
41+
*/
42+
protected hash(hashes: Uint8Array[]): Uint8Array {
3343
const hasher = this.hasherFactory(this.length, this.signSchema);
3444
hasher.reset();
3545

@@ -42,7 +52,11 @@ export class MerkleHashBuilder {
4252
return hash;
4353
}
4454

45-
calculateRootHash(hashes: Uint8Array[]): Uint8Array {
55+
/** @internal
56+
* Get root hash of Merkle Trees
57+
* @param hashes Inner transaction hashes
58+
*/
59+
protected calculateRootHash(hashes: Uint8Array[]): Uint8Array {
4660

4761
if (hashes.length === 0) {
4862
return new Uint8Array(this.length);
@@ -65,11 +79,18 @@ export class MerkleHashBuilder {
6579
return hashes[0];
6680
}
6781

68-
getRootHash(): Uint8Array {
82+
/**
83+
* Return root hash from Merkle tree
84+
*/
85+
public getRootHash(): Uint8Array {
6986
return this.calculateRootHash(this.hashes);
7087
}
7188

72-
update(hash: Uint8Array): void {
89+
/**
90+
* Update hashes array
91+
* @param hash Inner transaction hash buffer
92+
*/
93+
public update(hash: Uint8Array): void {
7394
this.hashes.push(hash);
7495
}
7596

src/model/transaction/AggregateTransaction.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,6 @@ export class AggregateTransaction extends Transaction {
299299
const paddedTransactionByte = GeneratorUtils.concatTypedArrays(transactionByte, innerTransactionPadding);
300300
byteTransactions += paddedTransactionByte.length;
301301
});
302-
this.innerTransactions.map((transaction) => {
303-
byteTransactions += (transaction.size - 80);
304-
});
305302

306303
const byteCosignatures = this.cosignatures.length * 96;
307304
return byteSize + byteTransactionHash + bytePayloadSize + byteHeader_Reserved1 +

test/model/transaction/AggregateTransaction.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ describe('AggregateTransaction', () => {
108108
[]);
109109

110110
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
111-
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('05010000');
111+
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('08010000');
112112
expect(signedTransaction.payload.substring(
113113
424,
114114
signedTransaction.payload.length,
115-
)).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D6D657373616765');
115+
)).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D6D657373616765000000');
116116
});
117117

118118
it('should createComplete an AggregateTransaction object with NamespaceRegistrationTransaction', () => {
@@ -131,13 +131,13 @@ describe('AggregateTransaction', () => {
131131
);
132132

133133
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
134-
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('FD000000');
135-
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('55000000000000005500000000000000');
134+
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('00010000');
135+
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('58000000000000005500000000000000');
136136

137137
expect(signedTransaction.payload.substring(
138138
424,
139139
signedTransaction.payload.length,
140-
)).to.be.equal('01904E41E803000000000000CFCBE72D994BE69B0013726F6F742D746573742D6E616D657370616365');
140+
)).to.be.equal('01904E41E803000000000000CFCBE72D994BE69B0013726F6F742D746573742D6E616D657370616365000000');
141141
});
142142

143143
it('should createComplete an AggregateTransaction object with MosaicDefinitionTransaction', () => {
@@ -160,12 +160,12 @@ describe('AggregateTransaction', () => {
160160

161161
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
162162

163-
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('EE000000');
164-
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('46000000000000004600000000000000');
163+
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('F0000000');
164+
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('48000000000000004600000000000000');
165165
expect(signedTransaction.payload.substring(
166166
424,
167167
signedTransaction.payload.length,
168-
)).to.be.equal('01904D410100000000000000E803000000000000E6DE84B80703');
168+
)).to.be.equal('01904D410100000000000000E803000000000000E6DE84B807030000');
169169
});
170170

171171
it('should createComplete an AggregateTransaction object with MosaicSupplyChangeTransaction', () => {
@@ -187,12 +187,12 @@ describe('AggregateTransaction', () => {
187187

188188
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
189189

190-
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('E9000000');
191-
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('41000000000000004100000000000000');
190+
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('F0000000');
191+
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('48000000000000004100000000000000');
192192
expect(signedTransaction.payload.substring(
193193
424,
194194
signedTransaction.payload.length,
195-
)).to.be.equal('01904D424CCCD78612DDF5CA0A0000000000000001');
195+
)).to.be.equal('01904D424CCCD78612DDF5CA0A000000000000000100000000000000');
196196
});
197197

198198
it('should createComplete an AggregateTransaction object with MultisigAccountModificationTransaction', () => {
@@ -245,13 +245,13 @@ describe('AggregateTransaction', () => {
245245
generationHash,
246246
);
247247

248-
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('65010000');
249-
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('5D000000000000005D00000000000000');
248+
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('68010000');
249+
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('60000000000000005D00000000000000');
250250
expect(signedTransaction.payload.substring(
251251
424,
252252
424 + 162,
253-
)).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D' +
254-
'6D65737361676568B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B763');
253+
)).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D0000000' +
254+
'00000746573742D6D65737361676500000068B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842');
255255

256256
});
257257

@@ -273,13 +273,13 @@ describe('AggregateTransaction', () => {
273273

274274
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
275275

276-
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('05010000');
277-
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('5D000000000000005D00000000000000');
276+
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('08010000');
277+
expect(signedTransaction.payload.substring(320, 352)).to.be.equal('60000000000000005D00000000000000');
278278
expect(signedTransaction.payload.substring(220, 224)).to.be.equal('4142');
279279
expect(signedTransaction.payload.substring(
280280
424,
281281
signedTransaction.payload.length,
282-
)).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D6D657373616765');
282+
)).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D6D657373616765000000');
283283
});
284284

285285
it('should validate if accounts have signed an aggregate transaction', () => {
@@ -346,7 +346,8 @@ describe('AggregateTransaction', () => {
346346
PublicAccount.createFromPublicKey('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF',
347347
NetworkType.MIJIN_TEST))).to.be.equal(false);
348348

349-
expect(aggregateTransaction.innerTransactions[0].signer!.publicKey).to.be.equal('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF');
349+
expect(aggregateTransaction.innerTransactions[0].signer!.publicKey)
350+
.to.be.equal('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF');
350351

351352
expect(Convert.hexToUint8(aggregateTransaction.serialize()).length).to.be.equal(aggregateTransaction.size);
352353
});
@@ -536,9 +537,8 @@ describe('AggregateTransaction', () => {
536537
NetworkType.MIJIN_TEST,
537538
[],
538539
);
539-
540540
expect(Convert.hexToUint8(aggregateTransaction.serialize()).length).to.be.equal(aggregateTransaction.size);
541-
expect(aggregateTransaction.size).to.be.equal(268);
541+
expect(aggregateTransaction.size).to.be.equal(272);
542542
});
543543
});
544544
});

test/model/transaction/LockFundsTransaction.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('LockFundsTransaction', () => {
124124

125125
expect(signedTx.payload.substring(
126126
144,
127-
signedTransaction.payload.length - 40,
127+
signedTransaction.payload.length - 104,
128128
)).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE000000000190484100000000');
129129
});
130130

0 commit comments

Comments
 (0)