Add registered call

This commit is contained in:
Andrea Maria Piana 2019-04-08 11:36:32 +02:00
parent 9c5b5be8d5
commit de5fa5f6ec
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
3 changed files with 52 additions and 2 deletions

View File

@ -70,6 +70,14 @@ contract NodesV2
inactiveNodeIndex[msg.sender] = inactiveNodes.length;
}
function registered(bytes memory publicKey)
public
view
returns (bool) {
address node = publicKeyToAddress(publicKey);
return !(activeNodeIndex[node] == 0 && inactiveNodeIndex[node] == 0);
}
function activeNodeCount() public view returns (uint) {
return activeNodes.length;
}

File diff suppressed because one or more lines are too long

View File

@ -124,6 +124,22 @@ contract('Nodes', async (accounts) => {
});
});
describe('registered', async () => {
beforeEach(async () => {
await instance.registerNode(node1.pk, node1.ip, node1.port);
});
it('it returns true when node is registered', async () => {
const response = await instance.registered(node1.pk);
assert.equal(true, response);
});
it('it returns true when node is registered', async () => {
const response = await instance.registered(node2.pk);
assert.equal(false, response);
});
});
describe('vote', async () => {
describe('first round of voting', async () => {
// Node1, Node2 and Node3 are active, Node4 is inactive