Skip to content

Commit

Permalink
test: make tests for hashflow work
Browse files Browse the repository at this point in the history
  • Loading branch information
Verisana committed Sep 19, 2023
1 parent 1711268 commit 460a9b0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ const baseConfigs: { [network: number]: BaseConfig } = {
process.env[`HASHFLOW_DISABLED_MMS_137`]?.split(',') || [],
adapterAddresses: {
PolygonAdapter01: '0xE44769f42E1e9592f86B82f206407a8f7C84b4ed',
PolygonAdapter02: '0xa05d8C3F278fC7b20b39Ea7A3035E3aD8D808c78',
PolygonBuyAdapter: '0xB11bCA7B01b425afD0743A4D77B4f593883f94C0',
PolygonAdapter02: '0x654cD2Cf97D23059B3db4FaA38BB2b1F8351211d',
PolygonBuyAdapter: '0x4426a1F87Ee7e366542c58e29c02AFa2b5878b37',
},
uniswapV2ExchangeRouterAddress:
'0xf3938337F7294fEf84e9B2c6D548A93F956Cc281',
Expand Down
5 changes: 4 additions & 1 deletion src/dex-helper/dummy-dex-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DummyCache implements ICache {
}

async rawget(key: string): Promise<string | null> {
return this.storage[key] ? this.storage[key] : null;
return null;
}

Expand All @@ -49,10 +50,12 @@ class DummyCache implements ICache {
value: string,
ttl: number,
): Promise<string | null> {
return null;
this.storage[key] = value;
return 'OK';
}

async rawdel(key: string): Promise<void> {
delete this.storage[key];
return;
}

Expand Down
39 changes: 36 additions & 3 deletions src/dex/hashflow/hashflow-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { Network, ContractMethod, SwapSide } from '../../constants';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { generateConfig } from '../../config';

// Give time for rate fetcher to fill the cache
const sleepMs = 3000;

function testForNetwork(
network: Network,
dexKey: string,
Expand Down Expand Up @@ -58,6 +61,11 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
undefined,
sleepMs,
);
});
it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => {
Expand All @@ -71,6 +79,11 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
undefined,
sleepMs,
);
});
} else {
Expand All @@ -85,6 +98,11 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
undefined,
sleepMs,
);
});
it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
Expand All @@ -98,6 +116,11 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
undefined,
sleepMs,
);
});
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
Expand All @@ -111,6 +134,11 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
undefined,
sleepMs,
);
});
it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => {
Expand All @@ -124,6 +152,11 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
undefined,
sleepMs,
);
});
}
Expand Down Expand Up @@ -163,9 +196,9 @@ describe('Hashflow E2E', () => {
const tokenASymbol: string = 'USDC';
const tokenBSymbol: string = 'DAI';

const tokenAAmount: string = '100000000';
const tokenBAmount: string = '100000000000000000000';
const nativeTokenAmount = '1000000000000000000';
const tokenAAmount: string = '1000000000';
const tokenBAmount: string = '1000000000000000000000';
const nativeTokenAmount = '100000000000000000000';

testForNetwork(
network,
Expand Down
4 changes: 2 additions & 2 deletions tests/tenderly-simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ export class TenderlySimulation implements TransactionSimulator {
return {
success: true,
gasUsed: data.transaction.gas_used,
tenderlyUrl: `https://dashboard.tenderly.co/${TENDERLY_ACCOUNT_ID}/${TENDERLY_PROJECT}/fork/${this.forkId}/simulation/${lastTx}`,
url: `https://dashboard.tenderly.co/${TENDERLY_ACCOUNT_ID}/${TENDERLY_PROJECT}/fork/${this.forkId}/simulation/${lastTx}`,
transaction: data.transaction,
};
} else {
return {
success: false,
tenderlyUrl: `https://dashboard.tenderly.co/${TENDERLY_ACCOUNT_ID}/${TENDERLY_PROJECT}/fork/${this.forkId}/simulation/${lastTx}`,
url: `https://dashboard.tenderly.co/${TENDERLY_ACCOUNT_ID}/${TENDERLY_PROJECT}/fork/${this.forkId}/simulation/${lastTx}`,
error: `Simulation failed: ${data.transaction.error_info.error_message} at ${data.transaction.error_info.address}`,
};
}
Expand Down
3 changes: 2 additions & 1 deletion tests/utils-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export async function testE2E(
),
);
expect(whitelistTx.success).toEqual(true);
console.log(`Successfully whitelisted ${deployedTestContractAddress}`);

if (testContractType === 'router') {
const setImplementationTx = await ts.simulate(
Expand Down Expand Up @@ -622,7 +623,7 @@ export async function newTestE2E({
parseInt(priceRoute.gasCost) - parseInt(swapTx!.gasUsed)
}`,
);
console.log(`Tenderly URL: ${swapTx!.tenderlyUrl}`);
console.log(`Tenderly URL: ${swapTx!.url}`);
expect(swapTx!.success).toEqual(true);
}
} finally {
Expand Down

0 comments on commit 460a9b0

Please sign in to comment.