zero-knowledge/src/test/java/com/hedera/hashgraph/zeroknowledge/vc/CredentialSubjectMerkleTreeLeafTest.java
/*
     * This test makes sure that the hash computation procedure is not altered by mistake
     * */
This test makes sure that the hash computation procedure is not altered by mistake
This test makes sure that the hash computation procedure is not altered by mistake
@Test
    public void merkleTreeLeafHashIsCorrectlyComputed() throws DeserializationException, FieldElementConversionException, FinalizationException {
        String key = "key";
        String value = "value";
        CredentialSubjectMerkleTreeLeaf merkleTreeLeaf = new CredentialSubjectMerkleTreeLeaf(key, value);
        FieldElement keyFieldElement = FieldElement.deserialize(key.getBytes(StandardCharsets.UTF_8));
        FieldElement valueFieldElement = FieldElement.deserialize(value.getBytes(StandardCharsets.UTF_8));
        PoseidonHash hash = PoseidonHash.getInstanceConstantLength(2);
        hash.update(keyFieldElement);
        hash.update(valueFieldElement);
        FieldElement merkleTreeLeafHash = merkleTreeLeaf.toFieldElement();
        FieldElement computedHash = hash.finalizeHash();
        assertEquals(merkleTreeLeafHash, computedHash);
    }
@ Test public void merkleTreeLeafHashIsCorrectlyComputed ( ) throws DeserializationException , FieldElementConversionException , FinalizationException { String key = "key" ; String value = "value" ; CredentialSubjectMerkleTreeLeaf merkleTreeLeaf = new CredentialSubjectMerkleTreeLeaf ( key , value ) ; FieldElement keyFieldElement = FieldElement . deserialize ( key . getBytes ( StandardCharsets . UTF_8 ) ) ; FieldElement valueFieldElement = FieldElement . deserialize ( value . getBytes ( StandardCharsets . UTF_8 ) ) ; PoseidonHash hash = PoseidonHash . getInstanceConstantLength ( 2 ) ; hash . update ( keyFieldElement ) ; hash . update ( valueFieldElement ) ; FieldElement merkleTreeLeafHash = merkleTreeLeaf . toFieldElement ( ) ; FieldElement computedHash = hash . finalizeHash ( ) ; assertEquals ( merkleTreeLeafHash , computedHash ) ; }
This test makes sure that the hash computation procedure is not altered by mistake
This test makes sure that the hash computation procedure is not altered by mistake
// Arrange // Act // Assert