def create_commit_reveal_pair(node_private, random_bytes, pubkey_index,
                                  epoch_hash):
        private = Private.generate()
        encoded = Private.encrypt(random_bytes, private)

        commit = TransactionFactory.create_commit_random_transaction(
            encoded, pubkey_index, epoch_hash, node_private)
        reveal = TransactionFactory.create_reveal_random_transaction(
            commit.get_hash(), private)

        return commit, reveal
    def create_dummy_commit_reveal(random_bytes, epoch_hash):
        node_private = Private.generate()

        private = Private.generate()

        encoded = Private.encrypt(random_bytes, private)

        commit = CommitRandomTransaction()
        commit.rand = encoded
        commit.pubkey_index = 10
        commit.signature = Private.sign(commit.get_signing_hash(epoch_hash),
                                        node_private)

        reveal = RevealRandomTransaction()
        reveal.commit_hash = commit.get_hash()
        reveal.key = Keys.to_bytes(private)

        return commit, reveal
    def test_pack_parse_commit_transaction(self):
        for i in range(10):
            dummy_private = Private.generate()
            original = CommitRandomTransaction()
            original.rand = Private.encrypt(os.urandom(32), dummy_private)
            original.pubkey_index = i
            original.signature = Private.sign(
                original.get_signing_hash(b"epoch_hash"), dummy_private)

            raw = original.pack()
            restored = CommitRandomTransaction()
            restored.parse(raw)

            self.assertEqual(TransactionParser.pack(original),
                             TransactionParser.pack(restored))
            self.assertEqual(original.get_hash(), restored.get_hash())
            self.assertEqual(original.get_signing_hash(b"epoch_hash"),
                             restored.get_signing_hash(b"epoch_hash"))