Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename Stellar assert auth macros for brevity #137

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -25,6 +25,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 @@ -17,6 +17,7 @@ soroban-sdk = { workspace = true }
[dev-dependencies]
axelar-soroban-std = { workspace = true, features = ["testutils"] }
soroban-sdk = { workspace = true, features = ["testutils"] }
paste = { workspace = true }

[lints]
workspace = true
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 @@ -6,7 +6,7 @@ use std::format;
use axelar_gas_service::error::ContractError;
use axelar_gas_service::{AxelarGasService, AxelarGasServiceClient};
use axelar_soroban_std::{
assert_contract_err, assert_invoke_auth_err, assert_last_emitted_event, types::Token,
assert_auth_err, assert_contract_err, assert_last_emitted_event, types::Token,
};
use soroban_sdk::Bytes;
use soroban_sdk::{
Expand Down Expand Up @@ -306,7 +306,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 @@ -356,7 +356,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 @@ -26,6 +26,7 @@ hex = "0.4"
hex-literal = "0.4"
rand = { version = "0.8.5" }
soroban-sdk = { workspace = true, features = ["testutils"] }
paste = { workspace = true }

[features]
library = [] # Only export the contract interface
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 @@ -2,7 +2,7 @@ use axelar_gateway::error::ContractError;
use axelar_gateway::testutils::{generate_proof, generate_signers_set, randint};
use axelar_gateway::types::{ProofSignature, ProofSigner, WeightedSigner, WeightedSigners};
use axelar_gateway::AxelarGateway;
use axelar_soroban_std::{assert_contract_err, assert_invoke_auth_ok};
use axelar_soroban_std::{assert_auth, assert_contract_err};
use soroban_sdk::{
testutils::{Address as _, BytesN as _},
Address, BytesN, Env, Vec,
Expand Down Expand Up @@ -287,9 +287,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 @@ -317,9 +317,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 @@ -352,9 +352,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 @@ -9,7 +9,7 @@ use axelar_gateway::testutils::{
};
use axelar_gateway::types::Message;
use axelar_soroban_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,
};
use soroban_sdk::{
bytes,
Expand All @@ -32,9 +32,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 @@ -65,9 +65,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 @@ -141,9 +141,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 @@ -273,9 +273,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 @@ -291,15 +291,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 @@ -329,14 +329,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 @@ -345,10 +342,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 @@ -437,6 +434,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 @@ -16,6 +16,7 @@ soroban-sdk = { workspace = true }
[dev-dependencies]
axelar-soroban-std = { workspace = true, features = ["testutils"] }
soroban-sdk = { workspace = true, features = ["testutils"] }
paste = { workspace = true }

[lints]
workspace = true
7 changes: 3 additions & 4 deletions contracts/axelar-operators/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ extern crate std;

use axelar_operators::error::ContractError;
use axelar_soroban_std::{
assert_contract_err, assert_invoke_auth_err, assert_last_emitted_event,
testutils::assert_invocation,
assert_auth_err, assert_contract_err, assert_last_emitted_event, testutils::assert_invocation,
};

use axelar_operators::{AxelarOperators, AxelarOperatorsClient};
Expand Down Expand Up @@ -201,9 +200,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
2 changes: 2 additions & 0 deletions contracts/interchain-token-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interchain-token = { workspace = true, features = ["library"] }
soroban-sdk = { workspace = true, features = ["alloc"] }
soroban-token-sdk = { workspace = true }


[dev-dependencies]
axelar-gas-service = { workspace = true, features = ["testutils"] }
axelar-gateway = { workspace = true, features = ["testutils"] }
Expand All @@ -29,6 +30,7 @@ hex = { workspace = true }
interchain-token = { workspace = true, features = ["testutils"] }
interchain-token-service = { workspace = true, features = ["testutils"] }
soroban-sdk = { workspace = true, features = ["testutils", "alloc"] }
paste = { workspace = true }

[features]
library = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod utils;

use axelar_soroban_std::address::AddressExt;
use axelar_soroban_std::assert_auth_err;
use axelar_soroban_std::assert_contract_err;
use axelar_soroban_std::assert_invoke_auth_err;
use axelar_soroban_std::events;
use interchain_token::InterchainTokenClient;
use interchain_token_service::error::ContractError;
Expand Down Expand Up @@ -226,14 +226,8 @@ fn deploy_interchain_token_fails_with_invalid_auth() {

let initial_supply = 100;

assert_invoke_auth_err!(
assert_auth_err!(
user,
client.try_deploy_interchain_token(
&sender,
&salt,
&token_metadata,
&initial_supply,
&minter,
)
client.deploy_interchain_token(&sender, &salt, &token_metadata, &initial_supply, &minter,)
);
}
6 changes: 3 additions & 3 deletions contracts/interchain-token-service/tests/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod utils;
use axelar_gateway::testutils::{generate_proof, get_approve_hash};
use axelar_gateway::types::Message as GatewayMessage;
use axelar_soroban_std::traits::BytesExt;
use axelar_soroban_std::{assert_invoke_auth_err, events};
use axelar_soroban_std::{assert_auth_err, events};
use interchain_token_service::types::{HubMessage, InterchainTransfer, Message};
use soroban_sdk::token;
use soroban_sdk::xdr::ToXdr;
Expand Down Expand Up @@ -188,9 +188,9 @@ fn executable_fails_if_not_executed_from_its() {
let message_id = String::from_str(&env, "test");
let payload = Bytes::from_hex(&env, "dead");

assert_invoke_auth_err!(
assert_auth_err!(
Address::generate(&env),
executable_client.try_execute_with_interchain_token(
executable_client.execute_with_interchain_token(
&source_chain,
&message_id,
&source_address,
Expand Down
Loading
Loading