Skip to content

Commit

Permalink
Merge pull request #128 from cpp-phoenix/test/burner_tests
Browse files Browse the repository at this point in the history
Burner vite tests
  • Loading branch information
ponderingdemocritus authored Feb 7, 2024
2 parents 6963cbc + 1c7e10a commit c152a0a
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
- name: Build dependencies
run: bun run build && bun run build-examples

- name: Run tests
run: bun vitest

# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v3
# env:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions examples/node/torii-bot/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"rootDir": "/Users/os/Documents/code/dojo.js/examples",
"allowJs": true,
"outDir": "dist",
"types": ["bun-types"],
"types": ["bun-types"]
},
"include": [
"./src/**/*",
"dojoConfig.ts",
"../../dojo-starter/target/dev/manifest.json",
"../../dojo-starter/target/dev/manifest.json"
],
"exclude": ["examples/dojo-starter/target/dev/manifest.json"],
"exclude": ["examples/dojo-starter/target/dev/manifest.json"]
}
8 changes: 4 additions & 4 deletions examples/react/react-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// "noUnusedLocals": true,
// "noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"allowSyntheticDefaultImports": true
},
"include": ["src", "dojoConfig.ts"],
"references": [
{
"path": "./tsconfig.node.json",
},
],
"path": "./tsconfig.node.json"
}
]
}
10 changes: 5 additions & 5 deletions examples/react/react-phaser-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
// "noUnusedLocals": true,
// "noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/*": ["./src/*"]
},
"references": [
{
"path": "./tsconfig.node.json",
},
],
"path": "./tsconfig.node.json"
}
]
}
10 changes: 5 additions & 5 deletions examples/react/react-threejs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
},
"@/*": ["./src/*"]
}
},
"include": ["src", "dojoConfig.ts"],
"references": [
{
"path": "./tsconfig.node.json",
},
],
"path": "./tsconfig.node.json"
}
]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"build-watch": "bun run build-core --watch & bun run build-create-burner --watch & bun run build-create-dojo --watch & bun run build-utils --watch & bun run build-react --watch & bun run build-torii-wasm --watch & bun run build-torii-client --watch & bun run build-state --watch",
"build": "bun run build-torii-wasm && bun run build-utils-wasm && bun run build-torii-client && bun run build-state && bun run build-core && bun run build-create-burner && bun run build-create-dojo && bun run build-utils && bun run build-react",
"build-examples": "bun run build-phaser && bun run build-react-app",
"test-create-burner": "bun --cwd packages/create-burner vitest",
"test-core": "bun --cwd packages/core vitest",
"clean": "rm -rf node_modules packages/create-burner/node_modules node_modules packages/create-dojo/node_modules packages/core/node_modules packages/utils/node_modules packages/torii-client/node_modules packages/torii-wasm/node_modules packages/react/node_modules bun.lockb packages/create-burner/bun.lockb packages/core/bun.lockb packages/utils/bun.lockb packages/torii-client/bun.lockb packages/torii-wasm/bun.lockb packages/react/bun.lockb && rm -rf examples/react/react-app/node_modules examples/react/react-app/bun.lockb examples/react/react-phaser-example/node_modules examples/react/react-phaser-example/bun.lockb",
"prettier-check": "bun x prettier --check .",
"prettier": "bun x prettier --write .",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"strict": true,
"strictNullChecks": true,
"types": ["bun-types"],
"esModuleInterop": true,
"esModuleInterop": true
},
"include": ["src/**/*.ts", "bin/generateComponents.cjs"],
"skipLibCheck": true,
"exclude": ["node_modules", "dist", "**/*.test.ts"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
8 changes: 6 additions & 2 deletions packages/create-burner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "module",
"scripts": {
"build": "tsup --dts-resolve",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "vitest"
},
"peerDependencies": {
"react": "^18.2.0",
Expand All @@ -24,14 +24,18 @@
"devDependencies": {
"@babel/core": "^7.21.4",
"@babel/preset-env": "^7.21.4",
"@testing-library/react": "^14.1.2",
"@testing-library/react-hooks": "^8.0.1",
"@types/js-cookie": "^3.0.3",
"@types/node": "^18.15.11",
"@types/react": "^18.2.33",
"@types/react-dom": "^18.0.11",
"@types/web": "^0.0.114",
"bun-types": "^1.0.1",
"jsdom": "^24.0.0",
"tsup": "^8.0.1",
"typescript": "^5.0.3"
"typescript": "^5.0.3",
"vitest": "^1.2.2"
},
"dependencies": {
"@dojoengine/core": "^0.5.6",
Expand Down
69 changes: 69 additions & 0 deletions packages/create-burner/test/connectors/burner.test.ts
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");
});
});
10 changes: 10 additions & 0 deletions packages/create-burner/test/hooks/useBurner.test.ts
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());
});
});
40 changes: 40 additions & 0 deletions packages/create-burner/test/manager/burnerManager.test.ts
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();
});
});
34 changes: 34 additions & 0 deletions packages/create-burner/test/mocks/mocks.ts
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;
};
40 changes: 40 additions & 0 deletions packages/create-burner/test/utils/storage.test.ts
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();
});
});
8 changes: 4 additions & 4 deletions packages/create-burner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"baseUrl": ".",
"rootDir": "src",
"paths": {
"~/*": ["src/*"],
},
"~/*": ["src/*"]
}
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist", "**/*.test.ts"],
"include": ["src/**/*.ts", "test/**/*.ts"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
6 changes: 3 additions & 3 deletions packages/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"baseUrl": ".",
"rootDir": "src",
"paths": {
"~/*": ["src/*"],
},
"~/*": ["src/*"]
}
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist", "**/*.test.ts"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
4 changes: 2 additions & 2 deletions packages/state/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"strict": true,
"strictNullChecks": true,
"types": ["bun-types"],
"esModuleInterop": true,
"esModuleInterop": true
},
"include": ["src/**/*.ts"],
"skipLibCheck": true,
"exclude": ["node_modules", "dist", "**/*.test.ts"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
4 changes: 2 additions & 2 deletions packages/torii-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"strict": true,
"strictNullChecks": true,
"types": ["bun-types"],
"esModuleInterop": true,
"esModuleInterop": true
},
"include": ["src/**/*.ts"],
"skipLibCheck": true,
"exclude": ["node_modules", "dist", "**/*.test.ts"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
4 changes: 2 additions & 2 deletions packages/torii-wasm/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"strict": true,
"strictNullChecks": true,
"types": ["bun-types"],
"esModuleInterop": true,
"esModuleInterop": true
},
"skipLibCheck": true,
"exclude": ["node_modules", "dist", "**/*.test.ts"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
}
Loading

0 comments on commit c152a0a

Please sign in to comment.