Skip to content

Commit 52386ef

Browse files
silverpillsilverpill
andauthored
Test against monero 0.18.4.3 (#152)
* Test against monero 0.18.4.3 * Add get_version() method to DaemonJsonRpcClient, fix test * Fix test --------- Co-authored-by: silverpill <silverpill@firemail.cc>
1 parent b943a4a commit 52386ef

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
monero: [ 0.18.1.2, 0.18.3.3, 0.18.3.4, 0.18.4.0, 0.18.4.1, 0.18.4.2 ]
14+
monero: [ 0.18.1.2, 0.18.3.3, 0.18.3.4, 0.18.4.0, 0.18.4.1, 0.18.4.2, 0.18.4.3 ]
1515

1616
steps:
1717
- uses: actions/checkout@v5

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Added `subtract_fee_from_outputs` to `transfer` options by @thesn10 ([#141](https://github.com/monero-rs/monero-rpc-rs/pull/141)).
1919
- Added `destinations` field to `get_transfer` return value by @bytenotbark ([#128](https://github.com/monero-rs/monero-rpc-rs/pull/128)).
2020
- Added `block_height` field to struct returned by `incoming_transfers` by @silverpill ([#151](https://github.com/monero-rs/monero-rpc-rs/pull/151)).
21+
- Added `get_version` method to `DaemonJsonRpcClient` by @silverpill ([#152](https://github.com/monero-rs/monero-rpc-rs/pull/152)).
2122

2223
### Changed
2324

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,23 @@ impl DaemonJsonRpcClient {
552552
Ok((headers.into_iter().map(From::from).collect(), untrusted))
553553
}
554554

555+
pub async fn get_version(&self) -> anyhow::Result<(u16, u16)> {
556+
#[derive(Deserialize)]
557+
struct Rsp {
558+
version: u32,
559+
}
560+
561+
let version = self
562+
.inner
563+
.request::<Rsp>("get_version", RpcParams::None)
564+
.await?;
565+
566+
let major = version.version >> 16;
567+
let minor = version.version - (major << 16);
568+
569+
Ok((u16::try_from(major)?, u16::try_from(minor)?))
570+
}
571+
555572
/// Enable additional functions for daemons in regtest mode.
556573
pub fn regtest(self) -> RegtestDaemonJsonRpcClient {
557574
RegtestDaemonJsonRpcClient(self)

tests/clients_tests/empty_blockchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub async fn run() {
1919
let genesis_block_hash = helpers::get_genesis_block_hash();
2020

2121
helpers::regtest::get_block_count_assert_height(&regtest, 1).await;
22-
helpers::regtest::on_get_block_hash_error_invalid_height(&regtest, 10).await;
22+
helpers::regtest::on_get_block_hash_error_invalid_height(&regtest, 10, 0).await;
2323
helpers::regtest::on_get_block_hash_assert_hash(&regtest, 0, genesis_block_hash).await;
2424

2525
let key_pair_1 = helpers::get_keypair_1();

tests/clients_tests/helpers/regtest.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use monero_rpc::{
88
};
99
use serde::Deserialize;
1010

11+
const DAEMON_VERSION_0_18_4_3: u16 = 15;
12+
1113
pub async fn get_block_count_assert_height(
1214
regtest: &RegtestDaemonJsonRpcClient,
1315
expected_height: u64,
@@ -28,12 +30,16 @@ pub async fn on_get_block_hash_assert_hash(
2830
pub async fn on_get_block_hash_error_invalid_height(
2931
regtest: &RegtestDaemonJsonRpcClient,
3032
height: u64,
33+
expected_height: u64,
3134
) {
35+
let version = regtest.get_version().await.unwrap();
3236
let block_hash = regtest.on_get_block_hash(height).await.unwrap_err();
33-
assert_eq!(
34-
block_hash.to_string(),
37+
let expected_error_message = if version.1 < DAEMON_VERSION_0_18_4_3 {
3538
format!("Invalid height {height} supplied.")
36-
);
39+
} else {
40+
format!("Server error: Requested block height: {height} greater than current top block height: {expected_height}")
41+
};
42+
assert_eq!(block_hash.to_string(), expected_error_message);
3743
}
3844

3945
fn get_expected_height_returned_by_generate_blocks(

tests/clients_tests/non_empty_blockchain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub async fn run() {
5050
helpers::regtest::on_get_block_hash_error_invalid_height(
5151
&regtest,
5252
generate_blocks_res.height + 1,
53+
generate_blocks_res.height,
5354
)
5455
.await;
5556
helpers::regtest::on_get_block_hash_assert_hash(

0 commit comments

Comments
 (0)