"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("@polkadot/types");
const chai_1 = require("../../chai");
const factory_1 = require("../../../src/factory");
const utils_1 = require("../../../src/utils");
describe("Encoding", () => {
    let registry;
    const createH256Le = (hash) => {
        return new (registry.createClass("H256Le"))(registry, hash);
    };
    before(() => {
        registry = new types_1.TypeRegistry();
        registry.register(factory_1.getAPITypes());
    });
    it("should encode / decode same block hash as H256Le", () => {
        const blockHashHexLE = "0x9067166e896765258f6636a082abad6953f17a0e8dc21fc4f85648ceeedbda69";
        const blockHash = createH256Le(blockHashHexLE);
        return chai_1.assert.equal(blockHash.toHex(), blockHashHexLE);
    });
    it("should strip prefix", () => {
        const blockHashHexBEWithPrefix = "0x5499ac3ca3ddf563ace6b6a56ec2e8bdc5f796bef249445c36d90a69d0757d4c";
        const blockHashHexBEWithoutPrefix = "5499ac3ca3ddf563ace6b6a56ec2e8bdc5f796bef249445c36d90a69d0757d4c";
        chai_1.assert.equal(utils_1.stripHexPrefix(blockHashHexBEWithPrefix), blockHashHexBEWithoutPrefix);
        chai_1.assert.equal(utils_1.stripHexPrefix(blockHashHexBEWithoutPrefix), blockHashHexBEWithoutPrefix);
    });
    it("should reverse endianness from le to be", () => {
        const blockHashHexLE = "0x9067166e896765258f6636a082abad6953f17a0e8dc21fc4f85648ceeedbda69";
        const blockHashHexBE = "0x69dadbeece4856f8c41fc28d0e7af15369adab82a036668f256567896e166790";
        const blockHash = createH256Le(blockHashHexLE);
        const result = utils_1.uint8ArrayToString(utils_1.reverseEndianness(blockHash));
        return chai_1.assert.equal(result, utils_1.stripHexPrefix(blockHashHexBE));
    });
    it("should reverse endianness hex", () => {
        const blockHashHexLE = "0x9067166e896765258f6636a082abad6953f17a0e8dc21fc4f85648ceeedbda69";
        const blockHashHexBE = "0x69dadbeece4856f8c41fc28d0e7af15369adab82a036668f256567896e166790";
        return chai_1.assert.equal(utils_1.reverseEndiannessHex(blockHashHexLE), utils_1.stripHexPrefix(blockHashHexBE));
    });
});
//# sourceMappingURL=encoding.test.js.map