rust-web3 icon indicating copy to clipboard operation
rust-web3 copied to clipboard

Add a public export for web3::helpers::TestTranport

Open adklempner opened this issue 6 years ago • 4 comments

I'd like to use the mocked TestTransport struct for testing a crate that depends on rust-web3.

Is there already a way of doing this? If not, what would be the best way to export it? Would be happy to open a PR for this.

adklempner avatar Jun 29 '18 14:06 adklempner

Sounds good to me, should probably be feature-gated like other transports.

tomusdrw avatar Jul 02 '18 12:07 tomusdrw

I tried use web3::helpers::tests::TestTransport but I'm getting an unresolved import error. Why doesn't this work?

creese avatar Nov 05 '20 03:11 creese

The entire tests module is gated with #[cfg(test)] which means it's only compiled when tests for web3 crate are running (the tests running on your crate that depends on web3 does not inlcude this code).

My earlier suggestion was to extract TestTransport to web3::transports module and expose it from there, adding a Cargo feature for the test transport (just like we have http and ws transports now.

tomusdrw avatar Nov 05 '20 11:11 tomusdrw

What do you think about switching Rc<RefCell<_>> to Arc<RwLock<_>> so that TestTransport implements Sync + Send?

marmistrz avatar Mar 14 '22 10:03 marmistrz