wallet-core: return mock currency specification for KUDOS and TESTKUDOS

This commit is contained in:
Florian Dold 2023-10-10 15:08:59 +02:00
parent adda4f8ce3
commit 47fdfc64a2
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 73 additions and 33 deletions

View File

@ -581,6 +581,7 @@ deploymentCli
logger.error( logger.error(
`unable to create instance ${instanceId}, HTTP status ${createResp.status}`, `unable to create instance ${instanceId}, HTTP status ${createResp.status}`,
); );
process.exit(2);
} }
const accountsUrl = new URL( const accountsUrl = new URL(

View File

@ -415,24 +415,28 @@ export const codecForScopeInfo = (): Codec<ScopeInfo> =>
.alternative(ScopeType.Auditor, codecForScopeInfoAuditor()) .alternative(ScopeType.Auditor, codecForScopeInfoAuditor())
.build("ScopeInfo"); .build("ScopeInfo");
export interface GetCurrencyInfoRequest { export interface GetCurrencySpecificationRequest {
scope: ScopeInfo; scope: ScopeInfo;
} }
export const codecForGetCurrencyInfoRequest = export const codecForGetCurrencyInfoRequest =
(): Codec<GetCurrencyInfoRequest> => (): Codec<GetCurrencySpecificationRequest> =>
buildCodecForObject<GetCurrencyInfoRequest>() buildCodecForObject<GetCurrencySpecificationRequest>()
.property("scope", codecForScopeInfo()) .property("scope", codecForScopeInfo())
.build("GetCurrencyInfoRequest"); .build("GetCurrencySpecificationRequest");
export interface GetCurrencyInfoResponse { export interface GetCurrencySpecificationResponse {
decimalSeparator: string; currencySpecification: CurrencySpecification;
numFractionalDigits: number; }
numTinyDigits: number;
/** export interface CurrencySpecification {
* Is the currency name leading or trailing? decimal_separator: string;
*/ fractional_input_digits: number;
isCurrencyNameLeading: boolean; fractional_normal_digits: number;
fractional_trailing_zero_digits: number;
is_currency_name_leading: boolean;
name: string;
alt_unit_names: { [n: number]: string };
} }
export interface InitRequest { export interface InitRequest {
@ -1605,10 +1609,11 @@ export interface UpdateExchangeEntryRequest {
exchangeBaseUrl: string; exchangeBaseUrl: string;
} }
export const codecForUpdateExchangeEntryRequest = (): Codec<UpdateExchangeEntryRequest> => export const codecForUpdateExchangeEntryRequest =
buildCodecForObject<UpdateExchangeEntryRequest>() (): Codec<UpdateExchangeEntryRequest> =>
.property("exchangeBaseUrl", codecForString()) buildCodecForObject<UpdateExchangeEntryRequest>()
.build("UpdateExchangeEntryRequest"); .property("exchangeBaseUrl", codecForString())
.build("UpdateExchangeEntryRequest");
export interface ForceExchangeUpdateRequest { export interface ForceExchangeUpdateRequest {
exchangeBaseUrl: string; exchangeBaseUrl: string;

View File

@ -61,8 +61,8 @@ import {
GetAmountRequest, GetAmountRequest,
GetBalanceDetailRequest, GetBalanceDetailRequest,
GetContractTermsDetailsRequest, GetContractTermsDetailsRequest,
GetCurrencyInfoRequest, GetCurrencySpecificationRequest,
GetCurrencyInfoResponse, GetCurrencySpecificationResponse,
GetExchangeTosRequest, GetExchangeTosRequest,
GetExchangeTosResult, GetExchangeTosResult,
GetPlanForOperationRequest, GetPlanForOperationRequest,
@ -218,7 +218,7 @@ export enum WalletApiOperation {
TestingWaitRefreshesFinal = "testingWaitRefreshesFinal", TestingWaitRefreshesFinal = "testingWaitRefreshesFinal",
TestingWaitTransactionState = "testingWaitTransactionState", TestingWaitTransactionState = "testingWaitTransactionState",
TestingSetTimetravel = "testingSetTimetravel", TestingSetTimetravel = "testingSetTimetravel",
GetScopedCurrencyInfo = "getScopedCurrencyInfo", GetCurrencySpecification = "getCurrencySpecification",
ListStoredBackups = "listStoredBackups", ListStoredBackups = "listStoredBackups",
CreateStoredBackup = "createStoredBackup", CreateStoredBackup = "createStoredBackup",
DeleteStoredBackup = "deleteStoredBackup", DeleteStoredBackup = "deleteStoredBackup",
@ -627,10 +627,10 @@ export type ListCurrenciesOp = {
response: WalletCurrencyInfo; response: WalletCurrencyInfo;
}; };
export type GetScopedCurrencyInfoOp = { export type GetCurrencySpecificationOp = {
op: WalletApiOperation.GetScopedCurrencyInfo; op: WalletApiOperation.GetCurrencySpecification;
request: GetCurrencyInfoRequest; request: GetCurrencySpecificationRequest;
response: GetCurrencyInfoResponse; response: GetCurrencySpecificationResponse;
}; };
// group: Deposits // group: Deposits
@ -1136,7 +1136,7 @@ export type WalletOperations = {
[WalletApiOperation.TestingWaitRefreshesFinal]: TestingWaitRefreshesFinal; [WalletApiOperation.TestingWaitRefreshesFinal]: TestingWaitRefreshesFinal;
[WalletApiOperation.TestingSetTimetravel]: TestingSetTimetravelOp; [WalletApiOperation.TestingSetTimetravel]: TestingSetTimetravelOp;
[WalletApiOperation.TestingWaitTransactionState]: TestingWaitTransactionStateOp; [WalletApiOperation.TestingWaitTransactionState]: TestingWaitTransactionStateOp;
[WalletApiOperation.GetScopedCurrencyInfo]: GetScopedCurrencyInfoOp; [WalletApiOperation.GetCurrencySpecification]: GetCurrencySpecificationOp;
[WalletApiOperation.CreateStoredBackup]: CreateStoredBackupsOp; [WalletApiOperation.CreateStoredBackup]: CreateStoredBackupsOp;
[WalletApiOperation.ListStoredBackups]: ListStoredBackupsOp; [WalletApiOperation.ListStoredBackups]: ListStoredBackupsOp;
[WalletApiOperation.DeleteStoredBackup]: DeleteStoredBackupOp; [WalletApiOperation.DeleteStoredBackup]: DeleteStoredBackupOp;

View File

@ -117,7 +117,7 @@ import {
sampleWalletCoreTransactions, sampleWalletCoreTransactions,
validateIban, validateIban,
codecForSharePaymentRequest, codecForSharePaymentRequest,
GetCurrencyInfoResponse, GetCurrencySpecificationResponse,
codecForGetCurrencyInfoRequest, codecForGetCurrencyInfoRequest,
CreateStoredBackupResponse, CreateStoredBackupResponse,
StoredBackupList, StoredBackupList,
@ -1427,16 +1427,50 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
await waitTransactionState(ws, req.transactionId, req.txState); await waitTransactionState(ws, req.transactionId, req.txState);
return {}; return {};
} }
case WalletApiOperation.GetScopedCurrencyInfo: { case WalletApiOperation.GetCurrencySpecification: {
// Ignore result, just validate in this mock implementation // Ignore result, just validate in this mock implementation
codecForGetCurrencyInfoRequest().decode(payload); const req = codecForGetCurrencyInfoRequest().decode(payload);
const resp: GetCurrencyInfoResponse = { // Hard-coded mock for KUDOS and TESTKUDOS
decimalSeparator: ",", if (req.scope.currency === "KUDOS") {
isCurrencyNameLeading: false, const kudosResp: GetCurrencySpecificationResponse = {
numFractionalDigits: 2, currencySpecification: {
numTinyDigits: 1, decimal_separator: ",",
name: "Kudos (Taler Demonstrator)",
fractional_input_digits: 2,
fractional_normal_digits: 2,
fractional_trailing_zero_digits: 2,
is_currency_name_leading: true,
alt_unit_names: {
"0": "ク",
},
},
};
} else if (req.scope.currency === "TESTKUDOS") {
const testkudosResp: GetCurrencySpecificationResponse = {
currencySpecification: {
decimal_separator: ",",
name: "Test (Taler Unstable Demonstrator)",
fractional_input_digits: 0,
fractional_normal_digits: 0,
fractional_trailing_zero_digits: 0,
is_currency_name_leading: true,
alt_unit_names: {},
},
};
return testkudosResp;
}
const defaultResp: GetCurrencySpecificationResponse = {
currencySpecification: {
decimal_separator: ",",
name: "Unknown",
fractional_input_digits: 2,
fractional_normal_digits: 2,
fractional_trailing_zero_digits: 2,
is_currency_name_leading: true,
alt_unit_names: {},
},
}; };
return resp; return defaultResp;
} }
case WalletApiOperation.ImportBackupRecovery: { case WalletApiOperation.ImportBackupRecovery: {
const req = codecForAny().decode(payload); const req = codecForAny().decode(payload);