difftreelog
CORE-386 Implement eth methods
in: master
5 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -253,6 +253,42 @@
save(self);
Ok(())
}
+
+ fn set_access(&mut self, caller: caller, mode: string) -> Result<void> {
+ let caller = T::CrossAccountId::from_eth(caller);
+ self.check_is_owner_or_admin(&caller)
+ .map_err(dispatch_to_evm::<T>)?;
+ self.collection.permissions.access = Some(match mode.as_str() {
+ "Normal" => AccessMode::Normal,
+ "AllowList" => AccessMode::AllowList,
+ _ => return Err("Not supported access mode".into()),
+ });
+ save(self);
+ Ok(())
+ }
+
+ fn add_to_allow_list(&self, caller: caller, user: address) -> Result<void> {
+ let caller = check_is_owner_or_admin(caller, self)?;
+ let user = T::CrossAccountId::from_eth(user);
+ <Pallet<T>>::toggle_allowlist(self, &caller, &user, true)
+ .map_err(dispatch_to_evm::<T>)?;
+ Ok(())
+ }
+
+ fn remove_from_allow_list(&self, caller: caller, user: address) -> Result<void> {
+ let caller = check_is_owner_or_admin(caller, self)?;
+ let user = T::CrossAccountId::from_eth(user);
+ <Pallet<T>>::toggle_allowlist(self, &caller, &user, false)
+ .map_err(dispatch_to_evm::<T>)?;
+ Ok(())
+ }
+
+ fn set_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {
+ check_is_owner_or_admin(caller, self)?;
+ self.collection.permissions.mint_mode = Some(mode);
+ save(self);
+ Ok(())
+ }
}
fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<void> {
@@ -263,10 +299,7 @@
Ok(())
}
-fn check_is_owner_or_admin<T: Config>(
- caller: caller,
- collection: &CollectionHandle<T>,
-) -> Result<T::CrossAccountId> {
+fn check_is_owner_or_admin<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<T::CrossAccountId> {
let caller = T::CrossAccountId::from_eth(caller);
collection
.check_is_owner_or_admin(&caller)
@@ -274,11 +307,7 @@
Ok(caller)
}
-fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {
- // TODO possibly delete for the lack of transaction
- collection
- .check_is_internal()
- .map_err(dispatch_to_evm::<T>)?;
+fn save<T: Config>(collection: &CollectionHandle<T>) {
<crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());
Ok(())
}
pallets/nonfungible/src/stubs/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 holder13contract Dummy {14 uint8 dummy;15 string stub_error = "this contract is implemented in native";16}1718contract ERC165 is Dummy {19 function supportsInterface(bytes4 interfaceID)20 external21 view22 returns (bool)23 {24 require(false, stub_error);25 interfaceID;26 return true;27 }28}2930// Inline31contract ERC721Events {32 event Transfer(33 address indexed from,34 address indexed to,35 uint256 indexed tokenId36 );37 event Approval(38 address indexed owner,39 address indexed approved,40 uint256 indexed tokenId41 );42 event ApprovalForAll(43 address indexed owner,44 address indexed operator,45 bool approved46 );47}4849// Inline50contract ERC721MintableEvents {51 event MintingFinished();52}5354// Selector: 3a54513b55contract Collection is Dummy, ERC165 {56 // Selector: setCollectionProperty(string,bytes) 2f073f6657 function setCollectionProperty(string memory key, bytes memory value)58 public59 {60 require(false, stub_error);61 key;62 value;63 dummy = 0;64 }6566 // Selector: deleteCollectionProperty(string) 7b7debce67 function deleteCollectionProperty(string memory key) public {68 require(false, stub_error);69 key;70 dummy = 0;71 }7273 // Throws error if key not found74 //75 // Selector: collectionProperty(string) cf24fd6d76 function collectionProperty(string memory key)77 public78 view79 returns (bytes memory)80 {81 require(false, stub_error);82 key;83 dummy;84 return hex"";85 }8687 // Selector: ethSetSponsor(address) 8f9af35688 function ethSetSponsor(address sponsor) public {89 require(false, stub_error);90 sponsor;91 dummy = 0;92 }9394 // Selector: ethConfirmSponsorship() a8580d1a95 function ethConfirmSponsorship() public {96 require(false, stub_error);97 dummy = 0;98 }99100 // Selector: setLimit(string,uint32) 68db30ca101 function setLimit(string memory limit, uint32 value) public {102 require(false, stub_error);103 limit;104 value;105 dummy = 0;106 }107108 // Selector: setLimit(string,bool) ea67e4c2109 function setLimit(string memory limit, bool value) public {110 require(false, stub_error);111 limit;112 value;113 dummy = 0;114 }115116 // Selector: contractAddress() f6b4dfb4117 function contractAddress() public view returns (address) {118 require(false, stub_error);119 dummy;120 return 0x0000000000000000000000000000000000000000;121 }122123 // Selector: addAdmin(address) 70480275124 function addAdmin(address newAdmin) public view {125 require(false, stub_error);126 newAdmin;127 dummy;128 }129130 // Selector: removeAdmin(address) 1785f53c131 function removeAdmin(address admin) public view {132 require(false, stub_error);133 admin;134 dummy;135 }136137 // Selector: setNesting(bool) e8fc50dd138 function setNesting(bool enable) public {139 require(false, stub_error);140 enable;141 dummy = 0;142 }143144 // Selector: setNesting(bool,address[]) 7df12a9a145 function setNesting(bool enable, address[] memory collections) public {146 require(false, stub_error);147 enable;148 collections;149 dummy = 0;150 }151}152153// Selector: 41369377154contract TokenProperties is Dummy, ERC165 {155 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa156 function setTokenPropertyPermission(157 string memory key,158 bool isMutable,159 bool collectionAdmin,160 bool tokenOwner161 ) public {162 require(false, stub_error);163 key;164 isMutable;165 collectionAdmin;166 tokenOwner;167 dummy = 0;168 }169170 // Selector: setProperty(uint256,string,bytes) 1752d67b171 function setProperty(172 uint256 tokenId,173 string memory key,174 bytes memory value175 ) public {176 require(false, stub_error);177 tokenId;178 key;179 value;180 dummy = 0;181 }182183 // Selector: deleteProperty(uint256,string) 066111d1184 function deleteProperty(uint256 tokenId, string memory key) public {185 require(false, stub_error);186 tokenId;187 key;188 dummy = 0;189 }190191 // Throws error if key not found192 //193 // Selector: property(uint256,string) 7228c327194 function property(uint256 tokenId, string memory key)195 public196 view197 returns (bytes memory)198 {199 require(false, stub_error);200 tokenId;201 key;202 dummy;203 return hex"";204 }205}206207// Selector: 42966c68208contract ERC721Burnable is Dummy, ERC165 {209 // Selector: burn(uint256) 42966c68210 function burn(uint256 tokenId) public {211 require(false, stub_error);212 tokenId;213 dummy = 0;214 }215}216217// Selector: 58800161218contract ERC721 is Dummy, ERC165, ERC721Events {219 // Selector: balanceOf(address) 70a08231220 function balanceOf(address owner) public view returns (uint256) {221 require(false, stub_error);222 owner;223 dummy;224 return 0;225 }226227 // Selector: ownerOf(uint256) 6352211e228 function ownerOf(uint256 tokenId) public view returns (address) {229 require(false, stub_error);230 tokenId;231 dummy;232 return 0x0000000000000000000000000000000000000000;233 }234235 // Not implemented236 //237 // Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672238 function safeTransferFromWithData(239 address from,240 address to,241 uint256 tokenId,242 bytes memory data243 ) public {244 require(false, stub_error);245 from;246 to;247 tokenId;248 data;249 dummy = 0;250 }251252 // Not implemented253 //254 // Selector: safeTransferFrom(address,address,uint256) 42842e0e255 function safeTransferFrom(256 address from,257 address to,258 uint256 tokenId259 ) public {260 require(false, stub_error);261 from;262 to;263 tokenId;264 dummy = 0;265 }266267 // Selector: transferFrom(address,address,uint256) 23b872dd268 function transferFrom(269 address from,270 address to,271 uint256 tokenId272 ) public {273 require(false, stub_error);274 from;275 to;276 tokenId;277 dummy = 0;278 }279280 // Selector: approve(address,uint256) 095ea7b3281 function approve(address approved, uint256 tokenId) public {282 require(false, stub_error);283 approved;284 tokenId;285 dummy = 0;286 }287288 // Not implemented289 //290 // Selector: setApprovalForAll(address,bool) a22cb465291 function setApprovalForAll(address operator, bool approved) public {292 require(false, stub_error);293 operator;294 approved;295 dummy = 0;296 }297298 // Not implemented299 //300 // Selector: getApproved(uint256) 081812fc301 function getApproved(uint256 tokenId) public view returns (address) {302 require(false, stub_error);303 tokenId;304 dummy;305 return 0x0000000000000000000000000000000000000000;306 }307308 // Not implemented309 //310 // Selector: isApprovedForAll(address,address) e985e9c5311 function isApprovedForAll(address owner, address operator)312 public313 view314 returns (address)315 {316 require(false, stub_error);317 owner;318 operator;319 dummy;320 return 0x0000000000000000000000000000000000000000;321 }322}323324// Selector: 5b5e139f325contract ERC721Metadata is Dummy, ERC165 {326 // Selector: name() 06fdde03327 function name() public view returns (string memory) {328 require(false, stub_error);329 dummy;330 return "";331 }332333 // Selector: symbol() 95d89b41334 function symbol() public view returns (string memory) {335 require(false, stub_error);336 dummy;337 return "";338 }339340 // Returns token's const_metadata341 //342 // Selector: tokenURI(uint256) c87b56dd343 function tokenURI(uint256 tokenId) public view returns (string memory) {344 require(false, stub_error);345 tokenId;346 dummy;347 return "";348 }349}350351// Selector: 68ccfe89352contract ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {353 // Selector: mintingFinished() 05d2035b354 function mintingFinished() public view returns (bool) {355 require(false, stub_error);356 dummy;357 return false;358 }359360 // `token_id` should be obtained with `next_token_id` method,361 // unlike standard, you can't specify it manually362 //363 // Selector: mint(address,uint256) 40c10f19364 function mint(address to, uint256 tokenId) public returns (bool) {365 require(false, stub_error);366 to;367 tokenId;368 dummy = 0;369 return false;370 }371372 // `token_id` should be obtained with `next_token_id` method,373 // unlike standard, you can't specify it manually374 //375 // Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f376 function mintWithTokenURI(377 address to,378 uint256 tokenId,379 string memory tokenUri380 ) public returns (bool) {381 require(false, stub_error);382 to;383 tokenId;384 tokenUri;385 dummy = 0;386 return false;387 }388389 // Not implemented390 //391 // Selector: finishMinting() 7d64bcb4392 function finishMinting() public returns (bool) {393 require(false, stub_error);394 dummy = 0;395 return false;396 }397}398399// Selector: 780e9d63400contract ERC721Enumerable is Dummy, ERC165 {401 // Selector: tokenByIndex(uint256) 4f6ccce7402 function tokenByIndex(uint256 index) public view returns (uint256) {403 require(false, stub_error);404 index;405 dummy;406 return 0;407 }408409 // Not implemented410 //411 // Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59412 function tokenOfOwnerByIndex(address owner, uint256 index)413 public414 view415 returns (uint256)416 {417 require(false, stub_error);418 owner;419 index;420 dummy;421 return 0;422 }423424 // Selector: totalSupply() 18160ddd425 function totalSupply() public view returns (uint256) {426 require(false, stub_error);427 dummy;428 return 0;429 }430}431432// Selector: d74d154f433contract ERC721UniqueExtensions is Dummy, ERC165 {434 // Selector: transfer(address,uint256) a9059cbb435 function transfer(address to, uint256 tokenId) public {436 require(false, stub_error);437 to;438 tokenId;439 dummy = 0;440 }441442 // Selector: burnFrom(address,uint256) 79cc6790443 function burnFrom(address from, uint256 tokenId) public {444 require(false, stub_error);445 from;446 tokenId;447 dummy = 0;448 }449450 // Selector: nextTokenId() 75794a3c451 function nextTokenId() public view returns (uint256) {452 require(false, stub_error);453 dummy;454 return 0;455 }456457 // Selector: mintBulk(address,uint256[]) 44a9945e458 function mintBulk(address to, uint256[] memory tokenIds)459 public460 returns (bool)461 {462 require(false, stub_error);463 to;464 tokenIds;465 dummy = 0;466 return false;467 }468469 // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006470 function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)471 public472 returns (bool)473 {474 require(false, stub_error);475 to;476 tokens;477 dummy = 0;478 return false;479 }480}481482contract UniqueNFT is483 Dummy,484 ERC165,485 ERC721,486 ERC721Metadata,487 ERC721Enumerable,488 ERC721UniqueExtensions,489 ERC721Mintable,490 ERC721Burnable,491 Collection,492 TokenProperties493{}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 holder13contract Dummy {14 uint8 dummy;15 string stub_error = "this contract is implemented in native";16}1718contract ERC165 is Dummy {19 function supportsInterface(bytes4 interfaceID)20 external21 view22 returns (bool)23 {24 require(false, stub_error);25 interfaceID;26 return true;27 }28}2930// Inline31contract ERC721Events {32 event Transfer(33 address indexed from,34 address indexed to,35 uint256 indexed tokenId36 );37 event Approval(38 address indexed owner,39 address indexed approved,40 uint256 indexed tokenId41 );42 event ApprovalForAll(43 address indexed owner,44 address indexed operator,45 bool approved46 );47}4849// Inline50contract ERC721MintableEvents {51 event MintingFinished();52}5354// Selector: 4136937755contract TokenProperties is Dummy, ERC165 {56 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa57 function setTokenPropertyPermission(58 string memory key,59 bool isMutable,60 bool collectionAdmin,61 bool tokenOwner62 ) public {63 require(false, stub_error);64 key;65 isMutable;66 collectionAdmin;67 tokenOwner;68 dummy = 0;69 }7071 // Selector: setProperty(uint256,string,bytes) 1752d67b72 function setProperty(73 uint256 tokenId,74 string memory key,75 bytes memory value76 ) public {77 require(false, stub_error);78 tokenId;79 key;80 value;81 dummy = 0;82 }8384 // Selector: deleteProperty(uint256,string) 066111d185 function deleteProperty(uint256 tokenId, string memory key) public {86 require(false, stub_error);87 tokenId;88 key;89 dummy = 0;90 }9192 // Throws error if key not found93 //94 // Selector: property(uint256,string) 7228c32795 function property(uint256 tokenId, string memory key)96 public97 view98 returns (bytes memory)99 {100 require(false, stub_error);101 tokenId;102 key;103 dummy;104 return hex"";105 }106}107108// Selector: 42966c68109contract ERC721Burnable is Dummy, ERC165 {110 // Selector: burn(uint256) 42966c68111 function burn(uint256 tokenId) public {112 require(false, stub_error);113 tokenId;114 dummy = 0;115 }116}117118// Selector: 58800161119contract ERC721 is Dummy, ERC165, ERC721Events {120 // Selector: balanceOf(address) 70a08231121 function balanceOf(address owner) public view returns (uint256) {122 require(false, stub_error);123 owner;124 dummy;125 return 0;126 }127128 // Selector: ownerOf(uint256) 6352211e129 function ownerOf(uint256 tokenId) public view returns (address) {130 require(false, stub_error);131 tokenId;132 dummy;133 return 0x0000000000000000000000000000000000000000;134 }135136 // Not implemented137 //138 // Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672139 function safeTransferFromWithData(140 address from,141 address to,142 uint256 tokenId,143 bytes memory data144 ) public {145 require(false, stub_error);146 from;147 to;148 tokenId;149 data;150 dummy = 0;151 }152153 // Not implemented154 //155 // Selector: safeTransferFrom(address,address,uint256) 42842e0e156 function safeTransferFrom(157 address from,158 address to,159 uint256 tokenId160 ) public {161 require(false, stub_error);162 from;163 to;164 tokenId;165 dummy = 0;166 }167168 // Selector: transferFrom(address,address,uint256) 23b872dd169 function transferFrom(170 address from,171 address to,172 uint256 tokenId173 ) public {174 require(false, stub_error);175 from;176 to;177 tokenId;178 dummy = 0;179 }180181 // Selector: approve(address,uint256) 095ea7b3182 function approve(address approved, uint256 tokenId) public {183 require(false, stub_error);184 approved;185 tokenId;186 dummy = 0;187 }188189 // Not implemented190 //191 // Selector: setApprovalForAll(address,bool) a22cb465192 function setApprovalForAll(address operator, bool approved) public {193 require(false, stub_error);194 operator;195 approved;196 dummy = 0;197 }198199 // Not implemented200 //201 // Selector: getApproved(uint256) 081812fc202 function getApproved(uint256 tokenId) public view returns (address) {203 require(false, stub_error);204 tokenId;205 dummy;206 return 0x0000000000000000000000000000000000000000;207 }208209 // Not implemented210 //211 // Selector: isApprovedForAll(address,address) e985e9c5212 function isApprovedForAll(address owner, address operator)213 public214 view215 returns (address)216 {217 require(false, stub_error);218 owner;219 operator;220 dummy;221 return 0x0000000000000000000000000000000000000000;222 }223}224225// Selector: 5b5e139f226contract ERC721Metadata is Dummy, ERC165 {227 // Selector: name() 06fdde03228 function name() public view returns (string memory) {229 require(false, stub_error);230 dummy;231 return "";232 }233234 // Selector: symbol() 95d89b41235 function symbol() public view returns (string memory) {236 require(false, stub_error);237 dummy;238 return "";239 }240241 // Returns token's const_metadata242 //243 // Selector: tokenURI(uint256) c87b56dd244 function tokenURI(uint256 tokenId) public view returns (string memory) {245 require(false, stub_error);246 tokenId;247 dummy;248 return "";249 }250}251252// Selector: 68ccfe89253contract ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {254 // Selector: mintingFinished() 05d2035b255 function mintingFinished() public view returns (bool) {256 require(false, stub_error);257 dummy;258 return false;259 }260261 // `token_id` should be obtained with `next_token_id` method,262 // unlike standard, you can't specify it manually263 //264 // Selector: mint(address,uint256) 40c10f19265 function mint(address to, uint256 tokenId) public returns (bool) {266 require(false, stub_error);267 to;268 tokenId;269 dummy = 0;270 return false;271 }272273 // `token_id` should be obtained with `next_token_id` method,274 // unlike standard, you can't specify it manually275 //276 // Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f277 function mintWithTokenURI(278 address to,279 uint256 tokenId,280 string memory tokenUri281 ) public returns (bool) {282 require(false, stub_error);283 to;284 tokenId;285 tokenUri;286 dummy = 0;287 return false;288 }289290 // Not implemented291 //292 // Selector: finishMinting() 7d64bcb4293 function finishMinting() public returns (bool) {294 require(false, stub_error);295 dummy = 0;296 return false;297 }298}299300// Selector: 780e9d63301contract ERC721Enumerable is Dummy, ERC165 {302 // Selector: tokenByIndex(uint256) 4f6ccce7303 function tokenByIndex(uint256 index) public view returns (uint256) {304 require(false, stub_error);305 index;306 dummy;307 return 0;308 }309310 // Not implemented311 //312 // Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59313 function tokenOfOwnerByIndex(address owner, uint256 index)314 public315 view316 returns (uint256)317 {318 require(false, stub_error);319 owner;320 index;321 dummy;322 return 0;323 }324325 // Selector: totalSupply() 18160ddd326 function totalSupply() public view returns (uint256) {327 require(false, stub_error);328 dummy;329 return 0;330 }331}332333// Selector: d74d154f334contract ERC721UniqueExtensions is Dummy, ERC165 {335 // Selector: transfer(address,uint256) a9059cbb336 function transfer(address to, uint256 tokenId) public {337 require(false, stub_error);338 to;339 tokenId;340 dummy = 0;341 }342343 // Selector: burnFrom(address,uint256) 79cc6790344 function burnFrom(address from, uint256 tokenId) public {345 require(false, stub_error);346 from;347 tokenId;348 dummy = 0;349 }350351 // Selector: nextTokenId() 75794a3c352 function nextTokenId() public view returns (uint256) {353 require(false, stub_error);354 dummy;355 return 0;356 }357358 // Selector: mintBulk(address,uint256[]) 44a9945e359 function mintBulk(address to, uint256[] memory tokenIds)360 public361 returns (bool)362 {363 require(false, stub_error);364 to;365 tokenIds;366 dummy = 0;367 return false;368 }369370 // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006371 function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)372 public373 returns (bool)374 {375 require(false, stub_error);376 to;377 tokens;378 dummy = 0;379 return false;380 }381}382383// Selector: f56cd7fa384contract Collection is Dummy, ERC165 {385 // Selector: setCollectionProperty(string,bytes) 2f073f66386 function setCollectionProperty(string memory key, bytes memory value)387 public388 {389 require(false, stub_error);390 key;391 value;392 dummy = 0;393 }394395 // Selector: deleteCollectionProperty(string) 7b7debce396 function deleteCollectionProperty(string memory key) public {397 require(false, stub_error);398 key;399 dummy = 0;400 }401402 // Throws error if key not found403 //404 // Selector: collectionProperty(string) cf24fd6d405 function collectionProperty(string memory key)406 public407 view408 returns (bytes memory)409 {410 require(false, stub_error);411 key;412 dummy;413 return hex"";414 }415416 // Selector: ethSetSponsor(address) 8f9af356417 function ethSetSponsor(address sponsor) public {418 require(false, stub_error);419 sponsor;420 dummy = 0;421 }422423 // Selector: ethConfirmSponsorship() a8580d1a424 function ethConfirmSponsorship() public {425 require(false, stub_error);426 dummy = 0;427 }428429 // Selector: setLimit(string,uint32) 68db30ca430 function setLimit(string memory limit, uint32 value) public {431 require(false, stub_error);432 limit;433 value;434 dummy = 0;435 }436437 // Selector: setLimit(string,bool) ea67e4c2438 function setLimit(string memory limit, bool value) public {439 require(false, stub_error);440 limit;441 value;442 dummy = 0;443 }444445 // Selector: contractAddress() f6b4dfb4446 function contractAddress() public view returns (address) {447 require(false, stub_error);448 dummy;449 return 0x0000000000000000000000000000000000000000;450 }451452 // Selector: addAdmin(address) 70480275453 function addAdmin(address newAdmin) public view {454 require(false, stub_error);455 newAdmin;456 dummy;457 }458459 // Selector: removeAdmin(address) 1785f53c460 function removeAdmin(address admin) public view {461 require(false, stub_error);462 admin;463 dummy;464 }465466 // Selector: setNesting(bool) e8fc50dd467 function setNesting(bool enable) public {468 require(false, stub_error);469 enable;470 dummy = 0;471 }472473 // Selector: setNesting(bool,address[]) 7df12a9a474 function setNesting(bool enable, address[] memory collections) public {475 require(false, stub_error);476 enable;477 collections;478 dummy = 0;479 }480481 // Selector: setAccess(string) 488f56aa482 function setAccess(string memory mode) public {483 require(false, stub_error);484 mode;485 dummy = 0;486 }487488 // Selector: addToAllowList(address) 31f59102489 function addToAllowList(address user) public view {490 require(false, stub_error);491 user;492 dummy;493 }494495 // Selector: removeFromAllowList(address) eba8dabc496 function removeFromAllowList(address user) public view {497 require(false, stub_error);498 user;499 dummy;500 }501502 // Selector: setMintMode(bool) 5dea9bd5503 function setMintMode(bool mode) public {504 require(false, stub_error);505 mode;506 dummy = 0;507 }508}509510contract UniqueNFT is511 Dummy,512 ERC165,513 ERC721,514 ERC721Metadata,515 ERC721Enumerable,516 ERC721UniqueExtensions,517 ERC721Mintable,518 ERC721Burnable,519 Collection,520 TokenProperties521{}tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -42,51 +42,6 @@
event MintingFinished();
}
-// Selector: 3a54513b
-interface Collection is Dummy, ERC165 {
- // Selector: setCollectionProperty(string,bytes) 2f073f66
- function setCollectionProperty(string memory key, bytes memory value)
- external;
-
- // Selector: deleteCollectionProperty(string) 7b7debce
- function deleteCollectionProperty(string memory key) external;
-
- // Throws error if key not found
- //
- // Selector: collectionProperty(string) cf24fd6d
- function collectionProperty(string memory key)
- external
- view
- returns (bytes memory);
-
- // Selector: ethSetSponsor(address) 8f9af356
- function ethSetSponsor(address sponsor) external;
-
- // Selector: ethConfirmSponsorship() a8580d1a
- function ethConfirmSponsorship() external;
-
- // Selector: setLimit(string,uint32) 68db30ca
- function setLimit(string memory limit, uint32 value) external;
-
- // Selector: setLimit(string,bool) ea67e4c2
- function setLimit(string memory limit, bool value) external;
-
- // Selector: contractAddress() f6b4dfb4
- function contractAddress() external view returns (address);
-
- // Selector: addAdmin(address) 70480275
- function addAdmin(address newAdmin) external view;
-
- // Selector: removeAdmin(address) 1785f53c
- function removeAdmin(address admin) external view;
-
- // Selector: setNesting(bool) e8fc50dd
- function setNesting(bool enable) external;
-
- // Selector: setNesting(bool,address[]) 7df12a9a
- function setNesting(bool enable, address[] memory collections) external;
-}
-
// Selector: 41369377
interface TokenProperties is Dummy, ERC165 {
// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
@@ -258,6 +213,63 @@
returns (bool);
}
+// Selector: f56cd7fa
+interface Collection is Dummy, ERC165 {
+ // Selector: setCollectionProperty(string,bytes) 2f073f66
+ function setCollectionProperty(string memory key, bytes memory value)
+ external;
+
+ // Selector: deleteCollectionProperty(string) 7b7debce
+ function deleteCollectionProperty(string memory key) external;
+
+ // Throws error if key not found
+ //
+ // Selector: collectionProperty(string) cf24fd6d
+ function collectionProperty(string memory key)
+ external
+ view
+ returns (bytes memory);
+
+ // Selector: ethSetSponsor(address) 8f9af356
+ function ethSetSponsor(address sponsor) external;
+
+ // Selector: ethConfirmSponsorship() a8580d1a
+ function ethConfirmSponsorship() external;
+
+ // Selector: setLimit(string,uint32) 68db30ca
+ function setLimit(string memory limit, uint32 value) external;
+
+ // Selector: setLimit(string,bool) ea67e4c2
+ function setLimit(string memory limit, bool value) external;
+
+ // Selector: contractAddress() f6b4dfb4
+ function contractAddress() external view returns (address);
+
+ // Selector: addAdmin(address) 70480275
+ function addAdmin(address newAdmin) external view;
+
+ // Selector: removeAdmin(address) 1785f53c
+ function removeAdmin(address admin) external view;
+
+ // Selector: setNesting(bool) e8fc50dd
+ function setNesting(bool enable) external;
+
+ // Selector: setNesting(bool,address[]) 7df12a9a
+ function setNesting(bool enable, address[] memory collections) external;
+
+ // Selector: setAccess(string) 488f56aa
+ function setAccess(string memory mode) external;
+
+ // Selector: addToAllowList(address) 31f59102
+ function addToAllowList(address user) external view;
+
+ // Selector: removeFromAllowList(address) eba8dabc
+ function removeFromAllowList(address user) external view;
+
+ // Selector: setMintMode(bool) 5dea9bd5
+ function setMintMode(bool mode) external;
+}
+
interface UniqueNFT is
Dummy,
ERC165,
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -221,6 +221,7 @@
expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
});
+ //TODO: CORE-302 add eth methods
itWeb3('Sponsoring collection from evm address via access list', async ({api, web3}) => {
const owner = await createEthAccountWithBalance(api, web3);
const collectionHelpers = evmCollectionHelpers(web3, owner);
@@ -228,65 +229,60 @@
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
- result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
+ result = await collectionEvm.methods.ethSetSponsor(sponsor).send({from: owner});
let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
- await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
+ await collectionEvm.methods.ethConfirmSponsorship().send({from: sponsor});
collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isConfirmed).to.be.true;
expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
const user = createEthAccount(web3);
- let nextTokenId = await collectionEvm.methods.nextTokenId().call();
+ const nextTokenId = await collectionEvm.methods.nextTokenId().call();
expect(nextTokenId).to.be.equal('1');
const oldPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
expect(oldPermissions.mintMode).to.be.false;
expect(oldPermissions.access).to.be.equal('Normal');
- //TODO: change value, when enum generated
- await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
- await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
- await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
+ await collectionEvm.methods.setAccess('AllowList').send({from: owner});
+ await collectionEvm.methods.addToAllowList(user).send({from: owner});
+ await collectionEvm.methods.setMintMode(true).send({from: owner});
const newPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
expect(newPermissions.mintMode).to.be.true;
expect(newPermissions.access).to.be.equal('AllowList');
- const ownerBalanceBefore = await ethBalanceViaSub(api, owner);
- const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
+ // const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);
- nextTokenId = await collectionEvm.methods.nextTokenId().call({from: user});
- expect(nextTokenId).to.be.equal('1');
- result = await collectionEvm.methods.mintWithTokenURI(
- user,
- nextTokenId,
- 'Test URI',
- ).send({from: user});
- const events = normalizeEvents(result.events);
- events[0].address = events[0].address.toLocaleLowerCase();
+ {
+ const nextTokenId = await collectionEvm.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const result = await collectionEvm.methods.mintWithTokenURI(
+ user,
+ nextTokenId,
+ 'Test URI',
+ ).call({from: user});
+ console.log(result);
+ const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address: collectionIdAddress.toLocaleLowerCase(),
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: user,
- tokenId: nextTokenId,
+ expect(events).to.be.deep.equal([
+ {
+ collectionIdAddress,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: user,
+ tokenId: nextTokenId,
+ },
},
- },
- ]);
-
- expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ ]);
- const ownerBalanceAfter = await ethBalanceViaSub(api, owner);
- expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
- const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);
- expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ }
});
itWeb3('Check that transaction via EVM spend money from sponsor address', async ({api, web3}) => {
@@ -296,22 +292,23 @@
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
- result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();
+ result = await collectionEvm.methods.ethSetSponsor(sponsor).send();
let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
- await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
+ await expect(collectionEvm.methods.ethConfirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
- await sponsorCollection.methods.confirmCollectionSponsorship().send();
+ await sponsorCollection.methods.ethConfirmSponsorship().send();
collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isConfirmed).to.be.true;
expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
const user = createEthAccount(web3);
- await collectionEvm.methods.addCollectionAdmin(user).send();
+ await collectionEvm.methods.addAdmin(user).send();
const ownerBalanceBefore = await ethBalanceViaSub(api, owner);
const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
+
const userCollectionEvm = evmCollection(web3, user, collectionIdAddress);
const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();
tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -91,6 +91,15 @@
},
{
"inputs": [
+ { "internalType": "address", "name": "user", "type": "address" }
+ ],
+ "name": "addToAllowList",
+ "outputs": [],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "address", "name": "approved", "type": "address" },
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
@@ -291,6 +300,15 @@
},
{
"inputs": [
+ { "internalType": "address", "name": "user", "type": "address" }
+ ],
+ "name": "removeFromAllowList",
+ "outputs": [],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "address", "name": "from", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
@@ -313,6 +331,13 @@
"type": "function"
},
{
+ "inputs": [{ "internalType": "string", "name": "mode", "type": "string" }],
+ "name": "setAccess",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
"inputs": [
{ "internalType": "address", "name": "operator", "type": "address" },
{ "internalType": "bool", "name": "approved", "type": "bool" }
@@ -397,6 +422,13 @@
"type": "function"
},
{
+ "inputs": [{ "internalType": "bool", "name": "mode", "type": "bool" }],
+ "name": "setMintMode",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
"inputs": [
{ "internalType": "bool", "name": "enable", "type": "bool" },
{