Skip to content

Commit cacc4e0

Browse files
authored
Merge branch 'version-1.5.x' into node-micro-block-inv-absence
2 parents 309ee34 + c7245d6 commit cacc4e0

File tree

6 files changed

+45
-170
lines changed

6 files changed

+45
-170
lines changed

node-it/src/test/scala/com/wavesplatform/it/sync/activation/AcceptFailedScriptActivationSuite.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class AcceptFailedScriptActivationSuite extends BaseTransactionSuite with NTPTim
300300
smartMatcherFee,
301301
100L,
302302
ts,
303-
ts + Order.MaxLiveTime,
303+
ts + 2.days.toMillis,
304304
smartMatcherFee
305305
)
306306
.explicitGet()
@@ -314,7 +314,7 @@ class AcceptFailedScriptActivationSuite extends BaseTransactionSuite with NTPTim
314314
smartMatcherFee,
315315
100L,
316316
ts,
317-
ts + Order.MaxLiveTime,
317+
ts + 2.days.toMillis,
318318
smartMatcherFee
319319
)
320320
.explicitGet()
@@ -375,7 +375,7 @@ class AcceptFailedScriptActivationSuite extends BaseTransactionSuite with NTPTim
375375
10L,
376376
100L,
377377
ts,
378-
ts + Order.MaxLiveTime,
378+
ts + 2.days.toMillis,
379379
smartMatcherFee,
380380
matcherFeeAssetId = IssuedAsset(ByteStr.decodeBase58(feeAsset).get)
381381
)
@@ -390,7 +390,7 @@ class AcceptFailedScriptActivationSuite extends BaseTransactionSuite with NTPTim
390390
10L,
391391
100L,
392392
ts,
393-
ts + Order.MaxLiveTime,
393+
ts + 2.days.toMillis,
394394
smartMatcherFee,
395395
matcherFeeAssetId = IssuedAsset(ByteStr.decodeBase58(feeAsset).get)
396396
)

node-it/src/test/scala/com/wavesplatform/it/sync/grpc/FailedTransactionGrpcSuite.scala

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,6 @@ class FailedTransactionGrpcSuite extends GrpcBaseTransactionSuite with FailedTra
121121
sender.setScript(contract, Right(Some(script)), setScriptFee, waitForTx = true)
122122
}
123123

124-
test("InvokeScriptTransaction: insufficient action fees propagates failed transaction") {
125-
val invokeFee = 0.005.waves
126-
val setAssetScriptMinFee = setAssetScriptFee + smartFee * 2
127-
val priorityFee = setAssetScriptMinFee + invokeFee
128-
129-
updateAssetScript(result = true, smartAsset, contract, setAssetScriptMinFee)
130-
131-
for (typeName <- Seq("transfer", "issue", "reissue", "burn")) {
132-
updateTikTok("unknown", setAssetScriptMinFee)
133-
134-
overflowBlock()
135-
sendTxsAndThenPriorityTx(
136-
_ =>
137-
sender
138-
.broadcastInvokeScript(
139-
caller,
140-
Recipient().withPublicKeyHash(contractAddr),
141-
Some(FUNCTION_CALL(FunctionHeader.User("tikTok"), List.empty)),
142-
fee = invokeFee
143-
),
144-
() => updateTikTok(typeName, priorityFee, waitForTx = false)
145-
)((txs, _) => assertFailedTxs(txs))
146-
}
147-
}
148-
149124
test("InvokeScriptTransaction: invoke script error in payment asset propagates failed transaction") {
150125
val invokeFee = 0.005.waves + smartFee
151126
val setAssetScriptMinFee = setAssetScriptFee + smartFee

node-it/src/test/scala/com/wavesplatform/it/sync/transactions/FailedTransactionSuite.scala

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ package com.wavesplatform.it.sync.transactions
33
import com.typesafe.config.Config
44
import com.wavesplatform.api.http.ApiError.TransactionNotAllowedByAssetScript
55
import com.wavesplatform.api.http.DebugMessage
6-
import com.wavesplatform.common.state.ByteStr
76
import com.wavesplatform.common.utils.EitherExt2
87
import com.wavesplatform.it.api.SyncHttpApi.*
9-
import com.wavesplatform.it.api.{StateChanges, TransactionStatus}
108
import com.wavesplatform.it.sync.*
119
import com.wavesplatform.it.transactions.BaseTransactionSuite
12-
import com.wavesplatform.lang.v1.compiler.Terms
1310
import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3
14-
import com.wavesplatform.state.{BooleanDataEntry, StringDataEntry}
11+
import com.wavesplatform.state.StringDataEntry
1512
import com.wavesplatform.test.*
1613
import com.wavesplatform.transaction.assets.exchange.AssetPair
1714
import com.wavesplatform.transaction.smart.script.ScriptCompiler
@@ -118,52 +115,6 @@ class FailedTransactionSuite extends BaseTransactionSuite with CancelAfterFailur
118115
sender.setScript(contract, Some(script), setScriptFee, waitForTx = true).id
119116
}
120117

