Importing packages only for testing purpose (without throwing an warning)

module jyunth_addr::Sample2{
 
    #[test_only]
    use std::debug::print;
 
    #[test]
    fun test_function(){
        print(&@std)
    }
}

This will not throw a warning saying that this package is not used inside the module.

Address type

module jyunth_addr::Sample2{
 
    const MY_ADDR: address = @jyunth_addr;
  
    #[test_only]
    use std::debug::print;
  
    #[test]
    fun test_function(){
        print(&MY_ADDR);
    }
}
  • This imports the @jyunth_addr from the Move.toml file. and then stores it in the constant MY_ADDR.
  • It is important that constants in the Move language always start with an uppercase letter. If the constant is in the global scope, it is good dev practice if the variable is in all-caps.
  • To print this, you can use the & pointer to the variable.

Working with boolean type (and also how to return multiple values from a single function)

module jyunth_addr::Sample2{
 
    fun confirm_value(choice: bool): (u64, bool){
        if(choice)
            return (10, choice)
        else
            return (20, choice)
    }
 
    #[test_only]
    use std::debug::print;
 
    #[test]
    fun test_function(){
        let (result1, result2) = confirm_value(false);
  
        print(&result1);
        print(&result2)
    }
}