Support bare flag on enums (#2518)
* Support bare flag on enums * Remove extra var allocation
This commit is contained in:
@@ -149,6 +149,8 @@ describe('Enum', (): void => {
|
||||
|
||||
expect(new Test(registry).toJSON()).toEqual({ A: null });
|
||||
expect(new Test(registry, 1234, 1).toJSON()).toEqual({ B: 1234 });
|
||||
expect(new Test(registry, 0x1234, 1).toU8a()).toEqual(new Uint8Array([1, 0x34, 0x12, 0x00, 0x00]));
|
||||
expect(new Test(registry, 0x1234, 1).toU8a(true)).toEqual(new Uint8Array([0x34, 0x12, 0x00, 0x00]));
|
||||
});
|
||||
|
||||
it('allows accessing the type and value', (): void => {
|
||||
|
||||
@@ -338,10 +338,8 @@ export default class Enum implements Codec {
|
||||
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
||||
*/
|
||||
public toU8a (isBare?: boolean): Uint8Array {
|
||||
const index = this.#indexes[this.#index];
|
||||
|
||||
return u8aConcat(
|
||||
new Uint8Array([index]),
|
||||
new Uint8Array(isBare ? [] : [this.#indexes[this.#index]]),
|
||||
this.#raw.toU8a(isBare)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user