Skip to content

Commit

Permalink
refactor(minor): remove "get" from function names (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgorenflo authored Jul 24, 2024
1 parent e4ef307 commit 216f153
Show file tree
Hide file tree
Showing 46 changed files with 302 additions and 313 deletions.
14 changes: 7 additions & 7 deletions ampd/proto/ampd.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ message SubscribeRequest {
bool include_block_begin_end = 2;
}

message EventBlockBegin { uint64 height = 1; }
message EventBlockBegin {uint64 height = 1;}

message EventBlockEnd { uint64 height = 1; }
message EventBlockEnd {uint64 height = 1;}

message Event {
string event_type = 1;
Expand All @@ -32,7 +32,7 @@ message SubscribeResponse {
}
}

message BroadcastRequest { google.protobuf.Any msg = 1; }
message BroadcastRequest {google.protobuf.Any msg = 1;}

message BroadcastResponse {}

Expand All @@ -47,16 +47,16 @@ message SignRequest {
Algorithm algorithm = 3;
}

message SignResponse { bytes signature = 1; }
message SignResponse {bytes signature = 1;}

message GetKeyRequest {
message KeyRequest {
string key_id = 1;
Algorithm algorithm = 2;
}

message GetKeyResponse { bytes pub_key = 1; }
message KeyResponse {bytes pub_key = 1;}

service Crypto {
rpc Sign(SignRequest) returns (SignResponse) {}
rpc GetKey(GetKeyRequest) returns (GetKeyResponse) {}
rpc Key(KeyRequest) returns (KeyResponse) {}
}
Empty file.
4 changes: 2 additions & 2 deletions ampd/src/broadcaster/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tonic::{Response, Status};
pub trait BroadcastClient {
async fn broadcast_tx(&mut self, request: BroadcastTxRequest) -> Result<TxResponse, Status>;
async fn simulate(&mut self, request: SimulateRequest) -> Result<SimulateResponse, Status>;
async fn get_tx(&mut self, request: GetTxRequest) -> Result<GetTxResponse, Status>;
async fn tx(&mut self, request: GetTxRequest) -> Result<GetTxResponse, Status>;
}

#[async_trait]
Expand All @@ -42,7 +42,7 @@ impl BroadcastClient for ServiceClient<Channel> {
self.simulate(request).await.map(Response::into_inner)
}

async fn get_tx(&mut self, request: GetTxRequest) -> Result<GetTxResponse, Status> {
async fn tx(&mut self, request: GetTxRequest) -> Result<GetTxResponse, Status> {
self.get_tx(request).await.map(Response::into_inner)
}
}
Expand Down
8 changes: 4 additions & 4 deletions ampd/src/broadcaster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ where

let response = self
.client
.get_tx(GetTxRequest {
.tx(GetTxRequest {
hash: tx_hash.to_string(),
})
.await;
Expand Down Expand Up @@ -580,7 +580,7 @@ mod tests {
.expect_broadcast_tx()
.returning(|_| Ok(TxResponse::default()));
client
.expect_get_tx()
.expect_tx()
.times((Config::default().tx_fetch_max_retries + 1) as usize)
.returning(|_| Err(Status::deadline_exceeded("time out")));

Expand Down Expand Up @@ -612,7 +612,7 @@ mod tests {
client
.expect_broadcast_tx()
.returning(|_| Ok(TxResponse::default()));
client.expect_get_tx().times(1).returning(|_| {
client.expect_tx().times(1).returning(|_| {
Ok(GetTxResponse {
tx_response: Some(TxResponse {
code: 32,
Expand Down Expand Up @@ -808,7 +808,7 @@ mod tests {
client
.expect_broadcast_tx()
.returning(|_| Ok(TxResponse::default()));
client.expect_get_tx().returning(|_| {
client.expect_tx().returning(|_| {
Ok(GetTxResponse {
tx_response: Some(TxResponse {
code: 0,
Expand Down
4 changes: 2 additions & 2 deletions ampd/src/commands/register_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct Args {
pub async fn run(config: Config, args: Args) -> Result<Option<String>, Error> {
let pub_key = verifier_pub_key(config.tofnd_config.clone()).await?;

let multisig_address = get_multisig_address(&config)?;
let multisig_address = multisig_address(&config)?;

let tofnd_config = config.tofnd_config.clone();

Expand Down Expand Up @@ -105,7 +105,7 @@ pub async fn run(config: Config, args: Args) -> Result<Option<String>, Error> {
)))
}

fn get_multisig_address(config: &Config) -> Result<TMAddress, Error> {
fn multisig_address(config: &Config) -> Result<TMAddress, Error> {
config
.handlers
.iter()
Expand Down
33 changes: 16 additions & 17 deletions ampd/src/evm/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn has_failed(tx_receipt: &TransactionReceipt) -> bool {
tx_receipt.status == Some(0u64.into())
}

fn get_event<'a>(
fn event<'a>(
gateway_address: &EVMAddress,
tx_receipt: &'a TransactionReceipt,
log_index: u32,
Expand Down Expand Up @@ -83,7 +83,7 @@ where
return Vote::FailedOnChain;
}

match get_event(gateway_address, tx_receipt, expected_event_index) {
match event(gateway_address, tx_receipt, expected_event_index) {
Some(event)
if tx_receipt.transaction_hash == expected_transaction_hash && to_verify == event =>
{
Expand Down Expand Up @@ -135,7 +135,7 @@ mod tests {
#[test]
fn should_not_verify_verifier_set_if_tx_id_does_not_match() {
let (gateway_address, tx_receipt, mut verifier_set) =
get_matching_verifier_set_and_tx_receipt();
matching_verifier_set_and_tx_receipt();

verifier_set.tx_id = Hash::random();
assert_eq!(
Expand All @@ -147,7 +147,7 @@ mod tests {
#[test]
fn should_not_verify_verifier_set_if_tx_failed() {
let (gateway_address, mut tx_receipt, verifier_set) =
get_matching_verifier_set_and_tx_receipt();
matching_verifier_set_and_tx_receipt();

tx_receipt.status = Some(0u64.into());
assert_eq!(
Expand All @@ -158,7 +158,7 @@ mod tests {

#[test]
fn should_not_verify_verifier_set_if_gateway_address_does_not_match() {
let (_, tx_receipt, verifier_set) = get_matching_verifier_set_and_tx_receipt();
let (_, tx_receipt, verifier_set) = matching_verifier_set_and_tx_receipt();

let gateway_address = EVMAddress::random();
assert_eq!(
Expand All @@ -170,7 +170,7 @@ mod tests {
#[test]
fn should_not_verify_verifier_set_if_log_index_does_not_match() {
let (gateway_address, tx_receipt, mut verifier_set) =
get_matching_verifier_set_and_tx_receipt();
matching_verifier_set_and_tx_receipt();

verifier_set.event_index = 0;
assert_eq!(
Expand All @@ -192,7 +192,7 @@ mod tests {
#[test]
fn should_not_verify_verifier_set_if_verifier_set_does_not_match() {
let (gateway_address, tx_receipt, mut verifier_set) =
get_matching_verifier_set_and_tx_receipt();
matching_verifier_set_and_tx_receipt();

verifier_set.verifier_set.threshold = Uint128::from(50u64);
assert_eq!(
Expand All @@ -203,8 +203,7 @@ mod tests {

#[test]
fn should_verify_verifier_set_if_correct() {
let (gateway_address, tx_receipt, verifier_set) =
get_matching_verifier_set_and_tx_receipt();
let (gateway_address, tx_receipt, verifier_set) = matching_verifier_set_and_tx_receipt();

assert_eq!(
verify_verifier_set(&gateway_address, &tx_receipt, &verifier_set),
Expand All @@ -214,7 +213,7 @@ mod tests {

#[test]
fn should_not_verify_msg_if_tx_id_does_not_match() {
let (gateway_address, tx_receipt, mut msg) = get_matching_msg_and_tx_receipt();
let (gateway_address, tx_receipt, mut msg) = matching_msg_and_tx_receipt();

msg.tx_id = Hash::random();
assert_eq!(
Expand All @@ -225,7 +224,7 @@ mod tests {

#[test]
fn should_not_verify_msg_if_tx_failed() {
let (gateway_address, mut tx_receipt, msg) = get_matching_msg_and_tx_receipt();
let (gateway_address, mut tx_receipt, msg) = matching_msg_and_tx_receipt();

tx_receipt.status = Some(0u64.into());
assert_eq!(
Expand All @@ -236,7 +235,7 @@ mod tests {

#[test]
fn should_not_verify_msg_if_gateway_address_does_not_match() {
let (_, tx_receipt, msg) = get_matching_msg_and_tx_receipt();
let (_, tx_receipt, msg) = matching_msg_and_tx_receipt();

let gateway_address = EVMAddress::random();
assert_eq!(
Expand All @@ -247,7 +246,7 @@ mod tests {

#[test]
fn should_not_verify_msg_if_log_index_does_not_match() {
let (gateway_address, tx_receipt, mut msg) = get_matching_msg_and_tx_receipt();
let (gateway_address, tx_receipt, mut msg) = matching_msg_and_tx_receipt();

msg.event_index = 0;
assert_eq!(
Expand All @@ -268,7 +267,7 @@ mod tests {

#[test]
fn should_not_verify_msg_if_msg_does_not_match() {
let (gateway_address, tx_receipt, mut msg) = get_matching_msg_and_tx_receipt();
let (gateway_address, tx_receipt, mut msg) = matching_msg_and_tx_receipt();

msg.source_address = EVMAddress::random();
assert_eq!(
Expand All @@ -279,15 +278,15 @@ mod tests {

#[test]
fn should_verify_msg_if_correct() {
let (gateway_address, tx_receipt, msg) = get_matching_msg_and_tx_receipt();
let (gateway_address, tx_receipt, msg) = matching_msg_and_tx_receipt();

assert_eq!(
verify_message(&gateway_address, &tx_receipt, &msg),
Vote::SucceededOnChain
);
}

fn get_matching_verifier_set_and_tx_receipt(
fn matching_verifier_set_and_tx_receipt(
) -> (EVMAddress, TransactionReceipt, VerifierSetConfirmation) {
let tx_id = Hash::random();
let log_index = 1;
Expand Down Expand Up @@ -326,7 +325,7 @@ mod tests {
(gateway_address, tx_receipt, verifier_set)
}

fn get_matching_msg_and_tx_receipt() -> (EVMAddress, TransactionReceipt, Message) {
fn matching_msg_and_tx_receipt() -> (EVMAddress, TransactionReceipt, Message) {
let tx_id = Hash::random();
let log_index = 1;
let gateway_address = EVMAddress::random();
Expand Down
8 changes: 4 additions & 4 deletions ampd/src/grpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod tests {
use crate::event_sub::MockEventSub;
use crate::grpc;
use crate::proto::{
Algorithm, BroadcastRequest, BroadcastResponse, GetKeyRequest, GetKeyResponse, SignRequest,
Algorithm, BroadcastRequest, BroadcastResponse, KeyRequest, KeyResponse, SignRequest,
SignResponse, SubscribeRequest,
};
use crate::queue::queued_broadcaster::MockBroadcasterClient;
Expand Down Expand Up @@ -80,7 +80,7 @@ mod tests {
}

#[test]
async fn get_key_should_work() {
async fn key_should_work() {
let key_id = "key_id";
let key: PublicKey = SigningKey::random(&mut OsRng).verifying_key().into();
let algorithm = Algorithm::Ed25519;
Expand All @@ -105,14 +105,14 @@ mod tests {
.await
.unwrap()
.crypto
.get_key(GetKeyRequest {
.key(KeyRequest {
key_id: key_id.to_string(),
algorithm: algorithm.into(),
})
.await
.unwrap()
.into_inner(),
GetKeyResponse {
KeyResponse {
pub_key: key.to_bytes()
}
);
Expand Down
26 changes: 15 additions & 11 deletions ampd/src/grpc/server/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ where
Ok(Response::new(proto::SignResponse { signature }))
}

async fn get_key(
async fn key(
&self,
req: Request<proto::GetKeyRequest>,
) -> Result<Response<proto::GetKeyResponse>, Status> {
req: Request<proto::KeyRequest>,
) -> Result<Response<proto::KeyResponse>, Status> {
let req = req.into_inner();

let algorithm = proto::Algorithm::from_i32(req.algorithm)
.ok_or(Status::invalid_argument("invalid algorithm"))?;
let key = self.key(&req.key_id, algorithm).await?;

Ok(Response::new(proto::GetKeyResponse {
Ok(Response::new(proto::KeyResponse {
pub_key: key.to_bytes(),
}))
}
Expand All @@ -92,9 +92,10 @@ mod tests {
use tokio::test;
use tonic::Code;

use super::proto::crypto_server::Crypto;
use super::proto::{self};
use super::Server;
use crate::proto::crypto_server;
use crate::proto::crypto_server::Crypto;
use crate::tofnd;
use crate::tofnd::grpc::MockMultisig;
use crate::types::PublicKey;
Expand Down Expand Up @@ -158,7 +159,7 @@ mod tests {
}

#[test]
async fn get_key_should_return_correct_key() {
async fn key_should_return_correct_key() {
let key_id = "key_id";
let algorithm = proto::Algorithm::Ecdsa;
let key: PublicKey = SigningKey::random(&mut OsRng).verifying_key().into();
Expand All @@ -173,27 +174,30 @@ mod tests {
.return_once(move |_, _| Ok(key));
let server = Server::new(multisig_client);

let req = tonic::Request::new(proto::GetKeyRequest {
let req = tonic::Request::new(proto::KeyRequest {
key_id: key_id.to_string(),
algorithm: algorithm.into(),
});
let res = server.get_key(req).await.unwrap().into_inner();
let res = crypto_server::Crypto::key(&server, req)
.await
.unwrap()
.into_inner();

assert_eq!(res.pub_key, key.to_bytes());
}

#[test]
async fn get_key_should_return_error_when_algorithm_is_invalid() {
async fn key_should_return_error_when_algorithm_is_invalid() {
let key_id = "key_id";

let multisig_client = MockMultisig::default();
let server = Server::new(multisig_client);

let req = tonic::Request::new(proto::GetKeyRequest {
let req = tonic::Request::new(proto::KeyRequest {
key_id: key_id.to_string(),
algorithm: 2,
});
let res = server.get_key(req).await.unwrap_err();
let res = crypto_server::Crypto::key(&server, req).await.unwrap_err();

assert_eq!(res.code(), Code::InvalidArgument);
}
Expand Down
Loading

0 comments on commit 216f153

Please sign in to comment.