Skip to content

Commit

Permalink
fix(ampd): broadcast client builder should not require the acc sequen…
Browse files Browse the repository at this point in the history
…ce (#367)
  • Loading branch information
fish-sammy authored Apr 23, 2024
1 parent ed07ad9 commit 6dae8d3
Showing 1 changed file with 66 additions and 64 deletions.
130 changes: 66 additions & 64 deletions ampd/src/broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ pub trait Broadcaster {
}

#[derive(Builder)]
#[builder(pattern = "owned")]
pub struct BroadcastClient<T, Q> {
client: T,
signer: SharableEcdsaClient,
query_client: Q,
address: TMAddress,
#[builder(setter(skip))]
acc_sequence: Option<u64>,
pub_key: (String, PublicKey),
config: Config,
Expand Down Expand Up @@ -310,7 +312,7 @@ mod tests {
use tonic::Status;

use crate::broadcaster::clients::{MockAccountQueryClient, MockBroadcastClient};
use crate::broadcaster::{BroadcastClient, Broadcaster, Config, Error};
use crate::broadcaster::{BroadcastClientBuilder, Broadcaster, Config, Error};
use crate::tofnd::grpc::{MockEcdsaClient, SharableEcdsaClient};
use crate::types::{PublicKey, TMAddress};
use crate::PREFIX;
Expand Down Expand Up @@ -345,15 +347,15 @@ mod tests {
})
});

let mut broadcaster = BroadcastClient {
client,
signer: SharableEcdsaClient::new(signer),
query_client,
address,
acc_sequence: None,
pub_key: (key_id.to_string(), pub_key),
config: Config::default(),
};
let mut broadcaster = BroadcastClientBuilder::default()
.client(client)
.signer(SharableEcdsaClient::new(signer))
.query_client(query_client)
.address(address)
.pub_key((key_id.to_string(), pub_key))
.config(Config::default())
.build()
.unwrap();
let msgs = vec![dummy_msg()];

assert!(matches!(
Expand Down Expand Up @@ -399,15 +401,15 @@ mod tests {
})
});

let mut broadcaster = BroadcastClient {
client,
signer: SharableEcdsaClient::new(signer),
query_client,
address,
acc_sequence: None,
pub_key: (key_id.to_string(), pub_key),
config: Config::default(),
};
let mut broadcaster = BroadcastClientBuilder::default()
.client(client)
.signer(SharableEcdsaClient::new(signer))
.query_client(query_client)
.address(address)
.pub_key((key_id.to_string(), pub_key))
.config(Config::default())
.build()
.unwrap();
let msgs = vec![dummy_msg()];

assert!(matches!(
Expand Down Expand Up @@ -472,15 +474,15 @@ mod tests {
})
});

let mut broadcaster = BroadcastClient {
client,
signer: SharableEcdsaClient::new(signer),
query_client,
address,
acc_sequence: None,
pub_key: (key_id.to_string(), pub_key),
config: Config::default(),
};
let mut broadcaster = BroadcastClientBuilder::default()
.client(client)
.signer(SharableEcdsaClient::new(signer))
.query_client(query_client)
.address(address)
.pub_key((key_id.to_string(), pub_key))
.config(Config::default())
.build()
.unwrap();
let msgs = vec![dummy_msg()];

assert!(matches!(
Expand Down Expand Up @@ -549,15 +551,15 @@ mod tests {
})
});

let mut broadcaster = BroadcastClient {
client,
signer: SharableEcdsaClient::new(signer),
query_client,
address,
acc_sequence: None,
pub_key: (key_id.to_string(), pub_key),
config: Config::default(),
};
let mut broadcaster = BroadcastClientBuilder::default()
.client(client)
.signer(SharableEcdsaClient::new(signer))
.query_client(query_client)
.address(address)
.pub_key((key_id.to_string(), pub_key))
.config(Config::default())
.build()
.unwrap();
let msgs = vec![dummy_msg()];

assert!(matches!(
Expand Down Expand Up @@ -631,15 +633,15 @@ mod tests {
})
});

let mut broadcaster = BroadcastClient {
client,
signer: SharableEcdsaClient::new(signer),
query_client,
address,
acc_sequence: None,
pub_key: (key_id.to_string(), pub_key),
config: Config::default(),
};
let mut broadcaster = BroadcastClientBuilder::default()
.client(client)
.signer(SharableEcdsaClient::new(signer))
.query_client(query_client)
.address(address)
.pub_key((key_id.to_string(), pub_key))
.config(Config::default())
.build()
.unwrap();
let msgs = vec![dummy_msg()];

assert!(matches!(
Expand Down Expand Up @@ -715,15 +717,15 @@ mod tests {
})
});

let mut broadcaster = BroadcastClient {
client,
signer: SharableEcdsaClient::new(signer),
query_client,
address,
acc_sequence: None,
pub_key: (key_id.to_string(), pub_key),
config: Config::default(),
};
let mut broadcaster = BroadcastClientBuilder::default()
.client(client)
.signer(SharableEcdsaClient::new(signer))
.query_client(query_client)
.address(address)
.pub_key((key_id.to_string(), pub_key))
.config(Config::default())
.build()
.unwrap();
let msgs = vec![dummy_msg()];

assert_eq!(broadcaster.acc_sequence, None);
Expand Down Expand Up @@ -807,15 +809,15 @@ mod tests {
})
});

let mut broadcaster = BroadcastClient {
client,
signer: SharableEcdsaClient::new(signer),
query_client,
address,
acc_sequence: None,
pub_key: (key_id.to_string(), pub_key),
config: Config::default(),
};
let mut broadcaster = BroadcastClientBuilder::default()
.client(client)
.signer(SharableEcdsaClient::new(signer))
.query_client(query_client)
.address(address)
.pub_key((key_id.to_string(), pub_key))
.config(Config::default())
.build()
.unwrap();

assert_eq!(broadcaster.acc_sequence, None);
assert!(broadcaster.broadcast(vec![dummy_msg()]).await.is_ok());
Expand Down

0 comments on commit 6dae8d3

Please sign in to comment.