Skip to content

Commit

Permalink
chore(package.json): Update nem2-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
jontey committed Apr 10, 2019
1 parent 4a36589 commit d08e01a
Show file tree
Hide file tree
Showing 7 changed files with 1,550 additions and 1,414 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
],
"license": "MIT",
"dependencies": {
"@octokit/request": "^2.1.2",
"crypto-js": "^3.1.9-1",
"js-sha3": "0.8.0",
"lodash": "^4.17.10",
"nem-sdk": "^1.6.4",
"nem2-sdk": "^0.10.1",
"nem-sdk": "^1.6.7",
"nem2-sdk": "^0.11.1",
"rxjs": "^6.2.2"
},
"devDependencies": {
Expand Down
12 changes: 8 additions & 4 deletions src/infrastructure/ApostilleHttp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { chain, remove, sortBy, uniq } from 'lodash';
import { Account, AccountHttp, Address, AggregateTransaction, Deadline, InnerTransaction, Listener, LockFundsTransaction, PublicAccount, QueryParams, SignedTransaction, Transaction, TransactionAnnounceResponse, TransactionHttp, TransactionInfo, TransactionType, TransferTransaction, UInt64, XEM } from 'nem2-sdk';
import { Account, AccountHttp, Address, AggregateTransaction, Deadline, InnerTransaction, Listener, LockFundsTransaction, Mosaic, NamespaceId, PublicAccount, QueryParams, SignedTransaction, Transaction, TransactionAnnounceResponse, TransactionHttp, TransactionInfo, TransactionType, TransferTransaction, UInt64 } from 'nem2-sdk';
import { EMPTY, forkJoin, Observable, of } from 'rxjs';
import { expand, filter, mergeMap, reduce, shareReplay } from 'rxjs/operators';
import { Errors } from '../types/Errors';
Expand Down Expand Up @@ -31,7 +31,7 @@ export class ApostilleHttp {
public static createLockFundsTransaction(signedAggregateBondedTransaction: SignedTransaction): LockFundsTransaction {
const lockFundsTransaction = LockFundsTransaction.create(
Deadline.create(),
XEM.createRelative(10),
new Mosaic(new NamespaceId('nem.xem'), UInt64.fromUint(10)),
UInt64.fromUint(480),
signedAggregateBondedTransaction,
signedAggregateBondedTransaction.networkType);
Expand Down Expand Up @@ -198,7 +198,11 @@ export class ApostilleHttp {
*/
public getCreationTransaction(publicAccount: PublicAccount): Promise<TransferTransaction> {
return new Promise((resolve, reject) => {
this.fetchAllTransactions(publicAccount).subscribe((transactions: Transaction[]) => {
this.fetchAllTransactions(publicAccount).pipe(
reduce((acc, txs) => {
return acc.concat(txs);
}),
).subscribe((transactions: Transaction[]) => {
if (transactions.length > 0) {
const firstTransaction = transactions[transactions.length - 1];
if (firstTransaction instanceof TransferTransaction) {
Expand Down Expand Up @@ -339,7 +343,7 @@ export class ApostilleHttp {
if (transaction.type === TransactionType.TRANSFER ||
transaction.type === TransactionType.MODIFY_MULTISIG_ACCOUNT) {
if (initiator.complete) {
const refreshedTransaction = transaction.replyGiven(Deadline.create());
const refreshedTransaction = transaction.reapplyGiven(Deadline.create());
const innerTransaction = refreshedTransaction.toAggregate(initiator.publicAccount);
innerTransactionsList.push({initiator, innerTransaction});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/Initiator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class Initiator {
let aggregateTransaction: AggregateTransaction | undefined;
if (transaction instanceof TransferTransaction ||
transaction instanceof ModifyMultisigAccountTransaction) {
const refreshedTransaction = transaction.replyGiven(Deadline.create());
const refreshedTransaction = transaction.reapplyGiven(Deadline.create());
if (this.complete) {
aggregateTransaction = AggregateTransaction.createComplete(
Deadline.create(),
Expand Down
6 changes: 4 additions & 2 deletions src/model/apostille/PublicApostille.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Deadline, PlainMessage, TransferTransaction, XEM } from 'nem2-sdk';
import { Address, Deadline, Mosaic, NamespaceId, PlainMessage, TransferTransaction, UInt64 } from 'nem2-sdk';
import { HashFunction } from '../../hash/HashFunction';

/**
Expand Down Expand Up @@ -37,7 +37,9 @@ class PublicApostille {
const creationTransaction = TransferTransaction.create(
Deadline.create(),
this.sinkAddress,
[XEM.createRelative(0)],
[
new Mosaic(new NamespaceId('nem.xem'), UInt64.fromUint(10)),
],
PlainMessage.create(this.hash),
this.sinkAddress.networkType,
);
Expand Down
2 changes: 1 addition & 1 deletion src/model/repository/HistoricalEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export enum HistoricalEndpoints {
// testnet
'http://104.128.226.60:7890' = 0x98,
// mijin_test
'http://api.beta.catapult.mijin.io:3000' = 0x90,
'http://13.114.200.132:3000' = 0x90,
}
// should be used as HistoricalEndpoints[networkType] // get the address
31 changes: 6 additions & 25 deletions tests/unit/infrastructure/ApostilleHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@ const getPublicApostilleAccount = ((publicKey: string, networkType: NetworkType)
});

const apostilleHttp = new ApostilleHttp(HistoricalEndpoints[NetworkType.MIJIN_TEST]);
// Apostille Public Account1 1
// Apostille Public Account 1
const apostillePublicAccount1 = getPublicApostilleAccount(
'E15CAB00A5A34216A8A29034F950A18DFC6F4F27BCCFBF9779DC6886653B7E56',
'9F4E94F2E6B45AC5469308212B6DBC4CE5CCE3183361D95973340B872F8277DA',
NetworkType.MIJIN_TEST);

// Apostille Public Account1 2
// Apostille Public Account 2
const apostillePublicAccount2 = getPublicApostilleAccount(
'67FD8C18BAACED8777EBF483B596D6BE0F93EDB2084FA39968DF8D2D96400E08',
NetworkType.MIJIN_TEST);

// Apostille Public Account 3
const apostillePublicAccount3 = getPublicApostilleAccount(
'901C9D46840BB74F4649EF3AF65A910A9F162DFA0FD5AD7E2739E5B82C2579F0',
NetworkType.MIJIN_TEST);

// Apostille Public Account 4
const apostillePublicAccount4 = getPublicApostilleAccount(
'95361ED8C94048BD5B0BDB229C19DF817DB7D66B59F4162E3F3A1D0D813B2AB9',
Expand All @@ -42,11 +37,6 @@ const owner1 = PublicAccount.createFromPublicKey(
'F8F36DE56950993330A020CDD76B5C1D82266E3460F91EE43FBEFB71E8A8A193',
NetworkType.MIJIN_TEST);

// Apostille Public Account 4
// const owner2 = PublicAccount.createFromPublicKey(
// '22816F825B4CACEA334723D51297D8582332D8B875A5829908AAE85831ABB508',
// NetworkType.MIJIN_TEST);

const network = NetworkType.MIJIN_TEST;
const pk = 'aaaaaaaaaaeeeeeeeeeebbbbbbbbbb5555555555dddddddddd1111111111aaee';
const accountPK = Account.createFromPrivateKey(pk, network);
Expand Down Expand Up @@ -85,13 +75,7 @@ describe('apostille public account non transaction methods should work properly'
return expect(apostilleHttp.isOwned(apostillePublicAccount2.publicAccount.address)).resolves.toBeFalsy();
});

it('should return creation transaction when it is transfer transaction', async () => {
expect.assertions(1);
const data = await apostilleHttp.getCreationTransaction(apostillePublicAccount3.publicAccount);
return expect(data.message.payload).toEqual('');
});

it('should return creation transaction when the it is an aggregate complete transaction', async () => {
it('should return creation transaction when it is an aggregate complete transaction', async () => {
expect.assertions(1);
const data = await apostilleHttp.getCreationTransaction(apostillePublicAccount1.publicAccount);
return expect(data.message.payload).toEqual('I am really really awesomeee');
Expand All @@ -108,16 +92,13 @@ describe('apostille public account non transaction methods should work properly'
expect.assertions(1);
const transactionInfo = await apostilleHttp.getCreationTransactionInfo(
apostillePublicAccount1.publicAccount);
return expect(transactionInfo.id).toEqual('5B160E18C60E680001790BA2');
return expect(transactionInfo.hash).toEqual('7356D0917464FDA989106FDCA9C66529AE07D59F93E9D857F15D60DF66A13B07');
});

describe('fetchAllTransactions', () => {
it('should return more than one page', async () => {
expect.assertions(1);
const accountLarge = PublicAccount.createFromPublicKey(
'FE9F2C724D0E0360A20B9ED7591E4E25CF25D6F4A4E8E52C491C62D2452397F8',
NetworkType.MIJIN_TEST);
const transactions = await apostilleHttp.fetchAllTransactions(accountLarge)
const transactions = await apostilleHttp.fetchAllTransactions(apostillePublicAccount1.publicAccount)
.pipe(
take(2),
reduce((acc, txs) => {
Expand Down
Loading

0 comments on commit d08e01a

Please sign in to comment.