use of com.esaulpaugh.headlong.abi.TupleType in project headlong by esaulpaugh.
the class ABIStudentTest method abiDecodeEncode.
@Test
public void abiDecodeEncode() {
final TupleType tt = TupleType.parse("(string,fixed128x9,bytes,bytes,uint16)");
final ByteBuffer studentAbi = ByteBuffer.wrap(Strings.decode(STUDENT_ABI));
// EU Gene perrylink Junior
final ABIStudent mikhail = new ABIStudent(tt.decode(studentAbi));
final ByteBuffer reencoded = tt.encode(mikhail.toTuple());
assertArrayEquals(studentAbi.array(), reencoded.array());
System.out.println(Strings.encode(reencoded));
System.out.println(Strings.encode(tt.encodePacked(mikhail.toTuple())));
System.out.println(mikhail);
}
use of com.esaulpaugh.headlong.abi.TupleType 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"));
}
Aggregations