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.soldiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: OTHER
+// This code is automatically generated
+
+pragma solidity >=0.8.0 <0.9.0;
+
+// Common stubs holder
+interface Dummy {
+
+}
+
+interface ERC165 is Dummy {
+ function supportsInterface(bytes4 interfaceID) external view returns (bool);
+}
+
+// Selector: 7d9262e6
+interface Collection is Dummy, ERC165 {
+ // Set collection property.
+ //
+ // @param key Property key.
+ // @param value Propery value.
+ //
+ // Selector: setCollectionProperty(string,bytes) 2f073f66
+ function setCollectionProperty(string memory key, bytes memory value)
+ external;
+
+ // Delete collection property.
+ //
+ // @param key Property key.
+ //
+ // Selector: deleteCollectionProperty(string) 7b7debce
+ function deleteCollectionProperty(string memory key) external;
+
+ // Get collection property.
+ //
+ // @dev Throws error if key not found.
+ //
+ // @param key Property key.
+ // @return bytes The property corresponding to the key.
+ //
+ // Selector: collectionProperty(string) cf24fd6d
+ function collectionProperty(string memory key)
+ external
+ view
+ returns (bytes memory);
+
+ // Set the sponsor of the collection.
+ //
+ // @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
+ //
+ // @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
+ //
+ // Selector: setCollectionSponsor(address) 7623402e
+ function setCollectionSponsor(address sponsor) external;
+
+ // Collection sponsorship confirmation.
+ //
+ // @dev After setting the sponsor for the collection, it must be confirmed with this function.
+ //
+ // Selector: confirmCollectionSponsorship() 3c50e97a
+ function confirmCollectionSponsorship() external;
+
+ // Set limits for the collection.
+ // @dev Throws error if limit not found.
+ // @param limit Name of the limit. Valid names:
+ // "accountTokenOwnershipLimit",
+ // "sponsoredDataSize",
+ // "sponsoredDataRateLimit",
+ // "tokenLimit",
+ // "sponsorTransferTimeout",
+ // "sponsorApproveTimeout"
+ // @param value Value of the limit.
+ //
+ // Selector: setCollectionLimit(string,uint32) 6a3841db
+ function setCollectionLimit(string memory limit, uint32 value) external;
+
+ // Set limits for the collection.
+ // @dev Throws error if limit not found.
+ // @param limit Name of the limit. Valid names:
+ // "ownerCanTransfer",
+ // "ownerCanDestroy",
+ // "transfersEnabled"
+ // @param value Value of the limit.
+ //
+ // Selector: setCollectionLimit(string,bool) 993b7fba
+ function setCollectionLimit(string memory limit, bool value) external;
+
+ // Get contract address.
+ //
+ // Selector: contractAddress() f6b4dfb4
+ function contractAddress() external view returns (address);
+
+ // Add collection admin by substrate address.
+ // @param new_admin Substrate administrator address.
+ //
+ // Selector: addCollectionAdminSubstrate(uint256) 5730062b
+ function addCollectionAdminSubstrate(uint256 newAdmin) external;
+
+ // Remove collection admin by substrate address.
+ // @param admin Substrate administrator address.
+ //
+ // Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
+ function removeCollectionAdminSubstrate(uint256 admin) external;
+
+ // Add collection admin.
+ // @param new_admin Address of the added administrator.
+ //
+ // Selector: addCollectionAdmin(address) 92e462c7
+ function addCollectionAdmin(address newAdmin) external;
+
+ // Remove collection admin.
+ //
+ // @param new_admin Address of the removed administrator.
+ //
+ // Selector: removeCollectionAdmin(address) fafd7b42
+ function removeCollectionAdmin(address admin) external;
+
+ // Toggle accessibility of collection nesting.
+ //
+ // @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
+ //
+ // Selector: setCollectionNesting(bool) 112d4586
+ function setCollectionNesting(bool enable) external;
+
+ // Toggle accessibility of collection nesting.
+ //
+ // @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
+ // @param collections Addresses of collections that will be available for nesting.
+ //
+ // Selector: setCollectionNesting(bool,address[]) 64872396
+ function setCollectionNesting(bool enable, address[] memory collections)
+ external;
+
+ // Set the collection access method.
+ // @param mode Access mode
+ // 0 for Normal
+ // 1 for AllowList
+ //
+ // Selector: setCollectionAccess(uint8) 41835d4c
+ function setCollectionAccess(uint8 mode) external;
+
+ // Add the user to the allowed list.
+ //
+ // @param user Address of a trusted user.
+ //
+ // Selector: addToCollectionAllowList(address) 67844fe6
+ function addToCollectionAllowList(address user) external;
+
+ // Remove the user from the allowed list.
+ //
+ // @param user Address of a removed user.
+ //
+ // Selector: removeFromCollectionAllowList(address) 85c51acb
+ function removeFromCollectionAllowList(address user) external;
+
+ // Switch permission for minting.
+ //
+ // @param mode Enable if "true".
+ //
+ // Selector: setCollectionMintMode(bool) 00018e84
+ function setCollectionMintMode(bool mode) external;
+}
+
+interface UniqueRefungible is Dummy, ERC165, Collection {}
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -72,7 +72,7 @@
});
});
-describe('Check ERC721 token URI', () => {
+describe('Check ERC721 token URI for NFT', () => {
itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const helper = evmCollectionHelpers(web3, owner);
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE} from '../util/helpers';
-import {createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth} from './util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth} from './util/helpers';
import reFungibleTokenAbi from './reFungibleTokenAbi.json';
import chai from 'chai';
@@ -73,6 +73,148 @@
});
});
+// FIXME: Need erc721 for ReFubgible.
+describe.skip('Check ERC721 token URI for ReFungible', () => {
+ itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const helper = evmCollectionHelpers(web3, owner);
+ let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ const receiver = createEthAccount(web3);
+ const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
+
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ result = await contract.methods.mint(
+ receiver,
+ nextTokenId,
+ ).send();
+
+ const events = normalizeEvents(result.events);
+ const address = collectionIdToAddress(collectionId);
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: receiver,
+ tokenId: nextTokenId,
+ },
+ },
+ ]);
+
+ expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');
+ });
+
+ itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const helper = evmCollectionHelpers(web3, owner);
+ let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ const receiver = createEthAccount(web3);
+ const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
+
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ result = await contract.methods.mint(
+ receiver,
+ nextTokenId,
+ ).send();
+
+ // Set URL
+ await contract.methods.setProperty(nextTokenId, 'url', Buffer.from('Token URI')).send();
+
+ const events = normalizeEvents(result.events);
+ const address = collectionIdToAddress(collectionId);
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: receiver,
+ tokenId: nextTokenId,
+ },
+ },
+ ]);
+
+ expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');
+ });
+
+ itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const helper = evmCollectionHelpers(web3, owner);
+ let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ const receiver = createEthAccount(web3);
+ const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
+
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ result = await contract.methods.mint(
+ receiver,
+ nextTokenId,
+ ).send();
+
+ const events = normalizeEvents(result.events);
+ const address = collectionIdToAddress(collectionId);
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: receiver,
+ tokenId: nextTokenId,
+ },
+ },
+ ]);
+
+ expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);
+ });
+
+ itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const helper = evmCollectionHelpers(web3, owner);
+ let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ const receiver = createEthAccount(web3);
+ const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
+
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ result = await contract.methods.mint(
+ receiver,
+ nextTokenId,
+ ).send();
+
+ // Set suffix
+ const suffix = '/some/suffix';
+ await contract.methods.setProperty(nextTokenId, 'suffix', Buffer.from(suffix)).send();
+
+ const events = normalizeEvents(result.events);
+ const address = collectionIdToAddress(collectionId);
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: receiver,
+ tokenId: nextTokenId,
+ },
+ },
+ ]);
+
+ expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);
+ });
+});
+
describe('Refungible: Plain calls', () => {
itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {
const alice = privateKeyWrapper('//Alice');