mirror of
git://holbrook.no/eth-accounts-index
synced 2024-11-25 10:16:46 +01:00
Add deactivation test
This commit is contained in:
parent
2579abaf3f
commit
a30614efed
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressActive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":true,"internalType":"uint256","name":"_accountIndex","type":"uint256"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressInactive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"activate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"deactivate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"entryIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"isActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"remove","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressActive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":true,"internalType":"uint256","name":"_accountIndex","type":"uint256"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressInactive","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_executor","type":"address"},{"indexed":false,"internalType":"address","name":"_account","type":"address"}],"name":"AddressRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"activate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"deactivate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"entryIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"isActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
||||||
|
@ -41,8 +41,11 @@ class AccountsIndex(TxFactory):
|
|||||||
def add(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
def add(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
return self.__single_address_method('add', contract_address, sender_address, address, tx_format)
|
return self.__single_address_method('add', contract_address, sender_address, address, tx_format)
|
||||||
|
|
||||||
def remove(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
def activate(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
return self.__single_address_method('remove', contract_address, sender_address, address, tx_format)
|
return self.__single_address_method('activate', contract_address, sender_address, address, tx_format)
|
||||||
|
|
||||||
|
def deactivate(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
|
||||||
|
return self.__single_address_method('deactivate', contract_address, sender_address, address, tx_format)
|
||||||
|
|
||||||
def have(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
def have(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
@ -58,7 +61,22 @@ class AccountsIndex(TxFactory):
|
|||||||
o['params'].append(self.normalize(tx))
|
o['params'].append(self.normalize(tx))
|
||||||
return o
|
return o
|
||||||
|
|
||||||
def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
def is_active(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
|
j = JSONRPCRequest(id_generator)
|
||||||
|
o = j.template()
|
||||||
|
o['method'] = 'eth_call'
|
||||||
|
enc = ABIContractEncoder()
|
||||||
|
enc.method('isActive')
|
||||||
|
enc.typ(ABIContractType.ADDRESS)
|
||||||
|
enc.address(address)
|
||||||
|
data = add_0x(enc.get())
|
||||||
|
tx = self.template(sender_address, contract_address)
|
||||||
|
tx = self.set_code(tx, data)
|
||||||
|
o['params'].append(self.normalize(tx))
|
||||||
|
return o
|
||||||
|
|
||||||
|
|
||||||
|
def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
|
||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_call'
|
o['method'] = 'eth_call'
|
||||||
|
@ -128,12 +128,7 @@ class Test(EthTesterCase):
|
|||||||
self.assertEqual(count, 2)
|
self.assertEqual(count, 2)
|
||||||
|
|
||||||
|
|
||||||
#registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[1])
|
def test_5_deactivate(self):
|
||||||
#registry.add(self.w3.eth.accounts[2])
|
|
||||||
|
|
||||||
#self.assertFalse(registry.have(self.w3.eth.accounts[3]))
|
|
||||||
|
|
||||||
def test_5_remove(self):
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
|
||||||
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
|
||||||
@ -157,70 +152,39 @@ class Test(EthTesterCase):
|
|||||||
count = c.parse_entry_count(r)
|
count = c.parse_entry_count(r)
|
||||||
self.assertEqual(count, 2)
|
self.assertEqual(count, 2)
|
||||||
|
|
||||||
(tx_hash, o) = c.remove(self.address, self.accounts[0], a)
|
(tx_hash, o) = c.deactivate(self.address, self.accounts[0], a)
|
||||||
r = self.conn.do(o)
|
r = self.conn.do(o)
|
||||||
|
o = receipt(r)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(r['status'], 1)
|
||||||
|
|
||||||
o = c.entry_count(self.address, sender_address=self.accounts[0])
|
o = c.entry_count(self.address, sender_address=self.accounts[0])
|
||||||
r = self.conn.do(o)
|
r = self.conn.do(o)
|
||||||
count = c.parse_entry_count(r)
|
count = c.parse_entry_count(r)
|
||||||
self.assertEqual(count, 1)
|
self.assertEqual(count, 2)
|
||||||
|
|
||||||
|
o = c.have(self.address, a, sender_address=self.accounts[0])
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(int(r, 16), 1)
|
||||||
|
|
||||||
# TODO: reinstate all tests
|
o = c.is_active(self.address, a, sender_address=self.accounts[0])
|
||||||
# def test_access(self):
|
r = self.conn.do(o)
|
||||||
# registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[1])
|
self.assertEqual(int(r, 16), 0)
|
||||||
# registry.add(self.w3.eth.accounts[2])
|
|
||||||
# self.eth_tester.mine_block()
|
(tx_hash, o) = c.activate(self.address, self.accounts[0], a)
|
||||||
# self.assertEqual(registry.count(), 2)
|
r = self.conn.do(o)
|
||||||
#
|
o = receipt(r)
|
||||||
# # account 2 does not have access
|
r = self.conn.do(o)
|
||||||
# registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[2])
|
self.assertEqual(r['status'], 1)
|
||||||
# registry.add(self.w3.eth.accounts[2])
|
|
||||||
# self.eth_tester.mine_block()
|
o = c.have(self.address, a, sender_address=self.accounts[0])
|
||||||
# self.assertEqual(registry.count(), 2)
|
r = self.conn.do(o)
|
||||||
#
|
self.assertEqual(int(r, 16), 1)
|
||||||
# # after this account 2 has access
|
|
||||||
# registry.contract.functions.addWriter(self.w3.eth.accounts[2]).transact()
|
o = c.is_active(self.address, a, sender_address=self.accounts[0])
|
||||||
# registry.add(self.w3.eth.accounts[3])
|
r = self.conn.do(o)
|
||||||
# self.eth_tester.mine_block()
|
self.assertEqual(int(r, 16), 1)
|
||||||
# self.assertEqual(registry.count(), 3)
|
|
||||||
#
|
|
||||||
# # after this account 2 no longer has access
|
|
||||||
# registry.contract.functions.deleteWriter(self.w3.eth.accounts[2]).transact()
|
|
||||||
# registry.add(self.w3.eth.accounts[3])
|
|
||||||
# self.eth_tester.mine_block()
|
|
||||||
# self.assertEqual(registry.count(), 3)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
# def test_no_duplicates(self):
|
|
||||||
# registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[1])
|
|
||||||
# tx_hash = registry.add(self.w3.eth.accounts[2])
|
|
||||||
# self.eth_tester.mine_block()
|
|
||||||
# tx_hash = registry.add(self.w3.eth.accounts[3])
|
|
||||||
# self.eth_tester.mine_block()
|
|
||||||
# # BUG: eth_tester does not detect the duplicate here, but does in the test.py file in the solidity folder
|
|
||||||
# #self.assertRaises(Exception):
|
|
||||||
# tx_hash = registry.add(self.w3.eth.accounts[2])
|
|
||||||
# self.eth_tester.mine_block()
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# def test_list(self):
|
|
||||||
# registry = AccountRegistry(self.w3, self.address, self.w3.eth.accounts[1])
|
|
||||||
#
|
|
||||||
# for i in range(2, 10):
|
|
||||||
# registry.add(self.w3.eth.accounts[i])
|
|
||||||
#
|
|
||||||
# self.assertEqual(registry.count(), 9)
|
|
||||||
#
|
|
||||||
# accounts_reverse = []
|
|
||||||
# for i in range(9, 1, -1):
|
|
||||||
# accounts_reverse.append(self.w3.eth.accounts[i])
|
|
||||||
#
|
|
||||||
# accounts_list = registry.last(8)
|
|
||||||
# for i in range(8):
|
|
||||||
# self.assertEqual(accounts_list[i], accounts_reverse[i])
|
|
||||||
#
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -6,8 +6,7 @@ pragma solidity >0.6.12;
|
|||||||
contract CustodialAccountIndex {
|
contract CustodialAccountIndex {
|
||||||
|
|
||||||
uint256 constant blockedField = 1 << 64;
|
uint256 constant blockedField = 1 << 64;
|
||||||
uint64 public entryCount;
|
address[] public entry;
|
||||||
address[] entryList;
|
|
||||||
mapping(address => uint256) public entryIndex;
|
mapping(address => uint256) public entryIndex;
|
||||||
mapping(address => bool) writers;
|
mapping(address => bool) writers;
|
||||||
address public owner;
|
address public owner;
|
||||||
@ -21,7 +20,10 @@ contract CustodialAccountIndex {
|
|||||||
|
|
||||||
constructor() public {
|
constructor() public {
|
||||||
owner = msg.sender;
|
owner = msg.sender;
|
||||||
entryList.push(address(0));
|
}
|
||||||
|
|
||||||
|
function entryCount() external returns (uint256) {
|
||||||
|
return entry.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addWriter(address _writer) public returns (bool) {
|
function addWriter(address _writer) public returns (bool) {
|
||||||
@ -42,11 +44,10 @@ contract CustodialAccountIndex {
|
|||||||
|
|
||||||
require(writers[msg.sender]);
|
require(writers[msg.sender]);
|
||||||
require(entryIndex[_account] == 0);
|
require(entryIndex[_account] == 0);
|
||||||
require(entryList.length < (1 << 128));
|
require(entry.length < (1 << 128));
|
||||||
i = entryList.length;
|
i = entry.length;
|
||||||
entryList.push(_account);
|
entry.push(_account);
|
||||||
entryIndex[_account] = i;
|
entryIndex[_account] = i;
|
||||||
entryCount += 1;
|
|
||||||
emit AddressAdded(msg.sender, i, _account);
|
emit AddressAdded(msg.sender, i, _account);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -70,17 +71,6 @@ contract CustodialAccountIndex {
|
|||||||
emit AddressActive(msg.sender, _account);
|
emit AddressActive(msg.sender, _account);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements AccountsIndex
|
|
||||||
// (An account can remove itself).
|
|
||||||
function remove(address _account) external returns (bool) {
|
|
||||||
require(writers[msg.sender] || msg.sender == _account);
|
|
||||||
require(entryIndex[_account] > 0);
|
|
||||||
entryIndex[_account] = 0;
|
|
||||||
entryCount = entryCount - 1;
|
|
||||||
emit AddressRemoved(msg.sender, _account);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements AccountsIndex
|
// Implements AccountsIndex
|
||||||
function have(address _account) external view returns (bool) {
|
function have(address _account) external view returns (bool) {
|
||||||
return entryIndex[_account] > 0;
|
return entryIndex[_account] > 0;
|
||||||
@ -88,7 +78,7 @@ contract CustodialAccountIndex {
|
|||||||
|
|
||||||
// Implements AccountsIndex
|
// Implements AccountsIndex
|
||||||
function isActive(address _account) external view returns (bool) {
|
function isActive(address _account) external view returns (bool) {
|
||||||
return this.have(_account) && entryIndex[_account] != blockedField;
|
return this.have(_account) && entryIndex[_account] & blockedField != blockedField;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements EIP173
|
// Implements EIP173
|
||||||
@ -102,17 +92,6 @@ contract CustodialAccountIndex {
|
|||||||
emit OwnershipTransferred(oldOwner, owner);
|
emit OwnershipTransferred(oldOwner, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements AccountsIndex
|
|
||||||
function entry(uint256 _idx) public returns(address) {
|
|
||||||
address r;
|
|
||||||
|
|
||||||
r = entryList[_idx + 1];
|
|
||||||
if (entryIndex[r] > 0) {
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
return address(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements EIP165
|
// Implements EIP165
|
||||||
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
||||||
if (_sum == 0xcbdb05c7) { // AccountsIndex
|
if (_sum == 0xcbdb05c7) { // AccountsIndex
|
||||||
|
Loading…
Reference in New Issue
Block a user