Skip to content

Commit

Permalink
odis load test with private key (#10551)
Browse files Browse the repository at this point in the history
* Refactor combiner

* Remove combiner timeouts

* fix lint

* fix combiner e2e tests

* point to published dependencies

* put auth behind flag

* fix config casing

* added memory allocation to function

* bump version

* bump combiner version

* switched to dev dependencies

* improve signer e2e tests

* add mainnet e2e command

* add privateKey param to loadTest script

* update context name

* add private key arg

* ++ logging

* with new PK

* fix addr bug

---------

Co-authored-by: Gaston Ponti <ponti@clabs.co>
Co-authored-by: soloseng <102702451+soloseng@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 11, 2023
1 parent c4d4791 commit 2cc7296
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
24 changes: 17 additions & 7 deletions packages/phone-number-privacy/monitor/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { genSessionID } from '@celo/phone-number-privacy-common/lib/utils/logger
import { normalizeAddressWith0x, privateKeyToAddress } from '@celo/utils/lib/address'
import { defined } from '@celo/utils/lib/sign-typed-data-utils'
import { LocalWallet } from '@celo/wallet-local'
import { ACCOUNT_ADDRESS, dekAuthSigner, generateRandomPhoneNumber, PRIVATE_KEY } from './resources'
import { dekAuthSigner, generateRandomPhoneNumber, PRIVATE_KEY } from './resources'

let phoneNumber = fetchEnv('PHONE_NUMBER')

Expand All @@ -33,7 +33,8 @@ export const queryOdisForSalt = async (
timeoutMs: number = 10000,
bypassQuota: boolean = false,
useDEK: boolean = false,
privateKey?: string
privateKey?: string,
privateKeyPercentage: number = 100
) => {
let authSigner: AuthSigner
let accountAddress: string
Expand All @@ -43,13 +44,18 @@ export const queryOdisForSalt = async (
const contractKit = newKit(blockchainProvider, new LocalWallet())

if (useDEK) {
accountAddress = ACCOUNT_ADDRESS
contractKit.connection.addAccount(privateKey ?? PRIVATE_KEY)
if (!privateKey || Math.random() > privateKeyPercentage * 0.01) {
privateKey = PRIVATE_KEY
}
contractKit.connection.addAccount(privateKey)
accountAddress = normalizeAddressWith0x(privateKeyToAddress(privateKey))
contractKit.defaultAccount = accountAddress
authSigner = dekAuthSigner(0)
phoneNumber = generateRandomPhoneNumber()
} else {
privateKey ??= await newPrivateKey()
if (!privateKey || Math.random() > privateKeyPercentage * 0.01) {
privateKey = await newPrivateKey()
}
accountAddress = normalizeAddressWith0x(privateKeyToAddress(privateKey))
contractKit.connection.addAccount(privateKey)
contractKit.defaultAccount = accountAddress
Expand Down Expand Up @@ -92,15 +98,19 @@ export const queryOdisForQuota = async (
blockchainProvider: string,
contextName: OdisContextName,
timeoutMs: number = 10000,
privateKey?: string
privateKey?: string,
privateKeyPercentage: number = 100
) => {
console.log(`contextName: ${contextName}`) // tslint:disable-line:no-console
console.log(`blockchain provider: ${blockchainProvider}`) // tslint:disable-line:no-console

const serviceContext = getServiceContext(contextName, OdisAPI.PNP)

const contractKit = newKit(blockchainProvider, new LocalWallet())
privateKey ??= await newPrivateKey()

if (!privateKey || Math.random() > privateKeyPercentage * 0.01) {
privateKey = await newPrivateKey()
}
const accountAddress = normalizeAddressWith0x(privateKeyToAddress(privateKey))
contractKit.connection.addAccount(privateKey)
contractKit.defaultAccount = accountAddress
Expand Down
4 changes: 2 additions & 2 deletions packages/phone-number-privacy/monitor/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
privateKeyToAddress,
} from '@celo/utils/lib/address'

export const PRIVATE_KEY = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
export const ACCOUNT_ADDRESS = normalizeAddressWith0x(privateKeyToAddress(PRIVATE_KEY)) // 0x1be31a94361a391bbafb2a4ccd704f57dc04d4bb
export const PRIVATE_KEY = '2c63bf6d60b16c8afa13e1069dbe92fef337c23855fff8b27732b3e9c6e7efd4'
export const ACCOUNT_ADDRESS = normalizeAddressWith0x(privateKeyToAddress(PRIVATE_KEY)) // 0x6037800e91eaa703e38bad40c01410bbdf0fea7e

interface DEK {
privateKey: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ yargs
.option('privateKey', {
type: 'string',
description: 'optional private key to send requests from',
})
.option('privateKeyPercentage', {
type: 'number',
description: 'percentage of time to use privateKey, if specified',
default: 100,
}),
(args) => {
if (args.rps == null || args.contextName == null) {
Expand Down Expand Up @@ -87,7 +92,8 @@ yargs
args.bypassQuota,
args.useDEK,
args.movingAvgRequests,
args.privateKey
args.privateKey,
args.privateKeyPercentage
) // tslint:disable-line:no-floating-promises
}
).argv
26 changes: 19 additions & 7 deletions packages/phone-number-privacy/monitor/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export async function testPNPSignQuery(
timeoutMs?: number,
bypassQuota?: boolean,
useDEK?: boolean,
privateKey?: string
privateKey?: string,
privateKeyPercentage: number = 100
) {
try {
const odisResponse: IdentifierHashDetails = await queryOdisForSalt(
Expand All @@ -25,7 +26,8 @@ export async function testPNPSignQuery(
timeoutMs,
bypassQuota,
useDEK,
privateKey
privateKey,
privateKeyPercentage
)
logger.debug({ odisResponse }, 'ODIS salt request successful. System is healthy.')
} catch (err) {
Expand All @@ -46,15 +48,17 @@ export async function testPNPQuotaQuery(
blockchainProvider: string,
contextName: OdisContextName,
timeoutMs?: number,
privateKey?: string
privateKey?: string,
privateKeyPercentage: number = 100
) {
logger.info(`Performing test PNP query for ${CombinerEndpointPNP.PNP_QUOTA}`)
try {
const odisResponse: PnpClientQuotaStatus = await queryOdisForQuota(
blockchainProvider,
contextName,
timeoutMs,
privateKey
privateKey,
privateKeyPercentage
)
logger.info({ odisResponse }, 'ODIS quota request successful. System is healthy.')
} catch (err) {
Expand Down Expand Up @@ -93,7 +97,8 @@ export async function concurrentRPSLoadTest(
bypassQuota: boolean = false,
useDEK: boolean = false,
movingAverageRequests: number = 50,
privateKey?: string
privateKey?: string,
privateKeyPercentage: number = 100
) {
const latencyQueue: number[] = []
let movingAvgLatencySum = 0
Expand Down Expand Up @@ -139,9 +144,16 @@ export async function concurrentRPSLoadTest(
undefined,
bypassQuota,
useDEK,
privateKey
privateKey,
privateKeyPercentage
)
: testPNPQuotaQuery(blockchainProvider, contextName, undefined, privateKey))
: testPNPQuotaQuery(
blockchainProvider,
contextName,
undefined,
privateKey,
privateKeyPercentage
))
} catch (_) {
logger.error('load test request failed')
}
Expand Down

0 comments on commit 2cc7296

Please sign in to comment.