Skip to content

Commit

Permalink
Merge branch 'feature/apostille_http_upgrades' of github.com:luxtagof…
Browse files Browse the repository at this point in the history
…ficial/Apostille-library into feature/apostille_http_upgrades
  • Loading branch information
jontey committed Dec 4, 2018
2 parents 5b20de9 + e167327 commit 127d36c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
17 changes: 9 additions & 8 deletions src/model/apostille/ApostillePublicAccount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, AggregateTransaction, Deadline, LockFundsTransaction, ModifyMultisigAccountTransaction, Mosaic, MultisigCosignatoryModification, MultisigCosignatoryModificationType, PlainMessage, PublicAccount, SignedTransaction, Transaction, TransferTransaction, UInt64, XEM } from 'nem2-sdk';
import { Account, AggregateTransaction, Deadline, InnerTransaction, LockFundsTransaction, ModifyMultisigAccountTransaction, Mosaic, MultisigCosignatoryModification, MultisigCosignatoryModificationType, PlainMessage, PublicAccount, SignedTransaction, Transaction, TransferTransaction, UInt64, XEM } from 'nem2-sdk';
import { HashFunction } from '../../hash/HashFunction';
import { Errors } from '../../types/Errors';

Expand Down Expand Up @@ -140,21 +140,22 @@ export class ApostillePublicAccount {
* @returns
* @memberof ApostillePublicAccount
*/

public signAggregate(transaction: Transaction, signers: Account[], isComplete: boolean): SignedTransaction {
if (isComplete) {
return this._signTransferTransactionAgregateComplete(transaction, signers);
} else {
return this._signTransferTransactionAggregateBonded(transaction, signers);
return this._signAgregateBondedTransaction(innerTransactions, signers);
}
}

private _signTransferTransactionAgregateComplete(
transaction: Transaction,
private _signAgregateCompleteTransaction(
innerTransactions: InnerTransaction[],
signers: Account[],
): SignedTransaction {
const aggregateTransaction = AggregateTransaction.createComplete(
Deadline.create(),
[transaction.toAggregate(this.publicAccount)],
innerTransactions,
this.publicAccount.address.networkType,
[]);

Expand All @@ -163,13 +164,13 @@ export class ApostillePublicAccount {
return signedAggregateTransaction;
}

private _signTransferTransactionAggregateBonded(
transaction: Transaction,
private _signAgregateBondedTransaction(
innerTransactions: InnerTransaction[],
signers: Account[],
): SignedTransaction {
const aggregateTransaction = AggregateTransaction.createBonded(
Deadline.create(),
[transaction.toAggregate(this.publicAccount)],
innerTransactions,
this.publicAccount.address.networkType);

const signedAggregateTransaction = this._signAggregate(aggregateTransaction, signers);
Expand Down
32 changes: 25 additions & 7 deletions tests/unit/model/apostille/ApostillePublicAccount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ describe('apostille public account transaction methods should work properly', ()
[signer.publicAccount],
0,
0);

const innerTransaction = transferTransaction.toAggregate(apostillePublicAccount.publicAccount);

expect(() => {
apostillePublicAccount.signAggregate(
transferTransaction,
[innerTransaction],
[],
true);
}).toThrowError(Errors[Errors.UNABLE_TO_SIGN_AGGREGATE_TRANSACTION]);
Expand All @@ -121,8 +124,10 @@ describe('apostille public account transaction methods should work properly', ()
[signer.publicAccount],
0,
0);

const innerTransaction = transferTransaction.toAggregate(apostillePublicAccount.publicAccount);
const signedTransferTransaction = apostillePublicAccount.signAggregate(
transferTransaction,
[innerTransaction],
[signer],
true);
expect(signedTransferTransaction.signer).toMatch(signer.publicAccount.publicKey);
Expand All @@ -134,8 +139,11 @@ describe('apostille public account transaction methods should work properly', ()
[signer.publicAccount],
0,
0);

const innerTransaction = transferTransaction.toAggregate(apostillePublicAccount.publicAccount);

const signedTransferTransaction = apostillePublicAccount.signAggregate(
transferTransaction,
[innerTransaction],
[signer, secondSigner],
true);
expect(signedTransferTransaction.signer).toMatch(signer.publicAccount.publicKey);
Expand All @@ -147,8 +155,10 @@ describe('apostille public account transaction methods should work properly', ()
[signer.publicAccount],
0,
0);

const innerTransaction = aggregateBondedTransaction.toAggregate(apostillePublicAccount.publicAccount);
const signedAggregateBondedTransaction = apostillePublicAccount.signAggregate(
aggregateBondedTransaction,
[innerTransaction],
[signer],
false);
expect(signedAggregateBondedTransaction.signer).toMatch(signer.publicAccount.publicKey);
Expand All @@ -160,8 +170,10 @@ describe('apostille public account transaction methods should work properly', ()
[signer.publicAccount],
0,
0);
const innerTransaction = aggregateBondedTransaction.toAggregate(apostillePublicAccount.publicAccount);

const signedAggregateBondedTransaction = apostillePublicAccount.signAggregate(
aggregateBondedTransaction,
[innerTransaction],
[signer, secondSigner],
false);
expect(signedAggregateBondedTransaction.signer).toMatch(signer.publicAccount.publicKey);
Expand All @@ -173,8 +185,11 @@ describe('apostille public account transaction methods should work properly', ()
[signer.publicAccount],
0,
0);

const innerTransaction = aggregateBondedTransaction.toAggregate(apostillePublicAccount.publicAccount);

const signedAggregateBondedTransaction = apostillePublicAccount.signAggregate(
aggregateBondedTransaction,
[innerTransaction],
[signer],
false);
const lockFundsTransaction = apostillePublicAccount.lockFundsTransaction(
Expand All @@ -188,8 +203,11 @@ describe('apostille public account transaction methods should work properly', ()
[signer.publicAccount],
0,
0);

const innerTransaction = aggregateBondedTransaction.toAggregate(apostillePublicAccount.publicAccount);

const signedAggregateBondedTransaction = apostillePublicAccount.signAggregate(
aggregateBondedTransaction,
[innerTransaction],
[signer],
false);
const lockFundsTransaction = apostillePublicAccount.lockFundsTransaction(
Expand Down

0 comments on commit 127d36c

Please sign in to comment.