Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(tests): fix tests and ci workflows #163

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
root = true
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
correct editorconfig 🍆


[*]
charset = utf-8
end_of_line = lf

[*.{js,jsx,mjs,ejs,yml,json,cpp,cc,h,html,md,sh,sql}]
indent_style = space
indent_size = 2
91 changes: 91 additions & 0 deletions .github/workflows/docker-build-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Docker build & push image
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be needed in a forthcoming PR for doing E2E testing in ephemeral CI instances.

The reason being it will be much easier to track regressions and also we need the container env anyway for network tests.


on:
push:
branches: [v4]
tags: ["v*"]
pull_request:
branches: [v4]
paths:
- .github/workflows/docker-build-push.yaml
- kiwistand/**
workflow_dispatch:

jobs:
build:
if: ${{ github.repository == 'attestate/kiwistand' }} # Comment this out if you want to publish your own images on a fork!
runs-on: ubuntu-latest
steps:
- name: Set lowercase repository owner environment variable
run: |
echo "OWNER_LOWERCASE=${OWNER,,}" >> ${GITHUB_ENV}
env:
OWNER: "${{ github.repository_owner }}"

- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
driver-opts: |
image=moby/buildkit:master
network=host

- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/[email protected]
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata tags and labels on PRs
if: github.event_name == 'pull_request'
id: meta-pr
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.OWNER_LOWERCASE }}/kiwistand
tags: |
type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }}
labels: |
org.opencontainers.image.source="https://github.com/${{ github.repository_owner }}/kiwistand"
- name: Extract metadata tags and labels for main, release or tag
if: github.event_name != 'pull_request'
id: meta
uses: docker/metadata-action@v5
with:
flavor: |
latest=auto
images: ghcr.io/${{ env.OWNER_LOWERCASE }}/kiwistand
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=raw,value=sha-${{ env.GITHUB_SHA_SHORT }}
labels: |
maintainer=${{ github.repository_owner }}
org.opencontainers.image.source="https://github.com/${{ github.repository_owner }}/kiwistand"

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
push: ${{ github.event_name != 'pull_request' }}
build-args: |
GIT_SHA=${{ env.GITHUB_SHA }}
DOCKER_LABEL=sha-${{ env.GITHUB_SHA_SHORT }}
tags: ${{ steps.meta.outputs.tags || steps.meta-pr.outputs.tags }}
labels: ${{ steps.meta.outputs.labels || steps.meta-pr.outputs.labels }}
cache-from: type=gha
cache-to: type=gha
8 changes: 8 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-

- run: npm ci
- run: npm run test
env:
HTTP_MESSAGES_MAX_PAGE_SIZE: "500"

15 changes: 15 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"checkJs": true,
"target": "ES2022",
"allowImportingTsExtensions": true,
"strictNullChecks": true,
"strictFunctionTypes": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}
Comment on lines +1 to +15
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev:
This gives typechecking in VSCode Studio (it uses the typescript typechecker).

10 changes: 4 additions & 6 deletions test/store_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ test("trying to add message to store that isn't on allowlist", async (t) => {
});

test("adding message from too far into the future", async (t) => {
env.MAX_TIMESTAMP_DELTA_SECS = 60;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes:

Type 'number' is not assignable to type 'string'

env.MAX_TIMESTAMP_DELTA_SECS = "60";
const address = "0x0f6A79A579658E401E0B81c6dde1F2cd51d97176";
const privateKey =
"0xad54bdeade5537fb0a553190159783e45d02d316a992db05cbed606d3ca36b39";
Expand All @@ -1232,7 +1232,7 @@ test("adding message from too far into the future", async (t) => {
const text = "hello world";
const href = "https://example.com";
const type = "amplify";
const timestamp = Math.floor(Date.now() / 1000) + 61;
const timestamp = (Math.floor(Date.now() / 1000) + 61).toString();
const message = id.create(text, href, type, timestamp);
const signedMessage = await id.sign(signer, message, EIP712_MESSAGE);

Expand Down Expand Up @@ -1275,7 +1275,6 @@ test("adding message from too far into the future", async (t) => {
),
);
});

test("adding message from before minimum timestamp", async (t) => {
const address = "0x0f6A79A579658E401E0B81c6dde1F2cd51d97176";
const privateKey =
Expand All @@ -1286,7 +1285,7 @@ test("adding message from before minimum timestamp", async (t) => {
const text = "hello world";
const href = "https://example.com";
const type = "amplify";
const timestamp = 0;
const timestamp = "0";
const message = id.create(text, href, type, timestamp);
const signedMessage = await id.sign(signer, message, EIP712_MESSAGE);

Expand Down Expand Up @@ -1317,7 +1316,7 @@ test("adding message from before minimum timestamp", async (t) => {
},
},
};
env.MIN_TIMESTAMP_SECS = 1;
env.MIN_TIMESTAMP_SECS = "1";
await t.throwsAsync(
async () =>
await store.add(
Expand All @@ -1330,7 +1329,6 @@ test("adding message from before minimum timestamp", async (t) => {
),
);
});

test.serial("adding a comment to the store with missing parent", async (t) => {
store.upvotes.clear();
t.plan(2);
Expand Down
10 changes: 4 additions & 6 deletions test/topics/messages_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ test.serial("adding valid message to trie", async (t) => {
process.env.DATA_DIR = "dbtestA";
const trie = await store.create();
const emptyRoot = trie.root();
const allowlistFn = () => new Set([address]);
const allowlistFn = async () => new Set([address]);
const result = await handlers.message(trie, allowlistFn)(evt);
t.true(result);
await rm("dbtestA", { recursive: true });
});

test.serial(
"adding valid message to trie with the signer being a delegated address",
async (t) => {
Expand Down Expand Up @@ -144,8 +143,8 @@ test.serial(
const emptyRoot = trie.root();

const custodian = "0xee324c588ceF1BF1c1360883E4318834af66366d";
const allowlistFn = () => new Set([custodian]);
const delegationsFn = () => ({
const allowlistFn = async () => new Set([custodian]);
const delegationsFn = async () => ({
[address]: custodian,
});
const result = await handlers.message(
Expand All @@ -155,5 +154,4 @@ test.serial(
)(evt);
t.true(result);
await rm("dbtestA", { recursive: true });
},
);
},);