git.delta.rocks / unique-network / refs/commits / 310b60e05536

difftreelog

CORE-320 Sponsorship for evm minting

Trubnikov Sergey2022-03-22parent: #7e99203.patch.diff
in: master

2 files changed

modifiedpallets/unique/src/eth/sponsoring.rsdiffbeforeafterboth
2929
30use pallet_nonfungible::erc::{UniqueNFTCall, ERC721UniqueExtensionsCall, ERC721Call};30use pallet_nonfungible::erc::{UniqueNFTCall, ERC721UniqueExtensionsCall, ERC721Call};
31use pallet_fungible::erc::{UniqueFungibleCall, ERC20Call};31use pallet_fungible::erc::{UniqueFungibleCall, ERC20Call};
32use up_data_structs::{CreateItemData, CreateNftData};
3233
33pub struct UniqueEthSponsorshipHandler<T: Config>(PhantomData<*const T>);34pub struct UniqueEthSponsorshipHandler<T: Config>(PhantomData<*const T>);
34impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)> for UniqueEthSponsorshipHandler<T> {35impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)> for UniqueEthSponsorshipHandler<T> {
57 withdraw_approve::<T>(&collection, who.as_sub(), &token_id)58 withdraw_approve::<T>(&collection, who.as_sub(), &token_id)
58 .map(|()| sponsor)59 .map(|()| sponsor)
59 }60 }
61 UniqueNFTCall::ERC721Mintable(call) => match call {
62 pallet_nonfungible::erc::ERC721MintableCall::Mint { .. } |
63 pallet_nonfungible::erc::ERC721MintableCall::MintWithTokenUri { .. } => {
64 withdraw_create_item(
65 &collection,
66 who.as_sub(),
67 &CreateItemData::NFT(CreateNftData::default()))
68 .map(|()| sponsor)
69 }
70 _ => None,
71 }
60 _ => None,72 _ => None,
61 }73 }
62 }74 }
modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
30} from './util/helpers';30} from './util/helpers';
31import {31import {
32 createCollectionExpectSuccess,32 createCollectionExpectSuccess,
33 createItemExpectSuccess,
34 getCreateCollectionResult,33 getCreateCollectionResult,
35 normalizeAccountId,
36 toSubstrateAddress,
37} from '../util/helpers';34} from '../util/helpers';
38import nonFungibleAbi from './nonFungibleAbi.json';35import nonFungibleAbi from './nonFungibleAbi.json';
39import {36import {
40 submitTransactionAsync,37 submitTransactionAsync,
41} from '../substrate/substrate-api';38} from '../substrate/substrate-api';
39import getBalance from '../substrate/get-balance';
42import { evmToAddress } from '@polkadot/util-crypto';40import {alicesPublicKey} from '../accounts';
4341
44describe('Sponsoring EVM contracts', () => {42describe('Sponsoring EVM contracts', () => {
45 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {43 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {
225 itWeb3.only('Sponsoring evm address from substrate collection', async ({api, web3}) => {216 itWeb3.only('Sponsoring evm address from substrate collection', async ({api, web3}) => {
226 const owner = privateKey('//Alice');217 const owner = privateKey('//Alice');
227 const userEth = createEthAccount(web3);218 const userEth = createEthAccount(web3);
228 const userSub = evmToAddress(userEth);
229 const collectionId = await createCollectionExpectSuccess();219 const collectionId = await createCollectionExpectSuccess();
230220
231 {221 {
244 const address = collectionIdToAddress(collectionId);234 const address = collectionIdToAddress(collectionId);
245 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});235 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});
236
237 { // This part should fail, because user not in access list and user have no money
246 const receiver = createEthAccount(web3);238 const nextTokenId = await contract.methods.nextTokenId().call();
247239 expect(nextTokenId).to.be.equal('1');
240 await expect(contract.methods.mintWithTokenURI(
241 userEth,
242 nextTokenId,
243 'Test URI',
248 { // This part should fail, because user not in access list and user have no money244 ).call({from: userEth})).to.be.rejectedWith(/PublicMintingNotAllowed/);
249 // const nextTokenId = await contract.methods.nextTokenId().call();245 }
250 // expect(nextTokenId).to.be.equal('1');
251 // const result = await contract.methods.mintWithTokenURI(
252 // receiver,
253 // nextTokenId,
254 // 'Test URI',
255 // ).send({from: userEth});
256 // const events = normalizeEvents(result.events);
257
258 // expect(events).to.be.deep.equal([
259 // {
260 // address,
261 // event: 'Transfer',
262 // args: {
263 // from: '0x0000000000000000000000000000000000000000',
264 // to: receiver,
265 // tokenId: nextTokenId,
266 // },
267 // },
268 // ]);
269
270 // expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
271 }
272246
273 {247 {
289 expect(result.success).to.be.true;263 expect(result.success).to.be.true;
290 }264 }
265
266 const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);
291267
292 {268 {
293 const nextTokenId = await contract.methods.nextTokenId().call();269 const nextTokenId = await contract.methods.nextTokenId().call();
294 expect(nextTokenId).to.be.equal('1');270 expect(nextTokenId).to.be.equal('1');
295 const result = await contract.methods.mintWithTokenURI(271 const result = await contract.methods.mintWithTokenURI(
296 receiver,272 userEth,
297 nextTokenId,273 nextTokenId,
298 'Test URI',274 'Test URI',
299 ).send({from: userEth});275 ).send({from: userEth});
305 event: 'Transfer',281 event: 'Transfer',
306 args: {282 args: {
307 from: '0x0000000000000000000000000000000000000000',283 from: '0x0000000000000000000000000000000000000000',
308 to: receiver,284 to: userEth,
309 tokenId: nextTokenId,285 tokenId: nextTokenId,
310 },286 },
311 },287 },
314 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');290 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
315 }291 }
316292
293 const [alicesBalanceAfter] = await getBalance(api, [alicesPublicKey]);
294 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
317 });295 });
318});296});
319297