10 Commits

Author SHA1 Message Date
lash
aa99032d00 Merge remote-tracking branch 'origin/master' into tmp 2022-04-20 21:24:23 +00:00
lash
af63615eeb Upgrade deps 2022-04-20 21:23:35 +00:00
0d2ec53b69 Merge branch 'Ida/ci-test' into 'master'
Add coverage and slither analysis

See merge request cicnet/eth-address-index!2
2022-02-20 19:47:03 +00:00
d68995329c Add coverage and slither analysis 2022-02-20 19:47:03 +00:00
lash
92e826d559 Add bump description to changelog 2022-02-20 05:19:20 +00:00
lash
d5de82198c Fix bug overwriting content when more than one declaration 2022-02-19 19:46:53 +00:00
nolash
3dd286285c Bump to whole patch version 2021-11-15 14:38:35 +01:00
nolash
0053a1fc71 Improve testrunner 2021-10-24 15:59:16 +02:00
nolash
8dd4de4e50 Create dev extra for unittest deps 2021-10-24 15:35:02 +02:00
nolash
c31e7fe86f Move erc20 dep to tests 2021-10-24 15:32:53 +02:00
16 changed files with 153 additions and 25 deletions

2
.gitignore vendored
View File

@@ -4,3 +4,5 @@ dist/
__pycache__
*.pyc
gmon.out
.idea
venv

58
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,58 @@
stages:
- test
- run-coverage
- slither-analyzer
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- .venv/
before_script:
- python -V # Print out python version for debugging
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
test:
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
script:
# install test dependencies
- cd python
- export PYTHONPATH=.
- pip install --extra-index-url https://pip.grassrootseconomics.net
--extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple
-r requirements.txt -r test_requirements.txt
# run tests
- bash run_tests.sh
run-coverage:
stage: test
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
script:
- cd python
- export PYTHONPATH=.
- pip install --extra-index-url https://pip.grassrootseconomics.net
--extra-index-url https://gitlab.com/api/v4/projects/27624814/packages/pypi/simple
-r requirements.txt -r test_requirements.txt
- pip install pytest pytest-cov
- coverage run -m pytest
- coverage html
- coverage report --fail-under=90
coverage: '/^TOTAL.+?(\d+\%)$/'
artifacts:
reports:
cobertura: python/htmlcov/index.html
slither-analyzer:
image: registry.gitlab.com/grassrootseconomics/cic-base-images/ci-solc-python:latest
allow_failure: true
script:
- cd solidity
- slither AddressDeclarator.sol
- slither AddressDeclarator.sol --print human-summary

BIN
python/.coverage Normal file

Binary file not shown.

7
python/.coveragerc Normal file
View File

