msg_sender is the caller of the function. If you are using Rust SDK for the testing, then you can set up test wallets to simulate the function caller.
Here is the basic example for the same
use fuels::{prelude::*, types::Identity};
// Load abi from json
abigen!(Contract(
name = "MyContract",
abi = "out/debug/my-contract-abi.json"
));
#[tokio::test]
async fn test_foo() {
// Launch a local network and deploy the contract
let mut wallets = launch_custom_provider_and_get_wallets(
WalletsConfig::new(
Some(1), /* Single wallet */
Some(1), /* Single coin (UTXO) */
Some(1_000_000_000), /* Amount per coin */
),
None,
None,
)
.await
.unwrap();
let wallet = wallets.pop().unwrap();
// Deploy the contract
let id = Contract::load_from(
"./out/debug/my-contract.bin",
LoadConfiguration::default(),
)
.unwrap()
.deploy(&wallet, TxPolicies::default())
.await
.unwrap();
let instance = MyContract::new(id.clone(), wallet.clone());
// Call the foo function
let result = instance.methods().foo().call().await.unwrap();
// Assert that the msg_sender is the wallet address
assert_eq!(Identity::Address(wallet.address().into()), result.value);
}
In this example, launch_custom_provider_and_get_wallets is used to set up a wallet and a local network. The contract is deployed through this wallet, which acts as the caller. When foo() is called, msg_sender() returns this wallet’s address.
you can refer to the docs here for more info.
Lmk if this what you are looking for.