Skip to content

Commit

Permalink
Misc tests and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 20, 2024
1 parent 0a4038c commit a1b92a2
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion convex-core/src/main/java/convex/core/cvm/CVMEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions convex-core/src/main/java/convex/core/cvm/Syntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public void validateStructure() throws InvalidDataException {
throw new InvalidDataException("Cannot double-wrap a Syntax value",this);
}
}
meta.validateStructure();
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion convex-core/src/main/java/convex/core/data/AArrayBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion convex-core/src/main/java/convex/core/data/ACAD3Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/data/ACell.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/data/CodedValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion convex-core/src/main/java/convex/core/data/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Special.NUM_SPECIALS)) {
Special<?> spec= Special.create((int)code);
Expand Down
2 changes: 1 addition & 1 deletion convex-core/src/main/java/convex/core/data/VectorTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions convex-core/src/main/java/convex/core/lang/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions convex-core/src/test/java/convex/core/data/CAD3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 2 additions & 6 deletions convex-peer/src/main/java/convex/peer/TransactionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit a1b92a2

Please sign in to comment.