yearn / yearn-sdk

🦧 SDK for the yearn.finance platform. WIP
https://npm.im/@yfi/sdk
MIT License
53 stars 56 forks source link

[WEB-1343-221] test: Add specs for the `VaultInterface` #221

Closed karelianpie closed 2 years ago

karelianpie commented 2 years ago

Closes https://github.com/yearn/yearn-sdk/issues/210

Add tests for the VaultInterface

karelianpie commented 2 years ago

Wondering if instead of creating our own mocks we should use https://github.com/Typescript-TDD/ts-auto-mock -- it's slightly different than factory.ts where we need to provide our own factories. @xgambitox mentioned this article https://khalilstemmler.com/articles/test-driven-development/how-to-mock-typescript/ and it would save a lot of boilerplate code. I know we've agreed to not add any unnecessary dependencies, but this would make testing a lot cleaner. Thoughts?

TL;DR We would get all this out of the box with ts-auto-mock

import { createMock } from 'ts-auto-mock';

interface Person {
  id: string;
  getName(): string;
  details: {
      phone: number
  }
}
const mock = createMock<Person>();
mock.id // ""
mock.getName() // ""
mock.details // "{ phone: 0 }"
FiboApe commented 2 years ago

@karelianpie what is the actual advantage of using that dependency? It just seems like it does the same thing as we do, just it is bassed of an interface

karelianpie commented 2 years ago

@karelianpie what is the actual advantage of using that dependency? It just seems like it does the same thing as we do, just it is bassed of an interface

It does what we do automagically, so we don't need to set random values ourselves. It looks at the type and generates a random value with that type. It might be tricky with this codebase though, because we have BigIntegers as strings, so I'm afraid it would just set a random string and not a number casted as string

FiboApe commented 2 years ago

@karelianpie yeah that's my concern as well, since we handle very specific web3/crypto things I think it's better for now to build our own factories, since we could get invalid data with this type of deps