diff --git a/src/fds/contracts/KeyValueTree.py b/src/fds/contracts/KeyValueTree.py new file mode 100644 index 0000000..21eb1e5 --- /dev/null +++ b/src/fds/contracts/KeyValueTree.py @@ -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 . + +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 diff --git a/src/fds/contracts/Multibox.py b/src/fds/contracts/Multibox.py index 0fe2b20..f685ba3 100644 --- a/src/fds/contracts/Multibox.py +++ b/src/fds/contracts/Multibox.py @@ -18,11 +18,35 @@ handles Multibox contract """ -from typing import Tuple, Union +from typing import Union -from ape import convert, networks, project +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.Exceptions import AccountNotSetUp + + +class MultiBox: + 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.Multibox.at(self.contract_address) + else: + return self.deploy() + + def deploy(self): + self.contract = project.Multibox.deploy(sender=self.account) + # * call the createRoot method and initialise the contract + self.contract.init(sender=self.account) + + def getRoots(self) -> ReceiptAPI: + return self.contract.getRoots() # type: ignore diff --git a/src/fds/contracts/PublicResolver.py b/src/fds/contracts/PublicResolver.py index c06f54f..77d31f9 100644 --- a/src/fds/contracts/PublicResolver.py +++ b/src/fds/contracts/PublicResolver.py @@ -64,6 +64,9 @@ def setAll( If this is desired behavior, use f"{x!r}" or "{!r}".format(x). Otherwise, decode the bytes """ + if not self.account: + raise AccountNotSetUp("Set up user account first") + self.node = f"0x{node.to_bytes(32, byteorder='big').hex()}" self.address = address self.content = content.encode("utf-8") @@ -127,7 +130,7 @@ def setMultiHash(self, node: int, _hash: str) -> ReceiptAPI: raise AccountNotSetUp("Set up user account first") self.node = f"0x{node.to_bytes(32, byteorder='big').hex()}" - self.hash = _hash.encode("utf-8") + self.hash = f"0x{_hash.encode().hex()}" return self.contract.setMultihash(self.node, self.hash, sender=self.account) # type: ignore @@ -139,4 +142,4 @@ def getMultiHash(self, node: int) -> str: """ self.node = f"0x{node.to_bytes(32, byteorder='big').hex()}" - return convert(self.contract.multihash(self.node), str) # type: ignore + return bytes.fromhex(convert(self.contract.multihash(self.node).hex(), str)[2:]).decode("utf-8") # type: ignore # noqa: 501 diff --git a/src/fds/contracts/key_value_tree.py b/src/fds/contracts/key_value_tree.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/fds/tests/conftest.py b/src/fds/tests/conftest.py index 0a5ccd1..a3e2f82 100644 --- a/src/fds/tests/conftest.py +++ b/src/fds/tests/conftest.py @@ -7,6 +7,7 @@ from ethpm_types import ContractType from fds.contracts.ENSRegistry import EnsRegistry +from fds.contracts.KeyValueTree import KeyValueTree from fds.fds_contract import FDSContract from fds.fds_crypto import Crypto from fds.fds_wallet import Wallet @@ -247,11 +248,27 @@ def ENS(owner, ensContract): def subDomainRegistrarContract(owner, ensContract): node = 1 node = node.to_bytes(32, byteorder="big") - contract = project.SubdomainRegistrar.deploy(ensContract.address, node, sender=owner) - - return contract + return project.SubdomainRegistrar.deploy(ensContract.address, node, sender=owner) @pytest.fixture def publicResolverContract(owner, ensContract): return project.PublicResolver.deploy(ensContract.address, sender=owner) + + +@pytest.fixture +def multibox(owner): + mb = project.Multibox.deploy(sender=owner) + mb.init(sender=owner) + + return mb + + +@pytest.fixture +def key_value_tree(owner): + return project.KeyValueTree.deploy(owner.address, sender=owner) + + +@pytest.fixture +def kvt(owner, key_value_tree): + return KeyValueTree(owner, key_value_tree.address) diff --git a/src/fds/tests/data/contracts/abi/Multibox.json b/src/fds/tests/data/contracts/abi/Multibox.json new file mode 100644 index 0000000..70597a4 --- /dev/null +++ b/src/fds/tests/data/contracts/abi/Multibox.json @@ -0,0 +1,176 @@ +{ + "contractName": "Multibox", + "abi": [ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "contract KeyValueTree", + "name": "kvt", + "type": "address" + } + ], + "name": "addRoot", + "outputs": [ + { + "internalType": "contract KeyValueTree", + "name": "", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "_newOwner", + "type": "address" + } + ], + "name": "changeOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "whoHasReadWriteRights", + "type": "address" + } + ], + "name": "createRoot", + "outputs": [ + { + "internalType": "contract KeyValueTree", + "name": "", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "getRootAt", + "outputs": [ + { + "internalType": "contract KeyValueTree", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getRoots", + "outputs": [ + { + "internalType": "contract KeyValueTree[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getRootsCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "init", + "outputs": [ + { + "internalType": "contract KeyValueTree", + "name": "", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address payable", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "removeRoot", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "revokeRoot", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } + ], + "bytecode": "0x608060405234801561001057600080fd5b5060008054600160a060020a03191633179055613aba806100326000396000f3fe608060405260043610620000d15763ffffffff60e060020a60003504166322fb78a98114620000d35780633466fda5146200012657806335a5e06d146200016657806338af30b014620001d05780638da5cb5b14620001fe5780639423fc6e14620002165780639c60b07e146200022e578063a57ae0dc1462000265578063a6f9dae114620002a2578063b435860214620002d9578063c4a85bc114620002f1578063c7fb2dc71462000328578063da8bb7c71462000356578063e1c7392a146200038d578063feac51f514620003a5575b005b348015620000e057600080fd5b506200010a60048036036020811015620000f957600080fd5b5035600160a060020a0316620003bd565b60408051600160a060020a039092168252519081900360200190f35b3480156200013357600080fd5b5062000154600480360360208110156200014c57600080fd5b503562000626565b60408051918252519081900360200190f35b3480156200017357600080fd5b506200017e620007a2565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015620001bc578181015183820152602001620001a2565b505050509050019250505060405180910390f35b348015620001dd57600080fd5b506200015460048036036020811015620001f657600080fd5b503562000807565b3480156200020b57600080fd5b506200010a620008df565b3480156200022357600080fd5b5062000154620008ee565b3480156200023b57600080fd5b5062000154600480360360208110156200025457600080fd5b5035600160a060020a0316620008f4565b3480156200027257600080fd5b506200010a600480360360408110156200028b57600080fd5b50600160a060020a03813516906020013562000901565b348015620002af57600080fd5b50620000d160048036036020811015620002c857600080fd5b5035600160a060020a031662000b95565b348015620002e657600080fd5b506200017e62000bcf565b348015620002fe57600080fd5b50620000d1600480360360208110156200031757600080fd5b5035600160a060020a031662000c31565b3480156200033557600080fd5b506200010a600480360360208110156200034e57600080fd5b503562000e53565b3480156200036357600080fd5b506200010a600480360360208110156200037c57600080fd5b5035600160a060020a031662000e80565b3480156200039a57600080fd5b506200010a62000f5d565b348015620003b257600080fd5b50620000d162000fcc565b600080548190600160a060020a0316620003d662001023565b600160a060020a03909116815260405190819003602001906000f08015801562000404573d6000803e3d6000fd5b506001549091501515620005155780600160a060020a03166390d1040e82600160a060020a031663bfbd3c1f6040518163ffffffff1660e060020a02815260040160206040518083038186803b1580156200045e57600080fd5b505afa15801562000473573d6000803e3d6000fd5b505050506040513d60208110156200048a57600080fd5b50516040805160e060020a63ffffffff85160281526004810192909252600160a060020a0387166024830152600360448301525160648083019260209291908290030181600087803b158015620004e057600080fd5b505af1158015620004f5573d6000803e3d6000fd5b505050506040513d60208110156200050c57600080fd5b50620006129050565b80600160a060020a03166390d1040e82600160a060020a031663bfbd3c1f6040518163ffffffff1660e060020a02815260040160206040518083038186803b1580156200056157600080fd5b505afa15801562000576573d6000803e3d6000fd5b505050506040513d60208110156200058d57600080fd5b50516040805160e060020a63ffffffff85160281526004810192909252600160a060020a0387166024830152600260448301525160648083019260209291908290030181600087803b158015620005e357600080fd5b505af1158015620005f8573d6000803e3d6000fd5b505050506040513d60208110156200060f57600080fd5b50505b6200061d8162000e80565b9150505b919050565b6000806001838154811015156200063957fe5b600091825260209091200154600160a060020a031690508215156200066357600091505062000621565b33600160a060020a031681600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b158015620006aa57600080fd5b505afa158015620006bf573d6000803e3d6000fd5b505050506040513d6020811015620006d657600080fd5b5051600160a060020a03161415620006f357600091505062000621565b6001805460001981019081106200070657fe5b60009182526020909120015460018054600160a060020a0390921691859081106200072d57fe5b60009182526020909120018054600160a060020a031916600160a060020a03929092169190911790556001805460001981019081106200076957fe5b60009182526020909120018054600160a060020a031916905560018054906200079790600019830162001034565b505060015492915050565b60606001805480602002602001604051908101604052809291908181526020018280548015620007fc57602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311620007dd575b505050505090505b90565b60008054600160a060020a031633146200082057600080fd5b811515620008315750600062000621565b6001805460001981019081106200084457fe5b60009182526020909120015460018054600160a060020a0390921691849081106200086b57fe5b60009182526020909120018054600160a060020a031916600160a060020a0392909216919091179055600180546000198101908110620008a757fe5b60009182526020909120018054600160a060020a03191690556001805490620008d590600019830162001034565b5050600154919050565b600054600160a060020a031681565b60015490565b600160a060020a03163190565b60008054604080517f8f1ac17500000000000000000000000000000000000000000000000000000000815260048101859052600160a060020a03928316602482015290518392839290871691638f1ac17591604480820192602092909190829003018186803b1580156200097457600080fd5b505afa15801562000989573d6000803e3d6000fd5b505050506040513d6020811015620009a057600080fd5b5051604080517f8da5cb5b00000000000000000000000000000000000000000000000000000000815290519192503091638da5cb5b91600480820192602092909190829003018186803b158015620009f757600080fd5b505afa15801562000a0c573d6000803e3d6000fd5b505050506040513d602081101562000a2357600080fd5b5051604080517f8da5cb5b0000000000000000000000000000000000000000000000000000000081529051600160a060020a0392831692881691638da5cb5b916004808301926020929190829003018186803b15801562000a8357600080fd5b505afa15801562000a98573d6000803e3d6000fd5b505050506040513d602081101562000aaf57600080fd5b5051600160a060020a03161462000ac95750905062000b8f565b801562000b8b573330868662000ade62001060565b600160a060020a039485168152928416602084015292166040808301919091526060820192909252905190819003608001906000f08015801562000b26573d6000803e3d6000fd5b506002805460018101918290557f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace018054600160a060020a031916600160a060020a038416908117909155600090815260036020526040902055925062000b8f915050565b5090505b92915050565b600054600160a060020a0316331462000bad57600080fd5b60008054600160a060020a031916600160a060020a0392909216919091179055565b60606002805480602002602001604051908101604052809291908181526020018280548015620007fc57602002820191906000526020600020908154600160a060020a03168152600190910190602001808311620007dd575050505050905090565b600054600160a060020a0316331462000c4957600080fd5b600160a060020a038116600090815260036020526040902054801562000df75781600160a060020a03166312424e3f6040518163ffffffff1660e060020a028152600401602060405180830381600087803b15801562000ca857600080fd5b505af115801562000cbd573d6000803e3d6000fd5b505050506040513d602081101562000cd457600080fd5b50511562000df757600160a060020a03821660009081526003602052604081205560028054600019810190811062000d0857fe5b60009182526020909120015460028054600160a060020a0390921691600019840190811062000d3357fe5b60009182526020909120018054600160a060020a031916600160a060020a039290921691909117905560028054600019810190811062000d6f57fe5b60009182526020909120018054600160a060020a0319169055600280549062000d9d90600019830162001034565b5081600160a060020a0316634bb278f36040518163ffffffff1660e060020a028152600401600060405180830381600087803b15801562000ddd57600080fd5b505af115801562000df2573d6000803e3d6000fd5b505050505b81600160a060020a031663e60955946040518163ffffffff1660e060020a028152600401600060405180830381600087803b15801562000e3657600080fd5b505af115801562000e4b573d6000803e3d6000fd5b505050505050565b600060018281548110151562000e6557fe5b600091825260209091200154600160a060020a031692915050565b600033600160a060020a031682600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b15801562000ec957600080fd5b505afa15801562000ede573d6000803e3d6000fd5b505050506040513d602081101562000ef557600080fd5b5051600160a060020a03161462000f0f5750600062000621565b506001805480820182556000919091527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6018054600160a060020a031916600160a060020a03831617905590565b6001546000908190151562000fc75760005462000f8390600160a060020a0316620003bd565b60005460408051600160a060020a039092168252519192507fb8a00d6d8ca1be30bfec34d8f97e55f0f0fd9eeb7fb46e030516363d4cfe1ad6919081900360200190a15b905090565b600054600160a060020a0316331462000fe457600080fd5b60008054604051600160a060020a0390911691303180156108fc02929091818181858888f1935050505015801562001020573d6000803e3d6000fd5b50565b60405161215f806200109383390190565b8154818355818111156200105b576000838152602090206200105b91810190830162001071565b505050565b60405161089d80620031f283390190565b6200080491905b808211156200108e576000815560010162001078565b509056fe60806040523480156200001157600080fd5b506040516020806200215f833981018060405260208110156200003357600080fd5b505160008054600160a060020a031916600160a060020a03831617815562000085907fc7f5bbf5fe95923f0691c94f666ac3dfed12456cd33bd018e7620c3d93edd5a6640100000000620000c9810204565b6003819055620000bf907f23e642b7242469a5e3184a6566020c815689149967703a98c0affc14b9ca9b28640100000000620001e9810204565b600455506200063b565b6000620000df836401000000006200032e810204565b158015620000ed5750600083115b15620000f857600080fd5b6200010c826401000000006200032e810204565b156200011757600080fd5b50806200012362000597565b6040810184905260018152600084111562000153576200014d848364010000000062000343810204565b60208201525b6000828152600760209081526040918290208351815460ff191690151517815583820151600182015591830151600283015560608301518051849392620001a2926005850192910190620005cb565b5060808201518051620001c0916006840191602090910190620005cb565b5060a08201518051620001de916007840191602090910190620005cb565b505050505b92915050565b60008262000200816401000000006200032e810204565b15156200020c57506003545b62000221813364010000000062000369810204565b15156200022d57506004545b62000241836401000000006200032e810204565b1562000278576200025c833364010000000062000369810204565b15156200026e575060009050620001e3565b82915050620001e3565b6200028d813364010000000062000454810204565b15156200029f575060009050620001e3565b6000620002b68285640100000000620000c9810204565b6005805460018101918290557f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db00186905560008681526006602052604081209190915554909150600160a060020a03163314620003265762000324813360026401000000006200051e810204565b505b949350505050565b60009081526007602052604090205460ff1690565b600091825260076020818152604084209091018054600181018255908452922082015590565b60006200037f836401000000006200032e810204565b15156200038f57506000620001e3565b600160a060020a038216331415620003aa57506001620001e3565b6000838152600760209081526040808320600160a060020a038616845260038101909252909120546000191415620003e7576000915050620001e3565b6000808052600380830160205260409091205414156200040c576000915050620001e3565b600080805260038201602052604081205413156200042f576001915050620001e3565b600160a060020a03831660009081526003909101602052604081205413905092915050565b60006200046a836401000000006200032e810204565b15156200047a57506000620001e3565b600160a060020a0382163314156200049557506001620001e3565b6000838152600760209081526040808320600160a060020a038616845260038101909252909120546000191415620004d2576000915050620001e3565b600080805260038201602052604090205460011215620004f7576001915050620001e3565b600160a060020a038316600090815260039091016020526040902054600112905092915050565b60008054600160a060020a03848116911614156200053f5750600262000590565b62000554843364010000000062000454810204565b151562000565575060001962000590565b506000838152600760209081526040808320600160a060020a03861684526003019091529020819055805b9392505050565b6040805160c0810182526000808252602082018190529181019190915260608082018190526080820181905260a082015290565b82805482825590600052602060002090810192821562000609579160200282015b8281111562000609578251825591602001919060010190620005ec565b50620006179291506200061b565b5090565b6200063891905b8082111562000617576000815560010162000622565b90565b611b14806200064b6000396000f3fe6080604052600436106101f75763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416628614ff81146101f95780631a0925411461023b5780631a8283e41461025057806322c1064a146102d05780632947ef381461031a57806339bf397e1461032f5780634d9b3735146103445780635ba5342a1461035957806362ecbd351461036e57806362fbdb76146103a7578063640a7f88146103bc5780637284e416146103e657806372965b30146103fb578063790c38b01461042b5780637b01127c1461045b578063821f32ce1461048b57806389f5df5d146104b55780638da5cb5b146104df5780638f1ac1751461051057806390d1040e1461054957806398aca92214610588578063a09e3d0a1461059d578063a24fa791146105c7578063a60efc65146105f1578063a6f9dae11461061b578063ae4c61611461064e578063b1cfda8814610678578063b7471dd0146106ae578063ba75d806146106de578063bfbd3c1f14610708578063cd98de851461071d578063ceef5f0214610756578063cf25611e1461079f578063d37684ff146107cf578063d4c602f1146107f9578063e073546b14610829578063e29581aa14610853578063f12a796b14610868578063f7260d3e14610892578063f7fed313146108a7578063fa8016441461096a575b005b34801561020557600080fd5b506102296004803603604081101561021c57600080fd5b50803590602001356109a6565b60408051918252519081900360200190f35b34801561024757600080fd5b506102296109d7565b34801561025c57600080fd5b506102806004803603604081101561027357600080fd5b50803590602001356109de565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156102bc5781810151838201526020016102a4565b505050509050019250505060405180910390f35b3480156102dc57600080fd5b50610306600480360360608110156102f357600080fd5b5080359060208101359060400135610a61565b604080519115158252519081900360200190f35b34801561032657600080fd5b50610229610b3d565b34801561033b57600080fd5b50610229610b43565b34801561035057600080fd5b506101f7610b62565b34801561036557600080fd5b50610229610bb7565b34801561037a57600080fd5b506103066004803603604081101561039157600080fd5b5080359060200135600160a060020a0316610bbd565b3480156103b357600080fd5b50610229610c72565b3480156103c857600080fd5b50610229600480360360208110156103df57600080fd5b5035610c78565b3480156103f257600080fd5b50610229610cab565b34801561040757600080fd5b506102296004803603604081101561041e57600080fd5b5080359060200135610cb1565b34801561043757600080fd5b506102296004803603604081101561044e57600080fd5b5080359060200135610ce8565b34801561046757600080fd5b506102296004803603604081101561047e57600080fd5b5080359060200135610dd7565b34801561049757600080fd5b50610229600480360360208110156104ae57600080fd5b5035610e13565b3480156104c157600080fd5b506101f7600480360360208110156104d857600080fd5b5035610e25565b3480156104eb57600080fd5b506104f4610e41565b60408051600160a060020a039092168252519081900360200190f35b34801561051c57600080fd5b506103066004803603604081101561053357600080fd5b5080359060200135600160a060020a0316610e50565b34801561055557600080fd5b506102296004803603606081101561056c57600080fd5b50803590600160a060020a036020820135169060400135610f07565b34801561059457600080fd5b50610229610f6e565b3480156105a957600080fd5b50610229600480360360208110156105c057600080fd5b5035610f74565b3480156105d357600080fd5b50610306600480360360208110156105ea57600080fd5b5035610f8a565b3480156105fd57600080fd5b506102296004803603602081101561061457600080fd5b5035610f9f565b34801561062757600080fd5b506101f76004803603602081101561063e57600080fd5b5035600160a060020a0316610fcf565b34801561065a57600080fd5b506102806004803603602081101561067157600080fd5b5035611015565b34801561068457600080fd5b506103066004803603606081101561069b57600080fd5b5080359060208101359060400135611093565b3480156106ba57600080fd5b50610229600480360360408110156106d157600080fd5b50803590602001356110d8565b3480156106ea57600080fd5b506102296004803603602081101561070157600080fd5b503561110f565b34801561071457600080fd5b50610229611147565b34801561072957600080fd5b506103066004803603604081101561074057600080fd5b5080359060200135600160a060020a031661114d565b34801561076257600080fd5b506107866004803603604081101561077957600080fd5b5080359060200135611223565b6040805192835260208301919091528051918290030190f35b3480156107ab57600080fd5b50610306600480360360408110156107c257600080fd5b50803590602001356112a3565b3480156107db57600080fd5b50610280600480360360208110156107f257600080fd5b50356113f6565b34801561080557600080fd5b506103066004803603604081101561081c57600080fd5b508035906020013561145b565b34801561083557600080fd5b506101f76004803603602081101561084c57600080fd5b50356115a6565b34801561085f57600080fd5b506102806115c2565b34801561087457600080fd5b506103066004803603602081101561088b57600080fd5b5035611632565b34801561089e57600080fd5b50610229611728565b3480156108b357600080fd5b506108d1600480360360208110156108ca57600080fd5b503561172e565b604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b838110156109155781810151838201526020016108fd565b50505050905001838103825284818151815260200191508051906020019060200280838360005b8381101561095457818101518382015260200161093c565b5050505090500194505050505060405180910390f35b34801561097657600080fd5b506103066004803603608081101561098d57600080fd5b5080359060208101359060408101359060600135611819565b60008281526007602081905260408220018054839081106109c357fe5b906000526020600020015490505b92915050565b6002545b90565b600054606090600160a060020a031633146109f857600080fd5b600082815260086020908152604080832086845282529182902080548351818402810184019094528084529091830182828015610a5457602002820191906000526020600020905b815481526020019060010190808311610a40575b5050505050905092915050565b6000610a6d8433610e50565b1515610a7b57506000610b36565b600084815260076020908152604080832086845260048101909252909120541515610b095760058101805460018181018355600092835260208084209092018790556006840180548083018255908452828420018690558683526004909301815260408083208690556008825280832088845282528220805480850182559083529120018390559050610b36565b50506000828152600860209081526040808320868452825282208054600181018255908352908220018290555b9392505050565b60035490565b60008054600160a060020a03163314610b5b57600080fd5b5060055490565b600054600160a060020a03163314610b7957600080fd5b60008054604051600160a060020a0390911691303180156108fc02929091818181858888f19350505050158015610bb4573d6000803e3d6000fd5b50565b60035481565b6000610bc883610f8a565b1515610bd6575060006109d1565b600160a060020a038216331415610bef575060016109d1565b6000838152600760209081526040808320600160a060020a038616845260038101909252909120546000191415610c2a5760009150506109d1565b600080805260038281016020526040909120541315610c4d5760019150506109d1565b600160a060020a03831660009081526003918201602052604090205413905092915050565b60045481565b6000610c84823361114d565b1515610c9257506000610ca6565b506000818152600760205260409020600601545b919050565b60025481565b6000610cbd833361114d565b1515610ccb575060006109d1565b60008381526007602052604090206006018054839081106109c357fe5b600082610cf481610f8a565b1515610cff57506003545b610d09813361114d565b1515610d1457506004545b610d1d83610f8a565b15610d4557610d2c833361114d565b1515610d3c5750600090506109d1565b829150506109d1565b610d4f8133610e50565b1515610d5f5750600090506109d1565b6000610d6b828561190e565b6005805460018101918290557f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db00186905560008681526006602052604081209190915554909150600160a060020a03163314610dcf57610dcd81336002610f07565b505b949350505050565b6000610de3833361114d565b1515610df1575060006109d1565b5060009182526007602090815260408084209284526004909201905290205490565b60009081526006602052604090205490565b600054600160a060020a03163314610e3c57600080fd5b600255565b600054600160a060020a031681565b6000610e5b83610f8a565b1515610e69575060006109d1565b600160a060020a038216331415610e82575060016109d1565b6000838152600760209081526040808320600160a060020a038616845260038101909252909120546000191415610ebd5760009150506109d1565b600080805260038201602052604090205460011215610ee05760019150506109d1565b600160a060020a038316600090815260039091016020526040902054600112905092915050565b60008054600160a060020a0384811691161415610f2657506002610b36565b610f308433610e50565b1515610f3f5750600019610b36565b506000928352600760209081526040808520600160a060020a0394909416855260039093019052912081905590565b60015490565b6000908152600760208190526040909120015490565b60009081526007602052604090205460ff1690565b6000610fab823361114d565b1515610fb957506000610ca6565b5060009081526007602052604090206005015490565b600054600160a060020a03163314610fe657600080fd5b6000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b606080611022833361114d565b151561102f579050610ca6565b6000838152600760209081526040918290206005018054835181840281018401909452808452909183018282801561108657602002820191906000526020600020905b815481526020019060010190808311611072575b5050505050915050919050565b600061109e84610f8a565b15156110cd57600454600054600160a060020a03163314156110bf57506003545b6110c98186610ce8565b9450505b610dcf848484610a61565b60006110e4833361114d565b15156110f2575060006109d1565b60008381526007602052604090206005018054839081106109c357fe5b60008054600160a060020a0316331461112757600080fd5b600580548390811061113557fe5b90600052602060002001549050919050565b60045490565b600061115883610f8a565b1515611166575060006109d1565b600160a060020a03821633141561117f575060016109d1565b6000838152600760209081526040808320600160a060020a0386168452600381019092529091205460001914156111ba5760009150506109d1565b6000808052600380830160205260409091205414156111dd5760009150506109d1565b600080805260038201602052604081205413156111fe5760019150506109d1565b600160a060020a03831660009081526003909101602052604081205413905092915050565b600080611230843361114d565b15156112415750600090508061129c565b600084815260076020526040902060050180548490811061125e57fe5b9060005260206000200154600760008681526020019081526020016000206006018481548110151561128c57fe5b9060005260206000200154915091505b9250929050565b60006112af8333610e50565b15156112bd575060006109d1565b6000838152600760205260408120600581018054919291859081106112de57fe5b60009182526020909120015490508015156112f857600080fd5b6000818152600483016020526040812055600582018054600019810190811061131d57fe5b9060005260206000200154826005018581548110151561133957fe5b600091825260209091200155600582018054600019810190811061135957fe5b600091825260208220015560058201805490611379906000198301611a26565b50600682018054600019810190811061138e57fe5b906000526020600020015482600601858154811015156113aa57fe5b60009182526020909120015560068201805460001981019081106113ca57fe5b6000918252602082200155600682018054906113ea906000198301611a26565b50600195945050505050565b60008181526007602081815260409283902090910180548351818402810184019094528084526060939283018282801561144f57602002820191906000526020600020905b81548152602001906001019080831161143b575b50505050509050919050565b60006114678333610e50565b1515611475575060006109d1565b600083815260076020819052604090912090810180546114ab91908590811061149a57fe5b906000526020600020015433610e50565b15156114bb5760009150506109d1565b600780820180546000198101926000929091839190859081106114da57fe5b90600052602060002001548152602001908152602001600020600101549050826007018281548110151561150a57fe5b9060005260206000200154836007018681548110151561152657fe5b6000918252602090912001556007830180548390811061154257fe5b600091825260208220015560078301805490611562906000198301611a26565b508060076000856007018581548110151561157957fe5b90600052602060002001548152602001908152602001600020600101819055506001935050505092915050565b600054600160a060020a031633146115bd57600080fd5b600155565b600054606090600160a060020a031633146115dc57600080fd5b600580548060200260200160405190810160405280929190818152602001828054801561162857602002820191906000526020600020905b815481526020019060010190808311611614575b5050505050905090565b600061163e8233610e50565b151561164c57506000610ca6565b60008281526007602052604090206002810154600182015461166e919061145b565b1561171f57600083815260066020526040902054801561171d576000848152600760209081526040808320805460ff1916905560069091528120556005805460001981019081106116bb57fe5b90600052602060002001546005828154811015156116d557fe5b6000918252602090912001556005805460001981019081106116f357fe5b60009182526020822001556005805490611711906000198301611a26565b50600192505050610ca6565b505b50600092915050565b60015481565b606080606061173d843361114d565b151561174d579150819050611814565b600084815260076020908152604091829020600501805483518184028101840190945280845290918301828280156117a457602002820191906000526020600020905b815481526020019060010190808311611790575b505050505092506007600085815260200190815260200160002060060180548060200260200160405190810160405280929190818152602001828054801561180b57602002820191906000526020600020905b8154815260200190600101908083116117f7575b50505050509150505b915091565b60006118258533610bbd565b151561183357506000610dcf565b60008581526007602052604090206006810154851015611902576000816005018681548110151561186057fe5b600091825260208083209091015480835260048501909152604082209190915560058301805491925086918890811061189557fe5b90600052602060002001819055508382600601878154811015156118b557fe5b600091825260208083209091019290925586815260049093018152604080842086905560088252808420898552825283208054600181810183559185529190932001849055509050610dcf565b50600095945050505050565b600061191983610f8a565b1580156119265750600083115b1561193057600080fd5b61193982610f8a565b1561194357600080fd5b508061194d611a4f565b604081018490526001815260008411156119715761196b8483611a00565b60208201525b6000828152600760209081526040918290208351815460ff1916901515178155838201516001820155918301516002830155606083015180518493926119be926005850192910190611a83565b50608082015180516119da916006840191602090910190611a83565b5060a082015180516119f6916007840191602090910190611a83565b5050505092915050565b600091825260076020818152604084209091018054600181018255908452922082015590565b815481835581811115611a4a57600083815260209020611a4a918101908301611ace565b505050565b6040805160c0810182526000808252602082018190529181019190915260608082018190526080820181905260a082015290565b828054828255906000526020600020908101928215611abe579160200282015b82811115611abe578251825591602001919060010190611aa3565b50611aca929150611ace565b5090565b6109db91905b80821115611aca5760008155600101611ad456fea165627a7a72305820a94a72dfbc557790c0914274c183f9b07a846099e80eac55353f2b258403c4470029608060405234801561001057600080fd5b5060405160808061089d8339810180604052608081101561003057600080fd5b5080516020820151604083015160609093015160048054600160a060020a0319908116600160a060020a039586161790915560008054821693851693909317835560018054909116939094169290921790925560025561080790819061009690396000f3fe6080604052600436106100745763ffffffff60e060020a6000350416630205217e8114610079578063043b0496146100aa57806312120511146100c157806312424e3f1461010057806345f9a3b5146101295780634bb278f314610153578063d0e30db014610168578063e609559414610170575b600080fd5b34801561008557600080fd5b5061008e610185565b60408051600160a060020a039092168252519081900360200190f35b3480156100b657600080fd5b506100bf610228565b005b3480156100cd57600080fd5b5061008e600480360360808110156100e457600080fd5b5080359060ff602082013516906040810135906060013561024d565b34801561010c57600080fd5b50610115610410565b604080519115158252519081900360200190f35b34801561013557600080fd5b506101156004803603602081101561014c57600080fd5b5035610573565b34801561015f57600080fd5b506100bf61060e565b6100bf610725565b34801561017c57600080fd5b506100bf61074b565b60008060009054906101000a9004600160a060020a0316600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b1580156101d757600080fd5b505afa1580156101eb573d6000803e3d6000fd5b505050506040513d602081101561020157600080fd5b5051600160a060020a0316331461021757600080fd5b50600454600160a060020a03165b90565b600454600160a060020a0316331461023f57600080fd5b600454600160a060020a0316ff5b604080518082018252601c8082527f19457468657265756d205369676e6564204d6573736167653a0a33320000000060208084019182529351600094859385938b939092019182918083835b602083106102b85780518252601f199092019160209182019101610299565b51815160209384036101000a600019018019909216911617905292019384525060408051808503815284830180835281519184019190912060009182905282860180845281905260ff8d166060870152608086018c905260a086018b90529151919650945060019360c08082019450601f19830192918290030190855afa158015610347573d6000803e3d6000fd5b505060408051601f198101516001547f8da5cb5b0000000000000000000000000000000000000000000000000000000083529251909450600160a060020a039092169250638da5cb5b916004808301926020929190829003018186803b1580156103b057600080fd5b505afa1580156103c4573d6000803e3d6000fd5b505050506040513d60208110156103da57600080fd5b5051600160a060020a03828116911614156103fd576103f7610410565b50610405565b610405610228565b505050949350505050565b600154600254604080517fa24fa791000000000000000000000000000000000000000000000000000000008152600481019290925251600092600160a060020a03169163a24fa791916024808301926020929190829003018186803b15801561047857600080fd5b505afa15801561048c573d6000803e3d6000fd5b505050506040513d60208110156104a257600080fd5b50511561056d576001805460025460048054604080517f90d1040e00000000000000000000000000000000000000000000000000000000815292830193909352600160a060020a03908116602483015260448201949094529051600093909216916390d1040e9160648082019260209290919082900301818787803b15801561052a57600080fd5b505af115801561053e573d6000803e3d6000fd5b505050506040513d602081101561055457600080fd5b50519050600181141561056b576001915050610225565b505b50600090565b60008060009054906101000a9004600160a060020a0316600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b1580156105c557600080fd5b505afa1580156105d9573d6000803e3d6000fd5b505050506040513d60208110156105ef57600080fd5b5051600160a060020a0316331461060557600080fd5b60039190915590565b6000809054906101000a9004600160a060020a0316600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b15801561065e57600080fd5b505afa158015610672573d6000803e3d6000fd5b505050506040513d602081101561068857600080fd5b5051600160a060020a0316331461069e57600080fd5b6000809054906101000a9004600160a060020a0316600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b1580156106ee57600080fd5b505afa158015610702573d6000803e3d6000fd5b505050506040513d602081101561071857600080fd5b5051600160a060020a0316ff5b600454600160a060020a0316331461073c57600080fd5b6000341161074957600080fd5b565b6000809054906101000a9004600160a060020a0316600160a060020a0316638da5cb5b6040518163ffffffff1660e060020a02815260040160206040518083038186803b15801561079b57600080fd5b505afa1580156107af573d6000803e3d6000fd5b505050506040513d60208110156107c557600080fd5b5051600160a060020a0316331461023f57600080fdfea165627a7a723058204f8ac421dfe9a1db32b4bee74de5e72757ec8ef53ac5fbc0c0d7f019414df8580029a165627a7a72305820d8a29302a7bdea4d92f53d443cf9feab37d479ad1cbce362875f039dcfe820d20029" + } + \ No newline at end of file diff --git a/src/fds/tests/unit_tests/test_key_value_tree.py b/src/fds/tests/unit_tests/test_key_value_tree.py new file mode 100644 index 0000000..335f996 --- /dev/null +++ b/src/fds/tests/unit_tests/test_key_value_tree.py @@ -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 diff --git a/src/fds/tests/unit_tests/test_multibox.py b/src/fds/tests/unit_tests/test_multibox.py new file mode 100644 index 0000000..8401c61 --- /dev/null +++ b/src/fds/tests/unit_tests/test_multibox.py @@ -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" diff --git a/src/fds/utils/convert.py b/src/fds/utils/convert.py new file mode 100644 index 0000000..4223afd --- /dev/null +++ b/src/fds/utils/convert.py @@ -0,0 +1,2 @@ +def int_to_bytes32(input: int) -> str: + return f"0x{input.to_bytes(32, byteorder='big').hex()}"