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

difftreelog

CORE-302 Fix shema => schema

Trubnikov Sergey2022-04-27parent: #4647586.patch.diff
in: master

6 files changed

modifiedpallets/evm-collection/src/eth.rsdiffbeforeafterboth
130 Ok(())130 Ok(())
131 }131 }
132132
133 fn set_offchain_shema(133 fn set_offchain_schema(
134 &self,134 &self,
135 caller: caller,135 caller: caller,
136 collection_address: address,136 collection_address: address,
137 shema: string,137 schema: string,
138 ) -> Result<void> {138 ) -> Result<void> {
139 let mut collection = collection_from_address(collection_address, &self.0)?;139 let mut collection = collection_from_address(collection_address, &self.0)?;
140 check_is_owner(caller, &collection)?;140 check_is_owner(caller, &collection)?;
141141
142 let shema = shema142 let schema = schema
143 .into_bytes()143 .into_bytes()
144 .try_into()144 .try_into()
145 .map_err(|_| error_feild_too_long(stringify!(shema), OFFCHAIN_SCHEMA_LIMIT))?;145 .map_err(|_| error_feild_too_long(stringify!(shema), OFFCHAIN_SCHEMA_LIMIT))?;
146 // collection.offchain_schema = shema;146 // collection.offchain_schema = schema;
147 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;147 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
148 Ok(())148 Ok(())
149 }149 }
modifiedpallets/evm-collection/src/stubs/Collection.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/evm-collection/src/stubs/Collection.soldiffbeforeafterboth
21 }21 }
22}22}
2323
24// Selector: 037b69c824// Selector: f83ad95b
25contract Collection is Dummy, ERC165 {25contract Collection is Dummy, ERC165 {
26 // Selector: create721Collection(string,string,string) 951c015126 // Selector: create721Collection(string,string,string) 951c0151
27 function create721Collection(27 function create721Collection(
55 dummy;55 dummy;
56 }56 }
5757
58 // Selector: setOffchainShema(address,string) d7dc2de358 // Selector: setOffchainSchema(address,string) 2c9d9d70
59 function setOffchainShema(address collectionAddress, string memory shema)59 function setOffchainSchema(address collectionAddress, string memory shema)
60 public60 public
61 view61 view
62 {62 {
modifiedtests/src/eth/api/Collection.soldiffbeforeafterboth
12 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);
13}13}
1414
15// Selector: 037b69c815// Selector: f83ad95b
16interface Collection is Dummy, ERC165 {16interface Collection is Dummy, ERC165 {
17 // Selector: create721Collection(string,string,string) 951c015117 // Selector: create721Collection(string,string,string) 951c0151
18 function create721Collection(18 function create721Collection(
29 // Selector: confirmSponsorship(address) abc0000129 // Selector: confirmSponsorship(address) abc00001
30 function confirmSponsorship(address collectionAddress) external view;30 function confirmSponsorship(address collectionAddress) external view;
3131
32 // Selector: setOffchainShema(address,string) d7dc2de332 // Selector: setOffchainSchema(address,string) 2c9d9d70
33 function setOffchainShema(address collectionAddress, string memory shema)33 function setOffchainSchema(address collectionAddress, string memory shema)
34 external34 external
35 view;35 view;
3636
modifiedtests/src/eth/collectionAbi.jsondiffbeforeafterboth
60 },60 },
61 { "internalType": "string", "name": "shema", "type": "string" }61 { "internalType": "string", "name": "shema", "type": "string" }
62 ],62 ],
63 "name": "setOffchainShema",63 "name": "setOffchainSchema",
64 "outputs": [],64 "outputs": [],
65 "stateMutability": "view",65 "stateMutability": "view",
66 "type": "function"66 "type": "function"
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
79 expect(collection.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));79 expect(collection.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
80 });80 });
81 81
82 itWeb3('Set offchain shema', async ({api, web3}) => {82 itWeb3('Set offchain schema', async ({api, web3}) => {
83 const owner = await createEthAccountWithBalance(api, web3);83 const owner = await createEthAccountWithBalance(api, web3);
84 const helper = collectionHelper(web3, owner);84 const helper = collectionHelper(web3, owner);
85 let result = await helper.methods.create721Collection('Shema collection', '2', '2').send();85 let result = await helper.methods.create721Collection('Schema collection', '2', '2').send();
86 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);86 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
87 const shema = 'Some shema';87 const schema = 'Some schema';
88 result = await helper.methods.setOffchainShema(collectionIdAddress, shema).send();88 result = await helper.methods.setOffchainSchema(collectionIdAddress, schema).send();
89 const collection = (await getDetailedCollectionInfo(api, collectionId))!;89 const collection = (await getDetailedCollectionInfo(api, collectionId))!;
90 expect(collection.offchainSchema.toHuman()).to.be.eq(shema);90 expect(collection.offchainSchema.toHuman()).to.be.eq(schema);
91 });91 });
92 92
93 itWeb3('Set variable on chain schema', async ({api, web3}) => {93 itWeb3('Set variable on chain schema', async ({api, web3}) => {
106 const helper = collectionHelper(web3, owner);106 const helper = collectionHelper(web3, owner);
107 let result = await helper.methods.create721Collection('Const collection', '4', '4').send();107 let result = await helper.methods.create721Collection('Const collection', '4', '4').send();
108 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);108 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
109 const constShema = 'Some const';109 const constSchema = 'Some const';
110 result = await helper.methods.setConstOnChainSchema(collectionIdAddress, constShema).send();110 result = await helper.methods.setConstOnChainSchema(collectionIdAddress, constSchema).send();
111 const collection = (await getDetailedCollectionInfo(api, collectionId))!;111 const collection = (await getDetailedCollectionInfo(api, collectionId))!;
112 expect(collection.constOnChainSchema.toHuman()).to.be.eq(constShema);112 expect(collection.constOnChainSchema.toHuman()).to.be.eq(constSchema);
113 });113 });
114114
115 itWeb3('Set limits', async ({api, web3}) => {115 itWeb3('Set limits', async ({api, web3}) => {
178 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');178 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
179179
180 // TODO: this wont work right now, need release 919000 first180 // TODO: this wont work right now, need release 919000 first
181 // await helper.methods.setOffchainShema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();181 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
182 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();182 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
183 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);183 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
184 });184 });
248 .call()).to.be.rejectedWith(EXPECTED_ERROR);248 .call()).to.be.rejectedWith(EXPECTED_ERROR);
249 }249 }
250 {250 {
251 const shema = 'Some shema';251 const schema = 'Some schema';
252 await expect(helper.methods252 await expect(helper.methods
253 .setOffchainShema(collectionAddressWithBadPrefix, shema)253 .setOffchainSchema(collectionAddressWithBadPrefix, schema)
254 .call()).to.be.rejectedWith(EXPECTED_ERROR);254 .call()).to.be.rejectedWith(EXPECTED_ERROR);
255 }255 }
256 {256 {
293 .call()).to.be.rejectedWith('Caller is not set as sponsor');293 .call()).to.be.rejectedWith('Caller is not set as sponsor');
294 }294 }
295 {295 {
296 const shema = 'Some shema';296 const schema = 'Some schema';
297 await expect(helperFromNotOwner.methods297 await expect(helperFromNotOwner.methods
298 .setOffchainShema(collectionIdAddress, shema)298 .setOffchainSchema(collectionIdAddress, schema)
299 .call()).to.be.rejectedWith(EXPECTED_ERROR);299 .call()).to.be.rejectedWith(EXPECTED_ERROR);
300 }300 }
301 {301 {
318 }318 }
319 });319 });
320320
321 itWeb3('(!negative test!) Set offchain shema (length limit)', async ({api, web3}) => {321 itWeb3('(!negative test!) Set offchain schema (length limit)', async ({api, web3}) => {
322 const owner = await createEthAccountWithBalance(api, web3);322 const owner = await createEthAccountWithBalance(api, web3);
323 const helper = collectionHelper(web3, owner);323 const helper = collectionHelper(web3, owner);
324 const result = await helper.methods.create721Collection('Shema collection', 'A', 'A').send();324 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();
325 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);325 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
326 const OFFCHAIN_SCHEMA_LIMIT = 8192;326 const OFFCHAIN_SCHEMA_LIMIT = 8192;
327 const shema = 'A'.repeat(OFFCHAIN_SCHEMA_LIMIT + 1);327 const schema = 'A'.repeat(OFFCHAIN_SCHEMA_LIMIT + 1);
328 await expect(helper.methods328 await expect(helper.methods
329 .setOffchainShema(collectionIdAddress, shema)329 .setOffchainSchema(collectionIdAddress, schema)
330 .call()).to.be.rejectedWith('shema is too long. Max length is ' + OFFCHAIN_SCHEMA_LIMIT);330 .call()).to.be.rejectedWith('schema is too long. Max length is ' + OFFCHAIN_SCHEMA_LIMIT);
331 });331 });
332332
333 itWeb3('(!negative test!) Set variable on chain schema (length limit)', async ({api, web3}) => {333 itWeb3('(!negative test!) Set variable on chain schema (length limit)', async ({api, web3}) => {
334 const owner = await createEthAccountWithBalance(api, web3);334 const owner = await createEthAccountWithBalance(api, web3);
335 const helper = collectionHelper(web3, owner);335 const helper = collectionHelper(web3, owner);
336 const result = await helper.methods.create721Collection('Shema collection', 'A', 'A').send();336 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();
337 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);337 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
338 const VARIABLE_ON_CHAIN_SCHEMA_LIMIT = 8192;338 const VARIABLE_ON_CHAIN_SCHEMA_LIMIT = 8192;
339 const variable = 'A'.repeat(VARIABLE_ON_CHAIN_SCHEMA_LIMIT + 1);339 const variable = 'A'.repeat(VARIABLE_ON_CHAIN_SCHEMA_LIMIT + 1);
345 itWeb3('(!negative test!) Set const on chain schema (length limit)', async ({api, web3}) => {345 itWeb3('(!negative test!) Set const on chain schema (length limit)', async ({api, web3}) => {
346 const owner = await createEthAccountWithBalance(api, web3);346 const owner = await createEthAccountWithBalance(api, web3);
347 const helper = collectionHelper(web3, owner);347 const helper = collectionHelper(web3, owner);
348 const result = await helper.methods.create721Collection('Shema collection', 'A', 'A').send();348 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();
349 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);349 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
350 const CONST_ON_CHAIN_SCHEMA_LIMIT = 32768;350 const CONST_ON_CHAIN_SCHEMA_LIMIT = 32768;
351 const constData = 'A'.repeat(CONST_ON_CHAIN_SCHEMA_LIMIT + 1);351 const constData = 'A'.repeat(CONST_ON_CHAIN_SCHEMA_LIMIT + 1);
357 itWeb3('(!negative test!) Set limits', async ({api, web3}) => {357 itWeb3('(!negative test!) Set limits', async ({api, web3}) => {
358 const owner = await createEthAccountWithBalance(api, web3);358 const owner = await createEthAccountWithBalance(api, web3);
359 const helper = collectionHelper(web3, owner);359 const helper = collectionHelper(web3, owner);
360 const result = await helper.methods.create721Collection('Shema collection', 'A', 'A').send();360 const result = await helper.methods.create721Collection('Schema collection', 'A', 'A').send();
361 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);361 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
362 const badJson = '{accountTokenOwnershipLimit: 1000}';362 const badJson = '{accountTokenOwnershipLimit: 1000}';
363 await expect(helper.methods363 await expect(helper.methods