* 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 })[]
)
| 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. |
nothing calls this directly
no test coverage detected