Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/auth/challenge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 2 additions & 0 deletions test/auth/sign.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions test/auth/token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
84 changes: 84 additions & 0 deletions test/blockchain/account.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
46 changes: 46 additions & 0 deletions test/blockchain/addCosigner.test.js
Original file line number Diff line number Diff line change
@@ -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
);
});
});
40 changes: 40 additions & 0 deletions test/blockchain/createTrustline.test.js
Original file line number Diff line number Diff line change
@@ -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
);
});
});
4 changes: 4 additions & 0 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -14,6 +16,8 @@ describe("Client", () => {
});

test("...on public network", () => {
expect.assertions(1);

Network.usePublicNetwork();

const clientInstance = new Client();
Expand Down
4 changes: 4 additions & 0 deletions test/utils/keypair.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ describe("utils/keypair", () => {
});

it("returns true if transaction is correctly signed", () => {
expect.assertions(1);

const keypair = Keypair.random();
const tx = generateSignedTx(keypair);

expect(verify(tx, keypair)).toBe(true);
});

it("returns false if transaction is not correctly signed", () => {
expect.assertions(1);

const keypair = Keypair.random();
const anotherKeypair = Keypair.random();
const tx = generateSignedTx(keypair);
Expand Down