You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2022/11/20 06:34:54 UTC

[incubator-tuweni] branch 2.3 updated (be3b5c01 -> 67b92a4a)

This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a change to branch 2.3
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git


    from be3b5c01 Add svn option to allow to prompt for password
     new c8be3d07 move to version 2.3.1
     new c76fb9e7 fix issue with constant bytes values slicing
     new 67b92a4a fix zero compares of different lengths

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 build.gradle                                                   |  2 +-
 bytes/src/main/java/org/apache/tuweni/bytes/Bytes.java         |  7 ++++++-
 .../java/org/apache/tuweni/bytes/ConstantBytes32Value.java     |  5 ++++-
 bytes/src/test/java/org/apache/tuweni/bytes/Bytes32Test.java   | 10 ++++++++++
 bytes/src/test/java/org/apache/tuweni/bytes/BytesTest.java     |  4 ++++
 5 files changed, 25 insertions(+), 3 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org


[incubator-tuweni] 02/03: fix issue with constant bytes values slicing

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch 2.3
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git

commit c76fb9e7fc07f21a03f026d6919182041bf14ee0
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sat Nov 19 17:23:44 2022 -0800

    fix issue with constant bytes values slicing
---
 .../java/org/apache/tuweni/bytes/ConstantBytes32Value.java     |  5 ++++-
 bytes/src/test/java/org/apache/tuweni/bytes/Bytes32Test.java   | 10 ++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/bytes/src/main/java/org/apache/tuweni/bytes/ConstantBytes32Value.java b/bytes/src/main/java/org/apache/tuweni/bytes/ConstantBytes32Value.java
index e5035594..7a007e26 100644
--- a/bytes/src/main/java/org/apache/tuweni/bytes/ConstantBytes32Value.java
+++ b/bytes/src/main/java/org/apache/tuweni/bytes/ConstantBytes32Value.java
@@ -38,7 +38,10 @@ class ConstantBytes32Value extends AbstractBytes implements Bytes32 {
 
   @Override
   public Bytes slice(int i, int length) {
-    return new ConstantBytes32Value(this.value);
+    if (length == 32) {
+      return this;
+    }
+    return new ConstantBytesValue(this.value, length);
   }
 
   @Override
diff --git a/bytes/src/test/java/org/apache/tuweni/bytes/Bytes32Test.java b/bytes/src/test/java/org/apache/tuweni/bytes/Bytes32Test.java
index 0a7fc208..d7de6a1d 100644
--- a/bytes/src/test/java/org/apache/tuweni/bytes/Bytes32Test.java
+++ b/bytes/src/test/java/org/apache/tuweni/bytes/Bytes32Test.java
@@ -27,6 +27,16 @@ class Bytes32Test {
     assertEquals(wrapped.slice(0, 37), wrappedCopy);
   }
 
+  @Test
+  void constantBytes32slice() {
+    assertEquals(Bytes32.ZERO.slice(12, 20).size(), 20);
+  }
+
+  @Test
+  void constantBytesslice() {
+    assertEquals(Bytes.repeat((byte) 1, 63).slice(12, 20).size(), 20);
+  }
+
   @Test
   void testMutableBytes32WrapWithOffset() {
     Bytes bytes = Bytes


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org


[incubator-tuweni] 03/03: fix zero compares of different lengths

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch 2.3
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git

commit 67b92a4afde9bf2cba60689facd18aeb0d0cf38e
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sat Nov 19 21:58:13 2022 -0800

    fix zero compares of different lengths
---
 bytes/src/main/java/org/apache/tuweni/bytes/Bytes.java     | 7 ++++++-
 bytes/src/test/java/org/apache/tuweni/bytes/BytesTest.java | 4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/bytes/src/main/java/org/apache/tuweni/bytes/Bytes.java b/bytes/src/main/java/org/apache/tuweni/bytes/Bytes.java
index 50291371..668abad8 100644
--- a/bytes/src/main/java/org/apache/tuweni/bytes/Bytes.java
+++ b/bytes/src/main/java/org/apache/tuweni/bytes/Bytes.java
@@ -1687,10 +1687,15 @@ public interface Bytes extends Comparable<Bytes> {
   default int compareTo(Bytes b) {
     checkNotNull(b);
 
-    int sizeCmp = Integer.compare(bitLength(), b.bitLength());
+    int bitLength = bitLength();
+    int sizeCmp = Integer.compare(bitLength, b.bitLength());
     if (sizeCmp != 0) {
       return sizeCmp;
     }
+    // same bitlength and is zeroes only, return 0.
+    if (bitLength == 0) {
+      return 0;
+    }
 
     for (int i = 0; i < size(); i++) {
       int cmp = Integer.compare(get(i) & 0xff, b.get(i) & 0xff);
diff --git a/bytes/src/test/java/org/apache/tuweni/bytes/BytesTest.java b/bytes/src/test/java/org/apache/tuweni/bytes/BytesTest.java
index 35507ef9..8a293cf0 100644
--- a/bytes/src/test/java/org/apache/tuweni/bytes/BytesTest.java
+++ b/bytes/src/test/java/org/apache/tuweni/bytes/BytesTest.java
@@ -309,6 +309,10 @@ class BytesTest extends CommonBytesTests {
     assertEquals(-1, Bytes.of(0x01).compareTo(Bytes.of(0x01, 0xff)));
     assertEquals(-1, Bytes.of(0x00, 0x00, 0x01).compareTo(Bytes.of(0x00, 0x02)));
     assertEquals(-1, Bytes.of(0x00, 0x01).compareTo(Bytes.of(0x00, 0x00, 0x05)));
+    assertEquals(0, Bytes.fromHexString("0x0000").compareTo(Bytes.fromHexString("0x00")));
+    assertEquals(0, Bytes.fromHexString("0x00").compareTo(Bytes.fromHexString("0x0000")));
+    assertEquals(0, Bytes.fromHexString("0x000000").compareTo(Bytes.fromHexString("0x000000")));
+    assertEquals(-1, Bytes.fromHexString("0x000001").compareTo(Bytes.fromHexString("0x0001")));
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org


[incubator-tuweni] 01/03: move to version 2.3.1

Posted by to...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch 2.3
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git

commit c8be3d0752af622c89c939640952a8af0eb7597f
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sat Nov 19 22:33:31 2022 -0800

    move to version 2.3.1
---
 build.gradle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build.gradle b/build.gradle
index 037c6a7e..1b048570 100644
--- a/build.gradle
+++ b/build.gradle
@@ -43,7 +43,7 @@ description = 'A set of libraries and other tools to aid development of blockcha
 //////
 // Version numbering
 
-def versionNumber = '2.3.0'
+def versionNumber = '2.3.1'
 def buildVersion = versionNumber + buildTag(buildRelease)
 
 static String buildTag(releaseBuild) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org