@evefrontier/dapp-kit 0.1.8 → 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -25
- package/dist/config/dapp-kit.d.ts +4 -0
- package/dist/config/dapp-kit.d.ts.map +1 -0
- package/dist/config/dapp-kit.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +1 -0
- package/dist/graphql/client.d.ts +277 -0
- package/dist/graphql/client.d.ts.map +1 -0
- package/dist/graphql/client.js +346 -0
- package/dist/graphql/index.d.ts +4 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +16 -0
- package/dist/graphql/queries.d.ts +103 -0
- package/dist/graphql/queries.d.ts.map +1 -0
- package/{graphql/queries.ts → dist/graphql/queries.js} +113 -223
- package/dist/graphql/types.d.ts +396 -0
- package/dist/graphql/types.d.ts.map +1 -0
- package/dist/graphql/types.js +4 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useCharacterDirectory.d.ts +16 -0
- package/dist/hooks/useCharacterDirectory.d.ts.map +1 -0
- package/dist/hooks/useCharacterDirectory.js +23 -0
- package/dist/hooks/useCharacterSearch.d.ts +24 -0
- package/dist/hooks/useCharacterSearch.d.ts.map +1 -0
- package/dist/hooks/useCharacterSearch.js +24 -0
- package/dist/hooks/useConnection.d.ts +51 -0
- package/dist/hooks/useConnection.d.ts.map +1 -0
- package/{hooks/useConnection.ts → dist/hooks/useConnection.js} +8 -10
- package/dist/hooks/useEntityRole.d.ts +26 -0
- package/dist/hooks/useEntityRole.d.ts.map +1 -0
- package/dist/hooks/useEntityRole.js +91 -0
- package/dist/hooks/useNotification.d.ts +72 -0
- package/dist/hooks/useNotification.d.ts.map +1 -0
- package/{hooks/useNotification.ts → dist/hooks/useNotification.js} +8 -12
- package/dist/hooks/useSmartObject.d.ts +44 -0
- package/dist/hooks/useSmartObject.d.ts.map +1 -0
- package/dist/hooks/useSmartObject.js +50 -0
- package/dist/hooks/useSponsoredTransaction.d.ts +147 -0
- package/dist/hooks/useSponsoredTransaction.d.ts.map +1 -0
- package/dist/hooks/useSponsoredTransaction.js +240 -0
- package/dist/hooks/useTypeNames.d.ts +11 -0
- package/dist/hooks/useTypeNames.d.ts.map +1 -0
- package/dist/hooks/useTypeNames.js +24 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/providers/EveFrontierProvider.d.ts +23 -0
- package/dist/providers/EveFrontierProvider.d.ts.map +1 -0
- package/dist/providers/EveFrontierProvider.js +23 -0
- package/dist/providers/NotificationProvider.d.ts +14 -0
- package/dist/providers/NotificationProvider.d.ts.map +1 -0
- package/dist/providers/NotificationProvider.js +66 -0
- package/dist/providers/SmartObjectProvider.d.ts +31 -0
- package/dist/providers/SmartObjectProvider.d.ts.map +1 -0
- package/dist/providers/SmartObjectProvider.js +80 -0
- package/dist/providers/VaultProvider.d.ts +10 -0
- package/dist/providers/VaultProvider.d.ts.map +1 -0
- package/dist/providers/VaultProvider.js +79 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/smartObject/useEntityData.d.ts +29 -0
- package/dist/providers/smartObject/useEntityData.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntityData.js +135 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts +14 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntitySubscription.js +58 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts +11 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts.map +1 -0
- package/dist/providers/smartObject/useObjectSelection.js +27 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts +18 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts.map +1 -0
- package/dist/providers/smartObject/usePollingBackstop.js +38 -0
- package/dist/types/character.d.ts +21 -0
- package/dist/types/character.d.ts.map +1 -0
- package/dist/types/character.js +1 -0
- package/dist/types/contexts.d.ts +61 -0
- package/dist/types/contexts.d.ts.map +1 -0
- package/dist/types/contexts.js +6 -0
- package/dist/types/entity.d.ts +245 -0
- package/dist/types/entity.d.ts.map +1 -0
- package/dist/types/entity.js +6 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/sponsoredTransaction.d.ts +26 -0
- package/dist/types/sponsoredTransaction.d.ts.map +1 -0
- package/dist/types/sponsoredTransaction.js +10 -0
- package/dist/types/types.d.ts +110 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +41 -0
- package/dist/types/worldApiReturnTypes.d.ts +68 -0
- package/dist/types/worldApiReturnTypes.d.ts.map +1 -0
- package/dist/types/worldApiReturnTypes.js +1 -0
- package/{utils/burnRate.ts → dist/utils/burnRate.d.ts} +4 -29
- package/dist/utils/burnRate.d.ts.map +1 -0
- package/dist/utils/burnRate.js +25 -0
- package/dist/utils/characters.d.ts +26 -0
- package/dist/utils/characters.d.ts.map +1 -0
- package/dist/utils/characters.js +84 -0
- package/dist/utils/constants.d.ts +153 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +190 -0
- package/dist/utils/datahub.d.ts +40 -0
- package/dist/utils/datahub.d.ts.map +1 -0
- package/{utils/datahub.ts → dist/utils/datahub.js} +32 -25
- package/dist/utils/entity.d.ts +58 -0
- package/dist/utils/entity.d.ts.map +1 -0
- package/dist/utils/entity.js +386 -0
- package/dist/utils/errors.d.ts +18 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +128 -0
- package/dist/utils/events/entityEvents.d.ts +44 -0
- package/dist/utils/events/entityEvents.d.ts.map +1 -0
- package/dist/utils/events/entityEvents.js +95 -0
- package/dist/utils/events/entitySubscription.d.ts +30 -0
- package/dist/utils/events/entitySubscription.d.ts.map +1 -0
- package/dist/utils/events/entitySubscription.js +84 -0
- package/dist/utils/events/graphqlEventStream.d.ts +90 -0
- package/dist/utils/events/graphqlEventStream.d.ts.map +1 -0
- package/dist/utils/events/graphqlEventStream.js +198 -0
- package/dist/utils/events/refetchScheduler.d.ts +30 -0
- package/dist/utils/events/refetchScheduler.d.ts.map +1 -0
- package/dist/utils/events/refetchScheduler.js +57 -0
- package/dist/utils/events/sseClient.d.ts +42 -0
- package/dist/utils/events/sseClient.d.ts.map +1 -0
- package/dist/utils/events/sseClient.js +97 -0
- package/dist/utils/fuel.d.ts +231 -0
- package/dist/utils/fuel.d.ts.map +1 -0
- package/dist/utils/fuel.js +652 -0
- package/dist/utils/grid.d.ts +115 -0
- package/dist/utils/grid.d.ts.map +1 -0
- package/dist/utils/grid.js +115 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/inventory.d.ts +3 -0
- package/dist/utils/inventory.d.ts.map +1 -0
- package/dist/utils/inventory.js +12 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +228 -0
- package/dist/utils/mapping.d.ts +30 -0
- package/dist/utils/mapping.d.ts.map +1 -0
- package/dist/utils/mapping.js +73 -0
- package/dist/utils/mvr/worldTypes.d.ts +35 -0
- package/dist/utils/mvr/worldTypes.d.ts.map +1 -0
- package/dist/utils/mvr/worldTypes.js +54 -0
- package/dist/utils/role.d.ts +116 -0
- package/dist/utils/role.d.ts.map +1 -0
- package/dist/utils/role.js +120 -0
- package/dist/utils/smartObject.d.ts +24 -0
- package/dist/utils/smartObject.d.ts.map +1 -0
- package/dist/utils/smartObject.js +24 -0
- package/dist/utils/utils.d.ts +133 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +213 -0
- package/dist/wallet/features.d.ts +28 -0
- package/dist/wallet/features.d.ts.map +1 -0
- package/dist/wallet/features.js +22 -0
- package/dist/wallet/index.d.ts +9 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +9 -0
- package/dist/wallet/utils.d.ts +71 -0
- package/dist/wallet/utils.d.ts.map +1 -0
- package/dist/wallet/utils.js +79 -0
- package/package.json +69 -35
- package/config/dapp-kit.ts +0 -20
- package/config/index.ts +0 -1
- package/graphql/client.ts +0 -578
- package/graphql/index.ts +0 -39
- package/graphql/types.ts +0 -468
- package/hooks/index.ts +0 -15
- package/hooks/useSmartObject.ts +0 -66
- package/hooks/useSponsoredTransaction.ts +0 -442
- package/index.ts +0 -88
- package/providers/EveFrontierProvider.tsx +0 -41
- package/providers/NotificationProvider.tsx +0 -108
- package/providers/SmartObjectProvider.tsx +0 -296
- package/providers/VaultProvider.tsx +0 -108
- package/providers/index.ts +0 -10
- package/types/contexts.ts +0 -67
- package/types/global.d.ts +0 -7
- package/types/index.ts +0 -4
- package/types/sponsoredTransaction.ts +0 -70
- package/types/types.ts +0 -198
- package/types/worldApiReturnTypes.ts +0 -144
- package/utils/__tests__/burnRate.test.ts +0 -121
- package/utils/__tests__/character.test.ts +0 -112
- package/utils/__tests__/characterOwnedObjects.test.ts +0 -225
- package/utils/__tests__/config.test.ts +0 -424
- package/utils/__tests__/datahub.test.ts +0 -58
- package/utils/__tests__/logger.test.ts +0 -145
- package/utils/__tests__/mapping.test.ts +0 -439
- package/utils/__tests__/utils.test.ts +0 -299
- package/utils/character.ts +0 -46
- package/utils/characterOwnedObjects.ts +0 -53
- package/utils/config.ts +0 -151
- package/utils/constants.ts +0 -254
- package/utils/errors.ts +0 -171
- package/utils/index.ts +0 -47
- package/utils/logger.ts +0 -300
- package/utils/mapping.ts +0 -118
- package/utils/transforms.ts +0 -263
- package/utils/utils.ts +0 -270
- package/wallet/features.ts +0 -136
- package/wallet/index.ts +0 -26
- package/wallet/utils.ts +0 -117
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
createLogger,
|
|
4
|
-
resolveLogLevelFromEnv,
|
|
5
|
-
} from "../logger";
|
|
6
|
-
|
|
7
|
-
describe("resolveLogLevelFromEnv", () => {
|
|
8
|
-
it("uses error when viteMode is production", () => {
|
|
9
|
-
expect(resolveLogLevelFromEnv({ viteMode: "production" })).toBe("error");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("uses warn when viteMode is test", () => {
|
|
13
|
-
expect(resolveLogLevelFromEnv({ viteMode: "test" })).toBe("warn");
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("uses debug for development or unset mode", () => {
|
|
17
|
-
expect(resolveLogLevelFromEnv({ viteMode: "development" })).toBe("debug");
|
|
18
|
-
expect(resolveLogLevelFromEnv({})).toBe("debug");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("prefers VITE_LOG_LEVEL over mode when it is a valid level", () => {
|
|
22
|
-
expect(
|
|
23
|
-
resolveLogLevelFromEnv({
|
|
24
|
-
viteLogLevel: "info",
|
|
25
|
-
viteMode: "production",
|
|
26
|
-
}),
|
|
27
|
-
).toBe("info");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("normalizes explicit log level to lowercase", () => {
|
|
31
|
-
expect(
|
|
32
|
-
resolveLogLevelFromEnv({ viteLogLevel: "WARN", viteMode: "development" }),
|
|
33
|
-
).toBe("warn");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("ignores invalid VITE_LOG_LEVEL and falls back to mode", () => {
|
|
37
|
-
expect(
|
|
38
|
-
resolveLogLevelFromEnv({
|
|
39
|
-
viteLogLevel: "not-a-level",
|
|
40
|
-
viteMode: "production",
|
|
41
|
-
}),
|
|
42
|
-
).toBe("error");
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe("createLogger — level gating", () => {
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
vi.restoreAllMocks();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("at error level, only error logs call console", () => {
|
|
52
|
-
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
53
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
54
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
55
|
-
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
56
|
-
|
|
57
|
-
const log = createLogger({ level: "error", scope: "gate" });
|
|
58
|
-
log.debug("d");
|
|
59
|
-
log.info("i");
|
|
60
|
-
log.warn("w");
|
|
61
|
-
log.error("e");
|
|
62
|
-
|
|
63
|
-
expect(debugSpy).not.toHaveBeenCalled();
|
|
64
|
-
expect(infoSpy).not.toHaveBeenCalled();
|
|
65
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
66
|
-
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("at silent level, no console methods are invoked", () => {
|
|
70
|
-
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
71
|
-
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
72
|
-
|
|
73
|
-
const log = createLogger({ level: "silent", scope: "quiet" });
|
|
74
|
-
log.debug("d");
|
|
75
|
-
log.error("e");
|
|
76
|
-
|
|
77
|
-
expect(debugSpy).not.toHaveBeenCalled();
|
|
78
|
-
expect(errorSpy).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("at warn level, warn and error log but not info or debug", () => {
|
|
82
|
-
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
83
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
84
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
85
|
-
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
86
|
-
|
|
87
|
-
const log = createLogger({ level: "warn", scope: "w" });
|
|
88
|
-
log.debug("d");
|
|
89
|
-
log.info("i");
|
|
90
|
-
log.warn("w");
|
|
91
|
-
log.error("e");
|
|
92
|
-
|
|
93
|
-
expect(debugSpy).not.toHaveBeenCalled();
|
|
94
|
-
expect(infoSpy).not.toHaveBeenCalled();
|
|
95
|
-
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
96
|
-
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("child logger inherits parent level", () => {
|
|
100
|
-
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
101
|
-
|
|
102
|
-
const parent = createLogger({ level: "error", scope: "p" });
|
|
103
|
-
const child = parent.child("c");
|
|
104
|
-
child.debug("x");
|
|
105
|
-
|
|
106
|
-
expect(debugSpy).not.toHaveBeenCalled();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe("createLogger — console format args (%s preservation)", () => {
|
|
111
|
-
afterEach(() => {
|
|
112
|
-
vi.restoreAllMocks();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("merges prefix into the first string so %s remains the console format string", () => {
|
|
116
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
117
|
-
|
|
118
|
-
const log = createLogger({ level: "info", scope: "fmt" });
|
|
119
|
-
log.info("%s world", "hello");
|
|
120
|
-
|
|
121
|
-
expect(infoSpy).toHaveBeenCalledTimes(1);
|
|
122
|
-
const args = infoSpy.mock.calls[0] as unknown[];
|
|
123
|
-
expect(args.length).toBe(2);
|
|
124
|
-
expect(typeof args[0]).toBe("string");
|
|
125
|
-
expect(args[0]).toContain("%s world");
|
|
126
|
-
expect(args[0]).toMatch(/\[fmt\]/);
|
|
127
|
-
expect(args[1]).toBe("hello");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("keeps prefix as a separate first arg when the first log argument is not a string", () => {
|
|
131
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
132
|
-
|
|
133
|
-
const log = createLogger({ level: "info", scope: "obj" });
|
|
134
|
-
const payload = { a: 1 };
|
|
135
|
-
log.info(payload, "extra");
|
|
136
|
-
|
|
137
|
-
expect(infoSpy).toHaveBeenCalledTimes(1);
|
|
138
|
-
const args = infoSpy.mock.calls[0] as unknown[];
|
|
139
|
-
expect(args.length).toBe(3);
|
|
140
|
-
expect(typeof args[0]).toBe("string");
|
|
141
|
-
expect(args[0]).toMatch(/\[obj\]/);
|
|
142
|
-
expect(args[1]).toBe(payload);
|
|
143
|
-
expect(args[2]).toBe("extra");
|
|
144
|
-
});
|
|
145
|
-
});
|
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { bcs } from "@mysten/sui/bcs";
|
|
3
|
-
import { deriveObjectID } from "@mysten/sui/utils";
|
|
4
|
-
import { parseStatus, getAssemblyType } from "../mapping";
|
|
5
|
-
import { Assemblies, State } from "../../types";
|
|
6
|
-
import { getObjectRegistryType } from "../constants";
|
|
7
|
-
|
|
8
|
-
// Mock env vars for testing
|
|
9
|
-
const TEST_EVE_WORLD_PACKAGE_ID =
|
|
10
|
-
"0x2ff3e06b96eb830bdcffbc6cae9b8fe43f005c3b94cef05d9ec23057df16f107";
|
|
11
|
-
|
|
12
|
-
// Mock the GraphQL client (only for getObjectId/getRegistryAddress tests)
|
|
13
|
-
vi.mock("../../graphql/client", () => ({
|
|
14
|
-
getSingletonObjectByType: vi.fn(),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
import { getSingletonObjectByType } from "../../graphql/client";
|
|
18
|
-
|
|
19
|
-
describe("mapping utilities", () => {
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
vi.clearAllMocks();
|
|
22
|
-
// Stub environment variables for tests
|
|
23
|
-
vi.stubEnv("VITE_EVE_WORLD_PACKAGE_ID", TEST_EVE_WORLD_PACKAGE_ID);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
vi.restoreAllMocks();
|
|
28
|
-
vi.unstubAllEnvs();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// ============================================================================
|
|
32
|
-
// parseStatus Tests
|
|
33
|
-
// ============================================================================
|
|
34
|
-
describe("parseStatus", () => {
|
|
35
|
-
it("returns State.ONLINE for 'ONLINE' status", () => {
|
|
36
|
-
expect(parseStatus("ONLINE")).toBe(State.ONLINE);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("returns State.ONLINE for lowercase 'online' status", () => {
|
|
40
|
-
expect(parseStatus("online")).toBe(State.ONLINE);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("returns State.ANCHORED for 'OFFLINE' status", () => {
|
|
44
|
-
expect(parseStatus("OFFLINE")).toBe(State.ANCHORED);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("returns State.ANCHORED for 'ANCHORED' status", () => {
|
|
48
|
-
expect(parseStatus("ANCHORED")).toBe(State.ANCHORED);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("returns State.UNANCHORED for 'UNANCHORED' status", () => {
|
|
52
|
-
expect(parseStatus("UNANCHORED")).toBe(State.UNANCHORED);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("returns State.NULL for undefined status", () => {
|
|
56
|
-
expect(parseStatus(undefined)).toBe(State.NULL);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("returns State.NULL for empty string", () => {
|
|
60
|
-
expect(parseStatus("")).toBe(State.NULL);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// ============================================================================
|
|
65
|
-
// getAssemblyType Tests
|
|
66
|
-
// ============================================================================
|
|
67
|
-
describe("getAssemblyType", () => {
|
|
68
|
-
it("returns SmartStorageUnit for storage_unit type", () => {
|
|
69
|
-
expect(
|
|
70
|
-
getAssemblyType(
|
|
71
|
-
`${TEST_EVE_WORLD_PACKAGE_ID}::storage_unit::StorageUnit<...>`,
|
|
72
|
-
),
|
|
73
|
-
).toBe(Assemblies.SmartStorageUnit);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("returns SmartTurret for turret type", () => {
|
|
77
|
-
expect(
|
|
78
|
-
getAssemblyType(`${TEST_EVE_WORLD_PACKAGE_ID}::turret::Turret<...>`),
|
|
79
|
-
).toBe(Assemblies.SmartTurret);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("returns SmartGate for gate type", () => {
|
|
83
|
-
expect(
|
|
84
|
-
getAssemblyType(`${TEST_EVE_WORLD_PACKAGE_ID}::gate::Gate<...>`),
|
|
85
|
-
).toBe(Assemblies.SmartGate);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("returns NetworkNode for network_node type", () => {
|
|
89
|
-
expect(
|
|
90
|
-
getAssemblyType(
|
|
91
|
-
`${TEST_EVE_WORLD_PACKAGE_ID}::network_node::NetworkNode<...>`,
|
|
92
|
-
),
|
|
93
|
-
).toBe(Assemblies.NetworkNode);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("returns Assembly as default for unknown type", () => {
|
|
97
|
-
expect(getAssemblyType("unknown::type::Unknown")).toBe(
|
|
98
|
-
Assemblies.Assembly,
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("handles type strings with different package IDs", () => {
|
|
103
|
-
expect(
|
|
104
|
-
getAssemblyType("0xabc123::storage_unit::StorageUnit<SomeType>"),
|
|
105
|
-
).toBe(Assemblies.SmartStorageUnit);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// ============================================================================
|
|
110
|
-
// getRegistryAddress Tests
|
|
111
|
-
// ============================================================================
|
|
112
|
-
describe("getRegistryAddress", () => {
|
|
113
|
-
const mockAssemblyRegistryAddress =
|
|
114
|
-
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
115
|
-
const mockCharacterRegistryAddress =
|
|
116
|
-
"0xfedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321";
|
|
117
|
-
|
|
118
|
-
beforeEach(() => {
|
|
119
|
-
vi.resetModules();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("fetches assembly registry address from GraphQL", async () => {
|
|
123
|
-
vi.mocked(getSingletonObjectByType).mockResolvedValueOnce({
|
|
124
|
-
data: {
|
|
125
|
-
objects: {
|
|
126
|
-
nodes: [{ address: mockAssemblyRegistryAddress }],
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const { getRegistryAddress } = await import("../mapping");
|
|
132
|
-
const address = await getRegistryAddress();
|
|
133
|
-
|
|
134
|
-
expect(getSingletonObjectByType).toHaveBeenCalledWith(
|
|
135
|
-
getObjectRegistryType(),
|
|
136
|
-
);
|
|
137
|
-
expect(address).toBe(mockAssemblyRegistryAddress);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("fetches character registry address from GraphQL", async () => {
|
|
141
|
-
vi.mocked(getSingletonObjectByType).mockResolvedValueOnce({
|
|
142
|
-
data: {
|
|
143
|
-
objects: {
|
|
144
|
-
nodes: [{ address: mockCharacterRegistryAddress }],
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const { getRegistryAddress } = await import("../mapping");
|
|
150
|
-
const address = await getRegistryAddress();
|
|
151
|
-
|
|
152
|
-
expect(getSingletonObjectByType).toHaveBeenCalledWith(
|
|
153
|
-
getObjectRegistryType(),
|
|
154
|
-
);
|
|
155
|
-
expect(address).toBe(mockCharacterRegistryAddress);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("caches assembly registry address after first fetch", async () => {
|
|
159
|
-
vi.mocked(getSingletonObjectByType).mockResolvedValueOnce({
|
|
160
|
-
data: {
|
|
161
|
-
objects: {
|
|
162
|
-
nodes: [{ address: mockAssemblyRegistryAddress }],
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
const { getRegistryAddress } = await import("../mapping");
|
|
168
|
-
|
|
169
|
-
const address = await getRegistryAddress();
|
|
170
|
-
|
|
171
|
-
expect(getSingletonObjectByType).toHaveBeenCalledTimes(1);
|
|
172
|
-
expect(address).toBe(mockAssemblyRegistryAddress);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("throws error when registry address is not found", async () => {
|
|
176
|
-
vi.mocked(getSingletonObjectByType).mockResolvedValueOnce({
|
|
177
|
-
data: {
|
|
178
|
-
objects: {
|
|
179
|
-
nodes: [],
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
const { getRegistryAddress } = await import("../mapping");
|
|
185
|
-
|
|
186
|
-
await expect(getRegistryAddress()).rejects.toThrow(
|
|
187
|
-
`ObjectRegistry not found for type: ${getObjectRegistryType()}`,
|
|
188
|
-
);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("throws error when GraphQL response has no data", async () => {
|
|
192
|
-
vi.mocked(getSingletonObjectByType).mockResolvedValueOnce({
|
|
193
|
-
data: undefined,
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
const { getRegistryAddress } = await import("../mapping");
|
|
197
|
-
|
|
198
|
-
await expect(getRegistryAddress()).rejects.toThrow(
|
|
199
|
-
`ObjectRegistry not found for type: ${getObjectRegistryType()}`,
|
|
200
|
-
);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// ============================================================================
|
|
205
|
-
describe("deriveObjectID derivation", () => {
|
|
206
|
-
const TenantItemIdBcs = bcs.struct("TenantItemId", {
|
|
207
|
-
item_id: bcs.u64(),
|
|
208
|
-
tenant: bcs.string(),
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("works with primitive string (from Sui docs)", () => {
|
|
212
|
-
const result = deriveObjectID(
|
|
213
|
-
"0xc0ffee",
|
|
214
|
-
"0x1::string::String",
|
|
215
|
-
bcs.String.serialize("foo").toBytes(),
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
expect(result).toBe(
|
|
219
|
-
"0x699219f4a2b6cfb8640bb853fc4ab4f497da038ec0614bfa2835aa27993399db",
|
|
220
|
-
);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("works with primitive u8 (from Sui docs)", () => {
|
|
224
|
-
const result = deriveObjectID(
|
|
225
|
-
"0x2",
|
|
226
|
-
"u8",
|
|
227
|
-
bcs.u8().serialize(1).toBytes(),
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
expect(result).toBe(
|
|
231
|
-
"0x4de7696edddfb592a8dc7c8b66053b1557eb4fa1a9194322562aabf3da9e9239",
|
|
232
|
-
);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("works with primitive u32 (from old Character contract)", () => {
|
|
236
|
-
const result = deriveObjectID(
|
|
237
|
-
"0xbe0c6bf206ff70ed30ef367dc46f8d47fa20263c3d3c04e0b08312b291a4755d",
|
|
238
|
-
"u32",
|
|
239
|
-
bcs.u32().serialize(1003).toBytes(),
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
expect(result).toBe(
|
|
243
|
-
"0xba2beac06dfcebe1963dea11ad37b4b851dd8060b6510c57e160e84280ed8b4c",
|
|
244
|
-
);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("works with TenantItemId struct", () => {
|
|
248
|
-
const key = TenantItemIdBcs.serialize({
|
|
249
|
-
item_id: 204305,
|
|
250
|
-
tenant: "yanns-macbook-pro.local",
|
|
251
|
-
}).toBytes();
|
|
252
|
-
|
|
253
|
-
const result = deriveObjectID(
|
|
254
|
-
"0x72ad8a9f876b922fb244761da022b328a8d487708d821f4d991414f320749c41",
|
|
255
|
-
"0xe938ed4a360f86554fda6f4493866b0732cdd996d80e1cee429ad35d0a03deee::game_id::TenantItemId",
|
|
256
|
-
key,
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
expect(result).toBe(
|
|
260
|
-
"0xac1edc9cd64eb00ee3f98a583d7f7c94a39493c984706e6b3afe2668c4c8fb4c",
|
|
261
|
-
);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it("works with TenantItemId struct in test tenant (sample #1 from contracts)", () => {
|
|
265
|
-
const key = TenantItemIdBcs.serialize({
|
|
266
|
-
item_id: 691735,
|
|
267
|
-
tenant: "test",
|
|
268
|
-
}).toBytes();
|
|
269
|
-
|
|
270
|
-
const result = deriveObjectID(
|
|
271
|
-
"0x70c704eb8ee89c910a31ecf550a85514d5a4d3d2742cc2fbd5b2131c3513b79c",
|
|
272
|
-
"0x8941524ae368d91a7f9ee95466d3e60b75ddc16de3c3b9233dc11f85ce86c258::game_id::TenantItemId",
|
|
273
|
-
key,
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
expect(result).toBe(
|
|
277
|
-
"0xccee853995609e171763798b6faaf635793a9a88d79211d6486bfdd268d3fd73",
|
|
278
|
-
);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it("works with TenantItemId struct in test tenant (sample #2 from contracts)", () => {
|
|
282
|
-
const key = TenantItemIdBcs.serialize({
|
|
283
|
-
item_id: 625814,
|
|
284
|
-
tenant: "test",
|
|
285
|
-
}).toBytes();
|
|
286
|
-
|
|
287
|
-
const result = deriveObjectID(
|
|
288
|
-
"0x70c704eb8ee89c910a31ecf550a85514d5a4d3d2742cc2fbd5b2131c3513b79c",
|
|
289
|
-
"0x8941524ae368d91a7f9ee95466d3e60b75ddc16de3c3b9233dc11f85ce86c258::game_id::TenantItemId",
|
|
290
|
-
key,
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
expect(result).toBe(
|
|
294
|
-
"0x4b63016cb24af75235f8ab7c43b9fdfa52bb87a0f99c8f6d3d58c228d6fdc4c5",
|
|
295
|
-
);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
it("works with new SSUID", () => {
|
|
299
|
-
const key = TenantItemIdBcs.serialize({
|
|
300
|
-
item_id: 1000000012533,
|
|
301
|
-
tenant: "tauceti",
|
|
302
|
-
}).toBytes();
|
|
303
|
-
|
|
304
|
-
const result = deriveObjectID(
|
|
305
|
-
"0x226c1a6e456f7438f4a2bc83808df75fb3e47fea4b11ef220f9a2df8fb91a97c",
|
|
306
|
-
"0x2ff3e06b96eb830bdcffbc6cae9b8fe43f005c3b94cef05d9ec23057df16f107::in_game_id::TenantItemId",
|
|
307
|
-
key,
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
expect(result).toBe(
|
|
311
|
-
"0xd4e78bd8312d46b58ad8acb0a352c278384914c705fd90968bef5eb8c44cb667",
|
|
312
|
-
);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("produces different results for different tenants", () => {
|
|
316
|
-
const key1 = TenantItemIdBcs.serialize({
|
|
317
|
-
item_id: 12345,
|
|
318
|
-
tenant: "tenant1",
|
|
319
|
-
}).toBytes();
|
|
320
|
-
|
|
321
|
-
const key2 = TenantItemIdBcs.serialize({
|
|
322
|
-
item_id: 12345,
|
|
323
|
-
tenant: "tenant2",
|
|
324
|
-
}).toBytes();
|
|
325
|
-
|
|
326
|
-
const parentId =
|
|
327
|
-
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
328
|
-
const keyType = "0x1234::game_id::TenantItemId";
|
|
329
|
-
|
|
330
|
-
const result1 = deriveObjectID(parentId, keyType, key1);
|
|
331
|
-
const result2 = deriveObjectID(parentId, keyType, key2);
|
|
332
|
-
|
|
333
|
-
expect(result1).not.toBe(result2);
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
it("produces different results for different parent IDs", () => {
|
|
337
|
-
const key = TenantItemIdBcs.serialize({
|
|
338
|
-
item_id: 12345,
|
|
339
|
-
tenant: "test",
|
|
340
|
-
}).toBytes();
|
|
341
|
-
|
|
342
|
-
const keyType = "0x1234::game_id::TenantItemId";
|
|
343
|
-
|
|
344
|
-
const result1 = deriveObjectID(
|
|
345
|
-
"0x1111111111111111111111111111111111111111111111111111111111111111",
|
|
346
|
-
keyType,
|
|
347
|
-
key,
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
const result2 = deriveObjectID(
|
|
351
|
-
"0x2222222222222222222222222222222222222222222222222222222222222222",
|
|
352
|
-
keyType,
|
|
353
|
-
key,
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
expect(result1).not.toBe(result2);
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
// ============================================================================
|
|
361
|
-
// getObjectId Tests (mocked)
|
|
362
|
-
// ============================================================================
|
|
363
|
-
describe("getObjectId", () => {
|
|
364
|
-
const mockRegistryAddress =
|
|
365
|
-
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
366
|
-
|
|
367
|
-
beforeEach(() => {
|
|
368
|
-
vi.resetModules();
|
|
369
|
-
|
|
370
|
-
vi.mocked(getSingletonObjectByType).mockResolvedValue({
|
|
371
|
-
data: {
|
|
372
|
-
objects: {
|
|
373
|
-
nodes: [{ address: mockRegistryAddress }],
|
|
374
|
-
},
|
|
375
|
-
},
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
it("fetches registry address and derives object ID", async () => {
|
|
380
|
-
const { getObjectId } = await import("../mapping");
|
|
381
|
-
const itemId = "12345";
|
|
382
|
-
|
|
383
|
-
const objectId = await getObjectId(itemId, "tauceti");
|
|
384
|
-
|
|
385
|
-
expect(getSingletonObjectByType).toHaveBeenCalledWith(
|
|
386
|
-
getObjectRegistryType(),
|
|
387
|
-
);
|
|
388
|
-
expect(typeof objectId).toBe("string");
|
|
389
|
-
expect(objectId.startsWith("0x")).toBe(true);
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it("uses OBJECT registry type when specified", async () => {
|
|
393
|
-
const { getObjectId } = await import("../mapping");
|
|
394
|
-
|
|
395
|
-
await getObjectId("12345", "tauceti");
|
|
396
|
-
|
|
397
|
-
expect(getSingletonObjectByType).toHaveBeenCalledWith(
|
|
398
|
-
getObjectRegistryType(),
|
|
399
|
-
);
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
it("uses default OBJECT registry type when not specified", async () => {
|
|
403
|
-
const { getObjectId } = await import("../mapping");
|
|
404
|
-
|
|
405
|
-
await getObjectId("12345", "tauceti");
|
|
406
|
-
|
|
407
|
-
expect(getSingletonObjectByType).toHaveBeenCalledWith(
|
|
408
|
-
getObjectRegistryType(),
|
|
409
|
-
);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
it("propagates errors when registry address not found", async () => {
|
|
413
|
-
vi.mocked(getSingletonObjectByType).mockResolvedValueOnce({
|
|
414
|
-
data: {
|
|
415
|
-
objects: {
|
|
416
|
-
nodes: [],
|
|
417
|
-
},
|
|
418
|
-
},
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
const { getObjectId } = await import("../mapping");
|
|
422
|
-
|
|
423
|
-
await expect(getObjectId("12345", "tauceti")).rejects.toThrow(
|
|
424
|
-
`ObjectRegistry not found for type: ${getObjectRegistryType()}`,
|
|
425
|
-
);
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it("caches registry address across multiple calls", async () => {
|
|
429
|
-
const { getObjectId } = await import("../mapping");
|
|
430
|
-
|
|
431
|
-
await getObjectId("12345", "tauceti");
|
|
432
|
-
await getObjectId("67890", "tauceti");
|
|
433
|
-
await getObjectId("11111", "tauceti");
|
|
434
|
-
|
|
435
|
-
// Should only fetch registry once (cached)
|
|
436
|
-
expect(getSingletonObjectByType).toHaveBeenCalledTimes(1);
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
});
|