Search in sources :

Example 31 with RLPElement

use of org.ethereum.util.RLPElement in project rskj by rsksmart.

the class RLPTest method encodeDecodeLongByteArrayWithOneByteLengthUsingEncode.

@Test
public void encodeDecodeLongByteArrayWithOneByteLengthUsingEncode() {
    byte[] bytes = new byte[56];
    byte[] encoded = RLP.encode(bytes);
    Assert.assertNotNull(encoded);
    Assert.assertEquals(2 + 56, encoded.length);
    Assert.assertEquals((byte) (183 + 1), encoded[0]);
    Assert.assertEquals((byte) 56, encoded[1]);
    RLPElement element = RLP.decode2OneItem(encoded, 0);
    Assert.assertNotNull(element);
    byte[] decoded = element.getRLPData();
    Assert.assertNotNull(decoded);
    Assert.assertArrayEquals(bytes, decoded);
}
Also used : RLPElement(org.ethereum.util.RLPElement) Test(org.junit.Test)

Example 32 with RLPElement

use of org.ethereum.util.RLPElement in project rskj by rsksmart.

the class RLPTest method encodeDecodeLongByteArrayWithTwoBytesLengthUsingEncode.

@Test
public void encodeDecodeLongByteArrayWithTwoBytesLengthUsingEncode() {
    byte[] bytes = new byte[256];
    byte[] encoded = RLP.encode(bytes);
    Assert.assertNotNull(encoded);
    Assert.assertEquals(3 + 256, encoded.length);
    Assert.assertEquals((byte) (183 + 2), encoded[0]);
    Assert.assertEquals((byte) 1, encoded[1]);
    Assert.assertEquals((byte) 0, encoded[2]);
    RLPElement element = RLP.decode2OneItem(encoded, 0);
    Assert.assertNotNull(element);
    byte[] decoded = element.getRLPData();
    Assert.assertNotNull(decoded);
    Assert.assertArrayEquals(bytes, decoded);
}
Also used : RLPElement(org.ethereum.util.RLPElement) Test(org.junit.Test)

Example 33 with RLPElement

use of org.ethereum.util.RLPElement in project rskj by rsksmart.

the class RLPTest method encodeDecodeSingleBytes.

@Test
public void encodeDecodeSingleBytes() {
    for (int k = 0; k < 128; k++) {
        byte[] bytes = new byte[1];
        bytes[0] = (byte) k;
        byte[] encoded = RLP.encodeElement(bytes);
        Assert.assertNotNull(encoded);
        Assert.assertEquals(1, encoded.length);
        RLPElement element = RLP.decode2OneItem(encoded, 0);
        Assert.assertNotNull(element);
        byte[] decoded = element.getRLPData();
        Assert.assertNotNull(decoded);
        Assert.assertArrayEquals(bytes, decoded);
    }
}
Also used : RLPElement(org.ethereum.util.RLPElement) Test(org.junit.Test)

Example 34 with RLPElement

use of org.ethereum.util.RLPElement in project rskj by rsksmart.

the class RLPTest method encodeDecodeLongByteArrayWithThreeBytesLengthBorderCaseUsingEncode.

@Test
public void encodeDecodeLongByteArrayWithThreeBytesLengthBorderCaseUsingEncode() {
    byte[] bytes = new byte[256 * 256 * 256 - 1];
    byte[] encoded = RLP.encode(bytes);
    Assert.assertNotNull(encoded);
    Assert.assertEquals(4 + 256 * 256 * 256 - 1, encoded.length);
    Assert.assertEquals((byte) (183 + 3), encoded[0]);
    Assert.assertEquals((byte) 0xff, encoded[1]);
    Assert.assertEquals((byte) 0xff, encoded[2]);
    Assert.assertEquals((byte) 0xff, encoded[3]);
    RLPElement element = RLP.decode2OneItem(encoded, 0);
    Assert.assertNotNull(element);
    byte[] decoded = element.getRLPData();
    Assert.assertNotNull(decoded);
    Assert.assertArrayEquals(bytes, decoded);
}
Also used : RLPElement(org.ethereum.util.RLPElement) Test(org.junit.Test)

Example 35 with RLPElement

use of org.ethereum.util.RLPElement in project rskj by rsksmart.

the class RLPTest method encodeDecodeShortByteArraysUsingEncode.

@Test
public void encodeDecodeShortByteArraysUsingEncode() {
    for (int k = 2; k < 56; k++) {
        byte[] bytes = new byte[k];
        byte[] encoded = RLP.encode(bytes);
        Assert.assertNotNull(encoded);
        Assert.assertEquals(1 + k, encoded.length);
        Assert.assertEquals((byte) (128 + k), encoded[0]);
        RLPElement element = RLP.decode2OneItem(encoded, 0);
        Assert.assertNotNull(element);
        byte[] decoded = element.getRLPData();
        Assert.assertNotNull(decoded);
        Assert.assertArrayEquals(bytes, decoded);
    }
}
Also used : RLPElement(org.ethereum.util.RLPElement) Test(org.junit.Test)

Aggregations

RLPElement (org.ethereum.util.RLPElement)38 Test (org.junit.Test)29 RLPList (org.ethereum.util.RLPList)19 ArrayList (java.util.ArrayList)4 LogInfo (org.ethereum.vm.LogInfo)3 Coin (co.rsk.core.Coin)2 RskAddress (co.rsk.core.RskAddress)2 Keccak256 (co.rsk.crypto.Keccak256)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Script (co.rsk.bitcoinj.script.Script)1 ScriptChunk (co.rsk.bitcoinj.script.ScriptChunk)1 BridgeConstants (co.rsk.config.BridgeConstants)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 Federation (co.rsk.peg.Federation)1 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)1 BridgeEventLoggerImpl (co.rsk.peg.utils.BridgeEventLoggerImpl)1 RemascTransaction (co.rsk.remasc.RemascTransaction)1 LinkedList (java.util.LinkedList)1 Block (org.ethereum.core.Block)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1