-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data-dependencies compatibility tests (#6313)
CHANGELOG_BEGIN CHANGELOG_END Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
- Loading branch information
1 parent
0f47b8d
commit f2cd820
Showing
6 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
exports_files(glob(["example/**"])) |
104 changes: 104 additions & 0 deletions
104
compatibility/bazel_tools/data_dependencies/data_dependencies.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("//bazel_tools:versions.bzl", "version_to_name") | ||
|
||
def _build_dar( | ||
name, | ||
package_name, | ||
srcs, | ||
data_dependencies, | ||
sdk_version): | ||
daml = "@daml-sdk-{sdk_version}//:daml".format( | ||
sdk_version = sdk_version, | ||
) | ||
native.genrule( | ||
name = name, | ||
srcs = srcs + data_dependencies, | ||
outs = ["%s.dar" % name], | ||
tools = [daml], | ||
cmd = """\ | ||
set -euo pipefail | ||
TMP_DIR=$$(mktemp -d) | ||
cleanup() {{ rm -rf $$TMP_DIR; }} | ||
trap cleanup EXIT | ||
mkdir -p $$TMP_DIR/src $$TMP_DIR/dep | ||
for src in {srcs}; do | ||
cp -L $$src $$TMP_DIR/src | ||
done | ||
DATA_DEPS= | ||
for dep in {data_dependencies}; do | ||
cp -L $$dep $$TMP_DIR/dep | ||
DATA_DEPS="$$DATA_DEPS\n - dep/$$(basename $$dep)" | ||
done | ||
cat <<EOF >$$TMP_DIR/daml.yaml | ||
sdk-version: {sdk_version} | ||
name: {name} | ||
source: src | ||
version: 0.0.1 | ||
dependencies: | ||
- daml-prim | ||
- daml-script | ||
data-dependencies:$$DATA_DEPS | ||
EOF | ||
$(location {daml}) build --project-root=$$TMP_DIR -o $$PWD/$(OUTS) | ||
""".format( | ||
daml = daml, | ||
name = package_name, | ||
data_dependencies = " ".join([ | ||
"$(location %s)" % dep | ||
for dep in data_dependencies | ||
]), | ||
sdk_version = sdk_version, | ||
srcs = " ".join([ | ||
"$(locations %s)" % src | ||
for src in srcs | ||
]), | ||
), | ||
) | ||
|
||
def data_dependencies_coins(sdk_version): | ||
"""Build the coin1 and coin2 packages with the given SDK version. | ||
""" | ||
_build_dar( | ||
name = "data-dependencies-coin1-{sdk_version}".format( | ||
sdk_version = sdk_version, | ||
), | ||
package_name = "data-dependencies-coin1", | ||
srcs = ["//bazel_tools/data_dependencies:example/CoinV1.daml"], | ||
data_dependencies = [], | ||
sdk_version = sdk_version, | ||
) | ||
_build_dar( | ||
name = "data-dependencies-coin2-{sdk_version}".format( | ||
sdk_version = sdk_version, | ||
), | ||
package_name = "data-dependencies-coin2", | ||
srcs = ["//bazel_tools/data_dependencies:example/CoinV2.daml"], | ||
data_dependencies = [], | ||
sdk_version = sdk_version, | ||
) | ||
|
||
def data_dependencies_upgrade(old_sdk_version, new_sdk_version): | ||
"""Build the coin-upgrade package using the new SDK version. | ||
The package will have data-dependencies on the coin1 and coin2 package | ||
built with the old SDK version. | ||
""" | ||
_build_dar( | ||
name = "data-dependencies-upgrade-old-{old_sdk_version}-new-{new_sdk_version}".format( | ||
old_sdk_version = old_sdk_version, | ||
new_sdk_version = new_sdk_version, | ||
), | ||
package_name = "data-dependencies-upgrade", | ||
srcs = ["//bazel_tools/data_dependencies:example/UpgradeFromCoinV1.daml"], | ||
data_dependencies = [ | ||
"data-dependencies-coin1-{sdk_version}".format( | ||
sdk_version = old_sdk_version, | ||
), | ||
"data-dependencies-coin2-{sdk_version}".format( | ||
sdk_version = old_sdk_version, | ||
), | ||
], | ||
sdk_version = new_sdk_version, | ||
) |
24 changes: 24 additions & 0 deletions
24
compatibility/bazel_tools/data_dependencies/example/CoinV1.daml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- COIN_BEGIN | ||
module CoinV1 where | ||
|
||
template Coin | ||
with | ||
issuer : Party | ||
owner : Party | ||
where | ||
signatory issuer, owner | ||
-- COIN_END | ||
|
||
template CoinProposal | ||
with | ||
issuer : Party | ||
owner : Party | ||
where | ||
signatory issuer | ||
observer owner | ||
choice CoinProposal_Accept : ContractId Coin | ||
controller owner | ||
do create Coin with .. |
14 changes: 14 additions & 0 deletions
14
compatibility/bazel_tools/data_dependencies/example/CoinV2.daml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- COIN_AMOUNT_BEGIN | ||
module CoinV2 where | ||
|
||
template CoinWithAmount | ||
with | ||
issuer : Party | ||
owner : Party | ||
amount : Int | ||
where | ||
signatory issuer, owner | ||
-- COIN_AMOUNT_END |
46 changes: 46 additions & 0 deletions
46
compatibility/bazel_tools/data_dependencies/example/UpgradeFromCoinV1.daml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- UPGRADE_MODULE_BEGIN | ||
module UpgradeFromCoinV1 where | ||
import CoinV2 | ||
import CoinV1 | ||
-- UPGRADE_MODULE_END | ||
|
||
-- UPGRADE_PROPOSAL_BEGIN | ||
template UpgradeCoinProposal | ||
with | ||
issuer : Party | ||
owner : Party | ||
where | ||
signatory issuer | ||
observer owner | ||
key (issuer, owner) : (Party, Party) | ||
maintainer key._1 | ||
choice Accept : ContractId UpgradeCoinAgreement | ||
controller owner | ||
do create UpgradeCoinAgreement with .. | ||
-- UPGRADE_PROPOSAL_END | ||
|
||
-- UPGRADE_AGREEMENT_BEGIN | ||
template UpgradeCoinAgreement | ||
with | ||
issuer : Party | ||
owner : Party | ||
where | ||
signatory issuer, owner | ||
key (issuer, owner) : (Party, Party) | ||
maintainer key._1 | ||
nonconsuming choice Upgrade : ContractId CoinWithAmount | ||
with | ||
coinId : ContractId Coin | ||
controller issuer | ||
do coin <- fetch coinId | ||
assert (coin.issuer == issuer) | ||
assert (coin.owner == owner) | ||
archive coinId | ||
create CoinWithAmount with | ||
issuer = coin.issuer | ||
owner = coin.owner | ||
amount = 1 | ||
-- UPGRADE_AGREEMENT_END |