From 59891594aa83cf159a2d6b82dbeaa11fc85f5548 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sun, 19 Mar 2023 21:05:05 -0400 Subject: [PATCH] Fix processor's determionation of protocol to support integration tests I'm really unhappy with a cfg(test) within the codebase. The double checking of it makes it tolerable though, especially when compared to dropping these tests. --- .github/workflows/monero-tests.yaml | 2 ++ processor/src/coins/monero.rs | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/monero-tests.yaml b/.github/workflows/monero-tests.yaml index 11783bf8..0734c80c 100644 --- a/.github/workflows/monero-tests.yaml +++ b/.github/workflows/monero-tests.yaml @@ -6,10 +6,12 @@ on: - develop paths: - "coins/monero/**" + - "processor/**" pull_request: paths: - "coins/monero/**" + - "processor/**" jobs: # Only run these once since they will be consistent regardless of any node diff --git a/processor/src/coins/monero.rs b/processor/src/coins/monero.rs index 0e7cfb18..c18787ed 100644 --- a/processor/src/coins/monero.rs +++ b/processor/src/coins/monero.rs @@ -290,7 +290,24 @@ impl Coin for Monero { // Sanity check this has at least one output planned assert!((!plan.payments.is_empty()) || plan.change.is_some()); - let protocol = Protocol::v16; + // Get the protocol for the specified block number + // For now, this should just be v16, the latest deployed protocol, since there's no upcoming + // hard fork to be mindful of + let get_protocol = || Protocol::v16; + + #[cfg(not(test))] + let protocol = get_protocol(); + // If this is a test, we won't be using a mainnet node and need a distinct protocol + // determination + // Just use whatever the node expects + #[cfg(test)] + let protocol = self.rpc.get_protocol().await.unwrap(); + + // Hedge against the above codegen failing by having an always included runtime check + if !cfg!(test) { + assert_eq!(protocol, get_protocol()); + } + // Check a fork hasn't occurred which this processor hasn't been updated for assert_eq!(protocol, self.rpc.get_protocol().await.map_err(|_| CoinError::ConnectionError)?);