Skip to content

Commit

Permalink
- Properly configure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clowestab committed Oct 10, 2024
1 parent be2da4a commit 6e479e3
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ export const CHAINS = {
CELO_ALFAJORES: 44787n,
} as const satisfies Record<string, Chain>;

const NAMES = new Map<Chain, string>(
export const CHAINS_NAMES = new Map<Chain, string>(
Object.entries(CHAINS).map(([a, b]) => [b, a])
);

export function chainName(chain: Chain): string {
const name = NAMES.get(chain);
const name = CHAINS_NAMES.get(chain);
if (!name) throw new TypeError(`unknown chain: ${chain}`);
return name;
}
9 changes: 9 additions & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import { CHAINS_NAMES } from './chains.js';

const args: { [key: string]: string } = {};
process.argv.slice(2).forEach((arg) => {
Expand All @@ -24,3 +25,11 @@ export const USER_CONFIG = envFileContent
acc[key.trim()] = value.trim();
return acc;
}, {});

export const testConfig = (chainName: string) => {
if (![...CHAINS_NAMES.values()].includes(chainName)) {
throw new TypeError(`unknown chain name: ${chainName}`);
}
USER_CONFIG['CHAIN_NAME'] = chainName;
return USER_CONFIG;
};
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type UserConfig = {
readonly ANKR_KEY: any;
readonly INFURA_KEY: string;
readonly ALCHEMY_KEY: string;
readonly ALCHEMY_PREMIUM: string;
readonly CHAIN_NAME: string;
readonly SHOULD_PREFETCH: boolean;
readonly PORT: number;
Expand Down
6 changes: 3 additions & 3 deletions test/gateway/arb1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { providerURL, createProviderPair } from '../../src/providers.js';
import { setupTests, testName } from './common.js';
import { afterAll } from 'bun:test';
import { describe } from '../bun-describe-fix.js';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';

const config = NitroRollup.arb1MainnetConfig;
describe(testName(config), async () => {
const rollup = new NitroRollup(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig('ARB1'), config),
config
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig('ARB1'), config.chain1),
infoLog: false,
});
afterAll(() => foundry.shutdown());
Expand Down
16 changes: 8 additions & 8 deletions test/gateway/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { EthSelfRollup } from '../../src/eth/EthSelfRollup.js';
import { afterAll } from 'bun:test';
import { describe } from '../bun-describe-fix.js';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';

export function testName(
{ chain1, chain2 }: ChainPair,
Expand Down Expand Up @@ -63,11 +63,11 @@ export function testOP(
) {
describe.skipIf(shouldSkip(opts))(testName(config), async () => {
const rollup = new OPRollup(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig(chainName(config.chain2)), config),
config
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: !!opts.log,
});
afterAll(() => foundry.shutdown());
Expand Down Expand Up @@ -99,11 +99,11 @@ export function testOPFault(
testName(config, { unfinalized: !!config.minAgeSec }),
async () => {
const rollup = new OPFaultRollup(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig(chainName(config.chain2)), config),
config
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: !!opts.log,
});
afterAll(() => foundry.shutdown());
Expand Down Expand Up @@ -143,11 +143,11 @@ export function testScroll(
) {
describe.skipIf(shouldSkip(opts))(testName(config), async () => {
const rollup = new ScrollRollup(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig(chainName(config.chain2)), config),
config
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: !!opts.log,
});
afterAll(() => foundry.shutdown());
Expand Down Expand Up @@ -175,7 +175,7 @@ export function testScroll(
export function testSelfEth(chain: Chain, opts: TestOptions) {
describe.skipIf(shouldSkip(opts))(chainName(chain), async () => {
const foundry = await Foundry.launch({
fork: providerURL(chain),
fork: providerURL(testConfig(chainName(chain)), chain),
infoLog: !!opts.log,
});
afterAll(() => foundry.shutdown());
Expand Down
7 changes: 4 additions & 3 deletions test/gateway/linea.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { createProviderPair, providerURL } from '../../src/providers.js';
import { setupTests, testName } from './common.js';
import { describe } from '../bun-describe-fix.js';
import { afterAll } from 'bun:test';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';
import { chainName } from '../../src/chains.js';

const config = LineaRollup.mainnetConfig;
describe(testName(config), async () => {
const rollup = new LineaRollup(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig(chainName(config.chain2)), config),
config
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: false,
});
afterAll(() => foundry.shutdown());
Expand Down
10 changes: 7 additions & 3 deletions test/gateway/polygon-pos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import { createProviderPair, providerURL } from '../../src/providers.js';
import { setupTests, testName } from './common.js';
import { describe } from '../bun-describe-fix.js';
import { afterAll } from 'bun:test';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';
import { chainName } from '../../src/chains.js';

const config = PolygonPoSRollup.mainnetConfig;
// 20240923: disabled until polygon has non-erigon rpcs
describe.skipIf(!!process.env.IS_CI)(testName(config), async () => {
const rollup = new PolygonPoSRollup(createProviderPair(USER_CONFIG, config), config);
const rollup = new PolygonPoSRollup(
createProviderPair(testConfig(chainName(config.chain2)), config),
config
);
rollup.configure = (c) => {
c.prover.proofRetryCount = 5; // hack for failing eth_getProof
};
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: false,
});
afterAll(() => foundry.shutdown());
Expand Down
7 changes: 4 additions & 3 deletions test/gateway/reverse-op.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import { providerURL, createProviderPair } from '../../src/providers.js';
import { setupTests, testName } from './common.js';
import { describe } from '../bun-describe-fix.js';
import { afterAll } from 'bun:test';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';
import { chainName } from '../../src/chains.js';

const config = ReverseOPRollup.mainnetConfig;
describe.skipIf(!!process.env.IS_CV)(
testName(config, { reverse: true }),
async () => {
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain2),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain2),
infoLog: false,
});
afterAll(() => foundry.shutdown());
const rollup = new ReverseOPRollup(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig(chainName(config.chain2)), config),
config
);
// NOTE: prove against prefork block, since state diverged on our fork
Expand Down
7 changes: 4 additions & 3 deletions test/gateway/taiko.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { providerURL, createProviderPair } from '../../src/providers.js';
import { setupTests, testName } from './common.js';
import { describe } from '../bun-describe-fix.js';
import { afterAll } from 'bun:test';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';
import { chainName } from '../../src/chains.js';

const config = TaikoRollup.mainnetConfig;
describe(testName(config), async () => {
const rollup = await TaikoRollup.create(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig(chainName(config.chain2)), config),
config
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: false,
});
afterAll(() => foundry.shutdown());
Expand Down
16 changes: 10 additions & 6 deletions test/gateway/unfinalized-arb1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import { providerURL, createProviderPair } from '../../src/providers.js';
import { setupTests, testName } from './common.js';
import { afterAll } from 'bun:test';
import { describe } from '../bun-describe-fix.js';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';
import { chainName } from '../../src/chains.js';

const config = NitroRollup.arb1MainnetConfig;
describe.skipIf(!!process.env.IS_CI)(
testName(config, { unfinalized: true }),
async () => {
const rollup = new NitroRollup(createProviderPair(USER_CONFIG, config), {
...config,
minAgeBlocks: 300,
});
const rollup = new NitroRollup(
createProviderPair(testConfig(chainName(config.chain2)), config),
{
...config,
minAgeBlocks: 300,
}
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: false,
});
afterAll(() => foundry.shutdown());
Expand Down
7 changes: 4 additions & 3 deletions test/gateway/unfinalized-linea.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { createProviderPair, providerURL } from '../../src/providers.js';
import { setupTests, testName } from './common.js';
import { describe } from '../bun-describe-fix.js';
import { afterAll } from 'bun:test';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';
import { chainName } from '../../src/chains.js';

// NOTE: since shomei does not produce proofs before finalization
// this approach wont work however the verifier does work
Expand All @@ -18,12 +19,12 @@ describe.skipIf(!!process.env.IS_CI)(
testName(config, { unfinalized: true }),
async () => {
const rollup = new UnfinalizedLineaRollup(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig(chainName(config.chain2)), config),
config,
(86400 * 2) / 12 // ~2 days of blocks >= finalization period
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: false,
});
afterAll(() => foundry.shutdown());
Expand Down
7 changes: 4 additions & 3 deletions test/gateway/zksync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { createProviderPair, providerURL } from '../../src/providers.js';
import { setupTests, testName } from './common.js';
import { describe } from '../bun-describe-fix.js';
import { afterAll } from 'bun:test';
import { USER_CONFIG } from '../../src/environment.js';
import { testConfig } from '../../src/environment.js';
import { chainName } from '../../src/chains.js';

const config = ZKSyncRollup.mainnetConfig;
describe(testName(config), async () => {
const rollup = new ZKSyncRollup(
createProviderPair(USER_CONFIG, config),
createProviderPair(testConfig(chainName(config.chain2)), config),
config
);
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
fork: providerURL(testConfig(chainName(config.chain2)), config.chain1),
infoLog: false,
infiniteCallGas: true, // Blake2s is ~12m gas per proof!
});
Expand Down
5 changes: 4 additions & 1 deletion test/proofs/zksync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { createProviderPair } from '../../src/providers.js';
import { USER_CONFIG } from '../../src/environment.js';

const config = ZKSyncRollup.mainnetConfig;
const rollup = new ZKSyncRollup(createProviderPair(USER_CONFIG, config), config);
const rollup = new ZKSyncRollup(
createProviderPair(USER_CONFIG, config),
config
);

rollup.provider2.on('debug', (e) => {
if (e.action === 'sendRpcPayload') {
Expand Down
5 changes: 4 additions & 1 deletion test/prover/LineaProver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { USER_CONFIG } from '../../src/environment.js';

describe('LineaProver', async () => {
const config = LineaRollup.mainnetConfig;
const gateway = new LineaRollup(createProviderPair(USER_CONFIG, config), config);
const gateway = new LineaRollup(
createProviderPair(USER_CONFIG, config),
config
);
const commit = await gateway.fetchLatestCommit();
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
Expand Down
5 changes: 4 additions & 1 deletion test/prover/ZKSyncProver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { USER_CONFIG } from '../../src/environment.js';

describe('ZKSyncProver', async () => {
const config = ZKSyncRollup.mainnetConfig;
const rollup = new ZKSyncRollup(createProviderPair(USER_CONFIG, config), config);
const rollup = new ZKSyncRollup(
createProviderPair(USER_CONFIG, config),
config
);
const commit = await rollup.fetchLatestCommit();
const foundry = await Foundry.launch({
fork: providerURL(USER_CONFIG, config.chain1),
Expand Down
7 changes: 5 additions & 2 deletions test/research/op-fault/find-resolved.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ethers } from 'ethers';
import { OPFaultRollup } from '../../../src/op/OPFaultRollup.js';
import { createProviderPair } from '../../../src/providers.js';
import { USER_CONFIG } from '../../src/environment.js';
import { USER_CONFIG } from '../../../src/environment.js';

const config = OPFaultRollup.mainnetConfig;
const rollup = new OPFaultRollup(createProviderPair(USER_CONFIG, config), config);
const rollup = new OPFaultRollup(
createProviderPair(USER_CONFIG, config),
config
);

// find the most recent dispute games
// warning: these might not be official games!
Expand Down

0 comments on commit 6e479e3

Please sign in to comment.