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 04:59:23 UTC

[incubator-tuweni] branch main updated: fix issue with constant bytes values slicing

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 37f862a3 fix issue with constant bytes values slicing
     new aa5cfaf7 Merge pull request #446 from atoulme/fix_constant_bytes_slice
37f862a3 is described below

commit 37f862a3d2b60e6dd12f4ecd196284e13176558d
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