diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 150443d82d..108ad08341 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,6 +1,5 @@ { "apiUrl": "http://localhost:3000", - "generationHash": "5E34C898234E17E8553359D4DEAA123742C323F4C42758C511E6CC805934853E", "testAccount": { "privateKey": "C422CC3C9257A1568036E1726E64EB5923C8363A13D4344F9E66CD89C8789BC7", "address": "SAMA2UEQNAQ45DWYDNJVLPWKQJDAHFZIVLWACIGN", diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 3a698b906b..4d666e63ae 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -14,17 +14,14 @@ * limitations under the License. */ -import {assert, expect} from 'chai'; -import {AccountHttp} from '../../src/infrastructure/AccountHttp'; -import { Listener } from '../../src/infrastructure/Listener'; -import { MultisigHttp } from '../../src/infrastructure/MultisigHttp'; -import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp'; -import { RestrictionAccountHttp } from '../../src/infrastructure/RestrictionAccountHttp'; -import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { assert, expect } from 'chai'; +import { AccountRepository } from '../../src/infrastructure/AccountRepository'; +import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; +import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { Account } from '../../src/model/account/Account'; -import {Address} from '../../src/model/account/Address'; -import {PublicAccount} from '../../src/model/account/PublicAccount'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; +import { Address } from '../../src/model/account/Address'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; @@ -36,11 +33,12 @@ import { MultisigAccountModificationTransaction } from '../../src/model/transact import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../src/model/UInt64'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; describe('AccountHttp', () => { + let helper = new IntegrationTestHelper(); let account: Account; let account2: Account; - let account3: Account; let multisigAccount: Account; let cosignAccount1: Account; let cosignAccount2: Account; @@ -48,42 +46,38 @@ describe('AccountHttp', () => { let accountAddress: Address; let accountPublicKey: string; let publicAccount: PublicAccount; - let accountHttp: AccountHttp; - let multisigHttp: MultisigHttp; - let namespaceHttp: NamespaceHttp; - let restrictionHttp: RestrictionAccountHttp; - let transactionHttp: TransactionHttp; + let accountRepository: AccountRepository; + let multisigRepository: MultisigRepository; + let namespaceRepository: NamespaceRepository; let namespaceId: NamespaceId; let generationHash: string; - let config; + let networkType: NetworkType; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - account3 = Account.createFromPrivateKey(json.testAccount3.privateKey, NetworkType.MIJIN_TEST); - multisigAccount = Account.createFromPrivateKey(json.multisigAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount1 = Account.createFromPrivateKey(json.cosignatoryAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount2 = Account.createFromPrivateKey(json.cosignatory2Account.privateKey, NetworkType.MIJIN_TEST); - cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST); - accountAddress = Address.createFromRawAddress(json.testAccount.address); - accountPublicKey = json.testAccount.publicKey; - publicAccount = PublicAccount.createFromPublicKey(json.testAccount.publicKey, NetworkType.MIJIN_TEST); - generationHash = json.generationHash; - accountHttp = new AccountHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - restrictionHttp = new RestrictionAccountHttp(json.apiUrl); - multisigHttp = new MultisigHttp(json.apiUrl); - namespaceHttp = new NamespaceHttp(json.apiUrl); - done(); + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + multisigAccount = helper.multisigAccount; + cosignAccount1 = helper.cosignAccount1; + cosignAccount2 = helper.cosignAccount2; + cosignAccount3 = helper.cosignAccount3; + accountAddress = helper.account.address; + accountPublicKey = helper.account.publicKey; + publicAccount = helper.account.publicAccount; + generationHash = helper.generationHash; + networkType = helper.networkType; + accountRepository = helper.repositoryFactory.createAccountRepository(); + multisigRepository = helper.repositoryFactory.createMultisigRepository(); + namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); /** * ========================= @@ -92,110 +86,56 @@ describe('AccountHttp', () => { */ describe('Make sure test account is not virgin', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('Announce TransferTransaction', (done) => { + it('Announce TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, [NetworkCurrencyMosaic.createAbsolute(1)], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); - const signedTransaction = transferTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + const signedTransaction = transferTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction); }); }); describe('Setup test NamespaceId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce NamespaceRegistrationTransaction', (done) => { + it('Announce NamespaceRegistrationTransaction', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(9), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); namespaceId = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Setup test AddressAlias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce addressAliasTransaction', (done) => { + it('Announce addressAliasTransaction', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, namespaceId, account.address, - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee, ); const signedTransaction = addressAliasTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Setup test multisig account', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MultisigAccountModificationTransaction', (done) => { + + it('Announce MultisigAccountModificationTransaction', () => { const modifyMultisigAccountTransaction = MultisigAccountModificationTransaction.create( Deadline.create(), 2, @@ -206,24 +146,19 @@ describe('AccountHttp', () => { cosignAccount3.publicAccount, ], [], - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee, ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [modifyMultisigAccountTransaction.toAggregate(multisigAccount.publicAccount)], - NetworkType.MIJIN_TEST, - []); + networkType, + [], + helper.maxFee); const signedTransaction = aggregateTransaction - .signTransactionWithCosignatories(multisigAccount, [cosignAccount1, cosignAccount2, cosignAccount3], generationHash); + .signTransactionWithCosignatories(multisigAccount, [cosignAccount1, cosignAccount2, cosignAccount3], generationHash); - listener.confirmed(multisigAccount.address).subscribe(() => { - done(); - }); - listener.status(multisigAccount.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -235,49 +170,44 @@ describe('AccountHttp', () => { describe('getAccountInfo', () => { it('should return account data given a NEM Address', (done) => { - accountHttp.getAccountInfo(accountAddress) - .subscribe((accountInfo) => { - expect(accountInfo.publicKey).to.be.equal(accountPublicKey); - done(); - }); + accountRepository.getAccountInfo(accountAddress) + .subscribe((accountInfo) => { + expect(accountInfo.publicKey).to.be.equal(accountPublicKey); + done(); + }); }); }); describe('getAccountsInfo', () => { it('should return account data given a NEM Address', (done) => { - accountHttp.getAccountsInfo([accountAddress]) - .subscribe((accountsInfo) => { - expect(accountsInfo[0].publicKey).to.be.equal(accountPublicKey); - done(); - }); + accountRepository.getAccountsInfo([accountAddress]) + .subscribe((accountsInfo) => { + expect(accountsInfo[0].publicKey).to.be.equal(accountPublicKey); + done(); + }); }); }); describe('getMultisigAccountGraphInfo', () => { it('should call getMultisigAccountGraphInfo successfully', (done) => { - setTimeout(() => { - multisigHttp.getMultisigAccountGraphInfo(multisigAccount.publicAccount.address).subscribe((multisigAccountGraphInfo) => { - expect(multisigAccountGraphInfo.multisigAccounts.get(0)![0]. - account.publicKey).to.be.equal(multisigAccount.publicKey); - done(); - }); - }, 1000); + multisigRepository.getMultisigAccountGraphInfo(multisigAccount.publicAccount.address).subscribe((multisigAccountGraphInfo) => { + expect(multisigAccountGraphInfo.multisigAccounts.get(0)![0].account.publicKey).to.be.equal(multisigAccount.publicKey); + done(); + }); }); }); describe('getMultisigAccountInfo', () => { it('should call getMultisigAccountInfo successfully', (done) => { - setTimeout(() => { - multisigHttp.getMultisigAccountInfo(multisigAccount.publicAccount.address).subscribe((multisigAccountInfo) => { - expect(multisigAccountInfo.account.publicKey).to.be.equal(multisigAccount.publicKey); - done(); - }); - }, 1000); + multisigRepository.getMultisigAccountInfo(multisigAccount.publicAccount.address).subscribe((multisigAccountInfo) => { + expect(multisigAccountInfo.account.publicKey).to.be.equal(multisigAccount.publicKey); + done(); + }); }); }); describe('outgoingTransactions', () => { it('should call outgoingTransactions successfully', (done) => { - accountHttp.getAccountOutgoingTransactions(publicAccount.address).subscribe((transactions) => { + accountRepository.getAccountOutgoingTransactions(publicAccount.address).subscribe((transactions) => { expect(transactions.length).to.be.greaterThan(0); done(); }); @@ -286,7 +216,7 @@ describe('AccountHttp', () => { describe('aggregateBondedTransactions', () => { it('should call aggregateBondedTransactions successfully', (done) => { - accountHttp.getAccountPartialTransactions(publicAccount.address).subscribe(() => { + accountRepository.getAccountPartialTransactions(publicAccount.address).subscribe(() => { done(); }, (error) => { console.log('Error:', error); @@ -297,7 +227,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should call transactions successfully', (done) => { - accountHttp.getAccountTransactions(publicAccount.address).subscribe((transactions) => { + accountRepository.getAccountTransactions(publicAccount.address).subscribe((transactions) => { expect(transactions.length).to.be.greaterThan(0); done(); }); @@ -306,7 +236,7 @@ describe('AccountHttp', () => { describe('unconfirmedTransactions', () => { it('should call unconfirmedTransactions successfully', (done) => { - accountHttp.getAccountUnconfirmedTransactions(publicAccount.address).subscribe((transactions) => { + accountRepository.getAccountUnconfirmedTransactions(publicAccount.address).subscribe((transactions) => { expect(transactions.length).to.be.equal(0); done(); }); @@ -315,7 +245,7 @@ describe('AccountHttp', () => { describe('getAddressNames', () => { it('should call getAddressNames successfully', (done) => { - namespaceHttp.getAccountsNames([accountAddress]).subscribe((addressNames) => { + namespaceRepository.getAccountsNames([accountAddress]).subscribe((addressNames) => { expect(addressNames.length).to.be.greaterThan(0); done(); }); @@ -328,55 +258,31 @@ describe('AccountHttp', () => { * ========================= */ describe('Remove test AddressAlias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('Announce addressAliasTransaction', (done) => { + it('Announce addressAliasTransaction', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Unlink, namespaceId, account.address, - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const signedTransaction = addressAliasTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Restore test multisig Accounts', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MultisigAccountModificationTransaction', (done) => { + it('Announce MultisigAccountModificationTransaction', () => { const removeCosigner1 = MultisigAccountModificationTransaction.create( Deadline.create(), -1, 0, [], - [ cosignAccount1.publicAccount, + [cosignAccount1.publicAccount, ], - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const removeCosigner2 = MultisigAccountModificationTransaction.create( Deadline.create(), @@ -386,7 +292,8 @@ describe('AccountHttp', () => { [ cosignAccount2.publicAccount, ], - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const removeCosigner3 = MultisigAccountModificationTransaction.create( @@ -397,26 +304,19 @@ describe('AccountHttp', () => { [ cosignAccount3.publicAccount, ], - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [removeCosigner1.toAggregate(multisigAccount.publicAccount), - removeCosigner2.toAggregate(multisigAccount.publicAccount), - removeCosigner3.toAggregate(multisigAccount.publicAccount)], - NetworkType.MIJIN_TEST, - []); + removeCosigner2.toAggregate(multisigAccount.publicAccount), + removeCosigner3.toAggregate(multisigAccount.publicAccount)], + networkType, + [], helper.maxFee); const signedTransaction = aggregateTransaction - .signTransactionWithCosignatories(cosignAccount1, [cosignAccount2, cosignAccount3], generationHash); - - listener.confirmed(cosignAccount1.address).subscribe(() => { - done(); - }); - listener.status(cosignAccount1.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + .signTransactionWithCosignatories(cosignAccount1, [cosignAccount2, cosignAccount3], generationHash); + return helper.announce(signedTransaction); }); }); }); diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index e4893caf16..30e7e192ea 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -14,49 +14,52 @@ * limitations under the License. */ -import {assert, expect} from 'chai'; +import { expect } from 'chai'; import { mergeMap } from 'rxjs/operators'; -import {BlockHttp} from '../../src/infrastructure/BlockHttp'; -import { Listener, ReceiptHttp, TransactionHttp } from '../../src/infrastructure/infrastructure'; -import {QueryParams} from '../../src/infrastructure/QueryParams'; +import { BlockHttp } from '../../src/infrastructure/BlockHttp'; +import { QueryParams } from '../../src/infrastructure/QueryParams'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { Deadline } from '../../src/model/transaction/Deadline'; -import { Transaction } from '../../src/model/transaction/Transaction'; import { TransactionInfo } from '../../src/model/transaction/TransactionInfo'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { BlockRepository } from "../../src/infrastructure/BlockRepository"; +import { ReceiptRepository } from "../../src/infrastructure/ReceiptRepository"; describe('BlockHttp', () => { + let helper = new IntegrationTestHelper(); let account: Account; let account2: Account; - let blockHttp: BlockHttp; - let receiptHttp: ReceiptHttp; - let transactionHttp: TransactionHttp; + let blockRepository: BlockRepository; + let receiptRepository: ReceiptRepository; let blockReceiptHash = ''; let blockTransactionHash = ''; - let config; let chainHeight; let generationHash: string; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - blockHttp = new BlockHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - receiptHttp = new ReceiptHttp(json.apiUrl); - generationHash = json.generationHash; - done(); + let networkType: NetworkType; + + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + generationHash = helper.generationHash; + networkType = helper.networkType; + blockRepository = helper.repositoryFactory.createBlockRepository(); + receiptRepository = helper.repositoryFactory.createReceiptRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + /** * ========================= * Setup Test Data @@ -64,14 +67,7 @@ describe('BlockHttp', () => { */ describe('Setup Test Data', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('Announce TransferTransaction', (done) => { const transferTransaction = TransferTransaction.create( @@ -79,35 +75,29 @@ describe('BlockHttp', () => { account2.address, [NetworkCurrencyMosaic.createAbsolute(1)], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const signedTransaction = transferTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe((transaction: Transaction) => { + helper.announce(signedTransaction).then(transaction => { chainHeight = transaction.transactionInfo!.height.toString(); - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); + return transaction; }); - transactionHttp.announce(signedTransaction); }); }); describe('getBlockByHeight', () => { it('should return block info given height', (done) => { - blockHttp.getBlockByHeight('1') - .subscribe((blockInfo) => { - blockReceiptHash = blockInfo.blockReceiptsHash; - blockTransactionHash = blockInfo.blockTransactionsHash; - expect(blockInfo.height.lower).to.be.equal(1); - expect(blockInfo.height.higher).to.be.equal(0); - expect(blockInfo.timestamp.lower).to.be.equal(0); - expect(blockInfo.timestamp.higher).to.be.equal(0); - done(); - }); + blockRepository.getBlockByHeight('1') + .subscribe((blockInfo) => { + blockReceiptHash = blockInfo.blockReceiptsHash; + blockTransactionHash = blockInfo.blockTransactionsHash; + expect(blockInfo.height.lower).to.be.equal(1); + expect(blockInfo.height.higher).to.be.equal(0); + expect(blockInfo.timestamp.lower).to.be.equal(0); + expect(blockInfo.timestamp.higher).to.be.equal(0); + done(); + }); }); }); @@ -116,39 +106,39 @@ describe('BlockHttp', () => { let firstId: string; it('should return block transactions data given height', (done) => { - blockHttp.getBlockTransactions('1') - .subscribe((transactions) => { - nextId = transactions[0].transactionInfo!.id; - firstId = transactions[1].transactionInfo!.id; - expect(transactions.length).to.be.greaterThan(0); - done(); - }); + blockRepository.getBlockTransactions('1') + .subscribe((transactions) => { + nextId = transactions[0].transactionInfo!.id; + firstId = transactions[1].transactionInfo!.id; + expect(transactions.length).to.be.greaterThan(0); + done(); + }); }); it('should return block transactions data given height with paginated transactionId', (done) => { - blockHttp.getBlockTransactions('1', new QueryParams(10, nextId)) - .subscribe((transactions) => { - expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); - expect(transactions.length).to.be.greaterThan(0); - done(); - }); + blockRepository.getBlockTransactions('1', new QueryParams(10, nextId)) + .subscribe((transactions) => { + expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); + expect(transactions.length).to.be.greaterThan(0); + done(); + }); }); }); describe('getBlocksByHeightWithLimit', () => { it('should return block info given height and limit', (done) => { - blockHttp.getBlocksByHeightWithLimit(chainHeight, 50) - .subscribe((blocksInfo) => { - expect(blocksInfo.length).to.be.greaterThan(0); - done(); - }); + blockRepository.getBlocksByHeightWithLimit(chainHeight, 50) + .subscribe((blocksInfo) => { + expect(blocksInfo.length).to.be.greaterThan(0); + done(); + }); }); }); describe('getMerkleReceipts', () => { it('should return Merkle Receipts', (done) => { - receiptHttp.getBlockReceipts(chainHeight).pipe( + receiptRepository.getBlockReceipts(chainHeight).pipe( mergeMap((_) => { - return receiptHttp.getMerkleReceipts(chainHeight, _.transactionStatements[0].generateHash()); + return receiptRepository.getMerkleReceipts(chainHeight, _.transactionStatements[0].generateHash()); })) .subscribe((merkleReceipts) => { expect(merkleReceipts.merklePath).not.to.be.null; @@ -158,30 +148,30 @@ describe('BlockHttp', () => { }); describe('getMerkleTransaction', () => { it('should return Merkle Transaction', (done) => { - blockHttp.getBlockTransactions(chainHeight).pipe( + blockRepository.getBlockTransactions(chainHeight).pipe( mergeMap((_) => { const hash = (_[0].transactionInfo as TransactionInfo).hash; if (hash) { - return blockHttp.getMerkleTransaction(chainHeight, hash); + return blockRepository.getMerkleTransaction(chainHeight, hash); } // If reaching this line, something is not right throw new Error('Tansacation hash is undefined'); })) .subscribe((merkleTransactionss) => { - expect(merkleTransactionss.merklePath).not.to.be.null; - done(); - }); + expect(merkleTransactionss.merklePath).not.to.be.null; + done(); + }); }); }); describe('getBlockReceipts', () => { it('should return block receipts', (done) => { - receiptHttp.getBlockReceipts(chainHeight) - .subscribe((statement) => { - expect(statement.transactionStatements).not.to.be.null; - expect(statement.transactionStatements.length).to.be.greaterThan(0); - done(); - }); + receiptRepository.getBlockReceipts(chainHeight) + .subscribe((statement) => { + expect(statement.transactionStatements).not.to.be.null; + expect(statement.transactionStatements.length).to.be.greaterThan(0); + done(); + }); }); }); }); diff --git a/e2e/infrastructure/ChainHttp.spec.ts b/e2e/infrastructure/ChainHttp.spec.ts index e761530138..53c3171900 100644 --- a/e2e/infrastructure/ChainHttp.spec.ts +++ b/e2e/infrastructure/ChainHttp.spec.ts @@ -14,42 +14,40 @@ * limitations under the License. */ -import {expect} from 'chai'; -import {ChainHttp} from '../../src/infrastructure/ChainHttp'; -import {QueryParams} from '../../src/infrastructure/QueryParams'; +import { expect } from 'chai'; +import { ChainHttp } from '../../src/infrastructure/ChainHttp'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { ChainRepository } from "../../src/infrastructure/ChainRepository"; + describe('ChainHttp', () => { - let chainHttp: ChainHttp; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - chainHttp = new ChainHttp(json.apiUrl); - done(); + let helper = new IntegrationTestHelper(); + let chainRepository: ChainRepository; + + before(() => { + return helper.start().then(() => { + chainRepository = helper.repositoryFactory.createChainRepository(); }); }); describe('getBlockchainHeight', () => { it('should return blockchain height', (done) => { - chainHttp.getBlockchainHeight() - .subscribe((height) => { - expect(height.lower).to.be.greaterThan(0); - done(); - }); + chainRepository.getBlockchainHeight() + .subscribe((height) => { + expect(height.lower).to.be.greaterThan(0); + done(); + }); }); }); describe('getBlockchainScore', () => { it('should return blockchain score', (done) => { - chainHttp.getChainScore() - .subscribe((blockchainScore) => { - expect(blockchainScore.scoreLow).to.not.be.equal(undefined); - expect(blockchainScore.scoreHigh.lower).to.be.equal(0); - expect(blockchainScore.scoreHigh.higher).to.be.equal(0); - done(); - }); + chainRepository.getChainScore() + .subscribe((blockchainScore) => { + expect(blockchainScore.scoreLow).to.not.be.equal(undefined); + expect(blockchainScore.scoreHigh.lower).to.be.equal(0); + expect(blockchainScore.scoreHigh.higher).to.be.equal(0); + done(); + }); }); }); }); diff --git a/e2e/infrastructure/DiagnosticHttp.spec.ts b/e2e/infrastructure/DiagnosticHttp.spec.ts index c9519a43f0..419dbe29db 100644 --- a/e2e/infrastructure/DiagnosticHttp.spec.ts +++ b/e2e/infrastructure/DiagnosticHttp.spec.ts @@ -14,42 +14,41 @@ * limitations under the License. */ -import {expect} from 'chai'; -import {DiagnosticHttp} from '../../src/infrastructure/DiagnosticHttp'; +import { expect } from 'chai'; +import { DiagnosticHttp } from '../../src/infrastructure/DiagnosticHttp'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { DiagnosticRepository } from "../../src/infrastructure/DiagnosticRepository"; + describe('DiagnosticHttp', () => { - let diagnosticHttp: DiagnosticHttp; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - diagnosticHttp = new DiagnosticHttp(json.apiUrl); - done(); + let helper = new IntegrationTestHelper(); + let diagnosticRepository: DiagnosticRepository; + + before(() => { + return helper.start().then(() => { + diagnosticRepository = helper.repositoryFactory.createDiagnosticRepository(); }); }); describe('getDiagnosticStorage', () => { it('should return diagnostic storage', (done) => { - diagnosticHttp.getDiagnosticStorage() - .subscribe((blockchainStorageInfo) => { - expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0); - expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0); - expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0); - done(); - }); + diagnosticRepository.getDiagnosticStorage() + .subscribe((blockchainStorageInfo) => { + expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0); + expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0); + expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0); + done(); + }); }); }); describe('getServerInfo', () => { it('should return diagnostic storage', (done) => { - diagnosticHttp.getServerInfo() - .subscribe((serverInfo) => { - expect(serverInfo.restVersion).not.to.be.null; - expect(serverInfo.sdkVersion).not.to.be.null; - done(); - }); + diagnosticRepository.getServerInfo() + .subscribe((serverInfo) => { + expect(serverInfo.restVersion).not.to.be.null; + expect(serverInfo.sdkVersion).not.to.be.null; + done(); + }); }); }); }); diff --git a/e2e/infrastructure/IntegrationTestHelper.ts b/e2e/infrastructure/IntegrationTestHelper.ts new file mode 100644 index 0000000000..8fc76c17fa --- /dev/null +++ b/e2e/infrastructure/IntegrationTestHelper.ts @@ -0,0 +1,125 @@ +/* + * Copyright 2019 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { Account } from "../../src/model/account/Account"; +import { RepositoryFactoryHttp } from "../../src/infrastructure/RepositoryFactoryHttp"; +import { RepositoryFactory } from "../../src/infrastructure/RepositoryFactory"; +import { NetworkType } from "../../src/model/blockchain/NetworkType"; +import { combineLatest } from "rxjs"; +import { IListener } from "../../src/infrastructure/IListener"; +import { SignedTransaction } from "../../src/model/transaction/SignedTransaction"; +import { filter } from "rxjs/operators"; +import { Transaction } from "../../src/model/transaction/Transaction"; +import { UInt64 } from "../../src/model/UInt64"; + +const yaml = require('js-yaml'); + +export class IntegrationTestHelper { + + public apiUrl: string; + public repositoryFactory: RepositoryFactory; + public account: Account; + public account2: Account; + public account3: Account; + public multisigAccount: Account; + public cosignAccount1: Account; + public cosignAccount2: Account; + public cosignAccount3: Account; + public cosignAccount4: Account; + public networkType: NetworkType; + public generationHash: string; + public listener: IListener; + public maxFee: UInt64; + public harvestingAccount: Account; + + start(): Promise { + return new Promise( + (resolve, reject) => { + + const path = require('path'); + require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, jsonData) => { + if (err) { + return reject(err); + } + const json = JSON.parse(jsonData); + console.log(`Running tests against: ${json.apiUrl}`); + this.apiUrl = json.apiUrl; + this.repositoryFactory = new RepositoryFactoryHttp(json.apiUrl); + combineLatest(this.repositoryFactory.getGenerationHash(), this.repositoryFactory.getNetworkType()).subscribe(([generationHash, networkType]) => { + this.networkType = networkType; + this.generationHash = generationHash; + this.account = this.createAccount(json.testAccount); + this.account2 = this.createAccount(json.testAccount2); + this.account3 = this.createAccount(json.testAccount3); + this.multisigAccount = this.createAccount(json.multisigAccount); + this.cosignAccount1 = this.createAccount(json.cosignatoryAccount); + this.cosignAccount2 = this.createAccount(json.cosignatory2Account); + this.cosignAccount3 = this.createAccount(json.cosignatory3Account); + this.cosignAccount4 = this.createAccount(json.cosignatory4Account); + this.harvestingAccount = this.createAccount(json.harvestingAccount); + this.listener = this.repositoryFactory.createListener(); + + this.maxFee = UInt64.fromUint(1000000); //What would be the best maxFee? In the future we will load the fee multiplier from rest. + + + require('fs').readFile(path.resolve(__dirname, '../../../catapult-service-bootstrap/build/generated-addresses/addresses.yaml'), (err, yamlData) => { + if (err) { + console.log(`catapult-service-bootstrap generated address could not be loaded. Ignoring and using accounts from network.conf. Error: ${err}`); + return resolve(this); + } else { + const parsedYaml = yaml.safeLoad(yamlData); + this.account = this.createAccount(parsedYaml.nemesis_addresses[0]); + this.account2 = this.createAccount(parsedYaml.nemesis_addresses[1]); + this.account3 = this.createAccount(parsedYaml.nemesis_addresses[2]); + this.multisigAccount = this.createAccount(parsedYaml.nemesis_addresses[3]); + this.cosignAccount1 = this.createAccount(parsedYaml.nemesis_addresses[4]); + this.cosignAccount4 = this.createAccount(parsedYaml.nemesis_addresses[5]); + this.harvestingAccount = this.createAccount(parsedYaml.nemesis_addresses_harvesting[0]); + return resolve(this); + } + }); + }, (error) => { + console.log("There has been an error loading the configuration. ", error) + return reject(error); + }); + }); + + + } + ); + }; + + createAccount(data): Account { + return Account.createFromPrivateKey(data.privateKey ? data.privateKey : data.private, this.networkType); + } + + announce(signedTransaction: SignedTransaction): Promise { + return new Promise( + (resolve, reject) => { + const address = signedTransaction.getSignerAddress(); + console.log(`Announcing transaction: ${signedTransaction.type}`); + this.listener.confirmed(address, signedTransaction.hash).subscribe((transaction) => { + console.log(`Transaction ${signedTransaction.type} confirmed`); + resolve(transaction); + }); + this.listener.status(address).pipe(filter(status => status.hash === signedTransaction.hash)).subscribe((error) => { + console.log(`Error processing transaction ${signedTransaction.type}`, error); + reject(error); + }); + this.repositoryFactory.createTransactionRepository().announce(signedTransaction); + } + ); + }; +} diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 8d431e8782..8a2f418aa7 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -14,157 +14,177 @@ * limitations under the License. */ import { assert, expect } from 'chai'; -import { AccountHttp } from '../../src/infrastructure/AccountHttp'; -import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; -import { Listener } from '../../src/infrastructure/Listener'; -import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { AccountRepository } from '../../src/infrastructure/AccountRepository'; +import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { Mosaic, UInt64 } from '../../src/model/model'; +import { + Address, + CosignatureTransaction, + LockFundsTransaction, + Mosaic, + SignedTransaction, + UInt64 +} from '../../src/model/model'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; -import { CosignatoryModificationAction } from '../../src/model/transaction/CosignatoryModificationAction'; import { Deadline } from '../../src/model/transaction/Deadline'; import { MultisigAccountModificationTransaction } from '../../src/model/transaction/MultisigAccountModificationTransaction'; -import { MultisigCosignatoryModification } from '../../src/model/transaction/MultisigCosignatoryModification'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; -import { TransactionUtils } from './TransactionUtils'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { NamespaceRepository } from "../../src/infrastructure/NamespaceRepository"; +import { filter } from "rxjs/operators"; +import { ChronoUnit } from "js-joda"; describe('Listener', () => { - let accountHttp: AccountHttp; - let apiUrl: string; - let transactionHttp: TransactionHttp; + let helper = new IntegrationTestHelper(); let account: Account; let account2: Account; + let multisigAccount: Account; let cosignAccount1: Account; let cosignAccount2: Account; let cosignAccount3: Account; - let cosignAccount4: Account; - let multisigAccount: Account; - let networkCurrencyMosaicId: MosaicId; - let namespaceHttp: NamespaceHttp; + let accountRepository: AccountRepository; + let namespaceRepository: NamespaceRepository; let generationHash: string; - let config; - - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - apiUrl = json.apiUrl; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - multisigAccount = Account.createFromPrivateKey(json.multisigAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount1 = Account.createFromPrivateKey(json.cosignatoryAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount2 = Account.createFromPrivateKey(json.cosignatory2Account.privateKey, NetworkType.MIJIN_TEST); - cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST); - cosignAccount4 = Account.createFromPrivateKey(json.cosignatory4Account.privateKey, NetworkType.MIJIN_TEST); - transactionHttp = new TransactionHttp(json.apiUrl); - accountHttp = new AccountHttp(json.apiUrl); - namespaceHttp = new NamespaceHttp(json.apiUrl); - generationHash = json.generationHash; - done(); + let networkType: NetworkType; + let networkCurrencyMosaicId: MosaicId; + let transactionRepository: TransactionRepository; + + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + multisigAccount = helper.multisigAccount; + cosignAccount1 = helper.cosignAccount1; + cosignAccount2 = helper.cosignAccount2; + cosignAccount3 = helper.cosignAccount3; + generationHash = helper.generationHash; + networkType = helper.networkType; + accountRepository = helper.repositoryFactory.createAccountRepository(); + namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); + transactionRepository = helper.repositoryFactory.createTransactionRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + afterEach((done) => { + // cold down + setTimeout(done, 200); + }); + + + let createSignedAggregatedBondTransaction = (aggregatedTo: Account, + signer: Account, + recipient: Address): SignedTransaction => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + recipient, + [], + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); + + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(2, ChronoUnit.MINUTES), + [transferTransaction.toAggregate(aggregatedTo.publicAccount)], + networkType, + [], helper.maxFee + ); + return signer.sign(aggregateTransaction, generationHash); + }; + + let createHashLockTransactionAndAnnounce = (signedAggregatedTransaction: SignedTransaction, + signer: Account, + mosaicId: MosaicId) => { + const lockFundsTransaction = LockFundsTransaction.create( + Deadline.create(), + new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + UInt64.fromUint(1000), + signedAggregatedTransaction, + networkType, helper.maxFee + ); + const signedLockFundsTransaction = signer.sign(lockFundsTransaction, generationHash); + transactionRepository.announce(signedLockFundsTransaction); + }; describe('Confirmed', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('confirmedTransactionsGiven address signer', (done) => { - listener.confirmed(account.address).subscribe((res) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - TransactionUtils.createAndAnnounce(account, account.address, transactionHttp, undefined, generationHash); + + it('confirmedTransactionsGiven address signer', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account.address, + [], + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); + const signedTransaction = account.sign(transferTransaction, generationHash); + return helper.announce(signedTransaction); }); }); describe('Confirmed', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('confirmedTransactionsGiven address recipient', (done) => { + + it('confirmedTransactionsGiven address recipient', () => { const recipientAddress = account2.address; - listener.confirmed(recipientAddress).subscribe((res) => { - done(); - }); - listener.status(recipientAddress).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - TransactionUtils.createAndAnnounce(account, recipientAddress, transactionHttp, undefined, generationHash); + const transferTransaction = TransferTransaction.create( + Deadline.create(), + recipientAddress, + [], + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); + const signedTransaction = account.sign(transferTransaction, generationHash); + return helper.announce(signedTransaction); }); }); describe('UnConfirmed', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('unconfirmedTransactionsAdded', (done) => { - listener.unconfirmedAdded(account.address).subscribe((res) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); + + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account.address, + [], + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); + const signedTransaction = account.sign(transferTransaction, generationHash); + helper.listener.unconfirmedAdded(account.address).pipe(filter((_) => _.transactionInfo!.hash === signedTransaction.hash)).subscribe(() => { done(); }); - TransactionUtils.createAndAnnounce(account, account.address, transactionHttp, undefined, generationHash); + helper.announce(signedTransaction); }); - }); - describe('UnConfirmed', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); it('unconfirmedTransactionsRemoved', (done) => { - listener.unconfirmedAdded(account.address).subscribe((res) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); + + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account.address, + [], + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); + const signedTransaction = account.sign(transferTransaction, generationHash); + helper.listener.unconfirmedRemoved(account.address).pipe(filter(hash => hash === signedTransaction.hash)).subscribe(() => { done(); }); - TransactionUtils.createAndAnnounce(account, account.address, transactionHttp, undefined, generationHash); + helper.announce(signedTransaction); }); }); describe('Get network currency mosaic id', () => { it('get mosaicId', (done) => { - namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId) => { + namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId: MosaicId) => { networkCurrencyMosaicId = networkMosaicId; done(); }); @@ -172,199 +192,139 @@ describe('Listener', () => { }); describe('TransferTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('standalone', (done) => { + it('standalone', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), cosignAccount1.address, [new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY)))], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = transferTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MultisigAccountModificationTransaction - Create multisig account', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('MultisigAccountModificationTransaction', (done) => { + + it('MultisigAccountModificationTransaction', () => { const modifyMultisigAccountTransaction = MultisigAccountModificationTransaction.create( Deadline.create(), 2, 1, - [ cosignAccount1.publicAccount, + [cosignAccount1.publicAccount, cosignAccount2.publicAccount, cosignAccount3.publicAccount, ], [], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [modifyMultisigAccountTransaction.toAggregate(multisigAccount.publicAccount)], - NetworkType.MIJIN_TEST, - []); + networkType, + [], helper.maxFee); const signedTransaction = aggregateTransaction - .signTransactionWithCosignatories(multisigAccount, [cosignAccount1, cosignAccount2, cosignAccount3], generationHash); + .signTransactionWithCosignatories(multisigAccount, [cosignAccount1, cosignAccount2, cosignAccount3], generationHash); - listener.confirmed(multisigAccount.address).subscribe((transaction) => { - done(); - }); - listener.status(multisigAccount.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('Aggregate Bonded Transactions', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('aggregateBondedTransactionsAdded', (done) => { - listener.aggregateBondedAdded(account.address).subscribe((res) => { + helper.listener.aggregateBondedAdded(account.address).subscribe(() => { done(); }); - listener.confirmed(account.address).subscribe((res) => { - TransactionUtils.announceAggregateBoundedTransaction(signedAggregatedTx, transactionHttp); + helper.listener.confirmed(account.address).subscribe(() => { + transactionRepository.announceAggregateBonded(signedAggregatedTx) }); - listener.status(account.address).subscribe((error) => { + helper.listener.status(account.address).subscribe((error) => { console.log('Error:', error); assert(false); done(); }); - const signedAggregatedTx = TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, account, - account2.address, generationHash); + const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); - TransactionUtils.createHashLockTransactionAndAnnounce(signedAggregatedTx, account, networkCurrencyMosaicId, - transactionHttp, generationHash); + createHashLockTransactionAndAnnounce(signedAggregatedTx, account, networkCurrencyMosaicId); }); }); describe('Aggregate Bonded Transactions', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); it('aggregateBondedTransactionsRemoved', (done) => { - listener.confirmed(cosignAccount1.address).subscribe((res) => { - listener.aggregateBondedRemoved(cosignAccount1.address).subscribe(() => { + helper.listener.confirmed(cosignAccount1.address).subscribe(() => { + helper.listener.aggregateBondedRemoved(cosignAccount1.address).subscribe(() => { done(); }); - listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { - accountHttp.getAccountPartialTransactions(cosignAccount1.publicAccount.address).subscribe((transactions) => { + helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { + accountRepository.getAccountPartialTransactions(cosignAccount1.publicAccount.address).subscribe((transactions) => { const transactionToCosign = transactions[0]; - TransactionUtils.cosignTransaction(transactionToCosign, cosignAccount2, transactionHttp); + const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign); + const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction); + transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction); + }); }); - listener.status(cosignAccount1.address).subscribe((error) => { + helper.listener.status(cosignAccount1.address).subscribe((error) => { console.log('Error:', error); assert(false); done(); }); - TransactionUtils.announceAggregateBoundedTransaction(signedAggregatedTx, transactionHttp); + transactionRepository.announceAggregateBonded(signedAggregatedTx) }); - listener.status(cosignAccount1.address).subscribe((error) => { + helper.listener.status(cosignAccount1.address).subscribe((error) => { console.log('Error:', error); assert(false); done(); }); const signedAggregatedTx = - TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address, generationHash); + createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - TransactionUtils. - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, - networkCurrencyMosaicId, transactionHttp, generationHash); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId); }); }); describe('Aggregate Bonded Transactions', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('cosignatureAdded', (done) => { - listener.cosignatureAdded(cosignAccount1.address).subscribe(() => { + helper.listener.cosignatureAdded(cosignAccount1.address).subscribe(() => { done(); }); - listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { - accountHttp.getAccountPartialTransactions(cosignAccount1.publicAccount.address).subscribe((transactions) => { + helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { + accountRepository.getAccountPartialTransactions(cosignAccount1.publicAccount.address).subscribe((transactions) => { const transactionToCosign = transactions[0]; - TransactionUtils.cosignTransaction(transactionToCosign, cosignAccount2, transactionHttp); + const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign); + const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction); + transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction); }); }); - listener.confirmed(cosignAccount1.address).subscribe((res) => { - TransactionUtils.announceAggregateBoundedTransaction(signedAggregatedTx, transactionHttp); + helper.listener.confirmed(cosignAccount1.address).subscribe(() => { + transactionRepository.announceAggregateBonded(signedAggregatedTx) }); - listener.status(cosignAccount1.address).subscribe((error) => { + helper.listener.status(cosignAccount1.address).subscribe((error) => { console.log('Error:', error); assert(false); done(); }); const signedAggregatedTx = - TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address, generationHash); + createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - TransactionUtils. - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, - networkCurrencyMosaicId, transactionHttp, generationHash); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId); }); }); describe('MultisigAccountModificationTransaction - Restore multisig Accounts', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Restore Multisig Account', (done) => { + + it('Restore Multisig Account', () => { const removeCosigner1 = MultisigAccountModificationTransaction.create( Deadline.create(), -1, 0, [], [cosignAccount1.publicAccount], - NetworkType.MIJIN_TEST, + networkType, ); const removeCosigner2 = MultisigAccountModificationTransaction.create( Deadline.create(), @@ -372,7 +332,7 @@ describe('Listener', () => { 0, [], [cosignAccount2.publicAccount], - NetworkType.MIJIN_TEST, + networkType, ); const removeCosigner3 = MultisigAccountModificationTransaction.create( @@ -381,62 +341,56 @@ describe('Listener', () => { -1, [], [cosignAccount3.publicAccount], - NetworkType.MIJIN_TEST, + networkType, ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [removeCosigner1.toAggregate(multisigAccount.publicAccount), - removeCosigner2.toAggregate(multisigAccount.publicAccount), - removeCosigner3.toAggregate(multisigAccount.publicAccount)], - NetworkType.MIJIN_TEST, + removeCosigner2.toAggregate(multisigAccount.publicAccount), + removeCosigner3.toAggregate(multisigAccount.publicAccount)], + networkType, []); const signedTransaction = aggregateTransaction - .signTransactionWithCosignatories(cosignAccount1, [cosignAccount2, cosignAccount3], generationHash); - - listener.confirmed(cosignAccount1.address).subscribe((transaction) => { - done(); - }); - listener.status(cosignAccount1.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + .signTransactionWithCosignatories(cosignAccount1, [cosignAccount2, cosignAccount3], generationHash); + return helper.announce(signedTransaction); }); }); describe('Transactions Status', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('transactionStatusGiven', (done) => { - listener.status(account.address).subscribe((error) => { + + it('transactionStatusGiven', () => { + const mosaics = [NetworkCurrencyMosaic.createRelative(1000000000000)]; + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + mosaics, + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); + + return helper.announce(transferTransaction.signWith(account, generationHash)).then(() => { + throw new Error("Transaction should have failed!!"); + }, error => { expect(error.status).to.be.equal('Failure_Core_Insufficient_Balance'); - done(); }); - const mosaics = [NetworkCurrencyMosaic.createRelative(1000000000000)]; - TransactionUtils.createAndAnnounce(account, account2.address, transactionHttp, mosaics, generationHash); }); }); describe('New Block', () => { - let listener: Listener; - before (() => { - listener = new Listener(apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('newBlock', (done) => { - listener.newBlock().subscribe((res) => { - done(); + helper.listener.newBlock().subscribe(() => { + done(); }); - TransactionUtils.createAndAnnounce(account, account.address, transactionHttp, undefined, generationHash); + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + [], + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); + + helper.announce(transferTransaction.signWith(account, generationHash)); }); }); }); diff --git a/e2e/infrastructure/MetadataHttp.spec.ts b/e2e/infrastructure/MetadataHttp.spec.ts index d2dc25d1b9..e28d0f4405 100644 --- a/e2e/infrastructure/MetadataHttp.spec.ts +++ b/e2e/infrastructure/MetadataHttp.spec.ts @@ -14,14 +14,11 @@ * limitations under the License. */ -import {assert, expect} from 'chai'; -import { Convert } from '../../src/core/format/Convert'; -import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure'; +import { expect } from 'chai'; import { MetadataHttp } from '../../src/infrastructure/MetadataHttp'; import { Account } from '../../src/model/account/Account'; -import {Address} from '../../src/model/account/Address'; -import {PublicAccount} from '../../src/model/account/PublicAccount'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; +import { Address } from '../../src/model/account/Address'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; @@ -34,50 +31,38 @@ import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMet import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetadataTransaction'; import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction'; import { UInt64 } from '../../src/model/UInt64'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { MetadataRepository } from "../../src/infrastructure/MetadataRepository"; describe('MetadataHttp', () => { + + let helper = new IntegrationTestHelper(); let account: Account; - let account2: Account; - let account3: Account; - let multisigAccount: Account; - let cosignAccount1: Account; - let cosignAccount2: Account; - let cosignAccount3: Account; let accountAddress: Address; - let accountPublicKey: string; - let publicAccount: PublicAccount; - let metadataHttp: MetadataHttp; - let transactionHttp: TransactionHttp; let mosaicId: MosaicId; let namespaceId: NamespaceId; let generationHash: string; - let config; + let networkType: NetworkType; + let metadataRepository: MetadataRepository; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - account3 = Account.createFromPrivateKey(json.testAccount3.privateKey, NetworkType.MIJIN_TEST); - multisigAccount = Account.createFromPrivateKey(json.multisigAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount1 = Account.createFromPrivateKey(json.cosignatoryAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount2 = Account.createFromPrivateKey(json.cosignatory2Account.privateKey, NetworkType.MIJIN_TEST); - cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST); - accountAddress = Address.createFromRawAddress(json.testAccount.address); - accountPublicKey = json.testAccount.publicKey; - publicAccount = PublicAccount.createFromPublicKey(json.testAccount.publicKey, NetworkType.MIJIN_TEST); - generationHash = json.generationHash; - metadataHttp = new MetadataHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - done(); + before(() => { + return helper.start().then(() => { + account = helper.account; + accountAddress = helper.account.address; + generationHash = helper.generationHash; + networkType = helper.networkType; + metadataRepository = helper.repositoryFactory.createMetadataRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + /** * ========================= * Setup test data @@ -85,117 +70,66 @@ describe('MetadataHttp', () => { */ describe('MosaicDefinitionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const nonce = MosaicNonce.createRandom(); mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, mosaicId, - MosaicFlags.create( true, true, true), + MosaicFlags.create(true, true, true), 3, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Setup test NamespaceId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce NamespaceRegistrationTransaction', (done) => { + + it('Announce NamespaceRegistrationTransaction', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(9), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); namespaceId = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('AccountMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + it('aggregate', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), account.publicKey, UInt64.fromUint(5), 23, `Test account meta value`, - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [accountMetadataTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, + networkType, [], ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + it('aggregate', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), account.publicKey, @@ -203,37 +137,24 @@ describe('MetadataHttp', () => { mosaicId, 22, `Test mosaic meta value`, - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicMetadataTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, + networkType, [], + helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('NamespaceMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), account.publicKey, @@ -241,24 +162,18 @@ describe('MetadataHttp', () => { namespaceId, 25, `Test namespace meta value`, - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [namespaceMetadataTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, + networkType, [], + helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -270,142 +185,142 @@ describe('MetadataHttp', () => { describe('getAccountMetadata', () => { it('should return metadata given a NEM Address', (done) => { - metadataHttp.getAccountMetadata(accountAddress) - .subscribe((metadata) => { - expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetId).to.be.undefined; - expect(metadata[0].metadataEntry.value).to.be.equal('Test account meta value'); - expect(metadata[0].metadataEntry.value.length).to.be.equal(23); - done(); - }); + metadataRepository.getAccountMetadata(accountAddress) + .subscribe((metadata) => { + expect(metadata.length).to.be.greaterThan(0); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.targetId).to.be.undefined; + expect(metadata[0].metadataEntry.value).to.be.equal('Test account meta value'); + expect(metadata[0].metadataEntry.value.length).to.be.equal(23); + done(); + }); }); }); describe('getAccountMetadataByKey', () => { it('should return metadata given a NEM Address and metadata key', (done) => { - metadataHttp.getAccountMetadataByKey(accountAddress, UInt64.fromUint(5).toHex()) - .subscribe((metadata) => { - expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetId).to.be.undefined; - expect(metadata[0].metadataEntry.value).to.be.equal('Test account meta value'); - expect(metadata[0].metadataEntry.value.length).to.be.equal(23); - done(); - }); + metadataRepository.getAccountMetadataByKey(accountAddress, UInt64.fromUint(5).toHex()) + .subscribe((metadata) => { + expect(metadata.length).to.be.greaterThan(0); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.targetId).to.be.undefined; + expect(metadata[0].metadataEntry.value).to.be.equal('Test account meta value'); + expect(metadata[0].metadataEntry.value.length).to.be.equal(23); + done(); + }); }); }); describe('getAccountMetadataByKeyAndSender', () => { it('should return metadata given a NEM Address and metadata key and sender public key', (done) => { - metadataHttp.getAccountMetadataByKeyAndSender(accountAddress, UInt64.fromUint(5).toHex(), account.publicKey) - .subscribe((metadata) => { - expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect(metadata.metadataEntry.targetId).to.be.undefined; - expect(metadata.metadataEntry.value).to.be.equal('Test account meta value'); - expect(metadata.metadataEntry.value.length).to.be.equal(23); - done(); - }); + metadataRepository.getAccountMetadataByKeyAndSender(accountAddress, UInt64.fromUint(5).toHex(), account.publicKey) + .subscribe((metadata) => { + expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata.metadataEntry.targetId).to.be.undefined; + expect(metadata.metadataEntry.value).to.be.equal('Test account meta value'); + expect(metadata.metadataEntry.value.length).to.be.equal(23); + done(); + }); }); }); describe('getMosaicMetadata', () => { it('should return metadata given a mosaicId', (done) => { - metadataHttp.getMosaicMetadata(mosaicId) - .subscribe((metadata) => { - expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect((metadata[0].metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); - expect(metadata[0].metadataEntry.value).to.be.equal('Test mosaic meta value'); - expect(metadata[0].metadataEntry.value.length).to.be.equal(22); - done(); - }); + metadataRepository.getMosaicMetadata(mosaicId) + .subscribe((metadata) => { + expect(metadata.length).to.be.greaterThan(0); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect((metadata[0].metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); + expect(metadata[0].metadataEntry.value).to.be.equal('Test mosaic meta value'); + expect(metadata[0].metadataEntry.value.length).to.be.equal(22); + done(); + }); }); }); describe('getMosaicMetadataByKey', () => { it('should return metadata given a mosaicId and metadata key', (done) => { - metadataHttp.getMosaicMetadataByKey(mosaicId, UInt64.fromUint(5).toHex()) - .subscribe((metadata) => { - expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect((metadata[0].metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); - expect(metadata[0].metadataEntry.value).to.be.equal('Test mosaic meta value'); - expect(metadata[0].metadataEntry.value.length).to.be.equal(22); - done(); - }); + metadataRepository.getMosaicMetadataByKey(mosaicId, UInt64.fromUint(5).toHex()) + .subscribe((metadata) => { + expect(metadata.length).to.be.greaterThan(0); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect((metadata[0].metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); + expect(metadata[0].metadataEntry.value).to.be.equal('Test mosaic meta value'); + expect(metadata[0].metadataEntry.value.length).to.be.equal(22); + done(); + }); }); }); describe('getMosaicMetadataByKeyAndSender', () => { it('should return metadata given a mosaicId and metadata key and sender public key', (done) => { - metadataHttp.getMosaicMetadataByKeyAndSender(mosaicId, UInt64.fromUint(5).toHex(), account.publicKey) - .subscribe((metadata) => { - expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect((metadata.metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); - expect(metadata.metadataEntry.value).to.be.equal('Test mosaic meta value'); - expect(metadata.metadataEntry.value.length).to.be.equal(22); - done(); - }); + metadataRepository.getMosaicMetadataByKeyAndSender(mosaicId, UInt64.fromUint(5).toHex(), account.publicKey) + .subscribe((metadata) => { + expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect((metadata.metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); + expect(metadata.metadataEntry.value).to.be.equal('Test mosaic meta value'); + expect(metadata.metadataEntry.value.length).to.be.equal(22); + done(); + }); }); }); describe('getNamespaceMetadata', () => { it('should return metadata given a namespaceId', (done) => { - metadataHttp.getNamespaceMetadata(namespaceId) - .subscribe((metadata) => { - expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect((metadata[0].metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); - expect(metadata[0].metadataEntry.value).to.be.equal('Test namespace meta value'); - expect(metadata[0].metadataEntry.value.length).to.be.equal(25); - done(); - }); + metadataRepository.getNamespaceMetadata(namespaceId) + .subscribe((metadata) => { + expect(metadata.length).to.be.greaterThan(0); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect((metadata[0].metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); + expect(metadata[0].metadataEntry.value).to.be.equal('Test namespace meta value'); + expect(metadata[0].metadataEntry.value.length).to.be.equal(25); + done(); + }); }); }); describe('getNamespaceMetadataByKey', () => { it('should return metadata given a namespaceId and metadata key', (done) => { - metadataHttp.getNamespaceMetadataByKey(namespaceId, UInt64.fromUint(5).toHex()) - .subscribe((metadata) => { - expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect((metadata[0].metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); - expect(metadata[0].metadataEntry.value).to.be.equal('Test namespace meta value'); - expect(metadata[0].metadataEntry.value.length).to.be.equal(25); - done(); - }); + metadataRepository.getNamespaceMetadataByKey(namespaceId, UInt64.fromUint(5).toHex()) + .subscribe((metadata) => { + expect(metadata.length).to.be.greaterThan(0); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect((metadata[0].metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); + expect(metadata[0].metadataEntry.value).to.be.equal('Test namespace meta value'); + expect(metadata[0].metadataEntry.value.length).to.be.equal(25); + done(); + }); }); }); describe('getNamespaceMetadataByKeyAndSender', () => { it('should return metadata given a namespaceId and metadata key and sender public key', (done) => { - metadataHttp.getNamespaceMetadataByKeyAndSender(namespaceId, UInt64.fromUint(5).toHex(), account.publicKey) - .subscribe((metadata) => { - expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); - expect((metadata.metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); - expect(metadata.metadataEntry.value).to.be.equal('Test namespace meta value'); - expect(metadata.metadataEntry.value.length).to.be.equal(25); - done(); - }); + metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, UInt64.fromUint(5).toHex(), account.publicKey) + .subscribe((metadata) => { + expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); + expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect((metadata.metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); + expect(metadata.metadataEntry.value).to.be.equal('Test namespace meta value'); + expect(metadata.metadataEntry.value.length).to.be.equal(25); + done(); + }); }); }); }); diff --git a/e2e/infrastructure/MosaicHttp.spec.ts b/e2e/infrastructure/MosaicHttp.spec.ts index c6140a2678..3ca7a0d325 100644 --- a/e2e/infrastructure/MosaicHttp.spec.ts +++ b/e2e/infrastructure/MosaicHttp.spec.ts @@ -13,47 +13,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {assert, expect} from 'chai'; -import { Listener, NamespaceHttp, TransactionHttp } from '../../src/infrastructure/infrastructure'; -import {MosaicHttp} from '../../src/infrastructure/MosaicHttp'; +import { expect } from 'chai'; +import { MosaicRepository } from '../../src/infrastructure/MosaicRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; -import {MosaicId} from '../../src/model/mosaic/MosaicId'; +import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { AliasAction } from '../../src/model/namespace/AliasAction'; -import {NamespaceId} from '../../src/model/namespace/NamespaceId'; +import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { Deadline } from '../../src/model/transaction/Deadline'; import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction'; import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction'; import { UInt64 } from '../../src/model/UInt64'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { NamespaceRepository } from "../../src/infrastructure/NamespaceRepository"; describe('MosaicHttp', () => { + let mosaicId: MosaicId; - let mosaicHttp: MosaicHttp; + let mosaicRepository: MosaicRepository; let account: Account; - let config; let namespaceId: NamespaceId; - let transactionHttp: TransactionHttp; - let namespaceHttp: NamespaceHttp; + let namespaceRepository: NamespaceRepository; let generationHash: string; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - mosaicHttp = new MosaicHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - namespaceHttp = new NamespaceHttp(json.apiUrl); - generationHash = json.generationHash; - done(); + let helper = new IntegrationTestHelper(); + let networkType: NetworkType; + + before(() => { + return helper.start().then(() => { + account = helper.account; + generationHash = helper.generationHash; + networkType = helper.networkType; + namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); + mosaicRepository = helper.repositoryFactory.createMosaicRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); /** * ========================= @@ -61,15 +64,8 @@ describe('MosaicHttp', () => { * ========================= */ describe('Setup test MosaicId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MosaicDefinitionTransaction', (done) => { + + it('Announce MosaicDefinitionTransaction', () => { const nonce = MosaicNonce.createRandom(); mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( @@ -79,75 +75,45 @@ describe('MosaicHttp', () => { MosaicFlags.create(true, true, false), 3, UInt64.fromUint(0), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction) => { - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('Setup test NamespaceId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce NamespaceRegistrationTransaction', (done) => { + + it('Announce NamespaceRegistrationTransaction', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); namespaceId = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('Setup test MosaicAlias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MosaicAliasTransaction', (done) => { + it('Announce MosaicAliasTransaction', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Link, namespaceId, mosaicId, - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe((transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -158,33 +124,33 @@ describe('MosaicHttp', () => { */ describe('getMosaic', () => { it('should return mosaic given mosaicId', (done) => { - mosaicHttp.getMosaic(mosaicId) - .subscribe((mosaicInfo) => { - expect(mosaicInfo.height.lower).not.to.be.null; - expect(mosaicInfo.divisibility).to.be.equal(3); - expect(mosaicInfo.isSupplyMutable()).to.be.equal(true); - expect(mosaicInfo.isTransferable()).to.be.equal(true); - done(); - }); + mosaicRepository.getMosaic(mosaicId) + .subscribe((mosaicInfo) => { + expect(mosaicInfo.height.lower).not.to.be.null; + expect(mosaicInfo.divisibility).to.be.equal(3); + expect(mosaicInfo.isSupplyMutable()).to.be.equal(true); + expect(mosaicInfo.isTransferable()).to.be.equal(true); + done(); + }); }); }); describe('getMosaics', () => { it('should return mosaics given array of mosaicIds', (done) => { - mosaicHttp.getMosaics([mosaicId]) - .subscribe((mosaicInfos) => { - expect(mosaicInfos[0].height.lower).not.to.be.null; - expect(mosaicInfos[0].divisibility).to.be.equal(3); - expect(mosaicInfos[0].isSupplyMutable()).to.be.equal(true); - expect(mosaicInfos[0].isTransferable()).to.be.equal(true); - done(); - }); + mosaicRepository.getMosaics([mosaicId]) + .subscribe((mosaicInfos) => { + expect(mosaicInfos[0].height.lower).not.to.be.null; + expect(mosaicInfos[0].divisibility).to.be.equal(3); + expect(mosaicInfos[0].isSupplyMutable()).to.be.equal(true); + expect(mosaicInfos[0].isTransferable()).to.be.equal(true); + done(); + }); }); }); describe('getMosaicsNames', () => { it('should call getMosaicsNames successfully', (done) => { - namespaceHttp.getMosaicsNames([mosaicId]).subscribe((mosaicNames) => { + namespaceRepository.getMosaicsNames([mosaicId]).subscribe((mosaicNames) => { expect(mosaicNames.length).to.be.greaterThan(0); done(); }); @@ -193,7 +159,7 @@ describe('MosaicHttp', () => { describe('getMosaicsFromAccount', () => { it('should call getMosaicsFromAccount successfully', (done) => { - mosaicHttp.getMosaicsFromAccount(account.address).subscribe((mosaics) => { + mosaicRepository.getMosaicsFromAccount(account.address).subscribe((mosaics) => { expect(mosaics.length).to.be.greaterThan(0); expect(mosaics.find((m) => m.id.toHex() === mosaicId.toHex()) !== undefined).to.be.true; done(); @@ -203,7 +169,7 @@ describe('MosaicHttp', () => { describe('getMosaicsFromAccounts', () => { it('should call getMosaicsFromAccounts successfully', (done) => { - mosaicHttp.getMosaicsFromAccounts([account.address]).subscribe((mosaics) => { + mosaicRepository.getMosaicsFromAccounts([account.address]).subscribe((mosaics) => { expect(mosaics.length).to.be.greaterThan(0); expect(mosaics.find((m) => m.id.toHex() === mosaicId.toHex()) !== undefined).to.be.true; done(); @@ -217,34 +183,19 @@ describe('MosaicHttp', () => { * ========================= */ describe('Remove test MosaicAlias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MosaicAliasTransaction', (done) => { + + it('Announce MosaicAliasTransaction', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Unlink, namespaceId, mosaicId, - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe((transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); }); diff --git a/e2e/infrastructure/NamespaceHttp.spec.ts b/e2e/infrastructure/NamespaceHttp.spec.ts index 4704173af4..d2e36d6065 100644 --- a/e2e/infrastructure/NamespaceHttp.spec.ts +++ b/e2e/infrastructure/NamespaceHttp.spec.ts @@ -13,165 +13,137 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {deepEqual} from 'assert'; -import {assert, expect} from 'chai'; -import { Listener } from '../../src/infrastructure/infrastructure'; -import {NamespaceHttp} from '../../src/infrastructure/NamespaceHttp'; -import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { deepEqual } from 'assert'; +import { expect } from 'chai'; +import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { Account } from '../../src/model/account/Account'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; -import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction'; import { UInt64 } from '../../src/model/UInt64'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { Address } from "../../src/model/account/Address"; describe('NamespaceHttp', () => { const defaultNamespaceId = NetworkCurrencyMosaic.NAMESPACE_ID; let namespaceId: NamespaceId; - let namespaceHttp: NamespaceHttp; + let namespaceRepository: NamespaceRepository; let account: Account; - let config; - let transactionHttp: TransactionHttp; let generationHash: string; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - namespaceHttp = new NamespaceHttp(json.apiUrl, NetworkType.MIJIN_TEST); - transactionHttp = new TransactionHttp(json.apiUrl); - generationHash = json.generationHash; - done(); + let helper = new IntegrationTestHelper(); + + before(() => { + return helper.start().then(() => { + account = helper.account; + generationHash = helper.generationHash; + namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); }); }); + + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + describe('NamespaceRegistrationTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + helper.networkType, + helper.maxFee ); namespaceId = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('AddressAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, namespaceId, account.address, - NetworkType.MIJIN_TEST, + helper.networkType, + helper.maxFee ); const signedTransaction = addressAliasTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('getNamespace', () => { it('should return namespace data given namepsaceId', (done) => { - namespaceHttp.getNamespace(defaultNamespaceId) - .subscribe((namespace) => { - expect(namespace.startHeight.lower).to.be.equal(1); - expect(namespace.startHeight.higher).to.be.equal(0); - done(); - }); + namespaceRepository.getNamespace(defaultNamespaceId) + .subscribe((namespace) => { + expect(namespace.startHeight.lower).to.be.equal(1); + expect(namespace.startHeight.higher).to.be.equal(0); + done(); + }); }); }); describe('getNamespacesFromAccount', () => { it('should return namespace data given publicKeyNemesis', (done) => { - namespaceHttp.getNamespacesFromAccount(account.address) - .subscribe((namespaces) => { - deepEqual(namespaces[0].owner, account.publicAccount); - done(); - }); + namespaceRepository.getNamespacesFromAccount(account.address) + .subscribe((namespaces) => { + deepEqual(namespaces[0].owner, account.publicAccount); + done(); + }); }); }); describe('getNamespacesFromAccounts', () => { it('should return namespaces data given publicKeyNemesis', (done) => { - namespaceHttp.getNamespacesFromAccounts([account.address]) - .subscribe((namespaces) => { - deepEqual(namespaces[0].owner, account.publicAccount); - done(); - }); + namespaceRepository.getNamespacesFromAccounts([account.address]) + .subscribe((namespaces) => { + deepEqual(namespaces[0].owner, account.publicAccount); + done(); + }); }); }); describe('getNamespacesName', () => { it('should return namespace name given array of namespaceIds', (done) => { - namespaceHttp.getNamespacesName([defaultNamespaceId]) - .subscribe((namespaceNames) => { - expect(namespaceNames[0].name).to.be.equal('currency'); - done(); - }); + namespaceRepository.getNamespacesName([defaultNamespaceId]) + .subscribe((namespaceNames) => { + expect(namespaceNames[0].name).to.be.equal('currency'); + done(); + }); }); }); describe('getLinkedMosaicId', () => { it('should return mosaicId given currency namespaceId', (done) => { - namespaceHttp.getLinkedMosaicId(defaultNamespaceId) - .subscribe((mosaicId) => { - expect(mosaicId).to.not.be.null; - done(); - }); + namespaceRepository.getLinkedMosaicId(defaultNamespaceId) + .subscribe((mosaicId) => { + expect(mosaicId).to.not.be.null; + done(); + }); }); }); describe('getLinkedAddress', () => { it('should return address given namespaceId', (done) => { - namespaceHttp.getLinkedAddress(namespaceId) - .subscribe((address) => { - expect(address.plain()).to.be.equal(account.address.plain()); - done(); - }); + namespaceRepository.getLinkedAddress(namespaceId) + .subscribe((address: Address) => { + expect(address.plain()).to.be.equal(account.address.plain()); + done(); + }); }); }); }); diff --git a/e2e/infrastructure/NetworkHttp.spec.ts b/e2e/infrastructure/NetworkHttp.spec.ts index c93481d652..376d5317ee 100644 --- a/e2e/infrastructure/NetworkHttp.spec.ts +++ b/e2e/infrastructure/NetworkHttp.spec.ts @@ -13,42 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {expect} from 'chai'; -import {NetworkHttp} from '../../src/infrastructure/NetworkHttp'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; +import { expect } from 'chai'; +import { NetworkRepository } from '../../src/infrastructure/NetworkRepository'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; describe('NetworkHttp', () => { - let networkHttp: NetworkHttp; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - networkHttp = new NetworkHttp(json.apiUrl); - done(); + let networkRepository: NetworkRepository; + let helper = new IntegrationTestHelper(); + let networkType: NetworkType; + + before(() => { + return helper.start().then(() => { + networkRepository = helper.repositoryFactory.createNetworkRepository(); + networkType = helper.networkType; }); }); describe('getNetworkType', () => { it('should return network type', (done) => { - networkHttp.getNetworkType() - .subscribe((networkType) => { - expect(networkType).to.be.equal(NetworkType.MIJIN_TEST); - done(); - }); + networkRepository.getNetworkType() + .subscribe((sentNetworkType) => { + expect(sentNetworkType).to.be.equal(networkType); + done(); + }); }); }); describe('getNetworkName', () => { it('should return network name and description', (done) => { - networkHttp.getNetworkName() - .subscribe((networkName) => { - expect(networkName.name.toLowerCase()).to.be.equal('mijintest'); - expect(networkName.description.toLowerCase()).to.be.equal('catapult development network'); - done(); - }); + networkRepository.getNetworkName() + .subscribe((networkName) => { + expect(networkName.name.toLowerCase()).to.be.not.null; + expect(networkName.description.toLowerCase()).to.be.not.null; + done(); + }); }); }); }); diff --git a/e2e/infrastructure/NodeHttp.spec.ts b/e2e/infrastructure/NodeHttp.spec.ts index 1e02252c34..60b64dbcef 100644 --- a/e2e/infrastructure/NodeHttp.spec.ts +++ b/e2e/infrastructure/NodeHttp.spec.ts @@ -14,46 +14,44 @@ * limitations under the License. */ -import {expect} from 'chai'; -import {NodeHttp} from '../../src/infrastructure/NodeHttp'; +import { expect } from 'chai'; +import { NodeRepository } from '../../src/infrastructure/NodeRepository'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; + describe('NodeHttp', () => { - let nodeHttp: NodeHttp; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - nodeHttp = new NodeHttp(json.apiUrl); - done(); + let nodeRepository: NodeRepository; + let helper = new IntegrationTestHelper(); + + before(() => { + return helper.start().then(() => { + nodeRepository = helper.repositoryFactory.createNodeRepository(); }); }); describe('getNodeInfo', () => { it('should return node info', (done) => { - nodeHttp.getNodeInfo() - .subscribe((nodeInfo) => { - expect(nodeInfo.friendlyName).not.to.be.undefined; - expect(nodeInfo.host).not.to.be.undefined; - expect(nodeInfo.networkIdentifier).not.to.be.undefined; - expect(nodeInfo.port).not.to.be.undefined; - expect(nodeInfo.publicKey).not.to.be.undefined; - expect(nodeInfo.roles).not.to.be.undefined; - expect(nodeInfo.version).not.to.be.undefined; - done(); - }); + nodeRepository.getNodeInfo() + .subscribe((nodeInfo) => { + expect(nodeInfo.friendlyName).not.to.be.undefined; + expect(nodeInfo.host).not.to.be.undefined; + expect(nodeInfo.networkIdentifier).not.to.be.undefined; + expect(nodeInfo.port).not.to.be.undefined; + expect(nodeInfo.publicKey).not.to.be.undefined; + expect(nodeInfo.roles).not.to.be.undefined; + expect(nodeInfo.version).not.to.be.undefined; + done(); + }); }); }); describe('getNodeTime', () => { it('should return node time', (done) => { - nodeHttp.getNodeTime() - .subscribe((nodeTime) => { - expect(nodeTime.receiveTimeStamp).not.to.be.undefined; - expect(nodeTime.sendTimeStamp).not.to.be.undefined; - done(); - }); + nodeRepository.getNodeTime() + .subscribe((nodeTime) => { + expect(nodeTime.receiveTimeStamp).not.to.be.undefined; + expect(nodeTime.sendTimeStamp).not.to.be.undefined; + done(); + }); }); }); }); diff --git a/e2e/infrastructure/RestrictionHttp.spec.ts b/e2e/infrastructure/RestrictionHttp.spec.ts index e165b346fd..7110e8a5a2 100644 --- a/e2e/infrastructure/RestrictionHttp.spec.ts +++ b/e2e/infrastructure/RestrictionHttp.spec.ts @@ -14,17 +14,12 @@ * limitations under the License. */ -import {deepEqual} from 'assert'; -import {assert, expect} from 'chai'; -import {AccountHttp} from '../../src/infrastructure/AccountHttp'; -import { Listener } from '../../src/infrastructure/infrastructure'; -import { RestrictionAccountHttp } from '../../src/infrastructure/RestrictionAccountHttp'; -import { RestrictionMosaicHttp } from '../../src/infrastructure/RestrictionMosaicHttp'; -import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { deepEqual } from 'assert'; +import { expect } from 'chai'; +import { RestrictionMosaicRepository } from '../../src/infrastructure/RestrictionMosaicRepository'; import { Account } from '../../src/model/account/Account'; -import {Address} from '../../src/model/account/Address'; -import {PublicAccount} from '../../src/model/account/PublicAccount'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; +import { Address } from '../../src/model/account/Address'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; @@ -38,53 +33,39 @@ import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction'; import { UInt64 } from '../../src/model/UInt64'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { RestrictionAccountRepository } from "../../src/infrastructure/RestrictionAccountRespository"; describe('RestrictionHttp', () => { + let helper = new IntegrationTestHelper(); let account: Account; - let account2: Account; let account3: Account; - let multisigAccount: Account; - let cosignAccount1: Account; - let cosignAccount2: Account; - let cosignAccount3: Account; let accountAddress: Address; - let accountPublicKey: string; - let publicAccount: PublicAccount; - let accountHttp: AccountHttp; - let restrictionMosaicHttp: RestrictionMosaicHttp; - let restrictionAccountHttp: RestrictionAccountHttp; - let transactionHttp: TransactionHttp; + let restrictionMosaicRepository: RestrictionMosaicRepository; + let generationHash: string; + let networkType: NetworkType; let mosaicId: MosaicId; let referenceMosaicId: MosaicId; - let generationHash: string; - let config; + let restrictionAccountRepository: RestrictionAccountRepository; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - account3 = Account.createFromPrivateKey(json.testAccount3.privateKey, NetworkType.MIJIN_TEST); - multisigAccount = Account.createFromPrivateKey(json.multisigAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount1 = Account.createFromPrivateKey(json.cosignatoryAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount2 = Account.createFromPrivateKey(json.cosignatory2Account.privateKey, NetworkType.MIJIN_TEST); - cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST); - accountAddress = Address.createFromRawAddress(json.testAccount.address); - accountPublicKey = json.testAccount.publicKey; - publicAccount = PublicAccount.createFromPublicKey(json.testAccount.publicKey, NetworkType.MIJIN_TEST); - generationHash = json.generationHash; - accountHttp = new AccountHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - restrictionMosaicHttp = new RestrictionMosaicHttp(json.apiUrl); - restrictionAccountHttp = new RestrictionAccountHttp(json.apiUrl); - done(); + before(() => { + return helper.start().then(() => { + account = helper.account; + account3 = helper.account3; + accountAddress = helper.account.address; + generationHash = helper.generationHash; + networkType = helper.networkType; + restrictionMosaicRepository = helper.repositoryFactory.createRestrictionMosaicRepository(); + restrictionAccountRepository = helper.repositoryFactory.createRestrictionAccountRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); /** * ========================= @@ -92,115 +73,61 @@ describe('RestrictionHttp', () => { * ========================= */ describe('MosaicDefinitionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const nonce = MosaicNonce.createRandom(); mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, mosaicId, - MosaicFlags.create( true, true, true), + MosaicFlags.create(true, true, true), 3, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicDefinitionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const nonce = MosaicNonce.createRandom(); referenceMosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, referenceMosaicId, - MosaicFlags.create( true, true, true), + MosaicFlags.create(true, true, true), 3, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Setup Test AccountAddressRestriction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce AccountRestrictionTransaction', (done) => { + it('Announce AccountRestrictionTransaction', () => { const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.AllowIncomingAddress, [account3.address], [], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicGlobalRestrictionTransaction - Reference', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( Deadline.create(), referenceMosaicId, @@ -209,33 +136,16 @@ describe('RestrictionHttp', () => { MosaicRestrictionType.NONE, UInt64.fromUint(0), MosaicRestrictionType.GE, - NetworkType.MIJIN_TEST, + networkType, undefined, helper.maxFee, ); const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicGlobalRestrictionTransaction - with referenceMosaicId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('standalone', (done) => { + it('standalone', () => { const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( Deadline.create(), mosaicId, @@ -244,57 +154,33 @@ describe('RestrictionHttp', () => { MosaicRestrictionType.NONE, UInt64.fromUint(0), MosaicRestrictionType.GE, - NetworkType.MIJIN_TEST, + networkType, undefined, helper.maxFee, // TODO: // referenceMosaicId, ); const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicAddressRestrictionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create( Deadline.create(), mosaicId, UInt64.fromUint(60641), account3.address, UInt64.fromUint(2), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -306,87 +192,76 @@ describe('RestrictionHttp', () => { describe('getAccountRestrictions', () => { it('should call getAccountRestrictions successfully', (done) => { - setTimeout(() => { - restrictionAccountHttp.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => { - expect(accountRestrictions.length).to.be.greaterThan(0); - done(); - }); - }, 1000); + + restrictionAccountRepository.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => { + expect(accountRestrictions.length).to.be.greaterThan(0); + done(); + }); }); }); describe('getAccountRestrictionsFromAccounts', () => { it('should call getAccountRestrictionsFromAccounts successfully', (done) => { - setTimeout(() => { - restrictionAccountHttp.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => { - deepEqual(accountRestrictions[0]!.address, accountAddress); - done(); - }); - }, 1000); + restrictionAccountRepository.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => { + deepEqual(accountRestrictions[0]!.address, accountAddress); + done(); + }); }); }); describe('getMosaicAddressRestriction', () => { it('should call getMosaicAddressRestriction successfully', (done) => { - setTimeout(() => { - restrictionMosaicHttp.getMosaicAddressRestriction(mosaicId, account3.address).subscribe((mosaicRestriction) => { - deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex()); - deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.ADDRESS); - deepEqual(mosaicRestriction.targetAddress.plain(), account3.address.plain()); - deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString()); - done(); - }); - }, 1000); + restrictionMosaicRepository.getMosaicAddressRestriction(mosaicId, account3.address).subscribe((mosaicRestriction) => { + deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex()); + deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.ADDRESS); + deepEqual(mosaicRestriction.targetAddress.plain(), account3.address.plain()); + deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString()); + done(); + }); }); }); describe('getMosaicAddressRestrictions', () => { it('should call getMosaicAddressRestrictions successfully', (done) => { - setTimeout(() => { - restrictionMosaicHttp.getMosaicAddressRestrictions(mosaicId, [account3.address]).subscribe((mosaicRestriction) => { - deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex()); - deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.ADDRESS); - deepEqual(mosaicRestriction[0].targetAddress.plain(), account3.address.plain()); - deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString()); - done(); - }); - }, 1000); + restrictionMosaicRepository.getMosaicAddressRestrictions(mosaicId, [account3.address]).subscribe((mosaicRestriction) => { + deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex()); + deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.ADDRESS); + deepEqual(mosaicRestriction[0].targetAddress.plain(), account3.address.plain()); + deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString()); + done(); + }); }); }); describe('getMosaicGlobalRestriction', () => { it('should call getMosaicGlobalRestriction successfully', (done) => { - setTimeout(() => { - restrictionMosaicHttp.getMosaicGlobalRestriction(mosaicId).subscribe((mosaicRestriction) => { - deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex()); - deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.GLOBAL); - deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(), - new MosaicId(UInt64.fromUint(0).toHex()).toHex()); - deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType, - MosaicRestrictionType.GE); - deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(), - UInt64.fromUint(0).toString()); - done(); - }); - }, 1000); + restrictionMosaicRepository.getMosaicGlobalRestriction(mosaicId).subscribe((mosaicRestriction) => { + deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex()); + deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.GLOBAL); + deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(), + new MosaicId(UInt64.fromUint(0).toHex()).toHex()); + deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType, + MosaicRestrictionType.GE); + deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(), + UInt64.fromUint(0).toString()); + done(); + }); }); }); describe('getMosaicGlobalRestrictions', () => { it('should call getMosaicGlobalRestrictions successfully', (done) => { - setTimeout(() => { - restrictionMosaicHttp.getMosaicGlobalRestrictions([mosaicId]).subscribe((mosaicRestriction) => { - deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex()); - deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.GLOBAL); - deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(), - new MosaicId(UInt64.fromUint(0).toHex()).toHex()); - deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType, - MosaicRestrictionType.GE); - deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(), - UInt64.fromUint(0).toString()); - done(); - }); - }, 1000); + restrictionMosaicRepository.getMosaicGlobalRestrictions([mosaicId]).subscribe((mosaicRestriction) => { + deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex()); + deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.GLOBAL); + deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(), + new MosaicId(UInt64.fromUint(0).toHex()).toHex()); + deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType, + MosaicRestrictionType.GE); + deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(), + UInt64.fromUint(0).toString()); + done(); + }); }); }); @@ -396,33 +271,16 @@ describe('RestrictionHttp', () => { * ========================= */ describe('Remove test AccountRestriction - Address', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('Announce AccountRestrictionTransaction', (done) => { + it('Announce AccountRestrictionTransaction', () => { const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.AllowIncomingAddress, [], [account3.address], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); }); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index ed6f0af930..3c0b266764 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -13,26 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {assert, expect} from 'chai'; +import { expect } from 'chai'; import * as CryptoJS from 'crypto-js'; -import {ChronoUnit} from 'js-joda'; -import {keccak_256, sha3_256} from 'js-sha3'; -import {Crypto} from '../../src/core/crypto'; +import { ChronoUnit } from 'js-joda'; +import { keccak_256, sha3_256 } from 'js-sha3'; +import { Crypto } from '../../src/core/crypto'; import { Convert, Convert as convert } from '../../src/core/format'; import { TransactionMapping } from '../../src/core/utils/TransactionMapping'; -import {AccountHttp} from '../../src/infrastructure/AccountHttp'; -import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; -import {Listener} from '../../src/infrastructure/Listener'; -import {TransactionHttp} from '../../src/infrastructure/TransactionHttp'; -import {Account} from '../../src/model/account/Account'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; +import { AccountRepository } from '../../src/infrastructure/AccountRepository'; +import { Account } from '../../src/model/account/Account'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; -import {MosaicFlags} from '../../src/model/mosaic/MosaicFlags'; -import {MosaicId} from '../../src/model/mosaic/MosaicId'; -import {MosaicNonce} from '../../src/model/mosaic/MosaicNonce'; -import {MosaicSupplyChangeAction} from '../../src/model/mosaic/MosaicSupplyChangeAction'; -import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; +import { MosaicId } from '../../src/model/mosaic/MosaicId'; +import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; +import { MosaicSupplyChangeAction } from '../../src/model/mosaic/MosaicSupplyChangeAction'; +import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountRestrictionModificationAction } from '../../src/model/restriction/AccountRestrictionModificationAction'; @@ -46,81 +43,98 @@ import { AccountOperationRestrictionTransaction } from '../../src/model/transact import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; -import {AggregateTransaction} from '../../src/model/transaction/AggregateTransaction'; -import {CosignatureSignedTransaction} from '../../src/model/transaction/CosignatureSignedTransaction'; +import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; +import { CosignatureSignedTransaction } from '../../src/model/transaction/CosignatureSignedTransaction'; import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction'; -import {Deadline} from '../../src/model/transaction/Deadline'; +import { Deadline } from '../../src/model/transaction/Deadline'; import { HashLockTransaction } from '../../src/model/transaction/HashLockTransaction'; -import {HashType} from '../../src/model/transaction/HashType'; +import { HashType } from '../../src/model/transaction/HashType'; import { LinkAction } from '../../src/model/transaction/LinkAction'; -import {LockFundsTransaction} from '../../src/model/transaction/LockFundsTransaction'; +import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTransaction'; import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction/MosaicAddressRestrictionTransaction'; import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction'; -import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction'; +import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; -import {MosaicSupplyChangeTransaction} from '../../src/model/transaction/MosaicSupplyChangeTransaction'; +import { MosaicSupplyChangeTransaction } from '../../src/model/transaction/MosaicSupplyChangeTransaction'; import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetadataTransaction'; -import {NamespaceRegistrationTransaction} from '../../src/model/transaction/NamespaceRegistrationTransaction'; -import {SecretLockTransaction} from '../../src/model/transaction/SecretLockTransaction'; -import {SecretProofTransaction} from '../../src/model/transaction/SecretProofTransaction'; -import { SignedTransaction } from '../../src/model/transaction/SignedTransaction'; -import {Transaction} from '../../src/model/transaction/Transaction'; -import {TransactionType} from '../../src/model/transaction/TransactionType'; -import {TransferTransaction} from '../../src/model/transaction/TransferTransaction'; -import {UInt64} from '../../src/model/UInt64'; +import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction'; +import { SecretLockTransaction } from '../../src/model/transaction/SecretLockTransaction'; +import { SecretProofTransaction } from '../../src/model/transaction/SecretProofTransaction'; +import { TransactionType } from '../../src/model/transaction/TransactionType'; +import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; +import { UInt64 } from '../../src/model/UInt64'; +import { Address } from "../../src/model/account/Address"; +import { PublicAccount } from "../../src/model/account/PublicAccount"; +import { RepositoryFactory } from "../../src/infrastructure/RepositoryFactory"; +import { MultisigRepository } from "../../src/infrastructure/MultisigRepository"; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { TransactionRepository } from "../../src/infrastructure/TransactionRepository"; +import { NamespaceRepository } from "../../src/infrastructure/NamespaceRepository"; + describe('TransactionHttp', () => { let transactionHash; let transactionId; + let helper = new IntegrationTestHelper(); let account: Account; let account2: Account; let account3: Account; - let testAccountNoBalance: Account; - let harvestingAccount: Account; - let transactionHttp: TransactionHttp; let multisigAccount: Account; let cosignAccount1: Account; let cosignAccount2: Account; let cosignAccount3: Account; + let accountAddress: Address; + let accountPublicKey: string; + let publicAccount: PublicAccount; + let repositoryFactory: RepositoryFactory; + let accountRepository: AccountRepository; + let multisigRepository: MultisigRepository; + let namespaceRepository: NamespaceRepository; + let generationHash: string; + let networkType: NetworkType; let mosaicId: MosaicId; - let namespaceId: NamespaceId; let networkCurrencyMosaicId: MosaicId; - let accountHttp: AccountHttp; - let namespaceHttp: NamespaceHttp; - let config; + let namespaceId: NamespaceId; + let harvestingAccount: Account; + let transactionRepository: TransactionRepository; const secureRandom = require('secure-random'); const sha256 = require('js-sha256'); const ripemd160 = require('ripemd160'); - let generationHash: string; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - account3 = Account.createFromPrivateKey(json.testAccount3.privateKey, NetworkType.MIJIN_TEST); - testAccountNoBalance = Account.createFromPrivateKey(json.testAccountNoBalance.privateKey, NetworkType.MIJIN_TEST); - harvestingAccount = Account.createFromPrivateKey(json.harvestingAccount.privateKey, NetworkType.MIJIN_TEST); - multisigAccount = Account.createFromPrivateKey(json.multisigAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount1 = Account.createFromPrivateKey(json.cosignatoryAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount2 = Account.createFromPrivateKey(json.cosignatory2Account.privateKey, NetworkType.MIJIN_TEST); - cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST); - accountHttp = new AccountHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - namespaceHttp = new NamespaceHttp(json.apiUrl); - generationHash = json.generationHash; - done(); + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + account3 = helper.account3; + multisigAccount = helper.multisigAccount; + cosignAccount1 = helper.cosignAccount1; + cosignAccount2 = helper.cosignAccount2; + cosignAccount3 = helper.cosignAccount3; + accountAddress = helper.account.address; + harvestingAccount = helper.harvestingAccount; + accountPublicKey = helper.account.publicKey; + publicAccount = helper.account.publicAccount; + generationHash = helper.generationHash; + networkType = helper.networkType; + repositoryFactory = helper.repositoryFactory; + accountRepository = helper.repositoryFactory.createAccountRepository(); + multisigRepository = helper.repositoryFactory.createMultisigRepository(); + namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); + transactionRepository = helper.repositoryFactory.createTransactionRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + describe('Get network currency mosaic id', () => { it('get mosaicId', (done) => { - namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId) => { + namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId: MosaicId) => { networkCurrencyMosaicId = networkMosaicId; done(); }); @@ -128,28 +142,23 @@ describe('TransactionHttp', () => { }); describe('MosaicDefinitionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const nonce = MosaicNonce.createRandom(); mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, mosaicId, - MosaicFlags.create( true, true, true), + MosaicFlags.create(true, true, true), 3, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: MosaicDefinitionTransaction) => { + + return helper.announce(signedTransaction).then((transaction: MosaicDefinitionTransaction) => { expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; expect(transaction.nonce, 'Nonce').not.to.be.undefined; expect(transaction.divisibility, 'Divisibility').not.to.be.undefined; @@ -157,107 +166,68 @@ describe('TransactionHttp', () => { expect(transaction.flags.supplyMutable, 'SupplyMutable').not.to.be.undefined; expect(transaction.flags.transferable, 'Transferable').not.to.be.undefined; expect(transaction.flags.restrictable, 'Restrictable').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); describe('MosaicDefinitionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const nonce = MosaicNonce.createRandom(); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, MosaicId.createFromNonce(nonce, account.publicAccount), - MosaicFlags.create( true, true, true), + MosaicFlags.create(true, true, true), 3, UInt64.fromUint(0), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicDefinitionTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); + networkType, + [], helper.maxFee); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('AccountMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), account.publicKey, UInt64.fromUint(5), 10, Convert.uint8ToUtf8(new Uint8Array(10)), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [accountMetadataTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, + networkType, [], + helper.maxFee ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { transaction.innerTransactions.forEach((innerTx) => { expect((innerTx as AccountMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; expect((innerTx as AccountMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; expect((innerTx as AccountMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; expect((innerTx as AccountMetadataTransaction).value, 'Value').not.to.be.undefined; }); - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); describe('MosaicMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), account.publicKey, @@ -265,16 +235,16 @@ describe('TransactionHttp', () => { mosaicId, 10, Convert.uint8ToUtf8(new Uint8Array(10)), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicMetadataTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { transaction.innerTransactions.forEach((innerTx) => { expect((innerTx as MosaicMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; expect((innerTx as MosaicMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; @@ -282,94 +252,50 @@ describe('TransactionHttp', () => { expect((innerTx as MosaicMetadataTransaction).value, 'Value').not.to.be.undefined; expect((innerTx as MosaicMetadataTransaction).targetMosaicId, 'TargetMosaicId').not.to.be.undefined; }); - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); + }); - transactionHttp.announce(signedTransaction); }); }); describe('NamespaceRegistrationTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(10), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); namespaceId = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: NamespaceRegistrationTransaction) => { + return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); describe('NamespaceRegistrationTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), 'root-test-namespace-' + Math.floor(Math.random() * 10000), UInt64.fromUint(5), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [registerNamespaceTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); + networkType, + [], helper.maxFee); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('NamespaceMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + it('aggregate', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), account.publicKey, @@ -377,16 +303,16 @@ describe('TransactionHttp', () => { namespaceId, 10, Convert.uint8ToUtf8(new Uint8Array(10)), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [namespaceMetadataTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { transaction.innerTransactions.forEach((innerTx) => { expect((innerTx as NamespaceMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; expect((innerTx as NamespaceMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; @@ -394,28 +320,12 @@ describe('TransactionHttp', () => { expect((innerTx as NamespaceMetadataTransaction).value, 'Value').not.to.be.undefined; expect((innerTx as NamespaceMetadataTransaction).targetNamespaceId, 'TargetNamespaceId').not.to.be.undefined; }); - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); describe('MosaicGlobalRestrictionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('standalone', (done) => { + it('standalone', () => { const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( Deadline.create(), mosaicId, @@ -424,31 +334,14 @@ describe('TransactionHttp', () => { MosaicRestrictionType.NONE, UInt64.fromUint(0), MosaicRestrictionType.GE, - NetworkType.MIJIN_TEST, + networkType, undefined, helper.maxFee ); const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicGlobalRestrictionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + it('aggregate', () => { const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( Deadline.create(), mosaicId, @@ -457,278 +350,144 @@ describe('TransactionHttp', () => { MosaicRestrictionType.GE, UInt64.fromUint(1), MosaicRestrictionType.GE, - NetworkType.MIJIN_TEST, + networkType, undefined, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicGlobalRestrictionTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicAddressRestrictionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create( Deadline.create(), mosaicId, UInt64.fromUint(60641), account3.address, UInt64.fromUint(2), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('TransferTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('standalone', (done) => { + it('standalone', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, [NetworkCurrencyMosaic.createAbsolute(1)], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = transferTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe((transaction: TransferTransaction) => { - expect(transaction.message, 'Message').not.to.be.undefined; - expect(transaction.mosaics, 'Mosaic').not.to.be.undefined; - expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('TransferTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + it('aggregate', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, [NetworkCurrencyMosaic.createAbsolute(1)], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [transferTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('AccountRestrictionTransaction - Outgoing Address', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('standalone', (done) => { + it('standalone', () => { const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.BlockOutgoingAddress, [account3.address], [], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionTransaction) => { + return helper.announce(signedTransaction).then((transaction: AccountAddressRestrictionTransaction) => { expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); describe('AccountRestrictionTransaction - Outgoing Address', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.BlockOutgoingAddress, [], [account3.address], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [addressModification.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction) }); }); describe('AccountRestrictionTransaction - Incoming Address', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.BlockIncomingAddress, [account3.address], [], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = addressModification.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionTransaction) => { - expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; - expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; - expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction) }); }); describe('AccountRestrictionTransaction - Incoming Address', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + it('aggregate', () => { const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.BlockIncomingAddress, [], [account3.address], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [addressModification.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('AccountRestrictionTransaction - Mosaic', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { - const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( + + it('standalone', () => { + AccountRestrictionModification.createForMosaic( AccountRestrictionModificationAction.Add, mosaicId, ); @@ -737,139 +496,80 @@ describe('TransactionHttp', () => { AccountRestrictionFlags.BlockMosaic, [mosaicId], [], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionTransaction) => { + return helper.announce(signedTransaction).then((transaction: AccountMosaicRestrictionTransaction) => { expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - done(); }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); }); }); describe('AccountRestrictionTransaction - Mosaic', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.BlockMosaic, [], [mosaicId], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [addressModification.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('AccountRestrictionTransaction - Incoming Operation', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.BlockIncomingTransactionType, [TransactionType.LINK_ACCOUNT], [], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = addressModification.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionTransaction) => { + return helper.announce(signedTransaction).then((transaction: AccountOperationRestrictionTransaction) => { expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - done(); - }); - listener.status(account3.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); describe('AccountRestrictionTransaction - Incoming Operation', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.BlockIncomingTransactionType, [], [TransactionType.LINK_ACCOUNT], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [addressModification.toAggregate(account3.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account3.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction) }); }); describe('AccountRestrictionTransaction - Outgoing Operation', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { - const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + + it('standalone', () => { + AccountRestrictionModification.createForOperation( AccountRestrictionModificationAction.Add, TransactionType.LINK_ACCOUNT, ); @@ -878,519 +578,305 @@ describe('TransactionHttp', () => { AccountRestrictionFlags.BlockOutgoingTransactionType, [TransactionType.LINK_ACCOUNT], [], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = addressModification.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionTransaction) => { + return helper.announce(signedTransaction).then((transaction: AccountOperationRestrictionTransaction) => { expect(transaction.restrictionAdditions, 'RestrictionAdditions').not.to.be.undefined; expect(transaction.restrictionDeletions, 'RestrictionDeletions').not.to.be.undefined; expect(transaction.restrictionFlags, 'RestrictionFlags').not.to.be.undefined; - done(); - }); - listener.status(account3.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); + }); }); describe('AccountRestrictionTransaction - Outgoing Operation', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), AccountRestrictionFlags.BlockOutgoingTransactionType, [], [TransactionType.LINK_ACCOUNT], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [addressModification.toAggregate(account3.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account3.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); + }); }); describe('AccountLinkTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('standalone', (done) => { const accountLinkTransaction = AccountLinkTransaction.create( Deadline.create(), harvestingAccount.publicKey, LinkAction.Link, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountLinkTransaction) => { + return helper.announce(signedTransaction).then((transaction: AccountLinkTransaction) => { expect(transaction.remotePublicKey, 'RemotePublicKey').not.to.be.undefined; expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; done(); }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + }); }); describe('AccountLinkTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const accountLinkTransaction = AccountLinkTransaction.create( Deadline.create(), harvestingAccount.publicKey, LinkAction.Unlink, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [accountLinkTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('AddressAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, namespaceId, account.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = addressAliasTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AddressAliasTransaction) => { + return helper.announce(signedTransaction).then((transaction: AddressAliasTransaction) => { expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; expect(transaction.address, 'Address').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); + }); - transactionHttp.announce(signedTransaction); }); }); describe('Transfer Transaction using address alias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce TransferTransaction', (done) => { + + it('Announce TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), namespaceId, [NetworkCurrencyMosaic.createAbsolute(1)], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = transferTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: TransferTransaction) => { - expect(transaction.recipientAddress, 'AecipientAddress').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('AddressAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Unlink, namespaceId, account.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [addressAliasTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicSupplyChangeTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( Deadline.create(), mosaicId, MosaicSupplyChangeAction.Increase, UInt64.fromUint(10), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = mosaicSupplyChangeTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: MosaicSupplyChangeTransaction) => { + return helper.announce(signedTransaction).then((transaction: MosaicSupplyChangeTransaction) => { expect(transaction.delta, 'Delta').not.to.be.undefined; expect(transaction.action, 'Action').not.to.be.undefined; expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - done(); }); - listener.status(account3.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + }); }); describe('MosaicSupplyChangeTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( Deadline.create(), mosaicId, MosaicSupplyChangeAction.Increase, UInt64.fromUint(10), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicSupplyChangeTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); + networkType, + [], helper.maxFee); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account3.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); + }); describe('MosaicAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Link, namespaceId, mosaicId, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: MosaicAliasTransaction) => { + return helper.announce(signedTransaction).then((transaction: MosaicAliasTransaction) => { expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - done(); }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); }); }); describe('HashLockTransaction - MosaicAlias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(), [], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const hashLockTransaction = HashLockTransaction.create(Deadline.create(), new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), UInt64.fromUint(10000), signedTransaction, - NetworkType.MIJIN_TEST); - - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(hashLockTransaction.signWith(account, generationHash)); + networkType, helper.maxFee); + const hashLockSignedTransaction = hashLockTransaction.signWith(account, generationHash); + return helper.announce(hashLockSignedTransaction); }); }); describe('MosaicAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Unlink, namespaceId, mosaicId, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicAliasTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('LockFundsTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(), [], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), UInt64.fromUint(10000), signedTransaction, - NetworkType.MIJIN_TEST); + networkType, helper.maxFee); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(lockFundsTransaction.signWith(account, generationHash)); + return helper.announce(lockFundsTransaction.signWith(account, generationHash)); }); }); describe('LockFundsTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(), [], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), UInt64.fromUint(10), signedTransaction, - NetworkType.MIJIN_TEST); + networkType, helper.maxFee); const aggregateLockFundsTransaction = AggregateTransaction.createComplete(Deadline.create(), [lockFundsTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(aggregateLockFundsTransaction.signWith(account, generationHash)); + networkType, + [], helper.maxFee); + return helper.announce(aggregateLockFundsTransaction.signWith(account, generationHash)); }); }); describe('Aggregate Complete Transaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('should announce aggregated complete transaction', (done) => { + + it('should announce aggregated complete transaction', () => { const tx = TransferTransaction.create( Deadline.create(), account2.address, [], PlainMessage.create('Hi'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggTx = AggregateTransaction.createComplete( Deadline.create(), [ tx.toAggregate(account.publicAccount), ], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); - const signedTx = account.sign(aggTx, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTx); + const signedTransaction = account.sign(aggTx, generationHash); + return helper.announce(signedTransaction); }); }); describe('SecretLockTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyMosaic.createAbsolute(10), @@ -1398,35 +884,22 @@ describe('TransactionHttp', () => { HashType.Op_Sha3_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe((transaction: SecretLockTransaction) => { + const signedTransaction = secretLockTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: SecretLockTransaction) => { expect(transaction.mosaic, 'Mosaic').not.to.be.undefined; expect(transaction.duration, 'Duration').not.to.be.undefined; expect(transaction.hashType, 'HashType').not.to.be.undefined; expect(transaction.secret, 'Secret').not.to.be.undefined; expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); }); }); describe('HashType: Op_Sha3_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyMosaic.createAbsolute(10), @@ -1434,33 +907,18 @@ describe('TransactionHttp', () => { HashType.Op_Sha3_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateSecretLockTransaction = AggregateTransaction.createComplete(Deadline.create(), [secretLockTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + networkType, + [], helper.maxFee); + return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); }); }); describe('HashType: Keccak_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyMosaic.createAbsolute(10), @@ -1468,29 +926,14 @@ describe('TransactionHttp', () => { HashType.Op_Keccak_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); + return helper.announce(secretLockTransaction.signWith(account, generationHash)); }); }); describe('HashType: Keccak_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyMosaic.createAbsolute(10), @@ -1498,33 +941,18 @@ describe('TransactionHttp', () => { HashType.Op_Keccak_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateSecretLockTransaction = AggregateTransaction.createComplete(Deadline.create(), [secretLockTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + networkType, + [], helper.maxFee); + return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); }); }); describe('HashType: Op_Hash_160', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); const secretLockTransaction = SecretLockTransaction.create( @@ -1534,29 +962,14 @@ describe('TransactionHttp', () => { HashType.Op_Hash_160, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); + return helper.announce(secretLockTransaction.signWith(account, generationHash)); }); }); describe('HashType: Op_Hash_160', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const secretSeed = String.fromCharCode.apply(null, Crypto.randomBytes(20)); const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); const secretLockTransaction = SecretLockTransaction.create( @@ -1566,33 +979,18 @@ describe('TransactionHttp', () => { HashType.Op_Hash_160, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateSecretLockTransaction = AggregateTransaction.createComplete(Deadline.create(), [secretLockTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + networkType, + [], helper.maxFee); + return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); }); }); describe('HashType: Op_Hash_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyMosaic.createAbsolute(10), @@ -1600,29 +998,14 @@ describe('TransactionHttp', () => { HashType.Op_Hash_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); + return helper.announce(secretLockTransaction.signWith(account, generationHash)); }); }); describe('HashType: Op_Hash_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyMosaic.createAbsolute(10), @@ -1630,33 +1013,19 @@ describe('TransactionHttp', () => { HashType.Op_Hash_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateSecretLockTransaction = AggregateTransaction.createComplete(Deadline.create(), [secretLockTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); + networkType, + [], helper.maxFee); + + return helper.announce(aggregateSecretLockTransaction.signWith(account, generationHash)); }); }); describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const secretSeed = Crypto.randomBytes(20); const secret = sha3_256.create().update(secretSeed).hex(); const proof = convert.uint8ToHex(secretSeed); @@ -1668,46 +1037,35 @@ describe('TransactionHttp', () => { HashType.Op_Sha3_256, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe(() => { - listener.confirmed(account2.address).subscribe((transaction: SecretProofTransaction) => { - expect(transaction.secret, 'Secret').not.to.be.undefined; - expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; - expect(transaction.hashType, 'HashType').not.to.be.undefined; - expect(transaction.proof, 'Proof').not.to.be.undefined; - done(); - }); + + const signedSecretLockTx = secretLockTransaction.signWith(account, generationHash); + + return helper.announce(signedSecretLockTx).then(() => { const secretProofTransaction = SecretProofTransaction.create( Deadline.create(), HashType.Op_Sha3_256, secret, account2.address, proof, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTx = secretProofTransaction.signWith(account2, generationHash); - transactionHttp.announce(signedTx); - }); - listener.status(account2.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - const signedSecretLockTx = secretLockTransaction.signWith(account, generationHash); - transactionHttp.announce(signedSecretLockTx); + return helper.announce(signedTx).then((transaction: SecretProofTransaction) => { + expect(transaction.secret, 'Secret').not.to.be.undefined; + expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined; + expect(transaction.hashType, 'HashType').not.to.be.undefined; + expect(transaction.proof, 'Proof').not.to.be.undefined; + }); + }) + + }); }); describe('SecretProofTransaction - HashType: Op_Sha3_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const secretSeed = Crypto.randomBytes(20); const secret = sha3_256.create().update(secretSeed).hex(); const proof = convert.uint8ToHex(secretSeed); @@ -1718,44 +1076,29 @@ describe('TransactionHttp', () => { HashType.Op_Sha3_256, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe(() => { - listener.confirmed(account2.address).subscribe(() => { - done(); - }); + + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { const secretProofTransaction = SecretProofTransaction.create( Deadline.create(), HashType.Op_Sha3_256, secret, account2.address, proof, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateSecretProofTransaction = AggregateTransaction.createComplete(Deadline.create(), [secretProofTransaction.toAggregate(account2.publicAccount)], - NetworkType.MIJIN_TEST, - []); - transactionHttp.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); + networkType, [], helper.maxFee); + return helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); + }) + }); }); describe('SecretProofTransaction - HashType: Op_Keccak_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const secretSeed = Crypto.randomBytes(20); const secret = keccak_256.create().update(secretSeed).hex(); const proof = convert.uint8ToHex(secretSeed); @@ -1766,40 +1109,25 @@ describe('TransactionHttp', () => { HashType.Op_Keccak_256, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe(() => { - listener.confirmed(account2.address).subscribe(() => { - done(); - }); + + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { const secretProofTransaction = SecretProofTransaction.create( Deadline.create(), HashType.Op_Keccak_256, secret, account2.address, proof, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - transactionHttp.announce(secretProofTransaction.signWith(account2, generationHash)); + return helper.announce(secretProofTransaction.signWith(account2, generationHash)); }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); }); }); describe('SecretProofTransaction - HashType: Op_Keccak_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const secretSeed = Crypto.randomBytes(20); const secret = keccak_256.create().update(secretSeed).hex(); const proof = convert.uint8ToHex(secretSeed); @@ -1810,44 +1138,28 @@ describe('TransactionHttp', () => { HashType.Op_Keccak_256, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe(() => { - listener.confirmed(account2.address).subscribe(() => { - done(); - }); + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { const secretProofTransaction = SecretProofTransaction.create( Deadline.create(), HashType.Op_Keccak_256, secret, account2.address, proof, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateSecretProofTransaction = AggregateTransaction.createComplete(Deadline.create(), [secretProofTransaction.toAggregate(account2.publicAccount)], - NetworkType.MIJIN_TEST, - []); - transactionHttp.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); + networkType, + [], helper.maxFee); + return helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); }); }); describe('SecretProofTransaction - HashType: Op_Hash_160', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const randomBytes = secureRandom.randomBuffer(32); const secretSeed = randomBytes.toString('hex'); const hash = sha256(Buffer.from(secretSeed, 'hex')); @@ -1860,46 +1172,26 @@ describe('TransactionHttp', () => { HashType.Op_Hash_160, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe(() => { - listener.confirmed(account2.address).subscribe(() => { - done(); - }); - listener.status(account2.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); + + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => { const secretProofTransaction = SecretProofTransaction.create( Deadline.create(), HashType.Op_Hash_160, secret, account2.address, proof, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTx = secretProofTransaction.signWith(account2, generationHash); - transactionHttp.announce(signedTx); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); + return helper.announce(signedTx); }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); }); }); describe('SecretProofTransaction - HashType: Op_Hash_160', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const randomBytes = secureRandom.randomBuffer(32); const secretSeed = randomBytes.toString('hex'); const hash = sha256(Buffer.from(secretSeed, 'hex')); @@ -1912,49 +1204,28 @@ describe('TransactionHttp', () => { HashType.Op_Hash_160, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe(() => { - listener.confirmed(account2.address).subscribe(() => { - done(); - }); - listener.status(account2.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - HashType.Op_Hash_160, - secret, - account2.address, - proof, - NetworkType.MIJIN_TEST, - ); - const aggregateSecretProofTransaction = AggregateTransaction.createComplete(Deadline.create(), - [secretProofTransaction.toAggregate(account2.publicAccount)], - NetworkType.MIJIN_TEST, - []); - transactionHttp.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Hash_160, + secret, + account2.address, + proof, + networkType, helper.maxFee + ); + const aggregateSecretProofTransaction = AggregateTransaction.createComplete(Deadline.create(), + [secretProofTransaction.toAggregate(account2.publicAccount)], + networkType, + [], helper.maxFee); + + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then( + () => helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); }); }); describe('SecretProofTransaction - HashType: Op_Hash_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const randomBytes = secureRandom.randomBuffer(32); const secretSeed = randomBytes.toString('hex'); const hash = sha256(Buffer.from(secretSeed, 'hex')); @@ -1967,45 +1238,25 @@ describe('TransactionHttp', () => { HashType.Op_Hash_256, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe(() => { - listener.confirmed(account2.address).subscribe(() => { - done(); - }); - listener.status(account2.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - HashType.Op_Hash_256, - secret, - account2.address, - proof, - NetworkType.MIJIN_TEST, - ); - transactionHttp.announce(secretProofTransaction.signWith(account2, generationHash)); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); + + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Hash_256, + secret, + account2.address, + proof, + networkType, helper.maxFee + ); + + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => + helper.announce(secretProofTransaction.signWith(account2, generationHash))); }); }); describe('SecretProofTransaction - HashType: Op_Hash_256', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const randomBytes = secureRandom.randomBuffer(32); const secretSeed = randomBytes.toString('hex'); const hash = sha256(Buffer.from(secretSeed, 'hex')); @@ -2018,64 +1269,42 @@ describe('TransactionHttp', () => { HashType.Op_Hash_256, secret, account2.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); - listener.confirmed(account.address).subscribe(() => { - listener.confirmed(account2.address).subscribe(() => { - done(); - }); - listener.status(account2.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - const secretProofTransaction = SecretProofTransaction.create( - Deadline.create(), - HashType.Op_Hash_256, - secret, - account2.address, - proof, - NetworkType.MIJIN_TEST, - ); - const aggregateSecretProofTransaction = AggregateTransaction.createComplete(Deadline.create(), - [secretProofTransaction.toAggregate(account2.publicAccount)], - NetworkType.MIJIN_TEST, - []); - transactionHttp.announce(aggregateSecretProofTransaction.signWith(account2, generationHash)); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(secretLockTransaction.signWith(account, generationHash)); + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Hash_256, + secret, + account2.address, + proof, + networkType, helper.maxFee + ); + const aggregateSecretProofTransaction = AggregateTransaction.createComplete(Deadline.create(), + [secretProofTransaction.toAggregate(account2.publicAccount)], + networkType, + [], helper.maxFee); + return helper.announce(secretLockTransaction.signWith(account, generationHash)).then(() => + helper.announce(aggregateSecretProofTransaction.signWith(account2, generationHash))); }); }); describe('SignTransactionGivenSignatures', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce cosign signatures given', (done) => { + + it('Announce cosign signatures given', () => { /** * @see https://github.com/nemtech/nem2-sdk-typescript-javascript/issues/112 */ - // AliceAccount: account - // BobAccount: account + // AliceAccount: account + // BobAccount: account const sendAmount = NetworkCurrencyMosaic.createRelative(1000); const backAmount = NetworkCurrencyMosaic.createRelative(1); const aliceTransferTransaction = TransferTransaction.create(Deadline.create(), account2.address, [sendAmount], - PlainMessage.create('payout'), NetworkType.MIJIN_TEST); - const bobTransferTransaction = TransferTransaction.create(Deadline.create(), account.address, [backAmount], - PlainMessage.create('payout'), NetworkType.MIJIN_TEST); + PlainMessage.create('payout'), networkType, helper.maxFee); + const bobTransferTransaction = TransferTransaction.create(Deadline.create(), account.address, [backAmount], + PlainMessage.create('payout'), networkType, helper.maxFee); // 01. Alice creates the aggregated tx and sign it. Then payload send to Bob const aggregateTransaction = AggregateTransaction.createComplete( @@ -2084,8 +1313,8 @@ describe('TransactionHttp', () => { aliceTransferTransaction.toAggregate(account.publicAccount), bobTransferTransaction.toAggregate(account2.publicAccount), ], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const aliceSignedTransaction = aggregateTransaction.signWith(account, generationHash); @@ -2101,21 +1330,13 @@ describe('TransactionHttp', () => { const signedTransaction = recreatedTx.signTransactionGivenSignatures(account, cosignatureSignedTransactions, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('transactions', () => { it('should call transactions successfully', (done) => { - accountHttp.getAccountTransactions(account.publicAccount.address).subscribe((transactions) => { + accountRepository.getAccountTransactions(account.publicAccount.address).subscribe((transactions) => { const transaction = transactions[0]; transactionId = transaction.transactionInfo!.id; transactionHash = transaction.transactionInfo!.hash; @@ -2126,84 +1347,84 @@ describe('TransactionHttp', () => { describe('getTransaction', () => { it('should return transaction info given transactionHash', (done) => { - transactionHttp.getTransaction(transactionHash) - .subscribe((transaction) => { - expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); - expect(transaction.transactionInfo!.id).to.be.equal(transactionId); - done(); - }); + transactionRepository.getTransaction(transactionHash) + .subscribe((transaction) => { + expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); + expect(transaction.transactionInfo!.id).to.be.equal(transactionId); + done(); + }); }); it('should return transaction info given transactionId', (done) => { - transactionHttp.getTransaction(transactionId) - .subscribe((transaction) => { - expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); - expect(transaction.transactionInfo!.id).to.be.equal(transactionId); - done(); - }); + transactionRepository.getTransaction(transactionId) + .subscribe((transaction) => { + expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); + expect(transaction.transactionInfo!.id).to.be.equal(transactionId); + done(); + }); }); }); describe('getTransactions', () => { it('should return transaction info given array of transactionHash', (done) => { - transactionHttp.getTransactions([transactionHash]) - .subscribe((transactions) => { - expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); - expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); - done(); - }); + transactionRepository.getTransactions([transactionHash]) + .subscribe((transactions) => { + expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); + expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); + done(); + }); }); it('should return transaction info given array of transactionId', (done) => { - transactionHttp.getTransactions([transactionId]) - .subscribe((transactions) => { - expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); - expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); - done(); - }); + transactionRepository.getTransactions([transactionId]) + .subscribe((transactions) => { + expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); + expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); + done(); + }); }); }); describe('getTransactionStatus', () => { it('should return transaction status given transactionHash', (done) => { - transactionHttp.getTransactionStatus(transactionHash) - .subscribe((transactionStatus) => { - expect(transactionStatus.group).to.be.equal('confirmed'); - expect(transactionStatus.height!.lower).to.be.greaterThan(0); - expect(transactionStatus.height!.higher).to.be.equal(0); - done(); - }); + transactionRepository.getTransactionStatus(transactionHash) + .subscribe((transactionStatus) => { + expect(transactionStatus.group).to.be.equal('confirmed'); + expect(transactionStatus.height!.lower).to.be.greaterThan(0); + expect(transactionStatus.height!.higher).to.be.equal(0); + done(); + }); }); }); describe('getTransactionsStatuses', () => { it('should return transaction status given array of transactionHash', (done) => { - transactionHttp.getTransactionsStatuses([transactionHash]) - .subscribe((transactionStatuses) => { - expect(transactionStatuses[0].group).to.be.equal('confirmed'); - expect(transactionStatuses[0].height!.lower).to.be.greaterThan(0); - expect(transactionStatuses[0].height!.higher).to.be.equal(0); - done(); - }); + transactionRepository.getTransactionsStatuses([transactionHash]) + .subscribe((transactionStatuses) => { + expect(transactionStatuses[0].group).to.be.equal('confirmed'); + expect(transactionStatuses[0].height!.lower).to.be.greaterThan(0); + expect(transactionStatuses[0].height!.higher).to.be.equal(0); + done(); + }); }); }); describe('announce', () => { it('should return success when announce', (done) => { const transferTransaction = TransferTransaction.create( - Deadline.create(), - account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], - PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, - ); + Deadline.create(), + account2.address, + [NetworkCurrencyMosaic.createAbsolute(1)], + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); const signedTransaction = transferTransaction.signWith(account, generationHash); - transactionHttp.announce(signedTransaction) - .subscribe((transactionAnnounceResponse) => { - expect(transactionAnnounceResponse.message) - .to.be.equal('packet 9 was pushed to the network via /transaction'); - done(); - }); + transactionRepository.announce(signedTransaction) + .subscribe((transactionAnnounceResponse) => { + expect(transactionAnnounceResponse.message) + .to.be.equal('packet 9 was pushed to the network via /transaction'); + done(); + }); }); }); @@ -2214,43 +1435,43 @@ describe('TransactionHttp', () => { account2.address, [NetworkCurrencyMosaic.createRelative(1)], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(2, ChronoUnit.MINUTES), [transferTransaction.toAggregate(multisigAccount.publicAccount)], - NetworkType.MIJIN_TEST, - []); + networkType, + [], helper.maxFee); const signedTransaction = aggregateTransaction.signWith(cosignAccount1, generationHash); - transactionHttp.announceAggregateBonded(signedTransaction) - .subscribe((transactionAnnounceResponse) => { - expect(transactionAnnounceResponse.message) - .to.be.equal('packet 500 was pushed to the network via /transaction/partial'); - done(); - }); + transactionRepository.announceAggregateBonded(signedTransaction) + .subscribe((transactionAnnounceResponse) => { + expect(transactionAnnounceResponse.message) + .to.be.equal('packet 500 was pushed to the network via /transaction/partial'); + done(); + }); }); }); describe('announceAggregateBondedCosignature', () => { it('should return success when announceAggregateBondedCosignature', (done) => { const payload = new CosignatureSignedTransaction('', '', ''); - transactionHttp.announceAggregateBondedCosignature(payload) - .subscribe((transactionAnnounceResponse) => { - expect(transactionAnnounceResponse.message) - .to.be.equal('packet 501 was pushed to the network via /transaction/cosignature'); - done(); - }); + transactionRepository.announceAggregateBondedCosignature(payload) + .subscribe((transactionAnnounceResponse) => { + expect(transactionAnnounceResponse.message) + .to.be.equal('packet 501 was pushed to the network via /transaction/cosignature'); + done(); + }); }); }); describe('getTransactionEffectiveFee', () => { it('should return effective paid fee given transactionHash', (done) => { - transactionHttp.getTransactionEffectiveFee(transactionHash) - .subscribe((effectiveFee) => { - expect(effectiveFee).to.not.be.undefined; - expect(effectiveFee).to.be.equal(0); - done(); - }); + transactionRepository.getTransactionEffectiveFee(transactionHash) + .subscribe((effectiveFee) => { + expect(effectiveFee).to.not.be.undefined; + expect(effectiveFee).to.be.equal(0); + done(); + }); }); }); }); diff --git a/e2e/infrastructure/TransactionUtils.ts b/e2e/infrastructure/TransactionUtils.ts deleted file mode 100644 index ad70b22baa..0000000000 --- a/e2e/infrastructure/TransactionUtils.ts +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2018 NEM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import {ChronoUnit} from 'js-joda'; -import {TransactionHttp} from '../../src/infrastructure/TransactionHttp'; -import {Account} from '../../src/model/account/Account'; -import {Address} from '../../src/model/account/Address'; -import { PublicAccount } from '../../src/model/account/PublicAccount'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; -import {PlainMessage} from '../../src/model/message/PlainMessage'; -import { Mosaic } from '../../src/model/mosaic/Mosaic'; -import { MosaicId } from '../../src/model/mosaic/MosaicId'; -import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; -import {AggregateTransaction} from '../../src/model/transaction/AggregateTransaction'; -import { CosignatoryModificationAction } from '../../src/model/transaction/CosignatoryModificationAction'; -import {CosignatureTransaction} from '../../src/model/transaction/CosignatureTransaction'; -import {Deadline} from '../../src/model/transaction/Deadline'; -import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTransaction'; -import { MultisigAccountModificationTransaction } from '../../src/model/transaction/MultisigAccountModificationTransaction'; -import { MultisigCosignatoryModification } from '../../src/model/transaction/MultisigCosignatoryModification'; -import { SignedTransaction } from '../../src/model/transaction/SignedTransaction'; -import {TransferTransaction} from '../../src/model/transaction/TransferTransaction'; -import {UInt64} from '../../src/model/UInt64'; - -export class TransactionUtils { - - public static createAndAnnounce(signer: Account, - recipient: Address, - transactionHttp: TransactionHttp, - mosaic: Mosaic[] = [], - generationHash: string) { - const transferTransaction = TransferTransaction.create( - Deadline.create(), - recipient, - mosaic, - PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, - ); - const signedTransaction = signer.sign(transferTransaction, generationHash); - transactionHttp.announce(signedTransaction); - } - - public static announceAggregateBoundedTransaction(signedTransaction: SignedTransaction, - transactionHttp: TransactionHttp) { - transactionHttp.announceAggregateBonded(signedTransaction); - } - - public static createSignedAggregatedBondTransaction(aggregatedTo: Account, - signer: Account, - recipient: Address, - generationHash: string) { - - const transferTransaction = TransferTransaction.create( - Deadline.create(), - recipient, - [], - PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, - ); - - const aggregateTransaction = AggregateTransaction.createBonded( - Deadline.create(2, ChronoUnit.MINUTES), - [transferTransaction.toAggregate(aggregatedTo.publicAccount)], - NetworkType.MIJIN_TEST, - [], - ); - return signer.sign(aggregateTransaction, generationHash); - } - - public static createHashLockTransactionAndAnnounce(signedAggregatedTransaction: SignedTransaction, - signer: Account, - mosaicId: MosaicId, - transactionHttp: TransactionHttp, - generationHash: string) { - const lockFundsTransaction = LockFundsTransaction.create( - Deadline.create(), - new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), - UInt64.fromUint(1000), - signedAggregatedTransaction, - NetworkType.MIJIN_TEST, - ); - const signedLockFundsTransaction = signer.sign(lockFundsTransaction, generationHash); - transactionHttp.announce(signedLockFundsTransaction); - } - - public static cosignTransaction(transaction: AggregateTransaction, - account: Account, - transactionHttp: TransactionHttp) { - const cosignatureTransaction = CosignatureTransaction.create(transaction); - const cosignatureSignedTransaction = account.signCosignatureTransaction(cosignatureTransaction); - transactionHttp.announceAggregateBondedCosignature(cosignatureSignedTransaction); - } - - public static createMultisigAccountModificationTransaction( account: Account, - transactionHttp: TransactionHttp, - generationHash: string) { - const modifyMultisig = MultisigAccountModificationTransaction.create( - Deadline.create(), - 2, - 1, - [PublicAccount.createFromPublicKey(account.publicKey, NetworkType.MIJIN_TEST)], - [], - NetworkType.MIJIN_TEST, - ); - const signedTransaction = account.sign(modifyMultisig, generationHash); - transactionHttp.announce(signedTransaction); - } -} diff --git a/e2e/infrastructure/UnresolvedMapping.spec.ts b/e2e/infrastructure/UnresolvedMapping.spec.ts index fe5bddabf2..bf8e54dd6d 100644 --- a/e2e/infrastructure/UnresolvedMapping.spec.ts +++ b/e2e/infrastructure/UnresolvedMapping.spec.ts @@ -13,79 +13,65 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {assert, expect} from 'chai'; +import { expect } from 'chai'; import { Convert } from '../../src/core/format'; -import {AccountHttp} from '../../src/infrastructure/AccountHttp'; -import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; -import {Listener} from '../../src/infrastructure/Listener'; -import {TransactionHttp} from '../../src/infrastructure/TransactionHttp'; -import {Account} from '../../src/model/account/Account'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; +import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { Account } from '../../src/model/account/Account'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import {MosaicFlags} from '../../src/model/mosaic/MosaicFlags'; -import {MosaicId} from '../../src/model/mosaic/MosaicId'; -import {MosaicNonce} from '../../src/model/mosaic/MosaicNonce'; -import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; +import { MosaicId } from '../../src/model/mosaic/MosaicId'; +import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; +import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; -import {AggregateTransaction} from '../../src/model/transaction/AggregateTransaction'; -import {Deadline} from '../../src/model/transaction/Deadline'; +import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; +import { Deadline } from '../../src/model/transaction/Deadline'; import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction/MosaicAddressRestrictionTransaction'; import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction'; -import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction'; +import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; -import {NamespaceRegistrationTransaction} from '../../src/model/transaction/NamespaceRegistrationTransaction'; -import {Transaction} from '../../src/model/transaction/Transaction'; -import {TransferTransaction} from '../../src/model/transaction/TransferTransaction'; -import {UInt64} from '../../src/model/UInt64'; +import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction'; +import { Transaction } from '../../src/model/transaction/Transaction'; +import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; +import { UInt64 } from '../../src/model/UInt64'; +import { IntegrationTestHelper } from "./IntegrationTestHelper"; +import { Address } from "../../src/model/account/Address"; +import { NamespaceRepository } from "../../src/infrastructure/NamespaceRepository"; + describe('TransactionHttp', () => { + let helper = new IntegrationTestHelper(); let account: Account; let account2: Account; - let account3: Account; - let testAccountNoBalance: Account; - let harvestingAccount: Account; - let transactionHttp: TransactionHttp; - let multisigAccount: Account; - let cosignAccount1: Account; - let cosignAccount2: Account; - let cosignAccount3: Account; + let namespaceRepository: NamespaceRepository; + let generationHash: string; + let networkType: NetworkType; let mosaicId: MosaicId; + let networkCurrencyMosaicId: MosaicId; let namespaceIdAddress: NamespaceId; let namespaceIdMosaic: NamespaceId; - let networkCurrencyMosaicId: MosaicId; - let accountHttp: AccountHttp; - let namespaceHttp: NamespaceHttp; - let config; - let generationHash: string; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - account3 = Account.createFromPrivateKey(json.testAccount3.privateKey, NetworkType.MIJIN_TEST); - testAccountNoBalance = Account.createFromPrivateKey(json.testAccountNoBalance.privateKey, NetworkType.MIJIN_TEST); - harvestingAccount = Account.createFromPrivateKey(json.harvestingAccount.privateKey, NetworkType.MIJIN_TEST); - multisigAccount = Account.createFromPrivateKey(json.multisigAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount1 = Account.createFromPrivateKey(json.cosignatoryAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount2 = Account.createFromPrivateKey(json.cosignatory2Account.privateKey, NetworkType.MIJIN_TEST); - cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST); - accountHttp = new AccountHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - namespaceHttp = new NamespaceHttp(json.apiUrl); - generationHash = json.generationHash; - done(); + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + generationHash = helper.generationHash; + networkType = helper.networkType; + namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + /** * ========================= * Setup test data @@ -93,7 +79,7 @@ describe('TransactionHttp', () => { */ describe('Get network currency mosaic id', () => { it('get mosaicId', (done) => { - namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId) => { + namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId: MosaicId) => { networkCurrencyMosaicId = networkMosaicId; done(); }); @@ -101,162 +87,88 @@ describe('TransactionHttp', () => { }); describe('MosaicDefinitionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const nonce = MosaicNonce.createRandom(); mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, mosaicId, - MosaicFlags.create( true, true, true), + MosaicFlags.create(true, true, true), 3, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('NamespaceRegistrationTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(50), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); namespaceIdMosaic = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('NamespaceRegistrationTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(50), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); namespaceIdAddress = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('AddressAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, namespaceIdAddress, account.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = addressAliasTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Link, namespaceIdMosaic, mosaicId, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -267,15 +179,8 @@ describe('TransactionHttp', () => { */ describe('MosaicMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), account.publicKey, @@ -283,41 +188,27 @@ describe('TransactionHttp', () => { namespaceIdMosaic, 10, Convert.uint8ToUtf8(new Uint8Array(10)), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicMetadataTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, [], helper.maxFee, ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + + return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { transaction.innerTransactions.forEach((innerTx) => { expect((innerTx as MosaicMetadataTransaction).targetMosaicId instanceof NamespaceId).to.be.true; }); - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); + }); - transactionHttp.announce(signedTransaction); }); }); describe('MosaicGlobalRestrictionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( Deadline.create(), namespaceIdMosaic, @@ -326,93 +217,59 @@ describe('TransactionHttp', () => { MosaicRestrictionType.NONE, UInt64.fromUint(0), MosaicRestrictionType.GE, - NetworkType.MIJIN_TEST, + networkType, undefined, helper.maxFee, ); const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { + return helper.announce(signedTransaction).then((transaction: Transaction) => { expect((transaction as MosaicGlobalRestrictionTransaction).mosaicId instanceof NamespaceId).to.be.true; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); + }); - transactionHttp.announce(signedTransaction); }); }); describe('MosaicAddressRestrictionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create( Deadline.create(), namespaceIdMosaic, UInt64.fromUint(60641), namespaceIdAddress, UInt64.fromUint(2), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee, ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + + return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { transaction.innerTransactions.forEach((innerTx) => { expect((innerTx as MosaicAddressRestrictionTransaction).mosaicId instanceof NamespaceId).to.be.true; expect((innerTx as MosaicAddressRestrictionTransaction).targetAddress instanceof NamespaceId).to.be.true; }); - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); describe('TransferTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, [NetworkCurrencyMosaic.createAbsolute(1)], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = transferTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: TransferTransaction) => { + return helper.announce(signedTransaction).then((transaction: TransferTransaction) => { expect(transaction.mosaics[0].id instanceof NamespaceId).to.be.true; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); @@ -423,72 +280,44 @@ describe('TransactionHttp', () => { */ describe('AddressAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Unlink, namespaceIdAddress, account.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = addressAliasTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AddressAliasTransaction) => { + + return helper.announce(signedTransaction).then((transaction: AddressAliasTransaction) => { expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; expect(transaction.address, 'Address').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); + }); - transactionHttp.announce(signedTransaction); }); }); describe('MosaicAliasTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Unlink, namespaceIdMosaic, mosaicId, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee, ); const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: MosaicAliasTransaction) => { + return helper.announce(signedTransaction).then((transaction: MosaicAliasTransaction) => { expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); }); - transactionHttp.announce(signedTransaction); }); }); }); diff --git a/e2e/service/MetadataTransactionService.spec.ts b/e2e/service/MetadataTransactionService.spec.ts index 968b38f763..df66835650 100644 --- a/e2e/service/MetadataTransactionService.spec.ts +++ b/e2e/service/MetadataTransactionService.spec.ts @@ -1,8 +1,5 @@ import { assert, expect } from 'chai'; -import { Convert } from '../../src/core/format/Convert'; -import { Listener } from '../../src/infrastructure/Listener'; -import { MetadataHttp } from '../../src/infrastructure/MetadataHttp'; -import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { MetadataRepository } from '../../src/infrastructure/MetadataRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MetadataType } from '../../src/model/metadata/MetadataType'; @@ -20,35 +17,40 @@ import { NamespaceRegistrationTransaction } from '../../src/model/transaction/Na import { TransactionType } from '../../src/model/transaction/TransactionType'; import { UInt64 } from '../../src/model/UInt64'; import { MetadataTransactionService } from '../../src/service/MetadataTransactionService'; +import { IntegrationTestHelper } from "../infrastructure/IntegrationTestHelper"; describe('MetadataTransactionService', () => { const deadline = Deadline.create(); const key = UInt64.fromUint(123); const newValue = 'new test value'; + + let helper = new IntegrationTestHelper(); + let networkType: NetworkType; + let targetAccount: Account; - let metadataHttp: MetadataHttp; - let transactionHttp: TransactionHttp; + let metadataRepository: MetadataRepository; let mosaicId: MosaicId; let namespaceId: NamespaceId; - let config; let generationHash: string; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - targetAccount = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - generationHash = json.generationHash; - metadataHttp = new MetadataHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - done(); + + before(() => { + return helper.start().then(() => { + targetAccount = helper.account; + generationHash = helper.generationHash; + networkType = helper.networkType; + metadataRepository = helper.repositoryFactory.createMetadataRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + /** * ========================= * Setup test data @@ -56,78 +58,44 @@ describe('MetadataTransactionService', () => { */ describe('MosaicDefinitionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const nonce = MosaicNonce.createRandom(); mosaicId = MosaicId.createFromNonce(nonce, targetAccount.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, mosaicId, - MosaicFlags.create( true, true, true), + MosaicFlags.create(true, true, true), 3, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = mosaicDefinitionTransaction.signWith(targetAccount, generationHash); - listener.confirmed(targetAccount.address).subscribe(() => { - done(); - }); - listener.status(targetAccount.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Setup test NamespaceId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce NamespaceRegistrationTransaction', (done) => { + + it('Announce NamespaceRegistrationTransaction', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(9), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); namespaceId = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(targetAccount, generationHash); - listener.confirmed(targetAccount.address).subscribe(() => { - done(); - }); - listener.status(targetAccount.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('MosaicMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), targetAccount.publicKey, @@ -135,36 +103,25 @@ describe('MetadataTransactionService', () => { mosaicId, newValue.length, newValue, - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicMetadataTransaction.toAggregate(targetAccount.publicAccount)], - NetworkType.MIJIN_TEST, + networkType, [], + helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - listener.confirmed(targetAccount.address).subscribe(() => { - done(); - }); - listener.status(targetAccount.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('NamespaceMetadataTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), targetAccount.publicKey, @@ -172,23 +129,17 @@ describe('MetadataTransactionService', () => { namespaceId, newValue.length, newValue, - NetworkType.MIJIN_TEST, + networkType, ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [namespaceMetadataTransaction.toAggregate(targetAccount.publicAccount)], - NetworkType.MIJIN_TEST, + networkType, [], + helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - listener.confirmed(targetAccount.address).subscribe(() => { - done(); - }); - listener.status(targetAccount.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -199,189 +150,167 @@ describe('MetadataTransactionService', () => { */ describe('Test new services', () => { it('should create AccountMetadataTransaction - no current metadata', (done) => { - const metaDataService = new MetadataTransactionService(metadataHttp); + const metaDataService = new MetadataTransactionService(metadataRepository); return metaDataService.createMetadataTransaction( - deadline, - NetworkType.MIJIN_TEST, - MetadataType.Account, - targetAccount.publicAccount, - key, - newValue, - targetAccount.publicAccount, - ).subscribe((transaction: AccountMetadataTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA_TRANSACTION); - expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); - expect(transaction.value).to.be.equal(newValue); - expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); - done(); + deadline, + networkType, + MetadataType.Account, + targetAccount.publicAccount, + key, + newValue, + targetAccount.publicAccount, + ).subscribe((transaction: AccountMetadataTransaction) => { + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA_TRANSACTION); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); + expect(transaction.value).to.be.equal(newValue); + expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); + done(); }); }); it('should create MosaicMetadataTransaction', (done) => { - const metaDataService = new MetadataTransactionService(metadataHttp); + const metaDataService = new MetadataTransactionService(metadataRepository); return metaDataService.createMetadataTransaction( - deadline, - NetworkType.MIJIN_TEST, - MetadataType.Mosaic, - targetAccount.publicAccount, - key, - newValue + 'delta', - targetAccount.publicAccount, - mosaicId, - ).subscribe((transaction: MosaicMetadataTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA_TRANSACTION); - expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); - expect(transaction.valueSizeDelta).to.be.equal(5); - expect(transaction.value).to.be.equal(newValue + 'delta'); - expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); - expect(transaction.targetMosaicId.toHex()).to.be.equal(mosaicId.toHex()); - done(); + deadline, + networkType, + MetadataType.Mosaic, + targetAccount.publicAccount, + key, + newValue + 'delta', + targetAccount.publicAccount, + mosaicId, + ).subscribe((transaction: MosaicMetadataTransaction) => { + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA_TRANSACTION); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); + expect(transaction.valueSizeDelta).to.be.equal(5); + expect(transaction.value).to.be.equal(newValue + 'delta'); + expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); + expect(transaction.targetMosaicId.toHex()).to.be.equal(mosaicId.toHex()); + done(); }); }); it('should create NamespaceMetadataTransaction', (done) => { - const metaDataService = new MetadataTransactionService(metadataHttp); + const metaDataService = new MetadataTransactionService(metadataRepository); return metaDataService.createMetadataTransaction( - deadline, - NetworkType.MIJIN_TEST, - MetadataType.Namespace, - targetAccount.publicAccount, - key, - newValue + 'delta', - targetAccount.publicAccount, - namespaceId, - ).subscribe((transaction: NamespaceMetadataTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA_TRANSACTION); - expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); - expect(transaction.valueSizeDelta).to.be.equal(5); - expect(transaction.value).to.be.equal(newValue + 'delta'); - expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); - expect(transaction.targetNamespaceId.toHex()).to.be.equal(namespaceId.toHex()); - done(); + deadline, + networkType, + MetadataType.Namespace, + targetAccount.publicAccount, + key, + newValue + 'delta', + targetAccount.publicAccount, + namespaceId, + ).subscribe((transaction: NamespaceMetadataTransaction) => { + expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA_TRANSACTION); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); + expect(transaction.valueSizeDelta).to.be.equal(5); + expect(transaction.value).to.be.equal(newValue + 'delta'); + expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); + expect(transaction.targetNamespaceId.toHex()).to.be.equal(namespaceId.toHex()); + done(); }); }); }); describe('Announce transaction through service', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('should create MosaicMetadataTransaction and announce', (done) => { - const metaDataService = new MetadataTransactionService(metadataHttp); + const metaDataService = new MetadataTransactionService(metadataRepository); return metaDataService.createMetadataTransaction( - deadline, - NetworkType.MIJIN_TEST, - MetadataType.Mosaic, - targetAccount.publicAccount, - key, - newValue + 'delta', - targetAccount.publicAccount, - mosaicId, - ).subscribe((transaction: MosaicMetadataTransaction) => { - const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), - [transaction.toAggregate(targetAccount.publicAccount)], - NetworkType.MIJIN_TEST, - [], - ); - const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - listener.confirmed(targetAccount.address).subscribe(() => { - done(); - }); - listener.status(targetAccount.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + deadline, + networkType, + MetadataType.Mosaic, + targetAccount.publicAccount, + key, + newValue + 'delta', + targetAccount.publicAccount, + mosaicId, + helper.maxFee + ).subscribe((transaction: MosaicMetadataTransaction) => { + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [transaction.toAggregate(targetAccount.publicAccount)], + networkType, + [], + helper.maxFee + ); + const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); + helper.announce(signedTransaction).then(() => { + done(); + }, (error) => { + console.log('Error:', error); + assert(false); + done(); + }); }); }); }); describe('Announce transaction through service with delta size increase', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('should create MosaicMetadataTransaction and announce', (done) => { - const metaDataService = new MetadataTransactionService(metadataHttp); + const metaDataService = new MetadataTransactionService(metadataRepository); return metaDataService.createMetadataTransaction( - deadline, - NetworkType.MIJIN_TEST, - MetadataType.Mosaic, - targetAccount.publicAccount, - key, - newValue + 'delta' + 'extra delta', - targetAccount.publicAccount, - mosaicId, - ).subscribe((transaction: MosaicMetadataTransaction) => { - const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), - [transaction.toAggregate(targetAccount.publicAccount)], - NetworkType.MIJIN_TEST, - [], - ); - const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - listener.confirmed(targetAccount.address).subscribe(() => { - done(); - }); - listener.status(targetAccount.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + deadline, + networkType, + MetadataType.Mosaic, + targetAccount.publicAccount, + key, + newValue + 'delta' + 'extra delta', + targetAccount.publicAccount, + mosaicId, + helper.maxFee + ).subscribe((transaction: MosaicMetadataTransaction) => { + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [transaction.toAggregate(targetAccount.publicAccount)], + networkType, + [], + helper.maxFee + ); + const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); + helper.announce(signedTransaction).then(() => { + done(); + }, (error) => { + console.log('Error:', error); + assert(false); + done(); + }); }); }); }); describe('Announce transaction through service with delta size decrease', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('should create MosaicMetadataTransaction and announce', (done) => { - const metaDataService = new MetadataTransactionService(metadataHttp); + const metaDataService = new MetadataTransactionService(metadataRepository); return metaDataService.createMetadataTransaction( - deadline, - NetworkType.MIJIN_TEST, - MetadataType.Mosaic, - targetAccount.publicAccount, - key, - newValue, - targetAccount.publicAccount, - mosaicId, - ).subscribe((transaction: MosaicMetadataTransaction) => { - const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), - [transaction.toAggregate(targetAccount.publicAccount)], - NetworkType.MIJIN_TEST, - [], - ); - const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - listener.confirmed(targetAccount.address).subscribe(() => { - done(); - }); - listener.status(targetAccount.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + deadline, + networkType, + MetadataType.Mosaic, + targetAccount.publicAccount, + key, + newValue, + targetAccount.publicAccount, + mosaicId, + ).subscribe((transaction: MosaicMetadataTransaction) => { + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [transaction.toAggregate(targetAccount.publicAccount)], + networkType, + [], + helper.maxFee + ); + const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); + helper.announce(signedTransaction).then(() => { + done(); + }, (error) => { + console.log('Error:', error); + assert(false); + done(); + }); }); }); }); diff --git a/e2e/service/MosaicRestrictionTransactionService.spec.ts b/e2e/service/MosaicRestrictionTransactionService.spec.ts index 7df4d59c53..482178aa9e 100644 --- a/e2e/service/MosaicRestrictionTransactionService.spec.ts +++ b/e2e/service/MosaicRestrictionTransactionService.spec.ts @@ -1,8 +1,6 @@ -import { assert, expect } from 'chai'; +import { expect } from 'chai'; import { KeyGenerator } from '../../src/core/format/KeyGenerator'; -import { Listener } from '../../src/infrastructure/Listener'; -import { RestrictionMosaicHttp } from '../../src/infrastructure/RestrictionMosaicHttp'; -import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { RestrictionMosaicRepository } from '../../src/infrastructure/RestrictionMosaicRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; @@ -17,35 +15,35 @@ import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/ import { TransactionType } from '../../src/model/transaction/TransactionType'; import { UInt64 } from '../../src/model/UInt64'; import { MosaicRestrictionTransactionService } from '../../src/service/MosaicRestrictionTransactionService'; +import { IntegrationTestHelper } from "../infrastructure/IntegrationTestHelper"; describe('MosaicRestrictionTransactionService', () => { const deadline = Deadline.create(); const key = KeyGenerator.generateUInt64Key('TestKey'); - let targetAccount: Account; let account: Account; - let restrictionHttp: RestrictionMosaicHttp; - let transactionHttp: TransactionHttp; + let restrictionRepository: RestrictionMosaicRepository; let mosaicId: MosaicId; - let config; let generationHash: string; + let helper = new IntegrationTestHelper(); + let networkType: NetworkType; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - targetAccount = Account.createFromPrivateKey(json.testAccount3.privateKey, NetworkType.MIJIN_TEST); - generationHash = json.generationHash; - restrictionHttp = new RestrictionMosaicHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); - done(); + before(() => { + return helper.start().then(() => { + account = helper.account; + generationHash = helper.generationHash; + networkType = helper.networkType; + restrictionRepository = helper.repositoryFactory.createRestrictionMosaicRepository(); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + /** * ========================= * Setup test data @@ -53,49 +51,27 @@ describe('MosaicRestrictionTransactionService', () => { */ describe('MosaicDefinitionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const nonce = MosaicNonce.createRandom(); mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, mosaicId, - MosaicFlags.create( true, true, true), + MosaicFlags.create(true, true, true), 3, UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('MosaicGlobalRestrictionTransaction - with referenceMosaicId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + it('standalone', () => { const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create( Deadline.create(), mosaicId, @@ -104,55 +80,34 @@ describe('MosaicRestrictionTransactionService', () => { MosaicRestrictionType.NONE, UInt64.fromUint(0), MosaicRestrictionType.GE, - NetworkType.MIJIN_TEST, + networkType, + undefined, + helper.maxFee ); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); - - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash) + return helper.announce(signedTransaction); }); }); describe('MosaicAddressRestrictionTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create( Deadline.create(), mosaicId, key, - targetAccount.address, + account.address, UInt64.fromUint(2), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -163,120 +118,97 @@ describe('MosaicRestrictionTransactionService', () => { */ describe('Test new services', () => { it('should create MosaicGlobalRestrictionTransaction', (done) => { - const service = new MosaicRestrictionTransactionService(restrictionHttp); + const service = new MosaicRestrictionTransactionService(restrictionRepository); return service.createMosaicGlobalRestrictionTransaction( - deadline, - NetworkType.MIJIN_TEST, - mosaicId, - key, - '1', - MosaicRestrictionType.GE, - ).subscribe((transaction: MosaicGlobalRestrictionTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.MOSAIC_GLOBAL_RESTRICTION); - expect(transaction.previousRestrictionValue.toString()).to.be.equal('0'); - expect(transaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.GE); - expect(transaction.newRestrictionValue.toString()).to.be.equal('1'); - expect(transaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); - done(); + deadline, + networkType, + mosaicId, + key, + '1', + MosaicRestrictionType.GE, undefined, helper.maxFee + ).subscribe((transaction: MosaicGlobalRestrictionTransaction) => { + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_GLOBAL_RESTRICTION); + expect(transaction.previousRestrictionValue.toString()).to.be.equal('0'); + expect(transaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.GE); + expect(transaction.newRestrictionValue.toString()).to.be.equal('1'); + expect(transaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); + expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); + done(); }); }); it('should create MosaicAddressRestrictionTransaction', (done) => { - const service = new MosaicRestrictionTransactionService(restrictionHttp); + const service = new MosaicRestrictionTransactionService(restrictionRepository); return service.createMosaicAddressRestrictionTransaction( - deadline, - NetworkType.MIJIN_TEST, - mosaicId, - key, - targetAccount.address, - '3', - ).subscribe((transaction: MosaicAddressRestrictionTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.MOSAIC_ADDRESS_RESTRICTION); - expect(transaction.previousRestrictionValue.toString()).to.be.equal('2'); - expect(transaction.newRestrictionValue.toString()).to.be.equal('3'); - expect(transaction.targetAddressToString()).to.be.equal(targetAccount.address.plain()); - expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); - done(); + deadline, + networkType, + mosaicId, + key, + account.address, + '3', + helper.maxFee + ).subscribe((transaction: MosaicAddressRestrictionTransaction) => { + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_ADDRESS_RESTRICTION); + expect(transaction.previousRestrictionValue.toString()).to.be.equal('2'); + expect(transaction.newRestrictionValue.toString()).to.be.equal('3'); + expect(transaction.targetAddressToString()).to.be.equal(account.address.plain()); + expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); + done(); }); }); }); describe('Announce MosaicGlobalRestriction through service', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('should create MosaicGlobalRestriction and announce', (done) => { - const service = new MosaicRestrictionTransactionService(restrictionHttp); - return service.createMosaicGlobalRestrictionTransaction( - deadline, - NetworkType.MIJIN_TEST, - mosaicId, - key, - '1', - MosaicRestrictionType.GE, + it('should create MosaicGlobalRestriction and announce', (done) => { + const service = new MosaicRestrictionTransactionService(restrictionRepository); + service.createMosaicGlobalRestrictionTransaction( + deadline, + networkType, + mosaicId, + key, + '1', + MosaicRestrictionType.GE, undefined, helper.maxFee ).subscribe((transaction: MosaicGlobalRestrictionTransaction) => { - const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), - [transaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [transaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + helper.announce(signedTransaction).then(() => { + done(); + }); }); }); }); describe('Announce MosaicAddressRestriction through service', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('should create MosaicAddressRestriction and announce', (done) => { - const service = new MosaicRestrictionTransactionService(restrictionHttp); + const service = new MosaicRestrictionTransactionService(restrictionRepository); return service.createMosaicAddressRestrictionTransaction( - deadline, - NetworkType.MIJIN_TEST, - mosaicId, - key, - targetAccount.address, - '3', + deadline, + networkType, + mosaicId, + key, + account.address, + '3', + helper.maxFee ).subscribe((transaction: MosaicAddressRestrictionTransaction) => { - const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), - [transaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - [], - ); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [transaction.toAggregate(account.publicAccount)], + networkType, + [], + helper.maxFee + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + helper.announce(signedTransaction).then(() => { + done(); + }); }); }); }); diff --git a/e2e/service/MosaicService.spec.ts b/e2e/service/MosaicService.spec.ts index 59fa9e718b..95036cfda8 100644 --- a/e2e/service/MosaicService.spec.ts +++ b/e2e/service/MosaicService.spec.ts @@ -14,35 +14,33 @@ * limitations under the License. */ -import { AccountHttp } from '../../src/infrastructure/AccountHttp'; -import { MosaicHttp } from '../../src/infrastructure/MosaicHttp'; +import { AccountRepository } from '../../src/infrastructure/AccountRepository'; +import { MosaicRepository } from '../../src/infrastructure/MosaicRepository'; import { Address } from '../../src/model/account/Address'; import { MosaicService } from '../../src/service/MosaicService'; +import { IntegrationTestHelper } from "../infrastructure/IntegrationTestHelper"; +import { NetworkType } from "../../src/model/blockchain/NetworkType"; describe('MosaicService', () => { let accountAddress: Address; - let accountHttp: AccountHttp; - let mosaicHttp: MosaicHttp; + let accountRepository: AccountRepository; + let mosaicRepository: MosaicRepository; + let generationHash: string; + let helper = new IntegrationTestHelper(); + let networkType: NetworkType; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - accountAddress = Address.createFromRawAddress(json.testAccount.address); - accountHttp = new AccountHttp(json.apiUrl); - mosaicHttp = new MosaicHttp(json.apiUrl); - done(); + before(() => { + return helper.start().then(() => { + accountAddress = helper.account.address; + generationHash = helper.generationHash; + networkType = helper.networkType; + accountRepository = helper.repositoryFactory.createAccountRepository(); + mosaicRepository = helper.repositoryFactory.createMosaicRepository(); }); }); it('should return the mosaic list skipping the expired mosaics', (done) => { - const mosaicService = new MosaicService(accountHttp, mosaicHttp); - - const address = accountAddress; - - return mosaicService.mosaicsAmountViewFromAddress(address).subscribe((amountViews) => { + const mosaicService = new MosaicService(accountRepository, mosaicRepository); + return mosaicService.mosaicsAmountViewFromAddress(accountAddress).subscribe((amountViews) => { const views = amountViews.map((v) => { return {mosaicId: v.fullName(), amount: v.relativeAmount()}; }); diff --git a/e2e/service/TransactionService.spec.ts b/e2e/service/TransactionService.spec.ts index 060d3dfe5d..5dfb643743 100644 --- a/e2e/service/TransactionService.spec.ts +++ b/e2e/service/TransactionService.spec.ts @@ -14,12 +14,9 @@ * limitations under the License. */ -import { assert } from 'chai'; -import { expect } from 'chai'; +import { assert, expect } from 'chai'; import { Convert } from '../../src/core/format/Convert'; -import { Listener } from '../../src/infrastructure/Listener'; -import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp'; -import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; @@ -44,45 +41,46 @@ import { SignedTransaction } from '../../src/model/transaction/SignedTransaction import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../src/model/UInt64'; import { TransactionService } from '../../src/service/TransactionService'; +import { IntegrationTestHelper } from "../infrastructure/IntegrationTestHelper"; describe('TransactionService', () => { - let account: Account; - let account2: Account; - let account3: Account; - let account4: Account; - let url: string; + let helper = new IntegrationTestHelper(); let generationHash: string; - let namespaceHttp: NamespaceHttp; let addressAlias: NamespaceId; let mosaicAlias: NamespaceId; let mosaicId: MosaicId; let newMosaicId: MosaicId; - let transactionHttp: TransactionHttp; - let config; let transactionHashes: string[]; let transactionHashesMultiple: string[]; - - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - account3 = Account.createFromPrivateKey(json.testAccount3.privateKey, NetworkType.MIJIN_TEST); - account4 = Account.createFromPrivateKey(json.cosignatory4Account.privateKey, NetworkType.MIJIN_TEST); - url = json.apiUrl; - generationHash = json.generationHash; - namespaceHttp = new NamespaceHttp(json.apiUrl); - transactionHttp = new TransactionHttp(json.apiUrl); + let account: Account; + let account2: Account; + let account3: Account; + let cosignAccount4: Account; + let networkType: NetworkType; + let transactionService: TransactionService; + let transactionRepository: TransactionRepository; + + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + account3 = helper.account3; + cosignAccount4 = helper.cosignAccount4; + generationHash = helper.generationHash; + networkType = helper.networkType; transactionHashes = []; transactionHashesMultiple = []; - done(); + transactionRepository = helper.repositoryFactory.createTransactionRepository(); + transactionService = new TransactionService(helper.repositoryFactory.createTransactionRepository(), helper.repositoryFactory.createReceiptRepository()); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); /** * ========================= @@ -90,111 +88,61 @@ describe('TransactionService', () => { * ========================= */ describe('Create address alias NamespaceId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce NamespaceRegistrationTransaction', (done) => { + + it('Announce NamespaceRegistrationTransaction', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(20), - NetworkType.MIJIN_TEST, + networkType, + helper.maxFee ); addressAlias = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); transactionHashes.push(signedTransaction.hash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Create mosaic alias NamespaceId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce NamespaceRegistrationTransaction', (done) => { + + it('Announce NamespaceRegistrationTransaction', () => { const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, UInt64.fromUint(50), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); mosaicAlias = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); transactionHashes.push(signedTransaction.hash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Setup test AddressAlias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce addressAliasTransaction', (done) => { + + it('Announce addressAliasTransaction', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, addressAlias, account.address, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = addressAliasTransaction.signWith(account, generationHash); transactionHashes.push(signedTransaction.hash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('Setup test MosaicId', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MosaicDefinitionTransaction', (done) => { + + it('Announce MosaicDefinitionTransaction', () => { const nonce = MosaicNonce.createRandom(); mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( @@ -204,90 +152,49 @@ describe('TransactionService', () => { MosaicFlags.create(true, true, false), 3, UInt64.fromUint(50), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); transactionHashes.push(signedTransaction.hash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('MosaicSupplyChangeTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { + + it('standalone', () => { const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( Deadline.create(), mosaicId, MosaicSupplyChangeAction.Increase, UInt64.fromUint(200000), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = mosaicSupplyChangeTransaction.signWith(account, generationHash); transactionHashes.push(signedTransaction.hash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Setup MosaicAlias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MosaicAliasTransaction', (done) => { + it('Announce MosaicAliasTransaction', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Link, mosaicAlias, mosaicId, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); transactionHashes.push(signedTransaction.hash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + + return helper.announce(signedTransaction); }); }); describe('Create Transfer with alias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - - it('Announce TransferTransaction', (done) => { + it('Announce TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), addressAlias, @@ -296,21 +203,13 @@ describe('TransactionService', () => { new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = transferTransaction.signWith(account, generationHash); transactionHashes.push(signedTransaction.hash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -321,26 +220,11 @@ describe('TransactionService', () => { */ describe('Create Aggreate TransferTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { + + it('aggregate', () => { const signedTransaction = buildAggregateTransaction().signWith(account, generationHash); transactionHashes.push(signedTransaction.hash); - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -351,16 +235,9 @@ describe('TransactionService', () => { */ describe('Transfer mosaic to account 3', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce TransferTransaction', (done) => { + + it('Announce TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account3.address, @@ -368,33 +245,16 @@ describe('TransactionService', () => { new Mosaic(mosaicAlias, UInt64.fromUint(200)), ], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = transferTransaction.signWith(account, generationHash); - transactionHashes.push(signedTransaction.hash); - - listener.confirmed(account.address).subscribe(() => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); describe('Create multiple transfers with alias', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('Announce TransferTransaction', (done) => { const transactions: SignedTransaction[] = []; @@ -406,19 +266,19 @@ describe('TransactionService', () => { new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); transactions.push(transaction1.signWith(account, generationHash)); // 2. Transfer C -> D const transaction2 = TransferTransaction.create( Deadline.create(), - account4.address, + cosignAccount4.address, [ new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); transactions.push(transaction2.signWith(account3, generationHash)); @@ -428,17 +288,17 @@ describe('TransactionService', () => { transactions.forEach((tx) => { transactionHashesMultiple.push(tx.hash); - transactionHttp.announce(tx); + transactionRepository.announce(tx); }); - listener.confirmed(account.address, lastSignedTx.hash).subscribe(() => { + helper.listener.confirmed(account.address, lastSignedTx.hash).subscribe(() => { done(); }); - listener.status(account.address).subscribe((error) => { + helper.listener.status(account.address).subscribe((error) => { console.log('Error:', error); assert(false); done(); }); - listener.status(account3.address).subscribe((error) => { + helper.listener.status(account3.address).subscribe((error) => { console.log('Error:', error); assert(false); done(); @@ -454,41 +314,40 @@ describe('TransactionService', () => { describe('should return resolved transaction', () => { it('call transaction service', (done) => { - const transactionService = new TransactionService(url); + transactionService.resolveAliases(transactionHashes).subscribe((transactions) => { - expect(transactions.length).to.be.equal(8); - transactions.map((tx) => { - if (tx instanceof TransferTransaction) { - expect((tx.recipientAddress as Address).plain()).to.be.equal(account.address.plain()); - expect(tx.mosaics.find((m) => m.id.toHex() === mosaicId.toHex())).not.to.equal(undefined); - } else if (tx instanceof AggregateTransaction) { - expect(tx.innerTransactions.length).to.be.equal(5); - // Assert Transfer - expect(((tx.innerTransactions[0] as TransferTransaction).recipientAddress as Address) + expect(transactions.length).to.be.equal(8); + transactions.map((tx) => { + if (tx instanceof TransferTransaction) { + expect((tx.recipientAddress as Address).plain()).to.be.equal(account.address.plain()); + expect(tx.mosaics.find((m) => m.id.toHex() === mosaicId.toHex())).not.to.equal(undefined); + } else if (tx instanceof AggregateTransaction) { + expect(tx.innerTransactions.length).to.be.equal(5); + // Assert Transfer + expect(((tx.innerTransactions[0] as TransferTransaction).recipientAddress as Address) .plain()).to.be.equal(account.address.plain()); - expect((tx.innerTransactions[0] as TransferTransaction).mosaics + expect((tx.innerTransactions[0] as TransferTransaction).mosaics .find((m) => m.id.toHex() === mosaicId.toHex())).not.to.equal(undefined); - // Assert MosaicMeta - expect((tx.innerTransactions[4] as MosaicMetadataTransaction) + // Assert MosaicMeta + expect((tx.innerTransactions[4] as MosaicMetadataTransaction) .targetMosaicId.toHex() === newMosaicId.toHex()).to.be.true; - } - }); - }, - done()); + } + }); + }, + done()); }); }); describe('Test resolve alias with multiple transaction in single block', () => { it('call transaction service', (done) => { - const transactionService = new TransactionService(url); transactionService.resolveAliases(transactionHashesMultiple).subscribe((tx) => { - expect(tx.length).to.be.equal(3); - expect((tx[0] as TransferTransaction).mosaics[0].id.toHex()).to.be.equal(mosaicId.toHex()); - expect((tx[1] as TransferTransaction).mosaics[0].id.toHex()).to.be.equal(mosaicId.toHex()); - expect(((tx[2] as AggregateTransaction).innerTransactions[4] as MosaicMetadataTransaction) + expect(tx.length).to.be.equal(3); + expect((tx[0] as TransferTransaction).mosaics[0].id.toHex()).to.be.equal(mosaicId.toHex()); + expect((tx[1] as TransferTransaction).mosaics[0].id.toHex()).to.be.equal(mosaicId.toHex()); + expect(((tx[2] as AggregateTransaction).innerTransactions[4] as MosaicMetadataTransaction) .targetMosaicId.toHex()).to.be.equal(newMosaicId.toHex()); - }, - done()); + }, + done()); }); }); @@ -501,7 +360,7 @@ describe('TransactionService', () => { new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); // Unlink MosaicAlias const mosaicAliasTransactionUnlink = MosaicAliasTransaction.create( @@ -509,7 +368,7 @@ describe('TransactionService', () => { AliasAction.Unlink, mosaicAlias, mosaicId, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); // Create a new Mosaic @@ -522,7 +381,7 @@ describe('TransactionService', () => { MosaicFlags.create(true, true, false), 3, UInt64.fromUint(0), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); // Link namespace with new MosaicId @@ -531,7 +390,7 @@ describe('TransactionService', () => { AliasAction.Link, mosaicAlias, newMosaicId, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); // Use new mosaicAlias in metadata @@ -542,7 +401,7 @@ describe('TransactionService', () => { mosaicAlias, 10, Convert.uint8ToUtf8(new Uint8Array(10)), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); return AggregateTransaction.createComplete(Deadline.create(), [ @@ -553,8 +412,8 @@ describe('TransactionService', () => { mosaicMetadataTransaction.toAggregate(account.publicAccount), ], - NetworkType.MIJIN_TEST, - [], + networkType, + [], helper.maxFee ); } diff --git a/e2e/service/TransactionService_AggregateBonded.spec.ts b/e2e/service/TransactionService_AggregateBonded.spec.ts index 780ccb8d49..d347b5e860 100644 --- a/e2e/service/TransactionService_AggregateBonded.spec.ts +++ b/e2e/service/TransactionService_AggregateBonded.spec.ts @@ -15,9 +15,7 @@ */ import { expect } from 'chai'; -import { Listener } from '../../src/infrastructure/Listener'; -import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp'; -import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; @@ -34,45 +32,65 @@ import { TransactionType } from '../../src/model/transaction/TransactionType'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../src/model/UInt64'; import { TransactionService } from '../../src/service/TransactionService'; -import { TransactionUtils } from '../infrastructure/TransactionUtils'; +import { IntegrationTestHelper } from "../infrastructure/IntegrationTestHelper"; +import { SignedTransaction } from "../../src/model/transaction/SignedTransaction"; +import { ChronoUnit } from "js-joda"; describe('TransactionService', () => { + + let helper = new IntegrationTestHelper(); let account: Account; let account2: Account; let multisigAccount: Account; let cosignAccount1: Account; let cosignAccount2: Account; let cosignAccount3: Account; - let networkCurrencyMosaicId: MosaicId; - let url: string; + let namespaceRepository: NamespaceRepository; let generationHash: string; - let transactionHttp: TransactionHttp; + let networkType: NetworkType; let transactionService: TransactionService; - let namespaceHttp: NamespaceHttp; - let config; + let networkCurrencyMosaicId: MosaicId; - before((done) => { - const path = require('path'); - require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => { - if (err) { - throw err; - } - const json = JSON.parse(data); - config = json; - account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST); - account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST); - multisigAccount = Account.createFromPrivateKey(json.multisigAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount1 = Account.createFromPrivateKey(json.cosignatoryAccount.privateKey, NetworkType.MIJIN_TEST); - cosignAccount2 = Account.createFromPrivateKey(json.cosignatory2Account.privateKey, NetworkType.MIJIN_TEST); - cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST); - url = json.apiUrl; - generationHash = json.generationHash; - transactionHttp = new TransactionHttp(url); - namespaceHttp = new NamespaceHttp(url); - transactionService = new TransactionService(url); - done(); + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + multisigAccount = helper.multisigAccount; + cosignAccount1 = helper.cosignAccount1; + cosignAccount2 = helper.cosignAccount2; + cosignAccount3 = helper.cosignAccount3; + generationHash = helper.generationHash; + networkType = helper.networkType; + namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); + transactionService = new TransactionService(helper.repositoryFactory.createTransactionRepository(), helper.repositoryFactory.createReceiptRepository()); }); }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + + + let createSignedAggregatedBondTransaction = (aggregatedTo: Account, + signer: Account, + recipient: Address): SignedTransaction => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + recipient, [], + PlainMessage.create('test-message'), + networkType, helper.maxFee + ); + + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(2, ChronoUnit.MINUTES), + [transferTransaction.toAggregate(aggregatedTo.publicAccount)], + networkType, [], helper.maxFee + ); + return signer.sign(aggregateTransaction, generationHash); + }; /** * ========================= @@ -81,7 +99,7 @@ describe('TransactionService', () => { */ describe('Get network currency mosaic id', () => { it('get mosaicId', (done) => { - namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId) => { + namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId: MosaicId) => { networkCurrencyMosaicId = networkMosaicId; done(); }); @@ -89,15 +107,8 @@ describe('TransactionService', () => { }); describe('Setup test multisig account', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MultisigAccountModificationTransaction', (done) => { + + it('Announce MultisigAccountModificationTransaction', () => { const modifyMultisigAccountTransaction = MultisigAccountModificationTransaction.create( Deadline.create(), 2, @@ -108,24 +119,16 @@ describe('TransactionService', () => { cosignAccount3.publicAccount, ], [], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [modifyMultisigAccountTransaction.toAggregate(multisigAccount.publicAccount)], - NetworkType.MIJIN_TEST, - []); + networkType, [], helper.maxFee); const signedTransaction = aggregateTransaction - .signTransactionWithCosignatories(multisigAccount, [cosignAccount1, cosignAccount2, cosignAccount3], generationHash); + .signTransactionWithCosignatories(multisigAccount, [cosignAccount1, cosignAccount2, cosignAccount3], generationHash); - listener.confirmed(multisigAccount.address).subscribe(() => { - done(); - }); - listener.status(multisigAccount.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); @@ -136,14 +139,7 @@ describe('TransactionService', () => { */ describe('should announce transaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('announce', (done) => { const transferTransaction = TransferTransaction.create( Deadline.create(), @@ -152,10 +148,10 @@ describe('TransactionService', () => { NetworkCurrencyMosaic.createAbsolute(1), ], PlainMessage.create('test-message'), - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedTransaction = transferTransaction.signWith(account, generationHash); - transactionService.announce(signedTransaction, listener).subscribe((tx: TransferTransaction) => { + transactionService.announce(signedTransaction, helper.listener).subscribe((tx: TransferTransaction) => { expect(tx.signer!.publicKey).to.be.equal(account.publicKey); expect((tx.recipientAddress as Address).equals(account2.address)).to.be.true; expect(tx.message.payload).to.be.equal('test-message'); @@ -165,27 +161,19 @@ describe('TransactionService', () => { }); describe('should announce aggregate bonded with hashlock', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('announce', (done) => { - const signedAggregatedTransaction = - TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, account, account2.address, generationHash); + const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedLockFundsTransaction = lockFundsTransaction.signWith(account, generationHash); transactionService - .announceHashLockAggregateBonded(signedLockFundsTransaction, signedAggregatedTransaction, listener).subscribe((tx) => { + .announceHashLockAggregateBonded(signedLockFundsTransaction, signedAggregatedTransaction, helper.listener).subscribe((tx) => { expect(tx.signer!.publicKey).to.be.equal(account.publicKey); expect(tx.type).to.be.equal(TransactionType.AGGREGATE_BONDED); done(); @@ -193,28 +181,21 @@ describe('TransactionService', () => { }); }); + describe('should announce aggregate bonded transaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); + it('announce', (done) => { - const signedAggregatedTransaction = - TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, account, account2.address, generationHash); + const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const signedLockFundsTransaction = lockFundsTransaction.signWith(account, generationHash); - transactionService.announce(signedLockFundsTransaction, listener).subscribe(() => { - transactionService.announceAggregateBonded(signedAggregatedTransaction, listener).subscribe((tx) => { + transactionService.announce(signedLockFundsTransaction, helper.listener).subscribe(() => { + transactionService.announceAggregateBonded(signedAggregatedTransaction, helper.listener).subscribe((tx) => { expect(tx.signer!.publicKey).to.be.equal(account.publicKey); expect(tx.type).to.be.equal(TransactionType.AGGREGATE_BONDED); done(); @@ -230,23 +211,16 @@ describe('TransactionService', () => { */ describe('Restore test multisig Accounts', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('Announce MultisigAccountModificationTransaction', (done) => { + + it('Announce MultisigAccountModificationTransaction', () => { const removeCosigner1 = MultisigAccountModificationTransaction.create( Deadline.create(), -1, 0, [], - [ cosignAccount1.publicAccount, + [cosignAccount1.publicAccount, ], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const removeCosigner2 = MultisigAccountModificationTransaction.create( Deadline.create(), @@ -256,7 +230,7 @@ describe('TransactionService', () => { [ cosignAccount2.publicAccount, ], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const removeCosigner3 = MultisigAccountModificationTransaction.create( @@ -267,26 +241,17 @@ describe('TransactionService', () => { [ cosignAccount3.publicAccount, ], - NetworkType.MIJIN_TEST, + networkType, helper.maxFee ); const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [removeCosigner1.toAggregate(multisigAccount.publicAccount), - removeCosigner2.toAggregate(multisigAccount.publicAccount), - removeCosigner3.toAggregate(multisigAccount.publicAccount)], - NetworkType.MIJIN_TEST, - []); + removeCosigner2.toAggregate(multisigAccount.publicAccount), + removeCosigner3.toAggregate(multisigAccount.publicAccount)], networkType, [], helper.maxFee); const signedTransaction = aggregateTransaction - .signTransactionWithCosignatories(cosignAccount1, [cosignAccount2, cosignAccount3], generationHash); + .signTransactionWithCosignatories(cosignAccount1, [cosignAccount2, cosignAccount3], generationHash); - listener.confirmed(cosignAccount1.address).subscribe(() => { - done(); - }); - listener.status(cosignAccount1.address).subscribe((error) => { - console.log('Error:', error); - done(); - }); - transactionHttp.announce(signedTransaction); + return helper.announce(signedTransaction); }); }); }); diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index de956a48e7..8ecba07c48 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -14,23 +14,21 @@ * limitations under the License. */ -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map} from 'rxjs/operators'; -import {AccountInfo} from '../model/account/AccountInfo'; +import { from as observableFrom, Observable, throwError } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; +import { AccountInfo } from '../model/account/AccountInfo'; import { ActivityBucket } from '../model/account/ActivityBucket'; -import {Address} from '../model/account/Address'; -import { NetworkType } from '../model/blockchain/NetworkType'; -import {Mosaic} from '../model/mosaic/Mosaic'; -import {MosaicId} from '../model/mosaic/MosaicId'; -import {AggregateTransaction} from '../model/transaction/AggregateTransaction'; -import {Transaction} from '../model/transaction/Transaction'; +import { Address } from '../model/account/Address'; +import { Mosaic } from '../model/mosaic/Mosaic'; +import { MosaicId } from '../model/mosaic/MosaicId'; +import { AggregateTransaction } from '../model/transaction/AggregateTransaction'; +import { Transaction } from '../model/transaction/Transaction'; import { UInt64 } from '../model/UInt64'; -import {AccountRepository} from './AccountRepository'; -import { AccountInfoDTO, - AccountRoutesApi } from './api'; -import {Http} from './Http'; -import {QueryParams} from './QueryParams'; -import {CreateTransactionFromDTO} from './transaction/CreateTransactionFromDTO'; +import { AccountRepository } from './AccountRepository'; +import { AccountInfoDTO, AccountRoutesApi } from './api'; +import { Http } from './Http'; +import { QueryParams } from './QueryParams'; +import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; /** * Account http repository. @@ -47,10 +45,9 @@ export class AccountHttp extends Http implements AccountRepository { /** * Constructor * @param url - * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string) { + super(url); this.accountRoutesApi = new AccountRoutesApi(url); } diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index 62193b921e..14bf2f5143 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -14,20 +14,22 @@ * limitations under the License. */ -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map} from 'rxjs/operators'; -import {PublicAccount} from '../model/account/PublicAccount'; -import {BlockInfo} from '../model/blockchain/BlockInfo'; +import { from as observableFrom, Observable, throwError } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; +import { PublicAccount } from '../model/account/PublicAccount'; +import { BlockInfo } from '../model/blockchain/BlockInfo'; import { MerklePathItem } from '../model/blockchain/MerklePathItem'; import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo'; -import { NetworkType } from '../model/blockchain/NetworkType'; -import {Transaction} from '../model/transaction/Transaction'; -import {UInt64} from '../model/UInt64'; +import { Transaction } from '../model/transaction/Transaction'; +import { UInt64 } from '../model/UInt64'; import { BlockInfoDTO, BlockRoutesApi } from './api'; -import {BlockRepository} from './BlockRepository'; -import {Http} from './Http'; -import {QueryParams} from './QueryParams'; -import {CreateTransactionFromDTO, extractBeneficiary} from './transaction/CreateTransactionFromDTO'; +import { BlockRepository } from './BlockRepository'; +import { Http } from './Http'; +import { QueryParams } from './QueryParams'; +import { + CreateTransactionFromDTO, + extractBeneficiary +} from './transaction/CreateTransactionFromDTO'; /** * Blocks returned limits: @@ -43,6 +45,7 @@ export enum LimitType { N_100 = 100, } + /** * Blockchain http repository. * @@ -53,15 +56,14 @@ export class BlockHttp extends Http implements BlockRepository { * @internal * Nem2 Library block routes api */ - private blockRoutesApi: BlockRoutesApi; + private readonly blockRoutesApi: BlockRoutesApi; /** * Constructor * @param url - * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string) { + super(url); this.blockRoutesApi = new BlockRoutesApi(url); } diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index d9654de2c9..eb44afb07d 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -15,44 +15,37 @@ */ // tslint:disable-next-line: ordered-imports -import {from as observableFrom, Observable, of as observableOf, throwError} from 'rxjs'; -import {catchError, map} from 'rxjs/operators'; -import {NetworkType} from '../model/blockchain/NetworkType'; -import { NodeRoutesApi } from './api/apis'; +import { from as observableFrom, Observable, of as observableOf, throwError } from 'rxjs'; +import { NetworkType } from '../model/blockchain/NetworkType'; import { QueryParams } from './QueryParams'; +import { NodeRoutesApi } from "./api/nodeRoutesApi"; +import { catchError, map, share, shareReplay } from 'rxjs/operators'; + /** * Http extended by all http services */ export abstract class Http { protected readonly url: string; - protected networkType: NetworkType; /** * Constructor * @param url Base catapult-rest url - * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - if (networkType) { - this.networkType = networkType; - } + constructor(url: string) { this.url = url; } - getNetworkTypeObservable(): Observable { - let networkTypeResolve; - if (!this.networkType) { - networkTypeResolve = observableFrom(new NodeRoutesApi(this.url).getNodeInfo()).pipe( - map(({body}) => { - this.networkType = body.networkIdentifier; - return body.networkIdentifier; - }), - catchError((error) => throwError(this.errorHandling(error))), - ); + createNetworkTypeObservable(networkType?: NetworkType | Observable): Observable { + if (networkType && networkType instanceof Observable) { + return networkType as Observable; + } else if (networkType) { + return observableOf(networkType as NetworkType); } else { - networkTypeResolve = observableOf(this.networkType); + return observableFrom(new NodeRoutesApi(this.url).getNodeInfo()).pipe( + map(({body}) => body.networkIdentifier), + catchError((error) => throwError(this.errorHandling(error))), + ).pipe(shareReplay(1)); } - return networkTypeResolve; } queryParams(queryParams?: QueryParams): any { diff --git a/src/infrastructure/IListener.ts b/src/infrastructure/IListener.ts new file mode 100644 index 0000000000..2101b0aea0 --- /dev/null +++ b/src/infrastructure/IListener.ts @@ -0,0 +1,131 @@ +/* + * Copyright 2019 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Observable } from 'rxjs'; +import { Address } from '../model/account/Address'; +import { BlockInfo } from '../model/blockchain/BlockInfo'; +import { AggregateTransaction } from '../model/transaction/AggregateTransaction'; +import { CosignatureSignedTransaction } from '../model/transaction/CosignatureSignedTransaction'; +import { Transaction } from '../model/transaction/Transaction'; +import { TransactionStatusError } from '../model/transaction/TransactionStatusError'; + + +/** + * Listener service + */ +export interface IListener { + + /** + * Open web socket connection. + * @returns Promise + */ + open(): Promise; + + /** + * returns a boolean that repressents the open state + * @returns a boolean + */ + isOpen(): Boolean; + + /** + * Close web socket connection. + * @returns void + */ + close(): void; + + /** + * Returns an observable stream of BlockInfo. + * Each time a new Block is added into the blockchain, + * it emits a new BlockInfo in the event stream. + * + * @return an observable stream of BlockInfo + */ + newBlock(): Observable + + /** + * Returns an observable stream of Transaction for a specific address. + * Each time a transaction is in confirmed state an it involves the address, + * it emits a new Transaction in the event stream. + * + * @param address address we listen when a transaction is in confirmed state + * @param transactionHash transactionHash for filtering multiple transactions + * @return an observable stream of Transaction with state confirmed + */ + + confirmed(address: Address, transactionHash?: string): Observable; + + /** + * Returns an observable stream of Transaction for a specific address. + * Each time a transaction is in unconfirmed state an it involves the address, + * it emits a new Transaction in the event stream. + * + * @param address address we listen when a transaction is in unconfirmed state + * @return an observable stream of Transaction with state unconfirmed + */ + unconfirmedAdded(address: Address): Observable; + + /** + * Returns an observable stream of Transaction Hashes for specific address. + * Each time a transaction with state unconfirmed changes its state, + * it emits a new message with the transaction hash in the event stream. + * + * @param address address we listen when a transaction is removed from unconfirmed state + * @return an observable stream of Strings with the transaction hash + */ + unconfirmedRemoved(address: Address): Observable; + + /** + * Return an observable of {@link AggregateTransaction} for specific address. + * Each time an aggregate bonded transaction is announced, + * it emits a new {@link AggregateTransaction} in the event stream. + * + * @param address address we listen when a transaction with missing signatures state + * @param transactionHash transactionHash for filtering multiple transactions + * @return an observable stream of AggregateTransaction with missing signatures state + */ + aggregateBondedAdded(address: Address, transactionHash?: string): Observable + + /** + * Returns an observable stream of Transaction Hashes for specific address. + * Each time an aggregate bonded transaction is announced, + * it emits a new message with the transaction hash in the event stream. + * + * @param address address we listen when a transaction is confirmed or rejected + * @return an observable stream of Strings with the transaction hash + */ + aggregateBondedRemoved(address: Address): Observable + + /** + * Returns an observable stream of {@link TransactionStatusError} for specific address. + * Each time a transaction contains an error, + * it emits a new message with the transaction status error in the event stream. + * + * @param address address we listen to be notified when some error happened + * @return an observable stream of {@link TransactionStatusError} + */ + status(address: Address): Observable; + + /** + * Returns an observable stream of {@link CosignatureSignedTransaction} for specific address. + * Each time a cosigner signs a transaction the address initialized, + * it emits a new message with the cosignatory signed transaction in the even stream. + * + * @param address address we listen when a cosignatory is added to some transaction address sent + * @return an observable stream of {@link CosignatureSignedTransaction} + */ + cosignatureAdded(address: Address): Observable; + +} diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index 7ccdf0236e..8112a0cc8c 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -37,6 +37,7 @@ import { CreateTransactionFromDTO, extractBeneficiary, } from './transaction/CreateTransactionFromDTO'; +import { IListener } from "./IListener"; enum ListenerChannelName { block = 'block', @@ -58,7 +59,7 @@ interface ListenerMessage { /** * Listener service */ -export class Listener { +export class Listener implements IListener { public readonly url: string; /** * @internal @@ -203,16 +204,6 @@ export class Listener { } } - /** - * Terminate web socket connection. - * @returns void - */ - public terminate(): void { - if (this.webSocket) { - this.webSocket.close(); - } - } - /** * Returns an observable stream of BlockInfo. * Each time a new Block is added into the blockchain, @@ -432,9 +423,9 @@ export class Listener { private accountAddedToMultiSig(transaction: Transaction, address: Address): boolean { if (transaction instanceof MultisigAccountModificationTransaction) { return transaction.publicKeyAdditions.find((_: PublicAccount) => - _.address.equals(address)) !== undefined || + _.address.equals(address)) !== undefined || transaction.publicKeyDeletions.find((_: PublicAccount) => - _.address.equals(address)) !== undefined; + _.address.equals(address)) !== undefined; } return false; } diff --git a/src/infrastructure/MetadataHttp.ts b/src/infrastructure/MetadataHttp.ts index 5d8d863fa7..3f193db43c 100644 --- a/src/infrastructure/MetadataHttp.ts +++ b/src/infrastructure/MetadataHttp.ts @@ -40,16 +40,21 @@ export class MetadataHttp extends Http implements MetadataRepository { * @internal * Nem2 Library metadata routes api */ - private metadataRoutesApi: MetadataRoutesApi; - + private readonly metadataRoutesApi: MetadataRoutesApi; + /** + * @internal + * network type for the mappings. + */ + private readonly networkTypeObservable: Observable; /** * Constructor * @param url * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string, networkType?: NetworkType | Observable) { + super(url); this.metadataRoutesApi = new MetadataRoutesApi(url); + this.networkTypeObservable = this.createNetworkTypeObservable(networkType); } /** diff --git a/src/infrastructure/MosaicHttp.ts b/src/infrastructure/MosaicHttp.ts index 6be9b42d3c..009a60e6c9 100644 --- a/src/infrastructure/MosaicHttp.ts +++ b/src/infrastructure/MosaicHttp.ts @@ -37,16 +37,22 @@ export class MosaicHttp extends Http implements MosaicRepository { * @internal * Nem2 Library mosaic routes api */ - private mosaicRoutesApi: MosaicRoutesApi; + private readonly mosaicRoutesApi: MosaicRoutesApi; + /** + * @internal + * network type for the mappings. + */ + private readonly networkTypeObservable: Observable; /** * Constructor * @param url * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string, networkType?: NetworkType | Observable) { + super(url); this.mosaicRoutesApi = new MosaicRoutesApi(url); + this.networkTypeObservable = this.createNetworkTypeObservable(networkType); } /** @@ -55,7 +61,7 @@ export class MosaicHttp extends Http implements MosaicRepository { * @returns Observable */ public getMosaic(mosaicId: MosaicId): Observable { - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.mosaicRoutesApi.getMosaic(mosaicId.toHex())).pipe( map(({body}) => new MosaicInfo( @@ -82,7 +88,7 @@ export class MosaicHttp extends Http implements MosaicRepository { const mosaicIdsBody = { mosaicIds: mosaicIds.map((id) => id.toHex()), }; - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.mosaicRoutesApi.getMosaics(mosaicIdsBody)).pipe( map(({body}) => body.map((mosaicInfoDTO) => { @@ -109,7 +115,7 @@ export class MosaicHttp extends Http implements MosaicRepository { * @param address Account address. */ public getMosaicsFromAccount(address: Address): Observable { - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.mosaicRoutesApi.getMosaicsFromAccount(address.plain())).pipe( map(({body}) => body.mosaics.map((mosaicInfo) => @@ -136,7 +142,7 @@ export class MosaicHttp extends Http implements MosaicRepository { const accountIdsBody = { addresses: addresses.map((address) => address.plain()), }; - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.mosaicRoutesApi.getMosaicsFromAccounts(accountIdsBody)).pipe( map(({body}) => body.mosaics.map((mosaicInfoDTO) => { diff --git a/src/infrastructure/MultisigHttp.ts b/src/infrastructure/MultisigHttp.ts index b379ce14e9..7770164123 100644 --- a/src/infrastructure/MultisigHttp.ts +++ b/src/infrastructure/MultisigHttp.ts @@ -35,16 +35,21 @@ export class MultisigHttp extends Http implements MultisigRepository { * @internal * Nem2 Library account routes api */ - private multisigRoutesApi: MultisigRoutesApi; - + private readonly multisigRoutesApi: MultisigRoutesApi; + /** + * @internal + * network type for the mappings. + */ + private readonly networkTypeObservable: Observable; /** * Constructor * @param url * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string, networkType?: NetworkType | Observable) { + super(url); this.multisigRoutesApi = new MultisigRoutesApi(url); + this.networkTypeObservable = this.createNetworkTypeObservable(networkType); } /** @@ -53,7 +58,7 @@ export class MultisigHttp extends Http implements MultisigRepository { * @returns Observable */ public getMultisigAccountInfo(address: Address): Observable { - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.multisigRoutesApi.getAccountMultisig(address.plain())) .pipe(map(({body}) => new MultisigAccountInfo( @@ -75,7 +80,7 @@ export class MultisigHttp extends Http implements MultisigRepository { * @returns Observable */ public getMultisigAccountGraphInfo(address: Address): Observable { - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.multisigRoutesApi.getAccountMultisigGraph(address.plain())) .pipe(map(({body}) => { diff --git a/src/infrastructure/NamespaceHttp.ts b/src/infrastructure/NamespaceHttp.ts index 61a734fb1e..fdbd87027b 100644 --- a/src/infrastructure/NamespaceHttp.ts +++ b/src/infrastructure/NamespaceHttp.ts @@ -48,14 +48,20 @@ export class NamespaceHttp extends Http implements NamespaceRepository { */ private namespaceRoutesApi: NamespaceRoutesApi; + /** + * @internal + * network type for the mappings. + */ + private readonly networkTypeObservable: Observable; /** * Constructor * @param url * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string, networkType?: NetworkType | Observable) { + super(url); this.namespaceRoutesApi = new NamespaceRoutesApi(url); + this.networkTypeObservable = this.createNetworkTypeObservable(networkType); } /** @@ -111,7 +117,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { * @returns Observable */ public getNamespace(namespaceId: NamespaceId): Observable { - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.namespaceRoutesApi.getNamespace(namespaceId.toHex())).pipe( map(({body}) => new NamespaceInfo( @@ -141,7 +147,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { */ public getNamespacesFromAccount(address: Address, queryParams?: QueryParams): Observable { - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.namespaceRoutesApi.getNamespacesFromAccount(address.plain(), this.queryParams(queryParams).pageSize, @@ -178,7 +184,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { const publicKeysBody = { addresses: addresses.map((address) => address.plain()), }; - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.namespaceRoutesApi.getNamespacesFromAccounts(publicKeysBody)).pipe( map(({body}) => body.namespaces.map((namespaceInfoDTO) => { @@ -229,7 +235,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { * @returns Observable */ public getLinkedMosaicId(namespaceId: NamespaceId): Observable { - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap(() => observableFrom( this.namespaceRoutesApi.getNamespace(namespaceId.toHex())).pipe( map(({body}) => { @@ -257,7 +263,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { * @returns Observable
*/ public getLinkedAddress(namespaceId: NamespaceId): Observable
{ - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap(() => observableFrom( this.namespaceRoutesApi.getNamespace(namespaceId.toHex())).pipe( map(({body}) => { diff --git a/src/infrastructure/NodeHttp.ts b/src/infrastructure/NodeHttp.ts index 50ab06d391..088d9990e0 100644 --- a/src/infrastructure/NodeHttp.ts +++ b/src/infrastructure/NodeHttp.ts @@ -14,14 +14,14 @@ * limitations under the License. */ -import {from as observableFrom, Observable, throwError} from 'rxjs'; -import {catchError, map} from 'rxjs/operators'; +import { from as observableFrom, Observable, throwError } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; import { NodeInfo } from '../model/node/NodeInfo'; import { NodeTime } from '../model/node/NodeTime'; import { UInt64 } from '../model/UInt64'; import { NodeRoutesApi } from './api'; -import {Http} from './Http'; -import {NodeRepository} from './NodeRepository'; +import { Http } from './Http'; +import { NodeRepository } from './NodeRepository'; /** * Node http repository. diff --git a/src/infrastructure/ReceiptHttp.ts b/src/infrastructure/ReceiptHttp.ts index c323223744..fa0d411d7f 100644 --- a/src/infrastructure/ReceiptHttp.ts +++ b/src/infrastructure/ReceiptHttp.ts @@ -35,16 +35,23 @@ export class ReceiptHttp extends Http implements ReceiptRepository { * @internal * Nem2 Library receipt routes api */ - private receiptRoutesApi: ReceiptRoutesApi; + private readonly receiptRoutesApi: ReceiptRoutesApi; + + /** + * @internal + * network type for the mappings. + */ + private readonly networkTypeObservable: Observable; /** * Constructor * @param url * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string, networkType?: NetworkType | Observable) { + super(url); this.receiptRoutesApi = new ReceiptRoutesApi(url); + this.networkTypeObservable = this.createNetworkTypeObservable(networkType); } /** @@ -75,7 +82,7 @@ export class ReceiptHttp extends Http implements ReceiptRepository { * @returns Observable */ public getBlockReceipts(height: string): Observable { - return this.getNetworkTypeObservable().pipe( + return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( this.receiptRoutesApi.getBlockReceipts(height)).pipe( map(({body}) => CreateStatementFromDTO(body, networkType)), diff --git a/src/infrastructure/RepositoryFactory.ts b/src/infrastructure/RepositoryFactory.ts new file mode 100644 index 0000000000..f343854697 --- /dev/null +++ b/src/infrastructure/RepositoryFactory.ts @@ -0,0 +1,130 @@ +/* + * Copyright 2019 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Observable } from "rxjs"; +import { NetworkType } from "../model/blockchain/NetworkType"; +import { AccountRepository } from "./AccountRepository"; +import { MultisigRepository } from "./MultisigRepository"; +import { ReceiptRepository } from "./ReceiptRepository"; +import { BlockRepository } from "./BlockRepository"; +import { ChainRepository } from "./ChainRepository"; +import { DiagnosticRepository } from "./DiagnosticRepository"; +import { MosaicRepository } from "./MosaicRepository"; +import { NamespaceRepository } from "./NamespaceRepository"; +import { NetworkRepository } from "./NetworkRepository"; +import { NodeRepository } from "./NodeRepository"; +import { TransactionRepository } from "./TransactionRepository"; +import { MetadataRepository } from "./MetadataRepository"; +import { RestrictionAccountRepository } from "./RestrictionAccountRespository"; +import { RestrictionMosaicRepository } from "./RestrictionMosaicRepository"; +import { Listener } from "./Listener"; +import { IListener } from "./IListener"; + +/** + * A repository factory allows clients to create repositories to access NEM Server without knowing + * the underline implementation. + * + */ +export interface RepositoryFactory { + + /** + * @returns the network type of the network. This method is cached, the server is only called the + * first time. + */ + getNetworkType(): Observable; + + /** + * @returns the generation hash used to sign transactions. Value retrieved from the block/1 + * endpoint. This method is cached, the server is only called the first time. + */ + getGenerationHash(): Observable; + + /** + * @returns a newly created {@link AccountRepository} + */ + createAccountRepository(): AccountRepository; + + /** + * @returns a newly created {@link MultisigRepository} + */ + createMultisigRepository(): MultisigRepository; + + /** + * @returns a newly created {@link BlockRepository} + */ + createBlockRepository(): BlockRepository; + + /** + * @returns a newly created {@link ReceiptRepository} + */ + createReceiptRepository(): ReceiptRepository; + + /** + * @returns a newly created {@link ChainRepository} + */ + createChainRepository(): ChainRepository; + + /** + * @returns a newly created {@link DiagnosticRepository} + */ + createDiagnosticRepository(): DiagnosticRepository; + + /** + * @returns a newly created {@link MosaicRepository} + */ + createMosaicRepository(): MosaicRepository; + + /** + * @returns a newly created {@link NamespaceRepository} + */ + createNamespaceRepository(): NamespaceRepository; + + /** + * @returns a newly created {@link NetworkRepository} + */ + createNetworkRepository(): NetworkRepository; + + /** + * @returns a newly created {@link NodeRepository} + */ + createNodeRepository(): NodeRepository; + + /** + * @returns a newly created {@link NodeRepository} + */ + createTransactionRepository(): TransactionRepository; + + /** + * @returns a newly created {@link MetadataRepository} + */ + createMetadataRepository(): MetadataRepository; + + /** + * @returns a newly created {@link RestrictionAccountRepository} + */ + createRestrictionAccountRepository(): RestrictionAccountRepository; + + /** + * @returns a newly created {@link RestrictionMosaicRepository} + */ + createRestrictionMosaicRepository(): RestrictionMosaicRepository; + + /** + * @returns a newly create {@link IListener} + */ + createListener(): IListener; + +} \ No newline at end of file diff --git a/src/infrastructure/RepositoryFactoryHttp.ts b/src/infrastructure/RepositoryFactoryHttp.ts new file mode 100644 index 0000000000..4f68950f2c --- /dev/null +++ b/src/infrastructure/RepositoryFactoryHttp.ts @@ -0,0 +1,141 @@ +/* + * Copyright 2019 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Observable, of as observableOf } from "rxjs"; +import { NetworkType } from "../model/blockchain/NetworkType"; +import { AccountRepository } from "./AccountRepository"; +import { MultisigRepository } from "./MultisigRepository"; +import { ReceiptRepository } from "./ReceiptRepository"; +import { BlockRepository } from "./BlockRepository"; +import { ChainRepository } from "./ChainRepository"; +import { DiagnosticRepository } from "./DiagnosticRepository"; +import { MosaicRepository } from "./MosaicRepository"; +import { NamespaceRepository } from "./NamespaceRepository"; +import { NetworkRepository } from "./NetworkRepository"; +import { NodeRepository } from "./NodeRepository"; +import { TransactionRepository } from "./TransactionRepository"; +import { MetadataRepository } from "./MetadataRepository"; +import { RestrictionAccountRepository } from "./RestrictionAccountRespository"; +import { RestrictionMosaicRepository } from "./RestrictionMosaicRepository"; +import { RepositoryFactory } from "./RepositoryFactory"; +import { AccountHttp } from "./AccountHttp"; +import { BlockHttp } from "./BlockHttp"; +import { ChainHttp } from "./ChainHttp"; +import { DiagnosticHttp } from "./DiagnosticHttp"; +import { MetadataHttp } from "./MetadataHttp"; +import { MosaicHttp } from "./MosaicHttp"; +import { MultisigHttp } from "./MultisigHttp"; +import { NamespaceHttp } from "./NamespaceHttp"; +import { NetworkHttp } from "./NetworkHttp"; +import { NodeHttp } from "./NodeHttp"; +import { ReceiptHttp } from "./ReceiptHttp"; +import { RestrictionAccountHttp } from "./RestrictionAccountHttp"; +import { RestrictionMosaicHttp } from "./RestrictionMosaicHttp"; +import { TransactionHttp } from "./TransactionHttp"; +import { share, map, shareReplay } from "rxjs/operators"; +import { Listener } from "./Listener"; +import { IListener } from "./IListener"; + +/** + * Receipt http repository. + * + */ +export class RepositoryFactoryHttp implements RepositoryFactory { + + private readonly url: string; + private readonly networkType: Observable; + private readonly generationHash: Observable; + + /** + * Constructor + * @param url the server url. + * @param networkType optional network type if you don't want to load it from the server. + */ + constructor(url: string, networkType?: NetworkType) { + this.url = url; + this.networkType = networkType ? observableOf(networkType) : this.createNetworkRepository().getNetworkType().pipe(shareReplay(1)); + this.generationHash = this.createBlockRepository().getBlockByHeight('1').pipe(map(b => b.generationHash)).pipe(shareReplay(1)); + } + + createAccountRepository(): AccountRepository { + return new AccountHttp(this.url); + } + + createBlockRepository(): BlockRepository { + return new BlockHttp(this.url); + } + + createChainRepository(): ChainRepository { + return new ChainHttp(this.url); + } + + createDiagnosticRepository(): DiagnosticRepository { + return new DiagnosticHttp(this.url); + } + + createMetadataRepository(): MetadataRepository { + return new MetadataHttp(this.url); + } + + createMosaicRepository(): MosaicRepository { + return new MosaicHttp(this.url, this.networkType); + } + + createMultisigRepository(): MultisigRepository { + return new MultisigHttp(this.url, this.networkType); + } + + createNamespaceRepository(): NamespaceRepository { + return new NamespaceHttp(this.url, this.networkType); + } + + createNetworkRepository(): NetworkRepository { + return new NetworkHttp(this.url); + } + + createNodeRepository(): NodeRepository { + return new NodeHttp(this.url); + } + + createReceiptRepository(): ReceiptRepository { + return new ReceiptHttp(this.url); + } + + createRestrictionAccountRepository(): RestrictionAccountRepository { + return new RestrictionAccountHttp(this.url); + } + + createRestrictionMosaicRepository(): RestrictionMosaicRepository { + return new RestrictionMosaicHttp(this.url); + } + + createTransactionRepository(): TransactionRepository { + return new TransactionHttp(this.url); + } + + getGenerationHash(): Observable { + return this.generationHash; + } + + getNetworkType(): Observable { + return this.networkType; + } + + createListener(): IListener { + return new Listener(this.url); + } + +} \ No newline at end of file diff --git a/src/infrastructure/RestrictionAccountHttp.ts b/src/infrastructure/RestrictionAccountHttp.ts index 2e46d016ce..39d7c29e07 100644 --- a/src/infrastructure/RestrictionAccountHttp.ts +++ b/src/infrastructure/RestrictionAccountHttp.ts @@ -35,16 +35,13 @@ export class RestrictionAccountHttp extends Http implements RestrictionAccountRe * @internal */ private restrictionAccountRoutesApi: RestrictionAccountRoutesApi; - /** * Constructor * @param url - * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string) { + super(url); this.restrictionAccountRoutesApi = new RestrictionAccountRoutesApi(url); - } /** diff --git a/src/infrastructure/RestrictionMosaicHttp.ts b/src/infrastructure/RestrictionMosaicHttp.ts index 5dbb2e7695..36c59ab8e2 100644 --- a/src/infrastructure/RestrictionMosaicHttp.ts +++ b/src/infrastructure/RestrictionMosaicHttp.ts @@ -24,7 +24,7 @@ import { MosaicGlobalRestriction } from '../model/restriction/MosaicGlobalRestri import { MosaicGlobalRestrictionItem } from '../model/restriction/MosaicGlobalRestrictionItem'; import { RestrictionMosaicRoutesApi } from './api/restrictionMosaicRoutesApi'; import {Http} from './Http'; -import { RestrictionMosaicRepository } from './RestrictionMosaicRespository'; +import { RestrictionMosaicRepository } from './RestrictionMosaicRepository'; import { MosaicAddressRestrictionDTO } from "./model/mosaicAddressRestrictionDTO"; import { MosaicGlobalRestrictionDTO } from "./model/mosaicGlobalRestrictionDTO"; @@ -44,8 +44,8 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo * @param url * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string) { + super(url); this.restrictionMosaicRoutesApi = new RestrictionMosaicRoutesApi(url); } diff --git a/src/infrastructure/RestrictionMosaicRespository.ts b/src/infrastructure/RestrictionMosaicRepository.ts similarity index 100% rename from src/infrastructure/RestrictionMosaicRespository.ts rename to src/infrastructure/RestrictionMosaicRepository.ts diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index d6a8b85906..611e66e389 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -56,15 +56,23 @@ export class TransactionHttp extends Http implements TransactionRepository { */ private blockRoutesApi: BlockRoutesApi; + + /** + * @internal + * network type for the mappings. + */ + private readonly networkTypeObservable: Observable; + /** * Constructor * @param url * @param networkType */ - constructor(url: string, networkType?: NetworkType) { - super(url, networkType); + constructor(url: string, networkType?: NetworkType | Observable) { + super(url); this.transactionRoutesApi = new TransactionRoutesApi(url); this.blockRoutesApi = new BlockRoutesApi(url); + this.networkTypeObservable = this.createNetworkTypeObservable(networkType); } /** diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 8f58f5d2a4..863c1cbae8 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -import { Observable } from 'rxjs/internal/Observable'; -import { of } from 'rxjs/internal/observable/of'; import { Convert, RawAddress } from '../../core/format'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; @@ -25,7 +23,6 @@ import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { ReceiptHttp } from '../../infrastructure/ReceiptHttp'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 3bab2f98aa..4d31fa9d3b 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -135,8 +135,7 @@ export class LockFundsTransaction extends Transaction { new UInt64(builder.getMosaic().amount.amount), ), new UInt64(builder.getDuration().blockDuration), - new SignedTransaction('', Convert.uint8ToHex(builder.getHash().hash256), '', - TransactionType.AGGREGATE_BONDED, networkType), + new SignedTransaction('', Convert.uint8ToHex(builder.getHash().hash256), '', TransactionType.AGGREGATE_BONDED, networkType), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as HashLockTransactionBuilder).fee.amount), ); diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 2c3a9de798..db890c7ca4 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,9 +14,6 @@ * limitations under the License. */ -import { Observable } from 'rxjs/internal/Observable'; -import { of } from 'rxjs/internal/observable/of'; -import { map } from 'rxjs/operators'; import { Convert, Convert as convert } from '../../core/format'; import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -27,13 +24,10 @@ import { SecretProofTransactionBuilder } from '../../infrastructure/catbuffer/Se import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; -import { ReceiptHttp } from '../../infrastructure/ReceiptHttp'; -import { TransactionService } from '../../service/TransactionService'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { NamespaceId } from '../namespace/NamespaceId'; -import { ResolutionType } from '../receipt/ResolutionType'; import { Statement } from '../receipt/Statement'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; diff --git a/src/model/transaction/SignedTransaction.ts b/src/model/transaction/SignedTransaction.ts index bc776b4eb6..aade32582c 100644 --- a/src/model/transaction/SignedTransaction.ts +++ b/src/model/transaction/SignedTransaction.ts @@ -17,6 +17,7 @@ import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import {NetworkType} from '../blockchain/NetworkType'; +import { TransactionType } from "./TransactionType"; /** * SignedTransaction object is used to transfer the transaction data and the signature to the server @@ -26,7 +27,6 @@ export class SignedTransaction { /** * @param payload * @param hash - * @param signer * @param type * @param networkType */ @@ -45,7 +45,7 @@ export class SignedTransaction { /** * Transaction type */ - public readonly type: number, + public readonly type: TransactionType, /** * Signer network type */ diff --git a/src/service/AggregateTransactionService.ts b/src/service/AggregateTransactionService.ts index 99997f0f77..4b278f54ef 100644 --- a/src/service/AggregateTransactionService.ts +++ b/src/service/AggregateTransactionService.ts @@ -14,18 +14,16 @@ * limitations under the License. */ -import {from as observableFrom , Observable, of as observableOf} from 'rxjs'; -import { flatMap, map, mergeMap, toArray} from 'rxjs/operators'; +import { from as observableFrom, Observable, of as observableOf } from 'rxjs'; +import { flatMap, map, mergeMap, toArray } from 'rxjs/operators'; import { TransactionMapping } from '../core/utils/TransactionMapping'; -import { AccountHttp } from '../infrastructure/AccountHttp'; -import { MultisigHttp } from '../infrastructure/MultisigHttp'; import { MultisigAccountGraphInfo } from '../model/account/MultisigAccountGraphInfo'; import { AggregateTransaction } from '../model/transaction/AggregateTransaction'; -import { CosignatoryModificationAction } from '../model/transaction/CosignatoryModificationAction'; import { InnerTransaction } from '../model/transaction/InnerTransaction'; import { MultisigAccountModificationTransaction } from '../model/transaction/MultisigAccountModificationTransaction'; import { SignedTransaction } from '../model/transaction/SignedTransaction'; import { TransactionType } from '../model/transaction/TransactionType'; +import { MultisigRepository } from "../infrastructure/MultisigRepository"; /** * Aggregated Transaction service @@ -34,9 +32,9 @@ export class AggregateTransactionService { /** * Constructor - * @param multisigHttp + * @param multisigRepository */ - constructor(private readonly multisigHttp: MultisigHttp) { + constructor(private readonly multisigRepository: MultisigRepository) { } /** @@ -54,13 +52,13 @@ export class AggregateTransactionService { signers.push(signedTransaction.signerPublicKey); } return observableFrom(aggregateTransaction.innerTransactions).pipe( - mergeMap((innerTransaction) => this.multisigHttp.getMultisigAccountInfo(innerTransaction.signer!.address) + mergeMap((innerTransaction) => this.multisigRepository.getMultisigAccountInfo(innerTransaction.signer!.address) .pipe( /** * For multisig account, we need to get the graph info in case it has multiple levels */ mergeMap((_) => _.minApproval !== 0 && _.minRemoval !== 0 ? - this.multisigHttp.getMultisigAccountGraphInfo(_.account.address) + this.multisigRepository.getMultisigAccountGraphInfo(_.account.address) .pipe( map((graphInfo) => this.validateCosignatories(graphInfo, signers, innerTransaction)), ) : observableOf(signers.find((s) => s === _.account.publicKey ) !== undefined), diff --git a/src/service/MetadataTransactionService.ts b/src/service/MetadataTransactionService.ts index 17d31b6448..17b9da7d35 100644 --- a/src/service/MetadataTransactionService.ts +++ b/src/service/MetadataTransactionService.ts @@ -31,6 +31,7 @@ import { MosaicMetadataTransaction } from '../model/transaction/MosaicMetadataTr import { NamespaceMetadataTransaction } from '../model/transaction/NamespaceMetadataTransaction'; import { Transaction } from '../model/transaction/Transaction'; import { UInt64 } from '../model/UInt64'; +import { MetadataRepository } from "../infrastructure/MetadataRepository"; /** * MetadataTransaction service @@ -39,9 +40,9 @@ export class MetadataTransactionService { /** * Constructor - * @param metadataHttp + * @param metadataRepository */ - constructor(private readonly metadataHttp: MetadataHttp) { + constructor(private readonly metadataRepository: MetadataRepository) { } /** @@ -129,7 +130,7 @@ export class MetadataTransactionService { value: string, senderPublicKey: string, maxFee: UInt64): Observable { - return this.metadataHttp.getAccountMetadataByKeyAndSender(Address.createFromPublicKey(targetPublicKey, networkType), + return this.metadataRepository.getAccountMetadataByKeyAndSender(Address.createFromPublicKey(targetPublicKey, networkType), key.toHex(), senderPublicKey) .pipe(map((metadata: Metadata) => { const currentValueByte = Convert.utf8ToUint8(metadata.metadataEntry.value); @@ -182,7 +183,7 @@ export class MetadataTransactionService { value: string, senderPublicKey: string, maxFee: UInt64): Observable { - return this.metadataHttp.getMosaicMetadataByKeyAndSender(mosaicId, + return this.metadataRepository.getMosaicMetadataByKeyAndSender(mosaicId, key.toHex(), senderPublicKey) .pipe(map((metadata: Metadata) => { const currentValueByte = Convert.utf8ToUint8(metadata.metadataEntry.value); @@ -237,7 +238,7 @@ export class MetadataTransactionService { value: string, senderPublicKey: string, maxFee: UInt64): Observable { - return this.metadataHttp.getNamespaceMetadataByKeyAndSender(namespaceId, + return this.metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, key.toHex(), senderPublicKey) .pipe(map((metadata: Metadata) => { const currentValueByte = Convert.utf8ToUint8(metadata.metadataEntry.value); diff --git a/src/service/MosaicRestrictionTransactionService.ts b/src/service/MosaicRestrictionTransactionService.ts index eecdbb3899..fc3e48e45d 100644 --- a/src/service/MosaicRestrictionTransactionService.ts +++ b/src/service/MosaicRestrictionTransactionService.ts @@ -27,7 +27,7 @@ import { MosaicAddressRestrictionTransaction } from '../model/transaction/Mosaic import { MosaicGlobalRestrictionTransaction } from '../model/transaction/MosaicGlobalRestrictionTransaction'; import { Transaction } from '../model/transaction/Transaction'; import { UInt64 } from '../model/UInt64'; -import { RestrictionMosaicRepository } from "../infrastructure/RestrictionMosaicRespository"; +import { RestrictionMosaicRepository } from "../infrastructure/RestrictionMosaicRepository"; import { NamespaceId } from "../model/namespace/NamespaceId"; /** @@ -35,8 +35,8 @@ import { NamespaceId } from "../model/namespace/NamespaceId"; */ export class MosaicRestrictionTransactionService { - private readonly defaultMosaicAddressRestrictionVaule = UInt64.fromHex('FFFFFFFFFFFFFFFF'); - private readonly defaultMosaicGlobalRestrictionVaule = UInt64.fromUint(0); + private readonly defaultMosaicAddressRestrictionValue = UInt64.fromHex('FFFFFFFFFFFFFFFF'); + private readonly defaultMosaicGlobalRestrictionValue = UInt64.fromUint(0); /** * Constructor @@ -68,7 +68,7 @@ export class MosaicRestrictionTransactionService { return this.getGlobalRestrictionEntry(mosaicId, restrictionKey).pipe( map((restrictionEntry: MosaicGlobalRestrictionItem | undefined) => { const currentValue = restrictionEntry ? UInt64.fromNumericString(restrictionEntry.restrictionValue) : - this.defaultMosaicGlobalRestrictionVaule; + this.defaultMosaicGlobalRestrictionValue; const currentType = restrictionEntry ? restrictionEntry.restrictionType : MosaicRestrictionType.NONE; return MosaicGlobalRestrictionTransaction.create( @@ -110,11 +110,11 @@ export class MosaicRestrictionTransactionService { return this.getGlobalRestrictionEntry(mosaicId, restrictionKey).pipe( switchMap((restrictionEntry: MosaicGlobalRestrictionItem | undefined) => { if (!restrictionEntry) { - throw Error('Global restriction is not valid for RetrictionKey: ' + restrictionKey); + throw Error('Global restriction is not valid for RestrictionKey: ' + restrictionKey); } return this.getAddressRestrictionEntry(mosaicId, restrictionKey, targetAddress).pipe( map((optionalValue) => { - const currentValue = optionalValue ? UInt64.fromNumericString(optionalValue) : this.defaultMosaicAddressRestrictionVaule; + const currentValue = optionalValue ? UInt64.fromNumericString(optionalValue) : this.defaultMosaicAddressRestrictionValue; return MosaicAddressRestrictionTransaction.create( deadline, mosaicId, diff --git a/src/service/MosaicService.ts b/src/service/MosaicService.ts index eedc30e81d..745e07b64b 100644 --- a/src/service/MosaicService.ts +++ b/src/service/MosaicService.ts @@ -24,6 +24,8 @@ import { Mosaic } from '../model/mosaic/Mosaic'; import { MosaicId } from '../model/mosaic/MosaicId'; import { MosaicAmountView } from './MosaicAmountView'; import { MosaicView } from './MosaicView'; +import { AccountRepository } from "../infrastructure/AccountRepository"; +import { MosaicRepository } from "../infrastructure/MosaicRepository"; /** * Mosaic service @@ -32,11 +34,11 @@ export class MosaicService { /** * Constructor - * @param accountHttp - * @param mosaicHttp + * @param accountRepository + * @param mosaicRepository */ - constructor(private readonly accountHttp: AccountHttp, - private readonly mosaicHttp: MosaicHttp) { + constructor(private readonly accountRepository: AccountRepository, + private readonly mosaicRepository: MosaicRepository) { } @@ -47,7 +49,7 @@ export class MosaicService { */ mosaicsView(mosaicIds: MosaicId[]): Observable { return observableOf(mosaicIds).pipe( - mergeMap((_) => this.mosaicHttp.getMosaics(mosaicIds).pipe( + mergeMap((_) => this.mosaicRepository.getMosaics(mosaicIds).pipe( mergeMap((_) => _), map((mosaicInfo: MosaicInfo) => { return new MosaicView(mosaicInfo); @@ -84,7 +86,7 @@ export class MosaicService { */ mosaicsAmountViewFromAddress(address: Address): Observable { return observableOf(address).pipe( - mergeMap((_) => this.accountHttp.getAccountInfo(_)), + mergeMap((_) => this.accountRepository.getAccountInfo(_)), mergeMap((_) => this.mosaicsAmountView(_.mosaics))); } } diff --git a/src/service/NamespaceService.ts b/src/service/NamespaceService.ts index 6327b2c8d6..66337732ae 100644 --- a/src/service/NamespaceService.ts +++ b/src/service/NamespaceService.ts @@ -14,13 +14,13 @@ * limitations under the License. */ -import {Observable} from 'rxjs'; -import {map, mergeMap} from 'rxjs/operators'; -import {NamespaceHttp} from '../infrastructure/NamespaceHttp'; -import {NamespaceId} from '../model/namespace/NamespaceId'; -import {NamespaceInfo} from '../model/namespace/NamespaceInfo'; -import {NamespaceName} from '../model/namespace/NamespaceName'; -import {Namespace} from './Namespace'; +import { Observable } from 'rxjs'; +import { map, mergeMap } from 'rxjs/operators'; +import { NamespaceId } from '../model/namespace/NamespaceId'; +import { NamespaceInfo } from '../model/namespace/NamespaceInfo'; +import { NamespaceName } from '../model/namespace/NamespaceName'; +import { Namespace } from './Namespace'; +import { NamespaceRepository } from "../infrastructure/NamespaceRepository"; /** * Namespace service @@ -29,9 +29,9 @@ export class NamespaceService { /** * Constructor - * @param namespaceHttp + * @param namespaceRepository */ - constructor(private readonly namespaceHttp: NamespaceHttp) { + constructor(private readonly namespaceRepository: NamespaceRepository) { } /** @@ -40,8 +40,8 @@ export class NamespaceService { * @returns {Observable} */ namespace(id: NamespaceId): Observable { - return this.namespaceHttp.getNamespace(id).pipe( - mergeMap((namespaceInfo: NamespaceInfo) => this.namespaceHttp + return this.namespaceRepository.getNamespace(id).pipe( + mergeMap((namespaceInfo: NamespaceInfo) => this.namespaceRepository .getNamespacesName(namespaceInfo.levels).pipe( map((names) => Object.assign( {__proto__: Object.getPrototypeOf(namespaceInfo)}, diff --git a/src/service/TransactionService.ts b/src/service/TransactionService.ts index d0f54ba621..b3ece0259a 100644 --- a/src/service/TransactionService.ts +++ b/src/service/TransactionService.ts @@ -14,11 +14,9 @@ * limitations under the License. */ -import {Observable, of} from 'rxjs'; -import { flatMap, map, mergeMap, toArray} from 'rxjs/operators'; -import { Listener } from '../infrastructure/Listener'; -import { ReceiptHttp } from '../infrastructure/ReceiptHttp'; -import { TransactionHttp } from '../infrastructure/TransactionHttp'; +import { Observable, of } from 'rxjs'; +import { flatMap, map, mergeMap, toArray } from 'rxjs/operators'; +import { IListener } from '../infrastructure/IListener'; import { NamespaceId } from '../model/namespace/NamespaceId'; import { AccountAddressRestrictionTransaction } from '../model/transaction/AccountAddressRestrictionTransaction'; import { AggregateTransaction } from '../model/transaction/AggregateTransaction'; @@ -34,21 +32,21 @@ import { Transaction } from '../model/transaction/Transaction'; import { TransactionType } from '../model/transaction/TransactionType'; import { TransferTransaction } from '../model/transaction/TransferTransaction'; import { ITransactionService } from './interfaces/ITransactionService'; +import { TransactionRepository } from "../infrastructure/TransactionRepository"; +import { ReceiptRepository } from "../infrastructure/ReceiptRepository"; /** * Transaction Service */ export class TransactionService implements ITransactionService { - private readonly transactionHttp: TransactionHttp; - private readonly receiptHttp: ReceiptHttp; /** * Constructor - * @param url Base catapult-rest url + * @param transactionRepository + * @param receiptRepository */ - constructor(url: string) { - this.transactionHttp = new TransactionHttp(url); - this.receiptHttp = new ReceiptHttp(url); + constructor(private readonly transactionRepository: TransactionRepository, + private readonly receiptRepository: ReceiptRepository) { } /** @@ -58,11 +56,11 @@ export class TransactionService implements ITransactionService { * @returns Observable */ public resolveAliases(transationHashes: string[]): Observable { - return this.transactionHttp.getTransactions(transationHashes).pipe( - mergeMap((_) => _), - mergeMap((transaction) => this.resolveTransaction(transaction)), - toArray(), - ); + return this.transactionRepository.getTransactions(transationHashes).pipe( + mergeMap((_) => _), + mergeMap((transaction) => this.resolveTransaction(transaction)), + toArray(), + ); } /** @@ -70,8 +68,8 @@ export class TransactionService implements ITransactionService { * @param listener Websocket listener * @returns {Observable} */ - public announce(signedTransaction: SignedTransaction, listener: Listener): Observable { - return this.transactionHttp.announce(signedTransaction).pipe( + public announce(signedTransaction: SignedTransaction, listener: IListener): Observable { + return this.transactionRepository.announce(signedTransaction).pipe( flatMap(() => listener.confirmed(signedTransaction.getSignerAddress(), signedTransaction.hash)), ); } @@ -83,8 +81,8 @@ export class TransactionService implements ITransactionService { * @param listener Websocket listener * @returns {Observable} */ - public announceAggregateBonded(signedTransaction: SignedTransaction, listener: Listener): Observable { - return this.transactionHttp.announceAggregateBonded(signedTransaction).pipe( + public announceAggregateBonded(signedTransaction: SignedTransaction, listener: IListener): Observable { + return this.transactionRepository.announceAggregateBonded(signedTransaction).pipe( flatMap(() => listener.aggregateBondedAdded(signedTransaction.getSignerAddress(), signedTransaction.hash)), ); } @@ -98,7 +96,7 @@ export class TransactionService implements ITransactionService { */ public announceHashLockAggregateBonded(signedHashLockTransaction: SignedTransaction, signedAggregateTransaction: SignedTransaction, - listener: Listener): Observable { + listener: IListener): Observable { return this.announce(signedHashLockTransaction, listener).pipe( flatMap(() => this.announceAggregateBonded(signedAggregateTransaction, listener)), ); @@ -122,7 +120,7 @@ export class TransactionService implements ITransactionService { /** * @internal - * Check if receiptHttp needs to be called to resolve transaction alias + * Check if receiptRepository needs to be called to resolve transaction alias * @param transaction Transaction * @return {boolean} */ @@ -141,21 +139,21 @@ export class TransactionService implements ITransactionService { case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: const accountAddressRestriction = transaction as AccountAddressRestrictionTransaction; return accountAddressRestriction.restrictionAdditions.find((address) => address instanceof NamespaceId) !== undefined || - accountAddressRestriction.restrictionDeletions.find((address) => address instanceof NamespaceId) !== undefined; + accountAddressRestriction.restrictionDeletions.find((address) => address instanceof NamespaceId) !== undefined; case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: const accountMosaicRestriction = transaction as AccountAddressRestrictionTransaction; return accountMosaicRestriction.restrictionAdditions.find((mosaicId) => mosaicId instanceof NamespaceId) !== undefined || - accountMosaicRestriction.restrictionDeletions.find((mosaicId) => mosaicId instanceof NamespaceId) !== undefined; + accountMosaicRestriction.restrictionDeletions.find((mosaicId) => mosaicId instanceof NamespaceId) !== undefined; case TransactionType.LOCK: return (transaction as LockFundsTransaction).mosaic.id instanceof NamespaceId; case TransactionType.MOSAIC_ADDRESS_RESTRICTION: const mosaicAddressRestriction = transaction as MosaicAddressRestrictionTransaction; return mosaicAddressRestriction.targetAddress instanceof NamespaceId || - mosaicAddressRestriction.mosaicId instanceof NamespaceId; + mosaicAddressRestriction.mosaicId instanceof NamespaceId; case TransactionType.MOSAIC_GLOBAL_RESTRICTION: const mosaicGlobalRestriction = transaction as MosaicGlobalRestrictionTransaction; return mosaicGlobalRestriction.referenceMosaicId instanceof NamespaceId || - mosaicGlobalRestriction.mosaicId instanceof NamespaceId; + mosaicGlobalRestriction.mosaicId instanceof NamespaceId; case TransactionType.MOSAIC_METADATA_TRANSACTION: return (transaction as MosaicMetadataTransaction).targetMosaicId instanceof NamespaceId; case TransactionType.MOSAIC_SUPPLY_CHANGE: @@ -165,25 +163,25 @@ export class TransactionService implements ITransactionService { case TransactionType.SECRET_LOCK: const secretLock = transaction as SecretLockTransaction; return secretLock.recipientAddress instanceof NamespaceId || - secretLock.mosaic.id instanceof NamespaceId; + secretLock.mosaic.id instanceof NamespaceId; case TransactionType.TRANSFER: const transfer = transaction as TransferTransaction; return transfer.recipientAddress instanceof NamespaceId || - transfer.mosaics.find((mosaic) => mosaic.id instanceof NamespaceId) !== undefined; + transfer.mosaics.find((mosaic) => mosaic.id instanceof NamespaceId) !== undefined; default: - throw new Error ('Transaction type not not recogonised.'); + throw new Error('Transaction type not not recogonised.'); } } /** * @internal - * Resolve transaction alais(s) from block receipt by calling receiptHttp + * Resolve transaction alais(s) from block receipt by calling receiptRepository * @param transaction Transaction to be resolved * @param aggregateIndex Aggregate transaction index * @return {Observable} */ private resolvedFromReceipt(transaction: Transaction, aggregateIndex: number): Observable { - return this.receiptHttp.getBlockReceipts(transaction.transactionInfo!.height.toString()).pipe( + return this.receiptRepository.getBlockReceipts(transaction.transactionInfo!.height.toString()).pipe( map((statement) => transaction.resolveAliases(statement, aggregateIndex)), ); } diff --git a/src/service/interfaces/ITransactionService.ts b/src/service/interfaces/ITransactionService.ts index 43bd0ae7fa..a6a7951804 100644 --- a/src/service/interfaces/ITransactionService.ts +++ b/src/service/interfaces/ITransactionService.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import {Observable} from 'rxjs'; -import { Listener } from '../../infrastructure/Listener'; +import { Observable } from 'rxjs'; +import { IListener } from '../../infrastructure/IListener'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; import { SignedTransaction } from '../../model/transaction/SignedTransaction'; import { Transaction } from '../../model/transaction/Transaction'; @@ -26,17 +26,17 @@ import { Transaction } from '../../model/transaction/Transaction'; export interface ITransactionService { /** - * @param transationHashes List of transaction hashes. + * @param transactionHashes List of transaction hashes. * @returns {Observable} */ - resolveAliases(transationHashes: string[]): Observable; + resolveAliases(transactionHashes: string[]): Observable; /** * @param signedTransaction Signed transaction to be announced. * @param listener Websocket listener * @returns {Observable} */ - announce(signedTransaction: SignedTransaction, listener: Listener): Observable; + announce(signedTransaction: SignedTransaction, listener: IListener): Observable; /** * Announce aggregate transaction @@ -44,7 +44,7 @@ export interface ITransactionService { * @param listener Websocket listener * @returns {Observable} */ - announceAggregateBonded(signedTransaction: SignedTransaction, listener: Listener): Observable; + announceAggregateBonded(signedTransaction: SignedTransaction, listener: IListener): Observable; /** * Announce aggregate bonded transaction with lock fund @@ -55,5 +55,5 @@ export interface ITransactionService { */ announceHashLockAggregateBonded(signedHashLockTransaction: SignedTransaction, signedAggregateTransaction: SignedTransaction, - listener: Listener): Observable; + listener: IListener): Observable; } diff --git a/test/infrastructure/RepositoryFactory.spec.ts b/test/infrastructure/RepositoryFactory.spec.ts new file mode 100644 index 0000000000..6199559a27 --- /dev/null +++ b/test/infrastructure/RepositoryFactory.spec.ts @@ -0,0 +1,155 @@ +/* + * Copyright 2019 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from "chai"; +import { RepositoryFactoryHttp } from "../../src/infrastructure/RepositoryFactoryHttp"; +import { BlockRepository } from "../../src/infrastructure/BlockRepository"; +import { instance, mock, when } from "ts-mockito"; +import { BlockInfo } from "../../src/model/blockchain/BlockInfo"; +import { of as observableOf } from 'rxjs'; +import { map } from "rxjs/operators"; +import { NetworkRepository } from "../../src/infrastructure/NetworkRepository"; +import { NetworkType } from "../../src/model/blockchain/NetworkType"; + +describe('RepositoryFactory', () => { + it('Should create repositories', () => { + const repositoryFactory = new RepositoryFactoryHttp("http://localhost:3000"); + + expect(repositoryFactory.createBlockRepository()).to.be.not.null; + expect(repositoryFactory.createNetworkRepository()).to.be.not.null; + expect(repositoryFactory.createNamespaceRepository()).to.be.not.null; + expect(repositoryFactory.createAccountRepository()).to.be.not.null; + expect(repositoryFactory.createChainRepository()).to.be.not.null; + expect(repositoryFactory.createDiagnosticRepository()).to.be.not.null; + expect(repositoryFactory.createMetadataRepository()).to.be.not.null; + expect(repositoryFactory.createMosaicRepository()).to.be.not.null; + expect(repositoryFactory.createMultisigRepository()).to.be.not.null; + expect(repositoryFactory.createNodeRepository()).to.be.not.null; + expect(repositoryFactory.createReceiptRepository()).to.be.not.null; + expect(repositoryFactory.createRestrictionAccountRepository()).to.be.not.null; + expect(repositoryFactory.createRestrictionMosaicRepository()).to.be.not.null; + expect(repositoryFactory.createTransactionRepository()).to.be.not.null; + + }); + + it('Should get GenerationHash from cache', (done) => { + + let counter = 0; + + const repositoryMock: BlockRepository = mock(); + + const observableOfBlockInfo = observableOf({generationHash: 'aaaa'} as BlockInfo).pipe(map(v => { + counter++; + return v; + })); + when(repositoryMock.getBlockByHeight('1')).thenReturn(observableOfBlockInfo); + + expect(observableOfBlockInfo).to.be.equals(observableOfBlockInfo); + + const repositoryFactory = new (class RepositoryFactoryHttpForTest extends RepositoryFactoryHttp { + + createBlockRepository(): BlockRepository { + return instance(repositoryMock); + } + })("http://localhost:3000"); + + expect(counter).to.be.equals(0); + repositoryFactory.getGenerationHash().subscribe(gh => { + expect(counter).to.be.equals(1); + expect(gh).to.be.equals('aaaa'); + repositoryFactory.getGenerationHash().subscribe(gh => { + expect(counter).to.be.equals(1); + expect(gh).to.be.equals('aaaa'); + repositoryFactory.getGenerationHash().subscribe(gh => { + expect(counter).to.be.equals(1); + expect(gh).to.be.equals('aaaa'); + done(); + }) + }) + }) + + }); + + it('Should get NetworkType from cache', (done) => { + + let counter = 0; + + const repositoryMock: NetworkRepository = mock(); + + let expectedNetworkType = NetworkType.MIJIN_TEST; + const observableOfBlockInfo = observableOf(expectedNetworkType).pipe(map(v => { + counter++; + return v; + })); + when(repositoryMock.getNetworkType()).thenReturn(observableOfBlockInfo); + + expect(observableOfBlockInfo).to.be.equals(observableOfBlockInfo); + + const repositoryFactory = new (class RepositoryFactoryHttpForTest extends RepositoryFactoryHttp { + + createNetworkRepository(): NetworkRepository { + return instance(repositoryMock); + } + })("http://localhost:3000"); + + expect(counter).to.be.equals(0); + repositoryFactory.getNetworkType().subscribe(networkType => { + expect(counter).to.be.equals(1); + expect(networkType).to.be.equals(expectedNetworkType); + repositoryFactory.getNetworkType().subscribe(networkType => { + expect(counter).to.be.equals(1); + expect(networkType).to.be.equals(expectedNetworkType); + done(); + }) + }) + + }); + + it('Should get NetworkType from memory', (done) => { + + let counter = 0; + + const repositoryMock: NetworkRepository = mock(); + + let expectedNetworkType = NetworkType.MIJIN_TEST; + const observableOfBlockInfo = observableOf(expectedNetworkType).pipe(map(v => { + counter++; + return v; + })); + when(repositoryMock.getNetworkType()).thenReturn(observableOfBlockInfo); + + expect(observableOfBlockInfo).to.be.equals(observableOfBlockInfo); + + const repositoryFactory = new (class RepositoryFactoryHttpForTest extends RepositoryFactoryHttp { + + createNetworkRepository(): NetworkRepository { + return instance(repositoryMock); + } + })("http://localhost:3000", expectedNetworkType); + + expect(counter).to.be.equals(0); + repositoryFactory.getNetworkType().subscribe(networkType => { + expect(counter).to.be.equals(0); + expect(networkType).to.be.equals(expectedNetworkType); + repositoryFactory.getNetworkType().subscribe(networkType => { + expect(counter).to.be.equals(0); + expect(networkType).to.be.equals(expectedNetworkType); + done(); + }) + }) + + }); + +}); diff --git a/e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts b/test/infrastructure/transaction/CreateTransactionFromDTO.spec.ts similarity index 99% rename from e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts rename to test/infrastructure/transaction/CreateTransactionFromDTO.spec.ts index e976235d46..dc7d4b9307 100644 --- a/e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts +++ b/test/infrastructure/transaction/CreateTransactionFromDTO.spec.ts @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {deepEqual} from 'assert'; -import {expect} from 'chai'; -import {CreateTransactionFromDTO} from '../../../src/infrastructure/transaction/CreateTransactionFromDTO'; +import { deepEqual } from 'assert'; +import { expect } from 'chai'; +import { CreateTransactionFromDTO } from '../../../src/infrastructure/transaction/CreateTransactionFromDTO'; import { Address } from '../../../src/model/account/Address'; import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction'; import ValidateTransaction from './ValidateTransaction'; diff --git a/e2e/infrastructure/transaction/ValidateTransaction.ts b/test/infrastructure/transaction/ValidateTransaction.ts similarity index 93% rename from e2e/infrastructure/transaction/ValidateTransaction.ts rename to test/infrastructure/transaction/ValidateTransaction.ts index 09bf1cd4ba..ac2b2b1e80 100644 --- a/e2e/infrastructure/transaction/ValidateTransaction.ts +++ b/test/infrastructure/transaction/ValidateTransaction.ts @@ -14,16 +14,13 @@ * limitations under the License. */ -import {deepEqual} from 'assert'; -import {expect} from 'chai'; -import {Address} from '../../../src/model/account/Address'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; -import { NetworkType } from '../../../src/model/blockchain/NetworkType'; +import { deepEqual } from 'assert'; +import { expect } from 'chai'; +import { Address } from '../../../src/model/account/Address'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; -import {MultisigCosignatoryModification} from '../../../src/model/transaction/MultisigCosignatoryModification'; -import {TransactionType} from '../../../src/model/transaction/TransactionType'; -import {UInt64} from '../../../src/model/UInt64'; +import { TransactionType } from '../../../src/model/transaction/TransactionType'; +import { UInt64 } from '../../../src/model/UInt64'; const ValidateTransaction = { validateStandaloneTx: (transaction, transactionDTO) => { diff --git a/test/model/transaction/Deadline.spec.ts b/test/model/transaction/Deadline.spec.ts index 45152760a2..1865350b01 100644 --- a/test/model/transaction/Deadline.spec.ts +++ b/test/model/transaction/Deadline.spec.ts @@ -53,10 +53,13 @@ describe('Deadline', () => { it('make sure epochAdjustment is correct', () => { const epochAdjustment = new Date(Deadline.timestampNemesisBlock * 1000); - expect(epochAdjustment.getFullYear()).to.be.equal(2019); - expect(epochAdjustment.getMonth() + 1).to.be.equal(11); - expect(epochAdjustment.getDate()).to.be.equal(11); - expect(epochAdjustment.getHours()).to.be.equal(0); - expect(epochAdjustment.getMinutes()).to.be.equal(0); + console.log(epochAdjustment.toUTCString()); + + expect(epochAdjustment.getUTCFullYear()).to.be.equal(2019); + expect(epochAdjustment.getUTCMonth() + 1).to.be.equal(11); + expect(epochAdjustment.getUTCDate()).to.be.equal(11); + expect(epochAdjustment.getUTCHours()).to.be.equal(0); + expect(epochAdjustment.getUTCMinutes()).to.be.equal(0); + expect(epochAdjustment.toUTCString()).to.be.equal("Mon, 11 Nov 2019 00:00:00 GMT"); }); }); diff --git a/test/service/AggregateTransactionService.spec.ts b/test/service/AggregateTransactionService.spec.ts index ea02e713a8..1f3f16a2b0 100644 --- a/test/service/AggregateTransactionService.spec.ts +++ b/test/service/AggregateTransactionService.spec.ts @@ -18,7 +18,8 @@ import { expect } from 'chai'; import { ChronoUnit } from 'js-joda'; import {of as observableOf} from 'rxjs'; import {deepEqual, instance, mock, when} from 'ts-mockito'; -import { MultisigHttp } from '../../src/infrastructure/MultisigHttp'; +import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; + import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { MultisigAccountGraphInfo } from '../../src/model/account/MultisigAccountGraphInfo'; @@ -75,27 +76,27 @@ describe('AggregateTransactionService', () => { const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { - const mockedAccountHttp = mock(MultisigHttp); + const mockedAccountRepository:MultisigRepository = mock(); - when(mockedAccountHttp.getMultisigAccountInfo(deepEqual(account1.address))) + when(mockedAccountRepository.getMultisigAccountInfo(deepEqual(account1.address))) .thenReturn(observableOf(givenAccount1Info())); - when(mockedAccountHttp.getMultisigAccountInfo(deepEqual(account4.address))) + when(mockedAccountRepository.getMultisigAccountInfo(deepEqual(account4.address))) .thenReturn(observableOf(givenAccount4Info())); - when(mockedAccountHttp.getMultisigAccountInfo(deepEqual(multisig2.address))) + when(mockedAccountRepository.getMultisigAccountInfo(deepEqual(multisig2.address))) .thenReturn(observableOf(givenMultisig2AccountInfo())); - when(mockedAccountHttp.getMultisigAccountInfo(deepEqual(multisig3.address))) + when(mockedAccountRepository.getMultisigAccountInfo(deepEqual(multisig3.address))) .thenReturn(observableOf(givenMultisig3AccountInfo())); - when(mockedAccountHttp.getMultisigAccountGraphInfo(deepEqual(multisig2.address))) + when(mockedAccountRepository.getMultisigAccountGraphInfo(deepEqual(multisig2.address))) .thenReturn(observableOf(givenMultisig2AccountGraphInfo())); - when(mockedAccountHttp.getMultisigAccountGraphInfo(deepEqual(multisig3.address))) + when(mockedAccountRepository.getMultisigAccountGraphInfo(deepEqual(multisig3.address))) .thenReturn(observableOf(givenMultisig3AccountGraphInfo())); - when(mockedAccountHttp.getMultisigAccountInfo(deepEqual(account2.address))) + when(mockedAccountRepository.getMultisigAccountInfo(deepEqual(account2.address))) .thenReturn(observableOf(givenAccount2Info())); - when(mockedAccountHttp.getMultisigAccountInfo(deepEqual(account3.address))) + when(mockedAccountRepository.getMultisigAccountInfo(deepEqual(account3.address))) .thenReturn(observableOf(givenAccount3Info())); - const accountHttp = instance(mockedAccountHttp); - aggregateTransactionService = new AggregateTransactionService(accountHttp); + const accountRepository = instance(mockedAccountRepository); + aggregateTransactionService = new AggregateTransactionService(accountRepository); }); it('should return isComplete: true for aggregated complete transaction - 2 levels Multisig', () => { diff --git a/test/service/MetadataTransactionservice.spec.ts b/test/service/MetadataTransactionservice.spec.ts index f5ef326dd2..93cb7dd7ba 100644 --- a/test/service/MetadataTransactionservice.spec.ts +++ b/test/service/MetadataTransactionservice.spec.ts @@ -14,24 +14,24 @@ * limitations under the License. */ -import {expect} from 'chai'; -import {of as observableOf} from 'rxjs'; -import {deepEqual, instance, mock, when} from 'ts-mockito'; +import { expect } from 'chai'; +import { of as observableOf } from 'rxjs'; +import { deepEqual, instance, mock, when } from 'ts-mockito'; import { Convert } from '../../src/core/format/Convert'; -import { MetadataHttp } from '../../src/infrastructure/MetadataHttp'; +import { MetadataRepository } from '../../src/infrastructure/MetadataRepository'; import { Account } from '../../src/model/account/Account'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { Metadata } from '../../src/model/metadata/Metadata'; import { MetadataEntry } from '../../src/model/metadata/MetadataEntry'; import { MetadataType } from '../../src/model/metadata/MetadataType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; -import {NamespaceId} from '../../src/model/namespace/NamespaceId'; +import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetadataTransaction'; import { TransactionType } from '../../src/model/transaction/TransactionType'; -import {UInt64} from '../../src/model/UInt64'; +import { UInt64 } from '../../src/model/UInt64'; import { MetadataTransactionService } from '../../src/service/MetadataTransactionService'; import { TestingAccount } from '../conf/conf.spec'; @@ -45,19 +45,19 @@ describe('MetadataTransactionService', () => { before(() => { account = TestingAccount; - const mockMetadataHttp = mock(MetadataHttp); + const mockMetadataRepository:MetadataRepository = mock(); - when(mockMetadataHttp + when(mockMetadataRepository .getAccountMetadataByKeyAndSender(deepEqual(account.address), key.toHex(), account.publicKey)) .thenReturn(observableOf(mockMetadata(MetadataType.Account))); - when(mockMetadataHttp + when(mockMetadataRepository .getMosaicMetadataByKeyAndSender(deepEqual(new MosaicId(targetIdHex)), key.toHex(), account.publicKey)) .thenReturn(observableOf(mockMetadata(MetadataType.Mosaic))); - when(mockMetadataHttp + when(mockMetadataRepository .getNamespaceMetadataByKeyAndSender(deepEqual(NamespaceId.createFromEncoded(targetIdHex)), key.toHex(), account.publicKey)) .thenReturn(observableOf(mockMetadata(MetadataType.Namespace))); - const metadataHttp = instance(mockMetadataHttp); - metadataTransactionService = new MetadataTransactionService(metadataHttp); + const metadataRepository = instance(mockMetadataRepository); + metadataTransactionService = new MetadataTransactionService(metadataRepository); }); it('should create AccountMetadataTransaction', (done) => { diff --git a/test/service/MosaicRestrictionTransactionservice.spec.ts b/test/service/MosaicRestrictionTransactionservice.spec.ts index 318bfb804f..11883af3bc 100644 --- a/test/service/MosaicRestrictionTransactionservice.spec.ts +++ b/test/service/MosaicRestrictionTransactionservice.spec.ts @@ -18,7 +18,7 @@ import { expect } from 'chai'; import { of as observableOf } from 'rxjs'; import { deepEqual, instance, mock, when } from 'ts-mockito'; import { KeyGenerator } from '../../src/core/format/KeyGenerator'; -import { RestrictionMosaicRepository } from '../../src/infrastructure/RestrictionMosaicRespository'; +import { RestrictionMosaicRepository } from '../../src/infrastructure/RestrictionMosaicRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; @@ -63,8 +63,8 @@ describe('MosaicRestrictionTransactionService', () => { when(mockRestrictionRepository .getMosaicAddressRestriction(deepEqual(mosaicId), deepEqual(account.address))) .thenReturn(observableOf(mockAddressRestriction())); - const restrictionHttp = instance(mockRestrictionRepository); - mosaicRestrictionTransactionService = new MosaicRestrictionTransactionService(restrictionHttp); + const restrictionRepository = instance(mockRestrictionRepository); + mosaicRestrictionTransactionService = new MosaicRestrictionTransactionService(restrictionRepository); }); it('should create MosaicGlobalRestriction Transaction', (done) => { diff --git a/test/service/NamespaceService.spec.ts b/test/service/NamespaceService.spec.ts index 1075d76a0d..0bce6222c6 100644 --- a/test/service/NamespaceService.spec.ts +++ b/test/service/NamespaceService.spec.ts @@ -14,62 +14,62 @@ * limitations under the License. */ -import {expect} from 'chai'; -import {Observable, of as observableOf} from 'rxjs'; -import {deepEqual, instance, mock, when} from 'ts-mockito'; -import {NamespaceHttp} from '../../src/infrastructure/NamespaceHttp'; -import {PublicAccount} from '../../src/model/account/PublicAccount'; -import {NetworkType} from '../../src/model/blockchain/NetworkType'; -import {EmptyAlias} from '../../src/model/namespace/EmptyAlias'; -import {NamespaceId} from '../../src/model/namespace/NamespaceId'; -import {NamespaceInfo} from '../../src/model/namespace/NamespaceInfo'; -import {NamespaceName} from '../../src/model/namespace/NamespaceName'; -import {UInt64} from '../../src/model/UInt64'; -import {NamespaceService} from '../../src/service/NamespaceService'; +import { expect } from 'chai'; +import { of as observableOf } from 'rxjs'; +import { deepEqual, instance, mock, when } from 'ts-mockito'; +import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; +import { EmptyAlias } from '../../src/model/namespace/EmptyAlias'; +import { NamespaceId } from '../../src/model/namespace/NamespaceId'; +import { NamespaceInfo } from '../../src/model/namespace/NamespaceInfo'; +import { NamespaceName } from '../../src/model/namespace/NamespaceName'; +import { UInt64 } from '../../src/model/UInt64'; +import { NamespaceService } from '../../src/service/NamespaceService'; describe('NamespaceService', () => { it('should return the NamespaceInfo + name for a root namespace', () => { - const mockedNamespaceHttp = mock(NamespaceHttp); + const mockedNamespaceRepository:NamespaceRepository = mock(); const rootNamespace = givenRootNamespace(); const subnamespace = givenSubnamespace(); - when(mockedNamespaceHttp.getNamespace(rootNamespace.id)) + when(mockedNamespaceRepository.getNamespace(rootNamespace.id)) .thenReturn(observableOf(rootNamespace)); - when(mockedNamespaceHttp.getNamespace(subnamespace.id)) + when(mockedNamespaceRepository.getNamespace(subnamespace.id)) .thenReturn(observableOf(subnamespace)); - when(mockedNamespaceHttp.getNamespacesName(deepEqual([rootNamespace.id]))) + when(mockedNamespaceRepository.getNamespacesName(deepEqual([rootNamespace.id]))) .thenReturn(observableOf([new NamespaceName(new NamespaceId([3316183705, 3829351378]), 'nem2tests')])); - when(mockedNamespaceHttp.getNamespacesName(deepEqual([rootNamespace.id, subnamespace.id]))) + when(mockedNamespaceRepository.getNamespacesName(deepEqual([rootNamespace.id, subnamespace.id]))) .thenReturn(observableOf([ new NamespaceName(new NamespaceId([3316183705, 3829351378]), 'nem2tests'), new NamespaceName(new NamespaceId([1781696705, 4157485863]), 'level2'), ])); - const namespaceHttp = instance(mockedNamespaceHttp); - const namespaceService = new NamespaceService(namespaceHttp); + const namespaceRepository = instance(mockedNamespaceRepository); + const namespaceService = new NamespaceService(namespaceRepository); namespaceService.namespace(rootNamespace.id).subscribe((namespace) => { expect(namespace.name).to.be.equal('nem2tests'); }); }); it('should return the NamespaceInfo + name for a subnamespace', () => { - const mockedNamespaceHttp = mock(NamespaceHttp); + const mockedNamespaceRepository:NamespaceRepository = mock(); const rootNamespace = givenRootNamespace(); const subnamespace = givenSubnamespace(); - when(mockedNamespaceHttp.getNamespace(rootNamespace.id)) + when(mockedNamespaceRepository.getNamespace(rootNamespace.id)) .thenReturn(observableOf(rootNamespace)); - when(mockedNamespaceHttp.getNamespace(subnamespace.id)) + when(mockedNamespaceRepository.getNamespace(subnamespace.id)) .thenReturn(observableOf(subnamespace)); - when(mockedNamespaceHttp.getNamespacesName(deepEqual([rootNamespace.id]))) + when(mockedNamespaceRepository.getNamespacesName(deepEqual([rootNamespace.id]))) .thenReturn(observableOf([new NamespaceName(new NamespaceId([3316183705, 3829351378]), 'nem2tests')])); - when(mockedNamespaceHttp.getNamespacesName(deepEqual([subnamespace.id]))) + when(mockedNamespaceRepository.getNamespacesName(deepEqual([subnamespace.id]))) .thenReturn(observableOf([new NamespaceName(new NamespaceId([1781696705, 4157485863]), 'level2')])); - when(mockedNamespaceHttp.getNamespacesName(deepEqual([rootNamespace.id, subnamespace.id]))) + when(mockedNamespaceRepository.getNamespacesName(deepEqual([rootNamespace.id, subnamespace.id]))) .thenReturn(observableOf([ new NamespaceName(new NamespaceId([3316183705, 3829351378]), 'nem2tests'), new NamespaceName(new NamespaceId([1781696705, 4157485863]), 'level2'), ])); - const namespaceHttp = instance(mockedNamespaceHttp); - const namespaceService = new NamespaceService(namespaceHttp); + const namespaceRepository = instance(mockedNamespaceRepository); + const namespaceService = new NamespaceService(namespaceRepository); namespaceService.namespace(subnamespace.id).subscribe((namespace) => { expect(namespace.name).to.be.equal('nem2tests.level2');