Skip to content

Commit

Permalink
Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Jan 26, 2022
1 parent 0d19c07 commit 18b80f3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/dapp/walletProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assert } from "chai";
import {WalletProvider} from "./walletProvider";
import {Transaction} from "../transaction";
import {Address} from "../address";
import { isBrowser } from "../testutils";
import { isOnBrowserTests } from "../testutils";

declare global {
namespace NodeJS {
Expand All @@ -18,7 +18,7 @@ declare global {

describe("test wallet provider", () => {
before(function() {
if (isBrowser()) {
if (isOnBrowserTests()) {
this.skip();
}
});
Expand All @@ -32,7 +32,7 @@ describe("test wallet provider", () => {
});

after(function() {
if (isBrowser()) {
if (isOnBrowserTests()) {
// Do nothing.
} else {
delete global.window;
Expand Down
4 changes: 2 additions & 2 deletions src/smartcontracts/wrapper/contractWrapper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddImmediateResult, isBrowser, MarkNotarized, MockProvider, setupUnitTestWatcherTimeouts, TestWallet } from "../../testutils";
import { AddImmediateResult, isOnBrowserTests, MarkNotarized, MockProvider, setupUnitTestWatcherTimeouts, TestWallet } from "../../testutils";
import { Address } from "../../address";
import { assert } from "chai";
import { QueryResponse } from "../queryResponse";
Expand All @@ -14,7 +14,7 @@ describe("test smart contract wrapper", async function () {
let provider = new MockProvider();
let alice: TestWallet;
before(async function () {
if (isBrowser()) {
if (isOnBrowserTests()) {
this.skip();
}

Expand Down
6 changes: 3 additions & 3 deletions src/smartcontracts/wrapper/esdt.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, ContractWrapper, createBalanceBuilder, Egld, Token, SystemWrapper, TokenType, setupInteractiveWithProvider } from "../..";
import { isBrowser, MockProvider, setupUnitTestWatcherTimeouts, TestWallet } from "../../testutils";
import { isOnBrowserTests, MockProvider, setupUnitTestWatcherTimeouts, TestWallet } from "../../testutils";
import { assert } from "chai";

describe("test ESDT transfers via the smart contract wrapper", async function () {
Expand All @@ -9,10 +9,10 @@ describe("test ESDT transfers via the smart contract wrapper", async function ()
let alice: TestWallet;
let market: ContractWrapper;
before(async function () {
if (isBrowser()) {
if (isOnBrowserTests()) {
this.skip();
}

({ erdSys, wallets: { alice } } = await setupInteractiveWithProvider(provider));
market = await erdSys.loadWrapper("src/testdata", "esdt-nft-marketplace");
market.address(dummyAddress).sender(alice).gas(500_000);
Expand Down
18 changes: 13 additions & 5 deletions src/testutils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AbiRegistry } from "../smartcontracts/typesystem";
import { TransactionWatcher } from "../transactionWatcher";

export async function loadContractCode(path: PathLike): Promise<Code> {
if (isBrowser()) {
if (isOnBrowserTests()) {
return Code.fromUrl(path.toString());
}

Expand All @@ -14,7 +14,7 @@ export async function loadContractCode(path: PathLike): Promise<Code> {
export async function loadAbiRegistry(paths: PathLike[]): Promise<AbiRegistry> {
let sources = paths.map(e => e.toString());

if (isBrowser()) {
if (isOnBrowserTests()) {
return AbiRegistry.load({ urls: sources });
}

Expand All @@ -24,15 +24,23 @@ export async function loadAbiRegistry(paths: PathLike[]): Promise<AbiRegistry> {
export async function extendAbiRegistry(registry: AbiRegistry, path: PathLike): Promise<AbiRegistry> {
let source = path.toString();

if (isBrowser()) {
if (isOnBrowserTests()) {
return registry.extendFromUrl(source);
}

return registry.extendFromFile(source);
}

export function isBrowser() {
return typeof window !== "undefined" && window.location.href.includes("browser-tests");
export function isOnBrowserTests() {
const BROWSER_TESTS_URL = "browser-tests";

let noWindow = typeof window === "undefined";
if (noWindow) {
return false;
}

let isOnTests = window.location.href.includes(BROWSER_TESTS_URL);
return isOnTests;
}

export function setupUnitTestWatcherTimeouts() {
Expand Down
4 changes: 2 additions & 2 deletions src/testutils/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Address } from "../address";
import { IProvider, ISigner } from "../interface";
import { UserSecretKey } from "../walletcore";
import { UserSigner } from "../walletcore/userSigner";
import { isBrowser } from "./utils";
import { isOnBrowserTests } from "./utils";

export async function loadAndSyncTestWallets(provider: IProvider): Promise<Record<string, TestWallet>> {
let wallets = await loadTestWallets();
Expand Down Expand Up @@ -50,7 +50,7 @@ export async function loadTestWallet(name: string): Promise<TestWallet> {
async function readTestWalletFileContents(name: string): Promise<string> {
let filePath = path.join("src", "testutils", "testwallets", name);

if (isBrowser()) {
if (isOnBrowserTests()) {
return await downloadTextFile(filePath);
}

Expand Down

0 comments on commit 18b80f3

Please sign in to comment.