--- a/pallets/refungible/src/erc_token.rs +++ b/pallets/refungible/src/erc_token.rs @@ -59,8 +59,11 @@ let key_scoped = PropertyScope::Eth .apply(key) .expect("property key shouldn't exceed length limit"); - let value = props.get(&key_scoped).ok_or("key not found")?; - Ok(H160::from_slice(value.as_slice())) + if let Some(value) = props.get(&key_scoped) { + Ok(H160::from_slice(value.as_slice())) + } else { + Ok(*T::CrossTokenAddressMapping::token_to_address(self.id, self.1).as_eth()) + } } fn parent_token_id(&self) -> Result { @@ -71,13 +74,16 @@ let key_scoped = PropertyScope::Eth .apply(key) .expect("property key shouldn't exceed length limit"); - let value = props.get(&key_scoped).ok_or("key not found")?; - let nft_token_address = H160::from_slice(value.as_slice()); - let nft_token_account = T::CrossAccountId::from_eth(nft_token_address); - let (_, token_id) = T::CrossTokenAddressMapping::address_to_token(&nft_token_account) - .ok_or("parent NFT should contain NFT token address")?; + if let Some(value) = props.get(&key_scoped) { + let nft_token_address = H160::from_slice(value.as_slice()); + let nft_token_account = T::CrossAccountId::from_eth(nft_token_address); + let (_, token_id) = T::CrossTokenAddressMapping::address_to_token(&nft_token_account) + .ok_or("parent NFT should contain NFT token address")?; - Ok(token_id.into()) + Ok(token_id.into()) + } else { + Ok(self.1.into()) + } } } --- a/tests/src/eth/reFungibleToken.test.ts +++ b/tests/src/eth/reFungibleToken.test.ts @@ -655,5 +655,22 @@ expect(tokenAddress).to.be.equal(nftTokenAddress); expect(tokenId).to.be.equal(nftTokenId); }); + + itWeb3('Default parent token address and id', async ({api, web3, privateKeyWrapper}) => { + const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); + + const {collectionIdAddress, collectionId} = await createRefungibleCollection(api, web3, owner); + const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner); + const refungibleTokenId = await refungibleContract.methods.nextTokenId().call(); + await refungibleContract.methods.mint(owner, refungibleTokenId).send(); + + const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId); + const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner); + + const tokenAddress = await refungibleTokenContract.methods.parentToken().call(); + const tokenId = await refungibleTokenContract.methods.parentTokenId().call(); + expect(tokenAddress).to.be.equal(rftTokenAddress); + expect(tokenId).to.be.equal(refungibleTokenId); + }); });