Package org.ethereum.util

Examples of org.ethereum.util.Value


   *
   * @param o the Node which could be a pair-, multi-item Node or single Value 
   * @return sha3 hash of RLP encoded node if length > 32 otherwise return node itself
   */
  public Object put(Object o) {
    Value value = new Value(o);
    byte[] enc = value.encode();
    if (enc.length >= 32) {
      byte[] sha = HashUtil.sha3(enc);
      this.nodes.put(new ByteArrayWrapper(sha), new Node(value, true));
      this.isDirty = true;
      return sha;
View Full Code Here


      return this.nodes.get(keyObj).getValue();
    }

    // Get the key of the database instead and cache it
    byte[] data = this.db.get(key);
    Value value = Value.fromRlpEncoded(data);
    // Create caching node
    this.nodes.put(keyObj, new Node(value, false));

    return value;
  }
View Full Code Here

public class ValueTest {

  @Test
  public void testCmp() {
    Value val1 = new Value("hello");
    Value val2 = new Value("world");
   
    assertFalse("Expected values not to be equal", val1.cmp(val2));

    Value val3 = new Value("hello");
    Value val4 = new Value("hello");
   
    assertTrue("Expected values to be equal", val3.cmp(val4));
  }
View Full Code Here

    assertTrue("Expected values to be equal", val3.cmp(val4));
  }

  @Test
  public void testTypes() {
    Value str = new Value("str");
    assertEquals(str.asString(), "str");

    Value num = new Value(1);
    assertEquals(num.asInt(), 1);

    Value inter = new Value(new Object[]{1});
    Object[] interExp = new Object[]{1};
    assertTrue(new Value(inter.asObj()).cmp(new Value(interExp)));

    Value byt = new Value(new byte[]{1, 2, 3, 4});
    byte[] bytExp = new byte[]{1, 2, 3, 4};
    assertTrue(Arrays.equals(byt.asBytes(), bytExp));

    Value bigInt = new Value(BigInteger.valueOf(10));
    BigInteger bigExp = BigInteger.valueOf(10);
    assertEquals(bigInt.asBigInt(), bigExp);
  }
View Full Code Here

    @Test
    public void longListRLPBug_1(){

        String testRlp = "f7808080d387206f72726563748a626574656c676575736580d387207870726573738a70726564696361626c658080808080808080808080";

        Value val = Value.fromRlpEncoded(Hex.decode(testRlp));

        assertEquals(testRlp, Hex.toHexString(val.encode()));
    }
View Full Code Here

TOP

Related Classes of org.ethereum.util.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.