diff --git a/packages/types/src/codec/Struct.spec.ts b/packages/types/src/codec/Struct.spec.ts index 2e9b6647b7..e395475659 100644 --- a/packages/types/src/codec/Struct.spec.ts +++ b/packages/types/src/codec/Struct.spec.ts @@ -8,43 +8,40 @@ import Text from '../Text'; import U32 from '../U32'; import Vector from './Vector'; +const testDecode = (type: string, input: any) => + it(`can decode from ${type}`, () => { + const s = new Struct({ + foo: Text, + bar: U32 + }, input); + expect([...s.keys()]).toEqual(['foo', 'bar']); + expect( + [...s.values()].map((v) => + v.toString() + ) + ).toEqual(['bazzing', '69']); + }); + +const testEncode = (to: CodecTo, expected: any) => + it(`can encode ${to}`, () => { + const s = new Struct({ + foo: Text, + bar: U32 + }, { foo: 'bazzing', bar: 69 }); + expect(s[to]()).toEqual(expected); + }); + describe('Struct', () => { - describe('decoding', () => { - const testDecode = (type: string, input: any) => - it(`can decode from ${type}`, () => { - const s = new Struct({ - foo: Text, - bar: U32 - }, input); - expect([...s.keys()]).toEqual(['foo', 'bar']); - expect( - [...s.values()].map((v) => - v.toString() - ) - ).toEqual(['bazzing', '69']); - }); - testDecode('array', ['bazzing', 69]); - testDecode('hex', '0x1c62617a7a696e6745000000'); - testDecode('object', { foo: 'bazzing', bar: 69 }); - testDecode('Uint8Array', Uint8Array.from([28, 98, 97, 122, 122, 105, 110, 103, 69, 0, 0, 0])); - }); + testDecode('array', ['bazzing', 69]); + testDecode('hex', '0x1c62617a7a696e6745000000'); + testDecode('object', { foo: 'bazzing', bar: 69 }); + testDecode('Uint8Array', Uint8Array.from([28, 98, 97, 122, 122, 105, 110, 103, 69, 0, 0, 0])); - describe('encoding', () => { - const testEncode = (to: CodecTo, expected: any) => - it(`can encode ${to}`, () => { - const s = new Struct({ - foo: Text, - bar: U32 - }, { foo: 'bazzing', bar: 69 }); - expect(s[to]()).toEqual(expected); - }); - - testEncode('toHex', '0x1c62617a7a696e6745000000'); - testEncode('toJSON', { foo: 'bazzing', bar: 69 }); - testEncode('toU8a', Uint8Array.from([28, 98, 97, 122, 122, 105, 110, 103, 69, 0, 0, 0])); - testEncode('toString', '{"foo":"bazzing","bar":69}'); - }); + testEncode('toHex', '0x1c62617a7a696e6745000000'); + testEncode('toJSON', { foo: 'bazzing', bar: 69 }); + testEncode('toU8a', Uint8Array.from([28, 98, 97, 122, 122, 105, 110, 103, 69, 0, 0, 0])); + testEncode('toString', '{"foo":"bazzing","bar":69}'); it('decodes null', () => { expect( @@ -88,18 +85,6 @@ describe('Struct', () => { ).toEqual('{"txt":"foo","u32":1193046}'); }); - it('exposes the properties on the object', () => { - const struct = new ( - Struct.with({ - txt: Text, - u32: U32 - }) - )({ txt: 'foo', u32: 0x123456 }); - - expect((struct as any).txt.toString()).toEqual('foo'); - expect((struct as any).u32.toNumber()).toEqual(0x123456); - }); - it('correctly encodes length', () => { expect( new ( diff --git a/packages/types/src/codec/Struct.ts b/packages/types/src/codec/Struct.ts index 88ceff0ebb..61446fd740 100644 --- a/packages/types/src/codec/Struct.ts +++ b/packages/types/src/codec/Struct.ts @@ -111,13 +111,6 @@ export default class Struct< return class extends Struct { constructor (value?: any, jsonMap?: Map) { super(Types, value, jsonMap); - - (Object.keys(Types) as Array).forEach((key, index) => { - Object.defineProperty(this, key, { - enumerable: true, - get: () => this.getAtIndex(index) - }); - }); } }; }