harness: modernize some tests, temporarily disable revocation test

This commit is contained in:
Florian Dold 2023-08-25 11:22:52 +02:00
parent 6cc3fb3d04
commit 3d6cff9c84
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
8 changed files with 101 additions and 61 deletions

View File

@ -19,13 +19,12 @@
*/
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { defaultCoinConfig } from "../harness/denomStructures.js";
import { GlobalTestState, WalletCli } from "../harness/harness.js";
import { GlobalTestState } from "../harness/harness.js";
import {
makeTestPayment,
createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2,
makeTestPaymentV2,
createWalletDaemonWithClient,
makeTestPaymentV2,
withdrawViaBankV2,
} from "../harness/helpers.js";
/**
@ -59,7 +58,7 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) {
{
const walletClient = walletOne;
await withdrawViaBankV2(t, {
const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
@ -67,6 +66,8 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) {
restrictAge: 13,
});
await wres.withdrawalFinishedCond;
const order = {
summary: "Buy me!",
amount: "TESTKUDOS:5",
@ -82,7 +83,7 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) {
}
{
await withdrawViaBankV2(t, {
const wres = await withdrawViaBankV2(t, {
walletClient: walletTwo,
bank,
exchange,
@ -90,6 +91,9 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) {
restrictAge: 13,
});
await wres.withdrawalFinishedCond;
const order = {
summary: "Buy me!",
amount: "TESTKUDOS:5",
@ -101,13 +105,16 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) {
}
{
await withdrawViaBankV2(t, {
const wres = await withdrawViaBankV2(t, {
walletClient: walletThree,
bank,
exchange,
amount: "TESTKUDOS:20",
});
await wres.withdrawalFinishedCond;
const order = {
summary: "Buy me!",
amount: "TESTKUDOS:5",

View File

@ -18,12 +18,10 @@
* Imports.
*/
import { PreparePayResultType, TalerErrorCode } from "@gnu-taler/taler-util";
import { Wallet, WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState, MerchantPrivateApi } from "../harness/harness.js";
import {
createSimpleTestkudosEnvironment,
createSimpleTestkudosEnvironmentV2,
withdrawViaBank,
withdrawViaBankV2,
} from "../harness/helpers.js";
@ -35,7 +33,14 @@ export async function runDenomUnofferedTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
await withdrawViaBankV2(t, { walletClient, bank, exchange, amount: "TESTKUDOS:20" });
const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
await wres.withdrawalFinishedCond;
// Make the exchange forget the denomination.
// Effectively we completely reset the exchange,
@ -108,7 +113,12 @@ export async function runDenomUnofferedTest(t: GlobalTestState) {
});
// Now withdrawal should work again.
await withdrawViaBankV2(t, { walletClient, bank, exchange, amount: "TESTKUDOS:20" });
await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});

View File

