diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 214cf281ed..6600a2c992 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -16,6 +16,7 @@ import { expect } from 'chai'; import { AccountRepository } from '../../src/infrastructure/AccountRepository'; +import { TransactionFilter } from '../../src/infrastructure/infrastructure'; import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { QueryParams } from '../../src/infrastructure/QueryParams'; @@ -24,7 +25,7 @@ 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 { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -92,7 +93,7 @@ describe('AccountHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, @@ -213,7 +214,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should not return accounts when account does not exist', () => { - return accountRepository.getAccountInfo(Account.generateNewAccount(networkType).address).toPromise().then((r) => { + return accountRepository.getAccountInfo(Account.generateNewAccount(networkType).address).toPromise().then(() => { return Promise.reject('should fail!'); }, (err) => { const error = JSON.parse(err.message); @@ -227,7 +228,7 @@ 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(); + publicAccount.address, new QueryParams(), new TransactionFilter().setType([TransactionType.TRANSFER])).toPromise(); expect(transactions.length).to.be.greaterThan(0); transactions.forEach((t) => { expect(t.type).to.be.eq(TransactionType.TRANSFER); diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index 0d12e7a93b..088bc62ce2 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -23,7 +23,7 @@ import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; 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 { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { Deadline } from '../../src/model/transaction/Deadline'; import { TransactionInfo } from '../../src/model/transaction/TransactionInfo'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; @@ -73,7 +73,7 @@ describe('BlockHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, @@ -111,7 +111,8 @@ describe('BlockHttp', () => { }); 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(); + const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1), + new QueryParams().setPageSize(10).setId(nextId)).toPromise(); expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); expect(transactions.length).to.be.greaterThan(0); }); diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 5fcfbfea62..287c19a5b6 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -24,7 +24,7 @@ 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 { MosaicId } from '../../src/model/mosaic/MosaicId'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; @@ -45,7 +45,7 @@ describe('Listener', () => { let namespaceRepository: NamespaceRepository; let generationHash: string; let networkType: NetworkType; - const networkCurrencyMosaicId: NamespaceId = NetworkCurrencyMosaic.NAMESPACE_ID; + const NetworkCurrencyLocalId: NamespaceId = NetworkCurrencyLocal.NAMESPACE_ID; let transactionRepository: TransactionRepository; before(() => { @@ -100,7 +100,7 @@ describe('Listener', () => { mosaicId: MosaicId | NamespaceId) => { const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, @@ -180,7 +180,7 @@ describe('Listener', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), cosignAccount1.address, - [new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY)))], + [new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY)))], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -220,7 +220,7 @@ describe('Listener', () => { it('aggregateBondedTransactionsAdded', (done) => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, account, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, account, NetworkCurrencyLocalId); helper.listener.aggregateBondedAdded(account.address).subscribe(() => { done(); }); @@ -239,7 +239,7 @@ describe('Listener', () => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, NetworkCurrencyLocalId); helper.listener.confirmed(cosignAccount1.address).subscribe(() => { helper.listener.aggregateBondedRemoved(cosignAccount1.address).subscribe(() => { done(); @@ -274,7 +274,7 @@ describe('Listener', () => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, NetworkCurrencyLocalId); helper.listener.cosignatureAdded(cosignAccount1.address).subscribe(() => { done(); }); @@ -341,7 +341,7 @@ describe('Listener', () => { describe('Transactions Status', () => { it('transactionStatusGiven', () => { - const mosaics = [NetworkCurrencyMosaic.createRelative(1000000000000)]; + const mosaics = [NetworkCurrencyLocal.createRelative(1000000000000)]; const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, diff --git a/e2e/infrastructure/NamespaceHttp.spec.ts b/e2e/infrastructure/NamespaceHttp.spec.ts index b32a912997..2f99342369 100644 --- a/e2e/infrastructure/NamespaceHttp.spec.ts +++ b/e2e/infrastructure/NamespaceHttp.spec.ts @@ -18,7 +18,7 @@ import { expect } from 'chai'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -28,7 +28,7 @@ import { UInt64 } from '../../src/model/UInt64'; import { IntegrationTestHelper } from './IntegrationTestHelper'; describe('NamespaceHttp', () => { - const defaultNamespaceId = NetworkCurrencyMosaic.NAMESPACE_ID; + const defaultNamespaceId = NetworkCurrencyLocal.NAMESPACE_ID; let namespaceId: NamespaceId; let namespaceRepository: NamespaceRepository; let account: Account; diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 9b081b9b24..b0da9ac687 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -35,7 +35,7 @@ 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 { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountRestrictionModificationAction } from '../../src/model/restriction/AccountRestrictionModificationAction'; @@ -94,7 +94,7 @@ describe('TransactionHttp', () => { let generationHash: string; let networkType: NetworkType; let mosaicId: MosaicId; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; let namespaceId: NamespaceId; let harvestingAccount: Account; let transactionRepository: TransactionRepository; @@ -134,7 +134,7 @@ describe('TransactionHttp', () => { describe('Get network currency mosaic id', () => { it('get mosaicId', async () => { - networkCurrencyMosaicId = + NetworkCurrencyLocalId = (await namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise()) as MosaicId; }); }); @@ -386,7 +386,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -399,7 +399,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -672,7 +672,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), namespaceId, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -772,7 +772,7 @@ describe('TransactionHttp', () => { ); 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))), + new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10000), signedTransaction, networkType, helper.maxFee); @@ -812,7 +812,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10000), signedTransaction, networkType, helper.maxFee); @@ -831,7 +831,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10), signedTransaction, networkType, helper.maxFee); @@ -871,7 +871,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -893,7 +893,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -912,7 +912,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -927,7 +927,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -948,7 +948,7 @@ describe('TransactionHttp', () => { const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -965,7 +965,7 @@ describe('TransactionHttp', () => { const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -984,7 +984,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -999,7 +999,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -1023,7 +1023,7 @@ describe('TransactionHttp', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(11), HashType.Op_Sha3_256, secret, @@ -1061,7 +1061,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, secret, @@ -1094,7 +1094,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, secret, @@ -1123,7 +1123,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, secret, @@ -1157,7 +1157,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -1189,7 +1189,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -1223,7 +1223,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, secret, @@ -1254,7 +1254,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, secret, @@ -1288,8 +1288,8 @@ describe('TransactionHttp', () => { // AliceAccount: account // BobAccount: account - const sendAmount = NetworkCurrencyMosaic.createRelative(1000); - const backAmount = NetworkCurrencyMosaic.createRelative(1); + const sendAmount = NetworkCurrencyLocal.createRelative(1000); + const backAmount = NetworkCurrencyLocal.createRelative(1); const aliceTransferTransaction = TransferTransaction.create(Deadline.create(), account2.address, [sendAmount], PlainMessage.create('payout'), networkType, helper.maxFee); @@ -1384,7 +1384,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -1399,7 +1399,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createRelative(1)], + [NetworkCurrencyLocal.createRelative(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); diff --git a/e2e/infrastructure/UnresolvedMapping.spec.ts b/e2e/infrastructure/UnresolvedMapping.spec.ts index 4b5a6f1e0c..e8713e202b 100644 --- a/e2e/infrastructure/UnresolvedMapping.spec.ts +++ b/e2e/infrastructure/UnresolvedMapping.spec.ts @@ -24,7 +24,7 @@ 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 { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType'; @@ -50,7 +50,7 @@ describe('TransactionHttp', () => { let generationHash: string; let networkType: NetworkType; let mosaicId: MosaicId; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; let namespaceIdAddress: NamespaceId; let namespaceIdMosaic: NamespaceId; @@ -79,7 +79,7 @@ describe('TransactionHttp', () => { */ describe('Get network currency mosaic id', () => { it('get mosaicId', async () => { - networkCurrencyMosaicId = + NetworkCurrencyLocalId = (await namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise()) as MosaicId; }); }); @@ -259,7 +259,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); diff --git a/e2e/service/BlockService.spec.ts b/e2e/service/BlockService.spec.ts new file mode 100644 index 0000000000..675510c51e --- /dev/null +++ b/e2e/service/BlockService.spec.ts @@ -0,0 +1,111 @@ +/* + * 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 { assert, expect } from 'chai'; +import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; +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 { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; +import { Deadline } from '../../src/model/transaction/Deadline'; +import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; +import { UInt64 } from '../../src/model/UInt64'; +import { BlockService } from '../../src/service/BlockService'; +import { IntegrationTestHelper } from '../infrastructure/IntegrationTestHelper'; + +describe('BlockService', () => { + const helper = new IntegrationTestHelper(); + let generationHash: string; + let account: Account; + let account2: Account; + let account3: Account; + let networkType: NetworkType; + let transactionHash: string; + let blockService: BlockService; + let transactionRepository: TransactionRepository; + let receiptRepository: ReceiptRepository; + + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + account3 = helper.account3; + generationHash = helper.generationHash; + networkType = helper.networkType; + transactionRepository = helper.repositoryFactory.createTransactionRepository(); + receiptRepository = helper.repositoryFactory.createReceiptRepository(); + blockService = new BlockService(helper.repositoryFactory); + }); + }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + + /** + * ========================= + * Setup test data + * ========================= + */ + describe('Create a transfer', () => { + it('Announce TransferTransaction', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + [NetworkCurrencyLocal.createAbsolute(1)], + PlainMessage.create('test-message'), + networkType, + helper.maxFee, + ); + + const signedTransaction = transferTransaction.signWith(account, generationHash); + transactionHash = signedTransaction.hash; + return helper.announce(signedTransaction); + }); + }); + + /** + * ========================= + * Test + * ========================= + */ + + describe('Validate transansaction', () => { + it('call block service', async () => { + const transaction = await transactionRepository.getTransaction(transactionHash).toPromise(); + const transactionInfo = transaction.transactionInfo; + if (transactionInfo && transactionInfo.height !== undefined) { + const validationResult = await blockService.validateTransactionInBlock(transactionHash, transactionInfo.height).toPromise(); + expect(validationResult).to.be.true; + } else { + assert(false, `Transaction (hash: ${transactionHash}) not found`); + } + }); + }); + + describe('Validate receipt', () => { + it('call block service', async () => { + const statements = await receiptRepository.getBlockReceipts(UInt64.fromUint(1)).toPromise(); + const statement = statements.transactionStatements[0]; + const validationResult = await blockService.validateStatementInBlock(statement.generateHash(), UInt64.fromUint(1)).toPromise(); + expect(validationResult).to.be.true; + }); + }); +}); diff --git a/e2e/service/TransactionService.spec.ts b/e2e/service/TransactionService.spec.ts index afaae119ff..19aadb7c3c 100644 --- a/e2e/service/TransactionService.spec.ts +++ b/e2e/service/TransactionService.spec.ts @@ -26,7 +26,7 @@ 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 { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -199,7 +199,7 @@ describe('TransactionService', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), @@ -353,7 +353,7 @@ describe('TransactionService', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), diff --git a/e2e/service/TransactionService_AggregateBonded.spec.ts b/e2e/service/TransactionService_AggregateBonded.spec.ts index 5b5a50f493..b4c4ec81d6 100644 --- a/e2e/service/TransactionService_AggregateBonded.spec.ts +++ b/e2e/service/TransactionService_AggregateBonded.spec.ts @@ -23,7 +23,7 @@ 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 { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; @@ -49,7 +49,7 @@ describe('TransactionService', () => { let generationHash: string; let networkType: NetworkType; let transactionService: TransactionService; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; before(() => { return helper.start().then(() => { @@ -100,7 +100,7 @@ describe('TransactionService', () => { describe('Get network currency mosaic id', () => { it('get mosaicId', () => { return namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise().then((networkMosaicId: MosaicId) => { - networkCurrencyMosaicId = networkMosaicId; + NetworkCurrencyLocalId = networkMosaicId; }); }); }); @@ -144,7 +144,7 @@ describe('TransactionService', () => { Deadline.create(), account2.address, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), ], PlainMessage.create('test-message'), networkType, helper.maxFee, @@ -164,7 +164,7 @@ describe('TransactionService', () => { const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, @@ -184,7 +184,7 @@ describe('TransactionService', () => { const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, diff --git a/package-lock.json b/package-lock.json index 293580cdef..603c759bc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3833,9 +3833,9 @@ } }, "nem2-sdk-openapi-typescript-node-client": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.3.tgz", - "integrity": "sha512-e0B4FCi/uOjag84wpWTMAvR/J//JAmtP0agKg8fEBTiuD4gbGDKLLhfNtMCuMWdCw1nFX5aVVJrx3MakP/ad8w==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.4.tgz", + "integrity": "sha512-53DukFQUCKr0+bH1fm3fLzIT/v10lv5kdMqBHX4h4jDUslQeXnlBpPi/qX/XDmu2hyjwOWZa7hFzLhlt8xqhdQ==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 9b33dcbc47..58b0f5b0ec 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "js-sha512": "^0.8.0", "long": "^4.0.0", "merkletreejs": "^0.1.7", - "nem2-sdk-openapi-typescript-node-client": "0.8.3", + "nem2-sdk-openapi-typescript-node-client": "0.8.4", "request": "^2.88.0", "request-promise-native": "^1.0.5", "ripemd160": "^2.0.2", diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 7e3a6df1f3..2242d63afb 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -29,6 +29,7 @@ import { AccountRepository } from './AccountRepository'; import { Http } from './Http'; import { QueryParams } from './QueryParams'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; +import { TransactionFilter } from './TransactionFilter'; /** * Account http repository. @@ -108,26 +109,30 @@ export class AccountHttp extends Http implements AccountRepository { UInt64.fromNumericString(dto.account.importance), UInt64.fromNumericString(dto.account.importanceHeight), ); + } /** * Gets an array of confirmed transactions for which an account is signer or receiver. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order, - this.queryParams(queryParams).transactionType)).pipe( - map(({body}) => body.map((transactionDTO) => { - return CreateTransactionFromDTO(transactionDTO); - })), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering, + this.transactionFilter(transactionFilter).type)).pipe( + map(({body}) => body.map((transactionDTO) => { + return CreateTransactionFromDTO(transactionDTO); + })), + catchError((error) => throwError(this.errorHandling(error))), + ); } /** @@ -135,15 +140,18 @@ export class AccountHttp extends Http implements AccountRepository { * A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountIncomingTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountIncomingTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.queryParams(queryParams).ordering), + this.transactionFilter(transactionFilter).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -156,15 +164,18 @@ export class AccountHttp extends Http implements AccountRepository { * A transaction is said to be outgoing with respect to an account if the account is the sender of a transaction. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountOutgoingTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.queryParams(queryParams).ordering), + this.transactionFilter(transactionFilter).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -178,15 +189,18 @@ export class AccountHttp extends Http implements AccountRepository { * Unconfirmed transactions are not guaranteed to be included in any block. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountUnconfirmedTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.queryParams(queryParams).ordering), + this.transactionFilter(transactionFilter).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -199,15 +213,18 @@ export class AccountHttp extends Http implements AccountRepository { * A transaction is said to be aggregate bonded with respect to an account if there are missing signatures. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountPartialTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountPartialTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.queryParams(queryParams).ordering), + this.transactionFilter(transactionFilter).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction; })), diff --git a/src/infrastructure/AccountRepository.ts b/src/infrastructure/AccountRepository.ts index 3e2ee11701..bf6c77ae3f 100644 --- a/src/infrastructure/AccountRepository.ts +++ b/src/infrastructure/AccountRepository.ts @@ -19,7 +19,8 @@ import {AccountInfo} from '../model/account/AccountInfo'; import {Address} from '../model/account/Address'; import {AggregateTransaction} from '../model/transaction/AggregateTransaction'; import {Transaction} from '../model/transaction/Transaction'; -import {QueryParams} from './QueryParams'; +import { QueryParams } from './QueryParams'; +import { TransactionFilter } from './TransactionFilter'; /** * Account interface repository. @@ -46,27 +47,32 @@ export interface AccountRepository { * Gets an array of confirmed transactions for which an account is signer or receiver. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountTransactions(address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; /** * Gets an array of transactions for which an account is the recipient of a transaction. * A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountIncomingTransactions( + address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; /** * Gets an array of transactions for which an account is the sender a transaction. * A transaction is said to be outgoing with respect to an account if the account is the sender of a transaction. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountOutgoingTransactions( + address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; /** * Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block. @@ -74,16 +80,20 @@ export interface AccountRepository { * Unconfirmed transactions are not guaranteed to be included in any block. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountUnconfirmedTransactions( + address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; /** * Gets an array of transactions for which an account is the sender or has sign the transaction. * A transaction is said to be aggregate bonded with respect to an account if there are missing signatures. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountPartialTransactions( + address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; } diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index eb3a5d94a4..7877dd3600 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -73,7 +73,7 @@ export class BlockHttp extends Http implements BlockRepository { this.blockRoutesApi.getBlockTransactions(height.toString(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)) + this.queryParams(queryParams).ordering)) .pipe(map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index 4a1fcca01c..ea1bc767bb 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -20,6 +20,7 @@ import { from as observableFrom, Observable, of as observableOf, throwError } fr import { catchError, map, shareReplay } from 'rxjs/operators'; import { NetworkType } from '../model/blockchain/NetworkType'; import { QueryParams } from './QueryParams'; +import { TransactionFilter } from './TransactionFilter'; /** * Http extended by all http services @@ -52,8 +53,13 @@ export abstract class Http { return { pageSize: queryParams ? queryParams.pageSize : undefined, id: queryParams ? queryParams.id : undefined, - order: queryParams ? queryParams.order : undefined, - transactionType: queryParams ? queryParams.transactionType : undefined, + ordering: queryParams ? queryParams.order : undefined, + }; + } + + transactionFilter(filter?: TransactionFilter): any { + return { + type: filter ? filter.convertCSV(filter.type) : undefined, }; } diff --git a/src/infrastructure/MetadataHttp.ts b/src/infrastructure/MetadataHttp.ts index fbd3ca4577..221cfcbe8a 100644 --- a/src/infrastructure/MetadataHttp.ts +++ b/src/infrastructure/MetadataHttp.ts @@ -62,7 +62,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getAccountMetadata(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), @@ -112,7 +112,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getMosaicMetadata(mosaicId.toHex(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), @@ -162,7 +162,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getNamespaceMetadata(namespaceId.toHex(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), diff --git a/src/infrastructure/NamespaceHttp.ts b/src/infrastructure/NamespaceHttp.ts index 86b3bff8ea..8471e95d5d 100644 --- a/src/infrastructure/NamespaceHttp.ts +++ b/src/infrastructure/NamespaceHttp.ts @@ -152,7 +152,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { this.namespaceRoutesApi.getNamespacesFromAccount(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.namespaces.map((namespaceInfoDTO) => { return new NamespaceInfo( namespaceInfoDTO.meta.active, diff --git a/src/infrastructure/NodeHttp.ts b/src/infrastructure/NodeHttp.ts index 988c8758d5..ce74c0fe8b 100644 --- a/src/infrastructure/NodeHttp.ts +++ b/src/infrastructure/NodeHttp.ts @@ -56,6 +56,7 @@ export class NodeHttp extends Http implements NodeRepository { return observableFrom(this.nodeRoutesApi.getNodeInfo()).pipe( map(({body}) => new NodeInfo( body.publicKey, + body.networkGenerationHash, body.port, body.networkIdentifier, body.version, diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index fa3fc36b73..e271e04ee3 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -1,5 +1,3 @@ -import { TransactionType } from '../model/transaction/TransactionType'; - /* * Copyright 2018 NEM * @@ -16,6 +14,8 @@ import { TransactionType } from '../model/transaction/TransactionType'; * limitations under the License. */ +import { TransactionType } from '../model/transaction/TransactionType'; + /** * @since 0.11.3 */ @@ -30,32 +30,39 @@ export enum Order { * @since 1.0 */ export class QueryParams { + /** + * Page size between 10 and 100, otherwise 10 + */ + public pageSize = 10; + /** + * Id after which we want objects to be returned + */ + public id?: string; + /** + * Order of transactions. + * DESC. Newer to older. + * ASC. Older to newer. + */ + public order: Order = Order.DESC; /** * Constructor - * @param pageSize - * @param id */ - constructor( - /** - * Page size between 10 and 100, otherwise 10 - */ - public readonly pageSize: number, - /** - * Id after which we want objects to be returned - */ - public readonly id?: string, - /** - * Order of transactions. - * DESC. Newer to older. - * ASC. Older to newer. - */ - public readonly order: Order = Order.DESC, - /** - * Transaction type filter - */ - public readonly transactionType?: TransactionType, - ) { + constructor() { + } + + public setPageSize(pageSize: number): QueryParams { this.pageSize = (pageSize >= 10 && pageSize <= 100) ? pageSize : 10; + return this; + } + + public setId(id?: string): QueryParams { + this.id = id; + return this; + } + + public setOrder(order: Order = Order.DESC): QueryParams { + this.order = order; + return this; } } diff --git a/src/infrastructure/TransactionFilter.ts b/src/infrastructure/TransactionFilter.ts new file mode 100644 index 0000000000..fcf54d197e --- /dev/null +++ b/src/infrastructure/TransactionFilter.ts @@ -0,0 +1,50 @@ +/* + * Copyright 2020 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 { TransactionType } from '../model/transaction/TransactionType'; +import { QueryParams } from './QueryParams'; + +/** + * The Transaction filter class + */ +export class TransactionFilter { + /** + * Transaction type list + */ + public type?: TransactionType[]; + /** + * Constructor + */ + constructor() { + } + + public setType(type?: TransactionType[]): TransactionFilter { + this.type = type; + return this; + } + + /** + * Return comma seperated list + * @param type Transaction type list + */ + public convertCSV(type?: TransactionType[]): string | undefined { + if (!type || type.length === 0) { + return undefined; + } else { + return type.map((t) => t.valueOf().toString()).join(','); + } + } +} diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 3a297391a7..46ab3b8f29 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -47,3 +47,4 @@ export * from './RepositoryFactory'; export * from './RestrictionAccountRepository'; export * from './RestrictionMosaicRepository'; export * from './TransactionRepository'; +export * from './TransactionFilter'; diff --git a/src/model/blockchain/MerklePathItem.ts b/src/model/blockchain/MerklePathItem.ts index a004229c18..d87006889d 100644 --- a/src/model/blockchain/MerklePathItem.ts +++ b/src/model/blockchain/MerklePathItem.ts @@ -1,3 +1,5 @@ +import { PositionEnum } from "nem2-sdk-openapi-typescript-node-client/dist/model/positionEnum"; + /* * Copyright 2019 NEM * @@ -26,7 +28,7 @@ export class MerklePathItem { constructor(/** * The position */ - public readonly position?: number, + public readonly position?: PositionEnum, /** * The hash */ diff --git a/src/model/model.ts b/src/model/model.ts index ee624e7d69..4f97aa7e4a 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -49,8 +49,9 @@ export * from './mosaic/MosaicSupplyChangeAction'; export * from './mosaic/MosaicFlags'; export * from '../service/MosaicView'; export * from '../service/MosaicAmountView'; -export * from './mosaic/NetworkCurrencyMosaic'; -export * from './mosaic/NetworkHarvestMosaic'; +export * from './mosaic/NetworkCurrencyLocal'; +export * from './mosaic/NetworkCurrencyPublic'; +export * from './mosaic/NetworkHarvestLocal'; export * from './mosaic/MosaicNames'; // Mosaic diff --git a/src/model/mosaic/NetworkCurrencyMosaic.ts b/src/model/mosaic/NetworkCurrencyLocal.ts similarity index 68% rename from src/model/mosaic/NetworkCurrencyMosaic.ts rename to src/model/mosaic/NetworkCurrencyLocal.ts index fb2ebc2722..c1a6e34dc9 100644 --- a/src/model/mosaic/NetworkCurrencyMosaic.ts +++ b/src/model/mosaic/NetworkCurrencyLocal.ts @@ -20,14 +20,14 @@ import {Mosaic} from './Mosaic'; import {MosaicId} from './MosaicId'; /** - * NetworkCurrencyMosaic mosaic + * NetworkCurrencyLocal mosaic for local test network (local bootstrap server) * * This represents the per-network currency mosaic. This mosaicId is aliased * with namespace name `cat.currency`. * * @since 0.10.2 */ -export class NetworkCurrencyMosaic extends Mosaic { +export class NetworkCurrencyLocal extends Mosaic { /** * namespaceId of `currency` namespace. @@ -66,33 +66,33 @@ export class NetworkCurrencyMosaic extends Mosaic { * @param amount */ private constructor(amount: UInt64) { - super(NetworkCurrencyMosaic.NAMESPACE_ID, amount); + super(NetworkCurrencyLocal.NAMESPACE_ID, amount); } /** - * Create NetworkCurrencyMosaic with using NetworkCurrencyMosaic as unit. + * Create NetworkCurrencyLocal with using NetworkCurrencyLocal as unit. * * @param amount - * @returns {NetworkCurrencyMosaic} + * @returns {NetworkCurrencyLocal} */ public static createRelative(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkCurrencyMosaic(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))); + return new NetworkCurrencyLocal(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))); } - return new NetworkCurrencyMosaic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))); + return new NetworkCurrencyLocal(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))); } /** - * Create NetworkCurrencyMosaic with using micro NetworkCurrencyMosaic as unit, - * 1 NetworkCurrencyMosaic = 1000000 micro NetworkCurrencyMosaic. + * Create NetworkCurrencyLocal with using micro NetworkCurrencyLocal as unit, + * 1 NetworkCurrencyLocal = 1000000 micro NetworkCurrencyLocal. * * @param amount - * @returns {NetworkCurrencyMosaic} + * @returns {NetworkCurrencyLocal} */ public static createAbsolute(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkCurrencyMosaic(UInt64.fromUint(amount)); + return new NetworkCurrencyLocal(UInt64.fromUint(amount)); } - return new NetworkCurrencyMosaic(amount as UInt64); + return new NetworkCurrencyLocal(amount as UInt64); } } diff --git a/src/model/mosaic/NetworkCurrencyPublic.ts b/src/model/mosaic/NetworkCurrencyPublic.ts new file mode 100644 index 0000000000..bb9b39bf04 --- /dev/null +++ b/src/model/mosaic/NetworkCurrencyPublic.ts @@ -0,0 +1,98 @@ +/* + * 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 {NamespaceId} from '../namespace/NamespaceId'; +import {UInt64} from '../UInt64'; +import {Mosaic} from './Mosaic'; +import {MosaicId} from './MosaicId'; + +/** + * NetworkCurrencyPublic mosaic for public / Public_test network + * + * This represents the per-network currency mosaic. This mosaicId is aliased + * with namespace name `symbol.xym`. + * + * @since 0.10.2 + */ +export class NetworkCurrencyPublic extends Mosaic { + + /** + * namespaceId of `currency` namespace. + * + * @type {Id} + */ + public static NAMESPACE_ID = new NamespaceId('symbol.xym'); + + /** + * Divisiblity + * @type {number} + */ + public static DIVISIBILITY = 6; + + /** + * Initial supply + * @type {number} + */ + public static INITIAL_SUPPLY = 8999999998; + + /** + * Is tranferable + * @type {boolean} + */ + public static TRANSFERABLE = true; + + /** + * Is Supply mutable + * @type {boolean} + */ + public static SUPPLY_MUTABLE = false; + + /** + * constructor + * @param owner + * @param amount + */ + private constructor(amount: UInt64) { + super(NetworkCurrencyPublic.NAMESPACE_ID, amount); + } + + /** + * Create NetworkCurrencyPublic with using NetworkCurrencyPublic as unit. + * + * @param amount + * @returns {NetworkCurrencyPublic} + */ + public static createRelative(amount: UInt64 | number) { + if (typeof amount === 'number') { + return new NetworkCurrencyPublic(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyPublic.DIVISIBILITY))); + } + return new NetworkCurrencyPublic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyPublic.DIVISIBILITY))); + } + + /** + * Create NetworkCurrencyPublic with using micro NetworkCurrencyPublic as unit, + * 1 NetworkCurrencyPublic = 1000000 micro NetworkCurrencyPublic. + * + * @param amount + * @returns {NetworkCurrencyPublic} + */ + public static createAbsolute(amount: UInt64 | number) { + if (typeof amount === 'number') { + return new NetworkCurrencyPublic(UInt64.fromUint(amount)); + } + return new NetworkCurrencyPublic(amount as UInt64); + } +} diff --git a/src/model/mosaic/NetworkHarvestMosaic.ts b/src/model/mosaic/NetworkHarvestLocal.ts similarity index 69% rename from src/model/mosaic/NetworkHarvestMosaic.ts rename to src/model/mosaic/NetworkHarvestLocal.ts index f9df23fb98..c600988cf1 100644 --- a/src/model/mosaic/NetworkHarvestMosaic.ts +++ b/src/model/mosaic/NetworkHarvestLocal.ts @@ -19,14 +19,14 @@ import {Mosaic} from './Mosaic'; import {MosaicId} from './MosaicId'; /** - * NetworkHarvestMosaic mosaic + * NetworkHarvestLocal mosaic * * This represents the per-network harvest mosaic. This mosaicId is aliased * with namespace name `cat.harvest`. * * @since 0.10.2 */ -export class NetworkHarvestMosaic extends Mosaic { +export class NetworkHarvestLocal extends Mosaic { /** * namespaceId of `currency` namespace. @@ -65,33 +65,33 @@ export class NetworkHarvestMosaic extends Mosaic { * @param amount */ private constructor(amount: UInt64) { - super(NetworkHarvestMosaic.NAMESPACE_ID, amount); + super(NetworkHarvestLocal.NAMESPACE_ID, amount); } /** - * Create NetworkHarvestMosaic with using NetworkHarvestMosaic as unit. + * Create NetworkHarvestLocal with using NetworkHarvestLocal as unit. * * @param amount - * @returns {NetworkHarvestMosaic} + * @returns {NetworkHarvestLocal} */ public static createRelative(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkHarvestMosaic(UInt64.fromUint(amount * Math.pow(10, NetworkHarvestMosaic.DIVISIBILITY))); + return new NetworkHarvestLocal(UInt64.fromUint(amount * Math.pow(10, NetworkHarvestLocal.DIVISIBILITY))); } - return new NetworkHarvestMosaic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkHarvestMosaic.DIVISIBILITY))); + return new NetworkHarvestLocal(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkHarvestLocal.DIVISIBILITY))); } /** - * Create NetworkHarvestMosaic with using micro NetworkHarvestMosaic as unit, - * 1 NetworkHarvestMosaic = 1000000 micro NetworkHarvestMosaic. + * Create NetworkHarvestLocal with using micro NetworkHarvestLocal as unit, + * 1 NetworkHarvestLocal = 1000000 micro NetworkHarvestLocal. * * @param amount - * @returns {NetworkHarvestMosaic} + * @returns {NetworkHarvestLocal} */ public static createAbsolute(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkHarvestMosaic(UInt64.fromUint(amount)); + return new NetworkHarvestLocal(UInt64.fromUint(amount)); } - return new NetworkHarvestMosaic(amount as UInt64); + return new NetworkHarvestLocal(amount as UInt64); } } diff --git a/src/model/node/NodeInfo.ts b/src/model/node/NodeInfo.ts index 82947da021..1d0632366d 100644 --- a/src/model/node/NodeInfo.ts +++ b/src/model/node/NodeInfo.ts @@ -22,6 +22,7 @@ export class NodeInfo { /** * @param publicKey + * @param networkGenerationHash * @param port * @param networkIdentifier * @param version @@ -33,6 +34,10 @@ export class NodeInfo { * The public key used to identify the node. */ public readonly publicKey: string, + /** + * The network generation hash + */ + public readonly networkGenerationHash: string, /** * The port used for the communication. */ diff --git a/src/service/BlockService.ts b/src/service/BlockService.ts new file mode 100644 index 0000000000..2e357ccae3 --- /dev/null +++ b/src/service/BlockService.ts @@ -0,0 +1,92 @@ +/* + * Copyright 2020 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 { sha3_256 } from 'js-sha3'; +import { PositionEnum } from 'nem2-sdk-openapi-typescript-node-client/dist/model/positionEnum'; +import { combineLatest, Observable, of } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; +import { BlockRepository } from '../infrastructure/BlockRepository'; +import { ReceiptRepository } from '../infrastructure/ReceiptRepository'; +import { RepositoryFactory } from '../infrastructure/RepositoryFactory'; +import { MerklePathItem } from '../model/blockchain/MerklePathItem'; +import { UInt64 } from '../model/UInt64'; + +/** + * Transaction Service + */ +export class BlockService { + private readonly blockRepository: BlockRepository; + private readonly receiptRepository: ReceiptRepository; + + /** + * Constructor + * @param repositoryFactory + */ + constructor(public readonly repositoryFactory: RepositoryFactory) { + this.blockRepository = repositoryFactory.createBlockRepository(); + this.receiptRepository = repositoryFactory.createReceiptRepository(); + } + + /** + * Validate transaction hash in block + * @param leaf transaction hash + * @param height block height + */ + public validateTransactionInBlock(leaf: string, height: UInt64): Observable { + const rootHashObservable = this.blockRepository.getBlockByHeight(height); + const merklePathItemObservable = this.blockRepository.getMerkleTransaction(height, leaf); + return combineLatest(rootHashObservable, merklePathItemObservable).pipe( + map((combined) => this.validateInBlock(leaf, combined[1].merklePath, combined[0].blockTransactionsHash)), + ).pipe(catchError(() => of(false))); + } + + /** + * Validate statement hash in block + * @param leaf statement hash + * @param height block height + */ + public validateStatementInBlock(leaf: string, height: UInt64): Observable { + const rootHashObservable = this.blockRepository.getBlockByHeight(height); + const merklePathItemObservable = this.receiptRepository.getMerkleReceipts(height, leaf); + return combineLatest(rootHashObservable, merklePathItemObservable).pipe( + map((combined) => this.validateInBlock(leaf, combined[1].merklePath, combined[0].blockReceiptsHash)), + ).pipe(catchError(() => of(false))); + } + + /** + * @internal + * Validate leaf against merkle tree in block + * @param leaf Leaf hash in merkle tree + * @param merklePathItem Merkle path item array + * @param rootHash Block root hash + */ + private validateInBlock(leaf: string, merklePathItem: MerklePathItem[] = [], rootHash: string): boolean { + if (merklePathItem.length === 0) { + return leaf.toUpperCase() === rootHash.toUpperCase(); + } + const rootToCompare = merklePathItem.reduce((proofHash, pathItem) => { + const hasher = sha3_256.create(); + // Left + if (pathItem.position !== undefined && pathItem.position === PositionEnum.Left) { + return hasher.update(Buffer.from(pathItem.hash + proofHash, 'hex')).hex(); + } else { + // Right + return hasher.update(Buffer.from(proofHash + pathItem.hash, 'hex')).hex(); + } + }, leaf); + return rootToCompare.toUpperCase() === rootHash.toUpperCase(); + } +} diff --git a/src/service/interfaces/IBlockService.ts b/src/service/interfaces/IBlockService.ts new file mode 100644 index 0000000000..e8d349c25b --- /dev/null +++ b/src/service/interfaces/IBlockService.ts @@ -0,0 +1,38 @@ +/* + * Copyright 2020 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 { UInt64 } from '../../model/UInt64'; + +/** + * Block Service Interface + */ +export interface IBlockService { + + /** + * Validate transaction hash in block + * @param leaf transaction hash + * @param height block height + */ + validateTransactionInBlock(leaf: string, height: UInt64): Observable; + + /** + * Validate statement hash in block + * @param leaf statement hash + * @param height block height + */ + validateStatementInBlock(leaf: string, height: UInt64): Observable; +} diff --git a/src/service/service.ts b/src/service/service.ts index fd6074d5c4..ed73b3ff59 100644 --- a/src/service/service.ts +++ b/src/service/service.ts @@ -20,3 +20,4 @@ export * from './AggregateTransactionService'; export * from './MetadataTransactionService'; export * from './MosaicRestrictionTransactionService'; export * from './TransactionService'; +export * from './BlockService'; diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 30618d20c0..ecfda570d4 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -31,7 +31,7 @@ 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 { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceRegistrationType } from '../../../src/model/namespace/NamespaceRegistrationType'; @@ -320,7 +320,7 @@ describe('TransactionMapping - createFromPayload', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -341,7 +341,7 @@ describe('TransactionMapping - createFromPayload', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -462,7 +462,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); @@ -471,7 +471,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedLockFundTransaction.payload) as LockFundsTransaction; - deepEqual(transaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(transaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); }); @@ -676,7 +676,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -693,7 +693,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), new NamespaceId([33347626, 3779697293]), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -710,7 +710,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], new EncryptedMessage('12324556'), NetworkType.MIJIN_TEST, @@ -871,7 +871,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -892,7 +892,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const recipientAddress = new NamespaceId('test'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -1049,7 +1049,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index fece5987ac..5e23359f61 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -26,7 +26,7 @@ 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 { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountRestrictionFlags } from '../../src/model/restriction/AccountRestrictionType'; @@ -217,7 +217,7 @@ describe('SerializeTransactionToJSON', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -236,7 +236,7 @@ describe('SerializeTransactionToJSON', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -341,7 +341,7 @@ describe('SerializeTransactionToJSON', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/infrastructure/TransactionFilter.spec.ts b/test/infrastructure/TransactionFilter.spec.ts new file mode 100644 index 0000000000..4e90894047 --- /dev/null +++ b/test/infrastructure/TransactionFilter.spec.ts @@ -0,0 +1,28 @@ +/* + * Copyright 2020 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 { TransactionFilter } from '../../src/infrastructure/TransactionFilter'; +import { TransactionType } from '../../src/model/transaction/TransactionType'; + +describe('TransactionFilter', () => { + it('should return correct query param', () => { + const param = new TransactionFilter() + .setType([TransactionType.TRANSFER, TransactionType.ACCOUNT_LINK]); + + expect(param.convertCSV(param.type)).to.be.equal('16724,16716'); + }); +}); diff --git a/test/model/message/EncryptedMessage.spec.ts b/test/model/message/EncryptedMessage.spec.ts index 7031093396..ae4cf20a5a 100644 --- a/test/model/message/EncryptedMessage.spec.ts +++ b/test/model/message/EncryptedMessage.spec.ts @@ -17,7 +17,7 @@ import {expect} from 'chai'; import {Account} from '../../../src/model/account/Account'; import {EncryptedMessage} from '../../../src/model/message/EncryptedMessage'; -import { Deadline, NetworkCurrencyMosaic, NetworkType, TransferTransaction } from '../../../src/model/model'; +import { Deadline, NetworkCurrencyLocal, NetworkType, TransferTransaction } from '../../../src/model/model'; describe('EncryptedMessage', () => { @@ -61,7 +61,7 @@ describe('EncryptedMessage', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), recipient.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], sender.encryptMessage('Testing simple transfer', recipient.publicAccount, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); diff --git a/test/model/mosaic/NetworkCurrency.spec.ts b/test/model/mosaic/NetworkCurrency.spec.ts new file mode 100644 index 0000000000..7f61656afa --- /dev/null +++ b/test/model/mosaic/NetworkCurrency.spec.ts @@ -0,0 +1,69 @@ +/* + * 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 {deepEqual} from 'assert'; +import {expect} from 'chai'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; +import { NetworkCurrencyPublic } from '../../../src/model/mosaic/NetworkCurrencyPublic'; +import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; +import { UInt64 } from '../../../src/model/UInt64'; + +describe('NetworkCurrencyLocal', () => { + + it('should createComplete an NetworkCurrencyLocal object', () => { + + const currency = NetworkCurrencyLocal.createRelative(1000); + + deepEqual(currency.id.id.toHex(), '85BBEA6CC462B244'); // holds NAMESPACE_ID + expect(currency.amount.compact()).to.be.equal(1000 * 1000000); + }); + + it('should set amount in smallest unit when toDTO()', () => { + + const currency = NetworkCurrencyLocal.createRelative(1000); + expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); + }); + + it('should have valid statics', () => { + deepEqual(NetworkCurrencyLocal.NAMESPACE_ID.id, new NamespaceId([3294802500, 2243684972]).id); + expect(NetworkCurrencyLocal.DIVISIBILITY).to.be.equal(6); + expect(NetworkCurrencyLocal.TRANSFERABLE).to.be.equal(true); + expect(NetworkCurrencyLocal.SUPPLY_MUTABLE).to.be.equal(false); + }); +}); + +describe('NetworkCurrencyPublic', () => { + + it('should createComplete an NetworkCurrencyPublic object', () => { + + const currency = NetworkCurrencyPublic.createRelative(1000); + deepEqual(currency.id.id.toHex(), 'E74B99BA41F4AFEE'); // holds NAMESPACE_ID + expect(currency.amount.compact()).to.be.equal(1000 * 1000000); + }); + + it('should set amount in smallest unit when toDTO()', () => { + + const currency = NetworkCurrencyPublic.createRelative(1000); + expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); + }); + + it('should have valid statics', () => { + deepEqual(NetworkCurrencyPublic.NAMESPACE_ID.id, new NamespaceId([1106554862, 3880491450]).id); + expect(NetworkCurrencyPublic.DIVISIBILITY).to.be.equal(6); + expect(NetworkCurrencyPublic.TRANSFERABLE).to.be.equal(true); + expect(NetworkCurrencyPublic.SUPPLY_MUTABLE).to.be.equal(false); + }); +}); diff --git a/test/model/mosaic/NetworkCurrencyMosaic.spec.ts b/test/model/mosaic/NetworkCurrencyMosaic.spec.ts deleted file mode 100644 index dd0acf6e2c..0000000000 --- a/test/model/mosaic/NetworkCurrencyMosaic.spec.ts +++ /dev/null @@ -1,45 +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 {deepEqual} from 'assert'; -import {expect} from 'chai'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; -import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; -import { UInt64 } from '../../../src/model/UInt64'; - -describe('NetworkCurrencyMosaic', () => { - - it('should createComplete an NetworkCurrencyMosaic object', () => { - - const currency = NetworkCurrencyMosaic.createRelative(1000); - - deepEqual(currency.id.id.toHex(), '85BBEA6CC462B244'); // holds NAMESPACE_ID - expect(currency.amount.compact()).to.be.equal(1000 * 1000000); - }); - - it('should set amount in smallest unit when toDTO()', () => { - - const currency = NetworkCurrencyMosaic.createRelative(1000); - expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); - }); - - it('should have valid statics', () => { - deepEqual(NetworkCurrencyMosaic.NAMESPACE_ID.id, new NamespaceId([3294802500, 2243684972]).id); - expect(NetworkCurrencyMosaic.DIVISIBILITY).to.be.equal(6); - expect(NetworkCurrencyMosaic.TRANSFERABLE).to.be.equal(true); - expect(NetworkCurrencyMosaic.SUPPLY_MUTABLE).to.be.equal(false); - }); -}); diff --git a/test/model/mosaic/NetworkHarvestMosaic.spec.ts b/test/model/mosaic/NetworkHarvestLocal.spec.ts similarity index 65% rename from test/model/mosaic/NetworkHarvestMosaic.spec.ts rename to test/model/mosaic/NetworkHarvestLocal.spec.ts index baa710071a..83cf35dd91 100644 --- a/test/model/mosaic/NetworkHarvestMosaic.spec.ts +++ b/test/model/mosaic/NetworkHarvestLocal.spec.ts @@ -17,15 +17,15 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; -import {NetworkHarvestMosaic} from '../../../src/model/mosaic/NetworkHarvestMosaic'; +import {NetworkHarvestLocal} from '../../../src/model/mosaic/NetworkHarvestLocal'; import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; import { UInt64 } from '../../../src/model/UInt64'; -describe('NetworkHarvestMosaic', () => { +describe('NetworkHarvestLocal', () => { - it('should createComplete an NetworkHarvestMosaic object', () => { + it('should createComplete an NetworkHarvestLocal object', () => { - const currency = NetworkHarvestMosaic.createRelative(1000); + const currency = NetworkHarvestLocal.createRelative(1000); deepEqual(currency.id.id.toHex(), '941299B2B7E1291C'); expect(currency.amount.compact()).to.be.equal(1000 * 1000); @@ -33,14 +33,14 @@ describe('NetworkHarvestMosaic', () => { it('should set amount in smallest unit when toDTO()', () => { - const currency = NetworkHarvestMosaic.createRelative(1000); + const currency = NetworkHarvestLocal.createRelative(1000); expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000); }); it('should have valid statics', () => { - deepEqual(NetworkHarvestMosaic.NAMESPACE_ID.id, new NamespaceId([3084986652, 2484246962]).id); - expect(NetworkHarvestMosaic.DIVISIBILITY).to.be.equal(3); - expect(NetworkHarvestMosaic.TRANSFERABLE).to.be.equal(true); - expect(NetworkHarvestMosaic.SUPPLY_MUTABLE).to.be.equal(true); + deepEqual(NetworkHarvestLocal.NAMESPACE_ID.id, new NamespaceId([3084986652, 2484246962]).id); + expect(NetworkHarvestLocal.DIVISIBILITY).to.be.equal(3); + expect(NetworkHarvestLocal.TRANSFERABLE).to.be.equal(true); + expect(NetworkHarvestLocal.SUPPLY_MUTABLE).to.be.equal(true); }); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index f4b136adc6..83fbb051e0 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -30,7 +30,7 @@ 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 { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -549,7 +549,7 @@ describe('AggregateTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, diff --git a/test/model/transaction/HashLockTransaction.spec.ts b/test/model/transaction/HashLockTransaction.spec.ts index 70df873a44..65a2fca403 100644 --- a/test/model/transaction/HashLockTransaction.spec.ts +++ b/test/model/transaction/HashLockTransaction.spec.ts @@ -16,7 +16,7 @@ import {expect} from 'chai'; import {Convert} from '../../../src/core/format'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; -import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashLockTransaction} from '../../../src/model/transaction/HashLockTransaction'; @@ -35,11 +35,11 @@ describe('HashLockTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const transaction = HashLockTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); - expect(transaction.mosaic.id).to.be.equal(NetworkCurrencyMosaic.NAMESPACE_ID); + expect(transaction.mosaic.id).to.be.equal(NetworkCurrencyLocal.NAMESPACE_ID); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); expect(Convert.hexToUint8(transaction.serialize()).length).to.be.equal(transaction.size); @@ -55,7 +55,7 @@ describe('HashLockTransaction', () => { const signedTransaction = account.sign(aggregateTransaction, generationHash); expect(() => { HashLockTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index 3287d3abda..f43a11b4c7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -20,7 +20,7 @@ import {Account} from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -58,7 +58,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -78,7 +78,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -98,11 +98,11 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const transaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); - deepEqual(transaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(transaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); }); @@ -117,7 +117,7 @@ describe('LockFundsTransaction', () => { const signedTransaction = account.sign(aggregateTransaction, generationHash); expect(() => { LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); @@ -133,7 +133,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -156,7 +156,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -174,7 +174,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 612b1ef7b8..ebb2d0cb04 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -23,7 +23,7 @@ import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -59,7 +59,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -76,7 +76,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -94,14 +94,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(0); @@ -114,7 +114,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -135,7 +135,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, 'non valid hash', @@ -150,14 +150,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, keccak_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(1); @@ -170,7 +170,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, 'non valid hash', @@ -184,14 +184,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, CryptoJS.RIPEMD160(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(2); @@ -204,7 +204,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, 'non valid hash', @@ -218,14 +218,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, CryptoJS.SHA256(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(3); @@ -238,7 +238,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, 'non valid hash', @@ -254,7 +254,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, CryptoJS.SHA256(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), @@ -271,14 +271,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = new NamespaceId('test'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(0); @@ -291,7 +291,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 6bdc150911..e8f551fda1 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -27,7 +27,7 @@ import { PlainMessage } from '../../../src/model/message/PlainMessage'; import { ReceiptSource, ResolutionEntry, ResolutionType, TransactionInfo } from '../../../src/model/model'; import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; -import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ResolutionStatement } from '../../../src/model/receipt/ResolutionStatement'; import { Statement } from '../../../src/model/receipt/Statement'; @@ -113,7 +113,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -140,7 +140,7 @@ describe('TransferTransaction', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -166,7 +166,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -188,7 +188,7 @@ describe('TransferTransaction', () => { Deadline.create(), new NamespaceId('nem.owner'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -211,7 +211,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, @@ -226,7 +226,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -289,7 +289,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage .create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, @@ -302,7 +302,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create('abc', recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); @@ -314,7 +314,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); @@ -384,7 +384,7 @@ describe('TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.createFromDTO('1'), namespaceId, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, ); @@ -401,7 +401,7 @@ describe('TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, ).setMaxFee(2); diff --git a/test/service/BlockService.spec.ts b/test/service/BlockService.spec.ts new file mode 100644 index 0000000000..6145946807 --- /dev/null +++ b/test/service/BlockService.spec.ts @@ -0,0 +1,112 @@ +/* + * 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 { of as observableOf } from 'rxjs'; +import { deepEqual, instance, mock, when } from 'ts-mockito'; +import { BlockRepository } from '../../src/infrastructure/BlockRepository'; +import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; +import { RepositoryFactory } from '../../src/infrastructure/RepositoryFactory'; +import { Account } from '../../src/model/account/Account'; +import { BlockInfo } from '../../src/model/blockchain/BlockInfo'; +import { MerklePathItem } from '../../src/model/blockchain/MerklePathItem'; +import { MerkleProofInfo } from '../../src/model/blockchain/MerkleProofInfo'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; +import { UInt64 } from '../../src/model/UInt64'; +import { BlockService } from '../../src/service/BlockService'; +import { TestingAccount } from '../conf/conf.spec'; +import { PositionEnum } from 'nem2-sdk-openapi-typescript-node-client'; + +describe('BlockService', () => { + + const mockBlockHash = 'D4EC16FCFE696EFDBF1820F68245C88135ACF4C6F888599C8E18BC09B9F08C7B'; + const leaf = '2717C8AAB0A21896D0C56375209E761F84383C3882F37A11D9D0159007263EB2'; + let blockService: BlockService; + let account: Account; + before(() => { + account = TestingAccount; + const mockBlockRepository = mock(); + const mockReceiptRepository = mock(); + const mockRepoFactory = mock(); + + when(mockBlockRepository.getBlockByHeight(deepEqual(UInt64.fromUint(1)))) + .thenReturn(observableOf(mockBlockInfo())); + when(mockBlockRepository.getBlockByHeight(deepEqual(UInt64.fromUint(2)))) + .thenReturn(observableOf(mockBlockInfo(true))); + when(mockBlockRepository.getMerkleTransaction(deepEqual(UInt64.fromUint(1)), leaf)) + .thenReturn(observableOf(mockMerklePath())); + when(mockBlockRepository.getMerkleTransaction(deepEqual(UInt64.fromUint(2)), leaf)) + .thenReturn(observableOf(mockMerklePath())); + when(mockReceiptRepository.getMerkleReceipts(deepEqual(UInt64.fromUint(1)), leaf)) + .thenReturn(observableOf(mockMerklePath())); + when(mockReceiptRepository.getMerkleReceipts(deepEqual(UInt64.fromUint(2)), leaf)) + .thenReturn(observableOf(mockMerklePath())); + const blockRepository = instance(mockBlockRepository); + const receiptRepository = instance(mockReceiptRepository); + + when(mockRepoFactory.createBlockRepository()).thenReturn(blockRepository); + when(mockRepoFactory.createReceiptRepository()).thenReturn(receiptRepository); + const repoFactory = instance(mockRepoFactory); + blockService = new BlockService(repoFactory); + }); + + it('should validate transaction', async () => { + const result = await blockService.validateTransactionInBlock(leaf, UInt64.fromUint(1)).toPromise(); + expect(result).to.be.true; + }); + + it('should validate transaction - wrong hash', async () => { + const result = await blockService.validateTransactionInBlock(leaf, UInt64.fromUint(2)).toPromise(); + expect(result).to.be.false; + }); + + it('should validate statement', async () => { + const result = await blockService.validateStatementInBlock(leaf, UInt64.fromUint(1)).toPromise(); + expect(result).to.be.true; + }); + + it('should validate statement - wrong hash', async () => { + const result = await blockService.validateStatementInBlock(leaf, UInt64.fromUint(2)).toPromise(); + expect(result).to.be.false; + }); + + function mockBlockInfo(isFake: boolean = false): BlockInfo { + if (isFake) { + return new BlockInfo( + 'hash', 'generationHash', UInt64.fromNumericString('0'), 1, 'signature', account.publicAccount, + NetworkType.MIJIN_TEST, 0, 0, UInt64.fromUint(1), UInt64.fromUint(0), UInt64.fromUint(0), 0, 'previousHash', + 'fakeHash', 'fakeHash', 'stateHash', undefined, + ); + } + return new BlockInfo( + 'hash', 'generationHash', UInt64.fromNumericString('0'), 1, 'signature', account.publicAccount, + NetworkType.MIJIN_TEST, 0, 0, UInt64.fromUint(1), UInt64.fromUint(0), UInt64.fromUint(0), 0, 'previousHash', + mockBlockHash, mockBlockHash, 'stateHash', undefined, + ); + } + + function mockMerklePath(): MerkleProofInfo { + return new MerkleProofInfo( + [ + new MerklePathItem(PositionEnum.Left, 'CDE45D740536E5361F392025A44B26546A138958E69CD6F18D22908F8F11ECF2'), + new MerklePathItem(PositionEnum.Right, '4EF55DAB8FEF9711B23DA71D2ACC58EFFF3969C3D572E06ACB898F99BED4827A'), + new MerklePathItem(PositionEnum.Left, '1BB95470065ED69D184948A0175EDC2EAB9E86A0CEB47B648A58A02A5445AF66'), + new MerklePathItem(PositionEnum.Right, 'D96B03809B8B198EFA5824191A979F7B85C0E9B7A6623DAFF38D4B2927EFDFB5'), + new MerklePathItem(PositionEnum.Right, '9981EBDBCA8E36BA4D4D4A450072026AC8C85BA6497666219E0E049BE3362E51'), + ], + ); + } +});