Skip to content

Commit

Permalink
renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Mar 7, 2024
1 parent 127937c commit f921d34
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./smartContractQueriesAdapter";
export * from "./queryRunnerAdapter";
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import { IContractQueryResponse } from "../interfaceOfNetwork";
import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery";

interface INetworkProvider {
queryContract(query: ILegacyQuery): Promise<IContractQueryResponse>;
queryContract(query: IQuery): Promise<IContractQueryResponse>;
}

interface ILegacyQuery {
interface IQuery {
address: IAddress;
caller?: IAddress;
func: { toString(): string };
value?: { toString(): string };
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<SmartContractQueryResponse> {
const legacyQuery: ILegacyQuery = {
async runQuery(query: SmartContractQuery): Promise<SmartContractQueryResponse> {
const legacyQuery: IQuery = {
address: Address.fromBech32(query.contract),
caller: query.caller ? Address.fromBech32(query.caller) : undefined,
func: query.function,
Expand Down
20 changes: 10 additions & 10 deletions src/smartContractQueriesController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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({
Expand All @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand All @@ -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({
Expand Down
18 changes: 2 additions & 16 deletions src/smartContractQueriesController.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -8,21 +7,8 @@ interface IAbi {
getEndpoint(name: string | ContractFunction): EndpointDefinition;
}

interface INetworkProvider {
queryContract(query: ILegacyQuery): Promise<IContractQueryResponse>;
}

interface ILegacyQuery {
address: IAddress;
caller?: IAddress;
func: { toString(): string };
value?: { toString(): string };
getEncodedArguments(): string[];
}

interface IQueryRunner {
networkProvider: INetworkProvider;
queryContract(query: SmartContractQuery): Promise<SmartContractQueryResponse>;
runQuery(query: SmartContractQuery): Promise<SmartContractQueryResponse>;
}

export class SmartContractQueriesController {
Expand Down Expand Up @@ -96,7 +82,7 @@ export class SmartContractQueriesController {
}

async runQuery(query: SmartContractQuery): Promise<SmartContractQueryResponse> {
const queryResponse = await this.queryRunner.queryContract(query);
const queryResponse = await this.queryRunner.runQuery(query);
return queryResponse;
}

Expand Down

0 comments on commit f921d34

Please sign in to comment.