@Test public void longScalar() { // Scalar should be encoded as the minimal byte array representing the number. For 0, that means // the empty byte array, which is a short element of zero-length, so 0x80. assertLongScalar(h("0x80"), 0); assertLongScalar(h("0x01"), 1); assertLongScalar(h("0x0F"), 15); assertLongScalar(h("0x820400"), 1024); }
@Test public void singleByteLowerBoundary() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.writeByte((byte) 0); assertThat(out.encoded()).isEqualTo(h("0x00")); }
@Test public void singleByteUpperBoundary() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.writeByte((byte) 0x7f); assertThat(out.encoded()).isEqualTo(h("0x7f")); }
@Test public void singleByte() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.writeByte((byte) 1); // Single byte should be encoded as itself assertThat(out.encoded()).isEqualTo(h("0x01")); }
@Test public void singleLongElement() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.writeBytesValue(h(times("3c", 2241))); // 2241 bytes, so long element: 0xb7 + length of value size + value, where the value size is // 2241, // 2241 is 0x8c1 so its size is 2 bytes. assertThat(out.encoded()).isEqualTo(h("0xb908c1" + times("3c", 2241))); }
@Test public void singleShortElement() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.writeByte((byte) 0xFF); // Bigger than single byte: 0x80 + length then value, where length is 1. assertThat(out.encoded()).isEqualTo(h("0x81FF")); }
@Test public void emptyList() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.startList(); out.endList(); assertThat(out.encoded()).isEqualTo(h("0xc0")); }
@Test public void simpleShortList() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.startList(); out.writeByte((byte) 0x2c); out.writeByte((byte) 0x3b); out.endList(); // List with payload size = 2 (both element are single bytes) // so 0xc0 + size then payloads assertThat(out.encoded()).isEqualTo(h("0xc22c3b")); }
@Test public void singleBarelyLongElement() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.writeBytesValue(h(times("2b", 56))); // 56 bytes, so long element: 0xb7 + length of value size + value, where the value size is 56. // 56 is 0x38 so its size is 1 byte. assertThat(out.encoded()).isEqualTo(h("0xb838" + times("2b", 56))); }
@Test public void simpleNestedList() { final BytesValueRLPOutput out = new BytesValueRLPOutput(); out.startList(); out.writeByte((byte) 0x2c); // Nested list has 2 simple elements, so will be 0xc20312 out.startList(); out.writeByte((byte) 0x03); out.writeByte((byte) 0x12); out.endList(); out.writeByte((byte) 0x3b); out.endList(); // List payload size = 5 (2 single bytes element + nested list of size 3) // so 0xc0 + size then payloads assertThat(out.encoded()).isEqualTo(h("0xc52cc203123b")); } }