diff --git a/backend/scripts/chaos.ts b/backend/scripts/chaos.ts index 9bfd5790ad..3fdbc41b65 100644 --- a/backend/scripts/chaos.ts +++ b/backend/scripts/chaos.ts @@ -10,7 +10,8 @@ import { getRandomTestBet } from 'shared/test/bets' const URL = `https://${DEV_CONFIG.apiEndpoint}/v0` // const URL = `http://localhost:8088/v0` -const USE_OLD_MARKET = true +const OLD_MARKET_SLUG = 'chaos-sweeps--cash' +const USE_OLD_MARKET = !!OLD_MARKET_SLUG const ENABLE_LIMIT_ORDERS = true if (require.main === module) { @@ -20,48 +21,51 @@ if (require.main === module) { return } const privateUsers = await getTestUsers(firestore, pg, 100) - const marketCreations = [ - { - question: 'test ' + Math.random().toString(36).substring(7), - outcomeType: 'MULTIPLE_CHOICE', - answers: Array(50) - .fill(0) - .map((_, i) => 'answer ' + i), - shouldAnswersSumToOne: true, - }, - // { - // question: 'test ' + Math.random().toString(36).substring(7), - // outcomeType: 'BINARY', - // }, - // { - // question: 'test ' + Math.random().toString(36).substring(7), - // outcomeType: 'MULTIPLE_CHOICE', - // answers: Array(50) - // .fill(0) - // .map((_, i) => 'answer ' + i), - // shouldAnswersSumToOne: false, - // }, - ] - log('creating markets') - const markets = await Promise.all( - marketCreations.map(async (market) => { - const resp = await fetch(URL + `/market`, { - method: 'POST', - headers: { - Authorization: `Key ${privateUsers[0].apiKey}`, - 'Content-Type': 'application/json', - }, - body: JSON.stringify(market), + let markets = [] + if (!USE_OLD_MARKET) { + const marketCreations = [ + { + question: 'test ' + Math.random().toString(36).substring(7), + outcomeType: 'MULTIPLE_CHOICE', + answers: Array(50) + .fill(0) + .map((_, i) => 'answer ' + i), + shouldAnswersSumToOne: true, + }, + // { + // question: 'test ' + Math.random().toString(36).substring(7), + // outcomeType: 'BINARY', + // }, + // { + // question: 'test ' + Math.random().toString(36).substring(7), + // outcomeType: 'MULTIPLE_CHOICE', + // answers: Array(50) + // .fill(0) + // .map((_, i) => 'answer ' + i), + // shouldAnswersSumToOne: false, + // }, + ] + log('creating markets') + markets = await Promise.all( + marketCreations.map(async (market) => { + const resp = await fetch(URL + `/market`, { + method: 'POST', + headers: { + Authorization: `Key ${privateUsers[0].apiKey}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(market), + }) + if (resp.status !== 200) { + console.error('Failed to create market', await resp.text()) + } + return resp.json() }) - if (resp.status !== 200) { - console.error('Failed to create market', await resp.text()) - } - return resp.json() - }) - ) + ) + } const contracts = await pg.map( `select * from contracts where slug in ($1:list)`, - USE_OLD_MARKET ? [['test-ubyxer']] : [markets.map((m: any) => m.slug)], + USE_OLD_MARKET ? [[OLD_MARKET_SLUG]] : [markets.map((m: any) => m.slug)], convertContract ) log(`Found ${contracts.length} contracts`) diff --git a/backend/shared/src/gidx/helpers.ts b/backend/shared/src/gidx/helpers.ts index 73a9aaf61c..f5d669f88d 100644 --- a/backend/shared/src/gidx/helpers.ts +++ b/backend/shared/src/gidx/helpers.ts @@ -5,13 +5,7 @@ import { ID_ERROR_MSG, IDENTITY_AND_FRAUD_THRESHOLD, } from 'common/gidx/gidx' -import { - getPrivateUserSupabase, - getUser, - isProd, - LOCAL_DEV, - log, -} from 'shared/utils' +import { getPrivateUserSupabase, getUser, isProd, log } from 'shared/utils' import { getPhoneNumber } from 'shared/helpers/get-phone-number' import { ENV_CONFIG } from 'common/envs/constants' import { @@ -30,10 +24,9 @@ import { intersection } from 'lodash' import { updatePrivateUser, updateUser } from 'shared/supabase/users' import { User } from 'common/user' -// TODO: when in production, configure endpoint here: https://portal.gidx-service.in/Integration/Index#ProfileNotification -export const GIDXCallbackUrl = LOCAL_DEV - ? 'https://enabled-bream-sharply.ngrok-free.app' - : 'https://' + ENV_CONFIG.apiEndpoint +export const GIDXCallbackUrl = 'https://' + ENV_CONFIG.apiEndpoint +// If you want to test your local endpoint, use ngrok or similar service +// LOCAL_DEV ? 'https://enabled-bream-sharply.ngrok-free.app' : ENV_CONFIG.apiEndpoint export const GIDX_BASE_URL = isProd() ? 'https://api.gidx-service.com' diff --git a/backend/shared/src/test/users.ts b/backend/shared/src/test/users.ts index 5967b9391b..94d9102d4e 100644 --- a/backend/shared/src/test/users.ts +++ b/backend/shared/src/test/users.ts @@ -1,7 +1,7 @@ import { log } from 'shared/monitoring/log' -import { incrementBalance } from 'shared/supabase/users' +import { incrementBalance, updateUser } from 'shared/supabase/users' import { SupabaseDirectClient } from 'shared/supabase/init' -import { randomString } from 'common/util/random' +import { randomString, secureRandomString } from 'common/util/random' import * as admin from 'firebase-admin' import { createUserMain } from 'shared/create-user-main' @@ -22,7 +22,7 @@ export const getTestUsers = async ( Array.from({ length: missing }).map(async () => { const userCredential = await auth.createUser({ email: 'manifoldTestNewUser+' + randomString() + '@gmail.com', - password: randomString(), + password: secureRandomString(16), emailVerified: true, displayName: 'Manifold Test User', }) @@ -59,12 +59,21 @@ export const getTestUsers = async ( ) log('got private users') await Promise.all( - privateUsers.map((pu) => - incrementBalance(pg, pu.id, { + privateUsers.map(async (pu) => { + await incrementBalance(pg, pu.id, { balance: 10_000, + cashBalance: 1_000, + totalCashDeposits: 1_000, totalDeposits: 10_000, }) - ) + await updateUser(pg, pu.id, { + sweepstakesVerified: true, + idVerified: true, + sweepstakes5kLimit: false, + kycDocumentStatus: 'verified', + kycLastAttemptTime: Date.now(), + }) + }) ) const apiKeysMissing = privateUsers.filter((p) => !p.apiKey) log(`${privateUsers.length} user balances incremented by 10k`) @@ -85,7 +94,7 @@ export const getTestUsers = async ( [apiKeysMissing.map((p) => p.id)], (r) => ({ id: r.id as string, apiKey: r.api_key as string }) ) - return [...refetchedUsers, ...privateUsers.filter((p) => !p.apiKey)] + return [...refetchedUsers, ...privateUsers.filter((p) => p.apiKey)] } return privateUsers } diff --git a/common/src/util/random.ts b/common/src/util/random.ts index fb02fa197e..11ff120ae2 100644 --- a/common/src/util/random.ts +++ b/common/src/util/random.ts @@ -1,5 +1,7 @@ // max 10 length string. For longer, concat multiple // Often used as a unique identifier. +import { randomBytes } from 'crypto' + export const randomString = (length = 10) => Math.random() .toString(36) @@ -57,3 +59,7 @@ export const shuffle = (array: unknown[], rand: () => number) => { ;[array[i], array[swapIndex]] = [array[swapIndex], array[i]] } } + +export const secureRandomString = (length: number): string => { + return randomBytes(length).toString('hex').slice(0, length) +}