Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes committed May 3, 2024
1 parent 33eba47 commit a01bcf8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
40 changes: 17 additions & 23 deletions typescript/sdk/src/ism/metadata/aggregation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand All @@ -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,
);
});
Expand All @@ -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);
});
});
});
11 changes: 4 additions & 7 deletions typescript/sdk/src/ism/metadata/aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { BaseMetadataBuilder, MetadataBuilder } from './builder.js';

export interface AggregationIsmMetadata {
submoduleMetadata: string[];
count: number;
}

const RANGE_SIZE = 4;
Expand All @@ -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) => {
Expand All @@ -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;
Expand All @@ -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');
}

Expand All @@ -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 };
}
}

0 comments on commit a01bcf8

Please sign in to comment.