Testing fromValue with contract id (#14633)

* testing from value contract id

CHANGELOG_BEGIN
CHANGELOG_END

* delete commented code

CHANGELOG_BEGIN
CHANGELOG_END

* separate Bar template from Foo daml Modules
This commit is contained in:
Chun Lok Ling 2022-08-08 10:44:16 +01:00 committed by GitHub
parent 8db2c58dac
commit 7e4b18ace6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 0 deletions

View File

@ -82,9 +82,11 @@ da_scala_test(
"@maven//:org_scalatest_scalatest_matchers_core",
"@maven//:org_scalatest_scalatest_shouldmatchers",
"@maven//:org_scalaz_scalaz_core",
"@maven//:com_chuusai_shapeless",
],
deps = [
":lib",
":test-daml-java.jar",
"//bazel_tools/runfiles:scala_runfiles",
"//daml-lf/archive:daml_lf_archive_reader",
"//daml-lf/data",
@ -102,6 +104,17 @@ daml_compile(
srcs = ["src/test/daml/Foo.daml"],
)
daml_compile(
name = "test-contract-id-daml",
srcs = ["src/test/daml/Bar.daml"],
)
dar_to_java(
name = "test-daml-java",
src = ":test-contract-id-daml.dar",
package_prefix = "ut",
)
jar_jar(
name = "shaded_binary",
input_jar = "//language-support/java/codegen:codegen_deploy.jar",

View File

@ -0,0 +1,23 @@
-- Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
module Bar where
template Bar
with
owner : Party
where
signatory owner
data ParameterizedContractId a = ParameterizedContractId
with
parameterizedContractId: ContractId a
deriving (Eq, Show)
template Haha
with
p : ParameterizedContractId Bar
owner : Party
where
signatory owner

View File

@ -0,0 +1,30 @@
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package com.daml.lf.codegen.backend.java
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import ut.bar.{Bar, ParameterizedContractId}
import com.daml.ledger.javaapi.data.codegen.ContractId
import shapeless.test.illTyped
final class FromValueSpec extends AnyWordSpec with Matchers {
"contractId<Bar>" should {
"not be cast to Bar.ContractId" in {
val fromConstructor: ParameterizedContractId[Bar] =
new ParameterizedContractId(new Bar.ContractId("SomeID"))
val parametrizedContractId: ParameterizedContractId[Bar] =
ParameterizedContractId.fromValue(fromConstructor.toValue(_.toValue), Bar.fromValue)
val contractIdBar: ContractId[Bar] = parametrizedContractId.parameterizedContractId
illTyped(
"contractIdBar: Bar.ContractId",
"type mismatch.+ContractId\\[.+Bar\\].+Bar.ContractId",
)
contractIdBar should not be a[Bar.ContractId]
}
}
}