Skip to content

Commit

Permalink
asset-registry: added test to check name and symblo length
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfridrich committed Oct 19, 2023
1 parent 2250a3a commit ca681e6
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 2 deletions.
60 changes: 60 additions & 0 deletions pallets/asset-registry/src/tests/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,63 @@ fn register_external_asset_should_not_work_when_user_cant_pay_storage_fees() {
);
});
}

#[test]
fn register_should_fail_when_name_is_too_long() {
ExtBuilder::default().build().execute_with(|| {
let asset_id = 1;
let name = vec![97u8; <Test as crate::Config>::StringLimit::get() as usize + 1];
let symbol = b"TKN".to_vec();
let decimals = 12;
let xcm_rate_limit = 1_000;
let ed = 10_000;
let is_sufficient = true;

let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap());
let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key)));

//Act
assert_noop!(Registry::register(
RuntimeOrigin::root(),
Some(asset_id),
Some(name.clone()),
AssetType::Token,
Some(ed),
Some(symbol.clone()),
Some(decimals),
Some(asset_location.clone()),
Some(xcm_rate_limit),
is_sufficient
), Error::<Test>::TooLong);
});
}

#[test]
fn register_should_fail_when_symbol_is_too_long() {
ExtBuilder::default().build().execute_with(|| {
let asset_id = 1;
let name = b"Test asset".to_vec();
let symbol = vec![97u8; <Test as crate::Config>::StringLimit::get() as usize + 1];
let decimals = 12;
let xcm_rate_limit = 1_000;
let ed = 10_000;
let is_sufficient = true;

let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap());
let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key)));

//Act
assert_noop!(Registry::register(
RuntimeOrigin::root(),
Some(asset_id),
Some(name.clone()),
AssetType::Token,
Some(ed),
Some(symbol.clone()),
Some(decimals),
Some(asset_location.clone()),
Some(xcm_rate_limit),
is_sufficient
), Error::<Test>::TooLong);
});
}
71 changes: 69 additions & 2 deletions pallets/asset-registry/src/tests/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fn update_origin_should_set_decimals_if_its_none() {

let details_0 = Registry::assets(asset_id).unwrap();

//NOTE: update origin is ste to ensure_signed
//NOTE: update origin is set to ensure_signed
//Act
assert_ok!(Registry::update(
RuntimeOrigin::signed(ALICE),
Expand Down Expand Up @@ -344,7 +344,6 @@ fn create_origin_should_always_set_decimals() {

let details_0 = Registry::assets(asset_id).unwrap();

//NOTE: update origin is ste to ensure_signed
//Act
assert_ok!(Registry::update(
RuntimeOrigin::root(),
Expand Down Expand Up @@ -615,3 +614,71 @@ fn update_should_not_work_when_name_is_same_as_old() {
);
});
}

#[test]
fn update_should_fail_when_name_is_too_long() {
ExtBuilder::default()
.with_assets(vec![
(Some(1), Some(b"Tkn1".to_vec()), UNIT, None, None, None, true),
(Some(2), Some(b"Tkn2".to_vec()), UNIT, None, None, None, true),
(Some(3), Some(b"Tkn3".to_vec()), UNIT, None, None, None, true),
])
.build()
.execute_with(|| {
let asset_id = 2;
let name = vec![97u8; <Test as crate::Config>::StringLimit::get() as usize + 1];
let ed = 10_000 * UNIT;
let xcm_rate_limit = 463;
let symbol = b"nTkn2".to_vec();
let decimals = 23;
let is_sufficient = false;

//Act
assert_noop!(Registry::update(
RuntimeOrigin::root(),
asset_id,
Some(name.clone()),
Some(AssetType::External),
Some(ed),
Some(xcm_rate_limit),
Some(is_sufficient),
Some(symbol.clone()),
Some(decimals),
None
), Error::<Test>::TooLong);
});
}

#[test]
fn update_should_fail_when_symbolis_too_long() {
ExtBuilder::default()
.with_assets(vec![
(Some(1), Some(b"Tkn1".to_vec()), UNIT, None, None, None, true),
(Some(2), Some(b"Tkn2".to_vec()), UNIT, None, None, None, true),
(Some(3), Some(b"Tkn3".to_vec()), UNIT, None, None, None, true),
])
.build()
.execute_with(|| {
let asset_id = 2;
let name = b"New Token Name".to_vec();
let ed = 10_000 * UNIT;
let xcm_rate_limit = 463;
let symbol = vec![97u8; <Test as crate::Config>::StringLimit::get() as usize + 1];
let decimals = 23;
let is_sufficient = false;

//Act
assert_noop!(Registry::update(
RuntimeOrigin::root(),
asset_id,
Some(name.clone()),
Some(AssetType::External),
Some(ed),
Some(xcm_rate_limit),
Some(is_sufficient),
Some(symbol.clone()),
Some(decimals),
None
), Error::<Test>::TooLong);
});
}

0 comments on commit ca681e6

Please sign in to comment.