diff --git a/src/adapters/index.ts b/src/adapters/index.ts new file mode 100644 index 00000000..e6409c29 --- /dev/null +++ b/src/adapters/index.ts @@ -0,0 +1 @@ +export * from "./smartContractQueriesAdapter"; diff --git a/src/adaptors/smartContractQueriesAdaptor.ts b/src/adapters/smartContractQueriesAdapter.ts similarity index 82% rename from src/adaptors/smartContractQueriesAdaptor.ts rename to src/adapters/smartContractQueriesAdapter.ts index b8c2151f..61e52704 100644 --- a/src/adaptors/smartContractQueriesAdaptor.ts +++ b/src/adapters/smartContractQueriesAdapter.ts @@ -2,16 +2,11 @@ import { Address } from "../address"; import { IAddress } from "../interface"; import { IContractQueryResponse } from "../interfaceOfNetwork"; import { SmartContractQuery, SmartContractQueryResponse } from "../smartContractQuery"; -import { ContractFunction, EndpointDefinition } from "../smartcontracts"; interface INetworkProvider { queryContract(query: ILegacyQuery): Promise; } -interface IAbi { - getEndpoint(name: string | ContractFunction): EndpointDefinition; -} - interface ILegacyQuery { address: IAddress; caller?: IAddress; @@ -20,12 +15,10 @@ interface ILegacyQuery { getEncodedArguments(): string[]; } -export class SmartContractQueriesAdaptor { - abi?: IAbi; +export class SmartContractQueriesAdapter { networkProvider: INetworkProvider; - constructor(options: { abi?: IAbi; networkProvider: INetworkProvider }) { - this.abi = options.abi; + constructor(options: { networkProvider: INetworkProvider }) { this.networkProvider = options.networkProvider; } diff --git a/src/adaptors/index.ts b/src/adaptors/index.ts deleted file mode 100644 index 9fa9c9a3..00000000 --- a/src/adaptors/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./smartContractQueriesAdaptor"; diff --git a/src/smartContractQueriesController.spec.ts b/src/smartContractQueriesController.spec.ts index 915c0c64..36d71a33 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 { SmartContractQueriesAdaptor } from "./adaptors/smartContractQueriesAdaptor"; +import { SmartContractQueriesAdapter } from "./adapters/smartContractQueriesAdapter"; describe("test smart contract queries controller", () => { describe("createQuery", () => { it("works without ABI, when arguments are buffers", function () { - const adapter = new SmartContractQueriesAdaptor({ networkProvider: new MockNetworkProvider() }); + const adapter = new SmartContractQueriesAdapter({ 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 SmartContractQueriesAdaptor({ networkProvider: new MockNetworkProvider() }); + const adapter = new SmartContractQueriesAdapter({ 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 SmartContractQueriesAdaptor({ networkProvider: new MockNetworkProvider() }); + const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider() }); const controller = new SmartContractQueriesController({ queryRunner: adapter, }); @@ -60,11 +60,11 @@ describe("test smart contract queries controller", () => { }); it("works with ABI, when arguments are native JS objects", async function () { - const adapter = new SmartContractQueriesAdaptor({ - abi: await loadAbiRegistry("src/testdata/lottery-esdt.abi.json"), + const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ + abi: await loadAbiRegistry("src/testdata/lottery-esdt.abi.json"), queryRunner: adapter, }); @@ -80,11 +80,11 @@ describe("test smart contract queries controller", () => { }); it("works with ABI, when arguments typed values", async function () { - const adapter = new SmartContractQueriesAdaptor({ - abi: await loadAbiRegistry("src/testdata/lottery-esdt.abi.json"), + const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ + abi: await loadAbiRegistry("src/testdata/lottery-esdt.abi.json"), queryRunner: adapter, }); @@ -123,11 +123,11 @@ describe("test smart contract queries controller", () => { ], }); - const adapter = new SmartContractQueriesAdaptor({ - abi: abi, + const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ + abi: abi, queryRunner: adapter, }); @@ -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 SmartContractQueriesAdaptor({ + const adapter = new SmartContractQueriesAdapter({ 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 SmartContractQueriesAdaptor({ + const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ @@ -212,11 +212,11 @@ describe("test smart contract queries controller", () => { }); it("works with ABI", async function () { - const adapter = new SmartContractQueriesAdaptor({ - abi: await loadAbiRegistry("src/testdata/lottery-esdt.abi.json"), + const adapter = new SmartContractQueriesAdapter({ networkProvider: new MockNetworkProvider(), }); const controller = new SmartContractQueriesController({ + abi: await loadAbiRegistry("src/testdata/lottery-esdt.abi.json"), queryRunner: adapter, }); diff --git a/src/smartContractQueriesController.ts b/src/smartContractQueriesController.ts index afcf0521..aceb1b57 100644 --- a/src/smartContractQueriesController.ts +++ b/src/smartContractQueriesController.ts @@ -1,4 +1,3 @@ -import { Address } from "./address"; import { Err } from "./errors"; import { IAddress } from "./interface"; import { IContractQueryResponse } from "./interfaceOfNetwork"; @@ -22,7 +21,6 @@ interface ILegacyQuery { } interface IQueryRunner { - abi?: IAbi; networkProvider: INetworkProvider; queryContract(query: SmartContractQuery): Promise; } @@ -32,8 +30,8 @@ export class SmartContractQueriesController { private readonly queryRunner: IQueryRunner; private readonly legacyResultsParser: ResultsParser; - constructor(options: { queryRunner: IQueryRunner }) { - this.abi = options.queryRunner.abi; + constructor(options: { abi?: IAbi; queryRunner: IQueryRunner }) { + this.abi = options.abi; this.queryRunner = options.queryRunner; this.legacyResultsParser = new ResultsParser(); }