From fb3035217d26e447017b08eee15895e5f424be28 Mon Sep 17 00:00:00 2001 From: mikera Date: Sun, 1 Dec 2024 16:18:27 +0000 Subject: [PATCH] Better test for Address equality --- .../src/main/java/convex/core/cvm/Address.java | 15 ++++++--------- .../src/main/java/convex/core/data/ACell.java | 2 +- .../src/test/java/convex/core/data/CAD3Test.java | 7 +++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/convex-core/src/main/java/convex/core/cvm/Address.java b/convex-core/src/main/java/convex/core/cvm/Address.java index cb67101a5..e2ba80fee 100644 --- a/convex-core/src/main/java/convex/core/cvm/Address.java +++ b/convex-core/src/main/java/convex/core/cvm/Address.java @@ -6,6 +6,7 @@ import convex.core.data.AExtensionValue; import convex.core.data.AString; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Strings; import convex.core.data.prim.CVMLong; @@ -94,18 +95,14 @@ public AType getType() { return Types.ADDRESS; } - @Override - public boolean equals(Object a) { - if (a==this) return true; // Fast path, avoids cast - if (!(a instanceof Address)) return false; // Handles null - return equals((Address)a); - } - @Override public boolean equals(ACell o) { if (o==this) return true; - if (!(o instanceof Address)) return false; - return value==((Address) o).value; + if (o instanceof Address) { + return value==((Address) o).value; + } else { + return Cells.equalsGeneric(this, o); + } } public final boolean equals(Address o) { 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 1abe55bf5..95c4961a0 100644 --- a/convex-core/src/main/java/convex/core/data/ACell.java +++ b/convex-core/src/main/java/convex/core/data/ACell.java @@ -95,7 +95,7 @@ public int hashCode() { } @Override - public boolean equals(Object a) { + public final boolean equals(Object a) { if (a==this) return true; // Fast path, avoids cast if (!(a instanceof ACell)) return false; // Handles null return equals((ACell)a); 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 7aac66062..d763390ad 100644 --- a/convex-core/src/test/java/convex/core/data/CAD3Test.java +++ b/convex-core/src/test/java/convex/core/data/CAD3Test.java @@ -39,6 +39,13 @@ public class CAD3Test extends ACVMTest { assertSame(Core.VECTOR,Reader.read("#["+Utils.toHexString(CVMTag.CORE_DEF)+"01]")); } + @Test public void testAddressExtension() { + Address a=Address.create(127); + ExtensionValue e=ExtensionValue.create((byte) CVMTag.ADDRESS, 127); + assertEquals(a,e); + assertEquals(e,a); + } + @Test public void testReadEncodings() { assertSame(Address.ZERO,Reader.read("#[EA00]")); assertSame(CVMLong.ZERO,Reader.read("#[10]"));