def check_check_func(self): key = BitcoinVersionedPrivateKey( "cN5YgNRq8rbcJwngdp3fRzv833E7Z74TsF8nB6GhzRg8Gd9aGWH1") client = TalosVCRestClient() chunk = generate_random_chunk(1) policy = client.get_policy_with_txid(chunk.get_tag_hex()) def get_bitcoin_address_for_pubkey_tmp(hex_pubkey): before = timer() priv = extract_bin_bitcoin_pubkey(hex_pubkey) hash_priv = get_bin_hash160(priv) addr = bin_hash160_to_address(hash_priv, version_byte=111) print "Time creation %s" % ((timer() - before) * 1000, ) return addr def check_access_allowed_tmp(hex_pubkey, policy): before = timer() addr = get_bitcoin_address_for_pubkey_tmp(str(hex_pubkey)) print "Bitcoin_lib %s" % ((timer() - before) * 1000, ) if addr == policy.owner: return True if addr in policy.shares: return True return False self.assertTrue( check_access_allowed_tmp(key.public_key().to_hex(), policy))
def test_storage1(self): key = BitcoinVersionedPrivateKey( "cN5YgNRq8rbcJwngdp3fRzv833E7Z74TsF8nB6GhzRg8Gd9aGWH1") talosStorage = TalosLevelDBDHTStorage("db_tmp") client = TalosVCRestClient() num_iter = 100 for i in range(num_iter): chunk = generate_random_chunk(i) policy = client.get_policy_with_txid(chunk.get_tag_hex()) before = timer() talosStorage.store_check_chunk(chunk, i, policy) print "Time store %s" % ((timer() - before) * 1000, ) keeper = TimeKeeper() before = timer() talosStorage.get_check_chunk(chunk.key, key.public_key().to_hex(), policy, time_keeper=keeper) print "Time get %s" % ((timer() - before) * 1000, ) count = 0 for (key, value) in talosStorage.iteritemsOlderThan(100): count += 1 self.assertEquals(0, count) count = 0 for (key, value) in talosStorage.iteritems(): count += 1 self.assertEquals(num_iter, count) time.sleep(6) count = 0 for (key, value) in talosStorage.iteritemsOlderThan(5): count += 1 self.assertEquals(num_iter, count)
def test_chunk1(self): client = TalosVCRestClient() for i in range(100): chunk = generate_random_chunk(i) policy = client.get_policy_with_txid(chunk.get_tag_hex()) before = timer() check_chunk_valid(chunk, policy, chunk_id=i) print "Time check %s" % ((timer() - before) * 1000, )
def test_cross(self): client = TalosVCRestClient() for i in range(100): chunk = generate_random_chunk(i) policy = client.get_policy_with_txid(chunk.get_tag_hex()) before = timer() pub_key = get_crypto_ecdsa_pubkey_from_bitcoin_hex( str(policy.owner_pk)) print "Time check %s" % ((timer() - before) * 1000, )
def test_storage(self): key = BitcoinVersionedPrivateKey( "cN5YgNRq8rbcJwngdp3fRzv833E7Z74TsF8nB6GhzRg8Gd9aGWH1") talosStorage = LevelDBStorage("db_tmp") client = TalosVCRestClient() for i in range(100): chunk = generate_random_chunk(i) policy = client.get_policy_with_txid(chunk.get_tag_hex()) before = timer() talosStorage.store_check_chunk(chunk, i, policy) print "Time store %s" % ((timer() - before) * 1000, ) keeper = TimeKeeper() before = timer() talosStorage.get_check_chunk(chunk.key, key.public_key().to_hex(), policy, time_keeper=keeper) print "Time get %s" % ((timer() - before) * 1000, ) for (key, value) in talosStorage.db.RangeIter(): print base64.b64encode(key) print base64.b64encode(value)