polkadot-js/api

View on GitHub
packages/types/src/interfaces/identity/IdentityFields.spec.ts

Summary

Maintainability
A
0 mins
Test Coverage
// Copyright 2017-2024 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals.d.ts" />

import { TypeRegistry } from '../../create/index.js';

describe('IdentityFields', (): void => {
  const registry = new TypeRegistry();

  it('has a custom u64 (64-bit) encodedLength', (): void => {
    expect(
      registry.createType('IdentityFields').encodedLength
    ).toEqual(8);
  });

  it('encodes a sample', (): void => {
    expect(
      registry.createType('IdentityFields', ['Display', 'Legal']).valueEncoded.eqn(1 + 2)
    ).toBe(true);
  });

  it('encodes to a valid u8a value', (): void => {
    expect(
      registry.createType('IdentityFields', ['Display', 'Legal']).toU8a()
    ).toEqual(new Uint8Array([3, 0, 0, 0, 0, 0, 0, 0]));
  });

  it('decodes from a u8a', (): void => {
    expect(
      registry.createType('IdentityFields', new Uint8Array([1 + 2 + 64, 0, 0, 0, 0, 0, 0, 0])).toHuman()
    ).toEqual(['Display', 'Legal', 'Image']);
  });
});