Skip to content

Commit

Permalink
Merge pull request #6204 from connext/main
Browse files Browse the repository at this point in the history
testnet-prod <- main sync
  • Loading branch information
preethamr authored May 19, 2024
2 parents 162d1e2 + 186a591 commit 4d5f738
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 27 deletions.
48 changes: 24 additions & 24 deletions packages/adapters/subgraph/src/lib/helpers/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const originTransfer = (entity: any, asset: Record<string, AssetId>): Ori
"to",
"callData",
]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `OriginTransfer` entity parser: Transfer entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -174,7 +174,7 @@ export const destinationTransfer = (entity: any): DestinationTransfer => {
"status",
"routers",
]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `DestinationTransfer` entity parser: Transfer entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -271,7 +271,7 @@ export const originMessage = (entity: any): OriginMessage => {
throw new NxtpError("Subgraph `OriginMessage` entity parser: OriginMessage entity is `undefined`.");
}
for (const field of ["index", "leaf", "root", "domain", "destinationDomain", "transferId", "message"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `OriginMessage` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -324,7 +324,7 @@ export const rootMessage = (entity: any): RootMessage => {
throw new NxtpError("Subgraph `RootMessage` entity parser: RootMessage, entity is `undefined`.");
}
for (const field of ["id", "spokeDomain", "hubDomain", "root", "timestamp", "gasPrice", "gasLimit", "blockNumber"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `RootMessage` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -355,7 +355,7 @@ export const aggregatedRoot = (entity: any): AggregatedRoot => {
throw new NxtpError("Subgraph `AggregatedRoot` entity parser: AggregatedRoot, entity is `undefined`.");
}
for (const field of ["id", "domain", "receivedRoot", "index"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `AggregatedRoot` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -377,7 +377,7 @@ export const propagatedRoot = (entity: any): PropagatedRoot => {
throw new NxtpError("Subgraph `PropagatedRoot` entity parser: PropagatedRoot, entity is `undefined`.");
}
for (const field of ["id", "aggregate", "domainsHash", "count"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `PropagatedRoot` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -407,7 +407,7 @@ export const proposedRoot = (entity: any): Snapshot => {
"baseAggregateRoot",
"timestamp",
]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `proposedRoot` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -431,7 +431,7 @@ export const proposedSpokeOptimisticRoot = (entity: any): SpokeOptimisticRoot =>
throw new NxtpError("Subgraph `SpokeOptimisticRoot` entity parser: SpokeOptimisticRoot, entity is `undefined`.");
}
for (const field of ["id", "aggregateRoot", "rootTimestamp", "endOfDispute", "domain", "timestamp"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `SpokeOptimisticRoot` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -454,7 +454,7 @@ export const snapshotRoot = (entity: any): SnapshotRoot => {
throw new NxtpError("Subgraph `snapshotRoot` entity parser: snapshotRoot, entity is `undefined`.");
}
for (const field of ["id", "spokeDomain", "root", "count", "timestamp", "blockNumber"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `snapshotRoot` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -478,7 +478,7 @@ export const finalizedRoot = (entity: any): OptimisticRootFinalized => {
throw new NxtpError("Subgraph `finalizedRoot` entity parser: finalizedRoot, entity is `undefined`.");
}
for (const field of ["id", "aggregateRoot", "timestamp"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `finalizedRoot` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -501,7 +501,7 @@ export const propagatedOptimisticRoot = (entity: any): OptimisticRootPropagated
);
}
for (const field of ["id", "aggregateRoot", "domainsHash", "timestamp"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `propagatedOptimisticRoot` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -523,7 +523,7 @@ export const connectorMeta = (entity: any): ConnectorMeta => {
throw new NxtpError("Subgraph `ConnectorMeta` entity parser: ConnectorMeta, entity is `undefined`.");
}
for (const field of ["id", "spokeDomain", "hubDomain", "rootManager", "mirrorConnector", "amb"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `ConnectorMeta` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -547,7 +547,7 @@ export const rootManagerMeta = (entity: any): RootManagerMeta => {
throw new NxtpError("Subgraph `RootManagerMeta` entity parser: RootManagerMeta, entity is `undefined`.");
}
for (const field of ["id", "connectors", "domains"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `RootManagerMeta` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -568,7 +568,7 @@ export const rootManagerMode = (entity: any): RootManagerMode => {
throw new NxtpError("Subgraph `RootManagerMode` entity parser: RootManagerMode, entity is `undefined`.");
}
for (const field of ["id", "mode"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `RootManagerMode` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -588,7 +588,7 @@ export const spokeConnectorMode = (entity: any): SpokeConnectorMode => {
throw new NxtpError("Subgraph `SpokeConnectorMode` entity parser: SpokeConnectorMode, entity is `undefined`.");
}
for (const field of ["id", "mode"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `SpokeConnectorMode` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -610,7 +610,7 @@ export const receivedAggregateRoot = (entity: any): ReceivedAggregateRoot => {
);
}
for (const field of ["id", "root", "domain", "blockNumber"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `ReceivedAggregateRoot` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -646,7 +646,7 @@ export const stableSwapPool = (entity: any): StableSwapPool => {
"invariant",
"lpTokenSupply",
]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `StableSwapPool` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -696,7 +696,7 @@ export const stableSwapExchange = (entity: any): StableSwapExchange => {
"timestamp",
"nonce",
]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `stableSwapExchange` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -751,7 +751,7 @@ export const stableSwapPoolEvent = (entity: any): StableSwapPoolEvent => {
"timestamp",
"nonce",
]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `stableSwapPoolEvent` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -808,7 +808,7 @@ export const stableSwapLpTransfer = (entity: any): StableSwapTransfer => {
"timestamp",
"nonce",
]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `stableSwapLpTransfer` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -841,7 +841,7 @@ export const relayerFeesIncrease = (entity: any): RelayerFeesIncrease => {
throw new NxtpError("Subgraph `RelayerFeesIncrease` entity parser: RelayerFeesIncrease, entity is `undefined`.");
}
for (const field of ["id", "increase"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `RelayerFeesIncrease` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -865,7 +865,7 @@ export const slippageUpdate = (entity: any): SlippageUpdate => {
throw new NxtpError("Subgraph `SlippageUpdate` entity parser: SlippageUpdate, entity is `undefined`.");
}
for (const field of ["id", "slippage"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `SlippageUpdate` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand All @@ -888,7 +888,7 @@ export const routerDailyTvl = (entity: any): RouterDailyTVL => {
throw new NxtpError("Subgraph `RouterDailyTVL` entity parser: RouterDailyTVL, entity is `undefined`.");
}
for (const field of ["id", "asset", "router", "timestamp", "balance"]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `RouterDailyTVL` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down Expand Up @@ -926,7 +926,7 @@ export const routerLiquidityEvent = (entity: any): RouterLiquidityEvent => {
"timestamp",
"nonce",
]) {
if (!entity[field]) {
if (entity[field] === undefined || entity[field] === null) {
throw new NxtpError("Subgraph `routerLiquidityEvent` entity parser: Message entity missing required field", {
missingField: field,
entity,
Expand Down
26 changes: 26 additions & 0 deletions packages/adapters/subgraph/test/lib/helpers/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,32 @@ describe("Helpers:parse", () => {
}).to.throw("Subgraph `StableSwapPool` entity parser: Message entity missing required field");
});

it("should not throw if a required boolean field is false", () => {
const entity = {
key: mkBytes32("0xa"),
domain: "1111",
isActive: false,
lpToken: mkAddress("0xa"),
initialA: 200,
futureA: 200,
initialATime: 0,
futureATime: 0,
swapFee: "400000",
adminFee: "0",
pooledTokens: [mkAddress("0xa"), mkAddress("0xb")],
tokenPrecisionMultipliers: ["1", "1"],
poolTokenDecimals: [18, 18],
balances: ["200000", "200000"],
virtualPrice: "400000",
invariant: "0",
lpTokenSupply: "0",
};

expect(() => {
stableSwapPool(entity);
}).not.to.throw("Subgraph `StableSwapPool` entity parser: Message entity missing required field");
});

it("should parse valid swap pool", () => {
const entity = {
key: mkBytes32("0xa"),
Expand Down
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 4d5f738

Please sign in to comment.