mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
Thread enableContractUpgrading through engine. (#17139)
This commit is contained in:
parent
9e0ff3e0d4
commit
9fddcb956c
@ -158,7 +158,11 @@ object CantonRunner {
|
||||
"-c" ::
|
||||
files.configFile.toString ::
|
||||
bootstrapOptions :::
|
||||
debugOptions
|
||||
debugOptions,
|
||||
None,
|
||||
// TODO: https://github.com/digital-asset/daml/issues/17082
|
||||
// Workaround to allow DevIT tests to pass.
|
||||
("enableContractUpgrading", ""),
|
||||
).run(ProcessLogger { str =>
|
||||
if (config.debug) println(str)
|
||||
outputBuffer += str
|
||||
|
@ -109,7 +109,7 @@ private[lf] final class ConcurrentCompiledPackages(compilerConfig: Compiler.Conf
|
||||
val defns =
|
||||
try {
|
||||
new speedy.Compiler(extendedSignatures, compilerConfig)
|
||||
.unsafeCompilePackage(pkgId, pkg)
|
||||
.unsafeCompilePackage(pkgId, pkg, compilerConfig.enableContractUpgrading)
|
||||
} catch {
|
||||
case e: validation.ValidationError =>
|
||||
return ResultError(Error.Package.Validation(e))
|
||||
|
@ -51,6 +51,13 @@ final case class EngineConfig(
|
||||
enableContractUpgrading: Boolean = false,
|
||||
) {
|
||||
|
||||
// TODO: https://github.com/digital-asset/daml/issues/17082
|
||||
// Workaround while we wait for: https://github.com/digital-asset/daml/pull/17126
|
||||
// And a canton PR to support enableContractUpgrading in canton-config.
|
||||
// Until then we set enableContractUpgrading via env-var.
|
||||
|
||||
val enableContractUpgradingEV = sys.env.get("enableContractUpgrading").isDefined
|
||||
|
||||
private[lf] def getCompilerConfig: speedy.Compiler.Config =
|
||||
speedy.Compiler.Config(
|
||||
allowedLanguageVersions,
|
||||
@ -69,6 +76,7 @@ final case class EngineConfig(
|
||||
speedy.Compiler.FullProfile
|
||||
else
|
||||
speedy.Compiler.NoProfile,
|
||||
enableContractUpgrading = enableContractUpgradingEV,
|
||||
)
|
||||
|
||||
private[lf] def authorizationChecker: AuthorizationChecker =
|
||||
|
@ -1858,6 +1858,9 @@ class EngineTest
|
||||
)
|
||||
.consume(contracts, lookupPackage, lookupKey)
|
||||
|
||||
// TODO: https://github.com/digital-asset/daml/issues/17082
|
||||
// - When `enableContractUpgrading = true`, these tests change behaviour & dont fail with "wrongly typed contract"
|
||||
|
||||
"error on fetch" in {
|
||||
val result = run(ImmArray(incorrectFetch))
|
||||
inside(result) { case Left(e) =>
|
||||
|
@ -69,6 +69,7 @@ private[lf] object Compiler {
|
||||
packageValidation: PackageValidationMode,
|
||||
profiling: ProfilingMode,
|
||||
stacktracing: StackTraceMode,
|
||||
enableContractUpgrading: Boolean = false,
|
||||
)
|
||||
|
||||
object Config {
|
||||
@ -101,7 +102,7 @@ private[lf] object Compiler {
|
||||
try {
|
||||
Right(packages.foldLeft(Map.empty[t.SDefinitionRef, SDefinition]) {
|
||||
case (acc, (pkgId, pkg)) =>
|
||||
acc ++ compiler.compilePackage(pkgId, pkg)
|
||||
acc ++ compiler.compilePackage(pkgId, pkg, compilerConfig.enableContractUpgrading)
|
||||
})
|
||||
} catch {
|
||||
case CompilationError(msg) => Left(s"Compilation Error: $msg")
|
||||
@ -145,7 +146,10 @@ private[lf] final class Compiler(
|
||||
def unsafeCompilePackage(
|
||||
pkgId: PackageId,
|
||||
pkg: Package,
|
||||
): Iterable[(t.SDefinitionRef, SDefinition)] = compilePackage(pkgId, pkg)
|
||||
enableContractUpgrading: Boolean = false,
|
||||
): Iterable[(t.SDefinitionRef, SDefinition)] = {
|
||||
compilePackage(pkgId, pkg, enableContractUpgrading)
|
||||
}
|
||||
|
||||
@throws[PackageNotFound]
|
||||
@throws[CompilationError]
|
||||
@ -153,8 +157,7 @@ private[lf] final class Compiler(
|
||||
pkgId: PackageId,
|
||||
module: Module,
|
||||
): Iterable[(t.SDefinitionRef, SDefinition)] = {
|
||||
val predPids = pkgInterface.lookupPredecessors(pkgId).getOrElse(List.empty)
|
||||
compileModule(pkgId, module, predPids)
|
||||
compileModule(pkgId, module, enableContractUpgrading = false)
|
||||
}
|
||||
|
||||
@throws[PackageNotFound]
|
||||
@ -348,7 +351,7 @@ private[lf] final class Compiler(
|
||||
private[this] def compileModule(
|
||||
pkgId: PackageId,
|
||||
module: Module,
|
||||
predPids: List[PackageId],
|
||||
enableContractUpgrading: Boolean,
|
||||
): Iterable[(t.SDefinitionRef, SDefinition)] = {
|
||||
val builder = Iterable.newBuilder[(t.SDefinitionRef, SDefinition)]
|
||||
def addDef(binding: (t.SDefinitionRef, SDefinition)): Unit = discard(builder += binding)
|
||||
@ -368,9 +371,15 @@ private[lf] final class Compiler(
|
||||
module.templates.foreach { case (tmplName, tmpl) =>
|
||||
val tmplId = Identifier(pkgId, QualifiedName(module.name, tmplName))
|
||||
|
||||
val optTargetTemplateId =
|
||||
if (enableContractUpgrading) {
|
||||
Some(tmplId) // soft
|
||||
} else {
|
||||
None // hard
|
||||
}
|
||||
|
||||
addDef(compileCreate(tmplId, tmpl))
|
||||
addDef(compileFetchTemplate(tmplId, tmpl))
|
||||
addDef(compileSoftFetchTemplate(tmplId, tmpl, predPids))
|
||||
addDef(compileFetchTemplate(tmplId, tmpl, optTargetTemplateId))
|
||||
addDef(compileTemplatePreCondition(tmplId, tmpl))
|
||||
addDef(compileAgreementText(tmplId, tmpl))
|
||||
addDef(compileSignatories(tmplId, tmpl))
|
||||
@ -387,8 +396,7 @@ private[lf] final class Compiler(
|
||||
}
|
||||
|
||||
tmpl.choices.values.foreach { choice =>
|
||||
addDef(compileTemplateChoice(tmplId, tmpl, choice))
|
||||
addDef(compileSoftTemplateChoice(tmplId, tmpl, predPids, choice))
|
||||
addDef(compileTemplateChoice(tmplId, tmpl, choice, optTargetTemplateId))
|
||||
addDef(compileChoiceController(tmplId, tmpl.param, choice))
|
||||
addDef(compileChoiceObserver(tmplId, tmpl.param, choice))
|
||||
}
|
||||
@ -435,6 +443,7 @@ private[lf] final class Compiler(
|
||||
private def compilePackage(
|
||||
pkgId: PackageId,
|
||||
pkg: Package,
|
||||
enableContractUpgrading: Boolean,
|
||||
): Iterable[(t.SDefinitionRef, SDefinition)] = {
|
||||
logger.trace(s"compilePackage: Compiling $pkgId...")
|
||||
|
||||
@ -456,11 +465,7 @@ private[lf] final class Compiler(
|
||||
|
||||
val t1 = Time.Timestamp.now()
|
||||
|
||||
// TODO https://github.com/digital-asset/daml/issues/16151
|
||||
// getOrElse will mask package load errors in lookupPredecessors
|
||||
val preds = pkgInterface.lookupPredecessors(pkgId).getOrElse(List.empty)
|
||||
|
||||
val result = pkg.modules.values.flatMap(compileModule(pkgId, _, preds))
|
||||
val result = pkg.modules.values.flatMap(compileModule(pkgId, _, enableContractUpgrading))
|
||||
|
||||
val t2 = Time.Timestamp.now()
|
||||
logger.trace(
|
||||
@ -625,17 +630,11 @@ private[lf] final class Compiler(
|
||||
tmplId: TypeConName,
|
||||
tmpl: Template,
|
||||
choice: TemplateChoice,
|
||||
optTargetTemplateId: Option[TypeConName],
|
||||
): (t.SDefinitionRef, SDefinition) =
|
||||
// Compiles a choice into:
|
||||
// ChoiceDefRef(SomeTemplate, SomeChoice) = \<actors> <cid> <choiceArg> <token> ->
|
||||
// let targ = fetch(tmplId) <cid>
|
||||
// _ = $beginExercise(tmplId, choice.name, choice.consuming, false) <choiceArg> <cid> <actors> [tmpl.signatories] [tmpl.observers] [choice.controllers] [tmpl.key]
|
||||
// <retValue> = [update] <token>
|
||||
// _ = $endExercise[tmplId] <retValue>
|
||||
// in <retValue>
|
||||
topLevelFunction3(t.TemplateChoiceDefRef(tmplId, choice.name)) {
|
||||
(cidPos, choiceArgPos, tokenPos, env) =>
|
||||
translateChoiceBody(env, tmplId, optTargetTemplateId = None, tmpl, choice)(
|
||||
translateChoiceBody(env, tmplId, optTargetTemplateId, tmpl, choice)(
|
||||
choiceArgPos,
|
||||
cidPos,
|
||||
None,
|
||||
@ -643,27 +642,6 @@ private[lf] final class Compiler(
|
||||
)
|
||||
}
|
||||
|
||||
private[this] def compileSoftTemplateChoice(
|
||||
tmplId: TypeConName,
|
||||
tmpl: Template,
|
||||
predPids: List[PackageId],
|
||||
choice: TemplateChoice,
|
||||
): (t.SDefinitionRef, SDefinition) = {
|
||||
// TODO: https://github.com/digital-asset/daml/issues/17082
|
||||
// - predPids is ignored for milestone-1
|
||||
// - might be useful in following milestones
|
||||
val _ = predPids
|
||||
topLevelFunction3(t.SoftTemplateChoiceDefRef(tmplId, choice.name)) {
|
||||
(cidPos, choiceArgPos, tokenPos, env) =>
|
||||
translateChoiceBody(env, tmplId, optTargetTemplateId = Some(tmplId), tmpl, choice)(
|
||||
choiceArgPos,
|
||||
cidPos,
|
||||
None,
|
||||
tokenPos,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private[this] def compileChoiceController(
|
||||
typeId: TypeConName,
|
||||
contractVarName: ExprVarName,
|
||||
@ -766,33 +744,16 @@ private[lf] final class Compiler(
|
||||
private[this] def compileFetchTemplate(
|
||||
tmplId: Identifier,
|
||||
tmpl: Template,
|
||||
optTargetTemplateId: Option[TypeConName],
|
||||
): (t.SDefinitionRef, SDefinition) =
|
||||
topLevelFunction2(t.FetchTemplateDefRef(tmplId)) { (cidPos, tokenPos, env) =>
|
||||
translateFetchTemplateBody(env, tmplId, tmpl, optTargetTemplateId = None)(
|
||||
translateFetchTemplateBody(env, tmplId, tmpl, optTargetTemplateId)(
|
||||
cidPos,
|
||||
None,
|
||||
tokenPos,
|
||||
)
|
||||
}
|
||||
|
||||
private[this] def compileSoftFetchTemplate(
|
||||
tmplId: Identifier,
|
||||
tmpl: Template,
|
||||
predPids: List[PackageId],
|
||||
): (t.SDefinitionRef, SDefinition) = {
|
||||
// TODO: https://github.com/digital-asset/daml/issues/17082
|
||||
// - predPids is ignored for milestone-1
|
||||
// - might be useful in following milestones
|
||||
val _ = predPids
|
||||
topLevelFunction2(t.SoftFetchTemplateDefRef(tmplId)) { (cidPos, tokenPos, env) =>
|
||||
translateFetchTemplateBody(env, tmplId, tmpl, optTargetTemplateId = Some(tmplId))(
|
||||
cidPos,
|
||||
None,
|
||||
tokenPos,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private[this] def compileFetchInterface(ifaceId: Identifier): (t.SDefinitionRef, SDefinition) =
|
||||
topLevelFunction2(t.FetchInterfaceDefRef(ifaceId)) { (cidPos, _, env) =>
|
||||
let(
|
||||
|
@ -687,9 +687,11 @@ private[lf] final class PhaseOne(
|
||||
compileExp(env, coid) { coid =>
|
||||
Return(t.FetchTemplateDefRef(tmplId)(coid))
|
||||
}
|
||||
// TODO: https://github.com/digital-asset/daml/issues/17082
|
||||
// - Soft fetch now has identical behavior to normal fetch, and could be removed
|
||||
case UpdateSoftFetchTemplate(tmplId, coid) =>
|
||||
compileExp(env, coid) { coid =>
|
||||
Return(t.SoftFetchTemplateDefRef(tmplId)(coid))
|
||||
Return(t.FetchTemplateDefRef(tmplId)(coid))
|
||||
}
|
||||
case UpdateFetchInterface(ifaceId, coid) =>
|
||||
compileExp(env, coid) { coid =>
|
||||
@ -720,10 +722,12 @@ private[lf] final class PhaseOne(
|
||||
Return(t.TemplateChoiceDefRef(tmplId, chId)(cid, arg))
|
||||
}
|
||||
}
|
||||
// TODO: https://github.com/digital-asset/daml/issues/17082
|
||||
// - Soft exercise now has identical behavior to normal exercise, and could be removed
|
||||
case UpdateSoftExercise(tmplId, chId, cid, arg) =>
|
||||
compileExp(env, cid) { cid =>
|
||||
compileExp(env, arg) { arg =>
|
||||
Return(t.SoftTemplateChoiceDefRef(tmplId, chId)(cid, arg))
|
||||
Return(t.TemplateChoiceDefRef(tmplId, chId)(cid, arg))
|
||||
}
|
||||
}
|
||||
case UpdateDynamicExercise(tmplId, chId, cid, arg) =>
|
||||
|
@ -245,12 +245,10 @@ object Profile {
|
||||
implicit val interfaceInstanceMethodDefRef: Allowed[InterfaceInstanceMethodDefRef] = allowAll
|
||||
implicit val interfaceInstanceViewDefRef: Allowed[InterfaceInstanceViewDefRef] = allowAll
|
||||
implicit val templateChoiceDefRef: Allowed[TemplateChoiceDefRef] = allowAll
|
||||
implicit val softTemplateChoiceDefRef: Allowed[SoftTemplateChoiceDefRef] = allowAll
|
||||
implicit val interfaceChoiceDefRef: Allowed[InterfaceChoiceDefRef] = allowAll
|
||||
implicit val choiceControllerDefRef: Allowed[ChoiceControllerDefRef] = allowAll
|
||||
implicit val choiceObserverDefRef: Allowed[ChoiceObserverDefRef] = allowAll
|
||||
implicit val fetchTemplateDefRef: Allowed[FetchTemplateDefRef] = allowAll
|
||||
implicit val softFetchTemplateDefRef: Allowed[SoftFetchTemplateDefRef] = allowAll
|
||||
implicit val fetchInterfaceDefRef: Allowed[FetchInterfaceDefRef] = allowAll
|
||||
implicit val choiceByKeyDefRef: Allowed[ChoiceByKeyDefRef] = allowAll
|
||||
implicit val fetchByKeyDefRef: Allowed[FetchByKeyDefRef] = allowAll
|
||||
@ -285,7 +283,6 @@ object Profile {
|
||||
case InterfaceChoiceDefRef(ifaceRef, name) =>
|
||||
s"exercise @${ifaceRef.qualifiedName} ${name}"
|
||||
case FetchTemplateDefRef(tmplRef) => s"fetch_template @${tmplRef.qualifiedName}"
|
||||
case SoftFetchTemplateDefRef(tmplRef) => s"soft_fetch_template @${tmplRef.qualifiedName}"
|
||||
case FetchInterfaceDefRef(ifaceRef) => s"fetch_interface @${ifaceRef.qualifiedName}"
|
||||
case ChoiceByKeyDefRef(tmplRef, name) =>
|
||||
s"exerciseByKey @${tmplRef.qualifiedName} ${name}"
|
||||
|
@ -402,8 +402,6 @@ private[lf] object SExpr {
|
||||
// references to definitions generated by the Speedy compiler
|
||||
final case class TemplateChoiceDefRef(ref: DefinitionRef, choiceName: ChoiceName)
|
||||
extends SDefinitionRef
|
||||
final case class SoftTemplateChoiceDefRef(ref: DefinitionRef, choiceName: ChoiceName)
|
||||
extends SDefinitionRef
|
||||
final case class InterfaceChoiceDefRef(ref: DefinitionRef, choiceName: ChoiceName)
|
||||
extends SDefinitionRef
|
||||
final case class ChoiceByKeyDefRef(ref: DefinitionRef, choiceName: ChoiceName)
|
||||
@ -411,7 +409,6 @@ private[lf] object SExpr {
|
||||
final case class CreateDefRef(ref: DefinitionRef) extends SDefinitionRef
|
||||
final case class TemplatePreConditionDefRef(ref: DefinitionRef) extends SDefinitionRef
|
||||
final case class FetchTemplateDefRef(ref: DefinitionRef) extends SDefinitionRef
|
||||
final case class SoftFetchTemplateDefRef(ref: DefinitionRef) extends SDefinitionRef
|
||||
final case class FetchInterfaceDefRef(ref: DefinitionRef) extends SDefinitionRef
|
||||
|
||||
final case class FetchByKeyDefRef(ref: DefinitionRef) extends SDefinitionRef
|
||||
|
@ -7,7 +7,6 @@ package language
|
||||
import com.daml.lf.data.TemplateOrInterface
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.language.Ast._
|
||||
import scala.annotation.tailrec
|
||||
|
||||
private[lf] class PackageInterface(val signatures: PartialFunction[PackageId, PackageSignature]) {
|
||||
|
||||
@ -363,34 +362,6 @@ private[lf] class PackageInterface(val signatures: PartialFunction[PackageId, Pa
|
||||
|
||||
val packageLanguageVersion: PartialFunction[PackageId, LanguageVersion] =
|
||||
signatures andThen (_.languageVersion)
|
||||
|
||||
// TODO https://github.com/digital-asset/daml/issues/16151
|
||||
// Do some println debugging here to understand when lookupPackage fails,
|
||||
// exploring test failures which show up when using "-z" flag to restrict bazel test run, i.e.
|
||||
// bazel run //daml-script/test:test_test_suite_src_com_digitalasset_daml_lf_engine_script_test_PackageUpgradesIT.scala -- -z softEx
|
||||
private[this] def lookupPredecessors(
|
||||
pkgId: PackageId,
|
||||
context: => Reference,
|
||||
): Either[LookupError, List[PackageId]] = {
|
||||
@tailrec def preds(
|
||||
pkgId: PackageId,
|
||||
acc: List[PackageId],
|
||||
): Either[LookupError, List[PackageId]] = {
|
||||
lookupPackage(pkgId, context) match {
|
||||
case Left(err) => Left(err)
|
||||
case Right(pkg) =>
|
||||
pkg.metadata.flatMap(_.upgradedPackageId) match {
|
||||
case None => Right(acc)
|
||||
case Some(pkgId2) => preds(pkgId2, acc :+ pkgId2)
|
||||
}
|
||||
}
|
||||
}
|
||||
preds(pkgId, List.empty)
|
||||
}
|
||||
|
||||
def lookupPredecessors(pkgId: PackageId): Either[LookupError, List[PackageId]] =
|
||||
lookupPredecessors(pkgId, Reference.Package(pkgId))
|
||||
|
||||
}
|
||||
|
||||
object PackageInterface {
|
||||
|
@ -66,14 +66,14 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
}
|
||||
}
|
||||
|
||||
"softFetch" should {
|
||||
"Upgrading/fetch" should {
|
||||
"succeed when given a contract id of the same type Coin V1" in {
|
||||
for {
|
||||
clients <- scriptClients()
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_softFetch_v1"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_fetch_v1"),
|
||||
dar = coinUpgradeV1V2Dar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -85,7 +85,7 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_softFetch_v2"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_fetch_v2"),
|
||||
dar = coinUpgradeV1V2Dar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -97,7 +97,7 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_softFetch_v2"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_fetch_v2"),
|
||||
dar = coinUpgradeV1V2Dar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -109,7 +109,7 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_softFetch_v2"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_fetch_v2"),
|
||||
dar = coinUpgradeV1V2NewFieldDar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -121,7 +121,7 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_softFetch_v1"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_fetch_v1"),
|
||||
dar = coinUpgradeV1V2Dar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -133,7 +133,7 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_none_softFetch_v1"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_none_fetch_v1"),
|
||||
dar = coinUpgradeV1V2NewFieldDar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -145,7 +145,7 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_some_softFetch_v1"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_some_fetch_v1"),
|
||||
dar = coinUpgradeV1V2NewFieldDar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -157,7 +157,7 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_softFetch_v3"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_fetch_v3"),
|
||||
dar = coinUpgradeV1V3Dar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -169,21 +169,21 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v3_softFetch_v1"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v3_fetch_v1"),
|
||||
dar = coinUpgradeV1V3Dar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
}
|
||||
}
|
||||
|
||||
"softExercise" should {
|
||||
"upgrading/exercise" should {
|
||||
"succeed when given a contract id of the same type Coin V2" in {
|
||||
for {
|
||||
clients <- scriptClients()
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_softExercise_v2"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v2_exercise_v2"),
|
||||
dar = coinUpgradeV1V2Dar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
@ -194,7 +194,7 @@ final class DevIT extends AsyncWordSpec with AbstractScriptTest with Inside with
|
||||
r <-
|
||||
run(
|
||||
clients,
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_softExercise_v2"),
|
||||
QualifiedName.assertFromString("CoinUpgrade:create_v1_exercise_v2"),
|
||||
dar = coinUpgradeV1V2Dar,
|
||||
)
|
||||
} yield r shouldBe SUnit
|
||||
|
@ -15,34 +15,34 @@ template Aux
|
||||
where
|
||||
signatory party
|
||||
|
||||
choice SoftFetch_Coin_1 : (Text, Coin_1.Coin.Coin)
|
||||
choice Fetch_Coin_1 : (Text, Coin_1.Coin.Coin)
|
||||
with cid : ContractId Coin_1.Coin.Coin
|
||||
controller party
|
||||
do
|
||||
coin <- softFetch cid
|
||||
coin <- fetch cid
|
||||
pure $
|
||||
( "soft fetch v1\n" <> show coin
|
||||
( "fetch v1\n" <> show coin
|
||||
, coin
|
||||
)
|
||||
|
||||
choice SoftFetch_Coin_2 : (Text, Coin_2.Coin.Coin)
|
||||
choice Fetch_Coin_2 : (Text, Coin_2.Coin.Coin)
|
||||
with cid : ContractId Coin_2.Coin.Coin
|
||||
controller party
|
||||
do
|
||||
coin <- softFetch cid
|
||||
coin <- fetch cid
|
||||
pure $
|
||||
( "soft fetch v2\n" <> show coin
|
||||
( "fetch v2\n" <> show coin
|
||||
, coin
|
||||
)
|
||||
|
||||
create_v1_softFetch_v2 : Script ()
|
||||
create_v1_softFetch_v2 = do
|
||||
create_v1_fetch_v2 : Script ()
|
||||
create_v1_fetch_v2 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_1.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
(_, coin) <- alice `submit` createAndExerciseCmd (Aux alice) SoftFetch_Coin_2 with
|
||||
(_, coin) <- alice `submit` createAndExerciseCmd (Aux alice) Fetch_Coin_2 with
|
||||
cid = coerceContractId cid
|
||||
-- the new field is empty
|
||||
coin.ccy === None
|
||||
@ -50,26 +50,26 @@ create_v1_softFetch_v2 = do
|
||||
(coin with ccy = Some "USD").ccy === Some "USD"
|
||||
pure ()
|
||||
|
||||
create_v2_none_softFetch_v1 : Script ()
|
||||
create_v2_none_softFetch_v1 = do
|
||||
create_v2_none_fetch_v1 : Script ()
|
||||
create_v2_none_fetch_v1 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_2.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
ccy = None
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) SoftFetch_Coin_1 with -- Downgrade/drop-None
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) Fetch_Coin_1 with -- Downgrade/drop-None
|
||||
cid = coerceContractId cid
|
||||
pure ()
|
||||
|
||||
create_v2_some_softFetch_v1 : Script ()
|
||||
create_v2_some_softFetch_v1 = do
|
||||
create_v2_some_fetch_v1 : Script ()
|
||||
create_v2_some_fetch_v1 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_2.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
ccy = Some "CHF"
|
||||
_ <- alice `submitMustFail` createAndExerciseCmd (Aux alice) SoftFetch_Coin_1 with -- refuse Downgrade/drop-Some
|
||||
_ <- alice `submitMustFail` createAndExerciseCmd (Aux alice) Fetch_Coin_1 with -- refuse Downgrade/drop-Some
|
||||
cid = coerceContractId cid
|
||||
pure ()
|
||||
|
@ -7,124 +7,124 @@ import Daml.Script
|
||||
import Coin_1_0_0.Coin qualified
|
||||
import Coin_2_0_0.Coin qualified
|
||||
|
||||
template Aux -- for softFetch
|
||||
template Aux -- for fetch
|
||||
with
|
||||
party : Party
|
||||
where
|
||||
signatory party
|
||||
|
||||
choice SoftFetch_Coin_1_0_0 : (Text, Coin_1_0_0.Coin.Coin)
|
||||
choice Fetch_Coin_1_0_0 : (Text, Coin_1_0_0.Coin.Coin)
|
||||
with cid : ContractId Coin_1_0_0.Coin.Coin
|
||||
controller party
|
||||
do
|
||||
coin <- softFetch cid
|
||||
coin <- fetch cid
|
||||
pure $
|
||||
( "soft fetch v1\n" <> show coin
|
||||
( "fetch v1\n" <> show coin
|
||||
, coin
|
||||
)
|
||||
|
||||
choice SoftFetch_Coin_2_0_0 : (Text, Coin_2_0_0.Coin.Coin)
|
||||
choice Fetch_Coin_2_0_0 : (Text, Coin_2_0_0.Coin.Coin)
|
||||
with cid : ContractId Coin_2_0_0.Coin.Coin
|
||||
controller party
|
||||
do
|
||||
coin <- softFetch cid
|
||||
coin <- fetch cid
|
||||
pure $
|
||||
( "soft fetch v2\n" <> show coin
|
||||
( "fetch v2\n" <> show coin
|
||||
, coin
|
||||
)
|
||||
|
||||
create_v1_softFetch_v1 : Script ()
|
||||
create_v1_softFetch_v1 = do
|
||||
create_v1_fetch_v1 : Script ()
|
||||
create_v1_fetch_v1 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_1_0_0.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) SoftFetch_Coin_1_0_0 with
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) Fetch_Coin_1_0_0 with
|
||||
cid = cid
|
||||
pure ()
|
||||
|
||||
create_v2_softFetch_v2 : Script ()
|
||||
create_v2_softFetch_v2 = do
|
||||
create_v2_fetch_v2 : Script ()
|
||||
create_v2_fetch_v2 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_2_0_0.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) SoftFetch_Coin_2_0_0 with
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) Fetch_Coin_2_0_0 with
|
||||
cid = cid
|
||||
pure ()
|
||||
|
||||
create_v1_softFetch_v2 : Script ()
|
||||
create_v1_softFetch_v2 = do
|
||||
create_v1_fetch_v2 : Script ()
|
||||
create_v1_fetch_v2 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_1_0_0.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) SoftFetch_Coin_2_0_0 with -- Upgrade
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) Fetch_Coin_2_0_0 with -- Upgrade
|
||||
cid = coerceContractId cid
|
||||
pure ()
|
||||
|
||||
create_v2_softFetch_v1 : Script ()
|
||||
create_v2_softFetch_v1 = do
|
||||
create_v2_fetch_v1 : Script ()
|
||||
create_v2_fetch_v1 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_2_0_0.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) SoftFetch_Coin_1_0_0 with -- Downgrade
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) Fetch_Coin_1_0_0 with -- Downgrade
|
||||
cid = coerceContractId cid
|
||||
pure ()
|
||||
|
||||
|
||||
template Aux2 -- for softExercise
|
||||
template Aux2 -- for exercise
|
||||
with
|
||||
party : Party
|
||||
where
|
||||
signatory party
|
||||
|
||||
choice SoftExercise_Steal_1_0_0 : (Text, ContractId Coin_2_0_0.Coin.Coin)
|
||||
choice Exercise_Steal_1_0_0 : (Text, ContractId Coin_2_0_0.Coin.Coin)
|
||||
with cid : ContractId Coin_1_0_0.Coin.Coin
|
||||
controller party
|
||||
do
|
||||
let cid1 = coerceContractId @_ @Coin_2_0_0.Coin.Coin cid
|
||||
cid2 <- softExercise cid1 (Coin_2_0_0.Coin.V2Steal party)
|
||||
cid2 <- exercise cid1 (Coin_2_0_0.Coin.V2Steal party)
|
||||
pure $
|
||||
( "soft exercise v1\n"
|
||||
( "exercise v1\n"
|
||||
, cid2
|
||||
)
|
||||
|
||||
choice SoftExercise_Steal_2_0_0 : (Text, ContractId Coin_2_0_0.Coin.Coin)
|
||||
choice Exercise_Steal_2_0_0 : (Text, ContractId Coin_2_0_0.Coin.Coin)
|
||||
with cid : ContractId Coin_2_0_0.Coin.Coin
|
||||
controller party
|
||||
do
|
||||
cid2 <- softExercise cid (Coin_2_0_0.Coin.V2Steal party)
|
||||
cid2 <- exercise cid (Coin_2_0_0.Coin.V2Steal party)
|
||||
pure $
|
||||
( "soft exercise v2\n"
|
||||
( "exercise v2\n"
|
||||
, cid2
|
||||
)
|
||||
|
||||
create_v2_softExercise_v2 : Script ()
|
||||
create_v2_softExercise_v2 = do
|
||||
create_v2_exercise_v2 : Script ()
|
||||
create_v2_exercise_v2 = do
|
||||
alice <- allocateParty "alice"
|
||||
bob <- allocateParty "bob"
|
||||
cid <- alice `submit` createCmd Coin_2_0_0.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = [bob]
|
||||
_ <- bob `submit` createAndExerciseCmd (Aux2 bob) SoftExercise_Steal_2_0_0 with
|
||||
_ <- bob `submit` createAndExerciseCmd (Aux2 bob) Exercise_Steal_2_0_0 with
|
||||
cid = cid
|
||||
pure ()
|
||||
|
||||
create_v1_softExercise_v2 : Script ()
|
||||
create_v1_softExercise_v2 = do
|
||||
create_v1_exercise_v2 : Script ()
|
||||
create_v1_exercise_v2 = do
|
||||
alice <- allocateParty "alice"
|
||||
bob <- allocateParty "bob"
|
||||
cid <- alice `submit` createCmd Coin_1_0_0.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = [bob]
|
||||
_ <- bob `submit` createAndExerciseCmd (Aux2 bob) SoftExercise_Steal_1_0_0 with -- Upgrade
|
||||
_ <- bob `submit` createAndExerciseCmd (Aux2 bob) Exercise_Steal_1_0_0 with -- Upgrade
|
||||
cid = cid
|
||||
pure ()
|
||||
|
@ -13,44 +13,44 @@ template Aux
|
||||
where
|
||||
signatory party
|
||||
|
||||
choice SoftFetch_Coin_1_0_0 : (Text, Coin_1_0_0.Coin.Coin)
|
||||
choice Fetch_Coin_1_0_0 : (Text, Coin_1_0_0.Coin.Coin)
|
||||
with cid : ContractId Coin_1_0_0.Coin.Coin
|
||||
controller party
|
||||
do
|
||||
coin <- softFetch cid
|
||||
coin <- fetch cid
|
||||
pure $
|
||||
( "soft fetch v1\n" <> show coin
|
||||
, coin
|
||||
)
|
||||
|
||||
choice SoftFetch_Coin_3_0_0 : (Text, Coin_3_0_0.Coin.Coin)
|
||||
choice Fetch_Coin_3_0_0 : (Text, Coin_3_0_0.Coin.Coin)
|
||||
with cid : ContractId Coin_3_0_0.Coin.Coin
|
||||
controller party
|
||||
do
|
||||
coin <- softFetch cid
|
||||
coin <- fetch cid
|
||||
pure $
|
||||
( "soft fetch v3\n" <> show coin
|
||||
, coin
|
||||
)
|
||||
|
||||
create_v1_softFetch_v3 : Script ()
|
||||
create_v1_softFetch_v3 = do
|
||||
create_v1_fetch_v3 : Script ()
|
||||
create_v1_fetch_v3 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_1_0_0.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) SoftFetch_Coin_3_0_0 with -- Upgrade
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) Fetch_Coin_3_0_0 with -- Upgrade
|
||||
cid = coerceContractId cid
|
||||
pure ()
|
||||
|
||||
create_v3_softFetch_v1 : Script ()
|
||||
create_v3_softFetch_v1 = do
|
||||
create_v3_fetch_v1 : Script ()
|
||||
create_v3_fetch_v1 = do
|
||||
alice <- allocateParty "alice"
|
||||
cid <- alice `submit` createCmd Coin_3_0_0.Coin.Coin with
|
||||
issuer = alice
|
||||
owner = alice
|
||||
obs = []
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) SoftFetch_Coin_1_0_0 with -- Downgrade
|
||||
_ <- alice `submit` createAndExerciseCmd (Aux alice) Fetch_Coin_1_0_0 with -- Downgrade
|
||||
cid = coerceContractId cid
|
||||
pure ()
|
||||
|
@ -11,8 +11,3 @@ template Coin
|
||||
where
|
||||
signatory issuer, owner
|
||||
observer obs
|
||||
|
||||
|
||||
-- TODO https://github.com/digital-asset/daml/issues/16151
|
||||
instance HasSoftFetch Coin where
|
||||
_softFetch = GHC.Types.primitive @"USoftFetch"
|
||||
|
@ -16,7 +16,3 @@ template Coin
|
||||
nonconsuming choice V2Choice : ()
|
||||
controller owner
|
||||
do pure ()
|
||||
|
||||
-- TODO https://github.com/digital-asset/daml/issues/16151
|
||||
instance HasSoftFetch Coin where
|
||||
_softFetch = GHC.Types.primitive @"USoftFetch"
|
||||
|
@ -20,10 +20,3 @@ template Coin
|
||||
with newOwner : Party
|
||||
controller newOwner
|
||||
do create this with owner = newOwner
|
||||
|
||||
-- TODO https://github.com/digital-asset/daml/issues/16151
|
||||
instance HasSoftFetch Coin where
|
||||
_softFetch = GHC.Types.primitive @"USoftFetch"
|
||||
|
||||
instance HasSoftExercise Coin V2Steal (ContractId Coin) where
|
||||
_softExercise = GHC.Types.primitive @"USoftExercise"
|
||||
|
@ -19,7 +19,3 @@ template Coin
|
||||
nonconsuming choice V3Choice : ()
|
||||
controller owner
|
||||
do pure ()
|
||||
|
||||
-- TODO https://github.com/digital-asset/daml/issues/16151
|
||||
instance HasSoftFetch Coin where
|
||||
_softFetch = GHC.Types.primitive @"USoftFetch"
|
||||
|
@ -149,7 +149,7 @@
|
||||
- Evaluation order of successful lookup_by_key of a local contract: [EvaluationOrderTest.scala](daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/EvaluationOrderTest.scala#L3020)
|
||||
- Evaluation order of successful lookup_by_key of a non-cached global contract: [EvaluationOrderTest.scala](daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/EvaluationOrderTest.scala#L2865)
|
||||
- Exceptions, throw/catch.: [ExceptionTest.scala](daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/ExceptionTest.scala#L26)
|
||||
- Rollback creates cannot be exercise: [EngineTest.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/EngineTest.scala#L2079)
|
||||
- Rollback creates cannot be exercise: [EngineTest.scala](daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/EngineTest.scala#L2082)
|
||||
- This checks that type checking in exercise_interface is done after checking activeness.: [EvaluationOrderTest.scala](daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/EvaluationOrderTest.scala#L1933)
|
||||
- This checks that type checking is done after checking activeness.: [EvaluationOrderTest.scala](daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/EvaluationOrderTest.scala#L1823)
|
||||
- This checks that type checking is done after checking activeness.: [EvaluationOrderTest.scala](daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/EvaluationOrderTest.scala#L2809)
|
||||
|
Loading…
Reference in New Issue
Block a user