use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class RLPTestCase method checkRLPAgainstJson.
public void checkRLPAgainstJson(RLPElement element, Object in) {
if (in instanceof List) {
Object[] array = ((List) in).toArray();
RLPList list = (RLPList) element;
for (int i = 0; i < array.length; i++) {
checkRLPAgainstJson(list.get(i), array[i]);
}
} else if (in instanceof Number) {
int computed = ByteUtil.byteArrayToInt(element.getRLPData());
this.computed.add(Integer.toString(computed));
this.expected.add(in.toString());
} else if (in instanceof String) {
String s = in.toString();
if (s.contains("#")) {
s = s.substring(1);
BigInteger expected = new BigInteger(s);
byte[] payload = element.getRLPData();
BigInteger computed = new BigInteger(1, payload);
this.computed.add(computed.toString());
this.expected.add(expected.toString());
} else {
String expected = new String(element.getRLPData() != null ? element.getRLPData() : new byte[0], StandardCharsets.UTF_8);
this.expected.add(expected);
this.computed.add(s);
}
} else {
throw new RuntimeException("Unexpected type: " + in.getClass());
}
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class RLPTest method encodeDecodeShortListWithTwoByteArraysWithTwoBytesLength.
@Test
public void encodeDecodeShortListWithTwoByteArraysWithTwoBytesLength() {
byte[] value1 = new byte[126];
byte[] value2 = new byte[126];
byte[] element1 = RLP.encodeElement(value1);
byte[] element2 = RLP.encodeElement(value2);
byte[] encoded = RLP.encodeList(element1, element2);
Assert.assertNotNull(encoded);
Assert.assertEquals(1 + 2 + 2 + 126 + 2 + 126, encoded.length);
Assert.assertEquals((byte) (247 + 2), encoded[0]);
Assert.assertEquals((byte) (1), encoded[1]);
Assert.assertEquals((byte) (0), encoded[2]);
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.RLPList in project rskj by rsksmart.
the class RLPTest method encodeDecodeEmptyList.
@Test
public void encodeDecodeEmptyList() {
byte[] encoded = RLP.encodeList();
Assert.assertNotNull(encoded);
Assert.assertEquals(1, encoded.length);
Assert.assertEquals((byte) 192, 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(0, list2.size());
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class RLPTest method encodeDecodeShortListWithTwoByteArraysWithOneByteLength.
@Test
public void encodeDecodeShortListWithTwoByteArraysWithOneByteLength() {
byte[] value1 = new byte[125];
byte[] value2 = new byte[126];
byte[] element1 = RLP.encodeElement(value1);
byte[] element2 = RLP.encodeElement(value2);
byte[] encoded = RLP.encodeList(element1, element2);
Assert.assertNotNull(encoded);
Assert.assertEquals(1 + 1 + 2 + 125 + 2 + 126, encoded.length);
Assert.assertEquals((byte) (247 + 1), encoded[0]);
Assert.assertEquals((byte) (255), encoded[1]);
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.RLPList in project rskj by rsksmart.
the class RLPTest method encodeDecodeShortListWithTwoByteArraysWithTwoBytesLengthBorderCase.
@Test
public void encodeDecodeShortListWithTwoByteArraysWithTwoBytesLengthBorderCase() {
byte[] value1 = new byte[128 * 256 - 3 - 1];
byte[] value2 = new byte[128 * 256 - 3];
byte[] element1 = RLP.encodeElement(value1);
byte[] element2 = RLP.encodeElement(value2);
byte[] encoded = RLP.encodeList(element1, element2);
Assert.assertNotNull(encoded);
Assert.assertEquals(1 + 2 + 3 + (128 * 256 - 3 - 1) + 3 + (128 * 256 - 3), encoded.length);
Assert.assertEquals((byte) (247 + 2), encoded[0]);
Assert.assertEquals((byte) (255), encoded[1]);
Assert.assertEquals((byte) (255), encoded[2]);
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());
}
Aggregations