Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC - BDD Test with cucumber #56

Draft
wants to merge 7 commits into
base: feature/peg_out
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions btest/features/registerBridge.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: User Register as a Bridge/LP

Scenario: Should register User as a Liquidity Provider
When User register as LP for the first time
Then User is registered as LP

14 changes: 14 additions & 0 deletions btest/helpers/basics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
async function estimateGas(deploy) {
console.log('deploy estimategas: ', deploy.estimateGas)

let gas = await deploy.estimateGas()
console.log('gas: ', gas)
gas = parseInt(gas)
gas += parseInt(gas/4)

return gas
}

module.exports = {
estimateGas
}
Empty file added btest/steps/pegin.steps.js
Empty file.
60 changes: 60 additions & 0 deletions btest/steps/registerBridge.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const assert = require('assert').strict;
const { Given, When, Then } = require('@cucumber/cucumber');
const { abi, bytecode } = require('../../build/contracts/LiquidityBridgeContract.json')
const ganache = require('ganache-cli'); // Mockup of eth network
const web3 = new (require('web3'))(ganache.provider());
const { estimateGas } = require('../helpers/basics');

// const state = {
// error: undefined,
// }

// todo: check if are real vals
const bridgeAddress = '0x0000000000000000000000000000000001000006';
const MINIMUM_COLLATERAL = "1"; // amount in wei
const MINIMUM_PEG_IN = "500000000000000000"; // amount in wei
const REWARD_PERCENTAGE = 10;
const RESIGN_DELAY_BLOCKS = 1;
const DUST_THRESHOLD = 2300 * 65164000;

let instance;

When (/User register as LP for the first time$/, async function () {
const accounts = await web3.eth.getAccounts()

try {
instance = new web3.eth.Contract(abi)
.deploy({
data: bytecode,
arguments: [bridgeAddress, MINIMUM_COLLATERAL, MINIMUM_PEG_IN, REWARD_PERCENTAGE, RESIGN_DELAY_BLOCKS, DUST_THRESHOLD]
})
console.log('deploy: ', instance)

// const gas = await estimateGas(deploy)
const gas = 5000000

console.log('gas', gas)
console.log('accounts[0]', accounts[0])
// instance = await deploy.send({
// from: accounts[0],
// gas
// })

// {from: currAddr, value : utils.LP_COLLATERAL}
// console.log('instance methods: ', instance._parent.methods)
const registerMethod = instance._parent.methods.register();
console.log('register method', registerMethod)
const methodGas = await estimateGas(registerMethod);
console.log('register method gas', methodGas)

const tx = await registerMethod.send({from: accounts[1], value: web3.utils.toBN(100)})
console.log('transaction: ', tx)
} catch (e) {
console.error("err: ", e)
}
})


Then (/User is registered as LP$/, async function () {
console.log('then: ', 1)
})
25 changes: 25 additions & 0 deletions config/cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const common = {
parallel: 2,
// format: ['progress-bar', 'cucumber-console-formatter', 'json:./reports/json/cucumber_report.json', 'html:./reports/html/cucumber_report.html'],
format: ['progress-bar', 'cucumber-console-formatter'],
paths: ['./btest/features/*.feature'],
require: ['./btest/steps/*steps.js'],
publishQuiet: true,
environment: {
API_URL: 'http://localhost:8080'
}
}

module.exports = {
default: {
...common
},
smoke: {
...common,
tags: "@smoke",
},
regression: {
...common,
tags: "@regression and not @smoke",
}
};
Loading