Skip to content

Commit

Permalink
hlb, cleanup daml used for tests (digital-asset#2370)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickchapman-da authored Aug 1, 2019
1 parent 1c12354 commit f5688bd
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 198 deletions.
8 changes: 4 additions & 4 deletions language-support/hs/bindings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ da_haskell_library(
)

daml_compile(
name = "quickstart",
srcs = glob(["test/daml/quickstart/*.daml"]),
main_src = "test/daml/quickstart/Main.daml",
name = "for-tests",
srcs = glob(["test/daml/for-tests/*.daml"]),
main_src = "test/daml/for-tests/Main.daml",
)

daml_compile(
Expand All @@ -48,8 +48,8 @@ da_haskell_test(
name = "test",
srcs = glob(["test/**/*.hs"]),
data = [
":for-tests.dar",
":for-upload.dar",
":quickstart.dar",
"//ledger/sandbox:sandbox-binary",
],
flaky = True, # FIXME Remove this once #1927 is solved
Expand Down
35 changes: 17 additions & 18 deletions language-support/hs/bindings/test/DA/Ledger/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ tGetPackage :: SandboxTest
tGetPackage withSandbox = testCase "getPackage" $ run withSandbox $ \pid -> do
lid <- getLedgerIdentity
Just package <- getPackage lid pid
liftIO $ assertBool "contents" ("IouTransfer_Accept" `isInfixOf` show package)
liftIO $ assertBool "contents" ("currency" `isInfixOf` show package)

tGetPackageBad :: SandboxTest
tGetPackageBad withSandbox = testCase "getPackage/bad" $ run withSandbox $ \_pid -> do
Expand Down Expand Up @@ -579,23 +579,22 @@ alice = Party "Alice"
bob = Party "Bob"

createIOU :: PackageId -> Party -> Text -> Int -> Command
createIOU quickstart party currency quantity = CreateCommand {tid,args}
createIOU pid party currency quantity = CreateCommand {tid,args}
where
tid = TemplateId (Identifier quickstart mod ent)
tid = TemplateId (Identifier pid mod ent)
mod = ModuleName "Iou"
ent = EntityName "Iou"
args = Record Nothing [
RecordField "issuer" (VParty party),
RecordField "owner" (VParty party),
RecordField "currency" (VText currency),
RecordField "amount" (VDecimal $ Text.pack $ show quantity),
RecordField "observers" (VList [])
RecordField "amount" (VInt quantity)
]

createWithKey :: PackageId -> Party -> Int -> Command
createWithKey quickstart owner n = CreateCommand {tid,args}
createWithKey pid owner n = CreateCommand {tid,args}
where
tid = TemplateId (Identifier quickstart mod ent)
tid = TemplateId (Identifier pid mod ent)
mod = ModuleName "ContractKeys"
ent = EntityName "WithKey"
args = Record Nothing [
Expand All @@ -604,9 +603,9 @@ createWithKey quickstart owner n = CreateCommand {tid,args}
]

createWithoutKey :: PackageId -> Party -> Int -> Command
createWithoutKey quickstart owner n = CreateCommand {tid,args}
createWithoutKey pid owner n = CreateCommand {tid,args}
where
tid = TemplateId (Identifier quickstart mod ent)
tid = TemplateId (Identifier pid mod ent)
mod = ModuleName "ContractKeys"
ent = EntityName "WithoutKey"
args = Record Nothing [
Expand Down Expand Up @@ -668,9 +667,9 @@ assertTextContains text frag =
enableSharing :: Bool
enableSharing = True

createSpecQuickstart :: IO SandboxSpec
createSpecQuickstart = do
dar <- locateRunfiles (mainWorkspace </> "language-support/hs/bindings/quickstart.dar")
createSpec :: IO SandboxSpec
createSpec = do
dar <- locateRunfiles (mainWorkspace </> "language-support/hs/bindings/for-tests.dar")
return SandboxSpec {dar}

testGroupWithSandbox :: TestName -> [WithSandbox -> TestTree] -> TestTree
Expand All @@ -683,9 +682,9 @@ testGroupWithSandbox name tests =
else do
-- runs in it's own freshly (and very slowly!) spun-up sandbox
let withSandbox' f = do
specQuickstart <- createSpecQuickstart
pid <- mainPackageId specQuickstart
withSandbox specQuickstart $ \sandbox -> f sandbox pid
spec <- createSpec
pid <- mainPackageId spec
withSandbox spec $ \sandbox -> f sandbox pid
testGroup name $ map (\f -> f withSandbox') tests

mainPackageId :: SandboxSpec -> IO PackageId
Expand All @@ -705,9 +704,9 @@ data SharedSandbox = SharedSandbox (MVar (Sandbox, PackageId))

acquireShared :: IO SharedSandbox
acquireShared = do
specQuickstart <- createSpecQuickstart
sandbox <- startSandbox specQuickstart
pid <- mainPackageId specQuickstart
spec <- createSpec
sandbox <- startSandbox spec
pid <- mainPackageId spec
mv <- newMVar (sandbox, pid)
return $ SharedSandbox mv

Expand Down
15 changes: 15 additions & 0 deletions language-support/hs/bindings/test/daml/for-tests/Iou.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

daml 1.2

module Iou where

template Iou
with
issuer : Party
owner : Party
currency : Text
amount : Int
where
signatory issuer, owner
9 changes: 9 additions & 0 deletions language-support/hs/bindings/test/daml/for-tests/Main.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

daml 1.2
module Main where

import Iou()
import ContractKeys()
import Valuepedia()
86 changes: 0 additions & 86 deletions language-support/hs/bindings/test/daml/quickstart/Iou.daml

This file was deleted.

49 changes: 0 additions & 49 deletions language-support/hs/bindings/test/daml/quickstart/IouTrade.daml

This file was deleted.

41 changes: 0 additions & 41 deletions language-support/hs/bindings/test/daml/quickstart/Main.daml

This file was deleted.

0 comments on commit f5688bd

Please sign in to comment.