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

Create project #2595

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 36 additions & 0 deletions .github/workflows/functions_emulated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,39 @@ jobs:
name: firestore-data-test-chunk_4
path: ./packages/functions/firestore-data/
retention-days: 1
chunk_5:
needs: npm-install
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
- uses: actions/cache@v3
with:
path: |
node_modules
packages/functions/node_modules
packages/interfaces/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json') }}
- name: Init
run: |
npm run build:functions
npm install -g firebase-tools
- name: Test
working-directory: packages/functions
run: |
export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json"
npm run milestone-sync &
firebase emulators:exec "
npm run test:ci -- --findRelatedTests test/controls/project/project.deactivate.spec.ts &&
npm run test:ci -- --findRelatedTests test/controls/project/project.create.spec.ts
" --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data
- name: Archive firestore data
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: firestore-data-test-chunk_5
path: ./packages/functions/firestore-data/
retention-days: 1
38 changes: 37 additions & 1 deletion .github/workflows/functions_online-emulated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ jobs:
npm run test-online:ci -- --findRelatedTests test/controls/token/token.create.spec.ts &&
npm run test-online:ci -- --findRelatedTests test/controls/token/token.cancel.pub.sale.spec.ts &&
npm run test-online:ci -- --findRelatedTests test/controls/token/token.airdrop.spec.ts &&
npm run test-online:ci -- --findRelatedTests test/controls/token/token.airdrop.claim.spec.ts
npm run test-online:ci -- --findRelatedTests test/controls/token/token.airdrop.claim.spec.ts &&
npm run test-online:ci -- --findRelatedTests test/controls/project/project.deactivate.spec.ts
" --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data
- name: Archive firestore data
uses: actions/upload-artifact@v3
Expand All @@ -232,3 +233,38 @@ jobs:
name: firestore-data-test-online-chunk_4
path: ./packages/functions/firestore-data/
retention-days: 1
chunk_5:
needs: npm-install
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
- uses: actions/cache@v3
with:
path: |
node_modules
packages/functions/node_modules
packages/interfaces/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/package.json') }}
- name: Init
run: |
npm run build:functions
npm install -g firebase-tools
- name: Test
working-directory: packages/functions
run: |
export GOOGLE_APPLICATION_CREDENTIALS="./test-service-account-key.json"
npm run milestone-sync &
firebase emulators:exec "
npm run test-online:ci -- --findRelatedTests test/controls/project/project.create.spec.ts
" --project dev --only functions,firestore,storage,ui,auth --export-on-exit=./firestore-data
- name: Archive firestore data
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: firestore-data-test-online-chunk_5
path: ./packages/functions/firestore-data/
retention-days: 1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"joi-to-types": "ts-node ./scripts/joi-generator-post.ts && ts-node ./scripts/joi-generator-tangle.ts && npm run prettier"
},
"devDependencies": {
"joi-to-typescript": "^4.4.1"
"joi-to-typescript": "4.7.0"
}
}
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"cors": "^2.8.5",
"dayjs": "^1.11.9",
"express": "^4.18.2",
"joi": "^17.10.1",
"joi": "17.10.2",
"lodash": "^4.17.21",
"rxjs": "^7.8.1",
"ws": "^8.13.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/database/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ENVIRONMENT=test
WEB3_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweEZCOTFiNTdEN2YzNmVhNjQ4NjQ3ODIyQjJGNGVEOEEyMDZCNERhNjQiLCJpc3MiOiJ3ZWIzLXN0b3JhZ2UiLCJpYXQiOjE2Njc0MDYzNzE3NDksIm5hbWUiOiJ0ZXN0IGRldiJ9.88vd8ZmeEle2Xqyc8uEMBOXJqDrFcxxF8gyHuXIjXgk
JWT_SECRET=asdas#@#@xdas31sad
ALGOLIA_APPID=6MPUETJRDB
ALGOLIA_KEY=a75153c20ebe86d31e1fe5874f55dbac
ENCRYPTION_SALT=c4kWxCtNVQ5c2m
IP_INFO_TOKEN=''
XPTOKEN_ID=0x08fe43472f5968c4ccfa7154599e3d9c8df3f2e0b6396cafc2b038f15ee1974e050100000000
XPTOKEN_UID=0xe71439be7001d2311658ded364e4043a284d16f4
XPTOKEN_GUARDIANID=0x551fd2c7c7bf356bac194587dab2fcd46420054b
2 changes: 2 additions & 0 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
"@build-5/interfaces": "*",
"dayjs": "^1.11.9",
"firebase-admin": "^11.10.1",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/jsonwebtoken": "^9.0.3",
"@types/lodash": "^4.14.197",
"dotenv": "^16.3.1",
"glob": "^10.3.4",
Expand Down
86 changes: 86 additions & 0 deletions packages/database/scripts/dbUpgrades/1.0.0/soonProjects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
COL,
MIN_IOTA_AMOUNT,
ProjectBilling,
SOON_PROJECT_ID,
SUB_COL,
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import jwt from 'jsonwebtoken';
import { FirebaseApp } from '../../../src/app/app';
import { Firestore } from '../../../src/firestore/firestore';
import serviceAccount from '../../serviceAccountKey.json';

