Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DonFungible committed Jan 5, 2024
1 parent 36f2f19 commit 092bfac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 61 deletions.
8 changes: 5 additions & 3 deletions packages/core-sdk/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ export function paramsTagValueDecoder(paramTag: Hex, paramValue: unknown) {

export function chainStringToViemChain(chainId: SupportedChainIds): Chain {
switch (chainId) {
case "1" || "mainnet":
case "1":
case "mainnet":
return mainnet;
case "11155111" || "sepolia":
case "11155111":
case "sepolia":
return sepolia;
default:
throw new Error(`chainId ${chainId} not supported`);
throw new Error(`chainId ${chainId as string} not supported`);
}
}
22 changes: 9 additions & 13 deletions packages/core-sdk/test/unit/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ import { Account } from "viem";

describe("Test StoryClient", function () {
describe("Test constructor", function () {
it("should succeed when passing in valid params", function () {
try {
StoryClient.newClient({
account: privateKeyToAccount(generatePrivateKey()),
});
} catch (error) {
expect.fail(`Function should not have thrown any error, but it threw: ${error}`);
}
it("should succeed when passing in default params", function () {
const client = StoryClient.newClient({
account: privateKeyToAccount(generatePrivateKey()),
});
expect(client).to.be.instanceOf(StoryClient);
});

it("throw error when wallet account is null", function () {
try {
StoryClient.newClient({
it("should throw error when wallet account is null", function () {
expect(() => {
const client = StoryClient.newClient({
account: null as any as Account,
});
expect.fail(`Function should not get here, it should throw an error `);
} catch (error) {}
}).to.throw("account is null");
});
});

Expand Down
70 changes: 25 additions & 45 deletions packages/core-sdk/test/unit/clientReadOnly.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import { expect } from "chai";
import { StoryClient, ReadOnlyClient } from "../../src";
import { fantom } from "viem/chains";
import { http } from "viem";

describe("Test StoryReadOnlyClient", function () {
describe("Test constructor", function () {
it("should succeed when passing in valid params", function () {
try {
StoryClient.newReadOnlyClient({});
} catch (error) {
expect.fail(`Function should not have thrown any error, but it threw: ${error}`);
}
it("should succeed when passing in default params", function () {
const client = StoryClient.newReadOnlyClient({});
expect(client).to.be.instanceOf(StoryClient);
});
it("should succeed when passing in chainId = '1' ", function () {
const client = StoryClient.newReadOnlyClient({ chainId: "1" });
expect(client).to.be.instanceOf(StoryClient);
});
it("should succeed when passing in chainId = 'mainnet' ", function () {
const client = StoryClient.newReadOnlyClient({ chainId: "mainnet" });
expect(client).to.be.instanceOf(StoryClient);
});
it("should succeed when passing in chainId = '11155111' ", function () {
const client = StoryClient.newReadOnlyClient({ chainId: "11155111" });
expect(client).to.be.instanceOf(StoryClient);
});
it("should succeed when passing in chainId = 'sepolia' ", function () {
const client = StoryClient.newReadOnlyClient({ chainId: "sepolia" });
expect(client).to.be.instanceOf(StoryClient);
});

it("should succeed when passing in valid params w/ provider", function () {
try {
it("should fail when passing in unsupported chain ID", function () {
expect(() =>
StoryClient.newReadOnlyClient({
chain: fantom,
//@ts-ignore
chainId: "fantom",
transport: http(process.env.RPC_PROVIDER_URL),
});
} catch (error) {
expect.fail(`Function should not have thrown any error, but it threw: ${error}`);
}
}),
).to.throw(`chainId fantom not supported`);
});
});

Expand Down Expand Up @@ -80,35 +91,4 @@ describe("Test StoryReadOnlyClient", function () {
});
});
});

// describe("Test getters w/ provider", function () {
// let client: ReadOnlyClient;

// beforeEach(function () {
// client = StoryClient.newReadOnlyClient({
// environment: Environment.TEST,
// provider: new providers.JsonRpcProvider(),
// });
// });

// describe("Test franchise getter w/ provider", function () {
// it("should return the same franchise when every time it's called", function () {
// const franchise1 = client.franchise;
// const franchise2 = client.franchise;
// expect(franchise1).to.be.equal(franchise2);
// });
// });
// });

// describe("Test franchise getter w/o creating a client", function () {
// let client: ReadOnlyClient;

// it("should throw error when a client hasn't been created", function () {
// try {
// client.franchise;

// expect.fail(`You haven't created a client yet.`);
// } catch (error) {}
// });
// });
});

0 comments on commit 092bfac

Please sign in to comment.