Skip to content

Commit

Permalink
fix(aptos): onTimeInterval config should under AccountConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedragon committed Dec 27, 2024
1 parent be3e50b commit a5db7f5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
38 changes: 20 additions & 18 deletions packages/sdk/src/aptos/aptos-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,28 @@ export class AptosPlugin extends Plugin {
contractConfig.moveCallConfigs.push(functionHandlerConfig)
}

// 3. Prepare interval handlers
config.contractConfigs.push(contractConfig)
}

// Prepare resource handlers
for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
const accountConfig = AccountConfig.fromPartial({
address: aptosProcessor.config.address,
chainId: aptosProcessor.getChainId(),
startBlock: aptosProcessor.config.startVersion
})
for (const handler of aptosProcessor.resourceChangeHandlers) {
const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1
accountConfig.moveResourceChangeConfigs.push({
handlerId: handlerId,
type: handler.type
})
}

// Prepare interval handlers
for (const handler of aptosProcessor.transactionIntervalHandlers) {
const handlerId = handlers.aptosTransactionIntervalHandlers.push(handler.handler) - 1
contractConfig.moveIntervalConfigs.push({
accountConfig.moveIntervalConfigs.push({
intervalConfig: {
handlerId: handlerId,
handlerName: handler.handlerName,
Expand All @@ -139,23 +157,7 @@ export class AptosPlugin extends Plugin {
type: ''
})
}
config.contractConfigs.push(contractConfig)
}

// Prepare resource handlers
for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
const accountConfig = AccountConfig.fromPartial({
address: aptosProcessor.config.address,
chainId: aptosProcessor.getChainId(),
startBlock: aptosProcessor.config.startVersion
})
for (const handler of aptosProcessor.resourceChangeHandlers) {
const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1
accountConfig.moveResourceChangeConfigs.push({
handlerId: handlerId,
type: handler.type
})
}
config.accountConfigs.push(accountConfig)
}

Expand Down
23 changes: 23 additions & 0 deletions packages/sdk/src/aptos/tests/aptots-global.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { before, describe, test } from 'node:test'
import { expect } from 'chai'

import { TestProcessorServer } from '../../testing/index.js'
import { AptosGlobalProcessor } from '../aptos-processor.js'

describe('Test Global Aptos Prcessor', () => {
const service = new TestProcessorServer(async () => {
AptosGlobalProcessor.bind({ address: '*' }).onTimeInterval((resources, ctx) => {})
})

before(async () => {
await service.start({ templateInstances: [] })
})

test('check configuration ', async () => {
const config = await service.getConfig({})
expect(config.contractConfigs).length(1)

expect(config.accountConfigs).length(1)
expect(config.accountConfigs[0].moveIntervalConfigs).length(1)
})
})

0 comments on commit a5db7f5

Please sign in to comment.