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

feat: adds unit tests #48

Closed
wants to merge 7 commits into from
Closed
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
23 changes: 23 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: unit-test

on: [push]

jobs:
unitTests:
name: 'unit tests'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3

- name: Install Yarn
run: npm install -g yarn

- name: Install node_modules with Yarn
run: yarn install

- name: run unit tests
run: yarn test:ci
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const nextJest = require('next/jest');

const createJestConfig = nextJest({ dir: './' });

const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testEnvironment: 'jest-environment-jsdom',
preset: 'ts-jest',
};

module.exports = createJestConfig(customJestConfig);
6 changes: 6 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TextEncoder as NodeTextEncoder } from 'util';

// Polyfill TextEncoder for Jest (used in viem)
if (typeof TextEncoder === 'undefined') {
global.TextEncoder = NodeTextEncoder;
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"prettier:format": "prettier --config-precedence file-override --write \"src/**/*.{tsx,ts,scss,md,json}\""
"prettier:format": "prettier --config-precedence file-override --write \"src/**/*.{tsx,ts,scss,md,json}\"",
"test": "jest --watch",
"test:ci": "jest"
},
"dependencies": {
"@ethersproject/providers": "^5.7.2",
Expand Down Expand Up @@ -36,6 +38,7 @@
"devDependencies": {
"@offchainlabs/prettier-config": "^0.2.1",
"@types/dotenv": "^8.2.0",
"@types/jest": "^29.5.4",
"@types/node": "18.16.3",
"@types/react": "18.2.2",
"@types/react-dom": "18.2.3",
Expand All @@ -44,11 +47,14 @@
"dotenv": "^16.0.3",
"eslint": "8.39.0",
"eslint-config-next": "13.4.13",
"jest": "^29.6.4",
"jest-environment-jsdom": "^29.6.4",
"postcss": "8.4.23",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.3.0",
"tailwind-merge": "^1.14.0",
"tailwindcss": "^3.3.3",
"ts-jest": "^29.1.1",
"typescript": "5.0.4"
}
}
}
43 changes: 43 additions & 0 deletions src/utils/__test__/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export const rollupConfig = {
confirmPeriodBlocks: 150,
stakeToken: '0x0000000000000000000000000000000000000000',
baseStake: 0.1,
owner: '0xF27c2fEfe6a39aa08763e504b44133CD992dd0f3',
extraChallengeTimeBlocks: 0,
wasmModuleRoot: '0xda4e3ad5e7feacb817c21c8d0220da7650fe9051ece68a3f0b1c5d38bbb27b21',
loserStakeEscrow: '0x0000000000000000000000000000000000000000',
chainId: 12286328813,
chainName: 'My Arbitrum L3 Chain',
chainConfig: '0x0000000000000000000000000000000000000000000000000000000000000000',
genesisBlockNum: 0,
sequencerInboxMaxTimeVariation: {
delayBlocks: 5760,
futureBlocks: 48,
delaySeconds: 86400,
futureSeconds: 3600,
},
};
export const parentChainId = 421613;

export const rollupContracts = {
rollup: '0x389a3eA93AcF8D3d9cE09008Db3b19b15D3698f0',
inbox: '0xe770844D0e343c5bcac19f16FD9559C6bA425c2F',
outbox: '0x5B8674639103E827d124a70CD1d48d3E59F41188',
adminProxy: '0xAaa60c3c0f3Fb37C57B2BF0E3e7533Cb6Ba79552',
sequencerInbox: '0x3d8d87d6280cA15f54dBF18151582E67F421576A',
bridge: '0x4816d0Bd98AF5635AEbAc468A9849C2A13Ed2ad0',
utils: '0x6efDC46924fc38763c5366a39BE4Ee1A14f22EA6',
validatorWalletCreator: '0x6601D1Fdc1db54b4AfA47E0876eE6575b0B3Cb60',
deployedAtBlockNumber: 36360310,
};

export const batchPoster = {
address: '0x3697A6Fd9682b905Cd81aB634BBc0d3bDe042059',
};

export const validators = [
{
privateKey: '0x3c5e657d99fcc95720df192aeca2be2c8ba743badbea6fcde2c086c16c8c2eb0',
address: '0xF27c2fEfe6a39aa08763e504b44133CD992dd0f3',
},
];
Loading