MCPcopy Create free account
hub / github.com/GalaChain/sdk / query

Method query

chain-test/src/unit/TestChaincode.ts:197–214  ·  view source on GitHub ↗

* Queries a chaincode method with read-only access (evaluate transaction). * Changes made during query are not persisted to the state. * * @template T - Expected return type of the query * @param method - Name of the contract method to query * @param args - Arguments to pass to the me

(
    method: string,
    ...args: (string | { serialize: () => string })[]
  )

Source from the content-addressed store, hash-verified

195 * @throws Error if the query fails
196 */
197 public async query<T = InvokeResponse>(
198 method: string,
199 ...args: (string | { serialize: () => string })[]
200 ): Promise<T> {
201 const argsSerialized = args.map((arg) => (typeof arg === "string" ? arg : arg.serialize()));
202 const copyOfState = { ...this.state }; // to prevent writes
203 const stub = new TestChaincodeStub([method, ...argsSerialized], copyOfState, {});
204 stub.mockCreator(this.callingUserMsp, this.callingUser);
205 const rawResponse = await this.chaincode.Invoke(stub);
206
207 if (rawResponse.status === 200) {
208 const stringResponse = rawResponse.payload.toString();
209
210 return JSON.parse(stringResponse) as T;
211 } else {
212 throw rawResponse.message;
213 }
214 }
215
216 /**
217 * Gets a direct reference to a contract instance for low-level testing.

Callers

nothing calls this directly

Calls 4

mockCreatorMethod · 0.95
serializeMethod · 0.80
InvokeMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected