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

feat: add unit tests for vc-task #2665

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from

Conversation

felixfaisal
Copy link
Member

@felixfaisal felixfaisal commented Apr 15, 2024

So this PR aims to mock some parts of the vc-task thread and test. I've created mock.rs to create all the mock instances: ;
A few problems I want to address in different issues:

  • Currently, I'm able to run these tests properly only under --test-threads 1, if not it fails with SendError. I want to debug this in another issue, for now I'm running these tests on a single thread. Not related to tee-dev
  • There is no way to test more than one assertion A1 as all others require network calls, So I'm only testing the A1 assertion, and secondly I'm not asserting if the credential str produced is correct or not.

Copy link

linear bot commented Apr 15, 2024

@felixfaisal felixfaisal marked this pull request as ready for review April 16, 2024 06:29
@felixfaisal felixfaisal changed the title feat: add mock.rs and unit tests feat: add unit tests for vc-task Apr 17, 2024
@@ -68,6 +68,7 @@ RUN \
fi

RUN cargo test --release --features development
RUN cargo test -p lc-vc-task-receiver -- --ignored --test-threads 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no rush i suggest debugging --test-threads before this PR gets merged.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I'm choosing to debug this in another issue, is because the most likely reason why it fails is because of the two globals we are using i.e. GLOBAL_MOCK_RPC_API and GLOBAL_MOCK_AUTHOR_API, it is something being used for only the unit testing, So I prefer doing it another PR. I would have to use a completely different mechanism to capture the values, and I think I should take a dig at it in a different/follow-up PR.

let sender_guard = GLOBAL_MOCK_RPC_API.lock().unwrap();
let sender = &*sender_guard;
sender.as_ref().expect("Not yet initialized").send(encoded_value).unwrap();
// Box::pin(ready(Ok([0u8; 32].into())))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the comment.

let top_calls_receiver = init_global_mock_author_api().unwrap();
let rpc_calls_receiver = init_global_rpc_api().unwrap();

thread::sleep(Duration::from_secs(2));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this sleep ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a sanity check to make sure things are initialised.

pub static ref SHIELDING_KEY: ShieldingCryptoMock = ShieldingCryptoMock::default();
}

pub fn init_global_mock_author_api() -> Result<Receiver<Vec<u8>>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about keeping only mock definitions here and removing test util functions and functions that initializes tests context (move everything to test.rs and remove this file) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can do that, I followed the pattern of unit tests in pallets.

use crate::mock::*;

#[test]
#[ignore]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test case ignored ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is so that it is not run with all the tests, and only run with the test-threads 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means if we add more ignored tests to this package they will be run alongside ones added in this PR, is this fine ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that should be fine imo, they will be run with cargo test -p lc-vc-task-receiver -- --ignored --test-threads 1

@felixfaisal felixfaisal requested a review from silva-fj June 3, 2024 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants