From 10996172e821a9948639ce49332cf338ae9ee727 Mon Sep 17 00:00:00 2001 From: Paul Puey Date: Fri, 29 Mar 2024 18:14:50 -0700 Subject: [PATCH] Use YOLO for testpartner script logins --- test/testconfig.ts | 8 +++++- test/testpartner.ts | 63 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/test/testconfig.ts b/test/testconfig.ts index 80312270..7297fa75 100644 --- a/test/testconfig.ts +++ b/test/testconfig.ts @@ -124,5 +124,11 @@ export const asTestConfig = asObject({ asObject({ appId: asOptional(asString, 'edge') }).withRest - ) + ), + YOLO_PASSWORD: asOptional(asString, null), + YOLO_USERNAME: asOptional(asString, null), + YOLO_PIN: asOptional(asString, null), + YOLO_OTPKEY: asOptional(asString), + YOLO_KEY: asOptional(asString, null), + YOLO_DUMP: asOptional(asBoolean, true) }).withRest diff --git a/test/testpartner.ts b/test/testpartner.ts index 9d3d71d2..1fbe3517 100644 --- a/test/testpartner.ts +++ b/test/testpartner.ts @@ -9,10 +9,13 @@ import { } from 'cleaners' import { addEdgeCorePlugins, + EdgeAccount, + EdgeContext, EdgeCurrencyWallet, EdgeSwapQuote, EdgeSwapRequest, lockEdgeCorePlugins, + makeEdgeContext, makeFakeEdgeWorld } from 'edge-core-js' import accountBasedPlugins from 'edge-currency-accountbased' @@ -73,9 +76,16 @@ async function main(): Promise { const loginKey = dump.loginKey const fakeUsers = [dump.data] - const world = await makeFakeEdgeWorld(fakeUsers, {}) - const context = await world.makeEdgeContext({ - allowNetworkAccess: true, + const { + YOLO_DUMP, + YOLO_KEY, + YOLO_PIN, + YOLO_PASSWORD, + YOLO_OTPKEY, + YOLO_USERNAME + } = config + + const contextOpts = { apiKey: '', appId: '', plugins: { @@ -86,16 +96,52 @@ async function main(): Promise { lifi: config.LIFI_INIT, polygon: config.POLYGON_INIT, piratechain: true, - thorchain: config.THORCHAIN_INIT + thorchain: config.THORCHAIN_INIT, + thorchainda: config.THORCHAIN_INIT } - }) + } + let account: EdgeAccount | undefined + let context: EdgeContext + if (YOLO_DUMP) { + const world = await makeFakeEdgeWorld(fakeUsers, {}) + context = await world.makeEdgeContext({ + ...contextOpts, + allowNetworkAccess: true + }) + account = await context.loginWithKey('bob', loginKey, { + pauseWallets: true + }) + } else { + context = await makeEdgeContext(contextOpts) + if (YOLO_USERNAME == null) { + throw new Error('No username') + } + if (YOLO_KEY != null) { + account = await context.loginWithKey(YOLO_USERNAME, YOLO_KEY, { + pauseWallets: true + }) + } else if (YOLO_PIN != null) { + account = await context.loginWithPIN(YOLO_USERNAME, YOLO_PIN, { + pauseWallets: true + }) + } else if (YOLO_PASSWORD != null) { + account = await context.loginWithPassword(YOLO_USERNAME, YOLO_PASSWORD, { + otpKey: YOLO_OTPKEY, + pauseWallets: true + }) + } + if (account == null) { + throw new Error('No account') + } + } await context.changeLogSettings({ defaultLogLevel: 'info', sources: {} }) - const account = await context.loginWithKey('bob', loginKey) + // const lk = await account.getLoginKey() + // console.log(`Login key: ${lk}`) const btcInfo = await account.getFirstWalletInfo('wallet:bitcoin') const bchInfo = await account.getFirstWalletInfo('wallet:bitcoincash') const ethInfo = await account.getFirstWalletInfo('wallet:ethereum') @@ -109,6 +155,8 @@ async function main(): Promise { const avaxWallet = await account.waitForCurrencyWallet(avaxInfo?.id ?? '') const arrrWallet = await account.waitForCurrencyWallet(arrrInfo?.id ?? '') const maticWallet = await account.waitForCurrencyWallet(maticInfo?.id ?? '') + await ethWallet.changePaused(false) + await avaxWallet.changePaused(false) const fetchQuote = async ({ fromWallet, @@ -151,6 +199,9 @@ async function main(): Promise { nativeAmount, quoteFor } + if (account == null) { + throw new Error('No account') + } const quote = await account.fetchSwapQuote(request).catch(e => { console.log(e) console.log(e.message)