Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 17 additions & 15 deletions src/storage/data_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,61 +319,63 @@ mod tests {
fn succeed_adding_content() {
with_default_mock_builder(|| {
// Register a content with 1234 bytes of type 1, which should be recognized.
let res = TestDataDirectory::add_content(Origin::signed(1), 1, 1234, None);
let res = TestDataDirectory::add_content(Origin::signed(1), 1, 1234, 0);
assert!(res.is_ok());
});
}

#[test]
fn accept_content_as_liaison() {
with_default_mock_builder(|| {
let res = TestDataDirectory::add_content(Origin::signed(1), 1, 1234, None);
let sender = 1 as u64;
let res = TestDataDirectory::add_content(Origin::signed(sender), 1, 1234, 0);
assert!(res.is_ok());

// An appropriate event should have been fired.
let (content_id, liaison) = match System::events().last().unwrap().event {
let (content_id, creator) = match System::events().last().unwrap().event {
MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
content_id,
liaison,
)) => (content_id, liaison),
creator,
)) => (content_id, creator),
_ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
};
assert_ne!(liaison, 0xdeadbeefu64);
assert_eq!(liaison, TEST_MOCK_LIAISON);
assert_ne!(creator, 0xdeadbeefu64);
assert_eq!(creator, sender);

// Accepting content should not work with some random origin
let res = TestDataDirectory::accept_content(Origin::signed(1), content_id);
assert!(res.is_err());

// However, with the liaison as origin it should.
let res = TestDataDirectory::accept_content(Origin::signed(liaison), content_id);
let res = TestDataDirectory::accept_content(Origin::signed(TEST_MOCK_LIAISON), content_id);
assert!(res.is_ok());
});
}

#[test]
fn reject_content_as_liaison() {
with_default_mock_builder(|| {
let res = TestDataDirectory::add_content(Origin::signed(1), 1, 1234, None);
let sender = 1 as u64;
let res = TestDataDirectory::add_content(Origin::signed(sender), 1, 1234, 0);
assert!(res.is_ok());

// An appropriate event should have been fired.
let (content_id, liaison) = match System::events().last().unwrap().event {
let (content_id, creator) = match System::events().last().unwrap().event {
MetaEvent::data_directory(data_directory::RawEvent::ContentAdded(
content_id,
liaison,
)) => (content_id, liaison),
creator,
)) => (content_id, creator),
_ => (0u64, 0xdeadbeefu64), // invalid value, unlikely to match
};
assert_ne!(liaison, 0xdeadbeefu64);
assert_eq!(liaison, TEST_MOCK_LIAISON);
assert_ne!(creator, 0xdeadbeefu64);
assert_eq!(creator, sender);

// Rejecting content should not work with some random origin
let res = TestDataDirectory::reject_content(Origin::signed(1), content_id);
assert!(res.is_err());

// However, with the liaison as origin it should.
let res = TestDataDirectory::reject_content(Origin::signed(liaison), content_id);
let res = TestDataDirectory::reject_content(Origin::signed(TEST_MOCK_LIAISON), content_id);
assert!(res.is_ok());
});
}
Expand Down
28 changes: 6 additions & 22 deletions src/storage/data_object_type_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn deposit_event<T>() = default;

fn on_initialise() {
fn on_initialize() {
// Create a default data object type if it was not created yet.
if CREATE_DETAULT_TYPE && !<DataObjectTypes<T>>::exists(Self::first_data_object_type_id()) {
let do_type: DataObjectType = DataObjectType::default();
Expand Down Expand Up @@ -163,26 +163,13 @@ mod tests {
}

#[test]
fn fail_register_without_root() {
fn succeed_register() {
with_default_mock_builder(|| {
let data: TestDataObjectType = TestDataObjectType {
description: "foo".as_bytes().to_vec(),
active: false,
};
let res =
TestDataObjectTypeRegistry::register_data_object_type(Origin::signed(1), data);
assert!(res.is_err());
});
}

#[test]
fn succeed_register_as_root() {
with_default_mock_builder(|| {
let data: TestDataObjectType = TestDataObjectType {
description: "foo".as_bytes().to_vec(),
active: false,
};
let res = TestDataObjectTypeRegistry::register_data_object_type(Origin::ROOT, data);
let res = TestDataObjectTypeRegistry::register_data_object_type(data);
assert!(res.is_ok());
});
}
Expand All @@ -195,7 +182,7 @@ mod tests {
description: "foo".as_bytes().to_vec(),
active: false,
};
let id_res = TestDataObjectTypeRegistry::register_data_object_type(Origin::ROOT, data);
let id_res = TestDataObjectTypeRegistry::register_data_object_type(data);
assert!(id_res.is_ok());

let dot_id = match System::events().last().unwrap().event {
Expand All @@ -213,7 +200,6 @@ mod tests {
active: false,
};
let res = TestDataObjectTypeRegistry::update_data_object_type(
Origin::ROOT,
dot_id + 1,
updated1,
);
Expand All @@ -225,7 +211,7 @@ mod tests {
active: false,
};
let res =
TestDataObjectTypeRegistry::update_data_object_type(Origin::ROOT, dot_id, updated3);
TestDataObjectTypeRegistry::update_data_object_type(dot_id, updated3);
assert!(res.is_ok());
assert_eq!(
*System::events().last().unwrap(),
Expand All @@ -247,7 +233,7 @@ mod tests {
description: "foo".as_bytes().to_vec(),
active: false,
};
let id_res = TestDataObjectTypeRegistry::register_data_object_type(Origin::ROOT, data);
let id_res = TestDataObjectTypeRegistry::register_data_object_type(data);
assert!(id_res.is_ok());
assert_eq!(
*System::events().last().unwrap(),
Expand All @@ -268,7 +254,6 @@ mod tests {

// Now activate the data object type
let res = TestDataObjectTypeRegistry::activate_data_object_type(
Origin::ROOT,
TEST_FIRST_DATA_OBJECT_TYPE_ID,
);
assert!(res.is_ok());
Expand All @@ -291,7 +276,6 @@ mod tests {

// Deactivate again.
let res = TestDataObjectTypeRegistry::deactivate_data_object_type(
Origin::ROOT,
TEST_FIRST_DATA_OBJECT_TYPE_ID,
);
assert!(res.is_ok());
Expand Down
19 changes: 6 additions & 13 deletions src/storage/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ impl traits::ContentIdExists<Test> for MockContent {
) -> Result<data_directory::DataObject<Test>, &'static str> {
match *which {
TEST_MOCK_EXISTING_CID => Ok(data_directory::DataObject {
data_object_type: 1,
signing_key: None,
type_id: 1,
size: 1234,
added_at_block: 10,
added_at_time: 1024,
added_at: data_directory::BlockAndTime {
block: 10,
time: 1024,
},
owner: 1,
liaison: TEST_MOCK_LIAISON,
liaison_judgement: data_directory::LiaisonJudgement::Pending,
Expand Down Expand Up @@ -142,6 +143,7 @@ impl data_directory::Trait for Test {
type Members = MockMembers;
type Roles = MockRoles;
type IsActiveDataObjectType = AnyDataObjectTypeIsActive;
type SchemaId = u64;
}

impl data_object_storage_registry::Trait for Test {
Expand Down Expand Up @@ -242,15 +244,6 @@ impl ExtBuilder {
.0,
);

t.extend(
data_directory::GenesisConfig::<Test> {
first_content_id: self.first_content_id,
}
.build_storage()
.unwrap()
.0,
);

t.extend(
data_object_storage_registry::GenesisConfig::<Test> {
first_relationship_id: self.first_relationship_id,
Expand Down