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

Various improvements #109

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
52b6a15
fix: copy address instead of shortenaddress or group
nicolasbrugneaux Nov 29, 2024
8e3996c
feat: show accurate unlocking period
nicolasbrugneaux Nov 29, 2024
f7cb634
fix: shows the correct proposal status
nicolasbrugneaux Nov 29, 2024
a258e82
fix: use the executedIds earlier in the flow to prioritize metadata<-…
nicolasbrugneaux Dec 3, 2024
d09f55a
refactor: use NEXT_PUBLIC_RPC_URL
nicolasbrugneaux Dec 4, 2024
b8f6816
chore: add anvil to tests
nicolasbrugneaux Dec 4, 2024
3dab9dd
Merge branch 'main' into fix/various
nicolasbrugneaux Dec 5, 2024
06f8e0d
fix: add foundry-toolchain
nicolasbrugneaux Dec 6, 2024
db0e282
fix: anvil on ci
nicolasbrugneaux Dec 6, 2024
e2372f6
fix: prettier
nicolasbrugneaux Dec 6, 2024
b3b1b98
fix: unused json
nicolasbrugneaux Dec 6, 2024
8f7d9b8
fix: quorum calculation
nicolasbrugneaux Dec 9, 2024
3cc68d8
fix: quorum calculation
nicolasbrugneaux Dec 10, 2024
3d0e29e
wip: tests
nicolasbrugneaux Dec 13, 2024
9b5deb9
fix: tests
nicolasbrugneaux Dec 16, 2024
45c3cc9
fake stash
nicolasbrugneaux Dec 16, 2024
209d515
wip: renderhooks
nicolasbrugneaux Dec 17, 2024
5d3c2ea
test: should pass!
nicolasbrugneaux Dec 18, 2024
2459980
Merge branch 'main' into fix/various
nicolasbrugneaux Dec 18, 2024
f237b89
fix: linting
nicolasbrugneaux Dec 18, 2024
55294c1
fix: ci
nicolasbrugneaux Dec 18, 2024
65f7f45
fix: prettier
nicolasbrugneaux Dec 18, 2024
c48b11c
fx: foundry version
nicolasbrugneaux Dec 18, 2024
2dfdab0
fix: anvil setup
nicolasbrugneaux Dec 18, 2024
6df3373
fix: more resilient snapshot
nicolasbrugneaux Dec 18, 2024
61b9025
fix: PR feedback
nicolasbrugneaux Dec 19, 2024
c0152ee
Merge branch 'main' into fix/various
nicolasbrugneaux Dec 19, 2024
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
Prev Previous commit
Next Next commit
fix: anvil on ci
  • Loading branch information
nicolasbrugneaux committed Dec 6, 2024
commit db0e282e8eaa0c17b9aed9e2a8210215fcaa2f97
12 changes: 7 additions & 5 deletions src/test/anvil/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { readFileSync } from 'fs';
import { parseEther } from 'viem';
import { celo } from 'viem/chains';

export const VITE_ANVIL_CELO_VERSION = process.env.VITE_ANVIL_CELO_VERSION as 'L1' | 'L2';

@@ -13,15 +15,15 @@ export const ANVIL_STATE_PATH = require.resolve(
: '@celo/devchain-anvil/l2-devchain.json',
);
const json = JSON.parse(readFileSync(ANVIL_STATE_PATH).toString());
export const FORK_BLOCK_NUMBER = BigInt(json.block.number as `0x${string}`);
export const FORK_BLOCK_NUMBER = BigInt(29162229);

export const ANVIL_CHAIN_ID = 12345;
export const ANVIL_FORK_URL = 12345;
export const ANVIL_CHAIN_ID = celo.id;
export const ANVIL_FORK_URL = 'https://public-archive-nodes.celo-testnet.org';

export const ANVIL_BASE_HOST = '127.0.0.1:8545';

export const TEST_MNEMONIC =
'concert load couple harbor equip island argue ramp clarify fence smart topic';
export const TEST_BALANCE = 1000000;
export const TEST_BALANCE = parseEther('1000');
export const TEST_GAS_PRICE = 0;
export const TEST_GAS_LIMIT = 20000000;
export const TEST_GAS_LIMIT = 20000000n;
13 changes: 6 additions & 7 deletions src/test/anvil/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { expect, test } from 'vitest';
import { FORK_BLOCK_NUMBER, TEST_BALANCE } from './constants';
import { testClient, walletClient } from './utils';
import { publicClient, walletClient } from './utils';

