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());
}
Aggregations