const ADMIN_ID = '0x551fd2c7c7bf356bac194587dab2fcd46420054b';

export const creditHighestPayment = async (app: FirebaseApp) => {
const db = new Firestore(app);
const isProdEnv = serviceAccount.project_id === 'soonaverse';

const project = isProdEnv ? prodProject : testProject;
const projectDocRef = db.doc(`${COL.PROJECT}/${project.uid}`);

if ((await projectDocRef.get()) !== undefined) {
console.log('Project already created');
return;
}

const batch = db.batch();

batch.create(projectDocRef, project);

const adminDocRef = projectDocRef.collection(SUB_COL.ADMINS).doc(ADMIN_ID);
const admin = {
project: SOON_PROJECT_ID,
projects: { [SOON_PROJECT_ID]: true },
uid: ADMIN_ID,
createdOn: dayjs().toDate(),
parentCol: COL.PROJECT,
parentId: project.uid,
};
batch.create(adminDocRef, admin);

const rawJwt = { uid: ADMIN_ID, project: project.uid, iat: dayjs().unix() };
const signed = jwt.sign(rawJwt, process.env.JWT_SECRET as string);
const apiKey = {
uid: '0xf43ea8069e6ed7006983c5037f35995af199bebf',
token: signed,
parentCol: COL.PROJECT,
parentId: project.uid,
createdOn: dayjs().toDate(),
};
const apiKeyDocRef = projectDocRef.collection(SUB_COL._API_KEY).doc();
batch.create(apiKeyDocRef, apiKey);

await batch.commit();
};

const testProject = {
uid: SOON_PROJECT_ID,
name: 'Soonaverse',
createdBy: ADMIN_ID,
deactivated: false,
config: {
billing: ProjectBilling.TOKEN_BASE,
tiers: [0, 0, 0, 0, 0].map((v) => v * MIN_IOTA_AMOUNT),
tokenTradingFeeDiscountPercentage: [0, 0, 0, 0, 0],
nativeTokenSymbol: 'SOON',
nativeTokenUid: '0x36ebf336f63f64718d088ec31c1db3151e0d8317',
},
};

const prodProject = {
uid: SOON_PROJECT_ID,
name: 'Soonaverse',
createdBy: ADMIN_ID,
deactivated: false,
config: {
billing: ProjectBilling.TOKEN_BASE,
tiers: [0, 10, 4000, 6000, 15000].map((v) => v * MIN_IOTA_AMOUNT),
tokenTradingFeeDiscountPercentage: [0, 25, 50, 75, 100],
nativeTokenSymbol: 'SOON',
nativeTokenUid: '0x9600b5afbb84f15e0d4c0f90ea60b2b8d7bd0f1e',
},
};

export const roll = creditHighestPayment;

This file was deleted.

55 changes: 0 additions & 55 deletions packages/database/scripts/dbUpgrades/1.0/totalGuardiansRoll.ts

This file was deleted.

5 changes: 5 additions & 0 deletions packages/database/src/firestore/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export class Firestore implements IDatabase {
public arrayRemove = <T>(...value: T[]) => admin.firestore.FieldValue.arrayRemove(...value);

public deleteField = () => admin.firestore.FieldValue.delete();

public get = async <T>(col: COL, uid: string) => {
const docRef = this.db.doc(`${col}/${uid}`);
return (await docRef.get()).data() as T;
};
}

export class FirestoreBatch implements IBatch {
Expand Down
2 changes: 2 additions & 0 deletions packages/database/src/firestore/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface IDatabase {
arrayUnion: <T>(...value: T[]) => any;
arrayRemove: <T>(...value: T[]) => any;
deleteField: () => any;

get: <T>(col: COL, uid: string) => Promise<T>;
}

export interface ICollectionGroup {
Expand Down
1 change: 1 addition & 0 deletions packages/functions/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
testEnvironment: 'node',
testTimeout: 900000,
globalSetup: './test/set-up.ts',
globalTeardown: './test/teardown.ts',
reporters: ['default', 'github-actions'],
};
2 changes: 1 addition & 1 deletion packages/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"glob": "9.3.4",
"interfaces": "^0.0.3",
"is-ipfs": "8.0.1",
"joi": "17.10.1",
"joi": "17.10.2",
"js-big-decimal": "1.4.1",
"jsonwebtoken": "9.0.0",
"lodash": "4.17.21",
Expand Down
2 changes: 2 additions & 0 deletions packages/functions/scripts/manualRefund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ db.collection(COL.MEMBER)
.collection(COL.TRANSACTION)
.doc(tranId)
.set(<Transaction>{
project: '',
projects: {},
type: TransactionType.CREDIT,
uid: tranId,
space: '',
Expand Down
Loading