From 57b9a5c2e3019e69a74355fb2af012ae3e5f92dd Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 31 Jul 2019 19:33:40 +0100 Subject: [PATCH 01/12] Renamed RestrictionType to AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 8 ++--- e2e/infrastructure/TransactionHttp.spec.ts | 14 ++++----- src/core/utils/DtoMapping.ts | 14 ++++----- src/model/account/AccountRestriction.ts | 4 +-- ...ctionType.ts => AccountRestrictionType.ts} | 2 +- src/model/model.ts | 2 +- ...dressRestrictionModificationTransaction.ts | 6 ++-- ...osaicRestrictionModificationTransaction.ts | 6 ++-- ...ationRestrictionModificationTransaction.ts | 6 ++-- .../AccountRestrictionTransaction.ts | 14 ++++----- test/core/utils/TransactionMapping.spec.ts | 31 ++++++++++--------- .../SerializeTransactionToJSON.spec.ts | 14 ++++----- test/model/account/AccountRestriction.spec.ts | 4 +-- .../model/account/AccountRestrictions.spec.ts | 4 +-- .../account/AccountRestrictionsInfo.spec.ts | 4 +-- .../AccountRestrictionTransaction.spec.ts | 22 ++++++------- 16 files changed, 78 insertions(+), 77 deletions(-) rename src/model/account/{RestrictionType.ts => AccountRestrictionType.ts} (96%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 89c0ba90ff..8f2d30b0b9 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 { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {PublicAccount} from '../../src/model/account/PublicAccount'; +import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasActionType } from '../../src/model/namespace/AliasActionType'; @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2f60993e0c..f7dba66f53 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'; @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -479,7 +479,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -516,7 +516,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 9a0e2b77d1..2babb31068 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,16 @@ 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.AllowAddress: + case AccountRestrictionType.BlockAddress: 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.AllowTransaction: + case AccountRestrictionType.BlockTransaction: 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/RestrictionType.ts b/src/model/account/AccountRestrictionType.ts similarity index 96% rename from src/model/account/RestrictionType.ts rename to src/model/account/AccountRestrictionType.ts index aa7d236ed0..93b503b5af 100644 --- a/src/model/account/RestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -23,7 +23,7 @@ * 0x80 + type The restriction is interpreted as a blocking operation. */ -export enum RestrictionType { +export enum AccountRestrictionType { AllowAddress = 0x01, AllowMosaic = 0x02, AllowTransaction = 0x04, diff --git a/src/model/model.ts b/src/model/model.ts index 62bb27f331..4224630cc8 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..2bb4aceaf4 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,12 @@ 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.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -64,12 +64,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 +92,12 @@ 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.AllowTransaction, AccountRestrictionType.BlockTransaction].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 98fb4f5c86..c30b9e5474 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 { AliasActionType } from '../../../src/model/namespace/AliasActionType'; 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.AllowAddress, [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.AllowAddress); 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,15 +125,16 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); - const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + const transaction = TransactionMapping + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -665,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -674,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.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -686,7 +687,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -695,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); }); @@ -707,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -716,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.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 5a13ee0d28..933663285b 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.AllowAddress, [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.AllowAddress); 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.AllowTransaction, [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.AllowTransaction); 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..d41a0e73a6 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.AllowAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 1ad76d7daa..8b30a7451b 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.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 01ac4771f9..981817bcea 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.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..8f83e951f3 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.AllowAddress, [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.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -182,7 +182,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -199,7 +199,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -224,7 +224,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 194a59a9a792d16c63ac69a037772f174c34c25d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Aug 2019 10:15:35 +0100 Subject: [PATCH 02/12] Refactored AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- e2e/infrastructure/TransactionHttp.spec.ts | 8 +- src/core/utils/DtoMapping.ts | 12 ++- src/model/account/AccountRestrictionType.ts | 89 ++++++++++++++++--- .../AccountRestrictionTransaction.ts | 12 ++- test/core/utils/TransactionMapping.spec.ts | 16 ++-- .../SerializeTransactionToJSON.spec.ts | 8 +- test/model/account/AccountRestriction.spec.ts | 2 +- .../model/account/AccountRestrictions.spec.ts | 2 +- .../account/AccountRestrictionsInfo.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +-- 11 files changed, 120 insertions(+), 47 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 8f2d30b0b9..0f884a6e77 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index f7dba66f53..1a34d057e5 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 2babb31068..7670b1815e 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -34,16 +34,20 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case AccountRestrictionType.AllowAddress: - case AccountRestrictionType.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 AccountRestrictionType.AllowMosaic: case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case AccountRestrictionType.AllowTransaction: - case AccountRestrictionType.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/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index 93b503b5af..757c1fde75 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -1,7 +1,7 @@ /* * Copyright 2019 NEM * - * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 * @@ -16,19 +16,82 @@ /** * 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. + * 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. */ -export enum AccountRestrictionType { - AllowAddress = 0x01, - AllowMosaic = 0x02, - AllowTransaction = 0x04, + // !!This enum will be deprecated once catbuffer code applied. +enum AccountRestrictionTypeEnum { + Address = 0x01, + Mosaic = 0x02, + TransactionType = 0x04, Sentinel = 0x05, - BlockAddress = (0x80 + 0x01), - BlockMosaic = (0x80 + 0x02), - BlockTransaction = (0x80 + 0x04), + 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/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 2bb4aceaf4..1ebbbf7849 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -41,7 +41,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.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( @@ -69,7 +72,7 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -97,7 +100,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.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 c30b9e5474..b1e9300864 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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'); }); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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(), - AccountRestrictionType.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(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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 933663285b..75f81eff2c 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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 d41a0e73a6..11defe8b1c 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -23,7 +23,7 @@ describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 8b30a7451b..0ed43b4f0b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: AccountRestrictionType.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 981817bcea..f4291f2468 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: AccountRestrictionType.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 8f83e951f3..59ccd31d5d 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 89e445b095cb86aa327d963d75cb2c2b7bbff3ef Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 5 Aug 2019 14:41:38 +0100 Subject: [PATCH 03/12] Updated tests --- e2e/infrastructure/TransactionHttp.spec.ts | 161 ++++++++++++++++- .../AccountRestrictionTransaction.spec.ts | 162 +++++++++++++++--- 2 files changed, 299 insertions(+), 24 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 1a34d057e5..2e14e46eb1 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -387,7 +387,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing 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.BlockOutgoingAddress, + [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 - Outgoing 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.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); @@ -425,7 +501,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -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); @@ -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); @@ -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/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 59ccd31d5d..eeb10081ff 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -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( @@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => { address, ); - expect(() => { - AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.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', () => { @@ -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(), - AccountRestrictionType.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', () => { @@ -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'); + + }); }); From af4bd943171b42c635f2c2d0bad30ee53ebf972e Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 31 Jul 2019 19:33:40 +0100 Subject: [PATCH 04/12] Renamed RestrictionType to AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 6 ++-- e2e/infrastructure/TransactionHttp.spec.ts | 14 +++++----- src/core/utils/DtoMapping.ts | 14 +++++----- src/model/account/AccountRestriction.ts | 4 +-- ...ctionType.ts => AccountRestrictionType.ts} | 2 +- src/model/model.ts | 2 +- ...dressRestrictionModificationTransaction.ts | 6 ++-- ...osaicRestrictionModificationTransaction.ts | 6 ++-- ...ationRestrictionModificationTransaction.ts | 6 ++-- .../AccountRestrictionTransaction.ts | 14 +++++----- test/core/utils/TransactionMapping.spec.ts | 28 +++++++++---------- .../SerializeTransactionToJSON.spec.ts | 14 +++++----- test/model/account/AccountRestriction.spec.ts | 4 +-- .../model/account/AccountRestrictions.spec.ts | 4 +-- .../account/AccountRestrictionsInfo.spec.ts | 4 +-- .../AccountRestrictionTransaction.spec.ts | 22 +++++++-------- 16 files changed, 75 insertions(+), 75 deletions(-) rename src/model/account/{RestrictionType.ts => AccountRestrictionType.ts} (96%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index d4f5242763..4925e44552 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.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2ad8b0be8d..dc056d7c98 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'; @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -479,7 +479,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -516,7 +516,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 9a0e2b77d1..2babb31068 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,16 @@ 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.AllowAddress: + case AccountRestrictionType.BlockAddress: 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.AllowTransaction: + case AccountRestrictionType.BlockTransaction: 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/RestrictionType.ts b/src/model/account/AccountRestrictionType.ts similarity index 96% rename from src/model/account/RestrictionType.ts rename to src/model/account/AccountRestrictionType.ts index aa7d236ed0..93b503b5af 100644 --- a/src/model/account/RestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -23,7 +23,7 @@ * 0x80 + type The restriction is interpreted as a blocking operation. */ -export enum RestrictionType { +export enum AccountRestrictionType { AllowAddress = 0x01, AllowMosaic = 0x02, AllowTransaction = 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..2bb4aceaf4 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,12 @@ 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.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -64,12 +64,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 +92,12 @@ 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.AllowTransaction, AccountRestrictionType.BlockTransaction].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..11f1b23e3c 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.AllowAddress, [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.AllowAddress); 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.AllowTransaction, [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.AllowTransaction); 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.AllowAddress, [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.AllowAddress); 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.AllowTransaction, [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.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f3ce56962..2fe89a589a 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.AllowAddress, [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.AllowAddress); 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.AllowTransaction, [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.AllowTransaction); 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..d41a0e73a6 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.AllowAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 1ad76d7daa..8b30a7451b 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.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 01ac4771f9..981817bcea 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.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..8f83e951f3 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.AllowAddress, [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.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -182,7 +182,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -199,7 +199,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -224,7 +224,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From e339f331f4c9124ae00aac4def9c5ea916121eb1 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Aug 2019 10:15:35 +0100 Subject: [PATCH 05/12] Refactored AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- e2e/infrastructure/TransactionHttp.spec.ts | 8 +- src/core/utils/DtoMapping.ts | 12 ++- src/model/account/AccountRestrictionType.ts | 89 ++++++++++++++++--- .../AccountRestrictionTransaction.ts | 12 ++- test/core/utils/TransactionMapping.spec.ts | 16 ++-- .../SerializeTransactionToJSON.spec.ts | 8 +- test/model/account/AccountRestriction.spec.ts | 2 +- .../model/account/AccountRestrictions.spec.ts | 2 +- .../account/AccountRestrictionsInfo.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +-- 11 files changed, 120 insertions(+), 47 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 4925e44552..c190d8c0ae 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index dc056d7c98..60ec20592d 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 2babb31068..7670b1815e 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -34,16 +34,20 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case AccountRestrictionType.AllowAddress: - case AccountRestrictionType.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 AccountRestrictionType.AllowMosaic: case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case AccountRestrictionType.AllowTransaction: - case AccountRestrictionType.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/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index 93b503b5af..757c1fde75 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -1,7 +1,7 @@ /* * Copyright 2019 NEM * - * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 * @@ -16,19 +16,82 @@ /** * 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. + * 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. */ -export enum AccountRestrictionType { - AllowAddress = 0x01, - AllowMosaic = 0x02, - AllowTransaction = 0x04, + // !!This enum will be deprecated once catbuffer code applied. +enum AccountRestrictionTypeEnum { + Address = 0x01, + Mosaic = 0x02, + TransactionType = 0x04, Sentinel = 0x05, - BlockAddress = (0x80 + 0x01), - BlockMosaic = (0x80 + 0x02), - BlockTransaction = (0x80 + 0x04), + 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/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 2bb4aceaf4..1ebbbf7849 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -41,7 +41,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.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( @@ -69,7 +72,7 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -97,7 +100,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.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 11f1b23e3c..29d45b2c40 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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'); }); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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(), - AccountRestrictionType.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(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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 2fe89a589a..1559522ba3 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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 d41a0e73a6..11defe8b1c 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -23,7 +23,7 @@ describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 8b30a7451b..0ed43b4f0b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: AccountRestrictionType.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 981817bcea..f4291f2468 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: AccountRestrictionType.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 8f83e951f3..59ccd31d5d 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 9db1e9064b6f0be6c0eacbe25ed990a41ae58790 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 5 Aug 2019 14:41:38 +0100 Subject: [PATCH 06/12] Updated tests --- e2e/infrastructure/TransactionHttp.spec.ts | 161 ++++++++++++++++- .../AccountRestrictionTransaction.spec.ts | 162 +++++++++++++++--- 2 files changed, 299 insertions(+), 24 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 60ec20592d..5e22d114e3 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -387,7 +387,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing 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.BlockOutgoingAddress, + [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 - Outgoing 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.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); @@ -425,7 +501,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -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); @@ -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); @@ -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/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 59ccd31d5d..eeb10081ff 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -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( @@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => { address, ); - expect(() => { - AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.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', () => { @@ -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(), - AccountRestrictionType.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', () => { @@ -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'); + + }); }); From eee44efc0f248f91288689ad335f5acbd2914167 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 31 Jul 2019 19:33:40 +0100 Subject: [PATCH 07/12] Renamed RestrictionType to AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 5 ++-- e2e/infrastructure/TransactionHttp.spec.ts | 14 +++++----- src/core/utils/DtoMapping.ts | 14 +++++----- src/model/account/AccountRestriction.ts | 4 +-- ...ctionType.ts => AccountRestrictionType.ts} | 2 +- src/model/model.ts | 2 +- ...dressRestrictionModificationTransaction.ts | 6 ++--- ...osaicRestrictionModificationTransaction.ts | 6 ++--- ...ationRestrictionModificationTransaction.ts | 6 ++--- .../AccountRestrictionTransaction.ts | 14 +++++----- test/core/utils/TransactionMapping.spec.ts | 26 +++++++++---------- .../SerializeTransactionToJSON.spec.ts | 14 +++++----- test/model/account/AccountRestriction.spec.ts | 4 +-- .../model/account/AccountRestrictions.spec.ts | 4 +-- .../account/AccountRestrictionsInfo.spec.ts | 4 +-- .../AccountRestrictionTransaction.spec.ts | 22 ++++++++-------- 16 files changed, 74 insertions(+), 73 deletions(-) rename src/model/account/{RestrictionType.ts => AccountRestrictionType.ts} (96%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index d4f5242763..a3f96ca7e1 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -19,6 +19,7 @@ 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'; @@ -200,7 +201,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +427,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2ad8b0be8d..dc056d7c98 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'; @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -479,7 +479,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -516,7 +516,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 9a0e2b77d1..2babb31068 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,16 @@ 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.AllowAddress: + case AccountRestrictionType.BlockAddress: 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.AllowTransaction: + case AccountRestrictionType.BlockTransaction: 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/RestrictionType.ts b/src/model/account/AccountRestrictionType.ts similarity index 96% rename from src/model/account/RestrictionType.ts rename to src/model/account/AccountRestrictionType.ts index aa7d236ed0..93b503b5af 100644 --- a/src/model/account/RestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -23,7 +23,7 @@ * 0x80 + type The restriction is interpreted as a blocking operation. */ -export enum RestrictionType { +export enum AccountRestrictionType { AllowAddress = 0x01, AllowMosaic = 0x02, AllowTransaction = 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..2bb4aceaf4 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,12 @@ 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.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -64,12 +64,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 +92,12 @@ 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.AllowTransaction, AccountRestrictionType.BlockTransaction].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..3e45e2f359 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.AllowAddress, [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.AllowAddress); 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.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -666,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [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.AllowAddress); 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.AllowTransaction, [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.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f3ce56962..2fe89a589a 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.AllowAddress, [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.AllowAddress); 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.AllowTransaction, [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.AllowTransaction); 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..d41a0e73a6 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.AllowAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 1ad76d7daa..8b30a7451b 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.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 01ac4771f9..981817bcea 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.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..8f83e951f3 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.AllowAddress, [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.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -182,7 +182,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -199,7 +199,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -224,7 +224,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 51f43f54ca73574a97dba63bb49d51bf41250d1c Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Aug 2019 10:15:35 +0100 Subject: [PATCH 08/12] Refactored AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- e2e/infrastructure/TransactionHttp.spec.ts | 8 +- src/core/utils/DtoMapping.ts | 12 ++- src/model/account/AccountRestrictionType.ts | 89 ++++++++++++++++--- .../AccountRestrictionTransaction.ts | 12 ++- test/core/utils/TransactionMapping.spec.ts | 16 ++-- .../SerializeTransactionToJSON.spec.ts | 8 +- test/model/account/AccountRestriction.spec.ts | 2 +- .../model/account/AccountRestrictions.spec.ts | 2 +- .../account/AccountRestrictionsInfo.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +-- 11 files changed, 120 insertions(+), 47 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index a3f96ca7e1..ba12110edf 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -201,7 +201,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -427,7 +427,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index dc056d7c98..60ec20592d 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 2babb31068..7670b1815e 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -34,16 +34,20 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case AccountRestrictionType.AllowAddress: - case AccountRestrictionType.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 AccountRestrictionType.AllowMosaic: case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case AccountRestrictionType.AllowTransaction: - case AccountRestrictionType.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/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index 93b503b5af..757c1fde75 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -1,7 +1,7 @@ /* * Copyright 2019 NEM * - * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 * @@ -16,19 +16,82 @@ /** * 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. + * 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. */ -export enum AccountRestrictionType { - AllowAddress = 0x01, - AllowMosaic = 0x02, - AllowTransaction = 0x04, + // !!This enum will be deprecated once catbuffer code applied. +enum AccountRestrictionTypeEnum { + Address = 0x01, + Mosaic = 0x02, + TransactionType = 0x04, Sentinel = 0x05, - BlockAddress = (0x80 + 0x01), - BlockMosaic = (0x80 + 0x02), - BlockTransaction = (0x80 + 0x04), + 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/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 2bb4aceaf4..1ebbbf7849 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -41,7 +41,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.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( @@ -69,7 +72,7 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -97,7 +100,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.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 3e45e2f359..29d45b2c40 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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'); }); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(), - AccountRestrictionType.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(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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 2fe89a589a..1559522ba3 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.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(AccountRestrictionType.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 d41a0e73a6..11defe8b1c 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -23,7 +23,7 @@ describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 8b30a7451b..0ed43b4f0b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: AccountRestrictionType.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 981817bcea..f4291f2468 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: AccountRestrictionType.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 8f83e951f3..59ccd31d5d 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 77218582881675cd3ae3e0b3be8e79e42e9a1969 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 5 Aug 2019 14:41:38 +0100 Subject: [PATCH 09/12] Updated tests --- e2e/infrastructure/TransactionHttp.spec.ts | 161 ++++++++++++++++- .../AccountRestrictionTransaction.spec.ts | 162 +++++++++++++++--- 2 files changed, 299 insertions(+), 24 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 60ec20592d..5e22d114e3 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -387,7 +387,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing 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.BlockOutgoingAddress, + [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 - Outgoing 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.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); @@ -425,7 +501,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -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); @@ -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); @@ -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/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 59ccd31d5d..eeb10081ff 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -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( @@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => { address, ); - expect(() => { - AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.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', () => { @@ -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(), - AccountRestrictionType.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', () => { @@ -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'); + + }); }); From 2583f86e16b14f15060d2538f1bdd25684491cfe Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 31 Jul 2019 19:33:40 +0100 Subject: [PATCH 10/12] Renamed RestrictionType to AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 5 +- src/model/account/AccountRestrictionType.ts | 97 --------------------- 2 files changed, 4 insertions(+), 98 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index ba12110edf..c8c2f0b13a 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -23,7 +23,6 @@ import { AccountRestrictionType } from '../../src/model/account/AccountRestricti 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'; @@ -427,7 +426,11 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), +<<<<<<< HEAD AccountRestrictionType.BlockIncomingAddress, +======= + AccountRestrictionType.BlockAddress, +>>>>>>> Renamed RestrictionType to AccountRestrictionType [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/model/account/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index 757c1fde75..e69de29bb2 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -1,97 +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 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, -} From c62ab70abda9ddec48f0c0f16e7da6555c5234d7 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Aug 2019 10:15:35 +0100 Subject: [PATCH 11/12] Refactored AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 4 + src/model/account/AccountRestrictionType.ts | 97 +++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index c8c2f0b13a..4d14a03a82 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -426,11 +426,15 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), +<<<<<<< HEAD <<<<<<< HEAD AccountRestrictionType.BlockIncomingAddress, ======= AccountRestrictionType.BlockAddress, >>>>>>> Renamed RestrictionType to AccountRestrictionType +======= + AccountRestrictionType.BlockIncomingAddress, +>>>>>>> Refactored AccountRestrictionType [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/model/account/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index e69de29bb2..757c1fde75 100644 --- a/src/model/account/AccountRestrictionType.ts +++ 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, +} From ed196f2820a412304606ff090860df931a940c9d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 20:13:14 +0100 Subject: [PATCH 12/12] Fixed merge issues --- e2e/infrastructure/AccountHttp.spec.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 4d14a03a82..c190d8c0ae 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -426,15 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), -<<<<<<< HEAD -<<<<<<< HEAD AccountRestrictionType.BlockIncomingAddress, -======= - AccountRestrictionType.BlockAddress, ->>>>>>> Renamed RestrictionType to AccountRestrictionType -======= - AccountRestrictionType.BlockIncomingAddress, ->>>>>>> Refactored AccountRestrictionType [addressPropertyFilter], NetworkType.MIJIN_TEST, );