use of com.jd.blockchain.ledger.merkletree.TreeOptions in project jdchain-core by blockchain-jd-com.
the class MerkleSortTreeTest method testAddDuplicatedData.
@Test
public void testAddDuplicatedData() {
Random random = new Random();
byte[] data = new byte[32];
random.nextBytes(data);
MemoryKVStorage storage = new MemoryKVStorage();
// 配置选项设置为”不报告重复数据项“;
// 以不同的 id 重复设置两个相同的数据,预期不会报告异常;
MerkleProofException ex = null;
try {
TreeOptions options = TreeOptions.build().setDefaultHashAlgorithm(HASH_ALGORITHM.code()).setReportKeyStorageConfliction(false);
MerkleSortTree<byte[]> mst = MerkleSortTree.createBytesTree(options, DEFAULT_MKL_KEY_PREFIX, storage);
mst.set(1, data);
mst.set(2, data);
mst.commit();
} catch (MerkleProofException e) {
ex = e;
}
assertNull(ex);
// 配置选项设置为”报告重复数据项“;
// 以不同的 id 重复设置两个相同的数据,预期将报告异常;
ex = null;
try {
TreeOptions options = TreeOptions.build().setDefaultHashAlgorithm(HASH_ALGORITHM.code()).setReportKeyStorageConfliction(true);
MerkleSortTree<byte[]> mst = MerkleSortTree.createBytesTree(options, DEFAULT_MKL_KEY_PREFIX, storage);
mst.set(1, data);
mst.set(2, data);
mst.commit();
} catch (MerkleProofException e) {
ex = e;
}
assertNotNull(ex);
}
Aggregations