HeliosLang/compiler

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

rjharmon opened this issue · 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)?

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

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