@Test public void intScalar() { // 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. assertIntScalar(0, h("0x80")); assertIntScalar(1, h("0x01")); assertIntScalar(15, h("0x0F")); assertIntScalar(1024, h("0x820400")); }
@Test public void emptyByteString() { final RLPInput in = RLP.input(h("0x80")); assertThat(in.isDone()).isFalse(); assertThat(in.readBytesValue()).isEqualTo(BytesValue.EMPTY); assertThat(in.isDone()).isTrue(); }
@Test public void raw() { final BytesValue initial = h("0xc80102c51112c22122"); final RLPInput in = RLP.input(initial); assertThat(in.raw()).isEqualTo(initial); }
@Test public void decodeValueWithLeadingZerosAsUnsignedInt() { RLPInput in = RLP.input(h("0x84000000D0")); assertThat(in.readUnsignedInt()).isEqualTo(208); }
@Test public void decodeValueWithLeadingZerosAsSignedInt() { RLPInput in = RLP.input(h("0x84000000D0")); assertThat(in.readInt()).isEqualTo(208); }
@Test public void singleLongElementBoundaryCase_6() { // A RLPx Frame can have a maximum length of 0xffffff, so boundary above this // will be not be real world scenarios. final RLPInput in = RLP.input(h("0xbb01000000" + times("3c", 16777216))); assertThat(in.isDone()).isFalse(); assertThat(in.readBytesValue()).isEqualTo(h(times("3c", 16777216))); assertThat(in.isDone()).isTrue(); }
@Test public void decodeValueWithLeadingZerosAsSignedLong() { RLPInput in = RLP.input(h("0x8800000000000000D0")); assertThat(in.readLong()).isEqualTo(208); }
@Test public void emptyList() { final RLPInput in = RLP.input(h("0xc0")); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(0); assertThat(in.isDone()).isFalse(); in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void singleByteLowerBoundary() { final RLPInput in = RLP.input(h("0x00")); assertThat(in.isDone()).isFalse(); assertThat(in.readByte()).isEqualTo((byte) 0); assertThat(in.isDone()).isTrue(); }
@Test public void singleByte() { final RLPInput in = RLP.input(h("0x01")); assertThat(in.isDone()).isFalse(); assertThat(in.readByte()).isEqualTo((byte) 1); assertThat(in.isDone()).isTrue(); }
@Test public void simpleLongListBoundaryCase_3() { final RLPInput in = RLP.input(h("0xf9ffff" + times("3c", 65535))); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(65535); for (int i = 0; i < 65535; i++) { assertThat(in.readByte()).isEqualTo((byte) 0x3c); } in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void simpleLongListBoundaryCase_1() { final RLPInput in = RLP.input(h("0xf8ff" + times("3c", 255))); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(255); for (int i = 0; i < 255; i++) { assertThat(in.readByte()).isEqualTo((byte) 0x3c); } in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void simpleLongListBoundaryCase_4() { final RLPInput in = RLP.input(h("0xfa010000" + times("3c", 65536))); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(65536); for (int i = 0; i < 65536; i++) { assertThat(in.readByte()).isEqualTo((byte) 0x3c); } in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void simpleLongListBoundaryCase_2() { final RLPInput in = RLP.input(h("0xf90100" + times("3c", 256))); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(256); for (int i = 0; i < 256; i++) { assertThat(in.readByte()).isEqualTo((byte) 0x3c); } in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void rlpListSizeOverflowsInt() { // Size value is encoded with 5 bytes - overflowing int AssertionsForClassTypes.assertThatThrownBy(() -> RLP.input(h("0xFC0100000000"))) .isInstanceOf(RLPException.class) .hasMessageContaining( "RLP item at offset 1 with size value consuming 5 bytes exceeds max supported size of 2147483647"); }
@Test public void rlpItemSizeOverflowsInt() { // Size value is encoded with 5 bytes - overflowing int AssertionsForClassTypes.assertThatThrownBy(() -> RLP.input(h("0xBC0100000000"))) .isInstanceOf(RLPException.class) .hasMessageContaining( "RLP item at offset 1 with size value consuming 5 bytes exceeds max supported size of 2147483647"); }