wallet-core,harness: get p2p tests to pass again
This commit is contained in:
parent
1ad2f4cbe9
commit
557213f9c4
@ -89,6 +89,8 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) {
|
||||
console.log(resp);
|
||||
}
|
||||
|
||||
await w1.walletClient.call(WalletApiOperation.TestingWaitRefreshesFinal, {});
|
||||
|
||||
const resp = await w1.walletClient.call(
|
||||
WalletApiOperation.InitiatePeerPushDebit,
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ import {
|
||||
TestPayResult,
|
||||
TransactionMajorState,
|
||||
TransactionMinorState,
|
||||
TransactionType,
|
||||
WithdrawTestBalanceRequest,
|
||||
} from "@gnu-taler/taler-util";
|
||||
import {
|
||||
@ -498,6 +499,59 @@ export async function waitUntilDone(ws: InternalWalletState): Promise<void> {
|
||||
logger.info("done waiting until all transactions are in a final state");
|
||||
}
|
||||
|
||||
export async function waitUntilRefreshesDone(
|
||||
ws: InternalWalletState,
|
||||
): Promise<void> {
|
||||
logger.info("waiting until all refresh transactions are in a final state");
|
||||
ws.ensureTaskLoopRunning();
|
||||
let p: OpenedPromise<void> | undefined = undefined;
|
||||
const cancelNotifs = ws.addNotificationListener((notif) => {
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
if (notif.type === NotificationType.TransactionStateTransition) {
|
||||
switch (notif.newTxState.major) {
|
||||
case TransactionMajorState.Pending:
|
||||
case TransactionMajorState.Aborting:
|
||||
break;
|
||||
default:
|
||||
p.resolve();
|
||||
}
|
||||
}
|
||||
});
|
||||
while (1) {
|
||||
p = openPromise();
|
||||
const txs = await getTransactions(ws, {
|
||||
includeRefreshes: true,
|
||||
filterByState: "nonfinal",
|
||||
});
|
||||
let finished = true;
|
||||
for (const tx of txs.transactions) {
|
||||
if (tx.type !== TransactionType.Refresh) {
|
||||
continue;
|
||||
}
|
||||
switch (tx.txState.major) {
|
||||
case TransactionMajorState.Pending:
|
||||
case TransactionMajorState.Aborting:
|
||||
case TransactionMajorState.Suspended:
|
||||
case TransactionMajorState.SuspendedAborting:
|
||||
finished = false;
|
||||
logger.info(
|
||||
`continuing waiting, ${tx.transactionId} in ${tx.txState.major}(${tx.txState.minor})`,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (finished) {
|
||||
break;
|
||||
}
|
||||
// Wait until transaction state changed
|
||||
await p.promise;
|
||||
}
|
||||
cancelNotifs();
|
||||
logger.info("done waiting until all refreshes are in a final state");
|
||||
}
|
||||
|
||||
async function waitUntilPendingReady(
|
||||
ws: InternalWalletState,
|
||||
transactionId: string,
|
||||
|
@ -945,6 +945,9 @@ function greedySelectPeer(
|
||||
denom.feeDeposit,
|
||||
);
|
||||
tally.amountAcc = Amounts.add(tally.amountAcc, coinSpend).amount;
|
||||
// Since this is a peer payment, there is no merchant to
|
||||
// potentially cover the deposit fees.
|
||||
tally.amountAcc = Amounts.sub(tally.amountAcc, denom.feeDeposit).amount;
|
||||
tally.depositFeesAcc = Amounts.add(
|
||||
tally.depositFeesAcc,
|
||||
denom.feeDeposit,
|
||||
|
@ -212,6 +212,7 @@ export enum WalletApiOperation {
|
||||
ApplyDevExperiment = "applyDevExperiment",
|
||||
ValidateIban = "validateIban",
|
||||
TestingWaitTransactionsFinal = "testingWaitTransactionsFinal",
|
||||
TestingWaitRefreshesFinal = "testingWaitRefreshesFinal",
|
||||
GetScopedCurrencyInfo = "getScopedCurrencyInfo",
|
||||
}
|
||||
|
||||
@ -976,6 +977,15 @@ export type TestingWaitTransactionsFinal = {
|
||||
response: EmptyObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wait until all refresh transactions are in a final state.
|
||||
*/
|
||||
export type TestingWaitRefreshesFinal = {
|
||||
op: WalletApiOperation.TestingWaitRefreshesFinal;
|
||||
request: EmptyObject;
|
||||
response: EmptyObject;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set a coin as (un-)suspended.
|
||||
* Suspended coins won't be used for payments.
|
||||
@ -1080,6 +1090,7 @@ export type WalletOperations = {
|
||||
[WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp;
|
||||
[WalletApiOperation.ValidateIban]: ValidateIbanOp;
|
||||
[WalletApiOperation.TestingWaitTransactionsFinal]: TestingWaitTransactionsFinal;
|
||||
[WalletApiOperation.TestingWaitRefreshesFinal]: TestingWaitRefreshesFinal;
|
||||
[WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp;
|
||||
};
|
||||
|
||||
|
@ -247,6 +247,7 @@ import {
|
||||
runIntegrationTest2,
|
||||
testPay,
|
||||
waitUntilDone,
|
||||
waitUntilRefreshesDone,
|
||||
withdrawTestBalance,
|
||||
} from "./operations/testing.js";
|
||||
import {
|
||||
@ -1586,6 +1587,8 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
|
||||
}
|
||||
case WalletApiOperation.TestingWaitTransactionsFinal:
|
||||
return await waitUntilDone(ws);
|
||||
case WalletApiOperation.TestingWaitRefreshesFinal:
|
||||
return await waitUntilRefreshesDone(ws);
|
||||
// default:
|
||||
// assertUnreachable(operation);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user