From 416f7180581f1ded819cd94511049199faf9c028 Mon Sep 17 00:00:00 2001 From: Pedro Novais <1478752+jpnovais@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:54:42 +0100 Subject: [PATCH] coordinator: smart contract deploy helper improver regex --- .../MakefileContractDeploymentHelper.kt | 17 +++-- .../MakefileContractDeploymentHelperKtTest.kt | 65 +++++++++++++++++++ 2 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 coordinator/ethereum/test-utils/src/test/kotlin/net/consensys/zkevm/ethereum/MakefileContractDeploymentHelperKtTest.kt diff --git a/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/MakefileContractDeploymentHelper.kt b/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/MakefileContractDeploymentHelper.kt index 7332dcb27..c616b0ea9 100644 --- a/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/MakefileContractDeploymentHelper.kt +++ b/coordinator/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/MakefileContractDeploymentHelper.kt @@ -74,11 +74,11 @@ fun executeCommand( return futureResult.toSafeFuture() } -private val lineaRollupAddressPattern = Pattern.compile( - "^LineaRollup(?:[a-zA-Z0-9]*)? deployed: address=(0x[0-9a-fA-F]{40}) blockNumber=(\\d+)" +internal val lineaRollupAddressPattern = Pattern.compile( + "^LineaRollup(?:.*)? deployed: address=(0x[0-9a-fA-F]{40}) blockNumber=(\\d+)" ) -private val l2MessageServiceAddressPattern = Pattern.compile( - "^L2MessageService deployed: address=(0x[0-9a-fA-F]{40}) blockNumber=(\\d+)" +internal val l2MessageServiceAddressPattern = Pattern.compile( + "^L2MessageService(?:.*)? deployed: address=(0x[0-9a-fA-F]{40}) blockNumber=(\\d+)" ) data class DeployedContract( @@ -91,7 +91,14 @@ fun getDeployedAddress( addressPattern: Pattern ): DeployedContract { val lines = commandResult.stdOut.toList().asReversed() - val matcher: Matcher? = lines + return getDeployedAddress(lines, addressPattern) +} + +fun getDeployedAddress( + cmdStdoutLines: List, + addressPattern: Pattern +): DeployedContract { + val matcher: Matcher? = cmdStdoutLines .firstOrNull { line -> addressPattern.matcher(line).find() } ?.let { addressPattern.matcher(it).also { it.find() } } diff --git a/coordinator/ethereum/test-utils/src/test/kotlin/net/consensys/zkevm/ethereum/MakefileContractDeploymentHelperKtTest.kt b/coordinator/ethereum/test-utils/src/test/kotlin/net/consensys/zkevm/ethereum/MakefileContractDeploymentHelperKtTest.kt new file mode 100644 index 000000000..62f8ed1f1 --- /dev/null +++ b/coordinator/ethereum/test-utils/src/test/kotlin/net/consensys/zkevm/ethereum/MakefileContractDeploymentHelperKtTest.kt @@ -0,0 +1,65 @@ +package net.consensys.zkevm.ethereum + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class MakefileContractDeploymentHelperKtTest { + + @Test + fun getDeployedAddress_messageService() { + assertThat( + getDeployedAddress( + listOf( + "L2MessageService artifact has been deployed in 1.2659626659999998s ", + "L2MessageService deployed: address=0xFE48d65B84AA0E23594Fd585c11cAD831F90AcB6 blockNumber=8", + "" + ), + l2MessageServiceAddressPattern + ) + ).isEqualTo( + DeployedContract("0xFE48d65B84AA0E23594Fd585c11cAD831F90AcB6", 8) + ) + + assertThat( + getDeployedAddress( + listOf( + "L2MessageServiceV1.2.3 artifact has been deployed in 1.2659626659999998s ", + "L2MessageServiceV1.2.3 deployed: address=0xFE48d65B84AA0E23594Fd585c11cAD831F90AcB6 blockNumber=8", + "" + ), + l2MessageServiceAddressPattern + ) + ).isEqualTo( + DeployedContract("0xFE48d65B84AA0E23594Fd585c11cAD831F90AcB6", 8) + ) + } + + @Test + fun getDeployedAddress_LineaRollup() { + assertThat( + getDeployedAddress( + listOf( + "LineaRollup artifact has been deployed in 1.855172125s ", + "LineaRollup deployed: address=0x8613180dF1485B8b87DEE3BCf31896659eb1a092 blockNumber=1414", + "" + ), + lineaRollupAddressPattern + ) + ).isEqualTo( + DeployedContract("0x8613180dF1485B8b87DEE3BCf31896659eb1a092", 1414) + ) + + assertThat( + getDeployedAddress( + listOf( + "LineaRollupV5.2.1 artifact has been deployed in 1.855172125s ", + "LineaRollupV5.2.1 deployed: address=0x8613180dF1485B8b87DEE3BCf31896659eb1a092 blockNumber=1414", + "" + ), + lineaRollupAddressPattern + ) + ).isEqualTo( + DeployedContract("0x8613180dF1485B8b87DEE3BCf31896659eb1a092", 1414) + ) + } +}