Skip to content

Commit

Permalink
use vitest (#726)
Browse files Browse the repository at this point in the history
* use vitest

* remove dangerouslyIgnore

* update delay

* fix

* add some delay
  • Loading branch information
ermalkaleci authored May 10, 2023
1 parent 508a532 commit 99b3e67
Show file tree
Hide file tree
Showing 41 changed files with 2,437 additions and 2,776 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@
"postinstall": "husky install"
},
"devDependencies": {
"@swc/core": "^1.3.46",
"@swc/helpers": "^0.5.0",
"@swc/core": "^1.3.56",
"@swc/helpers": "^0.5.1",
"@types/eslint": "^8",
"@types/node": "^18.15.13",
"@types/node": "^20.1.0",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"eslint": "^8.38.0",
"eslint": "^8.40.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"husky": "^8.0.0",
"lint-staged": "^13.2.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.0.4",
"unplugin-swc": "^1.3.2",
"vite-tsconfig-paths": "^4.0.8",
"vitest": "^0.29.8"
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.31.0"
},
"lint-staged": {
"*.{js,ts}": "eslint . --cache --ext .js,.ts --fix"
Expand Down
4 changes: 0 additions & 4 deletions packages/bodhi/.mocharc.js

This file was deleted.

79 changes: 0 additions & 79 deletions packages/bodhi/.npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion packages/bodhi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@ethersproject/strings": "~5.7.0",
"@types/bn.js": "~5.1.0",
"bn.js": "~5.2.0",
"ethers": "~5.7.0"
"ethers": "~5.7.2"
},
"devDependencies": {
"@types/chai": "~4.2.22",
Expand Down
1 change: 0 additions & 1 deletion packages/bodhi/src/evmChai/supportEmit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { providers } from 'ethers';

export function supportEmit(Assertion: Chai.AssertionStatic): void {
Expand Down
11 changes: 11 additions & 0 deletions packages/bodhi/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineProject, mergeConfig } from 'vitest/config';
import configShared from '../../vitest.shared';

export default mergeConfig(
configShared,
defineProject({
test: {
environment: 'jsdom',
},
})
);
62 changes: 0 additions & 62 deletions packages/eth-providers/.npmignore

This file was deleted.

16 changes: 3 additions & 13 deletions packages/eth-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"clean": "rm -rf lib tsconfig.tsbuildinfo",
"build": "tsc --build ./tsconfig.json",
"gql:typegen": "graphql-codegen --config codegen.yml",
"test:CI": "vitest --run --config vitest.config.ts"
"test:CI": "vitest --run --config vitest.config.e2e.ts"
},
"peerDependencies": {
"@acala-network/api": "~5.0.3-0",
Expand Down Expand Up @@ -36,21 +36,11 @@
},
"devDependencies": {
"@acala-network/api": "~5.0.3-0",
"@sinonjs/fake-timers": "~9.1.1",
"@types/bn.js": "~5.1.0",
"@types/chai": "~4.2.22",
"@types/chai-as-promised": "~7.1.4",
"@types/lru-cache": "~7.6.1",
"@types/sinon-chai": "^3.2.9",
"@types/sinonjs__fake-timers": "~8.1.2",
"@vitest/coverage-c8": "~0.28.5",
"chai": "~4.3.4",
"chai-as-promised": "~7.1.1",
"chai-subset": "~1.6.0",
"dotenv": "~10.0.0",
"sinon": "~13.0.1",
"sinon-chai": "~3.7.0",
"vitest": "^0.29.8"
"jsdom": "^22.0.0",
"vitest": "^0.31.0"
},
"files": [
"lib"
Expand Down
3 changes: 1 addition & 2 deletions packages/eth-providers/src/__tests__/MaxSizeSet.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MaxSizeSet } from '../utils/MaxSizeSet';
import { describe, it } from 'vitest';
import { expect } from 'chai';
import { describe, expect, it } from 'vitest';
import { mockChain } from './testUtils';

describe('MaxSizeSet', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/eth-providers/src/__tests__/decimals.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BigNumber } from '@ethersproject/bignumber';
import { describe, it } from 'vitest';
import { expect } from 'chai';
import { describe, expect, it } from 'vitest';
import { hexValue } from '@ethersproject/bytes';
import { nativeToEthDecimal } from '../utils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ERROR_PATTERN } from '../consts';
import { describe, it } from 'vitest';
import { expect } from 'chai';
import { describe, expect, it } from 'vitest';

