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

Make UUIDs iterable on value chain #103

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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