implement time travelling
This commit is contained in:
parent
1b0b3f146c
commit
c4d2899562
@ -31,6 +31,7 @@ import { Bank } from "./bank";
|
|||||||
import { classifyTalerUri, TalerUriType } from "../util/taleruri";
|
import { classifyTalerUri, TalerUriType } from "../util/taleruri";
|
||||||
import util = require("util");
|
import util = require("util");
|
||||||
import { Configuration } from "../util/talerconfig";
|
import { Configuration } from "../util/talerconfig";
|
||||||
|
import { setDangerousTimetravel } from "../util/time";
|
||||||
|
|
||||||
// Backwards compatibility with nodejs<0.11, where TextEncoder and TextDecoder
|
// Backwards compatibility with nodejs<0.11, where TextEncoder and TextDecoder
|
||||||
// are not globals yet.
|
// are not globals yet.
|
||||||
@ -119,6 +120,14 @@ const walletCli = clk
|
|||||||
.maybeOption("walletDbFile", ["--wallet-db"], clk.STRING, {
|
.maybeOption("walletDbFile", ["--wallet-db"], clk.STRING, {
|
||||||
help: "location of the wallet database file"
|
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, {
|
.maybeOption("inhibit", ["--inhibit"], clk.STRING, {
|
||||||
help:
|
help:
|
||||||
"Inhibit running certain operations, useful for debugging and testing.",
|
"Inhibit running certain operations, useful for debugging and testing.",
|
||||||
|
@ -34,9 +34,15 @@ export interface Duration {
|
|||||||
readonly d_ms: number | "forever";
|
readonly d_ms: number | "forever";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let timeshift: number = 0;
|
||||||
|
|
||||||
|
export function setDangerousTimetravel(dt: number) {
|
||||||
|
timeshift = dt;
|
||||||
|
}
|
||||||
|
|
||||||
export function getTimestampNow(): Timestamp {
|
export function getTimestampNow(): Timestamp {
|
||||||
return {
|
return {
|
||||||
t_ms: new Date().getTime(),
|
t_ms: new Date().getTime() + timeshift,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user