|
1 | 1 | import { BigNumber, providers } from 'ethers'; |
2 | 2 | import { estimateGas, estimateGasByNetwork } from './gasStation'; |
| 3 | +import { ChainId } from './types'; |
3 | 4 |
|
4 | 5 | describe('gasStation', () => { |
5 | 6 | const provider: providers.Provider = new providers.JsonRpcProvider(); |
@@ -41,5 +42,33 @@ describe('gasStation', () => { |
41 | 42 | const gas = await estimateGasByNetwork(tx, provider, 10); |
42 | 43 | expect(gas).toEqual(BigNumber.from(110)); |
43 | 44 | }); |
| 45 | + it('Expects to return 350000 for zksync when connected with contract address', async () => { |
| 46 | + jest |
| 47 | + .spyOn(provider, 'getNetwork') |
| 48 | + .mockImplementationOnce(async () => |
| 49 | + Promise.resolve({ chainId: ChainId.zksync, name: 'zksync' }), |
| 50 | + ); |
| 51 | + |
| 52 | + jest |
| 53 | + .spyOn(provider, 'getCode') |
| 54 | + .mockImplementationOnce(async () => Promise.resolve('0x1234')); |
| 55 | + |
| 56 | + const gas = await estimateGasByNetwork({ from: '0x123abc' }, provider); |
| 57 | + expect(gas).toEqual(BigNumber.from(350000)); |
| 58 | + }); |
| 59 | + it('Expects to return default for zksync when connected with EOA', async () => { |
| 60 | + jest |
| 61 | + .spyOn(provider, 'getNetwork') |
| 62 | + .mockImplementationOnce(async () => |
| 63 | + Promise.resolve({ chainId: ChainId.zksync, name: 'zksync' }), |
| 64 | + ); |
| 65 | + |
| 66 | + jest |
| 67 | + .spyOn(provider, 'getCode') |
| 68 | + .mockImplementationOnce(async () => Promise.resolve('0x')); |
| 69 | + |
| 70 | + const gas = await estimateGasByNetwork({ from: '0x123abc' }, provider); |
| 71 | + expect(gas).toEqual(BigNumber.from(130)); |
| 72 | + }); |
44 | 73 | }); |
45 | 74 | }); |
0 commit comments