Skip to content

Commit 4ccde62

Browse files
committed
Fixed aggregate transaction creatFromPayload
- Catbuffer use separate builder class for Complete and Bonded - Added unit tests
1 parent 0fb2071 commit 4ccde62

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/model/transaction/AggregateTransaction.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,14 @@ export class AggregateTransaction extends Transaction {
131131
* @returns {AggregateTransaction}
132132
*/
133133
public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction {
134-
const builder = AggregateCompleteTransactionBuilder
135-
.loadFromBinary(Convert.hexToUint8(payload));
136-
const type = builder.getType().valueOf();
134+
/**
135+
* Get transaction type from the payload hex
136+
* As buffer uses separate builder class for Complete and bonded
137+
*/
138+
const type = parseInt(Convert.uint8ToHex(Convert.hexToUint8(payload.substring(204, 208)).reverse()), 16);
139+
const builder = type === TransactionType.AGGREGATE_COMPLETE ?
140+
AggregateCompleteTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) :
141+
AggregateBondedTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
137142
const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions());
138143
const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0];
139144
const consignaturesHex = Convert.uint8ToHex(builder.getCosignatures());

test/core/utils/TransactionMapping.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ describe('TransactionMapping - createFromPayload', () => {
439439

440440
const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AggregateTransaction;
441441

442+
expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE);
442443
expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER);
443444
});
444445

@@ -461,6 +462,7 @@ describe('TransactionMapping - createFromPayload', () => {
461462

462463
const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AggregateTransaction;
463464

465+
expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_BONDED);
464466
expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER);
465467
});
466468

test/model/transaction/AggregateTransaction.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,33 @@ describe('AggregateTransaction', () => {
265265

266266
});
267267

268+
it('should createBonded an AggregateTransaction object with TransferTransaction', () => {
269+
const transferTransaction = TransferTransaction.create(
270+
Deadline.create(),
271+
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
272+
[],
273+
PlainMessage.create('test-message'),
274+
NetworkType.MIJIN_TEST,
275+
);
276+
277+
const aggregateTransaction = AggregateTransaction.createBonded(
278+
Deadline.create(2, ChronoUnit.MINUTES),
279+
[transferTransaction.toAggregate(account.publicAccount)],
280+
NetworkType.MIJIN_TEST,
281+
[],
282+
);
283+
284+
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
285+
286+
expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000');
287+
expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000');
288+
expect(signedTransaction.payload.substring(204, 208)).to.be.equal('4142');
289+
expect(signedTransaction.payload.substring(
290+
320,
291+
signedTransaction.payload.length,
292+
)).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D657373616765');
293+
});
294+
268295
it('should validate if accounts have signed an aggregate transaction', () => {
269296
const aggregateTransactionDTO = {
270297
meta: {

0 commit comments

Comments
 (0)