From 5dc7305ee4bc9d4b842fbcbc214d93f1d153bb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 30 Aug 2023 15:20:24 +0300 Subject: [PATCH 1/2] Fix localnet tests. --- .../smartContract.local.net.spec.ts | 24 +++++++++++-------- .../smartContractResults.local.net.spec.ts | 14 +++++++---- src/testutils/contractController.ts | 10 ++++---- src/testutils/networkProviders.ts | 2 +- src/transaction.local.net.spec.ts | 8 +++---- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/smartcontracts/smartContract.local.net.spec.ts b/src/smartcontracts/smartContract.local.net.spec.ts index 23f2ddf5..075bc712 100644 --- a/src/smartcontracts/smartContract.local.net.spec.ts +++ b/src/smartcontracts/smartContract.local.net.spec.ts @@ -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 () { diff --git a/src/smartcontracts/smartContractResults.local.net.spec.ts b/src/smartcontracts/smartContractResults.local.net.spec.ts index c27a5933..eeadf13d 100644 --- a/src/smartcontracts/smartContractResults.local.net.spec.ts +++ b/src/smartcontracts/smartContractResults.local.net.spec.ts @@ -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 () { diff --git a/src/testutils/contractController.ts b/src/testutils/contractController.ts index 4806d095..3fed66f7 100644 --- a/src/testutils/contractController.ts +++ b/src/testutils/contractController.ts @@ -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 { @@ -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 }> { diff --git a/src/testutils/networkProviders.ts b/src/testutils/networkProviders.ts index 75951743..475da761 100644 --- a/src/testutils/networkProviders.ts +++ b/src/testutils/networkProviders.ts @@ -15,7 +15,7 @@ export function createTestnetProvider(): INetworkProvider { export interface INetworkProvider { getNetworkConfig(): Promise; getAccount(address: IAddress): Promise; - getTransaction(txHash: string): Promise; + getTransaction(txHash: string, withProcessStatus?: boolean): Promise; getTransactionStatus(txHash: string): Promise; sendTransaction(tx: Transaction): Promise; simulateTransaction(tx: Transaction): Promise; diff --git a/src/transaction.local.net.spec.ts b/src/transaction.local.net.spec.ts index 9b72ce5e..30f674ec 100644 --- a/src/transaction.local.net.spec.ts +++ b/src/transaction.local.net.spec.ts @@ -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; @@ -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); @@ -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(); From 00f835efbe70ac08f3a46c764c6d00986f535618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 30 Aug 2023 17:27:30 +0300 Subject: [PATCH 2/2] Uncomment older test. --- src/smartcontracts/argSerializer.spec.ts | 40 +++++++++++------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/smartcontracts/argSerializer.spec.ts b/src/smartcontracts/argSerializer.spec.ts index 3398382a..06bcac91 100644 --- a/src/smartcontracts/argSerializer.spec.ts +++ b/src/smartcontracts/argSerializer.spec.ts @@ -1,23 +1,23 @@ +import BigNumber from "bignumber.js"; import { assert } from "chai"; +import { ArgSerializer } from "./argSerializer"; import { - U8Value, EndpointParameterDefinition, - TypedValue, - U32Value, + I16Value, + I32Value, I64Value, - U16Value, - OptionValue, List, + OptionValue, Tuple, - I32Value, - I16Value, + TypedValue, + U16Value, + U32Value, + U8Value, } from "./typesystem"; -import { ArgSerializer } from "./argSerializer"; -import BigNumber from "bignumber.js"; import { BytesValue } from "./typesystem/bytes"; -import { TypeMapper } from "./typesystem/typeMapper"; -import { TypeExpressionParser } from "./typesystem/typeExpressionParser"; import { CompositeValue } from "./typesystem/composite"; +import { TypeExpressionParser } from "./typesystem/typeExpressionParser"; +import { TypeMapper } from "./typesystem/typeMapper"; import { VariadicValue } from "./typesystem/variadic"; describe("test serializer", () => { @@ -55,16 +55,14 @@ describe("test serializer", () => { "00080009@abba@abba@abba" ); - // TODO: In a future PR, improve the types expression parser and enable this test, which currently fails. - - // serializeThenDeserialize( - // ["MultiArg, List>", "VarArgs"], - // [ - // CompositeValue.fromItems(providedOption(new U8Value(7)), List.fromItems([new U16Value(8), new U16Value(9)])), - // VariadicValue.fromItems(new BytesValue(Buffer.from("abba", "hex")), new BytesValue(Buffer.from("abba", "hex")), new BytesValue(Buffer.from("abba", "hex"))) - // ], - // "0107@0000000200080009@abba@abba@abba" - // ); + serializeThenDeserialize( + ["MultiArg, List>", "VarArgs"], + [ + CompositeValue.fromItems(OptionValue.newProvided(new U8Value(7)), List.fromItems([new U16Value(8), new U16Value(9)])), + VariadicValue.fromItems(new BytesValue(Buffer.from("abba", "hex")), new BytesValue(Buffer.from("abba", "hex")), new BytesValue(Buffer.from("abba", "hex"))) + ], + "0107@00080009@abba@abba@abba" + ); }); it("should serialize then back : tuples", async () => {