Skip to content

Commit

Permalink
Merge pull request #103 from OpenSTFoundation/jasonbanks/gh90/make-uu…
Browse files Browse the repository at this point in the history
…ids-iterable

Make UUIDs iterable on value chain
  • Loading branch information
benjaminbollen authored Feb 2, 2018
2 parents 1395b35 + 04092b3 commit 6b13d2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
38 changes: 9 additions & 29 deletions contracts/OpenSTValue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ contract OpenSTValue is OpsManaged, Hasher {
uint256 public chainIdValue;
EIP20Interface public valueToken;
address public registrar;
bytes32[] public uuids;
mapping(uint256 /* chainIdUtility */ => CoreInterface) internal cores;
mapping(bytes32 /* uuid */ => UtilityToken) internal utilityTokens;
mapping(bytes32 /* uuid */ => UtilityToken) public utilityTokens;
/// nonce makes the staking process atomic across the two-phased process
/// and protects against replay attack on (un)staking proofs during the process.
/// On the value chain nonces need to strictly increase by one; on the utility
Expand Down Expand Up @@ -421,34 +422,6 @@ contract OpenSTValue is OpsManaged, Hasher {
return address(cores[_chainIdUtility]);
}

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

/*
* Public view functions
*/
Expand All @@ -469,6 +442,12 @@ contract OpenSTValue is OpsManaged, Hasher {
return BLOCKS_TO_WAIT_SHORT;
}

/// @dev Returns size of uuids
/// @return size
function getUuidsSize() public view returns (uint256) {
return uuids.length;
}

/*
* Registrar functions
*/
Expand Down Expand Up @@ -534,6 +513,7 @@ contract OpenSTValue is OpsManaged, Hasher {
simpleStake: simpleStake,
stakingAccount: _stakingAccount
});
uuids.push(uuid);

UtilityTokenRegistered(uuid, address(simpleStake), _symbol, _name,
TOKEN_DECIMALS, _conversionRate, _chainIdUtility, _stakingAccount);
Expand Down
3 changes: 3 additions & 0 deletions test/OpenSTValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ contract('OpenSTValue', function(accounts) {
})

it('successfully registers', async () => {
assert.equal(await openSTValue.getUuidsSize.call(), 0);
assert.equal(await openSTValue.registerUtilityToken.call(symbol, name, conversionRate, chainIdRemote, 0, checkUuid, { from: registrar }), checkUuid);
result = await openSTValue.registerUtilityToken(symbol, name, conversionRate, chainIdRemote, 0, checkUuid, { from: registrar });

Expand All @@ -203,6 +204,8 @@ contract('OpenSTValue', function(accounts) {
var simpleStake = new SimpleStake(result.logs[0].args.stake);
assert.equal(await simpleStake.uuid.call(), checkUuid);
assert.equal(await simpleStake.eip20Token.call(), valueToken.address);
assert.equal(await openSTValue.getUuidsSize.call(), 1);
assert.equal((await openSTValue.utilityTokens.call(checkUuid))[0], symbol);
})

it('fails to register if already exists', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/Protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ contract('OpenST', function(accounts) {

stPrimeSimpleStakeContractAddress = event.stake;

Assert.notEqual((await openSTValue.utilityTokenProperties.call(uuidSTP))[5], utils.NullAddress);
Assert.notEqual((await openSTValue.utilityTokens.call(uuidSTP))[5], utils.NullAddress);
});

// Initialize Transfer to ST' Contract Address
Expand Down

0 comments on commit 6b13d2a

Please sign in to comment.