Skip to content

Commit

Permalink
convert to DRP
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangquocvietuet committed Feb 6, 2025
1 parent e52bd06 commit 39788e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions packages/object/tests/hashgraph.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MapDRP } from "@ts-drp/blueprints/src/index.js";
import { SetDRP } from "@ts-drp/blueprints/src/index.js";
import Benchmark from "benchmark";

import { DRPObject, ObjectACL } from "../src/index.js";
import { DRP, DRPObject, ObjectACL } from "../src/index.js";

const acl = new ObjectACL({
admins: new Map([["peer1", { ed25519PublicKey: "pubKey1", blsPublicKey: "pubKey1" }]]),
Expand Down Expand Up @@ -72,7 +72,7 @@ suite.add("Create a HashGraph with 1000 operations for set wins map", () => {
acl,
drp: new MapDRP<number, number>(),
});
const drp = object.drp as unknown as MapDRP<number, number>;
const drp = object.drp as DRP as MapDRP<number, number>;
for (let i = 0; i < 1000; ++i) {
drp.set(i, i);
}
Expand All @@ -84,7 +84,7 @@ suite.add(`Create a HashGraph with ${NUMBER_OF_OPERATIONS} operations for set wi
acl,
drp: new MapDRP<number, number>(),
});
const drp = object.drp as unknown as MapDRP<number, number>;
const drp = object.drp as DRP as MapDRP<number, number>;
for (let i = 0; i < NUMBER_OF_OPERATIONS; ++i) {
drp.set(i, i);
}
Expand All @@ -98,7 +98,7 @@ suite.add(
acl,
drp: new MapDRP<number, number>(),
});
const drp = object.drp as unknown as MapDRP<number, number>;
const drp = object.drp as DRP as MapDRP<number, number>;
for (let i = 0; i < NUMBER_OF_OPERATIONS; ++i) {
drp.set(i, i);
}
Expand All @@ -116,7 +116,7 @@ suite.add(
acl,
drp: new MapDRP<number, number>(),
});
const drp = object.drp as unknown as MapDRP<number, number>;
const drp = object.drp as DRP as MapDRP<number, number>;
for (let i = 0; i < NUMBER_OF_OPERATIONS; ++i) {
drp.set(i, i);
}
Expand All @@ -135,7 +135,7 @@ suite.add(
acl,
drp: new MapDRP<number, number>(),
});
const drp = object.drp as unknown as MapDRP<number, number>;
const drp = object.drp as DRP as MapDRP<number, number>;
for (let i = 0; i < 250; i += 4) {
drp.set(i, i);
if (i % 2 === 0) {
Expand Down Expand Up @@ -180,15 +180,15 @@ suite.add(
acl,
drp: new MapDRP<number, number>(),
});
const drp1 = object1.drp as unknown as MapDRP<number, number>;
const drp1 = object1.drp as DRP as MapDRP<number, number>;
initialize(drp1);

const object2: DRPObject = new DRPObject({
peerId: "peer2",
acl,
drp: new MapDRP<number, number>(),
});
const drp2 = object2.drp as unknown as MapDRP<number, number>;
const drp2 = object2.drp as DRP as MapDRP<number, number>;
initialize(drp2);

object1.merge(object2.hashGraph.getAllVertices());
Expand Down
26 changes: 13 additions & 13 deletions packages/object/tests/hashgraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,8 @@ describe("HashGraph for set wins map tests", () => {
\
-- V2:SET("key2, "value2")
*/
const drp1 = obj1.drp as unknown as MapDRP<string, string>;
const drp2 = obj2.drp as unknown as MapDRP<string, string>;
const drp1 = obj1.drp as DRP as MapDRP<string, string>;
const drp2 = obj2.drp as DRP as MapDRP<string, string>;
drp1.set("key1", "value1");
drp2.set("key2", "value2");
drp1.delete("key1");
Expand All @@ -785,8 +785,8 @@ describe("HashGraph for set wins map tests", () => {
--- V2:SET("key1", "value1") -- V3:DELETE("key1") -- V4:SET("key2", "value2")
*/

const drp1 = obj1.drp as unknown as MapDRP<string, string>;
const drp2 = obj2.drp as unknown as MapDRP<string, string>;
const drp1 = obj1.drp as DRP as MapDRP<string, string>;
const drp2 = obj2.drp as DRP as MapDRP<string, string>;

drp1.set("key1", "value2"); // smaller hash
drp2.set("key1", "value1"); // greater hash
Expand Down Expand Up @@ -814,9 +814,9 @@ describe("HashGraph for set wins map tests", () => {
\ ----------------------------\
-- V6:SET("key2", "eulav3") ---------------------------------------------------- v8:SET("key1", "value")
*/
const drp1 = obj1.drp as unknown as MapDRP<string, string>;
const drp2 = obj2.drp as unknown as MapDRP<string, string>;
const drp3 = obj3.drp as unknown as MapDRP<string, string>;
const drp1 = obj1.drp as DRP as MapDRP<string, string>;
const drp2 = obj2.drp as DRP as MapDRP<string, string>;
const drp3 = obj3.drp as DRP as MapDRP<string, string>;

drp1.set("key1", "value1");
drp1.delete("key2");
Expand Down Expand Up @@ -864,8 +864,8 @@ describe("HashGraph for delete wins map tests", () => {
\
-- V2:SET("key1", "value2") -- DELETE("key1")
*/
const drp1 = obj1.drp as unknown as MapDRP<string, string>;
const drp2 = obj2.drp as unknown as MapDRP<string, string>;
const drp1 = obj1.drp as DRP as MapDRP<string, string>;
const drp2 = obj2.drp as DRP as MapDRP<string, string>;

drp1.set("key1", "value1"); // greater hash
drp2.set("key1", "value2"); // smaller hash
Expand All @@ -885,8 +885,8 @@ describe("HashGraph for delete wins map tests", () => {
--V2:SET("key1", "value1") -- V4:SET("key2", "value3")
*/

const drp1 = obj1.drp as unknown as MapDRP<string, string>;
const drp2 = obj2.drp as unknown as MapDRP<string, string>;
const drp1 = obj1.drp as DRP as MapDRP<string, string>;
const drp2 = obj2.drp as DRP as MapDRP<string, string>;

drp1.set("key1", "value2");
drp2.set("key1", "value1");
Expand Down Expand Up @@ -927,8 +927,8 @@ describe("Hash validation tests", () => {
});

test("Should accept vertices with valid hash", () => {
const drp1 = obj1.drp as unknown as MapDRP<string, string>;
const drp2 = obj2.drp as unknown as MapDRP<string, string>;
const drp1 = obj1.drp as DRP as MapDRP<string, string>;
const drp2 = obj2.drp as DRP as MapDRP<string, string>;
drp1.set("key1", "value1");
drp2.set("key2", "value2");

Expand Down

0 comments on commit 39788e7

Please sign in to comment.