Skip to content

Commit

Permalink
Merge pull request #14 from WingsDao/feature-WEBD-1485
Browse files Browse the repository at this point in the history
New functional tests
  • Loading branch information
RomanFro authored Oct 16, 2018
2 parents 0e0699e + 713fb2b commit 9a78724
Show file tree
Hide file tree
Showing 22 changed files with 1,900 additions and 1,526 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
truffle.js
.node-
2 changes: 1 addition & 1 deletion build/contracts/BasicToken.json
Original file line number Diff line number Diff line change
Expand Up @@ -2362,5 +2362,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.027Z"
"updatedAt": "2018-10-16T06:55:43.628Z"
}
2,370 changes: 1,206 additions & 1,164 deletions build/contracts/Bridge.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/contracts/ControllerStub.json
Original file line number Diff line number Diff line change
Expand Up @@ -1121,5 +1121,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.026Z"
"updatedAt": "2018-10-16T06:55:43.626Z"
}
2 changes: 1 addition & 1 deletion build/contracts/DefaultToken.json
Original file line number Diff line number Diff line change
Expand Up @@ -965,5 +965,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.023Z"
"updatedAt": "2018-10-16T06:55:43.623Z"
}
2 changes: 1 addition & 1 deletion build/contracts/DetailedERC20.json
Original file line number Diff line number Diff line change
Expand Up @@ -1060,5 +1060,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.028Z"
"updatedAt": "2018-10-16T06:55:43.629Z"
}
2 changes: 1 addition & 1 deletion build/contracts/ERC20.json
Original file line number Diff line number Diff line change
Expand Up @@ -1233,5 +1233,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.029Z"
"updatedAt": "2018-10-16T06:55:43.629Z"
}
2 changes: 1 addition & 1 deletion build/contracts/ERC20Basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -802,5 +802,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.030Z"
"updatedAt": "2018-10-16T06:55:43.629Z"
}
506 changes: 274 additions & 232 deletions build/contracts/IBridge.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/contracts/IDAO.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.025Z"
"updatedAt": "2018-10-16T06:55:43.626Z"
}
2 changes: 1 addition & 1 deletion build/contracts/IWingsController.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,5 +651,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.026Z"
"updatedAt": "2018-10-16T06:55:43.626Z"
}
2 changes: 1 addition & 1 deletion build/contracts/Migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.024Z"
"updatedAt": "2018-10-16T06:55:43.624Z"
}
2 changes: 1 addition & 1 deletion build/contracts/Ownable.json
Original file line number Diff line number Diff line change
Expand Up @@ -1455,5 +1455,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.027Z"
"updatedAt": "2018-10-16T06:55:43.628Z"
}
2 changes: 1 addition & 1 deletion build/contracts/SafeMath.json
Original file line number Diff line number Diff line change
Expand Up @@ -2471,5 +2471,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.027Z"
"updatedAt": "2018-10-16T06:55:43.627Z"
}
2 changes: 1 addition & 1 deletion build/contracts/TestToken.json
Original file line number Diff line number Diff line change
Expand Up @@ -1291,5 +1291,5 @@
},
"networks": {},
"schemaVersion": "2.0.0",
"updatedAt": "2018-10-11T13:28:02.026Z"
"updatedAt": "2018-10-16T06:55:43.627Z"
}
2 changes: 1 addition & 1 deletion contracts/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract Bridge is IBridge {
// called by CrowdsaleController to transfer reward part of ETH
// collected by successful crowdsale to Forecasting contract.
// This call is made upon closing successful crowdfunding process
// iff agreed ETH reward part is not zero
// if agreed ETH reward part is not zero
function mintETHRewards(
address _contract, // Forecasting contract
uint256 _amount // agreed part of totalCollected which is intended for rewards
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ contract IBridge is Ownable {
DetailedERC20 token;

// crowdsale status
bool completed;
bool failed;
bool public completed;
bool public failed;

// whether sale results were communicated to crowdsale controller or not
bool notifiedSale;
bool public notifiedSale;

function transferManager(address _newManager) public onlyManager() {
require(_newManager != address(0));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wings-light-bridge",
"version": "1.2.3",
"version": "1.2.4",
"description": "Wings easy integration.",
"main": "truffle.js",
"directories": {
Expand Down
84 changes: 37 additions & 47 deletions test/Bridge.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Test scenario:
* - create bridge
* - set project token
* - set goal
* - set period
* - notify about collected amount
* - transfer rewards
* - check whether crowdsale reached minimal goal or not
* - finish bridge successfully
*/

'use strict';

const { should } = require('chai').should();
Expand All @@ -9,42 +21,28 @@ const ControllerStub = artifacts.require('ControllerStub');
const { sendETH, isRevert } = require('./helpers/utils');

contract('Bridge', (accounts) => {
let creator = accounts[0];
const creator = accounts[0];

const rewards = {
tokens: 10000,
eth: 10000
};

let totalCollected = web3.toWei(600000, 'ether'); // let's say 600000 USD
let totalCollectedETH = web3.toWei(100, 'ether');
let totalSold = web3.toWei(1500, 'ether');
const totalCollected = web3.toWei(600000, 'ether'); // let's say 600000 USD
const totalCollectedETH = web3.toWei(1000, 'ether');
const totalSold = web3.toWei(100000, 'ether');

let token, controller, bridge;

before(async () => {
// deploy bridge
bridge = await Bridge.new(
creator,
creator,
{
from: creator
}
);

// controller stub just for manager
controller = await ControllerStub.new(
rewards.eth,
rewards.tokens,
{
from: creator
}
);
bridge = await Bridge.new(creator, creator, { from: creator });

// deploy controller stub (it is manager of the bridge)
controller = await ControllerStub.new(rewards.eth, rewards.tokens, { from: creator });

// start crowdsale (in wings will be done in controller)
await bridge.start(0, 0, '0x0', {
from: creator
});
await bridge.start(0, 0, '0x0', { from: creator });
});

it('deploy token', async () => {
Expand All @@ -53,17 +51,14 @@ contract('Bridge', (accounts) => {
});
});

it('allow to change token', async () => {
const changeToken_event = bridge.CUSTOM_CROWDSALE_TOKEN_ADDED({}, {fromBlock: 0, toBlock: 'latest'});

it('change token', async () => {
await bridge.changeToken(token.address, {
from: creator
});

changeToken_event.get((error, events) => {
let args = events[0].args
args.token.should.be.equal(token.address)
});
let projectToken = (await bridge.getToken.call()).toString();

projectToken.should.be.equal(token.address)
});

it('doesn\'t allow to change token to token with incorrect decimals', async () => {
Expand All @@ -80,29 +75,27 @@ contract('Bridge', (accounts) => {
}
});

it('allow to set only minimal goal', async () => {
it('set only minimal goal', async () => {
const minimalGoal = web3.toWei(10, 'ether').toString(10);

await bridge.setCrowdsaleGoal(minimalGoal, 0, { from: creator });

let bridgeMinimalGoal = (await bridge.minimalGoal.call()).toString(10);
// console.log(`Minimal goal: ${web3.fromWei(bridgeMinimalGoal, 'ether')} ETH`);

bridgeMinimalGoal.should.be.equal(minimalGoal);
});

it('allow to set only hard cap', async () => {
it('set only hard cap', async () => {
const hardCap = web3.toWei(1000, 'ether').toString(10);

await bridge.setCrowdsaleGoal(0, hardCap, { from: creator });

let bridgeHardCap = (await bridge.hardCap.call()).toString(10);
// console.log(`Hard cap: ${web3.fromWei(bridgeHardCap, 'ether')} ETH`);

bridgeHardCap.should.be.equal(hardCap);
});

it('allow to set goals of crowdsale', async () => {
it('set goals of crowdsale', async () => {
const goal = {
min: web3.toWei(15, 'ether').toString(10),
max: web3.toWei(1500, 'ether').toString(10)
Expand All @@ -113,27 +106,23 @@ contract('Bridge', (accounts) => {
const minimalGoal = (await bridge.minimalGoal.call()).toString(10);
const hardCap = (await bridge.hardCap.call()).toString(10);

// console.log(`Minimal goal: ${web3.fromWei(minimalGoal, 'ether')} ETH`);
// console.log(`Hard cap: ${web3.fromWei(hardCap, 'ether')} ETH`);

minimalGoal.should.be.equal(goal.min);
hardCap.should.be.equal(goal.max);
});

it('allow to set only end timestamp', async () => {
it('set only end timestamp', async () => {
const now = Date.now();

const endTimestamp = Math.floor(now/1000).toString(10);

await bridge.setCrowdsalePeriod(0, endTimestamp, { from: creator });

let bridgeEndTimestamp = (await bridge.endTimestamp.call()).toString(10);
// console.log(`End timestamp: ${parseInt(bridgeEndTimestamp)}`);

bridgeEndTimestamp.should.be.equal(endTimestamp);
});

it('allow to set time period of crowdsale', async () => {
it('set time period of crowdsale', async () => {
const now = Date.now();

const timestamps = {
Expand All @@ -146,17 +135,12 @@ contract('Bridge', (accounts) => {
let startTimestamp = (await bridge.startTimestamp.call()).toString(10);
let endTimestamp = (await bridge.endTimestamp.call()).toString(10);

// console.log(`Start timestamp: ${parseInt(startTimestamp)}`);
// console.log(`End timestamp: ${parseInt(endTimestamp)}`);

startTimestamp.should.be.equal(timestamps.start);
endTimestamp.should.be.equal(timestamps.end);
});

it('notify sale', async () => {
await bridge.notifySale(totalCollected, totalCollectedETH, totalSold, {
from: creator
});
await bridge.notifySale(totalCollected, totalCollectedETH, totalSold, { from: creator });
});

it('check how notification went', async () => {
Expand Down Expand Up @@ -217,6 +201,12 @@ contract('Bridge', (accounts) => {
rewardsReady.should.be.equal(true);
});

it('crowdsale reached minimal goal', async () => {
let reached = await bridge.reachedMinGoal.call();

reached.should.be.equal(true);
});

it('finish Bridge successfully', async () => {
await bridge.finish({
from: creator
Expand Down
Loading

0 comments on commit 9a78724

Please sign in to comment.