UNPKG

@mutants/cardano-tx-builder

Version:

A package that provides utility functions to build and destructure a cardano transaction

103 lines (102 loc) 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const cbor_1 = require("cbor"); const tagPlutusData_1 = require("../tagPlutusData"); describe("tagPlutusData", () => { it("should correctly create a tagged plutus data", () => { expect((0, cbor_1.encode)((0, tagPlutusData_1.tagPlutusData)({ constructor: 0, fields: [ { bytes: "4d5554414e54", }, { bytes: Buffer.from("4d5554414e54", "hex"), }, { int: 123, }, { list: [ { plutusData: { constructor: 0, fields: [], }, }, { int: 321, }, ], }, { map: new Map([ [Buffer.from("name"), Buffer.from("Mutant #7890")], ]), }, { plutusData: { constructor: 0, fields: [ { int: 100, }, ], }, }, ], })).toString("hex")).toBe("d87986464d5554414e54464d5554414e54187b82d87980190141a1446e616d654c4d7574616e74202337383930d879811864"); }); it("should correctly create a tagged plutus data with indefinite length encoder", () => { const fields = [ { bytes: "4d5554414e54", }, { bytes: Buffer.from("4d5554414e54", "hex"), }, { int: 123, }, { list: [ { plutusData: { constructor: 0, fields: [], }, }, { int: 321, }, ], }, { map: new Map([ [Buffer.from("name"), Buffer.from("Mutant #7890")], ]), }, { plutusData: { constructor: 0, fields: [ { int: 100, }, ], }, }, ]; fields.encodeCBOR = cbor_1.Encoder.encodeIndefinite; expect((0, cbor_1.encode)((0, tagPlutusData_1.tagPlutusData)({ constructor: 0, fields, })).toString("hex")).toBe("d8799f464d5554414e54464d5554414e54187b82d87980190141a1446e616d654c4d7574616e74202337383930d879811864ff"); }); it("should throw an error when one of the fields has an invalid type", () => { expect(() => (0, tagPlutusData_1.tagPlutusData)({ constructor: 0, fields: [{ asd: 123 }], })).toThrow("Invalid PlutusDataField"); }); });