Skip to content

Commit

Permalink
Merge branch 'version-1.5.x' into NODE-2609
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot authored Oct 6, 2023
2 parents 9dc89e8 + c82177a commit 68d5e91
Show file tree
Hide file tree
Showing 31 changed files with 127 additions and 1,318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.wavesplatform.lang.v1.FunctionHeader
import com.wavesplatform.lang.v1.compiler.Terms
import com.wavesplatform.lang.v1.compiler.Terms.FUNCTION_CALL
import com.wavesplatform.state.DataEntry.Format
import com.wavesplatform.state.{AssetDistribution, AssetDistributionPage, DataEntry, EmptyDataEntry, LeaseBalance, Portfolio}
import com.wavesplatform.state.{AssetDistributionPage, DataEntry, EmptyDataEntry, LeaseBalance, Portfolio}
import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves}
import com.wavesplatform.transaction.assets.*
import com.wavesplatform.transaction.assets.exchange.{Order, ExchangeTransaction as ExchangeTx}
Expand Down Expand Up @@ -338,11 +338,6 @@ object AsyncHttpApi extends Assertions {
get(url, amountsAsStrings).as[AssetDistributionPage](amountsAsStrings)
}

def assetDistribution(asset: String, amountsAsStrings: Boolean = false): Future[AssetDistribution] = {
val req = s"/assets/$asset/distribution"
get(req, amountsAsStrings).as[AssetDistribution](amountsAsStrings)
}

