ethersphere / bee-js

Javascript client library for connecting to Bee decentralised storage
https://bee-js.ethswarm.org/
BSD 3-Clause "New" or "Revised" License
60 stars 27 forks source link

Replicable test environment #249

Open vojtechsimetka opened 3 years ago

vojtechsimetka commented 3 years ago

Rationale: In our current tests we spawn each time new fresh network. This means we just have an empty network without any data, balances or cheques etc. Given the nature of the network, it is unrealistic to deterministically set up the network to the same state by performing actions on top of it. Therefore the approach would be to take a snapshot of the locally run environment and run tests against it.

This comes as an outcome from a testing discussion on April 7th 2021

Phases/TODO:

  1. Local environment

    • [x] Create a local environment of 5 bee nodes with a local blockchain (ideally geth), deploy BZZ token, chequebook factory contract (and soon postage stamps). Make this replicable (either script or at least steps)
  2. CI job for cheques tests

    • [ ] Get the bee nodes into a state that we like in terms of accounting - have some nonzero balances and several cheques.
    • [ ] Save the blockchain state and keystore and statestore of Bee
    • [ ] Create CI job that spawns the local environment and restores the state
    • [ ] Run chequebook tests against it (cashing out cheques, probably also the depositing and withdrawing)
  3. CI job for feeds and other data

    • [ ] Get the bee nodes into a state that we want - probably some existing feeds and data
    • [ ] Save this state now including the localstore and use it in the CI
    • [ ] Run feed tests against it
  4. Replace the current test environment

    • This may include restoring the state between different tests so that we have predictable environment
nugaon commented 3 years ago

The orchestration of the test Bee clients along with generating its required keys are going to happen by swarm-cli as proposed in Bee ticket #1557. identity and docker commands will be used for that, the remaining implementation of the latter is going to start soon #17. In order to start the implementation of the command we need more information about swarm.key of Bee, the discussions about it has been already started. The test environment processes will have a different repository to keep all assets of it (smart contract codes, snapshots of Bee, etc.) there. This repository could be fetched by the CI and could be used to create test environment.

nugaon commented 3 years ago

Currently #297 PR solved the flaky tests and created a faster environment by the bee-factory project with supporting the followings:

The last point is not solved in the CI image build workflow, because:

nugaon commented 3 years ago

@ethersphere/js ?

vojtechsimetka commented 3 years ago

I would still love to have images with state in it so that we always have the same environment to test against (and sure from time to time this will need to recreate it as the Bee evolves and has new potentially incompatible internal state). But we would have what we always wanted - predictable non-empty state against which we run tests in all of our repos (bee-js, swarm-cli, bee-dashboard...). This would also make it much simpler locally, you could just pull the images and before each test restore the state.

That being said if we go the way of generating the state before running the tests, I would still advocate to save the state between tests. So the workflow would be:

  1. generate the state we want and save it
  2. locally this state could then be restored between test runs, on CI this could also potentially be stored in a cache similar to how node_modules are
  3. if needed, this state could also be restored between different tests (I don't think we need it now)