You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
host element that it binds itself to
walletContext that provides EVM connected wallet address and provider.
substrateProviderContext that provides substrate connected wallet addresses and providers.
Config from @buildwithsygma/sygma-sdk-core
getDomainConfig should return a config for mocked domain
init method should prepare a fake configuration on which the transfer functionality can be simulated
getDomains should return list of fake domains
For testing EVM and Substrate Build and execute methods
EVMAssetTransfer from @buildwithsygma/sygma-sdk-core
init method
createFungibleTransfer returns a mocked Transfer<Fungible> object
getFee returns a mocked EvmFee
buildApprovals returns list of mocked EVM approval transactions
buildTransferTransaction returns a EVM transfer transaction
Web3Provider from ethers
getSigner method that returns a fake signer
Signer from ethers
estimateGas returns a mocked estimated gas price of a transaction
getGasPrice returns a fake gas price
TransactionResponse from ethers
wait method that resolves a mocked Receipt
TransactionRequest from ethers
SubstrateAssetTransfer from @buildwithsygma/sygma-sdk-core
createFungibleTransfer returns a mocked SubstrateAssetTransfer instance
init fake init
getFee returns mocked fee
buildTransferTransaction returns a mocked SubstrateTransaction
paymentInfo method that returns mocked payment info
signAndSend method 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
The text was updated successfully, but these errors were encountered:
Testing the
FungibleTokenTransferController
FungibleTokenTransferController
houses most of the logic required to initiate fungible transfers usingbuildwithsygma/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:
host
element that it binds itself towalletContext
that provides EVM connected wallet address and provider.substrateProviderContext
that provides substrate connected wallet addresses and providers.Config
from@buildwithsygma/sygma-sdk-core
getDomainConfig
should return a config for mocked domaininit
method should prepare a fake configuration on which the transfer functionality can be simulatedgetDomains
should return list of fake domainsFor testing EVM and Substrate Build and execute methods
EVMAssetTransfer
from@buildwithsygma/sygma-sdk-core
init
methodcreateFungibleTransfer
returns a mockedTransfer<Fungible>
objectgetFee
returns a mockedEvmFee
buildApprovals
returns list of mocked EVM approval transactionsbuildTransferTransaction
returns a EVM transfer transactionWeb3Provider
fromethers
getSigner
method that returns a fake signerSigner
fromethers
estimateGas
returns a mocked estimated gas price of a transactiongetGasPrice
returns a fake gas priceTransactionResponse
fromethers
wait
method that resolves a mockedReceipt
TransactionRequest
fromethers
SubstrateAssetTransfer
from@buildwithsygma/sygma-sdk-core
createFungibleTransfer
returns a mockedSubstrateAssetTransfer
instanceinit
fake initgetFee
returns mocked feebuildTransferTransaction
returns a mockedSubstrateTransaction
SubstrateTransaction | SubmittableExtrinsic<"promise", SubmittableResult>
paymentInfo
method that returns mocked payment infosignAndSend
method that simulates a transfer transactionApproach 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
The text was updated successfully, but these errors were encountered: