failing p2p test case
This commit is contained in:
parent
fabe92195a
commit
a654c88a58
@ -31,6 +31,7 @@ import {
|
|||||||
AmountJson,
|
AmountJson,
|
||||||
Amounts,
|
Amounts,
|
||||||
AmountString,
|
AmountString,
|
||||||
|
BankAccessApiClient,
|
||||||
codecForAny,
|
codecForAny,
|
||||||
codecForBankWithdrawalOperationPostResponse,
|
codecForBankWithdrawalOperationPostResponse,
|
||||||
codecForBatchDepositSuccess,
|
codecForBatchDepositSuccess,
|
||||||
@ -53,7 +54,6 @@ import {
|
|||||||
HttpRequestLibrary,
|
HttpRequestLibrary,
|
||||||
readSuccessResponseJsonOrThrow,
|
readSuccessResponseJsonOrThrow,
|
||||||
} from "@gnu-taler/taler-util/http";
|
} from "@gnu-taler/taler-util/http";
|
||||||
import { BankAccessApiClient } from "../../taler-util/src/bank-api-client.js";
|
|
||||||
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
|
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
|
||||||
import { DenominationRecord } from "./db.js";
|
import { DenominationRecord } from "./db.js";
|
||||||
import { isWithdrawableDenom } from "./index.js";
|
import { isWithdrawableDenom } from "./index.js";
|
||||||
|
@ -18,8 +18,72 @@ import {
|
|||||||
AgeRestriction,
|
AgeRestriction,
|
||||||
AmountJson,
|
AmountJson,
|
||||||
Amounts,
|
Amounts,
|
||||||
|
DenomKeyType,
|
||||||
Duration,
|
Duration,
|
||||||
TransactionAmountMode,
|
TransactionAmountMode,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import test, { ExecutionContext } from "ava";
|
import test, { ExecutionContext } from "ava";
|
||||||
|
import { testing_greedySelectPeer } from "./coinSelection.js"
|
||||||
|
|
||||||
|
type Tester<T> = {
|
||||||
|
deep: {
|
||||||
|
equal(another: T): ReturnType<ExecutionContext["deepEqual"]>;
|
||||||
|
equals(another: T): ReturnType<ExecutionContext["deepEqual"]>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function expect<T>(t: ExecutionContext, thing: T): Tester<T> {
|
||||||
|
return {
|
||||||
|
deep: {
|
||||||
|
equal: (another: T) => t.deepEqual(thing, another),
|
||||||
|
equals: (another: T) => t.deepEqual(thing, another),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const inTheDistantFuture = AbsoluteTime.toProtocolTimestamp(
|
||||||
|
AbsoluteTime.addDuration(AbsoluteTime.now(), Duration.fromSpec({ hours: 1 }))
|
||||||
|
)
|
||||||
|
const inThePast = AbsoluteTime.toProtocolTimestamp(
|
||||||
|
AbsoluteTime.subtractDuraction(AbsoluteTime.now(), Duration.fromSpec({ hours: 1 }))
|
||||||
|
)
|
||||||
|
test("should select the coin", (t) => {
|
||||||
|
const instructedAmount = Amounts.parseOrThrow("LOCAL:2")
|
||||||
|
const tally = {
|
||||||
|
amountAcc: Amounts.zeroOfCurrency(instructedAmount.currency),
|
||||||
|
depositFeesAcc: Amounts.zeroOfCurrency(instructedAmount.currency),
|
||||||
|
lastDepositFee: Amounts.zeroOfCurrency(instructedAmount.currency),
|
||||||
|
};
|
||||||
|
const coins = testing_greedySelectPeer(
|
||||||
|
// candidates available
|
||||||
|
[{
|
||||||
|
"denomPub": {
|
||||||
|
"age_mask": 0,
|
||||||
|
"cipher": DenomKeyType.Rsa,
|
||||||
|
"rsa_public_key": "PPP"
|
||||||
|
},
|
||||||
|
"denomPubHash": "XXX",
|
||||||
|
"value": "LOCAL:10",
|
||||||
|
"feeDeposit": "LOCAL:0.1",
|
||||||
|
"feeRefresh": "LOCAL:0",
|
||||||
|
"feeRefund": "LOCAL:0",
|
||||||
|
"feeWithdraw": "LOCAL:0",
|
||||||
|
"stampExpireDeposit": inTheDistantFuture,
|
||||||
|
"stampExpireLegal": inTheDistantFuture,
|
||||||
|
"stampExpireWithdraw": inTheDistantFuture,
|
||||||
|
"stampStart": inThePast,
|
||||||
|
"exchangeBaseUrl": "http://exchange.localhost/",
|
||||||
|
"numAvailable": 5,
|
||||||
|
"maxAge": 32
|
||||||
|
}],
|
||||||
|
instructedAmount, tally);
|
||||||
|
|
||||||
|
expect(t, coins).deep.equal({
|
||||||
|
"XXX;32;http://exchange.localhost/": {
|
||||||
|
exchangeBaseUrl: "http://exchange.localhost/",
|
||||||
|
denomPubHash: "XXX",
|
||||||
|
maxAge: 32,
|
||||||
|
contributions: [Amounts.parseOrThrow("LOCAL:2")],
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
@ -894,6 +894,12 @@ interface PeerCoinSelectionTally {
|
|||||||
lastDepositFee: AmountJson;
|
lastDepositFee: AmountJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* exporting for testing
|
||||||
|
*/
|
||||||
|
export function testing_greedySelectPeer(...args: Parameters<typeof greedySelectPeer>): ReturnType<typeof greedySelectPeer> {
|
||||||
|
return greedySelectPeer(...args)
|
||||||
|
}
|
||||||
function greedySelectPeer(
|
function greedySelectPeer(
|
||||||
candidates: AvailableDenom[],
|
candidates: AvailableDenom[],
|
||||||
instructedAmount: AmountLike,
|
instructedAmount: AmountLike,
|
||||||
|
Loading…
Reference in New Issue
Block a user