Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.lfdecentralizedtrust.splice.codegen.java.splice.round.OpenMiningRound
import org.lfdecentralizedtrust.splice.config.ConfigTransforms
import org.lfdecentralizedtrust.splice.config.ConfigTransforms.{
ConfigurableApp,
updateAllSvAppFoundDsoConfigs_,
updateAutomationConfig,
}
import org.lfdecentralizedtrust.splice.http.v0.definitions.{
Expand All @@ -40,14 +41,20 @@ import org.lfdecentralizedtrust.splice.validator.automation.TopupMemberTrafficTr
import org.lfdecentralizedtrust.splice.wallet.automation.CollectRewardsAndMergeAmuletsTrigger

import scala.concurrent.{Future, blocking}
import scala.math.BigDecimal.javaBigDecimal2bigDecimal
import scala.util.{Success, Try}

// this test sets fees to zero, and that only works from 0.1.14 onwards
@org.lfdecentralizedtrust.splice.util.scalatesttags.SpliceAmulet_0_1_14
class ScanIntegrationTest extends IntegrationTest with WalletTestUtil with TimeTestUtil {
private val defaultPageSize = Limit.MaxPageSize
override def environmentDefinition: SpliceEnvironmentDefinition =
EnvironmentDefinition
.simpleTopology1Sv(this.getClass.getSimpleName)
.addConfigTransforms((_, config) =>
updateAllSvAppFoundDsoConfigs_(
_.copy(zeroTransferFees = true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for compat tests, see: ed075da#diff-34afbc0f017051b26567b18594e7d3bd5d0e21928e6848d59eb1257e9b66adfaR36
The old daml version will fail an expect for the fees not being 0 iirc

After fixing, I suggest you trigger the compat tests as per https://github.com/hyperledger-labs/splice/blob/main/DEVELOPMENT.md#daml-version-guards-in-integration-tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for catching this. I've added the SpliceAmulet_0_1_14 tag; and will kick-off a compat test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)(config)
)
.addConfigTransforms((_, config) =>
(updateAutomationConfig(ConfigurableApp.Validator)(
_.withPausedTrigger[CollectRewardsAndMergeAmuletsTrigger]
Expand Down Expand Up @@ -386,15 +393,8 @@ class ScanIntegrationTest extends IntegrationTest with WalletTestUtil with TimeT
balance.unlockedQty shouldBe (walletUsdToAmulet(aliceTapAmount) + transferAmount)
}
eventually() {
val approxBobFees = walletUsdToAmulet(3) // this value depends on transferAmount
val balance = bobWalletClient.balance()
assertInRange(
balance.unlockedQty,
(
walletUsdToAmulet(bobTapAmount) - transferAmount - approxBobFees,
walletUsdToAmulet(bobTapAmount) - transferAmount,
),
)
balance.unlockedQty shouldBe walletUsdToAmulet(bobTapAmount) - transferAmount
}
}
val bobBalanceAfterTransfer = bobWalletClient.balance()
Expand All @@ -417,17 +417,12 @@ class ScanIntegrationTest extends IntegrationTest with WalletTestUtil with TimeT
val transfer = activities.flatMap(_.transfer).loneElement
val inputAmuletAmount =
transfer.sender.inputAmuletAmount.map(BigDecimal(_)).getOrElse(BigDecimal(0))
val senderChangeFee = BigDecimal(transfer.sender.senderChangeFee)
senderChangeFee shouldBe (amuletConfig.amuletCreateFee)
val senderFee = BigDecimal(transfer.sender.senderFee)
val holdingFees = BigDecimal(transfer.sender.holdingFees)
val senderChangeAmount = BigDecimal(transfer.sender.senderChangeAmount)

senderFee shouldBe expectedSenderFee(transferAmount)
BigDecimal(transfer.sender.senderChangeFee) shouldBe BigDecimal(0)
BigDecimal(transfer.sender.senderFee) shouldBe BigDecimal(0)
BigDecimal(transfer.sender.holdingFees) shouldBe BigDecimal(0)

val totalSenderFee = senderFee + holdingFees + senderChangeFee

inputAmuletAmount - senderChangeAmount shouldBe (transferAmount + totalSenderFee)
val senderChangeAmount = BigDecimal(transfer.sender.senderChangeAmount)
inputAmuletAmount - senderChangeAmount shouldBe transferAmount

// alice receives transfer
transfer.receivers
Expand Down Expand Up @@ -476,9 +471,9 @@ class ScanIntegrationTest extends IntegrationTest with WalletTestUtil with TimeT
}
clue("Bob receives self-transfer") {
eventually() {
// a self-transfer should cost some fees.
// a self-transfer should not cost any fees.
val balance = bobWalletClient.balance()
balance.unlockedQty should be < bobBalanceAfterTransfer.unlockedQty
balance.unlockedQty shouldBe bobBalanceAfterTransfer.unlockedQty
}
}
clue("Bob's self-transfer is shown in scan activity") {
Expand All @@ -500,15 +495,14 @@ class ScanIntegrationTest extends IntegrationTest with WalletTestUtil with TimeT
val inputAmuletAmount =
transfer.sender.inputAmuletAmount.map(BigDecimal(_)).getOrElse(BigDecimal(0))
val senderChangeFee = BigDecimal(transfer.sender.senderChangeFee)
senderChangeFee shouldBe (amuletConfig.amuletCreateFee)
senderChangeFee shouldBe BigDecimal(0)

val senderFee = BigDecimal(transfer.sender.senderFee)
val holdingFees = BigDecimal(transfer.sender.holdingFees)
BigDecimal(transfer.sender.holdingFees) shouldBe BigDecimal(0)
val senderChangeAmount = BigDecimal(transfer.sender.senderChangeAmount)
senderFee shouldBe walletUsdToAmulet(SpliceUtil.defaultCreateFee.fee)
senderFee shouldBe BigDecimal(0)

val totalSenderFee = senderFee + holdingFees + senderChangeFee
inputAmuletAmount - senderChangeAmount shouldBe (selfTransferAmount + totalSenderFee)
inputAmuletAmount - senderChangeAmount shouldBe selfTransferAmount

BigDecimal(receiver.amount) shouldBe selfTransferAmount
BigDecimal(receiver.receiverFee) shouldBe BigDecimal(0)
Expand Down Expand Up @@ -555,9 +549,7 @@ class ScanIntegrationTest extends IntegrationTest with WalletTestUtil with TimeT
PartyId
.tryFromProtoPrimitive(receiver.party) shouldBe (charlieUserParty)
BigDecimal(receiver.amount) shouldBe transferAmount
BigDecimal(receiver.receiverFee) shouldBe expectedSenderFee(
transferAmount
) * receiverFeeRatio
BigDecimal(receiver.receiverFee) shouldBe BigDecimal(0)
}
}
}
Expand Down Expand Up @@ -800,22 +792,6 @@ class ScanIntegrationTest extends IntegrationTest with WalletTestUtil with TimeT
)
}

def expectedSenderFee(amount: BigDecimal) = {
val initialRate = SpliceUtil.defaultTransferFee.initialRate
val step1 = SpliceUtil.defaultTransferFee.steps.get(0)
val step2 = SpliceUtil.defaultTransferFee.steps.get(1)
val step3 = SpliceUtil.defaultTransferFee.steps.get(2)
val (step1Amount, step1Mult) = (walletUsdToAmulet(step1._1), step1._2)
val (step2Amount, step2Mult) = (walletUsdToAmulet(step2._1), step2._2)
// ensuring the right steps are hardcoded here.
walletUsdToAmulet(step3._1) should be > amount
val steppedRate =
initialRate * (amount min step1Amount) +
step1Mult * ((amount - step1Amount) max 0 min step2Amount) +
step2Mult * ((amount - step1Amount - step2Amount) max 0)
walletUsdToAmulet(SpliceUtil.defaultCreateFee.fee) + steppedRate
}

def triggerTopupAliceAndBob()(implicit env: SpliceTestConsoleEnvironment): (Boolean, Boolean) = {
val aliceTopupTrigger =
aliceValidatorBackend.appState.automation.trigger[TopupMemberTrafficTrigger]
Expand Down
Loading