Skip to content

Commit

Permalink
fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Feb 17, 2025
1 parent 59590a5 commit 45098df
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 26 deletions.
8 changes: 6 additions & 2 deletions zebra-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,10 @@ where
Utc::now(),
));

let tip_height = self.latest_chain_tip.best_tip_height().unwrap_or(Height::MIN);
let tip_height = self
.latest_chain_tip
.best_tip_height()
.unwrap_or(Height::MIN);
let testnet = self.network.is_a_test_network();

// This field is behind the `ENABLE_WALLET` feature flag in zcashd:
Expand All @@ -593,7 +596,8 @@ where
// For compatibility, we keep the field in the response, but always return 0.
let pay_tx_fee = 0.0;

let relay_fee = zebra_chain::transaction::zip317::MIN_MEMPOOL_TX_FEE_RATE as f64 / (zebra_chain::amount::COIN as f64);
let relay_fee = zebra_chain::transaction::zip317::MIN_MEMPOOL_TX_FEE_RATE as f64
/ (zebra_chain::amount::COIN as f64);
let difficulty = chain_tip_difficulty(self.network.clone(), self.state.clone()).await?;

let response = GetInfo {
Expand Down
6 changes: 5 additions & 1 deletion zebra-rpc/src/methods/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use zebra_chain::{
};

use zebra_consensus::ParameterCheckpoint;
use zebra_network::address_book_peers::MockAddressBookPeers;
use zebra_node_services::mempool;
use zebra_state::{BoxError, GetBlockTemplateChainInfo};

Expand Down Expand Up @@ -968,6 +969,7 @@ fn mock_services<Tip>(
zebra_state::ReadRequest,
>,
Tip,
MockAddressBookPeers,
>,
tokio::task::JoinHandle<()>,
)
Expand All @@ -978,14 +980,16 @@ where
let state = MockService::build().for_prop_tests();

let (rpc, mempool_tx_queue) = RpcImpl::new(
"RPC test",
"0.0.1",
"RPC test",
network,
false,
true,
mempool.clone(),
Buffer::new(state.clone(), 1),
chain_tip,
MockAddressBookPeers::new(vec![]),
crate::methods::LoggedLastEvent::new(None.into()),
);

(mempool, state, rpc, mempool_tx_queue)
Expand Down
19 changes: 16 additions & 3 deletions zebra-rpc/src/methods/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use zebra_chain::{
serialization::ZcashDeserializeInto,
subtree::NoteCommitmentSubtreeData,
};
use zebra_network::address_book_peers::MockAddressBookPeers;
use zebra_node_services::BoxError;
use zebra_state::{ReadRequest, ReadResponse, MAX_ON_DISK_HEIGHT};
use zebra_test::mock_service::MockService;
Expand Down Expand Up @@ -116,6 +117,8 @@ async fn test_z_get_treestate() {
Buffer::new(MockService::build().for_unit_tests::<_, _, BoxError>(), 1),
state,
tip,
MockAddressBookPeers::new(vec![]),
crate::methods::LoggedLastEvent::new(None.into()),
);

// Request the treestate by a hash.
Expand Down Expand Up @@ -198,14 +201,16 @@ async fn test_rpc_response_data_for_network(network: &Network) {

// Init RPC
let (rpc, _rpc_tx_queue_task_handle) = RpcImpl::new(
"RPC test",
"0.0.1",
"/Zebra:RPC test/",
network.clone(),
false,
true,
Buffer::new(mempool.clone(), 1),
read_state,
latest_chain_tip,
MockAddressBookPeers::new(vec![]),
crate::methods::LoggedLastEvent::new(None.into()),
);

// We only want a snapshot of the `getblocksubsidy` and `getblockchaininfo` methods for the non-default Testnet (with an NU6 activation height).
Expand All @@ -220,7 +225,10 @@ async fn test_rpc_response_data_for_network(network: &Network) {
}

// `getinfo`
let get_info = rpc.get_info().expect("We should have a GetInfo struct");
let get_info = rpc
.get_info()
.await
.expect("We should have a GetInfo struct");
snapshot_rpc_getinfo(get_info, &settings);

// `getblockchaininfo`
Expand Down Expand Up @@ -522,14 +530,16 @@ async fn test_mocked_rpc_response_data_for_network(network: &Network) {
let mempool = MockService::build().for_unit_tests();

let (rpc, _) = RpcImpl::new(
"RPC test",
"0.0.1",
"/Zebra:RPC test/",
network.clone(),
false,
true,
mempool,
state.clone(),
latest_chain_tip,
MockAddressBookPeers::new(vec![]),
crate::methods::LoggedLastEvent::new(None.into()),
);

// Test the response format from `z_getsubtreesbyindex` for Sapling.
Expand Down Expand Up @@ -599,6 +609,9 @@ fn snapshot_rpc_getinfo(info: GetInfo, settings: &insta::Settings) {
// replace with:
"[SubVersion]"
}),
".errorstimestamp" => dynamic_redaction(|_value, _path| {
"[LastErrorTimestamp]"
}),
})
});
}
Expand Down
15 changes: 12 additions & 3 deletions zebra-rpc/src/methods/tests/snapshots/get_info@mainnet_10.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
---
source: zebra-rpc/src/methods/tests/snapshot.rs
assertion_line: 161
expression: info
---
{
"build": "vRPC test",
"subversion": "[SubVersion]"
"version": 100,
"build": "v0.0.1",
"subversion": "[SubVersion]",
"protocolversion": 170120,
"blocks": 10,
"connections": 0,
"difficulty": 1.0,
"testnet": false,
"paytxfee": 0.0,
"relayfee": 0.000001,
"errors": "no errors",
"errorstimestamp": "[LastErrorTimestamp]"
}
15 changes: 12 additions & 3 deletions zebra-rpc/src/methods/tests/snapshots/get_info@testnet_10.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
---
source: zebra-rpc/src/methods/tests/snapshot.rs
assertion_line: 161
expression: info
---
{
"build": "vRPC test",
"subversion": "[SubVersion]"
"version": 100,
"build": "v0.0.1",
"subversion": "[SubVersion]",
"protocolversion": 170120,
"blocks": 10,
"connections": 0,
"difficulty": 1.0,
"testnet": true,
"paytxfee": 0.0,
"relayfee": 0.000001,
"errors": "no errors",
"errorstimestamp": "[LastErrorTimestamp]"
}
Loading

0 comments on commit 45098df

Please sign in to comment.