def make_bad_client(self, bad_cleint_thread, with_print=False):
     sk = random_sk()
     channel = ChannelWithPrint() if with_print else Channel()
     public_key = sk.get_public_key()
     inputs = {}
     number_of_pubs = random.randint(1, 3)
     secret_keys = [random_sk() for _ in range(number_of_pubs)]
     sks = {sk.get_public_key(): sk for sk in secret_keys}
     for pubk in sks:
         inputs[pubk] = []
         number_of_coins = random.randint(1, 2)
         addr = public_key_to_p2pkh(bytes.fromhex(pubk))
         for i in range(number_of_coins):
             min_amout_per_input = self.amount // number_of_pubs // number_of_coins
             coin_amount = random.randint(
                 min_amout_per_input + self.fee + 1,
                 min_amout_per_input + self.fee + 1000)
             coin_hash = fake_hash(addr, coin_amount)
             inputs[pubk].append(coin_hash + ":0")
             self.network.add_coin(addr, coin_amount, tx_hash=coin_hash)
     return bad_cleint_thread(self.HOST,
                              self.PORT,
                              self.network,
                              self.amount,
                              self.fee,
                              sk,
                              sks,
                              inputs,
                              public_key,
                              self.get_random_address(),
                              self.get_random_address(),
                              logger=channel)
 def make_bad_client(self, bad_cleint_thread , with_print = False):
     sk = random_sk()
     channel = ChannelWithPrint() if with_print else Channel()
     pubk = sk.get_public_key()
     addr = public_key_to_p2pkh(bytes.fromhex(pubk))
     self.network.add_coin(addr , self.amount + random.randint(self.amount + 1 , self.amount + self.fee + 1000))
     # add checking fro parent class inheritance here
     # (host, port, network, amount, fee, sk, pubk, addr_new, change, logger = logger, ssl = False)
     return bad_cleint_thread(self.HOST, self.PORT, self.network, self.amount, self.fee, sk, pubk, self.get_random_address(), self.get_random_address(), logger = channel)
 def make_clients_threads(self, number_of_clients=None, with_print=False):
     if not number_of_clients:
         number_of_clients = self.number_of_players
     players = [{
         "channel": ChannelWithPrint() if with_print else Channel()
     } for _ in range(number_of_clients)]
     for player in players:
         number_of_pubs = random.randint(1, 3)
         player["secret_keys"] = [
             random_sk() for _ in range(number_of_pubs)
         ]
         player["sks"] = {
             sk.get_public_key(): sk
             for sk in player["secret_keys"]
         }
         player["inputs"] = {}
         for pubk in player["sks"]:
             player["inputs"][pubk] = []
             number_of_coins = random.randint(1, 2)
             addr = public_key_to_p2pkh(bytes.fromhex(pubk))
             for i in range(number_of_coins):
                 min_amout_per_input = self.amount // number_of_pubs // number_of_coins
                 coin_amount = random.randint(
                     min_amout_per_input + self.fee + 1,
                     min_amout_per_input + self.fee + 1000)
                 coin_hash = fake_hash(addr, coin_amount)
                 player["inputs"][pubk].append(coin_hash + ":0")
                 self.network.add_coin(addr, coin_amount, tx_hash=coin_hash)
         player["sk"] = random_sk()
         player["pubk"] = player["sk"].get_public_key()
     protocolThreads = [
         testThread(self.HOST,
                    self.PORT,
                    self.network,
                    self.amount,
                    self.fee,
                    player["sk"],
                    player["sks"],
                    player["inputs"],
                    player["pubk"],
                    self.get_random_address(),
                    self.get_random_address(),
                    logger=player['channel']) for player in players
     ]
     return protocolThreads
    def make_clients_threads(self, number_of_clients = None, with_print = False):
        if not number_of_clients:
            number_of_clients = self.number_of_players
        # generate random keys
        players = [{"sk": random_sk(), "channel":ChannelWithPrint() if with_print else Channel()}  for sk in range(number_of_clients)]
        # loggers = [Channel() for _ in range(self.number_of_players)]
        for player in players:
            pubk = player["sk"].get_public_key()
            addr = public_key_to_p2pkh(bytes.fromhex(pubk))
            # add coins to pseudonetwork with sufficient ammount
            self.network.add_coin(addr , self.amount + random.randint(self.amount + 1 , self.amount + self.fee + 1000))

        # make threads
        protocolThreads = [testThread.from_sk(player["sk"], self.HOST, self.PORT, self.network, self.amount, self.fee, self.get_random_address(), self.get_random_address(), logger = player['channel']) for player in players]
        return protocolThreads
 def setUp(self):
     self.number_of_players = 5
     self.crypto = Crypto()
     self.messages = Messages()
     self.outchan = Channel()
     self.inchan = Channel()
     self.logchan = Channel()
     self.session = b"session"
     self.phase = Phase('Announcement')
     self.amount = 1000
     self.fee = 50
     self.secret_keys = [random_sk() for _ in range(self.number_of_players)]
     self.verification_keys = [
         make_fake_public_key(secret_key=sk) for sk in self.secret_keys
     ]
     self.players = {
         index + 1: vk
         for index, vk in enumerate(self.verification_keys)
     }
     self.inputs = {
         self.verification_keys[0]: {
             self.public_keys[0]: [
                 fake_hash(self.addresses[0], 500) + ":0",
                 fake_hash(self.addresses[0], 100) + ":0"
             ],
             self.public_keys[1]:
             [fake_hash(self.addresses[1], 500) + ":0"]
         },
         self.verification_keys[1]: {
             self.public_keys[2]: [
                 fake_hash(self.addresses[2], 1000) + ":0",
                 fake_hash(self.addresses[2], 100) + ":0"
             ],
         },
         self.verification_keys[2]: {
             self.public_keys[3]:
             [fake_hash(self.addresses[3], 1000) + ":0"],
             self.public_keys[4]:
             [fake_hash(self.addresses[4], 100) + ":0"],
         },
         self.verification_keys[3]: {
             self.public_keys[5]:
             [fake_hash(self.addresses[5], 10000) + ":0"],
         },
         self.verification_keys[4]: {
             self.public_keys[6]:
             [fake_hash(self.addresses[6], 1000) + ":0"],
             self.public_keys[7]:
             [fake_hash(self.addresses[7], 500) + ":0"]
         }
     }
     self.sks = {
         self.public_keys[0]: self.ec_keys[0],
         self.public_keys[1]: self.ec_keys[1],
     }
     self.all_sks = {
         self.verification_keys[0]: {
             self.public_keys[0]: self.ec_keys[0],
             self.public_keys[1]: self.ec_keys[1]
         },
         self.verification_keys[1]: {
             self.public_keys[2]: self.ec_keys[2],
         },
         self.verification_keys[2]: {
             self.public_keys[3]: self.ec_keys[3],
             self.public_keys[4]: self.ec_keys[4],
         },
         self.verification_keys[3]: {
             self.public_keys[5]: self.ec_keys[5],
         },
         self.verification_keys[4]: {
             self.public_keys[6]: self.ec_keys[6],
             self.public_keys[7]: self.ec_keys[7]
         }
     }
     self.sk = self.secret_keys[0]
     self.verification_key = self.verification_keys[0]
     self.new_addresses = [
         make_fake_address() for _ in range(self.number_of_players)
     ]
     self.changes = {
         vk: make_fake_address()
         for vk in self.verification_keys
     }
     self.addr_new = self.new_addresses[0]
     self.change = make_fake_address()
     self.round = Round(self.coin, self.crypto, self.messages, self.inchan,
                        self.outchan, self.logchan, self.session,
                        self.phase, self.amount, self.fee, self.sk,
                        self.sks, self.inputs, self.verification_key,
                        self.players, self.addr_new, self.change)