diff --git a/src/ajv.ts b/src/ajv.ts index ba7dfa0..693b83e 100644 --- a/src/ajv.ts +++ b/src/ajv.ts @@ -1,32 +1,10 @@ import Ajv, { type ErrorObject } from 'ajv' -import { ETHER_TO_GWEI } from './constants' - -function validDpositAmounts (data: boolean, deposits: string[]): boolean { - let sum = 0 - for (let i = 0; i < deposits.length; i++) { - const amount = parseInt(deposits[i]) - if (amount % ETHER_TO_GWEI !== 0 || amount > 32 * ETHER_TO_GWEI) { - return false - } - sum += amount - } - if (sum !== 32 * ETHER_TO_GWEI) { - return false - } else { - return true - } -} export function validatePayload ( data: any, schema: any, ): ErrorObject[] | undefined | null | boolean { const ajv = new Ajv() - ajv.addKeyword({ - keyword: 'validDpositAmounts', - validate: validDpositAmounts, - errors: true, - }) const validate = ajv.compile(schema) const isValid = validate(data) if (!isValid) { diff --git a/src/constants.ts b/src/constants.ts index 274d3e8..0a8d0f8 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -98,7 +98,7 @@ export const signEnrPayload = ( export const DKG_ALGORITHM = 'default' -export const CONFIG_VERSION = 'v1.8.0' +export const CONFIG_VERSION = 'v1.7.0' export const SDK_VERSION = pjson.version diff --git a/src/index.ts b/src/index.ts index 82b2fb4..f3ca275 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,7 +70,6 @@ export class Client extends Base { timestamp: new Date().toISOString(), threshold: Math.ceil((2 * newCluster.operators.length) / 3), num_validators: newCluster.validators.length, - deposit_amounts: newCluster.deposit_amounts ? newCluster.deposit_amounts : ['32000000000'] } try { diff --git a/src/schema.ts b/src/schema.ts index 474a3b3..d431816 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -53,14 +53,6 @@ export const definitionSchema = { required: ['fee_recipient_address', 'withdrawal_address'], }, }, - deposit_amounts: { - type: 'array', - items: { - type: 'string', - pattern: '^[0-9]+$', - }, - validDpositAmounts: true - }, }, required: ['name', 'operators', 'validators'], } diff --git a/src/verification/common.ts b/src/verification/common.ts index 27609cd..426ea4a 100644 --- a/src/verification/common.ts +++ b/src/verification/common.ts @@ -31,14 +31,6 @@ export const clusterConfigOrDefinitionHash = ( ): string => { let definitionType, val - if (semver.eq(cluster.version, 'v1.6.0')) { - definitionType = clusterDefinitionContainerTypeV1X6(configOnly) - val = hashClusterDefinitionV1X6(cluster, configOnly) - return ( - '0x' + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex') - ) - } - if (semver.eq(cluster.version, 'v1.7.0')) { definitionType = clusterDefinitionContainerTypeV1X7(configOnly) val = hashClusterDefinitionV1X7(cluster, configOnly) diff --git a/test/methods.test.ts b/test/methods.test.ts index dbd6f5a..2e6443f 100644 --- a/test/methods.test.ts +++ b/test/methods.test.ts @@ -35,23 +35,23 @@ describe('Cluster Client', () => { .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash })) const configHash = - await clientInstance.createClusterDefinition(clusterConfigV1X8) + await clientInstance.createClusterDefinition(clusterConfigV1X7) expect(configHash).toEqual(mockConfigHash) }) test('acceptClusterDefinition should return cluster definition', async () => { clientInstance['request'] = jest .fn() - .mockReturnValue(Promise.resolve(clusterLockV1X8.cluster_definition)) + .mockReturnValue(Promise.resolve(clusterLockV1X7.cluster_definition)) const clusterDefinition = await clientInstance.acceptClusterDefinition( { - enr: clusterLockV1X8.cluster_definition.operators[0].enr, - version: clusterLockV1X8.cluster_definition.version, + enr: clusterLockV1X7.cluster_definition.operators[0].enr, + version: clusterLockV1X7.cluster_definition.version, }, - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) - expect(clusterDefinition).toEqual(clusterLockV1X8.cluster_definition) + expect(clusterDefinition).toEqual(clusterLockV1X7.cluster_definition) }) test('createClusterDefinition should throw an error on invalid operators', async () => { @@ -60,7 +60,7 @@ describe('Cluster Client', () => { .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash })) try { await clientInstance.createClusterDefinition({ - ...clusterConfigV1X8, + ...clusterConfigV1X7, operators: [], }) } catch (error: any) { @@ -70,37 +70,9 @@ describe('Cluster Client', () => { } }) - test('createClusterDefinition should accept a configuration without deposit_amounts ', async () => { - clientInstance['request'] = jest - .fn() - .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash })) - - const configHash = await clientInstance.createClusterDefinition({ - ...clusterConfigV1X7, - }) - - expect(configHash).toEqual(mockConfigHash) - }) - - test('createClusterDefinition should throw on not valid deposit_amounts ', async () => { - clientInstance['request'] = jest - .fn() - .mockReturnValue(Promise.resolve({ config_hash: mockConfigHash })) - try { - await clientInstance.createClusterDefinition({ - ...clusterConfigV1X7, - deposit_amounts: ['34000000'] - }) - } catch (error: any) { - expect(error.message).toEqual( - "Schema compilation errors', must pass \"validDpositAmounts\" keyword validation", - ) - } - }) - test('validatePayload should throw an error on empty schema', async () => { try { - validatePayload({ ...clusterConfigV1X8, operators: [] }, '') + validatePayload({ ...clusterConfigV1X7, operators: [] }, '') } catch (error: any) { expect(error.message).toEqual('schema must be object or boolean') } @@ -109,29 +81,26 @@ describe('Cluster Client', () => { test('getClusterdefinition should return cluster definition if config hash exist', async () => { clientInstance['request'] = jest .fn() - .mockReturnValue(Promise.resolve(clusterLockV1X8.cluster_definition)) + .mockReturnValue(Promise.resolve(clusterLockV1X7.cluster_definition)) const clusterDefinition = await clientInstance.getClusterDefinition( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) - expect(clusterDefinition.deposit_amounts?.length).toEqual( - clusterLockV1X8.cluster_definition.deposit_amounts.length, - ) expect(clusterDefinition.config_hash).toEqual( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) }) test('getClusterLock should return lockFile if exist', async () => { clientInstance['request'] = jest .fn() - .mockReturnValue(Promise.resolve(clusterLockV1X8)) + .mockReturnValue(Promise.resolve(clusterLockV1X7)) const clusterLock = await clientInstance.getClusterLock( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) - expect(clusterLock.lock_hash).toEqual(clusterLockV1X8.lock_hash) + expect(clusterLock.lock_hash).toEqual(clusterLockV1X7.lock_hash) }) test('request method should set user agent header', async () => { @@ -171,7 +140,7 @@ describe('Cluster Client without a signer', () => { test('createClusterDefinition should throw an error without signer', async () => { try { - await clientInstance.createClusterDefinition(clusterConfigV1X8) + await clientInstance.createClusterDefinition(clusterConfigV1X7) } catch (err: any) { expect(err.message).toEqual('Signer is required in createClusterDefinition') } @@ -181,10 +150,10 @@ describe('Cluster Client without a signer', () => { try { await clientInstance.acceptClusterDefinition( { - enr: clusterLockV1X8.cluster_definition.operators[0].enr, - version: clusterLockV1X8.cluster_definition.version, + enr: clusterLockV1X7.cluster_definition.operators[0].enr, + version: clusterLockV1X7.cluster_definition.version, }, - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) } catch (err: any) { expect(err.message).toEqual('Signer is required in acceptClusterDefinition') @@ -194,25 +163,25 @@ describe('Cluster Client without a signer', () => { test('getClusterdefinition should return cluster definition if config hash exist', async () => { clientInstance['request'] = jest .fn() - .mockReturnValue(Promise.resolve(clusterLockV1X8.cluster_definition)) + .mockReturnValue(Promise.resolve(clusterLockV1X7.cluster_definition)) const clusterDefinition = await clientInstance.getClusterDefinition( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) expect(clusterDefinition.config_hash).toEqual( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) }) test('getClusterLock should return lockFile if exist', async () => { clientInstance['request'] = jest .fn() - .mockReturnValue(Promise.resolve(clusterLockV1X8)) + .mockReturnValue(Promise.resolve(clusterLockV1X7)) const clusterLock = await clientInstance.getClusterLock( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) - expect(clusterLock.lock_hash).toEqual(clusterLockV1X8.lock_hash) + expect(clusterLock.lock_hash).toEqual(clusterLockV1X7.lock_hash) }) test.each([{ version: 'v1.7.0', clusterLock: clusterLockV1X7 }, { version: 'v1.8.0', clusterLock: clusterLockV1X8 }])( diff --git a/test/sdk-package-test/cluster.test.ts b/test/sdk-package-test/cluster.test.ts index b8b55f8..6ec4a8c 100755 --- a/test/sdk-package-test/cluster.test.ts +++ b/test/sdk-package-test/cluster.test.ts @@ -1,6 +1,6 @@ import request from 'supertest' import dotenv from 'dotenv' -import { clusterConfigV1X8, clusterLockV1X7, clusterLockV1X8, enr } from './fixtures' +import { clusterConfigV1X7, clusterLockV1X7, clusterLockV1X8, enr } from './fixtures' import { client, updateClusterDef, @@ -32,7 +32,7 @@ describe('Cluster Definition', () => { }) beforeAll(async () => { - configHash = await client.createClusterDefinition(clusterConfigV1X8) + configHash = await client.createClusterDefinition(clusterConfigV1X7) }) it('should post a cluster definition and return confighash', async () => { @@ -41,7 +41,7 @@ describe('Cluster Definition', () => { it('should throw on post a cluster without a signer', async () => { try { - await clientWithoutAsigner.createClusterDefinition(clusterConfigV1X8) + await clientWithoutAsigner.createClusterDefinition(clusterConfigV1X7) } catch (err: any) { expect(err.message).toEqual('Signer is required in createClusterDefinition') } @@ -71,9 +71,9 @@ describe('Cluster Definition', () => { it('should update the cluster which the operator belongs to', async () => { const signerAddress = await signer.getAddress() - clusterConfigV1X8.operators.push({ address: signerAddress }) + clusterConfigV1X7.operators.push({ address: signerAddress }) - secondConfigHash = await client.createClusterDefinition(clusterConfigV1X8) + secondConfigHash = await client.createClusterDefinition(clusterConfigV1X7) const definitionData: ClusterDefintion = await client.acceptClusterDefinition( @@ -108,7 +108,7 @@ describe('Cluster Definition', () => { describe('Poll Cluster Lock', () => { // Test polling getClusterLock through mimicing the whole flow using obol-api endpoints - const { definition_hash: _, ...rest } = clusterLockV1X8.cluster_definition + const { definition_hash: _, ...rest } = clusterLockV1X7.cluster_definition const clusterWithoutDefHash = rest const clientWithoutAsigner = new Client({ baseUrl: 'https://obol-api-nonprod-dev.dev.obol.tech', @@ -126,7 +126,7 @@ describe('Poll Cluster Lock', () => { const pollReqIntervalId = setInterval(async function () { try { const lockFile = await client.getClusterLock( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) if (lockFile?.lock_hash) { clearInterval(pollReqIntervalId) @@ -144,8 +144,8 @@ describe('Poll Cluster Lock', () => { }, 5000) }), (async () => { - await updateClusterDef(clusterLockV1X8.cluster_definition) - await publishLockFile(clusterLockV1X8) + await updateClusterDef(clusterLockV1X7.cluster_definition) + await publishLockFile(clusterLockV1X7) })(), ]) expect(lockObject).toHaveProperty('lock_hash') @@ -158,7 +158,7 @@ describe('Poll Cluster Lock', () => { const pollReqIntervalId = setInterval(async function () { try { const lockFile = await clientWithoutAsigner.getClusterLock( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) if (lockFile?.lock_hash) { clearInterval(pollReqIntervalId) @@ -175,8 +175,8 @@ describe('Poll Cluster Lock', () => { }, 5000) }), (async () => { - await updateClusterDef(clusterLockV1X8.cluster_definition) - await publishLockFile(clusterLockV1X8) + await updateClusterDef(clusterLockV1X7.cluster_definition) + await publishLockFile(clusterLockV1X7) })(), ]) expect(lockObject).toHaveProperty('lock_hash') @@ -185,14 +185,10 @@ describe('Poll Cluster Lock', () => { it('should fetch the cluster definition for the configHash', async () => { const clusterDefinition: ClusterDefintion = await client.getClusterDefinition( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) - - expect(clusterDefinition.deposit_amounts?.length).toEqual( - clusterLockV1X8.cluster_definition.deposit_amounts.length, - ) expect(clusterDefinition.config_hash).toEqual( - clusterLockV1X8.cluster_definition.config_hash, + clusterLockV1X7.cluster_definition.config_hash, ) }) @@ -204,8 +200,8 @@ describe('Poll Cluster Lock', () => { }) afterAll(async () => { - const configHash = clusterLockV1X8.cluster_definition.config_hash - const lockHash = clusterLockV1X8.lock_hash + const configHash = clusterLockV1X7.cluster_definition.config_hash + const lockHash = clusterLockV1X7.lock_hash await request(app) .delete(`/lock/${lockHash}`)