Skip to content

Commit 54b1933

Browse files
cip-82: add test covering allocateDevelopmentFundCoupon and listActiveDevelopmentFundCoupons
Signed-off-by: Jose Velasco <jose.velasco@intellecteu.com>
1 parent 707adeb commit 54b1933

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

apps/app/src/test/scala/org/lfdecentralizedtrust/splice/integration/tests/DevelopmentFundCouponIntegrationTest.scala

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.lfdecentralizedtrust.splice.integration.tests
22

3+
import com.daml.ledger.javaapi.data.Identifier
34
import com.digitalasset.canton.config.NonNegativeFiniteDuration
5+
import com.digitalasset.canton.data.CantonTimestamp
46
import org.lfdecentralizedtrust.splice.codegen.java.splice.amulet.UnclaimedDevelopmentFundCoupon
57
import org.lfdecentralizedtrust.splice.config.ConfigTransforms
68
import org.lfdecentralizedtrust.splice.config.ConfigTransforms.{
@@ -11,6 +13,8 @@ import org.lfdecentralizedtrust.splice.integration.EnvironmentDefinition
1113
import org.lfdecentralizedtrust.splice.sv.automation.delegatebased.AdvanceOpenMiningRoundTrigger
1214
import org.lfdecentralizedtrust.splice.util.{TriggerTestUtil, WalletTestUtil}
1315

16+
import java.time.Duration
17+
1418
@org.lfdecentralizedtrust.splice.util.scalatesttags.SpliceDsoGovernance_0_1_21
1519
class DevelopmentFundCouponIntegrationTest
1620
extends SvIntegrationTestBase
@@ -19,6 +23,12 @@ class DevelopmentFundCouponIntegrationTest
1923

2024
private val threshold = 3
2125

26+
override protected lazy val sanityChecksIgnoredRootCreates: Seq[Identifier] = Seq(
27+
UnclaimedDevelopmentFundCoupon.TEMPLATE_ID_WITH_PACKAGE_ID
28+
)
29+
30+
override protected def runTokenStandardCliSanityCheck: Boolean = false
31+
2232
override def environmentDefinition
2333
: org.lfdecentralizedtrust.splice.integration.EnvironmentDefinition =
2434
EnvironmentDefinition
@@ -96,4 +106,61 @@ class DevelopmentFundCouponIntegrationTest
96106
},
97107
)
98108
}
109+
110+
"DevelopmentFundCoupons management flow" in { implicit env =>
111+
val sv1UserId = sv1WalletClient.config.ledgerApiUser
112+
val unclaimedDevelopmentFundCouponsToMint = Seq(10.0, 10.0, 30.0, 30.0)
113+
val unclaimedDevelopmentFundCouponTotal = unclaimedDevelopmentFundCouponsToMint.sum
114+
val aliceParty = onboardWalletUser(aliceWalletClient, aliceValidatorBackend)
115+
val bobParty = onboardWalletUser(bobWalletClient, bobValidatorBackend)
116+
val fundManager = aliceParty
117+
val beneficiary = bobParty
118+
val developmentFundCouponAmount = 40.0
119+
val expiresAt = CantonTimestamp.now().plus(Duration.ofDays(1))
120+
val reason = "Bob has contributed to the Daml repo"
121+
122+
val unclaimedDevelopmentFundCouponContractIds =
123+
clue("Mint some unclaimed development fund coupons") {
124+
unclaimedDevelopmentFundCouponsToMint.foreach { amount =>
125+
createUnclaimedDevelopmentFundCoupon(
126+
sv1ValidatorBackend.participantClientWithAdminToken,
127+
sv1UserId,
128+
amount,
129+
)
130+
}
131+
val unclaimedDevelopmentFundCouponContracts =
132+
sv1Backend.participantClient.ledger_api_extensions.acs
133+
.filterJava(UnclaimedDevelopmentFundCoupon.COMPANION)(dsoParty)
134+
unclaimedDevelopmentFundCouponContracts
135+
.map(co => BigDecimal(co.data.amount))
136+
.sum shouldBe unclaimedDevelopmentFundCouponTotal
137+
unclaimedDevelopmentFundCouponContracts.map(_.id)
138+
}
139+
140+
actAndCheck(
141+
"allocate one development fund coupon", {
142+
aliceWalletClient.allocateDevelopmentFundCoupon(
143+
unclaimedDevelopmentFundCouponContractIds,
144+
beneficiary,
145+
developmentFundCouponAmount,
146+
expiresAt,
147+
reason,
148+
fundManager,
149+
)
150+
},
151+
)(
152+
"One development fund coupon is allocated and the total of unclaimed development fund coupons has decreased",
153+
_ => {
154+
val activeDevelopmentFundCoupons =
155+
aliceWalletClient.listActiveDevelopmentFundCoupons().map(_.payload)
156+
activeDevelopmentFundCoupons.length shouldBe 1
157+
val bobDevelopmentFundCoupon = activeDevelopmentFundCoupons.head
158+
bobDevelopmentFundCoupon.amount shouldBe developmentFundCouponAmount
159+
sv1Backend.participantClient.ledger_api_extensions.acs
160+
.filterJava(UnclaimedDevelopmentFundCoupon.COMPANION)(dsoParty)
161+
.map(co => BigDecimal(co.data.amount))
162+
.sum shouldBe (unclaimedDevelopmentFundCouponTotal - developmentFundCouponAmount)
163+
},
164+
)
165+
}
99166
}

apps/app/src/test/scala/org/lfdecentralizedtrust/splice/util/WalletTestUtil.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,31 @@ trait WalletTestUtil extends TestCommon with AnsTestUtil {
10681068
created.contractId
10691069
}
10701070

1071+
/** Directly creates a new unclaimed development fund coupon. */
1072+
def createUnclaimedDevelopmentFundCoupon(
1073+
participantClient: ParticipantClientReference,
1074+
userId: String,
1075+
amount: BigDecimal = BigDecimal(10),
1076+
synchronizerId: Option[SynchronizerId] = None,
1077+
)(implicit
1078+
env: SpliceTestConsoleEnvironment
1079+
): amuletCodegen.UnclaimedDevelopmentFundCoupon.ContractId = {
1080+
val amulet =
1081+
new amuletCodegen.UnclaimedDevelopmentFundCoupon(
1082+
dsoParty.toProtoPrimitive,
1083+
amount.bigDecimal,
1084+
).create
1085+
val created = participantClient.ledger_api_extensions.commands
1086+
.submitWithResult(
1087+
userId = userId,
1088+
actAs = Seq(dsoParty),
1089+
readAs = Seq.empty,
1090+
update = amulet,
1091+
synchronizerId = synchronizerId,
1092+
)
1093+
created.contractId
1094+
}
1095+
10711096
protected def retryCommandSubmission[T](f: => T) = {
10721097
eventually() {
10731098
try {

0 commit comments

Comments
 (0)