Skip to content

Commit

Permalink
Fix localnet tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Aug 30, 2023
1 parent 9d98024 commit 5dc7305
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
24 changes: 14 additions & 10 deletions src/smartcontracts/smartContract.local.net.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { SmartContract } from "./smartContract";
import { assert } from "chai";
import { Logger } from "../logger";
import { prepareDeployment } from "../testutils";
import { createLocalnetProvider } from "../testutils/networkProviders";
import { loadTestWallets, TestWallet } from "../testutils/wallets";
import { TransactionWatcher } from "../transactionWatcher";
import { decodeUnsignedNumber } from "./codec";
import { ContractFunction } from "./function";
import { loadTestWallets, TestWallet } from "../testutils/wallets";
import { prepareDeployment } from "../testutils";
import { Logger } from "../logger";
import { assert } from "chai";
import { ResultsParser } from "./resultsParser";
import { SmartContract } from "./smartContract";
import { AddressValue, BigUIntValue, OptionalValue, OptionValue, TokenIdentifierValue, U32Value } from "./typesystem";
import { decodeUnsignedNumber } from "./codec";
import { BytesValue } from "./typesystem/bytes";
import { ResultsParser } from "./resultsParser";
import { createLocalnetProvider } from "../testutils/networkProviders";

describe("test on local testnet", function () {
let provider = createLocalnetProvider();
let watcher = new TransactionWatcher(provider);
let alice: TestWallet, bob: TestWallet, carol: TestWallet;
let provider = createLocalnetProvider();
let watcher: TransactionWatcher;
let resultsParser = new ResultsParser();

before(async function () {
({ alice, bob, carol } = await loadTestWallets());

watcher = new TransactionWatcher({
getTransaction: async (hash: string) => { return await provider.getTransaction(hash, true) }
});
});

it("counter: should deploy, then simulate transactions", async function () {
Expand Down
14 changes: 9 additions & 5 deletions src/smartcontracts/smartContractResults.local.net.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { assert } from "chai";
import { loadTestWallets, prepareDeployment, TestWallet } from "../testutils";
import { createLocalnetProvider } from "../testutils/networkProviders";
import { TransactionWatcher } from "../transactionWatcher";
import { assert } from "chai";
import { SmartContract } from "./smartContract";
import { ContractFunction } from "./function";
import { ResultsParser } from "./resultsParser";
import { createLocalnetProvider } from "../testutils/networkProviders";
import { SmartContract } from "./smartContract";

describe("fetch transactions from local testnet", function () {
let provider = createLocalnetProvider();
let watcher = new TransactionWatcher(provider);
let alice: TestWallet;
let provider = createLocalnetProvider();
let watcher: TransactionWatcher;

let resultsParser = new ResultsParser();

before(async function () {
({ alice } = await loadTestWallets());
watcher = new TransactionWatcher({
getTransaction: async (hash: string) => { return await provider.getTransaction(hash, true) }
});
});

it("counter smart contract", async function () {
Expand Down
10 changes: 6 additions & 4 deletions src/testutils/contractController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ITransactionOnNetwork } from "../interfaceOfNetwork";
import { Logger } from "../logger";
import { Interaction } from "../smartcontracts/interaction";
import { Transaction } from "../transaction";
import { TypedOutcomeBundle, UntypedOutcomeBundle } from "../smartcontracts/interface";
import { ResultsParser } from "../smartcontracts/resultsParser";
import { Logger } from "../logger";
import { Transaction } from "../transaction";
import { TransactionWatcher } from "../transactionWatcher";
import { ITransactionOnNetwork } from "../interfaceOfNetwork";
import { INetworkProvider } from "./networkProviders";

export class ContractController {
Expand All @@ -15,7 +15,9 @@ export class ContractController {
constructor(provider: INetworkProvider) {
this.parser = new ResultsParser();
this.provider = provider;
this.transactionCompletionAwaiter = new TransactionWatcher(provider);
this.transactionCompletionAwaiter = new TransactionWatcher({
getTransaction: async (hash: string) => { return await provider.getTransaction(hash, true) }
});
}

async deploy(transaction: Transaction): Promise<{ transactionOnNetwork: ITransactionOnNetwork, bundle: UntypedOutcomeBundle }> {
Expand Down
2 changes: 1 addition & 1 deletion src/testutils/networkProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function createTestnetProvider(): INetworkProvider {
export interface INetworkProvider {
getNetworkConfig(): Promise<INetworkConfig>;
getAccount(address: IAddress): Promise<IAccountOnNetwork>;
getTransaction(txHash: string): Promise<ITransactionOnNetwork>;
getTransaction(txHash: string, withProcessStatus?: boolean): Promise<ITransactionOnNetwork>;
getTransactionStatus(txHash: string): Promise<ITransactionStatus>;
sendTransaction(tx: Transaction): Promise<string>;
simulateTransaction(tx: Transaction): Promise<any>;
Expand Down
8 changes: 4 additions & 4 deletions src/transaction.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { TokenTransfer } from "./tokenTransfer";
import { Transaction } from "./transaction";
import { TransactionPayload } from "./transactionPayload";
import { TransactionWatcher } from "./transactionWatcher";
import { ProxyNetworkProvider } from "@multiversx/sdk-network-providers";

describe("test transaction", function () {
let alice: TestWallet, bob: TestWallet;
Expand All @@ -20,7 +19,9 @@ describe("test transaction", function () {
this.timeout(70000);

let provider = createLocalnetProvider();
let watcher = new TransactionWatcher(provider);
let watcher = new TransactionWatcher({
getTransaction: async (hash: string) => { return await provider.getTransaction(hash, true) }
});
let network = await provider.getNetworkConfig();

await alice.sync(provider);
Expand Down Expand Up @@ -67,9 +68,8 @@ describe("test transaction", function () {
this.timeout(70000);

let provider = createLocalnetProvider();
let newProvider = new ProxyNetworkProvider("http://localhost:7950", { timeout: 5000 });
let watcher = new TransactionWatcher({
getTransaction: async (hash: string) => { return await newProvider.getTransaction(hash, true) }
getTransaction: async (hash: string) => { return await provider.getTransaction(hash, true) }
});

let network = await provider.getNetworkConfig();
Expand Down

0 comments on commit 5dc7305

Please sign in to comment.