This repository was archived by the owner on Mar 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Add tests for FungibleTokenTransferController #177
Copy link
Copy link
Open
Labels
Description
Testing the FungibleTokenTransferController
FungibleTokenTransferController houses most of the logic required to initiate fungible transfers using buildwithsygma/sygma-sdk-core. However, since there are no tests written so far I would like to write down the approach and setup required to test its functionality.
Mocking
In order to test functionality of the controller itself, we will have to mock its dependancies. Controller logic is coupled with
the following components:
hostelement that it binds itself towalletContextthat provides EVM connected wallet address and provider.substrateProviderContextthat provides substrate connected wallet addresses and providers.Configfrom@buildwithsygma/sygma-sdk-coregetDomainConfigshould return a config for mocked domaininitmethod should prepare a fake configuration on which the transfer functionality can be simulatedgetDomainsshould return list of fake domains
For testing EVM and Substrate Build and execute methods
EVMAssetTransferfrom@buildwithsygma/sygma-sdk-coreinitmethodcreateFungibleTransferreturns a mockedTransfer<Fungible>objectgetFeereturns a mockedEvmFeebuildApprovalsreturns list of mocked EVM approval transactionsbuildTransferTransactionreturns a EVM transfer transaction
Web3ProviderfromethersgetSignermethod that returns a fake signer
SignerfromethersestimateGasreturns a mocked estimated gas price of a transactiongetGasPricereturns a fake gas price
TransactionResponsefrometherswaitmethod that resolves a mockedReceipt
TransactionRequestfromethersSubstrateAssetTransferfrom@buildwithsygma/sygma-sdk-corecreateFungibleTransferreturns a mockedSubstrateAssetTransferinstanceinitfake initgetFeereturns mocked feebuildTransferTransactionreturns a mockedSubstrateTransactionSubstrateTransaction | SubmittableExtrinsic<"promise", SubmittableResult>paymentInfomethod that returns mocked payment infosignAndSendmethod that simulates a transfer transaction
Approach to testing
Goal is to test the logic within FungibleTokenTransferController assuming that most of its dependancies would be using mocked values. Have a configuration of two EVM chains and one substrate chain each having a resource that can be transferred bi-directionally.
Test cases
- SDK is initialized on creation
- Correct routes are computed using mocked domains
- Resource selection should be important
- Transactions are prepared correctly
- Correct state is maintained throughout a transfer cycle
- Reset functionality works correctly
- Wallet connection is a required dependancy
- Fee is defined once transactions are prepared
- Estimated Gas is calculated on each transaction