Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2340] simple permissioning smart contract #1035

Merged
merged 20 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactoring
  • Loading branch information
macfarla committed Mar 4, 2019
commit 959b92e0b71d2b366f753ced5f7e4a3b95190a96
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
const TestPermissioning = artifacts.require('SimplePermissioning.sol');
var proxy;
var b4 = "0x9bd359fd";
var b32 = "0x9bd359fdc3a2ed5df436c3d8914b1532740128929892092b7fcb320c1b62f375";
var port1 = 30303;
var port2 = 30304;

var node1High = "0x9bd359fdc3a2ed5df436c3d8914b1532740128929892092b7fcb320c1b62f375";
var node1Low = "0x892092b7fcb320c1b62f3759bd359fdc3a2ed5df436c3d8914b1532740128929";
var node1Host = "0x9bd359fd";
var node1Port = 30303;

var node2High = "0x892092b7fcb320c1b62f3759bd359fdc3a2ed5df436c3d8914b1532740128929";
var node2Low = "0x892092b7fcb320c1b62f3759bd359fdc3a2ed5df436c3d8914b1532740128929";
var node2Host = "0x9bd359fd";
var node2Port = 30304;

contract('Permissioning Ipv4', () => {
describe('Function: permissioning Ipv4', () => {
it('Should NOT permit any node when none have been added', async () => {
proxy = await TestPermissioning.new();
let permitted = await proxy.enodeAllowedIpv4(b32, b32, b4, port1);
let permitted = await proxy.enodeAllowedIpv4(node1High, node1Low, node1Host, node1Port);
assert.equal(permitted, false, 'expected node NOT permitted');
});

it('Should compute key', async () => {
let key1 = await proxy.computeKeyIpv4(b32, b32, b4, port1);
let key2 = await proxy.computeKeyIpv4(b32, b32, b4, port1);
let key1 = await proxy.computeKeyIpv4(node1High, node1Low, node1Host, node1Port);
let key2 = await proxy.computeKeyIpv4(node1High, node1Low, node1Host, node1Port);
assert.equal(key1, key2, "computed keys should be the same");

let key3 = await proxy.computeKeyIpv4(b32, b32, b4, port2);
let key3 = await proxy.computeKeyIpv4(node1High, node1Low, node1Host, node2Port);
assert(key3 != key2, "keys for different ports should be different");
});

it('Should add a node to the whitelist and then permit that node', async () => {
await proxy.addEnodeIpv4(b32, b32, b4, port1);
let permitted = await proxy.enodeAllowedIpv4(b32, b32, b4, port1);
await proxy.addEnodeIpv4(node1High, node1Low, node1Host, node1Port);
let permitted = await proxy.enodeAllowedIpv4(node1High, node1Low, node1Host, node1Port);
assert.equal(permitted, true, 'expected node added to be permitted');

// await another
await proxy.addEnodeIpv4(b32, b32, b4, port2);
permitted = await proxy.enodeAllowedIpv4(b32, b32, b4, port2);
await proxy.addEnodeIpv4(node2High, node2Low, node2Host, node2Port);
permitted = await proxy.enodeAllowedIpv4(node2High, node2Low, node2Host, node2Port);
assert.equal(permitted, true, 'expected node 2 added to be permitted');

// first one still permitted
permitted = await proxy.enodeAllowedIpv4(b32, b32, b4, port1);
permitted = await proxy.enodeAllowedIpv4(node1High, node1Low, node1Host, node1Port);
assert.equal(permitted, true, 'expected node 1 added to be permitted');
});

it('Should allow a connection between 2 added nodes', async () => {
let permitted = await proxy.connectionAllowedIpv4(node1High, node1Low, node1Host, node1Port, node2High, node2Low, node2Host, node2Port);
assert.equal(permitted, true, 'expected 2 added nodes to work as source <> destination');
});

it('Should remove a node from the whitelist and then NOT permit that node', async () => {
await proxy.removeEnodeIpv4(b32, b32, b4, port1);
let permitted = await proxy.enodeAllowedIpv4(b32, b32, b4, port1);
await proxy.removeEnodeIpv4(node1High, node1Low, node1Host, node1Port);
let permitted = await proxy.enodeAllowedIpv4(node1High, node1Low, node1Host, node1Port);
assert.equal(permitted, false, 'expected removed node NOT permitted');

permitted = await proxy.connectionAllowedIpv4(node1High, node1Low, node1Host, node1Port, node2High, node2Low, node2Host, node2Port);
assert.equal(permitted, false, 'expected source disallowed since it was removed');
});

});
Expand Down
44 changes: 26 additions & 18 deletions ethereum/permissioning/src/main/resources/test-permissioning.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,62 @@
const TestPermissioning = artifacts.require('SimplePermissioning.sol');
var proxy;
var b16 = "0x9bd359fdc3a2ed5df436c3d8914b1532";
var b162 = "0x596c3d8914b1532fdc3a2ed5df439bd3";
var b32 = "0x9bd359fdc3a2ed5df436c3d8914b1532740128929892092b7fcb320c1b62f375";
var b322 = "0x892092b7fcb320c1b62f3759bd359fdc3a2ed5df436c3d8914b1532740128929";
var port1 = 30303;
var port2 = 30304;

var node1High = "0x9bd359fdc3a2ed5df436c3d8914b1532740128929892092b7fcb320c1b62f375";
var node1Low = "0x892092b7fcb320c1b62f3759bd359fdc3a2ed5df436c3d8914b1532740128929";
var node1Host = "0x9bd359fdc3a2ed5df436c3d8914b1532";
var node1Port = 30303;

var node2High = "0x892092b7fcb320c1b62f3759bd359fdc3a2ed5df436c3d8914b1532740128929";
var node2Low = "0x892092b7fcb320c1b62f3759bd359fdc3a2ed5df436c3d8914b1532740128929";
var node2Host = "0x596c3d8914b1532fdc3a2ed5df439bd3";
var node2Port = 30304;

contract('Permissioning Ipv6', () => {
describe('Function: permissioning Ipv6', () => {

it('Should NOT permit any node when none have been added', async () => {
proxy = await TestPermissioning.new();
let permitted = await proxy.enodeAllowedIpv6(b32, b32, b16, port1);
let permitted = await proxy.enodeAllowedIpv6(node1High, node1Low, node1Host, node1Port);
assert.equal(permitted, false, 'expected node NOT permitted');
});

it('Should compute key', async () => {
let key1 = await proxy.computeKeyIpv6(b32, b32, b16, port1);
let key2 = await proxy.computeKeyIpv6(b32, b32, b16, port1);
let key1 = await proxy.computeKeyIpv6(node1High, node1Low, node1Host, node1Port);
let key2 = await proxy.computeKeyIpv6(node1High, node1Low, node1Host, node1Port);
assert.equal(key1, key2, "computed keys should be the same");

let key3 = await proxy.computeKeyIpv6(b32, b32, b16, port2);
let key3 = await proxy.computeKeyIpv6(node1High, node1Low, node1Host, node2Port);
assert(key3 != key2, "keys for different ports should be different");
});

it('Should add a node to the whitelist and then permit that node', async () => {
await proxy.addEnodeIpv6(b32, b32, b16, port1);
let permitted = await proxy.enodeAllowedIpv6(b32, b32, b16, port1);
await proxy.addEnodeIpv6(node1High, node1Low, node1Host, node1Port);
let permitted = await proxy.enodeAllowedIpv6(node1High, node1Low, node1Host, node1Port);
assert.equal(permitted, true, 'expected node added to be permitted');

// await another
await proxy.addEnodeIpv6(b32, b322, b162, port2);
permitted = await proxy.enodeAllowedIpv6(b32, b322, b162, port2);
await proxy.addEnodeIpv6(node2High, node2Low, node2Host, node2Port);
permitted = await proxy.enodeAllowedIpv6(node2High, node2Low, node2Host, node2Port);
assert.equal(permitted, true, 'expected node 2 added to be permitted');

// first one still permitted
permitted = await proxy.enodeAllowedIpv6(b32, b32, b16, port1);
permitted = await proxy.enodeAllowedIpv6(node1High, node1Low, node1Host, node1Port);
assert.equal(permitted, true, 'expected node 1 added to be permitted');
});

it('Should allow a connection between 2 added nodes', async () => {
let permitted = await proxy.connectionAllowedIpv6(b32, b32, b16, port1, b32, b322, b162, port2);
let permitted = await proxy.connectionAllowedIpv6(node1High, node1Low, node1Host, node1Port, node2High, node2Low, node2Host, node2Port);
assert.equal(permitted, true, 'expected 2 added nodes to work as source <> destination');
});

it('Should remove a node from the whitelist and then NOT permit that node', async () => {
await proxy.removeEnodeIpv6(b32, b32, b16, port1);
let permitted = await proxy.enodeAllowedIpv6(b32, b32, b16, port1);
await proxy.removeEnodeIpv6(node1High, node1Low, node1Host, node1Port);
let permitted = await proxy.enodeAllowedIpv6(node1High, node1Low, node1Host, node1Port);
assert.equal(permitted, false, 'expected removed node NOT permitted');

permitted = await proxy.connectionAllowedIpv6(node1High, node1Low, node1Host, node1Port, node2High, node2Low, node2Host, node2Port);
assert.equal(permitted, false, 'expected source disallowed since it was removed');

});

});
Expand Down