Skip to content

Commit cd7f238

Browse files
use configured url and add testnet txs
1 parent e0afbb2 commit cd7f238

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

sdk/src/network-client.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,12 +1214,18 @@ class AleoNetworkClient {
12141214
}
12151215

12161216
try {
1217-
const res = await fetch(`https://api.explorer.provable.com/v1/mainnet/transaction/confirmed/${transactionId}`);
1218-
1217+
const res = await fetch(`${this.host}/transaction/confirmed/${transactionId}`, {
1218+
headers: this.headers
1219+
});
12191220
if (!res.ok) {
1220-
const text = await res.text();
1221+
let text = "";
1222+
try {
1223+
text = await res.text();
1224+
console.warn("Response text from server:", text);
1225+
} catch (err) {
1226+
console.warn("Failed to read response text:", err);
1227+
}
12211228

1222-
// Break early if the response indicates an invalid format
12231229
if (res.status >= 400 && res.status < 500 && text.includes("Invalid URL")) {
12241230
clearInterval(interval);
12251231
return reject(new Error(`Malformed transaction ID: ${text}`));

sdk/tests/network-client.test.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,45 @@ describe('NodeConnection', () => {
199199
});
200200

201201
describe('waitForTransactionConfirmation', () => {
202+
const mainnetAcceptedTx = "at1dl9lze8wscct0dee8x9tjnfmpjvj33hh23jcnp5f0ywjn5552yrsperzl9";
203+
const mainnetRejectedTx = "at1x5ed0pyjpt3770e0m60psvdvqeww5z5f32t7velrmrjfhvzgysxqll4g6a";
204+
const testnetAcceptedTx = "at1aknmzq2k2ktuy8l55hthlzkues98fuye0s05nnxfp86ruukz5grsrrujgv";
205+
const testnetRejectedTx = "at1xmjjt0sr2nv2ah38t7j9hmema28w7xfdckz9slyfjqjqywpudvxqdlxvd3";
206+
const invalidTx = "at1dl9lze8wscct0dee8x9tjnfmpj12345678jcnp5f0ywjn5552yrsperzl9";
207+
208+
const host = "https://api.explorer.provable.com/v1";
209+
210+
function getTxId(connection: AleoNetworkClient, type: "accepted" | "rejected") {
211+
const isTestnet = connection.host.includes("/testnet");
212+
return type === "accepted"
213+
? (isTestnet ? testnetAcceptedTx : mainnetAcceptedTx)
214+
: (isTestnet ? testnetRejectedTx : mainnetRejectedTx);
215+
}
216+
202217
it('should return accepted for a valid tx ID', async () => {
203-
const connection = new AleoNetworkClient("https://api.explorer.provable.com/");
204-
const status = await connection.waitForTransactionConfirmation("at1dl9lze8wscct0dee8x9tjnfmpjvj33hh23jcnp5f0ywjn5552yrsperzl9");
218+
const connection = new AleoNetworkClient(host);
219+
const txId = getTxId(connection, "accepted");
220+
const status = await connection.waitForTransactionConfirmation(txId);
205221
expect(status).to.equal("accepted");
206222
});
207-
223+
208224
it('should return rejected for a rejected tx ID', async () => {
209-
const connection = new AleoNetworkClient("https://api.explorer.provable.com/");
210-
const status = await connection.waitForTransactionConfirmation("at1x5ed0pyjpt3770e0m60psvdvqeww5z5f32t7velrmrjfhvzgysxqll4g6a");
225+
const connection = new AleoNetworkClient(host);
226+
const txId = getTxId(connection, "rejected");
227+
const status = await connection.waitForTransactionConfirmation(txId);
211228
expect(status).to.equal("rejected");
212229
});
213230

214231
it('should throw for a malformed tx ID', async () => {
215-
const connection = new AleoNetworkClient("https://api.explorer.provable.com/");
216-
try {
217-
await connection.waitForTransactionConfirmation("at1dl9lze8wscct0dee8x9tjnfmpj12345678jcnp5f0ywjn5552yrsperzl9");
218-
throw new Error("Expected waitForTransactionConfirmation to throw");
219-
} catch (err: any) {
220-
expect(err.message).to.include("Malformed transaction ID");
221-
expect(err.message).to.include("Invalid URL");
222-
}
223-
});
232+
const connection = new AleoNetworkClient(host);
233+
try {
234+
await connection.waitForTransactionConfirmation(invalidTx);
235+
throw new Error("Expected waitForTransactionConfirmation to throw");
236+
} catch (err: any) {
237+
expect(err.message).to.include("Malformed transaction ID");
238+
expect(err.message).to.include("Invalid URL");
239+
}
240+
});
224241
});
225242

226243
describe('findUnspentRecords', () => {

0 commit comments

Comments
 (0)