Skip to content

Commit

Permalink
Read local testnet URLs from env vars if available
Browse files Browse the repository at this point in the history
  • Loading branch information
banool committed Apr 3, 2024
1 parent b9e9413 commit a39c36f
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 118 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/ans/ans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
} from "../../../src";
import { isValidANSName } from "../../../src/internal/ans";
import { generateTransaction } from "../../../src/internal/transactionSubmission";
import { getAptosClient } from "../helper";
import { publishAnsContract } from "./publishANSContracts";

// This isn't great, we should look into deploying outside the test
jest.setTimeout(20000);

describe("ANS", () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos, config } = getAptosClient();

let changeExpirationDate: (
tokenMode: 0 | 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/api/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
SigningSchemeInput,
U64,
} from "../../../src";
import { getAptosClient } from "../helper";

describe("account api", () => {
const FUND_AMOUNT = 100_000_000;

describe("fetch data", () => {
test("it fetches account data", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
const data = await aptos.getAccountInfo({
accountAddress: "0x1",
});
Expand Down
7 changes: 3 additions & 4 deletions tests/e2e/api/coin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TransactionPayloadEntryFunction,
} from "../../../src";
import { FUND_AMOUNT, longTestTimeout } from "../../unit/helper";
import { getAptosClient } from "../helper";

describe("coin", () => {
test("it generates a transfer coin transaction with AptosCoin coin type", async () => {
Expand Down Expand Up @@ -41,8 +42,7 @@ describe("coin", () => {
});

test("it generates a transfer coin transaction with a custom coin type", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
const sender = Account.generate();
const recipient = Account.generate();
await aptos.fundAccount({ accountAddress: sender.accountAddress, amount: FUND_AMOUNT });
Expand Down Expand Up @@ -74,8 +74,7 @@ describe("coin", () => {
test(
"it transfers APT coin amount from sender to recipient",
async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
const sender = Account.generate();
const recipient = Account.generate();

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/api/collection.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Account, Aptos, AptosConfig, Network } from "../../../src";
import { Account } from "../../../src";
import { FUND_AMOUNT } from "../../unit/helper";
import { getAptosClient } from "../helper";

// use it here since all tests use the same configuration
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

// Disable these tests for now until we can test against LOCAL
describe("Collection", () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/api/digitalAsset.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Account, Aptos, AptosConfig, Bool, MoveString, MoveVector, Network, U8 } from "../../../src";
import { Account, Bool, MoveString, MoveVector, U8 } from "../../../src";
import { FUND_AMOUNT } from "../../unit/helper";
import { getAptosClient } from "../helper";

const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const collectionName = "Test Collection";
const collectionDescription = "My new collection!";
Expand Down
18 changes: 7 additions & 11 deletions tests/e2e/api/event.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Account, Aptos, AptosConfig, Network } from "../../../src";
import { Account } from "../../../src";
import { FUND_AMOUNT, longTestTimeout } from "../../unit/helper";
import { getAptosClient } from "../helper";

describe("Event", () => {
test("it should get transaction fee statement module event by event type", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const testAccount = Account.generate();
await aptos.fundAccount({ accountAddress: testAccount.accountAddress, amount: FUND_AMOUNT });
Expand All @@ -20,8 +20,7 @@ describe("Event", () => {
});

test("it should get fund event by creation number and address", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const testAccount = Account.generate();
await aptos.fundAccount({ accountAddress: testAccount.accountAddress, amount: FUND_AMOUNT });
Expand All @@ -35,8 +34,7 @@ describe("Event", () => {
});

test("it should get fund event by event type and address", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const testAccount = Account.generate();
await aptos.fundAccount({
Expand All @@ -53,8 +51,7 @@ describe("Event", () => {
});

test("it should get all events", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const testAccount = Account.generate();
await aptos.fundAccount({
Expand All @@ -70,8 +67,7 @@ describe("Event", () => {
test(
"it should filter events",
async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const testAccount1 = Account.generate();
const testAccount2 = Account.generate();
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/api/faucet.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Aptos, AptosConfig, Account, Network } from "../../../src";
import { Account } from "../../../src";
import { FUND_AMOUNT } from "../../unit/helper";
import { getAptosClient } from "../helper";

describe("Faucet", () => {
test("it should fund an account", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
const testAccount = Account.generate();

// Fund the account
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/api/fungibleAsset.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Account, Aptos, AptosConfig, Network, APTOS_COIN } from "../../../src";
import { Account, APTOS_COIN } from "../../../src";
import { getAptosClient } from "../helper";

const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

describe("FungibleAsset", () => {
test("it should fetch fungible asset metadata", async () => {
Expand Down
38 changes: 14 additions & 24 deletions tests/e2e/api/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,37 @@
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig, Aptos, Network, GraphqlQuery, ProcessorType, InputViewFunctionData } from "../../../src";
import { getAptosClient } from "../helper";

describe("general api", () => {
test("it fetches ledger info", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
const ledgerInfo = await aptos.getLedgerInfo();
expect(ledgerInfo.chain_id).toBe(4);
});

test("it fetches chain id", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
const chainId = await aptos.getChainId();
expect(chainId).toBe(4);
});

test("it fetches block data by block height", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
const blockHeight = 1;
const blockData = await aptos.getBlockByHeight({ blockHeight });
expect(blockData.block_height).toBe(blockHeight.toString());
});

test("it fetches block data by block version", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
const blockVersion = 1;
const blockData = await aptos.getBlockByVersion({ ledgerVersion: blockVersion });
expect(blockData.block_height).toBe(blockVersion.toString());
});

test("it fetches table item data", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();
type Supply = {
supply: {
vec: [
Expand Down Expand Up @@ -96,10 +92,10 @@ describe("general api", () => {
const topUserTransactions = await aptos.getChainTopUserTransactions({ limit: 3 });
expect(topUserTransactions.length).toEqual(3);
});

describe("View functions", () => {
test("it fetches view function data", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const payload: InputViewFunctionData = {
function: "0x1::chain_id::get",
Expand All @@ -111,8 +107,7 @@ describe("general api", () => {
});

test("it fetches view function with a type", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const payload: InputViewFunctionData = {
function: "0x1::chain_id::get",
Expand All @@ -124,8 +119,7 @@ describe("general api", () => {
});

test("it fetches view function with bool", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const payload: InputViewFunctionData = {
function: "0x1::account::exists_at",
Expand All @@ -147,8 +141,7 @@ describe("general api", () => {
});

test("it fetches view function with address input and different output types", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const payload: InputViewFunctionData = {
function: "0x1::account::get_sequence_number",
Expand All @@ -170,8 +163,7 @@ describe("general api", () => {
});

test("it fetches view functions with generics", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const payload: InputViewFunctionData = {
function: "0x1::coin::symbol",
Expand Down Expand Up @@ -200,8 +192,7 @@ describe("general api", () => {
});

test("view functions that fail in the VM fail here", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const payload: InputViewFunctionData = {
function: "0x1::account::get_sequence_number",
Expand All @@ -213,8 +204,7 @@ describe("general api", () => {
});

test("it should get the processor statuses for one", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

const processor = await aptos.getProcessorStatus(ProcessorType.ACCOUNT_TRANSACTION_PROCESSOR);
expect(processor.processor).toEqual(ProcessorType.ACCOUNT_TRANSACTION_PROCESSOR);
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/api/paginateQuery.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AptosConfig, Network, Aptos } from "../../../src";
import { getAptosClient } from "../helper";

describe("PaginateQuery", () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

test("it should paginate correctly on indexer queries", async () => {
const events = await aptos.getEvents();
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/api/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig, Aptos, Network, Account, TransactionResponse, U64 } from "../../../src";
import { Account, TransactionResponse, U64 } from "../../../src";
import { FUND_AMOUNT } from "../../unit/helper";
import { getAptosClient } from "../helper";

// use it here since all tests use the same configuration
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const { aptos } = getAptosClient();

describe("transaction api", () => {
test("it queries for the network estimated gas price", async () => {
Expand Down
7 changes: 2 additions & 5 deletions tests/e2e/client/aptosRequest.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import {
Account,
Aptos,
AptosApiError,
AptosApiType,
AptosConfig,
aptosRequest,
generateSignedTransaction,
GraphqlQuery,
Network,
NetworkToIndexerAPI,
NetworkToNodeAPI,
U64,
} from "../../../src";
import { VERSION } from "../../../src/version";
import { longTestTimeout } from "../../unit/helper";
import { getAptosClient } from "../helper";
import { singleSignerScriptBytecode } from "../transaction/helper";

const config = new AptosConfig({ network: Network.LOCAL });
const { aptos, config } = getAptosClient();

describe("aptos request", () => {
describe("headers", () => {
test(
"call should include all expected headers",
async () => {
const aptos = new Aptos(config);
const sender = Account.generate();
const receiverAccounts = Account.generate();
await aptos.fundAccount({ accountAddress: sender.accountAddress, amount: 100_000_000 });
Expand Down
Loading

0 comments on commit a39c36f

Please sign in to comment.