implement time travelling

This commit is contained in:
Florian Dold 2020-03-23 17:47:35 +05:30
parent 1b0b3f146c
commit c4d2899562
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 16 additions and 1 deletions

View File

@ -31,6 +31,7 @@ import { Bank } from "./bank";
import { classifyTalerUri, TalerUriType } from "../util/taleruri";
import util = require("util");
import { Configuration } from "../util/talerconfig";
import { setDangerousTimetravel } from "../util/time";
// Backwards compatibility with nodejs<0.11, where TextEncoder and TextDecoder
// are not globals yet.
@ -119,6 +120,14 @@ const walletCli = clk
.maybeOption("walletDbFile", ["--wallet-db"], clk.STRING, {
help: "location of the wallet database file"
})
.maybeOption("timetravel", ["--timetravel"], clk.INT, {
help: "modify system time by given offset in microseconds",
onPresentHandler: (x) => {
// Convert microseconds to milliseconds and do timetravel
logger.info(`timetravelling ${x} microseconds`);
setDangerousTimetravel(x / 1000);
},
})
.maybeOption("inhibit", ["--inhibit"], clk.STRING, {
help:
"Inhibit running certain operations, useful for debugging and testing.",

View File

@ -34,9 +34,15 @@ export interface Duration {
readonly d_ms: number | "forever";
}
let timeshift: number = 0;
export function setDangerousTimetravel(dt: number) {
timeshift = dt;
}
export function getTimestampNow(): Timestamp {
return {
t_ms: new Date().getTime(),
t_ms: new Date().getTime() + timeshift,
};
}