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.tsdiffbeforeafterboth--- 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);
+ });
});