Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to 'stable' rust toolchain channel #506

Closed
ebma opened this issue Apr 4, 2024 · 3 comments · Fixed by #513
Closed

Switch to 'stable' rust toolchain channel #506

ebma opened this issue Apr 4, 2024 · 3 comments · Fixed by #513
Assignees

Comments

@ebma
Copy link
Member

ebma commented Apr 4, 2024

At the moment, we are using the 'nightly' channel of the Rust toolchain. Going forward, we want to use the 'stable' channel because some tools like the SRTool don't work on 'nightly' anymore, at least not on the latest versions, see this issue.
Switching the toolchain was not possible before as we encountered compiler errors. It might be that the recent update of the polkadot dependencies to v0.9.42 resolves those problems.

TODO

Change the rust-toolchain.toml to use a 'stable' channel. Make sure that the vault, testchain and all tests still compile and work as expected.

@ebma
Copy link
Member Author

ebma commented Apr 4, 2024

@pendulum-chain/product This is a chore and doesn't add a new feature. It's nice to have but not urgent.

@b-yap b-yap self-assigned this Apr 8, 2024
@b-yap
Copy link
Contributor

b-yap commented Apr 16, 2024

We have to replace Mocktopus, which is a nightly-only library.

Current situation: I tried to use the famous mockall lib, but our problem is the usage of functions (static methods) called inside the Pallet{} struct.

sample code:

#[cfg(test)]
use mockall::automock;

#[cfg_attr(test, automock)]
pub mod pallet_helper {
    pub fn one() -> u64 {
        1
    }

    pub fn two() -> u64 {
        2
    }
}

pub mod prod {
    pub struct Pallet;

    impl Pallet {
        pub fn get_one() -> u64 {
             ...
             super::pallet_helper::one()
        }

        pub fn get_two() -> u64 {
            ...
            super::pallet_helper::two()
        }
    }
}

And in our test cases, we're testing get_one() and get_two():

  static MTX: Mutex<()> = Mutex::new(());

    #[test]
    fn test_1() {
        // The mutex might be poisoned if another test fails.  But we don't
        // care, because it doesn't hold any data.  So don't unwrap the Result
        // object; whether it's poisoned or not, we'll still hold the
        // MutexGuard.
        let _m = MTX.lock();

        let ctx = mock_helper::one_context();
        ctx.expect().returning(|| 2);
        let expected = 2;
        assert_eq!(expected, prod::Pallet::get_one());
    }    

But it fails:

assertion `left == right` failed
  left: 2
 right: 1

This pattern style is what I've observed in pallets vault-registry and reward-distribution.
It would be great to wrap the Pallet inside the mock!() macro. But that would be ugly. Or it might not even work. Maybe that's why Interlay used Mocktopus.

I'll continue the hunt for other mock libs to use

@prayagd
Copy link
Collaborator

prayagd commented Apr 25, 2024

@b-yap can you please estimate this ticket as i see you already started work on this and move this to ready?

@b-yap b-yap closed this as completed in #513 May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants