Skip to content

Commit

Permalink
Merge branch 'main' into serializer-null-or-undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed May 27, 2024
2 parents 2f4eb38 + a62a324 commit 4604253
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
9 changes: 2 additions & 7 deletions src/smartContractQueriesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Err } from "./errors";
import { IContractQueryResponse } from "./interfaceOfNetwork";
import { SmartContractQuery, SmartContractQueryResponse } from "./smartContractQuery";
import { ArgSerializer, ContractFunction, EndpointDefinition, NativeSerializer, ResultsParser } from "./smartcontracts";
import { isTyped } from "./smartcontracts/typesystem";

interface IAbi {
getEndpoint(name: string | ContractFunction): EndpointDefinition;
Expand Down Expand Up @@ -62,13 +63,7 @@ export class SmartContractQueriesController {
}

private areArgsOfTypedValue(args: any[]): boolean {
for (const arg of args) {
if (!arg.belongsToTypesystem) {
return false;
}
}

return true;
return args.every((arg) => isTyped(arg));
}

private areArgsBuffers(args: any[]): boolean {
Expand Down
3 changes: 2 additions & 1 deletion src/smartcontracts/nativeSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
I64Value,
I8Type,
I8Value,
isTyped,
List,
ListType,
NumericalType,
Expand Down Expand Up @@ -168,7 +169,7 @@ export namespace NativeSerializer {
}

function convertToTypedValue(value: any, type: Type, errorContext: ArgumentErrorContext): TypedValue {
if (value && value.belongsToTypesystem) {
if (value && isTyped(value)) {
// Value is already typed, no need to convert it.
return value;
}
Expand Down
16 changes: 10 additions & 6 deletions src/smartcontracts/smartContract.local.net.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { assert } from "chai";
import { promises } from "fs";
import { QueryRunnerAdapter } from "../adapters/queryRunnerAdapter";
import { Logger } from "../logger";
import { SmartContractQueriesController } from "../smartContractQueriesController";
import { prepareDeployment } from "../testutils";
import { createLocalnetProvider } from "../testutils/networkProviders";
import { loadTestWallets, TestWallet } from "../testutils/wallets";
import { TransactionComputer } from "../transactionComputer";
import { SmartContractTransactionsFactory } from "../transactionsFactories/smartContractTransactionsFactory";
import { TransactionsFactoryConfig } from "../transactionsFactories/transactionsFactoryConfig";
import { TransactionWatcher } from "../transactionWatcher";
import { decodeUnsignedNumber } from "./codec";
import { ContractFunction } from "./function";
import { ResultsParser } from "./resultsParser";
import { SmartContract } from "./smartContract";
import { AddressValue, BigUIntValue, OptionalValue, OptionValue, TokenIdentifierValue, U32Value } from "./typesystem";
import { BytesValue } from "./typesystem/bytes";
import { TransactionsFactoryConfig } from "../transactionsFactories/transactionsFactoryConfig";
import { SmartContractTransactionsFactory } from "../transactionsFactories/smartContractTransactionsFactory";
import { promises } from "fs";
import { TransactionComputer } from "../transactionComputer";
import { QueryRunnerAdapter } from "../adapters/queryRunnerAdapter";
import { SmartContractQueriesController } from "../smartContractQueriesController";

describe("test on local testnet", function () {
let alice: TestWallet, bob: TestWallet, carol: TestWallet;
Expand Down Expand Up @@ -258,6 +258,7 @@ describe("test on local testnet", function () {
// Check counter
let query = contract.createQuery({ func: new ContractFunction("get") });
let queryResponse = await provider.queryContract(query);
assert.lengthOf(queryResponse.getReturnDataParts(), 1);
assert.equal(3, decodeUnsignedNumber(queryResponse.getReturnDataParts()[0]));
});

Expand Down Expand Up @@ -336,6 +337,7 @@ describe("test on local testnet", function () {
});

const queryResponse = await smartContractQueriesController.runQuery(query);
assert.lengthOf(queryResponse.returnDataParts, 1);
assert.equal(3, decodeUnsignedNumber(Buffer.from(queryResponse.returnDataParts[0])));
});

Expand Down Expand Up @@ -398,6 +400,7 @@ describe("test on local testnet", function () {
// Query state, do some assertions
let query = contract.createQuery({ func: new ContractFunction("totalSupply") });
let queryResponse = await provider.queryContract(query);
assert.lengthOf(queryResponse.getReturnDataParts(), 1);
assert.equal(10000, decodeUnsignedNumber(queryResponse.getReturnDataParts()[0]));

query = contract.createQuery({
Expand Down Expand Up @@ -501,6 +504,7 @@ describe("test on local testnet", function () {
arguments: [],
});
let queryResponse = await smartContractQueriesController.runQuery(query);
assert.lengthOf(queryResponse.returnDataParts, 1);
assert.equal(10000, decodeUnsignedNumber(Buffer.from(queryResponse.returnDataParts[0])));

query = smartContractQueriesController.createQuery({
Expand Down
9 changes: 2 additions & 7 deletions src/transactionsFactories/smartContractTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IAddress } from "../interface";
import { Logger } from "../logger";
import { ArgSerializer, CodeMetadata, ContractFunction, EndpointDefinition } from "../smartcontracts";
import { NativeSerializer } from "../smartcontracts/nativeSerializer";
import { isTyped } from "../smartcontracts/typesystem";
import { TokenComputer, TokenTransfer } from "../tokens";
import { Transaction } from "../transaction";
import { byteArrayToHex, utf8ToHex } from "../utils.codec";
Expand Down Expand Up @@ -236,12 +237,6 @@ export class SmartContractTransactionsFactory {
}

private areArgsOfTypedValue(args: any[]): boolean {
for (const arg of args) {
if (!arg.belongsToTypesystem) {
return false;
}
}

return true;
return args.every((arg) => isTyped(arg));
}
}

0 comments on commit 4604253

Please sign in to comment.