use of org.ethereum.util.RLPElement in project rskj by rsksmart.
the class RLPTest method encodeDecodeLongByteArrayWithOneByteLengthUsingEncode.
@Test
public void encodeDecodeLongByteArrayWithOneByteLengthUsingEncode() {
byte[] bytes = new byte[56];
byte[] encoded = RLP.encode(bytes);
Assert.assertNotNull(encoded);
Assert.assertEquals(2 + 56, encoded.length);
Assert.assertEquals((byte) (183 + 1), encoded[0]);
Assert.assertEquals((byte) 56, encoded[1]);
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 encodeDecodeLongByteArrayWithTwoBytesLengthUsingEncode.
@Test
public void encodeDecodeLongByteArrayWithTwoBytesLengthUsingEncode() {
byte[] bytes = new byte[256];
byte[] encoded = RLP.encode(bytes);
Assert.assertNotNull(encoded);
Assert.assertEquals(3 + 256, encoded.length);
Assert.assertEquals((byte) (183 + 2), encoded[0]);
Assert.assertEquals((byte) 1, encoded[1]);
Assert.assertEquals((byte) 0, encoded[2]);
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 encodeDecodeSingleBytes.
@Test
public void encodeDecodeSingleBytes() {
for (int k = 0; k < 128; k++) {
byte[] bytes = new byte[1];
bytes[0] = (byte) k;
byte[] encoded = RLP.encodeElement(bytes);
Assert.assertNotNull(encoded);
Assert.assertEquals(1, encoded.length);
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 encodeDecodeLongByteArrayWithThreeBytesLengthBorderCaseUsingEncode.
@Test
public void encodeDecodeLongByteArrayWithThreeBytesLengthBorderCaseUsingEncode() {
byte[] bytes = new byte[256 * 256 * 256 - 1];
byte[] encoded = RLP.encode(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 encodeDecodeShortByteArraysUsingEncode.
@Test
public void encodeDecodeShortByteArraysUsingEncode() {
for (int k = 2; k < 56; k++) {
byte[] bytes = new byte[k];
byte[] encoded = RLP.encode(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