Skip to content

Commit

Permalink
Merge branch 'feat/beta' into common-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiblt1304 authored Jan 8, 2025
2 parents 09da690 + 95f2a61 commit f875592
Show file tree
Hide file tree
Showing 20 changed files with 282 additions and 279 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ permissions:
jobs:
contracts:
name: Contracts
uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@79d7ac76e34b3208fbe07559ac276d0ea48be4da
uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v4.2.0
with:
rust-toolchain: stable
coverage-args: --ignore-filename-regex='/.cargo/git' --output ./coverage.md
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

18 changes: 9 additions & 9 deletions chain-factory/tests/chain_factory_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use multiversx_sc::types::{
BigUint, CodeMetadata, MultiValueEncoded, TestAddress, TestSCAddress, TokenIdentifier,
};
use multiversx_sc_scenario::{
api::StaticApi, imports::MxscPath, managed_biguint, ExpectError, ScenarioTxRun, ScenarioWorld,
api::StaticApi, imports::MxscPath, managed_biguint, ReturnsHandledOrError, ScenarioTxRun,
ScenarioWorld,
};
use proxies::{
chain_config_proxy::ChainConfigContractProxy, chain_factory_proxy::ChainFactoryContractProxy,
Expand Down Expand Up @@ -88,9 +89,9 @@ impl ChainFactoryTestState {
max_validators: usize,
min_stake: BigUint<StaticApi>,
additional_stake_required: MultiValueEncoded<StaticApi, StakeMultiArg<StaticApi>>,
expected_result: Option<ExpectError<'_>>,
error_message: Option<&str>,
) {
let transaction = self
let response = self
.world
.tx()
.from(CONFIG_ADDRESS)
Expand All @@ -101,13 +102,12 @@ impl ChainFactoryTestState {
max_validators,
min_stake,
additional_stake_required,
);
)
.returns(ReturnsHandledOrError::new())
.run();

match expected_result {
Some(error) => {
transaction.returns(error).run();
}
None => transaction.run(),
if let Err(error) = response {
assert_eq!(error_message, Some(error.message.as_str()))
}
}
}
Expand Down
54 changes: 53 additions & 1 deletion common/proxies/src/token_handler_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ where
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init(
pub fn init<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
chain_factory_master: Arg0,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.argument(&chain_factory_master)
.original_result()
}
}
Expand Down Expand Up @@ -111,4 +115,52 @@ where
.argument(&tokens)
.original_result()
}

pub fn is_admin<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, bool> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("isAdmin")
.argument(&address)
.original_result()
}

pub fn add_admin<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("addAdmin")
.argument(&address)
.original_result()
}

pub fn remove_admin<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("removeAdmin")
.argument(&address)
.original_result()
}

