assert#equal TypeScript Examples

The following examples show how to use assert#equal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ARQL.test.ts    From SolarweaveBridge with MIT License 6 votes vote down vote up
describe('ARQL Tests', () => {
    it('Should be able to run a basic GraphQL Query', async () => {
        const Edges = await GraphQL(`query {
            transactions {
                edges {
                    cursor 
                    node {
                        id
                    }
                }
            }
        }`);

        console.log(Edges);

        equal(Edges !== null, true);
    });

    it('Should be able to retrieve entries from the Vote Account', async () => {
        const Edges = await RetrieveAccount('Vote111111111111111111111111111111111111111', 3, '', 'solarweave-cache-devnet-testrun1-index');
        equal(Edges.length === 3, true);
    });

    it('Should be able to retrieve latest entries from the database', async () => {
        const Edges = await RetrieveBlocks(3, '', 'solarweave-cache-devnet-testrun1');
        equal(Edges.length === 3, true);
    });

    it('Should be able to retrieve actual block data', async () => {
        const BlockData = await RetrieveBlock('AXhCf_ARKlIEmpvQaRSXnbAuVh0KRxG5B1ybZP0mhMM');
        equal(BlockData !== null, true);
    });
});
Example #2
Source File: Arweave.service.test.ts    From SolarweaveBridge with MIT License 6 votes vote down vote up
describe('Arweave Service Tests', () => {
    const slot = 1025219;
    const blockhash = '34zRbXQZktKRZarTzP6NHVFncyw8LqHtat8sXd7rwWUb';
    let SampleBlock = null;

    it('Should load the default wallet', async () => {
        const key = await LoadWallet();
        equal(key !== null, true);
    });

    it('Should get the appropriate address and balance', async () => {
        const { address, balance } = await GetBalance();

        equal(typeof address, 'string');
        equal(address.length > 1, true);

        equal(isNaN(Number(balance)), false);
        equal(Number(balance) > -1, true);
    });

    it('Should submit a block to Arweave', async () => {
        equal(SampleBlock !== null, true);
        
        const key = await LoadWallet();
        equal(key !== null, true);

        const transaction: ArweaveTransaction = PrepareTransaction(SampleBlock, slot);

        await SubmitBlocksToArweave([transaction]);
    });
});
Example #3
Source File: Compression.service.test.ts    From SolarweaveBridge with MIT License 6 votes vote down vote up
describe('Compression Service Tests', () => {
    it('Should compress a sample JSON object', async () => {
        const data = await CompressBlock({ example: 'hello world' });
        equal(typeof data, 'string');
    });

    it('Should compress and decompress a sample JSON object', async () => {
        const data = await CompressBlock({ example: 'hello world' });
        equal(typeof data, 'string');

        const parsed = await DecompressBlock(data);
        equal(parsed.example, 'hello world');
    });
});
Example #4
Source File: Solana.rpc.service.test.ts    From SolarweaveBridge with MIT License 6 votes vote down vote up
describe('Solana Base RPC Service Test', () => {
    it('Should retrieve the Genesis Hash', async () => {
        const payload = await GenesisHash();
        equal(payload.body.result.length > 0, true);
    });

    it('Should retrieve the Current Slot', async () => {
        const payload = await GetSlot();

        equal(typeof payload.body.result, 'number');
        equal(payload.body.result > 0, true);
    });

    it('Should retrieve the Latest Block', async () => {
        const slotPayload = await GetSlot();
        const slot: number = slotPayload.body.result;
        
        const blockPayload = await GetBlock(slot);
        const hash = blockPayload.body.result.blockhash;

        equal(typeof hash, 'string');
    });
});
Example #5
Source File: Solana.rpc.service.test.ts    From SolarweaveBridge with MIT License 6 votes vote down vote up
describe('Solana Block Traversal Test', async () => {
    const blocks = [];
    let latestSlot = -1;

    it('Retrieve the latest 4 blocks', async () => {
        const slotPayload = await GetSlot();
        latestSlot = slotPayload.body.result;

        for (let i = 0; i < 4; i++) {
            const blockPayload = await GetBlock(latestSlot - i);
            const block = blockPayload.body.result;

            equal(typeof block.blockhash, 'string');
            blocks.unshift(block);
        }
    });

    it('Previous block hashes match', async () => {
        for (let i = 1; i < blocks.length; i++) {
            const previousBlock = blocks[i - 1];
            const block = blocks[i];

            equal(block.previousBlockhash, previousBlock.blockhash);
        }
    });

    it('Should retrieve the latest 100 confirmed blocks', async () => {
        const confirmedBlocks = await GetConfirmedBlocks(latestSlot - 100, latestSlot);
        equal(confirmedBlocks.body.result.length > 10, true);
    });
});
Example #6
Source File: change-push-token.test.ts    From erouska-firebase with MIT License 6 votes vote down vote up
describe("changePushToken", () => {
    it("should not accept unauthorized calls", async () => {
        await rejects(async () => {
            await changePushTokenMock({});
        }, new functions.https.HttpsError("unauthenticated", "Chybějící autentizace"));
    });
    it("should not accept wrong input", async () => {
        await rejects(async () => {
            await changePushTokenMock({}, createAuth());
        }, new functions.https.HttpsError("invalid-argument", "Wrong arguments"));
    });
    it("should not accept missing BUID", async () => {
        await rejects(async () => {
            await changePushTokenMock(makeArguments("buid1", ""), createAuth());
        }, new functions.https.HttpsError("unauthenticated", "Zařízení neexistuje nebo nepatří Vašemu účtu"));
    });
    it("should not accept BUID not owned by the user", async () => {
        const buid = await registerBuidMock(makeDeviceData(), createAuth("different-uid", "my-phone"));
        await rejects(async () => {
            await changePushTokenMock(makeArguments(buid.buid, ""), createAuth());
        }, new functions.https.HttpsError("unauthenticated", "Zařízení neexistuje nebo nepatří Vašemu účtu"));
    });
    it("should change token of BUID owned by the user", async () => {
        const auth = createAuth();
        const buid = await registerBuidMock(makeDeviceData(), auth);
        const token = "my-token";
        await changePushTokenMock(makeArguments(buid.buid, token), auth);
        const doc = await firestore().collection("registrations").doc(buid.buid).get();
        equal(doc.get("pushRegistrationToken"), token);
    });
});
Example #7
Source File: is-buid-active.test.ts    From erouska-firebase with MIT License 6 votes vote down vote up
describe("isBuidActive", () => {
    it("should not accept unauthorized calls", async () => {
        await rejects(async () => {
            await isBuidActiveMock({});
        }, new functions.https.HttpsError("unauthenticated", "Chybějící autentizace"));
    });
    it("should not accept wrong input", async () => {
        await rejects(async () => {
            await isBuidActiveMock({}, createAuth());
        }, new functions.https.HttpsError("invalid-argument", "Wrong arguments"));
    });
    it("should return false if BUID does not exist", async () => {
        equal(await isBuidActiveMock(makeBuid("buid1"), createAuth()), false);
    });
    it("should return false if BUID is not owned by the user", async () => {
        const buid = await registerBuidMock(makeDeviceData(), createAuth("different-uid", "my-phone"));
        equal(await isBuidActiveMock(makeBuid(buid.buid), createAuth()), false);
    });
    it("should return true if BUID is owned by the user", async () => {
        const auth = createAuth();
        const buid = await registerBuidMock(makeDeviceData(), auth);
        equal(await isBuidActiveMock(makeBuid(buid.buid), auth), true);
    });
});
Example #8
Source File: Config.test.ts    From SolarweaveBridge with MIT License 5 votes vote down vote up
describe('Config Tests', () => {
    it('Should have a valid Arweave Object', () => {
        equal(arweave !== null, true);
    });

    it('Verify the contents of Solarweave Config', () => {
        equal(SolarweaveConfig.rpc_version, '2.0');
        equal(SolarweaveConfig.database, 'solarweave-devnet');
        equal(SolarweaveConfig.arweaveGraphQL, 'https://arweave.dev/graphql');
        equal(SolarweaveConfig.url, 'https://devnet.solana.com');
        equal(SolarweaveConfig.credentials, '.arweave.creds.json');
        equal(SolarweaveConfig.local, false);
        equal(SolarweaveConfig.localFile, 'solarweave.cache.json');
        equal(SolarweaveConfig.console, true);
        equal(SolarweaveConfig.debug, false);
        equal(SolarweaveConfig.compressed, true);
        equal(SolarweaveConfig.parallelize, 1);
        equal(SolarweaveConfig.benchmark, false);
        equal(SolarweaveConfig.verify, true);
        equal(SolarweaveConfig.index, true);
    });

    it('Should be able to update the Solarweave Config', () => {
        UpdateConfig(
            '2.0',
            'solarweave-devnet',
            'https://arweave.dev/graphql',
            'https://devnet.solana.com',
            '.arweave.creds.json',
            false,
            'solarweave.cache.json',
            true,
            false,
            true,
            1,
            1,
            false,
            true,
            false
        );
    });
});
Example #9
Source File: register-buid.test.ts    From erouska-firebase with MIT License 4 votes vote down vote up
describe("registerBuid", () => {
    it("should not accept unauthorized calls", async () => {
        await rejects(async () => {
            await registerBuidMock({});
        }, new functions.https.HttpsError("unauthenticated", "Chybějící autentizace"));
    });
    it("should not accept users without phone numbers", async () => {
        const auth = {
            auth: {
                uid: "1"
            }
        };
        await rejects(async () => {
            await registerBuidMock(makeDeviceData(), auth);
        }, new functions.https.HttpsError("failed-precondition", "Chybí telefonní číslo"));

        await rejects(async () => {
            await registerBuidMock(makeDeviceData(null), auth);
        }, new functions.https.HttpsError("failed-precondition", "Chybí telefonní číslo"));
    });
    it("should not accept wrong input", async () => {
        await rejects(async () => {
            await registerBuidMock({}, createAuth());
        }, new functions.https.HttpsError("invalid-argument", "Wrong arguments"));

        await rejects(async () => {
            await registerBuidMock({
                model: "model1",
                manufacturer: "model2"
            }, createAuth("uid1", "123456789"));
        }, new functions.https.HttpsError("invalid-argument", "Wrong arguments"));

        await rejects(async () => {
            await registerBuidMock(makeDeviceData("123"), createAuth("uid1", "123456789"));
        }, new functions.https.HttpsError("invalid-argument", "Špatné parametry"));
    });
    it("should create a user with the correct phone number", async () => {
        const fuid = "uid1";
        const phone = "123456789";
        await registerBuidMock(makeDeviceData(), createAuth(fuid, phone));
        const doc = await firestore().collection("users").doc(fuid).get();
        equal(doc.exists, true);
        equal(doc.get("registrationCount"), 1);
        equal(doc.get("unverifiedPhoneNumber"), undefined);
    });
    it("should create BUID", async () => {
        const fuid = "uid1";
        const phone = "123456789";
        const data = makeDeviceData();
        const response = await registerBuidMock(data, createAuth(fuid, phone));
        const buid = response.buid;

        const doc = await firestore().collection("registrations").doc(buid).get();
        equal(doc.exists, true);
        equal(doc.get("fuid"), fuid);
        equal(doc.get("model"), data.model);
        equal(doc.get("manufacturer"), data.manufacturer);
        equal(doc.get("platform"), data.platform);
        equal(doc.get("platformVersion"), data.platformVersion);
        equal(doc.get("locale"), data.locale);
        equal(doc.get("pushRegistrationToken"), data.pushRegistrationToken);
    });
    it("should create TUIDs", async () => {
        const fuid = "uid1";
        const phone = "123456789";
        const data = makeDeviceData();
        const response = await registerBuidMock(data, createAuth(fuid, phone));
        const buid = response.buid;
        const tuids = response.tuids;

        const dbTuids = [];
        for (const doc of (await firestore().collection("tuids").where("buid", "==", buid).get()).docs) {
            equal(doc.get("buid"), buid);
            equal(doc.get("fuid"), fuid);
            dbTuids.push(doc.id);
        }
        expect(tuids).to.have.members(dbTuids);
    });
    it("should support multiple BUIDs per user", async () => {
        const fuid = "uid1";
        const phone = "123456789";
        const data = makeDeviceData();

        const buids = await Promise.all([0, 0, 0].map(() => registerBuidMock(data, createAuth(fuid, phone))));
        const doc = await firestore().collection("users").doc(fuid).get();
        equal(doc.get("registrationCount"), buids.length);

        for (const buid of buids) {
            const buidDoc = await firestore().collection("registrations").doc(buid.buid).get();
            equal(buidDoc.exists, true);
        }
    });
    it("should not allow too many BUIDs per user", async () => {
        const auth = createAuth();
        const data = makeDeviceData();

        await Promise.all(Array.from(Array(MAX_BUIDS_PER_USER)).map(() => registerBuidMock(data, auth)));
        await rejects(async () => {
            await registerBuidMock(data, auth);
        }, new functions.https.HttpsError("resource-exhausted", "Na Vašem účtu je již příliš mnoho registrovaných zařízení"));
    });
    it("should allow users with unverified phone numbers", async () => {
        const uid = "uid1";
        const phone = "phone1";
        const auth = {
            auth: {
                uid,
            }
        };
        await registerBuidMock(makeDeviceData(phone), auth);
        const doc = await firestore().collection("users").doc(uid).get();
        equal(doc.get("unverifiedPhoneNumber"), phone);
    });
});
Example #10
Source File: sapio.ts    From sapio-studio with Mozilla Public License 2.0 4 votes vote down vote up
async list_contracts(workspace_name: string): Promise<Result<API>> {
        const workspace = await SapioWorkspace.new(workspace_name);
        const res = await SapioCompiler.command([
            'contract',
            'list',
            '--workspace',
            workspace.workspace_location(),
        ]);
        if ('err' in res) return res;
        const contracts = res.ok;
        const lines: Array<[string, string]> = contracts
            .trim()
            .split(/\r?\n/)
            .map((line: string) => {
                const v: string[] = line.split(' -- ')!;
                equal(v.length, 2);
                return v as [string, string];
            });

        const apis_p = Promise.all(
            lines.map(([name, key]: [string, string]): Promise<JSONSchema7> => {
                if (memo_apis.has(key)) {
                    return Promise.resolve(memo_apis.get(key));
                } else {
                    return SapioCompiler.command([
                        'contract',
                        'api',
                        '--key',
                        key,
                        '--workspace',
                        workspace.workspace_location(),
                    ]).then((v) => {
                        if ('err' in v) return v;
                        const api = JSON.parse(v.ok);
                        memo_apis.set(key, api);
                        return api;
                    });
                }
            })
        );
        const logos_p = Promise.all(
            lines.map(
                ([name, key]: [string, string]): Promise<Result<string>> => {
                    if (memo_logos.has(key)) {
                        return Promise.resolve(memo_logos.get(key));
                    } else {
                        return SapioCompiler.command([
                            'contract',
                            'logo',
                            '--key',
                            key,
                            '--workspace',
                            workspace.workspace_location(),
                        ])
                            .then((logo: Result<string>) => {
                                return 'ok' in logo
                                    ? { ok: logo.ok.trim() }
                                    : logo;
                            })
                            .then((logo: Result<string>) => {
                                if ('err' in logo) return logo;
                                memo_logos.set(key, logo);
                                return logo;
                            });
                    }
                }
            )
        );
        const [apis, logos] = await Promise.all([apis_p, logos_p]);

        const results: API = {};
        equal(lines.length, apis.length);
        equal(lines.length, logos.length);
        for (let i = 0; i < lines.length; ++i) {
            const [name, key] = lines[i]!;
            const api = apis[i]!;
            const logo = logos[i]!;
            if ('err' in logo) return logo;
            results[key] = {
                name,
                key,
                api,
                logo: logo.ok,
            };
        }
        return { ok: results };
    }