Skip to content

Commit

Permalink
Merge branch 'main' into feat/derive-into-event-macro
Browse files Browse the repository at this point in the history
  • Loading branch information
nbayindirli committed Jan 17, 2025
2 parents dd5fd56 + f9ec5a6 commit 99e618f
Show file tree
Hide file tree
Showing 30 changed files with 458 additions and 264 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ alloy-sol-types = { version = "0.8.14", default-features = false, features = [
] }
goldie = "0.5.0"
hex = { version = "0.4" }
paste = "1.0"

[workspace.lints.clippy]
nursery = { level = "warn", priority = -1 }
Expand Down
1 change: 1 addition & 0 deletions contracts/axelar-gas-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ soroban-sdk = { workspace = true }
stellar-axelar-std = { workspace = true }

[dev-dependencies]
paste = { workspace = true }
soroban-sdk = { workspace = true, features = ["testutils"] }
stellar-axelar-std = { workspace = true, features = ["testutils"] }

Expand Down
6 changes: 3 additions & 3 deletions contracts/axelar-gas-service/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use soroban_sdk::{bytes, Address, Bytes, Env, String, Symbol};
use stellar_axelar_gas_service::error::ContractError;
use stellar_axelar_gas_service::{AxelarGasService, AxelarGasServiceClient};
use stellar_axelar_std::types::Token;
use stellar_axelar_std::{assert_contract_err, assert_invoke_auth_err, assert_last_emitted_event};
use stellar_axelar_std::{assert_auth_err, assert_contract_err, assert_last_emitted_event};

