Skip to content

Commit

Permalink
Update Splice from CCI (#46)
Browse files Browse the repository at this point in the history
Signed-off-by: DA Automation <[email protected]>
Co-authored-by: DA Automation <[email protected]>
  • Loading branch information
canton-network-da and DA Automation authored Sep 30, 2024
1 parent 21584a2 commit 925d604
Show file tree
Hide file tree
Showing 77 changed files with 1,270 additions and 816 deletions.
2 changes: 1 addition & 1 deletion LATEST_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.1
0.2.3
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.2
0.2.4
1 change: 1 addition & 0 deletions apps/ans/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@types/uuid": "8.3.4",
"@vitejs/plugin-react": "^4.0.4",
"common-test-utils": "^0.1.0",
"common-test-vite-utils": "^0.1.0",
"happy-dom": "^11.0.0",
"prettier": "2.8.4",
"typescript": "4.9.5",
Expand Down
2 changes: 1 addition & 1 deletion apps/ans/frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import react from '@vitejs/plugin-react';
import { vitest_common_conf } from 'common-test-utils';
import { vitest_common_conf } from 'common-test-vite-utils';
import { defineConfig, loadEnv, mergeConfig } from 'vite';
import viteTsconfigPaths from 'vite-tsconfig-paths';

Expand Down
1 change: 1 addition & 0 deletions apps/app-manager/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@typescript-eslint/parser": "5.52.0",
"@vitejs/plugin-react": "^4.0.4",
"common-test-utils": "^0.1.0",
"common-test-vite-utils": "^0.1.0",
"eslint": "8.34.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-import": "2.27.5",
Expand Down
2 changes: 1 addition & 1 deletion apps/app-manager/frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import react from '@vitejs/plugin-react';
import { vitest_common_conf } from 'common-test-utils';
import { vitest_common_conf } from 'common-test-vite-utils';
import { defineConfig, loadEnv, mergeConfig } from 'vite';
import viteTsconfigPaths from 'vite-tsconfig-paths';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class ScanFrontendTimeBasedIntegrationTest
with TimeTestUtil
with SynchronizerFeesTestUtil
with TriggerTestUtil
with VotesFrontendTestUtil {
with VotesFrontendTestUtil
with ValidatorLicensesFrontendTestUtil
with SvTestUtil {

val amuletPrice = 2

Expand Down Expand Up @@ -593,5 +595,43 @@ class ScanFrontendTimeBasedIntegrationTest
}
}

"see the validator licenses" in { implicit env =>
withFrontEnd("scan-ui") { implicit webDriver =>
actAndCheck(
"Go to Scan UI main page",
go to s"http://localhost:${scanUIPort}",
)(
"Switch to the validator licenses tab",
_ => {
inside(find(id("navlink-/validator-licenses"))) { case Some(navlink) =>
navlink.underlying.click()
}
},
)

val licenseRows = getLicensesTableRows
val newValidatorParty = allocateRandomSvParty("validatorX")
val newSecret = sv1Backend.devNetOnboardValidatorPrepare()

actAndCheck(
"onboard new validator using the secret",
sv1Backend.onboardValidator(
newValidatorParty,
newSecret,
s"${newValidatorParty.uid.identifier}@example.com",
),
)(
"a new validator row is added",
_ => {
checkLastValidatorLicenseRow(
licenseRows.size.toLong,
sv1Backend.getDsoInfo().svParty,
newValidatorParty,
)
},
)
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class SvFrontendIntegrationTest
with SvFrontendTestUtil
with FrontendLoginUtil
with WalletTestUtil
with VotesFrontendTestUtil {
with VotesFrontendTestUtil
with ValidatorLicensesFrontendTestUtil {

override def environmentDefinition
: BaseEnvironmentDefinition[EnvironmentImpl, SpliceTestConsoleEnvironment] =
Expand Down Expand Up @@ -172,7 +173,7 @@ class SvFrontendIntegrationTest
},
)

val licenseRows = findAll(className("validator-licenses-table-row")).toList
val licenseRows = getLicensesTableRows
val newValidatorParty = allocateRandomSvParty("validatorX")

actAndCheck(
Expand All @@ -185,19 +186,11 @@ class SvFrontendIntegrationTest
)(
"a new validator row is added",
_ => {
val newLicenseRows = findAll(className("validator-licenses-table-row")).toList
newLicenseRows should have size (licenseRows.size + 1L)
val row: Element = inside(newLicenseRows) { case row :: _ =>
row
}
val sponsor =
seleniumText(row.childElement(className("validator-licenses-sponsor")))

val validator =
seleniumText(row.childElement(className("validator-licenses-validator")))

sponsor shouldBe sv1Backend.getDsoInfo().svParty.toProtoPrimitive
validator shouldBe newValidatorParty.toProtoPrimitive
checkLastValidatorLicenseRow(
licenseRows.size.toLong,
sv1Backend.getDsoInfo().svParty,
newValidatorParty,
)
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.daml.network.sv.util.SvUtil
import com.daml.network.util.TriggerTestUtil

import java.time.Duration as JavaDuration
import scala.concurrent.duration.DurationInt
import scala.jdk.CollectionConverters.*
import scala.util.Random

Expand Down Expand Up @@ -57,7 +58,8 @@ class SvTimeBasedOnboardingIntegrationTest
sv4Backend.start()
}
clue("An `SvOnboardingRequest` contract is created") {
eventually()(
// Increased timeout, because SV4 takes a while to start up
eventually(timeUntilSuccess = 60.seconds)(
// The onboarding is requested by SV4 during SvApp init.
sv1Backend.participantClientWithAdminToken.ledger_api_extensions.acs
.filterJava(splice.svonboarding.SvOnboardingRequest.COMPANION)(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.daml.network.integration.tests

import com.digitalasset.canton.topology.PartyId
import org.scalatest.Assertion

trait ValidatorLicensesFrontendTestUtil { self: FrontendIntegrationTestWithSharedEnvironment =>

def getLicensesTableRows(implicit webDriver: WebDriverType) = {
findAll(className("validator-licenses-table-row")).toList
}

def checkLastValidatorLicenseRow(
previousSize: Long,
expectedSponsor: PartyId,
expectedValidator: PartyId,
)(implicit webDriver: WebDriverType): Assertion = {
val newLicenseRows = findAll(className("validator-licenses-table-row")).toList
newLicenseRows should have size (previousSize + 1L)
val row: Element = inside(newLicenseRows) { case row :: _ =>
row
}
val sponsor =
seleniumText(row.childElement(className("validator-licenses-sponsor")))

val validator =
seleniumText(row.childElement(className("validator-licenses-validator")))

sponsor shouldBe expectedSponsor.toProtoPrimitive
validator shouldBe expectedValidator.toProtoPrimitive
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.network.integration.tests

import com.daml.network.integration.EnvironmentDefinition
import com.daml.network.integration.tests.SpliceTests.IntegrationTestWithSharedEnvironment
import com.daml.network.util.{WalletTestUtil}
import com.digitalasset.canton.HasExecutionContext
import com.digitalasset.canton.metrics.MetricValue

class WalletMetricsTest
extends IntegrationTestWithSharedEnvironment
with HasExecutionContext
with WalletTestUtil
with WalletTxLogTestUtil {

override def environmentDefinition: EnvironmentDefinition = {
EnvironmentDefinition
.simpleTopology1Sv(this.getClass.getSimpleName)
}

"Unlocked coin metrics" should {
"update when tapping coin" in { implicit env =>
val aliceUserParty = onboardWalletUser(aliceWalletClient, aliceValidatorBackend)
val before = aliceValidatorBackend.metrics
.get(
"cn.wallet.unlocked-amulet-balance",
Map("owner" -> aliceUserParty.toString),
)
.select[MetricValue.DoublePoint]
.value
.value
before shouldBe 0
actAndCheck(
"alice taps 100 coin",
aliceWalletClient.tap(100.0),
)(
"metrics update to reflect new coins",
_ => {
val after = aliceValidatorBackend.metrics
.get("cn.wallet.unlocked-amulet-balance", Map("owner" -> aliceUserParty.toString))
.select[MetricValue.DoublePoint]
.value
.value
val tapCC = walletUsdToAmulet(100.0)
BigDecimal(after) should beWithin(tapCC - smallAmount, tapCC)
},
)
}
}

"User wallet automation metrics" should {
"are labeled with the party ID of the wallet user" in { implicit env =>
val aliceUserParty = onboardWalletUser(aliceWalletClient, aliceValidatorBackend)
val bobUserParty = onboardWalletUser(bobWalletClient, bobValidatorBackend)
aliceWalletClient.tap(100.0)
p2pTransfer(aliceWalletClient, bobWalletClient, bobUserParty, 50.0)

// Polling triggers
// Not exhaustive, only triggers configured to run (e.g., no WalletSweepTrigger)
Seq(
"AmuletMetricsTrigger",
"CollectRewardsAndMergeAmuletsTrigger",
"DomainIngestionService",
"ExpireAcceptedTransferOfferTrigger",
"ExpireAppPaymentRequestsTrigger",
"ExpireBuyTrafficRequestsTrigger",
"ExpireTransferOfferTrigger",
"SubscriptionReadyForPaymentTrigger",
"TransferFollowTrigger",
).foreach(triggerName =>
clue(s"$triggerName should report polling iterations correctly") {
aliceValidatorBackend.metrics
.get(
"cn.trigger.iterations",
Map(
"trigger_name" -> triggerName,
"party" -> aliceUserParty.toString,
),
)
.select[MetricValue.LongPoint]
.value
// We always do one iteration right after startup
.value should be > 0L
}
)

// Task-based triggers
// Not exhaustive, only triggers that are invoked during init and transfers
Seq(
"AcceptedTransferOfferTrigger",
"DomainIngestionService",
).foreach(triggerName =>
clue(s"$triggerName should report task completions correctly") {
aliceValidatorBackend.metrics
.get(
"cn.trigger.completed",
Map(
"trigger_name" -> triggerName,
"party" -> aliceUserParty.toString,
),
)
.select[MetricValue.LongPoint]
.value
.value should be > 0L
}
)
}
}
}
14 changes: 4 additions & 10 deletions apps/common/frontend-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
"name": "common-test-utils",
"version": "0.1.0",
"private": true,
"types": "./lib/types/index.d.ts",
"types": ".lib/index.d.ts",
"exports": {
".": {
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js",
"default": "./lib/esm/index.js"
}
".": "./lib/index.js"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "4.0.0",
Expand All @@ -21,14 +16,13 @@
"typescript": "4.9.5"
},
"scripts": {
"build": "npm run build:tsc && node ./write-package-jsons.js",
"build:tsc": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
"build": "tsc",
"check": "npm run format:check && npm run lint:check",
"fix": "npm run format:fix && npm run lint:fix",
"format:check": "prettier --check -- src",
"format:fix": "prettier --write -- src",
"lint:check": "eslint --ignore-pattern src/com/* --max-warnings=0 -- src",
"lint:fix": "eslint --ignore-pattern src/com/* --fix --max-warnings=0 -- src",
"start": "nodemon -V -e ts,json -i lib/ -x \"npm run build\""
"start": "tsc --watch"
}
}
3 changes: 2 additions & 1 deletion apps/common/frontend-test-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './vitest.common.conf';
export { validatorLicensesHandler } from './mocks/handlers/validator-licenses-handler';
export { dsoInfoHandler, dsoInfo } from './mocks/handlers/dso-info-handler';
Loading

0 comments on commit 925d604

Please sign in to comment.