fix: reduce loop test igpconfig (#4005)

### Description
Refactor `testIgpConfig` in `testUtils.ts` for Enhanced Readability and
Maintainability by reduce loop
<!--
What's included in this PR?
-->

### 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.
<!--
Are there any minor or drive-by changes also included?
-->
These changes do not alter the logic but make the codebase cleaner and
more maintainable.
### Related issues

<!--
- Fixes #[issue number here]
-->

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure
implications, e.g. changes that would prohibit deploying older commits
using this infra tooling?

Yes/No
-->

### Testing

<!--
What kind of testing have these changes undergone?

None/Manual/Unit Tests
-->

---------

Co-authored-by: tiendn <tiendn.works@gmail.com>
pull/4016/head
Tien Dao 5 months ago committed by GitHub
parent f9bbdde764
commit 683a96257e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      typescript/.changeset/pink-mirrors-sneeze.md
  2. 35
      typescript/sdk/src/test/testUtils.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': major
---
Refactor testIgpConfig function for clarity and maintainability

@ -63,25 +63,30 @@ const TEST_ORACLE_CONFIG = {
tokenExchangeRate: ethers.utils.parseUnits('1', 10), tokenExchangeRate: ethers.utils.parseUnits('1', 10),
}; };
const TEST_OVERHEAD_COST = 60000;
export function testIgpConfig( export function testIgpConfig(
chains: ChainName[], chains: ChainName[],
owner = nonZeroAddress, owner = nonZeroAddress,
): ChainMap<IgpConfig> { ): ChainMap<IgpConfig> {
return Object.fromEntries( return Object.fromEntries(
chains.map((local) => [ chains.map((local) => {
local, const overhead: IgpConfig['overhead'] = {};
{ const oracleConfig: IgpConfig['oracleConfig'] = {};
owner, exclude(local, chains).map((remote: ChainName) => {
oracleKey: owner, overhead[remote] = TEST_OVERHEAD_COST;
beneficiary: owner, oracleConfig[remote] = TEST_ORACLE_CONFIG;
// TODO: these should be one map });
overhead: Object.fromEntries( return [
exclude(local, chains).map((remote) => [remote, 60000]), local,
), {
oracleConfig: Object.fromEntries( owner,
exclude(local, chains).map((remote) => [remote, TEST_ORACLE_CONFIG]), oracleKey: owner,
), beneficiary: owner,
}, overhead,
]), oracleConfig,
},
];
}),
); );
} }

Loading…
Cancel
Save