Skip to content

Commit

Permalink
Tweak chaos script and callback url
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Sep 16, 2024
1 parent f81c1a9 commit 38301ca
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 58 deletions.
84 changes: 44 additions & 40 deletions backend/scripts/chaos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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`)
Expand Down
15 changes: 4 additions & 11 deletions backend/shared/src/gidx/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
Expand Down
23 changes: 16 additions & 7 deletions backend/shared/src/test/users.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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',
})
Expand Down Expand Up @@ -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`)
Expand All @@ -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
}
6 changes: 6 additions & 0 deletions common/src/util/random.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
}

0 comments on commit 38301ca

Please sign in to comment.