import BN from "bn.js"; import { expect } from "chai"; import { ActionVertexInfo } from "../lib"; import { buildSeqListOfActionCalls } from "../lib/graph-utils"; describe("Test serializing action metas", () => { it("Should serialize a DAG of shape (0 + 1) -> 2", () => { const hit = buildSeqListOfActionCalls( [ buildTestActionVertexInfo([[2]], 1), buildTestActionVertexInfo([[2]], 1), buildTestActionVertexInfo([], 2), ], [0, 1] ); expect(hit).deep.eq([0, 1, 2]); }); it("Should serialize a DAG of shape (0 -> (1 + 2) + 2 -> 1)", () => { const hit = buildSeqListOfActionCalls( [ buildTestActionVertexInfo([[1, 2]], 1), buildTestActionVertexInfo([[]], 2), buildTestActionVertexInfo([[1]], 2), ], [0, 2] ); expect(hit).deep.eq([0, 2, 1]); }); it("Should serialize a DAG of shape (0 -> 2 + 1 -> 3) -> 4", () => { const hit = buildSeqListOfActionCalls( [ buildTestActionVertexInfo([[2]], 1), buildTestActionVertexInfo([[3]], 1), buildTestActionVertexInfo([[4]], 1), buildTestActionVertexInfo([[4]], 1), buildTestActionVertexInfo([], 2), ], [0, 1] ); expect(hit).deep.eq([0, 1, 2, 3, 4]); }); }); const buildTestActionVertexInfo = ( nextNodes: number[][], inDegree: number ): ActionVertexInfo => { return { // @ts-ignore nextNodes: nextNodes.map((n) => n.map((i) => { return { actionIdx: i, fraction: new BN(1) }; }) ), inDegree, }; };