@ -19,18 +19,18 @@
*/
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import {
GlobalTestState,
BankService,
ExchangeService,
GlobalTestState,
MerchantService,
setupDb,
WalletCli,
getPayto,
setupDb,
} from "../harness/harness.js";
import {
withdrawViaBank,
makeTestPayment,
SimpleTestEnvironment,
SimpleTestEnvironmentNg,
createWalletDaemonWithClient,
makeTestPaymentV2,
withdrawViaBankV2,
} from "../harness/helpers.js";
/**
@ -39,7 +39,7 @@ import {
*/
export async function createMyTestkudosEnvironment(
t: GlobalTestState,
): Promise<SimpleTestEnvironment> {
): Promise<SimpleTestEnvironmentNg> {
const db = await setupDb(t);
const bank = await BankService.create(t, {
@ -147,13 +147,19 @@ export async function createMyTestkudosEnvironment(
console.log("setup done!");
const wallet = new WalletCli(t);
const { walletClient, walletService } = await createWalletDaemonWithClient(
t,
{
name: "w1",
},
);
return {
commonDb: db,
exchange,
merchant,
wallet,
walletClient,
walletService,
bank,
exchangeBankAccount,
};
@ -165,19 +171,21 @@ export async function createMyTestkudosEnvironment(
export async function runFeeRegressionTest(t: GlobalTestState) {
// Set up test environment
const { wallet, bank, exchange, merchant } =
const { walletClient, bank, exchange, merchant } =
await createMyTestkudosEnvironment(t);
// Withdraw digital cash into the wallet.
await withdrawViaBank(t, {
wallet,
const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:1.92",
});
const coins = await wallet.client.call(WalletApiOperation.DumpCoins, {});
await wres.withdrawalFinishedCond;
const coins = await walletClient.call(WalletApiOperation.DumpCoins, {});
// Make sure we really withdraw one 0.64 and one 1.28 coin.
t.assertTrue(coins.coins.length === 2);
@ -188,11 +196,11 @@ export async function runFeeRegressionTest(t: GlobalTestState) {
fulfillment_url: "taler://fulfillment-success/thx",
};
await makeTestPayment(t, { wallet, merchant, order });
await makeTestPaymentV2(t, { walletClient, merchant, order });
await wallet.runUntilDone();
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
const txs = await wallet.client.call(WalletApiOperation.GetTransactions, {});
const txs = await walletClient.call(WalletApiOperation.GetTransactions, {});
t.assertAmountEquals(txs.transactions[1].amountEffective, "TESTKUDOS:1.30");
console.log(txs);
}

View File

@ -43,13 +43,15 @@ export async function runMerchantLongpollingTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
await withdrawViaBankV2(t, {
const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
await wres.withdrawalFinishedCond;
/**
* =========================================================================
* Create an order and let the wallet pay under a session ID

View File

@ -36,13 +36,15 @@ export async function runPaymentForgettableTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
await withdrawViaBankV2(t, {
const wres = await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
await wres.withdrawalFinishedCond;
{
const order = {
summary: "Buy me!",

View File

@ -24,10 +24,17 @@ import {
ConfirmPayResultType,
URL,
} from "@gnu-taler/taler-util";
import axiosImp from "axios";
const axios = axiosImp.default;
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { createSimpleTestkudosEnvironmentV2, withdrawViaBankV2 } from "../harness/helpers.js";
import {
createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2,
} from "../harness/helpers.js";
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
const httpLib = createPlatformHttpLib({
allowHttp: true,
enableThrottling: false,
});
/**
* Run test for basic, bank-integrated withdrawal.
@ -40,7 +47,12 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
await withdrawViaBankV2(t, { walletClient, bank, exchange, amount: "TESTKUDOS:20" });
await withdrawViaBankV2(t, {
walletClient,
bank,
exchange,
amount: "TESTKUDOS:20",
});
/**
* =========================================================================
@ -74,9 +86,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
t.assertTrue(orderStatus.already_paid_order_id === undefined);
let publicOrderStatusUrl = new URL(orderStatus.order_status_url);
let publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
validateStatus: () => true,
});
let publicOrderStatusResp = await httpLib.fetch(publicOrderStatusUrl.href);
if (publicOrderStatusResp.status != 402) {
throw Error(
@ -85,7 +95,7 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
}
let pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
publicOrderStatusResp.data,
publicOrderStatusResp.json(),
);
console.log(pubUnpaidStatus);
@ -102,10 +112,8 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
const proposalId = preparePayResp.proposalId;
console.log("requesting", publicOrderStatusUrl.href);
publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
validateStatus: () => true,
});
console.log("response body", publicOrderStatusResp.data);
publicOrderStatusResp = await httpLib.fetch(publicOrderStatusUrl.href);
console.log("response body", publicOrderStatusResp.json());
if (publicOrderStatusResp.status != 402) {
throw Error(
`expected status 402 (after claiming), but got ${publicOrderStatusResp.status}`,
@ -113,26 +121,20 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
}
pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
publicOrderStatusResp.data,
publicOrderStatusResp.json(),
);
const confirmPayRes = await walletClient.call(
WalletApiOperation.ConfirmPay,
{
const confirmPayRes = await walletClient.call(WalletApiOperation.ConfirmPay, {
proposalId: proposalId,
},
);
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
validateStatus: () => true,
});
console.log(publicOrderStatusResp.data);
t.assertTrue(confirmPayRes.type === ConfirmPayResultType.Done);
publicOrderStatusResp = await httpLib.fetch(publicOrderStatusUrl.href);
console.log(publicOrderStatusResp.json());
if (publicOrderStatusResp.status != 200) {
console.log(publicOrderStatusResp.data);
console.log(publicOrderStatusResp.json());
throw Error(
`expected status 200 (after paying), but got ${publicOrderStatusResp.status}`,
);
@ -229,19 +231,17 @@ export async function runPaywallFlowTest(t: GlobalTestState) {
console.log("requesting public status", publicOrderStatusUrl);
// Ask the order status of the claimed-but-unpaid order
publicOrderStatusResp = await axios.get(publicOrderStatusUrl.href, {
validateStatus: () => true,
});
publicOrderStatusResp = await httpLib.fetch(publicOrderStatusUrl.href);
if (publicOrderStatusResp.status != 402) {
throw Error(`expected status 402, but got ${publicOrderStatusResp.status}`);
}
pubUnpaidStatus = codecForMerchantOrderStatusUnpaid().decode(
publicOrderStatusResp.data,
publicOrderStatusResp.json(),
);
console.log(publicOrderStatusResp.data);
console.log(publicOrderStatusResp.json());
t.assertTrue(pubUnpaidStatus.already_paid_order_id === firstOrderId);
}

View File

@ -213,3 +213,4 @@ export async function runRevocationTest(t: GlobalTestState) {
runRevocationTest.timeoutMs = 120000;
runRevocationTest.suites = ["wallet"];
runRevocationTest.excludeByDefault = true;

View File

@ -0,0 +1,10 @@
// Work in progress.
// TS-based schema for the sandcastle configuration.
export interface SandcastleConfig {
currency: string;
merchant: {
apiKey: string;
baseUrl: string;
};
}