fn setup_env<'a>() -> (Env, Address, Address, AxelarGasServiceClient<'a>) {
let env = Env::default();
Expand Down Expand Up @@ -301,7 +301,7 @@ fn fail_collect_fees_unauthorized() {

StellarAssetClient::new(&env, &token.address).mint(&contract_id, &supply);

assert_invoke_auth_err!(user, client.try_collect_fees(&user, &token));
assert_auth_err!(user, client.collect_fees(&user, &token));
}

#[test]
Expand Down Expand Up @@ -351,7 +351,7 @@ fn fail_refund_unauthorized() {
let message_id = message_id(&env);
let user: Address = Address::generate(&env);

assert_invoke_auth_err!(user, client.try_refund(&message_id, &receiver, &token));
assert_auth_err!(user, client.refund(&message_id, &receiver, &token));
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions contracts/axelar-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ed25519-dalek = { version = "^2.1" }
goldie = { workspace = true }
hex = "0.4"
hex-literal = "0.4"
paste = { workspace = true }
rand = { version = "0.8.5" }
soroban-sdk = { workspace = true, features = ["testutils"] }
stellar-axelar-gateway = { workspace = true, features = ["testutils"] }
Expand Down
14 changes: 7 additions & 7 deletions contracts/axelar-gateway/tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use stellar_axelar_gateway::error::ContractError;
use stellar_axelar_gateway::testutils::{generate_proof, generate_signers_set, randint};
use stellar_axelar_gateway::types::{ProofSignature, ProofSigner, WeightedSigner, WeightedSigners};
use stellar_axelar_gateway::AxelarGateway;
use stellar_axelar_std::{assert_contract_err, assert_invoke_auth_ok};
use stellar_axelar_std::{assert_auth, assert_contract_err};

mod utils;
use utils::setup_env;
Expand Down Expand Up @@ -285,9 +285,9 @@ fn rotate_signers_fail_duplicated_signers() {

let data_hash = new_signers.signers.signers_rotation_hash(&env);
let proof = generate_proof(&env, data_hash.clone(), signers);
assert_invoke_auth_ok!(
assert_auth!(
client.operator(),
client.try_rotate_signers(&new_signers.signers, &proof, &true)
client.rotate_signers(&new_signers.signers, &proof, &true)
);

let proof = generate_proof(&env, data_hash, new_signers);
Expand Down Expand Up @@ -315,9 +315,9 @@ fn rotate_signers_panics_on_outdated_signer_set() {
);
let data_hash = new_signers.signers.signers_rotation_hash(&env);
let proof = generate_proof(&env, data_hash, original_signers.clone());
assert_invoke_auth_ok!(
assert_auth!(
client.operator(),
client.try_rotate_signers(&new_signers.signers, &proof, &true)
client.rotate_signers(&new_signers.signers, &proof, &true)
);
}

Expand Down Expand Up @@ -350,9 +350,9 @@ fn multi_rotate_signers() {

let data_hash = new_signers.signers.signers_rotation_hash(&env);
let proof = generate_proof(&env, data_hash.clone(), original_signers.clone());
assert_invoke_auth_ok!(
assert_auth!(
client.operator(),
client.try_rotate_signers(&new_signers.signers, &proof, &true)
client.rotate_signers(&new_signers.signers, &proof, &true)
);

let proof = generate_proof(&env, msg_hash.clone(), new_signers.clone());
Expand Down
45 changes: 21 additions & 24 deletions contracts/axelar-gateway/tests/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use stellar_axelar_gateway::testutils::{
};
use stellar_axelar_gateway::types::Message;
use stellar_axelar_std::{
assert_contract_err, assert_invocation, assert_invoke_auth_err, assert_invoke_auth_ok, events,
assert_auth, assert_auth_err, assert_contract_err, assert_invocation, events,
};

mod utils;
Expand All @@ -29,9 +29,9 @@ fn call_contract() {
let destination_address = String::from_str(&env, DESTINATION_ADDRESS);
let payload = bytes!(&env, 0x1234);

assert_invoke_auth_ok!(
assert_auth!(
user,
client.try_call_contract(&user, &destination_chain, &destination_address, &payload)
client.call_contract(&user, &destination_chain, &destination_address, &payload)
);

assert_invocation(
Expand Down Expand Up @@ -62,9 +62,9 @@ fn validate_message() {

let prev_event_count = env.events().all().len();

let approved = assert_invoke_auth_ok!(
let approved = assert_auth!(
contract_address,
client.try_validate_message(
client.validate_message(
&contract_address,
&source_chain,
&message_id,
Expand Down Expand Up @@ -138,9 +138,9 @@ fn execute_approved_message() {
let proof = generate_proof(&env, data_hash, signers);
client.approve_messages(&messages, &proof);

let approved = assert_invoke_auth_ok!(
let approved = assert_auth!(
contract_address,
client.try_validate_message(
client.validate_message(
&contract_address,
&source_chain,
&message_id,
Expand Down Expand Up @@ -270,9 +270,9 @@ fn rotate_signers_bypass_rotation_delay() {
let proof = generate_proof(&env, data_hash, signers);
let bypass_rotation_delay = true;

assert_invoke_auth_ok!(
assert_auth!(
client.operator(),
client.try_rotate_signers(&new_signers.signers, &proof, &bypass_rotation_delay)
client.rotate_signers(&new_signers.signers, &proof, &bypass_rotation_delay)
);

goldie::assert!(events::fmt_last_emitted_event::<SignersRotatedEvent>(&env));
Expand All @@ -288,15 +288,15 @@ fn rotate_signers_bypass_rotation_delay_unauthorized() {
let proof = generate_proof(&env, data_hash, signers);
let bypass_rotation_delay = true;

assert_invoke_auth_err!(
assert_auth_err!(
client.owner(),
client.try_rotate_signers(&new_signers.signers, &proof, &bypass_rotation_delay)
client.rotate_signers(&new_signers.signers, &proof, &bypass_rotation_delay)
);

let not_operator = Address::generate(&env);
assert_invoke_auth_err!(
assert_auth_err!(
not_operator,
client.try_rotate_signers(&new_signers.signers, &proof, &bypass_rotation_delay)
client.rotate_signers(&new_signers.signers, &proof, &bypass_rotation_delay)
);
}

Expand Down Expand Up @@ -326,14 +326,11 @@ fn transfer_operatorship_unauthorized() {
let (env, _, client) = setup_env(1, randint(1, 10));
let not_operator = Address::generate(&env);

assert_invoke_auth_err!(
assert_auth_err!(
client.owner(),
client.try_transfer_operatorship(&client.owner())
);
assert_invoke_auth_err!(
not_operator,
client.try_transfer_operatorship(&not_operator)
client.transfer_operatorship(&client.owner())
);
assert_auth_err!(not_operator, client.transfer_operatorship(&not_operator));
}

#[test]
Expand All @@ -342,10 +339,10 @@ fn transfer_ownership_unauthorized() {

let new_owner = Address::generate(&env);

assert_invoke_auth_err!(new_owner, client.try_transfer_ownership(&new_owner));
assert_invoke_auth_err!(
assert_auth_err!(new_owner, client.transfer_ownership(&new_owner));
assert_auth_err!(
client.operator(),
client.try_transfer_ownership(&client.operator())
client.transfer_ownership(&client.operator())
);
}

Expand Down Expand Up @@ -434,6 +431,6 @@ fn upgrade_unauthorized() {
let not_owner = Address::generate(&env);
let new_wasm_hash = BytesN::<32>::from_array(&env, &[0; 32]);

assert_invoke_auth_err!(not_owner, client.try_upgrade(&new_wasm_hash));
assert_invoke_auth_err!(client.operator(), client.try_upgrade(&new_wasm_hash));
assert_auth_err!(not_owner, client.upgrade(&new_wasm_hash));
assert_auth_err!(client.operator(), client.upgrade(&new_wasm_hash));
}
1 change: 1 addition & 0 deletions contracts/axelar-operators/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ soroban-sdk = { workspace = true }
stellar-axelar-std = { workspace = true }

[dev-dependencies]
paste = { workspace = true }
soroban-sdk = { workspace = true, features = ["testutils"] }
stellar-axelar-std = { workspace = true, features = ["testutils"] }

Expand Down
6 changes: 3 additions & 3 deletions contracts/axelar-operators/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, Symbol, Va
use stellar_axelar_operators::error::ContractError;
use stellar_axelar_operators::{AxelarOperators, AxelarOperatorsClient};
use stellar_axelar_std::testutils::assert_invocation;
use stellar_axelar_std::{assert_contract_err, assert_invoke_auth_err, assert_last_emitted_event};
use stellar_axelar_std::{assert_auth_err, assert_contract_err, assert_last_emitted_event};

#[contract]
pub struct TestTarget;
Expand Down Expand Up @@ -197,9 +197,9 @@ fn fail_execute_when_target_panics() {
client.add_operator(&operator);

// call execute as an operator
assert_invoke_auth_err!(
assert_auth_err!(
operator,
client.try_execute(
client.execute(
&operator,
&target,
&symbol_short!("failing"),
Expand Down
1 change: 1 addition & 0 deletions contracts/interchain-token-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ stellar-interchain-token = { workspace = true, features = ["library"] }
[dev-dependencies]
goldie = { workspace = true }
hex = { workspace = true }
paste = { workspace = true }
soroban-sdk = { workspace = true, features = ["testutils", "alloc"] }
stellar-axelar-gas-service = { workspace = true, features = ["testutils"] }
stellar-axelar-gateway = { workspace = true, features = ["testutils"] }
Expand Down
Loading

0 comments on commit 99e618f

Please sign in to comment.