use of com.esaulpaugh.headlong.abi.Tuple in project headlong by esaulpaugh.
the class SuperSerialTest method testSuperSerial.
@Test
public void testSuperSerial() throws Throwable {
// java -jar headlong-cli-0.2-SNAPSHOT.jar -e "(uint[],int[],uint32,(int32,uint8,(bool[],int8,int40,int64,int,int,int[]),bool,bool,int256[]),int,int)" "([ ], [ '' ], '80', ['7f', '3b', [ [ ], '', '', '30ffcc0009', '01', '02', [ '70' ] ], '', '01', ['0092030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2020']], '', '05')"
TestUtils.assertThrown(IllegalArgumentException.class, "tuple index 0: signed val exceeds bit limit: 256 >= 256", () -> SuperSerial.deserialize(TupleType.parse("(int256)"), "('0092030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2020')", false));
SuperSerial.deserialize(TupleType.parse("(uint256)"), "('0092030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2020')", false);
TestUtils.assertThrown(IllegalArgumentException.class, "RLPList not allowed for this type: int8", () -> SuperSerial.deserialize(TupleType.of("int8"), "(['90', '80', '77'])", false));
String sig = "(uint[],int[],uint32,(int32,uint8,(bool[],int8,int40,int64,int,int,int[]),bool,bool,int256[]),int,int)";
Function f = new Function(sig);
String vals = "([ ], [ '' ], '80', ['7f', '3b', [ [ ], '', '', '30ffcc0009', '01', '02', [ '70' ] ], '', '01', ['92030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2020']], '', '05')";
Tuple decoded = SuperSerial.deserialize(f.getInputs(), vals, false);
f.getInputs().validate(decoded);
ByteBuffer bb = f.getInputs().encode(decoded);
Tuple dd = f.getInputs().decode(bb);
assertEquals(decoded, dd);
}
use of com.esaulpaugh.headlong.abi.Tuple in project headlong by esaulpaugh.
the class SuperSerialTest method testParseArgs.
@Test
public void testParseArgs() throws Throwable {
String boolArrStr = "['00', '01', '01']";
TupleType tt = TupleType.parse("(bool[])");
Tuple tuple = tt.parseArgument("(\n" + boolArrStr + "\n)");
boolean[] arr0 = tuple.get(0);
assertArrayEquals(new boolean[] { false, true, true }, arr0);
boolean[] arr1 = (boolean[]) tt.get(0).parseArgument(boolArrStr);
assertArrayEquals(arr0, arr1);
IntType int32 = TupleType.parse("(int32)").get(0);
assertEquals(Integer.MIN_VALUE, int32.parseArgument(Integer.toString(Integer.MIN_VALUE)));
assertEquals(Integer.MAX_VALUE, int32.parseArgument(Integer.toString(Integer.MAX_VALUE)));
IntType int8 = TupleType.parse("(int8)").get(0);
TestUtils.assertThrown(IllegalArgumentException.class, "signed val exceeds bit limit: 8 >= 8", () -> int8.parseArgument("-129"));
TestUtils.assertThrown(IllegalArgumentException.class, "signed val exceeds bit limit: 8 >= 8", () -> int8.parseArgument("128"));
BooleanType bool = TupleType.parse("(bool)").get(0);
Object bool2 = TypeFactory.create("bool");
assertEquals(bool, bool2);
TypeFactory.createNonCapturing("bool").encode(true);
assertEquals(true, bool.parseArgument("true"));
assertEquals(true, bool.parseArgument("TRUE"));
assertEquals(true, bool.parseArgument("tRUe"));
assertEquals(false, bool.parseArgument("false"));
assertEquals(false, bool.parseArgument(""));
assertEquals(false, bool.parseArgument("?\t*jjgHJge"));
assertEquals(127, int8.parseArgument("127"));
assertEquals(127, int8.parseArgument("0127"));
assertEquals(127, int8.parseArgument("00127"));
}
use of com.esaulpaugh.headlong.abi.Tuple in project headlong by esaulpaugh.
the class SuperSerial method deserialize.
public static Tuple deserialize(TupleType tupleType, String str, boolean machine) {
Tuple in = deserializeTuple(tupleType, machine ? Strings.decode(str) : RLPEncoder.encodeSequentially(Notation.parse(str)));
tupleType.validate(in);
return in;
}
Aggregations