describe('filterLog', () => {
const err0 =
Expand Down
16 changes: 11 additions & 5 deletions packages/eth-providers/src/__tests__/e2e/evm-rpc-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DUMMY_BLOCK_HASH } from '../../consts';
import { EvmRpcProvider } from '../../rpc-provider';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { runWithTiming } from '../../utils';
import { afterAll, describe, expect, it } from 'vitest';
import { runWithTiming, sleep } from '../../utils';
import dotenv from 'dotenv';

dotenv.config();
Expand All @@ -25,7 +25,10 @@ describe('initilization', async () => {
const provider = EvmRpcProvider.from(ACALA_NODE_URL);
await provider.isReady();

afterAll(async () => await provider.disconnect());
afterAll(async () => {
await sleep(5000);
await provider.disconnect();
});

it('should already has initial block number and hash', async () => {
expect(provider.latestBlockNumber).to.gt(-1);
Expand All @@ -47,7 +50,10 @@ describe('getReceiptAtBlock', async () => {
let receipt1;
let receipt2;

afterAll(async () => await provider.disconnect());
afterAll(async () => {
await sleep(5000);
await provider.disconnect();
});

it('should find tx using tx hash or index from subql', async () => {
receipt1 = await provider.getReceiptAtBlock(txHash1, blockHash);
Expand All @@ -67,7 +73,7 @@ describe('getReceiptAtBlock', async () => {
const res1 = await provider.getReceiptAtBlockFromChain(txHash1, blockHash);
const res2 = await provider.getReceiptAtBlockFromChain(txHash2, blockHash);

delete res2['exitReason']; // full receipt contains exitReason
delete res2?.['exitReason']; // full receipt contains exitReason
expect(res1).to.deep.equal(receipt1);
expect(res2).to.deep.equal(receipt2);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { BigNumber } from '@ethersproject/bignumber';
import { Contract } from '@ethersproject/contracts';
import { EvmRpcProvider } from '../../rpc-provider';
import { Wallet } from '@ethersproject/wallet';
import { afterAll, describe, it } from 'vitest';
import { afterAll, describe, expect, it } from 'vitest';
import { createTestPairs } from '@polkadot/keyring/testingPairs';
import { expect } from 'chai';
import { sendTx } from '../../utils';
import { sendTx, sleep } from '../../utils';
import ACAABI from '@acala-network/contracts/build/contracts/Token.json';
import ADDRESS from '@acala-network/contracts/utils/MandalaAddress';
import evmAccounts from '../evmAccounts';
Expand All @@ -16,9 +15,11 @@ describe('TransactionReceipt', async () => {
await provider.isReady();

afterAll(async () => {
await sleep(5000);
await provider.disconnect();
await new Promise(resolve => setTimeout(resolve, 5000));
await sleep(1000);
});

it('getTransactionReceipt', async () => {
const account1 = evmAccounts[0];
const account2 = evmAccounts[1];
Expand All @@ -43,10 +44,10 @@ describe('TransactionReceipt', async () => {
});

const receipt = await provider.getReceiptAtBlock(result.hash, result.blockHash);

expect(receipt.blockHash).equal(result.blockHash);
expect(receipt.logs.length).equal(1);
expect(receipt.logs[0].blockNumber).equal(result.blockNumber);
expect(receipt.logs[0].topics.length).equal(3);
expect(receipt).toBeTruthy();
expect(receipt!.blockHash).equal(result.blockHash);
expect(receipt!.logs.length).equal(1);
expect(receipt!.logs[0].blockNumber).equal(result.blockNumber);
expect(receipt!.logs[0].topics.length).equal(3);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Contract, ContractFactory } from 'ethers';
import { Wallet } from '@ethersproject/wallet';
import { describe, expect, it } from 'vitest';
import { afterAll, describe, expect, it } from 'vitest';
import { formatEther, hexZeroPad, parseEther } from 'ethers/lib/utils';

import { AcalaJsonRpcProvider } from '../../json-rpc-provider';
Expand Down Expand Up @@ -29,6 +29,10 @@ describe('JsonRpcProvider', async () => {
const providerLocal = new AcalaJsonRpcProvider(localEthRpc);
const wallet = new Wallet(testKey, providerLocal);

afterAll(async () => {
await sleep(5000);
});

describe.concurrent('get chain data', () => {
it('get chain id', async () => {
const network = await provider.getNetwork();
Expand Down
7 changes: 4 additions & 3 deletions packages/eth-providers/src/__tests__/e2e/parseBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import {
karura3607973,
mandala938075,
} from './receipt-snapshots';
import { afterAll, beforeAll, describe, it } from 'vitest';
import { expect } from 'chai';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { getAllReceiptsAtBlock } from '../../utils/parseBlock';
import { hexlifyRpcResult } from '../../utils';
import { hexlifyRpcResult, sleep } from '../../utils';
import { options } from '@acala-network/api';

interface FormatedReceipt {
Expand Down Expand Up @@ -101,9 +100,11 @@ describe.concurrent('getAllReceiptsAtBlock', () => {
});

afterAll(async () => {
await sleep(5000);
await apiK.disconnect();
await apiA.disconnect();
await apiM.disconnect();
await sleep(5000);
});

describe.concurrent('transfer kar', async () => {
Expand Down
Loading

0 comments on commit 99b3e67

Please sign in to comment.