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

Integration tests framework #37

Merged
merged 21 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cac26f4
test: Protocol.js deploy and add core
benjaminbollen Nov 29, 2017
eaa5122
Adding truffle and ethereumjs-testrpc in dev dependencies
Nov 29, 2017
3c4e15e
test: simple gas measurement tracker and apply to integration tests
benjaminbollen Nov 29, 2017
7fa678e
test: register STP
benjaminbollen Nov 30, 2017
e25a580
test: Task Separation & Indentation Update
Nov 30, 2017
dbddcf4
test: Initialize Transfer to ST' Contract Address
Nov 30, 2017
d2007af
test: Protocol.js propose and registerd branded token
Nov 30, 2017
a4ed335
test: Protocol.js Adding registerUtilitytoken for branded token
Nov 30, 2017
846cb8e
Test: Protocol.js changing the call method to actual call
Nov 30, 2017
688da6d
test: Added Event Decoder Library for Events Assert
Nov 30, 2017
05926d0
test: stake for ST Prime
benjaminbollen Nov 30, 2017
021d338
test: Member details in global scope for everyone to use
Nov 30, 2017
3ae1376
Test: Protocol.js changing the validation based on events raised thro…
Nov 30, 2017
4e8fd5e
test: Protocol stake ST for ST Prime
benjaminbollen Dec 1, 2017
9f0c4fd
test: Member details in global scope for everyone to use
Nov 30, 2017
3993778
test: Basic Skeleton for Stake and Mint
Dec 1, 2017
d0b4d3d
test: approve and stake Simple Token
Dec 1, 2017
2531573
Test: Protocol.js staking st for branded token
Dec 1, 2017
90ce861
test: unstake ST' by redeemer, unstake BT by redeemer
Dec 5, 2017
f987c8a
test: clean up protocol integration test
benjaminbollen Dec 5, 2017
e1de2ce
test: disable operation functions as dead code
benjaminbollen Dec 5, 2017
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
3 changes: 3 additions & 0 deletions contracts/Core.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pragma solidity ^0.4.17;

import "./CoreInterface.sol";


/// @dev Core is a minimal stub that will become the anchoring and consensus point for
/// the utility chain to validate itself against
contract Core is CoreInterface {

/*
Expand Down
16 changes: 16 additions & 0 deletions contracts/OpenSTUtility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,22 @@ contract OpenSTUtility is Hasher, OpsManaged {
return tokenAddress;
}

/*
* Public view functions
*/
function registeredTokenProperties(
bytes32 _uuid)
external
view
returns (
address /* token */,
address /* registrar */)
{
RegisteredToken storage registeredToken = registeredTokens[_uuid];
return (
address(registeredToken.token),
registeredToken.registrar);
}

/*
* Operation functions
Expand Down
38 changes: 36 additions & 2 deletions contracts/OpenSTValue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ contract OpenSTValue is OpsManaged, Hasher {
bytes32 redemptionIntentHash = hashRedemptionIntent(
_uuid,
_redeemer,
nonces[_redeemer]++,
nonces[_redeemer],
_amountUT,
_redemptionUnlockHeight
);
Expand Down Expand Up @@ -329,11 +329,45 @@ contract OpenSTValue is OpsManaged, Hasher {
address _account)
public
view
returns (uint256 nextNonce)
returns (uint256 /* nextNonce */)
{
return (nonces[_account] + 1);
}

function core(
uint256 _chainIdUtility)
external
view
returns (address /* core address */ )
{
return address(cores[_chainIdUtility]);
}

function utilityTokenProperties(
bytes32 _uuid)
external
view
returns (
string symbol,
string name,
uint256 conversionRate,
uint8 decimals,
uint256 chainIdUtility,
address simpleStake,
address stakingAccount
/* utility token struct */ )
{
UtilityToken storage utilityToken = utilityTokens[_uuid];
return (
utilityToken.symbol,
utilityToken.name,
utilityToken.conversionRate,
utilityToken.decimals,
utilityToken.chainIdUtility,
address(utilityToken.simpleStake),
utilityToken.stakingAccount);
}

/*
* Registrar functions
*/
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"moment": "^2.19.2",
"web3": "^0.20.2"
},
"devDependencies": {},
"devDependencies": {
"truffle": "^4.0.1",
"ganache-cli": "^6.0.3",
"abi-decoder": "^1.0.9"
},
"author": "OpenST Foundation Ltd.",
"license": "Apache v2.0"
}
21 changes: 0 additions & 21 deletions test/OpenST.js

This file was deleted.

4 changes: 4 additions & 0 deletions test/OpenSTUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ contract('OpenSTUtility', function(accounts) {
})
})

/**
* note: code is removed from contracts as unused and space needed for protocol completion
TODO: remove once certain no such logic is required
describe('AddNameReservation', async () => {
before(async () => {
Expand Down Expand Up @@ -577,4 +580,5 @@ contract('OpenSTUtility', function(accounts) {
await Utils.expectThrow(openSTUtility.removeSymbolRoute(hashSymbol, { from: accounts[2] }));
})
})
*/
})
55 changes: 55 additions & 0 deletions test/OpenSTUtility_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ module.exports.checkProposedBrandedTokenEvent = (event, _requester, _uuid, _symb
assert.equal(event.args._conversionRate.toNumber(), _conversionRate.toNumber());
}

module.exports.validateProposedBrandedTokenEvent = (event, _requester, _symbol, _name, _conversionRate) => {
if (Number.isInteger(_conversionRate)) {
_conversionRate = new BigNumber(_conversionRate);
}

assert.equal(event.event, "ProposedBrandedToken");
assert.equal(event.args._requester, _requester);
assert.equal(event.args._symbol, _symbol);
assert.equal(event.args._name, _name);
assert.equal(event.args._conversionRate.toNumber(), _conversionRate.toNumber());
}


module.exports.checkRegisteredBrandedTokenEvent = (event, _registrar, _token, _uuid, _symbol, _name, _conversionRate, _requester) => {
assert.equal(event.event, "RegisteredBrandedToken");
if (Number.isInteger(_conversionRate)) {
Expand All @@ -71,6 +84,25 @@ module.exports.checkRegisteredBrandedTokenEvent = (event, _registrar, _token, _u
assert.equal(event.args._requester, _requester);
}

module.exports.checkRegisteredBrandedTokenEventOnProtocol = (formattedDecodedEvents, _registrar, _token, _uuid, _symbol, _name, _conversionRate, _requester) => {

var event = formattedDecodedEvents['RegisteredBrandedToken'];

assert.notEqual(event, null);

if (Number.isInteger(_conversionRate)) {
_conversionRate = new BigNumber(_conversionRate);
}

assert.equal(event._registrar, _registrar);
assert.equal(event._token, _token);
assert.equal(event._uuid, _uuid);
assert.equal(event._symbol, _symbol);
assert.equal(event._name, _name);
assert.equal(event._conversionRate, _conversionRate.toNumber());
assert.equal(event._requester, _requester);
}

module.exports.checkStakingIntentConfirmedEvent = (event, _uuid, _stakingIntentHash, _staker, _beneficiary, _amountST, _amountUT, _expirationHeight) => {
if (Number.isInteger(_amountST)) {
_amountST = new BigNumber(_amountST);
Expand All @@ -94,6 +126,29 @@ module.exports.checkStakingIntentConfirmedEvent = (event, _uuid, _stakingIntentH
assert.equal(event.args._expirationHeight.toNumber(), _expirationHeight.toNumber());
}

module.exports.checkStakingIntentConfirmedEventOnProtocol = (formattedDecodedEvents, _uuid, _stakingIntentHash,
_staker, _beneficiary, _amountST, _amountUT) => {

var event = formattedDecodedEvents['StakingIntentConfirmed'];

assert.notEqual(event, null);

if (Number.isInteger(_amountST)) {
_amountST = new BigNumber(_amountST);
}

if (Number.isInteger(_amountUT)) {
_amountUT = new BigNumber(_amountUT);
}

assert.equal(event._uuid, _uuid);
assert.equal(event._stakingIntentHash, _stakingIntentHash);
assert.equal(event._staker, _staker);
assert.equal(event._beneficiary, _beneficiary);
assert.equal(event._amountST, _amountST.toNumber());
assert.equal(event._amountUT, _amountUT.toNumber());
}

module.exports.checkProcessedMintEvent = (event, _uuid, _stakingIntentHash, _token, _staker, _beneficiary, _amount) => {
if (Number.isInteger(_amount)) {
_amount = new BigNumber(_amount);
Expand Down
110 changes: 109 additions & 1 deletion test/OpenSTValue_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ module.exports.checkUtilityTokenRegisteredEvent = (event, _uuid, _symbol, _name,

assert.equal(event.event, "UtilityTokenRegistered");
assert.equal(event.args._uuid, _uuid);
// TODO: re-evaluate checking
// assert.equal(event.args.stake, stake);
assert.equal(event.args._symbol, _symbol);
assert.equal(event.args._name, _name);
assert.equal(event.args._decimals.toNumber(), _decimals);
Expand All @@ -63,6 +65,30 @@ module.exports.checkUtilityTokenRegisteredEvent = (event, _uuid, _symbol, _name,
assert.equal(event.args._stakingAccount, _stakingAccount);
}

module.exports.checkUtilityTokenRegisteredEventOnProtocol = (formattedDecodedEvents, _uuid, _symbol, _name, _decimals, _conversionRate, _chainIdUtility, _stakingAccount) => {

var event = formattedDecodedEvents['UtilityTokenRegistered'];

assert.notEqual(event, null);

if (Number.isInteger(_decimals)) {
_decimals = new BigNumber(_decimals);
}

if (Number.isInteger(_conversionRate)) {
_conversionRate = new BigNumber(_conversionRate);
}

assert.equal(event._uuid, _uuid);
// assert.equal(event.args.stake, stake);
assert.equal(event._symbol, _symbol);
assert.equal(event._name, _name);
assert.equal(event._decimals, _decimals);
assert.equal(event._conversionRate, _conversionRate);
assert.equal(event._chainIdUtility, _chainIdUtility);
assert.equal(event._stakingAccount, _stakingAccount);
}

module.exports.checkStakingIntentDeclaredEvent = (event, _uuid, _staker, _stakerNonce, _beneficiary, _amountST, _amountUT, _unlockHeight, _stakingIntentHash, _chainIdUtility) => {
if (Number.isInteger(_stakerNonce)) {
_stakerNonce = new BigNumber(_stakerNonce);
Expand Down Expand Up @@ -92,6 +118,66 @@ module.exports.checkStakingIntentDeclaredEvent = (event, _uuid, _staker, _staker
assert.equal(event.args._chainIdUtility, _chainIdUtility);
}

module.exports.checkStakingIntentDeclaredEventProtocol = (formattedDecodedEvents, _uuid, _staker, _stakerNonce, _beneficiary,
_amountST, _amountUT, _chainIdUtility) => {

var event = formattedDecodedEvents['StakingIntentDeclared'];

if (Number.isInteger(_stakerNonce)) {
_stakerNonce = new BigNumber(_stakerNonce);
}

if (Number.isInteger(_amountST)) {
_amountST = new BigNumber(_amountST);
}

if (Number.isInteger(_amountUT)) {
_amountUT = new BigNumber(_amountUT);
}

if (Number.isInteger(_chainIdUtility)) {
_chainIdUtility = new BigNumber(_chainIdUtility);
}

assert.equal(event.event, "StakingIntentDeclared");
assert.equal(event._uuid, _uuid);
assert.equal(event._staker, _staker);
assert.equal(event._stakerNonce, _stakerNonce.toNumber());
assert.equal(event._beneficiary, _beneficiary);
assert.equal(event._amountST, _amountST.toNumber());
assert.equal(event._amountUT, _amountUT.toNumber());
assert.equal(event._chainIdUtility, _chainIdUtility.toNumber());
}

module.exports.checkStakingIntentDeclaredEventProtocol = (event, _uuid, _staker, _stakerNonce, _beneficiary,
_amountST, _amountUT, _chainIdUtility) => {

if (Number.isInteger(_stakerNonce)) {
_stakerNonce = new BigNumber(_stakerNonce);
}

if (Number.isInteger(_amountST)) {
_amountST = new BigNumber(_amountST);
}

if (Number.isInteger(_amountUT)) {
_amountUT = new BigNumber(_amountUT);
}

if (Number.isInteger(_chainIdUtility)) {
_chainIdUtility = new BigNumber(_chainIdUtility);
}

assert.equal(event.event, "StakingIntentDeclared");
assert.equal(event.args._uuid, _uuid);
assert.equal(event.args._staker, _staker);
assert.equal(event.args._stakerNonce.toNumber(), _stakerNonce.toNumber());
assert.equal(event.args._beneficiary, _beneficiary);
assert.equal(event.args._amountST.toNumber(), _amountST.toNumber());
assert.equal(event.args._amountUT.toNumber(), _amountUT.toNumber());
assert.equal(event.args._chainIdUtility.toNumber(), _chainIdUtility.toNumber());
}

module.exports.checkProcessedStakeEvent = (event, _uuid, _stakingIntentHash, _stake, _staker, _amountST, _amountUT) => {
if (Number.isInteger(_amountST)) {
_amountST = new BigNumber(_amountST);
Expand Down Expand Up @@ -132,6 +218,28 @@ module.exports.checkRedemptionIntentConfirmedEvent = (event, _uuid, _redemptionI
assert.equal(event.args._unlockHeight.toNumber(), _unlockHeight.toNumber());
}

module.exports.checkRedemptionIntentConfirmedEventOnProtocol = (formattedDecodedEvents, uuid, _redemptionIntentHash, _redeemer, _amountST, _amountUT) => {
var event = formattedDecodedEvents['RedemptionIntentConfirmed'];
assert.notEqual(event, null);

if (Number.isInteger(_amountST)) {
_amountST = new BigNumber(_amountST);
}

if (Number.isInteger(_amountUT)) {
_amountUT = new BigNumber(_amountUT);
}

var _unlockHeight = new BigNumber(event._expirationHeight);

assert.equal(event._uuid, uuid);
assert.equal(event._redemptionIntentHash, _redemptionIntentHash);
assert.equal(event._redeemer, _redeemer);
assert.equal(event._amountST, _amountST.toNumber());
assert.equal(event._amountUT, _amountUT.toNumber());
assert.isAbove(_unlockHeight.toNumber(), 0);
}

module.exports.checkProcessedUnstakeEvent = (event, _uuid, _redemptionIntentHash, stake, _redeemer, _amountST) => {
if (Number.isInteger(_amountST)) {
_amountST = new BigNumber(_amountST);
Expand All @@ -143,4 +251,4 @@ module.exports.checkProcessedUnstakeEvent = (event, _uuid, _redemptionIntentHash
assert.equal(event.args.stake, stake);
assert.equal(event.args._redeemer, _redeemer);
assert.equal(event.args._amountST.toNumber(), _amountST.toNumber());
}
}
Loading