difftreelog
feature: add `createERC721MetadataCompatibleRFTCollection` method
in: master
4 files changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth237 Ok(address)237 Ok(address)238 }238 }239240 #[weight(<SelfWeightOf<T>>::create_collection())]241 #[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]242 fn create_refungible_collection_with_properties(243 &mut self,244 caller: caller,245 name: string,246 description: string,247 token_prefix: string,248 base_uri: string,249 ) -> Result<address> {250 let (caller, name, description, token_prefix, base_uri_value) =251 convert_data::<T>(caller, name, description, token_prefix, base_uri)?;252 let data = make_data::<T>(253 name,254 CollectionMode::NFT,255 description,256 token_prefix,257 base_uri_value,258 true,259 )?;260 let collection_id = <pallet_refungible::Pallet<T>>::init_collection(caller.clone(), data)261 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;262263 let address = pallet_common::eth::collection_id_to_address(collection_id);264 Ok(address)265 }239266240 /// Check if a collection exists267 /// Check if a collection exists241 /// @param collection_address Address of the collection in question268 /// @param collection_address Address of the collection in questiontests/src/eth/api/UniqueRefungible.soldiffbeforeafterbothno changes
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth72 });72 });73});73});747475describe('Check ERC721 token URI', () => {75describe('Check ERC721 token URI for NFT', () => {76 itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {76 itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {77 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);77 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);78 const helper = evmCollectionHelpers(web3, owner);78 const helper = evmCollectionHelpers(web3, owner);tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';17import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';18import {createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth} from './util/helpers';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth} from './util/helpers';19import reFungibleTokenAbi from './reFungibleTokenAbi.json';19import reFungibleTokenAbi from './reFungibleTokenAbi.json';202021import chai from 'chai';21import chai from 'chai';73 });73 });74});74});7576// FIXME: Need erc721 for ReFubgible.77describe.skip('Check ERC721 token URI for ReFungible', () => {78 itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {79 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);80 const helper = evmCollectionHelpers(web3, owner);81 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();82 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);83 const receiver = createEthAccount(web3);84 const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});85 86 const nextTokenId = await contract.methods.nextTokenId().call();87 expect(nextTokenId).to.be.equal('1');88 result = await contract.methods.mint(89 receiver,90 nextTokenId,91 ).send();9293 const events = normalizeEvents(result.events);94 const address = collectionIdToAddress(collectionId);9596 expect(events).to.be.deep.equal([97 {98 address,99 event: 'Transfer',100 args: {101 from: '0x0000000000000000000000000000000000000000',102 to: receiver,103 tokenId: nextTokenId,104 },105 },106 ]);107108 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');109 });110111 itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {112 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);113 const helper = evmCollectionHelpers(web3, owner);114 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();115 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);116 const receiver = createEthAccount(web3);117 const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});118 119 const nextTokenId = await contract.methods.nextTokenId().call();120 expect(nextTokenId).to.be.equal('1');121 result = await contract.methods.mint(122 receiver,123 nextTokenId,124 ).send();125 126 // Set URL127 await contract.methods.setProperty(nextTokenId, 'url', Buffer.from('Token URI')).send();128 129 const events = normalizeEvents(result.events);130 const address = collectionIdToAddress(collectionId);131132 expect(events).to.be.deep.equal([133 {134 address,135 event: 'Transfer',136 args: {137 from: '0x0000000000000000000000000000000000000000',138 to: receiver,139 tokenId: nextTokenId,140 },141 },142 ]);143144 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');145 });146147 itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {148 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);149 const helper = evmCollectionHelpers(web3, owner);150 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();151 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);152 const receiver = createEthAccount(web3);153 const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});154 155 const nextTokenId = await contract.methods.nextTokenId().call();156 expect(nextTokenId).to.be.equal('1');157 result = await contract.methods.mint(158 receiver,159 nextTokenId,160 ).send();161 162 const events = normalizeEvents(result.events);163 const address = collectionIdToAddress(collectionId);164165 expect(events).to.be.deep.equal([166 {167 address,168 event: 'Transfer',169 args: {170 from: '0x0000000000000000000000000000000000000000',171 to: receiver,172 tokenId: nextTokenId,173 },174 },175 ]);176177 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);178 });179180 itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {181 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);182 const helper = evmCollectionHelpers(web3, owner);183 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();184 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);185 const receiver = createEthAccount(web3);186 const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});187 188 const nextTokenId = await contract.methods.nextTokenId().call();189 expect(nextTokenId).to.be.equal('1');190 result = await contract.methods.mint(191 receiver,192 nextTokenId,193 ).send();194 195 // Set suffix196 const suffix = '/some/suffix';197 await contract.methods.setProperty(nextTokenId, 'suffix', Buffer.from(suffix)).send();198199 const events = normalizeEvents(result.events);200 const address = collectionIdToAddress(collectionId);201202 expect(events).to.be.deep.equal([203 {204 address,205 event: 'Transfer',206 args: {207 from: '0x0000000000000000000000000000000000000000',208 to: receiver,209 tokenId: nextTokenId,210 },211 },212 ]);213214 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);215 });216});7521776describe('Refungible: Plain calls', () => {218describe('Refungible: Plain calls', () => {77 itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {219 itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {