difftreelog
chore make rft token default if parent token is not set
in: master
2 files changed
pallets/refungible/src/erc_token.rsdiffbeforeafterboth59 let key_scoped = PropertyScope::Eth59 let key_scoped = PropertyScope::Eth60 .apply(key)60 .apply(key)61 .expect("property key shouldn't exceed length limit");61 .expect("property key shouldn't exceed length limit");62 let value = props.get(&key_scoped).ok_or("key not found")?;62 if let Some(value) = props.get(&key_scoped) {63 Ok(H160::from_slice(value.as_slice()))63 Ok(H160::from_slice(value.as_slice()))64 } else {65 Ok(*T::CrossTokenAddressMapping::token_to_address(self.id, self.1).as_eth())66 }64 }67 }656866 fn parent_token_id(&self) -> Result<uint256> {69 fn parent_token_id(&self) -> Result<uint256> {71 let key_scoped = PropertyScope::Eth74 let key_scoped = PropertyScope::Eth72 .apply(key)75 .apply(key)73 .expect("property key shouldn't exceed length limit");76 .expect("property key shouldn't exceed length limit");74 let value = props.get(&key_scoped).ok_or("key not found")?;77 if let Some(value) = props.get(&key_scoped) {75 let nft_token_address = H160::from_slice(value.as_slice());78 let nft_token_address = H160::from_slice(value.as_slice());76 let nft_token_account = T::CrossAccountId::from_eth(nft_token_address);79 let nft_token_account = T::CrossAccountId::from_eth(nft_token_address);77 let (_, token_id) = T::CrossTokenAddressMapping::address_to_token(&nft_token_account)80 let (_, token_id) = T::CrossTokenAddressMapping::address_to_token(&nft_token_account)78 .ok_or("parent NFT should contain NFT token address")?;81 .ok_or("parent NFT should contain NFT token address")?;798280 Ok(token_id.into())83 Ok(token_id.into())84 } else {85 Ok(self.1.into())86 }81 }87 }82}88}8389tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth656 expect(tokenId).to.be.equal(nftTokenId);656 expect(tokenId).to.be.equal(nftTokenId);657 });657 });658659 itWeb3('Default parent token address and id', async ({api, web3, privateKeyWrapper}) => {660 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);661662 const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner);663 const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);664 const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();665 await refungibleContract.methods.mint(owner, refungibleTokenId).send();666667 const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);668 const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);669670 const tokenAddress = await refungibleTokenContract.methods.parentToken().call();671 const tokenId = await refungibleTokenContract.methods.parentTokenId().call();672 expect(tokenAddress).to.be.equal(rftTokenAddress);673 expect(tokenId).to.be.equal(refungibleTokenId);674 });658});675});659676660677