From 6d101753eaa3e687a258cdd0ab0412034724e61e Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Fri, 8 Nov 2024 10:44:43 +0400 Subject: [PATCH] Cleanup --- .../src/test/scala/units/Accounts.scala | 2 + .../units/AlternativeChainTestSuite.scala | 10 ++-- .../scala/units/BaseDockerTestSuite.scala | 21 +++++--- .../test/scala/units/BridgeC2ETestSuite.scala | 12 ++--- .../test/scala/units/BridgeE2CTestSuite.scala | 14 +++--- .../test/scala/units/RewardTestSuite.scala | 4 +- .../test/scala/units/SyncingTestSuite.scala | 4 +- .../test/scala/units/docker/EcContainer.scala | 50 +++++-------------- .../units/docker/WavesNodeContainer.scala | 22 ++------ .../test/scala/units/el/ElBridgeClient.scala | 2 +- src/main/scala/units/ClientConfig.scala | 8 ++- .../units/ConsensusClientDependencies.scala | 2 +- .../scala/units/client/JsonRpcClient.scala | 21 +++++--- .../client/engine/HttpEngineApiClient.scala | 8 +-- .../units/BaseIntegrationTestSuite.scala | 6 +-- .../units/BlockFullValidationTestSuite.scala | 8 +-- .../units/BlockIssuesForgingTestSuite.scala | 30 +++++------ .../scala/units/C2ETransfersTestSuite.scala | 2 +- .../scala/units/E2CTransfersTestSuite.scala | 46 ++++++++--------- .../HasConsensusLayerDappTxHelpers.scala | 8 +-- 20 files changed, 133 insertions(+), 147 deletions(-) diff --git a/consensus-client-it/src/test/scala/units/Accounts.scala b/consensus-client-it/src/test/scala/units/Accounts.scala index 71540d02..f359c1d5 100644 --- a/consensus-client-it/src/test/scala/units/Accounts.scala +++ b/consensus-client-it/src/test/scala/units/Accounts.scala @@ -23,6 +23,8 @@ trait Accounts { val clRichAccount1 = mkKeyPair("devnet rich", 0) val clRichAccount2 = mkKeyPair("devnet rich", 1) + val elBridgeAddress = EthAddress.unsafeFrom("0x0000000000000000000000000000000000006a7e") + val elRichAccount1 = Credentials.create("8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63") val elRichAccount2 = Credentials.create("ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f") diff --git a/consensus-client-it/src/test/scala/units/AlternativeChainTestSuite.scala b/consensus-client-it/src/test/scala/units/AlternativeChainTestSuite.scala index aa6228cc..62e52e40 100644 --- a/consensus-client-it/src/test/scala/units/AlternativeChainTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/AlternativeChainTestSuite.scala @@ -9,7 +9,7 @@ class AlternativeChainTestSuite extends BaseDockerTestSuite { "L2-383 Start an alternative chain after not getting an EL-block" in { step("EL miner #2 join") waves1.api.broadcastAndWait( - chainContract.join( + ChainContract.join( minerAccount = miner21Account, elRewardAddress = miner21RewardAddress ) @@ -19,10 +19,10 @@ class AlternativeChainTestSuite extends BaseDockerTestSuite { waitMinerEpoch(miner21Account) step("Issue miner #2 block confirmation") - val lastContractBlock = waves1.chainContract.getLastBlockMeta(0).getOrElse(fail("Can't get last block")) + val lastContractBlock = chainContract.getLastBlockMeta(0).getOrElse(fail("Can't get last block")) val lastWavesBlock = waves1.api.blockHeader(waves1.api.height).getOrElse(fail("Can't get current block header")) waves1.api.broadcastAndWait( - chainContract.extendMainChain( + ChainContract.extendMainChain( minerAccount = miner21Account, blockHash = BlockHash("0x0000000000000000000000000000000000000000000000000000000000000001"), parentBlockHash = lastContractBlock.hash, @@ -37,14 +37,14 @@ class AlternativeChainTestSuite extends BaseDockerTestSuite { step("Checking an alternative chain started") retry { - waves1.chainContract.getChainInfo(1L).getOrElse(fail("Can't get an alternative chain info")) + chainContract.getChainInfo(1L).getOrElse(fail("Can't get an alternative chain info")) } } private def waitMinerEpoch(minerAccount: KeyPair): Unit = { val expectedGenerator = minerAccount.toAddress retry { - val actualGenerator = waves1.chainContract.computedGenerator + val actualGenerator = chainContract.computedGenerator if (actualGenerator != expectedGenerator) fail(s"Expected $expectedGenerator generator, got $actualGenerator") }(patienceConfig.copy(timeout = WavesNodeContainer.AverageBlockDelay * 5)) } diff --git a/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala b/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala index a5cf0599..68f3bdbf 100644 --- a/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BaseDockerTestSuite.scala @@ -10,10 +10,13 @@ import monix.execution.atomic.AtomicBoolean import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers import org.scalatest.{BeforeAndAfterAll, EitherValues, OptionValues} +import sttp.client3.{HttpClientSyncBackend, Identity, SttpBackend} import units.BaseDockerTestSuite.generateWavesGenesisConfig +import units.client.HttpChainContractClient import units.client.contract.HasConsensusLayerDappTxHelpers import units.client.engine.model.BlockNumber import units.docker.{EcContainer, Networks, WavesNodeContainer} +import units.el.ElBridgeClient import units.eth.Gwei import units.test.TestEnvironment.* import units.test.{CustomMatchers, HasRetry} @@ -41,6 +44,8 @@ trait BaseDockerTestSuite protected lazy val wavesGenesisConfigPath = generateWavesGenesisConfig() + private implicit val httpClientBackend: SttpBackend[Identity, Any] = HttpClientSyncBackend() + protected lazy val ec1: EcContainer = new EcContainer( network = network, number = 1, @@ -52,12 +57,14 @@ trait BaseDockerTestSuite number = 1, ip = Networks.ipForNode(3), baseSeed = "devnet-1", - clMinerKeyPair = mkKeyPair("devnet-1", 0), chainContractAddress = chainContractAddress, - ecEngineApiUrl = s"http://${ec1.hostName}:${EcContainer.EnginePort}", + ecEngineApiUrl = ec1.engineApiDockerUrl, genesisConfigPath = wavesGenesisConfigPath ) + protected lazy val chainContract = new HttpChainContractClient(waves1.api, chainContractAddress) + protected lazy val elBridge = new ElBridgeClient(ec1.web3j, elBridgeAddress) + protected def startNodes(): Unit = { ec1.start() ec1.logPorts() @@ -74,12 +81,12 @@ trait BaseDockerTestSuite protected def setupNetwork(): Unit = { log.info("Set script") - waves1.api.broadcastAndWait(chainContract.setScript()) + waves1.api.broadcastAndWait(ChainContract.setScript()) log.info("Setup chain contract") val genesisBlock = ec1.engineApi.getBlockByNumber(BlockNumber.Number(0)).explicitGet().getOrElse(failRetry("No EL genesis block")) waves1.api.broadcastAndWait( - chainContract.setup( + ChainContract.setup( genesisBlock = genesisBlock, elMinerReward = rewardAmount.amount.longValue(), daoAddress = None, @@ -87,11 +94,11 @@ trait BaseDockerTestSuite invoker = chainContractAccount ) ) - log.info(s"Token id: ${waves1.chainContract.token}") + log.info(s"Token id: ${chainContract.token}") log.info("EL miner #1 join") val joinMiner1Result = waves1.api.broadcastAndWait( - chainContract.join( + ChainContract.join( minerAccount = miner11Account, elRewardAddress = miner11RewardAddress ) @@ -117,6 +124,8 @@ trait BaseDockerTestSuite } override protected def afterAll(): Unit = { + httpClientBackend.close() + stopNodes() network.close() super.afterAll() diff --git a/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala b/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala index 99976908..0566bb83 100644 --- a/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala @@ -13,8 +13,8 @@ class BridgeC2ETestSuite extends BaseDockerTestSuite { private val gweiAmount = UnitsConvert.toGwei(userAmount) "L2-380 Checking balances in CL->EL transfers" in { - def clAssetQuantity: Long = waves1.api.assetQuantity(waves1.chainContract.token) - def chainContractBalance: Long = waves1.api.balance(chainContractAddress, waves1.chainContract.token) + def clAssetQuantity: Long = waves1.api.assetQuantity(chainContract.token) + def chainContractBalance: Long = waves1.api.balance(chainContractAddress, chainContract.token) val clAssetQuantityBefore = clAssetQuantity val chainContractBalanceBefore = chainContractBalance @@ -22,10 +22,10 @@ class BridgeC2ETestSuite extends BaseDockerTestSuite { val elCurrHeight = ec1.web3j.ethBlockNumber().send().getBlockNumber.intValueExact() waves1.api.broadcastAndWait( - chainContract.transfer( + ChainContract.transfer( sender = clSender, destElAddress = elReceiverAddress, - asset = waves1.chainContract.token, + asset = chainContract.token, amount = wavesAmount ) ) @@ -62,7 +62,7 @@ class BridgeC2ETestSuite extends BaseDockerTestSuite { step("Prepare: issue tokens on chain contract and transfer to a user") waves1.api.broadcastAndWait( TxHelpers.reissue( - asset = waves1.chainContract.token, + asset = chainContract.token, sender = chainContractAccount, amount = wavesAmount ) @@ -72,7 +72,7 @@ class BridgeC2ETestSuite extends BaseDockerTestSuite { from = chainContractAccount, to = clSender.toAddress, amount = wavesAmount, - asset = waves1.chainContract.token + asset = chainContract.token ) ) } diff --git a/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala b/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala index 1bc84ebb..8a77ae02 100644 --- a/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala @@ -15,7 +15,7 @@ class BridgeE2CTestSuite extends BaseDockerTestSuite { private val wavesAmount = UnitsConvert.toWavesAmount(userAmount) private def sendNative(amount: BigInt = UnitsConvert.toWei(userAmount)): TransactionReceipt = - ec1.elBridge.sendNative(elSender, clRecipient.toAddress, amount) + elBridge.sendNative(elSender, clRecipient.toAddress, amount) private val tenGwei = BigInt(Convert.toWei("10", Convert.Unit.GWEI).toBigIntegerExact) @@ -67,7 +67,7 @@ class BridgeE2CTestSuite extends BaseDockerTestSuite { "L2-379 Checking balances in EL->CL transfers" in { step("Broadcast Bridge.sendNative transaction") - def bridgeBalance = ec1.web3j.ethGetBalance(ec1.elBridge.address.hex, DefaultBlockParameterName.LATEST).send().getBalance + def bridgeBalance = ec1.web3j.ethGetBalance(elBridgeAddress.hex, DefaultBlockParameterName.LATEST).send().getBalance val bridgeBalanceBefore = bridgeBalance val sendTxnReceipt = sendNative() @@ -79,7 +79,7 @@ class BridgeE2CTestSuite extends BaseDockerTestSuite { val blockHash = BlockHash(sendTxnReceipt.getBlockHash) step(s"Block with transaction: $blockHash") - val logsInBlock = ec1.engineApi.getLogs(blockHash, ec1.elBridge.address, Bridge.ElSentNativeEventTopic).explicitGet() + val logsInBlock = ec1.engineApi.getLogs(blockHash, elBridgeAddress, Bridge.ElSentNativeEventTopic).explicitGet() val transferEvents = logsInBlock.map { x => Bridge.ElSentNativeEvent.decodeArgs(x.data).explicitGet() @@ -91,12 +91,12 @@ class BridgeE2CTestSuite extends BaseDockerTestSuite { step(s"Wait block $blockHash on contract") val blockConfirmationHeight = retry { - waves1.chainContract.getBlock(blockHash).get.height + chainContract.getBlock(blockHash).get.height } step(s"Wait block $blockHash ($blockConfirmationHeight) finalization") retry { - val currFinalizedHeight = waves1.chainContract.getFinalizedBlock.height + val currFinalizedHeight = chainContract.getFinalizedBlock.height step(s"Current finalized height: $currFinalizedHeight") if (currFinalizedHeight < blockConfirmationHeight) fail("Not yet finalized") } @@ -107,11 +107,11 @@ class BridgeE2CTestSuite extends BaseDockerTestSuite { s"merkleProof={${transferProofs.map(EthEncoding.toHexString).mkString(",")}}" ) - def receiverBalance: Long = waves1.api.balance(clRecipient.toAddress, waves1.chainContract.token) + def receiverBalance: Long = waves1.api.balance(clRecipient.toAddress, chainContract.token) val receiverBalanceBefore = receiverBalance waves1.api.broadcastAndWait( - chainContract.withdraw( + ChainContract.withdraw( sender = clRecipient, blockHash = BlockHash(sendTxnReceipt.getBlockHash), merkleProof = transferProofs, diff --git a/consensus-client-it/src/test/scala/units/RewardTestSuite.scala b/consensus-client-it/src/test/scala/units/RewardTestSuite.scala index 98ba1d5b..d729e322 100644 --- a/consensus-client-it/src/test/scala/units/RewardTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/RewardTestSuite.scala @@ -14,7 +14,7 @@ class RewardTestSuite extends BaseDockerTestSuite { } val epoch1FirstContractBlock = retry { - waves1.chainContract.getBlock(epoch1FirstEcBlock.hash).getOrElse(failRetry(s"No first block ${epoch1FirstEcBlock.hash} confirmation")) + chainContract.getBlock(epoch1FirstEcBlock.hash).getOrElse(failRetry(s"No first block ${epoch1FirstEcBlock.hash} confirmation")) } val epoch1Number = epoch1FirstContractBlock.epoch @@ -24,7 +24,7 @@ class RewardTestSuite extends BaseDockerTestSuite { step(s"Wait for epoch #$epoch2Number data on chain contract") val epoch2FirstContractBlock = retry { - waves1.chainContract.getEpochFirstBlock(epoch2Number).get + chainContract.getEpochFirstBlock(epoch2Number).get } val epoch2FirstEcBlock = ec1.engineApi diff --git a/consensus-client-it/src/test/scala/units/SyncingTestSuite.scala b/consensus-client-it/src/test/scala/units/SyncingTestSuite.scala index 01c84f67..7b07e126 100644 --- a/consensus-client-it/src/test/scala/units/SyncingTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/SyncingTestSuite.scala @@ -34,7 +34,7 @@ class SyncingTestSuite extends BaseDockerTestSuite { step(s"Waiting blocks ${blocksWithTxns.mkString(", ")} on contract") blocksWithTxns.foreach { case (_, blockHash) => retry { - waves1.chainContract.getBlock(BlockHash(blockHash)).get + chainContract.getBlock(BlockHash(blockHash)).get } } @@ -47,7 +47,7 @@ class SyncingTestSuite extends BaseDockerTestSuite { step(s"Waiting blocks ${blocksWithTxns.mkString(", ")} disappear") blocksWithTxns.foreach { case (_, blockHash) => retry { - if (waves1.chainContract.getBlock(BlockHash(blockHash)).nonEmpty) throw new RuntimeException(s"Expected $blockHash to disappear") + if (chainContract.getBlock(BlockHash(blockHash)).nonEmpty) throw new RuntimeException(s"Expected $blockHash to disappear") } } diff --git a/consensus-client-it/src/test/scala/units/docker/EcContainer.scala b/consensus-client-it/src/test/scala/units/docker/EcContainer.scala index d9c3a7ef..7c20e44d 100644 --- a/consensus-client-it/src/test/scala/units/docker/EcContainer.scala +++ b/consensus-client-it/src/test/scala/units/docker/EcContainer.scala @@ -1,33 +1,28 @@ package units.docker import com.google.common.io.Files -import com.typesafe.config.{ConfigFactory, ConfigValueFactory} -import net.ceedubs.ficus.Ficus.toFicusConfig import org.testcontainers.containers.BindMode import org.testcontainers.containers.Network.NetworkImpl import org.web3j.protocol.Web3j import org.web3j.protocol.http.HttpService -import sttp.client3.HttpClientSyncBackend -import units.ClientConfig +import sttp.client3.{Identity, SttpBackend} +import units.client.JsonRpcClient import units.client.engine.{HttpEngineApiClient, LoggedEngineApiClient} -import units.docker.EcContainer.{EnginePort, RpcPort, mkConfig} -import units.el.ElBridgeClient -import units.eth.EthAddress +import units.docker.EcContainer.{EnginePort, RpcPort} import units.http.OkHttpLogger import units.test.TestEnvironment.* import java.io.File -import java.nio.charset.StandardCharsets -import scala.jdk.CollectionConverters.CollectionHasAsScala +import scala.concurrent.duration.DurationInt -class EcContainer(network: NetworkImpl, number: Int, ip: String) extends BaseContainer(s"ec-$number") { +class EcContainer(network: NetworkImpl, number: Int, ip: String)(implicit httpClientBackend: SttpBackend[Identity, Any]) + extends BaseContainer(s"ec-$number") { private val logFile = new File(s"$DefaultLogsDir/besu-$number.log") Files.touch(logFile) protected override val container = new GenericContainer(DockerImages.ExecutionClient) .withNetwork(network) .withExposedPorts(RpcPort, EnginePort) - .withEnv(EcContainer.peersEnv, EcContainer.peersVal.mkString(",")) .withEnv("LOG4J_CONFIGURATION_FILE", "/config/log4j2.xml") .withFileSystemBind(s"$ConfigsDir/ec-common/genesis.json", "/genesis.json", BindMode.READ_ONLY) .withFileSystemBind(s"$ConfigsDir/besu", "/config", BindMode.READ_ONLY) @@ -46,8 +41,13 @@ class EcContainer(network: NetworkImpl, number: Int, ip: String) extends BaseCon lazy val rpcPort = container.getMappedPort(RpcPort) lazy val enginePort = container.getMappedPort(EnginePort) - private val httpClientBackend = HttpClientSyncBackend() - lazy val engineApi = new LoggedEngineApiClient(new HttpEngineApiClient(mkConfig(container.getHost, enginePort), httpClientBackend)) + lazy val engineApiDockerUrl = s"http://$hostName:${EcContainer.EnginePort}" + lazy val engineApi = new LoggedEngineApiClient( + new HttpEngineApiClient( + JsonRpcClient.Config(apiUrl = s"http://${container.getHost}:$enginePort", apiRequestRetries = 5, apiRequestRetryWaitTime = 1.second), + httpClientBackend + ) + ) lazy val web3j = Web3j.build( new HttpService( @@ -58,11 +58,8 @@ class EcContainer(network: NetworkImpl, number: Int, ip: String) extends BaseCon ) ) - lazy val elBridge = new ElBridgeClient(web3j, EthAddress.unsafeFrom("0x0000000000000000000000000000000000006a7e")) - override def stop(): Unit = { web3j.shutdown() - httpClientBackend.close() super.stop() } @@ -72,25 +69,4 @@ class EcContainer(network: NetworkImpl, number: Int, ip: String) extends BaseCon object EcContainer { val RpcPort = 8545 val EnginePort = 8551 - - // TODO move - private val baseConfig = ConfigFactory.load(this.getClass.getClassLoader, "application.conf") - private def mkConfig(host: String, port: Int): ClientConfig = baseConfig - .getConfig("units.defaults") - .withValue("chain-contract", ConfigValueFactory.fromAnyRef("")) // Doesn't matter for HttpEngineApiClient - .withValue("execution-client-address", ConfigValueFactory.fromAnyRef(s"http://$host:$port")) - .resolve() - .as[ClientConfig] - - val (peersEnv, peersVal) = { - val file = new File(s"$ConfigsDir/ec-common/peers.env") - Files - .readLines(file, StandardCharsets.UTF_8) - .asScala - .mkString("") - .split('=') match { - case Array(peersEnv, peersVal, _*) => (peersEnv, peersVal.split(',').map(_.trim)) - case xs => throw new RuntimeException(s"Wrong $file content: ${xs.mkString(", ")}") - } - } } diff --git a/consensus-client-it/src/test/scala/units/docker/WavesNodeContainer.scala b/consensus-client-it/src/test/scala/units/docker/WavesNodeContainer.scala index 52baaed5..7951a7fa 100644 --- a/consensus-client-it/src/test/scala/units/docker/WavesNodeContainer.scala +++ b/consensus-client-it/src/test/scala/units/docker/WavesNodeContainer.scala @@ -3,14 +3,13 @@ package units.docker import com.google.common.io.Files import com.google.common.primitives.{Bytes, Ints} import com.typesafe.config.ConfigFactory -import com.wavesplatform.account.{Address, KeyPair, SeedKeyPair} -import com.wavesplatform.api.{LoggingBackend, NodeHttpApi} +import com.wavesplatform.account.{Address, SeedKeyPair} +import com.wavesplatform.api.NodeHttpApi import com.wavesplatform.common.utils.Base58 import com.wavesplatform.crypto import org.testcontainers.containers.BindMode import org.testcontainers.containers.Network.NetworkImpl -import sttp.client3.{HttpClientSyncBackend, UriContext} -import units.client.HttpChainContractClient +import sttp.client3.{Identity, SttpBackend, UriContext} import units.docker.WavesNodeContainer.* import units.test.TestEnvironment.* @@ -25,11 +24,11 @@ class WavesNodeContainer( number: Int, ip: String, baseSeed: String, - clMinerKeyPair: KeyPair, // Force CL miner chainContractAddress: Address, ecEngineApiUrl: String, genesisConfigPath: Path -) extends BaseContainer(s"wavesnode-$number") { +)(implicit httpClientBackend: SttpBackend[Identity, Any]) + extends BaseContainer(s"wavesnode-$number") { private val logFile = new File(s"$DefaultLogsDir/waves-$number.log") Files.touch(logFile) @@ -41,7 +40,6 @@ 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", @@ -65,18 +63,8 @@ class WavesNodeContainer( lazy val apiPort = container.getMappedPort(ApiPort) - // TODO common from EcContainer - private val httpClientBackend = new LoggingBackend(HttpClientSyncBackend()) - lazy val api = new NodeHttpApi(uri"http://${container.getHost}:$apiPort", httpClientBackend, AverageBlockDelay) - lazy val chainContract = new HttpChainContractClient(api, chainContractAddress) - - override def stop(): Unit = { - httpClientBackend.close() - super.stop() - } - override def logPorts(): Unit = log.debug(s"External host: ${container.getHost}, api: $apiPort") } diff --git a/consensus-client-it/src/test/scala/units/el/ElBridgeClient.scala b/consensus-client-it/src/test/scala/units/el/ElBridgeClient.scala index 4a3bcf6c..a9e087af 100644 --- a/consensus-client-it/src/test/scala/units/el/ElBridgeClient.scala +++ b/consensus-client-it/src/test/scala/units/el/ElBridgeClient.scala @@ -14,7 +14,7 @@ import units.test.HasRetry import java.util.Collections -class ElBridgeClient(web3j: Web3j, val address: EthAddress) extends HasRetry with ScorexLogging { +class ElBridgeClient(web3j: Web3j, address: EthAddress) extends HasRetry with ScorexLogging { def sendNative( sender: Credentials, recipient: Address, diff --git a/src/main/scala/units/ClientConfig.scala b/src/main/scala/units/ClientConfig.scala index 82290b7f..b35e5473 100644 --- a/src/main/scala/units/ClientConfig.scala +++ b/src/main/scala/units/ClientConfig.scala @@ -6,7 +6,7 @@ import com.wavesplatform.settings.* import net.ceedubs.ficus.Ficus.* import net.ceedubs.ficus.readers.ArbitraryTypeReader.arbitraryTypeValueReader import net.ceedubs.ficus.readers.{Generated, ValueReader} -import net.ceedubs.ficus.readers.namemappers.implicits.hyphenCase +import units.client.JsonRpcClient import scala.concurrent.duration.FiniteDuration @@ -22,6 +22,12 @@ case class ClientConfig( jwtSecretFile: Option[String] ) { lazy val chainContractAddress: Address = Address.fromString(chainContract).explicitGet() + + val jsonRpcClient = JsonRpcClient.Config( + apiUrl = executionClientAddress, + apiRequestRetries = apiRequestRetries, + apiRequestRetryWaitTime = apiRequestRetryWaitTime + ) } object ClientConfig { diff --git a/src/main/scala/units/ConsensusClientDependencies.scala b/src/main/scala/units/ConsensusClientDependencies.scala index 1b2a51cf..292c2057 100644 --- a/src/main/scala/units/ConsensusClientDependencies.scala +++ b/src/main/scala/units/ConsensusClientDependencies.scala @@ -37,7 +37,7 @@ class ConsensusClientDependencies(val config: ClientConfig) extends AutoCloseabl httpClientBackend } - val engineApiClient = new LoggedEngineApiClient(new HttpEngineApiClient(config, maybeAuthenticatedBackend)) + val engineApiClient = new LoggedEngineApiClient(new HttpEngineApiClient(config.jsonRpcClient, maybeAuthenticatedBackend)) val allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE) val peerDatabase = new PeerDatabaseImpl(config.network) diff --git a/src/main/scala/units/client/JsonRpcClient.scala b/src/main/scala/units/client/JsonRpcClient.scala index ba8ad3a9..4a411971 100644 --- a/src/main/scala/units/client/JsonRpcClient.scala +++ b/src/main/scala/units/client/JsonRpcClient.scala @@ -2,12 +2,14 @@ package units.client import cats.Id import cats.syntax.either.* +import net.ceedubs.ficus.Ficus.* +import net.ceedubs.ficus.readers.ArbitraryTypeReader.arbitraryTypeValueReader +import net.ceedubs.ficus.readers.{Generated, ValueReader} import play.api.libs.json.{JsError, JsValue, Reads, Writes} import sttp.client3.* import sttp.client3.playJson.* -import sttp.model.Uri -import units.client.JsonRpcClient.DefaultTimeout -import units.{ClientConfig, ClientError} +import units.ClientError +import units.client.JsonRpcClient.{Config, DefaultTimeout} import scala.concurrent.duration.{DurationInt, FiniteDuration} import scala.util.{Failure, Success, Try} @@ -15,9 +17,8 @@ import scala.util.{Failure, Success, Try} trait JsonRpcClient { private type RpcRequest[B] = Request[Either[ResponseException[String, JsError], JsonRpcResponse[B]], Any] - def config: ClientConfig + def config: Config def backend: SttpBackend[Id, ?] - def apiUrl: Uri protected def sendRequest[RQ: Writes, RP: Reads](requestBody: RQ, timeout: FiniteDuration = DefaultTimeout): Either[String, Option[RP]] = sendRequest(mkRequest(requestBody, timeout), config.apiRequestRetries) @@ -28,7 +29,7 @@ trait JsonRpcClient { private def mkRequest[A: Writes, B: Reads](requestBody: A, timeout: FiniteDuration): RpcRequest[B] = basicRequest .body(requestBody) - .post(apiUrl) + .post(config.sttpApiUri) .response(asJson[JsonRpcResponse[B]]) .readTimeout(timeout) @@ -67,4 +68,12 @@ trait JsonRpcClient { object JsonRpcClient { val DefaultTimeout: FiniteDuration = 1.minute + + case class Config(apiUrl: String, apiRequestRetries: Int, apiRequestRetryWaitTime: FiniteDuration) { + val sttpApiUri = uri"$apiUrl" + } + + object Config { + implicit val configValueReader: Generated[ValueReader[Config]] = arbitraryTypeValueReader + } } diff --git a/src/main/scala/units/client/engine/HttpEngineApiClient.scala b/src/main/scala/units/client/engine/HttpEngineApiClient.scala index 41deab4e..9ad77907 100644 --- a/src/main/scala/units/client/engine/HttpEngineApiClient.scala +++ b/src/main/scala/units/client/engine/HttpEngineApiClient.scala @@ -4,7 +4,6 @@ import cats.syntax.either.* import cats.syntax.traverse.* import play.api.libs.json.* import sttp.client3.* -import sttp.model.Uri import units.client.JsonRpcClient import units.client.engine.EngineApiClient.PayloadId import units.client.engine.HttpEngineApiClient.* @@ -12,14 +11,11 @@ import units.client.engine.model.* import units.client.engine.model.ForkChoiceUpdatedRequest.ForkChoiceAttributes import units.client.engine.model.PayloadStatus.{Syncing, Valid} import units.eth.EthAddress -import units.{BlockHash, ClientConfig, ClientError, JobResult} +import units.{BlockHash, ClientError, JobResult} import scala.concurrent.duration.{DurationInt, FiniteDuration} -class HttpEngineApiClient(val config: ClientConfig, val backend: SttpBackend[Identity, ?]) extends EngineApiClient with JsonRpcClient { - - val apiUrl: Uri = uri"${config.executionClientAddress}" - +class HttpEngineApiClient(val config: JsonRpcClient.Config, val backend: SttpBackend[Identity, ?]) extends EngineApiClient with JsonRpcClient { def forkChoiceUpdate(blockHash: BlockHash, finalizedBlockHash: BlockHash): JobResult[PayloadStatus] = { sendEngineRequest[ForkChoiceUpdatedRequest, ForkChoiceUpdatedResponse]( ForkChoiceUpdatedRequest(blockHash, finalizedBlockHash, None), diff --git a/src/test/scala/units/BaseIntegrationTestSuite.scala b/src/test/scala/units/BaseIntegrationTestSuite.scala index d49ed6ae..4acfd31a 100644 --- a/src/test/scala/units/BaseIntegrationTestSuite.scala +++ b/src/test/scala/units/BaseIntegrationTestSuite.scala @@ -36,15 +36,15 @@ trait BaseIntegrationTestSuite log.debug("EL init") val txs = List( - d.chainContract.setScript(), - d.chainContract.setup( + d.ChainContract.setScript(), + d.ChainContract.setup( d.ecGenesisBlock, elMinerDefaultReward.amount.longValue(), defaultSettings.daoRewardAccount.map(_.toAddress), defaultSettings.daoRewardAmount ) ) ++ - settings.initialMiners.map { x => d.chainContract.join(x.account, x.elRewardAddress) } + settings.initialMiners.map { x => d.ChainContract.join(x.account, x.elRewardAddress) } d.appendBlock(txs*) d.advanceConsensusLayerChanged() diff --git a/src/test/scala/units/BlockFullValidationTestSuite.scala b/src/test/scala/units/BlockFullValidationTestSuite.scala index 643f029c..99c9a941 100644 --- a/src/test/scala/units/BlockFullValidationTestSuite.scala +++ b/src/test/scala/units/BlockFullValidationTestSuite.scala @@ -32,7 +32,7 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite { d.triggerScheduledTasks() step(s"Append a CL micro block with ecBlock ${ecBlock.hash} confirmation") - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, ecBlock)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(reliable.account, ecBlock)) d.advanceConsensusLayerChanged() withClue("Validation doesn't happen:") { @@ -60,7 +60,7 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite { d.triggerScheduledTasks() step(s"Append a CL micro block with ecBlock ${ecBlock.hash} confirmation") - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() d.waitForCS[FollowingChain]("Following chain") { _ => } @@ -88,7 +88,7 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite { val ecBlock1 = d.createEcBlockBuilder("0", malfunction).buildAndSetLogs() d.ecClients.addKnown(ecBlock1) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(malfunction.account, ecBlock1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(malfunction.account, ecBlock1)) d.advanceConsensusLayerChanged() step("Start new epoch for ecBlock2") @@ -98,7 +98,7 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite { val ecBlock2 = badBlockPostProcessing(d.createEcBlockBuilder("0-0", malfunction, ecBlock1).rewardPrevMiner().buildAndSetLogs(blockLogs)) step(s"Append a CL micro block with ecBlock2 ${ecBlock2.hash} confirmation") - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(malfunction.account, ecBlock2, e2CTransfersRootHashHex)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(malfunction.account, ecBlock2, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() step(s"Receive ecBlock2 ${ecBlock2.hash} from a peer") diff --git a/src/test/scala/units/BlockIssuesForgingTestSuite.scala b/src/test/scala/units/BlockIssuesForgingTestSuite.scala index 7cea6538..d4322398 100644 --- a/src/test/scala/units/BlockIssuesForgingTestSuite.scala +++ b/src/test/scala/units/BlockIssuesForgingTestSuite.scala @@ -5,7 +5,7 @@ import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.wallet.Wallet import units.ELUpdater.State.ChainStatus.{FollowingChain, Mining, WaitForNewChain} import units.ELUpdater.WaitRequestedBlockTimeout -import units.client.contract.HasConsensusLayerDappTxHelpers.defaultFees +import units.client.contract.HasConsensusLayerDappTxHelpers.DefaultFees import units.client.engine.model.EcBlock import scala.concurrent.duration.DurationInt @@ -20,7 +20,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { override protected val defaultSettings: TestSettings = TestSettings.Default .copy( initialMiners = List(thisMiner, otherMiner1, otherMiner2), - additionalBalances = List(AddrWithBalance(transferReceiver.toAddress, defaultFees.chainContract.withdrawFee)) + additionalBalances = List(AddrWithBalance(transferReceiver.toAddress, DefaultFees.ChainContract.withdrawFee)) ) .withEnabledElMining @@ -30,7 +30,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(otherMiner1.address) val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs() d.ecClients.addKnown(ecBlock1) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(otherMiner1.account, ecBlock1)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.lastBlock.hash shouldBe ecBlock1.hash } @@ -39,7 +39,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(otherMiner1.address) val ecBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs() val ecBlock2Epoch = d.blockchain.height - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock2)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(otherMiner1.account, ecBlock2)) d.waitForCS[FollowingChain](s"Waiting ecBlock2 ${ecBlock2.hash}") { s => s.nodeChainInfo.lastBlock.hash shouldBe ecBlock2.hash @@ -80,7 +80,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(otherMiner1.address) val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs() d.ecClients.addKnown(ecBlock1) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(otherMiner1.account, ecBlock1)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe true @@ -90,7 +90,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2") d.advanceNewBlocks(otherMiner1.address) val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs() - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBadBlock2)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(otherMiner1.account, ecBadBlock2)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe true @@ -108,7 +108,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { s.chainSwitchInfo.referenceBlock.hash shouldBe ecBlock1.hash } - d.appendMicroBlockAndVerify(d.chainContract.startAltChain(otherMiner2.account, ecBlock2)) + d.appendMicroBlockAndVerify(d.ChainContract.startAltChain(otherMiner2.account, ecBlock2)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe false s.nodeChainInfo.lastBlock.hash shouldBe ecBlock2.hash @@ -126,7 +126,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(otherMiner2.address) val ecBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, parent = ecBlock2).rewardPrevMiner(1).buildAndSetLogs() val ecBlock3Epoch = d.blockchain.height - d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(otherMiner2.account, ecBlock3, chainId = 1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendAltChain(otherMiner2.account, ecBlock3, chainId = 1)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe false @@ -159,7 +159,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(otherMiner1.address) val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs() d.ecClients.addKnown(ecBlock1) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(otherMiner1.account, ecBlock1)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe true @@ -169,7 +169,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2") d.advanceNewBlocks(otherMiner1.address) val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs() - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBadBlock2)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(otherMiner1.account, ecBadBlock2)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe true @@ -198,7 +198,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with ecBadBlock3") d.advanceNewBlocks(otherMiner2.address) val ecBadBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, ecBlock2).rewardMiner(otherMiner2.elRewardAddress, 1).buildAndSetLogs() - d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(otherMiner2.account, ecBadBlock3, chainId = 1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendAltChain(otherMiner2.account, ecBadBlock3, chainId = 1)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe false @@ -225,7 +225,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(otherMiner1.address) val ecBlock1 = d.createEcBlockBuilder("0", otherMiner1).buildAndSetLogs() d.ecClients.addKnown(ecBlock1) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBlock1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(otherMiner1.account, ecBlock1)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe true @@ -235,7 +235,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with ecBadBlock2") d.advanceNewBlocks(otherMiner1.address) val ecBadBlock2 = d.createEcBlockBuilder("0-0", otherMiner1, ecBlock1).rewardPrevMiner().buildAndSetLogs() - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, ecBadBlock2)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(otherMiner1.account, ecBadBlock2)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe true @@ -250,7 +250,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { s.chainSwitchInfo.referenceBlock.hash shouldBe ecBlock1.hash } - d.appendMicroBlockAndVerify(d.chainContract.startAltChain(otherMiner2.account, ecBlock2)) + d.appendMicroBlockAndVerify(d.ChainContract.startAltChain(otherMiner2.account, ecBlock2)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe false @@ -268,7 +268,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with ecBlock3") d.advanceNewBlocks(otherMiner2.address) val ecBlock3 = d.createEcBlockBuilder("0-1-1", otherMiner2, ecBlock2).rewardPrevMiner(1).buildAndSetLogs() - d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(otherMiner2.account, ecBlock3, chainId = 1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendAltChain(otherMiner2.account, ecBlock3, chainId = 1)) d.waitForCS[FollowingChain]() { s => s.nodeChainInfo.isMain shouldBe false diff --git a/src/test/scala/units/C2ETransfersTestSuite.scala b/src/test/scala/units/C2ETransfersTestSuite.scala index cc9b68dd..5840f43e 100644 --- a/src/test/scala/units/C2ETransfersTestSuite.scala +++ b/src/test/scala/units/C2ETransfersTestSuite.scala @@ -68,6 +68,6 @@ class C2ETransfersTestSuite extends BaseIntegrationTestSuite { ) if (queueSize > 0) d.appendMicroBlock(TxHelpers.data(d.chainContractAccount, Seq(IntegerDataEntry("nativeTransfersCount", queueSize)))) - d.appendMicroBlockE(d.chainContract.transferUnsafe(transferSenderAccount, destElAddressHex, tokenId.getOrElse(d.token), transferAmount)) + d.appendMicroBlockE(d.ChainContract.transferUnsafe(transferSenderAccount, destElAddressHex, tokenId.getOrElse(d.token), transferAmount)) } } diff --git a/src/test/scala/units/E2CTransfersTestSuite.scala b/src/test/scala/units/E2CTransfersTestSuite.scala index a49ebb69..cefac22f 100644 --- a/src/test/scala/units/E2CTransfersTestSuite.scala +++ b/src/test/scala/units/E2CTransfersTestSuite.scala @@ -11,7 +11,7 @@ import org.web3j.abi.TypeReference import org.web3j.abi.datatypes.Event import org.web3j.abi.datatypes.generated.Bytes20 import units.ELUpdater.State.ChainStatus.{Mining, WaitForNewChain} -import units.client.contract.HasConsensusLayerDappTxHelpers.defaultFees +import units.client.contract.HasConsensusLayerDappTxHelpers.DefaultFees import units.eth.EthAddress import units.util.HexBytesConverter @@ -30,7 +30,7 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { override protected val defaultSettings: TestSettings = TestSettings.Default.copy( initialMiners = List(reliable), - additionalBalances = List(AddrWithBalance(transferReceiver.toAddress, defaultFees.chainContract.withdrawFee)) + additionalBalances = List(AddrWithBalance(transferReceiver.toAddress, DefaultFees.ChainContract.withdrawFee)) ) "Multiple withdrawals" in { @@ -46,8 +46,8 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { val settings = defaultSettings.copy( additionalBalances = List( - AddrWithBalance(transferReceiver1.toAddress, defaultFees.chainContract.withdrawFee), - AddrWithBalance(transferReceiver2.toAddress, defaultFees.chainContract.withdrawFee) + AddrWithBalance(transferReceiver1.toAddress, DefaultFees.ChainContract.withdrawFee), + AddrWithBalance(transferReceiver2.toAddress, DefaultFees.ChainContract.withdrawFee) ) ) @@ -57,15 +57,15 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs) def tryWithdraw(): Either[Throwable, BlockId] = d.appendMicroBlockE( - d.chainContract.withdraw(transferReceiver1, ecBlock, transfer1Proofs, 0, transfer1.amount), - d.chainContract.withdraw(transferReceiver2, ecBlock, transfer2Proofs, 1, transfer2.amount) + d.ChainContract.withdraw(transferReceiver1, ecBlock, transfer1Proofs, 0, transfer1.amount), + d.ChainContract.withdraw(transferReceiver2, ecBlock, transfer2Proofs, 1, transfer2.amount) ) tryWithdraw() should produce("not found for the contract address") step("Append a CL micro block with ecBlock confirmation") d.ecClients.addKnown(ecBlock) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() tryWithdraw() should beRight @@ -92,11 +92,11 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(reliable.address) val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs) d.ecClients.addKnown(ecBlock) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() def tryWithdraw(): Either[Throwable, BlockId] = - d.appendMicroBlockE(d.chainContract.withdraw(transferReceiver, ecBlock, transferProofs, index, transfer.amount)) + d.appendMicroBlockE(d.ChainContract.withdraw(transferReceiver, ecBlock, transferProofs, index, transfer.amount)) tryWithdraw() should produce(errorMessage) } @@ -107,11 +107,11 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(reliable.address) val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs) d.ecClients.addKnown(ecBlock) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() def tryWithdraw(): Either[Throwable, BlockId] = - d.appendMicroBlockE(d.chainContract.withdraw(transferReceiver, ecBlock, transferProofs, 0, amount)) + d.appendMicroBlockE(d.ChainContract.withdraw(transferReceiver, ecBlock, transferProofs, 0, amount)) tryWithdraw() should produce("Amount should be positive") } @@ -125,11 +125,11 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(reliable.address) val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs) def tryWithdraw(): Either[Throwable, BlockId] = - d.appendMicroBlockE(d.chainContract.withdraw(transferReceiver, ecBlock, transferProofs, 0, transfer.amount)) + d.appendMicroBlockE(d.ChainContract.withdraw(transferReceiver, ecBlock, transferProofs, 0, transfer.amount)) tryWithdraw() should produce("not found for the contract address") d.ecClients.addKnown(ecBlock) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() tryWithdraw() should beRight @@ -141,7 +141,7 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { "L2-273 Can't get transferred tokens twice" in { val settings = defaultSettings.copy( - additionalBalances = List(AddrWithBalance(transferReceiver.toAddress, defaultFees.chainContract.withdrawFee * 2)) + additionalBalances = List(AddrWithBalance(transferReceiver.toAddress, DefaultFees.ChainContract.withdrawFee * 2)) ) withExtensionDomain(settings) { d => @@ -149,11 +149,11 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(reliable.address) val ecBlock = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(ecBlockLogs) def tryWithdraw(): Either[Throwable, BlockId] = - d.appendMicroBlockE(d.chainContract.withdraw(transferReceiver, ecBlock, transferProofs, 0, transfer.amount)) + d.appendMicroBlockE(d.ChainContract.withdraw(transferReceiver, ecBlock, transferProofs, 0, transfer.amount)) tryWithdraw() should produce("not found for the contract address") d.ecClients.addKnown(ecBlock) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(reliable.account, ecBlock, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() tryWithdraw() should beRight @@ -182,7 +182,7 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { d.advanceNewBlocks(reliable.address) val ecBlock1 = d.createEcBlockBuilder("0", reliable).buildAndSetLogs(List(transferEvent)) def tryWithdraw(): Either[Throwable, BlockId] = - d.appendMicroBlockE(d.chainContract.withdraw(transferReceiver, ecBlock1, transferProofs, 0, transfer.amount)) + d.appendMicroBlockE(d.ChainContract.withdraw(transferReceiver, ecBlock1, transferProofs, 0, transfer.amount)) d.ecClients.willForge(ecBlock1) d.advanceConsensusLayerChanged() @@ -226,7 +226,7 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { d.advanceConsensusLayerChanged() d.ecClients.addKnown(ecBlock1) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(malfunction.account, ecBlock1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(malfunction.account, ecBlock1)) d.advanceConsensusLayerChanged() step(s"Try to append a block with a wrong transfers root hash") @@ -235,7 +235,7 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { d.advanceConsensusLayerChanged() // No root hash in extendMainChain tx - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(malfunction.account, ecBadBlock2)) // No root hash + d.appendMicroBlockAndVerify(d.ChainContract.extendMainChain(malfunction.account, ecBadBlock2)) // No root hash d.receiveNetworkBlock(ecBadBlock2, malfunction.account) d.advanceConsensusLayerChanged() @@ -262,15 +262,15 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { step(s"Confirm startAltChain and append with new blocks and remove a malfunction miner") d.appendMicroBlockAndVerify( - d.chainContract.startAltChain(reliable.account, ecBlock2, e2CTransfersRootHashHex), - d.chainContract.leave(malfunction.account) + d.ChainContract.startAltChain(reliable.account, ecBlock2, e2CTransfersRootHashHex), + d.ChainContract.leave(malfunction.account) ) d.advanceConsensusLayerChanged() d.waitForCS[Mining]("State is expected") { _ => } def tryWithdraw(): Either[Throwable, BlockId] = - d.appendMicroBlockE(d.chainContract.withdraw(transferReceiver, ecBlock2, transferProofs, 0, transfer.amount)) + d.appendMicroBlockE(d.ChainContract.withdraw(transferReceiver, ecBlock2, transferProofs, 0, transfer.amount)) withClue("Can't withdraw from a fork:") { tryWithdraw() should produce("is not finalized") } @@ -284,7 +284,7 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { step("Confirm extendAltChain to make this chain main") d.advanceMining() - d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(reliable.account, ecBlock3, chainId = 1)) + d.appendMicroBlockAndVerify(d.ChainContract.extendAltChain(reliable.account, ecBlock3, chainId = 1)) d.advanceConsensusLayerChanged() d.waitForCS[Mining]("State is expected") { _ => } diff --git a/src/test/scala/units/client/contract/HasConsensusLayerDappTxHelpers.scala b/src/test/scala/units/client/contract/HasConsensusLayerDappTxHelpers.scala index c410e7e8..c0c67fc7 100644 --- a/src/test/scala/units/client/contract/HasConsensusLayerDappTxHelpers.scala +++ b/src/test/scala/units/client/contract/HasConsensusLayerDappTxHelpers.scala @@ -13,7 +13,7 @@ import com.wavesplatform.transaction.{Asset, TxHelpers} import units.BlockHash import units.client.L2BlockLike import units.client.contract.HasConsensusLayerDappTxHelpers.* -import units.client.contract.HasConsensusLayerDappTxHelpers.defaultFees.chainContract.* +import units.client.contract.HasConsensusLayerDappTxHelpers.DefaultFees.ChainContract.* import units.eth.{EthAddress, EthereumConstants} trait HasConsensusLayerDappTxHelpers { @@ -22,7 +22,7 @@ trait HasConsensusLayerDappTxHelpers { def chainContractAccount: KeyPair lazy val chainContractAddress: Address = chainContractAccount.toAddress - object chainContract { + object ChainContract { def setScript(): SetScriptTransaction = TxHelpers.setScript(chainContractAccount, CompiledChainContract.script, fee = setScriptFee) def setup( @@ -229,8 +229,8 @@ trait HasConsensusLayerDappTxHelpers { object HasConsensusLayerDappTxHelpers { val EmptyE2CTransfersRootHashHex = EthereumConstants.NullHex - object defaultFees { - object chainContract { + object DefaultFees { + object ChainContract { val setScriptFee = 0.05.waves val setupFee = 2.waves val joinFee = 0.1.waves