diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c58f77e4..a17ff863 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,3 +32,14 @@ jobs: run: RUSTFLAGS="-D warnings" cargo test --locked env: RUST_BACKTRACE: 1 + + - name: Remove all golden files + run: find . -name "*.golden" -exec rm -rf {} \; + + - name: Regenerate golden files + run: RUSTFLAGS="-D warnings" cargo test --locked + env: + GOLDIE_UPDATE: 1 + + - name: Check for stale golden files + run: git diff --exit-code diff --git a/contracts/stellar-axelar-gas-service/src/contract.rs b/contracts/stellar-axelar-gas-service/src/contract.rs index 688c3fd1..febf51ef 100644 --- a/contracts/stellar-axelar-gas-service/src/contract.rs +++ b/contracts/stellar-axelar-gas-service/src/contract.rs @@ -2,25 +2,22 @@ use soroban_sdk::{contract, contractimpl, token, Address, Bytes, Env, String}; use stellar_axelar_std::events::Event; use stellar_axelar_std::ttl::extend_instance_ttl; use stellar_axelar_std::types::Token; -use stellar_axelar_std::{ensure, interfaces, Ownable, Upgradable}; +use stellar_axelar_std::{ensure, interfaces, Operatable, Ownable, Upgradable}; use crate::error::ContractError; use crate::event::{GasAddedEvent, GasCollectedEvent, GasPaidEvent, GasRefundedEvent}; use crate::interface::AxelarGasServiceInterface; -use crate::storage_types::DataKey; #[contract] -#[derive(Ownable, Upgradable)] +#[derive(Operatable, Ownable, Upgradable)] pub struct AxelarGasService; #[contractimpl] impl AxelarGasService { /// Initialize the gas service contract with a gas_collector address. - pub fn __constructor(env: Env, owner: Address, gas_collector: Address) { + pub fn __constructor(env: Env, owner: Address, operator: Address) { + interfaces::set_operator(&env, &operator); interfaces::set_owner(&env, &owner); - env.storage() - .instance() - .set(&DataKey::GasCollector, &gas_collector); } } @@ -94,8 +91,7 @@ impl AxelarGasServiceInterface for AxelarGasService { } fn collect_fees(env: Env, receiver: Address, token: Token) -> Result<(), ContractError> { - let gas_collector = Self::gas_collector(&env); - gas_collector.require_auth(); + Self::operator(&env).require_auth(); ensure!(token.amount > 0, ContractError::InvalidAmount); @@ -117,7 +113,7 @@ impl AxelarGasServiceInterface for AxelarGasService { } fn refund(env: Env, message_id: String, receiver: Address, token: Token) { - Self::gas_collector(&env).require_auth(); + Self::operator(&env).require_auth(); token::Client::new(&env, &token.address).transfer( &env.current_contract_address(), @@ -132,11 +128,4 @@ impl AxelarGasServiceInterface for AxelarGasService { } .emit(&env); } - - fn gas_collector(env: &Env) -> Address { - env.storage() - .instance() - .get(&DataKey::GasCollector) - .expect("gas collector not found") - } } diff --git a/contracts/stellar-axelar-gas-service/src/interface.rs b/contracts/stellar-axelar-gas-service/src/interface.rs index 7e5f8ca2..4083d9f3 100644 --- a/contracts/stellar-axelar-gas-service/src/interface.rs +++ b/contracts/stellar-axelar-gas-service/src/interface.rs @@ -1,10 +1,11 @@ use soroban_sdk::{contractclient, Address, Bytes, Env, String}; +use stellar_axelar_std::interfaces::OperatableInterface; use stellar_axelar_std::types::Token; use crate::error::ContractError; #[contractclient(name = "AxelarGasServiceClient")] -pub trait AxelarGasServiceInterface { +pub trait AxelarGasServiceInterface: OperatableInterface { /// Pay for gas using a token for sending a message on a destination chain. /// /// This function is called on the source chain before calling the gateway to send a message. @@ -38,14 +39,11 @@ pub trait AxelarGasServiceInterface { /// Allows the `gas_collector` to collect accumulated fees from the contract. /// - /// Only callable by the `gas_collector`. + /// Only callable by the `operator`. fn collect_fees(env: Env, receiver: Address, token: Token) -> Result<(), ContractError>; /// Refunds gas payment to the receiver in relation to a specific cross-chain message. /// - /// Only callable by the `gas_collector`. + /// Only callable by the `operator`. fn refund(env: Env, message_id: String, receiver: Address, token: Token); - - /// Returns the address of the `gas_collector`. - fn gas_collector(env: &Env) -> Address; } diff --git a/contracts/stellar-axelar-gas-service/src/lib.rs b/contracts/stellar-axelar-gas-service/src/lib.rs index 93c15bae..74263fc7 100644 --- a/contracts/stellar-axelar-gas-service/src/lib.rs +++ b/contracts/stellar-axelar-gas-service/src/lib.rs @@ -21,7 +21,6 @@ cfg_if::cfg_if! { pub use interface::{AxelarGasServiceClient, AxelarGasServiceInterface}; } else { pub mod event; - mod storage_types; mod contract; pub use contract::{AxelarGasService, AxelarGasServiceClient}; diff --git a/contracts/stellar-axelar-gas-service/src/storage_types.rs b/contracts/stellar-axelar-gas-service/src/storage_types.rs deleted file mode 100644 index 1f6f5990..00000000 --- a/contracts/stellar-axelar-gas-service/src/storage_types.rs +++ /dev/null @@ -1,7 +0,0 @@ -use soroban_sdk::contracttype; - -#[contracttype] -#[derive(Clone, Debug)] -pub enum DataKey { - GasCollector, -} diff --git a/contracts/stellar-axelar-gas-service/src/tests/test.rs b/contracts/stellar-axelar-gas-service/src/tests/test.rs index 068718e6..71f11dd2 100644 --- a/contracts/stellar-axelar-gas-service/src/tests/test.rs +++ b/contracts/stellar-axelar-gas-service/src/tests/test.rs @@ -18,11 +18,11 @@ fn setup_env<'a>() -> (Env, Address, Address, AxelarGasServiceClient<'a>) { let env = Env::default(); let owner: Address = Address::generate(&env); - let gas_collector: Address = Address::generate(&env); - let contract_id = env.register(AxelarGasService, (&owner, &gas_collector)); + let operator: Address = Address::generate(&env); + let contract_id = env.register(AxelarGasService, (&owner, &operator)); let client = AxelarGasServiceClient::new(&env, &contract_id); - (env, contract_id, gas_collector, client) + (env, contract_id, operator, client) } fn setup_token(env: &Env, recipient: &Address, amount: i128) -> Token { @@ -60,11 +60,11 @@ fn register_gas_service() { let env = Env::default(); let owner: Address = Address::generate(&env); - let gas_collector = Address::generate(&env); - let contract_id = env.register(AxelarGasService, (&owner, &gas_collector)); + let operator = Address::generate(&env); + let contract_id = env.register(AxelarGasService, (&owner, &operator)); let client = AxelarGasServiceClient::new(&env, &contract_id); - assert_eq!(client.gas_collector(), gas_collector); + assert_eq!(client.operator(), operator); } #[test] @@ -258,7 +258,7 @@ fn add_gas() { #[test] fn collect_fees_fails_with_zero_amount() { - let (env, _, gas_collector, client) = setup_env(); + let (env, _, operator, client) = setup_env(); let spender: Address = Address::generate(&env); let refund_amount = 0; let supply: i128 = 1000; @@ -270,16 +270,14 @@ fn collect_fees_fails_with_zero_amount() { }; assert_contract_err!( - client - .mock_all_auths() - .try_collect_fees(&gas_collector, &token), + client.mock_all_auths().try_collect_fees(&operator, &token), ContractError::InvalidAmount ); } #[test] fn collect_fees_fails_with_insufficient_balance() { - let (env, contract_id, gas_collector, client) = setup_env(); + let (env, contract_id, operator, client) = setup_env(); let supply: i128 = 5; let asset = &env.register_stellar_asset_contract_v2(Address::generate(&env)); @@ -294,9 +292,7 @@ fn collect_fees_fails_with_insufficient_balance() { }; assert_contract_err!( - client - .mock_all_auths() - .try_collect_fees(&gas_collector, &token), + client.mock_all_auths().try_collect_fees(&operator, &token), ContractError::InsufficientBalance ); } @@ -323,8 +319,8 @@ fn collect_fees_fails_without_authorization() { } #[test] -fn collect_fees() { - let (env, contract_id, gas_collector, client) = setup_env(); +fn collect_fees_succeeds() { + let (env, contract_id, operator, client) = setup_env(); let supply: i128 = 1000; let asset = &env.register_stellar_asset_contract_v2(Address::generate(&env)); @@ -342,24 +338,24 @@ fn collect_fees() { let transfer_token_auth = mock_auth!( env, - gas_collector, - token.transfer(gas_collector, client.address, token.amount) + operator, + token.transfer(operator, client.address, token.amount) ); let collect_fees_auth = mock_auth!( env, - gas_collector, - client.collect_fees(&gas_collector, &token), + operator, + client.collect_fees(&operator, &token), &[(transfer_token_auth.invoke).clone()] ); client .mock_auths(&[collect_fees_auth]) - .collect_fees(&gas_collector, &token); + .collect_fees(&operator, &token); goldie::assert!(fmt_last_emitted_event::(&env)); - assert_eq!(refund_amount, token_client.balance(&gas_collector)); + assert_eq!(refund_amount, token_client.balance(&operator)); assert_eq!(supply - refund_amount, token_client.balance(&contract_id)); } @@ -388,7 +384,7 @@ fn refund_fails_without_authorization() { #[test] #[should_panic(expected = "HostError: Error(Contract, #10)")] // "balance is not sufficient to spend" fn refund_fails_with_insufficient_balance() { - let (env, contract_id, gas_collector, client) = setup_env(); + let (env, contract_id, operator, client) = setup_env(); let supply: i128 = 1; let asset = &env.register_stellar_asset_contract_v2(Address::generate(&env)); @@ -407,13 +403,13 @@ fn refund_fails_with_insufficient_balance() { let transfer_token_auth = mock_auth!( env, - gas_collector, - token.transfer(gas_collector, client.address, token.amount) + operator, + token.transfer(operator, client.address, token.amount) ); let refund_auth = mock_auth!( env, - gas_collector, + operator, client.refund(&message_id, &receiver, &token), &[(transfer_token_auth.invoke).clone()] ); @@ -424,7 +420,7 @@ fn refund_fails_with_insufficient_balance() { } #[test] -fn refund() { +fn refund_succeeds() { let (env, contract_id, _, client) = setup_env(); let supply: i128 = 1000; @@ -445,7 +441,7 @@ fn refund() { let message_id = message_id(&env); assert_auth!( - &client.gas_collector(), + client.operator(), client.refund(&message_id, &receiver, &token) ); diff --git a/contracts/stellar-axelar-gas-service/src/tests/testdata/collect_fees.golden b/contracts/stellar-axelar-gas-service/src/tests/testdata/collect_fees_succeeds.golden similarity index 100% rename from contracts/stellar-axelar-gas-service/src/tests/testdata/collect_fees.golden rename to contracts/stellar-axelar-gas-service/src/tests/testdata/collect_fees_succeeds.golden diff --git a/contracts/stellar-axelar-gas-service/src/tests/testdata/refund.golden b/contracts/stellar-axelar-gas-service/src/tests/testdata/refund_succeeds.golden similarity index 100% rename from contracts/stellar-axelar-gas-service/src/tests/testdata/refund.golden rename to contracts/stellar-axelar-gas-service/src/tests/testdata/refund_succeeds.golden diff --git a/contracts/stellar-axelar-gas-service/src/testutils.rs b/contracts/stellar-axelar-gas-service/src/testutils.rs index 1c667e3b..cc8dbb3e 100644 --- a/contracts/stellar-axelar-gas-service/src/testutils.rs +++ b/contracts/stellar-axelar-gas-service/src/testutils.rs @@ -7,8 +7,8 @@ use crate::{AxelarGasService, AxelarGasServiceClient}; pub fn setup_gas_service<'a>(env: &Env) -> AxelarGasServiceClient<'a> { let owner: Address = Address::generate(env); - let gas_collector: Address = Address::generate(env); - let gas_service_id = env.register(AxelarGasService, (&owner, &gas_collector)); + let operator: Address = Address::generate(env); + let gas_service_id = env.register(AxelarGasService, (&owner, &operator)); let gas_service_client = AxelarGasServiceClient::new(env, &gas_service_id); gas_service_client diff --git a/contracts/stellar-interchain-token-service/src/tests/testdata/deploy_interchain_token_receive_succeeds.golden b/contracts/stellar-interchain-token-service/src/tests/testdata/deploy_interchain_token_receive_succeeds.golden deleted file mode 100644 index 39b8f699..00000000 --- a/contracts/stellar-interchain-token-service/src/tests/testdata/deploy_interchain_token_receive_succeeds.golden +++ /dev/null @@ -1,3 +0,0 @@ -contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARQG5) -topics: (Symbol(interchain_token_deployed), BytesN<32>(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), Contract(CC2X6B2EMWFZBSQLILCJNRFQWPAD4MS4XYWW7XU5GL3LHCWD7OU6A3ZS), String(Test), String(TEST), 18, Some(Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATYON))) -data: () \ No newline at end of file diff --git a/contracts/stellar-interchain-token-service/src/tests/testdata/interchain_token_deploy_salt.golden b/contracts/stellar-interchain-token-service/src/tests/testdata/interchain_token_deploy_salt.golden deleted file mode 100644 index 10021ae9..00000000 --- a/contracts/stellar-interchain-token-service/src/tests/testdata/interchain_token_deploy_salt.golden +++ /dev/null @@ -1 +0,0 @@ -c9041493478f368bec8b935a05d2a9e9f14d666a3e7cc2bc444cbfc2b06d1f9d \ No newline at end of file diff --git a/packages/stellar-axelar-std/src/tests/testdata/event_custom_multiple_topics_and_data_succeeds.golden b/packages/stellar-axelar-std/src/tests/testdata/event_custom_multiple_topics_and_data_succeeds.golden deleted file mode 100644 index d91056d5..00000000 --- a/packages/stellar-axelar-std/src/tests/testdata/event_custom_multiple_topics_and_data_succeeds.golden +++ /dev/null @@ -1,3 +0,0 @@ -contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4) -topics: (Symbol(emitted_data), String(topic-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M)) -data: (String(data-1), String(data-2)) \ No newline at end of file diff --git a/packages/stellar-axelar-std/src/tests/testdata/event_multi_data_succeeds.golden b/packages/stellar-axelar-std/src/tests/testdata/event_multi_data_succeeds.golden deleted file mode 100644 index a129f40a..00000000 --- a/packages/stellar-axelar-std/src/tests/testdata/event_multi_data_succeeds.golden +++ /dev/null @@ -1,3 +0,0 @@ -contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) -topics: (Symbol(multi_data), String(topic-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) -data: (String(data-1), String(data-2)) \ No newline at end of file diff --git a/packages/stellar-axelar-std/src/tests/testdata/event_named_succeeds.golden b/packages/stellar-axelar-std/src/tests/testdata/event_named_succeeds.golden deleted file mode 100644 index c4deb177..00000000 --- a/packages/stellar-axelar-std/src/tests/testdata/event_named_succeeds.golden +++ /dev/null @@ -1,3 +0,0 @@ -contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) -topics: (Symbol(custom_name), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) -data: (String(100)) \ No newline at end of file diff --git a/packages/stellar-axelar-std/src/tests/testdata/event_no_data_succeeds.golden b/packages/stellar-axelar-std/src/tests/testdata/event_no_data_succeeds.golden deleted file mode 100644 index d4662372..00000000 --- a/packages/stellar-axelar-std/src/tests/testdata/event_no_data_succeeds.golden +++ /dev/null @@ -1,3 +0,0 @@ -contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) -topics: (Symbol(no_data), String(topic-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) -data: () \ No newline at end of file diff --git a/packages/stellar-axelar-std/src/tests/testdata/event_no_topic_succeeds.golden b/packages/stellar-axelar-std/src/tests/testdata/event_no_topic_succeeds.golden deleted file mode 100644 index 9ce47704..00000000 --- a/packages/stellar-axelar-std/src/tests/testdata/event_no_topic_succeeds.golden +++ /dev/null @@ -1,3 +0,0 @@ -contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) -topics: (Symbol(no_topic)) -data: (String(data-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4), String(data-3)) \ No newline at end of file diff --git a/packages/stellar-axelar-std/src/tests/testdata/event_single_data_succeeds.golden b/packages/stellar-axelar-std/src/tests/testdata/event_single_data_succeeds.golden deleted file mode 100644 index 3f69bd28..00000000 --- a/packages/stellar-axelar-std/src/tests/testdata/event_single_data_succeeds.golden +++ /dev/null @@ -1,3 +0,0 @@ -contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) -topics: (Symbol(single_data), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M)) -data: (String(100)) \ No newline at end of file diff --git a/packages/stellar-axelar-std/src/tests/testdata/event_transfer_emission_succeeds.golden b/packages/stellar-axelar-std/src/tests/testdata/event_transfer_emission_succeeds.golden deleted file mode 100644 index 009bf2b2..00000000 --- a/packages/stellar-axelar-std/src/tests/testdata/event_transfer_emission_succeeds.golden +++ /dev/null @@ -1,3 +0,0 @@ -contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4) -topics: (Symbol(transferred), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAITA4)) -data: (String(100)) \ No newline at end of file