From dbc7c7f864d065dfae11865e50c623a8329d47cf Mon Sep 17 00:00:00 2001 From: codingsh Date: Tue, 15 Oct 2024 15:31:53 +0400 Subject: [PATCH] feat(deadman-switch): Add deadman switch getters --- src/index.ts | 3 ++ src/module/deadman-switch/index.ts | 3 ++ src/module/deadman-switch/usage.ts | 42 +++++++++++++++++++ src/module/index.ts | 3 ++ test/e2e/modules/deadmanSwitchValidator.ts | 3 ++ .../deadmanSwitch/deadmanSwitch.test.ts | 33 ++++++++++++++- 6 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7083d6ee..e63f2a7c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,6 +60,9 @@ export { getDeadmanSwitch, getDeadmanSwitchConfig, getDeadmanSwitchValidatorMockSignature, + getDeadmanSwitchTimeout, + getDeadmanSwitchNominee, + isDeadmanSwitchActive, OWNABLE_EXECUTOR_ADDRESS, getOwnableExecutor, getAddOwnableExecutorOwnerAction, diff --git a/src/module/deadman-switch/index.ts b/src/module/deadman-switch/index.ts index 437f9cb8..3d2125f3 100644 --- a/src/module/deadman-switch/index.ts +++ b/src/module/deadman-switch/index.ts @@ -3,4 +3,7 @@ export { getDeadmanSwitch } from './installation' export { getDeadmanSwitchConfig, getDeadmanSwitchValidatorMockSignature, + getDeadmanSwitchTimeout, + getDeadmanSwitchNominee, + isDeadmanSwitchActive, } from './usage' diff --git a/src/module/deadman-switch/usage.ts b/src/module/deadman-switch/usage.ts index d4a02cd4..186f2531 100644 --- a/src/module/deadman-switch/usage.ts +++ b/src/module/deadman-switch/usage.ts @@ -26,6 +26,48 @@ export const getDeadmanSwitchConfig = async ({ } } +export const getDeadmanSwitchTimeout = async ({ + account, + client, +}: { + account: Account + client: PublicClient +}): Promise => { + const [, timeout] = await getDeadmanSwitchConfig({ + account, + client, + }) + return timeout +} + +export const getDeadmanSwitchNominee = async ({ + account, + client, +}: { + account: Account + client: PublicClient +}): Promise
=> { + const [, , nominee] = await getDeadmanSwitchConfig({ + account, + client, + }) + return nominee +} + +export const isDeadmanSwitchActive = async ({ + account, + client, +}: { + account: Account + client: PublicClient +}): Promise => { + const [isActive] = await getDeadmanSwitchConfig({ + account, + client, + }) + return isActive === 1 +} + export const getDeadmanSwitchValidatorMockSignature = (): Hex => { return '0xe8b94748580ca0b4993c9a1b86b5be851bfc076ff5ce3a1ff65bf16392acfcb800f9b4f1aef1555c7fce5599fffb17e7c635502154a0333ba21f3ae491839af51c' } diff --git a/src/module/index.ts b/src/module/index.ts index ed31ee18..a1b84838 100644 --- a/src/module/index.ts +++ b/src/module/index.ts @@ -62,6 +62,9 @@ export { getDeadmanSwitch, getDeadmanSwitchConfig, getDeadmanSwitchValidatorMockSignature, + getDeadmanSwitchTimeout, + getDeadmanSwitchNominee, + isDeadmanSwitchActive } from './deadman-switch' export { diff --git a/test/e2e/modules/deadmanSwitchValidator.ts b/test/e2e/modules/deadmanSwitchValidator.ts index 7dd0337e..5bd6d340 100644 --- a/test/e2e/modules/deadmanSwitchValidator.ts +++ b/test/e2e/modules/deadmanSwitchValidator.ts @@ -44,4 +44,7 @@ export const testDeadmanSwitchValidator = async ({ ) expect(timeout).toEqual(deadmanSwitchValidator.timeout) }) + + + } diff --git a/test/unit/module/deadmanSwitch/deadmanSwitch.test.ts b/test/unit/module/deadmanSwitch/deadmanSwitch.test.ts index 351265f4..f16a056e 100644 --- a/test/unit/module/deadmanSwitch/deadmanSwitch.test.ts +++ b/test/unit/module/deadmanSwitch/deadmanSwitch.test.ts @@ -1,4 +1,6 @@ -import { DEADMAN_SWITCH_ADDRESS, getDeadmanSwitchConfig } from 'src' +import { DEADMAN_SWITCH_ADDRESS, getDeadmanSwitchConfig, getDeadmanSwitchTimeout, + getDeadmanSwitchNominee, + isDeadmanSwitchActive } from 'src' import { Address, zeroAddress } from 'viem' import { getDeadmanSwitch } from 'src' import { getClient } from 'src' @@ -6,6 +8,8 @@ import { MockClient } from 'test/utils/mocks/client' import { getAccount } from 'src' import { MockAccountDeployed } from 'test/utils/mocks/account' + + describe('Deadman switch Module', () => { // Setup const nominee = '0x0Cb7EAb54EB751579a82D80Fe2683687deb918f3' as Address @@ -54,4 +58,31 @@ describe('Deadman switch Module', () => { expect(timeout).toEqual(0) expect(nominee).toEqual(zeroAddress) }) + + it('should get deadman switch timeout', async () => { + const timeout = await getDeadmanSwitchTimeout({ + account, + client, + }) + + expect(timeout).toEqual(0) + }) + + it('should get deadman switch nominee', async () => { + const nomineeAddress = await getDeadmanSwitchNominee({ + account, + client, + }) + + expect(nomineeAddress).toEqual(zeroAddress) + }) + + it('should check if deadman switch is active', async () => { + const isActive = await isDeadmanSwitchActive({ + account, + client, + }) + + expect(isActive).toEqual(false) + }) })