0

I'm trying to calculate the price of some tokens in an AMM (we're on Moonbeam so getting the price in USDC by routing it through GLMR-quoted pools)

export function tokenPrice(token: string): BigInt {
  switch(token){
    case DOT:
      let glmrDot = GlmrDotContract.bind(Address.fromString(GLMR_DOT));
      let glmrBalance = glmrDot.try_balanceOf(Address.fromString(WGLMR)).value;
      let tokenBalance = glmrDot.try_balanceOf(Address.fromString(DOT)).value;
      return tokenBalance.div(glmrBalance).div(priceOfGlmr())
    case USDC:
      const glmrUsdc = USDCGlmrContract.bind(Address.fromString(GLMR_USDC));
      glmrBalance = glmrUsdc.try_balanceOf(Address.fromString(WGLMR)).value;
      tokenBalance = glmrUsdc.try_balanceOf(Address.fromString(USDC)).value;
      return glmrBalance.div(tokenBalance)
  }
  return BigInt.zero()
}

When I run my test in matchstick, I get

Could not find a mocked function for function with address: 0x555b…10d1, name: balanceOf, signature balanceOf(address):(uint256), params: [Address(0x0e358838ce72d5e61e0018a2ffac4bec5f4c88d2)]

Ideally, I'd have some way to stage tokens into that address, balanceOf would just work normally, reporting back the number of tokens in those pools so that my code could run.

Is there any way to do that? Or do have have to mock the call?

Steve
  • 4,457
  • 12
  • 48
  • 89

1 Answers1

1

Matchstick is a unit testing tool which means it is going to require mocks for everything outside of the event handler which includes external calls and the events. There is not a way to use matchstick without mocking.

What you are describing would be something like integration testing. You can achieve this using hardhat. You will also need to have ipfs and graph-node running. The setup for the tests would be calling contracts to trigger events, waiting for the subgraph to sync, and then asserting against graphql queries of the graph-node

Corey
  • 1,010
  • 9
  • 17