From 683a96257e446c4901022d589b5a618ef9c9f9d8 Mon Sep 17 00:00:00 2001 From: Tien Dao Date: Thu, 20 Jun 2024 16:53:08 +0700 Subject: [PATCH] fix: reduce loop test igpconfig (#4005) ### Description Refactor `testIgpConfig` in `testUtils.ts` for Enhanced Readability and Maintainability by reduce loop ### Drive-by changes 1. **Constant Usage:** Introduced `OVERHEAD_COST` as a constant to replace the magic number `60000`, making the purpose of this value clearer and the code easier to update. 2. **Improved Readability:** By using descriptive names and constants, the function is now easier to understand at a glance, which is particularly beneficial for new contributors or during code reviews. 3. **Dynamic Configuration Logic:** Ensured that the configuration for `overhead` and `oracleConfig` is dynamically generated for each chain, excluding the current chain to simulate realistic test scenarios. These changes do not alter the logic but make the codebase cleaner and more maintainable. ### Related issues ### Backward compatibility ### Testing --------- Co-authored-by: tiendn --- typescript/.changeset/pink-mirrors-sneeze.md | 5 +++ typescript/sdk/src/test/testUtils.ts | 35 +++++++++++--------- 2 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 typescript/.changeset/pink-mirrors-sneeze.md diff --git a/typescript/.changeset/pink-mirrors-sneeze.md b/typescript/.changeset/pink-mirrors-sneeze.md new file mode 100644 index 000000000..207dab4e5 --- /dev/null +++ b/typescript/.changeset/pink-mirrors-sneeze.md @@ -0,0 +1,5 @@ +--- +'@hyperlane-xyz/sdk': major +--- + +Refactor testIgpConfig function for clarity and maintainability diff --git a/typescript/sdk/src/test/testUtils.ts b/typescript/sdk/src/test/testUtils.ts index fc498469a..5613d6be6 100644 --- a/typescript/sdk/src/test/testUtils.ts +++ b/typescript/sdk/src/test/testUtils.ts @@ -63,25 +63,30 @@ const TEST_ORACLE_CONFIG = { tokenExchangeRate: ethers.utils.parseUnits('1', 10), }; +const TEST_OVERHEAD_COST = 60000; + export function testIgpConfig( chains: ChainName[], owner = nonZeroAddress, ): ChainMap { return Object.fromEntries( - chains.map((local) => [ - local, - { - owner, - oracleKey: owner, - beneficiary: owner, - // TODO: these should be one map - overhead: Object.fromEntries( - exclude(local, chains).map((remote) => [remote, 60000]), - ), - oracleConfig: Object.fromEntries( - exclude(local, chains).map((remote) => [remote, TEST_ORACLE_CONFIG]), - ), - }, - ]), + chains.map((local) => { + const overhead: IgpConfig['overhead'] = {}; + const oracleConfig: IgpConfig['oracleConfig'] = {}; + exclude(local, chains).map((remote: ChainName) => { + overhead[remote] = TEST_OVERHEAD_COST; + oracleConfig[remote] = TEST_ORACLE_CONFIG; + }); + return [ + local, + { + owner, + oracleKey: owner, + beneficiary: owner, + overhead, + oracleConfig, + }, + ]; + }), ); }