def test_005_verigy_signatures(self): message = b"some_message_for_test" sk_1 = random_sk() pubkey_1 = sk_1.get_public_key(True) signature_1 = sk_1.sign_message(message, True) self.assertTrue(self.coin.verify_signature(signature_1, message, pubkey_1)) sk_2 = random_sk() pubkey_2 = sk_2.get_public_key(False) signature_2 = sk_2.sign_message(message, False) self.assertTrue(self.coin.verify_signature(signature_2, message, pubkey_2)) self.assertFalse(self.coin.verify_signature(signature_2, message, pubkey_1))
def __init__(self, *args, **kwargs): super(TestCoin, self).__init__(*args, **kwargs) self.network = testNetwork() self.ec_keys = [random_sk() for _ in range(10)] self.public_keys = [make_fake_public_key(secret_key=sk) for sk in self.ec_keys] self.addresses = [address_from_public_key(public_key) for public_key in self.public_keys] for address in self.addresses: for value in [10000, 1000, 500, 100]: self.network.add_coin(address, value, tx_hash = fake_hash(address, value)) self.coin = Coin(self.network)
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)