Skip to content

Commit 9ffa6bd

Browse files
authored
Merge branch 'version-1.4.x' into node-2348-api-liquid-balances
2 parents 557636f + 9ead4d4 commit 9ffa6bd

File tree

38 files changed

+1744
-1011
lines changed

38 files changed

+1744
-1011
lines changed

Jenkinsfile

Lines changed: 0 additions & 119 deletions
This file was deleted.

build.sbt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ lazy val `lang-tests` = project
5353
.in(file("lang/tests"))
5454
.dependsOn(`lang-testkit`)
5555

56+
lazy val `lang-tests-js` = project
57+
.in(file("lang/tests-js"))
58+
.enablePlugins(ScalaJSPlugin)
59+
.dependsOn(`lang-js`)
60+
.settings(
61+
libraryDependencies += Dependencies.scalaJsTest.value,
62+
testFrameworks += new TestFramework("utest.runner.Framework")
63+
)
64+
5665
lazy val node = project.dependsOn(`lang-jvm`, `lang-testkit` % "test")
5766

5867
lazy val `grpc-server` = project.dependsOn(node % "compile;test->test;runtime->provided")
@@ -100,6 +109,7 @@ lazy val `waves-node` = (project in file("."))
100109
`lang-js`,
101110
`lang-jvm`,
102111
`lang-tests`,
112+
`lang-tests-js`,
103113
`lang-testkit`,
104114
`repl-js`,
105115
`repl-jvm`,
@@ -188,6 +198,7 @@ checkPRRaw := Def
188198
(`lang-tests` / Test / test).value
189199
(`repl-jvm` / Test / test).value
190200
(`lang-js` / Compile / fastOptJS).value
201+
(`lang-tests-js` / Test / test).value
191202
(`grpc-server` / Test / test).value
192203
(node / Test / test).value
193204
(`repl-js` / Compile / fastOptJS).value

grpc-server/src/main/scala/com/wavesplatform/events/Repo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Repo(db: DB, blocksApi: CommonBlocksApi)(implicit s: Scheduler) extends Bl
7373
db.put(keyForHeight(ls.keyBlock.height), ls.solidify().protobuf.update(_.append.block.optionalBlock := None).toByteArray)
7474
)
7575

76-
val ba = BlockAppended.from(block, diff, blockchainBeforeWithMinerReward)
76+
val ba = BlockAppended.from(block, diff, blockchainBeforeWithMinerReward, minerReward)
7777
liquidState = Some(LiquidState(ba, Seq.empty))
7878
handlers.forEach(_.handleUpdate(ba))
7979
}

grpc-server/src/main/scala/com/wavesplatform/events/events.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import com.wavesplatform.transaction.assets.exchange.ExchangeTransaction
2424
import com.wavesplatform.transaction.lease.LeaseTransaction
2525
import com.wavesplatform.transaction.smart.InvokeScriptTransaction
2626
import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction}
27-
import com.wavesplatform.transaction.{Asset, Authorized, EthereumTransaction, GenesisTransaction}
27+
import com.wavesplatform.transaction.{Asset, Authorized, EthereumTransaction}
2828

2929
import scala.collection.mutable
3030
import scala.collection.mutable.ArrayBuffer
@@ -557,21 +557,18 @@ final case class BlockAppended(
557557
}
558558

