From 2693ec4c28f9a088d14b39cac273a4e8e4ae0ab0 Mon Sep 17 00:00:00 2001 From: Fuyao Zhao Date: Tue, 17 Dec 2024 23:18:59 +0800 Subject: [PATCH] fix(sui): object chnage handler regression (#1084) --- packages/sdk/package.json | 1 + packages/sdk/src/sui/sui-plugin.ts | 19 ++++++++++--------- packages/sdk/src/sui/tests/sui.test.ts | 26 +++++++++++++++----------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 1477622ff8..9087f5932e 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -24,6 +24,7 @@ "./aptos/builtin": "./lib/aptos/builtin/index.js", "./aptos/builtin/0x1": "./lib/aptos/builtin/0x1.js", "./aptos/builtin/0x3": "./lib/aptos/builtin/0x3.js", + "./aptos/builtin/0x4": "./lib/aptos/builtin/0x4.js", "./solana": "./lib/solana/index.js", "./solana/builtin": "./lib/solana/builtin/index.js", "./solana/codegen": "./lib/solana/codegen/index.js", diff --git a/packages/sdk/src/sui/sui-plugin.ts b/packages/sdk/src/sui/sui-plugin.ts index 5323dd3c47..ef451a9073 100644 --- a/packages/sdk/src/sui/sui-plugin.ts +++ b/packages/sdk/src/sui/sui-plugin.ts @@ -140,17 +140,18 @@ export class SuiPlugin extends Plugin { chainId: processor.getChainId(), startBlock: processor.config.startCheckpoint // TODO maybe use another field }) - for (const handler of processor.objectHandlers) { - const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1 - for (const handler of processor.objectChangeHandlers) { - const handlerId = handlers.suiObjectChangeHandlers.push(handler.handler) - 1 - const objectChangeHandler: MoveResourceChangeConfig = { - type: handler.type, - handlerId - } - accountConfig.moveResourceChangeConfigs.push(objectChangeHandler) + for (const handler of processor.objectChangeHandlers) { + const handlerId = handlers.suiObjectChangeHandlers.push(handler.handler) - 1 + const objectChangeHandler: MoveResourceChangeConfig = { + type: handler.type, + handlerId } + accountConfig.moveResourceChangeConfigs.push(objectChangeHandler) + } + + for (const handler of processor.objectHandlers) { + const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1 accountConfig.moveIntervalConfigs.push({ intervalConfig: { diff --git a/packages/sdk/src/sui/tests/sui.test.ts b/packages/sdk/src/sui/tests/sui.test.ts index bc68d369e8..489b22ee3a 100644 --- a/packages/sdk/src/sui/tests/sui.test.ts +++ b/packages/sdk/src/sui/tests/sui.test.ts @@ -23,27 +23,31 @@ describe('Test Sui Example', () => { ctx.meter.Gauge('size').record(objects.length) }) - SuiObjectTypeProcessor.bind({ objectType: validator.Validator.type() }).onTimeInterval( - (self, objects, ctx) => { - ctx.meter - .Gauge('validator') - .record(self.data_decoded.voting_power, { address: self.data_decoded.metadata.primary_address }) - }, - 60, - 60, - { owned: false } - ) + SuiObjectTypeProcessor.bind({ objectType: validator.Validator.type() }) + .onTimeInterval( + (self, objects, ctx) => { + ctx.meter + .Gauge('validator') + .record(self.data_decoded.voting_power, { address: self.data_decoded.metadata.primary_address }) + }, + 60, + 60, + { owned: false } + ) + .onObjectChange((self, ctx) => {}) }) before(async () => { await service.start({ templateInstances: [] }) }) - test('check configuration ', async () => { + test('check configuration', async () => { const config = await service.getConfig({}) expect(config.contractConfigs).length(2) expect(config.accountConfigs).length(2) expect(config.accountConfigs[0].moveIntervalConfigs[0].ownerType).eq(MoveOwnerType.OBJECT) + expect(config.accountConfigs[1].moveIntervalConfigs[0].ownerType).eq(MoveOwnerType.TYPE) + expect(config.accountConfigs[1].moveResourceChangeConfigs[0].type).eq(validator.Validator.type().qname) }) test('Check event dispatch', async () => {