Skip to content

Commit 58e9ade

Browse files
committed
Change testing framework to vitest
1 parent 72ad468 commit 58e9ade

File tree

3 files changed

+35
-48
lines changed

3 files changed

+35
-48
lines changed

evm/evm-rpc/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
"main": "lib/index.js",
1515
"scripts": {
1616
"build": "rm -rf lib && tsc",
17-
"test": "tsc --noEmit -p tsconfig.test.json && npx tsx --test test/**/*.test.ts",
18-
"test:verification": "npx tsx --test test/verification.test.ts",
19-
"test:rpc": "npx tsx --test test/rpc.test.ts",
17+
"lint": "tsc --noEmit -p tsconfig.test.json",
18+
"test": "vitest --run",
2019
"capture-fixture": "npx tsx test/capture-fixtures.ts"
2120
},
2221
"dependencies": {
@@ -40,6 +39,7 @@
4039
"@types/node": "^20.10.0",
4140
"@types/secp256k1": "4.0.6",
4241
"tsx": "^4.7.0",
43-
"typescript": "5.5.4"
42+
"typescript": "5.5.4",
43+
"vitest": "^1.4.0"
4444
}
4545
}

evm/evm-rpc/test/rpc.test.ts

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {it, describe} from 'node:test'
2-
import assert from 'assert'
1+
import {describe, it, expect} from 'vitest'
32
import {loadBlock, loadReceipts} from './helpers/fixture-loader'
43
import {MockRpcClient} from './helpers/mock-rpc-client'
54
import {Rpc} from '../src/rpc'
@@ -18,10 +17,10 @@ describe('Rpc Class Integration', () => {
1817
const rpc = new Rpc({client: mockClient as any})
1918

2019
const blocks = await rpc.getBlockBatch([18000000], {transactions: true})
21-
assert.ok(blocks, 'Blocks should be returned')
22-
assert.equal(blocks.length, 1)
23-
assert.ok(blocks[0].block, 'Block should have block property')
24-
assert.equal(blocks[0].block.number, fixtureBlock.number)
20+
expect(blocks).toBeTruthy()
21+
expect(blocks.length).toEqual(1)
22+
expect(blocks[0].block).toBeTruthy()
23+
expect(blocks[0].block.number).toEqual(fixtureBlock.number)
2524
})
2625

2726
it('getBlockBatch without transactions returns blocks with tx hashes only', async () => {
@@ -35,8 +34,8 @@ describe('Rpc Class Integration', () => {
3534
const rpc = new Rpc({client: mockClient as any})
3635

3736
const blocks = await rpc.getBlockBatch([18000000])
38-
assert.ok(blocks, 'Blocks should be returned')
39-
assert.equal(blocks.length, 1)
37+
expect(blocks).toBeTruthy()
38+
expect(blocks.length).toEqual(1)
4039
})
4140

4241
it('getBlockBatch handles missing blocks', async () => {
@@ -47,7 +46,7 @@ describe('Rpc Class Integration', () => {
4746
const rpc = new Rpc({client: mockClient as any})
4847

4948
const blocks = await rpc.getBlockBatch([99999999], {transactions: true})
50-
assert.equal(blocks.length, 0, 'Missing blocks should be filtered out')
49+
expect(blocks.length).toEqual(0)
5150
})
5251
})
5352

@@ -65,10 +64,10 @@ describe('Rpc Class Integration', () => {
6564
const rpc = new Rpc({client: mockClient as any})
6665

6766
const blocks = await rpc.getBlockBatch([18000000], {receipts: true, transactions: true})
68-
assert.ok(blocks, 'Blocks should be returned')
69-
assert.equal(blocks.length, 1)
70-
assert.ok(blocks[0].receipts, 'Block should have receipts attached')
71-
assert.ok(blocks[0].receipts!.length > 0, 'Receipts should not be empty')
67+
expect(blocks).toBeTruthy()
68+
expect(blocks.length).toEqual(1)
69+
expect(blocks[0].receipts).toBeTruthy()
70+
expect(blocks[0].receipts!.length).toBeGreaterThan(0)
7271
})
7372
})
7473

@@ -86,8 +85,8 @@ describe('Rpc Class Integration', () => {
8685
})
8786

8887
const blocks = await rpc.getBlockBatch([18000000], {transactions: true})
89-
assert.ok(blocks, 'Blocks should be returned after verification')
90-
assert.equal(blocks.length, 1)
88+
expect(blocks).toBeTruthy()
89+
expect(blocks.length).toEqual(1)
9190
})
9291

9392
it('verifies transactions root when enabled', async () => {
@@ -103,8 +102,8 @@ describe('Rpc Class Integration', () => {
103102
})
104103

105104
const blocks = await rpc.getBlockBatch([18000000], {transactions: true})
106-
assert.ok(blocks, 'Blocks should be returned after tx root verification')
107-
assert.equal(blocks.length, 1)
105+
expect(blocks).toBeTruthy()
106+
expect(blocks.length).toEqual(1)
108107
})
109108

