From 935c3fb10e9651476ca5804e17782c5458aa3096 Mon Sep 17 00:00:00 2001 From: dylant-da <106664681+dylant-da@users.noreply.github.com> Date: Thu, 23 May 2024 09:36:05 +0100 Subject: [PATCH] Expand upgrade validation testing (#19123) * Remove duplication from tests * lint * lint * Simplify tests * lint * add more tests for dependency behaviour * track new test files * lint * add test for failure being only emitted in the module that originates it * fix stdout capture for rules_daml * lint * lint * Move CannotUpgradeView into own section * Fix more upgrades gen --- sdk/compiler/damlc/tests/BUILD.bazel | 57 + .../damlc/tests/src/DA/Test/DamlcUpgrades.hs | 1273 +++-------------- sdk/daml-lf/validation/BUILD.bazel | 10 +- .../validation/upgrade/UpgradesSpecBase.scala | 12 +- sdk/rules_daml/daml.bzl | 10 +- sdk/test-common/BUILD.bazel | 125 +- .../upgrades/CannotUpgradeView/v1/Main.daml | 13 + .../upgrades/CannotUpgradeView/v2/Main.daml | 14 + .../v1/Main.daml | 7 + .../v1/Other.daml | 9 + .../v2/Main.daml | 7 + .../v2/Other.daml | 10 + .../v1/Main.daml | 18 + .../v2/Main.daml | 19 + .../dep-v1/Dep.daml | 10 + .../dep-v2/Dep.daml | 10 + .../v1/Main.daml | 15 + .../v2/Main.daml | 15 + .../daml/upgrades/MissingChoice/v1/Main.daml | 5 - .../daml/upgrades/MissingChoice/v2/Main.daml | 5 - .../daml/upgrades/MissingDataCon/v1/Main.daml | 5 - .../daml/upgrades/MissingDataCon/v2/Main.daml | 5 - .../daml/upgrades/MissingModule/v1/Main.daml | 6 - .../daml/upgrades/MissingModule/v1/Other.daml | 5 - .../daml/upgrades/MissingModule/v2/Main.daml | 5 - .../upgrades/MissingTemplate/v1/Main.daml | 5 - .../upgrades/MissingTemplate/v2/Main.daml | 5 - .../RecordFieldsNewNonOptional/v1/Main.daml | 5 - .../RecordFieldsNewNonOptional/v2/Main.daml | 5 - .../v1/Main.daml | 0 .../v2/Main.daml | 0 .../v1/Main.daml | 6 + .../v2/Main.daml | 6 + .../v1/Main.daml | 0 .../v2/Main.daml | 6 + .../v1/Main.daml | 6 + .../v2/Main.daml | 0 .../dep-v1/Dep.daml | 15 + .../dep-v2/Dep.daml | 18 + .../v1/Main.daml | 23 + .../v2/Main.daml | 23 + .../TemplateChangedKeyType/v1/Main.daml | 5 - .../TemplateChangedKeyType/v2/Main.daml | 5 - .../daml/upgrades/ValidUpgrade/v1/Main.daml | 5 - .../daml/upgrades/ValidUpgrade/v2/Main.daml | 5 - .../v1/Main.daml | 5 + .../v2/Main.daml | 13 + .../v1/Main.daml | 9 + .../v2/Main.daml | 14 + .../v1/Main.daml | 5 + .../v2/Main.daml | 16 + .../v1/Main.daml | 13 + .../v2/Main.daml | 13 + .../v1/Main.daml | 14 + .../v2/Main.daml | 14 + .../v1/Main.daml | 11 + .../v2/Main.daml | 11 + .../v1/Main.daml | 12 + .../v2/Main.daml | 12 + .../v1/Main.daml | 12 + .../v2/Main.daml | 12 + .../v1/Main.daml | 11 + .../v2/Main.daml | 11 + .../v1/Main.daml | 9 + .../v2/Main.daml | 9 + 65 files changed, 864 insertions(+), 1175 deletions(-) create mode 100644 sdk/test-common/src/main/daml/upgrades/CannotUpgradeView/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/CannotUpgradeView/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v1/Other.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v2/Other.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChange/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChange/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/dep-v1/Dep.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/dep-v2/Dep.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/v2/Main.daml rename sdk/test-common/src/main/daml/upgrades/{FailsWhenATopLevelEnumChanges => SucceedWhenATopLevelEnumAddsAField}/v1/Main.daml (100%) rename sdk/test-common/src/main/daml/upgrades/{FailsWhenATopLevelEnumChanges => SucceedWhenATopLevelEnumAddsAField}/v2/Main.daml (100%) create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelEnumChanges/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelEnumChanges/v2/Main.daml rename sdk/test-common/src/main/daml/upgrades/{FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType => SucceedsWhenATopLevelVariantAddsAVariant}/v1/Main.daml (100%) create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAVariant/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v1/Main.daml rename sdk/test-common/src/main/daml/upgrades/{FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType => SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType}/v2/Main.daml (100%) create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/dep-v1/Dep.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/dep-v2/Dep.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenControllersOfTemplateChoiceAreChanged/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenControllersOfTemplateChoiceAreChanged/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenObserversOfTemplateChoiceAreChanged/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenObserversOfTemplateChoiceAreChanged/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesEnsure/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesEnsure/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyExpression/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyExpression/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyMaintainers/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyMaintainers/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesObservers/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesObservers/v2/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesSignatories/v1/Main.daml create mode 100644 sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesSignatories/v2/Main.daml diff --git a/sdk/compiler/damlc/tests/BUILD.bazel b/sdk/compiler/damlc/tests/BUILD.bazel index 3c9a5acaf8e4..dd6ca6333ab4 100644 --- a/sdk/compiler/damlc/tests/BUILD.bazel +++ b/sdk/compiler/damlc/tests/BUILD.bazel @@ -446,10 +446,67 @@ da_haskell_test( da_haskell_test( name = "upgrades", srcs = ["src/DA/Test/DamlcUpgrades.hs"], + compiler_flags = ["-Wno-unused-local-binds"], data = [ "//compiler/damlc", "//daml-script/daml:daml-script.dar", "//daml-script/runner:daml-script-binary", + "//test-common:upgrades-CannotUpgradeView-files", + "//test-common:upgrades-FailWhenATopLevelEnumChangesChangesTheOrderOfItsVariants-files", + "//test-common:upgrades-FailWhenATopLevelVariantChangesChangesTheOrderOfItsVariants-files", + "//test-common:upgrades-FailsOnlyInModuleNotInReexports-files", + "//test-common:upgrades-FailsWhenATopLevelRecordAddsANonOptionalField-files", + "//test-common:upgrades-FailsWhenATopLevelRecordAddsAnOptionalFieldBeforeTheEnd-files", + "//test-common:upgrades-FailsWhenATopLevelVariantAddsAFieldToAVariantsType-files", + "//test-common:upgrades-FailsWhenATopLevelVariantAddsAVariant-files", + "//test-common:upgrades-FailsWhenATopLevelVariantRemovesAVariant-files", + "//test-common:upgrades-FailsWhenAnInstanceIsDropped-files", + "//test-common:upgrades-FailsWhenAnInterfaceIsDefinedInAnUpgradingPackageWhenItWasAlreadyInThePriorPackage-files", + "//test-common:upgrades-FailsWhenExistingFieldInTemplateChoiceIsChanged-files", + "//test-common:upgrades-FailsWhenExistingFieldInTemplateIsChanged-files", + "//test-common:upgrades-FailsWhenNewFieldIsAddedToTemplateChoiceWithoutOptionalType-files", + "//test-common:upgrades-FailsWhenNewFieldIsAddedToTemplateWithoutOptionalType-files", + "//test-common:upgrades-FailsWhenOldFieldIsDeletedFromTemplate-files", + "//test-common:upgrades-FailsWhenOldFieldIsDeletedFromTemplateChoice-files", + "//test-common:upgrades-FailsWhenTemplateAddsKeyType-files", + "//test-common:upgrades-FailsWhenTemplateChangesKeyType-files", + "//test-common:upgrades-FailsWhenTemplateChoiceChangesItsReturnType-files", + "//test-common:upgrades-FailsWhenTemplateRemovesKeyType-files", + "//test-common:upgrades-FailsWhenTwoDeeplyNestedTypeSynonymsResolveToDifferentDatatypes-files", + "//test-common:upgrades-FailsWithSynonymReturnTypeChange-files", + "//test-common:upgrades-FailsWithSynonymReturnTypeChangeInSeparatePackage-files", + "//test-common:upgrades-MissingChoice-files", + "//test-common:upgrades-MissingDataCon-files", + "//test-common:upgrades-MissingModule-files", + "//test-common:upgrades-MissingTemplate-files", + "//test-common:upgrades-RecordFieldsNewNonOptional-files", + "//test-common:upgrades-SucceedWhenATopLevelEnumAddsAField-files", + "//test-common:upgrades-SucceedsWhenATopLevelEnumChanges-files", + "//test-common:upgrades-SucceedsWhenATopLevelRecordAddsAnOptionalFieldAtTheEnd-files", + "//test-common:upgrades-SucceedsWhenATopLevelTypeSynonymChanges-files", + "//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAVariant-files", + "//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-files", + "//test-common:upgrades-SucceedsWhenAnInstanceIsAddedSeparateDep-files", + "//test-common:upgrades-SucceedsWhenAnInstanceIsAddedUpgradedPackage-files", + "//test-common:upgrades-SucceedsWhenAnInterfaceIsOnlyDefinedInTheInitialPackage-files", + "//test-common:upgrades-SucceedsWhenNewFieldWithOptionalTypeIsAddedToTemplate-files", + "//test-common:upgrades-SucceedsWhenNewFieldWithOptionalTypeIsAddedToTemplateChoice-files", + "//test-common:upgrades-SucceedsWhenTemplateChoiceInputArgumentHasChanged-files", + "//test-common:upgrades-SucceedsWhenTemplateChoiceReturnsATemplateWhichHasChanged-files", + "//test-common:upgrades-SucceedsWhenTwoDeeplyNestedTypeSynonymsResolveToTheSameDatatypes-files", + "//test-common:upgrades-SucceedsWhenUpgradingADependency-files", + "//test-common:upgrades-TemplateChangedKeyType-files", + "//test-common:upgrades-ValidUpgrade-files", + "//test-common:upgrades-WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage-files", + "//test-common:upgrades-WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt-files", + "//test-common:upgrades-WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn-files", + "//test-common:upgrades-WarnsWhenControllersOfTemplateChoiceAreChanged-files", + "//test-common:upgrades-WarnsWhenObserversOfTemplateChoiceAreChanged-files", + "//test-common:upgrades-WarnsWhenTemplateChangesEnsure-files", + "//test-common:upgrades-WarnsWhenTemplateChangesKeyExpression-files", + "//test-common:upgrades-WarnsWhenTemplateChangesKeyMaintainers-files", + "//test-common:upgrades-WarnsWhenTemplateChangesObservers-files", + "//test-common:upgrades-WarnsWhenTemplateChangesSignatories-files", ], hackage_deps = [ "base", diff --git a/sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs b/sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs index 8b1ca9938c73..026ef3ce698e 100644 --- a/sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs +++ b/sdk/compiler/damlc/tests/src/DA/Test/DamlcUpgrades.hs @@ -19,6 +19,11 @@ import SdkVersion (SdkVersioned, sdkVersion, withSdkVersions) import Text.Regex.TDFA import qualified Data.Text as T import Safe (fromJustNote) +import Prelude hiding (unlines) +import qualified Prelude + +unlines :: [String] -> IO String +unlines = pure . Prelude.unlines main :: IO () main = withSdkVersions $ do @@ -30,1222 +35,280 @@ tests damlc = testGroup "Upgrade" [ test - "Warns when template changes signatories" - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template MyLib.A signatories:\n The upgraded template A has changed the definition of its signatories.") + "WarnsWhenTemplateChangesSignatories" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template Main.A signatories:\n The upgraded template A has changed the definition of its signatories.") + LF.versionDefault + NoDependencies + , test + "WarnsWhenTemplateChangesObservers" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template Main.A observers:\n The upgraded template A has changed the definition of its observers.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where signatory [p]" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where signatory [p, q]" - ] - ) - ] , test - "Warns when template changes observers" - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template MyLib.A observers:\n The upgraded template A has changed the definition of its observers.") + "SucceedsWhenATopLevelEnumChanges" + Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " observer p" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " observer p, q" - ] - ) - ] , test - "Warns when template changes ensure" - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template MyLib.A precondition:\n The upgraded template A has changed the definition of its precondition.") + "WarnsWhenTemplateChangesEnsure" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template Main.A precondition:\n The upgraded template A has changed the definition of its precondition.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " ensure True" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " ensure True == True" - ] - ) - ] , test - "Warns when template changes key expression" - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template MyLib.A key:\n The upgraded template A has changed the expression for computing its key.") + "WarnsWhenTemplateChangesKeyExpression" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template Main.A key:\n The upgraded template A has changed the expression for computing its key.") contractKeysMinVersion NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " key (p, \"example\") : (Party, Text)" - , " maintainer (fst key)" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " key (q, \"example\") : (Party, Text)" - , " maintainer (fst key)" - ] - ) - ] , test - "Warns when template changes key maintainers" - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template MyLib.A key:\n The upgraded template A has changed the maintainers for its key.") + "WarnsWhenTemplateChangesKeyMaintainers" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template Main.A key:\n The upgraded template A has changed the maintainers for its key.") contractKeysMinVersion NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " key (p, q) : (Party, Party)" - , " maintainer (fst key)" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " key (p, q) : (Party, Party)" - , " maintainer (snd key)" - ] - ) - ] , test - "Fails when template changes key type" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A key:\n The upgraded template A cannot change its key type.") + "FailsWhenTemplateChangesKeyType" + (FailWithError "\ESC\\[0;91merror type checking template Main.A key:\n The upgraded template A cannot change its key type.") contractKeysMinVersion NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " key (p, \"text\") : (Party, Text)" - , " maintainer (fst key)" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " key (p, 1) : (Party, Int)" - , " maintainer (fst key)" - ] - ) - ] , test - "Fails when template removes key type" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A key:\n The upgraded template A cannot remove its key.") + "FailsWhenTemplateRemovesKeyType" + (FailWithError "\ESC\\[0;91merror type checking template Main.A key:\n The upgraded template A cannot remove its key.") contractKeysMinVersion NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " key (p, \"text\") : (Party, Text)" - , " maintainer (fst key)" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - ] - ) - ] , test - "Fails when template adds key type" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A key:\n The upgraded template A cannot add a key where it didn't have one previously.") + "FailsWhenTemplateAddsKeyType" + (FailWithError "\ESC\\[0;91merror type checking template Main.A key:\n The upgraded template A cannot add a key where it didn't have one previously.") contractKeysMinVersion NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " key (p, \"text\") : (Party, Text)" - , " maintainer (fst key)" - ] - ) - ] , test - "Fails when new field is added to template without Optional type" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A :\n The upgraded template A has added new fields, but those fields are not Optional.") + "FailsWhenNewFieldIsAddedToTemplateWithoutOptionalType" + (FailWithError "\ESC\\[0;91merror type checking template Main.A :\n The upgraded template A has added new fields, but those fields are not Optional.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " existing1 : Int" - , " existing2 : Int" - , " where signatory p" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " existing1 : Int" - , " existing2 : Int" - , " new : Int" - , " where signatory p" - ] - ) - ] , test - "Fails when old field is deleted from template" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A :\n The upgraded template A is missing some of its original fields.") + "FailsWhenOldFieldIsDeletedFromTemplate" + (FailWithError "\ESC\\[0;91merror type checking template Main.A :\n The upgraded template A is missing some of its original fields.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " existing1 : Int" - , " existing2 : Int" - , " where signatory p" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " existing2 : Int" - , " where signatory p" - ] - ) - ] , test - "Fails when existing field in template is changed" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A :\n The upgraded template A has changed the types of some of its original fields.") + "FailsWhenExistingFieldInTemplateIsChanged" + (FailWithError "\ESC\\[0;91merror type checking template Main.A :\n The upgraded template A has changed the types of some of its original fields.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " existing1 : Int" - , " existing2 : Int" - , " where signatory p" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " existing1 : Text" - , " existing2 : Int" - , " where signatory p" - ] - ) - ] , test - "Succeeds when new field with optional type is added to template" + "SucceedsWhenNewFieldWithOptionalTypeIsAddedToTemplate" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " existing1 : Int" - , " existing2 : Int" - , " where signatory p" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " existing1 : Int" - , " existing2 : Int" - , " new : Optional Int" - , " where signatory p" - ] - ) - ] , test - "Fails when new field is added to template choice without Optional type" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A choice C:\n The upgraded input type of choice C on template A has added new fields, but those fields are not Optional.") + "FailsWhenNewFieldIsAddedToTemplateChoiceWithoutOptionalType" + (FailWithError "\ESC\\[0;91merror type checking template Main.A choice C:\n The upgraded input type of choice C on template A has added new fields, but those fields are not Optional.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing1 : Int" - , " existing2 : Int" - , " controller p" - , " do pure ()" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing1 : Int" - , " existing2 : Int" - , " new : Int" - , " controller p" - , " do pure ()" - ] - ) - ] , test - "Fails when old field is deleted from template choice" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A choice C:\n The upgraded input type of choice C on template A is missing some of its original fields.") + "FailsWhenOldFieldIsDeletedFromTemplateChoice" + (FailWithError "\ESC\\[0;91merror type checking template Main.A choice C:\n The upgraded input type of choice C on template A is missing some of its original fields.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing1 : Int" - , " existing2 : Int" - , " controller p" - , " do pure ()" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing2 : Int" - , " controller p" - , " do pure ()" - ] - ) - ] , test - "Fails when existing field in template choice is changed" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A choice C:\n The upgraded input type of choice C on template A has changed the types of some of its original fields.") + "FailsWhenExistingFieldInTemplateChoiceIsChanged" + (FailWithError "\ESC\\[0;91merror type checking template Main.A choice C:\n The upgraded input type of choice C on template A has changed the types of some of its original fields.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing1 : Int" - , " existing2 : Int" - , " controller p" - , " do pure ()" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing1 : Text" - , " existing2 : Int" - , " controller p" - , " do pure ()" - ] - ) - ] , test - "Warns when controllers of template choice are changed" - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template MyLib.A choice C:\n The upgraded choice C has changed the definition of controllers.") + "WarnsWhenControllersOfTemplateChoiceAreChanged" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template Main.A choice C:\n The upgraded choice C has changed the definition of controllers.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " controller p" - , " do pure ()" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " controller p, q" - , " do pure ()" - ] - ) - ] , test - "Warns when observers of template choice are changed" - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template MyLib.A choice C:\n The upgraded choice C has changed the definition of observers.") + "WarnsWhenObserversOfTemplateChoiceAreChanged" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template Main.A choice C:\n The upgraded choice C has changed the definition of observers.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " observer p" - , " controller p" - , " do pure ()" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " observer p, q" - , " controller p" - , " do pure ()" - ] - ) - ] , test - "Fails when template choice changes its return type" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A choice C:\n The upgraded choice C cannot change its return type.") + "FailsWhenTemplateChoiceChangesItsReturnType" + (FailWithError "\ESC\\[0;91merror type checking template Main.A choice C:\n The upgraded choice C cannot change its return type.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing1 : Int" - , " existing2 : Int" - , " controller p" - , " do pure ()" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : Int" - , " with" - , " existing1 : Int" - , " existing2 : Int" - , " controller p" - , " do pure 1" - ] - ) - ] , test - "Succeeds when template choice returns a template which has changed" + "SucceedsWhenTemplateChoiceReturnsATemplateWhichHasChanged" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : A" - , " controller p" - , " do pure (A p)" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Optional Party" - , " where" - , " signatory p" - , " choice C : A" - , " controller p" - , " do pure (A p (Some p))" - ] - ) - ] , test - "Succeeds when template choice input argument has changed" + "SucceedsWhenTemplateChoiceInputArgumentHasChanged" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " tpl : A" - , " controller p" - , " do pure ()" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " q : Optional Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " tpl : A" - , " controller p" - , " do pure ()" - ] - ) - ] , test - "Succeeds when new field with optional type is added to template choice" + "SucceedsWhenNewFieldWithOptionalTypeIsAddedToTemplateChoice" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing1 : Int" - , " existing2 : Int" - , " controller p" - , " do pure ()" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template A with" - , " p : Party" - , " where" - , " signatory p" - , " choice C : ()" - , " with" - , " existing1 : Int" - , " existing2 : Int" - , " new : Optional Int" - , " controller p" - , " do pure ()" - ] - ) - ] , test - "Fails when a top-level record adds a non-optional field" - (FailWithError "\ESC\\[0;91merror type checking data type MyLib.A:\n The upgraded data type A has added new fields, but those fields are not Optional.") + "FailsWhenATopLevelRecordAddsANonOptionalField" + (FailWithError "\ESC\\[0;91merror type checking data type Main.A:\n The upgraded data type A has added new fields, but those fields are not Optional.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = A { x : Int }" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = A { x : Int, y : Text }" - ] - ) - ] , test - "Succeeds when a top-level record adds an optional field at the end" + "SucceedsWhenATopLevelRecordAddsAnOptionalFieldAtTheEnd" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = A { x : Int }" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = A { x : Int, y : Optional Text }" - ] - ) - ] , test - "Fails when a top-level record adds an optional field before the end" - (FailWithError "\ESC\\[0;91merror type checking data type MyLib.A:\n The upgraded data type A has changed the order of its fields - any new fields must be added at the end of the record.") + "FailsWhenATopLevelRecordAddsAnOptionalFieldBeforeTheEnd" + (FailWithError "\ESC\\[0;91merror type checking data type Main.A:\n The upgraded data type A has changed the order of its fields - any new fields must be added at the end of the record.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = A { x : Int }" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = A { y : Optional Text, x : Int }" - ] - ) - ] , test - "Succeeds when a top-level variant adds a variant" + "SucceedsWhenATopLevelVariantAddsAVariant" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int }" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int } | Z { z : Int }" - ] - ) - ] , test - "Fails when a top-level variant removes a variant" + "FailsWhenATopLevelVariantRemovesAVariant" (FailWithError "\ESC\\[0;91merror type checking :\n Data type A.Z appears in package that is being upgraded, but does not appear in this package.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int } | Z { z : Int }" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int }" - ] - ) - ] , test - "Fail when a top-level variant changes changes the order of its variants" - (FailWithError "\ESC\\[0;91merror type checking data type MyLib.A:\n The upgraded data type A has changed the order of its variants - any new variant must be added at the end of the variant.") + "FailWhenATopLevelVariantChangesChangesTheOrderOfItsVariants" + (FailWithError "\ESC\\[0;91merror type checking data type Main.A:\n The upgraded data type A has changed the order of its variants - any new variant must be added at the end of the variant.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Z { z : Int } | Y { y : Int }" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int } | Z { z : Int }" - ] - ) - ] , test - "Fails when a top-level variant adds a field to a variant's type" - (FailWithError "\ESC\\[0;91merror type checking data type MyLib.A:\n The upgraded variant constructor Y from variant A has added a field.") + "FailsWhenATopLevelVariantAddsAFieldToAVariantsType" + (FailWithError "\ESC\\[0;91merror type checking data type Main.A:\n The upgraded variant constructor Y from variant A has added a field.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int }" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int, y2 : Int }" - ] - ) - ] , test - "Succeeds when a top-level variant adds an optional field to a variant's type" + "SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int }" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X { x : Int } | Y { y : Int, y2 : Optional Int }" - ] - ) - ] , test - "Succeed when a top-level enum adds a field" + "SucceedWhenATopLevelEnumAddsAField" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X | Y" - ] - ) - ] , test - "Fail when a top-level enum changes changes the order of its variants" - (FailWithError "\ESC\\[0;91merror type checking data type MyLib.A:\n The upgraded data type A has changed the order of its variants - any new variant must be added at the end of the enum.") + "FailWhenATopLevelEnumChangesChangesTheOrderOfItsVariants" + (FailWithError "\ESC\\[0;91merror type checking data type Main.A:\n The upgraded data type A has changed the order of its variants - any new variant must be added at the end of the enum.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X | Y | Z" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data A = X | Z | Y" - ] - ) - ] , test - "Succeeds when a top-level type synonym changes" + "SucceedsWhenATopLevelTypeSynonymChanges" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data X = X" - , "data Y = Y" - , "type A = X" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data X = X" - , "data Y = Y" - , "type A = Y" - ] - ) - ] , test - "Succeeds when two deeply nested type synonyms resolve to the same datatypes" + "SucceedsWhenTwoDeeplyNestedTypeSynonymsResolveToTheSameDatatypes" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "type Synonym1 a = (a, Synonym3)" - , "type Synonym2 = Int" - , "type Synonym3 = Text" - , "template A with" - , " p : Party" - , " q : Synonym1 Synonym2" - , " where signatory [p]" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "type Synonym1 a = (Synonym2, a)" - , "type Synonym2 = Int" - , "template A with" - , " p : Party" - , " q : Synonym1 Text" - , " where signatory [p]" - ] - ) - ] , test - "Fails when two deeply nested type synonyms resolve to different datatypes" - (FailWithError "\ESC\\[0;91merror type checking template MyLib.A :\n The upgraded template A has changed the types of some of its original fields.") + "FailsWhenTwoDeeplyNestedTypeSynonymsResolveToDifferentDatatypes" + (FailWithError "\ESC\\[0;91merror type checking template Main.A :\n The upgraded template A has changed the types of some of its original fields.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "type Synonym1 a = (a, Synonym3)" - , "type Synonym2 = Int" - , "type Synonym3 = Text" - , "template A with" - , " p : Party" - , " q : Synonym1 Synonym2" - , " where signatory [p]" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "type Synonym1 a = (a, Synonym3)" - , "type Synonym2 = Text" - , "type Synonym3 = Int" - , "template A with" - , " p : Party" - , " q : Synonym1 Synonym2" - , " where signatory [p]" - ] - ) - ] , test - "Succeeds when an interface is only defined in the initial package." + "SucceedsWhenAnInterfaceIsOnlyDefinedInTheInitialPackage" Succeed LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data IView = IView { i : Text }" -- TODO: Do we also want to ignore dropped viewtypes? - ] - ) - ] , test - "Fails when an interface is defined in an upgrading package when it was already in the prior package." - (FailWithError "\ESC\\[0;91merror type checking interface MyLib.I :\n Tried to upgrade interface I, but interfaces cannot be upgraded. They should be removed in any upgrading package.") + "FailsWhenAnInterfaceIsDefinedInAnUpgradingPackageWhenItWasAlreadyInThePriorPackage" + (FailWithError "\ESC\\[0;91merror type checking interface Main.I :\n Tried to upgrade interface I, but interfaces cannot be upgraded. They should be removed in any upgrading package.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - ] - ) - ] , test - "Warns when an interface and a template are defined in the same package." - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking module MyLib:\n This package defines both interfaces and templates.\n \n This is not recommended - templates are upgradeable, but interfaces are not, which means that this version of the package and its templates can never be uninstalled.\n \n It is recommended that interfaces are defined in their own package separate from their implementations.") + "WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking module Main:\n This package defines both interfaces and templates.\n \n This is not recommended - templates are upgradeable, but interfaces are not, which means that this version of the package and its templates can never be uninstalled.\n \n It is recommended that interfaces are defined in their own package separate from their implementations.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - ] - ) - ] , test - "Warns when an interface is used in the package that it's defined in." - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking interface MyLib.I :\n The interface I was defined in this package and implemented in this package by the following templates:\n \n 'T'\n \n However, it is recommended that interfaces are defined in their own package separate from their implementations.") + "WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking interface Main.I :\n The interface I was defined in this package and implemented in this package by the following templates:\n \n 'T'\n \n However, it is recommended that interfaces are defined in their own package separate from their implementations.") LF.versionDefault NoDependencies - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - , " interface instance I for T where" - , " view = IView \"hi\"" - , " method1 = 2" - ] - ) - ] , test - "Warns when an interface is defined and then used in a package that upgrades it." - (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template MyLib.T interface instance [0-9a-f]+:MyLib:I for MyLib:T:\n The template T has implemented interface I, which is defined in a previous version of this package.") + "WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt" + (SucceedWithWarning "\ESC\\[0;93mwarning while type checking template Main.T interface instance [0-9a-f]+:Main:I for Main:T:\n The template T has implemented interface I, which is defined in a previous version of this package.") LF.versionDefault DependOnV1 - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "import qualified \"mylib-v1\" MyLib as V1" - , "data IView = IView { i : Text }" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - , " interface instance V1.I for T where" - , " view = V1.IView \"hi\"" - , " method1 = 2" - ] - ) - ] , test - "Fails when an instance is dropped." - (FailWithError "\ESC\\[0;91merror type checking template MyLib.T :\n Implementation of interface I by template T appears in package that is being upgraded, but does not appear in this package.") + "FailsWhenAnInstanceIsDropped" + (FailWithError "\ESC\\[0;91merror type checking template Main.T :\n Implementation of interface I by template T appears in package that is being upgraded, but does not appear in this package.") LF.versionDefault - (SeparateDep [ - ( "daml/Dep.daml" - , unlines - [ "module Dep where" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - ] - ) - ]) - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "import Dep" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - , " interface instance I for T where" - , " view = IView \"hi\"" - , " method1 = 2" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "import Dep" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - ] - ) - ] + SeparateDep , test - "Succeeds when an instance is added (separate dep)." + "SucceedsWhenAnInstanceIsAddedSeparateDep" Succeed LF.versionDefault - (SeparateDep [ - ( "daml/Dep.daml" - , unlines - [ "module Dep where" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - ] - ) - ]) - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "import Dep" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - ] - ) - ] - [ ("daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "import Dep" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - , " interface instance I for T where" - , " view = IView \"hi\"" - , " method1 = 2" - ] - ) - ] + SeparateDep , test - "Succeeds when an instance is added (upgraded package)." + "SucceedsWhenAnInstanceIsAddedUpgradedPackage" Succeed LF.versionDefault DependOnV1 - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - ] - ) - ] - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "import qualified \"mylib-v1\" MyLib as V1" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - , " interface instance V1.I for T where" - , " view = V1.IView \"hi\"" - , " method1 = 2" - , "data IView = IView { i : Text }" - ] - ) - ] , test - "Cannot upgrade view" + "CannotUpgradeView" (FailWithError ".*Tried to implement a view of type (‘|\915\199\255)IView(’|\915\199\214) on interface (‘|\915\199\255)V1.I(’|\915\199\214), but the definition of interface (‘|\915\199\255)V1.I(’|\915\199\214) requires a view of type (‘|\915\199\255)V1.IView(’|\915\199\214)") LF.versionDefault DependOnV1 - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - , "data IView = IView { i : Text }" - , "interface I where" - , " viewtype IView" - , " method1 : Int" - ] - ) - ] - [ ( "daml/MyLib.daml" - , unlines - [ "module MyLib where" - , "import qualified \"mylib-v1\" MyLib as V1" - , "template T with" - , " p: Party" - , " where" - , " signatory p" - , " interface instance V1.I for T where" - , " view = IView \"hi\" None" - , " method1 = 2" - , "data IView = IView { i : Text, other : Optional Text }" - ] - ) - ] + , test + "ValidUpgrade" + Succeed + contractKeysMinVersion + NoDependencies + , test + "MissingModule" + (FailWithError "\ESC\\[0;91merror type checking :\n Module Other appears in package that is being upgraded, but does not appear in this package.") + LF.versionDefault + NoDependencies + , test + "MissingTemplate" + (FailWithError "\ESC\\[0;91merror type checking :\n Template U appears in package that is being upgraded, but does not appear in this package.") + LF.versionDefault + NoDependencies + , test + "MissingDataCon" + (FailWithError "\ESC\\[0;91merror type checking :\n Data type U appears in package that is being upgraded, but does not appear in this package.") + LF.versionDefault + NoDependencies + , test + "MissingChoice" + (FailWithError "\ESC\\[0;91merror type checking template Main.T :\n Choice C2 appears in package that is being upgraded, but does not appear in this package.") + LF.versionDefault + NoDependencies + , test + "TemplateChangedKeyType" + (FailWithError "\ESC\\[0;91merror type checking template Main.T key:\n The upgraded template T cannot change its key type.") + contractKeysMinVersion + NoDependencies + , test + "RecordFieldsNewNonOptional" + (FailWithError "\ESC\\[0;91merror type checking data type Main.Struct:\n The upgraded data type Struct has added new fields, but those fields are not Optional.") + LF.versionDefault + NoDependencies + , test + "FailsWithSynonymReturnTypeChange" + (FailWithError "\ESC\\[0;91merror type checking template Main.T choice C:\n The upgraded choice C cannot change its return type.") + LF.versionDefault + NoDependencies + , test + "FailsWithSynonymReturnTypeChangeInSeparatePackage" + (FailWithError "\ESC\\[0;91merror type checking template Main.T choice C:\n The upgraded choice C cannot change its return type.") + LF.versionDefault + SeparateDeps + , test + "SucceedsWhenUpgradingADependency" + Succeed + LF.versionDefault + SeparateDeps + , test + "FailsOnlyInModuleNotInReexports" + (FailWithError "\ESC\\[0;91merror type checking data type Other.A:\n The upgraded data type A has added new fields, but those fields are not Optional.") + LF.versionDefault + NoDependencies ] where contractKeysMinVersion :: LF.Version @@ -1253,15 +316,14 @@ tests damlc = fromJustNote "Expected at least one LF 2.x version to support contract keys." (LF.featureMinVersion LF.featureContractKeys LF.V2) + test :: String -> Expectation -> LF.Version -> Dependency - -> [(FilePath, String)] - -> [(FilePath, String)] -> TestTree - test name expectation lfVersion sharedDep oldVersion newVersion = + test name expectation lfVersion sharedDep = testCase name $ withTempDir $ \dir -> do let newDir = dir "newVersion" @@ -1269,22 +331,62 @@ tests damlc = let newDar = newDir "out.dar" let oldDar = oldDir "old.dar" + let testRunfile path = locateRunfiles (mainWorkspace "test-common/src/main/daml/upgrades" path) + + v1FilePaths <- listDirectory =<< testRunfile (name "v1") + let oldVersion = flip map v1FilePaths $ \path -> + ( "daml" path + , readFile =<< testRunfile (name "v1" path) + ) + v2FilePaths <- listDirectory =<< testRunfile (name "v2") + let newVersion = flip map v2FilePaths $ \path -> + ( "daml" path + , readFile =<< testRunfile (name "v2" path) + ) + (depV1Dar, depV2Dar) <- case sharedDep of - SeparateDep sharedDep -> do + SeparateDep -> do + depFilePaths <- listDirectory =<< testRunfile (name "dep") + let sharedDepFiles = flip map depFilePaths $ \path -> + ( "daml" path + , readFile =<< testRunfile (name "dep" path) + ) let sharedDir = dir "shared" let sharedDar = sharedDir "out.dar" - writeFiles sharedDir (projectFile lfVersion "mylib-shared" Nothing Nothing : sharedDep) + writeFiles sharedDir (projectFile lfVersion ("upgrades-example-" <> name <> "-dep") Nothing Nothing : sharedDepFiles) callProcessSilent damlc ["build", "--project-root", sharedDir, "-o", sharedDar] pure (Just sharedDar, Just sharedDar) + SeparateDeps -> do + depV1FilePaths <- listDirectory =<< testRunfile (name "dep-v1") + let depV1Files = flip map depV1FilePaths $ \path -> + ( "daml" path + , readFile =<< testRunfile (name "dep-v1" path) + ) + let depV1Dir = dir "shared-v1" + let depV1Dar = depV1Dir "out.dar" + writeFiles depV1Dir (projectFile lfVersion ("upgrades-example-" <> name <> "-dep-v1") Nothing Nothing : depV1Files) + callProcessSilent damlc ["build", "--project-root", depV1Dir, "-o", depV1Dar] + + depV2FilePaths <- listDirectory =<< testRunfile (name "dep-v2") + let depV2Files = flip map depV2FilePaths $ \path -> + ( "daml" path + , readFile =<< testRunfile (name "dep-v2" path) + ) + let depV2Dir = dir "shared-v2" + let depV2Dar = depV2Dir "out.dar" + writeFiles depV2Dir (projectFile lfVersion ("upgrades-example-" <> name <> "-dep-v2") Nothing Nothing : depV2Files) + callProcessSilent damlc ["build", "--project-root", depV2Dir, "-o", depV2Dar] + + pure (Just depV1Dar, Just depV2Dar) DependOnV1 -> pure (Nothing, Just oldDar) _ -> pure (Nothing, Nothing) - writeFiles oldDir (projectFile lfVersion "mylib-v1" Nothing depV1Dar : oldVersion) + writeFiles oldDir (projectFile lfVersion ("upgrades-example-" <> name) Nothing depV1Dar : oldVersion) callProcessSilent damlc ["build", "--project-root", oldDir, "-o", oldDar] - writeFiles newDir (projectFile lfVersion "mylib-v2" (Just oldDar) depV2Dar : newVersion) + writeFiles newDir (projectFile lfVersion ("upgrades-example-" <> name <> "-v2") (Just oldDar) depV2Dar : newVersion) case expectation of Succeed -> callProcessSilent damlc ["build", "--project-root", newDir, "-o", newDar] @@ -1304,7 +406,8 @@ tests damlc = assertFailure ("`daml build` succeeded, but did not give a warning matching '" <> show regexWithSeverity <> "':\n" <> show stderr) writeFiles dir fs = - for_ fs $ \(file, content) -> do + for_ fs $ \(file, ioContent) -> do + content <- ioContent createDirectoryIfMissing True (takeDirectory $ dir file) writeFileUTF8 (dir file) content @@ -1335,5 +438,5 @@ data Expectation data Dependency = NoDependencies | DependOnV1 - | SeparateDep [(FilePath, String)] - deriving (Show, Eq, Ord) + | SeparateDep + | SeparateDeps diff --git a/sdk/daml-lf/validation/BUILD.bazel b/sdk/daml-lf/validation/BUILD.bazel index 0cb11c2ea2ba..80616c8a76ae 100644 --- a/sdk/daml-lf/validation/BUILD.bazel +++ b/sdk/daml-lf/validation/BUILD.bazel @@ -189,16 +189,16 @@ da_scala_test_suite( "//test-common:upgrades-FailsWhenUpgradingV3ThenV2-v3.dar", # More tests ported from DamlcUpgrades.hs - "//test-common:upgrades-FailsWhenATopLevelEnumChanges-v1.dar", - "//test-common:upgrades-FailsWhenATopLevelEnumChanges-v2.dar", + "//test-common:upgrades-SucceedsWhenATopLevelEnumChanges-v1.dar", + "//test-common:upgrades-SucceedsWhenATopLevelEnumChanges-v2.dar", "//test-common:upgrades-FailsWhenATopLevelRecordAddsANonOptionalField-v1.dar", "//test-common:upgrades-FailsWhenATopLevelRecordAddsANonOptionalField-v2.dar", "//test-common:upgrades-FailsWhenATopLevelRecordAddsAnOptionalFieldBeforeTheEnd-v1.dar", "//test-common:upgrades-FailsWhenATopLevelRecordAddsAnOptionalFieldBeforeTheEnd-v2.dar", "//test-common:upgrades-FailsWhenATopLevelVariantAddsAFieldToAVariantsType-v1.dar", "//test-common:upgrades-FailsWhenATopLevelVariantAddsAFieldToAVariantsType-v2.dar", - "//test-common:upgrades-FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v1.dar", - "//test-common:upgrades-FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v2.dar", + "//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v1.dar", + "//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v2.dar", "//test-common:upgrades-FailsWhenATopLevelVariantAddsAVariant-v1.dar", "//test-common:upgrades-FailsWhenATopLevelVariantAddsAVariant-v2.dar", "//test-common:upgrades-FailsWhenATopLevelVariantRemovesAVariant-v1.dar", @@ -231,6 +231,8 @@ da_scala_test_suite( "//test-common:upgrades-SucceedsWhenAnInstanceIsAddedSeparateDep-v2.dar", "//test-common:upgrades-SucceedsWhenAnInstanceIsAddedUpgradedPackage-v1.dar", "//test-common:upgrades-SucceedsWhenAnInstanceIsAddedUpgradedPackage-v2.dar", + "//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAVariant-v1.dar", + "//test-common:upgrades-SucceedsWhenATopLevelVariantAddsAVariant-v2.dar", ], flaky = True, scala_deps = [ diff --git a/sdk/daml-lf/validation/src/test/scala/com/daml/lf/validation/upgrade/UpgradesSpecBase.scala b/sdk/daml-lf/validation/src/test/scala/com/daml/lf/validation/upgrade/UpgradesSpecBase.scala index 051f1abe9acf..2c2da59b2863 100644 --- a/sdk/daml-lf/validation/src/test/scala/com/daml/lf/validation/upgrade/UpgradesSpecBase.scala +++ b/sdk/daml-lf/validation/src/test/scala/com/daml/lf/validation/upgrade/UpgradesSpecBase.scala @@ -411,8 +411,8 @@ trait LongTests { this: UpgradesSpec => "Succeeds when a top-level variant adds a variant" in { testPackagePair( - "test-common/upgrades-FailsWhenATopLevelVariantAddsAVariant-v1.dar", - "test-common/upgrades-FailsWhenATopLevelVariantAddsAVariant-v2.dar", + "test-common/upgrades-SucceedsWhenATopLevelVariantAddsAVariant-v1.dar", + "test-common/upgrades-SucceedsWhenATopLevelVariantAddsAVariant-v2.dar", assertPackageUpgradeCheck(None), ) } @@ -453,16 +453,16 @@ trait LongTests { this: UpgradesSpec => "Succeeds when a top-level variant adds an optional field to a variant's type" in { testPackagePair( - "test-common/upgrades-FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v1.dar", - "test-common/upgrades-FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v2.dar", + "test-common/upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v1.dar", + "test-common/upgrades-SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType-v2.dar", assertPackageUpgradeCheck(None), ) } "Succeeds when a top-level enum changes" in { testPackagePair( - "test-common/upgrades-FailsWhenATopLevelEnumChanges-v1.dar", - "test-common/upgrades-FailsWhenATopLevelEnumChanges-v2.dar", + "test-common/upgrades-SucceedsWhenATopLevelEnumChanges-v1.dar", + "test-common/upgrades-SucceedsWhenATopLevelEnumChanges-v2.dar", assertPackageUpgradeCheck(None), ) } diff --git a/sdk/rules_daml/daml.bzl b/sdk/rules_daml/daml.bzl index eecc001c0489..9cd8f6c1b2bb 100644 --- a/sdk/rules_daml/daml.bzl +++ b/sdk/rules_daml/daml.bzl @@ -113,12 +113,13 @@ def _daml_build_impl(ctx): damlc = ctx.executable.damlc input_dars = [file_of_target(k) for k in dar_dict.keys()] output_dar = ctx.outputs.dar + output_stdout = ctx.outputs.stdout posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"] ghc_opts = ctx.attr.ghc_options ctx.actions.run_shell( tools = [damlc], inputs = [daml_yaml] + srcs + input_dars, - outputs = [output_dar], + outputs = [output_dar] + ([output_stdout] if output_stdout != None else []), progress_message = "Building Daml project %s" % name, command = """ set -eou pipefail @@ -131,7 +132,7 @@ def _daml_build_impl(ctx): {sed} -i 's/daml-script$/daml-script.dar/;s/daml3-script$/daml3-script.dar/;s/daml-trigger$/daml-trigger.dar/' $tmpdir/daml.yaml {cp_srcs} {cp_dars} - {damlc} build --project-root $tmpdir {ghc_opts} -o $PWD/{output_dar} + {damlc} build --project-root $tmpdir {ghc_opts} -o $PWD/{output_dar} 2>&1 | {output_stdout_command} """.format( config = daml_yaml.path, cp_srcs = "\n".join([ @@ -152,6 +153,7 @@ def _daml_build_impl(ctx): sed = posix.commands["sed"], damlc = damlc.path, output_dar = output_dar.path, + output_stdout_command = "tee " + output_stdout.path if output_stdout != None else "cat", sdk_version = sdk_version, ghc_opts = " ".join(ghc_opts), ), @@ -179,6 +181,9 @@ _daml_build = rule( mandatory = True, doc = "The generated DAR file.", ), + "stdout": attr.output( + doc = "The standard output of the build command.", + ), "ghc_options": attr.string_list( doc = "Options passed to GHC.", default = ["--ghc-option=-Werror", "--log-level=WARNING"], @@ -348,6 +353,7 @@ def daml_compile( dar_dict = {dar: path_to_dar(dar) for dar in (dependencies + data_dependencies + ([upgrades] if upgrades else []))}, dar = name + ".dar", + stdout = name + ".stdout", ghc_options = ghc_options + (["--enable-scenarios=yes"] if enable_scenarios and (target == None or _supports_scenarios(target)) else []) + diff --git a/sdk/test-common/BUILD.bazel b/sdk/test-common/BUILD.bazel index 2584ec89171e..72570ff60adf 100644 --- a/sdk/test-common/BUILD.bazel +++ b/sdk/test-common/BUILD.bazel @@ -69,6 +69,11 @@ da_scala_dar_resources_library( [ [ + filegroup( + name = "upgrades-{}-files".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/*/*.daml".format(identifier)]), + visibility = ["//visibility:public"], + ), daml_compile( name = "upgrades-{}-v1".format(identifier), srcs = glob(["src/main/daml/upgrades/{}/v1/*.daml".format(identifier)]), @@ -122,11 +127,10 @@ da_scala_dar_resources_library( "SucceedsWhenTemplateChoiceReturnsATemplateWhichHasChanged", # More tests ported from DamlcUpgrades.hs - "FailsWhenATopLevelEnumChanges", + "SucceedsWhenATopLevelEnumChanges", "FailsWhenATopLevelRecordAddsANonOptionalField", "FailsWhenATopLevelRecordAddsAnOptionalFieldBeforeTheEnd", "FailsWhenATopLevelVariantAddsAFieldToAVariantsType", - "FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType", "FailsWhenATopLevelVariantAddsAVariant", "FailsWhenATopLevelVariantRemovesAVariant", "FailsWhenTwoDeeplyNestedTypeSynonymsResolveToDifferentDatatypes", @@ -141,11 +145,30 @@ da_scala_dar_resources_library( # More more more tests ported from DamlcUpgrades.hs "FailsWhenAnInterfaceIsDefinedInAnUpgradingPackageWhenItWasAlreadyInThePriorPackage", "SucceedsWhenAnInterfaceIsOnlyDefinedInTheInitialPackage", + "SucceedWhenATopLevelEnumAddsAField", + "SucceedsWhenATopLevelVariantAddsAVariant", + "SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType", + "WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage", + "WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn", + "WarnsWhenControllersOfTemplateChoiceAreChanged", + "WarnsWhenObserversOfTemplateChoiceAreChanged", + "WarnsWhenTemplateChangesEnsure", + "WarnsWhenTemplateChangesKeyExpression", + "WarnsWhenTemplateChangesKeyMaintainers", + "WarnsWhenTemplateChangesObservers", + "WarnsWhenTemplateChangesSignatories", + "FailsWithSynonymReturnTypeChange", + "FailsOnlyInModuleNotInReexports", ] ] [ [ + filegroup( + name = "upgrades-{}-files".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/*/*.daml".format(identifier)]), + visibility = ["//visibility:public"], + ), daml_compile( name = "upgrades-{}-v1".format(identifier), srcs = glob(["src/main/daml/upgrades/{}/v1/*.daml".format(identifier)]), @@ -177,11 +200,99 @@ da_scala_dar_resources_library( for identifier in [ # More more more tests ported from DamlcUpgrades.hs "SucceedsWhenAnInstanceIsAddedUpgradedPackage", + "WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt", + ] +] + +[ + [ + filegroup( + name = "upgrades-{}-files".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/*/*.daml".format(identifier)]), + visibility = ["//visibility:public"], + ), + ] + for identifier in [ + "CannotUpgradeView", + ] +] + +[ + [ + filegroup( + name = "upgrades-{}-files".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/*/*.daml".format(identifier)]), + visibility = ["//visibility:public"], + ), + daml_compile( + name = "upgrades-{}-dep-v1".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/dep-v1/*.daml".format(identifier)]), + dependencies = ["//daml-script/daml:daml-script-2.dev.dar"], + enable_interfaces = True, + ghc_options = default_damlc_opts + ["--ghc-option=-Wno-unused-imports"], + project_name = "upgrades-example-{}-dep".format(identifier), + target = "2.dev", + version = "1.0.0", + visibility = ["//visibility:public"], + ), + daml_compile( + name = "upgrades-{}-dep-v2".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/dep-v2/*.daml".format(identifier)]), + dependencies = ["//daml-script/daml:daml-script-2.dev.dar"], + enable_interfaces = True, + ghc_options = default_damlc_opts + ["--ghc-option=-Wno-unused-imports"], + project_name = "upgrades-example-{}-dep".format(identifier), + target = "2.dev", + # We want to check the validity of this upgrade on the ledger + # client, not during compilation + typecheck_upgrades = False, + upgrades = "//test-common:upgrades-{}-dep-v1.dar".format(identifier), + version = "2.0.0", + visibility = ["//visibility:public"], + ), + daml_compile( + name = "upgrades-{}-v1".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/v1/*.daml".format(identifier)]), + data_dependencies = ["//test-common:upgrades-{}-dep-v1.dar".format(identifier)], + dependencies = ["//daml-script/daml:daml-script-2.dev.dar"], + enable_interfaces = True, + ghc_options = default_damlc_opts + ["--ghc-option=-Wno-unused-imports"], + project_name = "upgrades-example-{}".format(identifier), + target = "2.dev", + version = "1.0.0", + visibility = ["//visibility:public"], + ), + daml_compile( + name = "upgrades-{}-v2".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/v2/*.daml".format(identifier)]), + data_dependencies = ["//test-common:upgrades-{}-dep-v2.dar".format(identifier)], + dependencies = ["//daml-script/daml:daml-script-2.dev.dar"], + enable_interfaces = True, + ghc_options = default_damlc_opts + ["--ghc-option=-Wno-unused-imports"], + project_name = "upgrades-example-{}".format(identifier), + target = "2.dev", + # We want to check the validity of this upgrade on the ledger + # client, not during compilation + typecheck_upgrades = False, + upgrades = "//test-common:upgrades-{}-v1.dar".format(identifier), + version = "2.0.0", + visibility = ["//visibility:public"], + ), + ] + for identifier in [ + # More more more tests ported from DamlcUpgrades.hs + "FailsWithSynonymReturnTypeChangeInSeparatePackage", + "SucceedsWhenUpgradingADependency", ] ] [ [ + filegroup( + name = "upgrades-{}-files".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/*/*.daml".format(identifier)]), + visibility = ["//visibility:public"], + ), daml_compile( name = "upgrades-{}-dep".format(identifier), srcs = glob(["src/main/daml/upgrades/{}/dep/*.daml".format(identifier)]), @@ -231,6 +342,11 @@ da_scala_dar_resources_library( [ [ + filegroup( + name = "upgrades-{}-files".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/*/*.daml".format(identifier)]), + visibility = ["//visibility:public"], + ), daml_compile( name = "upgrades-{}-v1a".format(identifier), srcs = glob(["src/main/daml/upgrades/{}/v1a/*.daml".format(identifier)]), @@ -257,6 +373,11 @@ da_scala_dar_resources_library( [ [ + filegroup( + name = "upgrades-{}-files".format(identifier), + srcs = glob(["src/main/daml/upgrades/{}/*/*.daml".format(identifier)]), + visibility = ["//visibility:public"], + ), daml_compile( name = "upgrades-{}-v1".format(identifier), srcs = glob(["src/main/daml/upgrades/{}/v1/*.daml".format(identifier)]), diff --git a/sdk/test-common/src/main/daml/upgrades/CannotUpgradeView/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/CannotUpgradeView/v1/Main.daml new file mode 100644 index 000000000000..f07b10baf4d4 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/CannotUpgradeView/v1/Main.daml @@ -0,0 +1,13 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template T with + p: Party + where + signatory p +data IView = IView { i : Text } +interface I where + viewtype IView + method1 : Int + diff --git a/sdk/test-common/src/main/daml/upgrades/CannotUpgradeView/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/CannotUpgradeView/v2/Main.daml new file mode 100644 index 000000000000..be9d88b92b47 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/CannotUpgradeView/v2/Main.daml @@ -0,0 +1,14 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +import qualified "upgrades-example-CannotUpgradeView" Main as V1 +template T with + p: Party + where + signatory p + interface instance V1.I for T where + view = IView "hi" None + method1 = 2 +data IView = IView { i : Text, other : Optional Text } + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v1/Main.daml new file mode 100644 index 000000000000..ada6af57cd94 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v1/Main.daml @@ -0,0 +1,7 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main (module Other) where + +import Other + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v1/Other.daml b/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v1/Other.daml new file mode 100644 index 000000000000..efc0fbb2e8e8 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v1/Other.daml @@ -0,0 +1,9 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Other where + +data A = A + { field1 : Text + } + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v2/Main.daml new file mode 100644 index 000000000000..ada6af57cd94 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v2/Main.daml @@ -0,0 +1,7 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main (module Other) where + +import Other + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v2/Other.daml b/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v2/Other.daml new file mode 100644 index 000000000000..caa50e4090d2 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsOnlyInModuleNotInReexports/v2/Other.daml @@ -0,0 +1,10 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Other where + +data A = A + { field1 : Text + , field2 : Text + } + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChange/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChange/v1/Main.daml new file mode 100644 index 000000000000..4d91d5c3dfab --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChange/v1/Main.daml @@ -0,0 +1,18 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + +data A = A { a : Text } +data B = B { b : Text } + +type Synonym = A + +template T with + p : Party + where + signatory p + choice C : Synonym + controller p + do pure A { a = "a" } + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChange/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChange/v2/Main.daml new file mode 100644 index 000000000000..53b76e838296 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChange/v2/Main.daml @@ -0,0 +1,19 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + +data A = A { a : Text } +data B = B { b : Text } + +type Synonym = B + +template T with + p : Party + where + signatory p + choice C : Synonym + controller p + do pure B { b = "b" } + + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/dep-v1/Dep.daml b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/dep-v1/Dep.daml new file mode 100644 index 000000000000..58d4ac25b780 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/dep-v1/Dep.daml @@ -0,0 +1,10 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Dep where + +data A = A { a : Text } +data B = B { b : Text } + +type Synonym = A + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/dep-v2/Dep.daml b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/dep-v2/Dep.daml new file mode 100644 index 000000000000..b9fb4060b9f7 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/dep-v2/Dep.daml @@ -0,0 +1,10 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Dep where + +data A = A { a : Text } +data B = B { b : Text } + +type Synonym = B + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/v1/Main.daml new file mode 100644 index 000000000000..bc5bfa126e09 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/v1/Main.daml @@ -0,0 +1,15 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + +import Dep + +template T with + p: Party + where + signatory p + choice C : Synonym + controller p + do pure $ A { a = "a" } + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/v2/Main.daml new file mode 100644 index 000000000000..39aacb25df53 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/FailsWithSynonymReturnTypeChangeInSeparatePackage/v2/Main.daml @@ -0,0 +1,15 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + +import Dep + +template T with + p: Party + where + signatory p + choice C : Synonym + controller p + do pure $ B { b = "b" } + diff --git a/sdk/test-common/src/main/daml/upgrades/MissingChoice/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/MissingChoice/v1/Main.daml index 5488dd55b9db..8ecd086ae70b 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingChoice/v1/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingChoice/v1/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - template T with p: Party where diff --git a/sdk/test-common/src/main/daml/upgrades/MissingChoice/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/MissingChoice/v2/Main.daml index fbabcbce46c1..19f2491646ea 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingChoice/v2/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingChoice/v2/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - template T with p: Party where diff --git a/sdk/test-common/src/main/daml/upgrades/MissingDataCon/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/MissingDataCon/v1/Main.daml index 7e5f60caf327..886cad2f0080 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingDataCon/v1/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingDataCon/v1/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - data T = T with x : Text deriving Show diff --git a/sdk/test-common/src/main/daml/upgrades/MissingDataCon/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/MissingDataCon/v2/Main.daml index 0e20db3b6914..2cfbe6c313fa 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingDataCon/v2/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingDataCon/v2/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - data T = T with x : Text deriving Show diff --git a/sdk/test-common/src/main/daml/upgrades/MissingModule/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/MissingModule/v1/Main.daml index e7db69662574..5f88aa189e2b 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingModule/v1/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingModule/v1/Main.daml @@ -4,9 +4,3 @@ module Main where import qualified Other -import Daml.Script - -main : Script () -main = do - Other.main - pure () diff --git a/sdk/test-common/src/main/daml/upgrades/MissingModule/v1/Other.daml b/sdk/test-common/src/main/daml/upgrades/MissingModule/v1/Other.daml index d692821bc0bd..f4fa58717388 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingModule/v1/Other.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingModule/v1/Other.daml @@ -2,8 +2,3 @@ -- SPDX-License-Identifier: Apache-2.0 module Other where - -import Daml.Script - -main : Script () -main = pure () diff --git a/sdk/test-common/src/main/daml/upgrades/MissingModule/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/MissingModule/v2/Main.daml index 772e8c36aa4f..a7636046e676 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingModule/v2/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingModule/v2/Main.daml @@ -2,8 +2,3 @@ -- SPDX-License-Identifier: Apache-2.0 module Main where - -import Daml.Script - -main : Script () -main = pure () diff --git a/sdk/test-common/src/main/daml/upgrades/MissingTemplate/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/MissingTemplate/v1/Main.daml index 04fe4e672e47..8b8e4a421285 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingTemplate/v1/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingTemplate/v1/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - template T with p: Party where diff --git a/sdk/test-common/src/main/daml/upgrades/MissingTemplate/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/MissingTemplate/v2/Main.daml index 77190b073d9b..02c51e5c42b4 100644 --- a/sdk/test-common/src/main/daml/upgrades/MissingTemplate/v2/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/MissingTemplate/v2/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - template T with p: Party where diff --git a/sdk/test-common/src/main/daml/upgrades/RecordFieldsNewNonOptional/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/RecordFieldsNewNonOptional/v1/Main.daml index 527c512771c3..004722c0fa4d 100644 --- a/sdk/test-common/src/main/daml/upgrades/RecordFieldsNewNonOptional/v1/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/RecordFieldsNewNonOptional/v1/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - data Struct = Struct with field1 : Int diff --git a/sdk/test-common/src/main/daml/upgrades/RecordFieldsNewNonOptional/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/RecordFieldsNewNonOptional/v2/Main.daml index b0e06aac9e1f..e639371f8a42 100644 --- a/sdk/test-common/src/main/daml/upgrades/RecordFieldsNewNonOptional/v2/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/RecordFieldsNewNonOptional/v2/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - data Struct = Struct with field1 : Int field2 : Text diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWhenATopLevelEnumChanges/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedWhenATopLevelEnumAddsAField/v1/Main.daml similarity index 100% rename from sdk/test-common/src/main/daml/upgrades/FailsWhenATopLevelEnumChanges/v1/Main.daml rename to sdk/test-common/src/main/daml/upgrades/SucceedWhenATopLevelEnumAddsAField/v1/Main.daml diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWhenATopLevelEnumChanges/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedWhenATopLevelEnumAddsAField/v2/Main.daml similarity index 100% rename from sdk/test-common/src/main/daml/upgrades/FailsWhenATopLevelEnumChanges/v2/Main.daml rename to sdk/test-common/src/main/daml/upgrades/SucceedWhenATopLevelEnumAddsAField/v2/Main.daml diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelEnumChanges/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelEnumChanges/v1/Main.daml new file mode 100644 index 000000000000..1fba083b6247 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelEnumChanges/v1/Main.daml @@ -0,0 +1,6 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +data A = X + diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelEnumChanges/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelEnumChanges/v2/Main.daml new file mode 100644 index 000000000000..1b2b9aa82761 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelEnumChanges/v2/Main.daml @@ -0,0 +1,6 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +data A = X | Y + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAVariant/v1/Main.daml similarity index 100% rename from sdk/test-common/src/main/daml/upgrades/FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v1/Main.daml rename to sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAVariant/v1/Main.daml diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAVariant/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAVariant/v2/Main.daml new file mode 100644 index 000000000000..5f201a879182 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAVariant/v2/Main.daml @@ -0,0 +1,6 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +data A = X { x : Int } | Y { y : Int } | Z { z : Int } + diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v1/Main.daml new file mode 100644 index 000000000000..1fe0744b41f6 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v1/Main.daml @@ -0,0 +1,6 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +data A = X { x : Int } | Y { y : Int } + diff --git a/sdk/test-common/src/main/daml/upgrades/FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v2/Main.daml similarity index 100% rename from sdk/test-common/src/main/daml/upgrades/FailsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v2/Main.daml rename to sdk/test-common/src/main/daml/upgrades/SucceedsWhenATopLevelVariantAddsAnOptionalFieldToAVariantsType/v2/Main.daml diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/dep-v1/Dep.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/dep-v1/Dep.daml new file mode 100644 index 000000000000..79c8872021a4 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/dep-v1/Dep.daml @@ -0,0 +1,15 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Dep where + +data D = D { field1 : Text } + +template T with + p: Party + where + signatory p + choice C1 : D + controller p + do pure $ D "field1" + diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/dep-v2/Dep.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/dep-v2/Dep.daml new file mode 100644 index 000000000000..be20d39e3bbe --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/dep-v2/Dep.daml @@ -0,0 +1,18 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Dep where + +data D = D { field1 : Text, field2 : Optional Text } + +template T with + p: Party + where + signatory p + choice C1 : D + controller p + do pure $ D "field1" (Some "field2") + choice C2 : D + controller p + do pure $ D "field1" None + diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/v1/Main.daml new file mode 100644 index 000000000000..889d1cdb4805 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/v1/Main.daml @@ -0,0 +1,23 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + +import qualified Dep + +data D = D { field1 : Text } + +template T with + p: Party + t: ContractId Dep.T + where + signatory p + choice C1 : D + controller p + do + depD <- exercise t Dep.C1 + pure $ D "field1" + choice C2 : Dep.D + controller p + do exercise t Dep.C1 + diff --git a/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/v2/Main.daml new file mode 100644 index 000000000000..a355f8b74993 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/SucceedsWhenUpgradingADependency/v2/Main.daml @@ -0,0 +1,23 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + +import qualified Dep + +data D = D { field1 : Text, field2 : Optional Dep.D } + +template T with + p: Party + t: ContractId Dep.T + where + signatory p + choice C1 : D + controller p + do + depD <- exercise t Dep.C1 -- only works when party is same + pure $ D "field1" (Some depD) + choice C2 : Dep.D + controller p + do exercise t Dep.C2 -- only works when party is same + diff --git a/sdk/test-common/src/main/daml/upgrades/TemplateChangedKeyType/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/TemplateChangedKeyType/v1/Main.daml index a7d4b1ee4525..4c2dd24e4af5 100644 --- a/sdk/test-common/src/main/daml/upgrades/TemplateChangedKeyType/v1/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/TemplateChangedKeyType/v1/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - data TKey1 = TKey1 with p : Party data TKey2 = TKey2 with p : Party diff --git a/sdk/test-common/src/main/daml/upgrades/TemplateChangedKeyType/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/TemplateChangedKeyType/v2/Main.daml index eade83bd37e6..b4d112d4cf6a 100644 --- a/sdk/test-common/src/main/daml/upgrades/TemplateChangedKeyType/v2/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/TemplateChangedKeyType/v2/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - data TKey1 = TKey1 with p : Party data TKey2 = TKey2 with p : Party diff --git a/sdk/test-common/src/main/daml/upgrades/ValidUpgrade/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/ValidUpgrade/v1/Main.daml index 948ce155fbc8..d4beca6008a6 100644 --- a/sdk/test-common/src/main/daml/upgrades/ValidUpgrade/v1/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/ValidUpgrade/v1/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - data TKey1 = TKey1 { p : Party } template T with diff --git a/sdk/test-common/src/main/daml/upgrades/ValidUpgrade/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/ValidUpgrade/v2/Main.daml index 4510354ac742..fdb078a9218c 100644 --- a/sdk/test-common/src/main/daml/upgrades/ValidUpgrade/v2/Main.daml +++ b/sdk/test-common/src/main/daml/upgrades/ValidUpgrade/v2/Main.daml @@ -3,11 +3,6 @@ module Main where -import Daml.Script - -main : Script () -main = pure () - data TKey1 = TKey1 with p : Party diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage/v1/Main.daml new file mode 100644 index 000000000000..9ffb76bf00d7 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage/v1/Main.daml @@ -0,0 +1,5 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage/v2/Main.daml new file mode 100644 index 000000000000..8a8517388b83 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceAndATemplateAreDefinedInTheSamePackage/v2/Main.daml @@ -0,0 +1,13 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +data IView = IView { i : Text } +interface I where + viewtype IView + method1 : Int +template T with + p: Party + where + signatory p + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt/v1/Main.daml new file mode 100644 index 000000000000..2a757470c530 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt/v1/Main.daml @@ -0,0 +1,9 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +data IView = IView { i : Text } +interface I where + viewtype IView + method1 : Int + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt/v2/Main.daml new file mode 100644 index 000000000000..1cdbcf1688e8 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt/v2/Main.daml @@ -0,0 +1,14 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +import qualified "upgrades-example-WarnsWhenAnInterfaceIsDefinedAndThenUsedInAPackageThatUpgradesIt" Main as V1 +data IView = IView { i : Text } +template T with + p: Party + where + signatory p + interface instance V1.I for T where + view = V1.IView "hi" + method1 = 2 + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn/v1/Main.daml new file mode 100644 index 000000000000..9ffb76bf00d7 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn/v1/Main.daml @@ -0,0 +1,5 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn/v2/Main.daml new file mode 100644 index 000000000000..74856ffdb82f --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenAnInterfaceIsUsedInThePackageThatItsDefinedIn/v2/Main.daml @@ -0,0 +1,16 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +data IView = IView { i : Text } +interface I where + viewtype IView + method1 : Int +template T with + p: Party + where + signatory p + interface instance I for T where + view = IView "hi" + method1 = 2 + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenControllersOfTemplateChoiceAreChanged/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenControllersOfTemplateChoiceAreChanged/v1/Main.daml new file mode 100644 index 000000000000..0d086a78a689 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenControllersOfTemplateChoiceAreChanged/v1/Main.daml @@ -0,0 +1,13 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + choice C : () + controller p + do pure () + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenControllersOfTemplateChoiceAreChanged/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenControllersOfTemplateChoiceAreChanged/v2/Main.daml new file mode 100644 index 000000000000..7cc03de95d92 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenControllersOfTemplateChoiceAreChanged/v2/Main.daml @@ -0,0 +1,13 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + choice C : () + controller p, q + do pure () + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenObserversOfTemplateChoiceAreChanged/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenObserversOfTemplateChoiceAreChanged/v1/Main.daml new file mode 100644 index 000000000000..9b5a0d94ded9 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenObserversOfTemplateChoiceAreChanged/v1/Main.daml @@ -0,0 +1,14 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + choice C : () + observer p + controller p + do pure () + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenObserversOfTemplateChoiceAreChanged/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenObserversOfTemplateChoiceAreChanged/v2/Main.daml new file mode 100644 index 000000000000..1cf229df2cbd --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenObserversOfTemplateChoiceAreChanged/v2/Main.daml @@ -0,0 +1,14 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + choice C : () + observer p, q + controller p + do pure () + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesEnsure/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesEnsure/v1/Main.daml new file mode 100644 index 000000000000..ccad847af350 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesEnsure/v1/Main.daml @@ -0,0 +1,11 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + ensure True + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesEnsure/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesEnsure/v2/Main.daml new file mode 100644 index 000000000000..476351624215 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesEnsure/v2/Main.daml @@ -0,0 +1,11 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + ensure True == True + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyExpression/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyExpression/v1/Main.daml new file mode 100644 index 000000000000..22e6f2232e19 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyExpression/v1/Main.daml @@ -0,0 +1,12 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + key (p, "example") : (Party, Text) + maintainer (fst key) + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyExpression/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyExpression/v2/Main.daml new file mode 100644 index 000000000000..7e8b12262cf3 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyExpression/v2/Main.daml @@ -0,0 +1,12 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + key (q, "example") : (Party, Text) + maintainer (fst key) + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyMaintainers/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyMaintainers/v1/Main.daml new file mode 100644 index 000000000000..d3be82ead39e --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyMaintainers/v1/Main.daml @@ -0,0 +1,12 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + key (p, q) : (Party, Party) + maintainer (fst key) + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyMaintainers/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyMaintainers/v2/Main.daml new file mode 100644 index 000000000000..33ad6ce2d5ae --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesKeyMaintainers/v2/Main.daml @@ -0,0 +1,12 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + key (p, q) : (Party, Party) + maintainer (snd key) + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesObservers/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesObservers/v1/Main.daml new file mode 100644 index 000000000000..f9d0016926eb --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesObservers/v1/Main.daml @@ -0,0 +1,11 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + observer p + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesObservers/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesObservers/v2/Main.daml new file mode 100644 index 000000000000..745bc8b91144 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesObservers/v2/Main.daml @@ -0,0 +1,11 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where + signatory p + observer p, q + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesSignatories/v1/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesSignatories/v1/Main.daml new file mode 100644 index 000000000000..3ecae0885f37 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesSignatories/v1/Main.daml @@ -0,0 +1,9 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where signatory [p] + diff --git a/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesSignatories/v2/Main.daml b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesSignatories/v2/Main.daml new file mode 100644 index 000000000000..a0e796ed6f56 --- /dev/null +++ b/sdk/test-common/src/main/daml/upgrades/WarnsWhenTemplateChangesSignatories/v2/Main.daml @@ -0,0 +1,9 @@ +-- Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +-- SPDX-License-Identifier: Apache-2.0 + +module Main where +template A with + p : Party + q : Party + where signatory [p, q] +