From f921d342f6eb9b105d8709fb900ad760c26290a2 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 7 Mar 2024 11:32:05 +0200 Subject: [PATCH] renamings --- src/adapters/index.ts | 2 +- ...ueriesAdapter.ts => queryRunnerAdapter.ts} | 12 +++++------ src/smartContractQueriesController.spec.ts | 20 +++++++++---------- src/smartContractQueriesController.ts | 18 ++--------------- 4 files changed, 19 insertions(+), 33 deletions(-) rename src/adapters/{smartContractQueriesAdapter.ts => queryRunnerAdapter.ts} (80%) diff --git a/src/adapters/index.ts b/src/adapters/index.ts index e6409c29..e73a1b2d 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -1 +1 @@ -export * from "./smartContractQueriesAdapter"; +export * from "./queryRunnerAdapter"; diff --git a/src/adapters/smartContractQueriesAdapter.ts b/src/adapters/queryRunnerAdapter.ts similarity index 80% rename from src/adapters/smartContractQueriesAdapter.ts rename to src/adapters/queryRunnerAdapter.ts index 61e52704..b78840c7 100644 --- a/src/adapters/smartContractQueriesAdapter.ts +++ b/src/adapters/queryRunnerAdapter.ts @@ -4,10 +4,10 @@ import { IContractQueryResponse } from "../interfaceOfNetwork"; import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery"; interface INetworkProvider { - queryContract(query: ILegacyQuery): Promise; + queryContract(query: IQuery): Promise; } -interface ILegacyQuery { +interface IQuery { address: IAddress; caller?: IAddress; func: { toString(): string }; @@ -15,15 +15,15 @@ interface ILegacyQuery { getEncodedArguments(): string[]; } -export class SmartContractQueriesAdapter { - networkProvider: INetworkProvider; +export class QueryRunnerAdapter { + private readonly networkProvider: INetworkProvider; constructor(options: { networkProvider: INetworkProvider }) { this.networkProvider = options.networkProvider; } - async queryContract(query: SmartContractQuery): Promise { - const legacyQuery: ILegacyQuery = { + async runQuery(query: SmartContractQuery): Promise { + const legacyQuery: IQuery = { address: Address.fromBech32(query.contract), caller: query.caller ? Address.fromBech32(query.caller) : undefined, func: query.function, diff --git a/src/smartContractQueriesController.spec.ts b/src/smartContractQueriesController.spec.ts index 36d71a33..b1e6861c 100644 --- a/src/smartContractQueriesController.spec.ts +++ b/src/smartContractQueriesController.spec.ts @@ -6,12 +6,12 @@ import { SmartContractQueryResponse } from "./smartContractQuery"; import { AbiRegistry, BigUIntValue, BooleanValue, BytesValue, Tuple, U16Value, U64Value } from "./smartcontracts"; import { bigIntToBuffer } from "./smartcontracts/codec/utils"; import { MockNetworkProvider, loadAbiRegistry } from "./testutils"; -import { SmartContractQueriesAdapter } from "./adapters/smartContractQueriesAdapter"; +import { QueryRunnerAdapter } from "./adapters/queryRunnerAdapter"; describe("test smart contract queries controller", () => { describe("createQuery", () => { it("works without ABI, when arguments are buffers", function () { - const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider() }); + const adapter = new QueryRunnerAdapter({ networkProvider: new MockNetworkProvider() }); const controller = new SmartContractQueriesController({ queryRunner: adapter, }); @@ -28,7 +28,7 @@ describe("test smart contract queries controller", () => { }); it("works without ABI, when arguments are typed values", function () { - const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider() }); + const adapter = new QueryRunnerAdapter({ networkProvider: new MockNetworkProvider() }); const controller = new SmartContractQueriesController({ queryRunner: adapter, }); @@ -45,7 +45,7 @@ describe("test smart contract queries controller", () => { }); it("fails without ABI, when arguments aren't buffers, nor typed values", function () { - const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider() }); + const adapter = new QueryRunnerAdapter({ networkProvider: new MockNetworkProvider() }); const controller = new SmartContractQueriesController({ queryRunner: adapter, }); @@ -60,7 +60,7 @@ describe("test smart contract queries controller", () => { }); it("works with ABI, when arguments are native JS objects", async function () { - const adapter = new SmartContractQueriesAdapter({ + const adapter = new QueryRunnerAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ @@ -80,7 +80,7 @@ describe("test smart contract queries controller", () => { }); it("works with ABI, when arguments typed values", async function () { - const adapter = new SmartContractQueriesAdapter({ + const adapter = new QueryRunnerAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ @@ -123,7 +123,7 @@ describe("test smart contract queries controller", () => { ], }); - const adapter = new SmartContractQueriesAdapter({ + const adapter = new QueryRunnerAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ @@ -162,7 +162,7 @@ describe("test smart contract queries controller", () => { describe("runQuery", () => { it("calls queryContract on the network provider", async function () { const networkProvider = new MockNetworkProvider(); - const adapter = new SmartContractQueriesAdapter({ + const adapter = new QueryRunnerAdapter({ networkProvider: networkProvider, }); const controller = new SmartContractQueriesController({ @@ -192,7 +192,7 @@ describe("test smart contract queries controller", () => { describe("parseQueryResponse", () => { it("works without ABI", function () { - const adapter = new SmartContractQueriesAdapter({ + const adapter = new QueryRunnerAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ @@ -212,7 +212,7 @@ describe("test smart contract queries controller", () => { }); it("works with ABI", async function () { - const adapter = new SmartContractQueriesAdapter({ + const adapter = new QueryRunnerAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ diff --git a/src/smartContractQueriesController.ts b/src/smartContractQueriesController.ts index aceb1b57..b676b09c 100644 --- a/src/smartContractQueriesController.ts +++ b/src/smartContractQueriesController.ts @@ -1,5 +1,4 @@ import { Err } from "./errors"; -import { IAddress } from "./interface"; import { IContractQueryResponse } from "./interfaceOfNetwork"; import { SmartContractQuery, SmartContractQueryResponse } from "./smartContractQuery"; import { ArgSerializer, ContractFunction, EndpointDefinition, NativeSerializer, ResultsParser } from "./smartcontracts"; @@ -8,21 +7,8 @@ interface IAbi { getEndpoint(name: string | ContractFunction): EndpointDefinition; } -interface INetworkProvider { - queryContract(query: ILegacyQuery): Promise; -} - -interface ILegacyQuery { - address: IAddress; - caller?: IAddress; - func: { toString(): string }; - value?: { toString(): string }; - getEncodedArguments(): string[]; -} - interface IQueryRunner { - networkProvider: INetworkProvider; - queryContract(query: SmartContractQuery): Promise; + runQuery(query: SmartContractQuery): Promise; } export class SmartContractQueriesController { @@ -96,7 +82,7 @@ export class SmartContractQueriesController { } async runQuery(query: SmartContractQuery): Promise { - const queryResponse = await this.queryRunner.queryContract(query); + const queryResponse = await this.queryRunner.runQuery(query); return queryResponse; }