diff --git a/src/test/java/com/esaulpaugh/headlong/rlp/RLPStreamTest.java b/src/test/java/com/esaulpaugh/headlong/rlp/RLPStreamTest.java index f5f722e2..2dd298bd 100644 --- a/src/test/java/com/esaulpaugh/headlong/rlp/RLPStreamTest.java +++ b/src/test/java/com/esaulpaugh/headlong/rlp/RLPStreamTest.java @@ -61,50 +61,50 @@ public class RLPStreamTest { (byte) 0xca, (byte) 0x84, 92, '\r', '\n', '\f', (byte) 0x84, '\u0009', 'o', 'g', 's', }; - @Test - public void testRLPOutputStream() throws Throwable { - Object[] objects = new Object[] { - Strings.decode("0573490923738490"), - new HashSet(), - new Object[] { new byte[] { 0x77, 0x61 } } - }; - TestUtils.assertThrown(NullPointerException.class, () -> {try(RLPOutputStream ros = new RLPOutputStream(null)){}}); - try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) { - ros.write(0xc0); - ros.write(new byte[] { (byte) 0x7f, (byte) 0x20 }); - ros.writeSequence(new byte[] { 0x01 }, new byte[] { 0x02 }); - ros.writeSequence(Collections.singletonList(new byte[] { 0x03 })); - ros.writeList(Arrays.asList(new byte[] { 0x04 }, new byte[] { 0x05 }, new byte[] { 0x06 })); - byte[] bytes = baos.toByteArray(); - assertEquals("81c0827f20010203c3040506", Strings.encode(bytes)); - } - try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) { - Notation notation = Notation.forObjects(objects); - ros.writeSequence(objects); - byte[] bytes = baos.toByteArray(); - assertEquals(notation, Notation.forEncoding(bytes)); - } - try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) { - ros.writeList(Arrays.asList(objects)); - byte[] bytes = baos.toByteArray(); - assertEquals(Notation.forObjects(new Object[] { objects }), Notation.forEncoding(bytes)); - assertEquals("ce880573490923738490c0c3827761", baos.toString()); - assertEquals("ce880573490923738490c0c3827761", ros.toString()); - } - } + @Test + public void testRLPOutputStream() throws Throwable { + Object[] objects = new Object[] { + Strings.decode("0573490923738490"), + new HashSet(), + new Object[] { new byte[] { 0x77, 0x61 } } + }; + TestUtils.assertThrown(NullPointerException.class, () -> {try(RLPOutputStream ros = new RLPOutputStream(null)){}}); + try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) { + ros.write(0xc0); + ros.write(new byte[] { (byte) 0x7f, (byte) 0x20 }); + ros.writeSequence(new byte[] { 0x01 }, new byte[] { 0x02 }); + ros.writeSequence(Collections.singletonList(new byte[] { 0x03 })); + ros.writeList(Arrays.asList(new byte[] { 0x04 }, new byte[] { 0x05 }, new byte[] { 0x06 })); + byte[] bytes = baos.toByteArray(); + assertEquals("81c0827f20010203c3040506", Strings.encode(bytes)); + } + try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) { + Notation notation = Notation.forObjects(objects); + ros.writeSequence(objects); + byte[] bytes = baos.toByteArray(); + assertEquals(notation, Notation.forEncoding(bytes)); + } + try (Baos baos = new Baos(); RLPOutputStream ros = new RLPOutputStream(baos)) { + ros.writeList(Arrays.asList(objects)); + byte[] bytes = baos.toByteArray(); + assertEquals(Notation.forObjects(new Object[] { objects }), Notation.forEncoding(bytes)); + assertEquals("ce880573490923738490c0c3827761", baos.toString()); + assertEquals("ce880573490923738490c0c3827761", ros.toString()); + } + } @Test public void testObjectRLPStream() throws IOException { // write RLP Baos baos = new Baos(); - try (ObjectOutputStream oos = new ObjectOutputStream(new RLPOutputStream(baos))) { - oos.writeUTF("hello"); + try (ObjectOutputStream oos = new ObjectOutputStream(new RLPOutputStream(baos))) { + oos.writeUTF("hello"); // oos.flush(); - oos.writeChar('Z'); -// oos.writeObject(Tuple.of("jinro", new byte[] { (byte) 0xc0 }, new Boolean[] { false, true })); - oos.flush(); - } + oos.writeChar('Z'); +// oos.writeObject(Tuple.of("jinro", new byte[] { (byte) 0xc0 }, new Boolean[] { false, true })); + oos.flush(); + } // decode RLP Iterator iter = RLP_STRICT.sequenceIterator(baos.toByteArray());