Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schmanu committed Feb 21, 2024
1 parent b46ce3d commit fedbbef
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/hooks/__tests__/useAmounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const createMockVesting = (
amount: parseEther(amount.toString()).toString(),
curve: 0,
durationWeeks,
chainId: 4,
chainId: 11155111,
contract: hexZeroPad('0x2', 20),
tag: 'user',
startDate: Math.floor(fakeNow.getTime() / 1000) - DESYNC_BUFFER + ONE_WEEK * vestingStartDiffInWeeks,
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/__tests__/useContractDelegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('_getContractDelegate()', () => {
() =>
({
_isSigner: true,
getChainId: jest.fn(() => Promise.resolve(5)),
getChainId: jest.fn(() => Promise.resolve(11155111)),
getAddress: jest.fn(() => Promise.resolve(SAFE_ADDRESS)),
call: mockCall,
} as unknown as JsonRpcSigner),
Expand All @@ -42,7 +42,7 @@ describe('_getContractDelegate()', () => {
})

it('ignore the ZERO_ADDRESS as delegate', async () => {
const delegateIDInBytes = formatBytes32String(CHAIN_DELEGATE_ID['5'])
const delegateIDInBytes = formatBytes32String(CHAIN_DELEGATE_ID['11155111'])

mockCall.mockImplementation((transaction) => {
expect(transaction.to?.toString().toLowerCase()).toEqual(DELEGATE_REGISTRY_ADDRESS.toLowerCase())
Expand All @@ -54,14 +54,14 @@ describe('_getContractDelegate()', () => {
return Promise.resolve(hexZeroPad(ZERO_ADDRESS, 32))
})

const result = await _getContractDelegate('5', SAFE_ADDRESS, web3Provider)
const result = await _getContractDelegate('11155111', SAFE_ADDRESS, web3Provider)

expect(mockCall).toBeCalledTimes(1)
expect(result).toBe(null)
})

it('should encode the correct data and fetch the delegate on-chain once', async () => {
const delegateIDInBytes = formatBytes32String(CHAIN_DELEGATE_ID['5'])
const delegateIDInBytes = formatBytes32String(CHAIN_DELEGATE_ID['11155111'])

const delegateAddress = hexZeroPad('0x1', 20)

Expand All @@ -75,7 +75,7 @@ describe('_getContractDelegate()', () => {
return Promise.resolve(hexZeroPad(delegateAddress, 32))
})

const result = await _getContractDelegate('5', SAFE_ADDRESS, web3Provider)
const result = await _getContractDelegate('11155111', SAFE_ADDRESS, web3Provider)

expect(mockCall).toBeCalledTimes(1)
expect(result).toEqual({ address: delegateAddress, ens: 'test.eth' })
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/__tests__/useEnsResolution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ describe('useEnsResolution()', () => {
})

it('should accept EIP-3770 addresses with correct chain prefix', async () => {
const prefixedAddress = 'gor:0x1000000000000000000000000000000000000000'
const prefixedAddress = 'sep:0x1000000000000000000000000000000000000000'

web3Provider.resolveName = jest.fn()
jest.spyOn(useWeb3, 'useWeb3').mockImplementation(() => web3Provider)

jest.spyOn(useChain, 'useChain').mockImplementation(() => ({ chainId: '5', shortName: 'gor' } as ChainInfo))
jest.spyOn(useChain, 'useChain').mockImplementation(() => ({ chainId: '11155111', shortName: 'sep' } as ChainInfo))

jest.useFakeTimers()

Expand All @@ -95,14 +95,14 @@ describe('useEnsResolution()', () => {
web3Provider.resolveName = jest.fn()
jest.spyOn(useWeb3, 'useWeb3').mockImplementation(() => web3Provider)

jest.spyOn(useChain, 'useChain').mockImplementation(() => ({ chainId: '5', shortName: 'gor' } as ChainInfo))
jest.spyOn(useChain, 'useChain').mockImplementation(() => ({ chainId: '11155111', shortName: 'sep' } as ChainInfo))

jest.useFakeTimers()

const { result } = renderHook(() => useEnsResolution(prefixedAddress))

expect(result.current[0]).toBeUndefined()
expect(result.current[1]).toEqual('The chain prefix does not match that of the current chain (gor)')
expect(result.current[1]).toEqual('The chain prefix does not match that of the current chain (sep)')
expect(result.current[2]).toBeFalsy()
expect(web3Provider.resolveName).not.toHaveBeenCalled()

Expand Down
8 changes: 4 additions & 4 deletions src/hooks/__tests__/useIsTokenPaused.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('_getIsTokenPaused', () => {
it('should return true on error', async () => {
mockCall.mockImplementation(() => Promise.reject())

const result = await _getIsTokenPaused('5', web3Provider)
const result = await _getIsTokenPaused('11155111', web3Provider)

expect(result).toBeTruthy()
expect(mockCall).toBeCalledTimes(1)
Expand All @@ -27,7 +27,7 @@ describe('_getIsTokenPaused', () => {
it('should return true if token is paused', async () => {
mockCall.mockImplementation(async () => Promise.resolve(safeTokenInterface.encodeFunctionResult('paused', [true])))

const result = await _getIsTokenPaused('5', web3Provider)
const result = await _getIsTokenPaused('11155111', web3Provider)

expect(result).toBeTruthy()
expect(mockCall).toBeCalledTimes(1)
Expand All @@ -36,14 +36,14 @@ describe('_getIsTokenPaused', () => {
it('should return false if token is unpaused', async () => {
mockCall.mockImplementation(async () => Promise.resolve(safeTokenInterface.encodeFunctionResult('paused', [false])))

const result = await _getIsTokenPaused('5', web3Provider)
const result = await _getIsTokenPaused('11155111', web3Provider)

expect(result).toBeFalsy()
expect(mockCall).toBeCalledTimes(1)
})

it('returns null if no provider is defined', async () => {
const result = await _getIsTokenPaused('5', undefined)
const result = await _getIsTokenPaused('11155111', undefined)

expect(result).toBe(null)
})
Expand Down
20 changes: 15 additions & 5 deletions src/hooks/__tests__/useSafeTokenAllocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,12 @@ describe('useSafeTokenAllocation', () => {
return Promise.resolve('0x')
})

const result = await _getVotingPower({ chainId: '5', address: SAFE_ADDRESS, web3: web3Provider, vestingData: [] })
const result = await _getVotingPower({
chainId: '11155111',
address: SAFE_ADDRESS,
web3: web3Provider,
vestingData: [],
})
expect(result?.toNumber()).toEqual(0)
})

Expand All @@ -255,7 +260,12 @@ describe('useSafeTokenAllocation', () => {
return Promise.resolve('0x')
})

const result = await _getVotingPower({ chainId: '5', address: SAFE_ADDRESS, web3: web3Provider, vestingData: [] })
const result = await _getVotingPower({
chainId: '11155111',
address: SAFE_ADDRESS,
web3: web3Provider,
vestingData: [],
})
expect(result?.eq(parseEther('100'))).toBeTruthy()
})

Expand Down Expand Up @@ -289,7 +299,7 @@ describe('useSafeTokenAllocation', () => {
})

const result = await _getVotingPower({
chainId: '5',
chainId: '11155111',
address: SAFE_ADDRESS,
web3: web3Provider,
vestingData: mockVestings,
Expand Down Expand Up @@ -327,7 +337,7 @@ describe('useSafeTokenAllocation', () => {
})

const result = await _getVotingPower({
chainId: '5',
chainId: '11155111',
address: SAFE_ADDRESS,
web3: web3Provider,
vestingData: mockAllocation,
Expand Down Expand Up @@ -365,7 +375,7 @@ describe('useSafeTokenAllocation', () => {
})

const result = await _getVotingPower({
chainId: '5',
chainId: '11155111',
address: SAFE_ADDRESS,
web3: web3Provider,
vestingData: mockAllocation,
Expand Down
12 changes: 6 additions & 6 deletions src/utils/__tests__/claim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('createClaimTxs', () => {
account: safeAddress,
amount: parseEther('100').toString(),
amountClaimed: '0',
chainId: 5,
chainId: 11155111,
contract: mockUserAirdropAddress,
curve: 0,
durationWeeks: 416,
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('createClaimTxs', () => {
account: safeAddress,
amount: parseEther('200').toString(),
amountClaimed: '0',
chainId: 5,
chainId: 11155111,
contract: mockSep5AirdropAddress,
curve: 0,
durationWeeks: 416,
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('createClaimTxs', () => {
account: safeAddress,
amount: parseEther('100').toString(),
amountClaimed: '0',
chainId: 5,
chainId: 11155111,
contract: mockUserAirdropAddress,
curve: 0,
durationWeeks: 416,
Expand All @@ -147,7 +147,7 @@ describe('createClaimTxs', () => {
account: safeAddress,
amount: parseEther('50').toString(),
amountClaimed: '0',
chainId: 5,
chainId: 11155111,
contract: mockSep5AirdropAddress,
curve: 0,
durationWeeks: 416,
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('createClaimTxs', () => {
account: safeAddress,
amount: parseEther('100').toString(),
amountClaimed: '0',
chainId: 5,
chainId: 11155111,
contract: mockInvestorVestingAddress,
curve: 0,
durationWeeks: 416,
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('createClaimTxs', () => {
account: safeAddress,
amount: parseEther('100').toString(),
amountClaimed: '0',
chainId: 5,
chainId: 11155111,
contract: mockInvestorVestingAddress,
curve: 0,
durationWeeks: 416,
Expand Down

0 comments on commit fedbbef

Please sign in to comment.