pendulum-chain / spacewalk

Apache License 2.0
34 stars 7 forks source link

Switch to 'stable' rust toolchain channel #506

Closed ebma closed 4 months ago

ebma commented 5 months ago

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 commented 5 months ago

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

b-yap commented 4 months ago

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 commented 4 months ago

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