diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala index 8a5bc384f3..fdd2ec8aa2 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala @@ -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 @@ -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} @@ -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)) } @@ -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 ) } diff --git a/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppGeneratingBalanceTest.scala b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppGeneratingBalanceTest.scala new file mode 100644 index 0000000000..07aebadeb4 --- /dev/null +++ b/node/src/test/scala/com/wavesplatform/state/diffs/ci/sync/SyncDAppGeneratingBalanceTest.scala @@ -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 + } + } +}