Skip to content

Commit

Permalink
remove hardhat getBlockNumber RPC during alpha-router integ test beca…
Browse files Browse the repository at this point in the history
…use it might make tests fail with mining difficulty
  • Loading branch information
jsy1218 committed Oct 15, 2024
1 parent d5aaff2 commit 02146c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3156,9 +3156,11 @@ describe('alpha router integration', () => {
const amount = parseAmount('1.1', tokenIn);
const routeCachingProvider = new InMemoryRouteCachingProvider();
routeCachingProvider.cacheMode = CacheMode.Livemode;
routeCachingProvider.blocksToLive = Number.MAX_VALUE;
routeCachingProvider.expired = false;

// Insert a invalid cached routes for this test purpose to make sure it can get cleaned up
await routeCachingProvider.setCachedRoute(getInvalidCachedRoutesStub(await hardhat.providers[0]!.getBlockNumber())!, CurrencyAmount.fromRawAmount(USDC, 100));
await routeCachingProvider.setCachedRoute(getInvalidCachedRoutesStub(FORK_BLOCK)!, CurrencyAmount.fromRawAmount(USDC, 100));

// Create a new AlphaRouter with the new gas price provider
const customAlphaRouter: AlphaRouter = new AlphaRouter({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CachedRoutes, CacheMode, IRouteCachingProvider } from '../../../../../.
export class InMemoryRouteCachingProvider extends IRouteCachingProvider {
public routesCache: Map<string, CachedRoutes> = new Map();
public blocksToLive: number = 1;
public expired?: boolean = undefined;
public cacheMode: CacheMode = CacheMode.Darkmode;
public forceFail: boolean = false;
public internalGetCacheRouteCalls: number = 0;
Expand All @@ -15,6 +16,14 @@ export class InMemoryRouteCachingProvider extends IRouteCachingProvider {
return this.blocksToLive;
}

protected override filterExpiredCachedRoutes(
cachedRoutes: CachedRoutes | undefined,
blockNumber: number,
optimistic: boolean
): CachedRoutes | undefined {
return this.expired === undefined ? super.filterExpiredCachedRoutes(cachedRoutes, blockNumber, optimistic) : cachedRoutes;
}

protected override async _getCachedRoute(
chainId: ChainId,
amount: CurrencyAmount<Currency>,
Expand Down

0 comments on commit 02146c3

Please sign in to comment.