Skip to content

Commit

Permalink
More fixes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 3, 2024
1 parent 46bf364 commit e3fc8ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/cvm/CVMTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions convex-core/src/main/java/convex/core/data/AObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/etch/Etch.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ public <T extends ACell> RefSoft<T> 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
Expand Down
15 changes: 14 additions & 1 deletion convex-core/src/test/java/convex/core/data/ObjectsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit e3fc8ca

Please sign in to comment.