Newer
Older
head_data: HeadData(vec![1, 2, 3]),
egress_queue_roots,
fees: 0,
block_data_hash: Default::default(),
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
fn new_candidate_with_upward_messages(
id: u32,
upward_messages: Vec<(ParachainDispatchOrigin, Vec<u8>)>
) -> AttestedCandidate {
AttestedCandidate {
validity_votes: vec![],
candidate: CandidateReceipt {
parachain_index: id.into(),
collator: Default::default(),
signature: Default::default(),
head_data: HeadData(vec![1, 2, 3]),
egress_queue_roots: vec![],
fees: 0,
block_data_hash: Default::default(),
upward_messages: upward_messages.into_iter()
.map(|x| UpwardMessage { origin: x.0, data: x.1 })
.collect(),
}
}
}
#[test]
fn check_dispatch_upward_works() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
(2u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains.clone()), || {
let parachains = vec![0.into(), 1.into(), 2.into()];
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![0; 4] }
]);
Parachains::queue_upward_messages(1.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![1; 4] }
]);
let mut dispatched: Vec<(ParaId, ParachainDispatchOrigin, Vec<u8>)> = vec![];
let dummy = |id, origin, data: &[u8]| dispatched.push((id, origin, data.to_vec()));
Parachains::dispatch_upward_messages(0, ¶chains, 2, 3, dummy);
assert_eq!(dispatched, vec![
(0.into(), ParachainDispatchOrigin::Parachain, vec![0; 4])
]);
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(0)).is_empty());
assert_eq!(<RelayDispatchQueue<Test>>::get(ParaId::from(1)).len(), 1);
});
with_externalities(&mut new_test_ext(parachains.clone()), || {
let parachains = vec![0.into(), 1.into(), 2.into()];
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![0; 2] }
]);
Parachains::queue_upward_messages(1.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![1; 2] }
]);
Parachains::queue_upward_messages(2.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![2] }
]);
let mut dispatched: Vec<(ParaId, ParachainDispatchOrigin, Vec<u8>)> = vec![];
let dummy = |id, origin, data: &[u8]| dispatched.push((id, origin, data.to_vec()));
Parachains::dispatch_upward_messages(0, ¶chains, 2, 3, dummy);
assert_eq!(dispatched, vec![
(0.into(), ParachainDispatchOrigin::Parachain, vec![0; 2]),
(2.into(), ParachainDispatchOrigin::Parachain, vec![2])
]);
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(0)).is_empty());
assert_eq!(<RelayDispatchQueue<Test>>::get(ParaId::from(1)).len(), 1);
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(2)).is_empty());
});
with_externalities(&mut new_test_ext(parachains.clone()), || {
let parachains = vec![0.into(), 1.into(), 2.into()];
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![0; 2] }
]);
Parachains::queue_upward_messages(1.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![1; 2] }
]);
Parachains::queue_upward_messages(2.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![2] }
]);
let mut dispatched: Vec<(ParaId, ParachainDispatchOrigin, Vec<u8>)> = vec![];
let dummy = |id, origin, data: &[u8]| dispatched.push((id, origin, data.to_vec()));
Parachains::dispatch_upward_messages(1, ¶chains, 2, 3, dummy);
assert_eq!(dispatched, vec![
(1.into(), ParachainDispatchOrigin::Parachain, vec![1; 2]),
(2.into(), ParachainDispatchOrigin::Parachain, vec![2])
]);
assert_eq!(<RelayDispatchQueue<Test>>::get(ParaId::from(0)).len(), 1);
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(1)).is_empty());
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(2)).is_empty());
});
with_externalities(&mut new_test_ext(parachains.clone()), || {
let parachains = vec![0.into(), 1.into(), 2.into()];
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![0; 2] }
]);
Parachains::queue_upward_messages(1.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![1; 2] }
]);
Parachains::queue_upward_messages(2.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![2] }
]);
let mut dispatched: Vec<(ParaId, ParachainDispatchOrigin, Vec<u8>)> = vec![];
let dummy = |id, origin, data: &[u8]| dispatched.push((id, origin, data.to_vec()));
Parachains::dispatch_upward_messages(2, ¶chains, 2, 3, dummy);
assert_eq!(dispatched, vec![
(2.into(), ParachainDispatchOrigin::Parachain, vec![2]),
(0.into(), ParachainDispatchOrigin::Parachain, vec![0; 2])
]);
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(0)).is_empty());
assert_eq!(<RelayDispatchQueue<Test>>::get(ParaId::from(1)).len(), 1);
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(2)).is_empty());
});
}
#[test]
fn check_queue_upward_messages_works() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0] }
];
assert_ok!(Parachains::check_upward_messages(0.into(), &messages, 2, 3));
// all good.
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0] },
]);
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![1, 2] }
];
assert_ok!(Parachains::check_upward_messages(0.into(), &messages, 2, 3));
Parachains::queue_upward_messages(0.into(), &messages);
assert_eq!(<RelayDispatchQueue<Test>>::get(ParaId::from(0)), vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0] },
UpwardMessage { origin: ParachainDispatchOrigin::Parachain, data: vec![1, 2] },
]);
});
}
#[test]
fn check_queue_full_upward_messages_fails() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// oversize, but ok since it's just one and the queue is empty.
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0; 4] },
];
assert_ok!(Parachains::check_upward_messages(0.into(), &messages, 2, 3));
// oversize and bad since it's not just one.
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0] },
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0; 4] },
];
assert_err!(
Parachains::check_upward_messages(0.into(), &messages, 2, 3),
"Messages added when queue full"
);
// too many messages.
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0] },
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![1] },
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![2] },
];
assert_err!(
Parachains::check_upward_messages(0.into(), &messages, 2, 3),
"Messages added when queue full"
);
});
}
#[test]
fn check_queued_too_many_upward_messages_fails() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// too many messages.
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0] },
]);
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![1] },
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![2] },
];
assert_err!(
Parachains::check_upward_messages(0.into(), &messages, 2, 3),
"Messages added when queue full"
);
});
}
#[test]
fn check_queued_total_oversize_upward_messages_fails() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// too much data.
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0, 1] },
]);
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![2, 3] },
];
assert_err!(
Parachains::check_upward_messages(0.into(), &messages, 2, 3),
"Messages added when queue full"
);
});
}
#[test]
fn check_queued_pre_jumbo_upward_messages_fails() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// bad - already an oversize messages queued.
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0; 4] },
]);
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0] }
];
assert_err!(
Parachains::check_upward_messages(0.into(), &messages, 2, 3),
"Messages added when queue full"
);
});
}
#[test]
fn check_queued_post_jumbo_upward_messages_fails() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// bad - oversized and already a message queued.
Parachains::queue_upward_messages(0.into(), &vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0] },
]);
let messages = vec![
UpwardMessage { origin: ParachainDispatchOrigin::Signed, data: vec![0; 4] }
];
assert_err!(
Parachains::check_upward_messages(0.into(), &messages, 2, 3),
"Messages added when queue full"
);
});
}
#[test]
fn upward_queuing_works() {
// That the list of egress queue roots is in ascending order by `ParaId`.
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// parachain 0 is self
let mut candidates = vec![
new_candidate_with_upward_messages(0, vec![
(ParachainDispatchOrigin::Signed, vec![1]),
]),
new_candidate_with_upward_messages(1, vec![
(ParachainDispatchOrigin::Parachain, vec![2]),
])
];
candidates.iter_mut().for_each(make_attestations);
assert_ok!(Parachains::dispatch(
set_heads(candidates),
Origin::NONE,
));
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(0)).is_empty());
assert!(<RelayDispatchQueue<Test>>::get(ParaId::from(1)).is_empty());
});
}
fn active_parachains_should_work() {
let parachains = vec![
asynchronous rob
committed
(5u32.into(), vec![1,2,3], vec![1]),
(100u32.into(), vec![4,5,6], vec![2]),
];
with_externalities(&mut new_test_ext(parachains), || {
assert_eq!(Parachains::active_parachains(), vec![5u32.into(), 100u32.into()]);
assert_eq!(Parachains::parachain_code(&5u32.into()), Some(vec![1,2,3]));
assert_eq!(Parachains::parachain_code(&100u32.into()), Some(vec![4,5,6]));
});
}
#[test]
fn register_deregister() {
let parachains = vec![
asynchronous rob
committed
(5u32.into(), vec![1,2,3], vec![1]),
(100u32.into(), vec![4,5,6], vec![2,]),
];
with_externalities(&mut new_test_ext(parachains), || {
assert_eq!(Parachains::active_parachains(), vec![5u32.into(), 100u32.into()]);
assert_eq!(Parachains::parachain_code(&5u32.into()), Some(vec![1,2,3]));
assert_eq!(Parachains::parachain_code(&100u32.into()), Some(vec![4,5,6]));
assert_ok!(Parachains::register_parachain(99u32.into(), vec![7,8,9], vec![1, 1, 1]));
assert_eq!(Parachains::active_parachains(), vec![5u32.into(), 99u32.into(), 100u32.into()]);
assert_eq!(Parachains::parachain_code(&99u32.into()), Some(vec![7,8,9]));
assert_ok!(Parachains::deregister_parachain(5u32.into()));
assert_eq!(Parachains::active_parachains(), vec![99u32.into(), 100u32.into()]);
assert_eq!(Parachains::parachain_code(&5u32.into()), None);
});
}
#[test]
fn duty_roster_works() {
let parachains = vec![
asynchronous rob
committed
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
let check_roster = |duty_roster: &DutyRoster| {
assert_eq!(duty_roster.validator_duty.len(), 8);
for i in (0..2).map(ParaId::from) {
assert_eq!(duty_roster.validator_duty.iter().filter(|&&j| j == Chain::Parachain(i)).count(), 3);
}
assert_eq!(duty_roster.validator_duty.iter().filter(|&&j| j == Chain::Relay).count(), 2);
};
let duty_roster_0 = Parachains::calculate_duty_roster();
check_roster(&duty_roster_0);
System::initialize(&1, &H256::from([1; 32]), &Default::default(), &Default::default());
let duty_roster_1 = Parachains::calculate_duty_roster();
check_roster(&duty_roster_1);
assert!(duty_roster_0 != duty_roster_1);
System::initialize(&2, &H256::from([2; 32]), &Default::default(), &Default::default());
let duty_roster_2 = Parachains::calculate_duty_roster();
check_roster(&duty_roster_2);
assert!(duty_roster_0 != duty_roster_2);
assert!(duty_roster_1 != duty_roster_2);
});
}
#[test]
fn unattested_candidate_is_rejected() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
let candidate = AttestedCandidate {
validity_votes: vec![],
candidate: CandidateReceipt {
parachain_index: 0.into(),
collator: Default::default(),
signature: Default::default(),
head_data: HeadData(vec![1, 2, 3]),
egress_queue_roots: vec![],
fees: 0,
block_data_hash: Default::default(),
assert!(Parachains::dispatch(set_heads(vec![candidate]), Origin::NONE).is_err());
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
})
}
#[test]
fn attested_candidates_accepted_in_order() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
let mut candidate_a = AttestedCandidate {
validity_votes: vec![],
candidate: CandidateReceipt {
parachain_index: 0.into(),
collator: Default::default(),
signature: Default::default(),
head_data: HeadData(vec![1, 2, 3]),
egress_queue_roots: vec![],
fees: 0,
block_data_hash: Default::default(),
}
};
let mut candidate_b = AttestedCandidate {
validity_votes: vec![],
candidate: CandidateReceipt {
parachain_index: 1.into(),
collator: Default::default(),
signature: Default::default(),
head_data: HeadData(vec![2, 3, 4]),
egress_queue_roots: vec![],
fees: 0,
block_data_hash: Default::default(),
}
};
make_attestations(&mut candidate_a);
make_attestations(&mut candidate_b);
assert!(Parachains::dispatch(
set_heads(vec![candidate_b.clone(), candidate_a.clone()]),
).is_err());
assert!(Parachains::dispatch(
set_heads(vec![candidate_a.clone(), candidate_b.clone()]),
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
).is_ok());
});
}
#[test]
fn duplicate_vote_is_rejected() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
let mut candidate = AttestedCandidate {
validity_votes: vec![],
candidate: CandidateReceipt {
parachain_index: 0.into(),
collator: Default::default(),
signature: Default::default(),
head_data: HeadData(vec![1, 2, 3]),
egress_queue_roots: vec![],
fees: 0,
block_data_hash: Default::default(),
}
};
make_attestations(&mut candidate);
let mut double_validity = candidate.clone();
double_validity.validity_votes.push(candidate.validity_votes[0].clone());
assert!(Parachains::dispatch(
set_heads(vec![double_validity]),
).is_err());
});
}
#[test]
fn ingress_works() {
use sr_primitives::traits::OnFinalize;
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
(99u32.into(), vec![1, 2, 3], vec![4, 5, 6]),
];
with_externalities(&mut new_test_ext(parachains), || {
assert_eq!(Parachains::ingress(ParaId::from(1)), Some(Vec::new()));
assert_eq!(Parachains::ingress(ParaId::from(99)), Some(Vec::new()));
for i in 1..10 {
System::set_block_number(i);
let from_a = vec![(1.into(), [i as u8; 32].into())];
let mut candidate_a = AttestedCandidate {
validity_votes: vec![],
candidate: CandidateReceipt {
parachain_index: 0.into(),
collator: Default::default(),
signature: Default::default(),
head_data: HeadData(vec![1, 2, 3]),
egress_queue_roots: from_a.clone(),
fees: 0,
block_data_hash: Default::default(),
upward_messages: vec![],
}
};
let from_b = vec![(99.into(), [i as u8; 32].into())];
let mut candidate_b = AttestedCandidate {
validity_votes: vec![],
candidate: CandidateReceipt {
parachain_index: 1.into(),
collator: Default::default(),
signature: Default::default(),
head_data: HeadData(vec![1, 2, 3]),
egress_queue_roots: from_b.clone(),
fees: 0,
block_data_hash: Default::default(),
upward_messages: vec![],
}
};
make_attestations(&mut candidate_a);
make_attestations(&mut candidate_b);
assert!(Parachains::dispatch(
set_heads(vec![candidate_a, candidate_b]),
Origin::NONE,
).is_ok());
Parachains::on_finalize(i);
}
System::set_block_number(10);
set_heads(vec![]),
// parachain 1 has had a bunch of parachain candidates included,
// which raises the watermark.
assert_eq!(
Parachains::ingress(ParaId::from(1)),
Some(vec![
(9, BlockIngressRoots(vec![
(0.into(), [9; 32].into())
]))
]),
// parachain 99 hasn't had any candidates included, so the
// ingress is piling up.
assert_eq!(
Parachains::ingress(ParaId::from(99)),
Some((1..10).map(|i| (i, BlockIngressRoots(
vec![(1.into(), [i as u8; 32].into())]
))).collect::<Vec<_>>()),
);
assert_ok!(Parachains::deregister_parachain(1u32.into()));
// after deregistering, there is no ingress to 1, but unrouted messages
// from 1 stick around.
assert_eq!(Parachains::ingress(ParaId::from(1)), None);
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
assert_eq!(Parachains::ingress(ParaId::from(99)), Some((1..10).map(|i| (i, BlockIngressRoots(
vec![(1.into(), [i as u8; 32].into())]
))).collect::<Vec<_>>()));
Parachains::on_finalize(10);
System::set_block_number(11);
let mut candidate_c = AttestedCandidate {
validity_votes: vec![],
candidate: CandidateReceipt {
parachain_index: 99.into(),
collator: Default::default(),
signature: Default::default(),
head_data: HeadData(vec![1, 2, 3]),
egress_queue_roots: Vec::new(),
fees: 0,
block_data_hash: Default::default(),
upward_messages: vec![],
}
};
make_attestations(&mut candidate_c);
assert!(Parachains::dispatch(
set_heads(vec![candidate_c]),
Origin::NONE,
).is_ok());
Parachains::on_finalize(11);
System::set_block_number(12);
// at the next block, ingress to 99 should be empty.
assert_eq!(Parachains::ingress(ParaId::from(99)), Some(Vec::new()));
});
}
#[test]
fn egress_routed_to_non_existent_parachain_is_rejected() {
// That no parachain is routed to which doesn't exist
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// parachain 99 does not exist
let non_existent = vec![(99.into(), [1; 32].into())];
let mut candidate = new_candidate_with_egress_roots(non_existent);
make_attestations(&mut candidate);
let result = Parachains::dispatch(
set_heads(vec![candidate.clone()]),
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
);
assert_eq!(Err("Routing to non-existent parachain"), result);
});
}
#[test]
fn egress_routed_to_self_is_rejected() {
// That the parachain doesn't route to self
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// parachain 0 is self
let to_self = vec![(0.into(), [1; 32].into())];
let mut candidate = new_candidate_with_egress_roots(to_self);
make_attestations(&mut candidate);
let result = Parachains::dispatch(
set_heads(vec![candidate.clone()]),
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
);
assert_eq!(Err("Parachain routing to self"), result);
});
}
#[test]
fn egress_queue_roots_out_of_order_rejected() {
// That the list of egress queue roots is in ascending order by `ParaId`.
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// parachain 0 is self
let out_of_order = vec![(1.into(), [1; 32].into()), ((0.into(), [1; 32].into()))];
let mut candidate = new_candidate_with_egress_roots(out_of_order);
make_attestations(&mut candidate);
let result = Parachains::dispatch(
set_heads(vec![candidate.clone()]),
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
);
assert_eq!(Err("Egress routes out of order by ID"), result);
});
}
#[test]
fn egress_queue_roots_empty_trie_roots_rejected() {
let parachains = vec![
(0u32.into(), vec![], vec![]),
(1u32.into(), vec![], vec![]),
(2u32.into(), vec![], vec![]),
];
with_externalities(&mut new_test_ext(parachains), || {
// parachain 0 is self
let contains_empty_trie_root = vec![(1.into(), [1; 32].into()), ((2.into(), EMPTY_TRIE_ROOT.into()))];
let mut candidate = new_candidate_with_egress_roots(contains_empty_trie_root);
make_attestations(&mut candidate);
let result = Parachains::dispatch(
set_heads(vec![candidate.clone()]),
);
assert_eq!(Err("Empty trie root included"), result);
});
}
#[test]
fn empty_trie_root_const_is_blake2_hashed_null_node() {
let hashed_null_node = <NodeCodec<Blake2Hasher> as trie_db::NodeCodec<Blake2Hasher>>::hashed_null_node();
assert_eq!(hashed_null_node, EMPTY_TRIE_ROOT.into())
}