Skip to content

Commit

Permalink
chore(store): add examples to unit test entity store (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedragon authored Jan 22, 2025
1 parent c0bb4cc commit 3421b93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions examples/x2y2-database/src/processor.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import assert from 'assert'
import { before, describe, test } from 'node:test'
import { TestProcessorServer } from '@sentio/sdk/testing'
import { mockTransferLog } from '@sentio/sdk/eth/builtin/erc20'
import { User } from './schema/schema.js'

describe('Test Processor', () => {
const service = new TestProcessorServer(async () => await import('./processor.js'))
const server = new TestProcessorServer(async () => await import('./processor.js'))

before(async () => {
await service.start()
await server.start()
})

test('has config', async () => {
const config = await service.getConfig({})
const config = await server.getConfig({})
assert(config.contractConfigs.length > 0)
})

test('data is upsert', async () => {
await server.eth.testLog(
mockTransferLog('0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9', {
from: '0x0000000000000000000000000000000000000000',
to: '0xb329e39ebefd16f40d38f07643652ce17ca5bac1',
value: 10n ** 18n * 10n
})
)

const from = await server.store.list(User)
assert(from.length == 2)
})
})
4 changes: 2 additions & 2 deletions examples/x2y2-database/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ ERC20Processor.bind({ address: '0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9' }).o
// exporter.emit(ctx, event)
const from = new User({
name: 'from',
id: event.args.from
id: event.args.from.toLowerCase()
})

await ctx.store.upsert(from)
const to = new User({
name: 'to',
id: event.args.to
id: event.args.to.toLowerCase()
})
await ctx.store.upsert(to)
const transfer = new Transfer({
Expand Down

0 comments on commit 3421b93

Please sign in to comment.