Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: addressing flakiness of uniswap_trade_on_l1_from_l2.test.ts #5443

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion yarn-project/aztec-faucet/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import http from 'http';
import Koa from 'koa';
import cors from 'koa-cors';
import Router from 'koa-router';
import { Hex, http as ViemHttp, createWalletClient, parseEther } from 'viem';
import { Hex, http as ViemHttp, createPublicClient, createWalletClient, parseEther } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';

const {
Expand Down Expand Up @@ -68,6 +68,10 @@ async function transferEth(address: string) {
chain: chain.chainInfo,
transport: ViemHttp(chain.rpcUrl),
});
const publicClient = createPublicClient({
chain: chain.chainInfo,
transport: ViemHttp(chain.rpcUrl),
});
const hexAddress = createHex(address);
checkThrottle(hexAddress);
try {
Expand All @@ -76,6 +80,7 @@ async function transferEth(address: string) {
to: hexAddress,
value: parseEther(ETH_AMOUNT),
});
await publicClient.waitForTransactionReceipt({ hash });
mapping[hexAddress] = new Date();
logger.info(`Sent ${ETH_AMOUNT} ETH to ${hexAddress} in tx ${hash}`);
} catch (error) {
Expand Down
9 changes: 5 additions & 4 deletions yarn-project/end-to-end/src/e2e_cheat_codes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,25 @@ describe('e2e_cheat_codes', () => {
// without impersonation we wouldn't be able to send funds.
const myAddress = (await walletClient.getAddresses())[0];
const randomAddress = EthAddress.random().toString();
await walletClient.sendTransaction({
const tx1Hash = await walletClient.sendTransaction({
account: myAddress,
to: randomAddress,
value: parseEther('1'),
});
await publicClient.waitForTransactionReceipt({ hash: tx1Hash });
const beforeBalance = await publicClient.getBalance({ address: randomAddress });

// impersonate random address
await cc.eth.startImpersonating(EthAddress.fromString(randomAddress));
// send funds from random address
const amountToSend = parseEther('0.1');
const txHash = await walletClient.sendTransaction({
const tx2Hash = await walletClient.sendTransaction({
account: randomAddress,
to: myAddress,
value: amountToSend,
});
const tx = await publicClient.waitForTransactionReceipt({ hash: txHash });
const feePaid = tx.gasUsed * tx.effectiveGasPrice;
const txReceipt = await publicClient.waitForTransactionReceipt({ hash: tx2Hash });
const feePaid = txReceipt.gasUsed * txReceipt.effectiveGasPrice;
expect(await publicClient.getBalance({ address: randomAddress })).toBe(beforeBalance - amountToSend - feePaid);

// stop impersonating
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,24 @@ export const uniswapL1L2TestSuite = (
[registryAddress.toString(), uniswapL2Contract.address.toString()],
{} as any,
);
});

beforeEach(async () => {
// Give me some WETH so I can deposit to L2 and do the swap...
logger('Getting some weth');
await walletClient.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1') });
const hash = await walletClient.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1000') });
await publicClient.waitForTransactionReceipt({ hash });

const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
expect(wethBalance).toBe(parseEther('1000'));
});
// docs:end:uniswap_l1_l2_test_beforeAll

afterAll(async () => {
await cleanup();
});

// docs:start:uniswap_private
it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => {
const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
if (wethL1BeforeBalance < wethAmountToBridge) {
throw new Error('Not enough WETH to run this test. Try restarting anvil.');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I placed here this check a while ago and the message was incorrect (I though we are using anvil ETH and not WETH here).

}

// 1. Approve and deposit weth to the portal and move to L2
const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret();
Expand Down
Loading