Skip to content

Commit

Permalink
L2-379 checks
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuharnikov committed Oct 31, 2024
1 parent 2131a80 commit bee0913
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions consensus-client-it/src/test/scala/units/BridgeTestSuite.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand All @@ -83,25 +91,18 @@ 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, " +
s"merkleProof={${transferProofs.map(EthEncoding.toHexString).mkString(",")}}"
)
waves1.api.broadcastAndWait(withdraw())

val balanceAfter = balance
withClue("Received") {
balanceAfter shouldBe (balanceBefore + wavesAmount)
val balanceAfter = receiverBalance
withClue("3. Tokens received: ") {
balanceAfter shouldBe (receiverBalanceBefore + wavesAmount)
}
}

Expand Down

0 comments on commit bee0913

Please sign in to comment.