559559
object BlockAppended {
560-
def from(block: Block, diff: DetailedDiff, blockchainBeforeWithMinerReward: Blockchain): BlockAppended = {
560+
def from(block: Block, diff: DetailedDiff, blockchainBeforeWithMinerReward: Blockchain, minerReward: Option[Long]): BlockAppended = {
561+
val height = blockchainBeforeWithMinerReward.height
561562
val (blockStateUpdate, txsStateUpdates, txsMetadata, refAssets) =
562563
StateUpdate.container(blockchainBeforeWithMinerReward, diff, block.sender.toAddress)
563564

564565
// updatedWavesAmount can change as a result of either genesis transactions or miner rewards
565-
val updatedWavesAmount = blockchainBeforeWithMinerReward.height match {
566-
// genesis case
567-
case 0 => block.transactionData.collect { case GenesisTransaction(_, amount, _, _, _) => amount.value }.sum
568-
// miner reward case
569-
case height => blockchainBeforeWithMinerReward.wavesAmount(height).toLong
570-
}
566+
val wavesAmount = blockchainBeforeWithMinerReward.wavesAmount(height).toLong
567+
val updatedWavesAmount = wavesAmount + minerReward.filter(_ => height > 0).getOrElse(0L)
571568

572569
BlockAppended(
573570
block.id(),
574-
blockchainBeforeWithMinerReward.height + 1,
571+
height + 1,
575572
block,
576573
updatedWavesAmount,
577574
blockStateUpdate,

grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.wavesplatform.events.protobuf.BlockchainUpdated.Rollback.RollbackType
1414
import com.wavesplatform.events.protobuf.BlockchainUpdated.Update
1515
import com.wavesplatform.events.protobuf.serde.*
1616
import com.wavesplatform.events.protobuf.{TransactionMetadata, BlockchainUpdated as PBBlockchainUpdated}
17+
import com.wavesplatform.features.BlockchainFeatures.BlockReward
1718
import com.wavesplatform.history.Domain
1819
import com.wavesplatform.lang.directives.values.V5
1920
import com.wavesplatform.lang.v1.FunctionHeader
@@ -278,9 +279,74 @@ class BlockchainUpdatesSpec extends FreeSpec with WithBUDomain with ScalaFutures
278279
)
279280
}
280281

281-
"should include correct waves amount" in withNEmptyBlocksSubscription(settings = currentSettings) { result =>
282-
val balances = result.collect { case b if b.update.isAppend => b.getAppend.getBlock.updatedWavesAmount }
283-
balances shouldBe Seq(10000000000000000L, 10000000600000000L, 10000001200000000L)
282+
"should include correct waves amount" - {
283+
val totalWaves = 100_000_000_0000_0000L
284+
val reward = 6_0000_0000
285+
286+
"on preactivated block reward" in {
287+
val settings = currentSettings.setFeaturesHeight((BlockReward, 0))
288+
289+
withDomainAndRepo(settings) { case (d, repo) =>
290+
d.appendBlock()
291+
d.blockchain.wavesAmount(1) shouldBe totalWaves + reward
292+
repo.getBlockUpdate(1).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward
293+
294+
d.appendBlock()
295+
d.blockchain.wavesAmount(2) shouldBe totalWaves + reward * 2
296+
repo.getBlockUpdate(2).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 2
297+
}
298+
}
299+
300+
"on activation of block reward" in {
301+
val settings = currentSettings.setFeaturesHeight((BlockReward, 3))
302+
303+
withNEmptyBlocksSubscription(settings = settings, count = 3) { result =>
304+
val balances = result.collect { case b if b.update.isAppend => b.getAppend.getBlock.updatedWavesAmount }
305+
balances shouldBe Seq(totalWaves, totalWaves, totalWaves + reward, totalWaves + reward * 2)
306+
}
307+
308+
withDomainAndRepo(settings) { case (d, repo) =>
309+
d.appendBlock()
310+
d.blockchain.wavesAmount(1) shouldBe totalWaves
311+
repo.getBlockUpdate(1).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves
312+
313+
d.appendBlock()
314+
d.blockchain.wavesAmount(2) shouldBe totalWaves
315+
repo.getBlockUpdate(2).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves
316+
317+
d.appendBlock()
318+
d.blockchain.wavesAmount(3) shouldBe totalWaves + reward
319+
repo.getBlockUpdate(3).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward
320+
321+
d.appendBlock()
322+
d.blockchain.wavesAmount(4) shouldBe totalWaves + reward * 2
323+
repo.getBlockUpdate(4).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 2
324+
}
325+
}
326+
327+
"on rollbacks" in {
328+
withDomainAndRepo(currentSettings) { case (d, repo) =>
329+
d.appendBlock()
330+
331+
// block and micro append
332+
val block = d.appendBlock()
333+
block.sender shouldBe defaultSigner.publicKey
334+
335+
d.appendMicroBlock(TxHelpers.transfer(defaultSigner))
336+
d.blockchain.wavesAmount(2) shouldBe totalWaves + reward * 2
337+
repo.getBlockUpdate(2).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 2
338+
339+
// micro rollback
340+
d.appendKeyBlock(Some(block.id()))
341+
d.blockchain.wavesAmount(3) shouldBe totalWaves + reward * 3
342+
repo.getBlockUpdate(3).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 3
343+
344+
// block rollback
345+
d.rollbackTo(2)
346+
d.blockchain.wavesAmount(2) shouldBe totalWaves + reward * 2
347+
repo.getBlockUpdate(2).getUpdate.vanillaAppend.updatedWavesAmount shouldBe totalWaves + reward * 2
348+
}
349+
}
284350
}
285351

286352
"should include correct heights" in withNEmptyBlocksSubscription(settings = currentSettings) { result =>

lang/js/src/main/scala/JsAPI.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,19 @@ object JsAPI {
159159
"ast" -> toJs(expr),
160160
"complexity" -> complexity.toDouble
161161
)
162-
case CompileResult.DApp(_, di, error) =>
162+
case CompileResult.DApp(_, di, meta, error) =>
163+
val mappedMeta =
164+
meta.argsWithFuncName.map { case (func, argsWithName) =>
165+
func -> argsWithName.map { case (arg, argType) => arg -> argType.name }.toJSArray
166+
}.toJSDictionary
167+
163168
val compactNameToOriginalName: Map[String, String] =
164169
di.dApp.meta.compactNameAndOriginalNamePairList.map(pair => pair.compactName -> pair.originalName).toMap
165170

166171
val resultFields: Seq[(String, Any)] = Seq(
167172
"result" -> Global.toBuffer(di.bytes),
168173
"ast" -> toJs(di.dApp),
174+
"meta" -> mappedMeta,
169175
"complexity" -> di.maxComplexity._2.toDouble,
170176
"verifierComplexity" -> di.verifierComplexity.toDouble,
171177
"callableComplexities" -> di.callableComplexities.view.mapValues(_.toDouble).toMap.toJSDictionary,
@@ -176,13 +182,12 @@ object JsAPI {
176182
compactNameToOriginalName.getOrElse(name, name) -> complexity.toDouble
177183
}.toJSDictionary
178184
)
179-
val errorFieldOpt: Seq[(String, Any)] = {
185+
val errorFieldOpt: Seq[(String, Any)] =
180186
error
181187
.fold(
182188
error => Seq("error" -> error),
183189
_ => Seq()
184190
)
185-
}
186191
js.Dynamic.literal.applyDynamic("apply")((resultFields ++ errorFieldOpt)*)
187192
}
188193
)

lang/js/src/main/scala/JsApiUtils.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ object JsApiUtils {
5555
}
5656

5757
jObj.applyDynamic("apply")(
58-
"type" -> "DAPP",
59-
"posStart" -> ast.position.start,
60-
"posEnd" -> ast.position.end,
61-
"decList" -> ast.decs.map(serDec).toJSArray,
62-
"annFuncList" -> ast.fs.map(serAnnFunc)
58+
"type" -> "DAPP",
59+
"posStart" -> ast.position.start,
60+
"posEnd" -> ast.position.end,
61+
"decList" -> ast.decs.map(serDec).toJSArray,
62+
"annFuncList" -> ast.fs.map(serAnnFunc).toJSArray
6363
)
6464
}
6565

lang/js/src/main/scala/com/wavesplatform/lang/Global.scala

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
package com.wavesplatform.lang
22

3-
import java.math.{BigInteger, BigDecimal => BD}
4-
5-
import cats.syntax.either._
3+
import cats.syntax.either.*
4+
import com.wavesplatform.common.utils.{Base58, Base64}
65
import com.wavesplatform.lang.v1.BaseGlobal
76
import com.wavesplatform.lang.v1.evaluator.ctx.impl.Rounding
87
import com.wavesplatform.lang.v1.evaluator.ctx.impl.crypto.RSA.DigestAlgorithm
98

9+
import java.math.{BigInteger, BigDecimal as BD}
1010
import scala.collection.mutable
11-
import scala.scalajs.js.JSConverters._
11+
import scala.scalajs.js.JSConverters.*
1212
import scala.scalajs.js.typedarray.{ArrayBuffer, Int8Array}
1313
import scala.util.Try
1414

1515
object Global extends BaseGlobal {
16-
def base58Encode(input: Array[Byte]): Either[String, String] = Right(impl.Global.base58Encode(toBuffer(input)))
16+
def base58Encode(input: Array[Byte]): Either[String, String] = Right(Base58.encode(input))
1717
override def base58Decode(input: String, limit: Int): Either[String, Array[Byte]] =
1818
for {
1919
_ <- Either.cond(input.length <= limit, {}, s"Input is too long (${input.length}), limit is $limit")
20-
x <- impl.Global
21-
.base58Decode(input)
22-
.toOption
23-
.map(toArray)
24-
.toRight("Cannot decode")
20+
x <- Try(Base58.decode(input)).toEither.leftMap(_.getMessage)
2521
} yield x
2622

27-
override def base64Encode(input: Array[Byte]): Either[String, String] = Right(impl.Global.base64Encode(toBuffer(input)))
23+
override def base64Encode(input: Array[Byte]): Either[String, String] = Right(Base64.encode(input))
2824
override def base64Decode(input: String, limit: Int): Either[String, Array[Byte]] =
2925
for {
3026
_ <- Either.cond(input.length <= limit, {}, s"Input is too long (${input.length}), limit is $limit")
31-
x <- impl.Global
32-
.base64Decode(input)
33-
.toOption
34-
.map(toArray)
35-
.toRight("Cannot decode")
27+
x <- Try(Base64.decode(input)).toEither.leftMap(_.getMessage)
3628
} yield x
3729

3830
private val hex: Array[Char] = Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f')

0 commit comments

Comments
 (0)