pub fn admins(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ManagedAddress<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getAdmins")
.original_result()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,15 @@ impl ContractInteract {

pub async fn deploy_token_handler(&mut self) {
let token_handler_code_path = MxscPath::new(&self.token_handler_code);
let chain_factory_address = Bech32Address::from_bech32_string("chain_factory".to_string());

let new_address = self
.interactor
.tx()
.from(&self.wallet_address)
.gas(100_000_000u64)
.typed(token_handler_proxy::TokenHandlerProxy)
.init()
.init(chain_factory_address)
.code(token_handler_code_path)
.returns(ReturnsNewAddress)
.run()
Expand Down
83 changes: 42 additions & 41 deletions enshrine-esdt-safe/tests/enshrine_esdt_safe_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use multiversx_sc::types::{
use multiversx_sc_scenario::api::StaticApi;
use multiversx_sc_scenario::multiversx_chain_vm::crypto_functions::sha256;
use multiversx_sc_scenario::{imports::MxscPath, ScenarioWorld};
use multiversx_sc_scenario::{managed_address, ExpectError, ScenarioTxRun};
use multiversx_sc_scenario::{managed_address, ReturnsHandledOrError, ScenarioTxRun};
use proxies::enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy;
use proxies::fee_market_proxy::{FeeMarketProxy, FeeStruct, FeeType};
use proxies::header_verifier_proxy::HeaderverifierProxy;
Expand Down Expand Up @@ -180,7 +180,7 @@ impl EnshrineTestState {
.tx()
.from(ENSHRINE_ESDT_OWNER_ADDRESS)
.typed(TokenHandlerProxy)
.init()
.init(ENSHRINE_ESDT_ADDRESS)
.code(TOKEN_HANDLER_CODE_PATH)
.new_address(TOKEN_HANDLER_ADDRESS)
.run();
Expand Down Expand Up @@ -211,18 +211,18 @@ impl EnshrineTestState {
fn propose_set_fee(
&mut self,
fee_struct: Option<&FeeStruct<StaticApi>>,
expected_result: Option<ExpectError<'_>>,
error_message: Option<&str>,
) -> &mut Self {
if let Some(fee) = fee_struct {
self.propose_add_fee_token(fee, expected_result);
self.propose_add_fee_token(fee, error_message);
}

self
}

fn propose_execute_operation(
&mut self,
expected_result: Option<ExpectError<'_>>,
error_message: Option<&str>,
tokens: &Vec<TestTokenIdentifier>,
) {
let (tokens, data) = self.setup_payments(tokens);
Expand All @@ -232,17 +232,18 @@ impl EnshrineTestState {
let hash_of_hashes: ManagedBuffer<StaticApi> =
ManagedBuffer::from(&sha256(&operation_hash.to_vec()));

let transaction = self
let response = self
.world
.tx()
.from(USER_ADDRESS)
.to(ENSHRINE_ESDT_ADDRESS)
.typed(EnshrineEsdtSafeProxy)
.execute_operations(hash_of_hashes, operation);
.execute_operations(hash_of_hashes, operation)
.returns(ReturnsHandledOrError::new())
.run();

match expected_result {
Some(error) => transaction.returns(error).run(),
None => transaction.run(),
if let Err(error) = response {
assert_eq!(error_message, Some(error.message.as_str()))
}
}

Expand Down Expand Up @@ -299,7 +300,7 @@ impl EnshrineTestState {
sender: &TestAddress,
fee_payment: EsdtTokenPayment<StaticApi>,
tokens_to_register: Vec<TestTokenIdentifier>,
expected_result: Option<ExpectError<'_>>,
error_message: Option<&str>,
) {
let mut managed_token_ids: MultiValueEncoded<StaticApi, TokenIdentifier<StaticApi>> =
MultiValueEncoded::new();
Expand All @@ -308,18 +309,19 @@ impl EnshrineTestState {
managed_token_ids.push(TokenIdentifier::from(token_id))
}

let transaction = self
let response = self
.world
.tx()
.from(*sender)
.to(ENSHRINE_ESDT_ADDRESS)
.typed(EnshrineEsdtSafeProxy)
.register_new_token_id(managed_token_ids)
.esdt(fee_payment);
.esdt(fee_payment)
.returns(ReturnsHandledOrError::new())
.run();

match expected_result {
Some(error) => transaction.returns(error).run(),
None => transaction.run(),
if let Err(error) = response {
assert_eq!(error_message, Some(error.message.as_str()))
}
}

Expand All @@ -329,39 +331,41 @@ impl EnshrineTestState {
to: TestAddress,
payment: PaymentsVec<StaticApi>,
deposit_args: OptionalTransferData<StaticApi>,
expected_result: Option<ExpectError<'_>>,
error_message: Option<&str>,
) {
let transaction = self
let response = self
.world
.tx()
.from(from)
.to(ENSHRINE_ESDT_ADDRESS)
.typed(EnshrineEsdtSafeProxy)
.deposit(to, deposit_args)
.payment(payment);
.payment(payment)
.returns(ReturnsHandledOrError::new())
.run();

match expected_result {
Some(error) => transaction.returns(error).run(),
None => transaction.run(),
if let Err(error) = response {
assert_eq!(error_message, Some(error.message.as_str()))
}
}

fn propose_add_fee_token(
&mut self,
fee_struct: &FeeStruct<StaticApi>,
expected_result: Option<ExpectError<'_>>,
error_message: Option<&str>,
) {
let transaction = self
let response = self
.world
.tx()
.from(ENSHRINE_ESDT_OWNER_ADDRESS)
.to(FEE_MARKET_ADDRESS)
.typed(FeeMarketProxy)
.set_fee(fee_struct);
.set_fee(fee_struct)
.returns(ReturnsHandledOrError::new())
.run();

match expected_result {
Some(error) => transaction.returns(error).run(),
None => transaction.run(),
if let Err(error) = response {
assert_eq!(error_message, Some(error.message.as_str()))
}
}

Expand All @@ -388,7 +392,7 @@ impl EnshrineTestState {
fn propose_whitelist_enshrine_esdt(&mut self) {
self.world
.tx()
.from(ENSHRINE_ESDT_OWNER_ADDRESS)
.from(ENSHRINE_ESDT_ADDRESS)
.to(TOKEN_HANDLER_ADDRESS)
.typed(TokenHandlerProxy)
.whitelist_enshrine_esdt(ENSHRINE_ESDT_ADDRESS)
Expand Down Expand Up @@ -479,7 +483,7 @@ fn test_sovereign_prefix_no_prefix() {
state.propose_register_operation(&token_vec);
state.propose_register_esdt_in_header_verifier();
state.propose_whitelist_enshrine_esdt();
state.propose_execute_operation(Some(ExpectError(10, "action is not allowed")), &token_vec);
state.propose_execute_operation(Some("action is not allowed"), &token_vec);
}

#[test]
Expand All @@ -506,7 +510,7 @@ fn test_register_tokens_insufficient_funds() {
&USER_ADDRESS,
payment,
token_vec,
Some(ExpectError(10, "insufficient funds")),
Some("insufficient funds"),
);
}

Expand All @@ -522,10 +526,7 @@ fn test_register_tokens_wrong_token_as_fee() {
&ENSHRINE_ESDT_OWNER_ADDRESS,
payment,
token_vec,
Some(ExpectError(
4,
"WEGLD is the only token accepted as register fee",
)),
Some("WEGLD is the only token accepted as register fee"),
);
}

Expand Down Expand Up @@ -561,7 +562,7 @@ fn test_register_tokens_insufficient_wegld() {
&ENSHRINE_ESDT_OWNER_ADDRESS,
payment,
token_vec,
Some(ExpectError(4, "WEGLD fee amount is not met")),
Some("WEGLD fee amount is not met"),
);
}

Expand Down Expand Up @@ -609,7 +610,7 @@ fn test_deposit_token_nothing_to_transfer_fee_enabled() {
USER_ADDRESS,
payments,
OptionalValue::None,
Some(ExpectError(4, "Nothing to transfer")),
Some("Nothing to transfer"),
);
}

Expand All @@ -627,7 +628,7 @@ fn test_deposit_max_transfers_exceeded() {
USER_ADDRESS,
payments,
OptionalValue::None,
Some(ExpectError(4, "Too many tokens")),
Some("Too many tokens"),
);
}

Expand Down Expand Up @@ -710,7 +711,7 @@ fn test_deposit_with_transfer_data_gas_limit_too_high() {
USER_ADDRESS,
payments,
transfer_data,
Some(ExpectError(4, "Gas limit too high")),
Some("Gas limit too high"),
);
}

Expand Down Expand Up @@ -740,7 +741,7 @@ fn test_deposit_with_transfer_data_banned_endpoint() {
USER_ADDRESS,
payments,
transfer_data,
Some(ExpectError(4, "Banned endpoint name")),
Some("Banned endpoint name"),
);
}

Expand Down Expand Up @@ -844,7 +845,7 @@ fn test_deposit_with_transfer_data_not_enough_for_fee() {
USER_ADDRESS,
payments,
transfer_data,
Some(ExpectError(4, "Payment does not cover fee")),
Some("Payment does not cover fee"),
);
}

Expand Down
1 change: 1 addition & 0 deletions enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.lock

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

Loading

0 comments on commit f875592

Please sign in to comment.