How can I configure Hardhat to work with RSK regtest blockchain? - truffle

I intend to develop my smart contracts in Hardhat, and to test them on RSK regtest local node. I was able to find a Truffle regtest configuration.
development: {
host: "127.0.0.1",
port: 4444,
network_id: "*"
},
What hardhat.config.js configuration do I need to run my tests on RSK regtest?

To deploy and test your smart contracts on RSK regtest yourhardhat.config.js should look as follows:
/**
* #type import('hardhat/config').HardhatUserConfig
*/
require("#nomiclabs/hardhat-waffle");
module.exports = {
solidity: "0.7.3",
defaultNetwork: "rskregtest",
networks: {
rskregtest: {
url: "http://localhost:4444/",
},
},
};
Then you'll be able to run your tests by typing in the terminal
% npx hardhat test

Related

Appium Webdriverio Setup

I need help understanding how to set up a testing framework to using Appium, Webdriverio, Node.js, Jasmine. I have the wdio.conf.js file set up:
host: '127.0.0.1',
port: 4723,
path: '/wd/hub',
....
specs: [
'./spec/wdtest/test.js'
],
....
capabilities: [
{
automationName: "appium",
browserName: 'iOS',
commandTimeout: '7200',
sessionOverride: true,
debugLogSpacing: true,
platformVersion: '10.1',
platformName: 'iOS',
showIosLog: true,
deviceName: 'iPhone 6s',
nativeInstrumentsLib: true,
isolateSimDevice: true,
autoLaunch: true,
app: '/Users/fodgerl/Library/Developer/Xcode/...../Debug-iphonesimulator/myapp.app'
}
],
....
services: ['appium'],
appium: {
args: {
address: '127.0.0.1',
commandTimeout: '7200',
sessionOverride: true,
debugLogSpacing: true,
platformVersion: '10.1',
platformName: 'iOS',
deviceName: 'iPhone 6s',
showIosLog: true,
nativeInstrumentsLib: true,
isolateSimDevice: true,
app: '/Users/fodgerl/Library/...../Products/Debug-iphonesimulator/myapp.app'
}
},
framework: 'jasmine',
My package.json file has:
"scripts": {
"test": "wdio wdio.conf.js"
},
And I have a test js file that has this:
describe('test', function() {
it('test', function () {
//how do I interact with the app?
console.log("HEREEEEE");
});
});
When I run npm test, the simulator launches and the app launches within it. What I don't know is where to go to next? How do I open app/interact with elements/etc.
I have seen examples like:
var client = webdriverio.remote({
port: 4723,
logLevel: 'verbose',
desiredCapabilities: {
platformName: 'iOS',
platformVersion: '8.4',
deviceName: 'iPhone 6',
app: webviewApp
}
});
But do I need to do that if I already have the simulator up and running from the stuff in the conf file? I was trying to find some documentation on what .remote(), init(), etc does. Also, I looked in the Launcher for webdriverio but I couldn't determine where/how it was being used in the example here: https://github.com/webdriverio/webdriverio/blob/master/examples/wdio/runner-specs/jasmine.spec.js
Any help would be appreciated to get me started!! Thanks!
On running $ npm test, it executes $ ./node_modules/.bin/wdio wdio.conf.js. So you have the wdio test runner up and running.
Now, as mentioned in The Browser Object subsection:
If you use the wdio test runner you can access the webdriver instance through the global browser object. The session is initialized by the test runner so you don’t need to call init command. The same goes for ending the session. This is also done by the test runner process.
That's it! You can access the driver instance via the global variable browser as illustrated in the aforementioned example.
Hope that helps!
webdriver.io is just for running the tests. Not interacting with the app. Use appium to app/interact with elements/etc. Appium will record the step and elements path/s. From here you can create your test cases which can be run using wedriver.io

How I can start IE in 32bit mode in webdriver.io

