-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:rainbow-me/rainbow into @bruno/p…
…ublish-artifacts
- Loading branch information
Showing
7 changed files
with
343 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { Address } from 'viem'; | ||
|
||
import { staleBalancesStore } from '.'; | ||
import { DAI_ADDRESS, OP_ADDRESS } from '@/references'; | ||
import { ETH_ADDRESS } from '@rainbow-me/swaps'; | ||
import { ChainId } from '@/networks/types'; | ||
|
||
const TEST_ADDRESS_1 = '0xFOO'; | ||
const TEST_ADDRESS_2 = '0xBAR'; | ||
const THEN = Date.now() - 700000; | ||
const WHEN = Date.now() + 60000; | ||
|
||
test('should be able to add asset information to the staleBalances object', async () => { | ||
const { addStaleBalance, staleBalances } = staleBalancesStore.getState(); | ||
expect(staleBalances).toStrictEqual({}); | ||
addStaleBalance({ | ||
address: TEST_ADDRESS_1, | ||
chainId: ChainId.mainnet, | ||
info: { | ||
address: DAI_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: THEN, | ||
}, | ||
}); | ||
addStaleBalance({ | ||
address: TEST_ADDRESS_1, | ||
chainId: ChainId.mainnet, | ||
info: { | ||
address: ETH_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: WHEN, | ||
}, | ||
}); | ||
const newStaleBalances = staleBalancesStore.getState().staleBalances; | ||
expect(newStaleBalances).toStrictEqual({ | ||
[TEST_ADDRESS_1]: { | ||
[ChainId.mainnet]: { | ||
[DAI_ADDRESS]: { | ||
address: DAI_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: THEN, | ||
}, | ||
[ETH_ADDRESS]: { | ||
address: ETH_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: WHEN, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test('should generate accurate stale balance query params and clear expired data - case #1', async () => { | ||
const { getStaleBalancesQueryParam, clearExpiredData } = staleBalancesStore.getState(); | ||
clearExpiredData(TEST_ADDRESS_1); | ||
const queryParam = getStaleBalancesQueryParam(TEST_ADDRESS_1); | ||
expect(queryParam).toStrictEqual(`&token=${ChainId.mainnet}.${ETH_ADDRESS}`); | ||
}); | ||
|
||
test('should be able to remove expired stale balance and preserve unexpired data', async () => { | ||
const { addStaleBalance, clearExpiredData } = staleBalancesStore.getState(); | ||
addStaleBalance({ | ||
address: TEST_ADDRESS_1, | ||
chainId: ChainId.mainnet, | ||
info: { | ||
address: DAI_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: THEN, | ||
}, | ||
}); | ||
addStaleBalance({ | ||
address: TEST_ADDRESS_1, | ||
chainId: ChainId.mainnet, | ||
info: { | ||
address: ETH_ADDRESS as Address, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: WHEN, | ||
}, | ||
}); | ||
clearExpiredData(TEST_ADDRESS_1); | ||
const newStaleBalances = staleBalancesStore.getState().staleBalances; | ||
expect(newStaleBalances).toStrictEqual({ | ||
[TEST_ADDRESS_1]: { | ||
[ChainId.mainnet]: { | ||
[ETH_ADDRESS]: { | ||
address: ETH_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: WHEN, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test('should preserve data from other addresses when clearing expired data', async () => { | ||
const { addStaleBalance, clearExpiredData } = staleBalancesStore.getState(); | ||
addStaleBalance({ | ||
address: TEST_ADDRESS_1, | ||
chainId: ChainId.mainnet, | ||
info: { | ||
address: DAI_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: THEN, | ||
}, | ||
}); | ||
addStaleBalance({ | ||
address: TEST_ADDRESS_2, | ||
chainId: ChainId.mainnet, | ||
info: { | ||
address: ETH_ADDRESS as Address, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: WHEN, | ||
}, | ||
}); | ||
clearExpiredData(TEST_ADDRESS_1); | ||
const newStaleBalances = staleBalancesStore.getState().staleBalances; | ||
expect(newStaleBalances).toStrictEqual({ | ||
[TEST_ADDRESS_1]: { | ||
[ChainId.mainnet]: { | ||
[ETH_ADDRESS]: { | ||
address: ETH_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: WHEN, | ||
}, | ||
}, | ||
}, | ||
[TEST_ADDRESS_2]: { | ||
[ChainId.mainnet]: { | ||
[ETH_ADDRESS]: { | ||
address: ETH_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: WHEN, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test('should generate accurate stale balance query params and clear expired data - case #2', async () => { | ||
const { getStaleBalancesQueryParam, clearExpiredData } = staleBalancesStore.getState(); | ||
clearExpiredData(TEST_ADDRESS_2); | ||
const queryParam = getStaleBalancesQueryParam(TEST_ADDRESS_2); | ||
expect(queryParam).toStrictEqual(`&token=${ChainId.mainnet}.${ETH_ADDRESS}`); | ||
}); | ||
|
||
test('should generate accurate stale balance query params and clear expired data - case #3', async () => { | ||
const { addStaleBalance, getStaleBalancesQueryParam, clearExpiredData } = staleBalancesStore.getState(); | ||
addStaleBalance({ | ||
address: TEST_ADDRESS_1, | ||
chainId: ChainId.optimism, | ||
info: { | ||
address: OP_ADDRESS, | ||
transactionHash: '0xFOOBAR', | ||
expirationTime: WHEN, | ||
}, | ||
}); | ||
|
||
clearExpiredData(TEST_ADDRESS_1); | ||
const queryParam = getStaleBalancesQueryParam(TEST_ADDRESS_1); | ||
expect(queryParam).toStrictEqual(`&token=${ChainId.mainnet}.${ETH_ADDRESS}&token=${ChainId.optimism}.${OP_ADDRESS}`); | ||
|
||
clearExpiredData(TEST_ADDRESS_2); | ||
const queryParam2 = getStaleBalancesQueryParam(TEST_ADDRESS_2); | ||
expect(queryParam2).toStrictEqual(`&token=${ChainId.mainnet}.${ETH_ADDRESS}`); | ||
}); |
Oops, something went wrong.