@Test public void reset() { final RLPInput in = RLP.input(h("0xc80102c51112c22122")); for (int i = 0; i < 100; i++) { assertThat(in.enterList()).isEqualTo(3); assertThat(in.readByte()).isEqualTo((byte) 0x01); assertThat(in.readByte()).isEqualTo((byte) 0x02); assertThat(in.enterList()).isEqualTo(3); assertThat(in.readByte()).isEqualTo((byte) 0x11); assertThat(in.readByte()).isEqualTo((byte) 0x12); assertThat(in.enterList()).isEqualTo(2); assertThat(in.readByte()).isEqualTo((byte) 0x21); assertThat(in.readByte()).isEqualTo((byte) 0x22); in.reset(); } }
@Test public void simpleNestedList() { final RLPInput in = RLP.input(h("0xc52cc203123b")); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(3); assertThat(in.readByte()).isEqualTo((byte) 0x2c); assertThat(in.enterList()).isEqualTo(2); assertThat(in.readByte()).isEqualTo((byte) 0x03); assertThat(in.readByte()).isEqualTo((byte) 0x12); in.leaveList(); assertThat(in.readByte()).isEqualTo((byte) 0x3b); in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void simpleIntBeforeShortList() { final RLPInput in = RLP.input(h("0x02c22c3b")); assertThat(in.isDone()).isFalse(); assertThat(in.readIntScalar()).isEqualTo(2); assertThat(in.enterList()).isEqualTo(2); assertThat(in.readByte()).isEqualTo((byte) 0x2c); assertThat(in.readByte()).isEqualTo((byte) 0x3b); in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void simpleShortList() { final RLPInput in = RLP.input(h("0xc22c3b")); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(2); assertThat(in.readByte()).isEqualTo((byte) 0x2c); assertThat(in.readByte()).isEqualTo((byte) 0x3b); in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void singleShortElement() { final RLPInput in = RLP.input(h("0x81FF")); assertThat(in.isDone()).isFalse(); assertThat(in.readByte()).isEqualTo((byte) 0xFF); 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 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 singleByteUpperBoundary() { final RLPInput in = RLP.input(h("0x7f")); assertThat(in.isDone()).isFalse(); assertThat(in.readByte()).isEqualTo((byte) 0x7f); 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 leaveListEarly() { final RLPInput in = RLP.input(h("0xc80102c51112c22122")); assertThat(in.enterList()).isEqualTo(3); assertThat(in.readByte()).isEqualTo((byte) 0x01); assertThatThrownBy(() -> in.leaveList(false)) .isInstanceOf(RLPException.class) .hasMessageStartingWith("Not at the end of the current list"); }
@Test public void simpleShortListUpperBoundary() { final RLPInput in = RLP.input(h("0xf7" + times("3c", 55))); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(55); for (int i = 0; i < 55; 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_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 simpleLongListLowerBoundary() { final RLPInput in = RLP.input(h("0xf838" + times("3c", 56))); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(56); for (int i = 0; i < 56; i++) { assertThat(in.readByte()).isEqualTo((byte) 0x3c); } in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void simpleLongListBoundaryCase_5() { final RLPInput in = RLP.input(h("0xfaffffff" + times("3c", 16777215))); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(16777215); for (int i = 0; i < 16777215; i++) { assertThat(in.readByte()).isEqualTo((byte) 0x3c); } in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void simpleLongListBoundaryCase_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("0xfb01000000" + times("3c", 16777216))); assertThat(in.isDone()).isFalse(); assertThat(in.enterList()).isEqualTo(16777216); for (int i = 0; i < 16777216; i++) { assertThat(in.readByte()).isEqualTo((byte) 0x3c); } in.leaveList(); assertThat(in.isDone()).isTrue(); }
@Test public void ignoreListTail() { final RLPInput in = RLP.input(h("0xc80102c51112c22122")); assertThat(in.enterList()).isEqualTo(3); assertThat(in.readByte()).isEqualTo((byte) 0x01); in.leaveList(true); }