diff --git a/language-support/java/codegen/BUILD.bazel b/language-support/java/codegen/BUILD.bazel index 1c01d8a20e9b..061bc0fa37b4 100644 --- a/language-support/java/codegen/BUILD.bazel +++ b/language-support/java/codegen/BUILD.bazel @@ -315,8 +315,6 @@ java_library( module_prefix_test = "src/it/java/com/daml/ModulePrefixes.java" -contract_keys_test = "src/it/java/com/daml/ContractKeysTest.java" - java_test( name = "integration-tests-module-prefixes", srcs = [module_prefix_test], @@ -330,21 +328,6 @@ java_test( ], ) -java_test( - name = "integration-tests-contract-keys", - srcs = [contract_keys_test], - test_class = "com.daml.ContractKeysTest", - deps = [ - ":integration-tests-model-2.dev", - "//canton:bindings-java", - "@maven//:com_google_protobuf_protobuf_java", - "@maven//:org_junit_jupiter_junit_jupiter_api", - "@maven//:org_junit_jupiter_junit_jupiter_engine", - "@maven//:org_junit_platform_junit_platform_commons", - "@maven//:org_junit_platform_junit_platform_runner", - ], -) - [ [ # @@ -368,7 +351,6 @@ java_test( ], exclude = [ module_prefix_test, - contract_keys_test, ], ), test_class = "com.daml.AllTests", diff --git a/language-support/java/codegen/src/it/daml/Lib_1_6.daml b/language-support/java/codegen/src/it/daml/Lib_1_6.daml deleted file mode 100644 index 8aaee277af7a..000000000000 --- a/language-support/java/codegen/src/it/daml/Lib_1_6.daml +++ /dev/null @@ -1,19 +0,0 @@ --- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. --- SPDX-License-Identifier: Apache-2.0 - - -module Lib_1_6 where - -import Tests.Template1() -import Tests.Template2() -import Tests.RecordTest() -import Tests.OptionalTest() -import Tests.ListTest() -import Tests.VariantTest() - -import Tests.Import() -import Tests.Escape() -import Tests.TextMapTest() -import Tests.ContractKeys() -import Tests.ParametersOrder() -import Tests.UpgradeTest() diff --git a/language-support/java/codegen/src/it/daml/Lib_1_7.daml b/language-support/java/codegen/src/it/daml/Lib_1_7.daml deleted file mode 100644 index 040835382962..000000000000 --- a/language-support/java/codegen/src/it/daml/Lib_1_7.daml +++ /dev/null @@ -1,20 +0,0 @@ --- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. --- SPDX-License-Identifier: Apache-2.0 - - -module Lib_1_7 where - -import Tests.Template1() -import Tests.Template2() -import Tests.RecordTest() -import Tests.OptionalTest() -import Tests.ListTest() -import Tests.VariantTest() -import Tests.NumericTest() - -import Tests.Import() -import Tests.Escape() -import Tests.TextMapTest() -import Tests.ContractKeys() -import Tests.ParametersOrder() -import Tests.UpgradeTest() diff --git a/language-support/java/codegen/src/it/daml/Lib_1_8.daml b/language-support/java/codegen/src/it/daml/Lib_1_8.daml deleted file mode 100644 index 7cbde34ec2b6..000000000000 --- a/language-support/java/codegen/src/it/daml/Lib_1_8.daml +++ /dev/null @@ -1,20 +0,0 @@ --- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. --- SPDX-License-Identifier: Apache-2.0 - - -module Lib_1_8 where - -import Tests.Template1() -import Tests.Template2() -import Tests.RecordTest() -import Tests.OptionalTest() -import Tests.ListTest() -import Tests.VariantTest() -import Tests.NumericTest() - -import Tests.Import() -import Tests.Escape() -import Tests.TextMapTest() -import Tests.ContractKeys() -import Tests.ParametersOrder() -import Tests.UpgradeTest() diff --git a/language-support/java/codegen/src/it/daml/Lib_1_dev.daml b/language-support/java/codegen/src/it/daml/Lib_1_dev.daml deleted file mode 100644 index a86fc25cfe0d..000000000000 --- a/language-support/java/codegen/src/it/daml/Lib_1_dev.daml +++ /dev/null @@ -1,21 +0,0 @@ --- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. --- SPDX-License-Identifier: Apache-2.0 - - -module Lib_1_dev where - -import Tests.Template1() -import Tests.Template2() -import Tests.RecordTest() -import Tests.OptionalTest() -import Tests.ListTest() -import Tests.VariantTest() -import Tests.NumericTest() - -import Tests.Import() -import Tests.Escape() -import Tests.TextMapTest() -import Tests.GenMapTest() -import Tests.ContractKeys() -import Tests.ParametersOrder() -import Tests.UpgradeTest() diff --git a/language-support/java/codegen/src/it/daml/Lib_1_12.daml b/language-support/java/codegen/src/it/daml/Lib_2_1.daml similarity index 90% rename from language-support/java/codegen/src/it/daml/Lib_1_12.daml rename to language-support/java/codegen/src/it/daml/Lib_2_1.daml index f7b06e445853..ed4e8afdc583 100644 --- a/language-support/java/codegen/src/it/daml/Lib_1_12.daml +++ b/language-support/java/codegen/src/it/daml/Lib_2_1.daml @@ -2,7 +2,7 @@ -- SPDX-License-Identifier: Apache-2.0 -module Lib_1_12 where +module Lib_2_1 where import Tests.Template1() import Tests.Template2() @@ -16,6 +16,5 @@ import Tests.Import() import Tests.Escape() import Tests.TextMapTest() import Tests.GenMapTest() -import Tests.ContractKeys() import Tests.ParametersOrder() import Tests.UpgradeTest() diff --git a/language-support/java/codegen/src/it/daml/Lib_1_11.daml b/language-support/java/codegen/src/it/daml/Lib_2_dev.daml similarity index 95% rename from language-support/java/codegen/src/it/daml/Lib_1_11.daml rename to language-support/java/codegen/src/it/daml/Lib_2_dev.daml index 85b38c9e6746..4d423709696b 100644 --- a/language-support/java/codegen/src/it/daml/Lib_1_11.daml +++ b/language-support/java/codegen/src/it/daml/Lib_2_dev.daml @@ -2,7 +2,7 @@ -- SPDX-License-Identifier: Apache-2.0 -module Lib_1_11 where +module Lib_2_dev where import Tests.Template1() import Tests.Template2() diff --git a/language-support/java/codegen/src/it/java-1.11/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.11/com/daml/AllTests.java deleted file mode 100644 index f8c8985dd898..000000000000 --- a/language-support/java/codegen/src/it/java-1.11/com/daml/AllTests.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, - GenMapTest.class, - NumericTest.class, -}) -public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.11/com/daml/GenMapTest.java b/language-support/java/codegen/src/it/java-1.11/com/daml/GenMapTest.java deleted file mode 100644 index fcc5c1cfd3f5..000000000000 --- a/language-support/java/codegen/src/it/java-1.11/com/daml/GenMapTest.java +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.DamlRecord; -import com.daml.ledger.javaapi.data.Int64; -import com.daml.ledger.javaapi.data.Text; -import com.daml.ledger.javaapi.data.Variant; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.genmaptest.MapMapRecord; -import tests.genmaptest.MapRecord; -import tests.genmaptest.TemplateWithMap; -import tests.genmaptest.mapvariant.ParameterizedVariant; -import tests.genmaptest.mapvariant.RecordVariant; -import tests.genmaptest.mapvariant.TextVariant; - -@RunWith(JUnitPlatform.class) -public class GenMapTest { - - @Test - public void mapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildNone, buildText("None")), - buildEntryMap(buildSome(buildInt(1)), buildText("Some(1)")), - buildEntryMap(buildSome(buildInt(42)), buildText("Some(42)"))))) - .getRecord(); - - Map, String> javaMap = new HashMap<>(); - javaMap.put(Optional.empty(), "None"); - javaMap.put(Optional.of(1L), "Some(1)"); - javaMap.put(Optional.of(42L), "Some(42)"); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapRecord fromValue = MapRecord.fromValue(dataRecord); - MapRecord fromConstructor = new MapRecord(javaMap); - MapRecord fromRoundTrip = MapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private Map reverseMap(Map m) { - Map reversedMap = new HashMap<>(); - for (Map.Entry entry : m.entrySet()) reversedMap.put(entry.getValue(), entry.getKey()); - return reversedMap; - } - - @Test - public void mapMapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildMap(), buildMap()), - buildEntryMap( - buildMap(buildEntryMap(buildInt(1), buildText("1L"))), - buildMap(buildEntryMap(buildText("1L"), buildInt(1)))), - buildEntryMap( - buildMap( - buildEntryMap(buildInt(1), buildText("1L")), - buildEntryMap(buildInt(42), buildText("42L"))), - buildMap( - buildEntryMap(buildText("1L"), buildInt(1)), - buildEntryMap(buildText("42L"), buildInt(42))))))) - .getRecord(); - - Map inner1Map = new HashMap<>(); - Map inner2Map = new HashMap<>(); - inner2Map.put(1L, "1L"); - Map inner3Map = new HashMap<>(); - inner3Map.put(1L, "1L"); - inner3Map.put(42L, "42L"); - - Map, Map> javaMap = new HashMap<>(); - javaMap.put(inner1Map, reverseMap(inner1Map)); - javaMap.put(inner2Map, reverseMap(inner2Map)); - javaMap.put(inner3Map, reverseMap(inner3Map)); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapMapRecord fromValue = MapMapRecord.fromValue(dataRecord); - MapMapRecord fromConstructor = new MapMapRecord(javaMap); - MapMapRecord fromRoundTrip = MapMapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void textMapVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant("TextVariant", buildMap(buildEntryMap(buildText("key"), buildText("value")))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - TextVariant fromValue = TextVariant.fromValue(dataVariant); - TextVariant fromConstructor = new TextVariant<>(Collections.singletonMap("key", "value")); - TextVariant fromRoundTrip = TextVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapRecordVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "RecordVariant", - buildRecord( - buildRecordField("x", buildMap(buildEntryMap(buildText("key"), buildInt(42)))))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - RecordVariant fromValue = RecordVariant.fromValue(dataVariant); - RecordVariant fromConstructor = new RecordVariant<>(Collections.singletonMap("key", 42L)); - RecordVariant fromRoundTrip = RecordVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapParameterizedVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "ParameterizedVariant", buildMap(buildEntryMap(buildText("key"), buildInt(42)))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - ParameterizedVariant fromValue = - ParameterizedVariant.fromValue( - dataVariant, x -> x.asText().get().getValue(), x -> x.asInt64().get().getValue()); - ParameterizedVariant fromConstructor = - new ParameterizedVariant<>(Collections.singletonMap("key", 42L)); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - assertEquals(fromValue.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - } - - @Test - public void mapTemplateRoundTripTest() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField("owner", buildParty("party1")), - buildRecordField( - "valueMap", buildMap(buildEntryMap(buildInt(42), buildText("42"))))) - .getRecord(); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - TemplateWithMap fromValue = TemplateWithMap.fromValue(dataRecord); - TemplateWithMap fromConstructor = - new TemplateWithMap("party1", Collections.singletonMap(42L, "42")); - - TemplateWithMap fromRoundTrip = TemplateWithMap.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromValue.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private static ValueOuterClass.Value buildInt(int i) { - return ValueOuterClass.Value.newBuilder().setInt64(i).build(); - } - - private static ValueOuterClass.Value buildText(String text) { - return ValueOuterClass.Value.newBuilder().setText(text).build(); - } - - private static ValueOuterClass.Value buildParty(String party) { - return ValueOuterClass.Value.newBuilder().setParty(party).build(); - } - - private static ValueOuterClass.Value buildNone = - ValueOuterClass.Value.newBuilder().setOptional(ValueOuterClass.Optional.newBuilder()).build(); - - private static ValueOuterClass.Value buildSome(ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setOptional(ValueOuterClass.Optional.newBuilder().setValue(value)) - .build(); - } - - private static ValueOuterClass.Value buildMap(ValueOuterClass.GenMap.Entry... entries) { - ValueOuterClass.GenMap.Builder builder = ValueOuterClass.GenMap.newBuilder(); - for (ValueOuterClass.GenMap.Entry entry : entries) builder.addEntries(entry); - return ValueOuterClass.Value.newBuilder().setGenMap(builder).build(); - } - - private static ValueOuterClass.GenMap.Entry buildEntryMap( - ValueOuterClass.Value key, ValueOuterClass.Value value) { - return ValueOuterClass.GenMap.Entry.newBuilder().setKey(key).setValue(value).build(); - } - - private static ValueOuterClass.RecordField buildRecordField( - String field, ValueOuterClass.Value value) { - return ValueOuterClass.RecordField.newBuilder().setLabel(field).setValue(value).build(); - } - - private static ValueOuterClass.Value buildRecord(ValueOuterClass.RecordField... fields) { - ValueOuterClass.Record.Builder builder = ValueOuterClass.Record.newBuilder(); - for (ValueOuterClass.RecordField field : fields) builder.addFields(field); - return ValueOuterClass.Value.newBuilder().setRecord(builder).build(); - } - - private static ValueOuterClass.Value buildVariant( - String constructor, ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setVariant( - ValueOuterClass.Variant.newBuilder().setConstructor(constructor).setValue(value)) - .build(); - } -} diff --git a/language-support/java/codegen/src/it/java-1.11/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-1.11/com/daml/NumericTest.java deleted file mode 100644 index c600503251ed..000000000000 --- a/language-support/java/codegen/src/it/java-1.11/com/daml/NumericTest.java +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.numerictest.*; -import tests.numerictest.nestednumericbox.*; - -@RunWith(JUnitPlatform.class) -public class NumericTest { - - void checkRecord(NumericBox myRecord) { - assertEquals(myRecord.decimal, decimalValue()); - assertEquals(myRecord.numeric0, numeric0Value()); - assertEquals(myRecord.numeric37, numeric37Value()); - NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; - assertEquals(myNestedRecord.decimal, decimalValue().negate()); - assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); - assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); - assertTrue(myNestedRecord.nestedBox instanceof NoMore); - } - - @Test - void deserializableFromRecord() { - ArrayList fieldsList_ = new ArrayList<>(10); - fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); - fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); - DamlRecord nestedRecord = new DamlRecord(fieldsList_); - ArrayList fieldsList = new ArrayList<>(10); - fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); - fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); - fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); - fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); - Value value = new DamlRecord(fieldsList); - NumericBox record = NumericBox.fromValue(value); - checkRecord(record); - assertTrue( - "to value uses original Daml-LF names for fields", - record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); - } - - @Test - void objectMethodsWork() { - - NumericBox record1 = numericBox(); - NumericBox record2 = numericBox(); - - assertEquals(record1, record2); - assertEquals(record1.hashCode(), record2.hashCode()); - } - - ValueOuterClass.Record.Builder recordBuilder() { - return ValueOuterClass.Record.newBuilder(); - } - - ValueOuterClass.RecordField.Builder recordFieldBuilder() { - return ValueOuterClass.RecordField.newBuilder(); - } - - ValueOuterClass.Value.Builder valueBuilder() { - return ValueOuterClass.Value.newBuilder(); - } - - ValueOuterClass.Variant.Builder variantBuilder() { - return ValueOuterClass.Variant.newBuilder(); - } - - com.google.protobuf.Empty.Builder emptyBuilder() { - return com.google.protobuf.Empty.newBuilder(); - } - - @Test - void outerRecordRoundtrip() { - ValueOuterClass.Value protoValue = - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue(valueBuilder().setNumeric("10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric("99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric("9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor("Nested") - .setValue( - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue( - valueBuilder() - .setNumeric( - "-10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric( - "-99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric( - "-9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor( - "NoMore") - .setValue( - valueBuilder() - .setUnit( - emptyBuilder()))))))))))) - .build(); - - Value value = Value.fromProto(protoValue); - NumericBox fromValue = NumericBox.fromValue(value); - NumericBox fromConstructor = numericBox(); - NumericBox fromRoundTrip = - NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), value); - assertEquals(fromConstructor.toValue().toProto(), protoValue); - assertEquals(fromRoundTrip, fromConstructor); - } - - BigDecimal maxValue(int s) { - return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); - } - - java.math.BigDecimal decimalValue() { - return BigDecimal.TEN.setScale(10); - } - - java.math.BigDecimal numeric0Value() { - return maxValue(0); - } - - java.math.BigDecimal numeric37Value() { - return maxValue(37); - } - - NumericBox numericBox() { - return new NumericBox( - decimalValue(), - numeric0Value(), - numeric37Value(), - new Nested( - new NumericBox( - decimalValue().negate(), - numeric0Value().negate(), - numeric37Value().negate(), - new NoMore(Unit.getInstance())))); - } -} diff --git a/language-support/java/codegen/src/it/java-1.12/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.12/com/daml/AllTests.java deleted file mode 100644 index f8c8985dd898..000000000000 --- a/language-support/java/codegen/src/it/java-1.12/com/daml/AllTests.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, - GenMapTest.class, - NumericTest.class, -}) -public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.12/com/daml/GenMapTest.java b/language-support/java/codegen/src/it/java-1.12/com/daml/GenMapTest.java deleted file mode 100644 index fcc5c1cfd3f5..000000000000 --- a/language-support/java/codegen/src/it/java-1.12/com/daml/GenMapTest.java +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.DamlRecord; -import com.daml.ledger.javaapi.data.Int64; -import com.daml.ledger.javaapi.data.Text; -import com.daml.ledger.javaapi.data.Variant; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.genmaptest.MapMapRecord; -import tests.genmaptest.MapRecord; -import tests.genmaptest.TemplateWithMap; -import tests.genmaptest.mapvariant.ParameterizedVariant; -import tests.genmaptest.mapvariant.RecordVariant; -import tests.genmaptest.mapvariant.TextVariant; - -@RunWith(JUnitPlatform.class) -public class GenMapTest { - - @Test - public void mapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildNone, buildText("None")), - buildEntryMap(buildSome(buildInt(1)), buildText("Some(1)")), - buildEntryMap(buildSome(buildInt(42)), buildText("Some(42)"))))) - .getRecord(); - - Map, String> javaMap = new HashMap<>(); - javaMap.put(Optional.empty(), "None"); - javaMap.put(Optional.of(1L), "Some(1)"); - javaMap.put(Optional.of(42L), "Some(42)"); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapRecord fromValue = MapRecord.fromValue(dataRecord); - MapRecord fromConstructor = new MapRecord(javaMap); - MapRecord fromRoundTrip = MapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private Map reverseMap(Map m) { - Map reversedMap = new HashMap<>(); - for (Map.Entry entry : m.entrySet()) reversedMap.put(entry.getValue(), entry.getKey()); - return reversedMap; - } - - @Test - public void mapMapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildMap(), buildMap()), - buildEntryMap( - buildMap(buildEntryMap(buildInt(1), buildText("1L"))), - buildMap(buildEntryMap(buildText("1L"), buildInt(1)))), - buildEntryMap( - buildMap( - buildEntryMap(buildInt(1), buildText("1L")), - buildEntryMap(buildInt(42), buildText("42L"))), - buildMap( - buildEntryMap(buildText("1L"), buildInt(1)), - buildEntryMap(buildText("42L"), buildInt(42))))))) - .getRecord(); - - Map inner1Map = new HashMap<>(); - Map inner2Map = new HashMap<>(); - inner2Map.put(1L, "1L"); - Map inner3Map = new HashMap<>(); - inner3Map.put(1L, "1L"); - inner3Map.put(42L, "42L"); - - Map, Map> javaMap = new HashMap<>(); - javaMap.put(inner1Map, reverseMap(inner1Map)); - javaMap.put(inner2Map, reverseMap(inner2Map)); - javaMap.put(inner3Map, reverseMap(inner3Map)); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapMapRecord fromValue = MapMapRecord.fromValue(dataRecord); - MapMapRecord fromConstructor = new MapMapRecord(javaMap); - MapMapRecord fromRoundTrip = MapMapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void textMapVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant("TextVariant", buildMap(buildEntryMap(buildText("key"), buildText("value")))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - TextVariant fromValue = TextVariant.fromValue(dataVariant); - TextVariant fromConstructor = new TextVariant<>(Collections.singletonMap("key", "value")); - TextVariant fromRoundTrip = TextVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapRecordVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "RecordVariant", - buildRecord( - buildRecordField("x", buildMap(buildEntryMap(buildText("key"), buildInt(42)))))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - RecordVariant fromValue = RecordVariant.fromValue(dataVariant); - RecordVariant fromConstructor = new RecordVariant<>(Collections.singletonMap("key", 42L)); - RecordVariant fromRoundTrip = RecordVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapParameterizedVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "ParameterizedVariant", buildMap(buildEntryMap(buildText("key"), buildInt(42)))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - ParameterizedVariant fromValue = - ParameterizedVariant.fromValue( - dataVariant, x -> x.asText().get().getValue(), x -> x.asInt64().get().getValue()); - ParameterizedVariant fromConstructor = - new ParameterizedVariant<>(Collections.singletonMap("key", 42L)); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - assertEquals(fromValue.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - } - - @Test - public void mapTemplateRoundTripTest() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField("owner", buildParty("party1")), - buildRecordField( - "valueMap", buildMap(buildEntryMap(buildInt(42), buildText("42"))))) - .getRecord(); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - TemplateWithMap fromValue = TemplateWithMap.fromValue(dataRecord); - TemplateWithMap fromConstructor = - new TemplateWithMap("party1", Collections.singletonMap(42L, "42")); - - TemplateWithMap fromRoundTrip = TemplateWithMap.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromValue.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private static ValueOuterClass.Value buildInt(int i) { - return ValueOuterClass.Value.newBuilder().setInt64(i).build(); - } - - private static ValueOuterClass.Value buildText(String text) { - return ValueOuterClass.Value.newBuilder().setText(text).build(); - } - - private static ValueOuterClass.Value buildParty(String party) { - return ValueOuterClass.Value.newBuilder().setParty(party).build(); - } - - private static ValueOuterClass.Value buildNone = - ValueOuterClass.Value.newBuilder().setOptional(ValueOuterClass.Optional.newBuilder()).build(); - - private static ValueOuterClass.Value buildSome(ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setOptional(ValueOuterClass.Optional.newBuilder().setValue(value)) - .build(); - } - - private static ValueOuterClass.Value buildMap(ValueOuterClass.GenMap.Entry... entries) { - ValueOuterClass.GenMap.Builder builder = ValueOuterClass.GenMap.newBuilder(); - for (ValueOuterClass.GenMap.Entry entry : entries) builder.addEntries(entry); - return ValueOuterClass.Value.newBuilder().setGenMap(builder).build(); - } - - private static ValueOuterClass.GenMap.Entry buildEntryMap( - ValueOuterClass.Value key, ValueOuterClass.Value value) { - return ValueOuterClass.GenMap.Entry.newBuilder().setKey(key).setValue(value).build(); - } - - private static ValueOuterClass.RecordField buildRecordField( - String field, ValueOuterClass.Value value) { - return ValueOuterClass.RecordField.newBuilder().setLabel(field).setValue(value).build(); - } - - private static ValueOuterClass.Value buildRecord(ValueOuterClass.RecordField... fields) { - ValueOuterClass.Record.Builder builder = ValueOuterClass.Record.newBuilder(); - for (ValueOuterClass.RecordField field : fields) builder.addFields(field); - return ValueOuterClass.Value.newBuilder().setRecord(builder).build(); - } - - private static ValueOuterClass.Value buildVariant( - String constructor, ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setVariant( - ValueOuterClass.Variant.newBuilder().setConstructor(constructor).setValue(value)) - .build(); - } -} diff --git a/language-support/java/codegen/src/it/java-1.14/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.14/com/daml/AllTests.java deleted file mode 100644 index f8c8985dd898..000000000000 --- a/language-support/java/codegen/src/it/java-1.14/com/daml/AllTests.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, - GenMapTest.class, - NumericTest.class, -}) -public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.14/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-1.14/com/daml/NumericTest.java deleted file mode 100644 index 99398c06b94b..000000000000 --- a/language-support/java/codegen/src/it/java-1.14/com/daml/NumericTest.java +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.numerictest.NumericBox; -import tests.numerictest.nestednumericbox.Nested; -import tests.numerictest.nestednumericbox.NoMore; - -@RunWith(JUnitPlatform.class) -public class NumericTest { - - void checkRecord(NumericBox myRecord) { - assertEquals(myRecord.decimal, decimalValue()); - assertEquals(myRecord.numeric0, numeric0Value()); - assertEquals(myRecord.numeric37, numeric37Value()); - NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; - assertEquals(myNestedRecord.decimal, decimalValue().negate()); - assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); - assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); - assertTrue(myNestedRecord.nestedBox instanceof NoMore); - } - - @Test - void deserializableFromRecord() { - ArrayList fieldsList_ = new ArrayList<>(10); - fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); - fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); - DamlRecord nestedRecord = new DamlRecord(fieldsList_); - ArrayList fieldsList = new ArrayList<>(10); - fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); - fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); - fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); - fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); - Value value = new DamlRecord(fieldsList); - NumericBox record = NumericBox.fromValue(value); - checkRecord(record); - assertTrue( - "to value uses original Daml-LF names for fields", - record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); - } - - @Test - void objectMethodsWork() { - - NumericBox record1 = numericBox(); - NumericBox record2 = numericBox(); - - assertEquals(record1, record2); - assertEquals(record1.hashCode(), record2.hashCode()); - } - - ValueOuterClass.Record.Builder recordBuilder() { - return ValueOuterClass.Record.newBuilder(); - } - - ValueOuterClass.RecordField.Builder recordFieldBuilder() { - return ValueOuterClass.RecordField.newBuilder(); - } - - ValueOuterClass.Value.Builder valueBuilder() { - return ValueOuterClass.Value.newBuilder(); - } - - ValueOuterClass.Variant.Builder variantBuilder() { - return ValueOuterClass.Variant.newBuilder(); - } - - com.google.protobuf.Empty.Builder emptyBuilder() { - return com.google.protobuf.Empty.newBuilder(); - } - - @Test - void outerRecordRoundtrip() { - ValueOuterClass.Value protoValue = - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue(valueBuilder().setNumeric("10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric("99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric("9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor("Nested") - .setValue( - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue( - valueBuilder() - .setNumeric( - "-10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric( - "-99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric( - "-9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor( - "NoMore") - .setValue( - valueBuilder() - .setUnit( - emptyBuilder()))))))))))) - .build(); - - Value value = Value.fromProto(protoValue); - NumericBox fromValue = NumericBox.fromValue(value); - NumericBox fromConstructor = numericBox(); - NumericBox fromRoundTrip = - NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), value); - assertEquals(fromConstructor.toValue().toProto(), protoValue); - assertEquals(fromRoundTrip, fromConstructor); - } - - BigDecimal maxValue(int s) { - return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); - } - - java.math.BigDecimal decimalValue() { - return BigDecimal.TEN.setScale(10); - } - - java.math.BigDecimal numeric0Value() { - return maxValue(0); - } - - java.math.BigDecimal numeric37Value() { - return maxValue(37); - } - - NumericBox numericBox() { - return new NumericBox( - decimalValue(), - numeric0Value(), - numeric37Value(), - new Nested( - new NumericBox( - decimalValue().negate(), - numeric0Value().negate(), - numeric37Value().negate(), - new NoMore(Unit.getInstance())))); - } -} diff --git a/language-support/java/codegen/src/it/java-1.15/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.15/com/daml/AllTests.java deleted file mode 100644 index f8c8985dd898..000000000000 --- a/language-support/java/codegen/src/it/java-1.15/com/daml/AllTests.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, - GenMapTest.class, - NumericTest.class, -}) -public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.15/com/daml/GenMapTest.java b/language-support/java/codegen/src/it/java-1.15/com/daml/GenMapTest.java deleted file mode 100644 index 6e4037a7f2c5..000000000000 --- a/language-support/java/codegen/src/it/java-1.15/com/daml/GenMapTest.java +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.DamlRecord; -import com.daml.ledger.javaapi.data.Int64; -import com.daml.ledger.javaapi.data.Text; -import com.daml.ledger.javaapi.data.Variant; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.genmaptest.MapMapRecord; -import tests.genmaptest.MapRecord; -import tests.genmaptest.TemplateWithMap; -import tests.genmaptest.mapvariant.ParameterizedVariant; -import tests.genmaptest.mapvariant.RecordVariant; -import tests.genmaptest.mapvariant.TextVariant; - -@RunWith(JUnitPlatform.class) -public class GenMapTest { - - @Test - public void mapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildNone, buildText("None")), - buildEntryMap(buildSome(buildInt(1)), buildText("Some(1)")), - buildEntryMap(buildSome(buildInt(42)), buildText("Some(42)"))))) - .getRecord(); - - Map, String> javaMap = new HashMap<>(); - javaMap.put(Optional.empty(), "None"); - javaMap.put(Optional.of(1L), "Some(1)"); - javaMap.put(Optional.of(42L), "Some(42)"); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapRecord fromValue = MapRecord.fromValue(dataRecord); - MapRecord fromConstructor = new MapRecord(javaMap); - MapRecord fromRoundTrip = MapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private Map reverseMap(Map m) { - Map reversedMap = new HashMap<>(); - for (Map.Entry entry : m.entrySet()) reversedMap.put(entry.getValue(), entry.getKey()); - return reversedMap; - } - - @Test - public void mapMapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildMap(), buildMap()), - buildEntryMap( - buildMap(buildEntryMap(buildInt(1), buildText("1L"))), - buildMap(buildEntryMap(buildText("1L"), buildInt(1)))), - buildEntryMap( - buildMap( - buildEntryMap(buildInt(1), buildText("1L")), - buildEntryMap(buildInt(42), buildText("42L"))), - buildMap( - buildEntryMap(buildText("1L"), buildInt(1)), - buildEntryMap(buildText("42L"), buildInt(42))))))) - .getRecord(); - - Map inner1Map = new HashMap<>(); - Map inner2Map = new HashMap<>(); - inner2Map.put(1L, "1L"); - Map inner3Map = new HashMap<>(); - inner3Map.put(1L, "1L"); - inner3Map.put(42L, "42L"); - - Map, Map> javaMap = new HashMap<>(); - javaMap.put(inner1Map, reverseMap(inner1Map)); - javaMap.put(inner2Map, reverseMap(inner2Map)); - javaMap.put(inner3Map, reverseMap(inner3Map)); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapMapRecord fromValue = MapMapRecord.fromValue(dataRecord); - MapMapRecord fromConstructor = new MapMapRecord(javaMap); - MapMapRecord fromRoundTrip = MapMapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void textMapVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant("TextVariant", buildMap(buildEntryMap(buildText("key"), buildText("value")))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - TextVariant fromValue = TextVariant.fromValue(dataVariant); - TextVariant fromConstructor = new TextVariant<>(Collections.singletonMap("key", "value")); - TextVariant fromRoundTrip = TextVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapRecordVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "RecordVariant", - buildRecord( - buildRecordField("x", buildMap(buildEntryMap(buildText("key"), buildInt(42)))))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - RecordVariant fromValue = RecordVariant.fromValue(dataVariant); - RecordVariant fromConstructor = new RecordVariant<>(Collections.singletonMap("key", 42L)); - RecordVariant fromRoundTrip = RecordVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapParameterizedVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "ParameterizedVariant", buildMap(buildEntryMap(buildText("key"), buildInt(42)))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - ParameterizedVariant fromValue = - ParameterizedVariant.fromValue( - dataVariant, x -> x.asText().get().getValue(), x -> x.asInt64().get().getValue()); - ParameterizedVariant fromConstructor = - new ParameterizedVariant<>(Collections.singletonMap("key", 42L)); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - assertEquals(fromValue.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - } - - @Test - public void mapTemplateRoundTripTest() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField("owner", buildParty("party1")), - buildRecordField( - "valueMap", buildMap(buildEntryMap(buildInt(42), buildText("42"))))) - .getRecord(); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - TemplateWithMap fromValue = TemplateWithMap.fromValue(dataRecord); - TemplateWithMap fromConstructor = - new TemplateWithMap("party1", Collections.singletonMap(42L, "42")); - - TemplateWithMap fromRoundTrip = TemplateWithMap.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromValue.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private static ValueOuterClass.Value buildInt(int i) { - return ValueOuterClass.Value.newBuilder().setInt64(i).build(); - } - - private static ValueOuterClass.Value buildText(String text) { - return ValueOuterClass.Value.newBuilder().setText(text).build(); - } - - private static ValueOuterClass.Value buildParty(String party) { - return ValueOuterClass.Value.newBuilder().setParty(party).build(); - } - - private static final ValueOuterClass.Value buildNone = - ValueOuterClass.Value.newBuilder().setOptional(ValueOuterClass.Optional.newBuilder()).build(); - - private static ValueOuterClass.Value buildSome(ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setOptional(ValueOuterClass.Optional.newBuilder().setValue(value)) - .build(); - } - - private static ValueOuterClass.Value buildMap(ValueOuterClass.GenMap.Entry... entries) { - ValueOuterClass.GenMap.Builder builder = ValueOuterClass.GenMap.newBuilder(); - for (ValueOuterClass.GenMap.Entry entry : entries) builder.addEntries(entry); - return ValueOuterClass.Value.newBuilder().setGenMap(builder).build(); - } - - private static ValueOuterClass.GenMap.Entry buildEntryMap( - ValueOuterClass.Value key, ValueOuterClass.Value value) { - return ValueOuterClass.GenMap.Entry.newBuilder().setKey(key).setValue(value).build(); - } - - private static ValueOuterClass.RecordField buildRecordField( - String field, ValueOuterClass.Value value) { - return ValueOuterClass.RecordField.newBuilder().setLabel(field).setValue(value).build(); - } - - private static ValueOuterClass.Value buildRecord(ValueOuterClass.RecordField... fields) { - ValueOuterClass.Record.Builder builder = ValueOuterClass.Record.newBuilder(); - for (ValueOuterClass.RecordField field : fields) builder.addFields(field); - return ValueOuterClass.Value.newBuilder().setRecord(builder).build(); - } - - private static ValueOuterClass.Value buildVariant( - String constructor, ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setVariant( - ValueOuterClass.Variant.newBuilder().setConstructor(constructor).setValue(value)) - .build(); - } -} diff --git a/language-support/java/codegen/src/it/java-1.15/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-1.15/com/daml/NumericTest.java deleted file mode 100644 index 99398c06b94b..000000000000 --- a/language-support/java/codegen/src/it/java-1.15/com/daml/NumericTest.java +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.numerictest.NumericBox; -import tests.numerictest.nestednumericbox.Nested; -import tests.numerictest.nestednumericbox.NoMore; - -@RunWith(JUnitPlatform.class) -public class NumericTest { - - void checkRecord(NumericBox myRecord) { - assertEquals(myRecord.decimal, decimalValue()); - assertEquals(myRecord.numeric0, numeric0Value()); - assertEquals(myRecord.numeric37, numeric37Value()); - NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; - assertEquals(myNestedRecord.decimal, decimalValue().negate()); - assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); - assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); - assertTrue(myNestedRecord.nestedBox instanceof NoMore); - } - - @Test - void deserializableFromRecord() { - ArrayList fieldsList_ = new ArrayList<>(10); - fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); - fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); - DamlRecord nestedRecord = new DamlRecord(fieldsList_); - ArrayList fieldsList = new ArrayList<>(10); - fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); - fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); - fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); - fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); - Value value = new DamlRecord(fieldsList); - NumericBox record = NumericBox.fromValue(value); - checkRecord(record); - assertTrue( - "to value uses original Daml-LF names for fields", - record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); - } - - @Test - void objectMethodsWork() { - - NumericBox record1 = numericBox(); - NumericBox record2 = numericBox(); - - assertEquals(record1, record2); - assertEquals(record1.hashCode(), record2.hashCode()); - } - - ValueOuterClass.Record.Builder recordBuilder() { - return ValueOuterClass.Record.newBuilder(); - } - - ValueOuterClass.RecordField.Builder recordFieldBuilder() { - return ValueOuterClass.RecordField.newBuilder(); - } - - ValueOuterClass.Value.Builder valueBuilder() { - return ValueOuterClass.Value.newBuilder(); - } - - ValueOuterClass.Variant.Builder variantBuilder() { - return ValueOuterClass.Variant.newBuilder(); - } - - com.google.protobuf.Empty.Builder emptyBuilder() { - return com.google.protobuf.Empty.newBuilder(); - } - - @Test - void outerRecordRoundtrip() { - ValueOuterClass.Value protoValue = - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue(valueBuilder().setNumeric("10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric("99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric("9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor("Nested") - .setValue( - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue( - valueBuilder() - .setNumeric( - "-10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric( - "-99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric( - "-9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor( - "NoMore") - .setValue( - valueBuilder() - .setUnit( - emptyBuilder()))))))))))) - .build(); - - Value value = Value.fromProto(protoValue); - NumericBox fromValue = NumericBox.fromValue(value); - NumericBox fromConstructor = numericBox(); - NumericBox fromRoundTrip = - NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), value); - assertEquals(fromConstructor.toValue().toProto(), protoValue); - assertEquals(fromRoundTrip, fromConstructor); - } - - BigDecimal maxValue(int s) { - return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); - } - - java.math.BigDecimal decimalValue() { - return BigDecimal.TEN.setScale(10); - } - - java.math.BigDecimal numeric0Value() { - return maxValue(0); - } - - java.math.BigDecimal numeric37Value() { - return maxValue(37); - } - - NumericBox numericBox() { - return new NumericBox( - decimalValue(), - numeric0Value(), - numeric37Value(), - new Nested( - new NumericBox( - decimalValue().negate(), - numeric0Value().negate(), - numeric37Value().negate(), - new NoMore(Unit.getInstance())))); - } -} diff --git a/language-support/java/codegen/src/it/java-1.6/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.6/com/daml/AllTests.java deleted file mode 100644 index f364e09154a7..000000000000 --- a/language-support/java/codegen/src/it/java-1.6/com/daml/AllTests.java +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, -}) -public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.7/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.7/com/daml/AllTests.java deleted file mode 100644 index 45a38dc60734..000000000000 --- a/language-support/java/codegen/src/it/java-1.7/com/daml/AllTests.java +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, - NumericTest.class, -}) -public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.7/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-1.7/com/daml/NumericTest.java deleted file mode 100644 index d5356c397057..000000000000 --- a/language-support/java/codegen/src/it/java-1.7/com/daml/NumericTest.java +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.numerictest.*; -import tests.numerictest.nestednumericbox.*; - -@RunWith(JUnitPlatform.class) -public class NumericTest { - void checkRecord(NumericBox myRecord) { - assertEquals(myRecord.decimal, decimalValue()); - assertEquals(myRecord.numeric0, numeric0Value()); - assertEquals(myRecord.numeric37, numeric37Value()); - NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; - assertEquals(myNestedRecord.decimal, decimalValue().negate()); - assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); - assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); - assertTrue(myNestedRecord.nestedBox instanceof NoMore); - } - - @Test - void deserializableFromRecord() { - ArrayList fieldsList_ = new ArrayList<>(10); - fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); - fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); - DamlRecord nestedRecord = new DamlRecord(fieldsList_); - ArrayList fieldsList = new ArrayList<>(10); - fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); - fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); - fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); - fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); - Value value = new DamlRecord(fieldsList); - NumericBox record = NumericBox.fromValue(value); - checkRecord(record); - assertTrue( - "to value uses original Daml-LF names for fields", - record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); - } - - @Test - void objectMethodsWork() { - - NumericBox record1 = numericBox(); - NumericBox record2 = numericBox(); - - assertEquals(record1, record2); - assertEquals(record1.hashCode(), record2.hashCode()); - } - - ValueOuterClass.Record.Builder recordBuilder() { - return ValueOuterClass.Record.newBuilder(); - } - - ValueOuterClass.RecordField.Builder recordFieldBuilder() { - return ValueOuterClass.RecordField.newBuilder(); - } - - ValueOuterClass.Value.Builder valueBuilder() { - return ValueOuterClass.Value.newBuilder(); - } - - ValueOuterClass.Variant.Builder variantBuilder() { - return ValueOuterClass.Variant.newBuilder(); - } - - com.google.protobuf.Empty.Builder emptyBuilder() { - return com.google.protobuf.Empty.newBuilder(); - } - - @Test - void outerRecordRoundtrip() { - ValueOuterClass.Value protoValue = - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue(valueBuilder().setNumeric("10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric("99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric("9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor("Nested") - .setValue( - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue( - valueBuilder() - .setNumeric( - "-10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric( - "-99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric( - "-9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor( - "NoMore") - .setValue( - valueBuilder() - .setUnit( - emptyBuilder()))))))))))) - .build(); - - Value value = Value.fromProto(protoValue); - NumericBox fromValue = NumericBox.fromValue(value); - NumericBox fromConstructor = numericBox(); - NumericBox fromRoundTrip = - NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), value); - assertEquals(fromConstructor.toValue().toProto(), protoValue); - assertEquals(fromRoundTrip, fromConstructor); - } - - BigDecimal maxValue(int s) { - return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); - } - - java.math.BigDecimal decimalValue() { - return BigDecimal.TEN.setScale(10); - } - - java.math.BigDecimal numeric0Value() { - return maxValue(0); - } - - java.math.BigDecimal numeric37Value() { - return maxValue(37); - } - - NumericBox numericBox() { - return new NumericBox( - decimalValue(), - numeric0Value(), - numeric37Value(), - new Nested( - new NumericBox( - decimalValue().negate(), - numeric0Value().negate(), - numeric37Value().negate(), - new NoMore(Unit.getInstance())))); - } -} diff --git a/language-support/java/codegen/src/it/java-1.8/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.8/com/daml/AllTests.java deleted file mode 100644 index 45a38dc60734..000000000000 --- a/language-support/java/codegen/src/it/java-1.8/com/daml/AllTests.java +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, - NumericTest.class, -}) -public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.8/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-1.8/com/daml/NumericTest.java deleted file mode 100644 index c600503251ed..000000000000 --- a/language-support/java/codegen/src/it/java-1.8/com/daml/NumericTest.java +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.numerictest.*; -import tests.numerictest.nestednumericbox.*; - -@RunWith(JUnitPlatform.class) -public class NumericTest { - - void checkRecord(NumericBox myRecord) { - assertEquals(myRecord.decimal, decimalValue()); - assertEquals(myRecord.numeric0, numeric0Value()); - assertEquals(myRecord.numeric37, numeric37Value()); - NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; - assertEquals(myNestedRecord.decimal, decimalValue().negate()); - assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); - assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); - assertTrue(myNestedRecord.nestedBox instanceof NoMore); - } - - @Test - void deserializableFromRecord() { - ArrayList fieldsList_ = new ArrayList<>(10); - fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); - fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); - DamlRecord nestedRecord = new DamlRecord(fieldsList_); - ArrayList fieldsList = new ArrayList<>(10); - fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); - fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); - fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); - fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); - Value value = new DamlRecord(fieldsList); - NumericBox record = NumericBox.fromValue(value); - checkRecord(record); - assertTrue( - "to value uses original Daml-LF names for fields", - record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); - } - - @Test - void objectMethodsWork() { - - NumericBox record1 = numericBox(); - NumericBox record2 = numericBox(); - - assertEquals(record1, record2); - assertEquals(record1.hashCode(), record2.hashCode()); - } - - ValueOuterClass.Record.Builder recordBuilder() { - return ValueOuterClass.Record.newBuilder(); - } - - ValueOuterClass.RecordField.Builder recordFieldBuilder() { - return ValueOuterClass.RecordField.newBuilder(); - } - - ValueOuterClass.Value.Builder valueBuilder() { - return ValueOuterClass.Value.newBuilder(); - } - - ValueOuterClass.Variant.Builder variantBuilder() { - return ValueOuterClass.Variant.newBuilder(); - } - - com.google.protobuf.Empty.Builder emptyBuilder() { - return com.google.protobuf.Empty.newBuilder(); - } - - @Test - void outerRecordRoundtrip() { - ValueOuterClass.Value protoValue = - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue(valueBuilder().setNumeric("10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric("99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric("9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor("Nested") - .setValue( - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue( - valueBuilder() - .setNumeric( - "-10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric( - "-99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric( - "-9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor( - "NoMore") - .setValue( - valueBuilder() - .setUnit( - emptyBuilder()))))))))))) - .build(); - - Value value = Value.fromProto(protoValue); - NumericBox fromValue = NumericBox.fromValue(value); - NumericBox fromConstructor = numericBox(); - NumericBox fromRoundTrip = - NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), value); - assertEquals(fromConstructor.toValue().toProto(), protoValue); - assertEquals(fromRoundTrip, fromConstructor); - } - - BigDecimal maxValue(int s) { - return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); - } - - java.math.BigDecimal decimalValue() { - return BigDecimal.TEN.setScale(10); - } - - java.math.BigDecimal numeric0Value() { - return maxValue(0); - } - - java.math.BigDecimal numeric37Value() { - return maxValue(37); - } - - NumericBox numericBox() { - return new NumericBox( - decimalValue(), - numeric0Value(), - numeric37Value(), - new Nested( - new NumericBox( - decimalValue().negate(), - numeric0Value().negate(), - numeric37Value().negate(), - new NoMore(Unit.getInstance())))); - } -} diff --git a/language-support/java/codegen/src/it/java-1.dev/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.dev/com/daml/AllTests.java deleted file mode 100644 index f8c8985dd898..000000000000 --- a/language-support/java/codegen/src/it/java-1.dev/com/daml/AllTests.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, - GenMapTest.class, - NumericTest.class, -}) -public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.dev/com/daml/GenMapTest.java b/language-support/java/codegen/src/it/java-1.dev/com/daml/GenMapTest.java deleted file mode 100644 index 6e4037a7f2c5..000000000000 --- a/language-support/java/codegen/src/it/java-1.dev/com/daml/GenMapTest.java +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.DamlRecord; -import com.daml.ledger.javaapi.data.Int64; -import com.daml.ledger.javaapi.data.Text; -import com.daml.ledger.javaapi.data.Variant; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.genmaptest.MapMapRecord; -import tests.genmaptest.MapRecord; -import tests.genmaptest.TemplateWithMap; -import tests.genmaptest.mapvariant.ParameterizedVariant; -import tests.genmaptest.mapvariant.RecordVariant; -import tests.genmaptest.mapvariant.TextVariant; - -@RunWith(JUnitPlatform.class) -public class GenMapTest { - - @Test - public void mapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildNone, buildText("None")), - buildEntryMap(buildSome(buildInt(1)), buildText("Some(1)")), - buildEntryMap(buildSome(buildInt(42)), buildText("Some(42)"))))) - .getRecord(); - - Map, String> javaMap = new HashMap<>(); - javaMap.put(Optional.empty(), "None"); - javaMap.put(Optional.of(1L), "Some(1)"); - javaMap.put(Optional.of(42L), "Some(42)"); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapRecord fromValue = MapRecord.fromValue(dataRecord); - MapRecord fromConstructor = new MapRecord(javaMap); - MapRecord fromRoundTrip = MapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private Map reverseMap(Map m) { - Map reversedMap = new HashMap<>(); - for (Map.Entry entry : m.entrySet()) reversedMap.put(entry.getValue(), entry.getKey()); - return reversedMap; - } - - @Test - public void mapMapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildMap(), buildMap()), - buildEntryMap( - buildMap(buildEntryMap(buildInt(1), buildText("1L"))), - buildMap(buildEntryMap(buildText("1L"), buildInt(1)))), - buildEntryMap( - buildMap( - buildEntryMap(buildInt(1), buildText("1L")), - buildEntryMap(buildInt(42), buildText("42L"))), - buildMap( - buildEntryMap(buildText("1L"), buildInt(1)), - buildEntryMap(buildText("42L"), buildInt(42))))))) - .getRecord(); - - Map inner1Map = new HashMap<>(); - Map inner2Map = new HashMap<>(); - inner2Map.put(1L, "1L"); - Map inner3Map = new HashMap<>(); - inner3Map.put(1L, "1L"); - inner3Map.put(42L, "42L"); - - Map, Map> javaMap = new HashMap<>(); - javaMap.put(inner1Map, reverseMap(inner1Map)); - javaMap.put(inner2Map, reverseMap(inner2Map)); - javaMap.put(inner3Map, reverseMap(inner3Map)); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapMapRecord fromValue = MapMapRecord.fromValue(dataRecord); - MapMapRecord fromConstructor = new MapMapRecord(javaMap); - MapMapRecord fromRoundTrip = MapMapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void textMapVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant("TextVariant", buildMap(buildEntryMap(buildText("key"), buildText("value")))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - TextVariant fromValue = TextVariant.fromValue(dataVariant); - TextVariant fromConstructor = new TextVariant<>(Collections.singletonMap("key", "value")); - TextVariant fromRoundTrip = TextVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapRecordVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "RecordVariant", - buildRecord( - buildRecordField("x", buildMap(buildEntryMap(buildText("key"), buildInt(42)))))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - RecordVariant fromValue = RecordVariant.fromValue(dataVariant); - RecordVariant fromConstructor = new RecordVariant<>(Collections.singletonMap("key", 42L)); - RecordVariant fromRoundTrip = RecordVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapParameterizedVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "ParameterizedVariant", buildMap(buildEntryMap(buildText("key"), buildInt(42)))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - ParameterizedVariant fromValue = - ParameterizedVariant.fromValue( - dataVariant, x -> x.asText().get().getValue(), x -> x.asInt64().get().getValue()); - ParameterizedVariant fromConstructor = - new ParameterizedVariant<>(Collections.singletonMap("key", 42L)); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - assertEquals(fromValue.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - } - - @Test - public void mapTemplateRoundTripTest() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField("owner", buildParty("party1")), - buildRecordField( - "valueMap", buildMap(buildEntryMap(buildInt(42), buildText("42"))))) - .getRecord(); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - TemplateWithMap fromValue = TemplateWithMap.fromValue(dataRecord); - TemplateWithMap fromConstructor = - new TemplateWithMap("party1", Collections.singletonMap(42L, "42")); - - TemplateWithMap fromRoundTrip = TemplateWithMap.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromValue.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private static ValueOuterClass.Value buildInt(int i) { - return ValueOuterClass.Value.newBuilder().setInt64(i).build(); - } - - private static ValueOuterClass.Value buildText(String text) { - return ValueOuterClass.Value.newBuilder().setText(text).build(); - } - - private static ValueOuterClass.Value buildParty(String party) { - return ValueOuterClass.Value.newBuilder().setParty(party).build(); - } - - private static final ValueOuterClass.Value buildNone = - ValueOuterClass.Value.newBuilder().setOptional(ValueOuterClass.Optional.newBuilder()).build(); - - private static ValueOuterClass.Value buildSome(ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setOptional(ValueOuterClass.Optional.newBuilder().setValue(value)) - .build(); - } - - private static ValueOuterClass.Value buildMap(ValueOuterClass.GenMap.Entry... entries) { - ValueOuterClass.GenMap.Builder builder = ValueOuterClass.GenMap.newBuilder(); - for (ValueOuterClass.GenMap.Entry entry : entries) builder.addEntries(entry); - return ValueOuterClass.Value.newBuilder().setGenMap(builder).build(); - } - - private static ValueOuterClass.GenMap.Entry buildEntryMap( - ValueOuterClass.Value key, ValueOuterClass.Value value) { - return ValueOuterClass.GenMap.Entry.newBuilder().setKey(key).setValue(value).build(); - } - - private static ValueOuterClass.RecordField buildRecordField( - String field, ValueOuterClass.Value value) { - return ValueOuterClass.RecordField.newBuilder().setLabel(field).setValue(value).build(); - } - - private static ValueOuterClass.Value buildRecord(ValueOuterClass.RecordField... fields) { - ValueOuterClass.Record.Builder builder = ValueOuterClass.Record.newBuilder(); - for (ValueOuterClass.RecordField field : fields) builder.addFields(field); - return ValueOuterClass.Value.newBuilder().setRecord(builder).build(); - } - - private static ValueOuterClass.Value buildVariant( - String constructor, ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setVariant( - ValueOuterClass.Variant.newBuilder().setConstructor(constructor).setValue(value)) - .build(); - } -} diff --git a/language-support/java/codegen/src/it/java-1.dev/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-1.dev/com/daml/NumericTest.java deleted file mode 100644 index 99398c06b94b..000000000000 --- a/language-support/java/codegen/src/it/java-1.dev/com/daml/NumericTest.java +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.numerictest.NumericBox; -import tests.numerictest.nestednumericbox.Nested; -import tests.numerictest.nestednumericbox.NoMore; - -@RunWith(JUnitPlatform.class) -public class NumericTest { - - void checkRecord(NumericBox myRecord) { - assertEquals(myRecord.decimal, decimalValue()); - assertEquals(myRecord.numeric0, numeric0Value()); - assertEquals(myRecord.numeric37, numeric37Value()); - NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; - assertEquals(myNestedRecord.decimal, decimalValue().negate()); - assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); - assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); - assertTrue(myNestedRecord.nestedBox instanceof NoMore); - } - - @Test - void deserializableFromRecord() { - ArrayList fieldsList_ = new ArrayList<>(10); - fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); - fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); - DamlRecord nestedRecord = new DamlRecord(fieldsList_); - ArrayList fieldsList = new ArrayList<>(10); - fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); - fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); - fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); - fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); - Value value = new DamlRecord(fieldsList); - NumericBox record = NumericBox.fromValue(value); - checkRecord(record); - assertTrue( - "to value uses original Daml-LF names for fields", - record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); - } - - @Test - void objectMethodsWork() { - - NumericBox record1 = numericBox(); - NumericBox record2 = numericBox(); - - assertEquals(record1, record2); - assertEquals(record1.hashCode(), record2.hashCode()); - } - - ValueOuterClass.Record.Builder recordBuilder() { - return ValueOuterClass.Record.newBuilder(); - } - - ValueOuterClass.RecordField.Builder recordFieldBuilder() { - return ValueOuterClass.RecordField.newBuilder(); - } - - ValueOuterClass.Value.Builder valueBuilder() { - return ValueOuterClass.Value.newBuilder(); - } - - ValueOuterClass.Variant.Builder variantBuilder() { - return ValueOuterClass.Variant.newBuilder(); - } - - com.google.protobuf.Empty.Builder emptyBuilder() { - return com.google.protobuf.Empty.newBuilder(); - } - - @Test - void outerRecordRoundtrip() { - ValueOuterClass.Value protoValue = - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue(valueBuilder().setNumeric("10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric("99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric("9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor("Nested") - .setValue( - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue( - valueBuilder() - .setNumeric( - "-10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric( - "-99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric( - "-9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor( - "NoMore") - .setValue( - valueBuilder() - .setUnit( - emptyBuilder()))))))))))) - .build(); - - Value value = Value.fromProto(protoValue); - NumericBox fromValue = NumericBox.fromValue(value); - NumericBox fromConstructor = numericBox(); - NumericBox fromRoundTrip = - NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), value); - assertEquals(fromConstructor.toValue().toProto(), protoValue); - assertEquals(fromRoundTrip, fromConstructor); - } - - BigDecimal maxValue(int s) { - return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); - } - - java.math.BigDecimal decimalValue() { - return BigDecimal.TEN.setScale(10); - } - - java.math.BigDecimal numeric0Value() { - return maxValue(0); - } - - java.math.BigDecimal numeric37Value() { - return maxValue(37); - } - - NumericBox numericBox() { - return new NumericBox( - decimalValue(), - numeric0Value(), - numeric37Value(), - new Nested( - new NumericBox( - decimalValue().negate(), - numeric0Value().negate(), - numeric37Value().negate(), - new NoMore(Unit.getInstance())))); - } -} diff --git a/language-support/java/codegen/src/it/java-2.1/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-2.1/com/daml/AllTests.java index f8c8985dd898..f364e09154a7 100644 --- a/language-support/java/codegen/src/it/java-2.1/com/daml/AllTests.java +++ b/language-support/java/codegen/src/it/java-2.1/com/daml/AllTests.java @@ -9,7 +9,5 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ AllGenericTests.class, - GenMapTest.class, - NumericTest.class, }) public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-2.1/com/daml/GenMapTest.java b/language-support/java/codegen/src/it/java-2.1/com/daml/GenMapTest.java deleted file mode 100644 index 6e4037a7f2c5..000000000000 --- a/language-support/java/codegen/src/it/java-2.1/com/daml/GenMapTest.java +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.DamlRecord; -import com.daml.ledger.javaapi.data.Int64; -import com.daml.ledger.javaapi.data.Text; -import com.daml.ledger.javaapi.data.Variant; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.genmaptest.MapMapRecord; -import tests.genmaptest.MapRecord; -import tests.genmaptest.TemplateWithMap; -import tests.genmaptest.mapvariant.ParameterizedVariant; -import tests.genmaptest.mapvariant.RecordVariant; -import tests.genmaptest.mapvariant.TextVariant; - -@RunWith(JUnitPlatform.class) -public class GenMapTest { - - @Test - public void mapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildNone, buildText("None")), - buildEntryMap(buildSome(buildInt(1)), buildText("Some(1)")), - buildEntryMap(buildSome(buildInt(42)), buildText("Some(42)"))))) - .getRecord(); - - Map, String> javaMap = new HashMap<>(); - javaMap.put(Optional.empty(), "None"); - javaMap.put(Optional.of(1L), "Some(1)"); - javaMap.put(Optional.of(42L), "Some(42)"); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapRecord fromValue = MapRecord.fromValue(dataRecord); - MapRecord fromConstructor = new MapRecord(javaMap); - MapRecord fromRoundTrip = MapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private Map reverseMap(Map m) { - Map reversedMap = new HashMap<>(); - for (Map.Entry entry : m.entrySet()) reversedMap.put(entry.getValue(), entry.getKey()); - return reversedMap; - } - - @Test - public void mapMapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildMap(), buildMap()), - buildEntryMap( - buildMap(buildEntryMap(buildInt(1), buildText("1L"))), - buildMap(buildEntryMap(buildText("1L"), buildInt(1)))), - buildEntryMap( - buildMap( - buildEntryMap(buildInt(1), buildText("1L")), - buildEntryMap(buildInt(42), buildText("42L"))), - buildMap( - buildEntryMap(buildText("1L"), buildInt(1)), - buildEntryMap(buildText("42L"), buildInt(42))))))) - .getRecord(); - - Map inner1Map = new HashMap<>(); - Map inner2Map = new HashMap<>(); - inner2Map.put(1L, "1L"); - Map inner3Map = new HashMap<>(); - inner3Map.put(1L, "1L"); - inner3Map.put(42L, "42L"); - - Map, Map> javaMap = new HashMap<>(); - javaMap.put(inner1Map, reverseMap(inner1Map)); - javaMap.put(inner2Map, reverseMap(inner2Map)); - javaMap.put(inner3Map, reverseMap(inner3Map)); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapMapRecord fromValue = MapMapRecord.fromValue(dataRecord); - MapMapRecord fromConstructor = new MapMapRecord(javaMap); - MapMapRecord fromRoundTrip = MapMapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void textMapVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant("TextVariant", buildMap(buildEntryMap(buildText("key"), buildText("value")))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - TextVariant fromValue = TextVariant.fromValue(dataVariant); - TextVariant fromConstructor = new TextVariant<>(Collections.singletonMap("key", "value")); - TextVariant fromRoundTrip = TextVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapRecordVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "RecordVariant", - buildRecord( - buildRecordField("x", buildMap(buildEntryMap(buildText("key"), buildInt(42)))))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - RecordVariant fromValue = RecordVariant.fromValue(dataVariant); - RecordVariant fromConstructor = new RecordVariant<>(Collections.singletonMap("key", 42L)); - RecordVariant fromRoundTrip = RecordVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapParameterizedVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "ParameterizedVariant", buildMap(buildEntryMap(buildText("key"), buildInt(42)))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - ParameterizedVariant fromValue = - ParameterizedVariant.fromValue( - dataVariant, x -> x.asText().get().getValue(), x -> x.asInt64().get().getValue()); - ParameterizedVariant fromConstructor = - new ParameterizedVariant<>(Collections.singletonMap("key", 42L)); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - assertEquals(fromValue.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - } - - @Test - public void mapTemplateRoundTripTest() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField("owner", buildParty("party1")), - buildRecordField( - "valueMap", buildMap(buildEntryMap(buildInt(42), buildText("42"))))) - .getRecord(); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - TemplateWithMap fromValue = TemplateWithMap.fromValue(dataRecord); - TemplateWithMap fromConstructor = - new TemplateWithMap("party1", Collections.singletonMap(42L, "42")); - - TemplateWithMap fromRoundTrip = TemplateWithMap.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromValue.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private static ValueOuterClass.Value buildInt(int i) { - return ValueOuterClass.Value.newBuilder().setInt64(i).build(); - } - - private static ValueOuterClass.Value buildText(String text) { - return ValueOuterClass.Value.newBuilder().setText(text).build(); - } - - private static ValueOuterClass.Value buildParty(String party) { - return ValueOuterClass.Value.newBuilder().setParty(party).build(); - } - - private static final ValueOuterClass.Value buildNone = - ValueOuterClass.Value.newBuilder().setOptional(ValueOuterClass.Optional.newBuilder()).build(); - - private static ValueOuterClass.Value buildSome(ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setOptional(ValueOuterClass.Optional.newBuilder().setValue(value)) - .build(); - } - - private static ValueOuterClass.Value buildMap(ValueOuterClass.GenMap.Entry... entries) { - ValueOuterClass.GenMap.Builder builder = ValueOuterClass.GenMap.newBuilder(); - for (ValueOuterClass.GenMap.Entry entry : entries) builder.addEntries(entry); - return ValueOuterClass.Value.newBuilder().setGenMap(builder).build(); - } - - private static ValueOuterClass.GenMap.Entry buildEntryMap( - ValueOuterClass.Value key, ValueOuterClass.Value value) { - return ValueOuterClass.GenMap.Entry.newBuilder().setKey(key).setValue(value).build(); - } - - private static ValueOuterClass.RecordField buildRecordField( - String field, ValueOuterClass.Value value) { - return ValueOuterClass.RecordField.newBuilder().setLabel(field).setValue(value).build(); - } - - private static ValueOuterClass.Value buildRecord(ValueOuterClass.RecordField... fields) { - ValueOuterClass.Record.Builder builder = ValueOuterClass.Record.newBuilder(); - for (ValueOuterClass.RecordField field : fields) builder.addFields(field); - return ValueOuterClass.Value.newBuilder().setRecord(builder).build(); - } - - private static ValueOuterClass.Value buildVariant( - String constructor, ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setVariant( - ValueOuterClass.Variant.newBuilder().setConstructor(constructor).setValue(value)) - .build(); - } -} diff --git a/language-support/java/codegen/src/it/java-2.1/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-2.1/com/daml/NumericTest.java deleted file mode 100644 index 99398c06b94b..000000000000 --- a/language-support/java/codegen/src/it/java-2.1/com/daml/NumericTest.java +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.numerictest.NumericBox; -import tests.numerictest.nestednumericbox.Nested; -import tests.numerictest.nestednumericbox.NoMore; - -@RunWith(JUnitPlatform.class) -public class NumericTest { - - void checkRecord(NumericBox myRecord) { - assertEquals(myRecord.decimal, decimalValue()); - assertEquals(myRecord.numeric0, numeric0Value()); - assertEquals(myRecord.numeric37, numeric37Value()); - NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; - assertEquals(myNestedRecord.decimal, decimalValue().negate()); - assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); - assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); - assertTrue(myNestedRecord.nestedBox instanceof NoMore); - } - - @Test - void deserializableFromRecord() { - ArrayList fieldsList_ = new ArrayList<>(10); - fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); - fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); - DamlRecord nestedRecord = new DamlRecord(fieldsList_); - ArrayList fieldsList = new ArrayList<>(10); - fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); - fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); - fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); - fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); - Value value = new DamlRecord(fieldsList); - NumericBox record = NumericBox.fromValue(value); - checkRecord(record); - assertTrue( - "to value uses original Daml-LF names for fields", - record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); - } - - @Test - void objectMethodsWork() { - - NumericBox record1 = numericBox(); - NumericBox record2 = numericBox(); - - assertEquals(record1, record2); - assertEquals(record1.hashCode(), record2.hashCode()); - } - - ValueOuterClass.Record.Builder recordBuilder() { - return ValueOuterClass.Record.newBuilder(); - } - - ValueOuterClass.RecordField.Builder recordFieldBuilder() { - return ValueOuterClass.RecordField.newBuilder(); - } - - ValueOuterClass.Value.Builder valueBuilder() { - return ValueOuterClass.Value.newBuilder(); - } - - ValueOuterClass.Variant.Builder variantBuilder() { - return ValueOuterClass.Variant.newBuilder(); - } - - com.google.protobuf.Empty.Builder emptyBuilder() { - return com.google.protobuf.Empty.newBuilder(); - } - - @Test - void outerRecordRoundtrip() { - ValueOuterClass.Value protoValue = - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue(valueBuilder().setNumeric("10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric("99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric("9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor("Nested") - .setValue( - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue( - valueBuilder() - .setNumeric( - "-10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric( - "-99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric( - "-9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor( - "NoMore") - .setValue( - valueBuilder() - .setUnit( - emptyBuilder()))))))))))) - .build(); - - Value value = Value.fromProto(protoValue); - NumericBox fromValue = NumericBox.fromValue(value); - NumericBox fromConstructor = numericBox(); - NumericBox fromRoundTrip = - NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), value); - assertEquals(fromConstructor.toValue().toProto(), protoValue); - assertEquals(fromRoundTrip, fromConstructor); - } - - BigDecimal maxValue(int s) { - return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); - } - - java.math.BigDecimal decimalValue() { - return BigDecimal.TEN.setScale(10); - } - - java.math.BigDecimal numeric0Value() { - return maxValue(0); - } - - java.math.BigDecimal numeric37Value() { - return maxValue(37); - } - - NumericBox numericBox() { - return new NumericBox( - decimalValue(), - numeric0Value(), - numeric37Value(), - new Nested( - new NumericBox( - decimalValue().negate(), - numeric0Value().negate(), - numeric37Value().negate(), - new NoMore(Unit.getInstance())))); - } -} diff --git a/language-support/java/codegen/src/it/java-2.dev/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-2.dev/com/daml/AllTests.java index f8c8985dd898..f717cdcce643 100644 --- a/language-support/java/codegen/src/it/java-2.dev/com/daml/AllTests.java +++ b/language-support/java/codegen/src/it/java-2.dev/com/daml/AllTests.java @@ -7,9 +7,5 @@ import org.junit.runners.Suite; @RunWith(Suite.class) -@Suite.SuiteClasses({ - AllGenericTests.class, - GenMapTest.class, - NumericTest.class, -}) +@Suite.SuiteClasses({AllGenericTests.class, ContractKeysTest.class}) public class AllTests {} diff --git a/language-support/java/codegen/src/it/java/com/daml/ContractKeysTest.java b/language-support/java/codegen/src/it/java-2.dev/com/daml/ContractKeysTest.java similarity index 100% rename from language-support/java/codegen/src/it/java/com/daml/ContractKeysTest.java rename to language-support/java/codegen/src/it/java-2.dev/com/daml/ContractKeysTest.java diff --git a/language-support/java/codegen/src/it/java-2.dev/com/daml/GenMapTest.java b/language-support/java/codegen/src/it/java-2.dev/com/daml/GenMapTest.java deleted file mode 100644 index 6e4037a7f2c5..000000000000 --- a/language-support/java/codegen/src/it/java-2.dev/com/daml/GenMapTest.java +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.DamlRecord; -import com.daml.ledger.javaapi.data.Int64; -import com.daml.ledger.javaapi.data.Text; -import com.daml.ledger.javaapi.data.Variant; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.genmaptest.MapMapRecord; -import tests.genmaptest.MapRecord; -import tests.genmaptest.TemplateWithMap; -import tests.genmaptest.mapvariant.ParameterizedVariant; -import tests.genmaptest.mapvariant.RecordVariant; -import tests.genmaptest.mapvariant.TextVariant; - -@RunWith(JUnitPlatform.class) -public class GenMapTest { - - @Test - public void mapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildNone, buildText("None")), - buildEntryMap(buildSome(buildInt(1)), buildText("Some(1)")), - buildEntryMap(buildSome(buildInt(42)), buildText("Some(42)"))))) - .getRecord(); - - Map, String> javaMap = new HashMap<>(); - javaMap.put(Optional.empty(), "None"); - javaMap.put(Optional.of(1L), "Some(1)"); - javaMap.put(Optional.of(42L), "Some(42)"); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapRecord fromValue = MapRecord.fromValue(dataRecord); - MapRecord fromConstructor = new MapRecord(javaMap); - MapRecord fromRoundTrip = MapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private Map reverseMap(Map m) { - Map reversedMap = new HashMap<>(); - for (Map.Entry entry : m.entrySet()) reversedMap.put(entry.getValue(), entry.getKey()); - return reversedMap; - } - - @Test - public void mapMapRecordRoundTrip() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField( - "field", - buildMap( - buildEntryMap(buildMap(), buildMap()), - buildEntryMap( - buildMap(buildEntryMap(buildInt(1), buildText("1L"))), - buildMap(buildEntryMap(buildText("1L"), buildInt(1)))), - buildEntryMap( - buildMap( - buildEntryMap(buildInt(1), buildText("1L")), - buildEntryMap(buildInt(42), buildText("42L"))), - buildMap( - buildEntryMap(buildText("1L"), buildInt(1)), - buildEntryMap(buildText("42L"), buildInt(42))))))) - .getRecord(); - - Map inner1Map = new HashMap<>(); - Map inner2Map = new HashMap<>(); - inner2Map.put(1L, "1L"); - Map inner3Map = new HashMap<>(); - inner3Map.put(1L, "1L"); - inner3Map.put(42L, "42L"); - - Map, Map> javaMap = new HashMap<>(); - javaMap.put(inner1Map, reverseMap(inner1Map)); - javaMap.put(inner2Map, reverseMap(inner2Map)); - javaMap.put(inner3Map, reverseMap(inner3Map)); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - MapMapRecord fromValue = MapMapRecord.fromValue(dataRecord); - MapMapRecord fromConstructor = new MapMapRecord(javaMap); - MapMapRecord fromRoundTrip = MapMapRecord.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void textMapVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant("TextVariant", buildMap(buildEntryMap(buildText("key"), buildText("value")))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - TextVariant fromValue = TextVariant.fromValue(dataVariant); - TextVariant fromConstructor = new TextVariant<>(Collections.singletonMap("key", "value")); - TextVariant fromRoundTrip = TextVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapRecordVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "RecordVariant", - buildRecord( - buildRecordField("x", buildMap(buildEntryMap(buildText("key"), buildInt(42)))))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - RecordVariant fromValue = RecordVariant.fromValue(dataVariant); - RecordVariant fromConstructor = new RecordVariant<>(Collections.singletonMap("key", 42L)); - RecordVariant fromRoundTrip = RecordVariant.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataVariant); - assertEquals(fromConstructor, fromRoundTrip); - } - - @Test - public void mapParameterizedVariantRoundTripTest() { - - ValueOuterClass.Variant protoVariant = - buildVariant( - "ParameterizedVariant", buildMap(buildEntryMap(buildText("key"), buildInt(42)))) - .getVariant(); - - Variant dataVariant = Variant.fromProto(protoVariant); - ParameterizedVariant fromValue = - ParameterizedVariant.fromValue( - dataVariant, x -> x.asText().get().getValue(), x -> x.asInt64().get().getValue()); - ParameterizedVariant fromConstructor = - new ParameterizedVariant<>(Collections.singletonMap("key", 42L)); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - assertEquals(fromValue.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); - } - - @Test - public void mapTemplateRoundTripTest() { - - ValueOuterClass.Record protoRecord = - buildRecord( - buildRecordField("owner", buildParty("party1")), - buildRecordField( - "valueMap", buildMap(buildEntryMap(buildInt(42), buildText("42"))))) - .getRecord(); - - DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); - TemplateWithMap fromValue = TemplateWithMap.fromValue(dataRecord); - TemplateWithMap fromConstructor = - new TemplateWithMap("party1", Collections.singletonMap(42L, "42")); - - TemplateWithMap fromRoundTrip = TemplateWithMap.fromValue(fromConstructor.toValue()); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), dataRecord); - assertEquals(fromValue.toValue(), dataRecord); - assertEquals(fromConstructor, fromRoundTrip); - } - - private static ValueOuterClass.Value buildInt(int i) { - return ValueOuterClass.Value.newBuilder().setInt64(i).build(); - } - - private static ValueOuterClass.Value buildText(String text) { - return ValueOuterClass.Value.newBuilder().setText(text).build(); - } - - private static ValueOuterClass.Value buildParty(String party) { - return ValueOuterClass.Value.newBuilder().setParty(party).build(); - } - - private static final ValueOuterClass.Value buildNone = - ValueOuterClass.Value.newBuilder().setOptional(ValueOuterClass.Optional.newBuilder()).build(); - - private static ValueOuterClass.Value buildSome(ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setOptional(ValueOuterClass.Optional.newBuilder().setValue(value)) - .build(); - } - - private static ValueOuterClass.Value buildMap(ValueOuterClass.GenMap.Entry... entries) { - ValueOuterClass.GenMap.Builder builder = ValueOuterClass.GenMap.newBuilder(); - for (ValueOuterClass.GenMap.Entry entry : entries) builder.addEntries(entry); - return ValueOuterClass.Value.newBuilder().setGenMap(builder).build(); - } - - private static ValueOuterClass.GenMap.Entry buildEntryMap( - ValueOuterClass.Value key, ValueOuterClass.Value value) { - return ValueOuterClass.GenMap.Entry.newBuilder().setKey(key).setValue(value).build(); - } - - private static ValueOuterClass.RecordField buildRecordField( - String field, ValueOuterClass.Value value) { - return ValueOuterClass.RecordField.newBuilder().setLabel(field).setValue(value).build(); - } - - private static ValueOuterClass.Value buildRecord(ValueOuterClass.RecordField... fields) { - ValueOuterClass.Record.Builder builder = ValueOuterClass.Record.newBuilder(); - for (ValueOuterClass.RecordField field : fields) builder.addFields(field); - return ValueOuterClass.Value.newBuilder().setRecord(builder).build(); - } - - private static ValueOuterClass.Value buildVariant( - String constructor, ValueOuterClass.Value value) { - return ValueOuterClass.Value.newBuilder() - .setVariant( - ValueOuterClass.Variant.newBuilder().setConstructor(constructor).setValue(value)) - .build(); - } -} diff --git a/language-support/java/codegen/src/it/java-2.dev/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-2.dev/com/daml/NumericTest.java deleted file mode 100644 index 99398c06b94b..000000000000 --- a/language-support/java/codegen/src/it/java-2.dev/com/daml/NumericTest.java +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.daml.ledger.api.v2.ValueOuterClass; -import com.daml.ledger.javaapi.data.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import tests.numerictest.NumericBox; -import tests.numerictest.nestednumericbox.Nested; -import tests.numerictest.nestednumericbox.NoMore; - -@RunWith(JUnitPlatform.class) -public class NumericTest { - - void checkRecord(NumericBox myRecord) { - assertEquals(myRecord.decimal, decimalValue()); - assertEquals(myRecord.numeric0, numeric0Value()); - assertEquals(myRecord.numeric37, numeric37Value()); - NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; - assertEquals(myNestedRecord.decimal, decimalValue().negate()); - assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); - assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); - assertTrue(myNestedRecord.nestedBox instanceof NoMore); - } - - @Test - void deserializableFromRecord() { - ArrayList fieldsList_ = new ArrayList<>(10); - fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); - fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); - fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); - DamlRecord nestedRecord = new DamlRecord(fieldsList_); - ArrayList fieldsList = new ArrayList<>(10); - fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); - fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); - fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); - fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); - Value value = new DamlRecord(fieldsList); - NumericBox record = NumericBox.fromValue(value); - checkRecord(record); - assertTrue( - "to value uses original Daml-LF names for fields", - record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); - } - - @Test - void objectMethodsWork() { - - NumericBox record1 = numericBox(); - NumericBox record2 = numericBox(); - - assertEquals(record1, record2); - assertEquals(record1.hashCode(), record2.hashCode()); - } - - ValueOuterClass.Record.Builder recordBuilder() { - return ValueOuterClass.Record.newBuilder(); - } - - ValueOuterClass.RecordField.Builder recordFieldBuilder() { - return ValueOuterClass.RecordField.newBuilder(); - } - - ValueOuterClass.Value.Builder valueBuilder() { - return ValueOuterClass.Value.newBuilder(); - } - - ValueOuterClass.Variant.Builder variantBuilder() { - return ValueOuterClass.Variant.newBuilder(); - } - - com.google.protobuf.Empty.Builder emptyBuilder() { - return com.google.protobuf.Empty.newBuilder(); - } - - @Test - void outerRecordRoundtrip() { - ValueOuterClass.Value protoValue = - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue(valueBuilder().setNumeric("10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric("99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric("9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor("Nested") - .setValue( - valueBuilder() - .setRecord( - recordBuilder() - .addFields( - recordFieldBuilder() - .setLabel("decimal") - .setValue( - valueBuilder() - .setNumeric( - "-10.0000000000"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric0") - .setValue( - valueBuilder() - .setNumeric( - "-99999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("numeric37") - .setValue( - valueBuilder() - .setNumeric( - "-9.9999999999999999999999999999999999999"))) - .addFields( - recordFieldBuilder() - .setLabel("nestedBox") - .setValue( - valueBuilder() - .setVariant( - variantBuilder() - .setConstructor( - "NoMore") - .setValue( - valueBuilder() - .setUnit( - emptyBuilder()))))))))))) - .build(); - - Value value = Value.fromProto(protoValue); - NumericBox fromValue = NumericBox.fromValue(value); - NumericBox fromConstructor = numericBox(); - NumericBox fromRoundTrip = - NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); - - assertEquals(fromValue, fromConstructor); - assertEquals(fromConstructor.toValue(), value); - assertEquals(fromConstructor.toValue().toProto(), protoValue); - assertEquals(fromRoundTrip, fromConstructor); - } - - BigDecimal maxValue(int s) { - return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); - } - - java.math.BigDecimal decimalValue() { - return BigDecimal.TEN.setScale(10); - } - - java.math.BigDecimal numeric0Value() { - return maxValue(0); - } - - java.math.BigDecimal numeric37Value() { - return maxValue(37); - } - - NumericBox numericBox() { - return new NumericBox( - decimalValue(), - numeric0Value(), - numeric37Value(), - new Nested( - new NumericBox( - decimalValue().negate(), - numeric0Value().negate(), - numeric37Value().negate(), - new NoMore(Unit.getInstance())))); - } -} diff --git a/language-support/java/codegen/src/it/java/com/daml/AllGenericTests.java b/language-support/java/codegen/src/it/java/com/daml/AllGenericTests.java index 24ad51aeffde..f3e1c8d94961 100644 --- a/language-support/java/codegen/src/it/java/com/daml/AllGenericTests.java +++ b/language-support/java/codegen/src/it/java/com/daml/AllGenericTests.java @@ -13,13 +13,15 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ DecoderTest.class, + GenMapTest.class, ListTest.class, + NumericTest.class, OptionalTest.class, ParametrizedContractIdTest.class, RecordTest.class, TemplateMethodTest.class, TextMapTest.class, - VariantTest.class, UpgradeTest.class, + VariantTest.class, }) public class AllGenericTests {} diff --git a/language-support/java/codegen/src/it/java-1.14/com/daml/GenMapTest.java b/language-support/java/codegen/src/it/java/com/daml/GenMapTest.java similarity index 100% rename from language-support/java/codegen/src/it/java-1.14/com/daml/GenMapTest.java rename to language-support/java/codegen/src/it/java/com/daml/GenMapTest.java diff --git a/language-support/java/codegen/src/it/java-1.12/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java/com/daml/NumericTest.java similarity index 100% rename from language-support/java/codegen/src/it/java-1.12/com/daml/NumericTest.java rename to language-support/java/codegen/src/it/java/com/daml/NumericTest.java diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_11.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_11.java deleted file mode 100644 index 10091cfa99f6..000000000000 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_11.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml.testing; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - EnumTestForForAll.class, - NumericTestForAll.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.class, -}) -public class AllTestsFor1_11 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_12.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_12.java deleted file mode 100644 index e8291f9b3269..000000000000 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_12.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml.testing; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - EnumTestForForAll.class, - NumericTestForAll.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.class, -}) -public class AllTestsFor1_12 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_14.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_14.java deleted file mode 100644 index e74107e6d989..000000000000 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_14.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml.testing; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - EnumTestForForAll.class, - NumericTestForAll.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.class, -}) -public class AllTestsFor1_14 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_15.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_15.java deleted file mode 100644 index b13a9e7bba6a..000000000000 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_15.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml.testing; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - EnumTestForForAll.class, - NumericTestForAll.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.class, -}) -public class AllTestsFor1_15 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_8.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_8.java deleted file mode 100644 index 5ad6e7258543..000000000000 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_8.java +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml.testing; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - EnumTestForForAll.class, - NumericTestForAll.class, -}) -public class AllTestsFor1_8 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_dev.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_dev.java deleted file mode 100644 index 7a8a1939a8c0..000000000000 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_dev.java +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.daml.testing; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - EnumTestForForAll.class, - NumericTestForAll.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.class, -}) -public class AllTestsFor1_dev {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor2_1.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor2_1.java index 8d4f8fb3068f..53d8011f4e3b 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor2_1.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor2_1.java @@ -8,8 +8,8 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ - EnumTestForForAll.class, + EnumTestForAll.class, NumericTestForAll.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.class, + MapTestForAll.class, }) public class AllTestsFor2_1 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor2_dev.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor2_dev.java index 45e769cc3b1e..2fc7681a9235 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor2_dev.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor2_dev.java @@ -8,8 +8,8 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ - EnumTestForForAll.class, + EnumTestForAll.class, NumericTestForAll.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.class, + MapTestForAll.class, }) public class AllTestsFor2_dev {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/EnumTestForForAll.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/EnumTestForAll.java similarity index 99% rename from language-support/java/codegen/src/test/java/com/digitalasset/testing/EnumTestForForAll.java rename to language-support/java/codegen/src/test/java/com/digitalasset/testing/EnumTestForAll.java index 240646d4d457..80afccbf5496 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/EnumTestForForAll.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/EnumTestForAll.java @@ -20,7 +20,7 @@ import test.enummod.optionalcolor.*; @RunWith(JUnitPlatform.class) -public class EnumTestForForAll { +public class EnumTestForAll { @Test void enum2Value2Enum() { diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/MapTestForAll.java similarity index 97% rename from language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.java rename to language-support/java/codegen/src/test/java/com/digitalasset/testing/MapTestForAll.java index ca09587f44c8..9e544b84c534 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/MapTestForAll.java @@ -21,8 +21,7 @@ import test.variantmod.either.*; @RunWith(JUnitPlatform.class) -public -class GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_15AndFor1_devAndFor2_1AndFor2_dev { +public class MapTestForAll { private BigDecimal bg1() { return new BigDecimal("1.0000000000");