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

[C4GT] Asset: Add tests for InvalidAssetType #374

Open
3 tasks
vatsa287 opened this issue Mar 12, 2024 · 5 comments
Open
3 tasks

[C4GT] Asset: Add tests for InvalidAssetType #374

vatsa287 opened this issue Mar 12, 2024 · 5 comments
Assignees
Labels

Comments

@vatsa287
Copy link
Member

Description

Subtask under : cord-network/community#7

New testcase can be tested under cargo test -p pallet-asset after adding it in the code.

Goals

  • Add tests for InvalidAssetType for pallet/asset

Expected Outcome

  • Test should assert for InvalidAssetType being returned properly in all the possible calls.
  • If there are more than one function returning this error code, all of them should be validated either as one test case or as multiple test cases.

Acceptance Criteria

NA

Implementation Details

Look at other test cases, and add a test case for the same.
Ex: check method asset_create_should_succeed which validates creation of asset.

Mockups / Wireframes

NA


Product Name

CORD

Organization Name

Dhiway

Domain

Blockchain

Tech Skills Needed

Rust

Mentor(s)

@amarts @vatsa287

Complexity

[Low]

Category

[Test]

Sub Category

[Beginner friendly]

@aishalxgupta
Copy link

Hi @vatsa287
I'm confident in my understanding of the problem and possess the necessary skills. I'd be grateful for the opportunity to be assigned to this project

@hardik-pratap-singh
Copy link
Contributor

Hey @vatsa287 @amarts !!
I want to take this issue.
Kindly assign it to me if possible.

@hardik-pratap-singh
Copy link
Contributor

Hey @amarts @vatsa287 !
Is this issue still needs to be worked upon ?

If yes, I would love to work on it !
Can you please assign it to me ?

@vatsa287
Copy link
Member Author

To proceed to reach this error code of InvalidAssetType.

AssetType is a enum. Enums in rust have a discriminant value associated with all enums, starting with 0 as default.

AssetType has 3 values so has 0, 1, 2 in decoded way.

So you can try encoding an invalid discriminant, and compare the decoded value associated from AssetTypeOf. Since the input encoded byte-format value is not part of enum list. It must throw error.

^ @JiyaGupta-cs

@ritankarsaha
Copy link

@vatsa287

We need to simulate a situation where an invalid type is provided to functions that check or enforce valid asset types. Given that Rust enums are statically checked, passing an undefined variant directly is not possible. However, we can simulate an invalid discriminant by encoding and decoding operations that bypass the type system.

We have an enum AssetType with values like TypeA, TypeB, etc., with corresponding discriminants (0, 1, 2). Any value outside this range should be invalid.Directly creating an invalid value in Rust isn't possible, but we can create an encoded byte array representing an invalid discriminant and decode it into the type.

I think this should be the approach to this issue. I have also investigated into the previous PRs.

Can I work on this issue ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants