diff --git a/consensus-client-it/src/test/scala/com/wavesplatform/api/NodeHttpApi.scala b/consensus-client-it/src/test/scala/com/wavesplatform/api/NodeHttpApi.scala index 6ac2c127..d51d7e69 100644 --- a/consensus-client-it/src/test/scala/com/wavesplatform/api/NodeHttpApi.scala +++ b/consensus-client-it/src/test/scala/com/wavesplatform/api/NodeHttpApi.scala @@ -136,6 +136,20 @@ class NodeHttpApi(apiUri: Uri, backend: SttpBackend[Identity, ?]) extends HasRet } } + def assetQuantity(asset: IssuedAsset)(implicit loggingOptions: LoggingOptions = LoggingOptions()): Long = { + log.debug(s"${loggingOptions.prefix} assetQuantity($asset)") + basicRequest + .get(uri"$apiUri/assets/details/$asset?full=false") + .response(asJson[AssetDetailsResponse]) + .tag(LoggingOptionsTag, loggingOptions) + .send(backend) + .body match { + case Left(HttpError(body, statusCode)) => failRetry(s"Server returned error $body with status ${statusCode.code}") + case Left(DeserializationException(body, error)) => failRetry(s"failed to parse response $body: $error") + case Right(r) => r.quantity + } + } + def waitForConnectedPeers(atLeast: Int): Unit = { implicit val loggingOptions: LoggingOptions = LoggingOptions(logRequestBody = false) log.debug(s"${loggingOptions.prefix} waitForConnectedPeers($atLeast)") @@ -181,6 +195,11 @@ object NodeHttpApi { implicit val assetBalanceResponseFormat: OFormat[AssetBalanceResponse] = Json.format[AssetBalanceResponse] } + case class AssetDetailsResponse(quantity: Long) + object AssetDetailsResponse { + implicit val assetDetailsResponseFormat: OFormat[AssetDetailsResponse] = Json.format[AssetDetailsResponse] + } + case class ConnectedPeersResponse(peers: List[JsObject]) object ConnectedPeersResponse { implicit val connectedPeersResponseFormat: OFormat[ConnectedPeersResponse] = Json.format[ConnectedPeersResponse] diff --git a/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala b/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala new file mode 100644 index 00000000..adbae9e5 --- /dev/null +++ b/consensus-client-it/src/test/scala/units/BridgeC2ETestSuite.scala @@ -0,0 +1,59 @@ +package units + +import com.wavesplatform.transaction.TxHelpers +import units.eth.EthAddress + +class BridgeC2ETestSuite extends OneNodeTestSuite { + protected val clSender = clRichAccount1 + protected val elReceiver = elRichAccount1 + protected val userAmount = 1 + protected val wavesAmount = UnitsConvert.toWavesAmount(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) + + val clAssetQuantityBefore = clAssetQuantity + val chainContractBalanceBefore = chainContractBalance + + waves1.api.broadcastAndWait( + chainContract.transfer( + sender = clSender, + destElAddress = EthAddress.unsafeFrom(elReceiver.getAddress), + asset = waves1.chainContract.token, + amount = wavesAmount + ) + ) + + val chainContractBalanceAfter = chainContractBalance + withClue("1. Chain contract balance unchanged: ") { + chainContractBalanceAfter shouldBe chainContractBalanceBefore + } + + val clAssetQuantityAfter = clAssetQuantity + withClue("1. Tokens burned: ") { + clAssetQuantityAfter shouldBe (clAssetQuantityBefore - wavesAmount) + } + } + + override def beforeAll(): Unit = { + super.beforeAll() + + log.info("Prepare: issue tokens on chain contract and transfer to a user") + waves1.api.broadcastAndWait( + TxHelpers.reissue( + asset = waves1.chainContract.token, + sender = chainContractAccount, + amount = wavesAmount + ) + ) + waves1.api.broadcastAndWait( + TxHelpers.transfer( + from = chainContractAccount, + to = clSender.toAddress, + amount = wavesAmount, + asset = waves1.chainContract.token + ) + ) + } +} diff --git a/consensus-client-it/src/test/scala/units/BridgeTestSuite.scala b/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala similarity index 91% rename from consensus-client-it/src/test/scala/units/BridgeTestSuite.scala rename to consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala index 109cb762..aa8ee1e4 100644 --- a/consensus-client-it/src/test/scala/units/BridgeTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BridgeE2CTestSuite.scala @@ -3,29 +3,26 @@ package units import com.wavesplatform.account.KeyPair import com.wavesplatform.api.http.ApiError.ScriptExecutionError import com.wavesplatform.common.utils.EitherExt2 -import com.wavesplatform.settings.Constants import com.wavesplatform.utils.EthEncoding import org.web3j.protocol.core.DefaultBlockParameterName import org.web3j.protocol.core.methods.request.EthFilter import org.web3j.protocol.core.methods.response.EthLog -import org.web3j.utils.Convert import units.client.engine.model.GetLogsResponseEntry import units.eth.EthAddress import scala.jdk.CollectionConverters.CollectionHasAsScala -class BridgeTestSuite extends TwoNodesTestSuite { +class BridgeE2CTestSuite extends TwoNodesTestSuite { "L2-379 Checking balances in EL->CL transfers" in { val elSender = elRichAccount1 val clRecipient = clRichAccount1 val userAmount = 1 + val wavesAmount = UnitsConvert.toWavesAmount(userAmount) log.info("Broadcast Bridge.sendNative transaction") - val ethAmount = Convert.toWei(userAmount.toString, Convert.Unit.ETHER).toBigIntegerExact - def bridgeBalance = ec1.web3j.ethGetBalance(ec1.elBridge.address.hex, DefaultBlockParameterName.LATEST).send().getBalance val bridgeBalanceBefore = bridgeBalance - val sendTxnReceipt = ec1.elBridge.sendNativeAndWait(elSender, clRecipient.toAddress, ethAmount) + val sendTxnReceipt = ec1.elBridge.sendNativeAndWait(elSender, clRecipient.toAddress, UnitsConvert.toEthAmount(userAmount)) val bridgeBalanceAfter = bridgeBalance withClue("1. The balance of Bridge contract wasn't changed: ") { @@ -58,7 +55,6 @@ class BridgeTestSuite extends TwoNodesTestSuite { val sendTxnLogIndex = rawLogsInBlock.indexWhere(_.getTransactionHash == sendTxnReceipt.getTransactionHash) val transferProofs = Bridge.mkTransferProofs(transferEvents, sendTxnLogIndex).reverse - val wavesAmount = userAmount * Constants.UnitsInWave log.info(s"Wait block $blockHash on contract") val blockConfirmationHeight = retry { @@ -105,6 +101,4 @@ class BridgeTestSuite extends TwoNodesTestSuite { balanceAfter shouldBe (receiverBalanceBefore + wavesAmount) } } - - "L2-380 Checking balances in CL->EL transfers" in {} } diff --git a/consensus-client-it/src/test/scala/units/UnitsConvert.scala b/consensus-client-it/src/test/scala/units/UnitsConvert.scala new file mode 100644 index 00000000..416e262a --- /dev/null +++ b/consensus-client-it/src/test/scala/units/UnitsConvert.scala @@ -0,0 +1,11 @@ +package units + +import com.wavesplatform.settings.Constants +import org.web3j.utils.Convert + +import java.math.BigInteger + +object UnitsConvert { + def toWavesAmount(userAmount: BigDecimal): Long = (userAmount * Constants.UnitsInWave).toLongExact + def toEthAmount(userAmount: BigDecimal): BigInteger = Convert.toWei(userAmount.bigDecimal, Convert.Unit.ETHER).toBigIntegerExact +}