diff --git a/test/auth/challenge.test.js b/test/auth/challenge.test.js index b34eda9..39459bb 100644 --- a/test/auth/challenge.test.js +++ b/test/auth/challenge.test.js @@ -16,18 +16,26 @@ describe("Auth.Challenge", () => { }); it("signs challenge correctly by developer", () => { + expect.assertions(1); + expect(verify(tx, keypair)).toBe(true); }); it("contains memo", () => { + expect.assertions(1); + expect(tx.memo.value).toMatch(/Mobius authentication/); }); it("contains time bounds", () => { + expect.assertions(1); + expect(tx.timeBounds).not.toBeUndefined(); }); it("contains correct minimum bound", () => { + expect.assertions(1); + const timeNow = Math.floor(new Date().getTime() / 1000).toString(); expect(tx.timeBounds.minTime).toEqual(timeNow); }); diff --git a/test/auth/sign.test.js b/test/auth/sign.test.js index 0f8b172..a5e7d34 100644 --- a/test/auth/sign.test.js +++ b/test/auth/sign.test.js @@ -23,6 +23,8 @@ describe("Auth.Sign", () => { }); it("signs challenge correctly by user", () => { + expect.assertions(1); + const tx = generateSignedChallengeTx(userKeypair, developerKeypair); expect(verify(new Transaction(tx), userKeypair)).toBe(true); diff --git a/test/auth/token.test.js b/test/auth/token.test.js index 47c4058..06f089a 100644 --- a/test/auth/token.test.js +++ b/test/auth/token.test.js @@ -24,6 +24,8 @@ describe("Auth.Token", () => { }); it(".validate() returns true if current time is within bounds", () => { + expect.assertions(1); + freeze(new Date()); const tx = generateSignedChallengeTx(userKeypair, developerKeypair); @@ -37,6 +39,8 @@ describe("Auth.Token", () => { }); it(".validate() throws error if current time is outside bounds", () => { + expect.assertions(1); + const tx = generateSignedChallengeTx(userKeypair, developerKeypair); const token = new Token( developerKeypair.secret(), @@ -51,6 +55,8 @@ describe("Auth.Token", () => { }); it("returns transaction hash", () => { + expect.assertions(1); + const tx = generateSignedChallengeTx(userKeypair, developerKeypair); const token = new Token( developerKeypair.secret(), diff --git a/test/blockchain/account.test.js b/test/blockchain/account.test.js new file mode 100644 index 0000000..88e0f96 --- /dev/null +++ b/test/blockchain/account.test.js @@ -0,0 +1,84 @@ +import { Keypair, Network } from "stellar-sdk"; +import AccountBuilder from "../../src/blockhain/accountBuilder"; + +describe("AccountBuilder", () => { + beforeAll(() => { + Network.useTestNetwork(); + }); + + describe("when account is missing", () => { + const keypair = Keypair.fromSecret( + "SDSZGWR22BNISMXUXBYOKRWVAFYIQA4SX2MZLAF6MB5OHOPGES7GBPCV" + ); + + it("fails", () => { + expect.assertions(1); + + return expect(AccountBuilder.build(keypair)).rejects.toThrow(); + }); + }); + + describe("when account has not trustline & authorization", () => { + const keypair = Keypair.fromSecret( + "SA2VTRSZPZ5FICNHEUISJVAZNE5IGKUTXFZX6ISHX3JAI4QD7LBWUUIK" + ); + + test(".trustlineExists() should eq false", async () => { + expect.assertions(1); + + const account = await AccountBuilder.build(keypair); + + expect(account.trustlineExists()).toBeFalsy(); + }); + + test(".balance() should eq null", async () => { + expect.assertions(1); + + const account = await AccountBuilder.build(keypair); + + expect(account.balance()).toBeFalsy(); + }); + + test(".authorized() should eq false", async () => { + expect.assertions(1); + + const otherKeypair = Keypair.random(); + + const account = await AccountBuilder.build(keypair); + + expect(account.authorized(otherKeypair)).toBeFalsy(); + }); + }); + + describe("when account has trustline & authorization", () => { + const keypair = Keypair.fromSecret( + "SAAR4WYBEMS3HWZROEGJDDSMINYOK6PLSDX5AYEPO5AIVXWRFY2M6SBK" + ); + + test(".trustlineExists() should eq true", async () => { + expect.assertions(1); + + const account = await AccountBuilder.build(keypair); + + expect(account.trustlineExists()).toBeTruthy(); + }); + + test(".balance() should eq 1000", async () => { + expect.assertions(1); + + const account = await AccountBuilder.build(keypair); + + expect(account.balance()).toBe(1000); + }); + + test(".authorized() should eq true", async () => { + expect.assertions(1); + + const otherKeypair = keypair; + + const account = await AccountBuilder.build(keypair); + + expect(account.authorized(otherKeypair)).toBeTruthy(); + }); + }); +}); diff --git a/test/blockchain/addCosigner.test.js b/test/blockchain/addCosigner.test.js new file mode 100644 index 0000000..ea00ca9 --- /dev/null +++ b/test/blockchain/addCosigner.test.js @@ -0,0 +1,46 @@ +import { Keypair, Network } from "stellar-sdk"; +import AddCosigner from "../../src/blockhain/addCosigner"; + +describe("AddCosigner", () => { + const cosignerKeypair = Keypair.random(); + + beforeAll(() => { + Network.useTestNetwork(); + }); + + describe("when account is missing", () => { + const keypair = Keypair.fromSecret( + "SDSZGWR22BNISMXUXBYOKRWVAFYIQA4SX2MZLAF6MB5OHOPGES7GBPCV" + ); + + it( + "fails", + () => { + expect.assertions(1); + + return expect( + AddCosigner.call(keypair, cosignerKeypair) + ).rejects.toThrow(); + }, + 10000 + ); + }); + + describe("when account is present", () => { + const keypair = Keypair.fromSecret( + "SDWISE5L2DNVGOFQJ2ZI5FNXMSMU7NVIB3Q62X7RMFMFYQZSFHZJE3TN" + ); + + it( + "succeed", + () => { + expect.assertions(1); + + return expect( + AddCosigner.call(keypair, cosignerKeypair) + ).resolves.toBeDefined(); + }, + 10000 + ); + }); +}); diff --git a/test/blockchain/createTrustline.test.js b/test/blockchain/createTrustline.test.js new file mode 100644 index 0000000..ede6e26 --- /dev/null +++ b/test/blockchain/createTrustline.test.js @@ -0,0 +1,40 @@ +import { Keypair, Network } from "stellar-sdk"; +import CreateTrustline from "../../src/blockhain/createTrustline"; + +describe("CreateTrustline", () => { + beforeAll(() => { + Network.useTestNetwork(); + }); + + describe("when account is missing", () => { + const keypair = Keypair.fromSecret( + "SDSZGWR22BNISMXUXBYOKRWVAFYIQA4SX2MZLAF6MB5OHOPGES7GBPCV" + ); + + it( + "fails", + () => { + expect.assertions(1); + + return expect(CreateTrustline.call(keypair)).rejects.toThrow(); + }, + 10000 + ); + }); + + describe("when account is present", () => { + const keypair = Keypair.fromSecret( + "SDWISE5L2DNVGOFQJ2ZI5FNXMSMU7NVIB3Q62X7RMFMFYQZSFHZJE3TN" + ); + + it( + "succeed", + () => { + expect.assertions(1); + + return expect(CreateTrustline.call(keypair)).resolves.toBeDefined(); + }, + 10000 + ); + }); +}); diff --git a/test/client.test.js b/test/client.test.js index a71f67b..3d46a96 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -4,6 +4,8 @@ import Client from "../src/client"; describe("Client", () => { describe("should respect global Network config...", () => { test("...on test network", () => { + expect.assertions(1); + Network.useTestNetwork(); const clientInstance = new Client(); @@ -14,6 +16,8 @@ describe("Client", () => { }); test("...on public network", () => { + expect.assertions(1); + Network.usePublicNetwork(); const clientInstance = new Client(); diff --git a/test/utils/keypair.test.js b/test/utils/keypair.test.js index 6346a16..ea61002 100644 --- a/test/utils/keypair.test.js +++ b/test/utils/keypair.test.js @@ -36,6 +36,8 @@ describe("utils/keypair", () => { }); it("returns true if transaction is correctly signed", () => { + expect.assertions(1); + const keypair = Keypair.random(); const tx = generateSignedTx(keypair); @@ -43,6 +45,8 @@ describe("utils/keypair", () => { }); it("returns false if transaction is not correctly signed", () => { + expect.assertions(1); + const keypair = Keypair.random(); const anotherKeypair = Keypair.random(); const tx = generateSignedTx(keypair);