difftreelog
CORE-337 Rewrite set limits
in: master
9 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -16,10 +16,11 @@
use evm_coder::{solidity_interface, types::*, execution::{Result, Error}};
pub use pallet_evm::{PrecompileOutput, PrecompileResult, account::CrossAccountId};
-use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder};
+use pallet_evm_coder_substrate::dispatch_to_evm;
use sp_core::{H160, U256};
use sp_std::vec::Vec;
-use up_data_structs::Property;
+use up_data_structs::{Property, SponsoringRateLimit};
+use alloc::format;
use crate::{Pallet, CollectionHandle, Config, CollectionProperties};
@@ -87,37 +88,53 @@
Ok(())
}
- fn set_limits(
- &self,
+ fn set_limit(
+ &mut self,
caller: caller,
- limits_json: string,
+ limit: string,
+ value: string,
) -> Result<void> {
- // let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
- // check_is_owner(caller, &collection)?;
+ check_is_owner(caller, self)?;
+ let mut limits = self.limits.clone();
- // let limits = serde_json_core::from_str(limits_json.as_ref())
- // .map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;
- // collection.limits = limits.0;
- // collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+ match limit.as_str() {
+ "accountTokenOwnershipLimit" => {
+ limits.account_token_ownership_limit = parse_int(value)?;
+ },
+ "sponsoredDataSize" => {
+ limits.sponsored_data_size = parse_int(value)?;
+ },
+ "sponsoredDataRateLimit" => {
+ limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));
+ },
+ "tokenLimit" => {
+ limits.token_limit = parse_int(value)?;
+ },
+ "sponsorTransferTimeout" => {
+ limits.sponsor_transfer_timeout = parse_int(value)?;
+ },
+ "sponsorApproveTimeout" => {
+ limits.sponsor_approve_timeout = parse_int(value)?;
+ },
+ "ownerCanTransfer" => {
+ limits.owner_can_transfer = parse_bool(value)?;
+ },
+ "ownerCanDestroy" => {
+ limits.owner_can_destroy = parse_bool(value)?;
+ },
+ "transfersEnabled" => {
+ limits.transfers_enabled = parse_bool(value)?;
+ },
+ _ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit)))
+ }
+ self.limits = limits;
+ save(self);
Ok(())
}
fn contract_address(&self, _caller: caller) -> Result<address> {
Ok(crate::eth::collection_id_to_address(self.id))
}
-}
-
-fn collection_from_address<T: Config>(
- collection_address: address,
- gas_limit: u64
-) -> Result<CollectionHandle<T>> {
- let collection_id = crate::eth::map_eth_to_id(&collection_address)
- .ok_or(Error::Revert("Contract is not an unique collection".into()))?;
- let recorder = <SubstrateRecorder<T>>::new(gas_limit);
- let collection =
- CollectionHandle::new_with_recorder(collection_id, recorder)
- .ok_or(Error::Revert("Create collection handle error".into()))?;
- Ok(collection)
}
fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {
@@ -130,4 +147,16 @@
fn save<T: Config>(collection: &CollectionHandle<T>) {
<crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());
+}
+
+fn parse_int(value: string) -> Result<Option<u32>> {
+ value.parse::<u32>()
+ .map_err(|e| Error::Revert(format!("Int value \"{}\" parse error: {}", value, e)))
+ .map(|value| Some(value))
+}
+
+fn parse_bool(value: string) -> Result<Option<bool>> {
+ value.parse::<bool>()
+ .map_err(|e| Error::Revert(format!("Bool value \"{}\" parse error: {}", value, e)))
+ .map(|value| Some(value))
}
\ No newline at end of file
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -51,67 +51,6 @@
event MintingFinished();
}
-// Selector: 38e33c60
-contract Collection is Dummy, ERC165 {
- // Selector: setCollectionProperty(string,bytes) 2f073f66
- function setCollectionProperty(string memory key, bytes memory value)
- public
- {
- require(false, stub_error);
- key;
- value;
- dummy = 0;
- }
-
- // Selector: deleteCollectionProperty(string) 7b7debce
- function deleteCollectionProperty(string memory key) public {
- require(false, stub_error);
- key;
- dummy = 0;
- }
-
- // Throws error if key not found
- //
- // Selector: collectionProperty(string) cf24fd6d
- function collectionProperty(string memory key)
- public
- view
- returns (bytes memory)
- {
- require(false, stub_error);
- key;
- dummy;
- return hex"";
- }
-
- // Selector: ethSetSponsor(address) 8f9af356
- function ethSetSponsor(address sponsor) public {
- require(false, stub_error);
- sponsor;
- dummy = 0;
- }
-
- // Selector: ethConfirmSponsorship() a8580d1a
- function ethConfirmSponsorship() public {
- require(false, stub_error);
- dummy = 0;
- }
-
- // Selector: setLimits(string) 72cb345d
- function setLimits(string memory limitsJson) public view {
- require(false, stub_error);
- limitsJson;
- dummy;
- }
-
- // Selector: contractAddress() f6b4dfb4
- function contractAddress() public view returns (address) {
- require(false, stub_error);
- dummy;
- return 0x0000000000000000000000000000000000000000;
- }
-}
-
// Selector: 41369377
contract TokenProperties is Dummy, ERC165 {
// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
@@ -441,6 +380,68 @@
}
}
+// Selector: f5652829
+contract Collection is Dummy, ERC165 {
+ // Selector: setCollectionProperty(string,bytes) 2f073f66
+ function setCollectionProperty(string memory key, bytes memory value)
+ public
+ {
+ require(false, stub_error);
+ key;
+ value;
+ dummy = 0;
+ }
+
+ // Selector: deleteCollectionProperty(string) 7b7debce
+ function deleteCollectionProperty(string memory key) public {
+ require(false, stub_error);
+ key;
+ dummy = 0;
+ }
+
+ // Throws error if key not found
+ //
+ // Selector: collectionProperty(string) cf24fd6d
+ function collectionProperty(string memory key)
+ public
+ view
+ returns (bytes memory)
+ {
+ require(false, stub_error);
+ key;
+ dummy;
+ return hex"";
+ }
+
+ // Selector: ethSetSponsor(address) 8f9af356
+ function ethSetSponsor(address sponsor) public {
+ require(false, stub_error);
+ sponsor;
+ dummy = 0;
+ }
+
+ // Selector: ethConfirmSponsorship() a8580d1a
+ function ethConfirmSponsorship() public {
+ require(false, stub_error);
+ dummy = 0;
+ }
+
+ // Selector: setLimit(string,string) bf4d2014
+ function setLimit(string memory limit, string memory value) public {
+ require(false, stub_error);
+ limit;
+ value;
+ dummy = 0;
+ }
+
+ // Selector: contractAddress() f6b4dfb4
+ function contractAddress() public view returns (address) {
+ require(false, stub_error);
+ dummy;
+ return 0x0000000000000000000000000000000000000000;
+ }
+}
+
contract UniqueNFT is
Dummy,
ERC165,
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -26,7 +26,7 @@
};
use frame_support::traits::Get;
use sp_core::H160;
- use pallet_common::{CollectionHandle, CollectionById};
+ use pallet_common::CollectionById;
use sp_std::vec::Vec;
use alloc::format;
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -368,30 +368,21 @@
#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct CollectionLimits {
- #[serde(alias = "accountTokenOwnershipLimit")]
pub account_token_ownership_limit: Option<u32>,
- #[serde(alias = "sponsoredDataSize")]
pub sponsored_data_size: Option<u32>,
/// FIXME should we delete this or repurpose it?
/// None - setVariableMetadata is not sponsored
/// Some(v) - setVariableMetadata is sponsored
/// if there is v block between txs
- #[serde(alias = "sponsoredDataRateLimit")]
pub sponsored_data_rate_limit: Option<SponsoringRateLimit>,
- #[serde(alias = "tokenLimit")]
pub token_limit: Option<u32>,
// Timeouts for item types in passed blocks
- #[serde(alias = "sponsorTransferTimeout")]
pub sponsor_transfer_timeout: Option<u32>,
- #[serde(alias = "sponsorApproveTimeout")]
pub sponsor_approve_timeout: Option<u32>,
- #[serde(alias = "ownerCanTransfer")]
pub owner_can_transfer: Option<bool>,
- #[serde(alias = "ownerCanDestroy")]
pub owner_can_destroy: Option<bool>,
- #[serde(alias = "transfersEnabled")]
pub transfers_enabled: Option<bool>,
}
tests/src/eth/api/Collection.soldiffbeforeafterboth--- a/tests/src/eth/api/Collection.sol
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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: 15cc740e
-interface Collection is Dummy, ERC165 {
- // Selector: setSponsor(address) 59753fb1
- function setSponsor(address sponsor) external view;
-
- // Selector: confirmSponsorship() c8c6a056
- function confirmSponsorship() external view;
-
- // Selector: setLimits(string) 72cb345d
- function setLimits(string memory limitsJson) external view;
-
- // Selector: contractAddress() f6b4dfb4
- function contractAddress() external view returns (address);
-}
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56// Anonymous struct7struct Tuple0 {8 uint256 field_0;9 string field_1;10}1112// Common stubs holder13interface Dummy {1415}1617interface ERC165 is Dummy {18 function supportsInterface(bytes4 interfaceID) external view returns (bool);19}2021// Inline22interface ERC721Events {23 event Transfer(24 address indexed from,25 address indexed to,26 uint256 indexed tokenId27 );28 event Approval(29 address indexed owner,30 address indexed approved,31 uint256 indexed tokenId32 );33 event ApprovalForAll(34 address indexed owner,35 address indexed operator,36 bool approved37 );38}3940// Inline41interface ERC721MintableEvents {42 event MintingFinished();43}4445// Selector: 38e33c6046interface Collection is Dummy, ERC165 {47 // Selector: setCollectionProperty(string,bytes) 2f073f6648 function setCollectionProperty(string memory key, bytes memory value)49 external;5051 // Selector: deleteCollectionProperty(string) 7b7debce52 function deleteCollectionProperty(string memory key) external;5354 // Throws error if key not found55 //56 // Selector: collectionProperty(string) cf24fd6d57 function collectionProperty(string memory key)58 external59 view60 returns (bytes memory);6162 // Selector: ethSetSponsor(address) 8f9af35663 function ethSetSponsor(address sponsor) external;6465 // Selector: ethConfirmSponsorship() a8580d1a66 function ethConfirmSponsorship() external;6768 // Selector: setLimits(string) 72cb345d69 function setLimits(string memory limitsJson) external view;7071 // Selector: contractAddress() f6b4dfb472 function contractAddress() external view returns (address);73}7475// Selector: 4136937776interface TokenProperties is Dummy, ERC165 {77 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa78 function setTokenPropertyPermission(79 string memory key,80 bool isMutable,81 bool collectionAdmin,82 bool tokenOwner83 ) external;8485 // Selector: setProperty(uint256,string,bytes) 1752d67b86 function setProperty(87 uint256 tokenId,88 string memory key,89 bytes memory value90 ) external;9192 // Selector: deleteProperty(uint256,string) 066111d193 function deleteProperty(uint256 tokenId, string memory key) external;9495 // Throws error if key not found96 //97 // Selector: property(uint256,string) 7228c32798 function property(uint256 tokenId, string memory key)99 external100 view101 returns (bytes memory);102}103104// Selector: 42966c68105interface ERC721Burnable is Dummy, ERC165 {106 // Selector: burn(uint256) 42966c68107 function burn(uint256 tokenId) external;108}109110// Selector: 58800161111interface ERC721 is Dummy, ERC165, ERC721Events {112 // Selector: balanceOf(address) 70a08231113 function balanceOf(address owner) external view returns (uint256);114115 // Selector: ownerOf(uint256) 6352211e116 function ownerOf(uint256 tokenId) external view returns (address);117118 // Not implemented119 //120 // Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672121 function safeTransferFromWithData(122 address from,123 address to,124 uint256 tokenId,125 bytes memory data126 ) external;127128 // Not implemented129 //130 // Selector: safeTransferFrom(address,address,uint256) 42842e0e131 function safeTransferFrom(132 address from,133 address to,134 uint256 tokenId135 ) external;136137 // Selector: transferFrom(address,address,uint256) 23b872dd138 function transferFrom(139 address from,140 address to,141 uint256 tokenId142 ) external;143144 // Selector: approve(address,uint256) 095ea7b3145 function approve(address approved, uint256 tokenId) external;146147 // Not implemented148 //149 // Selector: setApprovalForAll(address,bool) a22cb465150 function setApprovalForAll(address operator, bool approved) external;151152 // Not implemented153 //154 // Selector: getApproved(uint256) 081812fc155 function getApproved(uint256 tokenId) external view returns (address);156157 // Not implemented158 //159 // Selector: isApprovedForAll(address,address) e985e9c5160 function isApprovedForAll(address owner, address operator)161 external162 view163 returns (address);164}165166// Selector: 5b5e139f167interface ERC721Metadata is Dummy, ERC165 {168 // Selector: name() 06fdde03169 function name() external view returns (string memory);170171 // Selector: symbol() 95d89b41172 function symbol() external view returns (string memory);173174 // Returns token's const_metadata175 //176 // Selector: tokenURI(uint256) c87b56dd177 function tokenURI(uint256 tokenId) external view returns (string memory);178}179180// Selector: 68ccfe89181interface ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {182 // Selector: mintingFinished() 05d2035b183 function mintingFinished() external view returns (bool);184185 // `token_id` should be obtained with `next_token_id` method,186 // unlike standard, you can't specify it manually187 //188 // Selector: mint(address,uint256) 40c10f19189 function mint(address to, uint256 tokenId) external returns (bool);190191 // `token_id` should be obtained with `next_token_id` method,192 // unlike standard, you can't specify it manually193 //194 // Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f195 function mintWithTokenURI(196 address to,197 uint256 tokenId,198 string memory tokenUri199 ) external returns (bool);200201 // Not implemented202 //203 // Selector: finishMinting() 7d64bcb4204 function finishMinting() external returns (bool);205}206207// Selector: 780e9d63208interface ERC721Enumerable is Dummy, ERC165 {209 // Selector: tokenByIndex(uint256) 4f6ccce7210 function tokenByIndex(uint256 index) external view returns (uint256);211212 // Not implemented213 //214 // Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59215 function tokenOfOwnerByIndex(address owner, uint256 index)216 external217 view218 returns (uint256);219220 // Selector: totalSupply() 18160ddd221 function totalSupply() external view returns (uint256);222}223224// Selector: d74d154f225interface ERC721UniqueExtensions is Dummy, ERC165 {226 // Selector: transfer(address,uint256) a9059cbb227 function transfer(address to, uint256 tokenId) external;228229 // Selector: burnFrom(address,uint256) 79cc6790230 function burnFrom(address from, uint256 tokenId) external;231232 // Selector: nextTokenId() 75794a3c233 function nextTokenId() external view returns (uint256);234235 // Selector: mintBulk(address,uint256[]) 44a9945e236 function mintBulk(address to, uint256[] memory tokenIds)237 external238 returns (bool);239240 // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006241 function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)242 external243 returns (bool);244}245246interface UniqueNFT is247 Dummy,248 ERC165,249 ERC721,250 ERC721Metadata,251 ERC721Enumerable,252 ERC721UniqueExtensions,253 ERC721Mintable,254 ERC721Burnable,255 Collection,256 TokenProperties257{}1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56// Anonymous struct7struct Tuple0 {8 uint256 field_0;9 string field_1;10}1112// Common stubs holder13interface Dummy {1415}1617interface ERC165 is Dummy {18 function supportsInterface(bytes4 interfaceID) external view returns (bool);19}2021// Inline22interface ERC721Events {23 event Transfer(24 address indexed from,25 address indexed to,26 uint256 indexed tokenId27 );28 event Approval(29 address indexed owner,30 address indexed approved,31 uint256 indexed tokenId32 );33 event ApprovalForAll(34 address indexed owner,35 address indexed operator,36 bool approved37 );38}3940// Inline41interface ERC721MintableEvents {42 event MintingFinished();43}4445// Selector: 4136937746interface TokenProperties is Dummy, ERC165 {47 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa48 function setTokenPropertyPermission(49 string memory key,50 bool isMutable,51 bool collectionAdmin,52 bool tokenOwner53 ) external;5455 // Selector: setProperty(uint256,string,bytes) 1752d67b56 function setProperty(57 uint256 tokenId,58 string memory key,59 bytes memory value60 ) external;6162 // Selector: deleteProperty(uint256,string) 066111d163 function deleteProperty(uint256 tokenId, string memory key) external;6465 // Throws error if key not found66 //67 // Selector: property(uint256,string) 7228c32768 function property(uint256 tokenId, string memory key)69 external70 view71 returns (bytes memory);72}7374// Selector: 42966c6875interface ERC721Burnable is Dummy, ERC165 {76 // Selector: burn(uint256) 42966c6877 function burn(uint256 tokenId) external;78}7980// Selector: 5880016181interface ERC721 is Dummy, ERC165, ERC721Events {82 // Selector: balanceOf(address) 70a0823183 function balanceOf(address owner) external view returns (uint256);8485 // Selector: ownerOf(uint256) 6352211e86 function ownerOf(uint256 tokenId) external view returns (address);8788 // Not implemented89 //90 // Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a1167291 function safeTransferFromWithData(92 address from,93 address to,94 uint256 tokenId,95 bytes memory data96 ) external;9798 // Not implemented99 //100 // Selector: safeTransferFrom(address,address,uint256) 42842e0e101 function safeTransferFrom(102 address from,103 address to,104 uint256 tokenId105 ) external;106107 // Selector: transferFrom(address,address,uint256) 23b872dd108 function transferFrom(109 address from,110 address to,111 uint256 tokenId112 ) external;113114 // Selector: approve(address,uint256) 095ea7b3115 function approve(address approved, uint256 tokenId) external;116117 // Not implemented118 //119 // Selector: setApprovalForAll(address,bool) a22cb465120 function setApprovalForAll(address operator, bool approved) external;121122 // Not implemented123 //124 // Selector: getApproved(uint256) 081812fc125 function getApproved(uint256 tokenId) external view returns (address);126127 // Not implemented128 //129 // Selector: isApprovedForAll(address,address) e985e9c5130 function isApprovedForAll(address owner, address operator)131 external132 view133 returns (address);134}135136// Selector: 5b5e139f137interface ERC721Metadata is Dummy, ERC165 {138 // Selector: name() 06fdde03139 function name() external view returns (string memory);140141 // Selector: symbol() 95d89b41142 function symbol() external view returns (string memory);143144 // Returns token's const_metadata145 //146 // Selector: tokenURI(uint256) c87b56dd147 function tokenURI(uint256 tokenId) external view returns (string memory);148}149150// Selector: 68ccfe89151interface ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {152 // Selector: mintingFinished() 05d2035b153 function mintingFinished() external view returns (bool);154155 // `token_id` should be obtained with `next_token_id` method,156 // unlike standard, you can't specify it manually157 //158 // Selector: mint(address,uint256) 40c10f19159 function mint(address to, uint256 tokenId) external returns (bool);160161 // `token_id` should be obtained with `next_token_id` method,162 // unlike standard, you can't specify it manually163 //164 // Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f165 function mintWithTokenURI(166 address to,167 uint256 tokenId,168 string memory tokenUri169 ) external returns (bool);170171 // Not implemented172 //173 // Selector: finishMinting() 7d64bcb4174 function finishMinting() external returns (bool);175}176177// Selector: 780e9d63178interface ERC721Enumerable is Dummy, ERC165 {179 // Selector: tokenByIndex(uint256) 4f6ccce7180 function tokenByIndex(uint256 index) external view returns (uint256);181182 // Not implemented183 //184 // Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59185 function tokenOfOwnerByIndex(address owner, uint256 index)186 external187 view188 returns (uint256);189190 // Selector: totalSupply() 18160ddd191 function totalSupply() external view returns (uint256);192}193194// Selector: d74d154f195interface ERC721UniqueExtensions is Dummy, ERC165 {196 // Selector: transfer(address,uint256) a9059cbb197 function transfer(address to, uint256 tokenId) external;198199 // Selector: burnFrom(address,uint256) 79cc6790200 function burnFrom(address from, uint256 tokenId) external;201202 // Selector: nextTokenId() 75794a3c203 function nextTokenId() external view returns (uint256);204205 // Selector: mintBulk(address,uint256[]) 44a9945e206 function mintBulk(address to, uint256[] memory tokenIds)207 external208 returns (bool);209210 // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006211 function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)212 external213 returns (bool);214}215216// Selector: f5652829217interface Collection is Dummy, ERC165 {218 // Selector: setCollectionProperty(string,bytes) 2f073f66219 function setCollectionProperty(string memory key, bytes memory value)220 external;221222 // Selector: deleteCollectionProperty(string) 7b7debce223 function deleteCollectionProperty(string memory key) external;224225 // Throws error if key not found226 //227 // Selector: collectionProperty(string) cf24fd6d228 function collectionProperty(string memory key)229 external230 view231 returns (bytes memory);232233 // Selector: ethSetSponsor(address) 8f9af356234 function ethSetSponsor(address sponsor) external;235236 // Selector: ethConfirmSponsorship() a8580d1a237 function ethConfirmSponsorship() external;238239 // Selector: setLimit(string,string) bf4d2014240 function setLimit(string memory limit, string memory value) external;241242 // Selector: contractAddress() f6b4dfb4243 function contractAddress() external view returns (address);244}245246interface UniqueNFT is247 Dummy,248 ERC165,249 ERC721,250 ERC721Metadata,251 ERC721Enumerable,252 ERC721UniqueExtensions,253 ERC721Mintable,254 ERC721Burnable,255 Collection,256 TokenProperties257{}tests/src/eth/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -108,7 +108,7 @@
const limits = {
accountTokenOwnershipLimit: 1000,
sponsoredDataSize: 1024,
- sponsoredDataRateLimit: {Blocks: 30},
+ sponsoredDataRateLimit: 30,
tokenLimit: 1000000,
sponsorTransferTimeout: 6,
sponsorApproveTimeout: 6,
@@ -117,14 +117,21 @@
transfersEnabled: false,
};
- const limitsJson = JSON.stringify(limits, null, 1);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
- await collectionEvm.methods.setLimits(limitsJson).send();
+ await collectionEvm.methods.setLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit.toString()).send();
+ await collectionEvm.methods.setLimit('sponsoredDataSize', limits.sponsoredDataSize.toString()).send();
+ await collectionEvm.methods.setLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit.toString()).send();
+ await collectionEvm.methods.setLimit('tokenLimit', limits.tokenLimit.toString()).send();
+ await collectionEvm.methods.setLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout.toString()).send();
+ await collectionEvm.methods.setLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout.toString()).send();
+ await collectionEvm.methods.setLimit('ownerCanTransfer', limits.ownerCanTransfer.toString()).send();
+ await collectionEvm.methods.setLimit('ownerCanDestroy', limits.ownerCanDestroy.toString()).send();
+ await collectionEvm.methods.setLimit('transfersEnabled', limits.transfersEnabled.toString()).send();
const collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.be.eq(limits.accountTokenOwnershipLimit);
expect(collectionSub.limits.sponsoredDataSize.unwrap().toNumber()).to.be.eq(limits.sponsoredDataSize);
- expect(collectionSub.limits.sponsoredDataRateLimit.unwrap().asBlocks.toNumber()).to.be.eq(limits.sponsoredDataRateLimit.Blocks);
+ expect(collectionSub.limits.sponsoredDataRateLimit.unwrap().asBlocks.toNumber()).to.be.eq(limits.sponsoredDataRateLimit);
expect(collectionSub.limits.tokenLimit.unwrap().toNumber()).to.be.eq(limits.tokenLimit);
expect(collectionSub.limits.sponsorTransferTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorTransferTimeout);
expect(collectionSub.limits.sponsorApproveTimeout.unwrap().toNumber()).to.be.eq(limits.sponsorApproveTimeout);
@@ -171,6 +178,21 @@
// const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
// expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
});
+
+ itWeb3('Collection address exist', async ({api, web3}) => {
+ const owner = await createEthAccountWithBalance(api, web3);
+ const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
+ const collectionHelper = evmCollectionHelper(web3, owner);
+ expect(await collectionHelper.methods
+ .isCollectionExist(collectionAddressForNonexistentCollection).call())
+ .to.be.false;
+
+ const result = await collectionHelper.methods.create721Collection('Const collection', '5', '5').send();
+ const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
+ expect(await collectionHelper.methods
+ .isCollectionExist(collectionIdAddress).call())
+ .to.be.true;
+ });
});
describe('(!negative tests!) Create collection from EVM', () => {
@@ -218,30 +240,6 @@
await expect(helper.methods
.create721Collection(collectionName, description, tokenPrefix)
.call()).to.be.rejectedWith('NotSufficientFounds');
- });
-
- itWeb3('(!negative test!) Collection address (Create collection handle error)', async ({api, web3}) => {
- const owner = await createEthAccountWithBalance(api, web3);
- const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
- const collectionEvm = evmCollection(web3, owner, collectionAddressForNonexistentCollection);
- const EXPECTED_ERROR = 'Create collection handle error';
- {
- const sponsor = await createEthAccountWithBalance(api, web3);
- await expect(collectionEvm.methods
- .setSponsor(sponsor)
- .call()).to.be.rejectedWith(EXPECTED_ERROR);
-
- const sponsorCollection = evmCollection(web3, sponsor, collectionAddressForNonexistentCollection);
- await expect(sponsorCollection.methods
- .confirmSponsorship()
- .call()).to.be.rejectedWith(EXPECTED_ERROR);
- }
- {
- const limits = '{"account_token_ownership_limit":1000}';
- await expect(collectionEvm.methods
- .setLimits(limits)
- .call()).to.be.rejectedWith(EXPECTED_ERROR);
- }
});
itWeb3('(!negative test!) Check owner', async ({api, web3}) => {
@@ -255,18 +253,17 @@
{
const sponsor = await createEthAccountWithBalance(api, web3);
await expect(contractEvmFromNotOwner.methods
- .setSponsor(sponsor)
+ .ethSetSponsor(sponsor)
.call()).to.be.rejectedWith(EXPECTED_ERROR);
const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
await expect(sponsorCollection.methods
- .confirmSponsorship()
+ .ethConfirmSponsorship()
.call()).to.be.rejectedWith('Caller is not set as sponsor');
}
{
- const limits = '{"account_token_ownership_limit":1000}';
await expect(contractEvmFromNotOwner.methods
- .setLimits(limits)
+ .setLimit('account_token_ownership_limit', '1000')
.call()).to.be.rejectedWith(EXPECTED_ERROR);
}
});
@@ -277,9 +274,14 @@
const result = await collectionHelper.methods.create721Collection('Schema collection', 'A', 'A').send();
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
- const badJson = '{accountTokenOwnershipLimit: 1000}';
await expect(collectionEvm.methods
- .setLimits(badJson)
- .call()).to.be.rejectedWith('Parse JSON error:');
+ .setLimit('badLimit', 'true')
+ .call()).to.be.rejectedWith('Unknown limit "badLimit"');
+ await expect(collectionEvm.methods
+ .setLimit('sponsoredDataSize', 'badValue')
+ .call()).to.be.rejectedWith('Int value "badValue" parse error:');
+ await expect(collectionEvm.methods
+ .setLimit('ownerCanTransfer', 'badValue')
+ .call()).to.be.rejectedWith('Bool value "badValue" parse error:');
});
});
\ No newline at end of file
tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -325,11 +325,12 @@
},
{
"inputs": [
- { "internalType": "string", "name": "limitsJson", "type": "string" }
+ { "internalType": "string", "name": "limit", "type": "string" },
+ { "internalType": "string", "name": "value", "type": "string" }
],
- "name": "setLimits",
+ "name": "setLimit",
"outputs": [],
- "stateMutability": "view",
+ "stateMutability": "nonpayable",
"type": "function"
},
{