Skip to content

Commit 22297f7

Browse files
committed
chore: instantiate different kinds of RPCHandlerArgs to test fee estimation errors
1 parent 41a1026 commit 22297f7

File tree

1 file changed

+40
-6
lines changed
  • stackslib/src/net/api/tests

1 file changed

+40
-6
lines changed

stackslib/src/net/api/tests/mod.rs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use std::net::SocketAddr;
18+
use std::sync::{Arc, Mutex};
1819

1920
use clarity::vm::costs::ExecutionCost;
2021
use clarity::vm::types::{QualifiedContractIdentifier, StacksAddressExtensions};
@@ -46,7 +47,7 @@ use crate::net::db::PeerDB;
4647
use crate::net::httpcore::{StacksHttpRequest, StacksHttpResponse};
4748
use crate::net::relay::Relayer;
4849
use crate::net::rpc::ConversationHttp;
49-
use crate::net::test::{TestEventObserver, TestPeer, TestPeerConfig};
50+
use crate::net::test::{RPCHandlerArgsType, TestEventObserver, TestPeer, TestPeerConfig};
5051
use crate::net::tests::inv::nakamoto::make_nakamoto_peers_from_invs_ext;
5152
use crate::net::{
5253
Attachment, AttachmentInstance, MemPoolEventDispatcher, RPCHandlerArgs, StackerDBConfig,
@@ -226,10 +227,28 @@ pub struct TestRPC<'a> {
226227

227228
impl<'a> TestRPC<'a> {
228229
pub fn setup(test_name: &str) -> TestRPC<'a> {
229-
Self::setup_ex(test_name, true)
230+
Self::setup_ex(test_name, true, None, None)
230231
}
231232

232-
pub fn setup_ex(test_name: &str, process_microblock: bool) -> TestRPC<'a> {
233+
pub fn setup_with_rpc_args(
234+
test_name: &str,
235+
rpc_handler_args_opt_1: Option<RPCHandlerArgsType>,
236+
rpc_handler_args_opt_2: Option<RPCHandlerArgsType>,
237+
) -> TestRPC<'a> {
238+
Self::setup_ex(
239+
test_name,
240+
true,
241+
rpc_handler_args_opt_1,
242+
rpc_handler_args_opt_2,
243+
)
244+
}
245+
246+
pub fn setup_ex(
247+
test_name: &str,
248+
process_microblock: bool,
249+
rpc_handler_args_opt_1: Option<RPCHandlerArgsType>,
250+
rpc_handler_args_opt_2: Option<RPCHandlerArgsType>,
251+
) -> TestRPC<'a> {
233252
// ST2DS4MSWSGJ3W9FBC6BVT0Y92S345HY8N3T6AV7R
234253
let privk1 = StacksPrivateKey::from_hex(
235254
"9f1f85a512a96a244e4c0d762788500687feb97481639572e3bffbd6860e6ab001",
@@ -317,6 +336,9 @@ impl<'a> TestRPC<'a> {
317336
let mut peer_1 = TestPeer::new(peer_1_config);
318337
let mut peer_2 = TestPeer::new(peer_2_config);
319338

339+
peer_1.rpc_handler_args = rpc_handler_args_opt_1;
340+
peer_2.rpc_handler_args = rpc_handler_args_opt_2;
341+
320342
// mine one block with a contract in it
321343
// first the coinbase
322344
// make a coinbase for this miner
@@ -976,7 +998,11 @@ impl<'a> TestRPC<'a> {
976998
}
977999

9781000
{
979-
let mut rpc_args = RPCHandlerArgs::default();
1001+
let mut rpc_args = peer_1
1002+
.rpc_handler_args
1003+
.as_ref()
1004+
.map(|args_type| args_type.instantiate())
1005+
.unwrap_or(RPCHandlerArgsType::make_default());
9801006
rpc_args.event_observer = event_observer;
9811007
let mut node_state = StacksNodeState::new(
9821008
&mut peer_1.network,
@@ -1020,7 +1046,11 @@ impl<'a> TestRPC<'a> {
10201046
}
10211047

10221048
{
1023-
let mut rpc_args = RPCHandlerArgs::default();
1049+
let mut rpc_args = peer_2
1050+
.rpc_handler_args
1051+
.as_ref()
1052+
.map(|args_type| args_type.instantiate())
1053+
.unwrap_or(RPCHandlerArgsType::make_default());
10241054
rpc_args.event_observer = event_observer;
10251055
let mut node_state = StacksNodeState::new(
10261056
&mut peer_2.network,
@@ -1076,7 +1106,11 @@ impl<'a> TestRPC<'a> {
10761106
let mut peer_1_stacks_node = peer_1.stacks_node.take().unwrap();
10771107
let mut peer_1_mempool = peer_1.mempool.take().unwrap();
10781108

1079-
let rpc_args = RPCHandlerArgs::default();
1109+
let rpc_args = peer_1
1110+
.rpc_handler_args
1111+
.as_ref()
1112+
.map(|args_type| args_type.instantiate())
1113+
.unwrap_or(RPCHandlerArgsType::make_default());
10801114
let mut node_state = StacksNodeState::new(
10811115
&mut peer_1.network,
10821116
&peer_1_sortdb,

0 commit comments

Comments
 (0)