-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
14 oct update part-1. SubDomainRegistrar, PublicResolver, keyValueTre…
…e, Multibox added & all tests added for them
- Loading branch information
1 parent
ba847f6
commit 958836d
Showing
9 changed files
with
360 additions
and
7 deletions.
There are no files selected for viewing
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,77 @@ | ||
""" | ||
Copyright 2023 The FairDataSociety Authors | ||
This file is part of the FairDataSociety library. | ||
The FairDataSociety library is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
The FairDataSociety library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with the FairDataSociety library. If not, see <http:www.gnu.org/licenses/>. | ||
handles KeyValueTree contract | ||
""" | ||
|
||
from typing import List, Tuple, Union | ||
|
||
from ape import networks, project | ||
from ape.api.accounts import AccountAPI | ||
from ape.api.transactions import ReceiptAPI | ||
from ape.types import AddressType | ||
|
||
from fds.utils.convert import int_to_bytes32 | ||
from fds.utils.Exceptions import AccountNotSetUp | ||
|
||
|
||
class KeyValueTree: | ||
def __init__(self, account: AccountAPI, contract_address: Union[AddressType, None] = None): | ||
self.account = account | ||
self.contract_address = contract_address | ||
self.contract = None | ||
self.web3 = networks.provider._web3 | ||
|
||
if not self.account: | ||
raise AccountNotSetUp("Set up user account first") | ||
|
||
if contract_address: | ||
self.contract = project.KeyValueTree.at(self.contract_address) | ||
|
||
def getSharedId(self) -> ReceiptAPI: | ||
return self.contract.getSharedId() # type: ignore | ||
|
||
def getRootId(self) -> ReceiptAPI: | ||
return self.contract.getRootId() # type: ignore | ||
|
||
def setKeyValue(self, nodeId: int, key: int, value: int) -> bool: | ||
self.nodeId = int_to_bytes32(nodeId) | ||
self.key = key.to_bytes(32, byteorder="big") | ||
self.value = value.to_bytes(32, byteorder="big") | ||
|
||
return self.contract.setKeyValue(self.nodeId, self.key, self.value, sender=self.account) # type: ignore # noqa: 501 | ||
|
||
def getKeyValue(self, nodeId: int, key: int) -> ReceiptAPI: | ||
self.nodeId = int_to_bytes32(nodeId) | ||
self.key = key.to_bytes(32, byteorder="big") | ||
|
||
return self.contract.getValue(self.nodeId, self.key) # type: ignore | ||
|
||
def getKeyValues(self, nodeId: int) -> Tuple: | ||
self.nodeId = int_to_bytes32(nodeId) | ||
return self.contract.getKeyValues(self.nodeId) # type: ignore | ||
|
||
def addChildNode(self, parent_node_id: str, sub_node_id: str) -> ReceiptAPI: | ||
self.parent_node_id = parent_node_id | ||
self.sub_node_id = sub_node_id | ||
|
||
return self.contract.addChildNode(self.parent_node_id, self.sub_node_id, sender=self.account) # type: ignore # noqa: 501 | ||
|
||
def getChildren(self, parent_node_id: str) -> List: | ||
self.parent_node_id = parent_node_id | ||
|
||
return self.contract.getChildren(self.parent_node_id) # type: ignore |
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
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
Empty file.
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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from ape import convert | ||
|
||
from fds.contracts.KeyValueTree import KeyValueTree | ||
|
||
|
||
def test_load_key_value_tree(owner, key_value_tree): | ||
kvt = KeyValueTree(owner, key_value_tree.address) | ||
|
||
assert kvt | ||
|
||
|
||
def test_get_shared_id(kvt): | ||
assert ( | ||
kvt.getSharedId().hex() | ||
== "0x23e642b7242469a5e3184a6566020c815689149967703a98c0affc14b9ca9b28" | ||
) | ||
|
||
|
||
def test_get_root_id(kvt): | ||
assert ( | ||
kvt.getRootId().hex() | ||
== "0xc7f5bbf5fe95923f0691c94f666ac3dfed12456cd33bd018e7620c3d93edd5a6" | ||
) | ||
|
||
|
||
def test_set_n_get_key_value(kvt): | ||
node = 1 | ||
key = 1 | ||
value = 420 | ||
|
||
kvt.setKeyValue(node, key, value) | ||
|
||
assert convert(kvt.getKeyValue(node, key).hex(), int) == value | ||
|
||
|
||
def test_add_child_node(kvt): | ||
parent_node_id = "0xc7f5bbf5fe95923f0691c94f666ac3dfed12456cd33bd018e7620c3d93edd5a6" | ||
sub_node_id = "0x23e642b7242469a5e3184a6566020c815689149967703a98c0affc14b9ca9b28" | ||
kvt.addChildNode(parent_node_id, sub_node_id) | ||
|
||
assert kvt.getChildren(parent_node_id)[-1].hex() == sub_node_id |
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,13 @@ | ||
from fds.contracts.Multibox import MultiBox | ||
|
||
|
||
def test_multibox_deploy(owner): | ||
mb = MultiBox(owner) | ||
|
||
assert mb | ||
|
||
|
||
def test_get_root(owner, multibox): | ||
mb = MultiBox(owner, multibox.address) | ||
|
||
assert mb.getRoots()[-1] != "0x000000000000000000000000000000000000000" |
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,2 @@ | ||
def int_to_bytes32(input: int) -> str: | ||
return f"0x{input.to_bytes(32, byteorder='big').hex()}" |