Fix bug overwriting content when more than one declaration

This commit is contained in:
lash 2022-02-19 19:46:53 +00:00
parent 3dd286285c
commit d5de82198c
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 65 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
confini~=0.5.1 confini~=0.5.2
chainlib-eth~=0.0.10 chainlib-eth~=0.0.22

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = eth-address-index name = eth-address-index
version = 0.2.4 version = 0.2.5
description = Signed metadata declarations for ethereum addresses description = Signed metadata declarations for ethereum addresses
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no
@ -38,3 +38,4 @@ packages =
console_scripts = console_scripts =
eth-address-declarator-deploy = eth_address_declarator.runnable.deploy:main eth-address-declarator-deploy = eth_address_declarator.runnable.deploy:main
eth-address-declarator-add = eth_address_declarator.runnable.add:main eth-address-declarator-add = eth_address_declarator.runnable.add:main
eth-address-declarator-view = eth_address_declarator.runnable.view:main

View File

@ -1,4 +1,4 @@
eth-tester==0.5.0b3 eth-tester==0.5.0b3
py-evm==0.3.0a20 py-evm==0.3.0a20
eth-accounts-index>=0.1.2a3,<0.2.0 eth-accounts-index~=0.1.3
eth_erc20>=0.1.2a3,<=0.2.0 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])) 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__': if __name__ == '__main__':
unittest.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)); contents[contents.length-1].push(blockhash(block.number));
addDeclaration(msg.sender, _initialDescription); addDeclaration(msg.sender, _initialDescription);
} }
function toReference(address _declarator, address _subject) private pure returns ( bytes32 ) { function toReference(address _declarator, address _subject) private pure returns ( bytes32 ) {
bytes32 k; bytes32 k;
bytes memory signMaterial = new bytes(40); bytes memory addrMaterial = new bytes(40);
bytes memory addrBytes = abi.encodePacked(_declarator); bytes memory addrBytes = abi.encodePacked(_declarator);
for (uint256 i = 0; i < 20; i++) { for (uint256 i = 0; i < 20; i++) {
signMaterial[i] = addrBytes[i]; addrMaterial[i] = addrBytes[i];
} }
addrBytes = abi.encodePacked(_subject); addrBytes = abi.encodePacked(_subject);
for (uint256 i = 0; i < 20; i++) { 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; return k;
} }
@ -77,9 +78,9 @@ contract AddressDeclarator {
declarator[_subject].push(tx.origin); declarator[_subject].push(tx.origin);
contents.push(declarationContents); contents.push(declarationContents);
declarationIndex[tx.origin].push(_subject); declarationIndex[tx.origin].push(_subject);
idx = contents.length-1;
} }
idx = contents.length-1;
declarationContentIndex[ks[0]] = idx; declarationContentIndex[ks[0]] = idx;
contents[idx].push(_proof); contents[idx].push(_proof);