mirror of
https://github.com/embarklabs/embark.git
synced 2025-03-02 14:20:41 +00:00
Improve the reliability of the expiration unit test in the test dapp by explicitly setting the `block.timestamp` and comparing an expiration value against that. This improves on the current implementation that relies on time passed which varies depending on the speed of unit tests run (CPU speed, logs shown, etc).
27 lines
817 B
JavaScript
27 lines
817 B
JavaScript
/*global contract, config, it, assert, mineAtTimestamp*/
|
|
const Expiration = require('Embark/contracts/Expiration');
|
|
const now = Math.floor(new Date().getTime()/1000.0); // Get unix epoch. The getTime method returns the time in milliseconds.
|
|
|
|
config({
|
|
contracts: {
|
|
deploy: {
|
|
"Expiration": {
|
|
args: [now + 1000]
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
contract("Expiration", function() {
|
|
it("should not have expired yet", async function () {
|
|
const isExpired = await Expiration.methods.isExpired().call();
|
|
assert.strictEqual(isExpired, false);
|
|
});
|
|
|
|
it("should have expired after skipping time", async function () {
|
|
await mineAtTimestamp(now + 1001); // sets block.timestamp to 1001
|
|
const isExpired = await Expiration.methods.isExpired().call();
|
|
assert.strictEqual(isExpired, true);
|
|
});
|
|
});
|