Enum with single-entry encoding (#1670)

* Enum with single-entry encoding

* Expand test with breakdown
This commit is contained in:
Jaco Greeff
2019-12-13 11:19:38 +01:00
committed by GitHub
parent 99073e2a88
commit 067f17b28b
+24 -1
View File
@@ -6,7 +6,7 @@ import { Registry } from '../types';
import { u8aToHex } from '@polkadot/util';
import { TypeRegistry } from './create';
import { TypeRegistry, createType } from './create';
import Null from '../primitive/Null';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
@@ -326,6 +326,29 @@ describe('Enum', (): void => {
expect(test.toHex()).toEqual('0x017b000000');
expect(test.encodedLength).toEqual(1 + 4);
});
it('encodes a single entry correctly', (): void => {
const Test = Enum.with({ A: 'u32' });
const test = new Test(registry, 0x44332211, 0);
expect(test.toHex()).toEqual(
'0x' +
'00' + // index
'11223344' // u32 LE encoded
);
});
it('encodes a single entry correctly (with embedded encoding)', (): void => {
const Test = Enum.with({ A: 'Address' });
const test = new Test(registry, createType(registry, 'AccountId', '0x0001020304050607080910111213141516171819202122232425262728293031'), 0);
expect(test.toHex()).toEqual(
'0x' +
'00' + // index
'ff' + // Address indicating an embedded AccountId
'0001020304050607080910111213141516171819202122232425262728293031' // AccountId
);
});
});
});
});