Skip to content

Commit ca33bb6

Browse files
committed
test: cached fetch
1 parent 93c23a7 commit ca33bb6

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ typings/
3636
# Optional eslint cache
3737
.eslintcache
3838

39+
# General cache (e.g. by node-fetch-cache
40+
.cache
41+
3942
# Optional REPL history
4043
.node_repl_history
4144

packages/boot/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"author": "Agoric",
2121
"license": "Apache-2.0",
2222
"dependencies": {
23-
"@endo/errors": "^1.2.9",
2423
"@agoric/builders": "^0.1.0",
2524
"@agoric/client-utils": "^0.1.0",
2625
"@agoric/cosmic-proto": "^0.4.0",
@@ -45,6 +44,7 @@
4544
"@agoric/zone": "^0.2.2",
4645
"@endo/bundle-source": "^3.5.1",
4746
"@endo/captp": "^4.4.4",
47+
"@endo/errors": "^1.2.9",
4848
"@endo/eventual-send": "^1.3.0",
4949
"@endo/far": "^1.1.10",
5050
"@endo/init": "^1.1.8",
@@ -62,6 +62,7 @@
6262
"@endo/patterns": "^1.4.8",
6363
"ava": "^5.3.0",
6464
"c8": "^10.1.2",
65+
"node-fetch-cache": "^4.1.2",
6566
"ts-blank-space": "^0.4.4"
6667
},
6768
"files": [

packages/boot/test/fast-usdc/fast-usdc.test.ts

+9-15
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import type { EndoZipBase64Bundle } from '@agoric/swingset-vat';
1616
import { makeRatio } from '@agoric/zoe/src/contractSupport/ratio.js';
1717
import { Fail } from '@endo/errors';
1818
import { makeMarshal } from '@endo/marshal';
19-
import { readFile } from 'node:fs/promises';
20-
import { createRequire } from 'node:module';
19+
import NodeFetchCache, { FileSystemCache } from 'node-fetch-cache';
2120
import {
2221
AckBehavior,
2322
insistManagerType,
@@ -28,7 +27,12 @@ import {
2827
type WalletFactoryTestContext,
2928
} from '../bootstrapTests/walletFactory.js';
3029

31-
const nodeRequire = createRequire(import.meta.url);
30+
// Releases are immutable, so we can cache them.
31+
// Doesn't help in CI but speeds up local development.
32+
// CI is on Github Actions, so fetching is reliable.
33+
const fetchCached = NodeFetchCache.create({
34+
cache: new FileSystemCache(),
35+
}) as unknown as typeof globalThis.fetch;
3236

3337
const test: TestFn<
3438
WalletFactoryTestContext & {
@@ -70,7 +74,7 @@ test.serial('oracles provision before contract deployment', async t => {
7074
});
7175

7276
const downloadCoreEval = async (
73-
{ fetch = globalThis.fetch } = {},
77+
{ fetch }: { fetch: typeof globalThis.fetch },
7478
config = {
7579
repo: 'Agoric/agoric-sdk',
7680
release: 'fast-usdc-beta-1',
@@ -111,18 +115,8 @@ const downloadCoreEval = async (
111115
test.serial('prop 87: Beta', async t => {
112116
const { evalProposal, bridgeUtils } = t.context;
113117

114-
const fetchFixture = async url => {
115-
const basename = url.split('/').at(-1);
116-
const cachePath = nodeRequire.resolve(`./bundles/${basename}`);
117-
t.log('load', url, 'from', cachePath);
118-
const txt = await readFile(cachePath, 'utf-8');
119-
return {
120-
text: async () => txt,
121-
json: async () => JSON.parse(txt),
122-
};
123-
};
124118
const materials = await downloadCoreEval({
125-
fetch: fetchFixture as unknown as typeof fetch,
119+
fetch: fetchCached,
126120
});
127121

128122
// Proposal 87 doesn't quite complete: noble ICA is mis-configured

yarn.lock

+51-2
Original file line numberDiff line numberDiff line change
@@ -3608,6 +3608,14 @@
36083608
dependencies:
36093609
"@types/node" "*"
36103610

3611+
3612+
version "2.6.11"
3613+
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.11.tgz#9b39b78665dae0e82a08f02f4967d62c66f95d24"
3614+
integrity sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==
3615+
dependencies:
3616+
"@types/node" "*"
3617+
form-data "^4.0.0"
3618+
36113619
"@types/node@*", "@types/node@>=13.7.0", "@types/node@^22.9.0":
36123620
version "22.9.0"
36133621
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.9.0.tgz#b7f16e5c3384788542c72dc3d561a7ceae2c0365"
@@ -4623,6 +4631,24 @@ cacache@^17.0.0:
46234631
tar "^6.1.11"
46244632
unique-filename "^3.0.0"
46254633

4634+
cacache@^18.0.1:
4635+
version "18.0.4"
4636+
resolved "https://registry.yarnpkg.com/cacache/-/cacache-18.0.4.tgz#4601d7578dadb59c66044e157d02a3314682d6a5"
4637+
integrity sha512-B+L5iIa9mgcjLbliir2th36yEwPftrzteHYujzsx3dFP/31GCHcIeS8f5MGd80odLOjaOvSpU3EEAmRQptkxLQ==
4638+
dependencies:
4639+
"@npmcli/fs" "^3.1.0"
4640+
fs-minipass "^3.0.0"
4641+
glob "^10.2.2"
4642+
lru-cache "^10.0.1"
4643+
minipass "^7.0.3"
4644+
minipass-collect "^2.0.1"
4645+
minipass-flush "^1.0.5"
4646+
minipass-pipeline "^1.2.4"
4647+
p-map "^4.0.0"
4648+
ssri "^10.0.0"
4649+
tar "^6.1.11"
4650+
unique-filename "^3.0.0"
4651+
46264652
call-bind-apply-helpers@^1.0.0, call-bind-apply-helpers@^1.0.1:
46274653
version "1.0.1"
46284654
resolved "https://registry.yarnpkg.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.1.tgz#32e5892e6361b29b0b545ba6f7763378daca2840"
@@ -8370,6 +8396,11 @@ locate-path@^7.1.0:
83708396
dependencies:
83718397
p-locate "^6.0.0"
83728398

8399+
locko@^1.1.0:
8400+
version "1.1.0"
8401+
resolved "https://registry.yarnpkg.com/locko/-/locko-1.1.0.tgz#43930d87a0d25f20c8d2974c3c4613e50a2978a9"
8402+
integrity sha512-pYB2dzRY93fJkg2RIl41AMNgTQftEjyTK9vlPrGOJvuGQsOjb267VJBw15BjiN3RBd1oBoKkOu9E2dRdFKIfAA==
8403+
83738404
[email protected], lodash.camelcase@^4.3.0:
83748405
version "4.3.0"
83758406
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
@@ -8440,7 +8471,7 @@ long@*, long@^5.0.0, long@^5.2.0, long@^5.2.1:
84408471
resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1"
84418472
integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==
84428473

8443-
lru-cache@^10.2.0:
8474+
lru-cache@^10.0.1, lru-cache@^10.2.0:
84448475
version "10.4.3"
84458476
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119"
84468477
integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==
@@ -9060,6 +9091,13 @@ minipass-collect@^1.0.2:
90609091
dependencies:
90619092
minipass "^3.0.0"
90629093

9094+
minipass-collect@^2.0.1:
9095+
version "2.0.1"
9096+
resolved "https://registry.yarnpkg.com/minipass-collect/-/minipass-collect-2.0.1.tgz#1621bc77e12258a12c60d34e2276ec5c20680863"
9097+
integrity sha512-D7V8PO9oaz7PWGLbCACuI1qEOsq7UKfLotx/C0Aet43fCUB/wfQ7DYeq2oR/svFJGYDHPr38SHATeaj/ZoKHKw==
9098+
dependencies:
9099+
minipass "^7.0.3"
9100+
90639101
minipass-fetch@^2.0.3:
90649102
version "2.1.2"
90659103
resolved "https://registry.yarnpkg.com/minipass-fetch/-/minipass-fetch-2.1.2.tgz#95560b50c472d81a3bc76f20ede80eaed76d8add"
@@ -9300,7 +9338,18 @@ node-addon-api@^5.0.0:
93009338
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-5.0.0.tgz#7d7e6f9ef89043befdb20c1989c905ebde18c501"
93019339
integrity sha512-CvkDw2OEnme7ybCykJpVcKH+uAOLV2qLqiyla128dN9TkEWfrYmxG6C2boDe5KcNQqZF3orkqzGgOMvZ/JNekA==
93029340

9303-
node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.7, node-fetch@^2.6.9, node-fetch@^2.7.0:
9341+
node-fetch-cache@^4.1.2:
9342+
version "4.1.2"
9343+
resolved "https://registry.yarnpkg.com/node-fetch-cache/-/node-fetch-cache-4.1.2.tgz#4fdbd152c80ec5de76749076a1c4bb16510af8ee"
9344+
integrity sha512-pcdJlxXE/fT0wcCY13RJUAyZeMKW4altG7P1GKLn1d4z1nLzM9Ua0ZIBiZUp90ppI/UqenZ+8UKWq+cKBk1fFA==
9345+
dependencies:
9346+
"@types/node-fetch" "2.6.11"
9347+
cacache "^18.0.1"
9348+
form-data "^4.0.0"
9349+
locko "^1.1.0"
9350+
node-fetch "2.7.0"
9351+
9352+
[email protected], node-fetch@^2.6.1, node-fetch@^2.6.12, node-fetch@^2.6.7, node-fetch@^2.6.9, node-fetch@^2.7.0:
93049353
version "2.7.0"
93059354
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
93069355
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==

0 commit comments

Comments
 (0)