daml/daml-lf/tests/LargeTransaction.daml
Gary Verhaegen 1872c668a5
replace DAML Authors with DA in copyright headers (#5228)
Change requested by Manoj.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-27 01:26:10 +01:00

145 lines
4.3 KiB
Haskell

-- Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
module LargeTransaction where
import DA.Assert
range: a -> (a -> a) -> Int -> [a]
range x next n =
if n <= 0 then []
else reverse (rangeHelper [x] next (n - 1))
rangeHelper: [a] -> (a -> a) -> Int -> [a]
rangeHelper xs next n =
if n <= 0 then xs
else
case xs of
[] -> []
h :: _ -> rangeHelper ((next h) :: xs) next (n - 1)
rangeTest = scenario do
rangeHelper [] (\x -> x + 2) 2 === []
rangeHelper [] (\x -> x + 2) 0 === []
rangeHelper [] (\x -> x + 2) (-1) === []
rangeHelper [3] (\x -> x + 2) 2 === [7, 5, 3]
rangeHelper [3] (\x -> x + 2) 0 === [3]
rangeHelper [3] (\x -> x + 2) (-1) === [3]
range 1 (\x -> x + 10) 0 === []
range 1 (\x -> x + 10) (-1) === []
range 1 (\x -> x + 10) 1 === [1]
range 7 (\x -> x + 10) 5 === [7, 17, 27, 37, 47]
range 3 (\x -> x + 2) 7 === [3, 5, 7, 9, 11, 13, 15]
template IntContainer
with
party: Party
value: Int
where
signatory party
template ListContainer
with
party: Party
list: [Int]
where
signatory party
template RangeOfInts
with
party: Party
start: Int
step: Int
size: Int
where
signatory party
controller party can
ToList: [Int]
do return (range start (\x -> x + step) size)
ToListContainer: ContractId ListContainer
do create ListContainer with party = party, list = (range start (\x -> x + step) size)
ToListOfIntContainers: [ContractId IntContainer]
do
let xs: [Int] = (range start (\x -> x + step) size)
mapA (\x -> create IntContainer with party = party, value = x) xs
template ListUtil
with
party: Party
where
signatory party
controller party can
Size: ContractId IntContainer
with list: [Int]
do create IntContainer with party = party, value = (length list)
rangeOfIntsToListTest = scenario do
p <- getParty "Dummy"
cid <- submit p do
create RangeOfInts with
party = p
start = 0
step = 10
size = 5
lst <- submit p do exercise cid ToList
lst === [0, 10, 20, 30, 40]
rangeOfIntsToListContainerTest = scenario do
p <- getParty "Dummy"
cid <- submit p do
create RangeOfInts with
party = p
start = 0
step = 10
size = 5
listContainerCid <- submit p (exercise cid ToListContainer)
listContainer <- submit p (fetch listContainerCid)
listContainer.list === [0, 10, 20, 30, 40]
listSizeTest = scenario do
p <- getParty "Dummy"
cid <- submit p do
create ListUtil with party = p
cid <- submit p (exercise cid Size with list = [0, 1, 2, 3, 4, 5, 6])
sizeContainer <- submit p (fetch cid)
sizeContainer.value === 7
largeTransactionWithOneContractTest = scenario do
let expectedSize: Int = 100
p: Party <- getParty "Dummy"
cid: ContractId RangeOfInts <- submit p do
create RangeOfInts with party = p, start = 0, step = 1, size = expectedSize
cid: ContractId ListContainer <- submit p do exercise cid ToListContainer
listContainer <- submit p do fetch cid
(length listContainer.list) === expectedSize
largeListAsAChoiceArgTest = scenario do
let expectedSize: Int = 100
let list: [Int] = range 0 (\x -> x + 1) expectedSize
p: Party <- getParty "Dummy"
cid: ContractId ListUtil <- submit p do create ListUtil with party = p
cid: ContractId IntContainer <- submit p do exercise cid Size with list = list
sizeContainer: IntContainer <- submit p do fetch cid
sizeContainer.value === expectedSize
largeTransactionWithManyContractsTest = scenario do
let expectedSize: Int = 100
p: Party <- getParty "Dummy"
cid: ContractId RangeOfInts <- submit p do
create RangeOfInts with party = p, start = 0, step = 1, size = expectedSize
cids: [ContractId IntContainer] <- submit p do exercise cid ToListOfIntContainers
(length cids) === expectedSize
list: [Int] <- fetchAllInts p cids
list === (range 0 (\x -> x + 1) expectedSize)
fetchAllInts: Party -> [ContractId IntContainer] -> Scenario [Int]
fetchAllInts p cids = mapA (\cid -> (fetchOneInt p cid)) cids
fetchOneInt: Party -> ContractId IntContainer -> Scenario Int
fetchOneInt p cid = do
c: IntContainer <- submit p do fetch cid
return c.value