Skip to content

Commit

Permalink
NODE-2570 Corrected RIDE generatingBalance field (#3898)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Nazarov <[email protected]>
  • Loading branch information
xrtm000 and phearnot authored Nov 15, 2023
1 parent d37fc36 commit 9b4827e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.EitherExt2
import com.wavesplatform.consensus.{FairPoSCalculator, PoSCalculator}
import com.wavesplatform.features.BlockchainFeatures
import com.wavesplatform.features.BlockchainFeatures.LightNode
import com.wavesplatform.features.MultiPaymentPolicyProvider.*
import com.wavesplatform.lang.{Global, ValidationError}
import com.wavesplatform.lang.directives.DirectiveSet
import com.wavesplatform.lang.directives.values.StdLibVersion
import com.wavesplatform.lang.script.Script
Expand All @@ -21,6 +21,7 @@ import com.wavesplatform.lang.v1.evaluator.{Log, ScriptResult}
import com.wavesplatform.lang.v1.traits.*
import com.wavesplatform.lang.v1.traits.domain.*
import com.wavesplatform.lang.v1.traits.domain.Recipient.*
import com.wavesplatform.lang.{Global, ValidationError}
import com.wavesplatform.state.*
import com.wavesplatform.state.BlockRewardCalculator.CurrentBlockRewardPart
import com.wavesplatform.state.diffs.invoke.{InvokeScript, InvokeScriptDiff, InvokeScriptTransactionLike}
Expand Down Expand Up @@ -157,7 +158,7 @@ class WavesEnvironment(
}

override def accountWavesBalanceOf(addressOrAlias: Recipient): Either[String, Environment.BalanceDetails] = {
val addressE: Either[ValidationError, account.Address] = addressOrAlias match {
val addressE = addressOrAlias match {
case Address(bytes) => account.Address.fromBytes(bytes.arr)
case Alias(name) => account.Alias.create(name).flatMap(a => blockchain.resolveAlias(a))
}
Expand All @@ -169,7 +170,10 @@ class WavesEnvironment(
} yield Environment.BalanceDetails(
portfolio.balance - portfolio.lease.out,
portfolio.balance,
blockchain.generatingBalance(address),
if (blockchain.isFeatureActivated(LightNode))
currentBlockchain().generatingBalance(address)
else
blockchain.generatingBalance(address),
effectiveBalance
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.wavesplatform.state.diffs.ci.sync

import com.wavesplatform.db.WithDomain
import com.wavesplatform.db.WithState.AddrWithBalance
import com.wavesplatform.features.BlockchainFeatures.LightNode
import com.wavesplatform.lang.directives.values.V7
import com.wavesplatform.lang.v1.compiler.TestCompiler
import com.wavesplatform.test.DomainPresets.*
import com.wavesplatform.test.PropSpec
import com.wavesplatform.transaction.TxHelpers.*

class SyncDAppGeneratingBalanceTest extends PropSpec with WithDomain {
property("sync balance changes should be taken into account for the generatingBalance field") {
val amount = 777
val dApp = TestCompiler(V7).compileContract(
s"""
| @Callable(i)
| func default() = {
| strict generatingBefore = i.caller.wavesBalance().generating
| strict result = Address(base58'$defaultAddress').invoke("call", [], [AttachedPayment(unit, $amount)])
| strict generatingAfter = i.caller.wavesBalance().generating
| [
| IntegerEntry("generatingDiff", generatingBefore - generatingAfter)
| ]
| }
|
| @Callable(i)
| func call() = []
""".stripMargin
)
withDomain(
BlockRewardDistribution.setFeaturesHeight(LightNode -> 4),
AddrWithBalance.enoughBalances(defaultSigner, secondSigner)
) { d =>
d.appendBlock(setScript(defaultSigner, dApp), setScript(secondSigner, dApp))

d.appendAndAssertSucceed(invoke(secondAddress, invoker = secondSigner))
d.liquidDiff.accountData.head._2.head._2.value shouldBe 0

d.appendAndAssertSucceed(invoke(secondAddress, invoker = secondSigner))
d.liquidDiff.accountData.head._2.head._2.value shouldBe amount
}
}
}

0 comments on commit 9b4827e

Please sign in to comment.