Skip to content

Commit

Permalink
Merge pull request #5027 from connext/fix_db_unit_test
Browse files Browse the repository at this point in the history
fix: snapshots unit test
  • Loading branch information
preethamr authored Oct 18, 2023
2 parents 3f01b9d + b139972 commit aefed13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/adapters/database/test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ describe("Database client", () => {
await pool.query("DELETE FROM snapshot_roots CASCADE");
await pool.query("DELETE FROM snapshots CASCADE");
await pool.query("DELETE FROM stableswap_exchanges CASCADE");
await pool.end();
restore();
reset();
});
Expand Down Expand Up @@ -1605,12 +1606,18 @@ describe("Database client", () => {

it("should save and get single snapshot", async () => {
const snapshots: Snapshot[] = [];
const optimisticRootPropagated: OptimisticRootPropagated[] = [];
for (let _i = 0; _i < batchSize; _i++) {
const m = mock.entity.snapshot();
m.id = `${_i}`;
snapshots.push(m);
const o = mock.entity.optimisticRootPropagated();
o.id = m.id;
o.aggregateRoot = m.aggregateRoot;
optimisticRootPropagated.push(o);
}
await saveProposedSnapshots(snapshots, pool);
await savePropagatedOptimisticRoots(optimisticRootPropagated, pool);

const dbSnapshot = await getPendingAggregateRoot(snapshots[0].aggregateRoot, pool);
expect(dbSnapshot!.id).to.eq(snapshots[0].id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ describe("Roots operations", () => {
describe("#updateProposedSnapshots", () => {
it("should work", async () => {
(mockContext.adapters.subgraph.getProposedSnapshotsByDomain as SinonStub).resolves(
mockReceivedAggregateRootSubgraphResponse,
mockProposedSnapshotsSubgraphResponse,
mockProposedSnapshotsSubgraphResponse,
);
const newDisputeCliff = mockProposedSnapshotsSubgraphResponse.sort((a, b) => b.endOfDispute - a.endOfDispute)[0]
.endOfDispute;

await updateProposedSnapshots();
expect(mockContext.adapters.database.saveProposedSnapshots as SinonStub).callCount(1);
expect(mockContext.adapters.database.saveCheckPoint as SinonStub).callCount(1);
Expand All @@ -123,11 +127,11 @@ describe("Roots operations", () => {
{ hub: "1337", snapshotId: 42, limit: 100 },
]);
expect(mockContext.adapters.database.saveCheckPoint as SinonStub).to.be.calledOnceWithExactly(
"proposed_optimistic_root" + mockConnectorMeta[0].hubDomain,
43,
"proposed_optimistic_root_" + mockConnectorMeta[0].hubDomain,
mockProposedSnapshotsSubgraphResponse[1].endOfDispute,
);
expect(mockContext.adapters.database.getCheckPoint as SinonStub).to.be.calledOnceWithExactly(
"proposed_optimistic_root" + mockConnectorMeta[0].hubDomain,
"proposed_optimistic_root_" + mockConnectorMeta[0].hubDomain,
);
});
it("initial conditions", async () => {
Expand Down

0 comments on commit aefed13

Please sign in to comment.