base.py (4692B)
1 # standard imports 2 import logging 3 import time 4 5 # external imports 6 from chainlib.eth.unittest.ethtester import EthTesterCase 7 from chainlib.connection import RPCConnection 8 from chainlib.eth.nonce import RPCNonceOracle 9 from chainlib.eth.tx import receipt 10 from chainlib.eth.address import to_checksum_address 11 from giftable_erc20_token.unittest import TestGiftableToken 12 from eth_erc20 import ERC20 13 from chainlib.eth.block import block_latest 14 from eth_accounts_index.unittest import TestAccountsIndex 15 from eth_accounts_index.registry import AccountRegistry 16 17 # local imports 18 from evm_tokenvote import Voter 19 20 logg = logging.getLogger(__name__) 21 22 hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' 23 hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9' 24 hash_of_baz = 'baa5a0964d3320fbc0c6a922140453c8513ea24ab8fd0577034804a967248096' 25 26 27 class TestEvmVoteAccounts(TestGiftableToken): 28 29 expire = 0 30 31 def setUp(self): 32 super(TestEvmVoteAccounts, self).setUp() 33 34 self.alice = self.accounts[1] 35 self.bob = self.accounts[2] 36 self.carol = self.accounts[3] 37 self.dave = self.accounts[4] 38 self.trent = self.accounts[5] 39 self.mallory = self.accounts[8] 40 self.ivan = self.accounts[9] 41 42 self.conn = RPCConnection.connect(self.chain_spec, 'default') 43 44 c = ERC20(self.chain_spec) 45 o = c.total_supply(self.address, sender_address=self.accounts[0]) 46 r = self.rpc.do(o) 47 self.supply = int(r, 16) 48 self.assertGreater(self.supply, 0) 49 50 self.token_address = self.address 51 52 53 class TestEvmVote(TestEvmVoteAccounts): 54 55 def setUp(self): 56 super(TestEvmVote, self).setUp() 57 58 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 59 c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 60 (tx_hash, o) = c.constructor(self.accounts[0], self.address) 61 self.rpc.do(o) 62 o = receipt(tx_hash) 63 r = self.rpc.do(o) 64 self.assertEqual(r['status'], 1) 65 self.voter_address = to_checksum_address(r['contract_address']) 66 logg.debug('published voter on address {} with hash {}'.format(self.voter_address, tx_hash)) 67 68 69 class TestEvmVoteProposal(TestEvmVote): 70 71 def setUp(self): 72 super(TestEvmVoteProposal, self).setUp() 73 description = hash_of_foo 74 nonce_oracle = RPCNonceOracle(self.ivan, conn=self.conn) 75 c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 76 (tx_hash, o) = c.propose(self.voter_address, self.ivan, description, 100) 77 self.rpc.do(o) 78 o = receipt(tx_hash) 79 r = self.rpc.do(o) 80 self.assertEqual(r['status'], 1) 81 82 o = block_latest() 83 self.proposal_block_height = self.rpc.do(o) 84 85 86 class TestEvmVoteRegistry(TestEvmVoteAccounts): 87 88 def setUp(self): 89 super(TestEvmVoteRegistry, self).setUp() 90 91 nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) 92 c = AccountRegistry(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 93 (tx_hash, o) = c.constructor(self.accounts[0]) 94 self.conn.do(o) 95 o = receipt(tx_hash) 96 r = self.rpc.do(o) 97 self.registry_address = r['contract_address'] 98 logg.debug('published with accounts registry (voter) contract address {}'.format(r['contract_address'])) 99 100 (tx_hash, o) = c.add_writer(self.registry_address, self.accounts[0], self.accounts[0]) 101 self.conn.do(o) 102 o = receipt(tx_hash) 103 r = self.rpc.do(o) 104 self.assertEqual(r['status'], 1) 105 106 (tx_hash, o) = c.constructor(self.accounts[0]) 107 self.conn.do(o) 108 o = receipt(tx_hash) 109 r = self.rpc.do(o) 110 self.proposer_registry_address = r['contract_address'] 111 logg.debug('published with accounts registry (proposer) contract address {}'.format(r['contract_address'])) 112 113 (tx_hash, o) = c.add_writer(self.proposer_registry_address, self.accounts[0], self.accounts[0]) 114 self.conn.do(o) 115 o = receipt(tx_hash) 116 r = self.rpc.do(o) 117 self.assertEqual(r['status'], 1) 118 119 c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 120 (tx_hash, o) = c.constructor(self.accounts[0], self.token_address, voter_registry=self.registry_address, proposer_registry=self.proposer_registry_address) 121 self.rpc.do(o) 122 o = receipt(tx_hash) 123 r = self.rpc.do(o) 124 self.assertEqual(r['status'], 1) 125 self.voter_address = to_checksum_address(r['contract_address']) 126 logg.debug('published voter on address {} with hash {}'.format(self.voter_address, tx_hash))