-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NODE-2520 Corrected fail/reject on transfer action balance error (#3897)
- Loading branch information
Showing
3 changed files
with
72 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeTransferBalanceErrorTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.wavesplatform.state.diffs.ci | ||
|
||
import com.wavesplatform.db.WithDomain | ||
import com.wavesplatform.db.WithState.AddrWithBalance | ||
import com.wavesplatform.features.BlockchainFeatures.{LightNode, RideV6} | ||
import com.wavesplatform.lang.directives.values.V5 | ||
import com.wavesplatform.lang.v1.compiler.TestCompiler | ||
import com.wavesplatform.test.DomainPresets.{RideV5, WavesSettingsOps} | ||
import com.wavesplatform.test.{PropSpec, produce} | ||
import com.wavesplatform.transaction.Asset.IssuedAsset | ||
import com.wavesplatform.transaction.TxHelpers.* | ||
|
||
class InvokeTransferBalanceErrorTest extends PropSpec with WithDomain { | ||
private val assetFailScript = TestCompiler(V5).compileExpression( | ||
s""" | ||
| strict c = ${(1 to 5).map(_ => "sigVerify(base58'', base58'', base58'')").mkString(" || ")} | ||
| if (true) then throw() else true | ||
""".stripMargin | ||
) | ||
|
||
property("invoke is always rejected with a lack of funds without execution of ScriptTransfer script after RideV6, corrected after LightNode") { | ||
val issueTx = issue(signer(10), script = Some(assetFailScript)) | ||
val asset = IssuedAsset(issueTx.id()) | ||
val dApp = TestCompiler(V5).compileContract( | ||
s""" | ||
| @Callable(i) | ||
| func default() = { | ||
| [ScriptTransfer(i.caller, 1, base58'$asset')] | ||
| } | ||
| | ||
| @Callable(i) | ||
| func complex() = { | ||
| strict c = ${(1 to 6).map(_ => "sigVerify(base58'', base58'', base58'')").mkString(" || ")} | ||
| [ScriptTransfer(i.caller, 1, base58'$asset')] | ||
| } | ||
""".stripMargin | ||
) | ||
withDomain( | ||
RideV5.setFeaturesHeight(RideV6 -> 6, LightNode -> 7), | ||
AddrWithBalance.enoughBalances(secondSigner, signer(10)) | ||
) { d => | ||
d.appendBlock(issueTx) | ||
d.appendBlock(setScript(secondSigner, dApp)) | ||
|
||
// RideV5 — always failed | ||
d.appendAndAssertFailed(invoke(), "Transaction is not allowed by script of the asset") | ||
d.appendAndAssertFailed(invoke(func = Some("complex")), "Transaction is not allowed by script of the asset") | ||
|
||
// RideV6 — always rejected | ||
d.appendBlockE(invoke()) should produce("negative asset balance") | ||
d.appendBlockE(invoke(func = Some("complex"))) should produce("negative asset balance") | ||
|
||
// LightNode — rejected or failed | ||
d.appendBlock() | ||
d.appendBlockE(invoke()) should produce("negative asset balance") | ||
d.appendAndAssertFailed(invoke(func = Some("complex")), "negative asset balance") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters