Search in sources :

Example 1 with MerkleDataNodeEncoder_V1

use of com.jd.blockchain.ledger.proof.MerkleDataNodeEncoder_V1 in project jdchain-core by blockchain-jd-com.

the class MerkleDataNodeEncoderTest method doTestV1.

private void doTestV1(long sn, long version, Bytes key, byte[] data) {
    HashFunction hashFunc = Crypto.getHashFunction(ClassicAlgorithm.SHA256);
    HashDigest dataHash = hashFunc.hash(data);
    MerkleDataNodeEncoder encoderV1 = new MerkleDataNodeEncoder_V1();
    DataNode node = encoderV1.create(ClassicAlgorithm.SHA256.code(), sn, key, version, data);
    assertEquals(dataHash, node.getValueHash());
    assertEquals(sn, node.getSN());
    assertEquals(version, node.getVersion());
    assertEquals(key, node.getKey());
    byte[] nodeBytes = node.toBytes();
    DataNode node_reversed = encoderV1.resolve(nodeBytes);
    assertEquals(dataHash, node_reversed.getValueHash());
    assertEquals(node.getNodeHash(), node_reversed.getNodeHash());
    assertEquals(encoderV1.getFormatVersion(), nodeBytes[0]);
    assertEquals(sn, node_reversed.getSN());
    assertEquals(version, node_reversed.getVersion());
    assertEquals(key, node_reversed.getKey());
}
Also used : HashFunction(com.jd.blockchain.crypto.HashFunction) HashDigest(com.jd.blockchain.crypto.HashDigest) DataNode(com.jd.blockchain.ledger.proof.MerkleSequenceTree.DataNode) MerkleDataNodeEncoder_V1(com.jd.blockchain.ledger.proof.MerkleDataNodeEncoder_V1) MerkleDataNodeEncoder(com.jd.blockchain.ledger.core.MerkleDataNodeEncoder)

Aggregations

HashDigest (com.jd.blockchain.crypto.HashDigest)1 HashFunction (com.jd.blockchain.crypto.HashFunction)1 MerkleDataNodeEncoder (com.jd.blockchain.ledger.core.MerkleDataNodeEncoder)1 MerkleDataNodeEncoder_V1 (com.jd.blockchain.ledger.proof.MerkleDataNodeEncoder_V1)1 DataNode (com.jd.blockchain.ledger.proof.MerkleSequenceTree.DataNode)1