diff --git a/packages/db/src/engines/MemoryDb.spec.ts b/packages/db/src/engines/MemoryDb.spec.ts new file mode 100644 index 000000000..dfb9ed89c --- /dev/null +++ b/packages/db/src/engines/MemoryDb.spec.ts @@ -0,0 +1,27 @@ +// Copyright 2017-2019 @polkadot/db authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import MemoryDb from './MemoryDb'; + +describe('MemoryDb', () => { + const memory = new MemoryDb(); + + it('gets the combioned size of the entry values', () => { + memory.put(new Uint8Array([1]), new Uint8Array([1, 2, 3])); + memory.put(new Uint8Array([2]), new Uint8Array([1, 2, 3])); + memory.put(new Uint8Array([3]), new Uint8Array([1, 2, 3])); + + expect(memory.size()).toEqual(9); + }); + + it('does not throw on the stubs', (done) => { + memory.close(); + memory.open(); + memory.drop(); + memory.empty(); + memory.rename('foo', 'bar'); + + memory.maintain(() => done()); + }); +}); diff --git a/packages/util/src/compact/toU8a.spec.ts b/packages/util/src/compact/toU8a.spec.ts index 3e9b26f2a..75da1ab4c 100644 --- a/packages/util/src/compact/toU8a.spec.ts +++ b/packages/util/src/compact/toU8a.spec.ts @@ -39,6 +39,14 @@ describe('encode', () => { ); }); + it('encodes basic u32 values (< 2^30)', () => { + expect( + compactToU8a(0x1fff) + ).toEqual( + new Uint8Array([253, 127]) + ); + }); + it('encodes basic u32 values (short)', () => { expect( compactToU8a(0xffff) diff --git a/packages/util/src/polyfill/fill.spec.ts b/packages/util/src/polyfill/fill.spec.ts index 21cdce74d..2378f60f9 100644 --- a/packages/util/src/polyfill/fill.spec.ts +++ b/packages/util/src/polyfill/fill.spec.ts @@ -4,19 +4,31 @@ describe('Array.fill', () => { let arrayFill: any; + let u8aFill: any; beforeEach(() => { arrayFill = Array.prototype.fill; - Array.prototype.fill = null as any; + u8aFill = Uint8Array.prototype.fill; + + // @ts-ignore + Array.prototype.fill = null; + // @ts-ignore + Uint8Array.prototype.fill = null; require('./fill'); }); afterEach(() => { Array.prototype.fill = arrayFill; + Uint8Array.prototype.fill = u8aFill; }); it('uses the polyfills', () => { - expect([1, 2, 3, 4, 5, 6, 7, 8].fill(5, 3)).toEqual([1, 2, 3, 5, 5, 5, 5, 5]); + expect( + [1, 2, 3, 4, 5, 6, 7, 8].fill(5, 3) + ).toEqual([1, 2, 3, 5, 5, 5, 5, 5]); + expect( + new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]).fill(5, 3) + ).toEqual(new Uint8Array([1, 2, 3, 5, 5, 5, 5, 5])); }); }); diff --git a/packages/util/src/polyfill/setPrototypeOf.spec.ts b/packages/util/src/polyfill/setPrototypeOf.spec.ts new file mode 100644 index 000000000..e483896eb --- /dev/null +++ b/packages/util/src/polyfill/setPrototypeOf.spec.ts @@ -0,0 +1,27 @@ +// Copyright 2017-2019 @polkadot/util authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +describe('setPrototypeOf', () => { + let orig: (o: any, proto: object | null) => any; + + beforeEach(() => { + orig = Object.setPrototypeOf; + + // @ts-ignore + Object.setPrototypeOf = null; + + require('./setPrototypeOf'); + }); + + afterEach(() => { + Object.setPrototypeOf = orig; + }); + + it('polyfills with no exceptions', () => { + const obj = {}; + const proto = { foo: 'bar' }; + + expect(Object.setPrototypeOf(obj, proto).__proto__).toBe(proto); + }); +});