|
| 1 | +import { describe, it, expect } from '@jest/globals'; |
| 2 | +import { Wallet } from 'ethers'; |
| 3 | +import { getWeb3Provider } from '../../src/index.js'; |
| 4 | + |
| 5 | +describe('getWeb3Provider()', () => { |
| 6 | + const { privateKey, address } = Wallet.createRandom(); |
| 7 | + it('should use the wallet', async () => { |
| 8 | + const provider = getWeb3Provider(privateKey); |
| 9 | + const providerAddress = await provider.getAddress(); |
| 10 | + expect(providerAddress).toBe(address); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should use bellecour by default', async () => { |
| 14 | + const provider = getWeb3Provider(privateKey); |
| 15 | + const network = await provider.provider.getNetwork(); |
| 16 | + expect(network.name).toBe('bellecour'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should accept RPC URL as host', () => { |
| 20 | + expect( |
| 21 | + getWeb3Provider(privateKey, { host: 'https://bellecour.iex.ec' }) |
| 22 | + ).toBeDefined(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should accept chainId as host', () => { |
| 26 | + expect(getWeb3Provider(privateKey, { host: 134 })).toBeDefined(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should accept chain name as host', () => { |
| 30 | + expect(getWeb3Provider(privateKey, { host: 'bellecour' })).toBeDefined(); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('When instantiating SDK with an experimental network', () => { |
| 34 | + describe('Without allowExperimentalNetworks', () => { |
| 35 | + it('should throw a configuration error', () => { |
| 36 | + expect(() => |
| 37 | + getWeb3Provider(privateKey, { host: 'arbitrum-sepolia-testnet' }) |
| 38 | + ).toThrow('Invalid provider host name or url'); |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + describe('With allowExperimentalNetworks: true', () => { |
| 43 | + it('should use the specified network', async () => { |
| 44 | + const provider = getWeb3Provider(privateKey, { |
| 45 | + host: 'arbitrum-sepolia-testnet', |
| 46 | + allowExperimentalNetworks: true, |
| 47 | + }); |
| 48 | + const network = await provider.provider.getNetwork(); |
| 49 | + expect(network.name).toBe('arbitrum-sepolia'); |
| 50 | + }); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments