Browse Source

Mock handlers for contract setup

Running this test with `--nocapture` reveals that we have unmocked
handlers. Adding these mocks fixes those panics (which are being
captured by tokio and hence did not abort the test).

Additionally we specialize the `mock_common_handlers` function to just
deal with the two `Sync` messages to make it clear that no more mocks
should be added to this function.
pAndLAndPayout
Thomas Eizinger 3 years ago
parent
commit
8c025d4ed2
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 9
      daemon/tests/happy_path.rs
  2. 20
      daemon/tests/harness/mocks/mod.rs
  3. 8
      daemon/tests/harness/mod.rs

9
daemon/tests/happy_path.rs

@ -85,6 +85,15 @@ async fn taker_takes_order_and_maker_accepts_and_contract_setup() {
maker.mocks.mock_party_params().await;
taker.mocks.mock_party_params().await;
maker.mocks.mock_monitor_oracle_attestation().await;
taker.mocks.mock_monitor_oracle_attestation().await;
maker.mocks.mock_oracle_monitor_attestation().await;
taker.mocks.mock_oracle_monitor_attestation().await;
maker.mocks.mock_monitor_start_monitoring().await;
taker.mocks.mock_monitor_start_monitoring().await;
maker.accept_take_request(received.clone()).await;
let (taker_cfd, maker_cfd) = next_cfd(taker.cfd_feed(), maker.cfd_feed()).await.unwrap();

20
daemon/tests/harness/mocks/mod.rs

@ -32,13 +32,9 @@ impl Mocks {
self.oracle.lock().await
}
/// Mock message handlers that are not important for the test, but the cfd
/// actor still sends messages
pub async fn mock_common_empty_handlers(&mut self) {
// Sync methods need to be mocked before actors start
pub async fn mock_sync_handlers(&mut self) {
self.oracle().await.expect_sync().return_const(());
self.monitor().await.expect_sync().return_const(());
self.mock_monitor_oracle_attestation().await;
}
// Helper function setting up a "happy path" wallet mock
@ -65,6 +61,13 @@ impl Mocks {
.return_const(Some(oracle::dummy_announcement()));
}
pub async fn mock_oracle_monitor_attestation(&mut self) {
self.oracle()
.await
.expect_monitor_attestation()
.return_const(());
}
pub async fn mock_party_params(&mut self) {
#[allow(clippy::redundant_closure)] // clippy is in the wrong here
self.wallet()
@ -79,6 +82,13 @@ impl Mocks {
.expect_oracle_attestation()
.return_const(());
}
pub async fn mock_monitor_start_monitoring(&mut self) {
self.monitor()
.await
.expect_start_monitoring()
.return_const(());
}
}
impl Default for Mocks {

8
daemon/tests/harness/mod.rs

@ -63,7 +63,6 @@ impl Maker {
let mut mocks = mocks::Mocks::default();
let (oracle, monitor, wallet) = mocks::create_actors(&mocks);
mocks.mock_common_empty_handlers().await;
let (wallet_addr, wallet_fut) = wallet.create(None).run();
tokio::spawn(wallet_fut);
@ -73,6 +72,8 @@ impl Maker {
let seed = Seed::default();
let (identity_pk, identity_sk) = seed.derive_identity();
// system startup sends sync messages, mock them
mocks.mock_sync_handlers().await;
let maker = daemon::MakerActorSystem::new(
db,
wallet_addr,
@ -119,6 +120,8 @@ impl Maker {
}
pub async fn publish_order(&mut self, new_order_params: maker_cfd::NewOrder) {
self.mocks.mock_monitor_oracle_attestation().await;
self.system
.cfd_actor_addr
.send(new_order_params)
@ -178,11 +181,12 @@ impl Taker {
let mut mocks = mocks::Mocks::default();
let (oracle, monitor, wallet) = mocks::create_actors(&mocks);
mocks.mock_common_empty_handlers().await;
let (wallet_addr, wallet_fut) = wallet.create(None).run();
tokio::spawn(wallet_fut);
// system startup sends sync messages, mock them
mocks.mock_sync_handlers().await;
let taker = daemon::TakerActorSystem::new(
db,
wallet_addr,

Loading…
Cancel
Save