I could create mocks of the dependencies but I'd really like to be able to fork mainnet using Ganache in a way similar to this (https://medium.com/@samajammin/how-to-interact-with-ethereums-mainnet-in-a-development-environment-with-ganache-3d8649df0876) ...but within the truffle test environment

  • So you want to deploy your contracts locally on Ganache, but then have them interacting with other contracts which are already deployed on mainnet (I suppose, either by passing those mainnet addresses to the local contracts, or by hard-coding them inside the local contracts)? – goodvibration Mar 2 '20 at 15:30
  • let me simplify it...i'm using a DEX as a dependency in my contract. I would like to use truffle to test against the actual contract, instead of against a mock. Is this possible? – Michael C Mar 2 '20 at 15:33
  • "i'm using a DEX as a dependency in my contract" - what does that mean? Please show some relevant code. – goodvibration Mar 2 '20 at 15:35
  • All I'm saying is that within one of my function calls, the contract calls Uniswap, for example, and relies on that exchange succeeding, for the function to work – Michael C Mar 2 '20 at 15:53
  • It's gonna be hard (or even impossible) with Truffle. Unless of course you deploy your contract into mainnet as well. Mocking is the correct way for doing it - you mock a contract with the exact same DEX function prototype, but which does nothing but returning true or false (to your request of course). Then you set this function to return true, then you check your contract's behavior on Ganache, then you do the same with false. – goodvibration Mar 2 '20 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.