diff --git a/bmc/src/main/java/foundation/icon/btp/bmc/BTPMessageCenter.java b/bmc/src/main/java/foundation/icon/btp/bmc/BTPMessageCenter.java index 466471d..e13dbc3 100644 --- a/bmc/src/main/java/foundation/icon/btp/bmc/BTPMessageCenter.java +++ b/bmc/src/main/java/foundation/icon/btp/bmc/BTPMessageCenter.java @@ -540,6 +540,7 @@ private void handleRelayMessage(String _prev, byte[] msgBytes) { link.setRxSeq(rxSeq.add(BigInteger.valueOf(msgCount))); } putLink(link); + RelayMessage(_prev, BigInteger.valueOf(msgCount)); // dispatch BTPMessages for (byte[] serializedMsg : serializedMsgs) { @@ -1184,4 +1185,8 @@ private void requireNormalMode() { throw BMCException.unknown("not normal mode"); } } + + @EventLog(indexed = 1) + public void RelayMessage(String _prev, BigInteger _count) { + } } diff --git a/bmc/src/main/java/foundation/icon/btp/bmc/ICONSpecific.java b/bmc/src/main/java/foundation/icon/btp/bmc/ICONSpecific.java index a7aea36..dbb5b79 100644 --- a/bmc/src/main/java/foundation/icon/btp/bmc/ICONSpecific.java +++ b/bmc/src/main/java/foundation/icon/btp/bmc/ICONSpecific.java @@ -148,4 +148,16 @@ public interface ICONSpecific { */ @External(readonly = true) BigInteger getMode(); + + /** + * (EventLog) Logs the event that handle the relay message + * The tracker monitors this event. + *

+ * indexed: 1 + * + * @param _prev String ( BTP Address of the previous BMC ) + * @param _count Integer ( number of the processed BTP message ) + */ + @EventLog(indexed = 1) + void RelayMessage(String _prev, BigInteger _count); } diff --git a/bmc/src/test/java/foundation/icon/btp/bmc/BMCIntegrationTest.java b/bmc/src/test/java/foundation/icon/btp/bmc/BMCIntegrationTest.java index 7325d95..de06333 100644 --- a/bmc/src/test/java/foundation/icon/btp/bmc/BMCIntegrationTest.java +++ b/bmc/src/test/java/foundation/icon/btp/bmc/BMCIntegrationTest.java @@ -139,4 +139,10 @@ static Consumer btpEvent( consumer, null); } + static Consumer relayMessageEvent( + Consumer consumer) { + return eventLogChecker( + ICONSpecificScoreClient.RelayMessage::eventLogs, + consumer, null); + } } diff --git a/bmc/src/test/java/foundation/icon/btp/bmc/MessageTest.java b/bmc/src/test/java/foundation/icon/btp/bmc/MessageTest.java index c625bbf..685a66b 100644 --- a/bmc/src/test/java/foundation/icon/btp/bmc/MessageTest.java +++ b/bmc/src/test/java/foundation/icon/btp/bmc/MessageTest.java @@ -158,6 +158,15 @@ static Consumer btpEventChecker( ))); } + static Consumer relayMessageEventChecker( + final BTPAddress prev, final int count) { + return BMCIntegrationTest.relayMessageEvent( + (el) -> { + assertEquals(prev.toString(), el.get_prev()); + assertEquals(BigInteger.valueOf(count), el.get_count()); + }); + } + @ParameterizedTest @MethodSource("sendMessageShouldSuccessArguments") void sendMessageShouldSuccess( @@ -282,6 +291,8 @@ void handleRelayMessageShouldSuccess( System.out.println("handleRelayMessageShouldIncreaseRxSeq"); Consumer checker = rxSeqChecker(prev); + System.out.println("handleRelayMessageShouldEmitRelayMessage"); + checker = checker.andThen(relayMessageEventChecker(prev, 1)); if (expectBTPError != null) { if (snCompare > 0) { System.out.println("handleRelayMessageShouldReplyBTPError"); diff --git a/bmc/src/test/java/foundation/icon/btp/bmc/MessageWithFeeTest.java b/bmc/src/test/java/foundation/icon/btp/bmc/MessageWithFeeTest.java index dd87afa..cc28ad5 100644 --- a/bmc/src/test/java/foundation/icon/btp/bmc/MessageWithFeeTest.java +++ b/bmc/src/test/java/foundation/icon/btp/bmc/MessageWithFeeTest.java @@ -277,6 +277,8 @@ void handleRelayMessageShouldSuccess( System.out.println("handleRelayMessageShouldIncreaseRxSeqAndAccumulateReward"); Consumer checker = MessageTest.rxSeqChecker(prev) .andThen(rewardChecker(msg)); + System.out.println("handleRelayMessageShouldEmitRelayMessage"); + checker = checker.andThen(MessageTest.relayMessageEventChecker(prev, 1)); if (expectBTPError != null) { System.out.println("handleRelayMessageShouldReplyBTPError"); checker = checker.andThen(responseMessageChecker(prev, msg, expectBTPError));