More Realistic Mockchain in E2E Tests
Chaingraph deterministically generates "mockchains" for use in end-to-end (E2E) tests. In the tests, Chaingraph connects to several simulated nodes – each with different understandings of the latest chain tip – and the tests confirm that Chaingraph correctly tracks data from each node.
Currently this data is mostly fake. Locking and unlocking scripts can be parsed but are otherwise invalid, transactions do not properly spend from valid outputs, etc. so it's not possible to test some GraphQL relationships and other API features using the resulting E2E test database.
It would be valuable to develop a @chaingraph/mockchain package which would deterministically generate a realistic looking sample blockchain, complete with N independent entities receiving block rewards and creating transactions to and from each other (using multiple common locking and redeem bytecode patterns).
It should accept:
- a deterministic seed
- a genesis/parent block hash
- an average transaction rate
- a transaction rate volatility
- a set of authentication templates – (default P2PK, P2PKH, some bare multisig, 2-of-3 P2SH, etc.) and transaction generation functions to use them
- a stale block rate
- the count/identity/hash rate of hypothetical node implementations
- a list of planned forks – to simulate a planned a chain split, listing which implementations which should fall on each side of the split)
- and a list of "unplanned" forks – to simulate blocks being mined by 3 groups of miners: implementations which only mine on one side of the incompatibility, implementations which only mine on the other side, and implementations which are indifferent to the incompatibility (and simply follow the chain with the most work)
Generating a "mockchain" could be rather expensive (considering all the hashing and signing required), so some strategy for caching the generated mockchain in development environments/CI would be valuable (without having to bloat the git repo with the generated data).
When using the generated mockchain, the E2E tests should simulate the number of nodes from the mockchain's implementation count, then sync most of the chain as if it is syncing from historical data. After that point, the simulated nodes should switch to a "live mode" in which transactions and blocks are "replayed" to Chaingraph in approximately the order they would be heard in real-time over the P2P network. (Most types of forks should be tested in this mode.)
This would make Chaingraph's E2E tests much more realistic, and allow us to fully test API features like spent_by relationships and Bitauth lookups. It would also be the perfect framework for testing Chaingraph-based block explorers and other applications which rely on sophisticated handling of unusual network conditions.