-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbun.setup.ts
More file actions
46 lines (40 loc) · 1.39 KB
/
bun.setup.ts
File metadata and controls
46 lines (40 loc) · 1.39 KB
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
import { afterAll, beforeAll, beforeEach } from '@jest/globals';
import { 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';
// In Bun, we set the timeout in bunfig.toml (timeout = 30000)
// Initialize test environment
beforeAll(async () => {
try {
await getTestEnvironment();
} catch (error) {
console.error('Error during test environment initialization:', error);
throw error;
}
});
// Mine blocks before each test
beforeEach(async () => {
try {
const testEnv = await getTestEnvironment();
// Mine 5 blocks
for (let i = 0; i < 5; i++) {
await testEnv.provider.send('evm_mine', []);
}
} catch (error) {
console.error('Error mining blocks:', error);
throw error;
}
});
// Add BigInt serialization support
if (typeof BigInt.prototype.toJSON !== 'function') {
Object.defineProperty(BigInt.prototype, 'toJSON', {
value: function() {
return this.toString();
}
});
}