use of com.jd.blockchain.ledger.proof.PathNode in project jdchain-core by blockchain-jd-com.
the class MerkleHashTrieTest method testDataSerialize.
/**
* 测试数据序列化;
*/
@Test
public void testDataSerialize() {
byte[] key = BytesUtils.toBytes("KEY-1");
HashDigest hashDigest = SHA256_HASH_FUNC.hash(key);
MerkleTrieData merkleData = new MerkleTrieDataEntry(key, 0, hashDigest.toBytes());
testMerkleDataSerialize(merkleData);
merkleData = new MerkleTrieDataEntry(key, 1024, hashDigest.toBytes());
testMerkleDataSerialize(merkleData);
merkleData = new MerkleTrieDataEntry(key, NumberMask.LONG.MAX_BOUNDARY_SIZE - 1, hashDigest.toBytes());
testMerkleDataSerialize(merkleData);
// 数据大小;
System.out.println("------ Merkle Data Serialize ------");
byte[] dataBytes = BinaryProtocol.encode(merkleData, MerkleTrieData.class);
System.out.printf("DataBytes= %s B\r\n", dataBytes.length);
System.out.println("------ Merkle Path Serialize ------");
int degree = 8;
PathNode pathNode = new PathNode(degree);
dataBytes = BinaryProtocol.encode(pathNode, MerklePath.class);
System.out.printf("childs=%s; bytes=%s B\r\n", 0, dataBytes.length);
for (int i = 0; i < degree; i++) {
HashDigest childHash = SHA256_HASH_FUNC.hash(BytesUtils.toBytes(1024 + i));
pathNode.setChildNode((byte) i, childHash, null);
dataBytes = BinaryProtocol.encode(pathNode, MerklePath.class);
System.out.printf("childs=%s; bytes=%s B\r\n", i + 1, dataBytes.length);
}
}
Aggregations