@@ -0,0 +1,7 @@
[run]
branch = True
[report]
omit = .venv/*
**/runnable/*.py
[html]

View File

@@ -1,4 +1,10 @@
- 0.1.2-pending
- 0.4.0
* Upgrade chainlib
- 0.3.0
* Use -a and -e flag combination for consistency
- 0.2.5
* Remove proof array idx overwrite when adding multiple proofs to subject
- 0.1.2
* Move to chainlib-eth
- 0.1.1-unreleased
- 0.1.0-unreleased

File diff suppressed because one or more lines are too long

View File

@@ -117,12 +117,15 @@ class Declarator(TxFactory):
@classmethod
def parse_declaration(self, v):
cursor = 0
v = strip_0x(v)
r = []
try:
v = strip_0x(v)
except ValueError:
return r
position = int.from_bytes(bytes.fromhex(v[cursor:cursor+64]), 'big')
cursor += (position * 2)
length = int.from_bytes(bytes.fromhex(v[cursor:cursor+64]), 'big')
cursor += 64
r = []
for i in range(length):
r.append(v[cursor:cursor+64])
cursor += 64

View File

@@ -32,14 +32,12 @@ logg = logging.getLogger()
#argparser.add_argument('--resolve', action='store_true', help='Attempt to resolve the hashes to actual content')
#argparser.add_argument('--resolve-http', dest='resolve_http', type=str, help='Base url to look up content hashes')
arg_flags = chainlib.eth.cli.argflag_std_read | chainlib.eth.cli.Flag.EXEC
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
argparser.add_argument('--declarator-address', required=True, type=str, help='Declarator of address')
arg_flags = chainlib.eth.cli.argflag_std_read | chainlib.eth.cli.Flag.EXEC | chainlib.eth.cli.Flag.WALLET
argparser = chainlib.eth.cli.ArgumentParser(arg_flags, arg_long={'-a': '--declarator-address'})
argparser.add_positional('address', type=str, help='Ethereum declaration address to look up')
args = argparser.parse_args()
extra_args = {
'declarator_address': None,
'address': None,
}
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=AddressDeclarator.gas())
@@ -52,6 +50,8 @@ conn = rpc.connect_by_config(config)
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
declarator_address = config.get('_WALLET_ADDRESS')
def out_element(e, w=sys.stdout):
w.write(e[1] + '\n')

View File

@@ -1,4 +1,2 @@
confini>=0.3.6rc3,<0.5.0
chainlib-eth>=0.0.10a5,<=0.1.0
eth_erc20>=0.1.2a3,<=0.2.0
funga>=0.5.1a1,<0.6.0
confini~=0.6.0
chainlib-eth>=0.1.0b1,<0.2.0

View File

@@ -2,6 +2,8 @@
set -e
set -x
default_pythonpath=$PYTHONPATH:.
export PYTHONPATH=${default_pythonpath:-.}
for f in `ls tests/*.py`; do
python $f
if [ $? -gt 0 ]; then

View File

@@ -1,6 +1,6 @@
[metadata]
name = eth-address-index
version = 0.2.5a1
version = 0.5.0
description = Signed metadata declarations for ethereum addresses
author = Louis Holbrook
author_email = dev@holbrook.no
@@ -28,11 +28,6 @@ packages =
eth_address_declarator.runnable
eth_address_declarator.unittest
[options.extras_require]
testing =
eth-tester==0.5.0b2
py-evm==0.3.0a20
[options.package_data]
* =
data/AddressDeclarator.json
@@ -43,3 +38,4 @@ testing =
console_scripts =
eth-address-declarator-deploy = eth_address_declarator.runnable.deploy:main
eth-address-declarator-add = eth_address_declarator.runnable.add:main
eth-address-declarator-view = eth_address_declarator.runnable.view:main

View File

@@ -22,4 +22,7 @@ f.close()
setup(
install_requires=requirements,
tests_require=test_requirements,
extras_require={
'dev': test_requirements,
},
)

View File

@@ -1,3 +1,4 @@
eth-tester==0.5.0b3
py-evm==0.3.0a20
eth-accounts-index>=0.1.2a3,<0.2.0
eth-accounts-index~=0.1.3
eth_erc20~=0.1.5

View File

@@ -183,5 +183,56 @@ class TestAddressDeclarator(TestAddressDeclaratorBase):
self.assertEqual(c.parse_declaration_address_at(r), strip_0x(self.accounts[2]))
def test_three_first(self):
d = []
for i in range(3):
d.append(add_0x(os.urandom(32).hex()))
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
for proof in d:
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[0], self.foo_token_address, proof)
self.rpc.do(o)
o = c.declarator_count(self.address, self.foo_token_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declarator_count(r), 1)
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
proofs = c.parse_declaration(r)
self.assertEqual(len(proofs), 3)
for i in range(3):
self.assertEqual(proofs[i], strip_0x(d[i]))
def test_three_first_different(self):
d = []
a = []
for i in range(3):
d.append(add_0x(os.urandom(32).hex()))
a.append(add_0x(os.urandom(20).hex()))
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
for i in range(3):
(tx_hash_hex, o) = c.add_declaration(self.address, self.accounts[0], a[i], d[i])
self.rpc.do(o)
for i in range(3):
o = c.declarator_count(self.address, a[i], sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_declarator_count(r), 1)
o = c.declaration(self.address, self.accounts[0], a[i], sender_address=self.accounts[0])
r = self.rpc.do(o)
proofs = c.parse_declaration(r)
self.assertEqual(len(proofs), 1)
self.assertEqual(proofs[0], strip_0x(d[i]))
if __name__ == '__main__':
unittest.main()

File diff suppressed because one or more lines are too long

View File

@@ -20,20 +20,21 @@ contract AddressDeclarator {
contents[contents.length-1].push(blockhash(block.number));
addDeclaration(msg.sender, _initialDescription);
}
function toReference(address _declarator, address _subject) private pure returns ( bytes32 ) {
bytes32 k;
bytes memory signMaterial = new bytes(40);
bytes memory addrMaterial = new bytes(40);
bytes memory addrBytes = abi.encodePacked(_declarator);
for (uint256 i = 0; i < 20; i++) {
signMaterial[i] = addrBytes[i];
addrMaterial[i] = addrBytes[i];
}
addrBytes = abi.encodePacked(_subject);
for (uint256 i = 0; i < 20; i++) {
signMaterial[i+20] = addrBytes[i];
addrMaterial[i+20] = addrBytes[i];
}
k = sha256(signMaterial);
k = sha256(addrMaterial);
return k;
}
@@ -77,9 +78,9 @@ contract AddressDeclarator {
declarator[_subject].push(tx.origin);
contents.push(declarationContents);
declarationIndex[tx.origin].push(_subject);
idx = contents.length-1;
}
idx = contents.length-1;
declarationContentIndex[ks[0]] = idx;
contents[idx].push(_proof);