|
1 | | -import { addMulticallListeners, removeMulticallListeners, updateMulticallResults } from './actions' |
| 1 | +import { |
| 2 | + addMulticallListeners, |
| 3 | + errorFetchingMulticallResults, |
| 4 | + fetchingMulticallResults, |
| 5 | + removeMulticallListeners, |
| 6 | + updateMulticallResults |
| 7 | +} from './actions' |
2 | 8 | import reducer, { MulticallState } from './reducer' |
3 | 9 | import { Store, createStore } from '@reduxjs/toolkit' |
4 | 10 |
|
@@ -169,4 +175,89 @@ describe('multicall reducer', () => { |
169 | 175 | }) |
170 | 176 | }) |
171 | 177 | }) |
| 178 | + describe('fetchingMulticallResults', () => { |
| 179 | + it('updates state to fetching', () => { |
| 180 | + store.dispatch( |
| 181 | + fetchingMulticallResults({ |
| 182 | + chainId: 1, |
| 183 | + fetchingBlockNumber: 2, |
| 184 | + calls: [{ address: DAI_ADDRESS, callData: '0x0' }] |
| 185 | + }) |
| 186 | + ) |
| 187 | + expect(store.getState()).toEqual({ |
| 188 | + callResults: { |
| 189 | + [1]: { |
| 190 | + [`${DAI_ADDRESS}-0x0`]: { fetchingBlockNumber: 2 } |
| 191 | + } |
| 192 | + } |
| 193 | + }) |
| 194 | + }) |
| 195 | + }) |
| 196 | + |
| 197 | + describe('errorFetchingMulticallResults', () => { |
| 198 | + it('does nothing if not fetching', () => { |
| 199 | + store.dispatch( |
| 200 | + errorFetchingMulticallResults({ |
| 201 | + chainId: 1, |
| 202 | + fetchingBlockNumber: 1, |
| 203 | + calls: [{ address: DAI_ADDRESS, callData: '0x0' }] |
| 204 | + }) |
| 205 | + ) |
| 206 | + expect(store.getState()).toEqual({ |
| 207 | + callResults: { |
| 208 | + [1]: {} |
| 209 | + } |
| 210 | + }) |
| 211 | + }) |
| 212 | + it('updates block number if we were fetching', () => { |
| 213 | + store.dispatch( |
| 214 | + fetchingMulticallResults({ |
| 215 | + chainId: 1, |
| 216 | + fetchingBlockNumber: 2, |
| 217 | + calls: [{ address: DAI_ADDRESS, callData: '0x0' }] |
| 218 | + }) |
| 219 | + ) |
| 220 | + store.dispatch( |
| 221 | + errorFetchingMulticallResults({ |
| 222 | + chainId: 1, |
| 223 | + fetchingBlockNumber: 2, |
| 224 | + calls: [{ address: DAI_ADDRESS, callData: '0x0' }] |
| 225 | + }) |
| 226 | + ) |
| 227 | + expect(store.getState()).toEqual({ |
| 228 | + callResults: { |
| 229 | + [1]: { |
| 230 | + [`${DAI_ADDRESS}-0x0`]: { |
| 231 | + blockNumber: 2, |
| 232 | + // null data indicates error |
| 233 | + data: null |
| 234 | + } |
| 235 | + } |
| 236 | + } |
| 237 | + }) |
| 238 | + }) |
| 239 | + it('does nothing if not errored on latest block', () => { |
| 240 | + store.dispatch( |
| 241 | + fetchingMulticallResults({ |
| 242 | + chainId: 1, |
| 243 | + fetchingBlockNumber: 3, |
| 244 | + calls: [{ address: DAI_ADDRESS, callData: '0x0' }] |
| 245 | + }) |
| 246 | + ) |
| 247 | + store.dispatch( |
| 248 | + errorFetchingMulticallResults({ |
| 249 | + chainId: 1, |
| 250 | + fetchingBlockNumber: 2, |
| 251 | + calls: [{ address: DAI_ADDRESS, callData: '0x0' }] |
| 252 | + }) |
| 253 | + ) |
| 254 | + expect(store.getState()).toEqual({ |
| 255 | + callResults: { |
| 256 | + [1]: { |
| 257 | + [`${DAI_ADDRESS}-0x0`]: { fetchingBlockNumber: 3 } |
| 258 | + } |
| 259 | + } |
| 260 | + }) |
| 261 | + }) |
| 262 | + }) |
172 | 263 | }) |
0 commit comments