Skip to content

Commit 14363b9

Browse files
committed
Add new Integration test for ValidatorLicense grant
Signed-off-by: Divam <[email protected]>
1 parent 8f209bb commit 14363b9

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package org.lfdecentralizedtrust.splice.integration.tests
5+
6+
import org.lfdecentralizedtrust.splice.codegen.java.splice.validatorlicense.{
7+
LicenseKind,
8+
ValidatorLicense,
9+
}
10+
import scala.jdk.OptionConverters.*
11+
12+
class SvValidatorLicenseIntegrationTest extends SvIntegrationTestBase {
13+
14+
"grant validator license via admin API" in { implicit env =>
15+
initDso()
16+
17+
val dsoParty = sv1Backend.getDsoInfo().dsoParty
18+
val sv1Party = sv1Backend.getDsoInfo().svParty
19+
val validatorParty = allocateRandomSvParty("test-validator", Some(100))
20+
21+
// Verify no license exists initially
22+
val initialLicenses = sv1Backend.participantClientWithAdminToken.ledger_api_extensions.acs
23+
.filterJava(ValidatorLicense.COMPANION)(
24+
dsoParty,
25+
c => c.data.validator == validatorParty.toProtoPrimitive,
26+
)
27+
initialLicenses should have length 0
28+
29+
actAndCheck(
30+
"SV grants validator license to a new party",
31+
sv1Backend.grantValidatorLicense(validatorParty),
32+
)(
33+
"a ValidatorLicense contract is created",
34+
_ => {
35+
val licenses = sv1Backend.participantClientWithAdminToken.ledger_api_extensions.acs
36+
.filterJava(ValidatorLicense.COMPANION)(
37+
dsoParty,
38+
c => c.data.validator == validatorParty.toProtoPrimitive,
39+
)
40+
41+
licenses should have length 1
42+
val license = licenses.head
43+
license.data.validator shouldBe validatorParty.toProtoPrimitive
44+
license.data.sponsor shouldBe sv1Party.toProtoPrimitive
45+
license.data.dso shouldBe dsoParty.toProtoPrimitive
46+
},
47+
)
48+
}
49+
50+
"granting license to an onboarded validator does not affect license kind" in { implicit env =>
51+
initDso()
52+
aliceValidatorBackend.startSync()
53+
54+
val dsoParty = sv1Backend.getDsoInfo().dsoParty
55+
56+
// Use alice's validator who should already be onboarded with an OperatorLicense
57+
val aliceValidatorParty = aliceValidatorBackend.getValidatorPartyId()
58+
59+
// Verify alice already has an OperatorLicense
60+
val initialLicenses = sv1Backend.participantClientWithAdminToken.ledger_api_extensions.acs
61+
.filterJava(ValidatorLicense.COMPANION)(
62+
dsoParty,
63+
c => c.data.validator == aliceValidatorParty.toProtoPrimitive,
64+
)
65+
initialLicenses should have length 1
66+
val initialLicense = initialLicenses.head
67+
initialLicense.data.validator shouldBe aliceValidatorParty.toProtoPrimitive
68+
initialLicense.data.kind.toScala shouldBe Some(LicenseKind.OPERATORLICENSE)
69+
70+
// Grant a license to Alice (creates NonOperatorLicense)
71+
sv1Backend.grantValidatorLicense(aliceValidatorParty)
72+
73+
// Wait for the merge trigger to merge the duplicate licenses
74+
eventually() {
75+
val licenses = sv1Backend.participantClientWithAdminToken.ledger_api_extensions.acs
76+
.filterJava(ValidatorLicense.COMPANION)(
77+
dsoParty,
78+
c => c.data.validator == aliceValidatorParty.toProtoPrimitive,
79+
)
80+
81+
licenses should have length 1
82+
val mergedLicense = licenses.head
83+
// The merged license should still have kind OperatorLicense
84+
mergedLicense.data.kind.toScala shouldBe Some(LicenseKind.OPERATORLICENSE)
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)