diff --git a/packages/sdk/src/aptos/aptos-plugin.ts b/packages/sdk/src/aptos/aptos-plugin.ts index 4215ee7f3..68460c0eb 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 000000000..cbc63526e --- /dev/null +++ b/packages/sdk/src/aptos/tests/aptots-global.test.ts @@ -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) + }) +})