diff options
author | Sebastian <sebasjm@gmail.com> | 2023-11-05 00:53:53 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-11-05 00:53:53 -0300 |
commit | 31cf3187e447e2c4ec8a473362c5bacc07a874f1 (patch) | |
tree | 74e528b91eb313cf4d991410afda6ce905a218d6 /packages/taler-harness | |
parent | 78240f6c0f600f905f29e6dceb75286461297f24 (diff) | |
download | wallet-core-31cf3187e447e2c4ec8a473362c5bacc07a874f1.tar.xz |
exchange and merchant api
Diffstat (limited to 'packages/taler-harness')
-rw-r--r-- | packages/taler-harness/src/http-client/bank-core.ts | 244 | ||||
-rw-r--r-- | packages/taler-harness/src/index.ts | 79 |
2 files changed, 229 insertions, 94 deletions
diff --git a/packages/taler-harness/src/http-client/bank-core.ts b/packages/taler-harness/src/http-client/bank-core.ts index ccefd2bfe..9919fc0a7 100644 --- a/packages/taler-harness/src/http-client/bank-core.ts +++ b/packages/taler-harness/src/http-client/bank-core.ts @@ -1,8 +1,8 @@ -import { AccessToken, Amounts, TalerCoreBankHttpClient, TalerCorebankApi, TestForApi, buildPayto, encodeCrock, failOrThrow, getRandomBytes, parsePaytoUri, stringifyPaytoUri, succeedOrThrow } from "@gnu-taler/taler-util" +import { AccessToken, AmountJson, Amounts, TalerCoreBankHttpClient, TalerCorebankApi, TalerRevenueHttpClient, TalerWireGatewayApi, TalerWireGatewayHttpClient, TestForApi, buildPayto, encodeCrock, failOrThrow, getRandomBytes, parsePaytoUri, stringifyPaytoUri, succeedOrThrow } from "@gnu-taler/taler-util" -export function createTestForBankCore(adminToken: AccessToken): TestForApi<TalerCoreBankHttpClient> { +export function createTestForBankCore(api: TalerCoreBankHttpClient, adminToken: AccessToken): TestForApi<TalerCoreBankHttpClient> { return { test_abortCashoutById: { success: undefined, @@ -46,17 +46,17 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler success: undefined, }, test_abortWithdrawalById: { - "invalid-id": async (api) => { + "invalid-id": async () => { await failOrThrow("invalid-id", () => api.abortWithdrawalById("invalid") ) }, - "not-found": async (api) => { + "not-found": async () => { await failOrThrow("not-found", () => api.abortWithdrawalById("11111111-1111-1111-1111-111111111111") ) }, - "previously-confirmed": async (api) => { + "previously-confirmed": async () => { const { username: exchangeUser, token: exchangeToken } = await createRandomTestUser(api, adminToken, { is_taler_exchange: true }) const { username, token } = await createRandomTestUser(api, adminToken) @@ -86,7 +86,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler api.abortWithdrawalById(withdrawal_id) ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => @@ -105,15 +105,15 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_confirmWithdrawalById: { - "insufficient-funds": async (api) => { + "insufficient-funds": async () => { }, - "invalid-id": async (api) => { + "invalid-id": async () => { await failOrThrow("invalid-id", () => api.confirmWithdrawalById("invalid") ) }, - "no-exchange-or-reserve-selected": async (api) => { + "no-exchange-or-reserve-selected": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => @@ -130,12 +130,12 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler api.confirmWithdrawalById(withdrawal_id) ) }, - "not-found": async (api) => { + "not-found": async () => { await failOrThrow("not-found", () => api.confirmWithdrawalById("11111111-1111-1111-1111-111111111111") ) }, - "previously-aborted": async (api) => { + "previously-aborted": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => api.getAccount({ username, token }) @@ -153,7 +153,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler api.confirmWithdrawalById(withdrawal_id) ) }, - success: async (api) => { + success: async () => { const { username: exchangeUser, token: exchangeToken } = await createRandomTestUser(api, adminToken, { is_taler_exchange: true }) const { username, token } = await createRandomTestUser(api, adminToken) @@ -185,7 +185,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, test_createAccount: { "insufficient-funds": undefined, - "payto-already-exists": async (api) => { + "payto-already-exists": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => @@ -203,7 +203,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ); }, - "username-reserved": async (api) => { + "username-reserved": async () => { await failOrThrow("username-reserved", () => api.createAccount(adminToken, { name: "admin", @@ -211,7 +211,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - "username-already-exists": async (api) => { + "username-already-exists": async () => { const username = "harness-" + encodeCrock(getRandomBytes(10)).toLowerCase(); await succeedOrThrow(() => api.createAccount(adminToken, { @@ -227,7 +227,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ); }, - "invalid-phone-or-email": async (api) => { + "invalid-phone-or-email": async () => { const username = "harness-" + encodeCrock(getRandomBytes(10)).toLowerCase(); await failOrThrow("invalid-input", () => api.createAccount(adminToken, { @@ -240,7 +240,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - success: async (api) => { + success: async () => { const username = "harness-" + encodeCrock(getRandomBytes(10)).toLowerCase(); await succeedOrThrow(() => @@ -250,7 +250,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - unauthorized: async (api) => { + unauthorized: async () => { const username = "harness-" + encodeCrock(getRandomBytes(10)).toLowerCase(); await succeedOrThrow(() => @@ -278,7 +278,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, test_createTransaction: { - "creditor-not-found": async (api) => { + "creditor-not-found": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => @@ -294,7 +294,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - "creditor-same": async (api) => { + "creditor-same": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => @@ -311,7 +311,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - "insufficient-funds": async (api) => { + "insufficient-funds": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const { username: otherUser, token: otherToken } = await createRandomTestUser(api, adminToken) @@ -331,7 +331,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - "not-found": async (api) => { + "not-found": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const { username: otherUser, token: otherToken } = await createRandomTestUser(api, adminToken) @@ -351,7 +351,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - "invalid-input": async (api) => { + "invalid-input": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const { username: otherUser, token: otherToken } = await createRandomTestUser(api, adminToken) @@ -380,7 +380,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) const { username: otherUser, token: otherToken } = await createRandomTestUser(api, adminToken) @@ -401,7 +401,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - unauthorized: async (api) => { + unauthorized: async () => { const { username, token } = await createRandomTestUser(api, adminToken) const { username: otherUser, token: otherToken } = await createRandomTestUser(api, adminToken) @@ -423,7 +423,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_createWithdrawal: { - "account-not-found": async (api) => { + "account-not-found": async () => { const userInfo = await succeedOrThrow(() => api.getAccount({ username: "admin", token: adminToken }) ) @@ -434,7 +434,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - "insufficient-funds": async (api) => { + "insufficient-funds": async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => api.getAccount({ username, token }) @@ -448,7 +448,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => api.getAccount({ username, token }) @@ -460,7 +460,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - unauthorized: async (api) => { + unauthorized: async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => api.getAccount({ username, token }) @@ -474,7 +474,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_deleteAccount: { - "balance-not-zero": async (api) => { + "balance-not-zero": async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("balance-not-zero", () => @@ -482,12 +482,12 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - "not-found": async (api) => { + "not-found": async () => { await failOrThrow("not-found", () => api.deleteAccount({ username: "not-found", token: adminToken }) ) }, - "username-reserved": async (api) => { + "username-reserved": async () => { await failOrThrow("username-reserved", () => api.deleteAccount({ username: "admin", token: adminToken }) ) @@ -495,7 +495,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler api.deleteAccount({ username: "bank", token: adminToken }) ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => @@ -518,7 +518,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - unauthorized: async (api) => { + unauthorized: async () => { const username = "harness-" + encodeCrock(getRandomBytes(10)).toLowerCase(); await succeedOrThrow(() => @@ -536,19 +536,19 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_getAccount: { - "not-found": async (api) => { + "not-found": async () => { await failOrThrow("not-found", () => api.getAccount({ username: "not-found", token: adminToken }) ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) await succeedOrThrow(() => api.getAccount({ username, token }) ) }, - unauthorized: async (api) => { + unauthorized: async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("unauthorized", () => api.getAccount({ username, token: "wrongtoken" as AccessToken }) @@ -556,7 +556,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_getAccounts: { - success: async (api) => { + success: async () => { await succeedOrThrow(() => api.getAccounts(adminToken) ) @@ -573,14 +573,14 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - unauthorized: async (api) => { + unauthorized: async () => { await failOrThrow("unauthorized", () => api.getAccounts("ASDASD" as AccessToken) ) }, }, test_getConfig: { - success: async (api) => { + success: async () => { const config = await succeedOrThrow(() => api.getConfig()) if (!api.isCompatible(config.version)) { @@ -590,13 +590,13 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_getMonitor: { - "unauthorized": async (api) => { + "unauthorized": async () => { await failOrThrow("unauthorized", () => ( api.getMonitor("wrongtoken" as AccessToken) )) }, - "invalid-input": async (api) => { + "invalid-input": async () => { await failOrThrow("invalid-input", () => ( api.getMonitor(adminToken, { @@ -607,7 +607,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, "monitor-not-supported": undefined, - success: async (api) => { + success: async () => { await succeedOrThrow(() => ( api.getMonitor(adminToken) @@ -623,7 +623,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_getPublicAccounts: { - success: async (api) => { + success: async () => { await succeedOrThrow(() => ( api.getPublicAccounts() )) @@ -646,13 +646,13 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_getTransactionById: { - "not-found": async (api) => { + "not-found": async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("not-found", () => api.getTransactionById({ username, token }, 123123123) ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) const { username: otherUser, token: otherToken } = await createRandomTestUser(api, adminToken) @@ -683,7 +683,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - unauthorized: async (api) => { + unauthorized: async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("unauthorized", () => api.getTransactionById({ username, token: "wrongtoken" as AccessToken }, 123123123) @@ -691,13 +691,13 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_getTransactions: { - "not-found": async (api) => { + "not-found": async () => { await failOrThrow("not-found", () => api.getTransactions({ username: "not-found", token: adminToken, })) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) // await succeedOrThrow(() => api.getTransactions(creds)) const txs = await succeedOrThrow(() => api.getTransactions({ username, token }, { @@ -705,7 +705,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler order: "asc" })) }, - unauthorized: async (api) => { + unauthorized: async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("unauthorized", () => api.getTransactions({ @@ -716,20 +716,20 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_getWithdrawalById: { - "invalid-id": async (api) => { + "invalid-id": async () => { await failOrThrow("invalid-id", () => api.getWithdrawalById("invalid") ) }, - "not-found": async (api) => { + "not-found": async () => { await failOrThrow("not-found", () => api.getWithdrawalById("11111111-1111-1111-1111-111111111111") ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) const userInfo = await succeedOrThrow(() => api.getAccount({ username, token }) @@ -745,7 +745,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_updateAccount: { - "cant-change-legal-name-or-admin": async (api) => { + "cant-change-legal-name-or-admin": async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("cant-change-legal-name-or-admin", () => @@ -755,7 +755,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - "not-found": async (api) => { + "not-found": async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("not-found", () => api.updateAccount({ username: "notfound", token }, { @@ -765,7 +765,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }) ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) await succeedOrThrow(() => @@ -777,7 +777,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - unauthorized: async (api) => { + unauthorized: async () => { await failOrThrow("unauthorized", () => api.updateAccount({ username: "notfound", token: "wrongtoken" as AccessToken }, { @@ -789,7 +789,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, }, test_updatePassword: { - "not-found": async (api) => { + "not-found": async () => { await failOrThrow("not-found", () => api.updatePassword({ username: "notfound", token: adminToken }, { @@ -800,7 +800,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, - "old-password-invalid-or-not-allowed": async (api) => { + "old-password-invalid-or-not-allowed": async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("old-password-invalid-or-not-allowed", () => @@ -811,7 +811,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler ) }, - success: async (api) => { + success: async () => { const { username, token } = await createRandomTestUser(api, adminToken) await succeedOrThrow(() => @@ -823,7 +823,7 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler }, - unauthorized: async (api) => { + unauthorized: async () => { const { username, token } = await createRandomTestUser(api, adminToken) await failOrThrow("unauthorized", () => api.updatePassword({ username: "admin", token }, { @@ -838,6 +838,128 @@ export function createTestForBankCore(adminToken: AccessToken): TestForApi<Taler } } +export function createTestForBankRevenue(bank: TalerCoreBankHttpClient, adminToken: AccessToken): TestForApi<TalerRevenueHttpClient> { + + return { + test_getHistory: { + "endpoint-wrong-or-username-wrong": async () => { + const history = await failOrThrow("endpoint-wrong-or-username-wrong", () => + bank.getRevenueAPI("notfound").getHistory("wrongtoken" as AccessToken) + ) + }, + "invalid-input": undefined, + success: async () => { + const { token: exchangeToken, username: exchangeUsername } = await createRandomTestUser(bank, adminToken, { + is_taler_exchange: true + }) + const { token: merchantToken, username: merchantUsername } = await createRandomTestUser(bank, adminToken) + const config = await succeedOrThrow(() => bank.getConfig()) + + const merchantinfo = await succeedOrThrow(() => + bank.getAccount({ username: merchantUsername, token: merchantToken }) + ) + const account = parsePaytoUri(merchantinfo.payto_uri)! + account.params["message"] = "all" + + const amount = Amounts.stringify({ + currency: config.currency.name, + fraction: 0, + value: 1 + }) + + await succeedOrThrow(() => + bank.createTransaction({ username: exchangeUsername, token: exchangeToken }, { + payto_uri: stringifyPaytoUri(account), + amount + }) + ) + const history = await succeedOrThrow(() => + bank.getRevenueAPI(merchantUsername).getHistory(merchantToken) + ) + }, + unauthorized: async () => { + const { token: merchantToken, username: merchantUsername } = await createRandomTestUser(bank, adminToken) + const history = await failOrThrow("unauthorized", () => + bank.getRevenueAPI(merchantUsername).getHistory("wrongtoken" as AccessToken) + ) + }, + } + } +} + +export function createTestForBankWireGateway(bank: TalerCoreBankHttpClient, adminToken: AccessToken): TestForApi<TalerWireGatewayHttpClient> { + return { + //not used in production + test_addIncoming: { + "invalid-input": undefined, + "not-found": undefined, + "reserve-id-already-used": undefined, + success: undefined, + unauthorized: undefined, + }, + test_getHistoryIncoming: { + "invalid-input": async () => { + }, + "not-found": async () => { + }, + success: async () => { + }, + unauthorized: async () => { + }, + }, + test_getHistoryOutgoing: { + "invalid-input": async () => { + }, + "not-found": async () => { + }, + success: async () => { + }, + unauthorized: async () => { + }, + }, + test_transfer: { + "invalid-input": async () => { + }, + "not-found": async () => { + }, + "request-uid-already-used": async () => { + }, + success: async () => { + const { token: exchangeToken, username: exchangeUsername } = await createRandomTestUser(bank, adminToken, { + is_taler_exchange: true + }) + const { token: merchantToken, username: merchantUsername } = await createRandomTestUser(bank, adminToken) + const config = await succeedOrThrow(() => bank.getConfig()) + + const merchantInfo = await succeedOrThrow(() => + bank.getAccount({ username: merchantUsername, token: merchantToken }) + ) + const account = parsePaytoUri(merchantInfo.payto_uri)! + account.params["message"] = "all" + + const amount = Amounts.stringify({ + currency: config.currency.name, + fraction: 0, + value: 1 + }) + const resp = await succeedOrThrow(() => + bank.getWireGatewayAPI(merchantUsername).transfer(exchangeToken, { + amount, + credit_account: merchantInfo.payto_uri, + exchange_base_url: "", + request_uid: "", + wtid: "" + }) + ) + + }, + unauthorized: async () => { + }, + } + } +} + + export async function createRandomTestUser(api: TalerCoreBankHttpClient, adminToken: AccessToken, options: Partial<TalerCorebankApi.RegisterAccountRequest> = {}) { const username = "harness-" + encodeCrock(getRandomBytes(10)).toLowerCase(); await succeedOrThrow(() => diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index af4e5c788..5bf60d54f 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -30,6 +30,7 @@ import { TalerCoreBankHttpClient, TalerCorebankApiClient, TalerError, + TestForApi, addPaytoQueryParams, decodeCrock, generateIban, @@ -656,12 +657,46 @@ deploymentCli process.exit(2); }); + +type TestResult = { testName: string, caseName: string, result: "skiped" | "ok" | "fail", error?: any } + +async function getTestSummary<T extends object>(filter: string | undefined, ...apis: Array<TestForApi<T>>) { + const regex = !filter ? undefined : new RegExp(filter) + const apiState = await Promise.all(apis.flatMap(api => Object.entries(api).flatMap(([testName, casesMap]) => { + return Object.entries(casesMap).map(async ([caseName, caseFunc]): Promise<TestResult> => { + if (!caseFunc) { + return { testName, caseName, result: "skiped" as const } + } + if (regex && !regex.test(`${testName}:${caseName}`)) { + return { testName, caseName, result: "skiped" as const } + } + return caseFunc() + .then(r => ({ testName, caseName, result: "ok" as const })) + .catch(error => ({ testName, caseName, result: "fail" as const, error })) + }) + }))) + + return apiState.reduce((prev, testResult) => { + if (testResult.result === "ok") { + prev.ok.push(testResult) + } + if (testResult.result === "skiped") { + prev.skiped.push(testResult) + } + if (testResult.result === "fail") { + prev.fail.push(testResult) + } + return prev + }, { "ok": [] as TestResult[], "skiped": [] as TestResult[], "fail": [] as TestResult[] }) +} + deploymentCli .subcommand("testBankAPI", "test-bank-api", { help: "test api compatibility.", }) .requiredArgument("corebankApiBaseUrl", clk.STRING) .maybeOption("adminPwd", ["--admin-password"], clk.STRING) + .maybeOption("filter", ["--filter"], clk.STRING) .flag("showCurl", ["--show-curl"]) .action(async (args) => { const httpLib = createPlatformHttpLib(); @@ -685,55 +720,33 @@ deploymentCli scope: "readwrite" }) + if (args.testBankAPI.showCurl) { + setPrintHttpRequestAsCurl(true) + } + if (resp.type === "fail") { console.log("wrong admin password") return; } - const tester = createTestForBankCore(resp.body.access_token) - if (args.testBankAPI.showCurl) { - setPrintHttpRequestAsCurl(true) - } + const bankCore = createTestForBankCore(api, resp.body.access_token) - const apiState = await Promise.all(Object.entries(tester).flatMap(([testName, casesMap]) => { - return Object.entries(casesMap).map(([caseName, caseFunc]) => { - if (!caseFunc) { - return { testName, caseName, result: "skiped" as const } - } - return caseFunc(api) - .then(r => ({ testName, caseName, result: "ok" as const })) - .catch(error => ({ testName, caseName, result: "fail" as const, error })) - }) - })) - - const total = apiState.reduce((prev, testResult) => { - if (testResult.result === "ok") { - prev.ok += 1 - } - if (testResult.result === "skiped") { - prev.skiped += 1 - } - if (testResult.result === "fail") { - prev.fail += 1 - } - return prev - }, { "ok": 0, "skiped": 0, "fail": 0 }) + const summary = await getTestSummary(args.testBankAPI.filter, bankCore) - console.log("successful tests:", total.ok) - console.log("uncompleted tests:", total.skiped) - apiState.forEach((testResult) => { + console.log("successful tests:", summary.ok.length) + console.log("uncompleted tests:", summary.skiped.length) + summary.skiped.forEach((testResult) => { if (testResult.result === "skiped") { console.log(" ", testResult.testName, testResult.caseName) } }) - console.log("failed tests:", total.fail) - apiState.filter(t => t.result === "fail").forEach((testResult, i) => { + console.log("failed tests:", summary.fail.length) + summary.fail.forEach((testResult, i) => { console.log(i, ")", testResult) }) }); - deploymentCli .subcommand("coincfg", "gen-coin-config", { help: "Generate a coin/denomination configuration for the exchange.", |