test('anvil is setup', async () => {
await expect(walletClient.getAddresses()).resolves.toMatchInlineSnapshot(`
[
"0x5409ED021D9299bf6814279A6A1411A7e866A631",
]
`);

await expect(
testClient.getBalance({ address: (await walletClient.getAddresses())[0] }),
).resolves.toBe(BigInt(TEST_BALANCE) * 10n ** 18n);
await expect(testClient.getBlobBaseFee()).resolves.toBe(0n);
await expect(testClient.getBlockNumber()).resolves.toBe(FORK_BLOCK_NUMBER);
});
publicClient.getBalance({ address: (await walletClient.getAddresses())[0] }),
).resolves.toBe(TEST_BALANCE);
await expect(publicClient.getBlobBaseFee()).resolves.toBe(0n);
await expect(publicClient.getBlockNumber()).resolves.toBe(FORK_BLOCK_NUMBER);
}, 60_000);
12 changes: 10 additions & 2 deletions src/test/anvil/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { fetchLogs } from '@viem/anvil';
import { beforeEach } from 'node:test';
import { afterEach } from 'vitest';
import { ANVIL_BASE_HOST } from './constants';
import { pool } from './utils';
import { ANVIL_BASE_HOST, ANVIL_FORK_URL, FORK_BLOCK_NUMBER } from './constants';
import { pool, testClient } from './utils';

beforeEach(async () => {
testClient.reset({
jsonRpcUrl: ANVIL_FORK_URL,
blockNumber: FORK_BLOCK_NUMBER,
});
});

afterEach(async (context) => {
context.onTestFailed(async () => {
21 changes: 14 additions & 7 deletions src/test/anvil/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTestClient, createWalletClient, http, publicActions, type Chain } from 'viem';
import { createPublicClient, createTestClient, createWalletClient, http } from 'viem';
import { mnemonicToAccount } from 'viem/accounts';
import { celoAlfajores } from 'viem/chains';
import { ANVIL_BASE_HOST, ANVIL_CHAIN_ID, TEST_MNEMONIC } from './constants';
import { celo } from 'viem/chains';
import { ANVIL_BASE_HOST, TEST_MNEMONIC } from './constants';

/**
* The id of the current test worker.
@@ -10,8 +10,7 @@ import { ANVIL_BASE_HOST, ANVIL_CHAIN_ID, TEST_MNEMONIC } from './constants';
*/
export const pool = Number(process.env.VITEST_POOL_ID ?? 1);
export const anvil = {
...celoAlfajores,
id: ANVIL_CHAIN_ID,
...celo,
rpcUrls: {
default: {
http: [`http://${ANVIL_BASE_HOST}/${pool}`],
@@ -22,13 +21,21 @@ export const anvil = {
webSocket: [`ws://${ANVIL_BASE_HOST}/${pool}`],
},
},
} as const satisfies Chain;
} as unknown as typeof celo;

export const testClient = createTestClient({
chain: anvil,
mode: 'anvil',
account: mnemonicToAccount(TEST_MNEMONIC),
transport: http(),
});

export const publicClient = createPublicClient({
chain: anvil,
// For some reason if we don't set a batch size it fails on anvil?
batch: { multicall: { batchSize: 2048 } },
transport: http(),
}).extend(publicActions);
});

export const walletClient = createWalletClient({
chain: anvil,
16 changes: 10 additions & 6 deletions src/test/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { startProxy } from '@viem/anvil';
import { formatEther } from 'viem';
import { celo } from 'viem/chains';
import {
ANVIL_CHAIN_ID,
ANVIL_STATE_PATH,
ANVIL_FORK_URL,
FORK_BLOCK_NUMBER,
TEST_BALANCE,
TEST_GAS_LIMIT,
TEST_GAS_PRICE,
@@ -13,14 +15,16 @@ export default async function setup() {
port: 8545,
host: '::', // By default, the proxy will listen on all interfaces.
options: {
chainId: ANVIL_CHAIN_ID,
state: ANVIL_STATE_PATH,
chainId: celo.id,
// state: ANVIL_STATE_PATH,
mnemonic: TEST_MNEMONIC,
balance: TEST_BALANCE,
balance: BigInt(formatEther(TEST_BALANCE)),
gasPrice: TEST_GAS_PRICE,
gasLimit: TEST_GAS_LIMIT,
forkUrl: ANVIL_FORK_URL,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we still need to fork at all?

forkBlockNumber: FORK_BLOCK_NUMBER,
blockBaseFeePerGas: 0,
stopTimeout: 1000,
startTimeout: 60_000,
},
});
}