Skip to content

Commit f403298

Browse files
Transition network detection in the network test to be a O(1) check
1 parent c348dd8 commit f403298

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

sdk/tests/network-client.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ async function expectThrows(f: () => Promise<any>): Promise<void> {
3535

3636
describe('NodeConnection', () => {
3737
let connection: AleoNetworkClient;
38+
let network: string;
3839
let windowFetchSpy: sinon.SinonSpy;
3940

4041
beforeEach(() => {
4142
connection = new AleoNetworkClient("https://api.explorer.provable.com/v1");
43+
if (connection.host === "https://api.explorer.provable.com/v1/testnet") {
44+
network = "testnet";
45+
} else {
46+
network = "mainnet";
47+
}
4248
windowFetchSpy = sinon.spy(globalThis, 'fetch');
4349
});
4450

@@ -237,8 +243,7 @@ describe('NodeConnection', () => {
237243

238244
describe('Test API methods that return wasm objects', () => {
239245
it('Plaintext returned from the API should have expected properties', async () => {
240-
const transactions = await connection.getTransactions(27400);
241-
if (transactions.length > 0) {
246+
if (network === "testnet") {
242247
// Check a struct variant of a plaintext object.
243248
let plaintext = await connection.getProgramMappingPlaintext("credits.aleo", "committee", "aleo17m3l8a4hmf3wypzkf5lsausfdwq9etzyujd0vmqh35ledn2sgvqqzqkqal");
244249
expect(plaintext.plaintextType()).equal("struct");
@@ -259,8 +264,7 @@ describe('NodeConnection', () => {
259264

260265
it('should have correct data within the wasm object and summary object for an execution transaction', async () => {
261266
// Get the first transaction at block 24700 on testnet.
262-
const transactions = await connection.getTransactions(27400);
263-
if (transactions.length > 0) {
267+
if (network === "testnet") {
264268
const transaction = await connection.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
265269
const transition = <Transition>transaction.transitions()[0];
266270
const summary = <TransactionObject>transaction.summary(true);
@@ -325,8 +329,7 @@ describe('NodeConnection', () => {
325329

326330
it('should have correct data within the wasm object and summary object for a deployment transaction', async () => {
327331
// Get the deployment transaction for token_registry.aleo
328-
const transactions = await connection.getTransactions(27400);
329-
if (transactions.length === 0) {
332+
if (network === "mainnet") {
330333
const transaction = await connection.getTransactionObject("at15mwg0jyhvpjjrfxwrlwzn8puusnmy7r3xzvpjht4e5gzgnp68q9qd0qqec");
331334
const summary = <TransactionObject>transaction.summary(true);
332335
const deployment = <DeploymentObject>summary.deployment;
@@ -352,8 +355,8 @@ describe('NodeConnection', () => {
352355
});
353356

354357
it('Should give the correct JSON response when requesting multiple transactions', async () => {
355-
const transactions = await connection.getTransactions(27400);
356-
if (transactions.length > 0) {
358+
if (network === "testnet") {
359+
const transactions = await connection.getTransactions(27400);
357360
expect(transactions.length).equal(4);
358361
expect(transactions[0].status).equal("accepted");
359362
expect(transactions[0].type).equal("execute");

0 commit comments

Comments
 (0)