Skip to content

Commit 2b2e6f2

Browse files
authored
feat: add PayloadLocation::OffChain enum variant (#2678)
# Goal The goal of this PR is to add an enum variant, `PayloadLocation::OffChain` to better represent Intents and Schemas for which data is stored off-chain, but not specifically on IPFS. Closes #2677 # Checklist - [x] Unit Tests updated? - [x] e2e Tests updated? - [x] Spec version incremented?
1 parent f171355 commit 2b2e6f2

6 files changed

Lines changed: 118 additions & 69 deletions

File tree

common/primitives/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pub enum PayloadLocation {
7070
Itemized,
7171
/// Paginated payload location for onchain storage in paginated form
7272
Paginated,
73+
/// Message payload is located off-chain, other than IPFS
74+
OffChain,
7375
}
7476

7577
/// Support for up to 16 user-enabled features on a collection.

e2e/schemas/schemas.test.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let fundingSource: KeyringPair;
2020
describe('#schemas pallet tests', function () {
2121
let keys: KeyringPair;
2222
let accountWithNoFunds: KeyringPair;
23-
const createdIntents: { intentId: number; intentName: string; schemaIds: number[] }[] = [];
23+
const createdIntents: { intentId: number; intentName: string; payloadLocation: string; schemaIds: number[] }[] = [];
2424
const createdIntentGroups: { intentGroupId: number; intentIds: number[]; intentGroupName: string }[] = [];
2525

2626
before(async function () {
@@ -29,10 +29,16 @@ describe('#schemas pallet tests', function () {
2929
accountWithNoFunds = createKeys();
3030

3131
const intentName = 'e-e.' + generateSchemaPartialName(20);
32-
const f = ExtrinsicHelper.createIntent(keys, 'OnChain', [], intentName);
32+
const payloadLocation = 'OnChain';
33+
const f = ExtrinsicHelper.createIntent(keys, payloadLocation, [], intentName);
3334
const { target: createIntentEvent } = await f.fundAndSend(fundingSource);
3435
if (createIntentEvent && ExtrinsicHelper.apiPromise.events.schemas.IntentCreated.is(createIntentEvent)) {
35-
createdIntents.push({ intentId: createIntentEvent.data.intentId.toNumber(), intentName, schemaIds: [] });
36+
createdIntents.push({
37+
intentId: createIntentEvent.data.intentId.toNumber(),
38+
intentName,
39+
payloadLocation,
40+
schemaIds: [],
41+
});
3642
}
3743

3844
assert.equal(createdIntents.length, 1);
@@ -61,20 +67,23 @@ describe('#schemas pallet tests', function () {
6167
});
6268
});
6369

64-
it('should successfully create an intent with a name', async function () {
65-
const intentName = 'e-e.' + generateSchemaPartialName(20);
66-
const f = ExtrinsicHelper.createIntent(keys, 'OnChain', [], intentName);
67-
const { target: createIntentEvent, eventMap } = await f.fundAndSend(fundingSource);
68-
if (createIntentEvent && ExtrinsicHelper.apiPromise.events.schemas.IntentCreated.is(createIntentEvent)) {
69-
createdIntents.push({
70-
intentId: createIntentEvent.data.intentId.toNumber(),
71-
intentName: createIntentEvent.data.intentName.toString(),
72-
schemaIds: [],
73-
});
74-
}
70+
['OnChain', 'OffChain', 'Itemized', 'Paginated', 'IPFS'].forEach((payloadLocation) => {
71+
it(`should successfully create an intent with a name and payload location ${payloadLocation}`, async function () {
72+
const intentName = 'e-e.' + generateSchemaPartialName(20);
73+
const f = ExtrinsicHelper.createIntent(keys, 'OnChain', [], intentName);
74+
const { target: createIntentEvent, eventMap } = await f.fundAndSend(fundingSource);
75+
if (createIntentEvent && ExtrinsicHelper.apiPromise.events.schemas.IntentCreated.is(createIntentEvent)) {
76+
createdIntents.push({
77+
intentId: createIntentEvent.data.intentId.toNumber(),
78+
intentName: createIntentEvent.data.intentName.toString(),
79+
payloadLocation,
80+
schemaIds: [],
81+
});
82+
}
7583

76-
assertExtrinsicSuccess(eventMap);
77-
assert.notEqual(createIntentEvent, undefined);
84+
assertExtrinsicSuccess(eventMap);
85+
assert.notEqual(createIntentEvent, undefined);
86+
});
7887
});
7988

8089
it('create intent should fail if name is a duplicate', async function () {
@@ -85,6 +94,7 @@ describe('#schemas pallet tests', function () {
8594
createdIntents.push({
8695
intentId: createIntentEvent.data.intentId.toNumber(),
8796
intentName: createIntentEvent.data.intentName.toString(),
97+
payloadLocation: 'OnChain',
8898
schemaIds: [],
8999
});
90100
}

pallets/messages/src/tests/other_tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ fn populate_messages_v3(
3434
let cid = cid_in.unwrap_or_else(|| &DUMMY_CID_BASE32[..]);
3535

3636
let payload = match payload_location {
37-
// Just stick Itemized & Paginated here for coverage; we don't use them for Messages
38-
PayloadLocation::OnChain | PayloadLocation::Itemized | PayloadLocation::Paginated =>
39-
generate_payload(1),
37+
// Just stick OffChain, Itemized & Paginated here for coverage; we don't use them for Messages
38+
PayloadLocation::OnChain |
39+
PayloadLocation::OffChain |
40+
PayloadLocation::Itemized |
41+
PayloadLocation::Paginated => generate_payload(1),
4042
PayloadLocation::IPFS =>
4143
(multibase::decode(core::str::from_utf8(cid).unwrap()).unwrap().1, IPFS_PAYLOAD_LENGTH)
4244
.encode(),

pallets/schemas/src/tests/intent_tests.rs

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,42 @@ fn create_intent_happy_path() {
2525
new_test_ext().execute_with(|| {
2626
// arrange
2727
let sender: AccountId = test_public(1);
28-
let name = "namespace.descriptor";
29-
let intent_name: SchemaNamePayload =
30-
BoundedVec::try_from(name.to_string().into_bytes()).expect("should convert");
3128

32-
// act
33-
assert_ok!(SchemasPallet::create_intent(
34-
RuntimeOrigin::signed(sender.clone()),
35-
intent_name.clone(),
29+
let payload_locations = [
3630
PayloadLocation::OnChain,
37-
BoundedVec::default(),
38-
));
39-
let res = SchemasPallet::get_intent_by_id(1);
40-
let parsed_name = intent_name.into_inner();
41-
42-
// assert
43-
System::assert_last_event(
44-
AnnouncementEvent::IntentCreated {
45-
key: sender,
46-
intent_id: 1,
47-
intent_name: parsed_name,
48-
}
49-
.into(),
50-
);
51-
assert!(res.as_ref().is_some());
31+
PayloadLocation::IPFS,
32+
PayloadLocation::Itemized,
33+
PayloadLocation::Paginated,
34+
PayloadLocation::OffChain,
35+
];
36+
37+
payload_locations.iter().enumerate().for_each(|(index, location)| {
38+
let expected_id: IntentId = index as IntentId + 1;
39+
let name = "namespace.descriptor".to_owned() + &index.to_string();
40+
let intent_name: SchemaNamePayload =
41+
BoundedVec::try_from(name.to_string().into_bytes()).expect("should convert");
42+
43+
// act
44+
assert_ok!(SchemasPallet::create_intent(
45+
RuntimeOrigin::signed(sender.clone()),
46+
intent_name.clone(),
47+
*location,
48+
BoundedVec::default(),
49+
));
50+
let res = SchemasPallet::get_intent_by_id(expected_id);
51+
let parsed_name = intent_name.into_inner();
52+
53+
// assert
54+
System::assert_last_event(
55+
AnnouncementEvent::IntentCreated {
56+
key: sender.clone(),
57+
intent_id: expected_id,
58+
intent_name: parsed_name,
59+
}
60+
.into(),
61+
);
62+
assert!(res.as_ref().is_some());
63+
})
5264
})
5365
}
5466

@@ -98,9 +110,12 @@ fn create_intent_via_governance_with_append_only_setting_and_non_itemized_should
98110
let intent_name: SchemaNamePayload =
99111
BoundedVec::try_from(name.to_string().into_bytes()).expect("should convert");
100112

101-
for location in
102-
[PayloadLocation::OnChain, PayloadLocation::IPFS, PayloadLocation::Paginated]
103-
{
113+
for location in [
114+
PayloadLocation::OnChain,
115+
PayloadLocation::IPFS,
116+
PayloadLocation::Paginated,
117+
PayloadLocation::OffChain,
118+
] {
104119
// act and assert
105120
assert_noop!(
106121
SchemasPallet::create_intent_via_governance(
@@ -127,7 +142,8 @@ fn create_intent_via_governance_with_signature_required_setting_and_wrong_locati
127142
let intent_name: SchemaNamePayload =
128143
BoundedVec::try_from(name.to_string().into_bytes()).expect("should convert");
129144

130-
for location in [PayloadLocation::OnChain, PayloadLocation::IPFS] {
145+
for location in [PayloadLocation::OnChain, PayloadLocation::IPFS, PayloadLocation::OffChain]
146+
{
131147
// act and assert
132148
assert_noop!(
133149
SchemasPallet::create_intent_via_governance(

pallets/schemas/src/tests/other_tests.rs

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -518,30 +518,49 @@ fn create_schema_v4_happy_path() {
518518
// arrange
519519
sudo_set_max_schema_size();
520520
let sender: AccountId = test_public(1);
521-
let name = "namespace.descriptor";
522-
let intent_name: SchemaNamePayload =
523-
BoundedVec::try_from(name.to_string().into_bytes()).expect("should convert");
524-
let (intent_id, _) = SchemasPallet::create_intent_for(
525-
intent_name,
521+
let payload_locations = [
526522
PayloadLocation::OnChain,
527-
BoundedVec::default(),
528-
)
529-
.expect("should have created an intent");
530-
531-
// act
532-
assert_ok!(SchemasPallet::create_schema_v4(
533-
RuntimeOrigin::signed(sender.clone()),
534-
intent_id,
535-
create_bounded_schema_vec(r#"{"name": "Doe", "type": "lost"}"#),
536-
ModelType::AvroBinary,
537-
));
538-
let res = SchemasPallet::get_schema_by_id(1);
523+
PayloadLocation::IPFS,
524+
PayloadLocation::Itemized,
525+
PayloadLocation::Paginated,
526+
PayloadLocation::OffChain,
527+
];
528+
payload_locations.iter().enumerate().for_each(|(i, payload_location)| {
529+
let expected_schema_id: SchemaId = i as SchemaId + 1;
530+
let name = "namespace.descriptor".to_owned() + &i.to_string();
531+
let intent_name: SchemaNamePayload =
532+
BoundedVec::try_from(name.to_string().into_bytes()).expect("should convert");
533+
let (intent_id, _) = SchemasPallet::create_intent_for(
534+
intent_name,
535+
*payload_location,
536+
BoundedVec::default(),
537+
)
538+
.expect("should have created an intent");
539+
540+
// act
541+
assert_ok!(SchemasPallet::create_schema_v4(
542+
RuntimeOrigin::signed(sender.clone()),
543+
intent_id,
544+
create_bounded_schema_vec(r#"{"name": "Doe", "type": "lost"}"#),
545+
ModelType::AvroBinary,
546+
));
547+
let res = SchemasPallet::get_schema_by_id(expected_schema_id);
539548

540-
// assert
541-
System::assert_last_event(
542-
AnnouncementEvent::SchemaCreated { key: sender, schema_id: 1 }.into(),
543-
);
544-
assert!(res.as_ref().is_some());
549+
// assert
550+
System::assert_last_event(
551+
AnnouncementEvent::SchemaCreated {
552+
key: sender.clone(),
553+
schema_id: expected_schema_id,
554+
}
555+
.into(),
556+
);
557+
assert!(res.as_ref().is_some());
558+
let res = res.unwrap();
559+
assert_eq!(
560+
res.payload_location, *payload_location,
561+
"Schema payload location should match Intent"
562+
);
563+
})
545564
})
546565
}
547566

runtime/frequency/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
673673
spec_name: Cow::Borrowed("frequency"),
674674
impl_name: Cow::Borrowed("frequency"),
675675
authoring_version: 1,
676-
spec_version: 190,
676+
spec_version: 191,
677677
impl_version: 0,
678678
apis: RUNTIME_API_VERSIONS,
679679
transaction_version: 1,
@@ -687,7 +687,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
687687
spec_name: Cow::Borrowed("frequency-testnet"),
688688
impl_name: Cow::Borrowed("frequency"),
689689
authoring_version: 1,
690-
spec_version: 190,
690+
spec_version: 191,
691691
impl_version: 0,
692692
apis: RUNTIME_API_VERSIONS,
693693
transaction_version: 1,

0 commit comments

Comments
 (0)