Skip to content

Commit

Permalink
updated readme + unit tests for rate-limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Sep 30, 2024
1 parent 7e61026 commit 35e6793
Show file tree
Hide file tree
Showing 15 changed files with 12,423 additions and 6,976 deletions.
6 changes: 5 additions & 1 deletion .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ runs:
shell: bash
- run: npm run lint
shell: bash
- run: npm test
- run: npm run test:unit
name: Unit Tests
shell: bash
- run: npm run test:integration
name: Miniflare Integration Tests
shell: bash
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
.mf
.env
.dev.vars
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,100 @@

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

## Running Locally

1. Install the project
```sh
npm i
```

2. CloudFlare Authentication
```sh
npx wrangler login
```

3. Get Your Account Id
```sh
npx wrangler whoami
```

4. Add your configs to `wrangler.toml`
```sh
[env.YOUR_USERNAME]
workers_dev = true
account_id = "YOUR_ACCOUNT_ID"
r2_buckets = [
{ binding = "CARPARK", bucket_name = "carpark-YOUR_USERNAME-0", preview_bucket_name = "carpark-YOUR_USERNAME-preview-0" }
]

[env.YOUR_USERNAME.vars]
DEBUG = "true"
FF_RATE_LIMITER_ENABLED = "false"
CONTENT_CLAIMS_SERVICE_URL = "https://dev.claims.web3.storage"
```
If you want to enable the Rate Limiter and KV add the following too:
```sh
[[env.YOUR_USERNAME.unsafe.bindings]]
name = "RATE_LIMITER"
type = "ratelimit"
namespace_id = "0"
simple = { limit = 100, period = 60 }

[[env.YOUR_USERNAME.kv_namespaces]]
binding = "AUTH_TOKEN_METADATA"
id = "YOUR_TOKEN" //FIXME how to obtain this token?
```
5. Start local server
```sh
npx wrangler dev -e YOUR_USERNAME
```
### Additional Tooling
*Kubo*: An IPFS implementation in Go
We are going to use it to save testing content and get valid CIDs.
```sh
docker pull ipfs/kubo:latest
docker run --rm -it --net=host ipfs/kubo:latest
```
Then add the sample content to get a valid CID for testing
```sh
echo "hello world" | ipfs add --cid-version=1
```
6. Sample Request
```sh
curl -XGET -i http://localhost
```
## Testing
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`).
Note:
- 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?
In order to run the existing tests you can execute the following commands:
**Miniflare Tests**
```sh
npm run test
```
**Unit Tests**
```sh
npm run test:unit
```
**Integration Tests**
```sh
TBD
```
## Contributing
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)!
Expand Down
13 changes: 13 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
},
"modules": false
}
]
]
}
12 changes: 12 additions & 0 deletions jest.unit.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"testMatch": ["**/test/unit/**/*.spec.js"],
"transform": {
"^.+\\.js$": "babel-jest"
},
"moduleFileExtensions": ["js"],
"globals": {
"ts-jest": {
"useESM": true
}
}
}
Loading

0 comments on commit 35e6793

Please sign in to comment.