Skip to content

Commit

Permalink
Merge branch 'main' into counted-variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Aug 30, 2023
2 parents 407bce7 + 836222b commit 6e2e695
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 45 deletions.
40 changes: 19 additions & 21 deletions src/smartcontracts/argSerializer.spec.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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<Option<u8>, List<u16>>", "VarArgs<bytes>"],
// [
// 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<Option<u8>, List<u16>>", "VarArgs<bytes>"],
[
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 <valuesToString> then back <stringToValues>: tuples", async () => {
Expand Down
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 6e2e695

Please sign in to comment.