Skip to content

Commit e2a694f

Browse files
authored
Merge pull request #489 from NEMStudios/task/g455_namespace_max_depth
Make namespace max depth configurable in idGenerator
2 parents 0c4577b + 25e9b4a commit e2a694f

File tree

5 files changed

+45
-12
lines changed

5 files changed

+45
-12
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/format/IdGenerator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
import {sha3_256} from 'js-sha3';
1717
import * as utilities from './Utilities';
18+
import { idGeneratorConst } from './Utilities';
1819

1920
export class IdGenerator {
2021
/**

src/core/format/Utilities.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export const tryParseUint = (str) => {
9494

9595
export const idGeneratorConst = {
9696
namespace_base_id: [0, 0],
97-
namespace_max_depth: 3,
9897
name_pattern: /^[a-z0-9][a-z0-9-_]*$/,
9998
};
10099

@@ -114,9 +113,6 @@ export const extractPartName = (name, start, size) => {
114113
};
115114

116115
export const append = (path, id, name) => {
117-
if (idGeneratorConst.namespace_max_depth === path.length) {
118-
this.throwInvalidFqn('too many parts', name);
119-
}
120116
path.push(id);
121117
};
122118

test/core/format/Convert.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,49 @@ describe('convert', () => {
147147
});
148148
});
149149

150+
describe('hexToUint8Reverse', () => {
151+
it('can parse empty hex string into array', () => {
152+
// Act:
153+
const actual = convert.hexToUint8Reverse('');
154+
155+
// Assert:
156+
const expected = Uint8Array.of();
157+
expect(actual).to.deep.equal(expected);
158+
});
159+
160+
it('can parse valid hex string into array', () => {
161+
// Act:
162+
const actual = convert.hexToUint8Reverse('026ee415fc15');
163+
164+
// Assert:
165+
const expected = Uint8Array.of(0x15, 0xFC, 0x15, 0xE4, 0x6E, 0x02);
166+
expect(actual).to.deep.equal(expected);
167+
});
168+
169+
it('can parse valid hex string containing all valid hex characters into array', () => {
170+
// Act:
171+
const actual = convert.hexToUint8Reverse('abcdef0123456789ABCDEF');
172+
173+
// Assert:
174+
const expected = Uint8Array.of(0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB);
175+
expect(actual).to.deep.equal(expected);
176+
});
177+
178+
it('cannot parse hex string with invalid characters into array', () => {
179+
// Assert:
180+
expect(() => {
181+
convert.hexToUint8Reverse('abcdef012345G789ABCDEF');
182+
}).to.throw('unrecognized hex char');
183+
});
184+
185+
it('cannot parse hex string with invalid size into array', () => {
186+
// Assert:
187+
expect(() => {
188+
convert.hexToUint8Reverse('abcdef012345G789ABCDE');
189+
}).to.throw('hex string has unexpected size');
190+
});
191+
});
192+
150193
describe('uint8ToHex', () => {
151194
it('can format empty array into hex string', () => {
152195
// Act:

test/core/format/IdGenerator.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,11 @@ describe('id generator', () => {
234234
expect(idGenerator.generateNamespacePath('foo.bar.baz')).to.deep.equal(expected);
235235
});
236236

237-
it('rejects names with too many parts', () => {
238-
// Assert:
239-
['a.b.c.d', 'a.b.c.d.e'].forEach((name) =>
240-
expect(() => idGenerator.generateNamespacePath(name), `name ${name}`).to.throw('too many parts'));
241-
});
242-
243237
it('rejects improper qualified names', () => {
244238
// Assert:
245239
['a:b:c', 'a::b'].forEach((name) =>
246240
expect(() => idGenerator.generateNamespacePath(name), `name ${name}`).to.throw('invalid part name'));
247241
});
248-
249242
addBasicTests(idGenerator.generateNamespacePath);
250243
});
251244
});

0 commit comments

Comments
 (0)