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

Testing framework: RnD #239

Closed
2ndshadow opened this issue Feb 20, 2024 · 4 comments
Closed

Testing framework: RnD #239

2ndshadow opened this issue Feb 20, 2024 · 4 comments
Assignees

Comments

@2ndshadow
Copy link

Epic: Testing framework for squids #220
Estimate: 2d

@vanruch
Copy link
Contributor

vanruch commented Mar 5, 2024

Mock data sinks

Mock TypeORM store

Use in-memory sqlite data source (outdated example here)

Mock Filestore

Do we need it? Devs can just delete files manually after testing

Mock bigquery

I haven't found an easy solution to mock BigQuery. I think best solution here would be to recommend users to use something like https://github.com/goccy/bigquery-emulator and connect to it

Mock Batch Processors

MockEvmBatchProcessor gets EvmProcessor instance and only cares for what was set in .addLog, .addTransaction, .addStateDiff, .addTrace & .setFields calls

import {handler, processor} from "./src"
import {encodeLog} from "@subsquid/evm-utils"
import * as contract from "./abi/contract.ts"

const tokenAddress = '0x12313123...'

test("Correctly calculates minted amounts", () => {
  const mockProcessor = new MockEvmBatchProcessor(processor)
  const db = new MockTypeOrm()
  
  mockProcessor.run(db, handler)
    
  // This would wait until handler(ctx) is called
  await mockProcessor.inject([{
	logs: [
	  encodeLog(contract.events.Mint, tokenAddress, {
	    to: ...
	    amount: 10n
	   }),
       encodeLog(contract.events.Mint, tokenAddress, {
	    to: ...
        amount: 100n
	   }),
	 ],
	}])

  expect((await db.get(Token, tokenAddress)).totalSupply).toBe(110n)
})

Similar one for substrate

@dzhelezov
Copy link
Contributor

Can we generate events from the ABI?

@dzhelezov
Copy link
Contributor

also not clear how db.get() works

@mo4islona
Copy link
Contributor

mo4islona commented Mar 5, 2024

also not clear how db.get() works

Why we can't use a real database?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@mo4islona @vanruch @dzhelezov @2ndshadow @belopash and others