hashgraph / hedera-smart-contracts

Contains Hedera Smart Contract Service supporting files
Apache License 2.0
37 stars 51 forks source link

fix: updated current dependencies and migrate from ethersjs v5.x to v6.x (#642 #550) #644

Closed quiet-node closed 5 months ago

quiet-node commented 6 months ago

Description: This pull request aims to update the existing dependencies to their latest versions and migrate all test suites from using ethers.js@v5 to ethers.js@v6. Additional details can be found in issue#641.

Tasks done:

Upgraded all dependencies to the latest versions

Migrated from ethersjs v5 to v6

  1. Utility functions can now be accessed directly from the ethers object rather than the ethers.utils object.

  2. The .address() method has been replaced with await .getAddress() and the removal of await contract.deployed()

    • In v6, deployment transactions now return typed BaseContract objects. The .address attribute has been removed and replaced with the .getAddress() ⇒ Promise<string> function which provides the resolved address of the contract
    • .deployed() has also been removed from the BaseContract objects
  3. The .getSighash(x) method has been replaced with .getFunction(x).selector.

    • In version 6, the Interface class no longer includes the .getSighash(x) method. Instead, .getFunction(x).selector is now in use.
  4. The ethers.constants.AddressZero has been replaced with ethers.ZeroAddress

  5. The ethers.constants.HashZero has been replaced with ethers.ZeroHash

  6. The .events object has been replaced with the .logs object. Within the logs object, the .event attribute is no longer used to store the name of the event; it has been replaced with the name attribute in the fragment object.

  7. One of the significant changes in version 6 is the replacement of the BigNumber class with the built-in ES2020 BigInt provided by modern JavaScript environments. Consequently, all BigNumber-related functions such as .toNumber(), .add(), .sub(), .div(), .mod(), .eq(), etc., are now non-relevant and can be replaced with simple ES2020 BigInt operations.

  8. When a transaction is supposed to failed, the returned error object does not have .reason attribute equals to transaction failed but instead the .code attribute represents CALL_EXCEPTION or the code -32008

  9. When a transaction is reverted, the returned error object main reason is CONTRACT_REVERT_EXECUTED_CODE instead of CALL_EXCEPTION

  10. _signingKey() object has been replaced with signingKey

  11. Methods operations

    • contract.callStatic.foo(args) => contract.foo.staticCall(args)
    • contract.staticCallResult.foo(addr) => contract.foo.staticCallResult(args)
    • contract.populateTransaction.foo(addr) => contract.foo.populateTransaction(args)
  12. ethers.utils.splitSignature(signedData) has been replaced with ethers.Signature.from(signedData)

  13. additions of multiple await tx.wait() which eventually wait until the transactions are completely done and the states have been completely written to mirror node before another request

  14. .hexZeroPad() has been replaced with .zeroPadValue()

  15. _signTypedData() has been replaced with .signTypedData()

  16. ethers.utils.defaultAbiCoder() has been replaced with ethers.AbiCoder.defaultAbiCoder()

  17. .deployTransaction() has been replaced with .deploymentTransaction()

  18. solidityKeccak256() has been replaced with .solidityPackedKeccak256()

  19. formatBytes32String() has been replaced with .encodeBytes32String()

  20. arrayify() has been replaced with .getBytes()

  21. addition of BigInt(x) converter to convert int to BigInt

Related issue(s): #641

**Note: Upgrading dependencies to their latest versions includes transitioning from ethers.js v5.x to v6.x. It is essential to migrate the test suites from using ethers.js v5 to v6 within the same pull request.

Fixes #642 Fixes #550

Notes for reviewer:

Checklist

github-actions[bot] commented 6 months ago

Test Results

  15 files  +  2    74 suites  +4   7m 22s :stopwatch: +28s 242 tests +  5  235 :heavy_check_mark: ±  0  6 :zzz: +4  1 :x: +1  252 runs  +15  245 :heavy_check_mark: +10  6 :zzz: +4  1 :x: +1 

For more details on these failures, see this check.

Results for commit 52baa6c4. ± Comparison against base commit a3178b5a.

This pull request removes 86 and adds 91 tests. Note that renamed tests count towards both. ``` Should NOT allow a non-operator to transfer tokens to another account ‑ @OZERC1155 Tests Should NOT allow a non-operator to transfer tokens to another account Should NOT be able to change the current proxy admin if the caller is not an admin ‑ @OZERC1967Upgrade Upgradable Vote Tests Proxy Contract tests Should NOT be able to change the current proxy admin if the caller is not an admin Should NOT be able to send ERC721 token to invalidErc721Receiver via safeTransferFrom ‑ @OZIERC721Receiver Tests Should NOT be able to send ERC721 token to invalidErc721Receiver via safeTransferFrom Should NOT burn insufficient amount of token ‑ @OZERC1155 Tests Should NOT burn insufficient amount of token Should NOT transfer the ownership to another account if the caller is not owner ‑ @OZERC1155 Tests Should NOT transfer the ownership to another account if the caller is not owner Should allow an operator to transfer a token to another account ‑ @OZERC1155 Tests Should allow an operator to transfer a token to another account Should allow an operator to transfer tokens in batch to another account ‑ @OZERC1155 Tests Should allow an operator to transfer tokens in batch to another account Should be able to change the current proxy admin to a new address ‑ @OZERC1967Upgrade Upgradable Vote Tests Proxy Contract tests Should be able to change the current proxy admin to a new address Should be able to get the predefined ERC1967 ADMIN_SLOT ‑ @OZERC1967Upgrade Upgradable Vote Tests Proxy Contract tests Should be able to get the predefined ERC1967 ADMIN_SLOT Should be able to get the predefined ERC1967 IMPLEMENTATION_SLOT ‑ @OZERC1967Upgrade Upgradable Vote Tests Proxy Contract tests Should be able to get the predefined ERC1967 IMPLEMENTATION_SLOT … ``` ``` Should NOT allow a non-operator to transfer tokens to another account ‑ @OZERC1155Token Test Suite Should NOT allow a non-operator to transfer tokens to another account Should NOT be able to change the current proxy admin if the caller is not an admin ‑ @OZERC1967Upgrade Upgradable Vote Test Suite Proxy Contract tests Should NOT be able to change the current proxy admin if the caller is not an admin Should NOT be able to send ERC721 token to invalidErc721Receiver via safeTransferFrom ‑ @OZIERC721Receiver Test Suite Should NOT be able to send ERC721 token to invalidErc721Receiver via safeTransferFrom Should NOT burn insufficient amount of token ‑ @OZERC1155Token Test Suite Should NOT burn insufficient amount of token Should NOT transfer the ownership to another account if the caller is not owner ‑ @OZERC1155Token Test Suite Should NOT transfer the ownership to another account if the caller is not owner Should allow an operator to transfer a token to another account ‑ @OZERC1155Token Test Suite Should allow an operator to transfer a token to another account Should allow an operator to transfer tokens in batch to another account ‑ @OZERC1155Token Test Suite Should allow an operator to transfer tokens in batch to another account Should be able to change the current proxy admin to a new address ‑ @OZERC1967Upgrade Upgradable Vote Test Suite Proxy Contract tests Should be able to change the current proxy admin to a new address Should be able to get the predefined ERC1967 ADMIN_SLOT ‑ @OZERC1967Upgrade Upgradable Vote Test Suite Proxy Contract tests Should be able to get the predefined ERC1967 ADMIN_SLOT Should be able to get the predefined ERC1967 IMPLEMENTATION_SLOT ‑ @OZERC1967Upgrade Upgradable Vote Test Suite Proxy Contract tests Should be able to get the predefined ERC1967 IMPLEMENTATION_SLOT … ```

:recycle: This comment has been updated with latest results.