def test_retrieve_balance(self): _address = '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' address = ethereum.Address(address=_address) self.assertEqual(address.balance, 744997704382925139479303.0) with self.assertRaises(error.EtherscanInitializationError): _bad_address = 5 ethereum.Address(_bad_address)
def test_blocks_mined(self): _address = '0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b' address = ethereum.Address(address=_address) expected_block_number = 3462296 block_number = address.blocks_mined[0].block_number self.assertEqual(expected_block_number, block_number)
def test_token_balance(self): contract_address = '0x57d90b64a1a57749b0f932f1a3395792e12e7055' _address = '0xe04f27eb70e025b78871a2ad7eabe85e61212761' address = ethereum.Address(address=_address) token_balance = address.token_balance(contract_address) self.assertEqual(token_balance, 135499.0)
class TestBlockObject(BaseEthereumTestCase): data = { "blockNumber": "2165403", "timeStamp": "1472533979", "blockMiner": "0x13a06d3dfe21e0db5c016c03ea7d2509f7f8d1e3", "blockReward": "5314181600000000000", "uncles": [{ "miner": "0xbcdfc35b86bedf72f0cda046a3c16829a2ef41d1", "unclePosition": "0", "blockreward": "3750000000000000000" }, { "miner": "0x0d0c9855c722ff0c78f21e43aa275a5b8ea60dce", "unclePosition": "1", "blockreward": "3750000000000000000" }], "uncleInclusionReward": "312500000000000000" } uncles = [{ "miner": ethereum.Address("0xbcdfc35b86bedf72f0cda046a3c16829a2ef41d1"), "block_reward": float("3750000000000000000") }, { "miner": ethereum.Address("0x0d0c9855c722ff0c78f21e43aa275a5b8ea60dce"), "block_reward": float("3750000000000000000") }] def test_initialization(self): with self.assertRaises(error.EtherscanInitializationError): ethereum.Block(2.0) def test_block_attributes(self): block_rewards = ethereum.Block(2165403) self.assertEqual(block_rewards.time_stamp, int(self.data.get('timeStamp'))) self.assertEqual(block_rewards.block_miner, self.data.get('blockMiner')) self.assertEqual(block_rewards.block_reward, float(self.data.get('blockReward'))) self.assertEqual(block_rewards.uncle_inclusion_reward, float(self.data.get('uncleInclusionReward'))) datetime_mined = datetime.datetime.utcfromtimestamp( int(self.data.get('timeStamp'))) self.assertEqual(block_rewards.datetime_mined, datetime_mined) # test uncles uncle_one_address = block_rewards.uncles[0]['miner'] uncle_one_reward = block_rewards.uncles[0]['block_reward'] expected_uncle_address = self.uncles[0]['miner'].address expected_uncle_reward = self.uncles[0]['block_reward'] self.assertEqual(uncle_one_address, expected_uncle_address) self.assertEqual(uncle_one_reward, expected_uncle_reward)
def test_transaction_property(self): _address = '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae' address = ethereum.Address(address=_address) self.assertIsInstance(address.transactions, ethereum.TransactionContainer)