Skip to content

Commit

Permalink
test: verify function
Browse files Browse the repository at this point in the history
  • Loading branch information
bayological committed Jan 3, 2024
1 parent f2a51fd commit bc5a4eb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Contract, Wallet, constants, providers, utils } from 'ethers'
import {
getBrokerAddressFromRegistry,
getContractsByChainId,
getSymbolFromTokenAddress,
increaseAllowance,
} from './utils'
import contractAddresses from './contracts.json'

Check failure on line 8 in src/util.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18.x and ubuntu-latest

Cannot find module './contracts.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

jest.mock('ethers', () => {
return {
Expand Down Expand Up @@ -91,4 +93,23 @@ describe('Utils', () => {
expect(tx).toEqual(fakePopulatedTxObj)
})
})

describe('getContractsByChainId', () => {
it('should return contract addresses for a valid chainId', () => {
const validChainId = 42220
const expectedContracts = contractAddresses[validChainId]

const contracts = getContractsByChainId(validChainId)

expect(contracts).toEqual(expectedContracts)
})

it('should throw an error for a non-existent chainId', () => {
const invalidChainId = 99999

expect(() => {
getContractsByChainId(invalidChainId)
}).toThrow(`No contracts found for chainId ${invalidChainId}`)
})
})
})

0 comments on commit bc5a4eb

Please sign in to comment.