From 3cb4b11164ba33c6b4ba353390090d310ee49f36 Mon Sep 17 00:00:00 2001 From: Fernando Boucquez Date: Fri, 31 Jan 2020 16:31:58 -0300 Subject: [PATCH] E2E test improvements by replacing done callbacks with async/await/promises when possible --- e2e/infrastructure/AccountHttp.spec.ts | 78 +++----- e2e/infrastructure/BlockHttp.spec.ts | 92 ++++----- e2e/infrastructure/ChainHttp.spec.ts | 22 +-- e2e/infrastructure/DiagnosticHttp.spec.ts | 24 +-- e2e/infrastructure/IntegrationTestHelper.ts | 9 +- e2e/infrastructure/Listener.spec.ts | 26 +-- e2e/infrastructure/MetadataHttp.spec.ts | 183 ++++++++---------- e2e/infrastructure/MosaicHttp.spec.ts | 58 +++--- e2e/infrastructure/NamespaceHttp.spec.ts | 56 ++---- e2e/infrastructure/NetworkHttp.spec.ts | 20 +- e2e/infrastructure/NodeHttp.spec.ts | 32 ++- e2e/infrastructure/RestrictionHttp.spec.ts | 88 ++++----- e2e/infrastructure/TransactionHttp.spec.ts | 136 +++++-------- e2e/infrastructure/UnresolvedMapping.spec.ts | 7 +- .../MetadataTransactionService.spec.ts | 125 +++++------- ...osaicRestrictionTransactionService.spec.ts | 39 ++-- e2e/service/MosaicService.spec.ts | 7 +- e2e/service/TransactionService.spec.ts | 61 +++--- ...TransactionService_AggregateBonded.spec.ts | 41 ++-- 19 files changed, 439 insertions(+), 665 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index c2fdfbb6bb..e559ed7152 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { assert, expect } from 'chai'; +import { expect } from 'chai'; import { AccountRepository } from '../../src/infrastructure/AccountRepository'; import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; @@ -171,59 +171,42 @@ describe('AccountHttp', () => { */ describe('getAccountInfo', () => { - it('should return account data given a NEM Address', (done) => { - accountRepository.getAccountInfo(accountAddress) - .subscribe((accountInfo) => { - expect(accountInfo.publicKey).to.be.equal(accountPublicKey); - done(); - }); + it('should return account data given a NEM Address', async () => { + const accountInfo = await accountRepository.getAccountInfo(accountAddress).toPromise(); + expect(accountInfo.publicKey).to.be.equal(accountPublicKey); }); }); describe('getAccountsInfo', () => { - it('should return account data given a NEM Address', (done) => { - accountRepository.getAccountsInfo([accountAddress]) - .subscribe((accountsInfo) => { - expect(accountsInfo[0].publicKey).to.be.equal(accountPublicKey); - done(); - }); + it('should return account data given a NEM Address', async () => { + const accountsInfo = await accountRepository.getAccountsInfo([accountAddress]).toPromise(); + expect(accountsInfo[0].publicKey).to.be.equal(accountPublicKey); }); }); describe('getMultisigAccountGraphInfo', () => { - it('should call getMultisigAccountGraphInfo successfully', (done) => { - multisigRepository.getMultisigAccountGraphInfo(multisigAccount.publicAccount.address).subscribe((multisigAccountGraphInfo) => { - expect(multisigAccountGraphInfo.multisigAccounts.get(0)![0].account.publicKey).to.be.equal(multisigAccount.publicKey); - done(); - }); + it('should call getMultisigAccountGraphInfo successfully', async () => { + const multisigAccountGraphInfo = await multisigRepository.getMultisigAccountGraphInfo(multisigAccount.publicAccount.address).toPromise(); + expect(multisigAccountGraphInfo.multisigAccounts.get(0)![0].account.publicKey).to.be.equal(multisigAccount.publicKey); }); }); describe('getMultisigAccountInfo', () => { - it('should call getMultisigAccountInfo successfully', (done) => { - multisigRepository.getMultisigAccountInfo(multisigAccount.publicAccount.address).subscribe((multisigAccountInfo) => { - expect(multisigAccountInfo.account.publicKey).to.be.equal(multisigAccount.publicKey); - done(); - }); + it('should call getMultisigAccountInfo successfully', async () => { + const multisigAccountInfo = await multisigRepository.getMultisigAccountInfo(multisigAccount.publicAccount.address).toPromise(); + expect(multisigAccountInfo.account.publicKey).to.be.equal(multisigAccount.publicKey); }); }); describe('outgoingTransactions', () => { - it('should call outgoingTransactions successfully', (done) => { - accountRepository.getAccountOutgoingTransactions(publicAccount.address).subscribe((transactions) => { - expect(transactions.length).to.be.greaterThan(0); - done(); - }); + it('should call outgoingTransactions successfully', async () => { + const transactions = await accountRepository.getAccountOutgoingTransactions(publicAccount.address).toPromise(); + expect(transactions.length).to.be.greaterThan(0); }); }); describe('aggregateBondedTransactions', () => { - it('should call aggregateBondedTransactions successfully', (done) => { - accountRepository.getAccountPartialTransactions(publicAccount.address).subscribe(() => { - done(); - }, (error) => { - console.log('Error:', error); - assert(false); - }); + it('should call aggregateBondedTransactions successfully', async () => { + await accountRepository.getAccountPartialTransactions(publicAccount.address).toPromise(); }); }); @@ -243,7 +226,6 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should call transactions successfully by type', async () => { const transactions = await accountRepository.getAccountTransactions(publicAccount.address, {transactionType: TransactionType.TRANSFER} as QueryParams).toPromise(); - expect(transactions.length).to.be.greaterThan(0); transactions.forEach((t) => { expect(t.type).to.be.eq(TransactionType.TRANSFER); @@ -252,29 +234,23 @@ describe('AccountHttp', () => { }); describe('transactions', () => { - it('should call transactions successfully', (done) => { - accountRepository.getAccountTransactions(publicAccount.address).subscribe((transactions) => { - expect(transactions.length).to.be.greaterThan(0); - done(); - }); + it('should call transactions successfully', async () => { + const transactions = await accountRepository.getAccountTransactions(publicAccount.address).toPromise(); + expect(transactions.length).to.be.greaterThan(0); }); }); describe('unconfirmedTransactions', () => { - it('should call unconfirmedTransactions successfully', (done) => { - accountRepository.getAccountUnconfirmedTransactions(publicAccount.address).subscribe((transactions) => { - expect(transactions.length).to.be.equal(0); - done(); - }); + it('should call unconfirmedTransactions successfully', async () => { + const transactions = await accountRepository.getAccountUnconfirmedTransactions(publicAccount.address).toPromise(); + expect(transactions.length).to.be.equal(0); }); }); describe('getAddressNames', () => { - it('should call getAddressNames successfully', (done) => { - namespaceRepository.getAccountsNames([accountAddress]).subscribe((addressNames) => { - expect(addressNames.length).to.be.greaterThan(0); - done(); - }); + it('should call getAddressNames successfully', async () => { + const addressNames = await namespaceRepository.getAccountsNames([accountAddress]).toPromise(); + expect(addressNames.length).to.be.greaterThan(0); }); }); diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index 70049078f4..a39b95530e 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -69,7 +69,7 @@ describe('BlockHttp', () => { describe('Setup Test Data', () => { - it('Announce TransferTransaction', (done) => { + it('Announce TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, @@ -79,25 +79,23 @@ describe('BlockHttp', () => { helper.maxFee, ); const signedTransaction = transferTransaction.signWith(account, generationHash); - helper.announce(signedTransaction).then((transaction) => { + return helper.announce(signedTransaction).then((transaction) => { chainHeight = transaction.transactionInfo!.height.toString(); - done(); + return chainHeight; }); }); }); describe('getBlockByHeight', () => { - it('should return block info given height', (done) => { - blockRepository.getBlockByHeight(UInt64.fromUint(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(); - }); + it('should return block info given height', async () => { + const blockInfo = await blockRepository.getBlockByHeight(UInt64.fromUint(1)).toPromise(); + 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); + }); }); @@ -105,50 +103,38 @@ describe('BlockHttp', () => { let nextId: string; let firstId: string; - it('should return block transactions data given height', (done) => { - blockRepository.getBlockTransactions(UInt64.fromUint(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', async () => { + const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1)).toPromise(); + nextId = transactions[0].transactionInfo!.id; + firstId = transactions[1].transactionInfo!.id; + expect(transactions.length).to.be.greaterThan(0); }); - it('should return block transactions data given height with paginated transactionId', (done) => { - blockRepository.getBlockTransactions(UInt64.fromUint(1), new QueryParams(10, nextId)) - .subscribe((transactions) => { - expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); - expect(transactions.length).to.be.greaterThan(0); - done(); - }); + it('should return block transactions data given height with paginated transactionId', async () => { + const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1), new QueryParams(10, nextId)).toPromise(); + expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); + expect(transactions.length).to.be.greaterThan(0); }); }); describe('getBlocksByHeightWithLimit', () => { - it('should return block info given height and limit', (done) => { - blockRepository.getBlocksByHeightWithLimit(chainHeight, 50) - .subscribe((blocksInfo) => { - expect(blocksInfo.length).to.be.greaterThan(0); - done(); - }); + it('should return block info given height and limit', async () => { + const blocksInfo = await blockRepository.getBlocksByHeightWithLimit(chainHeight, 50).toPromise(); + expect(blocksInfo.length).to.be.greaterThan(0); }); }); describe('getMerkleReceipts', () => { - it('should return Merkle Receipts', (done) => { - receiptRepository.getBlockReceipts(chainHeight).pipe( + it('should return Merkle Receipts', async () => { + const merkleReceipts = await receiptRepository.getBlockReceipts(chainHeight).pipe( mergeMap((_) => { return receiptRepository.getMerkleReceipts(chainHeight, _.transactionStatements[0].generateHash()); - })) - .subscribe((merkleReceipts) => { - expect(merkleReceipts.merklePath).not.to.be.null; - done(); - }); + })).toPromise(); + expect(merkleReceipts.merklePath).not.to.be.null; }); }); describe('getMerkleTransaction', () => { - it('should return Merkle Transaction', (done) => { - blockRepository.getBlockTransactions(chainHeight).pipe( + it('should return Merkle Transaction', async () => { + const merkleTransactionss = await blockRepository.getBlockTransactions(chainHeight).pipe( mergeMap((_) => { const hash = (_[0].transactionInfo as TransactionInfo).hash; if (hash) { @@ -156,22 +142,16 @@ describe('BlockHttp', () => { } // 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(); - }); + })).toPromise(); + expect(merkleTransactionss.merklePath).not.to.be.null; }); }); describe('getBlockReceipts', () => { - it('should return block receipts', (done) => { - receiptRepository.getBlockReceipts(chainHeight) - .subscribe((statement) => { - expect(statement.transactionStatements).not.to.be.null; - expect(statement.transactionStatements.length).to.be.greaterThan(0); - done(); - }); + it('should return block receipts', async () => { + const statement = await receiptRepository.getBlockReceipts(chainHeight).toPromise(); + expect(statement.transactionStatements).not.to.be.null; + expect(statement.transactionStatements.length).to.be.greaterThan(0); }); }); }); diff --git a/e2e/infrastructure/ChainHttp.spec.ts b/e2e/infrastructure/ChainHttp.spec.ts index 59eb1984cd..00fe8eb953 100644 --- a/e2e/infrastructure/ChainHttp.spec.ts +++ b/e2e/infrastructure/ChainHttp.spec.ts @@ -29,24 +29,18 @@ describe('ChainHttp', () => { }); describe('getBlockchainHeight', () => { - it('should return blockchain height', (done) => { - chainRepository.getBlockchainHeight() - .subscribe((height) => { - expect(height.lower).to.be.greaterThan(0); - done(); - }); + it('should return blockchain height', async () => { + const height = await chainRepository.getBlockchainHeight().toPromise(); + expect(height.lower).to.be.greaterThan(0); }); }); describe('getBlockchainScore', () => { - it('should return blockchain score', (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(); - }); + it('should return blockchain score', async () => { + const blockchainScore = await chainRepository.getChainScore().toPromise(); + expect(blockchainScore.scoreLow).to.not.be.equal(undefined); + expect(blockchainScore.scoreHigh.lower).to.be.equal(0); + expect(blockchainScore.scoreHigh.higher).to.be.equal(0); }); }); }); diff --git a/e2e/infrastructure/DiagnosticHttp.spec.ts b/e2e/infrastructure/DiagnosticHttp.spec.ts index 70e9dff83b..1b3d48154f 100644 --- a/e2e/infrastructure/DiagnosticHttp.spec.ts +++ b/e2e/infrastructure/DiagnosticHttp.spec.ts @@ -29,25 +29,19 @@ describe('DiagnosticHttp', () => { }); describe('getDiagnosticStorage', () => { - it('should return diagnostic storage', (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(); - }); + it('should return diagnostic storage', async () => { + const blockchainStorageInfo = await diagnosticRepository.getDiagnosticStorage().toPromise(); + expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0); + expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0); + expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0); }); }); describe('getServerInfo', () => { - it('should return diagnostic storage', (done) => { - diagnosticRepository.getServerInfo() - .subscribe((serverInfo) => { - expect(serverInfo.restVersion).not.to.be.null; - expect(serverInfo.sdkVersion).not.to.be.null; - done(); - }); + it('should return diagnostic storage', async () => { + const serverInfo = await diagnosticRepository.getServerInfo().toPromise(); + expect(serverInfo.restVersion).not.to.be.null; + expect(serverInfo.sdkVersion).not.to.be.null; }); }); }); diff --git a/e2e/infrastructure/IntegrationTestHelper.ts b/e2e/infrastructure/IntegrationTestHelper.ts index a8dba96d4d..0e3fc02228 100644 --- a/e2e/infrastructure/IntegrationTestHelper.ts +++ b/e2e/infrastructure/IntegrationTestHelper.ts @@ -73,13 +73,14 @@ export class IntegrationTestHelper { // What would be the best maxFee? In the future we will load the fee multiplier from rest. this.maxFee = UInt64.fromUint(1000000); - require('fs').readFile(path.resolve(__dirname, - '../../../catapult-service-bootstrap/build/generated-addresses/addresses.yaml'), - (error: any, yamlData: any) => { + const bootstrapRoot = process.env.CATAPULT_SERVICE_BOOTSTRAP || path.resolve(__dirname, '../../../../catapult-service-bootstrap'); + const bootstrapPath = `${bootstrapRoot}/build/generated-addresses/addresses.yaml`; + require('fs').readFile(bootstrapPath, (error: any, yamlData: any) => { if (error) { - console.log(`catapult-service-bootstrap generated address could not be loaded. Ignoring and using accounts from network.conf.`); + console.log(`catapult-service-bootstrap generated address could not be loaded from path ${bootstrapPath}. Ignoring and using accounts from network.conf.`); return resolve(this); } else { + console.log(`catapult-service-bootstrap generated address loaded from path ${bootstrapPath}.`); const parsedYaml = this.yaml.safeLoad(yamlData); this.account = this.createAccount(parsedYaml.nemesis_addresses[0]); this.account2 = this.createAccount(parsedYaml.nemesis_addresses[1]); diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 7275251fb1..9734a2826b 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -22,14 +22,7 @@ import { TransactionRepository } from '../../src/infrastructure/TransactionRepos import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { - Address, - CosignatureTransaction, - LockFundsTransaction, - Mosaic, - SignedTransaction, - 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'; @@ -52,7 +45,7 @@ describe('Listener', () => { let namespaceRepository: NamespaceRepository; let generationHash: string; let networkType: NetworkType; - let networkCurrencyMosaicId: MosaicId; + let networkCurrencyMosaicId: NamespaceId = NetworkCurrencyMosaic.NAMESPACE_ID; let transactionRepository: TransactionRepository; before(() => { @@ -104,7 +97,7 @@ describe('Listener', () => { const createHashLockTransactionAndAnnounce = (signedAggregatedTransaction: SignedTransaction, signer: Account, - mosaicId: MosaicId) => { + mosaicId: MosaicId | NamespaceId) => { const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), @@ -163,11 +156,10 @@ describe('Listener', () => { filter((_) => _.transactionInfo!.hash === signedTransaction.hash)).subscribe(() => { done(); }); - helper.announce(signedTransaction); + transactionRepository.announce(signedTransaction); }); it('unconfirmedTransactionsRemoved', (done) => { - const transferTransaction = TransferTransaction.create( Deadline.create(), account.address, @@ -179,15 +171,7 @@ describe('Listener', () => { helper.listener.unconfirmedRemoved(account.address).pipe(filter((hash) => hash === signedTransaction.hash)).subscribe(() => { done(); }); - helper.announce(signedTransaction); - }); - }); - describe('Get network currency mosaic id', () => { - it('get mosaicId', (done) => { - namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId: MosaicId) => { - networkCurrencyMosaicId = networkMosaicId; - done(); - }); + transactionRepository.announce(signedTransaction); }); }); diff --git a/e2e/infrastructure/MetadataHttp.spec.ts b/e2e/infrastructure/MetadataHttp.spec.ts index 5b8a9062e6..252f21be09 100644 --- a/e2e/infrastructure/MetadataHttp.spec.ts +++ b/e2e/infrastructure/MetadataHttp.spec.ts @@ -183,143 +183,116 @@ describe('MetadataHttp', () => { */ describe('getAccountMetadata', () => { - it('should return metadata given a NEM Address', (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(); - }); + it('should return metadata given a NEM Address', async () => { + const metadata = await metadataRepository.getAccountMetadata(accountAddress).toPromise(); + 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); }); }); describe('getAccountMetadataByKey', () => { - it('should return metadata given a NEM Address and metadata key', (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(); - }); + it('should return metadata given a NEM Address and metadata key', async () => { + const metadata = await metadataRepository.getAccountMetadataByKey(accountAddress, UInt64.fromUint(5).toHex()).toPromise(); + 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); }); }); describe('getAccountMetadataByKeyAndSender', () => { - it('should return metadata given a NEM Address and metadata key and sender public key', (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(); - }); + it('should return metadata given a NEM Address and metadata key and sender public key', async () => { + const metadata = await metadataRepository.getAccountMetadataByKeyAndSender(accountAddress, UInt64.fromUint(5).toHex(), account.publicKey).toPromise(); + 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); }); }); describe('getMosaicMetadata', () => { - it('should return metadata given a mosaicId', (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(); - }); + it('should return metadata given a mosaicId', async () => { + const metadata = await metadataRepository.getMosaicMetadata(mosaicId).toPromise(); + 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); }); }); describe('getMosaicMetadataByKey', () => { - it('should return metadata given a mosaicId and metadata key', (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(); - }); + it('should return metadata given a mosaicId and metadata key', async () => { + const metadata = await metadataRepository.getMosaicMetadataByKey(mosaicId, UInt64.fromUint(5).toHex()).toPromise(); + 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); }); }); describe('getMosaicMetadataByKeyAndSender', () => { - it('should return metadata given a mosaicId and metadata key and sender public key', (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(); - }); + it('should return metadata given a mosaicId and metadata key and sender public key', async () => { + const metadata = await metadataRepository.getMosaicMetadataByKeyAndSender(mosaicId, UInt64.fromUint(5).toHex(), account.publicKey).toPromise(); + 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); }); }); describe('getNamespaceMetadata', () => { - it('should return metadata given a namespaceId', (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(); - }); + it('should return metadata given a namespaceId', async () => { + const metadata = await metadataRepository.getNamespaceMetadata(namespaceId).toPromise(); + 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); }); }); describe('getNamespaceMetadataByKey', () => { - it('should return metadata given a namespaceId and metadata key', (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(); - }); + it('should return metadata given a namespaceId and metadata key', async () => { + const metadata = await metadataRepository.getNamespaceMetadataByKey(namespaceId, UInt64.fromUint(5).toHex()).toPromise(); + 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); }); }); describe('getNamespaceMetadataByKeyAndSender', () => { - it('should return metadata given a namespaceId and metadata key and sender public key', (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(); - }); + it('should return metadata given a namespaceId and metadata key and sender public key', async () => { + const metadata = await metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, UInt64.fromUint(5).toHex(), account.publicKey).toPromise(); + 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); }); }); }); diff --git a/e2e/infrastructure/MosaicHttp.spec.ts b/e2e/infrastructure/MosaicHttp.spec.ts index 63656756a5..bdcb367761 100644 --- a/e2e/infrastructure/MosaicHttp.spec.ts +++ b/e2e/infrastructure/MosaicHttp.spec.ts @@ -123,57 +123,45 @@ describe('MosaicHttp', () => { * ========================= */ describe('getMosaic', () => { - it('should return mosaic given mosaicId', (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(); - }); + it('should return mosaic given mosaicId', async () => { + const mosaicInfo = await mosaicRepository.getMosaic(mosaicId).toPromise(); + 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); }); }); describe('getMosaics', () => { - it('should return mosaics given array of mosaicIds', (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(); - }); + it('should return mosaics given array of mosaicIds', async () => { + const mosaicInfos = await mosaicRepository.getMosaics([mosaicId]).toPromise(); + 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); }); }); describe('getMosaicsNames', () => { - it('should call getMosaicsNames successfully', (done) => { - namespaceRepository.getMosaicsNames([mosaicId]).subscribe((mosaicNames) => { - expect(mosaicNames.length).to.be.greaterThan(0); - done(); - }); + it('should call getMosaicsNames successfully', async () => { + const mosaicNames = await namespaceRepository.getMosaicsNames([mosaicId]).toPromise(); + expect(mosaicNames.length).to.be.greaterThan(0); }); }); describe('getMosaicsFromAccount', () => { - it('should call getMosaicsFromAccount successfully', (done) => { - 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(); - }); + it('should call getMosaicsFromAccount successfully', async () => { + const mosaics = await mosaicRepository.getMosaicsFromAccount(account.address).toPromise(); + expect(mosaics.length).to.be.greaterThan(0); + expect(mosaics.find((m) => m.id.toHex() === mosaicId.toHex()) !== undefined).to.be.true; }); }); describe('getMosaicsFromAccounts', () => { - it('should call getMosaicsFromAccounts successfully', (done) => { - 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(); - }); + it('should call getMosaicsFromAccounts successfully', async () => { + const mosaics = await mosaicRepository.getMosaicsFromAccounts([account.address]).toPromise(); + expect(mosaics.length).to.be.greaterThan(0); + expect(mosaics.find((m) => m.id.toHex() === mosaicId.toHex()) !== undefined).to.be.true; }); }); diff --git a/e2e/infrastructure/NamespaceHttp.spec.ts b/e2e/infrastructure/NamespaceHttp.spec.ts index 4f02b927af..b32a912997 100644 --- a/e2e/infrastructure/NamespaceHttp.spec.ts +++ b/e2e/infrastructure/NamespaceHttp.spec.ts @@ -85,64 +85,46 @@ describe('NamespaceHttp', () => { }); describe('getNamespace', () => { - it('should return namespace data given namepsaceId', (done) => { - namespaceRepository.getNamespace(defaultNamespaceId) - .subscribe((namespace) => { - expect(namespace.startHeight.lower).to.be.equal(1); - expect(namespace.startHeight.higher).to.be.equal(0); - done(); - }); + it('should return namespace data given namepsaceId', async () => { + const namespace = await namespaceRepository.getNamespace(defaultNamespaceId).toPromise(); + expect(namespace.startHeight.lower).to.be.equal(1); + expect(namespace.startHeight.higher).to.be.equal(0); }); }); describe('getNamespacesFromAccount', () => { - it('should return namespace data given publicKeyNemesis', (done) => { - namespaceRepository.getNamespacesFromAccount(account.address) - .subscribe((namespaces) => { - deepEqual(namespaces[0].owner, account.publicAccount); - done(); - }); + it('should return namespace data given publicKeyNemesis', async () => { + const namespaces = await namespaceRepository.getNamespacesFromAccount(account.address).toPromise(); + deepEqual(namespaces[0].owner, account.publicAccount); }); }); describe('getNamespacesFromAccounts', () => { - it('should return namespaces data given publicKeyNemesis', (done) => { - namespaceRepository.getNamespacesFromAccounts([account.address]) - .subscribe((namespaces) => { - deepEqual(namespaces[0].owner, account.publicAccount); - done(); - }); + it('should return namespaces data given publicKeyNemesis', async () => { + const namespaces = await namespaceRepository.getNamespacesFromAccounts([account.address]).toPromise(); + deepEqual(namespaces[0].owner, account.publicAccount); }); }); describe('getNamespacesName', () => { - it('should return namespace name given array of namespaceIds', (done) => { - namespaceRepository.getNamespacesName([defaultNamespaceId]) - .subscribe((namespaceNames) => { - expect(namespaceNames[0].name).to.be.equal('currency'); - done(); - }); + it('should return namespace name given array of namespaceIds', async () => { + const namespaceNames = await namespaceRepository.getNamespacesName([defaultNamespaceId]).toPromise(); + expect(namespaceNames[0].name).to.be.equal('currency'); }); }); describe('getLinkedMosaicId', () => { - it('should return mosaicId given currency namespaceId', (done) => { - namespaceRepository.getLinkedMosaicId(defaultNamespaceId) - .subscribe((mosaicId) => { - expect(mosaicId).to.not.be.null; - done(); - }); + it('should return mosaicId given currency namespaceId', async () => { + const mosaicId = await namespaceRepository.getLinkedMosaicId(defaultNamespaceId).toPromise(); + expect(mosaicId).to.not.be.null; }); }); describe('getLinkedAddress', () => { - it('should return address given namespaceId', (done) => { - namespaceRepository.getLinkedAddress(namespaceId) - .subscribe((address: Address) => { - expect(address.plain()).to.be.equal(account.address.plain()); - done(); - }); + it('should return address given namespaceId', async () => { + const address = (await namespaceRepository.getLinkedAddress(namespaceId).toPromise()) as Address; + expect(address.plain()).to.be.equal(account.address.plain()); }); }); }); diff --git a/e2e/infrastructure/NetworkHttp.spec.ts b/e2e/infrastructure/NetworkHttp.spec.ts index 1e4e74c8db..e450a4cf9c 100644 --- a/e2e/infrastructure/NetworkHttp.spec.ts +++ b/e2e/infrastructure/NetworkHttp.spec.ts @@ -31,23 +31,17 @@ describe('NetworkHttp', () => { }); describe('getNetworkType', () => { - it('should return network type', (done) => { - networkRepository.getNetworkType() - .subscribe((sentNetworkType) => { - expect(sentNetworkType).to.be.equal(networkType); - done(); - }); + it('should return network type', async () => { + const sentNetworkType = await networkRepository.getNetworkType().toPromise(); + expect(sentNetworkType).to.be.equal(networkType); }); }); describe('getNetworkName', () => { - it('should return network name and description', (done) => { - networkRepository.getNetworkName() - .subscribe((networkName) => { - expect(networkName.name.toLowerCase()).to.be.not.null; - expect(networkName.description.toLowerCase()).to.be.not.null; - done(); - }); + it('should return network name and description', async () => { + const networkName = await networkRepository.getNetworkName().toPromise(); + expect(networkName.name.toLowerCase()).to.be.not.null; + expect(networkName.description.toLowerCase()).to.be.not.null; }); }); }); diff --git a/e2e/infrastructure/NodeHttp.spec.ts b/e2e/infrastructure/NodeHttp.spec.ts index 4d6cfd427b..8d81df82ee 100644 --- a/e2e/infrastructure/NodeHttp.spec.ts +++ b/e2e/infrastructure/NodeHttp.spec.ts @@ -29,29 +29,23 @@ describe('NodeHttp', () => { }); describe('getNodeInfo', () => { - it('should return node info', (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(); - }); + it('should return node info', async () => { + const nodeInfo = await nodeRepository.getNodeInfo().toPromise(); + 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; }); }); describe('getNodeTime', () => { - it('should return node time', (done) => { - nodeRepository.getNodeTime() - .subscribe((nodeTime) => { - expect(nodeTime.receiveTimeStamp).not.to.be.undefined; - expect(nodeTime.sendTimeStamp).not.to.be.undefined; - done(); - }); + it('should return node time', async () => { + const nodeTime = await nodeRepository.getNodeTime().toPromise(); + expect(nodeTime.receiveTimeStamp).not.to.be.undefined; + expect(nodeTime.sendTimeStamp).not.to.be.undefined; }); }); }); diff --git a/e2e/infrastructure/RestrictionHttp.spec.ts b/e2e/infrastructure/RestrictionHttp.spec.ts index 5ab72e8e1b..823e722df0 100644 --- a/e2e/infrastructure/RestrictionHttp.spec.ts +++ b/e2e/infrastructure/RestrictionHttp.spec.ts @@ -191,77 +191,65 @@ describe('RestrictionHttp', () => { */ describe('getAccountRestrictions', () => { - it('should call getAccountRestrictions successfully', (done) => { + it('should call getAccountRestrictions successfully', async () => { - restrictionAccountRepository.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => { - expect(accountRestrictions.length).to.be.greaterThan(0); - done(); - }); + const accountRestrictions = await restrictionAccountRepository.getAccountRestrictions(accountAddress).toPromise(); + expect(accountRestrictions.length).to.be.greaterThan(0); }); }); describe('getAccountRestrictionsFromAccounts', () => { - it('should call getAccountRestrictionsFromAccounts successfully', (done) => { - restrictionAccountRepository.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => { - deepEqual(accountRestrictions[0]!.address, accountAddress); - done(); - }); + it('should call getAccountRestrictionsFromAccounts successfully', async () => { + const accountRestrictions = await restrictionAccountRepository.getAccountRestrictionsFromAccounts([accountAddress]).toPromise(); + deepEqual(accountRestrictions[0]!.address, accountAddress); }); }); describe('getMosaicAddressRestriction', () => { - it('should call getMosaicAddressRestriction successfully', (done) => { - 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(); - }); + it('should call getMosaicAddressRestriction successfully', async () => { + const mosaicRestriction = await restrictionMosaicRepository.getMosaicAddressRestriction(mosaicId, account3.address).toPromise(); + 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()); }); }); describe('getMosaicAddressRestrictions', () => { - it('should call getMosaicAddressRestrictions successfully', (done) => { - 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(); - }); + it('should call getMosaicAddressRestrictions successfully', async () => { + const mosaicRestriction = await restrictionMosaicRepository.getMosaicAddressRestrictions(mosaicId, [account3.address]).toPromise(); + 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()); }); }); describe('getMosaicGlobalRestriction', () => { - it('should call getMosaicGlobalRestriction successfully', (done) => { - 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(); - }); + it('should call getMosaicGlobalRestriction successfully', async () => { + const mosaicRestriction = await restrictionMosaicRepository.getMosaicGlobalRestriction(mosaicId).toPromise(); + 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()); }); }); describe('getMosaicGlobalRestrictions', () => { - it('should call getMosaicGlobalRestrictions successfully', (done) => { - 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(); - }); + it('should call getMosaicGlobalRestrictions successfully', async () => { + const mosaicRestriction = await restrictionMosaicRepository.getMosaicGlobalRestrictions([mosaicId]).toPromise(); + 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()); }); }); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index eacf9e548d..9b081b9b24 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -133,11 +133,9 @@ describe('TransactionHttp', () => { }); describe('Get network currency mosaic id', () => { - it('get mosaicId', (done) => { - namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId: MosaicId) => { - networkCurrencyMosaicId = networkMosaicId; - done(); - }); + it('get mosaicId', async () => { + networkCurrencyMosaicId = + (await namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise()) as MosaicId; }); }); @@ -611,7 +609,7 @@ describe('TransactionHttp', () => { describe('AccountLinkTransaction', () => { - it('standalone', (done) => { + it('standalone', () => { const accountLinkTransaction = AccountLinkTransaction.create( Deadline.create(), harvestingAccount.publicKey, @@ -623,7 +621,7 @@ describe('TransactionHttp', () => { return helper.announce(signedTransaction).then((transaction: AccountLinkTransaction) => { expect(transaction.remotePublicKey, 'RemotePublicKey').not.to.be.undefined; expect(transaction.linkAction, 'LinkAction').not.to.be.undefined; - done(); + return signedTransaction; }); }); @@ -1327,82 +1325,62 @@ describe('TransactionHttp', () => { }); describe('transactions', () => { - it('should call transactions successfully', (done) => { - accountRepository.getAccountTransactions(account.publicAccount.address).subscribe((transactions) => { - const transaction = transactions[0]; - transactionId = transaction.transactionInfo!.id; - transactionHash = transaction.transactionInfo!.hash; - done(); - }); + it('should call transactions successfully', async () => { + const transactions = await accountRepository.getAccountTransactions(account.publicAccount.address).toPromise(); + const transaction = transactions[0]; + transactionId = transaction.transactionInfo!.id; + transactionHash = transaction.transactionInfo!.hash; }); }); describe('getTransaction', () => { - it('should return transaction info given transactionHash', (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 transactionHash', async () => { + const transaction = await transactionRepository.getTransaction(transactionHash).toPromise(); + expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); + expect(transaction.transactionInfo!.id).to.be.equal(transactionId); }); - it('should return transaction info given transactionId', (done) => { - transactionRepository.getTransaction(transactionId) - .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', async () => { + const transaction = await transactionRepository.getTransaction(transactionId).toPromise(); + expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); + expect(transaction.transactionInfo!.id).to.be.equal(transactionId); }); }); describe('getTransactions', () => { - it('should return transaction info given array of transactionHash', (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 transactionHash', async () => { + const transactions = await transactionRepository.getTransactions([transactionHash]).toPromise(); + expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); + expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); }); - it('should return transaction info given array of 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(); - }); + it('should return transaction info given array of transactionId', async () => { + const transactions = await transactionRepository.getTransactions([transactionId]).toPromise(); + expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash); + expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId); }); }); describe('getTransactionStatus', () => { - it('should return transaction status given transactionHash', (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(); - }); + it('should return transaction status given transactionHash', async () => { + const transactionStatus = await transactionRepository.getTransactionStatus(transactionHash).toPromise(); + expect(transactionStatus.group).to.be.equal('confirmed'); + expect(transactionStatus.height!.lower).to.be.greaterThan(0); + expect(transactionStatus.height!.higher).to.be.equal(0); }); }); describe('getTransactionsStatuses', () => { - it('should return transaction status given array of transactionHash', (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(); - }); + it('should return transaction status given array of transactionHash', async () => { + const transactionStatuses = await transactionRepository.getTransactionsStatuses([transactionHash]).toPromise(); + 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); }); }); describe('announce', () => { - it('should return success when announce', (done) => { + it('should return success when announce', async () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, @@ -1411,17 +1389,13 @@ describe('TransactionHttp', () => { networkType, helper.maxFee, ); const signedTransaction = transferTransaction.signWith(account, generationHash); - transactionRepository.announce(signedTransaction) - .subscribe((transactionAnnounceResponse) => { - expect(transactionAnnounceResponse.message) - .to.be.equal('packet 9 was pushed to the network via /transaction'); - done(); - }); + const transactionAnnounceResponse = await transactionRepository.announce(signedTransaction).toPromise(); + expect(transactionAnnounceResponse.message).to.be.equal('packet 9 was pushed to the network via /transaction'); }); }); describe('announceAggregateBonded', () => { - it('should return success when announceAggregateBonded', (done) => { + it('should return success when announceAggregateBonded', async () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, @@ -1435,35 +1409,25 @@ describe('TransactionHttp', () => { networkType, [], helper.maxFee); const signedTransaction = aggregateTransaction.signWith(cosignAccount1, generationHash); - transactionRepository.announceAggregateBonded(signedTransaction) - .subscribe((transactionAnnounceResponse) => { - expect(transactionAnnounceResponse.message) - .to.be.equal('packet 500 was pushed to the network via /transaction/partial'); - done(); - }); + const transactionAnnounceResponse = await transactionRepository.announceAggregateBonded(signedTransaction).toPromise(); + expect(transactionAnnounceResponse.message) + .to.be.equal('packet 500 was pushed to the network via /transaction/partial'); }); }); describe('announceAggregateBondedCosignature', () => { - it('should return success when announceAggregateBondedCosignature', (done) => { + it('should return success when announceAggregateBondedCosignature', async () => { const payload = new CosignatureSignedTransaction('', '', ''); - transactionRepository.announceAggregateBondedCosignature(payload) - .subscribe((transactionAnnounceResponse) => { - expect(transactionAnnounceResponse.message) - .to.be.equal('packet 501 was pushed to the network via /transaction/cosignature'); - done(); - }); + const transactionAnnounceResponse = await transactionRepository.announceAggregateBondedCosignature(payload).toPromise(); + expect(transactionAnnounceResponse.message).to.be.equal('packet 501 was pushed to the network via /transaction/cosignature'); }); }); describe('getTransactionEffectiveFee', () => { - it('should return effective paid fee given transactionHash', (done) => { - transactionRepository.getTransactionEffectiveFee(transactionHash) - .subscribe((effectiveFee) => { - expect(effectiveFee).to.not.be.undefined; - expect(effectiveFee).to.be.equal(0); - done(); - }); + it('should return effective paid fee given transactionHash', async () => { + const effectiveFee = await transactionRepository.getTransactionEffectiveFee(transactionHash).toPromise(); + expect(effectiveFee).to.not.be.undefined; + expect(effectiveFee).to.be.equal(0); }); }); }); diff --git a/e2e/infrastructure/UnresolvedMapping.spec.ts b/e2e/infrastructure/UnresolvedMapping.spec.ts index 696aa12541..416258e1f3 100644 --- a/e2e/infrastructure/UnresolvedMapping.spec.ts +++ b/e2e/infrastructure/UnresolvedMapping.spec.ts @@ -78,11 +78,8 @@ describe('TransactionHttp', () => { * ========================= */ describe('Get network currency mosaic id', () => { - it('get mosaicId', (done) => { - namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId: MosaicId) => { - networkCurrencyMosaicId = networkMosaicId; - done(); - }); + it('get mosaicId', async () => { + networkCurrencyMosaicId = (await namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise()) as MosaicId; }); }); diff --git a/e2e/service/MetadataTransactionService.spec.ts b/e2e/service/MetadataTransactionService.spec.ts index 5ace0b128f..1c074e69c4 100644 --- a/e2e/service/MetadataTransactionService.spec.ts +++ b/e2e/service/MetadataTransactionService.spec.ts @@ -1,4 +1,5 @@ -import { assert, expect } from 'chai'; +import { expect } from 'chai'; +import { Convert } from '../../src/core/format'; import { MetadataRepository } from '../../src/infrastructure/MetadataRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; @@ -7,7 +8,6 @@ import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; -import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction'; @@ -148,10 +148,11 @@ describe('MetadataTransactionService', () => { * ========================= */ describe('Test new services', () => { - it('should create AccountMetadataTransaction - no current metadata', (done) => { + + it('should create AccountMetadataTransaction - no current metadata', async () => { const metaDataService = new MetadataTransactionService(metadataRepository); - return metaDataService.createMetadataTransaction( + const transaction = await metaDataService.createMetadataTransaction( deadline, networkType, MetadataType.Account, @@ -159,66 +160,65 @@ describe('MetadataTransactionService', () => { key, newValue, targetAccount.publicAccount, - ).subscribe((transaction: AccountMetadataTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA); - 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(); - }); + ).toPromise(); + + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); + expect(transaction.value).to.be.equal(newValue); + expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); }); - it('should create MosaicMetadataTransaction', (done) => { - const metaDataService = new MetadataTransactionService(metadataRepository); - return metaDataService.createMetadataTransaction( + it('should create MosaicMetadataTransaction', async () => { + const metaDataService = new MetadataTransactionService(metadataRepository); + const updateValue = newValue + 'delta'; + const transaction = await metaDataService.createMetadataTransaction( deadline, networkType, MetadataType.Mosaic, targetAccount.publicAccount, key, - newValue + 'delta', + updateValue, targetAccount.publicAccount, mosaicId, - ).subscribe((transaction: MosaicMetadataTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA); - 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(); - }); + ).toPromise() as MosaicMetadataTransaction; + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); + expect(transaction.valueSizeDelta).to.be.equal(5); + expect(transaction.value).to.be.equals( Convert.decodeHex(Convert.xor(Convert.utf8ToUint8(newValue), Convert.utf8ToUint8(updateValue)))); + expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); + expect(transaction.targetMosaicId.toHex()).to.be.equal(mosaicId.toHex()); }); - it('should create NamespaceMetadataTransaction', (done) => { + + it('should create NamespaceMetadataTransaction', async () => { const metaDataService = new MetadataTransactionService(metadataRepository); - return metaDataService.createMetadataTransaction( + const updateValue = newValue + 'delta'; + const transaction = await metaDataService.createMetadataTransaction( deadline, networkType, MetadataType.Namespace, targetAccount.publicAccount, key, - newValue + 'delta', + updateValue, targetAccount.publicAccount, namespaceId, - ).subscribe((transaction: NamespaceMetadataTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA); - 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(); - }); + ).toPromise() as NamespaceMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); + expect(transaction.valueSizeDelta).to.be.equal(5); + expect(transaction.value).to.be.equals( Convert.decodeHex(Convert.xor(Convert.utf8ToUint8(newValue), Convert.utf8ToUint8(updateValue)))); + expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); + expect(transaction.targetNamespaceId.toHex()).to.be.equal(namespaceId.toHex()); }); }); describe('Announce transaction through service', () => { - it('should create MosaicMetadataTransaction and announce', (done) => { + it('should create MosaicMetadataTransaction and announce', async () => { const metaDataService = new MetadataTransactionService(metadataRepository); - return metaDataService.createMetadataTransaction( + const transaction = await metaDataService.createMetadataTransaction( deadline, networkType, MetadataType.Mosaic, @@ -228,28 +228,21 @@ describe('MetadataTransactionService', () => { 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(); - }); - }); + ).toPromise(); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [transaction.toAggregate(targetAccount.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); + return helper.announce(signedTransaction); }); }); describe('Announce transaction through service with delta size increase', () => { - it('should create MosaicMetadataTransaction and announce', (done) => { + it('should create MosaicMetadataTransaction and announce', () => { const metaDataService = new MetadataTransactionService(metadataRepository); return metaDataService.createMetadataTransaction( @@ -262,7 +255,7 @@ describe('MetadataTransactionService', () => { targetAccount.publicAccount, mosaicId, helper.maxFee, - ).subscribe((transaction: MosaicMetadataTransaction) => { + ).toPromise().then((transaction: MosaicMetadataTransaction) => { const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [transaction.toAggregate(targetAccount.publicAccount)], networkType, @@ -270,20 +263,14 @@ describe('MetadataTransactionService', () => { helper.maxFee, ); const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - helper.announce(signedTransaction).then(() => { - done(); - }, (error) => { - console.log('Error:', error); - assert(false); - done(); - }); + return helper.announce(signedTransaction); }); }); }); describe('Announce transaction through service with delta size decrease', () => { - it('should create MosaicMetadataTransaction and announce', (done) => { + it('should create MosaicMetadataTransaction and announce', async () => { const metaDataService = new MetadataTransactionService(metadataRepository); return metaDataService.createMetadataTransaction( @@ -295,7 +282,7 @@ describe('MetadataTransactionService', () => { newValue, targetAccount.publicAccount, mosaicId, - ).subscribe((transaction: MosaicMetadataTransaction) => { + ).toPromise().then((transaction: MosaicMetadataTransaction) => { const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [transaction.toAggregate(targetAccount.publicAccount)], networkType, @@ -303,13 +290,7 @@ describe('MetadataTransactionService', () => { helper.maxFee, ); const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - helper.announce(signedTransaction).then(() => { - done(); - }, (error) => { - console.log('Error:', error); - assert(false); - done(); - }); + return helper.announce(signedTransaction); }); }); }); diff --git a/e2e/service/MosaicRestrictionTransactionService.spec.ts b/e2e/service/MosaicRestrictionTransactionService.spec.ts index eee4d636f6..8f1e2f8239 100644 --- a/e2e/service/MosaicRestrictionTransactionService.spec.ts +++ b/e2e/service/MosaicRestrictionTransactionService.spec.ts @@ -194,7 +194,7 @@ describe('MosaicRestrictionTransactionService', () => { * ========================= */ describe('Test new services - MosaicGlobalRestriction', () => { - it('should create MosaicGlobalRestrictionTransaction', (done) => { + it('should create MosaicGlobalRestrictionTransaction', () => { const service = new MosaicRestrictionTransactionService(restrictionRepository, namespaceRepository); return service.createMosaicGlobalRestrictionTransaction( @@ -204,20 +204,19 @@ describe('MosaicRestrictionTransactionService', () => { key, '1', MosaicRestrictionType.GE, undefined, helper.maxFee, - ).subscribe((transaction: MosaicGlobalRestrictionTransaction) => { + ).toPromise().then((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(); }); }); }); describe('Test new services - MosaicGlobalRestriction', () => { - it('should create MosaicGlobalRestrictionTransaction using alias', (done) => { + it('should create MosaicGlobalRestrictionTransaction using alias', () => { const service = new MosaicRestrictionTransactionService(restrictionRepository, namespaceRepository); return service.createMosaicGlobalRestrictionTransaction( deadline, @@ -226,20 +225,19 @@ describe('MosaicRestrictionTransactionService', () => { key, '2', MosaicRestrictionType.GE, undefined, helper.maxFee, - ).subscribe((transaction: MosaicGlobalRestrictionTransaction) => { + ).toPromise().then((transaction: MosaicGlobalRestrictionTransaction) => { expect(transaction.type).to.be.equal(TransactionType.MOSAIC_GLOBAL_RESTRICTION); expect(transaction.previousRestrictionValue.toString()).to.be.equal('1'); expect(transaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.GE); expect(transaction.newRestrictionValue.toString()).to.be.equal('2'); expect(transaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); - done(); }); }); }); describe('Test new services - MosaicAddressRestriction', () => { - it('should create MosaicAddressRestrictionTransaction', (done) => { + it('should create MosaicAddressRestrictionTransaction', () => { const service = new MosaicRestrictionTransactionService(restrictionRepository, namespaceRepository); return service.createMosaicAddressRestrictionTransaction( deadline, @@ -249,19 +247,18 @@ describe('MosaicRestrictionTransactionService', () => { account.address, '3', helper.maxFee, - ).subscribe((transaction: MosaicAddressRestrictionTransaction) => { + ).toPromise().then((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('Test new services - MosaicAddressRestriction', () => { - it('should create MosaicAddressRestrictionTransaction with address alias', (done) => { + it('should create MosaicAddressRestrictionTransaction with address alias', () => { const service = new MosaicRestrictionTransactionService(restrictionRepository, namespaceRepository); return service.createMosaicAddressRestrictionTransaction( @@ -272,29 +269,28 @@ describe('MosaicRestrictionTransactionService', () => { namespaceIdAddress, '4', helper.maxFee, - ).subscribe((transaction: MosaicAddressRestrictionTransaction) => { + ).toPromise().then((transaction: MosaicAddressRestrictionTransaction) => { expect(transaction.type).to.be.equal(TransactionType.MOSAIC_ADDRESS_RESTRICTION); expect(transaction.previousRestrictionValue.toString()).to.be.equal('3'); expect(transaction.newRestrictionValue.toString()).to.be.equal('4'); expect(transaction.targetAddressToString()).to.be.equal(account.address.plain()); expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); - done(); }); }); }); describe('Announce MosaicGlobalRestriction through service', () => { - it('should create MosaicGlobalRestriction and announce', (done) => { + it('should create MosaicGlobalRestriction and announce', () => { const service = new MosaicRestrictionTransactionService(restrictionRepository, namespaceRepository); - service.createMosaicGlobalRestrictionTransaction( + return service.createMosaicGlobalRestrictionTransaction( deadline, networkType, mosaicId, key, '1', MosaicRestrictionType.GE, undefined, helper.maxFee, - ).subscribe((transaction: MosaicGlobalRestrictionTransaction) => { + ).toPromise().then((transaction: MosaicGlobalRestrictionTransaction) => { const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [transaction.toAggregate(account.publicAccount)], networkType, @@ -302,18 +298,15 @@ describe('MosaicRestrictionTransactionService', () => { helper.maxFee, ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - helper.announce(signedTransaction).then(() => { - done(); - }); + return helper.announce(signedTransaction); }); }); }); describe('Announce MosaicAddressRestriction through service', () => { - it('should create MosaicAddressRestriction and announce', (done) => { + it('should create MosaicAddressRestriction and announce', () => { const service = new MosaicRestrictionTransactionService(restrictionRepository, namespaceRepository); - return service.createMosaicAddressRestrictionTransaction( deadline, networkType, @@ -322,7 +315,7 @@ describe('MosaicRestrictionTransactionService', () => { account.address, '3', helper.maxFee, - ).subscribe((transaction: MosaicAddressRestrictionTransaction) => { + ).toPromise().then((transaction: MosaicAddressRestrictionTransaction) => { const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), [transaction.toAggregate(account.publicAccount)], networkType, @@ -330,9 +323,7 @@ describe('MosaicRestrictionTransactionService', () => { helper.maxFee, ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); - helper.announce(signedTransaction).then(() => { - done(); - }); + return helper.announce(signedTransaction); }); }); }); diff --git a/e2e/service/MosaicService.spec.ts b/e2e/service/MosaicService.spec.ts index 5760136205..f094dab832 100644 --- a/e2e/service/MosaicService.spec.ts +++ b/e2e/service/MosaicService.spec.ts @@ -38,13 +38,12 @@ describe('MosaicService', () => { mosaicRepository = helper.repositoryFactory.createMosaicRepository(); }); }); - it('should return the mosaic list skipping the expired mosaics', (done) => { + it('should return the mosaic list skipping the expired mosaics', () => { const mosaicService = new MosaicService(accountRepository, mosaicRepository); - return mosaicService.mosaicsAmountViewFromAddress(accountAddress).subscribe((amountViews) => { - const views = amountViews.map((v) => { + return mosaicService.mosaicsAmountViewFromAddress(accountAddress).toPromise().then((amountViews) => { + return amountViews.map((v) => { return {mosaicId: v.fullName(), amount: v.relativeAmount()}; }); - done(); }); }); }); diff --git a/e2e/service/TransactionService.spec.ts b/e2e/service/TransactionService.spec.ts index e183f27fe9..d226ce5449 100644 --- a/e2e/service/TransactionService.spec.ts +++ b/e2e/service/TransactionService.spec.ts @@ -310,41 +310,40 @@ describe('TransactionService', () => { */ describe('should return resolved transaction', () => { - it('call transaction service', (done) => { - - 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) - .plain()).to.be.equal(account.address.plain()); - 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) - .targetMosaicId.toHex() === newMosaicId.toHex()).to.be.true; - } - }); - }, - done()); + it('call transaction service', () => { + return transactionService.resolveAliases(transactionHashes).toPromise().then((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) + .plain()).to.be.equal(account.address.plain()); + 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) + .targetMosaicId.toHex() === newMosaicId.toHex()).to.be.true; + } + return tx; + }); + }); }); }); describe('Test resolve alias with multiple transaction in single block', () => { - it('call transaction service', (done) => { - 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) - .targetMosaicId.toHex()).to.be.equal(newMosaicId.toHex()); - }, - done()); + it('call transaction service', () => { + return transactionService.resolveAliases(transactionHashesMultiple).toPromise().then((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) + .targetMosaicId.toHex()).to.be.equal(newMosaicId.toHex()); + return tx; + }); }); }); diff --git a/e2e/service/TransactionService_AggregateBonded.spec.ts b/e2e/service/TransactionService_AggregateBonded.spec.ts index d85b5fa368..cbc554d0c5 100644 --- a/e2e/service/TransactionService_AggregateBonded.spec.ts +++ b/e2e/service/TransactionService_AggregateBonded.spec.ts @@ -98,10 +98,9 @@ describe('TransactionService', () => { * ========================= */ describe('Get network currency mosaic id', () => { - it('get mosaicId', (done) => { - namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId: MosaicId) => { + it('get mosaicId', () => { + return namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise().then((networkMosaicId: MosaicId) => { networkCurrencyMosaicId = networkMosaicId; - done(); }); }); }); @@ -140,7 +139,7 @@ describe('TransactionService', () => { describe('should announce transaction', () => { - it('announce', (done) => { + it('announce', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, @@ -151,18 +150,17 @@ describe('TransactionService', () => { networkType, helper.maxFee, ); const signedTransaction = transferTransaction.signWith(account, generationHash); - transactionService.announce(signedTransaction, helper.listener).subscribe((tx: TransferTransaction) => { + return transactionService.announce(signedTransaction, helper.listener).toPromise().then((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'); - done(); }); }); }); describe('should announce aggregate bonded with hashlock', () => { - it('announce', (done) => { + it('announce', async () => { const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), @@ -172,18 +170,16 @@ describe('TransactionService', () => { networkType, helper.maxFee, ); const signedLockFundsTransaction = lockFundsTransaction.signWith(account, generationHash); - transactionService - .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(); - }); + const tx = await transactionService.announceHashLockAggregateBonded(signedLockFundsTransaction, signedAggregatedTransaction, helper.listener).toPromise(); + expect(tx.signer!.publicKey).to.be.equal(account.publicKey); + expect(tx.type).to.be.equal(TransactionType.AGGREGATE_BONDED); + }); }); describe('should announce aggregate bonded transaction', () => { - it('announce', (done) => { + it('announce', async () => { const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), @@ -193,13 +189,12 @@ describe('TransactionService', () => { networkType, helper.maxFee, ); const signedLockFundsTransaction = lockFundsTransaction.signWith(account, generationHash); - 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(); - }); - }); + const signedLockFundsTransactionResponse = await transactionService.announce(signedLockFundsTransaction, helper.listener).toPromise(); + expect(signedLockFundsTransactionResponse.transactionInfo!.hash).to.be.equal(signedLockFundsTransaction.hash); + const tx = await transactionService.announceAggregateBonded(signedAggregatedTransaction, helper.listener).toPromise(); + expect(tx.signer!.publicKey).to.be.equal(account.publicKey); + expect(tx.type).to.be.equal(TransactionType.AGGREGATE_BONDED); + }); }); @@ -211,7 +206,7 @@ describe('TransactionService', () => { describe('Restore test multisig Accounts', () => { - it('Announce MultisigAccountModificationTransaction', () => { + it('Announce MultisigAccountModificationTransaction', async () => { const removeCosigner1 = MultisigAccountModificationTransaction.create( Deadline.create(), -1, @@ -250,7 +245,7 @@ describe('TransactionService', () => { const signedTransaction = aggregateTransaction .signTransactionWithCosignatories(cosignAccount1, [cosignAccount2, cosignAccount3], generationHash); - return helper.announce(signedTransaction); + await helper.announce(signedTransaction); }); }); });