Skip to content

Commit

Permalink
Contracts: make UUIDs iterable. Relates to #90
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Banks committed Jan 31, 2018
1 parent a7104c6 commit 04092b3
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 @@ -112,8 +112,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 @@ -414,34 +415,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 @@ -462,6 +435,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 @@ -527,6 +506,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 @@ -127,7 +127,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 04092b3

Please sign in to comment.