diff --git a/catapult-sdk/src/model/ModelSchemaBuilder.js b/catapult-sdk/src/model/ModelSchemaBuilder.js index a757078c2..7ee209848 100644 --- a/catapult-sdk/src/model/ModelSchemaBuilder.js +++ b/catapult-sdk/src/model/ModelSchemaBuilder.js @@ -43,8 +43,8 @@ class ModelSchemaBuilder { // region block blockHeader: { size: ModelType.int, - version: ModelType.int, - network: ModelType.int, + version: ModelType.uint8, + network: ModelType.uint8, type: ModelType.int, height: ModelType.uint64, timestamp: ModelType.uint64, @@ -57,7 +57,7 @@ class ModelSchemaBuilder { receiptsHash: ModelType.binary, stateHash: ModelType.binary, beneficiaryAddress: ModelType.binary, - feeMultiplier: ModelType.int + feeMultiplier: ModelType.uint32 }, blockHeaderMetadata: { hash: ModelType.binary, @@ -84,20 +84,20 @@ class ModelSchemaBuilder { finalizedBlock: { height: ModelType.uint64, hash: ModelType.binary, - finalizationEpoch: ModelType.uint, - finalizationPoint: ModelType.uint + finalizationEpoch: ModelType.uint32, + finalizationPoint: ModelType.uint32 }, finalizationProof: { - version: ModelType.uint, - finalizationEpoch: ModelType.uint, - finalizationPoint: ModelType.uint, + version: ModelType.uint32, + finalizationEpoch: ModelType.uint32, + finalizationPoint: ModelType.uint32, height: ModelType.uint64, hash: ModelType.binary, messageGroups: { type: ModelType.array, schemaName: 'messageGroup' } }, messageGroup: { - stage: ModelType.uint, + stage: ModelType.uint32, height: ModelType.uint64, hashes: { type: ModelType.array, schemaName: ModelType.binary }, signatures: { type: ModelType.array, schemaName: 'bmTreeSignature' } @@ -118,8 +118,8 @@ class ModelSchemaBuilder { transaction: { size: ModelType.int, - version: ModelType.int, - network: ModelType.int, + version: ModelType.uint8, + network: ModelType.uint8, type: ModelType.int, deadline: ModelType.uint64, maxFee: ModelType.uint64 @@ -167,7 +167,7 @@ class ModelSchemaBuilder { addressHeight: ModelType.uint64, publicKey: ModelType.binary, publicKeyHeight: ModelType.uint64, - accountType: ModelType.int, + accountType: ModelType.uint8, supplementalPublicKeys: { type: ModelType.object, schemaName: 'supplementalPublicKey' }, importance: ModelType.uint64, importanceHeight: ModelType.uint64, @@ -183,7 +183,7 @@ class ModelSchemaBuilder { activityBucket: { startHeight: ModelType.uint64, totalFeesPaid: ModelType.uint64, - beneficiaryCount: ModelType.int, + beneficiaryCount: ModelType.uint32, rawScore: ModelType.uint64 }, mosaic: { @@ -198,8 +198,8 @@ class ModelSchemaBuilder { }, votingPublicKey: { publicKey: ModelType.binary, - startEpoch: ModelType.uint, - endEpoch: ModelType.uint + startEpoch: ModelType.uint32, + endEpoch: ModelType.uint32 }, // endregion @@ -220,7 +220,7 @@ class ModelSchemaBuilder { db: ModelType.string }, nodeInfo: { - version: ModelType.int, + version: ModelType.uint8, roles: ModelType.int, port: ModelType.int, networkIdentifier: ModelType.int, diff --git a/catapult-sdk/src/model/ModelType.js b/catapult-sdk/src/model/ModelType.js index 72d995363..9aada1d80 100644 --- a/catapult-sdk/src/model/ModelType.js +++ b/catapult-sdk/src/model/ModelType.js @@ -39,23 +39,26 @@ const ModelType = { /** Schema property type indicating a string value. */ string: SchemaType.max + 4, - /** Schema property type indicating an uint value. */ - uint: SchemaType.max + 5, + /** Schema property type indicating an uint byte value. */ + uint8: SchemaType.max + 5, /** Schema property type indicating an uint16 value. */ uint16: SchemaType.max + 6, + /** Schema property type indicating an uint32 value. */ + uint32: SchemaType.max + 7, + /** Schema property type indicating a uint64 value as string. */ - uint64: SchemaType.max + 7, + uint64: SchemaType.max + 8, /** Schema property type indicating a uint64 identifier as hexadecimal. */ - uint64HexIdentifier: SchemaType.max + 8, + uint64HexIdentifier: SchemaType.max + 9, /** Schema property type indicating an int value. */ - int: SchemaType.max + 9, + int: SchemaType.max + 10, /** Schema property type indicating a boolean value. */ - boolean: SchemaType.max + 10 + boolean: SchemaType.max + 11 }; Object.assign(ModelType, SchemaType); diff --git a/catapult-sdk/src/plugins/accountLink.js b/catapult-sdk/src/plugins/accountLink.js index e2abb7a5a..ac630b964 100644 --- a/catapult-sdk/src/plugins/accountLink.js +++ b/catapult-sdk/src/plugins/accountLink.js @@ -33,24 +33,24 @@ const accountLinkPlugin = { registerSchema: builder => { builder.addTransactionSupport(EntityType.accountLink, { linkedPublicKey: ModelType.binary, - linkAction: ModelType.int + linkAction: ModelType.uint8 }); builder.addTransactionSupport(EntityType.nodeKeyLink, { linkedPublicKey: ModelType.binary, - linkAction: ModelType.int + linkAction: ModelType.uint8 }); builder.addTransactionSupport(EntityType.votingKeyLink, { linkedPublicKey: ModelType.binary, - startEpoch: ModelType.uint, - endEpoch: ModelType.uint, - linkAction: ModelType.int + startEpoch: ModelType.uint32, + endEpoch: ModelType.uint32, + linkAction: ModelType.uint8 }); builder.addTransactionSupport(EntityType.vrfKeyLink, { linkedPublicKey: ModelType.binary, - linkAction: ModelType.int + linkAction: ModelType.uint8 }); }, diff --git a/catapult-sdk/src/plugins/lockSecret.js b/catapult-sdk/src/plugins/lockSecret.js index 637fa41ba..c5b623f63 100644 --- a/catapult-sdk/src/plugins/lockSecret.js +++ b/catapult-sdk/src/plugins/lockSecret.js @@ -40,8 +40,8 @@ const lockSecretPlugin = { mosaicId: ModelType.uint64HexIdentifier, amount: ModelType.uint64, endHeight: ModelType.uint64, - status: ModelType.int, - hashAlgorithm: ModelType.int, + status: ModelType.uint8, + hashAlgorithm: ModelType.uint8, secret: ModelType.binary, recipientAddress: ModelType.binary, compositeHash: ModelType.binary @@ -53,13 +53,13 @@ const lockSecretPlugin = { mosaicId: ModelType.uint64HexIdentifier, amount: ModelType.uint64, duration: ModelType.uint64, - hashAlgorithm: ModelType.int + hashAlgorithm: ModelType.uint8 }); builder.addTransactionSupport(EntityType.secretProof, { secret: ModelType.binary, recipientAddress: ModelType.binary, proof: ModelType.binary, - hashAlgorithm: ModelType.int + hashAlgorithm: ModelType.uint8 }); }, diff --git a/catapult-sdk/src/plugins/metadata.js b/catapult-sdk/src/plugins/metadata.js index 53209dbf2..31ab9aa17 100644 --- a/catapult-sdk/src/plugins/metadata.js +++ b/catapult-sdk/src/plugins/metadata.js @@ -36,7 +36,7 @@ const metadataPlugin = { targetAddress: ModelType.binary, scopedMetadataKey: ModelType.uint64HexIdentifier, valueSizeDelta: ModelType.int, - valueSize: ModelType.int, + valueSize: ModelType.uint16, value: ModelType.binary }); @@ -45,7 +45,7 @@ const metadataPlugin = { scopedMetadataKey: ModelType.uint64HexIdentifier, targetMosaicId: ModelType.uint64HexIdentifier, valueSizeDelta: ModelType.int, - valueSize: ModelType.int, + valueSize: ModelType.uint16, value: ModelType.binary }); @@ -54,7 +54,7 @@ const metadataPlugin = { scopedMetadataKey: ModelType.uint64HexIdentifier, targetNamespaceId: ModelType.uint64HexIdentifier, valueSizeDelta: ModelType.int, - valueSize: ModelType.int, + valueSize: ModelType.uint16, value: ModelType.binary }); @@ -70,7 +70,7 @@ const metadataPlugin = { scopedMetadataKey: ModelType.uint64HexIdentifier, targetId: ModelType.uint64HexIdentifier, metadataType: ModelType.int, - valueSize: ModelType.int, + valueSize: ModelType.uint16, value: ModelType.binary }); }, diff --git a/catapult-sdk/src/plugins/mosaic.js b/catapult-sdk/src/plugins/mosaic.js index a38e04473..660542c8a 100644 --- a/catapult-sdk/src/plugins/mosaic.js +++ b/catapult-sdk/src/plugins/mosaic.js @@ -31,15 +31,15 @@ const mosaicPlugin = { builder.addTransactionSupport(EntityType.mosaicDefinition, { id: ModelType.uint64HexIdentifier, duration: ModelType.uint64, - nonce: ModelType.int, - flags: ModelType.int, - divisibility: ModelType.int + nonce: ModelType.uint32, + flags: ModelType.uint8, + divisibility: ModelType.uint8 }); builder.addTransactionSupport(EntityType.mosaicSupplyChange, { mosaicId: ModelType.uint64HexIdentifier, delta: ModelType.uint64, - action: ModelType.int + action: ModelType.uint8 }); builder.addSchema('mosaicDescriptor', { @@ -53,8 +53,8 @@ const mosaicPlugin = { startHeight: ModelType.uint64, ownerAddress: ModelType.binary, revision: ModelType.int, - flags: ModelType.int, - divisibility: ModelType.int, + flags: ModelType.uint8, + divisibility: ModelType.uint8, duration: ModelType.uint64 }); }, diff --git a/catapult-sdk/src/plugins/namespace.js b/catapult-sdk/src/plugins/namespace.js index 5766ae53b..872c893c8 100644 --- a/catapult-sdk/src/plugins/namespace.js +++ b/catapult-sdk/src/plugins/namespace.js @@ -47,18 +47,18 @@ const namespacePlugin = { builder.addTransactionSupport(EntityType.aliasAddress, { namespaceId: ModelType.uint64HexIdentifier, address: ModelType.binary, - aliasAction: ModelType.int + aliasAction: ModelType.uint8 }); builder.addTransactionSupport(EntityType.aliasMosaic, { namespaceId: ModelType.uint64HexIdentifier, mosaicId: ModelType.uint64HexIdentifier, - aliasAction: ModelType.int + aliasAction: ModelType.uint8 }); builder.addTransactionSupport(EntityType.registerNamespace, { id: ModelType.uint64HexIdentifier, - registrationType: ModelType.int, + registrationType: ModelType.uint8, parentId: ModelType.uint64HexIdentifier, duration: ModelType.uint64, name: ModelType.string @@ -80,8 +80,8 @@ const namespacePlugin = { }); builder.addSchema('namespaceDescriptor.namespace', { - registrationType: ModelType.int, - depth: ModelType.int, + registrationType: ModelType.uint8, + depth: ModelType.uint8, level0: ModelType.uint64HexIdentifier, level1: ModelType.uint64HexIdentifier, level2: ModelType.uint64HexIdentifier, @@ -96,17 +96,17 @@ const namespacePlugin = { }); builder.addSchema('namespaceDescriptor.alias.mosaic', { - type: ModelType.int, + type: ModelType.uint8, mosaicId: ModelType.uint64HexIdentifier }); builder.addSchema('namespaceDescriptor.alias.address', { - type: ModelType.int, + type: ModelType.uint8, address: ModelType.binary }); builder.addSchema('namespaceDescriptor.alias.empty', { - type: ModelType.int + type: ModelType.uint8 }); builder.addSchema('namespaceNameTuple', { diff --git a/catapult-sdk/src/plugins/restrictions.js b/catapult-sdk/src/plugins/restrictions.js index a2b2d2249..2d2a3948c 100644 --- a/catapult-sdk/src/plugins/restrictions.js +++ b/catapult-sdk/src/plugins/restrictions.js @@ -107,14 +107,14 @@ const restrictionsPlugin = { accountRestrictionTypeDescriptors.forEach(restrictionTypeDescriptor => { // transaction schemas builder.addTransactionSupport(restrictionTypeDescriptor.entityType, { - restrictionFlags: ModelType.int, + restrictionFlags: ModelType.uint16, restrictionAdditions: { type: ModelType.array, schemaName: restrictionTypeDescriptor.valueType }, restrictionDeletions: { type: ModelType.array, schemaName: restrictionTypeDescriptor.valueType } }); // aggregated account restriction subschemas builder.addSchema(`accountRestriction.${restrictionTypeDescriptor.schemaPrefix}AccountRestriction`, { - restrictionFlags: ModelType.int, + restrictionFlags: ModelType.uint16, values: { type: ModelType.array, schemaName: restrictionTypeDescriptor.valueType } }); }); @@ -158,8 +158,8 @@ const restrictionsPlugin = { restrictionKey: ModelType.uint64HexIdentifier, previousRestrictionValue: ModelType.uint64, newRestrictionValue: ModelType.uint64, - previousRestrictionType: ModelType.int, - newRestrictionType: ModelType.int + previousRestrictionType: ModelType.uint8, + newRestrictionType: ModelType.uint8 }); // mosaic restriction schemas @@ -169,7 +169,7 @@ const restrictionsPlugin = { }); builder.addSchema('mosaicRestrictions.entry', { compositeHash: ModelType.binary, - entryType: ModelType.uint, + entryType: ModelType.uint32, mosaicId: ModelType.uint64HexIdentifier, targetAddress: ModelType.binary, restrictions: { type: ModelType.array, schemaName: 'mosaicRestrictions.entry.restrictions' } @@ -182,7 +182,7 @@ const restrictionsPlugin = { builder.addSchema('mosaicRestrictions.entry.restrictions.restriction', { referenceMosaicId: ModelType.uint64HexIdentifier, restrictionValue: ModelType.uint64, - restrictionType: ModelType.int + restrictionType: ModelType.uint8 }); }, diff --git a/catapult-sdk/test/model/ModelFormatterBuilder_spec.js b/catapult-sdk/test/model/ModelFormatterBuilder_spec.js index eac1121a8..72e868149 100644 --- a/catapult-sdk/test/model/ModelFormatterBuilder_spec.js +++ b/catapult-sdk/test/model/ModelFormatterBuilder_spec.js @@ -27,7 +27,9 @@ const modelSchema = new ModelSchemaBuilder().build(); const formattingRules = { [ModelType.none]: () => 'none', [ModelType.binary]: () => 'binary', - [ModelType.uint]: () => 'uint', + [ModelType.uint8]: () => 'uint8', + [ModelType.uint16]: () => 'uint16', + [ModelType.uint32]: () => 'uint32', [ModelType.uint64]: () => 'uint64', [ModelType.uint64HexIdentifier]: () => 'uint64HexIdentifier', [ModelType.objectId]: () => 'objectId', @@ -97,8 +99,8 @@ describe('model formatter builder', () => { transaction: { signature: 'binary', signerPublicKey: 'binary', - version: 'int', - network: 'int', + version: 'uint8', + network: 'uint8', type: 'int', maxFee: 'uint64', @@ -157,8 +159,8 @@ describe('model formatter builder', () => { block: { signature: 'binary', signerPublicKey: 'binary', - version: 'int', - network: 'int', + version: 'uint8', + network: 'uint8', type: 'int', height: 'uint64', @@ -203,7 +205,7 @@ describe('model formatter builder', () => { addressHeight: 'uint64', publicKey: 'binary', publicKeyHeight: 'uint64', - accountType: 'int', + accountType: 'uint8', importance: 'uint64', importanceHeight: 'uint64', mosaics: [ @@ -239,8 +241,8 @@ describe('model formatter builder', () => { latestFinalizedBlock: { height: 'uint64', hash: 'binary', - finalizationEpoch: 'uint', - finalizationPoint: 'uint' + finalizationEpoch: 'uint32', + finalizationPoint: 'uint32' } }); }); diff --git a/catapult-sdk/test/model/ModelSchemaBuilder_spec.js b/catapult-sdk/test/model/ModelSchemaBuilder_spec.js index 651f116f6..4d4ddf98d 100644 --- a/catapult-sdk/test/model/ModelSchemaBuilder_spec.js +++ b/catapult-sdk/test/model/ModelSchemaBuilder_spec.js @@ -349,24 +349,15 @@ describe('model schema builder', () => { // Assert: expect(matchingProperties).to.deep.equal([ 'blockHeader.size', - 'blockHeader.version', - 'blockHeader.network', 'blockHeader.type', - 'blockHeader.feeMultiplier', 'blockHeaderMetadata.totalTransactionsCount', 'blockHeaderMetadata.transactionsCount', 'blockHeaderMetadata.statementsCount', 'transaction.size', - 'transaction.version', - 'transaction.network', 'transaction.type', 'transactionMetadata.index', - 'account.accountType', - 'activityBucket.beneficiaryCount', - - 'nodeInfo.version', 'nodeInfo.roles', 'nodeInfo.port', 'nodeInfo.networkIdentifier', @@ -377,18 +368,35 @@ describe('model schema builder', () => { ]); }); - it('exposes correct uint properties', () => { + it('exposes correct uint8 properties', () => { + // Act: + const matchingProperties = extractSchemaPropertiesWithType('uint8'); + + // Assert: + expect(matchingProperties).to.deep.equal([ + 'blockHeader.version', + 'blockHeader.network', + 'transaction.version', + 'transaction.network', + 'account.accountType', + 'nodeInfo.version' + ]); + }); + + it('exposes correct uint32 properties', () => { // Act: - const matchingProperties = extractSchemaPropertiesWithType('uint'); + const matchingProperties = extractSchemaPropertiesWithType('uint32'); // Assert: expect(matchingProperties).to.deep.equal([ + 'blockHeader.feeMultiplier', 'finalizedBlock.finalizationEpoch', 'finalizedBlock.finalizationPoint', 'finalizationProof.version', 'finalizationProof.finalizationEpoch', 'finalizationProof.finalizationPoint', 'messageGroup.stage', + 'activityBucket.beneficiaryCount', 'votingPublicKey.startEpoch', 'votingPublicKey.endEpoch' ]); diff --git a/catapult-sdk/test/model/ModelType_spec.js b/catapult-sdk/test/model/ModelType_spec.js index 002817caa..7a213b78b 100644 --- a/catapult-sdk/test/model/ModelType_spec.js +++ b/catapult-sdk/test/model/ModelType_spec.js @@ -33,13 +33,14 @@ describe('model type enumeration', () => { objectId: 5, statusCode: 6, string: 7, - uint: 8, + uint8: 8, uint16: 9, - uint64: 10, - uint64HexIdentifier: 11, - int: 12, - boolean: 13, - max: 13 + uint32: 10, + uint64: 11, + uint64HexIdentifier: 12, + int: 13, + boolean: 14, + max: 14 }); }); }); diff --git a/catapult-sdk/test/plugins/namespace_spec.js b/catapult-sdk/test/plugins/namespace_spec.js index 6e1974e01..c4f2188cf 100644 --- a/catapult-sdk/test/plugins/namespace_spec.js +++ b/catapult-sdk/test/plugins/namespace_spec.js @@ -137,6 +137,9 @@ describe('namespace plugin', () => { const formattingRules = { [ModelType.none]: () => 'none', [ModelType.binary]: () => 'binary', + [ModelType.uint8]: () => 'uint8', + [ModelType.uint16]: () => 'uint16', + [ModelType.uint32]: () => 'uint32', [ModelType.uint64]: () => 'uint64', [ModelType.uint64HexIdentifier]: () => 'uint64HexIdentifier', [ModelType.objectId]: () => 'objectId', @@ -189,7 +192,7 @@ describe('namespace plugin', () => { // Assert: expect(formattedAlias).to.contain.all.keys(['type', 'mosaicId']); expect(formattedAlias).deep.equal({ - type: 'int', + type: 'uint8', mosaicId: 'uint64HexIdentifier' }); }); @@ -207,7 +210,7 @@ describe('namespace plugin', () => { // Assert: expect(formattedAlias).to.contain.all.keys(['type', 'address']); expect(formattedAlias).deep.equal({ - type: 'int', + type: 'uint8', address: 'binary' }); }); @@ -224,7 +227,7 @@ describe('namespace plugin', () => { // Assert: expect(formattedAlias).to.contain.all.keys(['type']); expect(formattedAlias).deep.equal({ - type: 'int' + type: 'uint8' }); }); }); diff --git a/rest/src/db/dbFormattingRules.js b/rest/src/db/dbFormattingRules.js index ab107663b..ca527ca72 100644 --- a/rest/src/db/dbFormattingRules.js +++ b/rest/src/db/dbFormattingRules.js @@ -40,9 +40,10 @@ module.exports = { [ModelType.objectId]: value => (undefined === value ? '' : value.toHexString().toUpperCase()), [ModelType.statusCode]: value => status.toString(value >>> 0), [ModelType.string]: value => value.toString(), - [ModelType.uint]: value => convert.int32ToUint32(value), + [ModelType.uint8]: value => value, // `uint16` required solely because accountRestrictions->restrictionAdditions array has uint16 provided as binary [ModelType.uint16]: value => (value instanceof Binary ? Buffer.from(value.buffer).readInt16LE(0) : value), + [ModelType.uint32]: value => convert.int32ToUint32(value), [ModelType.uint64]: value => uint64.toString(longToUint64(value)), // `uint64HexIdentifier` requires branching accountRestrictions->restrictionAdditions provides uint64 as binary [ModelType.uint64HexIdentifier]: value => uint64.toHex(value instanceof Binary ? uint64.fromBytes(value.buffer) : longToUint64(value)), diff --git a/rest/src/server/messageFormattingRules.js b/rest/src/server/messageFormattingRules.js index 57874d397..287b522dd 100644 --- a/rest/src/server/messageFormattingRules.js +++ b/rest/src/server/messageFormattingRules.js @@ -28,8 +28,9 @@ module.exports = { [ModelType.binary]: value => convert.uint8ToHex(value), [ModelType.statusCode]: status.toString, [ModelType.string]: value => value.toString(), - [ModelType.uint]: value => value, + [ModelType.uint8]: value => value, [ModelType.uint16]: value => value, + [ModelType.uint32]: value => value, [ModelType.uint64]: value => uint64.toString(value), [ModelType.uint64HexIdentifier]: value => uint64.toHex(value), [ModelType.int]: value => value, diff --git a/rest/test/db/dbFormattingRules_spec.js b/rest/test/db/dbFormattingRules_spec.js index aebf22400..32b60c034 100644 --- a/rest/test/db/dbFormattingRules_spec.js +++ b/rest/test/db/dbFormattingRules_spec.js @@ -23,7 +23,7 @@ const { convertToLong } = require('../../src/db/dbUtils'); const test = require('../testUtils'); const catapult = require('catapult-sdk'); const { expect } = require('chai'); -const { Binary, Int32 } = require('mongodb'); +const { Binary } = require('mongodb'); const { ModelType } = catapult.model; @@ -94,20 +94,17 @@ describe('db formatting rules', () => { expect(result).to.equal('catapult'); }); - describe('can format uint type', () => { + describe('can format uint8 type', () => { const testCases = [ - { name: 'uint value 0 (min)', value: new Int32(0), formated: 0 }, - { name: 'uint8 value 255', value: new Int32(255), formated: 255 }, - { name: 'uint16 value 65535', value: new Int32(65535), formated: 65535 }, - { name: 'uint32 value 4294967295 (max)', value: new Int32(-1), formated: 4294967295 }, - { name: 'uint32 value 2147483647', value: new Int32(2147483647), formated: 2147483647 }, - { name: 'uint32 value 2147483648', value: new Int32(-2147483648), formated: 2147483648 } + { name: 'value 0', value: 0, formated: 0 }, + { name: 'value 128', value: 128, formated: 128 }, + { name: 'value 255 (max)', value: 255, formated: 255 } ]; testCases.forEach(testCase => { it(testCase.name, () => { // Arrange + Act: - const result = formattingRules[ModelType.uint](testCase.value); + const result = formattingRules[ModelType.uint8](testCase.value); // Assert: expect(result).to.equal(testCase.formated); @@ -115,71 +112,103 @@ describe('db formatting rules', () => { }); }); - it('can format uint16 type', () => { - // Act: - const result = formattingRules[ModelType.uint16](17434); + describe('can format uint16 type', () => { + const testCases = [ + { name: 'value 0', value: 0, formated: 0 }, + { name: 'value 17434', value: 17434, formated: 17434 }, + { name: 'value 32768', value: 32768, formated: 32768 }, + { name: 'value 65535 (max)', value: 65535, formated: 65535 } + ]; - // Assert: - expect(result).to.equal(17434); - }); + testCases.forEach(testCase => { + it(testCase.name, () => { + // Arrange + Act: + const result = formattingRules[ModelType.uint16](testCase.value); - it('can format uint16 type from Binary', () => { - // Arrange: - const buffer = Buffer.alloc(2, 0); - buffer.writeUInt16LE(17434); - const object = new Binary(buffer); + // Assert: + expect(result).to.equal(testCase.formated); + }); + }); - // Act: - const result = formattingRules[ModelType.uint16](object); + it('can format uint16 type from Binary', () => { + // Arrange: + const buffer = Buffer.alloc(2, 0); + buffer.writeUInt16LE(17434); + const object = new Binary(buffer); - // Assert: - expect(result).to.deep.equal(17434); + // Act: + const result = formattingRules[ModelType.uint16](object); + + // Assert: + expect(result).to.deep.equal(17434); + }); }); - it('can format uint64 type from Long', () => { - // Arrange: - const object = convertToLong([1, 2]); + describe('can format uint32 type', () => { + const testCases = [ + { name: 'value 0', value: 0, formated: 0 }, + { name: 'value 2147483647', value: 2147483647, formated: 2147483647 }, + { name: 'value -2147483648', value: -2147483648, formated: 2147483648 }, + { name: 'value 4294967295 (max)', value: -1, formated: 4294967295 } + ]; - // Act: - const result = formattingRules[ModelType.uint64](object); + testCases.forEach(testCase => { + it(testCase.name, () => { + // Arrange + Act: + const result = formattingRules[ModelType.uint32](testCase.value); - // Assert: - expect(result).to.equal('8589934593'); + // Assert: + expect(result).to.equal(testCase.formated); + }); + }); }); - it('can format uint64HexIdentifier type from Long', () => { - // Arrange: - const object = convertToLong([1, 2]); + describe('can format uint64 type', () => { + it('can format uint64 type from Long', () => { + // Arrange: + const object = convertToLong([1, 2]); - // Act: - const result = formattingRules[ModelType.uint64HexIdentifier](object); + // Act: + const result = formattingRules[ModelType.uint64](object); - // Assert: - expect(result).to.equal('0000000200000001'); - }); + // Assert: + expect(result).to.equal('8589934593'); + }); - it('can format uint64HexIdentifier type from Binary', () => { - // Arrange: - const buffer = Buffer.alloc(8, 0); - buffer.writeUInt32LE(0x00ABCDEF, 0); - buffer.writeUInt32LE(0x000FDFFF, 4); - const object = new Binary(buffer); + it('can format uint64HexIdentifier type from Long', () => { + // Arrange: + const object = convertToLong([1, 2]); - // Act: - const result = formattingRules[ModelType.uint64HexIdentifier](object); + // Act: + const result = formattingRules[ModelType.uint64HexIdentifier](object); - // Assert: - expect(result).to.equal('000FDFFF00ABCDEF'); + // Assert: + expect(result).to.equal('0000000200000001'); + }); + + it('can format uint64HexIdentifier type from Binary', () => { + // Arrange: + const buffer = Buffer.alloc(8, 0); + buffer.writeUInt32LE(0x00ABCDEF, 0); + buffer.writeUInt32LE(0x000FDFFF, 4); + const object = new Binary(buffer); + + // Act: + const result = formattingRules[ModelType.uint64HexIdentifier](object); + + // Assert: + expect(result).to.equal('000FDFFF00ABCDEF'); + }); }); describe('can format int type', () => { const testCases = [ - { name: 'int value 0', value: new Int32(0), formated: 0 }, - { name: 'int8 value 255', value: new Int32(255), formated: 255 }, - { name: 'int16 value 65535', value: new Int32(65535), formated: 65535 }, - { name: 'int32 value -1', value: new Int32(-1), formated: -1 }, - { name: 'int32 value -2147483648 (min)', value: new Int32(-2147483648), formated: -2147483648 }, - { name: 'int32 value 2147483647 (max)', value: new Int32(2147483647), formated: 2147483647 } + { name: 'value 0', value: 0, formated: 0 }, + { name: 'value 255', value: 255, formated: 255 }, + { name: 'value 65535', value: 65535, formated: 65535 }, + { name: 'value -1', value: -1, formated: -1 }, + { name: 'value -2147483648 (min)', value: -2147483648, formated: -2147483648 }, + { name: 'value 2147483647 (max)', value: 2147483647, formated: 2147483647 } ]; testCases.forEach(testCase => { diff --git a/rest/test/server/messageFormattingRules_spec.js b/rest/test/server/messageFormattingRules_spec.js index efd72f589..027aa2ed3 100644 --- a/rest/test/server/messageFormattingRules_spec.js +++ b/rest/test/server/messageFormattingRules_spec.js @@ -75,12 +75,12 @@ describe('message formatting rules', () => { expect(result).to.equal('catapult'); }); - it('can format uint type', () => { + it('can format uint8 type', () => { // Arrange: const object = 12345678; // Act: - const result = formattingRules[ModelType.uint](object); + const result = formattingRules[ModelType.uint8](object); // Assert: expect(result).to.deep.equal(12345678); @@ -97,6 +97,17 @@ describe('message formatting rules', () => { expect(result).to.deep.equal(56); }); + it('can format uint32 type', () => { + // Arrange: + const object = 12345678; + + // Act: + const result = formattingRules[ModelType.uint32](object); + + // Assert: + expect(result).to.deep.equal(12345678); + }); + it('can format uint64 type', () => { // Arrange: const object = [1, 2];