aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-harness/src
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-11-21 19:35:26 +0100
committerFlorian Dold <florian@dold.me>2024-11-21 19:37:04 +0100
commit3090d60068a6a4a3441fd0e6481190a03c407847 (patch)
tree76367fe58cdda6512c0d76e884546c7a3ed616b6 /packages/taler-harness/src
parent89a6f069a93a109525de114e3dea6ec1823b5fb8 (diff)
harness: extend test-kyc-decision to provoke exchange crash
Diffstat (limited to 'packages/taler-harness/src')
-rw-r--r--packages/taler-harness/src/integrationtests/test-kyc-decisions.ts129
1 files changed, 126 insertions, 3 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-kyc-decisions.ts b/packages/taler-harness/src/integrationtests/test-kyc-decisions.ts
index 16c2d3f71..fbb8f7958 100644
--- a/packages/taler-harness/src/integrationtests/test-kyc-decisions.ts
+++ b/packages/taler-harness/src/integrationtests/test-kyc-decisions.ts
@@ -18,20 +18,34 @@
* Imports.
*/
import {
+ AccountKycStatus,
+ codecForAccountKycStatus,
+ codecForKycProcessClientInformation,
Configuration,
Duration,
encodeCrock,
- hashFullPaytoUri,
hashNormalizedPaytoUri,
+ j2s,
TalerProtocolTimestamp,
+ TransactionMajorState,
+ TransactionMinorState,
+ WireGatewayApiClient,
} from "@gnu-taler/taler-util";
+import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
+import {
+ createSyncCryptoApi,
+ WalletApiOperation,
+} from "@gnu-taler/taler-wallet-core";
import {
createKycTestkudosEnvironment,
postAmlDecision,
+ withdrawViaBankV3,
} from "../harness/environments.js";
import {
getTestHarnessPaytoForLabel,
GlobalTestState,
+ harnessHttpLib,
+ waitMs,
} from "../harness/harness.js";
function adjustExchangeConfig(config: Configuration) {
@@ -54,13 +68,47 @@ function adjustExchangeConfig(config: Configuration) {
export async function runKycDecisionsTest(t: GlobalTestState) {
// Set up test environment
- const { walletClient, bankClient, exchange, amlKeypair, merchant } =
- await createKycTestkudosEnvironment(t, { adjustExchangeConfig });
+ // FIXME: Reduced test environment without merchant suffices
+ const {
+ walletClient,
+ bankClient,
+ exchange,
+ amlKeypair,
+ exchangeBankAccount,
+ } = await createKycTestkudosEnvironment(t, { adjustExchangeConfig });
const merchantPayto = getTestHarnessPaytoForLabel("merchant-default");
+ const cryptoApi = createSyncCryptoApi();
+
+ const wireGatewayApiClient = new WireGatewayApiClient(
+ exchangeBankAccount.wireGatewayApiBaseUrl,
+ {
+ auth: {
+ username: exchangeBankAccount.accountName,
+ password: exchangeBankAccount.accountPassword,
+ },
+ },
+ );
+
+ const merchantPair = await cryptoApi.createEddsaKeypair({});
+
+ const sigResp = await cryptoApi.signWalletKycAuth({
+ accountPriv: merchantPair.priv,
+ accountPub: merchantPair.pub,
+ });
+
const kycPaytoHash = encodeCrock(hashNormalizedPaytoUri(merchantPayto));
+ const wres = await withdrawViaBankV3(t, {
+ walletClient,
+ exchange,
+ bankClient,
+ amount: "TESTKUDOS:20",
+ });
+
+ await wres.withdrawalFinishedCond;
+
// Make a decision where the exchange doesn't know the account yet.
await postAmlDecision(t, {
amlPriv: amlKeypair.priv,
@@ -76,6 +124,7 @@ export async function runKycDecisionsTest(t: GlobalTestState) {
{
operation_type: "DEPOSIT",
display_priority: 1,
+ exposed: true,
measures: ["verboten"],
threshold: "TESTKUDOS:10",
timeframe: Duration.toTalerProtocolDuration(
@@ -84,9 +133,83 @@ export async function runKycDecisionsTest(t: GlobalTestState) {
}),
),
},
+ {
+ operation_type: "WITHDRAW",
+ display_priority: 1,
+ exposed: true,
+ measures: ["verboten"],
+ threshold: "TESTKUDOS:0",
+ timeframe: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({
+ days: 1,
+ }),
+ ),
+ },
],
},
});
+
+ const dgRes = await walletClient.call(WalletApiOperation.CreateDepositGroup, {
+ amount: "TESTKUDOS:15",
+ depositPaytoUri: merchantPayto,
+ testingFixedPriv: merchantPair.priv,
+ });
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: dgRes.transactionId,
+ txState: {
+ major: TransactionMajorState.Pending,
+ minor: TransactionMinorState.KycAuthRequired,
+ },
+ });
+
+ await wireGatewayApiClient.adminAddKycauth({
+ amount: "TESTKUDOS:0.1",
+ debitAccountPayto: merchantPayto,
+ accountPub: merchantPair.pub,
+ });
+
+ let checkResp: AccountKycStatus | undefined;
+
+ while (1) {
+ let checkHttpResp = await harnessHttpLib.fetch(
+ new URL(`kyc-check/${kycPaytoHash}`, exchange.baseUrl).href,
+ {
+ headers: {
+ ["Account-Owner-Signature"]: sigResp.sig,
+ },
+ },
+ );
+
+ console.log(`status: ${checkHttpResp.status}`);
+
+ if (checkHttpResp.status == 409) {
+ await waitMs(200);
+ continue;
+ }
+
+ checkResp = await readSuccessResponseJsonOrThrow(
+ checkHttpResp,
+ codecForAccountKycStatus(),
+ );
+
+ break;
+ }
+
+ t.assertTrue(!!checkResp);
+
+ console.log(j2s(checkResp));
+
+ let infoHttpResp = await harnessHttpLib.fetch(
+ new URL(`kyc-info/${checkResp.access_token}`, exchange.baseUrl).href,
+ );
+ t.assertDeepEqual(infoHttpResp.status, 200);
+ const infoResp = await readSuccessResponseJsonOrThrow(
+ infoHttpResp,
+ codecForKycProcessClientInformation(),
+ );
+
+ console.log(j2s(infoResp));
}
runKycDecisionsTest.suites = ["wallet"];