From d5553823bc16db4cb4e9e164ae4525464eb367d2 Mon Sep 17 00:00:00 2001 From: brunoedcf Date: Thu, 26 Jan 2023 12:23:06 -0300 Subject: [PATCH 1/3] first blockchain functions tests - addresses.ts type testing --- src/blockchain/__tests__/addresses.spec.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/blockchain/__tests__/addresses.spec.ts diff --git a/src/blockchain/__tests__/addresses.spec.ts b/src/blockchain/__tests__/addresses.spec.ts new file mode 100644 index 0000000..0734f7a --- /dev/null +++ b/src/blockchain/__tests__/addresses.spec.ts @@ -0,0 +1,21 @@ +import { assertType, expectTypeOf } from 'vitest' +import { + getTokenAddress, + getP2PixAddress, + getProviderUrl, + isPossibleNetwork, + possibleChains, + network2Chain, +} from '../addresses' + +test("My addresses.ts types work properly", () =>{ + + expectTypeOf(getTokenAddress).toBeFunction() + expectTypeOf(getP2PixAddress).toBeFunction() + expectTypeOf(getProviderUrl).toBeFunction() + expectTypeOf(isPossibleNetwork).toBeFunction() + + expectTypeOf(possibleChains).toBeObject() + expectTypeOf(network2Chain).toBeObject() + +}) \ No newline at end of file From 588b513a0bb1e6385b0fce65a671d8a74cac8899 Mon Sep 17 00:00:00 2001 From: brunoedcf Date: Fri, 27 Jan 2023 14:23:45 -0300 Subject: [PATCH 2/3] addresses.ts function testing --- src/blockchain/__tests__/addresses.spec.ts | 102 +++++++++++++++++++-- src/blockchain/addresses.ts | 2 +- 2 files changed, 94 insertions(+), 10 deletions(-) diff --git a/src/blockchain/__tests__/addresses.spec.ts b/src/blockchain/__tests__/addresses.spec.ts index 0734f7a..645756e 100644 --- a/src/blockchain/__tests__/addresses.spec.ts +++ b/src/blockchain/__tests__/addresses.spec.ts @@ -1,4 +1,4 @@ -import { assertType, expectTypeOf } from 'vitest' +import { expectTypeOf, it, expect, vi } from 'vitest' import { getTokenAddress, getP2PixAddress, @@ -8,14 +8,98 @@ import { network2Chain, } from '../addresses' -test("My addresses.ts types work properly", () =>{ +import { setActivePinia, createPinia } from 'pinia' +import { NetworkEnum } from "@/model/NetworkEnum"; +import { useEtherStore } from "@/store/ether"; - expectTypeOf(getTokenAddress).toBeFunction() - expectTypeOf(getP2PixAddress).toBeFunction() - expectTypeOf(getProviderUrl).toBeFunction() - expectTypeOf(isPossibleNetwork).toBeFunction() +describe("addresses.ts types", () => { - expectTypeOf(possibleChains).toBeObject() - expectTypeOf(network2Chain).toBeObject() + it("My addresses.ts types work properly", () =>{ + + expectTypeOf(getTokenAddress).toBeFunction() + expectTypeOf(getP2PixAddress).toBeFunction() + expectTypeOf(getProviderUrl).toBeFunction() + expectTypeOf(isPossibleNetwork).toBeFunction() + + expectTypeOf(possibleChains).toBeObject() + expectTypeOf(network2Chain).toBeObject() + + }) + +}) + +describe("addresses.ts functions", () => { + + beforeEach(() => { + setActivePinia(createPinia()) + }) + + it('getTokenAddress Ethereum', () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.ethereum) + expect(getTokenAddress()).toBe("0x294003F602c321627152c6b7DED3EAb5bEa853Ee") + }) + + it('getTokenAddress Polygon', () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.polygon) + expect(getTokenAddress()).toBe("0x294003F602c321627152c6b7DED3EAb5bEa853Ee") + }) + + it('getTokenAddress Default', () => { + expect(getTokenAddress()).toBe("0x294003F602c321627152c6b7DED3EAb5bEa853Ee") + }) + + it('getP2PixAddress Ethereum', () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.ethereum) + expect(getP2PixAddress()).toBe("0x5f3EFA9A90532914545CEf527C530658af87e196") + }) + + it('getP2PixAddress Polygon', () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.polygon) + expect(getP2PixAddress()).toBe("0x5f3EFA9A90532914545CEf527C530658af87e196") + }) + + it('getP2PixAddress Default', () => { + expect(getP2PixAddress()).toBe("0x5f3EFA9A90532914545CEf527C530658af87e196") + }) + + it('getProviderUrl Ethereum', () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.ethereum) + expect(getProviderUrl()).toBe(import.meta.env.VITE_GOERLI_API_URL) + }) + + it('getProviderUrl Polygon', () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.polygon) + expect(getProviderUrl()).toBe(import.meta.env.VITE_MUMBAI_API_URL) + }) + + it('getProviderUrl Default', () => { + expect(getProviderUrl()).toBe(import.meta.env.VITE_GOERLI_API_URL) + }) + + it('isPossibleNetwork Returns', () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.ethereum) + expect(isPossibleNetwork("0x5")).toBe(true) + expect(isPossibleNetwork("5")).toBe(true) + expect(isPossibleNetwork("0x13881")).toBe(true) + expect(isPossibleNetwork("80001")).toBe(true) + + expect(isPossibleNetwork("")).toBe(false) + expect(isPossibleNetwork(" ")).toBe(false) + expect(isPossibleNetwork("0x55")).toBe(false) + }) + +}) + +describe("addresses.ts Unset Store", () => { + it('getProviderUrl Unset', () => { + expect(getProviderUrl()).toBe(undefined) + }) +}) -}) \ No newline at end of file diff --git a/src/blockchain/addresses.ts b/src/blockchain/addresses.ts index 8fc74fe..887a8a6 100644 --- a/src/blockchain/addresses.ts +++ b/src/blockchain/addresses.ts @@ -30,7 +30,7 @@ const getProviderUrl = (): string => { Ethereum: import.meta.env.VITE_GOERLI_API_URL, Polygon: import.meta.env.VITE_MUMBAI_API_URL, }; - + return possibleProvidersUrls[etherStore.networkName]; }; From 16aa47061ed8b6e73454c9c86f7cf75651ce4a26 Mon Sep 17 00:00:00 2001 From: brunoedcf Date: Fri, 27 Jan 2023 21:08:32 -0300 Subject: [PATCH 3/3] fixing lint --- src/blockchain/__tests__/addresses.spec.ts | 171 +++++++++++---------- src/blockchain/addresses.ts | 2 +- 2 files changed, 89 insertions(+), 84 deletions(-) diff --git a/src/blockchain/__tests__/addresses.spec.ts b/src/blockchain/__tests__/addresses.spec.ts index 645756e..8bb306c 100644 --- a/src/blockchain/__tests__/addresses.spec.ts +++ b/src/blockchain/__tests__/addresses.spec.ts @@ -1,105 +1,110 @@ -import { expectTypeOf, it, expect, vi } from 'vitest' +import { expectTypeOf, it, expect } from "vitest"; import { - getTokenAddress, - getP2PixAddress, - getProviderUrl, - isPossibleNetwork, - possibleChains, - network2Chain, -} from '../addresses' + getTokenAddress, + getP2PixAddress, + getProviderUrl, + isPossibleNetwork, + possibleChains, + network2Chain, +} from "../addresses"; -import { setActivePinia, createPinia } from 'pinia' +import { setActivePinia, createPinia } from "pinia"; import { NetworkEnum } from "@/model/NetworkEnum"; import { useEtherStore } from "@/store/ether"; describe("addresses.ts types", () => { + it("My addresses.ts types work properly", () => { + expectTypeOf(getTokenAddress).toBeFunction(); + expectTypeOf(getP2PixAddress).toBeFunction(); + expectTypeOf(getProviderUrl).toBeFunction(); + expectTypeOf(isPossibleNetwork).toBeFunction(); - it("My addresses.ts types work properly", () =>{ - - expectTypeOf(getTokenAddress).toBeFunction() - expectTypeOf(getP2PixAddress).toBeFunction() - expectTypeOf(getProviderUrl).toBeFunction() - expectTypeOf(isPossibleNetwork).toBeFunction() - - expectTypeOf(possibleChains).toBeObject() - expectTypeOf(network2Chain).toBeObject() - - }) - -}) + expectTypeOf(possibleChains).toBeObject(); + expectTypeOf(network2Chain).toBeObject(); + }); +}); describe("addresses.ts functions", () => { + beforeEach(() => { + setActivePinia(createPinia()); + }); - beforeEach(() => { - setActivePinia(createPinia()) - }) + it("getTokenAddress Ethereum", () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.ethereum); + expect(getTokenAddress()).toBe( + "0x294003F602c321627152c6b7DED3EAb5bEa853Ee" + ); + }); - it('getTokenAddress Ethereum', () => { - const etherStore = useEtherStore(); - etherStore.setNetworkName(NetworkEnum.ethereum) - expect(getTokenAddress()).toBe("0x294003F602c321627152c6b7DED3EAb5bEa853Ee") - }) + it("getTokenAddress Polygon", () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.polygon); + expect(getTokenAddress()).toBe( + "0x294003F602c321627152c6b7DED3EAb5bEa853Ee" + ); + }); - it('getTokenAddress Polygon', () => { - const etherStore = useEtherStore(); - etherStore.setNetworkName(NetworkEnum.polygon) - expect(getTokenAddress()).toBe("0x294003F602c321627152c6b7DED3EAb5bEa853Ee") - }) + it("getTokenAddress Default", () => { + expect(getTokenAddress()).toBe( + "0x294003F602c321627152c6b7DED3EAb5bEa853Ee" + ); + }); - it('getTokenAddress Default', () => { - expect(getTokenAddress()).toBe("0x294003F602c321627152c6b7DED3EAb5bEa853Ee") - }) + it("getP2PixAddress Ethereum", () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.ethereum); + expect(getP2PixAddress()).toBe( + "0x5f3EFA9A90532914545CEf527C530658af87e196" + ); + }); - it('getP2PixAddress Ethereum', () => { - const etherStore = useEtherStore(); - etherStore.setNetworkName(NetworkEnum.ethereum) - expect(getP2PixAddress()).toBe("0x5f3EFA9A90532914545CEf527C530658af87e196") - }) + it("getP2PixAddress Polygon", () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.polygon); + expect(getP2PixAddress()).toBe( + "0x5f3EFA9A90532914545CEf527C530658af87e196" + ); + }); - it('getP2PixAddress Polygon', () => { - const etherStore = useEtherStore(); - etherStore.setNetworkName(NetworkEnum.polygon) - expect(getP2PixAddress()).toBe("0x5f3EFA9A90532914545CEf527C530658af87e196") - }) + it("getP2PixAddress Default", () => { + expect(getP2PixAddress()).toBe( + "0x5f3EFA9A90532914545CEf527C530658af87e196" + ); + }); - it('getP2PixAddress Default', () => { - expect(getP2PixAddress()).toBe("0x5f3EFA9A90532914545CEf527C530658af87e196") - }) + it("getProviderUrl Ethereum", () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.ethereum); + expect(getProviderUrl()).toBe(import.meta.env.VITE_GOERLI_API_URL); + }); - it('getProviderUrl Ethereum', () => { - const etherStore = useEtherStore(); - etherStore.setNetworkName(NetworkEnum.ethereum) - expect(getProviderUrl()).toBe(import.meta.env.VITE_GOERLI_API_URL) - }) + it("getProviderUrl Polygon", () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.polygon); + expect(getProviderUrl()).toBe(import.meta.env.VITE_MUMBAI_API_URL); + }); - it('getProviderUrl Polygon', () => { - const etherStore = useEtherStore(); - etherStore.setNetworkName(NetworkEnum.polygon) - expect(getProviderUrl()).toBe(import.meta.env.VITE_MUMBAI_API_URL) - }) + it("getProviderUrl Default", () => { + expect(getProviderUrl()).toBe(import.meta.env.VITE_GOERLI_API_URL); + }); - it('getProviderUrl Default', () => { - expect(getProviderUrl()).toBe(import.meta.env.VITE_GOERLI_API_URL) - }) + it("isPossibleNetwork Returns", () => { + const etherStore = useEtherStore(); + etherStore.setNetworkName(NetworkEnum.ethereum); + expect(isPossibleNetwork("0x5")).toBe(true); + expect(isPossibleNetwork("5")).toBe(true); + expect(isPossibleNetwork("0x13881")).toBe(true); + expect(isPossibleNetwork("80001")).toBe(true); - it('isPossibleNetwork Returns', () => { - const etherStore = useEtherStore(); - etherStore.setNetworkName(NetworkEnum.ethereum) - expect(isPossibleNetwork("0x5")).toBe(true) - expect(isPossibleNetwork("5")).toBe(true) - expect(isPossibleNetwork("0x13881")).toBe(true) - expect(isPossibleNetwork("80001")).toBe(true) - - expect(isPossibleNetwork("")).toBe(false) - expect(isPossibleNetwork(" ")).toBe(false) - expect(isPossibleNetwork("0x55")).toBe(false) - }) - -}) + expect(isPossibleNetwork("")).toBe(false); + expect(isPossibleNetwork(" ")).toBe(false); + expect(isPossibleNetwork("0x55")).toBe(false); + }); +}); describe("addresses.ts Unset Store", () => { - it('getProviderUrl Unset', () => { - expect(getProviderUrl()).toBe(undefined) - }) -}) - + it("getProviderUrl Unset", () => { + expect(getProviderUrl()).toBe(undefined); + }); +}); diff --git a/src/blockchain/addresses.ts b/src/blockchain/addresses.ts index 887a8a6..8fc74fe 100644 --- a/src/blockchain/addresses.ts +++ b/src/blockchain/addresses.ts @@ -30,7 +30,7 @@ const getProviderUrl = (): string => { Ethereum: import.meta.env.VITE_GOERLI_API_URL, Polygon: import.meta.env.VITE_MUMBAI_API_URL, }; - + return possibleProvidersUrls[etherStore.networkName]; };