Code coverage for Solidity smart-contracts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
solidity-coverage/test/units/api.js

100 lines
2.6 KiB

const assert = require('assert');
const util = require('./../util/util.js');
const API = require('./../../api.js');
const detect = require('detect-port');
const Ganache = require('ganache-cli');
describe('api', () => {
let opts;
beforeEach(() => opts = {silent: true})
it('getInstrumentationData', function(){
const api = new API(opts);
const canonicalPath = 'statements/single.sol'
const source = util.getCode(canonicalPath);
api.instrument([{
source: source,
canonicalPath: canonicalPath
}]);
const data = api.getInstrumentationData();
const hash = Object.keys(data)[0];
assert(data[hash].hits === 0);
});
it('setInstrumentationData', function(){
let api = new API(opts);
const canonicalPath = 'statements/single.sol'
const source = util.getCode(canonicalPath);
api.instrument([{
source: source,
canonicalPath: canonicalPath
}]);
const cloneA = api.getInstrumentationData();
const hash = Object.keys(cloneA)[0];
// Verify cloning
cloneA[hash].hits = 5;
const cloneB = api.getInstrumentationData();
assert(cloneB[hash].hits === 0);
// Verify setting
api = new API(opts);
api.instrument([{
source: source,
canonicalPath: canonicalPath
}]);
api.setInstrumentationData(cloneA);
const cloneC = api.getInstrumentationData();
assert(cloneC[hash].hits === 5);
});
it('ganache: autoLaunchServer === false', async function(){
const api = new API(opts);
const port = api.port;
const server = await api.ganache(Ganache, false);
assert(typeof port === 'number')
assert(typeof server === 'object');
assert(typeof server.listen === 'function');
const freePort = await detect(port);
assert(freePort === port);
});
it('config: autoLaunchServer: false', async function(){
opts.autoLaunchServer = false;
const api = new API(opts);
const port = api.port;
const server = await api.ganache(Ganache);
assert(typeof port === 'number')
assert(typeof server === 'object');
assert(typeof server.listen === 'function');
const freePort = await detect(port);
assert(freePort === port);
})
it('api.utils', async function(){
const api = new API(opts);
assert(api.utils.assembleFiles !== undefined)
assert(api.utils.checkContext !== undefined)
assert(api.utils.finish !== undefined)
assert(api.utils.getTempLocations !== undefined)
assert(api.utils.setupTempFolders !== undefined)
assert(api.utils.loadSource !== undefined)
assert(api.utils.loadSolcoverJS !== undefined)
assert(api.utils.save !== undefined)
});
})