git.delta.rocks / unique-network / refs/commits / d855cf844d12

difftreelog

NFTPAR-142: Off-chain and on-chain data schema. Fixed tests. Added negative set variable metadata test for out of limits data.

sotmorskiy2020-12-03parent: #7ff8498.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
321 /// Unexpected collection type.321 /// Unexpected collection type.
322 UnexpectedCollectionType,322 UnexpectedCollectionType,
323 /// Can't store metadata in fungible tokens.323 /// Can't store metadata in fungible tokens.
324 CantSotreMetadataInFungibleTokens324 CantStoreMetadataInFungibleTokens
325 }325 }
326}326}
327327
1194 1194
1195 Self::collection_exists(collection_id)?;1195 Self::collection_exists(collection_id)?;
1196
1197 ensure!(ChainLimit::get().custom_data_limit >= data.len() as u32, Error::<T>::TokenVariableDataLimitExceeded);
11961198
1197 // Modify permissions check1199 // Modify permissions check
1198 let target_collection = <Collection<T>>::get(collection_id);1200 let target_collection = <Collection<T>>::get(collection_id);
1206 {1208 {
1207 CollectionMode::NFT => Self::set_nft_variable_data(collection_id, item_id, data)?,1209 CollectionMode::NFT => Self::set_nft_variable_data(collection_id, item_id, data)?,
1208 CollectionMode::ReFungible(_) => Self::set_re_fungible_variable_data(collection_id, item_id, data)?,1210 CollectionMode::ReFungible(_) => Self::set_re_fungible_variable_data(collection_id, item_id, data)?,
1209 CollectionMode::Fungible(_) => fail!(Error::<T>::CantSotreMetadataInFungibleTokens),1211 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),
1210 _ => fail!(Error::<T>::UnexpectedCollectionType)1212 _ => fail!(Error::<T>::UnexpectedCollectionType)
1211 };1213 };
12121214
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
1725 collection_id,1725 collection_id,
1726 1,1726 1,
1727 too_big_const_data1727 too_big_const_data
1728 ), "const_data exceeded data limit.");1728 ), Error::<Test>::TokenConstDataLimitExceeded);
1729 });1729 });
1730}1730}
17311731
1756 collection_id,1756 collection_id,
1757 1,1757 1,
1758 too_big_const_data1758 too_big_const_data
1759 ), "variable_data exceeded data limit.");1759 ), Error::<Test>::TokenVariableDataLimitExceeded);
1760 });1760 });
1761}1761}
17621762
1787 collection_id,1787 collection_id,
1788 1,1788 1,
1789 too_big_const_data1789 too_big_const_data
1790 ), "const_data exceeded data limit.");1790 ), Error::<Test>::TokenConstDataLimitExceeded);
1791 });1791 });
1792}1792}
17931793
1818 collection_id,1818 collection_id,
1819 1,1819 1,
1820 too_big_const_data1820 too_big_const_data
1821 ), "variable_data exceeded data limit.");1821 ), Error::<Test>::TokenVariableDataLimitExceeded);
1822 });1822 });
1823}1823}
1824// #endregion1824// #endregion
1905 create_test_item(1, &data.into());1905 create_test_item(1, &data.into());
19061906
1907 let variable_data = b"test set_variable_meta_data method.".to_vec();1907 let variable_data = b"test set_variable_meta_data method.".to_vec();
1908 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()), "Can't store metadata in fungible tokens.");1908 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()), Error::<Test>::CantStoreMetadataInFungibleTokens);
1909 });1909 });
1910}1910}
1911
1912#[test]
1913fn set_variable_meta_data_on_nft_token_fails_for_big_data() {
1914 new_test_ext().execute_with(|| {
1915 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits {
1916 collection_numbers_limit: default_collection_numbers_limit(),
1917 account_token_ownership_limit: 10,
1918 collections_admins_limit: 5,
1919 custom_data_limit: 10,
1920 nft_sponsor_transfer_timeout: 15,
1921 fungible_sponsor_transfer_timeout: 15,
1922 refungible_sponsor_transfer_timeout: 15,
1923 }));
1924
1925 let collection_id = create_test_collection(&CollectionMode::NFT, 1);
1926
1927 let origin1 = Origin::signed(1);
1928
1929 let data = default_nft_data();
1930 create_test_item(1, &data.into());
1931
1932 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
1933 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);
1934 });
1935}
1936
1937#[test]
1938fn set_variable_meta_data_on_re_fungible_token_fails_for_big_data() {
1939 new_test_ext().execute_with(|| {
1940 assert_ok!(TemplateModule::set_chain_limits(RawOrigin::Root.into(), ChainLimits {
1941 collection_numbers_limit: default_collection_numbers_limit(),
1942 account_token_ownership_limit: 10,
1943 collections_admins_limit: 5,
1944 custom_data_limit: 10,
1945 nft_sponsor_transfer_timeout: 15,
1946 fungible_sponsor_transfer_timeout: 15,
1947 refungible_sponsor_transfer_timeout: 15,
1948 }));
1949
1950
1951 let collection_id = create_test_collection(&CollectionMode::ReFungible(3), 1);
1952
1953 let origin1 = Origin::signed(1);
1954
1955 let data = default_re_fungible_data();
1956 create_test_item(1, &data.into());
1957
1958 let variable_data = b"test set_variable_meta_data method, bigger than limits.".to_vec();
1959 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data), Error::<Test>::TokenVariableDataLimitExceeded);
1960 });
1961}
1962