Skip to content

Commit

Permalink
Merge branch 'master' into tim/remove-server-gating-flag
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/commonwealth/scripts/refresh-all-memberships.ts
#	packages/commonwealth/server-test.ts
#	packages/commonwealth/server/controllers/server_comments_controller.ts
#	packages/commonwealth/server/controllers/server_threads_controller.ts
#	packages/commonwealth/server/routing/external.ts
#	packages/commonwealth/server/routing/router.ts
#	packages/commonwealth/server/util/requirementsModule/validateTopicGroupsMembership.ts
#	packages/commonwealth/test/integration/api/linking.spec.ts
#	packages/commonwealth/test/integration/api/polls.spec.ts
#	packages/commonwealth/test/integration/api/subscriptions.spec.ts
#	packages/commonwealth/test/integration/api/thread.update.spec.ts
#	packages/commonwealth/test/integration/api/userDashboard.spec.ts
#	packages/commonwealth/test/unit/server_controllers/server_comments_controller.spec.ts
#	packages/commonwealth/test/unit/server_controllers/server_groups_controller.spec.ts
#	packages/commonwealth/test/unit/server_controllers/server_threads_controller.spec.ts
#	packages/commonwealth/test/util/modelUtils.ts
  • Loading branch information
timolegros committed Jan 5, 2024
2 parents b005d45 + b922412 commit c8d6a0e
Show file tree
Hide file tree
Showing 538 changed files with 5,172 additions and 18,986 deletions.
55 changes: 14 additions & 41 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

- name: Cache browsers
id: playwright-cache
Expand Down Expand Up @@ -154,14 +148,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

- name: Cache browsers
id: playwright-cache
Expand Down Expand Up @@ -250,14 +238,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

- name: Cache browsers
id: playwright-cache
Expand Down Expand Up @@ -360,6 +342,9 @@ jobs:
exit 1
fi
- name: Build libs
run: yarn workspace @hicommonwealth/core build

- name: Run linter
env:
GITHUB_BASE_REF: ${{ github.base_ref }}
Expand All @@ -368,7 +353,7 @@ jobs:
- name: Commonwealth Typecheck
run: yarn --cwd packages/commonwealth check-types

- name: Dicsord-Bot Typecheck
- name: Discord-Bot Typecheck
run: yarn --cwd packages/discord-bot check-types

# These tests run quickly, so run them in a separate job
Expand Down Expand Up @@ -417,14 +402,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

