diff --git a/consensus-client-it/src/test/scala/units/BridgeTestSuite.scala b/consensus-client-it/src/test/scala/units/BridgeTestSuite.scala index 2e40cce7..109cb762 100644 --- a/consensus-client-it/src/test/scala/units/BridgeTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/BridgeTestSuite.scala @@ -1,11 +1,11 @@ package units import com.wavesplatform.account.KeyPair -import com.wavesplatform.api.NodeHttpApi.ErrorResponse 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 @@ -21,10 +21,16 @@ class BridgeTestSuite extends TwoNodesTestSuite { val userAmount = 1 log.info("Broadcast Bridge.sendNative transaction") - val ethAmount = Convert.toWei(userAmount.toString, Convert.Unit.ETHER).toBigIntegerExact - val sendTxnReceipt = ec1.elBridge.sendNativeAndWait(elSender, clRecipient.toAddress, ethAmount) + val ethAmount = Convert.toWei(userAmount.toString, Convert.Unit.ETHER).toBigIntegerExact - // TODO check the balance of contract wasn't changed + 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 bridgeBalanceAfter = bridgeBalance + withClue("1. The balance of Bridge contract wasn't changed: ") { + bridgeBalanceAfter shouldBe bridgeBalanceBefore + } val blockHash = BlockHash(sendTxnReceipt.getBlockHash) log.info(s"Block with transaction: $blockHash") @@ -72,9 +78,11 @@ class BridgeTestSuite extends TwoNodesTestSuite { amount = wavesAmount ) - val attempt1 = waves1.api.broadcast(withdraw()).left.value - attempt1.error shouldBe ScriptExecutionError.Id - attempt1.message should include("is not finalized") + withClue("2. Withdraws from non-finalized blocks are denied: ") { + val attempt1 = waves1.api.broadcast(withdraw()).left.value + attempt1.error shouldBe ScriptExecutionError.Id + attempt1.message should include("is not finalized") + } log.info(s"Wait block $blockHash ($blockConfirmationHeight) finalization") retry { @@ -83,15 +91,8 @@ class BridgeTestSuite extends TwoNodesTestSuite { if (currFinalizedHeight < blockConfirmationHeight) fail("Not yet finalized") } - // TODO: try to send from other person - withClue("Try ") { - val attempt2 = waves1.api.broadcast(withdraw(clRichAccount2)).left.value - attempt2.error shouldBe ScriptExecutionError.Id - attempt2.message should include("Check your withdraw arguments") - } - - def balance: Long = waves1.api.balance(clRecipient.toAddress, waves1.chainContract.token) - val balanceBefore = balance + def receiverBalance: Long = waves1.api.balance(clRecipient.toAddress, waves1.chainContract.token) + val receiverBalanceBefore = receiverBalance log.info( s"Broadcast withdraw transaction: transferIndexInBlock=$sendTxnLogIndex, amount=$wavesAmount, " + @@ -99,9 +100,9 @@ class BridgeTestSuite extends TwoNodesTestSuite { ) waves1.api.broadcastAndWait(withdraw()) - val balanceAfter = balance - withClue("Received") { - balanceAfter shouldBe (balanceBefore + wavesAmount) + val balanceAfter = receiverBalance + withClue("3. Tokens received: ") { + balanceAfter shouldBe (receiverBalanceBefore + wavesAmount) } }