Skip to content

Commit

Permalink
GRPC test
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 committed Dec 15, 2023
1 parent a5bddfe commit 33d15ee
Showing 1 changed file with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.wavesplatform.api.grpc.test

import com.google.protobuf.ByteString
import com.wavesplatform.account.KeyPair
import com.wavesplatform.api.grpc.{ApplicationStatus, TransactionResponse, TransactionsApiGrpcImpl, TransactionsRequest}
import com.wavesplatform.api.grpc.{ApplicationStatus, TransactionResponse, TransactionSnapshotResponse, TransactionSnapshotsRequest, TransactionsApiGrpcImpl, TransactionsRequest}
import com.wavesplatform.block.Block
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.EitherExt2
Expand All @@ -11,16 +11,21 @@ import com.wavesplatform.db.WithDomain
import com.wavesplatform.db.WithState.AddrWithBalance
import com.wavesplatform.history.Domain
import com.wavesplatform.protobuf.transaction.{PBTransactions, Recipient}
import com.wavesplatform.state.TxMeta
import com.wavesplatform.protobuf.{ByteStrExt, PBSnapshots}
import com.wavesplatform.state.diffs.ENOUGH_AMT
import com.wavesplatform.state.{StateSnapshot, TxMeta}
import com.wavesplatform.test.*
import com.wavesplatform.test.DomainPresets.*
import com.wavesplatform.transaction.Asset.Waves
import com.wavesplatform.transaction.{TxHelpers, TxVersion}
import com.wavesplatform.transaction.TxHelpers.*
import com.wavesplatform.transaction.assets.exchange.{ExchangeTransaction, Order, OrderType}
import com.wavesplatform.transaction.{TxHelpers, TxVersion}
import com.wavesplatform.utils.DiffMatchers
import monix.execution.Scheduler.Implicits.global
import org.scalatest.{Assertion, BeforeAndAfterAll}

import scala.collection.immutable.VectorMap

class TransactionsApiGrpcSpec extends FreeSpec with BeforeAndAfterAll with DiffMatchers with WithDomain with GrpcApiHelpers {

val sender: KeyPair = TxHelpers.signer(1)
Expand Down Expand Up @@ -69,6 +74,64 @@ class TransactionsApiGrpcSpec extends FreeSpec with BeforeAndAfterAll with DiffM
}
}

"GetTransactionSnapshots" in withDomain(TransactionStateSnapshot, AddrWithBalance.enoughBalances(secondSigner)) { d =>
val recipient = signer(2).toAddress
val txs = Seq.fill(5)(transfer(amount = 1, fee = 100_000, from = secondSigner, to = recipient))

val firstThreeSnapshots = Seq(
StateSnapshot(balances =
VectorMap(
(secondAddress, Waves) -> (ENOUGH_AMT - 100_001),
(recipient, Waves) -> 1,
(defaultAddress, Waves) -> 200_040_000 // reward and 40% fee
)
),
StateSnapshot(balances =
VectorMap(
(secondAddress, Waves) -> (ENOUGH_AMT - 200_002),
(recipient, Waves) -> 2,
(defaultAddress, Waves) -> 200_080_000
)
),
StateSnapshot(balances =
VectorMap(
(secondAddress, Waves) -> (ENOUGH_AMT - 300_003),
(recipient, Waves) -> 3,
(defaultAddress, Waves) -> 200_120_000
)
)
)

def getSnapshots() = {
val request = TransactionSnapshotsRequest.of(txs.map(_.id().toByteString))
val (observer, response) = createObserver[TransactionSnapshotResponse]
getGrpcApi(d).getTransactionSnapshots(request, observer)
response.runSyncUnsafe().flatMap(_.snapshot).map(PBSnapshots.fromProtobuf(_, ByteStr.empty, 0)._1)
}

d.appendBlock(txs(0), txs(1))
d.appendMicroBlock(txs(2))
getSnapshots() shouldBe firstThreeSnapshots

d.appendBlock(txs(3), txs(4))
getSnapshots() shouldBe firstThreeSnapshots ++ Seq(
StateSnapshot(balances =
VectorMap(
(secondAddress, Waves) -> (ENOUGH_AMT - 400_004),
(recipient, Waves) -> 4,
(defaultAddress, Waves) -> 400_340_000 // 2 blocks reward, 100% fee from previous block and 40% fee from current
)
),
StateSnapshot(balances =
VectorMap(
(secondAddress, Waves) -> (ENOUGH_AMT - 500_005),
(recipient, Waves) -> 5,
(defaultAddress, Waves) -> 400_380_000
)
)
)
}

"NODE-973. GetTransactions should return correct data for orders with attachment" in {
def checkOrderAttachment(txResponse: TransactionResponse, expectedAttachment: ByteStr): Assertion = {
PBTransactions
Expand Down Expand Up @@ -143,7 +206,10 @@ class TransactionsApiGrpcSpec extends FreeSpec with BeforeAndAfterAll with DiffM
val challengedMiner = TxHelpers.signer(2)
val resender = TxHelpers.signer(3)
val recipient = TxHelpers.signer(4)
withDomain(TransactionStateSnapshot.configure(_.copy(lightNodeBlockFieldsAbsenceInterval = 0)), balances = AddrWithBalance.enoughBalances(sender)) { d =>
withDomain(
TransactionStateSnapshot.configure(_.copy(lightNodeBlockFieldsAbsenceInterval = 0)),
balances = AddrWithBalance.enoughBalances(sender)
) { d =>
val grpcApi = getGrpcApi(d)
val challengingMiner = d.wallet.generateNewAccount().get

Expand Down

0 comments on commit 33d15ee

Please sign in to comment.