Skip to content

Commit e6562d5

Browse files
authored
Removed metadata size validation (#527)
* Fixed #526 - Removed metadata size validation * Added unit tests for coverage * added unit tests * improved coverage
1 parent 87eebe1 commit e6562d5

File tree

8 files changed

+208
-51
lines changed

8 files changed

+208
-51
lines changed

src/model/transaction/AccountMetadataTransaction.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ export class AccountMetadataTransaction extends Transaction {
106106
signer?: PublicAccount,
107107
transactionInfo?: TransactionInfo) {
108108
super(TransactionType.ACCOUNT_METADATA, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
109-
if (value.length > 1024) {
110-
throw new Error('The maximum value size is 1024');
111-
}
112109
}
113110

114111
/**

src/model/transaction/MosaicMetadataTransaction.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ export class MosaicMetadataTransaction extends Transaction {
120120
signer?: PublicAccount,
121121
transactionInfo?: TransactionInfo) {
122122
super(TransactionType.MOSAIC_METADATA, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
123-
if (value.length > 1024) {
124-
throw new Error('The maximum value size is 1024');
125-
}
126123
}
127124

128125
/**

src/model/transaction/NamespaceMetadataTransaction.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ export class NamespaceMetadataTransaction extends Transaction {
116116
signer?: PublicAccount,
117117
transactionInfo?: TransactionInfo) {
118118
super(TransactionType.NAMESPACE_METADATA, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
119-
if (value.length > 1024) {
120-
throw new Error('The maximum value size is 1024');
121-
}
122119
}
123120

124121
/**

test/core/utils/TransactionMapping.spec.ts

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,76 @@ describe('TransactionMapping - createFromPayload', () => {
414414
NetworkType.MIJIN_TEST,
415415
);
416416

417+
const accountLinkTransaction = AccountLinkTransaction.create(
418+
Deadline.create(),
419+
account.publicKey,
420+
LinkAction.Link,
421+
NetworkType.MIJIN_TEST,
422+
);
423+
const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace(
424+
Deadline.create(),
425+
'root-test-namespace',
426+
UInt64.fromUint(1000),
427+
NetworkType.MIJIN_TEST,
428+
);
429+
const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create(
430+
Deadline.create(),
431+
new MosaicId(UInt64.fromUint(1).toDTO()),
432+
UInt64.fromUint(4444),
433+
UInt64.fromUint(0),
434+
MosaicRestrictionType.NONE,
435+
UInt64.fromUint(0),
436+
MosaicRestrictionType.GE,
437+
NetworkType.MIJIN_TEST,
438+
);
439+
const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create(
440+
Deadline.create(),
441+
new NamespaceId('test'),
442+
UInt64.fromUint(4444),
443+
account.address,
444+
UInt64.fromUint(0),
445+
NetworkType.MIJIN_TEST,
446+
UInt64.fromUint(0),
447+
);
448+
const accountMetadataTransaction = AccountMetadataTransaction.create(
449+
Deadline.create(),
450+
account.publicKey,
451+
UInt64.fromUint(1000),
452+
1,
453+
Convert.uint8ToUtf8(new Uint8Array(10)),
454+
NetworkType.MIJIN_TEST,
455+
);
456+
const mosaicMetadataTransaction = MosaicMetadataTransaction.create(
457+
Deadline.create(),
458+
account.publicKey,
459+
UInt64.fromUint(1000),
460+
new MosaicId([2262289484, 3405110546]),
461+
1,
462+
Convert.uint8ToUtf8(new Uint8Array(10)),
463+
NetworkType.MIJIN_TEST,
464+
);
465+
const namespaceMetadataTransaction = NamespaceMetadataTransaction.create(
466+
Deadline.create(),
467+
account.publicKey,
468+
UInt64.fromUint(1000),
469+
new NamespaceId([2262289484, 3405110546]),
470+
1,
471+
Convert.uint8ToUtf8(new Uint8Array(10)),
472+
NetworkType.MIJIN_TEST,
473+
);
474+
417475
const aggregateTransaction = AggregateTransaction.createComplete(
418476
Deadline.create(),
419-
[transferTransaction.toAggregate(account.publicAccount)],
477+
[
478+
transferTransaction.toAggregate(account.publicAccount),
479+
accountLinkTransaction.toAggregate(account.publicAccount),
480+
registerNamespaceTransaction.toAggregate(account.publicAccount),
481+
mosaicGlobalRestrictionTransaction.toAggregate(account.publicAccount),
482+
mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount),
483+
mosaicMetadataTransaction.toAggregate(account.publicAccount),
484+
namespaceMetadataTransaction.toAggregate(account.publicAccount),
485+
accountMetadataTransaction.toAggregate(account.publicAccount),
486+
],
420487
NetworkType.MIJIN_TEST,
421488
[]);
422489

@@ -426,6 +493,7 @@ describe('TransactionMapping - createFromPayload', () => {
426493

427494
expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE);
428495
expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER);
496+
expect(transaction.innerTransactions.length).to.be.equal(8);
429497
});
430498

431499
it('should create AggregatedTransaction - Bonded', () => {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2018 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {expect} from 'chai';
18+
import {MosaicId} from '../../../src/model/mosaic/MosaicId';
19+
import { MosaicNames } from '../../../src/model/mosaic/MosaicNames';
20+
import { NamespaceName } from '../../../src/model/namespace/NamespaceName';
21+
import { NamespaceId } from '../../../src/model/namespace/NamespaceId';
22+
23+
describe('MosaicNames', () => {
24+
25+
let namespaceName: NamespaceName[];
26+
let mosaicId: MosaicId;
27+
28+
before(() => {
29+
namespaceName = [new NamespaceName(new NamespaceId('test'), 'test')];
30+
mosaicId = new MosaicId('85BBEA6CC462B244');
31+
});
32+
33+
it('should createComplete a Mosaic name', () => {
34+
const mosaicNames = new MosaicNames(mosaicId, namespaceName);
35+
expect(mosaicNames.mosaicId.toHex()).to.be.equal('85BBEA6CC462B244');
36+
expect(mosaicNames.names[0].name).to.be.equal('test');
37+
expect(mosaicNames.names[0].parentId).to.be.undefined;
38+
expect(mosaicNames.names[0].namespaceId.fullName).to.be.equal('test');
39+
});
40+
});

test/model/transaction/AccountMetadataTransaction.spec.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import { AccountMetadataTransaction } from '../../../src/model/transaction/Accou
2222
import { Deadline } from '../../../src/model/transaction/Deadline';
2323
import { UInt64 } from '../../../src/model/UInt64';
2424
import { TestingAccount } from '../../conf/conf.spec';
25+
import { EmbeddedTransactionBuilder } from 'catbuffer-typescript/builders/EmbeddedTransactionBuilder';
26+
import { TransactionType } from '../../../src/model/transaction/TransactionType';
27+
import { deepEqual } from 'assert';
2528

2629
describe('AccountMetadataTransaction', () => {
2730
let account: Account;
@@ -77,19 +80,6 @@ describe('AccountMetadataTransaction', () => {
7780
)).to.be.equal('9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6E80300000000000001000A0000000000000000000000');
7881
});
7982

80-
it('should throw error if value size is bigger than 1024', () => {
81-
expect(() => {
82-
AccountMetadataTransaction.create(
83-
Deadline.create(),
84-
account.publicKey,
85-
UInt64.fromUint(1000),
86-
1,
87-
Convert.uint8ToUtf8(new Uint8Array(1025)),
88-
NetworkType.MIJIN_TEST,
89-
);
90-
}).to.throw(Error, 'The maximum value size is 1024');
91-
});
92-
9383
describe('size', () => {
9484
it('should return 182 for AccountMetadataTransaction byte size', () => {
9585
const accountMetadataTransaction = AccountMetadataTransaction.create(
@@ -108,4 +98,39 @@ describe('AccountMetadataTransaction', () => {
10898
expect(signedTransaction.hash).not.to.be.undefined;
10999
});
110100
});
101+
102+
it('should create EmbeddedTransactionBuilder', () => {
103+
const accountMetadataTransaction = AccountMetadataTransaction.create(
104+
Deadline.create(),
105+
account.publicKey,
106+
UInt64.fromUint(1000),
107+
1,
108+
Convert.uint8ToUtf8(new Uint8Array(10)),
109+
NetworkType.MIJIN_TEST,
110+
);
111+
112+
Object.assign(accountMetadataTransaction, {signer: account.publicAccount});
113+
114+
const embedded = accountMetadataTransaction.toEmbeddedTransaction();
115+
116+
expect(embedded).to.be.instanceOf(EmbeddedTransactionBuilder);
117+
expect(Convert.uint8ToHex(embedded.signerPublicKey.key)).to.be.equal(account.publicKey);
118+
expect(embedded.type.valueOf()).to.be.equal(TransactionType.ACCOUNT_METADATA.valueOf());
119+
});
120+
121+
it('should resolve alias', () => {
122+
const accountMetadataTransaction = AccountMetadataTransaction.create(
123+
Deadline.create(),
124+
account.publicKey,
125+
UInt64.fromUint(1000),
126+
1,
127+
Convert.uint8ToUtf8(new Uint8Array(10)),
128+
NetworkType.MIJIN_TEST,
129+
);
130+
131+
const resolved = accountMetadataTransaction.resolveAliases();
132+
133+
expect(resolved).to.be.instanceOf(AccountMetadataTransaction);
134+
deepEqual(accountMetadataTransaction, resolved);
135+
});
111136
});

test/model/transaction/MosaicMetadataTransaction.spec.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { MosaicMetadataTransaction } from '../../../src/model/transaction/Mosaic
3030
import { TransactionInfo } from '../../../src/model/transaction/TransactionInfo';
3131
import { UInt64 } from '../../../src/model/UInt64';
3232
import { TestingAccount } from '../../conf/conf.spec';
33+
import { EmbeddedTransactionBuilder } from 'catbuffer-typescript';
34+
import { TransactionType } from '../../../src/model/model';
3335

3436
describe('MosaicMetadataTransaction', () => {
3537
let account: Account;
@@ -97,20 +99,6 @@ describe('MosaicMetadataTransaction', () => {
9799
'787B6E8030000000000004CCCD78612DDF5CA01000A0000000000000000000000');
98100
});
99101

100-
it('should throw error if value size is bigger than 1024', () => {
101-
expect(() => {
102-
MosaicMetadataTransaction.create(
103-
Deadline.create(),
104-
account.publicKey,
105-
UInt64.fromUint(1000),
106-
new MosaicId([2262289484, 3405110546]),
107-
1,
108-
Convert.uint8ToUtf8(new Uint8Array(1025)),
109-
NetworkType.MIJIN_TEST,
110-
);
111-
}).to.throw(Error, 'The maximum value size is 1024');
112-
});
113-
114102
it('should create and sign an MosaicMetadataTransaction object using alias', () => {
115103
const namespacId = NamespaceId.createFromEncoded('9550CA3FC9B41FC5');
116104
const mosaicMetadataTransaction = MosaicMetadataTransaction.create(
@@ -187,4 +175,24 @@ describe('MosaicMetadataTransaction', () => {
187175
const signedTransaction = mosaicMetadataTransaction.signWith(account, generationHash);
188176
expect(signedTransaction.hash).not.to.be.undefined;
189177
});
178+
179+
it('should create EmbeddedTransactionBuilder', () => {
180+
const mosaicMetadataTransaction = MosaicMetadataTransaction.create(
181+
Deadline.create(),
182+
account.publicKey,
183+
UInt64.fromUint(1000),
184+
new MosaicId([2262289484, 3405110546]),
185+
1,
186+
Convert.uint8ToUtf8(new Uint8Array(10)),
187+
NetworkType.MIJIN_TEST,
188+
);
189+
190+
Object.assign(mosaicMetadataTransaction, {signer: account.publicAccount});
191+
192+
const embedded = mosaicMetadataTransaction.toEmbeddedTransaction();
193+
194+
expect(embedded).to.be.instanceOf(EmbeddedTransactionBuilder);
195+
expect(Convert.uint8ToHex(embedded.signerPublicKey.key)).to.be.equal(account.publicKey);
196+
expect(embedded.type.valueOf()).to.be.equal(TransactionType.MOSAIC_METADATA.valueOf());
197+
});
190198
});

test/model/transaction/NamespaceMetadataTransaction.spec.ts

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import { Deadline } from '../../../src/model/transaction/Deadline';
2323
import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetadataTransaction';
2424
import { UInt64 } from '../../../src/model/UInt64';
2525
import { TestingAccount } from '../../conf/conf.spec';
26+
import { EmbeddedTransactionBuilder } from 'catbuffer-typescript/builders/EmbeddedTransactionBuilder';
27+
import { TransactionType } from '../../../src/model/transaction/TransactionType';
28+
import { deepEqual } from 'assert';
2629

2730
describe('NamespaceMetadataTransaction', () => {
2831
let account: Account;
@@ -82,20 +85,6 @@ describe('NamespaceMetadataTransaction', () => {
8285
'A8787B6E8030000000000004CCCD78612DDF5CA01000A0000000000000000000000');
8386
});
8487

85-
it('should throw error if value size is bigger than 1024', () => {
86-
expect(() => {
87-
NamespaceMetadataTransaction.create(
88-
Deadline.create(),
89-
account.publicKey,
90-
UInt64.fromUint(1000),
91-
new NamespaceId([2262289484, 3405110546]),
92-
1,
93-
Convert.uint8ToUtf8(new Uint8Array(1025)),
94-
NetworkType.MIJIN_TEST,
95-
);
96-
}).to.throw(Error, 'The maximum value size is 1024');
97-
});
98-
9988
describe('size', () => {
10089
it('should return 190 for NamespaceMetadataTransaction byte size', () => {
10190
const namespaceMetadataTransaction = NamespaceMetadataTransaction.create(
@@ -128,4 +117,40 @@ describe('NamespaceMetadataTransaction', () => {
128117
const signedTransaction = namespaceMetadataTransaction.signWith(account, generationHash);
129118
expect(signedTransaction.hash).not.to.be.undefined;
130119
});
120+
121+
it('should create EmbeddedTransactionBuilder', () => {
122+
const namespaceMetadataTransaction = NamespaceMetadataTransaction.create(
123+
Deadline.create(),
124+
account.publicKey,
125+
UInt64.fromUint(1000),
126+
new NamespaceId([2262289484, 3405110546]),
127+
1,
128+
Convert.uint8ToUtf8(new Uint8Array(10)),
129+
NetworkType.MIJIN_TEST,
130+
);
131+
132+
Object.assign(namespaceMetadataTransaction, {signer: account.publicAccount});
133+
134+
const embedded = namespaceMetadataTransaction.toEmbeddedTransaction();
135+
136+
expect(embedded).to.be.instanceOf(EmbeddedTransactionBuilder);
137+
expect(Convert.uint8ToHex(embedded.signerPublicKey.key)).to.be.equal(account.publicKey);
138+
expect(embedded.type.valueOf()).to.be.equal(TransactionType.NAMESPACE_METADATA.valueOf());
139+
});
140+
141+
it('should resolve alias', () => {
142+
const namespaceMetadataTransaction = NamespaceMetadataTransaction.create(
143+
Deadline.create(),
144+
account.publicKey,
145+
UInt64.fromUint(1000),
146+
new NamespaceId([2262289484, 3405110546]),
147+
1,
148+
Convert.uint8ToUtf8(new Uint8Array(10)),
149+
NetworkType.MIJIN_TEST,
150+
);
151+
const resolved = namespaceMetadataTransaction.resolveAliases();
152+
153+
expect(resolved).to.be.instanceOf(NamespaceMetadataTransaction);
154+
deepEqual(namespaceMetadataTransaction, resolved);
155+
});
131156
});

0 commit comments

Comments
 (0)