- name: Run unit tests
run: yarn --cwd packages/commonwealth unit-test --forbid-only
Expand Down Expand Up @@ -501,14 +480,8 @@ jobs:
path: '**/node_modules'
key: ${{ matrix.node }}-${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Add node-gyp
run: yarn global add node-gyp

- name: Install dependencies
run: yarn --ignore-engines

- name: Init Db
run: cd packages/commonwealth && npx sequelize db:migrate
- name: Build project
run: yarn build-project

## EVM Section:
- name: Start EVM Testnet
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
docker-compose.yaml
stellar
node_modules/
*/build
*/dist
**/build
**/dist
**/.DS_Store
*.env
*.log
*/build/
.idea
.vscode
*.postgres
Expand Down
21 changes: 11 additions & 10 deletions knowledge_base/Package-Scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ If you add a script to the package.json, you must add documentation here, descri
- [datadog-db-setup](#datadog-db-setup)
- [send-cosmos-notifs](#send-cosmos-notifs)
- [send-notification-digest-emails](#send-notification-digest-emails)
- [storybook](#storybook)
- [Playwright](#playwright)
- [e2e-start-server](#e2e-start-server)
- [test-e2e](#test-e2e)
Expand Down Expand Up @@ -74,6 +73,16 @@ If you add a script to the package.json, you must add documentation here, descri

# Build Scripts

## build-project

Definition: `yarn global add node-gyp && yarn --ignore-engines && yarn workspace @hicommonwealth/core build && yarn workspace commonwealth migrate-db`

Description: Temporary placeholder for common script used by the CI pipeline to:

- Install dependencies
- Incrementally build project with references (tsc -b)
- Migrate DB

## build-all

Definition: `NODE_OPTIONS=--max_old_space_size=4096 webpack --config webpack/webpack.prod.config.js --progress && yarn build-consumer`
Expand Down Expand Up @@ -332,14 +341,6 @@ Definition: `SEND_EMAILS=true ts-node --project tsconfig.json server.ts`

Description: Schedules a daily task for sending notification email digests.

## storybook

Definition: `storybook dev -p 6006`

Description: Compiles and serves a development build of Storybook reflecting source code changes in-browser in real time, at localhost:6006.

Contributor: Daniel Martins

# Playwright

## e2e-start-server
Expand Down Expand Up @@ -530,4 +531,4 @@ Description: Starts existing dormant Cosmos devnet containers.

Definition: `chmod u+x test/util/cosmos-chain-testing/v1/stop.sh && ./test/util/cosmos-chain-testing/v1/stop.sh && chmod u+x test/util/cosmos-chain-testing/v1beta1/stop.sh && ./test/util/cosmos-chain-testing/v1beta1/stop.sh && chmod u+x test/util/cosmos-chain-testing/ethermint/stop.sh && ./test/util/cosmos-chain-testing/ethermint/stop.sh`

Description: Stop all Cosmos devnet containers.
Description: Stop all Cosmos devnet containers.
20 changes: 20 additions & 0 deletions libs/adapters/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@hicommonwealth/adapters",
"private": "true",
"version": "0.1.0",
"description": "External adapters",
"files": [
"build"
],
"main": "build/index",
"scripts": {
"build": "tsc --build",
"clean": "rm -rf build",
"check-types": "tsc --noEmit",
"test": "NODE_ENV=test ts-mocha '__tests__/**/*.spec.ts'"
},
"dependencies": {
"hot-shots": "^9",
"typescript-logging": "^0.6.4"
}
}
1 change: 1 addition & 0 deletions libs/adapters/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TODO = 1;
9 changes: 9 additions & 0 deletions libs/adapters/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"tsBuildInfoFile": "build/.tsbuildinfo"
},
"include": ["src"]
}
43 changes: 43 additions & 0 deletions libs/chains/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@hicommonwealth/chains",
"private": "true",
"version": "0.1.0",
"description": "Chain types",
"files": [
"build"
],
"main": "build/index",
"scripts": {
"build": "tsc --build",
"clean": "rm -rf build",
"check-types": "tsc --noEmit",
"test": "NODE_ENV=test ts-mocha '__tests__/**/*.spec.ts'"
},
"dependencies": {
"@canvas-js/interfaces": "^0.5.0-alpha4",
"@cosmjs/amino": "^0.31.0",
"@cosmjs/proto-signing": "^0.31.0",
"@cosmjs/stargate": "^0.31.0",
"@cosmjs/tendermint-rpc": "^0.31.0",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/hash": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/strings": "^5.7.0",
"@ethersproject/units": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"@osmonauts/lcd": "^0.10.0",
"ethers": "5.7.2"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@typechain/ethers-v5": "^6.0.0",
"hardhat": "^2.3.0",
"hardhat-typechain": "^0.3.5",
"ts-generator": "^0.1.1",
"typechain": "^4.0.1"
}
}
1 change: 1 addition & 0 deletions libs/chains/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TODO = 1;
9 changes: 9 additions & 0 deletions libs/chains/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"tsBuildInfoFile": "build/.tsbuildinfo"
},
"include": ["src"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { getFileSizeBytes } from '../../server/util/getFilesSizeBytes';
import { getFileSizeBytes } from '../../src/utils/getFileSizeBytes';

describe('ChainIconSizeLimit tests', () => {
describe('checkIconSize', () => {
it("should return zero if url provided doesn't exist", async () => {
const fileSizeBytes = await getFileSizeBytes('badUrl');
expect(fileSizeBytes).to.equal(0);
Expand Down
19 changes: 19 additions & 0 deletions libs/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@hicommonwealth/core",
"private": "true",
"version": "0.1.0",
"description": "Core Model",
"files": [
"build"
],
"main": "build/index",
"scripts": {
"build": "tsc --build",
"clean": "rm -rf build",
"check-types": "tsc --noEmit",
"test": "NODE_ENV=test ts-mocha '__tests__/**/*.spec.ts'"
},
"dependencies": {
"zod": "^3.22.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import {
ChainBase,
ChainCategoryType,
ChainType,
} from 'common-common/src/types';
import { z } from 'zod';
import { ALL_COMMUNITIES } from '../../server/middleware/databaseValidationService';
import { getFileSizeBytes } from '../../server/util/getFilesSizeBytes';
import { ChainBase, ChainCategoryType, ChainType } from '../types';
import { checkIconSize } from '../utils/checkIconSize';
import { ALL_COMMUNITIES } from '../utils/constants';

export const MAX_COMMUNITY_IMAGE_SIZE_KB = 500;

async function checkIconSize(val, ctx) {
const fileSizeBytes = await getFileSizeBytes(val);
if (fileSizeBytes === 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Image url provided doesn't exist",
});
return;
}
if (fileSizeBytes >= MAX_COMMUNITY_IMAGE_SIZE_KB * 1024) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Image must be smaller than ${MAX_COMMUNITY_IMAGE_SIZE_KB}kb`,
});
}
}

export const createCommunitySchema = z.object({
export const CreateCommunitySchema = z.object({
id: z.string(),
name: z
.string()
Expand Down Expand Up @@ -68,3 +45,5 @@ export const createCommunitySchema = z.object({
element: z.string().url().startsWith('https://matrix.to/').optional(),
discord: z.string().url().startsWith('https://discord.com/').optional(),
});

export type CreateCommunity = z.infer<typeof CreateCommunitySchema>;
1 change: 1 addition & 0 deletions libs/core/src/community/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './createCommunity';
2 changes: 2 additions & 0 deletions libs/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * as Community from './community';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export enum RedisNamespaces {
Database_Cleaner = 'database_cleaner',
Compound_Gov_Version = 'compound_gov_version',
Token_Balance = 'token_balance',
Activity_Cache = 'activity_cache',
}

export interface ISnapshotNotification {
Expand Down
20 changes: 20 additions & 0 deletions libs/core/src/utils/checkIconSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { z } from 'zod';
import { MAX_COMMUNITY_IMAGE_SIZE_KB } from './constants';
import { getFileSizeBytes } from './getFileSizeBytes';

export async function checkIconSize(val: string, ctx: z.RefinementCtx) {
const fileSizeBytes = await getFileSizeBytes(val);
if (fileSizeBytes === 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Image url provided doesn't exist",
});
return;
}
if (fileSizeBytes >= MAX_COMMUNITY_IMAGE_SIZE_KB * 1024) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Image must be smaller than ${MAX_COMMUNITY_IMAGE_SIZE_KB}kb`,
});
}
}
2 changes: 2 additions & 0 deletions libs/core/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ALL_COMMUNITIES = 'all_communities';
export const MAX_COMMUNITY_IMAGE_SIZE_KB = 500;
12 changes: 12 additions & 0 deletions libs/core/src/utils/getFileSizeBytes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export async function getFileSizeBytes(url: string): Promise<number> {
try {
if (!url) return 0;
// Range header is to prevent it from reading any bytes from the GET request because we only want the headers.
const response = await fetch(url, { headers: { Range: 'bytes=0-0' } });
if (!response) return 0;
const contentRange = response.headers.get('content-range');
return contentRange ? parseInt(contentRange.split('/')[1], 10) : 0;
} catch (err) {
return 0;
}
}
10 changes: 10 additions & 0 deletions libs/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"tsBuildInfoFile": "build/.tsbuildinfo",
"strict": true
},
"include": ["src"]
}
Loading

0 comments on commit c8d6a0e

Please sign in to comment.