Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCL 0.5.x upgrade #14

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading