From 5152da508b4caf257e47827482680fd37db5b3f6 Mon Sep 17 00:00:00 2001 From: Nam Chu Hoai Date: Fri, 10 Mar 2023 05:16:19 -0500 Subject: [PATCH] Validator metadata name matches key (#1918) ### Description If you use a different name, then MP lookup can fail. Thus we should validate that the key matches the name --- typescript/sdk/src/providers/MultiProvider.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/typescript/sdk/src/providers/MultiProvider.ts b/typescript/sdk/src/providers/MultiProvider.ts index fb7f9e188..9990aaaf2 100644 --- a/typescript/sdk/src/providers/MultiProvider.ts +++ b/typescript/sdk/src/providers/MultiProvider.ts @@ -40,9 +40,13 @@ export class MultiProvider { chainMetadata: ChainMap = defaultChainMetadata, options: MultiProviderOptions = {}, ) { - Object.values(chainMetadata).forEach((cm) => { + Object.entries(chainMetadata).forEach(([key, cm]) => { if (!isValidChainMetadata(cm)) throw new Error(`Invalid chain metadata for ${cm.chainId}`); + if (key !== cm.name) + throw new Error( + `Chain name mismatch: Key was ${key}, but name is ${cm.name}`, + ); }); this.metadata = chainMetadata;