-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstability.test.js
64 lines (50 loc) · 2.99 KB
/
stability.test.js
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
// tests/stability.test.js
const StabilityManager = require('../src/tokens/stability');
const AstroNeuralEconomicAmplifier = require('../src/tokens/anea'); // Assuming ANEA is in this file
jest.mock('../src/tokens/anea'); // Mock the ANEA class
describe('StabilityManager', () => {
let stabilityManager;
let aneaMock;
beforeEach(() => {
stabilityManager = new StabilityManager();
aneaMock = new AstroNeuralEconomicAmplifier();
stabilityManager.anea = aneaMock; // Use the mocked ANEA
});
test('should stabilize GTC when price is above target', async () => {
const currentPriceGTC = 315000; // Above target
await stabilityManager.stabilize(currentPriceGTC);
expect(aneaMock.amplifyLiquidity).toHaveBeenCalled(); // Check if ANEA was called
expect(stabilityManager.liquidityPool.usd).toBeLessThan(parseFloat(process.env.INITIAL_USD)); // USD should decrease
});
test('should stabilize GTC when price is below target', async () => {
const currentPriceGTC = 313000; // Below target
await stabilityManager.stabilize(currentPriceGTC);
expect(aneaMock.amplifyLiquidity).toHaveBeenCalled(); // Check if ANEA was called
expect(stabilityManager.liquidityPool.gtc).toBeGreaterThan(parseFloat(process.env.INITIAL_GTC)); // GTC should increase
});
test('should not adjust liquidity if no adjustment is needed', async () => {
const currentPriceGTC = stabilityManager.targetValueGTC; // At target
await stabilityManager.stabilize(currentPriceGTC);
expect(aneaMock.amplifyLiquidity).toHaveBeenCalled(); // Check if ANEA was called
expect(stabilityManager.liquidityPool.gtc).toBe(parseFloat(process.env.INITIAL_GTC)); // GTC should remain the same
expect(stabilityManager.liquidityPool.usd).toBe(parseFloat(process.env.INITIAL_USD)); // USD should remain the same
});
test('should log error when insufficient USD after adjustment', async () => {
stabilityManager.liquidityPool.usd = 0; // Set USD to 0 to trigger error
const currentPriceGTC = 315000; // Above target
await stabilityManager.stabilize(currentPriceGTC);
expect(stabilityManager.logger.error).toHaveBeenCalledWith(expect.stringContaining("Insufficient USD in liquidity pool after adjustment."));
});
test('should check current liquidity', async () => {
const liquidity = await stabilityManager.checkLiquidity();
expect(liquidity).toEqual({
gtc: parseFloat(process.env.INITIAL_GTC) || 1000000,
usd: parseFloat(process.env.INITIAL_USD) || 314159000000
});
});
test('should reset liquidity to initial values', async () => {
await stabilityManager.resetLiquidity();
expect(stabilityManager.liquidityPool.gtc).toBe(parseFloat(process.env.INITIAL_GTC) || 1000000);
expect(stabilityManager.liquidityPool.usd).toBe(parseFloat(process.env.INITIAL_USD) || 314159000000);
});
});