helios icon indicating copy to clipboard operation
helios copied to clipboard

Test harness / network emulator can't `waitUntil` a target time

Open rjharmon opened this issue 2 years ago • 2 comments

Tried to implement a waitUntil() for test environment:

function waitUntil(time: Date, network, params) {
    const targetSlot = params.timeToSlot(BigInt(time.getTime()))
    const current = params.liveSlot

    const slotsToWait = targetSlot - current;
    if (slotsToWait < 1) {
        throw new Error(`the indicated time is not in the future`)
    }
    // console.warn(`waiting ${slotsToWait} until ${time}`);

    network.tick(slotsToWait)
}

timeToSlot() fails on params.#raw (it's undefined).

Perhaps the network emulator should genesis at current time as of the call to network.initNetworkParams() (and require that it's still at slot 0)?

rjharmon avatar Jun 03 '23 21:06 rjharmon

This is probably a good idea, the latestTip in the NetworkParams can be updated to current time.

christianschmitz avatar Jun 08 '23 07:06 christianschmitz

we've been letting slot 0 be epoch-time 0, and then timeToSlot uses timeMs / 1000

rjharmon avatar Jul 13 '23 16:07 rjharmon