difftreelog
CORE-320 Sponsorship for evm minting
in: master
2 files changed
pallets/unique/src/eth/sponsoring.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/sponsoring.rs
+++ b/pallets/unique/src/eth/sponsoring.rs
@@ -29,6 +29,7 @@
use pallet_nonfungible::erc::{UniqueNFTCall, ERC721UniqueExtensionsCall, ERC721Call};
use pallet_fungible::erc::{UniqueFungibleCall, ERC20Call};
+use up_data_structs::{CreateItemData, CreateNftData};
pub struct UniqueEthSponsorshipHandler<T: Config>(PhantomData<*const T>);
impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)> for UniqueEthSponsorshipHandler<T> {
@@ -57,6 +58,17 @@
withdraw_approve::<T>(&collection, who.as_sub(), &token_id)
.map(|()| sponsor)
}
+ UniqueNFTCall::ERC721Mintable(call) => match call {
+ pallet_nonfungible::erc::ERC721MintableCall::Mint { .. } |
+ pallet_nonfungible::erc::ERC721MintableCall::MintWithTokenUri { .. } => {
+ withdraw_create_item(
+ &collection,
+ who.as_sub(),
+ &CreateItemData::NFT(CreateNftData::default()))
+ .map(|()| sponsor)
+ }
+ _ => None,
+ }
_ => None,
}
}
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth30} 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';434144describe('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();230220231 {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});236237 { // This part should fail, because user not in access list and user have no money246 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);257258 // 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 // ]);269270 // expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');271 }272246273 {247 {289 expect(result.success).to.be.true;263 expect(result.success).to.be.true;290 }264 }265266 const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);291267292 {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 }316292293 const [alicesBalanceAfter] = await getBalance(api, [alicesPublicKey]);294 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;317 });295 });318});296});319297