-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1ebb4a
commit d9c7f49
Showing
4 changed files
with
208 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest"; | ||
import { IrysService } from "../src/services/irysService"; | ||
import { defaultCharacter, IrysDataType } from "@elizaos/core"; | ||
|
||
// Mock NodeCache | ||
vi.mock("node-cache", () => { | ||
return { | ||
default: vi.fn().mockImplementation(() => ({ | ||
set: vi.fn(), | ||
get: vi.fn().mockReturnValue(null), | ||
})), | ||
}; | ||
}); | ||
|
||
// Mock path module | ||
vi.mock("path", async () => { | ||
const actual = await vi.importActual("path"); | ||
return { | ||
...actual, | ||
join: vi.fn().mockImplementation((...args) => args.join("/")), | ||
}; | ||
}); | ||
|
||
// Mock the ICacheManager | ||
const mockCacheManager = { | ||
get: vi.fn().mockResolvedValue(null), | ||
set: vi.fn(), | ||
delete: vi.fn(), | ||
}; | ||
|
||
describe("IrysService", () => { | ||
let irysService; | ||
let mockedRuntime; | ||
|
||
beforeEach(async () => { | ||
vi.clearAllMocks(); | ||
mockCacheManager.get.mockResolvedValue(null); | ||
|
||
mockedRuntime = { | ||
character: defaultCharacter, | ||
getSetting: vi.fn().mockImplementation((key: string) => { | ||
if (key === "EVM_WALLET_PRIVATE_KEY") // TEST PRIVATE KEY | ||
return "0xd6ed963c4eb8436b284f62636a621c164161ee25218b3be5ca4cad1261f8c390"; | ||
return undefined; | ||
}), | ||
}; | ||
irysService = new IrysService(); | ||
await irysService.initialize(mockedRuntime); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllTimers(); | ||
}); | ||
|
||
describe("Store String on Irys", () => { | ||
it("should store string on Irys", async () => { | ||
const result = await irysService.providerUploadDataOnIrys("Hello World", IrysDataType.OTHER, ["test"], ["test"]); | ||
expect(result.success).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest"; | ||
import { IrysService } from "../src/services/irysService"; | ||
import { defaultCharacter } from "@elizaos/core"; | ||
|
||
// Mock NodeCache | ||
vi.mock("node-cache", () => { | ||
return { | ||
default: vi.fn().mockImplementation(() => ({ | ||
set: vi.fn(), | ||
get: vi.fn().mockReturnValue(null), | ||
})), | ||
}; | ||
}); | ||
|
||
// Mock path module | ||
vi.mock("path", async () => { | ||
const actual = await vi.importActual("path"); | ||
return { | ||
...actual, | ||
join: vi.fn().mockImplementation((...args) => args.join("/")), | ||
}; | ||
}); | ||
|
||
// Mock the ICacheManager | ||
const mockCacheManager = { | ||
get: vi.fn().mockResolvedValue(null), | ||
set: vi.fn(), | ||
delete: vi.fn(), | ||
}; | ||
|
||
describe("IrysService", () => { | ||
let irysService; | ||
let mockedRuntime; | ||
|
||
beforeEach(async () => { | ||
vi.clearAllMocks(); | ||
mockCacheManager.get.mockResolvedValue(null); | ||
|
||
mockedRuntime = { | ||
character: defaultCharacter, | ||
getSetting: vi.fn().mockImplementation((key: string) => { | ||
if (key === "EVM_WALLET_PRIVATE_KEY") // TEST PRIVATE KEY | ||
return "0xd6ed963c4eb8436b284f62636a621c164161ee25218b3be5ca4cad1261f8c390"; | ||
return undefined; | ||
}), | ||
}; | ||
irysService = new IrysService(); | ||
await irysService.initialize(mockedRuntime); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllTimers(); | ||
}); | ||
|
||
describe("Initialize IrysService", () => { | ||
it("should initialize IrysService", async () => { | ||
expect(irysService).toBeDefined(); | ||
}); | ||
|
||
it("should initialize IrysUploader", async () => { | ||
const result = await irysService.initializeIrysUploader(); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest"; | ||
import { IrysService } from "../src/services/irysService"; | ||
import { defaultCharacter, IrysDataType, IrysMessageType } from "@elizaos/core"; | ||
|
||
// Mock NodeCache | ||
vi.mock("node-cache", () => { | ||
return { | ||
default: vi.fn().mockImplementation(() => ({ | ||
set: vi.fn(), | ||
get: vi.fn().mockReturnValue(null), | ||
})), | ||
}; | ||
}); | ||
|
||
// Mock path module | ||
vi.mock("path", async () => { | ||
const actual = await vi.importActual("path"); | ||
return { | ||
...actual, | ||
join: vi.fn().mockImplementation((...args) => args.join("/")), | ||
}; | ||
}); | ||
|
||
// Mock the ICacheManager | ||
const mockCacheManager = { | ||
get: vi.fn().mockResolvedValue(null), | ||
set: vi.fn(), | ||
delete: vi.fn(), | ||
}; | ||
|
||
describe("IrysService", () => { | ||
let irysService; | ||
let mockedRuntime; | ||
|
||
beforeEach(async () => { | ||
vi.clearAllMocks(); | ||
mockCacheManager.get.mockResolvedValue(null); | ||
|
||
mockedRuntime = { | ||
character: defaultCharacter, | ||
getSetting: vi.fn().mockImplementation((key: string) => { | ||
if (key === "EVM_WALLET_PRIVATE_KEY") // TEST PRIVATE KEY | ||
return "0xd6ed963c4eb8436b284f62636a621c164161ee25218b3be5ca4cad1261f8c390"; | ||
return undefined; | ||
}), | ||
}; | ||
irysService = new IrysService(); | ||
await irysService.initialize(mockedRuntime); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllTimers(); | ||
}); | ||
|
||
describe("Store String on Irys", () => { | ||
it("should store string on Irys", async () => { | ||
const result = await irysService.workerUploadDataOnIrys("Hello World", IrysDataType.OTHER, IrysMessageType.DATA_STORAGE, ["test"], ["test"]); | ||
expect(result.success).toBe(true); | ||
}); | ||
|
||
it("should retrieve data from Irys", async () => { | ||
const result = await irysService.getDataFromAnAgent(["0xb9dBf1966c9C6E4D93b4C61bbC4cDDb32900f4bE"], []); | ||
expect(result.success).toBe(true); | ||
expect(result.data.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it("should get a response from the orchestrator", async () => { | ||
const result = await irysService.workerUploadDataOnIrys("Hello World", IrysDataType.OTHER, IrysMessageType.REQUEST, ["test"], ["test"]); | ||
expect(result.success).toBe(true); | ||
expect(result.data.length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
}); | ||
|