diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index d4f5242763..c190d8c0ae 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -19,10 +19,10 @@ import {assert, expect} from 'chai'; import {AccountHttp} from '../../src/infrastructure/AccountHttp'; import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure'; import { Account } from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import {Address} from '../../src/model/account/Address'; import {PublicAccount} from '../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2ad8b0be8d..5e22d114e3 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -25,8 +25,8 @@ import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; import {Listener} from '../../src/infrastructure/Listener'; import {TransactionHttp} from '../../src/infrastructure/TransactionHttp'; import {Account} from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import {MosaicId} from '../../src/model/mosaic/MosaicId'; @@ -387,7 +387,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockOutgoingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -425,7 +425,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -441,7 +441,83 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [addressModification.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('AccountRestrictionTransaction - Incoming Address', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + + it('standalone', (done) => { + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Add, + account3.address, + ); + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockIncomingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account, generationHash); + + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + expect(transaction.modifications, 'Modifications').not.to.be.undefined; + expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; + expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; + expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined; + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Incoming Address', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Remove, + account3.address, + ); + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -479,7 +555,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -516,7 +592,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -537,7 +613,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Operation', () => { + describe('AccountRestrictionTransaction - Incoming Operation', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -554,7 +630,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -575,7 +651,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Operation', () => { + describe('AccountRestrictionTransaction - Incoming Operation', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -591,7 +667,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -612,6 +688,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); + + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + + it('standalone', (done) => { + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + TransactionType.LINK_ACCOUNT, + ); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account3, generationHash); + + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + expect(transaction.modifications, 'Modifications').not.to.be.undefined; + expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; + expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; + expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined; + done(); + }); + listener.status(account3.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Remove, + TransactionType.LINK_ACCOUNT, + ); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [addressModification.toAggregate(account3.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account3, generationHash); + listener.confirmed(account3.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account3.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountLinkTransaction', () => { let listener: Listener; before (() => { diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 9a0e2b77d1..7670b1815e 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -17,8 +17,8 @@ import { AccountRestriction } from '../../model/account/AccountRestriction'; import { AccountRestrictions } from '../../model/account/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../model/account/AccountRestrictionsInfo'; +import { AccountRestrictionType } from '../../model/account/AccountRestrictionType'; import { Address } from '../../model/account/Address'; -import { RestrictionType } from '../../model/account/RestrictionType'; import { MosaicId } from '../../model/mosaic/MosaicId'; export class DtoMapping { @@ -34,16 +34,20 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case RestrictionType.AllowAddress: - case RestrictionType.BlockAddress: + case AccountRestrictionType.AllowIncomingAddress: + case AccountRestrictionType.BlockIncomingAddress: + case AccountRestrictionType.AllowOutgoingAddress: + case AccountRestrictionType.BlockOutgoingAddress: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => Address.createFromEncoded(value))); - case RestrictionType.AllowMosaic: - case RestrictionType.BlockMosaic: + case AccountRestrictionType.AllowMosaic: + case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case RestrictionType.AllowTransaction: - case RestrictionType.BlockTransaction: + case AccountRestrictionType.AllowIncomingTransactionType: + case AccountRestrictionType.AllowOutgoingTransactionType: + case AccountRestrictionType.BlockIncomingTransactionType: + case AccountRestrictionType.BlockOutgoingTransactionType: return new AccountRestriction(prop.restrictionType, prop.values); default: throw new Error(`Invalid restriction type: ${prop.restrictionType}`); diff --git a/src/model/account/AccountRestriction.ts b/src/model/account/AccountRestriction.ts index 7eb6928f11..47bf9a345c 100644 --- a/src/model/account/AccountRestriction.ts +++ b/src/model/account/AccountRestriction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RestrictionType } from './RestrictionType'; +import { AccountRestrictionType } from './AccountRestrictionType'; /** * Account restriction structure describes restriction information. */ @@ -29,7 +29,7 @@ export class AccountRestriction { /** * Account restriction type */ - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, /** * Restriction values. */ diff --git a/src/model/account/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts new file mode 100644 index 0000000000..757c1fde75 --- /dev/null +++ b/src/model/account/AccountRestrictionType.ts @@ -0,0 +1,97 @@ +/* + * 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. + */ + +/** + * Account restriction type + * 0x01 Account restriction type is an address. + * 0x02 Account restriction type is a mosaic id. + * 0x04 Account restriction type is a transaction type. + * 0x05 restriction type sentinel. + * 0x40 Account restriction is interpreted as outgoing restriction. + * 0x80 Account restriction is interpreted as blocking operation. + */ + + // !!This enum will be deprecated once catbuffer code applied. +enum AccountRestrictionTypeEnum { + Address = 0x01, + Mosaic = 0x02, + TransactionType = 0x04, + Sentinel = 0x05, + Outgoing = 0x40, + Block = 0x80, +} + +export enum AccountRestrictionType { + /** + * Allow only incoming transactions from a given address. + */ + AllowIncomingAddress = AccountRestrictionTypeEnum.Address, + + /** + * Allow only incoming transactions containing a a given mosaic identifier. + */ + AllowMosaic = AccountRestrictionTypeEnum.Mosaic, + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowIncomingTransactionType = AccountRestrictionTypeEnum.TransactionType, + + /** + * Allow only outgoing transactions to a given address. + */ + AllowOutgoingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Outgoing), + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Block incoming transactions from a given address. + */ + BlockIncomingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions containing a given mosaic identifier. + */ + BlockMosaic = (AccountRestrictionTypeEnum.Mosaic + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions with a given transaction type. + */ + BlockIncomingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block), + + /** + * Block outgoing transactions from a given address. + */ + BlockOutgoingAddress = (AccountRestrictionTypeEnum.Address + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + /** + * Block outgoing transactions with a given transaction type. + */ + BlockOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Account restriction sentinel. + */ + Sentinel = AccountRestrictionTypeEnum.Sentinel, +} diff --git a/src/model/account/RestrictionType.ts b/src/model/account/RestrictionType.ts deleted file mode 100644 index aa7d236ed0..0000000000 --- a/src/model/account/RestrictionType.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ - -/** - * Account restriction type - * 0x01 The restriction type is an address. - * 0x02 The restriction type is mosaic id. - * 0x03 The restriction type is a transaction type. - * 0x04 restriction type sentinel. - * 0x80 + type The restriction is interpreted as a blocking operation. - */ - -export enum RestrictionType { - AllowAddress = 0x01, - AllowMosaic = 0x02, - AllowTransaction = 0x04, - Sentinel = 0x05, - BlockAddress = (0x80 + 0x01), - BlockMosaic = (0x80 + 0x02), - BlockTransaction = (0x80 + 0x04), -} diff --git a/src/model/model.ts b/src/model/model.ts index ec948eca39..2c0c7a755b 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -28,7 +28,7 @@ export * from './account/AccountRestrictions'; export * from './account/AccountRestrictionsInfo'; export * from './account/AccountRestriction'; export * from './account/RestrictionModificationType'; -export * from './account/RestrictionType'; +export * from './account/AccountRestrictionType'; export * from './account/AccountNames'; // Blockchain diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts index 3a9d99f813..822bc9d284 100644 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio * @returns {AccountAddressRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts index 3a32656795..9de6449f61 100644 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction * @returns {AccountAddressRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts index 38160cc79d..45788393e3 100644 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountOperationRestrictionModificationTransaction extends Transact * @returns {AccountOperationRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountOperationRestrictionModificationTransaction extends Transact version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 7e0f26c313..1ebbbf7849 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RestrictionType } from '../account/RestrictionType'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountAddressRestrictionModificationTransaction } from './AccountAddressRestrictionModificationTransaction'; @@ -36,12 +36,15 @@ export class AccountRestrictionTransaction { */ public static createAddressRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![RestrictionType.AllowAddress, RestrictionType.BlockAddress].includes(restrictionType)) { + if (![AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -64,12 +67,12 @@ export class AccountRestrictionTransaction { */ public static createMosaicRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![RestrictionType.AllowMosaic, RestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -92,12 +95,15 @@ export class AccountRestrictionTransaction { */ public static createOperationRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![RestrictionType.AllowTransaction, RestrictionType.BlockTransaction].includes(restrictionType)) { + if (![AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountOperationRestrictionModificationTransaction.create( diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index b3653114f1..29d45b2c40 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -20,10 +20,10 @@ import { sha3_256 } from 'js-sha3'; import {Convert as convert} from '../../../src/core/format'; import { TransactionMapping } from '../../../src/core/utils/TransactionMapping'; import { Account } from '../../../src/model/account/Account'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import { Address } from '../../../src/model/account/Address'; import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; import { EncryptedMessage } from '../../../src/model/model'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; @@ -35,7 +35,7 @@ import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrency import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionModificationTransaction } from'../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; import { AccountMosaicRestrictionModificationTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -89,7 +89,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); }); @@ -102,7 +102,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -111,7 +111,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications[0].value[0]).to.be.equal(2262289484); expect(transaction.modifications[0].value[1]).to.be.equal(3405110546); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -134,7 +134,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -666,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -675,7 +675,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -687,7 +687,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -696,7 +696,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications.length).to.be.equal(1); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -717,7 +717,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f3ce56962..1559522ba3 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -18,10 +18,10 @@ import { expect } from 'chai'; import { sha3_256 } from 'js-sha3'; import {Convert as convert} from '../../src/core/format'; import { Account } from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -91,7 +91,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -103,7 +103,7 @@ describe('SerializeTransactionToJSON', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -111,7 +111,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -131,7 +131,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/account/AccountRestriction.spec.ts b/test/model/account/AccountRestriction.spec.ts index 5bc3e189b6..11defe8b1c 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -17,13 +17,13 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import { AccountRestriction } from '../../../src/model/account/AccountRestriction'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import { Address } from '../../../src/model/account/Address'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 1ad76d7daa..0ed43b4f0b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -17,7 +17,7 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import {Address} from '../../../src/model/account/Address'; -import { AccountRestrictions, RestrictionModificationType, RestrictionType, AccountRestriction } from '../../../src/model/model'; +import { AccountRestriction, AccountRestrictions, AccountRestrictionType, RestrictionModificationType } from '../../../src/model/model'; describe('AccountRestrictions', () => { @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 01ac4771f9..f4291f2468 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -18,9 +18,9 @@ import {deepEqual} from 'assert'; import { AccountRestriction } from '../../../src/model/account/AccountRestriction'; import { AccountRestrictions } from '../../../src/model/account/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../../src/model/account/AccountRestrictionsInfo'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import {Address} from '../../../src/model/account/Address'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; describe('AccountRestrictionsInfo', () => { @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..eeb10081ff 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -16,9 +16,9 @@ import {expect} from 'chai'; import {Account} from '../../../src/model/account/Account'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import {Address} from '../../../src/model/account/Address'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -90,7 +90,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -148,7 +148,7 @@ describe('AccountRestrictionTransaction', () => { expect(addressRestrictionTransaction.maxFee.lower).to.be.equal(1); }); - it('should create address restriction transaction', () => { + it('should create allow incmoing address restriction transaction', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress( @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => { address, ); - expect(() => { - AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - RestrictionType.Sentinel, - [addressRestrictionFilter], - NetworkType.MIJIN_TEST, - ); - }).to.throw(Error, 'Restriction type is not allowed.'); - + const invalidType = [AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowMosaic, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockIncomingTransactionType, + AccountRestrictionType.BlockMosaic, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + type, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); }); it('should create mosaic restriction transaction', () => { @@ -199,7 +208,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -213,7 +222,7 @@ describe('AccountRestrictionTransaction', () => { }); - it('should throw exception when create mosaic restriction transaction with wrong type', () => { + it('should throw exception when create account mosaic restriction transaction with wrong type', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( @@ -221,15 +230,26 @@ describe('AccountRestrictionTransaction', () => { mosaicId, ); - expect(() => { - AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( - Deadline.create(), - RestrictionType.Sentinel, - [mosaicRestrictionFilter], - NetworkType.MIJIN_TEST, - ); - }).to.throw(Error, 'Restriction type is not allowed.'); - + const invalidType = [AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockIncomingTransactionType, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.BlockIncomingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + Deadline.create(), + type, + [mosaicRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); }); it('should create operation restriction transaction', () => { @@ -241,7 +261,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -254,4 +274,106 @@ describe('AccountRestrictionTransaction', () => { )).to.be.equal('0401004E42'); }); + + it('should throw exception when create account operation restriction transaction with wrong type', () => { + + const operation = TransactionType.ADDRESS_ALIAS; + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + operation, + ); + + const invalidType = [AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowMosaic, + AccountRestrictionType.BlockMosaic, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + type, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); + }); + + it('should create outgoing address restriction transaction', () => { + + const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Add, + address, + ); + let addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.AllowOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + let signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('4101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + }); + + it('should create outgoing operation restriction transaction', () => { + + const operation = TransactionType.ADDRESS_ALIAS; + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + operation, + ); + let operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.AllowOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + let signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('4401004E42'); + + operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C401004E42'); + + }); });