-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from cpp-phoenix/test/burner_tests
Burner vite tests
- Loading branch information
Showing
22 changed files
with
243 additions
and
41 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
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
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
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
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,69 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { BurnerConnector } from "../../src/connectors/burner"; | ||
import { getBurnerConnector } from "../mocks/mocks"; | ||
import { KATANA_PREFUNDED_ADDRESS } from "@dojoengine/core"; | ||
|
||
describe("BurnerConnector", () => { | ||
const burnerObj = new BurnerConnector({}, null); | ||
|
||
it("should test available method", async () => { | ||
expect(burnerObj.available()).toBe(true); | ||
}), | ||
it("should test ready method", async () => { | ||
expect(await burnerObj.ready()).toBe(true); | ||
expect(burnerObj.ready()).toBeTypeOf("object"); | ||
}), | ||
it("should test connect method", async () => { | ||
expect(() => burnerObj.connect()).rejects.toThrowError( | ||
"account not found" | ||
); | ||
}), | ||
it("should test disconnect method", async () => { | ||
expect(await burnerObj.disconnect()).toBeUndefined(); | ||
}), | ||
it("should test account method", async () => { | ||
expect(await burnerObj.account()).toBeNull(); | ||
}), | ||
it("should test id method", async () => { | ||
expect(burnerObj.id).toBe("Burner Account"); | ||
}), | ||
it("should test name method", async () => { | ||
expect(burnerObj.name).toBe("Burner Connector"); | ||
expect(burnerObj.name).toBeTypeOf("string"); | ||
}), | ||
it("should test icon method", async () => { | ||
expect(burnerObj.icon).toBe("my-icon-url"); | ||
}); | ||
}); | ||
|
||
describe("BurnerConnector2", () => { | ||
const burnerObj = getBurnerConnector(); | ||
|
||
it("should test available method", async () => { | ||
expect(burnerObj.available()).toBe(true); | ||
}), | ||
it("should test ready method", async () => { | ||
expect(await burnerObj.ready()).toBe(true); | ||
expect(burnerObj.ready()).toBeTypeOf("object"); | ||
}), | ||
it("should test connect method", async () => { | ||
expect(await burnerObj.connect()).toBeTypeOf("object"); | ||
}), | ||
it("should test disconnect method", async () => { | ||
expect(await burnerObj.disconnect()).toBeUndefined(); | ||
}), | ||
it("should test account method", async () => { | ||
expect(await burnerObj.account()).not.toBeNull(); | ||
}), | ||
it("should test id method", async () => { | ||
console.log(burnerObj.id); | ||
expect(burnerObj.id).toEqual(KATANA_PREFUNDED_ADDRESS); | ||
}), | ||
it("should test name method", async () => { | ||
expect(burnerObj.name).toBe("Burner Connector"); | ||
expect(burnerObj.name).toBeTypeOf("string"); | ||
}), | ||
it("should test icon method", async () => { | ||
expect(burnerObj.icon).toBe("my-icon-url"); | ||
}); | ||
}); |
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,10 @@ | ||
//@vitest-environment jsdom | ||
import { describe, it, expect } from "vitest"; | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import { useBurner } from "../../src/hooks/useBurner"; | ||
|
||
describe("useBurner", () => { | ||
it("testing", () => { | ||
const { result } = renderHook(() => useBurner()); | ||
}); | ||
}); |
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,40 @@ | ||
import { describe, it, afterEach, expect, vi } from "vitest"; | ||
import { getBurnerManager } from "../mocks/mocks"; | ||
|
||
describe("BurnerManager", () => { | ||
const burnerManager = getBurnerManager(); | ||
|
||
it("should init burner account", async () => { | ||
burnerManager.init(); | ||
}), | ||
it("should update isDeploying", async () => { | ||
burnerManager.updateIsDeploying(false); | ||
expect(burnerManager.isDeploying).toBeFalsy(); | ||
}), | ||
it("should list burner accounts", async () => { | ||
expect(burnerManager.list()).toStrictEqual([]); | ||
}), | ||
it("should select burner accounts", async () => { | ||
expect(() => burnerManager.select("test")).toThrowError( | ||
"burner not found" | ||
); | ||
}), | ||
it("should get burner accounts", async () => { | ||
expect(() => burnerManager.get("test")).toThrowError( | ||
"burner not found" | ||
); | ||
}), | ||
it("should create burner accounts", async () => { | ||
expect(burnerManager.create()).rejects.toThrowError(); | ||
}), | ||
it("should copy burner to clipboard", async () => { | ||
expect( | ||
burnerManager.copyBurnersToClipboard() | ||
).rejects.toThrowError(); | ||
}), | ||
it("should set burner from clipboard", async () => { | ||
expect( | ||
burnerManager.setBurnersFromClipboard() | ||
).rejects.toThrowError(); | ||
}); | ||
}); |
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,34 @@ | ||
import { BurnerManager } from "../../src/manager/burnerManager"; | ||
import { Account, RpcProvider } from "starknet"; | ||
import { BurnerConnector } from "../../src/connectors/burner"; | ||
import { | ||
KATANA_PREFUNDED_ADDRESS, | ||
KATANA_PREFUNDED_PRIVATE_KEY, | ||
LOCAL_KATANA, | ||
} from "@dojoengine/core"; | ||
|
||
export const getBurnerManager = (): BurnerManager => { | ||
const burnerManager = new BurnerManager({ | ||
masterAccount: new Account( | ||
new RpcProvider({ nodeUrl: LOCAL_KATANA }), | ||
KATANA_PREFUNDED_ADDRESS, | ||
KATANA_PREFUNDED_PRIVATE_KEY | ||
), | ||
accountClassHash: KATANA_PREFUNDED_PRIVATE_KEY, | ||
rpcProvider: new RpcProvider({ nodeUrl: LOCAL_KATANA }), | ||
}); | ||
return burnerManager; | ||
}; | ||
|
||
export const getBurnerConnector = (): BurnerConnector => { | ||
const publicKey = KATANA_PREFUNDED_ADDRESS; | ||
const burnerObj = new BurnerConnector( | ||
{}, | ||
new Account( | ||
new RpcProvider({ nodeUrl: LOCAL_KATANA }), | ||
publicKey, | ||
KATANA_PREFUNDED_PRIVATE_KEY | ||
) | ||
); | ||
return burnerObj; | ||
}; |
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,40 @@ | ||
import { describe, it, expect, vi } from "vitest"; | ||
import Storage from "../../src/utils/storage"; | ||
import Cookies from "js-cookie"; | ||
import { BurnerStorage } from "../../src/types"; | ||
import { | ||
KATANA_PREFUNDED_ADDRESS, | ||
KATANA_PREFUNDED_PRIVATE_KEY, | ||
KATANA_CLASS_HASH, | ||
KATANA_ETH_CONTRACT_ADDRESS, | ||
} from "@dojoengine/core"; | ||
|
||
vi.mock("js-cookie"); | ||
|
||
describe("storage", () => { | ||
it("should return null", async () => { | ||
Cookies.get = vi.fn().mockReturnValue({}); | ||
expect(Storage.keys()).toStrictEqual([]); | ||
}), | ||
it("should return a json", async () => { | ||
const storageObj: BurnerStorage = { | ||
KATANA_ETH_CONTRACT_ADDRESS: { | ||
privateKey: KATANA_PREFUNDED_PRIVATE_KEY, | ||
publicKey: KATANA_PREFUNDED_ADDRESS, | ||
deployTx: KATANA_CLASS_HASH, | ||
active: true, | ||
}, | ||
}; | ||
Cookies.get = vi.fn().mockReturnValue(JSON.stringify(storageObj)); | ||
expect(Storage.get("test")).toStrictEqual(storageObj); | ||
}), | ||
it("should set successfully", async () => { | ||
Storage.set("test", 10); | ||
}), | ||
it("should remove key", async () => { | ||
Storage.remove("test"); | ||
}), | ||
it("should clear all", async () => { | ||
Storage.clear(); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.