difftreelog
added repartition method to refungible erc20 extensions
in: master
7 files changed
pallets/refungible/src/erc.rsdiffbeforeafterboth1// 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/>.161extern crate alloc;17extern crate alloc;2use evm_coder::{generate_stubgen, solidity_interface, types::*};18use evm_coder::{generate_stubgen, solidity_interface, types::*};pallets/refungible/src/erc_token.rsdiffbeforeafterboth150 Ok(true)150 Ok(true)151 }151 }152153 #[weight(<SelfWeightOf<T>>::repartition_item())]154 fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {155 let caller = T::CrossAccountId::from_eth(caller);156 let amount = amount.try_into().map_err(|_| "amount overflow")?;157158 <Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;159 Ok(true)160 }152}161}153162154impl<T: Config> RefungibleTokenHandle<T> {163impl<T: Config> RefungibleTokenHandle<T> {pallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth31 );31 );32}32}3334// Selector: 79cc679035contract ERC20UniqueExtensions is Dummy, ERC165 {36 // Selector: burnFrom(address,uint256) 79cc679037 function burnFrom(address from, uint256 amount) public returns (bool) {38 require(false, stub_error);39 from;40 amount;41 dummy = 0;42 return false;43 }44}453346// Selector: 942e8b2234// Selector: 942e8b2247contract ERC20 is Dummy, ERC165, ERC20Events {35contract ERC20 is Dummy, ERC165, ERC20Events {127 }115 }128}116}117118// Selector: ab8deb37119contract ERC20UniqueExtensions is Dummy, ERC165 {120 // Selector: burnFrom(address,uint256) 79cc6790121 function burnFrom(address from, uint256 amount) public returns (bool) {122 require(false, stub_error);123 from;124 amount;125 dummy = 0;126 return false;127 }128129 // Selector: repartition(uint256) d2418ca7130 function repartition(uint256 amount) public returns (bool) {131 require(false, stub_error);132 amount;133 dummy = 0;134 return false;135 }136}129137130contract UniqueRefungibleToken is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}138contract UniqueRefungibleToken is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}131139tests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth22 );22 );23}23}2425// Selector: 79cc679026interface ERC20UniqueExtensions is Dummy, ERC165 {27 // Selector: burnFrom(address,uint256) 79cc679028 function burnFrom(address from, uint256 amount) external returns (bool);29}302431// Selector: 942e8b2225// Selector: 942e8b2232interface ERC20 is Dummy, ERC165, ERC20Events {26interface ERC20 is Dummy, ERC165, ERC20Events {65 returns (uint256);59 returns (uint256);66}60}6162// Selector: ab8deb3763interface ERC20UniqueExtensions is Dummy, ERC165 {64 // Selector: burnFrom(address,uint256) 79cc679065 function burnFrom(address from, uint256 amount) external returns (bool);6667 // Selector: repartition(uint256) d2418ca768 function repartition(uint256 amount) external returns (bool);69}677068interface UniqueRefungibleToken is71interface UniqueRefungibleToken is69 Dummy,72 Dummy,tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth211 }211 }212 });212 });213214 itWeb3('Can perform repartition()', async ({web3, api, privateKeyWrapper}) => {215 const alice = privateKeyWrapper('//Alice');216217 const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;218219 const owner = createEthAccount(web3);220 await transferBalanceToEth(api, alice, owner);221222 const receiver = createEthAccount(web3);223 await transferBalanceToEth(api, alice, receiver);224225 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;226227 const address = tokenIdToAddress(collectionId, tokenId);228 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});229230 await contract.methods.repartition(200).send({from: owner});231 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);232 await contract.methods.transfer(receiver, 110).send({from: owner});233 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);234 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);235 236 await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected;237238 await contract.methods.transfer(receiver, 90).send({from: owner});239 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);240 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);241242 await contract.methods.repartition(150).send({from: receiver});243 await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;244 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);245 });213});246});214247215describe('Refungible: Fees', () => {248describe('Refungible: Fees', () => {tests/src/eth/reFungibleTokenAbi.jsondiffbeforeafterboth102 "stateMutability": "view",102 "stateMutability": "view",103 "type": "function"103 "type": "function"104 },104 },105 {106 "inputs": [107 { "internalType": "uint256", "name": "amount", "type": "uint256" }108 ],109 "name": "repartition",110 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],111 "stateMutability": "nonpayable",112 "type": "function"113 },105 {114 {106 "inputs": [115 "inputs": [107 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }116 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }