Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unit test on testnet prod #4810

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,9 @@ export const getMissingXCalls = async () => {
}

if (txIdsByDestinationDomain.has(originTransfer.xparams.destinationDomain)) {
txIdsByDestinationDomain
.get(originTransfer.xparams.destinationDomain)
?.push(`"${originTransfer.transferId as string}"`);
txIdsByDestinationDomain.get(originTransfer.xparams.destinationDomain)?.push(`"${originTransfer.transferId}"`);
} else {
txIdsByDestinationDomain.set(originTransfer.xparams.destinationDomain, [
`"${originTransfer.transferId as string}"`,
]);
txIdsByDestinationDomain.set(originTransfer.xparams.destinationDomain, [`"${originTransfer.transferId}"`]);
}

allTxById.set(originTransfer.transferId, originTransfer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,7 @@ describe("Operations:GetXCalls", () => {
];
(mockPubContext.adapters.subgraph.getLatestBlockNumber as SinonStub).resolves(mockBlockNumber);
(mockPubContext.adapters.subgraph.getDestinationXCalls as SinonStub).resolves(mockSubgraphResponse);
});

it("happy: should retrieve xcalls from the subgraph and publish them", async () => {
await getXCalls();

// Should have been called once per available/configured chain.
expect((mockPubContext.adapters.cache.transfers.getLatestNonce as SinonStub).callCount).to.be.eq(
Object.keys(mockInfo).length,
);
expect((mockPubContext.adapters.mqClient.publish as SinonStub).calledWithExactly(mockSubgraphResponse[0]));
expect((mockPubContext.adapters.mqClient.publish as SinonStub).calledWithExactly(mockSubgraphResponse[1]));
expect((mockPubContext.adapters.cache.transfers.setLatestNonce as SinonStub).calledWithExactly(mock.domain.A, 9));
expect(
(mockPubContext.adapters.cache.transfers.setLatestNonce as SinonStub).calledWithExactly(mock.domain.A, 10),
);
});

it("happy: should catch up the missing nonces from the subgraph and store them", async () => {
const xtransfer1 = mock.entity.xtransfer({
transferId: mkBytes32("0x1"),
nonce: 9,
Expand All @@ -70,16 +53,37 @@ describe("Operations:GetXCalls", () => {
const txIdsByDestinationDomain: Map<string, string[]> = new Map();
const allTxById: Map<string, XTransfer> = new Map();
const latestNonces: Map<string, number> = new Map();
const txByOriginDomain: Map<string, XTransfer[]> = new Map();
txIdsByDestinationDomain.set("13338", [xtransfer1.transferId, xtransfer2.transferId]);
allTxById.set(xtransfer1.transferId, xtransfer1);
allTxById.set(xtransfer2.transferId, xtransfer2);
txByOriginDomain.set("13337", [xtransfer1, xtransfer2]);
latestNonces.set("13337", 10);

(mockPubContext.adapters.subgraph.getOriginXCalls as SinonStub).resolves({
txIdsByDestinationDomain,
allTxById,
latestNonces,
txByOriginDomain,
});
});

it("happy: should retrieve xcalls from the subgraph and publish them", async () => {
await getXCalls();

// Should have been called once per available/configured chain.
expect((mockPubContext.adapters.cache.transfers.getLatestNonce as SinonStub).callCount).to.be.eq(
Object.keys(mockInfo).length,
);
expect((mockPubContext.adapters.mqClient.publish as SinonStub).calledWithExactly(mockSubgraphResponse[0]));
expect((mockPubContext.adapters.mqClient.publish as SinonStub).calledWithExactly(mockSubgraphResponse[1]));
expect((mockPubContext.adapters.cache.transfers.setLatestNonce as SinonStub).calledWithExactly(mock.domain.A, 9));
expect(
(mockPubContext.adapters.cache.transfers.setLatestNonce as SinonStub).calledWithExactly(mock.domain.A, 10),
);
});

it("happy: should catch up the missing nonces from the subgraph and store them", async () => {
await getXCalls();

// Should have been called once per available/configured chain.
Expand All @@ -96,11 +100,9 @@ describe("Operations:GetXCalls", () => {

it("should not publish if nothing available", async () => {
(mockPubContext.adapters.subgraph.getDestinationXCalls as SinonStub).resolves([]);

await getXCalls();

expect((mockPubContext.adapters.mqClient.publish as SinonStub).callCount).to.be.eq(0);
expect((mockPubContext.adapters.cache.transfers.setLatestNonce as SinonStub).callCount).to.be.eq(0);
expect((mockPubContext.adapters.cache.transfers.setLatestNonce as SinonStub).callCount).to.be.eq(1);
});

it("should catch publish error", async () => {
Expand Down