110109
it('detects invalid block hash', async () => {
@@ -120,16 +119,9 @@ describe('Rpc Class Integration', () => {
120119
verifyBlockHash: true
121120
})
122121

123-
await assert.rejects(
124-
() => rpc.getBlockBatch([18000000], {transactions: true}),
125-
(error: any) => {
126-
assert.ok(
127-
error.message.includes('failed to verify') || error.message.includes('hash'),
128-
'Error should be about hash verification'
129-
)
130-
return true
131-
}
132-
)
122+
await expect(
123+
rpc.getBlockBatch([18000000], {transactions: true})
124+
).rejects.toThrow()
133125
})
134126
})
135127

@@ -147,8 +139,8 @@ describe('Rpc Class Integration', () => {
147139
})
148140

149141
const blocks = await rpc.getBlockBatch([50000000], {transactions: true})
150-
assert.ok(blocks, 'Blocks should be returned')
151-
assert.equal(blocks.length, 1)
142+
expect(blocks).toBeTruthy()
143+
expect(blocks.length).toEqual(1)
152144
})
153145

154146
it('handles Arbitrum transaction types correctly', async () => {
@@ -164,8 +156,8 @@ describe('Rpc Class Integration', () => {
164156
})
165157

166158
const blocks = await rpc.getBlockBatch([150000000], {transactions: true})
167-
assert.ok(blocks, 'Blocks should be returned')
168-
assert.equal(blocks.length, 1)
159+
expect(blocks).toBeTruthy()
160+
expect(blocks.length).toEqual(1)
169161
})
170162

171163
it('handles Hyperliquid system transactions correctly', async () => {
@@ -181,8 +173,8 @@ describe('Rpc Class Integration', () => {
181173
})
182174

183175
const blocks = await rpc.getBlockBatch([50000], {transactions: true})
184-
assert.ok(blocks, 'Blocks should be returned')
185-
assert.equal(blocks.length, 1)
176+
expect(blocks).toBeTruthy()
177+
expect(blocks.length).toEqual(1)
186178
})
187179
})
188180
})

evm/evm-rpc/test/verification.test.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {it, describe} from 'node:test'
2-
import assert from 'assert'
1+
import {describe, it, expect} from 'vitest'
32
import {loadBlock, loadReceipts, hasReceipts, listFixtures, getChainId} from './helpers/fixture-loader'
43
import {blockHash} from '../src/verification'
54
import {ChainUtils} from '../src/chain-utils'
@@ -12,7 +11,7 @@ describe('Verification Functions', () => {
1211
it('blockHash verification', async () => {
1312
const block = loadBlock(fixture.chain, fixture.blockNumber)
1413
const computed = await blockHash(block)
15-
assert.equal(computed, block.hash, `Block hash mismatch for ${fixture.name}`)
14+
expect(computed).toEqual(block.hash)
1615
})
1716

1817
it('transactionsRoot verification', async () => {
@@ -22,7 +21,7 @@ describe('Verification Functions', () => {
2221
const chainId = getChainId(fixture.chain)
2322
const utils = new ChainUtils(chainId)
2423
const computed = await utils.calculateTransactionsRoot(block)
25-
assert.equal(computed, block.transactionsRoot, `Transactions root mismatch for ${fixture.name}`)
24+
expect(computed).toEqual(block.transactionsRoot)
2625
})
2726

2827
if (hasReceipts(fixture.chain, fixture.blockNumber)) {
@@ -32,7 +31,7 @@ describe('Verification Functions', () => {
3231
const chainId = getChainId(fixture.chain)
3332
const utils = new ChainUtils(chainId)
3433
const computed = await utils.calculateReceiptsRoot(block, receipts)
35-
assert.equal(computed, block.receiptsRoot, `Receipts root mismatch for ${fixture.name}`)
34+
expect(computed).toEqual(block.receiptsRoot)
3635
})
3736

3837
it('logsBloom verification', async () => {
@@ -42,7 +41,7 @@ describe('Verification Functions', () => {
4241
const chainId = getChainId(fixture.chain)
4342
const utils = new ChainUtils(chainId)
4443
const computed = utils.calculateLogsBloom(block, logs)
45-
assert.equal(computed, block.logsBloom, `Logs bloom mismatch for ${fixture.name}`)
44+
expect(computed).toEqual(block.logsBloom)
4645
})
4746
}
4847

@@ -61,11 +60,7 @@ describe('Verification Functions', () => {
6160

6261
const recovered = utils.recoverTxSender(tx)
6362
if (recovered) {
64-
assert.equal(
65-
recovered.toLowerCase(),
66-
tx.from.toLowerCase(),
67-
`Sender mismatch for tx ${tx.hash} in ${fixture.name}`
68-
)
63+
expect(recovered.toLowerCase()).toEqual(tx.from.toLowerCase())
6964
}
7065
}
7166
})

0 commit comments

Comments
 (0)