use of org.ethereum.util.RLPElement in project rskj by rsksmart.
the class RLPTest method encodeDecodeSingleBytesWithHighValue.
@Test
public void encodeDecodeSingleBytesWithHighValue() {
for (int k = 128; k < 256; k++) {
byte[] bytes = new byte[1];
bytes[0] = (byte) k;
byte[] encoded = RLP.encodeElement(bytes);
Assert.assertNotNull(encoded);
Assert.assertEquals(2, encoded.length);
Assert.assertEquals((byte) 129, encoded[0]);
RLPElement element = RLP.decode2OneItem(encoded, 0);
Assert.assertNotNull(element);
byte[] decoded = element.getRLPData();
Assert.assertNotNull(decoded);
Assert.assertArrayEquals(bytes, decoded);
}
}
use of org.ethereum.util.RLPElement in project rskj by rsksmart.
the class RLPTest method encodeDecodeShortListWithTwoByteArrays.
@Test
public void encodeDecodeShortListWithTwoByteArrays() {
byte[] value1 = new byte[] { 0x01, 0x02 };
byte[] value2 = new byte[] { 0x03, 0x04 };
byte[] element1 = RLP.encodeElement(value1);
byte[] element2 = RLP.encodeElement(value2);
byte[] encoded = RLP.encodeList(element1, element2);
Assert.assertNotNull(encoded);
Assert.assertEquals(1 + 3 + 3, encoded.length);
Assert.assertEquals((byte) (192 + 3 + 3), encoded[0]);
ArrayList<RLPElement> list = RLP.decode2(encoded);
Assert.assertNotNull(list);
Assert.assertEquals(1, list.size());
RLPList list2 = (RLPList) list.get(0);
Assert.assertNotNull(list2);
Assert.assertEquals(2, list2.size());
Assert.assertArrayEquals(value1, list2.get(0).getRLPData());
Assert.assertArrayEquals(value2, list2.get(1).getRLPData());
}
use of org.ethereum.util.RLPElement in project rskj by rsksmart.
the class RLPTest method encodeDecodeLongByteArrayWithThreeBytesLengthBorderCase.
@Test
public void encodeDecodeLongByteArrayWithThreeBytesLengthBorderCase() {
byte[] bytes = new byte[256 * 256 * 256 - 1];
byte[] encoded = RLP.encodeElement(bytes);
Assert.assertNotNull(encoded);
Assert.assertEquals(4 + 256 * 256 * 256 - 1, encoded.length);
Assert.assertEquals((byte) (183 + 3), encoded[0]);
Assert.assertEquals((byte) 0xff, encoded[1]);
Assert.assertEquals((byte) 0xff, encoded[2]);
Assert.assertEquals((byte) 0xff, encoded[3]);
RLPElement element = RLP.decode2OneItem(encoded, 0);
Assert.assertNotNull(element);
byte[] decoded = element.getRLPData();
Assert.assertNotNull(decoded);
Assert.assertArrayEquals(bytes, decoded);
}
use of org.ethereum.util.RLPElement in project rskj by rsksmart.
the class RLPTest method encodeDecodeLongByteArrayWithFourBytesLength.
@Test
public void encodeDecodeLongByteArrayWithFourBytesLength() {
byte[] bytes = new byte[256 * 256 * 256];
byte[] encoded = RLP.encodeElement(bytes);
Assert.assertNotNull(encoded);
Assert.assertEquals(5 + 256 * 256 * 256, encoded.length);
Assert.assertEquals((byte) (183 + 4), encoded[0]);
Assert.assertEquals((byte) 0x01, encoded[1]);
Assert.assertEquals((byte) 0x00, encoded[2]);
Assert.assertEquals((byte) 0x00, encoded[3]);
Assert.assertEquals((byte) 0x00, encoded[4]);
RLPElement element = RLP.decode2OneItem(encoded, 0);
Assert.assertNotNull(element);
byte[] decoded = element.getRLPData();
Assert.assertNotNull(decoded);
Assert.assertArrayEquals(bytes, decoded);
}
use of org.ethereum.util.RLPElement in project rskj by rsksmart.
the class RLPTest method encodeDecodeShortByteArrays.
@Test
public void encodeDecodeShortByteArrays() {
for (int k = 2; k < 56; k++) {
byte[] bytes = new byte[k];
byte[] encoded = RLP.encodeElement(bytes);
Assert.assertNotNull(encoded);
Assert.assertEquals(1 + k, encoded.length);
Assert.assertEquals((byte) (128 + k), encoded[0]);
RLPElement element = RLP.decode2OneItem(encoded, 0);
Assert.assertNotNull(element);
byte[] decoded = element.getRLPData();
Assert.assertNotNull(decoded);
Assert.assertArrayEquals(bytes, decoded);
}
}
Aggregations