mirror of
git://holbrook.no/eth-address-index
synced 2024-11-16 14:36:46 +01:00
Rehabilitate tests
This commit is contained in:
parent
0043beb07b
commit
67b21c369f
File diff suppressed because one or more lines are too long
@ -75,7 +75,7 @@ class AddressDeclarator:
|
||||
# self.contract.functions.add(token_address, data).transact({'from': self.signer_address})
|
||||
#
|
||||
|
||||
def to_endorsement_key(declarator_address_hex, declaration_address_hex):
|
||||
def to_declarator_key(declarator_address_hex, declaration_address_hex):
|
||||
h = hashlib.new('sha256')
|
||||
h.update(bytes.fromhex(token_address_hex[2:]))
|
||||
h.update(bytes.fromhex(endorser_address_hex[2:]))
|
||||
|
File diff suppressed because one or more lines are too long
2
python/test_requirements.txt
Normal file
2
python/test_requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
eth-tester==0.5.0b2
|
||||
py-evm==0.3.0a20
|
@ -16,6 +16,7 @@ logging.getLogger('eth.vm').setLevel(logging.WARNING)
|
||||
|
||||
testdir = os.path.dirname(__file__)
|
||||
|
||||
description = '0x{:<064s}'.format(b'foo'.hex())
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
|
||||
@ -27,21 +28,20 @@ class Test(unittest.TestCase):
|
||||
})
|
||||
|
||||
# create store of used accounts
|
||||
f = open(os.path.join(testdir, '../eth_token_endorser/data/TokenEndorser.bin'), 'r')
|
||||
f = open(os.path.join(testdir, '../eth_address_declarator/data/AddressDeclarator.bin'), 'r')
|
||||
bytecode = f.read()
|
||||
f.close()
|
||||
|
||||
f = open(os.path.join(testdir, '../eth_token_endorser/data/TokenEndorser.json'), 'r')
|
||||
f = open(os.path.join(testdir, '../eth_address_declarator/data/AddressDeclarator.json'), 'r')
|
||||
self.abi = json.load(f)
|
||||
f.close()
|
||||
|
||||
|
||||
backend = eth_tester.PyEVMBackend(eth_params)
|
||||
self.eth_tester = eth_tester.EthereumTester(backend)
|
||||
provider = web3.Web3.EthereumTesterProvider(self.eth_tester)
|
||||
self.w3 = web3.Web3(provider)
|
||||
c = self.w3.eth.contract(abi=self.abi, bytecode=bytecode)
|
||||
tx_hash = c.constructor().transact({'from': self.w3.eth.accounts[0]})
|
||||
tx_hash = c.constructor(description).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
r = self.w3.eth.getTransactionReceipt(tx_hash)
|
||||
|
||||
@ -49,11 +49,11 @@ class Test(unittest.TestCase):
|
||||
|
||||
|
||||
# create token
|
||||
f = open(os.path.join(testdir, '../eth_token_endorser/data/GiftableToken.bin'), 'r')
|
||||
f = open(os.path.join(testdir, '../eth_address_declarator/data/GiftableToken.bin'), 'r')
|
||||
bytecode = f.read()
|
||||
f.close()
|
||||
|
||||
f = open(os.path.join(testdir, '../eth_token_endorser/data/GiftableToken.json'), 'r')
|
||||
f = open(os.path.join(testdir, '../eth_address_declarator/data/GiftableToken.json'), 'r')
|
||||
self.abi_token = json.load(f)
|
||||
f.close()
|
||||
|
||||
@ -80,54 +80,67 @@ class Test(unittest.TestCase):
|
||||
c = self.w3.eth.contract(abi=self.abi, address=self.address)
|
||||
|
||||
d = '0x' + os.urandom(32).hex()
|
||||
c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]})
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]})
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.addDeclaration(self.address_token_two, d).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[0]})
|
||||
c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
self.assertEqual(c.functions.declaratorCount(self.address_token_one).call(), 2)
|
||||
self.assertEqual(c.functions.declaratorCount(self.address_token_two).call(), 1)
|
||||
|
||||
|
||||
def test_endorsement(self):
|
||||
def test_declaration(self):
|
||||
c = self.w3.eth.contract(abi=self.abi, address=self.address)
|
||||
|
||||
d = '0x' + os.urandom(32).hex()
|
||||
c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]})
|
||||
c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
d_two = '0x' + os.urandom(32).hex()
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.addDeclaration(self.address_token_one, d_two).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[2]})
|
||||
c.functions.addDeclaration(self.address_token_two, d).transact({'from': self.w3.eth.accounts[2]})
|
||||
|
||||
proofs = c.functions.declaration(self.w3.eth.accounts[1], self.address_token_one).call()
|
||||
self.assertEqual(proofs[0].hex(), d[2:])
|
||||
self.assertEqual(proofs[1].hex(), d_two[2:])
|
||||
|
||||
|
||||
h = hashlib.new('sha256')
|
||||
h.update(bytes.fromhex(self.address_token_one[2:]))
|
||||
h.update(bytes.fromhex(self.w3.eth.accounts[0][2:]))
|
||||
z = h.digest()
|
||||
|
||||
assert d[2:] == c.functions.endorsement(z.hex()).call().hex()
|
||||
|
||||
c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[0]})
|
||||
|
||||
assert c.functions.endorsers(self.w3.eth.accounts[0], 0).call() == 1
|
||||
assert c.functions.endorsers(self.w3.eth.accounts[1], 0).call() == 1
|
||||
assert c.functions.endorsers(self.w3.eth.accounts[0], 1).call() == 2
|
||||
|
||||
assert c.functions.tokens(1).call() == self.address_token_one
|
||||
assert c.functions.tokens(2).call() == self.address_token_two
|
||||
|
||||
assert c.functions.tokenIndex(self.address_token_one).call() == 1
|
||||
assert c.functions.tokenIndex(self.address_token_two).call() == 2
|
||||
|
||||
|
||||
|
||||
def test_symbol_index(self):
|
||||
def test_declaration_count(self):
|
||||
c = self.w3.eth.contract(abi=self.abi, address=self.address)
|
||||
d = '0x' + os.urandom(32).hex()
|
||||
c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[0]})
|
||||
c.functions.add(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.add(self.address_token_two, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
|
||||
self.assertEqual(c.functions.tokenSymbolIndex('FOO').call(), self.address_token_one);
|
||||
self.assertEqual(c.functions.tokenSymbolIndex('BAR').call(), self.address_token_two);
|
||||
d = '0x' + os.urandom(32).hex()
|
||||
d_two = '0x' + os.urandom(32).hex()
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.addDeclaration(self.address_token_one, d_two).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[2]})
|
||||
c.functions.addDeclaration(self.address_token_two, d).transact({'from': self.w3.eth.accounts[2]})
|
||||
|
||||
self.assertEqual(c.functions.declarationCount(self.w3.eth.accounts[1]).call(), 1)
|
||||
self.assertEqual(c.functions.declarationCount(self.w3.eth.accounts[2]).call(), 2)
|
||||
|
||||
|
||||
def test_declarator_to_subject(self):
|
||||
c = self.w3.eth.contract(abi=self.abi, address=self.address)
|
||||
|
||||
d = '0x' + os.urandom(32).hex()
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[2]})
|
||||
c.functions.addDeclaration(self.address_token_two, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
|
||||
|
||||
self.assertEqual(c.functions.declarationAddressAt(self.w3.eth.accounts[1], 0).call(), self.address_token_one)
|
||||
self.assertEqual(c.functions.declarationAddressAt(self.w3.eth.accounts[2], 0).call(), self.address_token_one)
|
||||
self.assertEqual(c.functions.declarationAddressAt(self.w3.eth.accounts[1], 1).call(), self.address_token_two)
|
||||
|
||||
|
||||
def test_subject_to_declarator(self):
|
||||
c = self.w3.eth.contract(abi=self.abi, address=self.address)
|
||||
|
||||
d = '0x' + os.urandom(32).hex()
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
c.functions.addDeclaration(self.address_token_one, d).transact({'from': self.w3.eth.accounts[2]})
|
||||
c.functions.addDeclaration(self.address_token_two, d).transact({'from': self.w3.eth.accounts[1]})
|
||||
|
||||
self.assertEqual(c.functions.declaratorAddressAt(self.address_token_one, 0).call(), self.w3.eth.accounts[1])
|
||||
self.assertEqual(c.functions.declaratorAddressAt(self.address_token_one, 1).call(), self.w3.eth.accounts[2])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user