Configuring Gas Price when running Code Coverage - solidity

I'm currently using the following code coverage tool found here. I'm trying to set the gas price to 0 when configuring ganache in the .solcover.js file. I've used the following:
module.exports = {
client: require("ganache-cli") ,
providerOptions: { gasPrice : "0" }
};
and
module.exports = {
client: require("ganache-cli") ,
providerOptions: { options: { gasPrice : "0" }}
};
when I run npx truffle run coverage in my test I print out ganache like:
const g = require("ganache-cli");
.
.
.
console.log(g.provider().options.gasPrice);
But I set get the default hex value of 0x77359400 instead of 0. I'm not too sure where I'm going wrong?

Related

Get zero coverage with nyc and playwright

I'm struggling to set up coverage correctly using Playwright. It reports 0 coverage in all files (except the test files themselves, if I include them).
I'm getting inspiration from https://playwright.dev/docs/api/class-coverage and https://github.com/bgotink/playwright-coverage/blob/main/src/fixtures.ts. Our project is a monorepo where tests in a folder e2e-tests/ run end to end tests on servers contained in other adjacent folders, e.g. frontend/.
The current setup is using a page fixture like so in each test-file:
// frontend.spec.ts
import { test, expect } from "../fixtures";
test("something", ({ page ) => {
// Do test stuff with page
});
where the fixture is defined as
// fixtures/page.ts
import { Page, TestInfo } from "#playwright/test";
const pageWithCoverage = async (
{ page, browserName }: { page: Page; browserName: string },
use: (page: Page) => Promise<void>,
testInfo: TestInfo
) => {
if (!page.coverage) throw new Error(`Could not collect coverage with browser "${browserName}"`);
console.log("📈 Collecting coverage");
await page.coverage.startJSCoverage();
await use(page);
await page.coverage.stopJSCoverage();
};
export default pageWithCoverage;
To collect coverage I run
npx nyc --all --cwd ".." --include "**/frontend/**/* --nycrc-path e2e-tests/.nycrc npm t
where the relevant part concerning the file structure is:
--all --cwd ".." --include "**/frontend/**/*"
I'm using a .nycrc file containing nyc-config-tsx in order to instrument tsx files:
// .nycrc
{
"extends": "nyc-config-tsx",
"all": true
}
Can you tell what the issue is?
The frontend is built using next.
I get similar results storing results to files using v8toIstanbul and running npx nyc report

TronBox compile issue

I've installed the latest tronbox (2.7.5) using npm
Created a new project using command tronbox init
In file tronbox.js I've updated the compiler version to 0.4.25 (see the file below).
When compiling using the command tronbox compile --compile-all --reset I'm getting:
Windows error:
And then the following message in my terminal:
Error: Error parsing C:/dev/temp/contracts/Migrations.sol: Command failed: tronbox --download-compiler 0.4.25
at checkExecSyncError (child_process.js:575:11)
at execSync (child_process.js:612:13)
at getWrapper (C:\Users\***\AppData\Roaming\npm\node_modules\tronbox\build\components\TronSolc.js:1:1717)
at Object.parseImports (C:\Users\***\AppData\Roaming\npm\node_modules\tronbox\build\components\Compile\parser.js:1:2345)
at C:\Users\***\AppData\Roaming\npm\node_modules\tronbox\build\components\Compile\profiler.js:1:4981
at C:\Users\***\AppData\Roaming\npm\node_modules\tronbox\build\components\Resolver\index.js:1:1727
at C:\Users\***\AppData\Roaming\npm\node_modules\tronbox\node_modules\async\internal\onlyOnce.js:12:16
at next (C:\Users\***\AppData\Roaming\npm\node_modules\tronbox\node_modules\async\whilst.js:68:18)
at C:\Users\***\AppData\Roaming\npm\node_modules\tronbox\build\components\Resolver\index.js:1:1495
at C:\Users\***\AppData\Roaming\npm\node_modules\tronbox\build\components\Resolver\fs.js:1:1685
I added this line to the top of my tronbox.js file:
console.log('Running tronbox compile');
and noticed that once compiling the output is written twice on my screen:
I'm not sure it relates but for some reason, it runs twice.
Any idea? Is this a tronbox issue?
const port = process.env.HOST_PORT || 9090
module.exports = {
networks: {
mainnet: {
// Don't put your private key here:
privateKey: process.env.PRIVATE_KEY_MAINNET,
/*
Create a .env file (it must be gitignored) containing something like
export PRIVATE_KEY_MAINNET=4E7FECCB71207B867C495B51A9758B104B1D4422088A87F4978BE64636656243
Then, run the migration with:
source .env && tronbox migrate --network mainnet
*/
userFeePercentage: 100,
feeLimit: 1e8,
fullHost: 'https://api.trongrid.io',
network_id: '1'
},
shasta: {
privateKey: process.env.PRIVATE_KEY_SHASTA,
userFeePercentage: 50,
feeLimit: 1e8,
fullHost: 'https://api.shasta.trongrid.io',
network_id: '2'
},
nile: {
privateKey: process.env.PRIVATE_KEY_NILE,
fullNode: 'https://httpapi.nileex.io/wallet',
solidityNode: 'https://httpapi.nileex.io/walletsolidity',
eventServer: 'https://eventtest.nileex.io',
network_id: '3'
},
development: {
// For trontools/quickstart docker image
privateKey: 'da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0',
userFeePercentage: 0,
feeLimit: 1e8,
fullHost: 'http://127.0.0.1:' + port,
network_id: '9'
},
compilers: {
solc: {
version: '0.4.25'
}
}
}
}
This seems like a regression bug in tronbox 2.7.4 and 2.7.5 since when I use tronbox 2.5.2 everything works smoothly.

CASL is not working properly in Vue Production Mode

I have defined some rules for specific roles, they all are working fine. But when I build vue project in production mode, all the rules gives false. Details are here below:
I have this file ability.js, which is giving me rules:
export const getRules = (role, userId) => {
const { can, cannot, rules } = AbilityBuilder.extract()
switch(role) {
case 'TENANT_ADMIN':
can('manage', 'all')
break
case 'TENANT_AGENT':
can('view', 'ConversationView')
break
case 'TENANT_AGENT_LIMITED':
can('view', 'ConversationView', { userId: userId })
break
}
return rules
}
I'm updating rules like this in App.vue (all values are valid)
this.$ability.update(getRules(role, userId))
I'm checking permissions using below code.
class ConversationView {
constructor(props) {
Object.assign(this, props)
}
}
this.$can('view', new ConversationView({ userId: Id }))
Now, when I run this code in local/development mode. It is working fine (giving me true where it needs to), but when I generate a production build it is not working as expected (always gives me false)
Development Build Command:
vue-cli-service build --mode local --modern
Development Build .env.local
VUE_APP_STAGE=development
NODE_ENV=development
Production Build Command:
vue-cli-service build --mode prod --modern
Production Build .env.prod
VUE_APP_STAGE=production
NODE_ENV=production
Let me know why this is happening.
Replicated the steps here.
Follow below link to view running and expected version:
LINK 01
Output:
Checking for '1' => true
Checking for 1 => false
Checking for '2' => false
Clone the same project in your local, or download it from [github 2
After running, we're getting this output:
Checking for '1' => false
Checking for 1 => false
Checking for '2' => false
Got the solution. Because of minification for production build code was not working as expected. Had to define modelName function to return proper name.
Follow the link for more info.
https://stalniy.github.io/casl/abilities/2017/07/21/check-abilities.html#instance-checks

How to pass environment value from npm to wdio file

I wanted to pass the test environment value from command line with npm command which should be accessible into wdio.conf file. Something like npm test --env='stage'.
How to achieve it.
I do not think there is direct way in WDIO to achieve it. The one option that we used is:
Defined the below in the wdio.conf.js file:
const testEnv = process.env.TEST_ENV || 'FIT'; //code to read the value from cmd
exports.config = {
....
beforeSession: function(){
global.testEnv = testEnv; //making the testEnv global
}
....
}
Command to start the test: TEST_ENV='stag' npm test
So in your project the variable testEnv would be available throughout.
You can do it like this:
if (process.argv !== undefined && process.argv.length) {
process.argv.forEach(arg => {
if (arg.indexOf('--env=') !== -1) {
process.env.env = arg.replace('--env=', '');
}
});
}
console.log("Environment : " + process.env.env)
},

Use tslint-eslint-rules with Gulp.js

Objective: Use TSLint to lint any TS files in the project done using VS 2015
I set up a gulp task as follows (from Setup TSLint in Visual Studio 2015):
//The actual task to run
gulp.task("TSLint:All", function () {
return gulp.src(TYPE_SCRIPT_FILES)
.pipe(plumber())
.pipe(tslint())
.pipe(tslint.report(
"verbose", {
emitError: false,
reportLimit: 50
}));
});
Things were working fine. Now I want to use the tslint-eslint-rules rules for linting.
I do the following
Install the eslint-eslint-rules package as shown on https://github.com/buzinas/tslint-eslint-rules
Create file called tslint.json as shown below
{
"rulesDirectory": "node_modules/tslint-eslint-rules/dist/rules",
"rules": {
"no-constant-condition": true
}
}
Change my Gulp task as follows
gulp.task("TSLint:All", function () {
return gulp.src(TYPE_SCRIPT_FILES)
.pipe(plumber())
.pipe(tslint({
configuration: "tslint.json"
}
))
.pipe(tslint.report(
"verbose", {
emitError: false,
reportLimit: 50
}));
});
I start getting the following error (I believe for every error flagged by Linter):
Plumber found unhandled error:
SyntaxError: Unexpected token
How can I correct this ?