Skip to content

Commit

Permalink
- New genesis template: first node has multiple miners;
Browse files Browse the repository at this point in the history
- Force CL miner for Waves node;
- Accounts file;
- Python code fixes.
  • Loading branch information
vsuharnikov committed Nov 2, 2024
1 parent e8e9541 commit c1868a2
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import play.api.libs.json.*
import sttp.client3.*
import sttp.client3.playJson.*
import sttp.model.{StatusCode, Uri}
import units.test.HasRetry

import scala.concurrent.duration.DurationInt
import scala.util.chaining.scalaUtilChainingOps
Expand Down
28 changes: 28 additions & 0 deletions consensus-client-it/src/test/scala/units/Accounts.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package units

import com.google.common.primitives.{Bytes, Ints}
import com.wavesplatform.account.{KeyPair, SeedKeyPair}
import com.wavesplatform.crypto
import org.web3j.crypto.Credentials
import units.eth.EthAddress

import java.nio.charset.StandardCharsets

trait Accounts {
val chainContractAccount: KeyPair = mkKeyPair("devnet cc 1", 0)

val miner1Account = mkKeyPair("devnet-1", 0)
val miner1RewardAddress = EthAddress.unsafeFrom("0x7dbcf9c6c3583b76669100f9be3caf6d722bc9f9")

val miner2Account = mkKeyPair("devnet-2", 0)
val miner2RewardAddress = EthAddress.unsafeFrom("0xcf0b9e13fdd593f4ca26d36afcaa44dd3fdccbed")

val clRichAccount1 = mkKeyPair("devnet rich", 0)
val clRichAccount2 = mkKeyPair("devnet rich", 1)

val elRichAccount1 = Credentials.create("8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63")
val elRichAccount2 = Credentials.create("ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f")

protected def mkKeyPair(seed: String, nonce: Int): SeedKeyPair =
SeedKeyPair(crypto.secureHash(Bytes.concat(Ints.toByteArray(nonce), seed.getBytes(StandardCharsets.UTF_8))))
}
35 changes: 7 additions & 28 deletions consensus-client-it/src/test/scala/units/BaseItTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package units

import com.google.common.primitives.{Bytes, Ints}
import com.typesafe.config.ConfigFactory
import com.wavesplatform.account.{AddressScheme, KeyPair, SeedKeyPair}
import com.wavesplatform.api.HasRetry
import com.wavesplatform.GenesisBlockGenerator
import com.wavesplatform.account.AddressScheme
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.utils.ScorexLogging
import com.wavesplatform.{GenesisBlockGenerator, crypto}
import monix.execution.atomic.AtomicBoolean
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.{BeforeAndAfterAll, EitherValues, OptionValues}
import org.web3j.crypto.Credentials
import units.BaseItTestSuite.generateWavesGenesisConfig
import units.client.contract.HasConsensusLayerDappTxHelpers
import units.docker.BaseContainer.{ConfigsDir, DefaultLogsDir}
import units.docker.Networks
import units.eth.{EthAddress, Gwei}
import units.test.CustomMatchers
import units.eth.Gwei
import units.test.{CustomMatchers, HasRetry}

import java.io.PrintStream
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Path}
import scala.concurrent.duration.DurationInt

Expand All @@ -34,31 +30,17 @@ trait BaseItTestSuite
with OptionValues
with ReportingTestName
with HasRetry
with Accounts
with HasConsensusLayerDappTxHelpers {
override val currentHitSource: ByteStr = ByteStr.empty
override val chainContractAccount: KeyPair = mkKeyPair("devnet-1", 2)
protected val rewardAmount: Gwei = Gwei.ofRawGwei(2_000_000_000L)
override val currentHitSource: ByteStr = ByteStr.empty
protected val rewardAmount: Gwei = Gwei.ofRawGwei(2_000_000_000L)

protected lazy val network = Networks.network

protected val miner1Account = mkKeyPair("devnet-1", 0)
protected val miner1RewardAddress = EthAddress.unsafeFrom("0x7dbcf9c6c3583b76669100f9be3caf6d722bc9f9")

protected val miner2Account = mkKeyPair("devnet-2", 0)
protected val miner2RewardAddress = EthAddress.unsafeFrom("0xcf0b9e13fdd593f4ca26d36afcaa44dd3fdccbed")

protected val clRichAccount1 = mkKeyPair("devnet-0", 0)
protected val clRichAccount2 = mkKeyPair("devnet-0", 1)

protected val elRichAccount1 = Credentials.create("8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63")
protected val elRichAccount2 = Credentials.create("ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f")

protected lazy val wavesGenesisConfigPath = generateWavesGenesisConfig()

protected def startNodes(): Unit

protected def stopNodes(): Unit

protected def setupNetwork(): Unit

override def beforeAll(): Unit = {
Expand All @@ -75,9 +57,6 @@ trait BaseItTestSuite
network.close()
super.afterAll()
}

protected def mkKeyPair(seed: String, nonce: Int): SeedKeyPair =
SeedKeyPair(crypto.secureHash(Bytes.concat(Ints.toByteArray(nonce), seed.getBytes(StandardCharsets.UTF_8))))
}

