Skip to content

Commit

Permalink
Update to type SmartContractQueryInput
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Dec 9, 2024
1 parent cff7892 commit 29c10e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
34 changes: 15 additions & 19 deletions src/abi/interaction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from "bignumber.js";
import { assert } from "chai";
import { Address } from "../address";
import { SmartContractQueryInput, SmartContractQueryResponse } from "../smartContractQuery";
import { SmartContractQueryResponse } from "../smartContractQuery";
import { SmartContractController } from "../smartContracts";
import {
loadAbiRegistry,
Expand Down Expand Up @@ -228,15 +228,13 @@ describe("test smart contract interactor", function () {
// Query;

const interactionQuery = interaction.buildQuery();
let response = await controller.query(
new SmartContractQueryInput({
contract: interactionQuery.address,
arguments: interactionQuery.getEncodedArguments(),
function: interactionQuery.func.toString(),
caller: interactionQuery.caller,
value: BigInt(interactionQuery.value.toString()),
}),
);
let response = await controller.query({
contract: interactionQuery.address,
arguments: interactionQuery.getEncodedArguments(),
function: interactionQuery.func.toString(),
caller: interactionQuery.caller,
value: BigInt(interactionQuery.value.toString()),
});
assert.isTrue(response.length == 1);
assert.deepEqual(response[0], new BigNumber(42));

Expand Down Expand Up @@ -299,15 +297,13 @@ describe("test smart contract interactor", function () {

// Query "get()"
const interactionQuery = getInteraction.buildQuery();
let response = await controller.query(
new SmartContractQueryInput({
contract: interactionQuery.address,
arguments: interactionQuery.getEncodedArguments(),
function: interactionQuery.func.toString(),
caller: interactionQuery.caller,
value: BigInt(interactionQuery.value.toString()),
}),
);
let response = await controller.query({
contract: interactionQuery.address,
arguments: interactionQuery.getEncodedArguments(),
function: interactionQuery.func.toString(),
caller: interactionQuery.caller,
value: BigInt(interactionQuery.value.toString()),
});
assert.deepEqual(response[0], new BigNumber(7));

let incrementTransaction = incrementInteraction
Expand Down
12 changes: 2 additions & 10 deletions src/smartContractQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@ export class SmartContractQuery {
}
}

export class SmartContractQueryInput {
export type SmartContractQueryInput = {
contract: Address;
caller?: Address;
value?: bigint;
function: string;
arguments: any[];

constructor(options: { contract: Address; caller?: Address; value?: bigint; function: string; arguments: any[] }) {
this.contract = options.contract;
this.caller = options.caller;
this.value = options.value;
this.function = options.function;
this.arguments = options.arguments;
}
}
};

export class SmartContractQueryResponse {
function: string;
Expand Down

0 comments on commit 29c10e3

Please sign in to comment.