Skip to content

Commit 0cb41c4

Browse files
committed
updated readme + unit tests for rate-limiter
1 parent 7e61026 commit 0cb41c4

File tree

15 files changed

+12424
-6977
lines changed

15 files changed

+12424
-6977
lines changed

.github/actions/test/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ runs:
1313
shell: bash
1414
- run: npm run lint
1515
shell: bash
16-
- run: npm test
16+
- run: npm run test:unit
17+
name: Unit Tests
18+
shell: bash
19+
- run: npm run test
20+
name: Miniflare Integration Tests
1721
shell: bash

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
dist
33
.mf
44
.env
5+
.dev.vars

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,100 @@
1010

1111
![freeway overview diagram](./docs/freeway.png)
1212

13+
## Running Locally
14+
15+
1. Install the project
16+
```sh
17+
npm i
18+
```
19+
20+
2. CloudFlare Authentication
21+
```sh
22+
npx wrangler login
23+
```
24+
25+
3. Get Your Account Id
26+
```sh
27+
npx wrangler whoami
28+
```
29+
30+
4. Add your configs to `wrangler.toml`
31+
```sh
32+
[env.YOUR_USERNAME]
33+
workers_dev = true
34+
account_id = "YOUR_ACCOUNT_ID"
35+
r2_buckets = [
36+
{ binding = "CARPARK", bucket_name = "carpark-YOUR_USERNAME-0", preview_bucket_name = "carpark-YOUR_USERNAME-preview-0" }
37+
]
38+
39+
[env.YOUR_USERNAME.vars]
40+
DEBUG = "true"
41+
FF_RATE_LIMITER_ENABLED = "false"
42+
CONTENT_CLAIMS_SERVICE_URL = "https://dev.claims.web3.storage"
43+
```
44+
45+
If you want to enable the Rate Limiter and KV add the following too:
46+
```sh
47+
[[env.YOUR_USERNAME.unsafe.bindings]]
48+
name = "RATE_LIMITER"
49+
type = "ratelimit"
50+
namespace_id = "0"
51+
simple = { limit = 100, period = 60 }
52+
53+
[[env.YOUR_USERNAME.kv_namespaces]]
54+
binding = "AUTH_TOKEN_METADATA"
55+
id = "YOUR_TOKEN" //FIXME how to obtain this token?
56+
```
57+
58+
5. Start local server
59+
```sh
60+
npx wrangler dev -e YOUR_USERNAME
61+
```
62+
63+
### Additional Tooling
64+
65+
*Kubo*: An IPFS implementation in Go
66+
We are going to use it to save testing content and get valid CIDs.
67+
68+
```sh
69+
docker pull ipfs/kubo:latest
70+
docker run --rm -it --net=host ipfs/kubo:latest
71+
```
72+
73+
Then add the sample content to get a valid CID for testing
74+
```sh
75+
echo "hello world" | ipfs add --cid-version=1
76+
```
77+
78+
6. Sample Request
79+
```sh
80+
curl -XGET -i http://localhost
81+
```
82+
83+
## Testing
84+
85+
Freeway is using miniflare v3 for testing which allows you to define the testing configurations in the JavaScript code (see `src/test/index.spec.js`).
86+
87+
Note:
88+
- Miniflare v3 doesn't support the Rate Limiting bidding for now, so we need to mock the rate limiting API to be able to use it in tests and in local development?
89+
90+
In order to run the existing tests you can execute the following commands:
91+
92+
**Miniflare Tests**
93+
```sh
94+
npm run test
95+
```
96+
97+
**Unit Tests**
98+
```sh
99+
npm run test:unit
100+
```
101+
102+
**Integration Tests**
103+
```sh
104+
TBD
105+
```
106+
13107
## Contributing
14108
15109
Feel free to join in. All welcome. Please read our [contributing guidelines](https://github.com/web3-storage/freeway/blob/main/CONTRIBUTING.md) and/or [open an issue](https://github.com/web3-storage/freeway/issues)!

babel.config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
},
9+
"modules": false
10+
}
11+
]
12+
]
13+
}

jest.unit.config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"testMatch": ["**/test/unit/**/*.spec.js"],
3+
"transform": {
4+
"^.+\\.js$": "babel-jest"
5+
},
6+
"moduleFileExtensions": ["js"],
7+
"globals": {
8+
"ts-jest": {
9+
"useESM": true
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)