These instructions will get you a useful helpers for testing purposes your Solidity Dapp.
What things you need to install the software and how to install them:
To add an entry to your package.json's dependencies:
npm install solidity-unittests-helpers --save
To add an entry to your package.json's devDependencies:
npm install solidity-unittests-helpers --save-dev
npm uninstall [<@scope>/]solidity-unittests-helpers[@<version>]... [-S|--save|-D|--save-dev|-O|--save-optional|--no-save]
aliases: remove, rm, r, un, unlink
This uninstalls a package, completely removing everything npm installed on its behalf.
Example:
npm uninstall solidity-unittests-helpers
In global mode (ie, with -g or --global appended to the command), it uninstalls the current package context as a global package.
npm uninstall takes 3 exclusive, optional flags which save or update the package version in your main package.json:
-
-S, --save: Package will be removed from your dependencies.
-
-D, --save-dev: Package will be removed from your devDependencies.
-
-O, --save-optional: Package will be removed from your optionalDependencies.
-
--no-save: Package will not be removed from your package.json file.
We use SemVer for versioning. For the versions available, see the tags on this page.
Can be used to ensure a clean state for testing. Source
var SolUnittestHelpers = require("solidity-unittests-helpers");
beforeEach(function () {
SolUnittestHelpers.snapshot();
})
afterEach(function () {
SolUnittestHelpers.revert();
});
Provide way to testing negative and positive transactions.
Negative testing commonly referred to as error path testing or failure testing is generally done to ensure the stability of the application.
var SolUnittestHelpers = require("solidity-unittests-helpers");
let asserts = SolUnittestHelpers.asserts(assert);
// equal
asserts.equal(3, '3', '== coerces values to strings');
// isTrue
var teaServed = true;
asserts.isTrue(teaServed, 'the tea has been served');
// isFalse
var teaServed = false;
asserts.isFalse(teaServed, 'no tea yet? hmm...');
// throws
asserts.throws(fn, 'function throws a reference error');
// doesNotThrow
asserts.doesNotThrow(fn, 'Any Error thrown must not have this message');
Get timestamp from the latest block Source
var SolUnittestHelpers = require("solidity-unittests-helpers");
let time = await SolUnittestHelpers.latestTime();
console.log("time:", time);
// ==> "time: 1528634956"
var SolUnittestHelpers = require("solidity-unittests-helpers");
let duration = SolUnittestHelpers.duration;
// seconds
duration.seconds(25);
// ==> 25 seconds == 25
// minutes
duration.minutes(1);
// ==> 2 minutes == 120
// days
duration.days(1);
//==> 1 days == 86400
// weeks
duration.weeks(1);
// ==> 1 weeks == 604800
// years (1 year == 365 days)
// Take care if you perform calendar calculations using these units,
// because not every year equals 365 days and not even every day has
// 24 hours because of leap seconds.
// https://en.wikipedia.org/wiki/Leap_second
duration.year(1);
// ==> 1 years == 31536000
var SolUnittestHelpers = require("solidity-unittests-helpers");
await console.log('Time now: ', SolUnittestHelpers.latestTime());
await SolUnittestHelpers.increaseTimeWith(duration.days(1));
await console.log('after increaseTimeWith: ', SolUnittestHelpers.latestTime());
// Time now: 1528723737
// after increaseTimeWith: 1528810142
var SolUnittestHelpers = require("solidity-unittests-helpers");
await console.log('Time now: ', SolUnittestHelpers.latestTime());
await SolUnittestHelpers.increaseTimeTo(duration.years(2019));
await console.log('after increaseTimeTo: ', SolUnittestHelpers.latestTime());
// Time now: 1528638172
// after increaseTimeTo: 63671184023
-
Vanja Solomichev - Vanija
-
Andrii Baran - andriy-baran
-
Serhii Budnik - Zikot4
This project is licensed under the MIT License - see the LICENSE file for details
We love pull requests. If you have something you want to add or remove, please open a new pull request.