Skip to content

Commit

Permalink
LF: Test preprocessor resuming (#10936)
Browse files Browse the repository at this point in the history
CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored Sep 21, 2021
1 parent 2edfc06 commit 8b3b033
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,6 @@ class EngineTest
}
}

"command translation" should {
"returns correct error when resuming" in {
val translator =
new preprocessing.Preprocessor(
ConcurrentCompiledPackages(suffixLenientEngine.config.getCompilerConfig)
)
val id = Identifier(basicTestsPkgId, "BasicTests:MyRec")
val wrongRecord =
ValueRecord(Some(id), ImmArray(Some[Name]("wrongLbl") -> ValueText("foo")))
val res = translator
.translateValue(
TTyConApp(id, ImmArray.Empty),
wrongRecord,
)
.consume(lookupContract, lookupPackage, lookupKey)
inside(res) { case Left(Error.Preprocessing(error)) =>
error shouldBe a[Error.Preprocessing.TypeMismatch]
}
}
}

"minimal create command" should {
val id = Identifier(basicTestsPkgId, "BasicTests:Simple")
val let = Time.Timestamp.now()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.lf
package engine

import com.daml.lf.data.{FrontStack, ImmArray, Ref}
import com.daml.lf.language.Ast
import com.daml.lf.value.Value.{ValueInt64, ValueList, ValueParty, ValueRecord}
import org.scalatest.Inside
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class CommandPreprocessorSpec extends AnyWordSpec with Inside with Matchers {

import com.daml.lf.testing.parser.Implicits._
import com.daml.lf.transaction.test.TransactionBuilder.Implicits.{defaultPackageId => _, _}

private[this] implicit val defaultPackageId: Ref.PackageId =
defaultParserParameters.defaultPackageId

private[this] lazy val pkg =
p"""
module Mod {

record @serializable Record = { owners: List Party, data : Int64 };

template (this : Record) = {
precondition True,
signatories Mod:Record {owners} this,
observers Mod:Record {owners} this,
agreement "Agreement",
choices { },
key @(List Party) (Mod:Record {owners} this) (\ (parties: List Party) -> parties)
};

}
"""

private[this] val pkgs = Map(defaultPackageId -> pkg)
private[this] val parties = ValueList(FrontStack(ValueParty("Alice")))

"preprocessor" should {
"returns correct result when resuming" in {
val preporcessor = new preprocessing.Preprocessor(ConcurrentCompiledPackages())
val intermediaryResult = preporcessor
.translateValue(
Ast.TTyCon("Mod:Record"),
ValueRecord("", ImmArray("owners" -> parties, "data" -> ValueInt64(42))),
)
intermediaryResult shouldBe a[ResultNeedPackage[_]]
val finalResult = intermediaryResult.consume(_ => None, pkgs.get, _ => None)
finalResult shouldBe a[Right[_, _]]
}

"returns correct error when resuming" in {
val preporcessor = new preprocessing.Preprocessor(ConcurrentCompiledPackages())
val intermediaryResult = preporcessor
.translateValue(
Ast.TTyCon("Mod:Record"),
ValueRecord(
"",
ImmArray("owners" -> parties, "wrong_field" -> ValueInt64(42)),
),
)
intermediaryResult shouldBe a[ResultNeedPackage[_]]
val finalResult = intermediaryResult.consume(_ => None, pkgs.get, _ => None)
inside(finalResult) { case Left(Error.Preprocessing(error)) =>
error shouldBe a[Error.Preprocessing.TypeMismatch]
}
}
}

}

0 comments on commit 8b3b033

Please sign in to comment.