From e3fc8ca930e43bf53c4d6cdbfbfb83d5bd0918e7 Mon Sep 17 00:00:00 2001 From: mikera Date: Tue, 3 Dec 2024 00:02:52 +0000 Subject: [PATCH] More fixes and tests --- .../src/main/java/convex/core/cvm/CVMTag.java | 2 +- .../src/main/java/convex/core/data/AObject.java | 8 ++++++-- convex-core/src/main/java/convex/etch/Etch.java | 2 +- .../test/java/convex/core/data/ObjectsTest.java | 15 ++++++++++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/convex-core/src/main/java/convex/core/cvm/CVMTag.java b/convex-core/src/main/java/convex/core/cvm/CVMTag.java index 12968832e..6788a9ea8 100644 --- a/convex-core/src/main/java/convex/core/cvm/CVMTag.java +++ b/convex-core/src/main/java/convex/core/cvm/CVMTag.java @@ -85,7 +85,7 @@ public class CVMTag { public static final byte OP_DO = (byte)0xDA; // (do ...) public static final byte OP_INVOKE = (byte)0xDB; // (...) - function Invoke - public static final byte OP_COND = (byte)0xDB; // (cond ...) + public static final byte OP_COND = (byte)0xDC; // (cond ...) public static final byte FN = (byte) 0xCF; diff --git a/convex-core/src/main/java/convex/core/data/AObject.java b/convex-core/src/main/java/convex/core/data/AObject.java index 2696044bd..049935a43 100644 --- a/convex-core/src/main/java/convex/core/data/AObject.java +++ b/convex-core/src/main/java/convex/core/data/AObject.java @@ -56,8 +56,12 @@ public final AString print(long limit) { * @return A Blob representing this value in encoded form */ public Blob getEncoding() { - if (encoding==null) encoding=createEncoding(); - return encoding; + Blob result=encoding; + if (result==null) { + result=createEncoding(); + encoding=result; + } + return result; } /** diff --git a/convex-core/src/main/java/convex/etch/Etch.java b/convex-core/src/main/java/convex/etch/Etch.java index c52d831df..36e62fbd6 100644 --- a/convex-core/src/main/java/convex/etch/Etch.java +++ b/convex-core/src/main/java/convex/etch/Etch.java @@ -750,7 +750,7 @@ public RefSoft read(AArrayBlob key,long pointer) throws IOE try { Hash hash=Hash.wrap(key); T cell=store.decode(encoding); - cell.getEncoding().attachContentHash(hash); + encoding.attachContentHash(hash); if (memorySize>0) { // need to attach memory size for cell diff --git a/convex-core/src/test/java/convex/core/data/ObjectsTest.java b/convex-core/src/test/java/convex/core/data/ObjectsTest.java index 0165fee88..0f83a12cf 100644 --- a/convex-core/src/test/java/convex/core/data/ObjectsTest.java +++ b/convex-core/src/test/java/convex/core/data/ObjectsTest.java @@ -13,6 +13,7 @@ import java.io.IOException; import convex.core.Constants; +import convex.core.crypto.Hashing; import convex.core.cvm.CVMEncoder; import convex.core.data.Refs.RefTreeStats; import convex.core.data.util.BlobBuilder; @@ -82,8 +83,8 @@ public static void doCellTests(ACell a) { private static final CVMEncoder CVM_ENCODER=new CVMEncoder(); public static void doCAD3Tests(ACell a) { - Blob enc=Format.encodeMultiCell(a, true); try { + Blob enc=Format.encodeMultiCell(a, true); ACell cad=CAD3_ENCODER.decodeMultiCell(enc); assertEquals(a,cad); assertEquals(cad,a); @@ -100,6 +101,18 @@ public static void doCAD3Tests(ACell a) { } catch (BadFormatException e) { fail(e); } + + try { + Blob encoding=a.getEncoding(); + ACell b=Format.read(encoding); + assertEquals(b.getHash(),Hashing.sha3(encoding.getBytes())); + assertEquals(a,b); + + b.attachEncoding(null); + assertEquals(encoding,b.getEncoding()); + } catch (BadFormatException e) { + fail(e); + } } private static void doBranchTests(ACell a) {