object BaseItTestSuite {
Expand Down
57 changes: 29 additions & 28 deletions consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.web3j.protocol.exceptions.TransactionException
import org.web3j.utils.Convert
import units.el.ElBridgeClient

class BridgeE2CTestSuite extends TwoNodesTestSuite {
class BridgeE2CTestSuite extends OneNodeTestSuite {
protected val elSender = elRichAccount1
protected val clRecipient = clRichAccount1
protected val userAmount = 1
Expand All @@ -19,38 +19,39 @@ class BridgeE2CTestSuite extends TwoNodesTestSuite {
protected def sendNative(amount: BigInt = UnitsConvert.toWei(userAmount)): TransactionReceipt =
ec1.elBridge.sendNative(elSender, clRecipient.toAddress, amount)

private val tenGwei = BigInt(Convert.toWei("10", Convert.Unit.GWEI).toBigIntegerExact)
protected val tenGwei = BigInt(Convert.toWei("10", Convert.Unit.GWEI).toBigIntegerExact)

"L2-264 Amount should % 10 Gwei" in {
try sendNative(tenGwei + 1)
catch {
case e: TransactionException =>
val encodedRevertReason = e.getTransactionReceipt.get().getRevertReason
val revertReason = ElBridgeClient.decodeRevertReason(encodedRevertReason)
revertReason shouldBe "Sent value 10000000001 must be a multiple of 10000000000"
"Negative" - {
def sendNativeInvalid(amount: BigInt): TransactionException =
try {
sendNative(amount)
fail(s"Expected sendNative($amount) to fail")
} catch {
case e: TransactionException => e
}

"L2-264 Amount should % 10 Gwei" in {
val e = sendNativeInvalid(tenGwei + 1)
val encodedRevertReason = e.getTransactionReceipt.get().getRevertReason
val revertReason = ElBridgeClient.decodeRevertReason(encodedRevertReason)
revertReason shouldBe "Sent value 10000000001 must be a multiple of 10000000000"
}
}

"L2-265 Amount should be between 10 and MAX_AMOUNT_IN_WEI Gwei" in {
withClue("1. Less than 10 Gwei: ") {
try sendNative(1)
catch {
case e: TransactionException =>
val encodedRevertReason = e.getTransactionReceipt.get().getRevertReason
val revertReason = ElBridgeClient.decodeRevertReason(encodedRevertReason)
revertReason shouldBe "Sent value 1 must be greater or equal to 10000000000"
"L2-265 Amount should be between 10 and MAX_AMOUNT_IN_WEI Gwei" in {
withClue("1. Less than 10 Gwei: ") {
val e = sendNativeInvalid(1)
val encodedRevertReason = e.getTransactionReceipt.get().getRevertReason
val revertReason = ElBridgeClient.decodeRevertReason(encodedRevertReason)
revertReason shouldBe "Sent value 1 must be greater or equal to 10000000000"
}
}

withClue("2. More than MAX_AMOUNT_IN_WEI: ") {
val maxAmountInWei = BigInt(Long.MaxValue)
val biggerAmount = (maxAmountInWei / tenGwei + 1) * tenGwei
try sendNative(biggerAmount)
catch {
case e: TransactionException =>
val encodedRevertReason = e.getTransactionReceipt.get().getRevertReason
val revertReason = ElBridgeClient.decodeRevertReason(encodedRevertReason)
revertReason shouldBe s"Sent value $biggerAmount must be less or equal to $maxAmountInWei"
withClue("2. More than MAX_AMOUNT_IN_WEI: ") {
val maxAmountInWei = BigInt(Long.MaxValue)
val biggerAmount = (maxAmountInWei / tenGwei + 1) * tenGwei
val e = sendNativeInvalid(biggerAmount)
val encodedRevertReason = e.getTransactionReceipt.get().getRevertReason
val revertReason = ElBridgeClient.decodeRevertReason(encodedRevertReason)
revertReason shouldBe s"Sent value $biggerAmount must be less or equal to $maxAmountInWei"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ trait OneNodeTestSuite extends BaseItTestSuite {
number = 1,
ip = Networks.ipForNode(3),
baseSeed = "devnet-1",
clMinerKeyPair = mkKeyPair("devnet-1", 0),
chainContractAddress = chainContractAddress,
ecEngineApiUrl = s"http://${ec1.hostName}:${EcContainer.EnginePort}",
genesisConfigPath = wavesGenesisConfigPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ trait TwoNodesTestSuite extends BaseItTestSuite {
number = 1,
ip = Networks.ipForNode(4),
baseSeed = "devnet-1",
clMinerKeyPair = mkKeyPair("devnet-1", 0),
chainContractAddress = chainContractAddress,
ecEngineApiUrl = s"http://${ec1.hostName}:${EcContainer.EnginePort}",
genesisConfigPath = wavesGenesisConfigPath
Expand All @@ -32,6 +33,7 @@ trait TwoNodesTestSuite extends BaseItTestSuite {
number = 2,
ip = Networks.ipForNode(5),
baseSeed = "devnet-2",
clMinerKeyPair = mkKeyPair("devnet-2", 0),
chainContractAddress = chainContractAddress,
ecEngineApiUrl = s"http://${ec2.hostName}:${EcContainer.EnginePort}",
genesisConfigPath = wavesGenesisConfigPath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package units.docker

import com.google.common.io.Files as GFiles
import com.wavesplatform.account.Address
import com.google.common.primitives.{Bytes, Ints}
import com.wavesplatform.account.{Address, KeyPair, SeedKeyPair}
import com.wavesplatform.api.{LoggingBackend, NodeHttpApi}
import com.wavesplatform.common.utils.Base58
import com.wavesplatform.crypto
import org.testcontainers.containers.BindMode
import org.testcontainers.containers.Network.NetworkImpl
import org.testcontainers.utility.DockerImageName
Expand All @@ -22,6 +24,7 @@ class WavesNodeContainer(
number: Int,
ip: String,
baseSeed: String,
clMinerKeyPair: KeyPair, // Force CL miner
chainContractAddress: Address,
ecEngineApiUrl: String,
genesisConfigPath: Path
Expand All @@ -37,6 +40,7 @@ class WavesNodeContainer(
"NODE_NUMBER" -> s"$number",
"WAVES_WALLET_SEED" -> Base58.encode(baseSeed.getBytes(StandardCharsets.UTF_8)),
"JAVA_OPTS" -> List(
s"-Dwaves.miner.private-keys.0=${Base58.encode(clMinerKeyPair.privateKey.arr)}",
s"-Dunits.defaults.chain-contract=$chainContractAddress",
s"-Dunits.defaults.execution-client-address=$ecEngineApiUrl",
"-Dlogback.file.level=TRACE",
Expand Down Expand Up @@ -78,4 +82,6 @@ class WavesNodeContainer(
object WavesNodeContainer {
val ApiPort = 6869

def mkKeyPair(seed: String, nonce: Int): SeedKeyPair =
SeedKeyPair(crypto.secureHash(Bytes.concat(Ints.toByteArray(nonce), seed.getBytes(StandardCharsets.UTF_8))))
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package units.el

import com.wavesplatform.account.Address
import com.wavesplatform.api.HasRetry
import com.wavesplatform.utils.ScorexLogging
import org.web3j.abi.datatypes.{AbiTypes, Type}
import org.web3j.abi.{FunctionReturnDecoder, TypeReference}
Expand All @@ -11,6 +10,7 @@ import org.web3j.protocol.core.methods.response.TransactionReceipt
import org.web3j.tx.gas.DefaultGasProvider
import units.bridge.BridgeContract
import units.eth.EthAddress
import units.test.HasRetry

import java.util.Collections

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wavesplatform.api
package units.test

import org.scalatest.concurrent.Eventually.PatienceConfig

Expand Down
2 changes: 1 addition & 1 deletion local-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ See [./deploy](./deploy/).
* Node wallet seed:
* wavesnode-1: `devnet-1`
* wavesnode-2: `devnet-2`
* Chain contract: `3FdaanzgX4roVgHevhq8L8q42E7EZL9XTQr`
* Chain contract: `3FZyX72BjuE6s5PMTVQN9mJTN4jEJto95nv`
* EL mining reward accounts:
* Reward account for **Miner 1** (`wavesnode-1`, `besu-1`):
* Address: `0x7dBcf9c6C3583b76669100f9BE3CaF6d722bc9f9`
Expand Down
71 changes: 42 additions & 29 deletions local-network/configs/wavesnode/genesis-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,71 @@ genesis-generator {
# seed text -> share
# the sum of shares should be <= initial-balance
distributions = [
# CL miner on wavesnode-1
# Miner on wavesnode-1
# Seed text: devnet-1
# Nonce: 0
# Seed: HnyGuCEnV1A
# Private key: DwPvPGEp3LPg5gVRz7Pqd8mHa6dWK9dXtP4XDmKTz6ga
# Public key: Atej9hrXKQS6cLjuhjEnKyF5boyYGSp5VBZvfcmF9FqY
# Address: 3FNraPMYcfuGREcxorNSEBHgNLjmYtaHy9e
# Usage: local-network, consensus-client-it
{ seed-text = "devnet-1", nonce = 0, amount = 998036000000000 }

# Chain contract on wavesnode-1
# Miner on wavesnode-1
# Seed text: devnet-1
# Nonce: 2
# Nonce: 1
# Seed: HnyGuCEnV1A
# Private key: 7TzN4c2XgvSN28gEbvW5wmUecfa4SrPRLXjgr5DRfQMG
# Public key: 5yxSxDhB2ZL5agYnU6WRtEqPg3T3FfUY3zouKrMpnTX6
# Address: 3FdaanzgX4roVgHevhq8L8q42E7EZL9XTQr
{ seed-text = "devnet-1", nonce = 2, amount = 20000000000 }

# DAO Address
# Seed text: devnet dao 1
# Nonce: 0
# Seed: 2ttKSSq2o7VU6kFwN
# Private key: EXC4wafzVus3tmesKEouuewZHGNzEG5qxNHMN66XAiG4
# Public key: 7S2iCGvRcx3bJA3y8R9k6sJdVATg3ss8r4RuW1S8VriA
# Address: 3FYp54DX9Np9uouxBtnnCFPYWzz7K3kvSD2
{ seed-text = "devnet dao 1", nonce = 0, amount = 100000000 }
# Private key: 5r7KpS3MNXxRcz9jMbpjZKhaZVxDxF74H4VLW6ydi4aT
# Public key: 2JYMTjUK7tC8NQi6TD6oWgy41YbrnXuoLzZydrFKTKt6
# Address: 3FSgXpgbT6m1speWgVx3cVxAZKmdr4barHU
# Usage: consensus-client-it
{ seed-text = "devnet-1", nonce = 1, amount = 998036000000000 }

# CL miner on wavesnode-2
# Miner on wavesnode-2
# Seed text: devnet-2
# Nonce: 0
# Seed: HnyGuCEnV1B
# Private key: F17jrRWmrR7en6eY6ptvnUTNqc9W8RSP34hpX7bNhbht
# Public key: FuibB1rJ1uHVvvY6FNmhLqnbvQBNtziWbh7zh5c1CQCG
# Address: 3FSrRN8X7cDsLyYTScS8Yf8KSwZgJBwf1jU
# Usage: local-network, consensus-client-it
{ seed-text = "devnet-2", nonce = 0, amount = 998036000000000 }

# Additional addresses

# Seed text: devnet-0
# Seed text: devnet rich
# Nonce: 0
# Seed: HnyGuCEnV19
# Private key: 8aYKVCJVYfcSQeSH1kM4D2e4Fcj5cAQzMh8uZ5hW2tB9
# Public key: GRKksNikCNXYT7HqxCnqzjP5pf4NctgtTnmCvCMDEhAT
# Address: 3Ffcu52v7ETMAFhNAqQvHsv4JuQjEVP9q6E
{ seed-text = "devnet-0", nonce = 0, amount = 2305842994213693951 }
# Seed: RtxP5VZ8GyepM8T
# Private key: 5Kn5nRo6piCWg4cwoHWj41L8YnASfYSRt9RkwXxfCjQx
# Public key: HWVpTRztoFNwbCsJ1PxtneNSVywkwD8PzMwagDM1YoE6
# Address: 3FiaGiTaJ57qLpw5zmdxSejnUYCK2R9E2DV
{ seed-text = "devnet rich", nonce = 0, amount = 2305842994213693951 }

# Seed text: devnet-0
# Seed text: devnet rich
# Nonce: 1
# Seed: HnyGuCEnV19
# Private key: 5tE8jwZ3B4eLTvdz7LqEBMcmspoqXD9nPCEfcZgh2BeV
# Public key: BArfnBGQ9gkNHC2EftXf42uJuBioSffZiJoyYCTtwxof
# Address: 3FQFFWxMCDmyZhkRzKA7QiAZL4RKMhJvFnu
{ seed-text = "devnet-0", nonce = 1, amount = 2305842994213693952 }
# Seed: RtxP5VZ8GyepM8T
# Private key: HkHtYtTVyUy2hcjNLowuEBTrjvCcuq4vGSaWac6Q5gLi
# Public key: AhbKXvrNikp2iynszNxAAzoE7hgzaaZpV9jyVpi5D1jS
# Address: 3FfXrt2RZCBQm7AKjeRhQjR9vGwu8Cb3RjN
{ seed-text = "devnet rich", nonce = 1, amount = 2305842994213693952 }

# DAO Address
# Seed text: devnet dao 1
# Nonce: 0
# Seed: 2ttKSSq2o7VU6kFwN
# Private key: EXC4wafzVus3tmesKEouuewZHGNzEG5qxNHMN66XAiG4
# Public key: 7S2iCGvRcx3bJA3y8R9k6sJdVATg3ss8r4RuW1S8VriA
# Address: 3FYp54DX9Np9uouxBtnnCFPYWzz7K3kvSD2
{ seed-text = "devnet dao 1", nonce = 0, amount = 100000000 }

# Chain contract on wavesnode-1
# Seed text: devnet cc 1
# Nonce: 0
# Seed: RtxP5VZ8GyGYRu2
# Private key: GckEsHqD68uYq6J92gQCBpaAR3U7qGnAoJ7rQVcFHqzN
# Public key: HeUYUuLfr8Vzig5FasjdKHJC4hq8T2izN2ktizcKnBDZ
# Address: 3FZyX72BjuE6s5PMTVQN9mJTN4jEJto95nv
# Address: 3FdaanzgX4roVgHevhq8L8q42E7EZL9XTQr
{ seed-text = "devnet cc 1", nonce = 0, amount = 20000000000 }
]
}
2 changes: 1 addition & 1 deletion local-network/configs/wavesnode/units.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
units {
defaults {
chain-contract = "3FdaanzgX4roVgHevhq8L8q42E7EZL9XTQr"
chain-contract = "3FZyX72BjuE6s5PMTVQN9mJTN4jEJto95nv"
execution-client-address = "http://ec-"${NODE_NUMBER}":8551"
network {
port = 6865
Expand Down
2 changes: 1 addition & 1 deletion local-network/deploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

r = network.cl_chain_contract.setup(
el_genesis_block_hash,
daoAddress = '3FYp54DX9Np9uouxBtnnCFPYWzz7K3kvSD2'
daoAddress = network.cl_dao.address
)
waves.force_success(log, r, "Can not setup the chain contract")

Expand Down
Loading

0 comments on commit c1868a2

Please sign in to comment.