Skip to content

Commit

Permalink
Reapply "change type of "decimal" to int168 from fixed168x10"
Browse files Browse the repository at this point in the history
This reverts commit 3db9c78.
  • Loading branch information
esaulpaugh committed Jun 10, 2024
1 parent d0cd871 commit ca489a6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/esaulpaugh/headlong/abi/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ private TypeFactory() {}
local.put("ufixed128x18", new BigDecimalType("ufixed128x18", FIXED_BIT_LEN, FIXED_SCALE, true));
local.put("fixed168x10", new BigDecimalType("fixed168x10", DECIMAL_BIT_LEN, DECIMAL_SCALE, false));

local.put("decimal", local.get("fixed168x10"));
local.put("bool", BooleanType.INSTANCE);

local.put("decimal", local.get("int168"));

local.put("int", local.get("int256"));
local.put("uint", local.get("uint256"));
local.put("fixed", local.get("fixed128x18"));
local.put("ufixed", local.get("ufixed128x18"));

local.put("bool", BooleanType.INSTANCE);

final Map<String, ABIType<?>> localLegacy = new HashMap<>(256);
for (Map.Entry<String, ABIType<?>> e : local.entrySet()) {
ABIType<?> value = e.getValue();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/esaulpaugh/headlong/abi/DecodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public void testSingletonReturn() throws Throwable {
);
assertThrown(
IllegalArgumentException.class,
"return type not a singleton: (fixed168x10,uint256)",
"return type not a singleton: (int168,uint256)",
() -> Function.parse("bim()", "(decimal,uint)").decodeSingletonReturn(new byte[0])
);
Function bar = Function.parse("bar()", "(bool)");
Expand Down
15 changes: 6 additions & 9 deletions src/test/java/com/esaulpaugh/headlong/abi/EncodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,19 +636,16 @@ private static void testMinAndMax(UnitType<?> type, String err1Substr, String er

@Test
public void testDecimalMinMax() throws Throwable {
final BigDecimalType decimal = TypeFactory.create("decimal");
assertEquals(decimal, TypeFactory.create("fixed168x10"));
final BigIntegerType decimal = TypeFactory.create("decimal");
assertEquals(decimal, TypeFactory.create("int168"));

final BigDecimal decimalMin = new BigDecimal("-18707220957835557353007165858768422651595.9365500928");
final BigDecimal decimalMax = new BigDecimal("18707220957835557353007165858768422651595.9365500927");

assertThrown(ILLEGAL, "signed val exceeds bit limit: 168 >= 168", () -> decimal.validate(decimalMin.subtract(O_0000000001)));
decimal.validate(decimalMin);
decimal.validate(decimalMax);
assertThrown(ILLEGAL, "signed val exceeds bit limit: 168 >= 168", () -> decimal.validate(decimalMax.add(O_0000000001)));

assertEquals(decimalMin, decimal.minDecimal());
assertEquals(decimalMax, decimal.maxDecimal());
assertThrown(ILLEGAL, "signed val exceeds bit limit: 168 >= 168", () -> decimal.validate(decimalMin.unscaledValue().subtract(BigInteger.ONE)));
decimal.validate(decimalMin.unscaledValue());
decimal.validate(decimalMax.unscaledValue());
assertThrown(ILLEGAL, "signed val exceeds bit limit: 168 >= 168", () -> decimal.validate(decimalMax.unscaledValue().add(BigInteger.ONE)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testNonCanonicalEquals() {
testNonCanonicalEquals("foo(uint256[5][])", "foo(uint[5][])");
testNonCanonicalEquals("foo(uint256[100][100])","foo(uint[100][100])");

testNonCanonicalEquals("foo(bool,(decimal[0][][99]))","foo(bool,(fixed168x10[0][][99]))");
testNonCanonicalEquals("foo(bool,(decimal[0][][99]))","foo(bool,(int168[0][][99]))");
}

private static void testNonCanonicalEquals(String canonical, String nonCanonical) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/esaulpaugh/headlong/abi/TupleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ public void testGetElement() {
TupleType<?> tt = TupleType.parse("(bytes8,decimal)");
ArrayType<ByteType, Byte, byte[]> at = tt.get(0);
assertEquals(8, at.getLength());
BigDecimalType decimal = tt.get(1);
assertEquals("fixed168x10", decimal.getCanonicalType());
BigIntegerType decimal = tt.get(1);
assertEquals("int168", decimal.getCanonicalType());
assertEquals("iii", Single.of("iii").get0());

TupleType<?> outer = TupleType.parse("((address,int256))");
Expand Down

0 comments on commit ca489a6

Please sign in to comment.