121-
test("InvokeScriptTransaction: insufficient action fees propagates failed transaction") {
122-
val invokeFee = 0.005.waves
123-
val setAssetScriptMinFee = setAssetScriptFee + smartFee
124-
val priorityFee = setAssetScriptMinFee + invokeFee
125-
126-
updateAssetScript(result = true, smartAsset, contract, setAssetScriptMinFee)
127-
128-
for (typeName <- Seq("transfer", "issue", "reissue", "burn")) {
129-
updateTikTok("unknown", setAssetScriptMinFee)
130-
131-
val prevBalance = sender.balance(caller.toAddress.toString).balance
132-
val prevAssetBalance = sender.assetBalance(contractAddress, smartAsset)
133-
val prevAssets = sender.assetsBalance(contractAddress)
134-
135-
overflowBlock()
136-
sendTxsAndThenPriorityTx(
137-
_ => sender.invokeScript(caller, contractAddress, Some("tikTok"), fee = invokeFee)._1.id,
138-
() => updateTikTok(typeName, priorityFee, waitForTx = false)
139-
) { (txs, priorityTx) =>
140-
logPriorityTx(priorityTx)
141-
142-
val failed = assertFailedTxs(txs)
143-
144-
sender.balance(caller.toAddress.toString).balance shouldBe prevBalance - txs.size * invokeFee
145-
sender.assetBalance(contractAddress, smartAsset) shouldBe prevAssetBalance
146-
sender.assetsBalance(contractAddress).balances should contain theSameElementsAs prevAssets.balances
147-
148-
val (scriptInvokedInfo, issuedInfo) =
149-
if (typeName == "issue")
150-
("", " with 1 assets issued")
151-
else
152-
(" with 1 total scripts invoked", "")
153-
154-
val minFee = if (typeName == "issue") invokeFee + issueFee else invokeFee + smartFee
155-
val text = s"Fee in WAVES for InvokeScriptTransaction ($invokeFee in WAVES)" +
156-
s"$scriptInvokedInfo$issuedInfo does not exceed minimal value of $minFee WAVES."
157-
158-
failed.foreach { s =>
159-
checkStateChange(sender.stateChanges(s.id), 2, text)
160-
}
161-
162-
failed
163-
}
164-
}
165-
}
166-
167118
test("InvokeScriptTransaction: reject transactions if account script failed") {
168119
val invokeFee = 0.005.waves
169120
val setAssetScriptMinFee = setAssetScriptFee + smartFee
@@ -212,50 +163,6 @@ class FailedTransactionSuite extends BaseTransactionSuite with CancelAfterFailur
212163
}
213164
}
214165