def effectiveBalance(address: String, confirmations: Option[Int] = None, amountsAsStrings: Boolean = false): Future[Balance] = {
val maybeConfirmations = confirmations.fold("")(a => s"/$a")
get(s"/addresses/effectiveBalance/$address$maybeConfirmations", amountsAsStrings).as[Balance](amountsAsStrings)
Expand Down Expand Up @@ -603,9 +598,6 @@ object AsyncHttpApi extends Assertions {
def stateChanges(invokeScriptTransactionId: String, amountsAsStrings: Boolean): Future[StateChanges] =
transactionInfo[StateChanges](invokeScriptTransactionId, amountsAsStrings)

def debugStateChangesByAddress(address: String, limit: Int = 10000, after: Option[String] = None): Future[Seq[StateChanges]] =
get(s"/debug/stateChanges/address/$address/limit/$limit${after.fold("")(a => s"?after=$a")}").as[Seq[StateChanges]]

def assetBalance(address: String, asset: String, amountsAsStrings: Boolean = false): Future[AssetBalance] =
get(s"/assets/balance/$address/$asset", amountsAsStrings).as[AssetBalance](amountsAsStrings)

Expand Down Expand Up @@ -647,12 +639,6 @@ object AsyncHttpApi extends Assertions {
def cancelSponsorship(sender: KeyPair, assetId: String, fee: Long, version: Byte = 1): Future[Transaction] =
sponsorAsset(sender, assetId, None, fee, version)

def transfer(sourceAddress: String, recipient: String, amount: Long, fee: Long): Future[Transaction] =
postJson(
"/assets/transfer",
TransferRequest(Some(1.toByte), Some(sourceAddress), None, recipient, None, amount, None, fee)
).as[Transaction]

def massTransfer(
sender: KeyPair,
transfers: Seq[Transfer],
Expand Down Expand Up @@ -809,8 +795,6 @@ object AsyncHttpApi extends Assertions {
def rollback(to: Int, returnToUTX: Boolean = true): Future[Unit] =
postJson("/debug/rollback", RollbackParams(to, returnToUTX)).map(_ => ())

def rollbackToBlockId(id: String): Future[Unit] = delete(s"/debug/rollback-to/$id").map(_ => ())

def ensureTxDoesntExist(txId: String): Future[Unit] =
utx()
.zip(findTransactionInfo(txId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.wavesplatform.it.Node
import com.wavesplatform.it.sync.*
import com.wavesplatform.lang.script.v1.ExprScript
import com.wavesplatform.lang.v1.compiler.Terms
import com.wavesplatform.state.{AssetDistribution, AssetDistributionPage, DataEntry}
import com.wavesplatform.state.{AssetDistributionPage, DataEntry}
import com.wavesplatform.transaction.assets.exchange.Order
import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransaction}
import com.wavesplatform.transaction.smart.InvokeScriptTransaction
Expand Down Expand Up @@ -261,9 +261,6 @@ object SyncHttpApi extends Assertions with matchers.should.Matchers {
): AssetDistributionPage =
sync(async(n).assetDistributionAtHeight(asset, height, limit, maybeAfter, amountsAsStrings))

def assetDistribution(asset: String): AssetDistribution =
sync(async(n).assetDistribution(asset))

def broadcastIssue(
source: KeyPair,
name: String,
Expand Down Expand Up @@ -307,10 +304,6 @@ object SyncHttpApi extends Assertions with matchers.should.Matchers {
sync(async(n).stateChanges(transactionId, amountsAsStrings))
}

def debugStateChangesByAddress(address: String, limit: Int, after: Option[String] = None): Seq[StateChanges] = {
sync(async(n).debugStateChangesByAddress(address, limit, after))
}

def payment(sourceAddress: String, recipient: String, amount: Long, fee: Long): Transaction =
sync(async(n).payment(sourceAddress, recipient, amount, fee))

Expand Down Expand Up @@ -813,15 +806,6 @@ object SyncHttpApi extends Assertions with matchers.should.Matchers {
}
}

def rollbackToBlockId(id: String): Unit = {
sync(
Future.traverse(nodes) { node =>
com.wavesplatform.it.api.AsyncHttpApi.NodeAsyncHttpApi(node).rollbackToBlockId(id)
},
ConditionAwaitTime
)
}

def waitForHeight(height: Int): Unit = {
sync(
Future.traverse(nodes) { node =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ class IssueReissueBurnAssetSuite extends BaseFreeSpec {
val acc = createDapp(script(simpleReissuableAsset))
val asset = issueValidated(acc, simpleReissuableAsset)
invokeScript(acc, "transferAndBurn", assetId = asset, count = 100)
nodes.waitForHeightArise()
sender.assetDistribution(asset).map { case (a, v) => a.toString -> v } shouldBe Map(
val height1 = nodes.waitForHeightArise()
sender.assetDistributionAtHeight(asset, height1 - 1, 10).items.map { case (a, v) => a.toString -> v } shouldBe Map(
miner.address -> 100L,
acc.toAddress.toString -> (simpleReissuableAsset.quantity - 200)
)
reissue(acc, CallableMethod, asset, 400, reissuable = false)
invokeScript(acc, "transferAndBurn", assetId = asset, count = 100)
nodes.waitForHeightArise()
sender.assetDistribution(asset).map { case (a, v) => a.toString -> v } shouldBe Map(
val height2 = nodes.waitForHeightArise()
sender.assetDistributionAtHeight(asset, height2 - 1, 10).items.map { case (a, v) => a.toString -> v } shouldBe Map(
miner.address -> 200L,
acc.toAddress.toString -> simpleReissuableAsset.quantity
)
Expand All @@ -269,7 +269,7 @@ class IssueReissueBurnAssetSuite extends BaseFreeSpec {
val addressStr = acc.toAddress.toString
val assetA = issueValidated(acc, simpleReissuableAsset)

sender.debugStateChangesByAddress(addressStr, 100).flatMap(_.stateChanges) should matchPattern {
sender.transactionsByAddress(addressStr, 100).flatMap(_.stateChanges) should matchPattern {
case Seq(StateChangesDetails(Nil, Nil, Seq(issue), Nil, Nil, Nil, None, Nil)) if issue.name == simpleReissuableAsset.name =>
}

Expand All @@ -291,7 +291,7 @@ class IssueReissueBurnAssetSuite extends BaseFreeSpec {

nodes.rollback(height, returnToUTX = false)

sender.debugStateChangesByAddress(addressStr, 100).flatMap(_.stateChanges) should matchPattern {
sender.transactionsByAddress(addressStr, 100).flatMap(_.stateChanges) should matchPattern {
case Seq(StateChangesDetails(Nil, Nil, Seq(issue), Nil, Nil, Nil, None, Nil)) if issue.name == simpleReissuableAsset.name =>
}
assertApiError(sender.stateChanges(txId), TransactionDoesNotExist)
Expand Down Expand Up @@ -381,7 +381,7 @@ class IssueReissueBurnAssetSuite extends BaseFreeSpec {
f(stateChanges(tx))
f(stateChangesStrings(tx))

val result = sender.debugStateChangesByAddress(tx.sender.get, 100)
val result = sender.transactionsByAddress(tx.sender.get, 100)
val stateChange = result.find(_.id == tx.id)
stateChange shouldBe defined
f(stateChange.get.stateChanges.get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SponsorFeeActionSuite extends BaseFreeSpec {

val stateChanges = miner.stateChanges(invokeTx._1.id).stateChanges.toSeq
stateChanges should matchDebugResult
miner.debugStateChangesByAddress(globalDAppAddress, limit = 100).flatMap(_.stateChanges) should matchDebugResult
miner.transactionsByAddress(globalDAppAddress, limit = 100).flatMap(_.stateChanges) should matchDebugResult

sponsoredAssetId = stateChanges.head.sponsorFees.head.assetId
miner.assetsDetails(sponsoredAssetId).minSponsoredAssetFee shouldBe Some(minSponsoredAssetFee)
Expand Down Expand Up @@ -167,7 +167,7 @@ class SponsorFeeActionSuite extends BaseFreeSpec {
.head

miner
.debugStateChangesByAddress(dAppAddress, limit = 100)
.transactionsByAddress(dAppAddress, limit = 100)
.flatMap(_.stateChanges)
.find(_.sponsorFees == Seq(SponsorFeeResponse(`cancelledAssetId`, None)))
.head
Expand Down Expand Up @@ -228,7 +228,7 @@ class SponsorFeeActionSuite extends BaseFreeSpec {
) if sponsorFeeResponses.size == 9 && sponsorFeeResponses.last == SponsorFeeResponse(`assetId`, Some(`lastMinSponsoredAssetFee`)) =>
}
txStateChanges should matchDebugResult
miner.debugStateChangesByAddress(dAppAddress, limit = 100).flatMap(_.stateChanges) should matchDebugResult
miner.transactionsByAddress(dAppAddress, limit = 100).flatMap(_.stateChanges) should matchDebugResult

miner.assetsDetails(assetId).minSponsoredAssetFee shouldBe Some(lastMinSponsoredAssetFee)

Expand Down Expand Up @@ -276,7 +276,7 @@ class SponsorFeeActionSuite extends BaseFreeSpec {
) =>
}
txStateChanges should matchDebugResult
miner.debugStateChangesByAddress(dAppAddress, limit = 100).flatMap(_.stateChanges) should matchDebugResult
miner.transactionsByAddress(dAppAddress, limit = 100).flatMap(_.stateChanges) should matchDebugResult

miner.assetsDetails(assetId).minSponsoredAssetFee shouldBe None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class MicroblocksFeeTestSuite extends BaseFreeSpec {
def requests(n: Int): Future[Unit] =
Future
.sequence {
//Not mining node sends transfer transactions to another not mining node
//Mining nodes collect fee
// Not mining node sends transfer transactions to another not mining node
// Mining nodes collect fee
(1 to n).map { _ =>
notMiner.transfer(notMiner.address, firstAddress, (1 + Random.nextInt(10)).waves, fee)
notMiner.transfer(notMiner.keyPair, firstAddress, (1 + Random.nextInt(10)).waves, fee)
}
}
.map(_ => ())
Expand All @@ -46,7 +46,7 @@ class MicroblocksFeeTestSuite extends BaseFreeSpec {
_ <- txRequestsGen(200, 2.waves)
_ <- traverse(nodes)(_.waitForHeight(microblockActivationHeight + 3))

initialBalances <- notMiner.debugStateAt(microblockActivationHeight - 1) //100%
initialBalances <- notMiner.debugStateAt(microblockActivationHeight - 1) // 100%

balancesBeforeActivation <- notMiner.debugStateAt(microblockActivationHeight) // 100%
blockBeforeActivation <- notMiner.blockHeadersAt(microblockActivationHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package com.wavesplatform.it.sync

import com.wavesplatform.account.KeyPair
import com.wavesplatform.it.Node
import com.wavesplatform.it.api.SyncHttpApi._
import com.wavesplatform.it.api.SyncHttpApi.*
import com.wavesplatform.it.transactions.BaseTransactionSuite
import com.wavesplatform.state.AssetDistributionPage
import com.wavesplatform.transaction.transfer.MassTransferTransaction
import org.scalatest.CancelAfterFailure

import scala.concurrent.duration._

class AssetDistributionSuite extends BaseTransactionSuite with CancelAfterFailure {

lazy val node: Node = nodes.head
Expand Down Expand Up @@ -47,8 +45,6 @@ class AssetDistributionSuite extends BaseTransactionSuite with CancelAfterFailur
.assetDistributionAtHeight(issueTx, distributionHeight, 100)
.items

assetDis should be equals node.assetDistribution(issueTx)

val issuerAssetDis = assetDis.view.filterKeys(_ == issuer.toAddress).values

issuerAssetDis.size shouldBe 1
Expand All @@ -72,30 +68,6 @@ class AssetDistributionSuite extends BaseTransactionSuite with CancelAfterFailur
)
}

test("'Asset distribution' works properly") {
val receivers = for (i <- 0 until 10) yield KeyPair(s"receiver#$i".getBytes("UTF-8"))

val issueTx = node.issue(issuer, "TestCoin#2", "no description", issueAmount, 8, false, issueFee, waitForTx = true).id

node
.massTransfer(
issuer,
receivers.map(rc => MassTransferTransaction.Transfer(rc.toAddress.toString, 10)).toList,
minFee + minFee * receivers.length,
assetId = Some(issueTx),
waitForTx = true
)

nodes.waitForHeightArise()

val distribution = node.assetDistribution(issueTx)

distribution.size shouldBe (receivers.size + 1)
distribution(issuer.toAddress) shouldBe (issueAmount - 10 * receivers.length)

assert(receivers.forall(rc => distribution(rc.toAddress) == 10), "Distribution correct")
}

test("Correct last page and entry count") {
val receivers = for (i <- 0 until 50) yield KeyPair(s"receiver#$i".getBytes("UTF-8"))

Expand Down Expand Up @@ -124,22 +96,6 @@ class AssetDistributionSuite extends BaseTransactionSuite with CancelAfterFailur
assert(pages.map(_.items.size).sum == 51)
}

test("Unlimited list") {
val receivers = for (i <- 0 until 2000) yield KeyPair(s"receiver#$i".getBytes("UTF-8"))

val assetId = node.issue(issuer, "TestCoin#2", "no description", issueAmount, 8, false, issueFee, waitForTx = true).id

receivers.foreach { receiver =>
node.transfer(issuer, receiver.toAddress.toString, 10, assetId = Some(assetId))
}

node.waitFor("empty utx")(_.utxSize, (_: Int) == 0, 1 second)
nodes.waitForHeightArise()

val list = node.assetDistribution(assetId)
list should have size 2001
}

def distributionPages(asset: String, height: Int, limit: Int): List[AssetDistributionPage] = {
def _load(acc: List[AssetDistributionPage], maybeAfter: Option[String]): List[AssetDistributionPage] = {
val page = node.assetDistributionAtHeight(asset, height, limit, maybeAfter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package com.wavesplatform.it.sync
import com.typesafe.config.Config
import com.wavesplatform.account.KeyPair
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils._
import com.wavesplatform.it._
import com.wavesplatform.it.api.AsyncHttpApi._
import com.wavesplatform.it.api._
import com.wavesplatform.test._
import com.wavesplatform.common.utils.*
import com.wavesplatform.it.*
import com.wavesplatform.it.api.AsyncHttpApi.*
import com.wavesplatform.it.api.*
import com.wavesplatform.test.*
import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves}
import com.wavesplatform.transaction.TxVersion
import com.wavesplatform.transaction.assets.IssueTransaction
import com.wavesplatform.transaction.transfer.TransferTransaction
import play.api.libs.json._
import play.api.libs.json.*

import scala.concurrent.Future.traverse
import scala.concurrent.duration._
import scala.concurrent.duration.*
import scala.concurrent.{Await, Future}
import scala.util.Random

class NFTBalanceSuite extends BaseFreeSpec {
import NFTBalanceSuite._
import NFTBalanceSuite.*

override protected def nodeConfigs: Seq[Config] =
NodeConfigs.newBuilder
Expand All @@ -43,7 +43,7 @@ class NFTBalanceSuite extends BaseFreeSpec {
val fundAndIssue =
for {
_ <- traverse(nodes)(_.waitForHeight(2))
fundTx <- node.transfer(node.address, issuer.toAddress.toString, 1000.waves, 0.001.waves)
fundTx <- node.transfer(node.keyPair, issuer.toAddress.toString, 1000.waves, 0.001.waves)
_ <- node.waitForTransaction(fundTx.id)
_ <- Future.sequence((simple ++ nft) map { tx =>
for {
Expand Down Expand Up @@ -125,11 +125,10 @@ class NFTBalanceSuite extends BaseFreeSpec {
"returns error on wrong limit" in {
val assertion = getNFTPage(node, issuer.toAddress.toString, 10000000, None)
.map(_ => org.scalatest.Assertions.fail("BadRequest expected"))
.recoverWith {
case ex: Throwable =>
Future.successful {
assert(ex.getMessage contains "Too big sequence requested")
}
.recoverWith { case ex: Throwable =>
Future.successful {
assert(ex.getMessage contains "Too big sequence requested")
}
}

Await.result(assertion, 10.seconds)
Expand All @@ -138,11 +137,10 @@ class NFTBalanceSuite extends BaseFreeSpec {
"returns error on wrong base58 in after" in {
val assertion = getNFTPage(node, issuer.toAddress.toString, 100, Some("wr0ngbase58str1ng"))
.map(_ => org.scalatest.Assertions.fail("BadRequest expected"))
.recoverWith {
case ex: Throwable =>
Future.successful {
assert(ex.getMessage contains "Invalid asset id")
}
.recoverWith { case ex: Throwable =>
Future.successful {
assert(ex.getMessage contains "Invalid asset id")
}
}

Await.result(assertion, 10.seconds)
Expand Down Expand Up @@ -194,12 +192,12 @@ object NFTBalanceSuite {
}

def fundAddresses(faucet: Node, addrs: String*): Unit = {
import com.wavesplatform.it.api.AsyncHttpApi._
import com.wavesplatform.it.api.AsyncHttpApi.*

val transactions =
Future.sequence(addrs map { addr =>
NodeAsyncHttpApi(faucet)
.transfer(faucet.address, addr, 1000.waves, 0.001.waves)
.transfer(faucet.keyPair, addr, 1000.waves, 0.001.waves)
.flatMap { tx =>
NodeAsyncHttpApi(faucet)
.waitForTransaction(tx.id, retryInterval = 1.second)
Expand Down Expand Up @@ -237,7 +235,7 @@ object NFTBalanceSuite {
loop(None, Nil)
}

//returns asset ids from addresses portfolio
// returns asset ids from addresses portfolio
def getPortfolio(node: Node, address: String): Future[List[String]] = {
node
.get(s"/assets/balance/$address")
Expand Down
Loading

0 comments on commit 68d5e91

Please sign in to comment.