mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 18:41:38 +01:00
748801f417
* Adds 4byte registry fallback to getMethodData() (#6435) * Adds fetchWithCache to guard against unnecessary API calls * Add custom fetch wrapper with abort on timeout * Use opts and cacheRefreshTime in fetch-with-cache util * Use custom fetch wrapper with timeout for fetch-with-cache * Improve contract method data fetching (#6623) * Remove async call from getTransactionActionKey() * Stop blocking confirm screen rendering on method data loading, and base screen route on transactionCategory * Remove use of withMethodData, fix use of knownMethodData, in relation to transaction-list-item.component * Load data contract method data progressively, making it non-blocking; requires simplifying conf-tx-base lifecycle logic. * Allow editing of gas price while loading on the confirm screen. * Fix transactionAction component and its unit tests. * Fix confirm transaction components for cases of route transitions within metamask. * Only call toString on id if truthy in getNavigateTxData() * Fix knownMethodData retrieval and data fetching from fourbyte
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
import assert from 'assert'
|
|
import nock from 'nock'
|
|
|
|
import http from './fetch'
|
|
|
|
describe('custom fetch fn', () => {
|
|
it('fetches a url', async () => {
|
|
nock('https://api.infura.io')
|
|
.get('/money')
|
|
.reply(200, '{"hodl": false}')
|
|
|
|
const fetch = http()
|
|
const response = await (await fetch('https://api.infura.io/money')).json()
|
|
assert.deepEqual(response, {
|
|
hodl: false,
|
|
})
|
|
})
|
|
|
|
it('throws when the request hits a custom timeout', async () => {
|
|
nock('https://api.infura.io')
|
|
.get('/moon')
|
|
.delay(2000)
|
|
.reply(200, '{"moon": "2012-12-21T11:11:11Z"}')
|
|
|
|
const fetch = http({
|
|
timeout: 123,
|
|
})
|
|
|
|
try {
|
|
await fetch('https://api.infura.io/moon').then(r => r.json())
|
|
assert.fail('Request should throw')
|
|
} catch (e) {
|
|
assert.ok(e)
|
|
}
|
|
})
|
|
|
|
it('should abort the request when the custom timeout is hit', async () => {
|
|
nock('https://api.infura.io')
|
|
.get('/moon')
|
|
.delay(2000)
|
|
.reply(200, '{"moon": "2012-12-21T11:11:11Z"}')
|
|
|
|
const fetch = http({
|
|
timeout: 123,
|
|
})
|
|
|
|
try {
|
|
await fetch('https://api.infura.io/moon').then(r => r.json())
|
|
assert.fail('Request should be aborted')
|
|
} catch (e) {
|
|
assert.deepEqual(e.message, 'Aborted')
|
|
}
|
|
})
|
|
})
|