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

Merge branch 'develop' #572

Merged
merged 19 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8351245
Registries: Remove registry-id as a argument for create (#559)
vatsa287 Jan 6, 2025
accb726
pallet-asset: Added new test-case for DistributionLimitExceeded. (#522)
ritankarsaha Jan 6, 2025
cd868be
Namespace: Add pallet to have namespace feature (#560)
vatsa287 Jan 9, 2025
c6d6890
namespace: Remove approval requirement for usage (#563)
vatsa287 Jan 9, 2025
1170905
docs: Update readme for PR validation requirements. (#540)
vatsa287 Jan 9, 2025
5909de8
network-score : Add Test Cases for SpaceMismatch error
huamanraj Jan 12, 2025
281c3e5
namespace: Add digest and blob for namespace create
vatsa287 Jan 13, 2025
bd7b0f9
namespace: Identifier updates (#565)
vatsa287 Jan 17, 2025
f651a06
namespace: Integrate with Registries framework
vatsa287 Jan 17, 2025
df9669b
registries: Integration testing with Namespace
vatsa287 Jan 17, 2025
38a265f
registries: Benchmarking updates for Namespace
vatsa287 Jan 17, 2025
ed1eb94
entries: Integration testing with updated Registries & Namespace
vatsa287 Jan 17, 2025
6eba730
Update to use new identifiers
vatsa287 Jan 18, 2025
2b49de3
namespace, registries: Update lookup table on create (#569)
vatsa287 Jan 19, 2025
345121e
Update the CORD version to 0.9.5 (#570)
vatsa287 Jan 20, 2025
bf18b86
Registries: Add tests for AuthorizationNotFound (#566)
muditDhiway Jan 20, 2025
3de3cc7
Fixes: #310 Add test cases for SchemaNotFound error (#551)
Vaibhavsahu2810 Jan 21, 2025
98a9e67
develop merge conflits
smohan-dw Jan 26, 2025
c7420da
fix upstream merge conflicts
smohan-dw Jan 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
745 changes: 387 additions & 358 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
"node/testing",
"pallets/asset",
"pallets/chain-space",
"pallets/namespace",
"pallets/did",
"pallets/did-name",
"pallets/identity",
Expand Down Expand Up @@ -898,6 +899,7 @@ pallet-registries = { path = "pallets/registries", default-features = false }
pallet-entries = { path = "pallets/entries", default-features = false }
pallet-schema-accounts = { path = "pallets/schema-accounts", default-features = false }
pallet-meta-tx = { path = "pallets/meta-tx", default-features = false }
pallet-namespace = { path = 'pallets/namespace', default-features = false }


[profile.release]
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,40 @@ If you would like to contribute, please fork the repository, follow the [contrib

### Before submitting the PR

There are 3 tests which run as part of PR validation.
There are 4 tests which run as part of PR validation.

- Build - `cargo build --release`
- #### Cargo Format

Ensures the code format is in accordance with official Rust guidelines. Add the formatted files as part of the commit.

- Clippy - `cargo clippy --all --no-deps --all-targets --features=runtime-benchmarks -- -D warnings`
```bash
cargo +nightly fmt --all
```

- #### Build

Transform CORD codebase into executable binary.

```bash
cargo build --release
```

- Clippy

Runs the linter to maintain clean and idiomatic code.

```bash
cargo clippy --all --no-deps --all-targets --features=runtime-benchmarks -- -D warnings`
```

- Test

Runs CORD Network unit tests, integration tests and benchmarks defined for all modules.

```bash
cargo test --release --locked --features=runtime-benchmarks --no-fail-fast --verbose --color always --all --all-targets
```

- Test - `cargo test --release --locked --features=runtime-benchmarks --no-fail-fast --verbose --color always --all --all-targets`

Note that each of these would take significant time to run, and hence, if you are working on a specific pallet, you can use `-p <pallet-name> --lib` instead of `--all`. That should be faster than normal full test locally.

Expand Down
2 changes: 1 addition & 1 deletion pallets/asset/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl mock_origin::Config for Test {

parameter_types! {
pub const MaxEncodedValueLength: u32 = 1_024;
pub const MaxAssetDistribution: u32 = u32::MAX;
pub const MaxAssetDistribution: u32 = 25;
}

impl Config for Test {
Expand Down
210 changes: 157 additions & 53 deletions pallets/asset/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::mock::*;
use crate::{mock::*, types::AssetIssuanceEntry, Error};
use codec::Encode;
use cord_utilities::mock::{mock_origin::DoubleOrigin, SubjectId};
use frame_support::{assert_err, assert_ok, BoundedVec};
Expand Down Expand Up @@ -278,12 +278,15 @@ fn asset_unauthorized_operation_should_fail() {
authorization_id.clone()
));

assert_err!(Asset::issue(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), // Unauthorized author attempting the action
issue_entry.clone(),
issue_entry_digest,
unauthorized_authorization_id.clone()
), Error::<Test>::UnauthorizedOperation);
assert_err!(
Asset::issue(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(), // Unauthorized author attempting the action
issue_entry.clone(),
issue_entry_digest,
unauthorized_authorization_id.clone()
),
Error::<Test>::UnauthorizedOperation
);

assert_ok!(Asset::issue(
DoubleOrigin(author.clone(), creator.clone()).into(),
Expand All @@ -292,29 +295,32 @@ fn asset_unauthorized_operation_should_fail() {
authorization_id.clone()
));

assert_err!(Asset::transfer(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
transfer_entry.clone(),
transfer_entry_digest,
),
Error::<Test>::UnauthorizedOperation
assert_err!(
Asset::transfer(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
transfer_entry.clone(),
transfer_entry_digest,
),
Error::<Test>::UnauthorizedOperation
);

assert_err!(Asset::transfer(
DoubleOrigin(author.clone(), creator.clone()).into(),
unauthorized_transfer_entry.clone(),
unauthorized_entry_digest,
),
Error::<Test>::UnauthorizedOperation
assert_err!(
Asset::transfer(
DoubleOrigin(author.clone(), creator.clone()).into(),
unauthorized_transfer_entry.clone(),
unauthorized_entry_digest,
),
Error::<Test>::UnauthorizedOperation
);

assert_err!(Asset::status_change(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
asset_id.clone(),
Some(instance_id.clone()),
AssetStatusOf::INACTIVE
),
Error::<Test>::UnauthorizedOperation
assert_err!(
Asset::status_change(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
asset_id.clone(),
Some(instance_id.clone()),
AssetStatusOf::INACTIVE
),
Error::<Test>::UnauthorizedOperation
);

assert_ok!(Asset::vc_create(
Expand All @@ -324,13 +330,14 @@ fn asset_unauthorized_operation_should_fail() {
authorization_id.clone()
));

assert_err!(Asset::vc_issue(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
issue_entry.clone(),
issue_entry_digest,
unauthorized_authorization_id
),
Error::<Test>::UnauthorizedOperation
assert_err!(
Asset::vc_issue(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
issue_entry.clone(),
issue_entry_digest,
unauthorized_authorization_id
),
Error::<Test>::UnauthorizedOperation
);

assert_ok!(Asset::vc_issue(
Expand All @@ -340,31 +347,33 @@ fn asset_unauthorized_operation_should_fail() {
authorization_id
));

assert_err!(Asset::vc_transfer(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
transfer_entry.clone(),
transfer_entry_digest,
),
Error::<Test>::UnauthorizedOperation
assert_err!(
Asset::vc_transfer(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
transfer_entry.clone(),
transfer_entry_digest,
),
Error::<Test>::UnauthorizedOperation
);

assert_err!(Asset::vc_transfer(
DoubleOrigin(author.clone(), creator.clone()).into(),
unauthorized_transfer_entry.clone(),
unauthorized_entry_digest,
),
Error::<Test>::UnauthorizedOperation
assert_err!(
Asset::vc_transfer(
DoubleOrigin(author.clone(), creator.clone()).into(),
unauthorized_transfer_entry.clone(),
unauthorized_entry_digest,
),
Error::<Test>::UnauthorizedOperation
);

assert_err!(Asset::vc_status_change(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
asset_id.clone(),
Some(instance_id.clone()),
AssetStatusOf::INACTIVE
),
Error::<Test>::UnauthorizedOperation
assert_err!(
Asset::vc_status_change(
DoubleOrigin(unauthorized_author.clone(), unauthorized_creator.clone()).into(),
asset_id.clone(),
Some(instance_id.clone()),
AssetStatusOf::INACTIVE
),
Error::<Test>::UnauthorizedOperation
);

});
}

Expand Down Expand Up @@ -3057,3 +3066,98 @@ fn asset_vc_status_change_with_wrong_asset_id_should_fail() {
);
});
}

#[test]
fn asset_issue_should_fail_when_distribution_limit_exceeds() {
let creator = DID_00;
let author = ACCOUNT_00;
let capacity = 200u64;

let raw_space = [2u8; 256].to_vec();
let space_digest = <Test as frame_system::Config>::Hashing::hash(&raw_space.encode()[..]);
let space_id_digest = <Test as frame_system::Config>::Hashing::hash(
&[&space_digest.encode()[..], &creator.encode()[..]].concat()[..],
);
let space_id: SpaceIdOf = generate_space_id::<Test>(&space_id_digest);

let auth_digest = <Test as frame_system::Config>::Hashing::hash(
&[&space_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..],
);
let authorization_id: Ss58Identifier = generate_authorization_id::<Test>(&auth_digest);
let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap();
let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap();
let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap();
let asset_qty = 1000;
let asset_value = 10;
let asset_type = AssetTypeOf::MF;

let entry = AssetInputEntryOf::<Test> {
asset_desc,
asset_qty,
asset_type,
asset_value,
asset_tag,
asset_meta,
};

let digest = <Test as frame_system::Config>::Hashing::hash(&[&entry.encode()[..]].concat()[..]);

let issue_id_digest = <Test as frame_system::Config>::Hashing::hash(
&[&digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..],
);

let asset_id: Ss58Identifier = generate_asset_id::<Test>(&issue_id_digest);

new_test_ext().execute_with(|| {
// Create and approve space
assert_ok!(Space::create(
DoubleOrigin(author.clone(), creator.clone()).into(),
space_digest,
));
assert_ok!(Space::approve(RawOrigin::Root.into(), space_id.clone(), capacity));
assert_ok!(Asset::create(
DoubleOrigin(author.clone(), creator.clone()).into(),
entry.clone(),
digest,
authorization_id.clone()
));

let max_distribution = <Test as Config>::MaxAssetDistribution::get();

for _ in 0..max_distribution {
let issuance_entry = AssetIssuanceEntry {
asset_id: asset_id.clone(),
asset_owner: creator.clone(),
asset_issuance_qty: Some(1),
};

let issuance_digest =
<Test as frame_system::Config>::Hashing::hash(&issuance_entry.encode()[..]);

assert_ok!(Asset::issue(
DoubleOrigin(author.clone(), creator.clone()).into(),
issuance_entry,
issuance_digest,
authorization_id.clone()
));
}
let exceeding_entry = AssetIssuanceEntry {
asset_id: asset_id.clone(),
asset_owner: creator.clone(),
asset_issuance_qty: Some(1),
};

let exceeding_digest =
<Test as frame_system::Config>::Hashing::hash(&exceeding_entry.encode()[..]);

assert_err!(
Asset::issue(
DoubleOrigin(author.clone(), creator.clone()).into(),
exceeding_entry,
exceeding_digest,
authorization_id.clone()
),
Error::<Test>::DistributionLimitExceeded
);
});
}
3 changes: 3 additions & 0 deletions pallets/entries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sp-core = { workspace = true }
cord-utilities = { workspace = true }
sp-keystore = { workspace = true }
serde_json = { workspace = true }
pallet-namespace = { workspace = true }
pallet-registries = { workspace = true }
pallet-schema-accounts = { workspace = true }

Expand All @@ -66,6 +67,7 @@ std = [
"sp-std/std",
"identifier/std",
"cord-utilities/std",
"pallet-namespace/std",
"pallet-registries/std",
"pallet-schema-accounts/std",
]
Expand All @@ -75,6 +77,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"cord-utilities/runtime-benchmarks",
"pallet-namespace/runtime-benchmarks",
"pallet-registries/runtime-benchmarks",
"pallet-schema-accounts/runtime-benchmarks",
]
Expand Down
Loading
Loading