Skip to content

Commit

Permalink
Merge pull request #37 from OpenSTFoundation/benjaminbollen/gh14/inte…
Browse files Browse the repository at this point in the history
…gration

Integration tests framework
  • Loading branch information
benjaminbollen authored Dec 6, 2017
2 parents d5c45fa + e1de2ce commit dc2e5df
Show file tree
Hide file tree
Showing 13 changed files with 982 additions and 33 deletions.
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._expirationHeight.toNumber(), _expirationHeight.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

0 comments on commit dc2e5df

Please sign in to comment.