I am running an WebDriver.io test using gulp-wdio npm pakage
on selenium-standalone
The Code that I run in gulp is:
gulp.task('e2e', function () {
return gulp.src('wdio.conf.js')
.pipe(wdio({
wdio: {
specs: './test/features/**/*.feature'
}
}));
});
And my wdio.conf.js define browsers this way:
capabilities: [
{
browserName: 'internet explorer',
version: 'ANY'
}
],
How ever the typing is very slow, i had found on the internet that running 32 bit version of the web-driver resolves the issue, how ever I can't find how to configure the capabilities or some other place to run the IE32 bit driver by default...
Any help will be appreciated #:-)
After 2 days of research I had found the solution !!!
There is a configuration file that need to be supplied to the selenium standalone
as shown in this Example
so our final setup is done in this way:
We have a configuration file called wdio.browsers.setup.js that contains the browsers setup:
module.exports = {
baseURL: 'https://selenium-release.storage.googleapis.com',
version: '3.3.1',
drivers: {
chrome: {
version: '2.29',
arch: process.arch,
// - Recent versions of the driver: https://sites.google.com/a/chromium.org/chromedriver/
baseURL: 'https://chromedriver.storage.googleapis.com'
},
ie: {
version: '3.0.0',
arch: 'ia32',
// - Recent versions of the driver: http://selenium-release.storage.googleapis.com/index.html
baseURL: 'https://selenium-release.storage.googleapis.com'
},
firefox: {
version: '0.15.0',
arch: process.arch,
baseURL: 'https://github.com/mozilla/geckodriver/releases/download'
}
}
};
and then inside wdio.conf.js we load it and assign to a special parameters
let browsersSetup = require('./wdio.browsers.setup');
exports.config = {
seleniumArgs: browsersSetup,
seleniumInstallArgs: browsersSetup,
After that all is working fine #:-)
Note: if you have your web-driver installed globally remove the global setup first it's located in:
C:\Users\%USERNAME%\AppData\Roaming\npm
Then you can run the local installation using:
./node_modules/.bin/selenium-standalone install --config=../../wdio.browsers.setup.js
Please find the below working solution for IE browser to install 32 bit:
services: ["selenium-standalone"],
seleniumArgs: {
drivers: {`enter code here`
ie: {
version: "3.4.0", // or whatever latest is
arch: "ia32", // forces use of 32 bit driver
baseURL: "https://selenium-release.storage.googleapis.com"
},
},
},
seleniumInstallArgs: {
drivers: {
ie: {
version: "3.4.0", // or whatever latest is
arch: "ia32", // forces use of 32 bit driver
baseURL: "https://selenium-release.storage.googleapis.com"
},
},
},

Node JS + Grunt-sonar-runner + Code Coverage not showing

I created a REST service in node js and wrote the test cases using mocha. I have been able to generate the code coverage using istanbul and is working absolutely fine. Now my requirement is to show the code coverage using Sonar. The code compliance violations are getting listed as expected. But the code coverage is not getting generated in sonar. I doubt there is something wrong with the gruntfile.js configuration. Currently, I generate the code compliance violation by copying the source inside the grunt-sonar-runner folder within node_modules and execute grunt-sonar-runner. My current folder structure is as shown below :
<ProjectRoot>
|--server.js
|--[test]
|--|--serverTest.js
|--[node_modules]
|--|--[grunt-sonar-runner]
|--|--|--[src]
|--|--|--|--server.js
In the gruntfile.js,
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/*.js',
'test/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp']
},
// Configuration to be run (and then tested).
sonarRunner: {
analysis: {
options: {
debug: true,
separator: '\n',
sonar: {
host: {
url: 'http://localhost:9000'
},
jdbc: {
url: 'jdbc:h2:tcp://localhost:9092/sonar',
username: 'sonar',
password: 'sonar'
},
projectKey: 'sonar:grunt-sonar-runner:0.1.0',
projectName: 'Grunt Sonar Runner',
projectVersion: '0.10',
sources: ['src'].join(','),
language: 'js',
sourceEncoding: 'UTF-8'
}
}
},
dryRun: {
options: {
dryRun: true,
debug: true,
separator: '\n',
sonar: {
host: {
url: 'http://localhost:9000'
},
jdbc: {
url: 'jdbc:mysql://localhost:3306/sonar',
username: 'sonar',
password: 'sonar'
},
projectKey: 'sonar:grunt-sonar-runner:0.1.0',
projectName: 'Grunt Sonar Runner',
projectVersion: '0.10',
sources: ['src'].join(','),
exclusions: '**/R.js'
}
}
}
},
// Unit tests.
mochaTest: {
test: {
options: {
reporter: 'spec'
},
src: ['test/**/*.js'],
}
}
});
we have two sections --> analysis and dryRun. What is this dryRun ?
Just outside that, we have a key called mochaTest.
While running mocha with istanbul, I am getting coverage reports generated in the project root inside a folder called coverage. Unfortunately it is not getting listed in sonar. Any help would be appreciated.
Thanks in Advance,
Noble
Just had to define a sonar-roject.properties in the project root folder. Inside that properties file, we can specify the relative path to the lcov.info generated by istanbul. After starting up the sonar qube server, just run sonar-runner (provided sonar runner is present in the system path). Sonar reports will be visible in sonar dashboard

