Skip to content

Commit

Permalink
Use YOLO for testpartner script logins
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Mar 30, 2024
1 parent 72718ee commit 16269c7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- added: Login info to testconfig for testpartners.ts
- changed: Change Lifi and Thorchain DA to use variable quotes
- fixed: LiFi and Thorchain/DA memo handling

## 2.3.1 (2024-03-29)

- fixed: Use proper `EdgeMemo` API on `EdgeSpendInfo`
Expand Down
8 changes: 7 additions & 1 deletion test/testconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 57 additions & 6 deletions test/testpartner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -73,9 +76,16 @@ async function main(): Promise<void> {
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: {
Expand All @@ -86,16 +96,52 @@ async function main(): Promise<void> {
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')
Expand All @@ -109,6 +155,8 @@ async function main(): Promise<void> {
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,
Expand Down Expand Up @@ -151,6 +199,9 @@ async function main(): Promise<void> {
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)
Expand Down

0 comments on commit 16269c7

Please sign in to comment.