diff --git a/yarn-project/aztec-faucet/src/bin/index.ts b/yarn-project/aztec-faucet/src/bin/index.ts index df33695c57b..dd93e9655f1 100644 --- a/yarn-project/aztec-faucet/src/bin/index.ts +++ b/yarn-project/aztec-faucet/src/bin/index.ts @@ -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 { @@ -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 { @@ -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) { diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index 37daaf1b9b9..20c7761db90 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -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 diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index fd1ca3c1acc..cfc3b3de554 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -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.'); - } // 1. Approve and deposit weth to the portal and move to L2 const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret();