test: cosmosclient (part2) #2791
                
     Merged
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Please see #2789 before reading this PR.
This PR adds a unit-test on
cosmosclient.CreateTX. Because this requires a lot of new mocks, I wanted to make a separate PR, in order to gather your opinion specifically on this test. In particular, I would like to know if you're fine with this test pattern, and how it is written.The PR introduces 4 new mocks, that are now part of the
cosmosclient.Clientstruct fields :accountRetrieverof typeclient.AccountRetriever(interface from cosmos-sdk)bankQueryClientof typex/bank/types.QueryClientfaucetClientof typeFaucetClient, a newly created interface defined in cosmosclient package. This allows to mock the interaction with thepkg/cosmosfaucet.gasomoterof typeGasometer, an other newly created interface defined in cosmosclient package. This allows to mock thetx.CalculateGasfunction from the cosmos-sdk. Because this is a function, this time I needed to create a specific struct that exposesCalculateGasmethod that itself calltx.CalculateGas. I can understand if some of you find this pattern cumbersome, but afaik this is the only way to mock a function call.Now the cool part of this is ofc the tests: I can test all the different cases we have in
CreateTx; like when fauchet is enabled with enough or insufficient balances, when fees and gasPrices are both provided, how gas amount is computed etc...For me the benefit is worth the small amount of complexity added in the
Clientimplementation. But maybe you're not agree, then let's discuss :)