forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
daml-lf: introduce Numeric in internal AST (digital-asset#2608)
* daml-lf: introduce numeric in daml-lf AST * daml-lf: add test for command preprocessor * interface-reader: fix for Numerics * Address Gerolf's review
- Loading branch information
1 parent
67c2e2a
commit 9a4dff6
Showing
32 changed files
with
648 additions
and
365 deletions.
There are no files selected for viewing
325 changes: 213 additions & 112 deletions
325
daml-lf/archive/src/main/scala/com/digitalasset/daml/lf/archive/DecodeV1.scala
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
102 changes: 102 additions & 0 deletions
102
daml-lf/engine/src/test/scala/com/digitalasset/daml/lf/engine/CommandPreprocessorSpec.scala
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,102 @@ | ||
// Copyright (c) 2019 The DAML Authors. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.digitalasset.daml | ||
package lf | ||
package engine | ||
|
||
import com.digitalasset.daml.lf.data._ | ||
import com.digitalasset.daml.lf.language.Ast.{TNat, TTyCon} | ||
import com.digitalasset.daml.lf.language.Util._ | ||
import com.digitalasset.daml.lf.testing.parser.Implicits._ | ||
import com.digitalasset.daml.lf.value.Value._ | ||
import com.digitalasset.daml.lf.value.ValueVersion | ||
import org.scalatest.prop.TableDrivenPropertyChecks | ||
import org.scalatest.{Matchers, WordSpec} | ||
|
||
import scala.language.implicitConversions | ||
|
||
@SuppressWarnings(Array("org.wartremover.warts.Any")) | ||
class CommandPreprocessorSpec extends WordSpec with Matchers with TableDrivenPropertyChecks { | ||
|
||
import defaultParserParameters.{defaultPackageId => pkgId} | ||
|
||
private implicit def toName(s: String): Ref.Name = Ref.Name.assertFromString(s) | ||
|
||
val recordCon = Ref.Identifier(pkgId, Ref.QualifiedName.assertFromString("Module:Record")) | ||
val variantCon = Ref.Identifier(pkgId, Ref.QualifiedName.assertFromString("Module:Variant")) | ||
val enumCon = Ref.Identifier(pkgId, Ref.QualifiedName.assertFromString("Module:Enum")) | ||
|
||
val pkg = | ||
p""" | ||
module Module { | ||
|
||
record Record = { field : Int64 }; | ||
variant Variant = variant1 : Text | variant2 : Int64 ; | ||
enum Enum = value1 | value2; | ||
|
||
} | ||
|
||
""" | ||
|
||
"translateValue" should { | ||
|
||
val testCases = Table( | ||
"type" -> "value", | ||
TUnit -> | ||
ValueUnit, | ||
TBool -> | ||
ValueBool(true), | ||
TInt64 -> | ||
ValueInt64(42), | ||
TTimestamp -> | ||
ValueTimestamp(Time.Timestamp.assertFromString("1969-07-20T20:17:00Z")), | ||
TDate -> | ||
ValueDate(Time.Date.assertFromString("1879-03-14")), | ||
TText -> | ||
ValueText("daml"), | ||
TNumeric(TNat(10)) -> | ||
ValueNumeric(Numeric.assertFromString("10.0000000000")), | ||
// TNumeric(TNat(9)) -> | ||
// ValueNumeric(Numeric.assertFromString("9.000000000")), | ||
TParty -> | ||
ValueParty(Ref.Party.assertFromString("Alice")), | ||
TContractId(TTyCon(recordCon)) -> | ||
ValueContractId(AbsoluteContractId(Ref.ContractIdString.assertFromString("contractId"))), | ||
TList(TText) -> | ||
ValueList(FrontStack(ValueText("a"), ValueText("b"))), | ||
TMap(TBool) -> | ||
ValueMap(SortedLookupList(Map("0" -> ValueBool(true), "1" -> ValueBool(false)))), | ||
TOptional(TText) -> | ||
ValueOptional(Some(ValueText("text"))), | ||
TTyCon(recordCon) -> | ||
ValueRecord(None, ImmArray(Some[Ref.Name]("field") -> ValueInt64(33))), | ||
TTyCon(variantCon) -> | ||
ValueVariant(None, "variant1", ValueText("some test")), | ||
TTyCon(enumCon) -> | ||
ValueEnum(None, "value1"), | ||
) | ||
|
||
val compiledPackage = ConcurrentCompiledPackages() | ||
assert(compiledPackage.addPackage(pkgId, pkg) == ResultDone(())) | ||
val preprocessor = CommandPreprocessor(compiledPackage) | ||
import preprocessor.translateValue | ||
val valueVersion = ValueVersion("last") | ||
|
||
"succeeds on well type values" in { | ||
forAll(testCases) { (typ, value) => | ||
translateValue(typ, VersionedValue(valueVersion, value)) shouldBe a[ResultDone[_]] | ||
} | ||
} | ||
|
||
"fails on non-well type values" in { | ||
forAll(testCases) { (typ1, value1) => | ||
forAll(testCases) { (_, value2) => | ||
if (value1 != value2) | ||
translateValue(typ1, VersionedValue(valueVersion, value2)) shouldBe a[ResultError] | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.