Skip to content

Commit c0045d0

Browse files
refactor waitForTransactionConfirmation return + test updates
1 parent cd7f238 commit c0045d0

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

sdk/src/network-client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ class AleoNetworkClient {
12011201
transactionId: string,
12021202
checkInterval: number = 2000,
12031203
timeout: number = 45000
1204-
): Promise<"accepted" | "rejected"> {
1204+
): Promise<ConfirmedTransactionJSON> {
12051205
const startTime = Date.now();
12061206

12071207
return new Promise((resolve, reject) => {
@@ -1236,16 +1236,16 @@ class AleoNetworkClient {
12361236
return;
12371237
}
12381238

1239-
const data = await res.json();
1240-
1239+
const text = await res.text();
1240+
const data = parseJSON(text);
12411241
if (data?.status === "accepted") {
12421242
clearInterval(interval);
1243-
return resolve("accepted");
1243+
return resolve(data);
12441244
}
12451245

12461246
if (data?.status === "rejected") {
12471247
clearInterval(interval);
1248-
return resolve("rejected");
1248+
return reject(new Error(`Transaction ${transactionId} was rejected by the network`));
12491249
}
12501250

12511251
// no status? keep polling

sdk/tests/network-client.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,23 @@ describe('NodeConnection', () => {
214214
: (isTestnet ? testnetRejectedTx : mainnetRejectedTx);
215215
}
216216

217-
it('should return accepted for a valid tx ID', async () => {
217+
it('should return confirmed transaction data for an accepted tx ID', async () => {
218218
const connection = new AleoNetworkClient(host);
219219
const txId = getTxId(connection, "accepted");
220-
const status = await connection.waitForTransactionConfirmation(txId);
221-
expect(status).to.equal("accepted");
220+
const data = await connection.waitForTransactionConfirmation(txId);
221+
expect(data.status).to.equal("accepted");
222+
expect(data.type).to.be.a("string");
222223
});
223224

224-
it('should return rejected for a rejected tx ID', async () => {
225+
it('should throw for a rejected tx ID', async () => {
225226
const connection = new AleoNetworkClient(host);
226227
const txId = getTxId(connection, "rejected");
227-
const status = await connection.waitForTransactionConfirmation(txId);
228-
expect(status).to.equal("rejected");
228+
try {
229+
await connection.waitForTransactionConfirmation(txId);
230+
throw new Error("Expected waitForTransactionConfirmation to throw for rejected tx");
231+
} catch (err: any) {
232+
expect(err.message).to.include("was rejected by the network");
233+
}
229234
});
230235

231236
it('should throw for a malformed tx ID', async () => {

0 commit comments

Comments
 (0)