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

Method invoke

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

* Invokes a chaincode method with write capabilities (submit transaction). * Changes made during invocation are persisted to the state. * * @template T - Expected return type of the invocation * @param method - Name of the contract method to invoke * @param args - Arguments to pass to

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

Source from the content-addressed store, hash-verified

166 * @throws Error if the invocation fails
167 */
168 public async invoke<T = InvokeResponse>(
169 method: string,
170 ...args: (string | { serialize: () => string })[]
171 ): Promise<T> {
172 const argsSerialized = args.map((arg) => (typeof arg === "string" ? arg : arg.serialize()));
173 const newWrites = {};
174 const stub = new TestChaincodeStub([method, ...argsSerialized], this.state, newWrites);
175 stub.mockCreator(this.callingUserMsp, this.callingUser);
176 const rawResponse = await this.chaincode.Invoke(stub);
177
178 if (rawResponse.status === 200) {
179 const stringResponse = rawResponse.payload.toString();
180 this.writes.push(newWrites);
181 return JSON.parse(stringResponse) as T;
182 } else {
183 throw rawResponse.message;
184 }
185 }
186
187 /**
188 * Queries a chaincode method with read-only access (evaluate transaction).

Calls 4

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

Tested by 8

createTestFixtureFunction · 0.76
testFnFunction · 0.76
createRegisteredUserFunction · 0.64
getPublicKeyFunction · 0.64
getUserProfileFunction · 0.64
getMyProfileFunction · 0.64