From d53e95523f57608d486d7e24e39042d7c0167c46 Mon Sep 17 00:00:00 2001 From: Yulong Date: Fri, 27 Dec 2024 10:34:13 +0800 Subject: [PATCH] fix(aptos): onTimeInterval config should under AccountConfig --- packages/sdk/src/aptos/aptos-plugin.ts | 38 ++++++++++--------- .../sdk/src/aptos/tests/aptots-global.test.ts | 22 +++++++++++ 2 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 packages/sdk/src/aptos/tests/aptots-global.test.ts diff --git a/packages/sdk/src/aptos/aptos-plugin.ts b/packages/sdk/src/aptos/aptos-plugin.ts index 4215ee7f32..68460c0eb9 100644 --- a/packages/sdk/src/aptos/aptos-plugin.ts +++ b/packages/sdk/src/aptos/aptos-plugin.ts @@ -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, @@ -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) } diff --git a/packages/sdk/src/aptos/tests/aptots-global.test.ts b/packages/sdk/src/aptos/tests/aptots-global.test.ts new file mode 100644 index 0000000000..b6760b61ed --- /dev/null +++ b/packages/sdk/src/aptos/tests/aptots-global.test.ts @@ -0,0 +1,22 @@ +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) + }) +})