Skip to content

Commit

Permalink
add some test case
Browse files Browse the repository at this point in the history
  • Loading branch information
317787106 committed Sep 27, 2024
1 parent ddccce4 commit 450763b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions plugins/src/test/java/org/tron/plugins/utils/ByteArrayTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.tron.plugins.utils;

import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;

@Slf4j
public class ByteArrayTest {

@Test
public void testToStrToInt() {
String test = "abc";
byte[] testBytes = test.getBytes();
Assert.assertEquals(test, ByteArray.toStr(testBytes));

int i = 5;
Assert.assertEquals(ByteArray.toInt(ByteArray.fromInt(i)), 5);
}

@Test
public void testFromHexString() {
Assert.assertArrayEquals(ByteArray.EMPTY_BYTE_ARRAY, ByteArray.fromHexString(null));

Assert.assertArrayEquals(ByteArray.fromHexString("12"), ByteArray.fromHexString("0x12"));

Assert.assertArrayEquals(ByteArray.fromHexString("0x2"), ByteArray.fromHexString("0x02"));
}

@Test
public void testCompareUnsigned() {
byte[] a = new byte[] {1, 2};
Assert.assertEquals(0, ByteArray.compareUnsigned(a, a));
Assert.assertEquals(-1, ByteArray.compareUnsigned(null, a));
Assert.assertEquals(1, ByteArray.compareUnsigned(a, null));

byte[] b = new byte[] {1, 3};
Assert.assertEquals(-1, ByteArray.compareUnsigned(a, b));
Assert.assertEquals(1, ByteArray.compareUnsigned(b, a));

byte[] c = new byte[] {1, 2, 3};
Assert.assertEquals(-1, ByteArray.compareUnsigned(a, c));
Assert.assertEquals(1, ByteArray.compareUnsigned(c, a));
}
}

0 comments on commit 450763b

Please sign in to comment.