Skip to content

Commit

Permalink
fix: more StableContainer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Sep 22, 2024
1 parent ded7143 commit 624f6b4
Show file tree
Hide file tree
Showing 3 changed files with 618 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ssz/src/type/stableContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ function readVariableOffsets(
// the offset indices so we can more easily deserialize the fields in once pass first we get the fixed sizes
// Note: `fixedSizes[i] = null` if that field has variable length

const size = end - activeFieldsEnd;
const size = end - start;
const activeFieldsByteLen = activeFieldsEnd - start;

// with the fixed sizes, we can read the offsets, and store for our single pass
Expand Down
10 changes: 9 additions & 1 deletion packages/ssz/src/viewDU/stableContainer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getNodeAtDepth, LeafNode, Node, zeroNode} from "@chainsafe/persistent-merkle-tree";
import {getNodeAtDepth, LeafNode, Node, zeroNode, HashComputationLevel} from "@chainsafe/persistent-merkle-tree";
import {ByteViews, Type} from "../type/abstract";
import {BasicType, isBasicType} from "../type/basic";
import {CompositeType, isCompositeType} from "../type/composite";
Expand Down Expand Up @@ -66,6 +66,14 @@ class StableContainerTreeViewDU<Fields extends Record<string, Type<unknown>>> ex
return {...result, activeFields: this.activeFields};
}

commit(hcOffset = 0, hcByLevel: HashComputationLevel[] | null = null): void {
super.commit(hcOffset, hcByLevel);
this._rootNode = this.type.tree_setActiveFields(this._rootNode, this.activeFields);
if (hcByLevel !== null) {
hcByLevel[hcOffset].push(this._rootNode.left, this._rootNode.right, this._rootNode);
}
}

/**
* Same method to `type/container.ts` that call ViewDU.serializeToBytes() of internal fields.
*/
Expand Down
Loading

0 comments on commit 624f6b4

Please sign in to comment.