Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { wallet } from "@cityofzion/neon-core";
import { mocked } from "ts-jest/utils";
import { SendAssetConfig } from "../../lib/funcs/types";
import * as fill from "../../src/funcs/fill";
import { signWithPrivateKey as _signWithPrivateKey } from "../../src/funcs/sign";
import { ClaimGasConfig } from "../../src/funcs/types";
jest.mock("../../src/funcs/sign");
const signWithPrivateKey = mocked(_signWithPrivateKey, false);
describe("fillUrl", () => {
test("skips if url present", async () => {
const expectedUrl = "http://localhost.com";
const config = {
api: {
getRPCEndpoint: jest.fn()
} as any,
account: {},
url: expectedUrl
} as SendAssetConfig;
const result = await fill.fillUrl(config);
expect(result.url).toBe(expectedUrl);
expect(config.api.getRPCEndpoint).not.toBeCalled();
import { tx } from "@cityofzion/neon-core";
import { mocked } from "ts-jest/utils";
import { getVerificationSignatureForSmartContract as _getVerificationSignatureForSmartContract } from "../../src/funcs/common";
import * as mint from "../../src/funcs/mint";
import { DoInvokeConfig } from "../../src/funcs/types";
jest.mock("../../src/funcs/common");
const getVerificationSignatureForSmartContract = mocked(
_getVerificationSignatureForSmartContract,
false
);
describe("addAttributeForMintToken", () => {
test("skips if no script object present", async () => {
const config = {
tx: new tx.ContractTransaction({} as any)
} as DoInvokeConfig;
const result = await mint.addAttributeForMintToken(config);
expect(result.tx!.attributes.length).toBe(0);
});
test("adds attribute if script object present", async () => {
import React from "react";
import { mocked } from "ts-jest/utils";
import { render, fireEvent } from "utils/tests";
import DemoSandbox from "../DemoSandbox";
import useSandbox from "../useSandbox";
jest.mock("../useSandbox");
const useSandboxMock = mocked(useSandbox);
beforeEach(() => {
useSandboxMock.mockImplementation(defaultSandbox => ({
sandbox: defaultSandbox,
loading: false,
}));
});
describe("DemoSandbox", () => {
it("should not return to a from url that does not start with /packages so malicious urls can't be returned to", () => {
const sandbox = {};
const push = jest.fn();
const router = {
push,
query: {
pkg: "tree",
import { mocked } from "ts-jest/utils";
import { createScript, generateDeployScript } from "../../src/sc/core";
import _ScriptBuilder from "../../src/sc/ScriptBuilder";
import * as _u from "../../src/u";
import testIntents from "./scriptIntents.json";
jest.mock("../../src/sc/ScriptBuilder");
jest.mock("../../src/u");
const ScriptBuilder = mocked(_ScriptBuilder, true);
const u = mocked(_u, false);
beforeEach(() => {
jest.clearAllMocks();
});
describe("createScript", () => {
test("single ScriptIntent", () => {
const intent = testIntents[1].scriptIntent;
const result = createScript(intent);
expect(ScriptBuilder).toHaveBeenCalledTimes(1);
const sb = ScriptBuilder.mock.instances[0];
expect(sb.emitAppCall).toBeCalledWith(
intent.scriptHash,
intent.operation,
intent.args,
false
import React, { FC } from "react";
import { act, renderHook } from "@testing-library/react-hooks";
import { render } from "@testing-library/react";
import { mocked } from "ts-jest/utils";
import useInterval from "../useInterval";
jest.useFakeTimers();
const setInterval = mocked(window.setInterval);
const clearInterval = mocked(window.clearInterval);
beforeEach(() => {
setInterval.mockClear();
clearInterval.mockClear();
});
interface TestProps {
cb: () => void;
delay?: number;
defaultRunning?: boolean;
}
const Test: FC = ({ cb, delay = 300, defaultRunning = false }) => {
useInterval(cb, delay, defaultRunning);
return null;
};
expect(formCollection.clear).toHaveBeenCalledTimes(1)
expect(formCollection.all().length).toBe(3)
expect(formCollection.getInitialFormsIds()).toEqual([])
formCollection.all().forEach(
(form: Form, index): void => {
expect(fillSpy).toHaveBeenNthCalledWith(
index + 1,
mockValues[index],
false,
true
)
}
)
mocked(fillSpy).mockClear()
})
test(`should return empty for GitbookTheme`, () => {
mocked(MarkdownPlugin).theme = new GitbookTheme({} as Renderer, '/', {});
const data = {
project: {
name: 'Project title',
},
model: {
name: 'Reflection title',
},
};
const result = projectTitle.call(data);
expect(result).toEqual('');
});
});
test(`should compile`, () => {
mocked(Handlebars).helpers.relativeURL = () => {
return 'url';
};
mocked(MarkdownPlugin).settings = { hideProjectTitle: false };
mocked(MarkdownPlugin).theme = { indexName: 'pagex.md' } as MarkdownTheme;
const data = {
project: {
name: 'Project title',
},
model: {
name: 'Reflection title',
},
};
const result = projectTitle.call(data);
expect(result).toMatchSnapshot();
});
beforeEach(() => {
execute = jest.fn(() => Promise.resolve(response));
mocked(createClient).mockReturnValue({
execute,
});
resultPromise = createMiddleware(middlewareOptions)({
dispatch,
getState: jest.fn(),
})(next)(action);
});