|
1 | 1 | import { expect } from 'chai'; |
| 2 | +import { BigNumber } from 'ethers'; |
| 3 | + |
| 4 | +import { calculateMultipliedBalance } from '../core/KeyFunder.js'; |
2 | 5 |
|
3 | 6 | import { |
4 | 7 | ChainConfigSchema, |
@@ -181,6 +184,60 @@ describe('KeyFunderConfig Schemas', () => { |
181 | 184 | const result = ChainConfigSchema.safeParse(config); |
182 | 185 | expect(result.success).to.be.false; |
183 | 186 | }); |
| 187 | + |
| 188 | + it('should reject balance without leading digit (.5)', () => { |
| 189 | + const config = { |
| 190 | + balances: { |
| 191 | + 'hyperlane-relayer': '.5', |
| 192 | + }, |
| 193 | + }; |
| 194 | + const result = ChainConfigSchema.safeParse(config); |
| 195 | + expect(result.success).to.be.false; |
| 196 | + }); |
| 197 | + |
| 198 | + it('should accept balance with leading zero (0.5)', () => { |
| 199 | + const config = { |
| 200 | + balances: { |
| 201 | + 'hyperlane-relayer': '0.5', |
| 202 | + }, |
| 203 | + }; |
| 204 | + const result = ChainConfigSchema.safeParse(config); |
| 205 | + expect(result.success).to.be.true; |
| 206 | + }); |
| 207 | + |
| 208 | + it('should accept high precision balances (up to 18 decimals)', () => { |
| 209 | + const config = { |
| 210 | + balances: { |
| 211 | + 'hyperlane-relayer': '0.000000000000000001', |
| 212 | + }, |
| 213 | + }; |
| 214 | + const result = ChainConfigSchema.safeParse(config); |
| 215 | + expect(result.success).to.be.true; |
| 216 | + }); |
| 217 | + }); |
| 218 | + |
| 219 | + describe('Multiplier precision (calculateMultipliedBalance)', () => { |
| 220 | + const oneEther = BigNumber.from('1000000000000000000'); |
| 221 | + |
| 222 | + it('should calculate 1.5x correctly (1 ETH * 1.5 = 1.5 ETH)', () => { |
| 223 | + const result = calculateMultipliedBalance(oneEther, 1.5); |
| 224 | + expect(result.toString()).to.equal('1500000000000000000'); |
| 225 | + }); |
| 226 | + |
| 227 | + it('should calculate 2.0x correctly (1 ETH * 2.0 = 2 ETH)', () => { |
| 228 | + const result = calculateMultipliedBalance(oneEther, 2.0); |
| 229 | + expect(result.toString()).to.equal('2000000000000000000'); |
| 230 | + }); |
| 231 | + |
| 232 | + it('should floor third decimal (1 ETH * 1.555 = 1.55 ETH, not 1.56 ETH)', () => { |
| 233 | + const result = calculateMultipliedBalance(oneEther, 1.555); |
| 234 | + expect(result.toString()).to.equal('1550000000000000000'); |
| 235 | + }); |
| 236 | + |
| 237 | + it('should floor (1 ETH * 1.999 = 1.99 ETH, not 2 ETH)', () => { |
| 238 | + const result = calculateMultipliedBalance(oneEther, 1.999); |
| 239 | + expect(result.toString()).to.equal('1990000000000000000'); |
| 240 | + }); |
184 | 241 | }); |
185 | 242 |
|
186 | 243 | describe('KeyFunderConfigSchema', () => { |
|
0 commit comments