From a1b92a24c5040cc5dc073fc75ac30026468262f2 Mon Sep 17 00:00:00 2001 From: mikera Date: Fri, 20 Dec 2024 15:59:20 +0000 Subject: [PATCH] Misc tests and checks --- .../src/main/java/convex/core/cvm/ARecordGeneric.java | 2 +- convex-core/src/main/java/convex/core/cvm/CVMEncoder.java | 5 ++++- convex-core/src/main/java/convex/core/cvm/Syntax.java | 1 + .../src/main/java/convex/core/data/AArrayBlob.java | 3 ++- .../src/main/java/convex/core/data/ACAD3Record.java | 3 ++- convex-core/src/main/java/convex/core/data/ACell.java | 2 +- .../src/main/java/convex/core/data/CodedValue.java | 2 +- convex-core/src/main/java/convex/core/data/Format.java | 5 ++++- .../src/main/java/convex/core/data/VectorTree.java | 2 +- convex-core/src/main/java/convex/core/lang/Core.java | 6 ++---- convex-core/src/test/java/convex/core/data/CAD3Test.java | 3 +++ .../src/main/java/convex/peer/TransactionHandler.java | 8 ++------ 12 files changed, 24 insertions(+), 18 deletions(-) diff --git a/convex-core/src/main/java/convex/core/cvm/ARecordGeneric.java b/convex-core/src/main/java/convex/core/cvm/ARecordGeneric.java index f72699518..318c78ae4 100644 --- a/convex-core/src/main/java/convex/core/cvm/ARecordGeneric.java +++ b/convex-core/src/main/java/convex/core/cvm/ARecordGeneric.java @@ -124,7 +124,7 @@ protected void validateCell() throws InvalidDataException { Cells.validateCell(values); } - protected void validateStructure() throws InvalidDataException { + public void validateStructure() throws InvalidDataException { super.validateStructure(); if (values.count()!=format.count()) { throw new InvalidDataException("Expected "+format.count()+ "Record values but was: "+values.count(),this); diff --git a/convex-core/src/main/java/convex/core/cvm/CVMEncoder.java b/convex-core/src/main/java/convex/core/cvm/CVMEncoder.java index 4cd44499e..8d4465277 100644 --- a/convex-core/src/main/java/convex/core/cvm/CVMEncoder.java +++ b/convex-core/src/main/java/convex/core/cvm/CVMEncoder.java @@ -23,7 +23,10 @@ public ACell read(Blob encoding,int offset) throws BadFormatException { protected ACell readExtension(byte tag, Blob blob, int offset) throws BadFormatException { // We expect a VLQ Count following the tag long code=Format.readVLQCount(blob,offset+1); - if (tag == CVMTag.CORE_DEF) return Core.fromCode(code); + if (tag == CVMTag.CORE_DEF) { + ACell cc=Core.fromCode(code); + if (cc!=null) return cc; + } if (tag == CVMTag.ADDRESS) return Address.create(code); return ExtensionValue.create(tag, code); diff --git a/convex-core/src/main/java/convex/core/cvm/Syntax.java b/convex-core/src/main/java/convex/core/cvm/Syntax.java index 0892945b1..e7607ba56 100644 --- a/convex-core/src/main/java/convex/core/cvm/Syntax.java +++ b/convex-core/src/main/java/convex/core/cvm/Syntax.java @@ -244,6 +244,7 @@ public void validateStructure() throws InvalidDataException { throw new InvalidDataException("Cannot double-wrap a Syntax value",this); } } + meta.validateStructure(); } @Override diff --git a/convex-core/src/main/java/convex/core/data/AArrayBlob.java b/convex-core/src/main/java/convex/core/data/AArrayBlob.java index 2ab25693e..aeea51e53 100644 --- a/convex-core/src/main/java/convex/core/data/AArrayBlob.java +++ b/convex-core/src/main/java/convex/core/data/AArrayBlob.java @@ -370,7 +370,8 @@ public void validateCell() throws InvalidDataException { } @Override - protected void validateStructure() { + public void validateStructure() throws InvalidDataException { + super.validateStructure(); // nothing to do by default } diff --git a/convex-core/src/main/java/convex/core/data/ACAD3Record.java b/convex-core/src/main/java/convex/core/data/ACAD3Record.java index 55d5a6fbc..dd7a4248a 100644 --- a/convex-core/src/main/java/convex/core/data/ACAD3Record.java +++ b/convex-core/src/main/java/convex/core/data/ACAD3Record.java @@ -31,7 +31,8 @@ public void validateCell() throws InvalidDataException { } @Override - protected void validateStructure() throws InvalidDataException { + public void validateStructure() throws InvalidDataException { + super.validateStructure(); // Nothing to do, any child refs are valid } diff --git a/convex-core/src/main/java/convex/core/data/ACell.java b/convex-core/src/main/java/convex/core/data/ACell.java index 5db1d638a..94ea878b5 100644 --- a/convex-core/src/main/java/convex/core/data/ACell.java +++ b/convex-core/src/main/java/convex/core/data/ACell.java @@ -52,7 +52,7 @@ public void validate() throws InvalidDataException { * * @throws InvalidDataException If the Cell is invalid */ - protected void validateStructure() throws InvalidDataException { + public void validateStructure() throws InvalidDataException { // nothing by default } diff --git a/convex-core/src/main/java/convex/core/data/CodedValue.java b/convex-core/src/main/java/convex/core/data/CodedValue.java index e6ac8842d..ab8a04562 100644 --- a/convex-core/src/main/java/convex/core/data/CodedValue.java +++ b/convex-core/src/main/java/convex/core/data/CodedValue.java @@ -32,7 +32,7 @@ public void validateCell() throws InvalidDataException { } @Override - protected void validateStructure() throws InvalidDataException { + public void validateStructure() throws InvalidDataException { // Nothing to do, any child refs are valid } diff --git a/convex-core/src/main/java/convex/core/data/Format.java b/convex-core/src/main/java/convex/core/data/Format.java index d4676520d..93aedc80d 100644 --- a/convex-core/src/main/java/convex/core/data/Format.java +++ b/convex-core/src/main/java/convex/core/data/Format.java @@ -526,7 +526,10 @@ private static ACell readExtension(byte tag, Blob blob, int offset) throws BadFo // We expect a VLQ Count following the tag long code=readVLQCount(blob,offset+1); - if (tag == CVMTag.CORE_DEF) return Core.fromCode(code); + if (tag == CVMTag.CORE_DEF) { + ACell cc=Core.fromCode(code); + if (cc!=null) return cc; + } if ((tag == CVMTag.OP_SPECIAL)&&(code spec= Special.create((int)code); diff --git a/convex-core/src/main/java/convex/core/data/VectorTree.java b/convex-core/src/main/java/convex/core/data/VectorTree.java index df69d98eb..a09518c11 100644 --- a/convex-core/src/main/java/convex/core/data/VectorTree.java +++ b/convex-core/src/main/java/convex/core/data/VectorTree.java @@ -685,7 +685,7 @@ protected void validateCell() throws InvalidDataException { } @Override - protected void validateStructure() throws InvalidDataException { + public void validateStructure() throws InvalidDataException { super.validateStructure(); long c = 0; int blen = children.length; diff --git a/convex-core/src/main/java/convex/core/lang/Core.java b/convex-core/src/main/java/convex/core/lang/Core.java index 5a813741b..f7c3a9c34 100644 --- a/convex-core/src/main/java/convex/core/lang/Core.java +++ b/convex-core/src/main/java/convex/core/lang/Core.java @@ -3009,14 +3009,12 @@ private static Context applyDocumentation(Context ctx) throws IOException { * Read a Core definition from an encoding * @param b Blob containing encoding * @param pos Position to read Core code function - * @return Singleton cell representing the Core value - * @throws BadFormatException In case of encoding error + * @return Singleton cell representing the Core value, or null if not defined */ public static ACell fromCode(long code) throws BadFormatException { - if (code <0 || code>=CODE_MAP.length) throw new BadFormatException("Core code out of range: "+code); + if (code <0 || code>=CODE_MAP.length) return null; ACell o = CODE_MAP[(int)code]; - if (o == null) throw new BadFormatException("Core code definition not found: " + code); return o; } diff --git a/convex-core/src/test/java/convex/core/data/CAD3Test.java b/convex-core/src/test/java/convex/core/data/CAD3Test.java index 2e32209b1..3cb0bc5c7 100644 --- a/convex-core/src/test/java/convex/core/data/CAD3Test.java +++ b/convex-core/src/test/java/convex/core/data/CAD3Test.java @@ -63,6 +63,9 @@ public class CAD3Test extends ACVMTest { assertSame(Vectors.empty(),Reader.read("#[8000]")); assertNull(Reader.read("#[00]")); assertEquals(ExtensionValue.create((byte) 0xe5, 0),Reader.read("#[e500]")); + + assertEquals(Core.QUOTE,Reader.read("#[ed00]")); + assertEquals(ExtensionValue.create(CVMTag.CORE_DEF,1280),Reader.read("#[ed8a00]")); } @Test public void testDenseRecords() { diff --git a/convex-peer/src/main/java/convex/peer/TransactionHandler.java b/convex-peer/src/main/java/convex/peer/TransactionHandler.java index 7cdca0a20..ab7f95201 100644 --- a/convex-peer/src/main/java/convex/peer/TransactionHandler.java +++ b/convex-peer/src/main/java/convex/peer/TransactionHandler.java @@ -416,7 +416,7 @@ void maybeGetOwnTransactions(Peer p) { // Try to set hostname if not correctly set trySetHostname: - if (!Utils.equals(desiredHostname, currentHostname)) { + if ((desiredHostname!=null)&&!Utils.equals(desiredHostname, currentHostname)) { log.info("Trying to update own hostname from: {} to {}",currentHostname,desiredHostname); Address address=ps.getController(); if (address==null) break trySetHostname; @@ -426,11 +426,7 @@ void maybeGetOwnTransactions(Peer p) { if (!Cells.equals(peerKey, as.getAccountKey())) break trySetHostname; String code; - if (desiredHostname==null) { - code = String.format("(set-peer-data %s {:url nil})", peerKey); - } else { - code = String.format("(set-peer-data %s {:url \"%s\"})", peerKey, desiredHostname); - } + code = String.format("(set-peer-data %s {:url \"%s\"})", peerKey, desiredHostname); ACell message = Reader.read(code); ATransaction transaction = Invoke.create(address, as.getSequence()+1, message); newTransactions.add(p.getKeyPair().signData(transaction));