This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple account permissioning (#1409)
* simple account permissioning
- Loading branch information
Showing
7 changed files
with
135 additions
and
67 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...ptance-tests/simple-permissioning-smart-contract/contracts/SimpleAccountPermissioning.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pragma solidity >=0.4.0 <0.6.0; | ||
// THIS CONTRACT IS FOR TESTING PURPOSES ONLY | ||
// DO NOT USE THIS CONTRACT IN PRODUCTION APPLICATIONS | ||
|
||
contract SimpleAccountPermissioning { | ||
mapping (address => bool) private whitelist; | ||
|
||
function transactionAllowed( | ||
address sender, | ||
address target, | ||
uint256 value, | ||
uint256 gasPrice, | ||
uint256 gasLimit, | ||
bytes memory payload) | ||
public view returns (bool) { | ||
return whitelistContains(sender); | ||
} | ||
function addAccount(address account) public { | ||
whitelist[account] = true; | ||
} | ||
function removeAccount(address account) public { | ||
whitelist[account] = false; | ||
} | ||
function whitelistContains(address account) public view returns(bool) { | ||
return whitelist[account]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
acceptance-tests/simple-permissioning-smart-contract/migrations/2_deploy_contracts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
var SimplePermissioning = artifacts.require("SimplePermissioning"); | ||
var SimpleNodePermissioning = artifacts.require("SimpleNodePermissioning"); | ||
var SimpleAccountPermissioning = artifacts.require("SimpleAccountPermissioning"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(SimplePermissioning); | ||
deployer.deploy(SimpleNodePermissioning); | ||
deployer.deploy(SimpleAccountPermissioning); | ||
}; |
43 changes: 43 additions & 0 deletions
43
acceptance-tests/simple-permissioning-smart-contract/test/test-account-permissioning.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const TestPermissioning = artifacts.require('SimpleAccountPermissioning.sol'); | ||
var proxy; | ||
|
||
var address1 = "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"; | ||
var address2 = "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73"; | ||
|
||
var value = 99; | ||
var gasPrice = 88; | ||
var gasLimit = 77; | ||
var payload = "0x1234"; | ||
|
||
contract('Permissioning: Accounts', () => { | ||
it('Should NOT permit any transaction when account whitelist is empty', async () => { | ||
proxy = await TestPermissioning.new(); | ||
let permitted = await proxy.transactionAllowed(address1, address2, value, gasPrice, gasLimit, payload); | ||
assert.equal(permitted, false, 'expected tx NOT permitted'); | ||
}); | ||
|
||
it('Should add an account to the whitelist and then permit that node', async () => { | ||
await proxy.addAccount(address1); | ||
let permitted = await proxy.transactionAllowed(address1, address2, value, gasPrice, gasLimit, payload); | ||
assert.equal(permitted, true, 'added address1: expected tx1 to be permitted'); | ||
|
||
// await another | ||
await proxy.addAccount(address2); | ||
permitted = await proxy.transactionAllowed(address2, address1, value, gasPrice, gasLimit, payload); | ||
assert.equal(permitted, true, 'added address2: expected tx2 to be permitted'); | ||
|
||
// first one still permitted | ||
permitted = await proxy.transactionAllowed(address1, address2, value, gasPrice, gasLimit, payload); | ||
assert.equal(permitted, true, 'expected tx from address1 to still be permitted'); | ||
}); | ||
|
||
it('Should remove an account from the whitelist and then NOT permit that account to send tx', async () => { | ||
await proxy.removeAccount(address2); | ||
let permitted = await proxy.transactionAllowed(address2, address1, value, gasPrice, gasLimit, payload); | ||
assert.equal(permitted, false, 'expected removed account (address2) NOT permitted to send tx'); | ||
|
||
// first one still permitted | ||
permitted = await proxy.transactionAllowed(address1, address2, value, gasPrice, gasLimit, payload); | ||
assert.equal(permitted, true, 'expected tx from address1 to still be permitted'); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
acceptance-tests/simple-permissioning-smart-contract/test/test-node-permissioning.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const TestPermissioning = artifacts.require('SimpleNodePermissioning.sol'); | ||
var proxy; | ||
|
||
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: Nodes', () => { | ||
it('Should NOT permit any node when none have been added', async () => { | ||
proxy = await TestPermissioning.new(); | ||
let permitted = await proxy.enodeAllowed(node1High, node1Low, node1Host, node1Port); | ||
assert.equal(permitted, false, 'expected node NOT permitted'); | ||
}); | ||
|
||
it('Should compute key', async () => { | ||
let key1 = await proxy.computeKey(node1High, node1Low, node1Host, node1Port); | ||
let key2 = await proxy.computeKey(node1High, node1Low, node1Host, node1Port); | ||
assert.equal(key1, key2, "computed keys should be the same"); | ||
|
||
let key3 = await proxy.computeKey(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.addEnode(node1High, node1Low, node1Host, node1Port); | ||
let permitted = await proxy.enodeAllowed(node1High, node1Low, node1Host, node1Port); | ||
assert.equal(permitted, true, 'expected node added to be permitted'); | ||
|
||
// await another | ||
await proxy.addEnode(node2High, node2Low, node2Host, node2Port); | ||
permitted = await proxy.enodeAllowed(node2High, node2Low, node2Host, node2Port); | ||
assert.equal(permitted, true, 'expected node 2 added to be permitted'); | ||
|
||
// first one still permitted | ||
permitted = await proxy.enodeAllowed(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.connectionAllowed(node1High, node1Low, node1Host, node1Port, node2High, node2Low, node2Host, node2Port); | ||
assert.equal(permitted, '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', '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.removeEnode(node1High, node1Low, node1Host, node1Port); | ||
let permitted = await proxy.enodeAllowed(node1High, node1Low, node1Host, node1Port); | ||
assert.equal(permitted, false, 'expected removed node NOT permitted'); | ||
|
||
permitted = await proxy.connectionAllowed(node1High, node1Low, node1Host, node1Port, node2High, node2Low, node2Host, node2Port); | ||
assert.equal(permitted, '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'expected source disallowed since it was removed'); | ||
|
||
}); | ||
}); |
63 changes: 0 additions & 63 deletions
63
acceptance-tests/simple-permissioning-smart-contract/test/test-permissioning.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters