Skip to content

Commit

Permalink
NODE-2577: Auto tests for the subscribe request in blockchain updates (
Browse files Browse the repository at this point in the history
  • Loading branch information
Kseolis authored Jun 5, 2023
1 parent 2f56bfa commit a062faa
Show file tree
Hide file tree
Showing 10 changed files with 1,530 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ class BlockchainUpdatesSpec extends FreeSpec with WithBUDomain with ScalaFutures

startRead.lock()

val subscription = Future(repo.createSubscriptionObserver(SubscribeRequest.of(1, toHeight)))
val subscription = Future(repo.createFakeObserver(SubscribeRequest.of(1, toHeight)))

appendExtraBlocks(d)

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ object FakeObserver {
ur.subscribe(request, obs)
obs
}

def createSubscriptionObserver(request: SubscribeRequest): FakeObserver[SubscribeEvent] = {
val obs = FakeObserver.apply[SubscribeEvent]
ur.subscribe(request, obs)
obs
}
}

// Matchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wavesplatform.events

import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.events.FakeObserver.*
import FakeObserver.*
import com.wavesplatform.events.api.grpc.protobuf.SubscribeRequest
import com.wavesplatform.events.protobuf.TransactionMetadata
import com.wavesplatform.protobuf.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.wavesplatform.events

import com.google.common.util.concurrent.MoreExecutors
import com.wavesplatform.db.WithDomain
import com.wavesplatform.events.FakeObserver.*
import FakeObserver.*
import com.wavesplatform.db.WithState.AddrWithBalance
import com.wavesplatform.events.api.grpc.protobuf.SubscribeRequest
import com.wavesplatform.events.protobuf.BlockchainUpdated as PBBlockchainUpdated
import com.wavesplatform.events.repo.LiquidState
Expand Down Expand Up @@ -48,11 +49,13 @@ trait WithBUDomain extends WithDomain { _: Suite =>
}
}

def withGenerateSubscription(request: SubscribeRequest = SubscribeRequest.of(1, Int.MaxValue), settings: WavesSettings)(
generateBlocks: Domain => Unit
)(f: Seq[PBBlockchainUpdated] => Unit): Unit = {
def withGenerateSubscription(
request: SubscribeRequest = SubscribeRequest.of(1, Int.MaxValue),
settings: WavesSettings,
balances: Seq[AddrWithBalance] = Seq(AddrWithBalance(TxHelpers.defaultSigner.toAddress, Constants.TotalWaves * Constants.UnitsInWave))
)(generateBlocks: Domain => Unit)(f: Seq[PBBlockchainUpdated] => Unit): Unit = {
withDomainAndRepo(settings) { (d, repo) =>
d.appendBlock(TxHelpers.genesis(TxHelpers.defaultSigner.toAddress, Constants.TotalWaves * Constants.UnitsInWave))
d.appendBlock(balances.map(awb => TxHelpers.genesis(awb.address, awb.balance))*)

val subscription = repo.createFakeObserver(request)
generateBlocks(d)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.wavesplatform.events.fixtures

object PrepareInvokeTestData {
val scriptTransferIssueAssetNum: Long = 21000
val scriptTransferUnitNum: Long = 22000
val scriptTransferAssetNum: Long = 25000
val paymentNum: Long = 30000
val sponsorFeeAssetNum: Long = 35000
val sponsorFeeIssueAssetNum: Long = 40000
val reissueNum: Int = 50000
val burnNum: Int = 100000
val leaseNum: Long = 200000
val baz = "baz"
val bar = "bar"

val issueData: Map[String, Any] = Map(
"name" -> "issuedAssetName",
"description" -> "asset_ride_description",
"amount" -> 416168000,
"decimals" -> 8,
"nonce" -> 1
)

val dataMap: Map[String, Any] = Map(
"intVal" -> 25400,
"stringVal" -> "test_string",
"booleanVal" -> "true"
)

def invokeAssetScript(libVersion: Int): String =
s"""
|{-# STDLIB_VERSION $libVersion #-}
|{-# CONTENT_TYPE DAPP #-}
|{-# SCRIPT_TYPE ACCOUNT #-}
|@Callable(i)
|func setData(assetId:ByteVector, address:ByteVector)={
|let issueAsset = Issue("${issueData.apply("name")}","${issueData.apply("description")}",${issueData.apply("amount")},
|${issueData.apply("decimals")},true,unit,${issueData.apply("nonce")})
|let issueAssetId = issueAsset.calculateAssetId()
|let lease = Lease(Address(address), $leaseNum)
| [
| issueAsset,
| lease,
| LeaseCancel(lease.calculateLeaseId()),
| IntegerEntry("int", ${dataMap.apply("intVal")}),
| BinaryEntry("byte", assetId),
| BooleanEntry("bool", ${dataMap.apply("booleanVal")}),
| StringEntry("str", "${dataMap.apply("stringVal")}"),
| DeleteEntry("int"),
| Reissue(assetId, $reissueNum,true),
| Burn(assetId, $burnNum),
| ScriptTransfer(Address(address), $scriptTransferAssetNum, assetId),
| ScriptTransfer(Address(address), $scriptTransferIssueAssetNum, issueAssetId),
| ScriptTransfer(Address(address), $scriptTransferUnitNum, unit),
| SponsorFee(assetId, $sponsorFeeAssetNum),
| SponsorFee(issueAssetId, $sponsorFeeIssueAssetNum)
| ]
|}
|""".stripMargin

def mainDAppScript(libVersion: Int): String =
s"""
|{-# STDLIB_VERSION $libVersion #-}
|{-# CONTENT_TYPE DAPP #-}
|{-# SCRIPT_TYPE ACCOUNT #-}
|@Callable(i)
|func foo(acc1:ByteVector, acc2:ByteVector, a:Int, key1:String, assetId:ByteVector)={
|strict res = invoke(Address(acc1),"$bar",[a, assetId, acc2],[AttachedPayment(assetId,$paymentNum)])
|match res {
| case r : Int =>
|(
| [
| IntegerEntry(key1, r)
| ]
|)
| case _ => throw("Incorrect invoke result for res in dApp 1")
| }
|}
|""".stripMargin

def nestedDAppScript(firstRecipient: String, libVersion: Int): String =
s"""
|{-# STDLIB_VERSION $libVersion #-}
|{-# CONTENT_TYPE DAPP #-}
|{-# SCRIPT_TYPE ACCOUNT #-}
|@Callable(i)
|func $bar(a: Int, assetId: ByteVector, acc1: ByteVector)={
|strict res2 = invoke(Address(acc1),"$baz",[a],[])
|match res2 {
|case r: Int =>
|(
| [
| ScriptTransfer($firstRecipient, $scriptTransferAssetNum, assetId)
| ],
| a * 2
|)
| case _ => throw("Incorrect invoke result for res2")
| }
|}
|""".stripMargin

def doubleNestedDAppScript(secondRecipient: String, libVersion: Int): String =
s"""
|{-# STDLIB_VERSION $libVersion #-}
|{-# CONTENT_TYPE DAPP #-}
|{-# SCRIPT_TYPE ACCOUNT #-}
|@Callable(i)
|func $baz(a: Int) = {
|(
| [
| ScriptTransfer($secondRecipient, $scriptTransferUnitNum, unit)
| ],
|a + 2
|)
|}
|""".stripMargin
}
Loading

0 comments on commit a062faa

Please sign in to comment.