Digix Dev Tool Release — Tempo

Chris Hitchcott (Digix Core Dev)

Why was Tempo created?

Tempo allows us to easily test time sensitive code in our Solidity contracts such as storage fee and demurrage operations of DGX within the TestRPC environment.

A tool to simplify time management in EVM Tests

There are different APIs for traversing time in tests that run against testrpc as well as a 'regular' EVM.

Tempo provides a simple interface for ‘fast-forwarding’ time (mining blocks) that will transparently fallback to regular mining when TestRPC is not available.

Example

describe('feeDays', function () {
// set the 'now' using tempo...
it('calculates the correct number of fee days', function () {
const numberOfDays = randomInt(12, 40);
const numberOfSeconds = numberOfDays * 60 * 60 * 24;
let beforeTime;
tempo.waitForBlocks(1) // reset the time
.then(() => {
beforeTime = tempo.currentTimestamp;
// check the current time is fine...
return digixMath.feeDays.call(beforeTime);
}).then((res) => {
assert.equal(0, res.toNumber());
// zoom a few days into the future
return tempo.waitForBlocks(1, numberOfSeconds);
})
.then(() => digixMath.feeDays.call(beforeTime))
.then((res) => assert.equal(numberOfDays, res.toNumber()));
});
});
A single golf clap? Or a long standing ovation?

By clapping more or less, you can signal to us which stories really stand out.