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);
|
console.log(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await w1.walletClient.call(WalletApiOperation.TestingWaitRefreshesFinal, {});
|
||||||
|
|
||||||
const resp = await w1.walletClient.call(
|
const resp = await w1.walletClient.call(
|
||||||
WalletApiOperation.InitiatePeerPushDebit,
|
WalletApiOperation.InitiatePeerPushDebit,
|
||||||
{
|
{
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
TestPayResult,
|
TestPayResult,
|
||||||
TransactionMajorState,
|
TransactionMajorState,
|
||||||
TransactionMinorState,
|
TransactionMinorState,
|
||||||
|
TransactionType,
|
||||||
WithdrawTestBalanceRequest,
|
WithdrawTestBalanceRequest,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
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");
|
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(
|
async function waitUntilPendingReady(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
transactionId: string,
|
transactionId: string,
|
||||||
|
@ -945,6 +945,9 @@ function greedySelectPeer(
|
|||||||
denom.feeDeposit,
|
denom.feeDeposit,
|
||||||
);
|
);
|
||||||
tally.amountAcc = Amounts.add(tally.amountAcc, coinSpend).amount;
|
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 = Amounts.add(
|
||||||
tally.depositFeesAcc,
|
tally.depositFeesAcc,
|
||||||
denom.feeDeposit,
|
denom.feeDeposit,
|
||||||
|
@ -212,6 +212,7 @@ export enum WalletApiOperation {
|
|||||||
ApplyDevExperiment = "applyDevExperiment",
|
ApplyDevExperiment = "applyDevExperiment",
|
||||||
ValidateIban = "validateIban",
|
ValidateIban = "validateIban",
|
||||||
TestingWaitTransactionsFinal = "testingWaitTransactionsFinal",
|
TestingWaitTransactionsFinal = "testingWaitTransactionsFinal",
|
||||||
|
TestingWaitRefreshesFinal = "testingWaitRefreshesFinal",
|
||||||
GetScopedCurrencyInfo = "getScopedCurrencyInfo",
|
GetScopedCurrencyInfo = "getScopedCurrencyInfo",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -976,6 +977,15 @@ export type TestingWaitTransactionsFinal = {
|
|||||||
response: EmptyObject;
|
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.
|
* Set a coin as (un-)suspended.
|
||||||
* Suspended coins won't be used for payments.
|
* Suspended coins won't be used for payments.
|
||||||
@ -1080,6 +1090,7 @@ export type WalletOperations = {
|
|||||||
[WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp;
|
[WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp;
|
||||||
[WalletApiOperation.ValidateIban]: ValidateIbanOp;
|
[WalletApiOperation.ValidateIban]: ValidateIbanOp;
|
||||||
[WalletApiOperation.TestingWaitTransactionsFinal]: TestingWaitTransactionsFinal;
|
[WalletApiOperation.TestingWaitTransactionsFinal]: TestingWaitTransactionsFinal;
|
||||||
|
[WalletApiOperation.TestingWaitRefreshesFinal]: TestingWaitRefreshesFinal;
|
||||||
[WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp;
|
[WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -247,6 +247,7 @@ import {
|
|||||||
runIntegrationTest2,
|
runIntegrationTest2,
|
||||||
testPay,
|
testPay,
|
||||||
waitUntilDone,
|
waitUntilDone,
|
||||||
|
waitUntilRefreshesDone,
|
||||||
withdrawTestBalance,
|
withdrawTestBalance,
|
||||||
} from "./operations/testing.js";
|
} from "./operations/testing.js";
|
||||||
import {
|
import {
|
||||||
@ -1586,6 +1587,8 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
|
|||||||
}
|
}
|
||||||
case WalletApiOperation.TestingWaitTransactionsFinal:
|
case WalletApiOperation.TestingWaitTransactionsFinal:
|
||||||
return await waitUntilDone(ws);
|
return await waitUntilDone(ws);
|
||||||
|
case WalletApiOperation.TestingWaitRefreshesFinal:
|
||||||
|
return await waitUntilRefreshesDone(ws);
|
||||||
// default:
|
// default:
|
||||||
// assertUnreachable(operation);
|
// assertUnreachable(operation);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user