How to watch and reload an ExpressJS app with pm2

I'm developing an ExpressJS app.
I use pm2 to load it:
myapp$ pm2 start bin/www
This works fine, except that adding the --watch flag doesn't seem to work; every time I change the JS source I need to explicitly restart it for my changes to take effect:
myapp$ pm2 restart www
What am I doing wrong? I've tried the --watch flag with a non-ExpressJS app and it worked as expected.
See this solution in Stack Overflow
The problem is relative to the path where pm2 is watching, and if it is relative to the execution file or the actual root path of the project.
2021 Feb.
Things have changed a bit now. Gave a full example below from my project. Below works:
1 . Create config file. File: ecosystem.config.js
module.exports = {
apps: [
{
name: 'api',
script: './bin/www', // --------------- our node start script here like index.js
// ------------------------------------ watch options - begin
watch: ['../'],
watch_delay: 1000,
ignore_watch: ['node_modules'],
watch_options: {
followSymlinks: false,
},
// ------------------------------------ watch options - end
env: {
NODE_ENV: 'development',
PORT: 3001,
DEBUG: 'api:*',
MONGODB_URI:
'mongodb://localhost:27017/collection1?readPreference=primary&ssl=false',
},
env_production: {
NODE_ENV: 'production',
},
},
],
deploy: {
production: {
// user: "SSH_USERNAME",
// host: "SSH_HOSTMACHINE",
},
},
};
2 . Run server (dev/ prod)
pm2 start ecosystem.config.js
pm2 start ecosystem.config.js --env production
3 . More information :
https://pm2.keymetrics.io/docs/usage/watch-and-restart/
You need to specify the app location to the --watch option
myapp$ pm2 start bin/www --watch /your/location/to/app
I never managed to make default watch settings work in Ubuntu, however using polling via advanced watch options worked:
"watch": true,
"ignore_watch" : ["node_modules"],
"watch_options": {
"usePolling": true,
"interval": 1000
}
More info:
https://github.com/buunguyen/PM2/blob/master/ADVANCED_README.md#watch--restart
https://github.com/paulmillr/chokidar#api

Loading dependencies outside of the Intern directory when running tests through Selenium

I have a project where Intern unit tests are supposed to be in a different directory tree than the source code under test. Somewhat like this:
projectRoot
projectRoot/src
projectRoot/tests
projectRoot/tests/intern.js
projectRoot/tests/node_modules/intern
projectRoot/tests/MyTestSuite.js
In the Intern configuration file, I define an AMD package that uses relative paths with ../ to reach src from the unit test suites. Here's an example configuration:
define({
environments: [ { browserName: 'chrome', platform: 'WINDOWS' }],
webdriver: { host: 'localhost', port: 4444 },
useSauceConnect: false,
loader: {
packages: [
{ name: 'testSuites', location: '.' },
{ name: 'externalDep', location: '../src' }
]
},
suites: [ 'testSuites/MyTestSuite' ]
});
And a matching unit test suite
define([ "intern!tdd", "intern/chai!assert","externalDep/ExternalDep"],
function(tdd, assert, ExternalDep) {
tdd.suite("Suite that has external dependency", function() {
tdd.test("Test if external dependency is loaded correctly", function() {
assert(ExternalDep === "hello");
});
});
}
);
This works fine when tested directly in the browser (client.html) or node (client.js). When fired off through a Selenium Server (with runner.js), however, the client.html running in the browser started by Selenium can't find the external dependencies. In the above example, it tries to request ExternalDep at http://localhost:9000/__intern/src/ExternalDep.js, which is a 404 because the src directory is not within intern.
I suppose that if I put intern.js at the highest common super-directory of both the tests and the source code, it would work. But our project is currently set up in a way which makes that impractical. Is there a way for configuring sources that live beyond the location of the Intern config file, or did I just make a silly mistake?
Thanks!
There is no problem putting the tests in a different directory from the rest of the code, but projectRoot needs to be the working directory from which you start the runner, and you need to change your loader configuration to match.
So, instead of right now where you are starting Intern from projectRoot/tests like this:
…/projectRoot/tests$ ./.bin/intern-runner config=intern
you need to start it from projectRoot:
…/projectRoot$ ./tests/.bin/intern-runner config=tests/intern
…and change your loader configuration:
loader: {
packages: [
{ name: 'testSuites', location: 'tests' },
{ name: 'externalDep', location: 'src' }
]
},

Resources