Exemple #1
0
    def test_deserialization_valid_json(self):
        # Test valid json throws no errors
        msg = b'this is a pretend merkle tree hash'
        sk, vk = ED25519Wallet.new()
        signature = ED25519Wallet.sign(sk, msg)

        d = {
            MerkleSignature.SIG: signature,
            MerkleSignature.TS: 'now',
            MerkleSignature.SENDER: vk
        }
        binary = json.dumps(d).encode()
        MerkleSignature.from_bytes(binary)
Exemple #2
0
    def test_serialization(self):
        """
        Tests that a created block data reply successfully serializes and deserializes. The deserialized object should
        have the same properties as the original one before it was serialized.
        """
        msg = b'this is a pretend merkle tree hash'
        sk, vk = ED25519Wallet.new()
        signature = ED25519Wallet.sign(sk, msg)

        timestamp = 'now'
        valid_merkle_sig = MerkleSignature.create(sig_hex=signature,
                                                  timestamp=timestamp,
                                                  sender=vk)

        valid_merkle_sig_serialized = valid_merkle_sig.serialize()

        clone = MerkleSignature.from_bytes(valid_merkle_sig_serialized)

        self.assertEqual(valid_merkle_sig.signature, clone.signature)
        self.assertEqual(valid_merkle_sig.timestamp, clone.timestamp)
        self.assertEqual(valid_merkle_sig.sender, clone.sender)