Skip to content

Commit

Permalink
CCL 0.5.x upgrade (#14)
Browse files Browse the repository at this point in the history
* Feature: added extra unit test

* Feature: using CCL 0.5.x.

* chore: comment fix

---------

Co-authored-by: Mateusz Czeladka <mateusz.czeladka@cardanofoundation.org>
  • Loading branch information
matiwinnetou and Mateusz Czeladka authored Sep 1, 2023
1 parent 38efc54 commit 8449bf4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@

<slf4j.version>2.0.7</slf4j.version>
<lombok.version>1.18.26</lombok.version>
<cardano.client.lib.version>0.4.3</cardano.client.lib.version>
<cardano.client.lib.version>0.5.0-beta2</cardano.client.lib.version>
<vavr.version>0.10.4</vavr.version>

<junit-jupiter-engine.version>5.9.3</junit-jupiter-engine.version>

<git.repository>cardano-foundation/merkle-tree-java</git.repository>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- TODO replace with plutus specific annotations only -->
<dependency>
<groupId>com.bloxbean.cardano</groupId>
<artifactId>cardano-client-core</artifactId>
<artifactId>cardano-client-annotation-processor</artifactId>
<version>${cardano.client.lib.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -140,6 +139,13 @@
<configuration>
<source>17</source>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/org/cardanofoundation/merkle/MerkleTreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,17 @@ public void testMerkleToList1() {

@Test
public void testMerkleToList2() {
val originalList = List.of("", "", "", "", "", "", "");

val mt = MerkleTree.fromList(originalList, fromStringFun());

val items = MerkleTree.toList(mt);

assertArrayEquals(items.toJavaArray(), originalList.toJavaArray());
}

@Test
public void testMerkleToList3() {
val originalList = new ArrayList<String>();

for (int i = 0; i < 1_000_000; i++) {
Expand All @@ -373,6 +384,28 @@ public void testMerkleToList2() {
assertArrayEquals(items.toJavaArray(), originalList.toArray());
}

@Test
public void testSparseMerkleProofAndVerify() {
val items1 = List.of("", "", "", "", "", "", "");

val mt1 = MerkleTree.fromList(items1, fromStringFun());
val root1 = mt1.itemHash();

val items2 = List.of("", "", "", "", "", "", "beaver");
var mt2 = MerkleTree.fromList(items2, fromStringFun());
val root2 = mt2.itemHash();

var proof2 = MerkleTree.getProof(mt2, "beaver", fromStringFun());

assertTrue(
MerkleTree.verifyProof(
root2,
"beaver",
proof2.orElseThrow(),
fromStringFun())
);
}

private static Function<String, byte[]> fromStringFun() {
return str -> str.getBytes(UTF_8);
}
Expand Down

0 comments on commit 8449bf4

Please sign in to comment.