Skip to content

Commit

Permalink
run format
Browse files Browse the repository at this point in the history
  • Loading branch information
nbayindirli committed Jan 6, 2025
1 parent 56e7c45 commit 783a3c3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 65 deletions.
2 changes: 1 addition & 1 deletion contracts/axelar-gateway/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::ContractError;
use crate::types::{ProofSignature, ProofSigner, WeightedSigner};
use axelar_soroban_std::events::Event;
use axelar_soroban_std::ensure;
use axelar_soroban_std::events::Event;
use soroban_sdk::{crypto::Hash, Bytes, BytesN, Env, Vec};

use crate::event;
Expand Down
29 changes: 5 additions & 24 deletions contracts/axelar-gateway/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ impl Event for ContractCalledEvent {

impl Event for MessageApprovedEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "message_approved"),
self.message.clone(),
)
(Symbol::new(env, "message_approved"), self.message.clone())
}

fn data(&self, env: &Env) -> impl IntoVal<Env, Val> + Debug {
Expand All @@ -61,10 +58,7 @@ impl Event for MessageApprovedEvent {

impl Event for MessageExecutedEvent {
fn topics(&self, env: &Env) -> impl Topics + Debug {
(
Symbol::new(env, "message_executed"),
self.message.clone(),
)
(Symbol::new(env, "message_executed"), self.message.clone())
}

fn data(&self, env: &Env) -> impl IntoVal<Env, Val> + Debug {
Expand All @@ -89,7 +83,6 @@ impl Event for SignersRotatedEvent {
#[cfg(any(test, feature = "testutils"))]
use axelar_soroban_std::impl_event_testutils;


#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
ContractCalledEvent,
Expand All @@ -98,22 +91,10 @@ impl_event_testutils!(
);

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
MessageApprovedEvent,
(Symbol, Message),
()
);
impl_event_testutils!(MessageApprovedEvent, (Symbol, Message), ());

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
MessageExecutedEvent,
(Symbol, Message),
()
);
impl_event_testutils!(MessageExecutedEvent, (Symbol, Message), ());

#[cfg(any(test, feature = "testutils"))]
impl_event_testutils!(
SignersRotatedEvent,
(Symbol, u64, BytesN<32>),
()
);
impl_event_testutils!(SignersRotatedEvent, (Symbol, u64, BytesN<32>), ());
19 changes: 11 additions & 8 deletions contracts/axelar-gateway/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,19 @@ pub fn randint(a: u32, b: u32) -> u32 {
rand::thread_rng().gen_range(a..b)
}

pub fn generate_signers_set(env: &Env, num_signers: u32, domain_separator: BytesN<32>) -> TestSignerSet {
pub fn generate_signers_set(
env: &Env,
num_signers: u32,
domain_separator: BytesN<32>,
) -> TestSignerSet {
generate_signers_set_with_randomness(env, num_signers, domain_separator, true)
}

pub fn generate_deterministic_signers_set(env: &Env, num_signers: u32, domain_separator: BytesN<32>) -> TestSignerSet {
pub fn generate_deterministic_signers_set(
env: &Env,
num_signers: u32,
domain_separator: BytesN<32>,
) -> TestSignerSet {
generate_signers_set_with_randomness(env, num_signers, domain_separator, false)
}

Expand Down Expand Up @@ -239,12 +247,7 @@ pub fn rotate_to_new_signers<'a>(
num_signers: u32,
use_rng: bool,
) -> TestSignerSet {
let (new_signers, proof) = generate_new_signers(
env,
signers,
num_signers,
use_rng,
);
let (new_signers, proof) = generate_new_signers(env, signers, num_signers, use_rng);

client.rotate_signers(&new_signers.signers, &proof, &bypass_rotation_delay);
new_signers
Expand Down
41 changes: 9 additions & 32 deletions contracts/axelar-gateway/tests/gateway.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use axelar_gateway::error::ContractError;
use axelar_gateway::event::{
ContractCalledEvent, MessageApprovedEvent, MessageExecutedEvent, SignersRotatedEvent,
};
#[cfg(any(test, feature = "testutils"))]
use axelar_gateway::testutils::{
generate_deterministic_test_message, generate_new_signers, generate_proof, generate_signers_set, generate_test_message, get_approve_hash, randint, rotate_to_new_signers
generate_deterministic_test_message, generate_new_signers, generate_proof,
generate_signers_set, generate_test_message, get_approve_hash, randint, rotate_to_new_signers,
};
use axelar_gateway::types::Message;
use axelar_gateway::event::{
ContractCalledEvent, MessageApprovedEvent, MessageExecutedEvent, SignersRotatedEvent
};
use axelar_soroban_std::{
assert_contract_err, assert_invocation, assert_invoke_auth_err, assert_invoke_auth_ok, events,
};
Expand Down Expand Up @@ -222,29 +223,15 @@ fn approve_messages_skip_duplicate_message() {
#[test]
fn rotate_signers() {
let (env, signers, client) = setup_env(1, 5);
rotate_to_new_signers(
&env,
signers,
&client,
false,
5,
false
);
rotate_to_new_signers(&env, signers, &client, false, 5, false);

goldie::assert!(events::fmt_last_emitted_event::<SignersRotatedEvent>(&env));
}

#[test]
fn approve_messages_after_rotation() {
let (env, signers, client) = setup_env(1, 5);
let new_signers = rotate_to_new_signers(
&env,
signers,
&client,
false,
5,
false
);
let new_signers = rotate_to_new_signers(&env, signers, &client, false, 5, false);

let (message, _) = generate_deterministic_test_message(&env);
let messages = vec![&env, message.clone()];
Expand All @@ -258,12 +245,7 @@ fn approve_messages_after_rotation() {
#[test]
fn rotate_signers_bypass_rotation_delay() {
let (env, signers, client) = setup_env(1, 5);
let (new_signers, proof) = generate_new_signers(
&env,
signers,
5,
false,
);
let (new_signers, proof) = generate_new_signers(&env, signers, 5, false);
let bypass_rotation_delay = true;

assert_invoke_auth_ok!(
Expand All @@ -277,12 +259,7 @@ fn rotate_signers_bypass_rotation_delay() {
#[test]
fn rotate_signers_bypass_rotation_delay_unauthorized() {
let (env, signers, client) = setup_env(1, 5);
let (new_signers, proof) = generate_new_signers(
&env,
signers,
5,
true,
);
let (new_signers, proof) = generate_new_signers(&env, signers, 5, true);
let bypass_rotation_delay = true;

assert_invoke_auth_err!(
Expand Down

0 comments on commit 783a3c3

Please sign in to comment.