difftreelog
feat updates for createERC721MetadataCompatibleCollections
in: master
13 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -665,6 +665,11 @@
property_key_from_bytes(b"schemaName").expect(EXPECT_CONVERT_ERROR)
}
+ /// Key "schemaVersion".
+ pub fn schema_version() -> up_data_structs::PropertyKey {
+ property_key_from_bytes(b"schemaVersion").expect(EXPECT_CONVERT_ERROR)
+ }
+
/// Key "baseURI".
pub fn base_uri() -> up_data_structs::PropertyKey {
property_key_from_bytes(b"baseURI").expect(EXPECT_CONVERT_ERROR)
@@ -672,12 +677,12 @@
/// Key "url".
pub fn url() -> up_data_structs::PropertyKey {
- property_key_from_bytes(b"url").expect(EXPECT_CONVERT_ERROR)
+ property_key_from_bytes(b"URI").expect(EXPECT_CONVERT_ERROR)
}
/// Key "suffix".
pub fn suffix() -> up_data_structs::PropertyKey {
- property_key_from_bytes(b"suffix").expect(EXPECT_CONVERT_ERROR)
+ property_key_from_bytes(b"URISuffix").expect(EXPECT_CONVERT_ERROR)
}
/// Key "parentNft".
@@ -685,7 +690,7 @@
property_key_from_bytes(b"parentNft").expect(EXPECT_CONVERT_ERROR)
}
- /// Key "parentNft".
+ /// Key "ERC721Metadata".
pub fn erc721_metadata() -> up_data_structs::PropertyKey {
property_key_from_bytes(b"ERC721Metadata").expect(EXPECT_CONVERT_ERROR)
}
@@ -695,6 +700,9 @@
pub mod value {
use super::*;
+ /// Value "Schema version".
+ pub const SCHEMA_VERSION: &[u8] = b"1.0.0";
+
/// Value "ERC721Metadata".
pub const ERC721_METADATA: &[u8] = b"ERC721Metadata";
@@ -709,7 +717,12 @@
property_value_from_bytes(ERC721_METADATA).expect(EXPECT_CONVERT_ERROR)
}
- /// Value for [`ERC721_METADATA`].
+ /// Value for [`SCHEMA_VERSION`].
+ pub fn schema_version() -> up_data_structs::PropertyValue {
+ property_value_from_bytes(SCHEMA_VERSION).expect(EXPECT_CONVERT_ERROR)
+ }
+
+ /// Value for [`ERC721_METADATA_SUPPORTED`].
pub fn erc721_metadata_supported() -> up_data_structs::PropertyValue {
property_value_from_bytes(ERC721_METADATA_SUPPORTED).expect(EXPECT_CONVERT_ERROR)
}
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -116,7 +116,18 @@
.try_push(up_data_structs::PropertyKeyPermission {
key: key::suffix(),
permission: up_data_structs::PropertyPermission {
- mutable: false,
+ mutable: true,
+ collection_admin: true,
+ token_owner: false,
+ },
+ })
+ .map_err(|e| Error::Revert(format!("{:?}", e)))?;
+
+ token_property_permissions
+ .try_push(up_data_structs::PropertyKeyPermission {
+ key: key::url(),
+ permission: up_data_structs::PropertyPermission {
+ mutable: true,
collection_admin: true,
token_owner: false,
},
@@ -129,6 +140,13 @@
value: property_value::erc721(),
})
.map_err(|e| Error::Revert(format!("{:?}", e)))?;
+
+ properties
+ .try_push(up_data_structs::Property {
+ key: key::schema_version(),
+ value: property_value::schema_version(),
+ })
+ .map_err(|e| Error::Revert(format!("{:?}", e)))?;
properties
.try_push(up_data_structs::Property {
@@ -266,7 +284,7 @@
}
#[weight(<SelfWeightOf<T>>::create_collection())]
- #[solidity(rename_selector = "createERC721MetadataNFTCollection")]
+ #[solidity(rename_selector = "createERC721MetadataCompatibleNFTCollection")]
fn create_nonfungible_collection_with_properties(
&mut self,
caller: caller,
@@ -339,7 +357,7 @@
}
#[weight(<SelfWeightOf<T>>::create_collection())]
- #[solidity(rename_selector = "createERC721MetadataRFTCollection")]
+ #[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]
fn create_refungible_collection_with_properties(
&mut self,
caller: caller,
pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -23,7 +23,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0xf62c7aa9
+/// @dev the ERC-165 identifier for this interface is 0x95eb98f4
contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -65,9 +65,9 @@
return 0x0000000000000000000000000000000000000000;
}
- /// @dev EVM selector for this function is: 0xd1df968c,
- /// or in textual repr: createERC721MetadataNFTCollection(string,string,string,string)
- function createERC721MetadataNFTCollection(
+ /// @dev EVM selector for this function is: 0xa9e7b5c0,
+ /// or in textual repr: createERC721MetadataCompatibleNFTCollection(string,string,string,string)
+ function createERC721MetadataCompatibleNFTCollection(
string memory name,
string memory description,
string memory tokenPrefix,
@@ -112,9 +112,9 @@
return 0x0000000000000000000000000000000000000000;
}
- /// @dev EVM selector for this function is: 0xbea6a299,
- /// or in textual repr: createERC721MetadataRFTCollection(string,string,string,string)
- function createERC721MetadataRFTCollection(
+ /// @dev EVM selector for this function is: 0xa5596388,
+ /// or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)
+ function createERC721MetadataCompatibleRFTCollection(
string memory name,
string memory description,
string memory tokenPrefix,
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -18,7 +18,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0xf62c7aa9
+/// @dev the ERC-165 identifier for this interface is 0x95eb98f4
interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -46,9 +46,9 @@
string memory tokenPrefix
) external payable returns (address);
- /// @dev EVM selector for this function is: 0xd1df968c,
- /// or in textual repr: createERC721MetadataNFTCollection(string,string,string,string)
- function createERC721MetadataNFTCollection(
+ /// @dev EVM selector for this function is: 0xa9e7b5c0,
+ /// or in textual repr: createERC721MetadataCompatibleNFTCollection(string,string,string,string)
+ function createERC721MetadataCompatibleNFTCollection(
string memory name,
string memory description,
string memory tokenPrefix,
@@ -71,9 +71,9 @@
string memory tokenPrefix
) external payable returns (address);
- /// @dev EVM selector for this function is: 0xbea6a299,
- /// or in textual repr: createERC721MetadataRFTCollection(string,string,string,string)
- function createERC721MetadataRFTCollection(
+ /// @dev EVM selector for this function is: 0xa5596388,
+ /// or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)
+ function createERC721MetadataCompatibleRFTCollection(
string memory name,
string memory description,
string memory tokenPrefix,
tests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth--- a/tests/src/eth/collectionHelpersAbi.json
+++ b/tests/src/eth/collectionHelpersAbi.json
@@ -32,7 +32,7 @@
{ "internalType": "string", "name": "tokenPrefix", "type": "string" },
{ "internalType": "string", "name": "baseUri", "type": "string" }
],
- "name": "createERC721MetadataNFTCollection",
+ "name": "createERC721MetadataCompatibleNFTCollection",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "payable",
"type": "function"
@@ -44,7 +44,7 @@
{ "internalType": "string", "name": "tokenPrefix", "type": "string" },
{ "internalType": "string", "name": "baseUri", "type": "string" }
],
- "name": "createERC721MetadataRFTCollection",
+ "name": "createERC721MetadataCompatibleRFTCollection",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "payable",
"type": "function"
tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -14,7 +14,7 @@
itEth('Can be set', async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test'});
+ const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
await collection.addAdmin(alice, {Ethereum: caller});
const address = helper.ethAddress.fromCollectionId(collection.collectionId);
@@ -24,7 +24,7 @@
const raw = (await collection.getData())?.raw;
- expect(raw.properties[1].value).to.equal('testValue');
+ expect(raw.properties[0].value).to.equal('testValue');
});
itEth('Can be deleted', async({helper}) => {
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -97,7 +97,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
- let result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});
+ let result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});
const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);
const collection = helper.nft.getCollectionObject(collectionId);
@@ -167,7 +167,7 @@
// itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {
// const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
// const collectionHelpers = evmCollectionHelpers(web3, owner);
- // const result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send();
+ // const result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send();
// const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
// const sponsor = privateKeyWrapper('//Alice');
// const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -223,7 +223,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
- let result = await collectionHelpers.methods.createERC721MetadataNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});
+ let result = await collectionHelpers.methods.createERC721MetadataCompatibleNFTCollection('Sponsor collection', '1', '1', '').send({value: Number(2n * nominal)});
const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);
const collection = helper.nft.getCollectionObject(collectionId);
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -83,14 +83,12 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const receiver = helper.eth.createAccount();
- const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- let result = await collectionHelper.methods.createERC721MetadataNFTCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * helper.balance.getOneTokenNominal())});
- const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', tokenPrefix);
const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const nextTokenId = await contract.methods.nextTokenId().call();
expect(nextTokenId).to.be.equal('1');
- result = await contract.methods.mint(
+ const result = await contract.methods.mint(
receiver,
nextTokenId,
).send();
@@ -115,7 +113,7 @@
});
itEth('TokenURI from url', async ({helper}) => {
- const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'url', 'Token URI');
+ const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');
});
@@ -126,7 +124,7 @@
itEth('TokenURI from baseURI + suffix', async ({helper}) => {
const suffix = '/some/suffix';
- const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'suffix', suffix);
+ const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);
});
});
@@ -146,7 +144,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const receiver = helper.eth.createAccount();
- const {collectionAddress} = await helper.eth.createERC721MetadataNFTCollection(owner, 'Mint collection', '6', '6', '');
+ const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const nextTokenId = await contract.methods.nextTokenId().call();
tests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -101,7 +101,7 @@
itEth('Can perform mint()', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createERC721MetadataNFTCollection(owner, 'A', 'A', 'A', '');
+ const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'A', 'A', 'A', '');
const caller = await helper.eth.createAccountWithBalance(donor);
const receiver = helper.eth.createAccount();
tests/src/eth/reFungible.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';18import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';19import {IKeyringPair} from '@polkadot/types/types';2021describe('Refungible: Information getting', () => {22 let donor: IKeyringPair;2324 before(async function() {25 await usingEthPlaygrounds(async (helper, privateKey) => {26 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2728 donor = privateKey('//Alice');29 });30 });3132 itEth('totalSupply', async ({helper}) => {33 const caller = await helper.eth.createAccountWithBalance(donor);34 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');35 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);36 const nextTokenId = await contract.methods.nextTokenId().call();37 await contract.methods.mint(caller, nextTokenId).send();38 const totalSupply = await contract.methods.totalSupply().call();39 expect(totalSupply).to.equal('1');40 });4142 itEth('balanceOf', async ({helper}) => {43 const caller = await helper.eth.createAccountWithBalance(donor);44 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');45 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4647 {48 const nextTokenId = await contract.methods.nextTokenId().call();49 await contract.methods.mint(caller, nextTokenId).send();50 }51 {52 const nextTokenId = await contract.methods.nextTokenId().call();53 await contract.methods.mint(caller, nextTokenId).send();54 }55 {56 const nextTokenId = await contract.methods.nextTokenId().call();57 await contract.methods.mint(caller, nextTokenId).send();58 }5960 const balance = await contract.methods.balanceOf(caller).call();61 expect(balance).to.equal('3');62 });6364 itEth('ownerOf', async ({helper}) => {65 const caller = await helper.eth.createAccountWithBalance(donor);66 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');67 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6869 const tokenId = await contract.methods.nextTokenId().call();70 await contract.methods.mint(caller, tokenId).send();7172 const owner = await contract.methods.ownerOf(tokenId).call();73 expect(owner).to.equal(caller);74 });7576 itEth('ownerOf after burn', async ({helper}) => {77 const caller = await helper.eth.createAccountWithBalance(donor);78 const receiver = helper.eth.createAccount();79 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');80 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);8182 const tokenId = await contract.methods.nextTokenId().call();83 await contract.methods.mint(caller, tokenId).send();84 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);8586 await tokenContract.methods.repartition(2).send();87 await tokenContract.methods.transfer(receiver, 1).send();8889 await tokenContract.methods.burnFrom(caller, 1).send();9091 const owner = await contract.methods.ownerOf(tokenId).call();92 expect(owner).to.equal(receiver);93 });9495 itEth('ownerOf for partial ownership', async ({helper}) => {96 const caller = await helper.eth.createAccountWithBalance(donor);97 const receiver = helper.eth.createAccount();98 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');99 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);100101 const tokenId = await contract.methods.nextTokenId().call();102 await contract.methods.mint(caller, tokenId).send();103 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);104105 await tokenContract.methods.repartition(2).send();106 await tokenContract.methods.transfer(receiver, 1).send();107108 const owner = await contract.methods.ownerOf(tokenId).call();109 expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');110 });111});112113describe('Refungible: Plain calls', () => {114 let donor: IKeyringPair;115116 before(async function() {117 await usingEthPlaygrounds(async (helper, privateKey) => {118 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);119120 donor = privateKey('//Alice');121 });122 });123124 itEth('Can perform mint()', async ({helper}) => {125 const owner = await helper.eth.createAccountWithBalance(donor);126 const receiver = helper.eth.createAccount();127 const {collectionAddress} = await helper.eth.createERC721MetadataRFTCollection(owner, 'Minty', '6', '6', '');128 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);129 130 const nextTokenId = await contract.methods.nextTokenId().call();131 expect(nextTokenId).to.be.equal('1');132 const result = await contract.methods.mintWithTokenURI(133 receiver,134 nextTokenId,135 'Test URI',136 ).send();137138 const event = result.events.Transfer;139 expect(event.address).to.equal(collectionAddress);140 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');141 expect(event.returnValues.to).to.equal(receiver);142 expect(event.returnValues.tokenId).to.equal(nextTokenId);143144 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');145 });146147 itEth('Can perform mintBulk()', async ({helper}) => {148 const owner = await helper.eth.createAccountWithBalance(donor);149 const receiver = helper.eth.createAccount();150 const {collectionAddress} = await helper.eth.createERC721MetadataRFTCollection(owner, 'MintBulky', '6', '6', '');151 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);152153 {154 const nextTokenId = await contract.methods.nextTokenId().call();155 expect(nextTokenId).to.be.equal('1');156 const result = await contract.methods.mintBulkWithTokenURI(157 receiver,158 [159 [nextTokenId, 'Test URI 0'],160 [+nextTokenId + 1, 'Test URI 1'],161 [+nextTokenId + 2, 'Test URI 2'],162 ],163 ).send();164165 const events = result.events.Transfer;166 for (let i = 0; i < 2; i++) {167 const event = events[i];168 expect(event.address).to.equal(collectionAddress);169 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');170 expect(event.returnValues.to).to.equal(receiver);171 expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));172 }173174 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');175 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');176 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');177 }178 });179180 itEth('Can perform burn()', async ({helper}) => {181 const caller = await helper.eth.createAccountWithBalance(donor);182 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');183 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);184185 const tokenId = await contract.methods.nextTokenId().call();186 await contract.methods.mint(caller, tokenId).send();187 {188 const result = await contract.methods.burn(tokenId).send();189 const event = result.events.Transfer;190 expect(event.address).to.equal(collectionAddress);191 expect(event.returnValues.from).to.equal(caller);192 expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');193 expect(event.returnValues.tokenId).to.equal(tokenId.toString());194 }195 });196197 itEth('Can perform transferFrom()', async ({helper}) => {198 const caller = await helper.eth.createAccountWithBalance(donor);199 const receiver = helper.eth.createAccount();200 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');201 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);202203 const tokenId = await contract.methods.nextTokenId().call();204 const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);205 await contract.methods.mint(caller, tokenId).send();206207 const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);208 await tokenContract.methods.repartition(15).send();209210 {211 const tokenEvents: any = [];212 tokenContract.events.allEvents((_: any, event: any) => {213 tokenEvents.push(event);214 });215 const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();216217 let event = result.events.Transfer;218 expect(event.address).to.equal(collectionAddress);219 expect(event.returnValues.from).to.equal(caller);220 expect(event.returnValues.to).to.equal(receiver);221 expect(event.returnValues.tokenId).to.equal(tokenId.toString());222223 event = tokenEvents[0];224 expect(event.address).to.equal(tokenAddress);225 expect(event.returnValues.from).to.equal(caller);226 expect(event.returnValues.to).to.equal(receiver);227 expect(event.returnValues.value).to.equal('15');228 }229230 {231 const balance = await contract.methods.balanceOf(receiver).call();232 expect(+balance).to.equal(1);233 }234235 {236 const balance = await contract.methods.balanceOf(caller).call();237 expect(+balance).to.equal(0);238 }239 });240241 itEth('Can perform transfer()', async ({helper}) => {242 const caller = await helper.eth.createAccountWithBalance(donor);243 const receiver = helper.eth.createAccount();244 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');245 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);246247 const tokenId = await contract.methods.nextTokenId().call();248 await contract.methods.mint(caller, tokenId).send();249250 {251 const result = await contract.methods.transfer(receiver, tokenId).send();252 253 const event = result.events.Transfer;254 expect(event.address).to.equal(collectionAddress);255 expect(event.returnValues.from).to.equal(caller);256 expect(event.returnValues.to).to.equal(receiver);257 expect(event.returnValues.tokenId).to.equal(tokenId.toString());258 }259260 {261 const balance = await contract.methods.balanceOf(caller).call();262 expect(+balance).to.equal(0);263 }264265 {266 const balance = await contract.methods.balanceOf(receiver).call();267 expect(+balance).to.equal(1);268 }269 });270271 itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {272 const caller = await helper.eth.createAccountWithBalance(donor);273 const receiver = helper.eth.createAccount();274 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');275 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);276277 const tokenId = await contract.methods.nextTokenId().call();278 await contract.methods.mint(caller, tokenId).send();279280 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);281282 await tokenContract.methods.repartition(2).send();283 await tokenContract.methods.transfer(receiver, 1).send();284285 const events: any = [];286 contract.events.allEvents((_: any, event: any) => {287 events.push(event);288 });289 await tokenContract.methods.transfer(receiver, 1).send();290291 const event = events[0];292 expect(event.address).to.equal(collectionAddress);293 expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');294 expect(event.returnValues.to).to.equal(receiver);295 expect(event.returnValues.tokenId).to.equal(tokenId.toString());296 });297298 itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {299 const caller = await helper.eth.createAccountWithBalance(donor);300 const receiver = helper.eth.createAccount();301 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');302 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);303304 const tokenId = await contract.methods.nextTokenId().call();305 await contract.methods.mint(caller, tokenId).send();306307 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);308309 await tokenContract.methods.repartition(2).send();310311 const events: any = [];312 contract.events.allEvents((_: any, event: any) => {313 events.push(event);314 });315 await tokenContract.methods.transfer(receiver, 1).send();316317 const event = events[0];318 expect(event.address).to.equal(collectionAddress);319 expect(event.returnValues.from).to.equal(caller);320 expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');321 expect(event.returnValues.tokenId).to.equal(tokenId.toString());322 });323});324325describe('RFT: Fees', () => {326 let donor: IKeyringPair;327328 before(async function() {329 await usingEthPlaygrounds(async (helper, privateKey) => {330 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);331332 donor = privateKey('//Alice');333 });334 });335336 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {337 const caller = await helper.eth.createAccountWithBalance(donor);338 const receiver = helper.eth.createAccount();339 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');340 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);341342 const tokenId = await contract.methods.nextTokenId().call();343 await contract.methods.mint(caller, tokenId).send();344345 const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());346 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));347 expect(cost > 0n);348 });349350 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {351 const caller = await helper.eth.createAccountWithBalance(donor);352 const receiver = helper.eth.createAccount();353 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');354 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);355356 const tokenId = await contract.methods.nextTokenId().call();357 await contract.methods.mint(caller, tokenId).send();358359 const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());360 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));361 expect(cost > 0n);362 });363});364365describe('Common metadata', () => {366 let donor: IKeyringPair;367 let alice: IKeyringPair;368369 before(async function() {370 await usingEthPlaygrounds(async (helper, privateKey) => {371 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);372373 donor = privateKey('//Alice');374 [alice] = await helper.arrange.createAccounts([20n], donor);375 });376 });377378 itEth('Returns collection name', async ({helper}) => {379 const caller = helper.eth.createAccount();380 const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11'});381 382 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);383 const name = await contract.methods.name().call();384 expect(name).to.equal('Leviathan');385 });386387 itEth('Returns symbol name', async ({helper}) => {388 const caller = await helper.eth.createAccountWithBalance(donor);389 const {collectionId} = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '12'});390 const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);391 const symbol = await contract.methods.symbol().call();392 expect(symbol).to.equal('12');393 });394});tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -80,14 +80,12 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const receiver = helper.eth.createAccount();
- const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- let result = await collectionHelper.methods.createERC721MetadataNFTCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * helper.balance.getOneTokenNominal())});
- const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Mint collection', 'a', 'b', tokenPrefix);
const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
const nextTokenId = await contract.methods.nextTokenId().call();
expect(nextTokenId).to.be.equal('1');
- result = await contract.methods.mint(
+ const result = await contract.methods.mint(
receiver,
nextTokenId,
).send();
@@ -112,7 +110,7 @@
});
itEth('TokenURI from url', async ({helper}) => {
- const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'url', 'Token URI');
+ const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');
});
@@ -123,7 +121,7 @@
itEth('TokenURI from baseURI + suffix', async ({helper}) => {
const suffix = '/some/suffix';
- const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'suffix', suffix);
+ const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);
});
});
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -186,11 +186,11 @@
return {collectionId, collectionAddress};
}
- async createERC721MetadataNFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
+ async createERC721MetadataCompatibleNFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
- const result = await collectionHelper.methods.createERC721MetadataNFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
+ const result = await collectionHelper.methods.createERC721MetadataCompatibleNFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
@@ -210,11 +210,11 @@
return {collectionId, collectionAddress};
}
- async createERC721MetadataRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
+ async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string}> {
const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
- const result = await collectionHelper.methods.createERC721MetadataRFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
+ const result = await collectionHelper.methods.createERC721MetadataCompatibleRFTCollection(name, description, tokenPrefix, baseUri).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);