Skip to content

Commit

Permalink
Create project
Browse files Browse the repository at this point in the history
Fixes

Fixes

Fixes

Fixes
  • Loading branch information
Boldizsar Mezei committed Sep 21, 2023
1 parent 45bf316 commit 2f73dd9
Show file tree
Hide file tree
Showing 160 changed files with 2,127 additions and 1,541 deletions.
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
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
6 changes: 5 additions & 1 deletion packages/functions/src/controls/address.control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import {
Network,
WenError,
} from '@build-5/interfaces';
import { Context } from '../runtime/firebase/common';
import { createAddressValidationOrder } from '../services/payment/tangle-service/address/address-validation.service';
import { invalidArgument } from '../utils/error.utils';

export const validateAddressControl = async (owner: string, params: AddressValidationRequest) => {
export const validateAddressControl = async (
{ owner }: Context,
params: AddressValidationRequest,
) => {
const network = (params.network as Network) || DEFAULT_NETWORK;
const member = await build5Db().doc(`${COL.MEMBER}/${owner}`).get<Member>();

Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/controls/auth.control.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { TOKEN_EXPIRY_HOURS } from '@build-5/interfaces';
import dayjs from 'dayjs';
import jwt from 'jsonwebtoken';
import { Context } from '../runtime/firebase/common';
import { getJwtSecretKey } from '../utils/config.utils';

export const generateCustomTokenControl = async (owner: string) => {
export const generateCustomTokenControl = async ({ owner }: Context) => {
const rawJwt = {
uid: owner,
iat: dayjs().unix(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
Transaction,
} from '@build-5/interfaces';
import { get } from 'lodash';
import { Context } from '../../runtime/firebase/common';
import { approveAwardParticipant } from '../../services/payment/tangle-service/award/award.approve.participant.service';

export const approveAwardParticipantControl = async (
owner: string,
{ owner }: Context,
params: AwardApproveParticipantRequest,
): Promise<AwardApproveParticipantResponse> => {
const members = params.members.map((m) => m.toLowerCase());
Expand Down
6 changes: 5 additions & 1 deletion packages/functions/src/controls/award/award.cancel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { build5Db } from '@build-5/database';
import { Award, AwardCancelRequest, COL, WenError } from '@build-5/interfaces';
import dayjs from 'dayjs';
import { Context } from '../../runtime/firebase/common';
import { invalidArgument } from '../../utils/error.utils';
import { assertIsGuardian } from '../../utils/token.utils';

export const cancelAwardControl = (owner: string, params: AwardCancelRequest): Promise<Award> =>
export const cancelAwardControl = (
{ owner }: Context,
params: AwardCancelRequest,
): Promise<Award> =>
build5Db().runTransaction(async (transaction) => {
const awardDocRef = build5Db().doc(`${COL.AWARD}/${params.uid}`);
const award = await transaction.get<Award>(awardDocRef);
Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/controls/award/award.create.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { build5Db } from '@build-5/database';
import { Award, AwardCreateRequest, COL, SUB_COL } from '@build-5/interfaces';
import { Context } from '../../runtime/firebase/common';
import { createAward } from '../../services/payment/tangle-service/award/award.create.service';

export const createAwardControl = async (owner: string, params: AwardCreateRequest) => {
export const createAwardControl = async ({ owner }: Context, params: AwardCreateRequest) => {
const { owner: awardOwner, award } = await createAward(owner, params);

const batch = build5Db().batch();
Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/controls/award/award.fund.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { build5Db } from '@build-5/database';
import { AwardFundRequest, COL, Transaction } from '@build-5/interfaces';
import { Context } from '../../runtime/firebase/common';
import {
createAwardFundOrder,
getAwardForFunding,
} from '../../services/payment/tangle-service/award/award.fund.service';

export const fundAwardControl = async (
owner: string,
{ owner }: Context,
params: AwardFundRequest,
): Promise<Transaction> => {
const award = await getAwardForFunding(owner, params.uid);
Expand Down
5 changes: 3 additions & 2 deletions packages/functions/src/controls/award/award.owner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { build5Db } from '@build-5/database';
import {
Award,
AwardAddOwnerRequest,
Expand All @@ -8,11 +7,13 @@ import {
WenError,
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import { Context } from '../../runtime/firebase/common';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
import { build5Db } from '@build-5/database';

export const addOwnerControl = async (
owner: string,
{ owner }: Context,
params: AwardAddOwnerRequest,
): Promise<AwardOwner> => {
const awardDocRef = build5Db().doc(`${COL.AWARD}/${params.uid}`);
Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/controls/award/award.participate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
WenError,
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import { Context } from '../../runtime/firebase/common';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';

export const awardParticipateControl = async (
owner: string,
{ owner }: Context,
params: AwardParticpateRequest,
): Promise<AwardParticipant> => {
const awardDocRef = build5Db().doc(`${COL.AWARD}/${params.uid}`);
Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/controls/award/award.reject.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { build5Db } from '@build-5/database';
import { Award, AwardRejectRequest, COL, WenError } from '@build-5/interfaces';
import { Context } from '../../runtime/firebase/common';
import { invalidArgument } from '../../utils/error.utils';
import { assertIsGuardian } from '../../utils/token.utils';

export const rejectAwardControl = async (
owner: string,
{ owner }: Context,
params: AwardRejectRequest,
): Promise<Award> => {
const awardDocRef = build5Db().doc(`${COL.AWARD}/${params.uid}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { AddressTypes, ED25519_ADDRESS_TYPE, INodeInfo } from '@iota/iota.js-next';
import dayjs from 'dayjs';
import { last } from 'lodash';
import { Context } from '../../runtime/firebase/common';
import { SmrWallet } from '../../services/wallet/SmrWalletService';
import { AddressDetails, WalletService } from '../../services/wallet/wallet';
import { assertMemberHasValidAddress, assertSpaceHasValidAddress } from '../../utils/address.utils';
Expand All @@ -36,7 +37,10 @@ import { createAliasOutput } from '../../utils/token-minting-utils/alias.utils';
import { assertIsGuardian } from '../../utils/token.utils';
import { getRandomEthAddress } from '../../utils/wallet.utils';

export const mintCollectionOrderControl = async (owner: string, params: CollectionMintRequest) => {
export const mintCollectionOrderControl = async (
{ owner }: Context,
params: CollectionMintRequest,
) => {
const network = params.network as Network;

const member = await build5Db().doc(`${COL.MEMBER}/${owner}`).get<Member>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { build5Db } from '@build-5/database';
import { ApproveCollectionRequest, COL, Collection, WenError } from '@build-5/interfaces';
import { Context } from '../../runtime/firebase/common';
import { invalidArgument } from '../../utils/error.utils';
import { assertIsGuardian } from '../../utils/token.utils';

export const approveCollectionControl = async (
owner: string,
{ owner }: Context,
params: ApproveCollectionRequest,
): Promise<Collection> => {
const collectionDocRef = build5Db().doc(`${COL.COLLECTION}/${params.uid}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import {
SUB_COL,
WenError,
} from '@build-5/interfaces';
import { hasStakedSoonTokens } from '../../services/stake.service';
import { Context } from '../../runtime/firebase/common';
import { hasStakedTokens } from '../../services/stake.service';
import { assertSpaceHasValidAddress } from '../../utils/address.utils';
import { dateToTimestamp, serverTime } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
import { getRandomEthAddress } from '../../utils/wallet.utils';
import { populateTokenUidOnDiscounts } from './common';

export const createCollectionControl = async (owner: string, params: CreateCollectionRequest) => {
const hasStakedSoons = await hasStakedSoonTokens(owner);
export const createCollectionControl = async (
{ project, owner }: Context,
params: CreateCollectionRequest,
) => {
const hasStakedSoons = await hasStakedTokens(project, owner);
if (!hasStakedSoons) {
throw invalidArgument(WenError.no_staked_soon);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { build5Db } from '@build-5/database';
import { COL, Collection, RejectCollectionRequest, WenError } from '@build-5/interfaces';
import dayjs from 'dayjs';
import { Context } from '../../runtime/firebase/common';
import { invalidArgument } from '../../utils/error.utils';
import { assertIsGuardian } from '../../utils/token.utils';

export const rejectCollectionControl = async (
owner: string,
{ owner }: Context,
params: RejectCollectionRequest,
): Promise<Collection> => {
const collectionDocRef = build5Db().doc(`${COL.COLLECTION}/${params.uid}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import dayjs from 'dayjs';
import { isEmpty, last, set } from 'lodash';
import { updateMintedCollectionSchemaObject } from '../../runtime/firebase/collection/CollectionUpdateMintedRequestSchema';
import { updateCollectionSchemaObject } from '../../runtime/firebase/collection/CollectionUpdateRequestSchema';
import { UidSchemaObject } from '../../runtime/firebase/common';
import { Context, UidSchemaObject } from '../../runtime/firebase/common';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
import { assertValidationAsync } from '../../utils/schema.utils';
import { assertIsGuardian } from '../../utils/token.utils';
import { populateTokenUidOnDiscounts } from './common';

export const updateCollectionControl = async (owner: string, rawParams: UidSchemaObject) => {
export const updateCollectionControl = async ({ owner }: Context, rawParams: UidSchemaObject) => {
const collectionDocRef = build5Db().doc(`${COL.COLLECTION}/${rawParams.uid}`);
const collection = await collectionDocRef.get<Collection>();
if (!collection) {
Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/controls/credit/credit.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import {
WenError,
} from '@build-5/interfaces';
import dayjs from 'dayjs';
import { Context } from '../../runtime/firebase/common';
import { WalletService } from '../../services/wallet/wallet';
import { dateToTimestamp } from '../../utils/dateTime.utils';
import { invalidArgument } from '../../utils/error.utils';
import { getRandomEthAddress } from '../../utils/wallet.utils';

export const creditUnrefundableControl = (
owner: string,
{ owner }: Context,
params: CreditUnrefundableRequest,
): Promise<Transaction> =>
build5Db().runTransaction(async (transaction) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/functions/src/controls/member/member.create.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { build5Db } from '@build-5/database';
import { COL, Member } from '@build-5/interfaces';
import { Context } from '../../runtime/firebase/common';
import { getRandomNonce } from '../../utils/wallet.utils';
import { build5Db } from '@build-5/database';

export const createMemberControl = async (owner: string) => {
export const createMemberControl = async ({ owner }: Context) => {
const memberDocRef = build5Db().collection(COL.MEMBER).doc(owner);
const member = await memberDocRef.get<Member>();

Expand Down
3 changes: 2 additions & 1 deletion packages/functions/src/controls/member/member.update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
NftStatus,
WenError,
} from '@build-5/interfaces';
import { Context } from '../../runtime/firebase/common';
import { invalidArgument } from '../../utils/error.utils';
import { cleanupParams } from '../../utils/schema.utils';

export const updateMemberControl = async (
owner: string,
{ owner }: Context,
params: MemberUpdateRequest,
): Promise<Member> => {
const memberDocRef = build5Db().doc(`${COL.MEMBER}/${owner}`);
Expand Down
10 changes: 3 additions & 7 deletions packages/functions/src/controls/nft/nft.bid.control.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { build5Db } from '@build-5/database';
import { COL, NftBidRequest, Transaction, WenError } from '@build-5/interfaces';
import { Context } from '../../runtime/firebase/common';
import { createNftBidOrder } from '../../services/payment/tangle-service/nft/nft-bid.service';
import { invalidArgument } from '../../utils/error.utils';

export const nftBidControl = async (
owner: string,
{ owner, ip }: Context,
params: NftBidRequest,
customParams?: Record<string, unknown>,
): Promise<Transaction> => {
const memberDocRef = build5Db().doc(`${COL.MEMBER}/${owner}`);
const member = await memberDocRef.get();
if (!member) {
throw invalidArgument(WenError.member_does_not_exists);
}

const bidTransaction = await createNftBidOrder(
params.nft,
owner,
(customParams?.ip as string) || '',
);
const bidTransaction = await createNftBidOrder(params.nft, owner, ip || '');

const transactionDocRef = build5Db().doc(`${COL.TRANSACTION}/${bidTransaction.uid}`);
await transactionDocRef.create(bidTransaction);
Expand Down
Loading

0 comments on commit 2f73dd9

Please sign in to comment.