diff --git a/Cargo.lock b/Cargo.lock index 73ebda23..99aea59f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,6 +371,7 @@ version = "0.1.0" dependencies = [ "axelar-soroban-std", "cfg-if", + "paste", "soroban-sdk", ] @@ -385,6 +386,7 @@ dependencies = [ "goldie", "hex", "hex-literal", + "paste", "rand", "rand_chacha", "soroban-sdk", @@ -395,6 +397,7 @@ name = "axelar-operators" version = "0.1.0" dependencies = [ "axelar-soroban-std", + "paste", "soroban-sdk", ] @@ -405,6 +408,7 @@ dependencies = [ "axelar-soroban-std-derive", "goldie", "hex", + "paste", "soroban-sdk", "soroban-token-sdk", ] @@ -414,6 +418,7 @@ name = "axelar-soroban-std-derive" version = "0.1.0" dependencies = [ "axelar-soroban-std", + "paste", "proc-macro2", "quote", "soroban-sdk", @@ -1159,6 +1164,7 @@ version = "0.1.0" dependencies = [ "axelar-soroban-std", "cfg-if", + "paste", "soroban-sdk", "soroban-token-sdk", ] @@ -1177,6 +1183,7 @@ dependencies = [ "hex", "interchain-token", "interchain-token-service", + "paste", "soroban-sdk", "soroban-token-sdk", ] diff --git a/Cargo.toml b/Cargo.toml index ff5bba0a..ab2c0fe8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/contracts/axelar-gas-service/Cargo.toml b/contracts/axelar-gas-service/Cargo.toml index 0e5c055c..a4cb2334 100644 --- a/contracts/axelar-gas-service/Cargo.toml +++ b/contracts/axelar-gas-service/Cargo.toml @@ -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 diff --git a/contracts/axelar-gas-service/tests/test.rs b/contracts/axelar-gas-service/tests/test.rs index 4f323787..091cdadb 100644 --- a/contracts/axelar-gas-service/tests/test.rs +++ b/contracts/axelar-gas-service/tests/test.rs @@ -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::{ @@ -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] @@ -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] diff --git a/contracts/axelar-gateway/Cargo.toml b/contracts/axelar-gateway/Cargo.toml index 2778f762..d930380f 100644 --- a/contracts/axelar-gateway/Cargo.toml +++ b/contracts/axelar-gateway/Cargo.toml @@ -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 diff --git a/contracts/axelar-gateway/tests/auth.rs b/contracts/axelar-gateway/tests/auth.rs index 4ac8bb72..b853ff05 100644 --- a/contracts/axelar-gateway/tests/auth.rs +++ b/contracts/axelar-gateway/tests/auth.rs @@ -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, @@ -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); @@ -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) ); } @@ -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()); diff --git a/contracts/axelar-gateway/tests/gateway.rs b/contracts/axelar-gateway/tests/gateway.rs index 29d071d9..eeb1225b 100644 --- a/contracts/axelar-gateway/tests/gateway.rs +++ b/contracts/axelar-gateway/tests/gateway.rs @@ -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, @@ -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( @@ -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, @@ -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, @@ -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::(&env)); @@ -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) ); } @@ -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(¬_operator) + client.transfer_operatorship(&client.owner()) ); + assert_auth_err!(not_operator, client.transfer_operatorship(¬_operator)); } #[test] @@ -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()) ); } @@ -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)); } diff --git a/contracts/axelar-operators/Cargo.toml b/contracts/axelar-operators/Cargo.toml index 059f19c9..c97878ab 100644 --- a/contracts/axelar-operators/Cargo.toml +++ b/contracts/axelar-operators/Cargo.toml @@ -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 diff --git a/contracts/axelar-operators/tests/test.rs b/contracts/axelar-operators/tests/test.rs index 5636fd7c..dfed965a 100644 --- a/contracts/axelar-operators/tests/test.rs +++ b/contracts/axelar-operators/tests/test.rs @@ -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}; @@ -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"), diff --git a/contracts/interchain-token-service/Cargo.toml b/contracts/interchain-token-service/Cargo.toml index 8b64e025..9660ae19 100644 --- a/contracts/interchain-token-service/Cargo.toml +++ b/contracts/interchain-token-service/Cargo.toml @@ -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"] } @@ -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 = [] diff --git a/contracts/interchain-token-service/tests/deploy_interchain_token.rs b/contracts/interchain-token-service/tests/deploy_interchain_token.rs index 9155b6c1..e77c6c50 100644 --- a/contracts/interchain-token-service/tests/deploy_interchain_token.rs +++ b/contracts/interchain-token-service/tests/deploy_interchain_token.rs @@ -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; @@ -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,) ); } diff --git a/contracts/interchain-token-service/tests/executable.rs b/contracts/interchain-token-service/tests/executable.rs index a676c235..4d8a34f5 100644 --- a/contracts/interchain-token-service/tests/executable.rs +++ b/contracts/interchain-token-service/tests/executable.rs @@ -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; @@ -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, diff --git a/contracts/interchain-token-service/tests/trusted_chain.rs b/contracts/interchain-token-service/tests/trusted_chain.rs index 6faf8939..f248202d 100644 --- a/contracts/interchain-token-service/tests/trusted_chain.rs +++ b/contracts/interchain-token-service/tests/trusted_chain.rs @@ -3,9 +3,7 @@ mod utils; use interchain_token_service::event::{TrustedChainRemovedEvent, TrustedChainSetEvent}; use utils::setup_env; -use axelar_soroban_std::{ - assert_contract_err, assert_invoke_auth_err, assert_invoke_auth_ok, events, -}; +use axelar_soroban_std::{assert_auth, assert_auth_err, assert_contract_err, events}; use interchain_token_service::error::ContractError; use soroban_sdk::testutils::Address as _; use soroban_sdk::{Address, String}; @@ -16,7 +14,7 @@ fn set_trusted_address() { let chain = String::from_str(&env, "chain"); - assert_invoke_auth_ok!(client.owner(), client.try_set_trusted_chain(&chain)); + assert_auth!(client.owner(), client.set_trusted_chain(&chain)); goldie::assert!(events::fmt_last_emitted_event::(&env)); @@ -30,7 +28,7 @@ fn set_trusted_chain_fails_if_not_owner() { let not_owner = Address::generate(&env); let chain = String::from_str(&env, "chain"); - assert_invoke_auth_err!(not_owner, client.try_set_trusted_chain(&chain)); + assert_auth_err!(not_owner, client.set_trusted_chain(&chain)); } #[test] @@ -53,9 +51,9 @@ fn remove_trusted_chain() { let chain = String::from_str(&env, "chain"); - assert_invoke_auth_ok!(client.owner(), client.try_set_trusted_chain(&chain)); + assert_auth!(client.owner(), client.set_trusted_chain(&chain)); - assert_invoke_auth_ok!(client.owner(), client.try_remove_trusted_chain(&chain)); + assert_auth!(client.owner(), client.remove_trusted_chain(&chain)); goldie::assert!(events::fmt_last_emitted_event::( &env diff --git a/contracts/interchain-token/Cargo.toml b/contracts/interchain-token/Cargo.toml index 88f692fc..8e2431de 100644 --- a/contracts/interchain-token/Cargo.toml +++ b/contracts/interchain-token/Cargo.toml @@ -18,6 +18,7 @@ soroban-token-sdk = { workspace = true } [dev-dependencies] axelar-soroban-std = { workspace = true, features = ["testutils"] } soroban-sdk = { workspace = true, features = ["testutils"] } +paste = { workspace = true } [features] library = [] # Only export the contract interface diff --git a/contracts/interchain-token/tests/test.rs b/contracts/interchain-token/tests/test.rs index 8f05dce2..f594f906 100644 --- a/contracts/interchain-token/tests/test.rs +++ b/contracts/interchain-token/tests/test.rs @@ -1,9 +1,7 @@ #![cfg(test)] extern crate std; -use axelar_soroban_std::{ - assert_invoke_auth_err, assert_invoke_auth_ok, assert_last_emitted_event, -}; +use axelar_soroban_std::{assert_auth, assert_auth_err, assert_last_emitted_event}; use interchain_token::{InterchainToken, InterchainTokenClient}; use soroban_sdk::{ @@ -111,7 +109,7 @@ fn transfer_ownership_from_non_owner() { let (token, _owner, _minter) = setup_token(&env); - assert_invoke_auth_err!(user, token.try_transfer_ownership(&new_owner)); + assert_auth_err!(user, token.transfer_ownership(&new_owner)); } #[test] @@ -123,7 +121,7 @@ fn transfer_ownership() { assert_eq!(token.owner(), owner); - assert_invoke_auth_ok!(owner, token.try_transfer_ownership(&new_owner)); + assert_auth!(owner, token.transfer_ownership(&new_owner)); assert_eq!(token.owner(), new_owner); } @@ -168,10 +166,10 @@ fn transfer() { let (token, _owner, minter) = setup_token(&env); - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user1, &amount)); + assert_auth!(minter, token.mint_from(&minter, &user1, &amount)); assert_eq!(token.balance(&user1), amount); - assert_invoke_auth_ok!(user1, token.try_transfer(&user1, &user2, &600_i128)); + assert_auth!(user1, token.transfer(&user1, &user2, &600_i128)); assert_eq!(token.balance(&user1), 400_i128); assert_eq!(token.balance(&user2), 600_i128); } @@ -189,14 +187,14 @@ fn fail_transfer_from_with_negative_amount() { let (token, _owner, minter) = setup_token(&env); - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user1, &1000_i128)); + assert_auth!(minter, token.mint_from(&minter, &user1, &1000_i128)); assert_eq!(token.balance(&user1), 1000_i128); let expiration_ledger = 200; - assert_invoke_auth_ok!( + assert_auth!( user1, - token.try_approve(&user1, &user2, &500_i128, &expiration_ledger) + token.approve(&user1, &user2, &500_i128, &expiration_ledger) ); assert_eq!(token.allowance(&user1, &user2), 500_i128); @@ -215,7 +213,7 @@ fn fail_transfer_from_without_approval() { let (token, _owner, minter) = setup_token(&env); - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user1, &1000_i128)); + assert_auth!(minter, token.mint_from(&minter, &user1, &1000_i128)); assert_eq!(token.balance(&user1), 1000_i128); token.transfer_from(&user2, &user1, &user3, &400_i128); @@ -233,14 +231,14 @@ fn fail_transfer_from_with_insufficient_allowance() { let (token, _owner, minter) = setup_token(&env); - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user1, &1000_i128)); + assert_auth!(minter, token.mint_from(&minter, &user1, &1000_i128)); assert_eq!(token.balance(&user1), 1000_i128); let expiration_ledger = 200; - assert_invoke_auth_ok!( + assert_auth!( user1, - token.try_approve(&user1, &user2, &100_i128, &expiration_ledger) + token.approve(&user1, &user2, &100_i128, &expiration_ledger) ); assert_eq!(token.allowance(&user1, &user2), 100_i128); @@ -257,20 +255,20 @@ fn transfer_from() { let (token, _owner, minter) = setup_token(&env); - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user1, &1000_i128)); + assert_auth!(minter, token.mint_from(&minter, &user1, &1000_i128)); assert_eq!(token.balance(&user1), 1000_i128); let expiration_ledger = 200; - assert_invoke_auth_ok!( + assert_auth!( user1, - token.try_approve(&user1, &user2, &500_i128, &expiration_ledger) + token.approve(&user1, &user2, &500_i128, &expiration_ledger) ); assert_eq!(token.allowance(&user1, &user2), 500_i128); - assert_invoke_auth_ok!( + assert_auth!( user2, - token.try_transfer_from(&user2, &user1, &user3, &400_i128) + token.transfer_from(&user2, &user1, &user3, &400_i128) ); assert_eq!(token.balance(&user1), 600_i128); assert_eq!(token.balance(&user2), 0_i128); @@ -287,9 +285,9 @@ fn fail_mint_from_invalid_minter() { let (token, owner, minter) = setup_token(&env); - assert_invoke_auth_err!(owner, token.try_mint_from(&minter, &user, &amount)); - assert_invoke_auth_err!(user, token.try_mint_from(&minter, &user, &amount)); - assert_invoke_auth_err!(user, token.try_mint(&user, &amount)); + assert_auth_err!(owner, token.mint_from(&minter, &user, &amount)); + assert_auth_err!(user, token.mint_from(&minter, &user, &amount)); + assert_auth_err!(user, token.mint(&user, &amount)); } #[test] @@ -301,10 +299,10 @@ fn mint_from_minter_succeeds() { let (token, owner, minter) = setup_token(&env); - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user, &amount)); + assert_auth!(minter, token.mint_from(&minter, &user, &amount)); assert_eq!(token.balance(&user), amount); - assert_invoke_auth_ok!(owner, token.try_mint(&user, &amount)); + assert_auth!(owner, token.mint(&user, &amount)); assert_eq!(token.balance(&user), amount * 2); } @@ -317,7 +315,7 @@ fn fail_add_minter_from_non_owner() { let (token, _owner, _minter1) = setup_token(&env); - assert_invoke_auth_err!(user, token.try_add_minter(&minter2)); + assert_auth_err!(user, token.add_minter(&minter2)); } #[test] @@ -330,7 +328,7 @@ fn add_minter_succeeds() { let (token, owner, _minter1) = setup_token(&env); - assert_invoke_auth_ok!(owner, token.try_add_minter(&minter2)); + assert_auth!(owner, token.add_minter(&minter2)); assert_last_emitted_event( &env, @@ -339,7 +337,7 @@ fn add_minter_succeeds() { (), ); - assert_invoke_auth_ok!(minter2, token.try_mint_from(&minter2, &user, &amount)); + assert_auth!(minter2, token.mint_from(&minter2, &user, &amount)); assert_eq!(token.balance(&user), amount); } @@ -352,7 +350,7 @@ fn fail_remove_minter_from_non_owner() { let (token, _owner, _minter) = setup_token(&env); - assert_invoke_auth_err!(user, token.try_remove_minter(&minter1)); + assert_auth_err!(user, token.remove_minter(&minter1)); } #[test] @@ -365,7 +363,7 @@ fn remove_minter() { let (token, owner, _minter) = setup_token(&env); - assert_invoke_auth_ok!(owner, token.try_remove_minter(&minter1)); + assert_auth!(owner, token.remove_minter(&minter1)); assert_last_emitted_event( &env, @@ -374,7 +372,7 @@ fn remove_minter() { (), ); - assert_invoke_auth_err!(minter1, token.try_mint_from(&minter1, &user, &amount)); + assert_auth_err!(minter1, token.mint_from(&minter1, &user, &amount)); } #[test] @@ -388,7 +386,7 @@ fn fail_burn_with_negative_amount() { let (token, _owner, minter) = setup_token(&env); let amount = 1000; - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user, &amount)); + assert_auth!(minter, token.mint_from(&minter, &user, &amount)); assert_eq!(token.balance(&user), amount); let burn_amount = -1; @@ -407,7 +405,7 @@ fn fail_burn_with_insufficient_balance() { let (token, _owner, minter) = setup_token(&env); let amount = 1000; - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user, &amount)); + assert_auth!(minter, token.mint_from(&minter, &user, &amount)); assert_eq!(token.balance(&user), amount); let burn_amount = 2000; @@ -424,10 +422,10 @@ fn burn_succeeds() { let (token, _owner, minter) = setup_token(&env); let amount = 1000; - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user, &amount)); + assert_auth!(minter, token.mint_from(&minter, &user, &amount)); assert_eq!(token.balance(&user), amount); - assert_invoke_auth_ok!(user, token.try_burn(&user, &amount)); + assert_auth!(user, token.burn(&user, &amount)); assert_eq!(token.balance(&user), 0); } @@ -457,7 +455,7 @@ fn fail_burn_from_without_approval() { let (token, _owner, minter) = setup_token(&env); let amount = 1000; - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user1, &amount)); + assert_auth!(minter, token.mint_from(&minter, &user1, &amount)); assert_eq!(token.balance(&user1), amount); let burn_amount = 500; @@ -474,19 +472,19 @@ fn burn_from_succeeds() { let (token, _owner, minter) = setup_token(&env); let amount = 1000; - assert_invoke_auth_ok!(minter, token.try_mint_from(&minter, &user1, &amount)); + assert_auth!(minter, token.mint_from(&minter, &user1, &amount)); assert_eq!(token.balance(&user1), amount); let expiration_ledger = 200; let burn_amount = 100; - assert_invoke_auth_ok!( + assert_auth!( user1, - token.try_approve(&user1, &user2, &burn_amount, &expiration_ledger) + token.approve(&user1, &user2, &burn_amount, &expiration_ledger) ); assert_eq!(token.allowance(&user1, &user2), burn_amount); - assert_invoke_auth_ok!(user2, token.try_burn_from(&user2, &user1, &burn_amount)); + assert_auth!(user2, token.burn_from(&user2, &user1, &burn_amount)); assert_eq!(token.allowance(&user1, &user2), 0); assert_eq!(token.balance(&user1), (amount - burn_amount)); assert_eq!(token.balance(&user2), 0); diff --git a/packages/axelar-soroban-std-derive/Cargo.toml b/packages/axelar-soroban-std-derive/Cargo.toml index 819104ea..cc4c857c 100644 --- a/packages/axelar-soroban-std-derive/Cargo.toml +++ b/packages/axelar-soroban-std-derive/Cargo.toml @@ -15,9 +15,11 @@ quote = "1.0" soroban-sdk = { workspace = true } syn = { version = "2.0", features = ["full"] } + [dev-dependencies] axelar-soroban-std = { workspace = true } soroban-sdk = { workspace = true, features = ["testutils"] } +paste = { workspace = true } [lints] workspace = true diff --git a/packages/axelar-soroban-std-derive/tests/test.rs b/packages/axelar-soroban-std-derive/tests/test.rs index b59a6d43..e69752ed 100644 --- a/packages/axelar-soroban-std-derive/tests/test.rs +++ b/packages/axelar-soroban-std-derive/tests/test.rs @@ -2,7 +2,7 @@ use soroban_sdk::{contract, contracterror, contractimpl, testutils::Address as _ mod testdata; mod operatable { - use axelar_soroban_std::{assert_invoke_auth_ok, interfaces::OperatableClient}; + use axelar_soroban_std::{assert_auth, interfaces::OperatableClient}; use axelar_soroban_std_derive::Operatable; use super::*; @@ -34,13 +34,13 @@ mod operatable { assert_eq!(operator, client.operator()); let new_operator = Address::generate(&env); - assert_invoke_auth_ok!(operator, client.try_transfer_operatorship(&new_operator)); + assert_auth!(operator, client.transfer_operatorship(&new_operator)); assert_eq!(new_operator, client.operator()); } } mod ownable { - use axelar_soroban_std::{assert_invoke_auth_ok, interfaces::OwnableClient}; + use axelar_soroban_std::{assert_auth, interfaces::OwnableClient}; use axelar_soroban_std_derive::Ownable; use super::*; @@ -72,13 +72,13 @@ mod ownable { assert_eq!(owner, client.owner()); let new_owner = Address::generate(&env); - assert_invoke_auth_ok!(owner, client.try_transfer_ownership(&new_owner)); + assert_auth!(owner, client.transfer_ownership(&new_owner)); assert_eq!(new_owner, client.owner()); } } mod upgradable { - use axelar_soroban_std::assert_invoke_auth_ok; + use axelar_soroban_std::assert_auth; use axelar_soroban_std_derive::{Ownable, Upgradable}; use super::*; @@ -125,9 +125,9 @@ mod upgradable { let client = ContractClient::new(env, &contract_id); let new_wasm_hash = env.deployer().upload_contract_wasm(UPGRADED_WASM); - assert_invoke_auth_ok!(owner, client.try_upgrade(&new_wasm_hash)); + assert_auth!(owner, client.upgrade(&new_wasm_hash)); let client = testdata::ContractClient::new(env, &contract_id); - assert_invoke_auth_ok!(owner, client.try_migrate(&())); + assert_auth!(owner, client.migrate(&())); } } diff --git a/packages/axelar-soroban-std/Cargo.toml b/packages/axelar-soroban-std/Cargo.toml index 9f80c7c9..19f6d8e0 100644 --- a/packages/axelar-soroban-std/Cargo.toml +++ b/packages/axelar-soroban-std/Cargo.toml @@ -19,6 +19,7 @@ soroban-token-sdk = { workspace = true } axelar-soroban-std-derive = { workspace = true } goldie = { workspace = true } soroban-sdk = { workspace = true, features = ["testutils"] } +paste = { workspace = true } [features] testutils = ["soroban-sdk/testutils", "hex"] diff --git a/packages/axelar-soroban-std/src/error.rs b/packages/axelar-soroban-std/src/error.rs index 23cb45b5..062b9ab7 100644 --- a/packages/axelar-soroban-std/src/error.rs +++ b/packages/axelar-soroban-std/src/error.rs @@ -106,13 +106,15 @@ macro_rules! assert_some { } #[macro_export] -macro_rules! assert_invoke_auth_ok { +macro_rules! assert_auth { ($caller:expr, $client:ident . $method:ident ( $($arg:expr),* $(,)? )) => {{ use soroban_sdk::IntoVal; - let call_result = $client - .mock_auths($crate::mock_auth!($caller, $client, $method, $($arg),*)) - .$method($($arg),*); + paste::paste! { + let call_result = $client + .mock_auths($crate::mock_auth!($caller, $client, $method, $($arg),*)) + .[]($($arg),*); + } match call_result { Ok(outer) => { @@ -127,14 +129,15 @@ macro_rules! assert_invoke_auth_ok { } #[macro_export] -macro_rules! assert_invoke_auth_err { +macro_rules! assert_auth_err { ($caller:expr, $client:ident . $method:ident ( $($arg:expr),* $(,)? )) => {{ use soroban_sdk::{IntoVal, xdr::{ScError, ScErrorCode, ScVal}}; + paste::paste! { let call_result = $client .mock_auths($crate::mock_auth!($caller, $client, $method, $($arg),*)) - .$method($($arg),*); - + .[]($($arg),*); + } match call_result { Err(_) => { let val = ScVal::Error(ScError::Context(ScErrorCode::InvalidAction)); diff --git a/packages/axelar-soroban-std/src/interfaces/operatable.rs b/packages/axelar-soroban-std/src/interfaces/operatable.rs index 906d8085..9148c030 100644 --- a/packages/axelar-soroban-std/src/interfaces/operatable.rs +++ b/packages/axelar-soroban-std/src/interfaces/operatable.rs @@ -71,7 +71,7 @@ impl_event_testutils!(OperatorshipTransferredEvent, (Symbol, Address, Address), mod test { use crate::interfaces::testdata::Contract; use crate::interfaces::{OperatableClient, OperatorshipTransferredEvent}; - use crate::{assert_invoke_auth_err, assert_invoke_auth_ok, events}; + use crate::{assert_auth, assert_auth_err, events}; use soroban_sdk::testutils::Address as _; use soroban_sdk::{Address, Env}; @@ -105,10 +105,7 @@ mod test { let client = prepare_client(&env, Some(operator)); let new_operator = Address::generate(&env); - assert_invoke_auth_err!( - new_operator, - client.try_transfer_operatorship(&new_operator) - ); + assert_auth_err!(new_operator, client.transfer_operatorship(&new_operator)); } #[test] @@ -120,7 +117,7 @@ mod test { assert_eq!(client.operator(), operator); let new_operator = Address::generate(&env); - assert_invoke_auth_ok!(operator, client.try_transfer_operatorship(&new_operator)); + assert_auth!(operator, client.transfer_operatorship(&new_operator)); goldie::assert!(events::fmt_last_emitted_event::(&env)); diff --git a/packages/axelar-soroban-std/src/interfaces/ownable.rs b/packages/axelar-soroban-std/src/interfaces/ownable.rs index 9cc4e4d8..bb29510c 100644 --- a/packages/axelar-soroban-std/src/interfaces/ownable.rs +++ b/packages/axelar-soroban-std/src/interfaces/ownable.rs @@ -71,7 +71,7 @@ impl_event_testutils!(OwnershipTransferredEvent, (Symbol, Address, Address), ()) mod test { use crate::interfaces::testdata::Contract; use crate::interfaces::{OwnableClient, OwnershipTransferredEvent}; - use crate::{assert_invoke_auth_err, assert_invoke_auth_ok, events}; + use crate::{assert_auth, assert_auth_err, events}; use soroban_sdk::testutils::Address as _; use soroban_sdk::{Address, Env}; @@ -105,7 +105,7 @@ mod test { let client = prepare_client(&env, Some(owner)); let new_owner = Address::generate(&env); - assert_invoke_auth_err!(new_owner, client.try_transfer_ownership(&new_owner)); + assert_auth_err!(new_owner, client.transfer_ownership(&new_owner)); } #[test] @@ -117,7 +117,7 @@ mod test { assert_eq!(client.owner(), owner); let new_owner = Address::generate(&env); - assert_invoke_auth_ok!(owner, client.try_transfer_ownership(&new_owner)); + assert_auth!(owner, client.transfer_ownership(&new_owner)); goldie::assert!(events::fmt_last_emitted_event::( &env diff --git a/packages/axelar-soroban-std/src/interfaces/upgradable.rs b/packages/axelar-soroban-std/src/interfaces/upgradable.rs index 8146c8f7..1d6e095a 100644 --- a/packages/axelar-soroban-std/src/interfaces/upgradable.rs +++ b/packages/axelar-soroban-std/src/interfaces/upgradable.rs @@ -107,7 +107,7 @@ pub enum MigrationError { #[cfg(test)] mod test { use crate::interfaces::upgradable::UpgradedEvent; - use crate::{assert_invoke_auth_err, assert_invoke_auth_ok, events}; + use crate::{assert_auth, assert_auth_err, events}; use crate::interfaces::testdata::{ContractClient, ContractNonTrivialClient, MigrationData}; use crate::interfaces::{testdata, upgradable}; @@ -151,7 +151,7 @@ mod test { let owner = Address::generate(&env); let (client, hash) = prepare_client_and_bytecode(&env, Some(owner)); - assert_invoke_auth_err!(Address::generate(&env), client.try_upgrade(&hash)); + assert_auth_err!(Address::generate(&env), client.upgrade(&hash)); } #[test] @@ -160,7 +160,7 @@ mod test { let owner = Address::generate(&env); let (client, hash) = prepare_client_and_bytecode(&env, Some(owner.clone())); - assert_invoke_auth_ok!(owner, client.try_upgrade(&hash)); + assert_auth!(owner, client.upgrade(&hash)); } #[test] @@ -169,7 +169,7 @@ mod test { let owner = Address::generate(&env); let (client, hash) = prepare_client_and_bytecode(&env, Some(owner.clone())); - assert_invoke_auth_ok!(owner, client.try_upgrade(&hash)); + assert_auth!(owner, client.upgrade(&hash)); assert!(client.try_migrate(&()).is_err()); } @@ -179,8 +179,8 @@ mod test { let owner = Address::generate(&env); let (client, hash) = prepare_client_and_bytecode(&env, Some(owner.clone())); - assert_invoke_auth_ok!(owner, client.try_upgrade(&hash)); - assert_invoke_auth_err!(Address::generate(&env), client.try_migrate(&())); + assert_auth!(owner, client.upgrade(&hash)); + assert_auth_err!(Address::generate(&env), client.migrate(&())); } #[test] @@ -189,7 +189,7 @@ mod test { let owner = Address::generate(&env); let (client, _) = prepare_client_and_bytecode(&env, Some(owner.clone())); - assert_invoke_auth_err!(owner, client.try_migrate(&())); + assert_auth_err!(owner, client.migrate(&())); } #[test] @@ -198,11 +198,11 @@ mod test { let owner = Address::generate(&env); let (client, hash) = prepare_client_and_bytecode(&env, Some(owner.clone())); - assert_invoke_auth_ok!(owner, client.try_upgrade(&hash)); + assert_auth!(owner, client.upgrade(&hash)); assert!(client.migration_data().is_none()); - assert_invoke_auth_ok!(owner, client.try_migrate(&())); + assert_auth!(owner, client.migrate(&())); assert_eq!( client.migration_data(), @@ -221,7 +221,7 @@ mod test { let hash = env.deployer().upload_contract_wasm(WASM_NON_TRIVIAL); let client = ContractNonTrivialClient::new(&env, &contract_id); - assert_invoke_auth_ok!(owner, client.try_upgrade(&hash)); + assert_auth!(owner, client.upgrade(&hash)); assert!(client.migration_data().is_none()); @@ -231,7 +231,7 @@ mod test { data3: 42, }; - assert_invoke_auth_ok!(owner, client.try_migrate(&data)); + assert_auth!(owner, client.migrate(&data)); assert_eq!(client.migration_data(), Some(data.data1)); @@ -251,7 +251,7 @@ mod test { }); let client = ContractClient::new(&env, &contract_id); - assert_invoke_auth_ok!(owner, client.try_migrate(&())); + assert_auth!(owner, client.migrate(&())); } #[test] @@ -260,8 +260,8 @@ mod test { let owner = Address::generate(&env); let (client, hash) = prepare_client_and_bytecode(&env, Some(owner.clone())); - assert_invoke_auth_ok!(owner, client.try_upgrade(&hash)); - assert_invoke_auth_ok!(owner, client.try_migrate(&())); - assert_invoke_auth_err!(owner, client.try_migrate(&())); + assert_auth!(owner, client.upgrade(&hash)); + assert_auth!(owner, client.migrate(&())); + assert_auth_err!(owner, client.migrate(&())); } }