-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
84 lines (74 loc) · 2.07 KB
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { cleanupTestEnvironment, resetTestEnvironment, getTestEnvironment } from './src/tests/utils/globalTestSetup.js';
import { config } from 'dotenv';
// Load test environment variables
config({ path: '.env.test' });
// Set default environment variables if not set
process.env.PRIVATE_KEY = process.env.PRIVATE_KEY || '0x0123456789012345678901234567890123456789012345678901234567890123';
process.env.INFURA_API_KEY = process.env.INFURA_API_KEY || '1234567890abcdef1234567890abcdef';
process.env.PROVIDER_URL = process.env.PROVIDER_URL || 'https://eth-sepolia.g.alchemy.com/v2/demo';
// Increase the timeout for all tests
jest.setTimeout(30000);
// Reset environment before all tests
beforeAll(async () => {
try {
await resetTestEnvironment();
} catch (error) {
console.error('Error during test environment reset:', error);
throw error;
}
});
// Mine 10 blocks before each test
beforeEach(async () => {
try {
const testEnv = await getTestEnvironment();
// Mine 10 blocks
for (let i = 0; i < 10; i++) {
await testEnv.provider.send('evm_mine', []);
}
} catch (error) {
console.error('Error mining blocks:', error);
throw error;
}
});
// Clean up after all tests
afterAll(async () => {
try {
await cleanupTestEnvironment();
} catch (error) {
console.error('Error during test environment cleanup:', error);
}
});
// Add BigInt serialization support
declare global {
interface BigInt {
toJSON(): string;
}
}
// Add BigInt serialization support
(BigInt.prototype as any).toJSON = function() {
return this.toString();
};
// Extend Jest's expect
declare global {
namespace jest {
interface Matchers<R> {
toBeBigInt(expected: bigint): R;
}
}
}
expect.extend({
toBeBigInt(received: bigint, expected: bigint) {
const pass = received === expected;
if (pass) {
return {
message: () => `expected ${received} not to be ${expected}`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to be ${expected}`,
pass: false,
};
}
},
});