Skip to content

Commit

Permalink
Merge pull request #6197 from 0xkenj1/feat/improve-txservice-logs
Browse files Browse the repository at this point in the history
feat: improve txservice logs
  • Loading branch information
preethamr authored May 19, 2024
2 parents cd1c759 + bb56191 commit 186a591
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
14 changes: 13 additions & 1 deletion packages/adapters/txservice/src/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,19 @@ export class RpcProviderAggregator {
return await provider.call(formatted, blockTag);
}
} catch (error: unknown) {
throw new TransactionReadError(TransactionReadError.reasons.ContractReadError, { error });
throw new TransactionReadError(TransactionReadError.reasons.ContractReadError, {
error,
provider: {
url: provider.name,
blockNumber: provider.syncedBlockNumber,
lag: provider.lag,
synced: provider.synced,
metrics: {
reliability: provider.reliability,
priority: provider.priority,
},
},
});
}
});
}
Expand Down
23 changes: 21 additions & 2 deletions packages/adapters/txservice/test/aggregator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ describe("RpcProviderAggregator", () => {
coreSyncProvider = Sinon.createStubInstance(SyncProvider);
(coreSyncProvider as any)._syncedBlockNumber = 123;
(coreSyncProvider as any).synced = true;
(coreSyncProvider as any).name = "-------fakeProvider------";
(coreSyncProvider as any).lag = 1;
(coreSyncProvider as any).reliability = 1.0;
(coreSyncProvider as any).priority = 0;
(coreSyncProvider as any).url = "https://-------fakeProvider------";
Sinon.stub(coreSyncProvider, "syncedBlockNumber").get(() => (coreSyncProvider as any)._syncedBlockNumber);
(chainProvider as any).providers = [coreSyncProvider];
Expand Down Expand Up @@ -290,9 +294,24 @@ describe("RpcProviderAggregator", () => {
it("should return error result if the signer readContract call throws", async () => {
const testError = new Error("test error");
signer.call.rejects(testError);

// The error.context.error is the "test error" thrown by the signer.call.
await expect(chainProvider.readContract(TEST_READ_TX)).to.be.rejectedWith(TransactionReadError);
await expect(chainProvider.readContract(TEST_READ_TX)).to.rejected.then((error) => {
if (error instanceof TransactionReadError) {
expect(error.context.error).to.eq(testError);
expect(error.context.provider).to.deep.eq({
url: coreSyncProvider.name,
blockNumber: coreSyncProvider.syncedBlockNumber,
lag: coreSyncProvider.lag,
synced: coreSyncProvider.synced,
metrics: {
reliability: coreSyncProvider.reliability,
priority: coreSyncProvider.priority,
},
});
} else {
expect.fail("Error should be a TransactionReadError");
}
});
});

it("should execute with provider if no signer available", async () => {
Expand Down

0 comments on commit 186a591

Please sign in to comment.