Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor all test in jellyfish-api-core to be independent #295

Closed
fuxingloh opened this issue May 26, 2021 · 0 comments · Fixed by #301, #305, #308, #312 or #313
Closed

refactor all test in jellyfish-api-core to be independent #295

fuxingloh opened this issue May 26, 2021 · 0 comments · Fixed by #301, #305, #308, #312 or #313
Assignees
Labels
kind/refactor Non feature refactor change triage/accepted Triage has been accepted

Comments

@fuxingloh
Copy link
Contributor

What would you like to be added:

All test in jellyfish-api-core to be refactored such that they are independent with each file for each method.

jellyfish-api-core/__tests__/category/
├── account/
│  ├── listAccounts.test.ts
│  └── getAccount.test.ts
├── blockchain/
│  └── getBlockchainInfo.test.ts

Within the test itself, spin up as many containers as required for independent testing. Be selective of what container you need, if you don't need an individual container for various setup, just use one container. Some test only required one container while others need different scenario with a clean chain.

Single Chain
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)

beforeAll(async () => {
  await container.start()
  await container.waitForReady()
  await container.waitForWalletCoinbaseMaturity()
})

afterAll(async () => {
  await container.stop()
})

it('should setWalletFlag', async () => {
  ...
})
Multiple Chains
describe('regtest without masternode', () => {
  const container = new RegTestContainer()
  const client = new ContainerAdapterClient(container)

  beforeAll(async () => {
    await container.start()
    await container.waitForReady()
  })

  afterAll(async () => {
    await container.stop()
  })

  it('should setWalletFlag', async () => {
    ...
  })
})

describe('with masternode', () => {
  const container = new MasterNodeRegTestContainer()
  const client = new ContainerAdapterClient(container)

  beforeAll(async () => {
    await container.start()
    await container.waitForReady()
    await container.waitForWalletCoinbaseMaturity()
  })

  afterAll(async () => {
    await container.stop()
  })

  it('should setWalletFlag', async () => {
    ...
  })
})

Why is this needed:

It’s getting very difficult to maintain side-effect and writing independent tests. Writing a clean and independent test is not easy, it requires a certain mastery with strong testing principles. Refactoring __tests__ in jellyfish-api-core will allow us to have a cleaner testing culture.

@fuxingloh fuxingloh added kind/feature New feature request triage/accepted Triage has been accepted area/jellyfish-api-core labels May 26, 2021
@fuxingloh fuxingloh added the kind/refactor Non feature refactor change label May 27, 2021
@defichain-bot defichain-bot removed the kind/feature New feature request label May 27, 2021
@fuxingloh fuxingloh reopened this May 28, 2021
This was referenced May 29, 2021
eli-lim pushed a commit that referenced this issue Mar 27, 2022
* added PoolPairService.getTotalLiquidityUsd to be resolved via cache

* fixed poolpair tests
canonbrother pushed a commit that referenced this issue Jun 1, 2022
* added PoolPairService.getTotalLiquidityUsd to be resolved via cache

* fixed poolpair tests
canonbrother pushed a commit that referenced this issue Jun 1, 2022
* added PoolPairService.getTotalLiquidityUsd to be resolved via cache

* fixed poolpair tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment