Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add acceptance tests for cryptoTransfer function #485

Merged
merged 7 commits into from
Sep 6, 2022

Conversation

lukelee-sl
Copy link
Member

Signed-off-by: lukelee-sl luke.lee@swirldslabs.com

Description:
hashgraph/hedera-services#3758

The issue referenced above in hedera-services describes several scenarios where using the cryptoTransfer function fails.

Currently, cryptoTransfer succeeds only when the token type being transferred is of homogenous (fungible -> fungible or nft -> nft). Also there is no support for sending hbars as one of the legs of the transfer.

Added several acceptance tests to show use cases where the function succeeds and also when it fails due to heterogeneous token types.

Related issue(s):
hashgraph/hedera-services#3758

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com>
@lukelee-sl lukelee-sl self-assigned this Aug 31, 2022
Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com>
@codecov-commenter
Copy link

codecov-commenter commented Aug 31, 2022

Codecov Report

Merging #485 (8fd7615) into main (37b3bae) will not change coverage.
The diff coverage is n/a.

❗ Current head 8fd7615 differs from pull request most recent head 9afe9ff. Consider uploading reports for the commit 9afe9ff to get more accurate results

@@           Coverage Diff           @@
##             main     #485   +/-   ##
=======================================
  Coverage   76.38%   76.38%           
=======================================
  Files          12       12           
  Lines         923      923           
  Branches      144      144           
=======================================
  Hits          705      705           
  Misses        165      165           
  Partials       53       53           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com>
@lukelee-sl
Copy link
Member Author

Here are some results after some exploration.

  • In services code there is a checks that ensures that fungibles transfers add up to zero.
  • The solidity cryptoTransfer function takes IHederaTokenService.TokenTransferList[] as an argument.
    • TokenTransferList is a struct that contains both and array of AccountAmount (for fungible tokens) and an array of NftTransfer (for NFT). A user could take this to mean that a transfer of heterogeneous types of tokens is possible but services code seems to indicate that this is not possible.
  • In my test - homogeneous transfers using crytoTransfer worked
  • but heterogeneous transfers failed (as expected).
  • I attempted to swap NFT tokens in two separate accounts in a single call and was not successful.
  • Also attempted to transfer tokens from a wallet after it was given an allowance but a separate account and was not successful.
  • Possible future feature improvements
    • Allow for heterogeneous token type cryptoTransfer
    • Allow HBARs to be transferred as part of the cryptoTransfer

Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com>
Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com>
Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions

packages/server/tests/acceptance/htsPrecompile.spec.ts Outdated Show resolved Hide resolved
packages/server/tests/contracts/BaseHTS.sol Outdated Show resolved Hide resolved
packages/server/tests/acceptance/htsPrecompile.spec.ts Outdated Show resolved Hide resolved
packages/server/tests/acceptance/htsPrecompile.spec.ts Outdated Show resolved Hide resolved
packages/server/tests/acceptance/htsPrecompile.spec.ts Outdated Show resolved Hide resolved
@stoqnkpL
Copy link

stoqnkpL commented Sep 2, 2022

There are a couple of problems with the setup:

  1. The HTS precompiled contract function cryptoTransfer(TokenTransferList[] memory tokenTransfers) does not support transfers using allowances, it was never designed to. Currently, the only way to make a transfer using allowances through the precompile is to use the redirect functions transferFrom:
    IERC20(token).transferFrom(sender, recipient, amount);
    IERC721(token).transferFrom(from, to, tokenId);

I'm not sure why the transferFrom functions were not exposed to HTS precompile top-level like the other functions from ERC20 and ERC721 were with PR3638. In any case, the cryptoTransfer function will not work with allowances.

  1. Transfers of HBars via cryptoTransfer is also not supported, only transfers of Fungible tokens and NFTs.

For context, we have existing EETs covering the transfer of tokens (including mixing fungible and nfts) via cryptoTransfer here.
We have existing EETs covering the transferFrom ERC redirect functions here.

Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com>
Nana-EC
Nana-EC previously approved these changes Sep 3, 2022
Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

packages/server/tests/acceptance/htsPrecompile.spec.ts Outdated Show resolved Hide resolved
@Nana-EC Nana-EC added enhancement New feature or request P1 process Build, test and deployment-process related tasks labels Sep 3, 2022
@Nana-EC Nana-EC added this to the 0.8.0 milestone Sep 3, 2022
Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com>
@sonarcloud
Copy link

sonarcloud bot commented Sep 3, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@lukelee-sl lukelee-sl merged commit 53153e4 into main Sep 6, 2022
@lukelee-sl lukelee-sl deleted the 3758-add-cryptoTransfer-acceptance-tests branch September 6, 2022 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 process Build, test and deployment-process related tasks
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants