Skip to content

Commit 6bcda24

Browse files
committed
test: fix json parse error
1 parent 5716bd6 commit 6bcda24

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

package-lock.json

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/src/cli.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,8 @@ async function contractFunctionCall(_network: CLINetworkAdapter, args: string[])
890890

891891
try {
892892
const response = await broadcastTransaction({ transaction: tx, network });
893-
if ('error' in response) {
894-
return JSONStringify(response);
895-
}
893+
if (response.hasOwnProperty('error')) return JSONStringify(response);
894+
896895
return JSONStringify({
897896
txid: `0x${tx.txid()}`,
898897
transaction: generateExplorerTxPageUrl(tx.txid(), network),

packages/cli/tests/cli.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('Contract function call', () => {
115115
const txid = '0x6c764e276b500babdac6cec159667f4b68938d31eee82419473a418222af7d5d';
116116
fetchMock.once(JSON.stringify(TEST_ABI)).once(txid);
117117

118-
const result = await contractFunctionCall(testnetNetwork, args);
118+
const result = JSON.parse(await contractFunctionCall(testnetNetwork, args));
119119

120120
expect(result.txid).toEqual(txid);
121121
});
@@ -136,7 +136,7 @@ describe('Contract function call', () => {
136136
const txid = '0x97f41dfa44a5833acd9ca30ffe31d7137623c0e31a5c6467daeed8e61a03f51c';
137137
fetchMock.once(JSON.stringify(TEST_ABI)).once(txid);
138138

139-
const result = await contractFunctionCall(testnetNetwork, args);
139+
const result = JSON.parse(await contractFunctionCall(testnetNetwork, args));
140140

141141
expect(result.txid).toEqual(txid);
142142
});
@@ -157,7 +157,7 @@ describe('Contract function call', () => {
157157
const txid = '0x5fc468f21345c5ecaf1c007fce9630d9a79ec1945ed8652cc3c42fb542e35fe2';
158158
fetchMock.once(JSON.stringify(TEST_ABI)).once(txid);
159159

160-
const result = await contractFunctionCall(testnetNetwork, args);
160+
const result = JSON.parse(await contractFunctionCall(testnetNetwork, args));
161161

162162
expect(result.txid).toEqual(txid);
163163
});
@@ -182,7 +182,7 @@ describe('Contract function call', () => {
182182
const txid = '0x94b1cfab79555b8c6725f19e4fcd6268934d905578a3e8ef7a1e542b931d3676';
183183
fetchMock.once(JSON.stringify(TEST_ABI)).once(txid);
184184

185-
const result = await contractFunctionCall(testnetNetwork, args);
185+
const result = JSON.parse(await contractFunctionCall(testnetNetwork, args));
186186

187187
expect(result.txid).toEqual(txid);
188188
});
@@ -205,7 +205,7 @@ describe('Contract function call', () => {
205205
const txid = '0x6b6cd5bfb44c46a68090f0c5f659e9cc02518eafab67b0b740e1e77a55bbf284';
206206
fetchMock.once(JSON.stringify(TEST_ABI)).once(txid);
207207

208-
const result = await contractFunctionCall(testnetNetwork, args);
208+
const result = JSON.parse(await contractFunctionCall(testnetNetwork, args));
209209

210210
expect(result.txid).toEqual(txid);
211211
});

packages/cli/tests/direct-function-args.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ describe('Contract Function Call with Direct Arguments', () => {
127127
// Validate the transaction
128128
expect(capturedTxHex).toBeTruthy();
129129
expect(typeof capturedTxHex).toBe('string');
130-
expect(capturedTxHex.length).toBeGreaterThan(100); // Reasonable transaction length
131130

132131
// Compare the captured transaction hex with our expected transaction
133132
expect(capturedTxHex).toEqual(expectedTxHex);

0 commit comments

Comments
 (0)