diff --git a/packages/adapters/database/test/client.spec.ts b/packages/adapters/database/test/client.spec.ts index 0eafa5a39f..6c7e7082be 100644 --- a/packages/adapters/database/test/client.spec.ts +++ b/packages/adapters/database/test/client.spec.ts @@ -74,6 +74,8 @@ import { saveStableSwapPoolEvent, saveStableSwapTransfers, saveStableSwapLpBalances, + getMessageRootStatusFromIndex, + getAggregateRootByRootAndDomain, } from "../src/client"; describe("Database client", () => { @@ -1136,6 +1138,54 @@ describe("Database client", () => { expect(queryRes.rows[0].processed).to.eq(false); }); + it("should get getAggregateRootByRootAndDomain", async () => { + const roots: ReceivedAggregateRoot[] = []; + for (let _i = 0; _i < 10; _i++) { + const m = mock.entity.receivedAggregateRoot(); + m.domain = mock.domain.A; + roots.push(m); + } + + await saveReceivedAggregateRoot(roots, pool); + + const receivedAggregatedRoot = await getAggregateRootByRootAndDomain(mock.domain.A, roots[1].root, "ASC", pool); + + expect(receivedAggregatedRoot).to.deep.eq(roots[1]); + }); + + it("should get getMessageRootStatusFromIndex", async () => { + const messages: RootMessage[] = []; + const roots: AggregatedRoot[] = []; + const totalCount = 100; + const processedCount = 10; + const aggregatedCount = 20; + for (let _i = 0; _i < totalCount; _i++) { + const rootMessage = mock.entity.rootMessage(); + rootMessage.spokeDomain = mock.domain.A; + rootMessage.count = _i; + rootMessage.processed = _i < processedCount; + messages.push(rootMessage); + + const m = mock.entity.aggregatedRoot(); + m.index = _i; + m.domain = mock.domain.A; + m.receivedRoot = _i < aggregatedCount ? rootMessage.root : getRandomBytes32(); + roots.push(m); + } + + await saveSentRootMessages(messages, pool); + await saveAggregatedRoots(roots, pool); + + const messageStatus = await getMessageRootStatusFromIndex(mock.domain.A, 0, pool); + + expect(messageStatus).to.deep.eq({ + aggregatedCount: aggregatedCount, + lastAggregatedRoot: roots[aggregatedCount - 1].id, + processedCount: processedCount, + unprocessedCount: totalCount - processedCount, + }); + }); + it("should save assets", async () => { const assets = [mock.entity.asset(), mock.entity.asset(), mock.entity.asset()]; await saveAssets(assets, pool); diff --git a/packages/utils/src/types/db.ts b/packages/utils/src/types/db.ts index 6d274b331b..5537f69e28 100644 --- a/packages/utils/src/types/db.ts +++ b/packages/utils/src/types/db.ts @@ -439,9 +439,9 @@ export const convertFromDbReceivedAggregateRoot = (message: any): ReceivedAggreg */ export const convertFromDbRootStatus = (status: any): RootMessageStatus => { const obj = { - processedCount: status.processed_count, - unprocessedCount: status.unprocessed_count, - aggregatedCount: status.aggregated_count, + processedCount: +status.processed_count, + unprocessedCount: +status.unprocessed_count, + aggregatedCount: +status.aggregated_count, lastAggregatedRoot: status.last_aggregated_id ? status.last_aggregated_id.split("-")[0] : undefined, }; return sanitizeNull(obj);