215-
test("InvokeScriptTransaction: transactionHeightById returns only succeed transactions") {
216-
val invokeFee = 0.005.waves + smartFee
217-
val setAssetScriptMinFee = setAssetScriptFee + smartFee
218-
val priorityFee = setAssetScriptMinFee + invokeFee
219-
220-
updateAccountScript(None, caller, setScriptFee + smartFee)
221-
updateTikTok("reissue", setAssetScriptMinFee)
222-
updateAssetScript(result = true, smartAsset, contract, setAssetScriptMinFee)
223-
waitForEmptyUtx()
224-
overflowBlock()
225-
226-
val failedTxs = sendTxsAndThenPriorityTx(
227-
_ => sender.invokeScript(caller, contractAddress, Some("tikTok"), fee = invokeFee)._1.id,
228-
() => updateAssetScript(result = false, smartAsset, contract, priorityFee)
229-
) { (txs, priorityTx) =>
230-
logPriorityTx(priorityTx)
231-
assertFailedTxs(txs)
232-
}
233-
234-
checkTransactionHeightById(failedTxs)
235-
}
236-
237-
test("ExchangeTransaction: transaction validates as failed when asset script fails") {
238-
val Precondition(amountAsset, priceAsset, buyFeeAsset, sellFeeAsset) =
239-
exchangePreconditions(
240-
Some(ScriptCompiler.compile("true", ScriptEstimatorV3(fixOverflow = true, overhead = false)).explicitGet()._1.bytes().base64)
241-
)
242-
243-
val assetPair = AssetPair.createAssetPair(amountAsset, priceAsset).get
244-
val fee = 0.003.waves + 4 * smartFee
245-
val sellMatcherFee = fee / 100000L
246-
val buyMatcherFee = fee / 100000L
247-
248-
val (assetScript, _) =
249-
ScriptCompiler.compile("if true then throw(\"error\") else false", ScriptEstimatorV3(fixOverflow = true, overhead = false)).explicitGet()
250-
val scriptTx = sender.setAssetScript(priceAsset, buyerAddress, script = Some(assetScript.bytes().base64))
251-
nodes.waitForHeightAriseAndTxPresent(scriptTx.id)
252-
253-
val tx = mkExchange(buyer, seller, matcher, assetPair, fee, buyFeeAsset, sellFeeAsset, buyMatcherFee, sellMatcherFee)
254-
val result = sender.signedValidate(tx.json())
255-
(result \ "valid").as[Boolean] shouldBe false
256-
(result \ "error").as[String] should include("not allowed by script of the asset")
257-
}
258-
259166
test("ExchangeTransaction: invalid exchange tx when asset script fails on broadcast") {
260167
val init = Seq(
261168
sender.setScript(firstKeyPair, None, setScriptFee + smartFee).id,
@@ -309,38 +216,6 @@ class FailedTransactionSuite extends BaseTransactionSuite with CancelAfterFailur
309216
private def waitForTxs(txs: Seq[String]): Unit =
310217
nodes.waitFor("preconditions", 500.millis)(_.transactionStatus(txs).forall(_.status == "confirmed"))(_.forall(identity))
311218

312-
private def checkStateChange(info: StateChanges, code: Int, text: String, strict: Boolean = false): Unit = {
313-
info.stateChanges shouldBe defined
314-
info.stateChanges.get.issues.size shouldBe 0
315-
info.stateChanges.get.reissues.size shouldBe 0
316-
info.stateChanges.get.burns.size shouldBe 0
317-
info.stateChanges.get.error shouldBe defined
318-
info.stateChanges.get.error.get.code shouldBe code
319-
if (strict)
320-
info.stateChanges.get.error.get.text shouldBe text
321-
else
322-
info.stateChanges.get.error.get.text should include(text)
323-
}
324-
325-
private def checkTransactionHeightById(failedTxs: Seq[TransactionStatus]): Unit = {
326-
val defineTxs = failedTxs.map { status =>
327-
sender
328-
.invokeScript(
329-
caller,
330-
contractAddress,
331-
Some("defineTxHeight"),
332-
List(Terms.CONST_BYTESTR(ByteStr.decodeBase58(status.id).get).explicitGet()),
333-
fee = invokeFee
334-
)
335-
._1
336-
.id
337-
}
338-
339-
waitForTxs(defineTxs)
340-
341-
failedTxs.foreach(status => sender.getDataByKey(contractAddress, status.id) shouldBe BooleanDataEntry(status.id, value = false))
342-
}
343-
344219
private def exchangePreconditions(initScript: Option[String]): Precondition = {
345220
val transfers = Seq(
346221
sender.transfer(sender.keyPair, sellerAddress.toAddress.toString, 100.waves).id,

node/src/test/scala/com/wavesplatform/RxScheduler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ trait RxScheduler extends BeforeAndAfterAll { _: Suite =>
2424

2525
def test[A](f: => Future[A]): A = Await.result(f, 10.seconds)
2626

27-
def send[A](p: Observer[A])(a: A): Future[Ack] =
27+
def send[A](p: Observer[A], timeout: Int = 500)(a: A): Future[Ack] =
2828
p.onNext(a)
2929
.map(ack => {
30-
Thread.sleep(500)
30+
Thread.sleep(timeout)
3131
ack
3232
})
3333

node/src/test/scala/com/wavesplatform/network/RxExtensionLoaderSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class RxExtensionLoaderSpec extends FreeSpec with RxScheduler with BlockGen {
9292
"should blacklist GetSignatures timeout" in withExtensionLoader(Seq.tabulate(100)(byteStr), 1.millis) { (_, _, _, ccsw, _) =>
9393
val ch = new EmbeddedChannel()
9494
test(for {
95-
_ <- send(ccsw)(ChannelClosedAndSyncWith(None, Some(BestChannel(ch, 1: BigInt))))
95+
_ <- send(ccsw, timeout = 1000)(ChannelClosedAndSyncWith(None, Some(BestChannel(ch, 1: BigInt))))
9696
} yield {
9797
ch.isOpen shouldBe false
9898
})

node/src/test/scala/com/wavesplatform/state/diffs/ci/InvokeActionsFeeTest.scala

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import com.wavesplatform.lang.v1.compiler.TestCompiler
1010
import com.wavesplatform.state.diffs.FeeValidation.{FeeConstants, FeeUnit}
1111
import com.wavesplatform.test.*
1212
import com.wavesplatform.transaction.Asset.IssuedAsset
13-
import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment
13+
import com.wavesplatform.transaction.TxHelpers.*
1414
import com.wavesplatform.transaction.smart.InvokeScriptTransaction
15+
import com.wavesplatform.transaction.smart.InvokeScriptTransaction.Payment
1516
import com.wavesplatform.transaction.{Transaction, TransactionType, TxHelpers}
1617
import org.scalatest.{EitherValues, Inside}
1718

@@ -26,10 +27,7 @@ class InvokeActionsFeeTest extends PropSpec with Inside with WithState with DBCa
2627

2728
private val verifier: Script =
2829
TestCompiler(V4).compileExpression(
29-
s""" {-# STDLIB_VERSION 4 #-}
30-
| {-# SCRIPT_TYPE ASSET #-}
31-
| {-# CONTENT_TYPE EXPRESSION #-}
32-
|
30+
s"""
3331
| !(sigVerify_32Kb(base58'', base58'', base58'') ||
3432
| sigVerify_32Kb(base58'', base58'', base58'') ||
3533
| sigVerify_32Kb(base58'', base58'', base58''))
@@ -38,13 +36,13 @@ class InvokeActionsFeeTest extends PropSpec with Inside with WithState with DBCa
3836

3937
private def dApp(asset: IssuedAsset): Script =
4038
TestCompiler(V4).compileContract(s"""
41-
| @Callable(i)
42-
| func default() =
43-
| [
44-
| ScriptTransfer(i.caller, 1, base58'$asset'),
45-
| Burn(base58'$asset', 1),
46-
| Reissue(base58'$asset', 1, false)
47-
| ]
39+
| @Callable(i)
40+
| func default() =
41+
| [
42+
| ScriptTransfer(i.caller, 1, base58'$asset'),
43+
| Burn(base58'$asset', 1),
44+
| Reissue(base58'$asset', 1, false)
45+
| ]
4846
""".stripMargin)
4947

5048
private val paymentPreconditions: (Seq[AddrWithBalance], List[Transaction], () => InvokeScriptTransaction, () => InvokeScriptTransaction) = {
@@ -64,6 +62,33 @@ class InvokeActionsFeeTest extends PropSpec with Inside with WithState with DBCa
6462
(balances, List(issue, transfer1, transfer2, setVerifier, setDApp), invokeFromScripted, invokeFromNonScripted)
6563
}
6664

65+
property("insufficient action fees propagates failed transaction before RIDE V5 activation") {
66+
withDomain(RideV4, AddrWithBalance.enoughBalances(secondSigner)) { d =>
67+
val issueTx = issue(script = Some(TestCompiler(V4).compileExpression("true")))
68+
val asset = IssuedAsset(issueTx.id())
69+
val dApp = TestCompiler(V4).compileContract(
70+
s"""
71+
| @Callable(i)
72+
| func transfer() = [ScriptTransfer(i.caller, 1, base58'$asset')]
73+
|
74+
| @Callable(i)
75+
| func reissue() = [Reissue(base58'$asset', 1, true)]
76+
|
77+
| @Callable(i)
78+
| func burn() = [Burn(base58'$asset', 1)]
79+
|
80+
| @Callable(i)
81+
| func issue() = [Issue("name", "", 1000, 4, true, unit, 0)]
82+
""".stripMargin
83+
)
84+
d.appendBlock(issueTx, setScript(secondSigner, dApp))
85+
d.appendAndAssertFailed(invoke(func = Some("transfer")), "with 1 total scripts invoked does not exceed minimal value of 900000 WAVES")
86+
d.appendAndAssertFailed(invoke(func = Some("reissue")), "with 1 total scripts invoked does not exceed minimal value of 900000 WAVES")
87+
d.appendAndAssertFailed(invoke(func = Some("burn")), "with 1 total scripts invoked does not exceed minimal value of 900000 WAVES")
88+
d.appendAndAssertFailed(invoke(func = Some("issue")), "with 1 assets issued does not exceed minimal value of 100500000 WAVES")
89+
}
90+
}
91+
6792
property(s"fee for asset scripts is not required after activation ${BlockchainFeatures.SynchronousCalls}") {
6893
val (balances, preparingTxs, invokeFromScripted, invokeFromNonScripted) = paymentPreconditions
6994
withDomain(fsWithV5, balances) { d =>

0 commit comments

Comments
 (0)