From a01bcf84122618faca0cd98aa6de84d3ac3c85d3 Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Fri, 3 May 2024 01:08:50 -0400 Subject: [PATCH] Fix tests --- .../sdk/src/ism/metadata/aggregation.test.ts | 40 ++++++++----------- .../sdk/src/ism/metadata/aggregation.ts | 11 ++--- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/typescript/sdk/src/ism/metadata/aggregation.test.ts b/typescript/sdk/src/ism/metadata/aggregation.test.ts index d330bd278d..a8ba09048d 100644 --- a/typescript/sdk/src/ism/metadata/aggregation.test.ts +++ b/typescript/sdk/src/ism/metadata/aggregation.test.ts @@ -5,34 +5,28 @@ import { AggregationIsmMetadataBuilder, } from './aggregation.js'; -type Fixture = { - decoded: AggregationIsmMetadata; +type Fixture = AggregationIsmMetadata & { encoded: string; }; const fixtures: Fixture[] = [ { - decoded: { - submoduleMetadata: [ - '290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563', - '510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9', - '356e5a2cc1eba076e650ac7473fccc37952b46bc2e419a200cec0c451dce2336', - ], - count: 3, - }, + submoduleMetadata: [ + '290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563', + '510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9', + '356e5a2cc1eba076e650ac7473fccc37952b46bc2e419a200cec0c451dce2336', + ], encoded: '000000180000003800000038000000580000005800000078290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9356e5a2cc1eba076e650ac7473fccc37952b46bc2e419a200cec0c451dce2336', }, { - decoded: { - count: 5, - submoduleMetadata: [ - '290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563', - '510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9', - '356e5a2cc1eba076e650ac7473fccc37952b46bc2e419a200cec0c451dce2336', - 'f2e59013a0a379837166b59f871b20a8a0d101d1c355ea85d35329360e69c000', - ], - }, + submoduleMetadata: [ + '290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563', + '510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9', + '356e5a2cc1eba076e650ac7473fccc37952b46bc2e419a200cec0c451dce2336', + '', + 'f2e59013a0a379837166b59f871b20a8a0d101d1c355ea85d35329360e69c000', + ], encoded: '000000280000004800000048000000680000006800000088000000000000000000000088000000a8290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563510e4e770828ddbf7f7b00ab00a9f6adaf81c0dc9cc85f1f8249c256942d61d9356e5a2cc1eba076e650ac7473fccc37952b46bc2e419a200cec0c451dce2336f2e59013a0a379837166b59f871b20a8a0d101d1c355ea85d35329360e69c000', }, @@ -41,7 +35,7 @@ const fixtures: Fixture[] = [ describe('AggregationMetadataBuilder', () => { fixtures.forEach((fixture, i) => { it(`should encode fixture ${i}`, () => { - expect(AggregationIsmMetadataBuilder.encode(fixture.decoded)).to.equal( + expect(AggregationIsmMetadataBuilder.encode(fixture)).to.equal( fixture.encoded, ); }); @@ -50,9 +44,9 @@ describe('AggregationMetadataBuilder', () => { expect( AggregationIsmMetadataBuilder.decode( fixture.encoded, - fixture.decoded.count, - ), - ).to.deep.equal(fixture.decoded); + fixture.submoduleMetadata.length, + ).submoduleMetadata, + ).to.deep.equal(fixture.submoduleMetadata); }); }); }); diff --git a/typescript/sdk/src/ism/metadata/aggregation.ts b/typescript/sdk/src/ism/metadata/aggregation.ts index e846f7a028..03e2e9ea3c 100644 --- a/typescript/sdk/src/ism/metadata/aggregation.ts +++ b/typescript/sdk/src/ism/metadata/aggregation.ts @@ -8,7 +8,6 @@ import { BaseMetadataBuilder, MetadataBuilder } from './builder.js'; export interface AggregationIsmMetadata { submoduleMetadata: string[]; - count: number; } const RANGE_SIZE = 4; @@ -29,12 +28,11 @@ export class AggregationIsmMetadataBuilder ); return AggregationIsmMetadataBuilder.encode({ submoduleMetadata: metadatas, - count: ismConfig.threshold, }); } static encode(metadata: AggregationIsmMetadata): string { - const rangeSize = 2 * RANGE_SIZE * metadata.count; + const rangeSize = 2 * RANGE_SIZE * metadata.submoduleMetadata.length; let encoded = Buffer.alloc(rangeSize, 0); metadata.submoduleMetadata.forEach((meta, index) => { @@ -43,8 +41,7 @@ export class AggregationIsmMetadataBuilder } const start = encoded.length; - encoded = Buffer.concat([encoded, Buffer.from(meta)]); - // TODO: FIX THIS, IDK WHY ITS NOT WORKING + encoded = Buffer.concat([encoded, Buffer.from(meta, 'hex')]); const end = encoded.length; const rangeStart = 2 * RANGE_SIZE * index; @@ -59,7 +56,7 @@ export class AggregationIsmMetadataBuilder const rangeStart = index * 2 * RANGE_SIZE; const encoded = Buffer.from(metadata, 'hex'); const start = encoded.readUint32BE(rangeStart); - const end = encoded.readUint32BE(rangeStart + 1); + const end = encoded.readUint32BE(rangeStart + RANGE_SIZE); return encoded.subarray(start, end).toString('hex'); } @@ -72,6 +69,6 @@ export class AggregationIsmMetadataBuilder for (let i = 0; i < count; i++) { submoduleMetadata.push(this.metadataRange(metadata, i)); } - return { submoduleMetadata, count }; + return { submoduleMetadata }; } }