From fa7028dca50ac89a2d93871e2c361b0baf9902e0 Mon Sep 17 00:00:00 2001 From: Daniel Porteous Date: Thu, 4 Apr 2024 15:59:22 +0100 Subject: [PATCH] Read local testnet URLs from env vars if available --- tests/e2e/ans/ans.test.ts | 4 +- tests/e2e/api/account.test.ts | 4 +- tests/e2e/api/coin.test.ts | 7 ++-- tests/e2e/api/collection.test.ts | 6 +-- tests/e2e/api/digitalAsset.test.ts | 6 +-- tests/e2e/api/event.test.ts | 18 ++++----- tests/e2e/api/faucet.test.ts | 6 +-- tests/e2e/api/fungibleAsset.test.ts | 6 +-- tests/e2e/api/general.test.ts | 38 +++++++------------ tests/e2e/api/paginateQuery.test.ts | 5 +-- tests/e2e/api/transaction.test.ts | 6 +-- tests/e2e/client/aptosRequest.test.ts | 9 ++--- tests/e2e/client/customClient.test.ts | 17 +++------ tests/e2e/client/get.test.ts | 4 +- tests/e2e/client/post.test.ts | 4 +- tests/e2e/helper.ts | 29 ++++++++++++++ .../transaction/generateTransaction.test.ts | 7 +--- tests/e2e/transaction/signTransaction.test.ts | 7 +--- .../transaction/transactionArguments.test.ts | 7 +--- .../transaction/transactionBuilder.test.ts | 8 ++-- .../transaction/transactionSimulation.test.ts | 6 +-- .../transaction/transactionSubmission.test.ts | 8 ++-- .../accountSequenceNumber.test.ts | 8 +--- .../transactionWorker.test.ts | 7 +--- 24 files changed, 108 insertions(+), 119 deletions(-) create mode 100644 tests/e2e/helper.ts diff --git a/tests/e2e/ans/ans.test.ts b/tests/e2e/ans/ans.test.ts index f4c05ad82..8e2b3a3df 100644 --- a/tests/e2e/ans/ans.test.ts +++ b/tests/e2e/ans/ans.test.ts @@ -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, diff --git a/tests/e2e/api/account.test.ts b/tests/e2e/api/account.test.ts index 30731ed1f..84f77a10e 100644 --- a/tests/e2e/api/account.test.ts +++ b/tests/e2e/api/account.test.ts @@ -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", }); diff --git a/tests/e2e/api/coin.test.ts b/tests/e2e/api/coin.test.ts index b3f713251..69f0e6e36 100644 --- a/tests/e2e/api/coin.test.ts +++ b/tests/e2e/api/coin.test.ts @@ -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 () => { @@ -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 }); @@ -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(); diff --git a/tests/e2e/api/collection.test.ts b/tests/e2e/api/collection.test.ts index c7b7fc1c7..9f90b869e 100644 --- a/tests/e2e/api/collection.test.ts +++ b/tests/e2e/api/collection.test.ts @@ -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", () => { diff --git a/tests/e2e/api/digitalAsset.test.ts b/tests/e2e/api/digitalAsset.test.ts index 12de91dc4..8fe3314fd 100644 --- a/tests/e2e/api/digitalAsset.test.ts +++ b/tests/e2e/api/digitalAsset.test.ts @@ -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!"; diff --git a/tests/e2e/api/event.test.ts b/tests/e2e/api/event.test.ts index 821a4305d..53bf00517 100644 --- a/tests/e2e/api/event.test.ts +++ b/tests/e2e/api/event.test.ts @@ -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 }); @@ -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 }); @@ -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({ @@ -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({ @@ -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(); diff --git a/tests/e2e/api/faucet.test.ts b/tests/e2e/api/faucet.test.ts index 4ef8d7f53..6d64fb741 100644 --- a/tests/e2e/api/faucet.test.ts +++ b/tests/e2e/api/faucet.test.ts @@ -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 diff --git a/tests/e2e/api/fungibleAsset.test.ts b/tests/e2e/api/fungibleAsset.test.ts index 4ea81cf7a..e4d18b24e 100644 --- a/tests/e2e/api/fungibleAsset.test.ts +++ b/tests/e2e/api/fungibleAsset.test.ts @@ -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 () => { diff --git a/tests/e2e/api/general.test.ts b/tests/e2e/api/general.test.ts index f8ffe629a..70dbc7370 100644 --- a/tests/e2e/api/general.test.ts +++ b/tests/e2e/api/general.test.ts @@ -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: [ @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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); diff --git a/tests/e2e/api/paginateQuery.test.ts b/tests/e2e/api/paginateQuery.test.ts index dc96b5d40..c69d54d26 100644 --- a/tests/e2e/api/paginateQuery.test.ts +++ b/tests/e2e/api/paginateQuery.test.ts @@ -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(); diff --git a/tests/e2e/api/transaction.test.ts b/tests/e2e/api/transaction.test.ts index 7f227bc86..123eee82a 100644 --- a/tests/e2e/api/transaction.test.ts +++ b/tests/e2e/api/transaction.test.ts @@ -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 () => { diff --git a/tests/e2e/client/aptosRequest.test.ts b/tests/e2e/client/aptosRequest.test.ts index 4c7617407..2997ae4db 100644 --- a/tests/e2e/client/aptosRequest.test.ts +++ b/tests/e2e/client/aptosRequest.test.ts @@ -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 }); @@ -99,7 +96,7 @@ describe("aptos request", () => { try { const response = await aptosRequest( { - url: `${NetworkToNodeAPI[config.network]}`, + url: `${NetworkToNodeAPI[config.network]}`, // todo, this should be config.fullnode instead. method: "GET", path: "accounts/0x1", originMethod: "test fullnode 200 status", diff --git a/tests/e2e/client/customClient.test.ts b/tests/e2e/client/customClient.test.ts index f7cf1dfea..aab931a8e 100644 --- a/tests/e2e/client/customClient.test.ts +++ b/tests/e2e/client/customClient.test.ts @@ -1,7 +1,4 @@ import { - AptosConfig, - Aptos, - Network, getAptosFullNode, Account, postAptosFaucet, @@ -11,23 +8,22 @@ import { generateSignedTransaction, } from "../../../src"; import { customClient } from "../../unit/helper"; +import { getAptosClient } from "../helper"; describe("custom client", () => { test("it uses default client when it doesnt set in AptosConfig", () => { - const config = new AptosConfig(); - const aptos = new Aptos(config); + const { aptos } = getAptosClient(); expect(aptos.config.client.provider).toBeInstanceOf(Function); expect(aptos.config.client.provider.name).toBe("aptosClient"); }); test("it uses a custom client set in AptosConfig", () => { - const config = new AptosConfig({ client: { provider: customClient } }); - const aptos = new Aptos(config); + const { aptos } = getAptosClient({ client: { provider: customClient } }); expect(aptos.config.client.provider).toBeInstanceOf(Function); expect(aptos.config.client.provider.name).toBe("customClient"); }); test("it uses custom client for fetch queries", async () => { - const config = new AptosConfig({ network: Network.LOCAL, client: { provider: customClient } }); + const { config } = getAptosClient({ client: { provider: customClient } }); const response = await getAptosFullNode<{ headers?: { customClient?: any } }, {}>({ aptosConfig: config, originMethod: "getInfo", @@ -37,7 +33,7 @@ describe("custom client", () => { }); test("it uses custom client for post queries", async () => { - const config = new AptosConfig({ network: Network.LOCAL, client: { provider: customClient } }); + const { config } = getAptosClient({ client: { provider: customClient } }); const account = Account.generate(); const response = await postAptosFaucet<{ headers?: { customClient?: any } }, {}>({ aptosConfig: config, @@ -52,8 +48,7 @@ describe("custom client", () => { }); test("it uses custom client for transaction submission", async () => { - const config = new AptosConfig({ network: Network.LOCAL, client: { provider: customClient } }); - const aptos = new Aptos(config); + const { aptos, config } = getAptosClient({ client: { provider: customClient } }); const account = Account.generate(); const recipient = Account.generate(); await aptos.fundAccount({ accountAddress: account.accountAddress, amount: 100_000_000 }); diff --git a/tests/e2e/client/get.test.ts b/tests/e2e/client/get.test.ts index 771ecbbbd..77738a3e8 100644 --- a/tests/e2e/client/get.test.ts +++ b/tests/e2e/client/get.test.ts @@ -1,6 +1,7 @@ import { AptosConfig, LedgerInfo, getAptosFullNode } from "../../../src"; +import { getAptosClient } from "../helper"; -const aptosConfig = new AptosConfig({ +const partialConfig = new AptosConfig({ clientConfig: { HEADERS: { clientConfig: "clientConfig-header" }, API_KEY: "api-key", @@ -9,6 +10,7 @@ const aptosConfig = new AptosConfig({ indexerConfig: { HEADERS: { indexerHeader: "indexer-header" } }, faucetConfig: { HEADERS: { faucetHeader: "faucet-header" }, AUTH_TOKEN: "auth-token" }, }); +const { config: aptosConfig } = getAptosClient(partialConfig); // All tests are expected to catch becuase server call will fail // due to a fake API_KEY. But that is ok because we just want diff --git a/tests/e2e/client/post.test.ts b/tests/e2e/client/post.test.ts index a3cd1a53e..26556d5ec 100644 --- a/tests/e2e/client/post.test.ts +++ b/tests/e2e/client/post.test.ts @@ -10,8 +10,9 @@ import { } from "../../../src"; import { GetChainTopUserTransactionsQuery } from "../../../src/types/generated/operations"; import { GetChainTopUserTransactions } from "../../../src/types/generated/queries"; +import { getAptosClient } from "../helper"; -const aptosConfig = new AptosConfig({ +const partialConfig = new AptosConfig({ clientConfig: { HEADERS: { clientConfig: "clientConfig-header" }, API_KEY: "api-key", @@ -20,6 +21,7 @@ const aptosConfig = new AptosConfig({ indexerConfig: { HEADERS: { indexerHeader: "indexer-header" } }, faucetConfig: { HEADERS: { faucetHeader: "faucet-header" }, AUTH_TOKEN: "auth-token" }, }); +const { config: aptosConfig } = getAptosClient(partialConfig); // All tests are expected to catch becuase server call will fail // due to a fake API_KEY. But that is ok because we just want diff --git a/tests/e2e/helper.ts b/tests/e2e/helper.ts new file mode 100644 index 000000000..940660ef8 --- /dev/null +++ b/tests/e2e/helper.ts @@ -0,0 +1,29 @@ +import { Aptos, AptosConfig, Network, NetworkToNetworkName } from "../../src"; + +/** + * Use this function whenever you want an Aptos client. + * + * By default it uses Network.LOCAL. You can change this in one of two ways: + * + * 1. If you set the APTOS_NETWORK env var, it will use that Network. For example, + * export APTOS_NETWORK=devnet. + * 2. For more control, you can set the APTOS_NODE_API_URL, APTOS_INDEXER_API_URL, and + * APTOS_FAUCET_API_URL env vars. + * + * The APTOS_NETWORK env var is applied first, followed by the others. So if you set + * APTOS_NETWORK=devnet and APTOS_NODE_API_URL=http://localhost:8080, it will use the + * given URL for the node API and the the default URLs for devnet for the other APIs. + */ +export function getAptosClient(additionalConfig?: Partial): { aptos: Aptos; config: AptosConfig } { + const networkRaw = process.env.APTOS_NETWORK; + const network = networkRaw ? NetworkToNetworkName[networkRaw] : Network.LOCAL; + const config = new AptosConfig({ + network, + fullnode: process.env.APTOS_NODE_API_URL, + indexer: process.env.APTOS_INDEXER_API_URL, + faucet: process.env.APTOS_FAUCET_API_URL, + ...additionalConfig, + }); + const aptos = new Aptos(config); + return { aptos, config }; +} diff --git a/tests/e2e/transaction/generateTransaction.test.ts b/tests/e2e/transaction/generateTransaction.test.ts index 128b7cfcb..045784810 100644 --- a/tests/e2e/transaction/generateTransaction.test.ts +++ b/tests/e2e/transaction/generateTransaction.test.ts @@ -1,7 +1,4 @@ import { - AptosConfig, - Network, - Aptos, Account, Deserializer, U64, @@ -14,11 +11,11 @@ import { TypeTagAddress, } from "../../../src"; import { longTestTimeout } from "../../unit/helper"; +import { getAptosClient } from "../helper"; import { fundAccounts, singleSignerScriptBytecode } from "./helper"; describe("generate transaction", () => { - const config = new AptosConfig({ network: Network.LOCAL }); - const aptos = new Aptos(config); + const { aptos } = getAptosClient(); const senderAccount = Account.generate(); const recieverAccounts = [Account.generate(), Account.generate()]; const secondarySignerAccount = Account.generate(); diff --git a/tests/e2e/transaction/signTransaction.test.ts b/tests/e2e/transaction/signTransaction.test.ts index c7538c8e7..a1b7dbf0b 100644 --- a/tests/e2e/transaction/signTransaction.test.ts +++ b/tests/e2e/transaction/signTransaction.test.ts @@ -1,7 +1,4 @@ import { - AptosConfig, - Network, - Aptos, Account, Deserializer, U64, @@ -11,10 +8,10 @@ import { AccountAuthenticatorSingleKey, } from "../../../src"; import { longTestTimeout } from "../../unit/helper"; +import { getAptosClient } from "../helper"; import { fundAccounts, publishTransferPackage, singleSignerScriptBytecode } from "./helper"; -const config = new AptosConfig({ network: Network.LOCAL }); -const aptos = new Aptos(config); +const { aptos } = getAptosClient(); describe("sign transaction", () => { const contractPublisherAccount = Account.generate(); diff --git a/tests/e2e/transaction/transactionArguments.test.ts b/tests/e2e/transaction/transactionArguments.test.ts index 35797f84c..bd8490f24 100644 --- a/tests/e2e/transaction/transactionArguments.test.ts +++ b/tests/e2e/transaction/transactionArguments.test.ts @@ -3,9 +3,6 @@ import { Account, - AptosConfig, - Network, - Aptos, AccountAddress, Bool, U128, @@ -33,6 +30,7 @@ import { MAX_U64_BIG_INT, MAX_U8_NUMBER, } from "../../../src/bcs/consts"; +import { getAptosClient } from "../helper"; import { fundAccounts, rawTransactionHelper, @@ -53,8 +51,7 @@ jest.setTimeout(10000); // `sender_address: address` or all of the `&signer` addresses: `signer_addresses: vector
` describe("various transaction arguments", () => { - const config = new AptosConfig({ network: Network.LOCAL }); - const aptos = new Aptos(config); + const { aptos } = getAptosClient(); const senderAccount = Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey(PUBLISHER_ACCOUNT_PK), legacy: false, diff --git a/tests/e2e/transaction/transactionBuilder.test.ts b/tests/e2e/transaction/transactionBuilder.test.ts index 1adf115c5..cfc9c9c91 100644 --- a/tests/e2e/transaction/transactionBuilder.test.ts +++ b/tests/e2e/transaction/transactionBuilder.test.ts @@ -3,10 +3,7 @@ import { Account, - Aptos, - AptosConfig, Deserializer, - Network, U64, AccountAddress, EntryFunctionABI, @@ -30,10 +27,11 @@ import { SignedTransaction, } from "../../../src"; import { FUND_AMOUNT, longTestTimeout } from "../../unit/helper"; +import { getAptosClient } from "../helper"; import { fundAccounts, multiSignerScriptBytecode, publishTransferPackage } from "./helper"; -const config = new AptosConfig({ network: Network.LOCAL }); -const aptos = new Aptos(config); +const { aptos, config } = getAptosClient(); + /* eslint-disable max-len */ describe("transaction builder", () => { // TODO: The example function deployed here has all the arguments backwards from normal transfers, we should fix that diff --git a/tests/e2e/transaction/transactionSimulation.test.ts b/tests/e2e/transaction/transactionSimulation.test.ts index a1ad0a0b2..50beea829 100644 --- a/tests/e2e/transaction/transactionSimulation.test.ts +++ b/tests/e2e/transaction/transactionSimulation.test.ts @@ -1,10 +1,10 @@ -import { AptosConfig, Network, Aptos, Account, U64, SigningSchemeInput } from "../../../src"; +import { Account, U64, SigningSchemeInput } from "../../../src"; import { longTestTimeout } from "../../unit/helper"; +import { getAptosClient } from "../helper"; import { fundAccounts, multiSignerScriptBytecode, publishTransferPackage, singleSignerScriptBytecode } from "./helper"; describe("transaction simulation", () => { - const config = new AptosConfig({ network: Network.LOCAL }); - const aptos = new Aptos(config); + const { aptos } = getAptosClient(); const contractPublisherAccount = Account.generate(); const singleSignerED25519SenderAccount = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: false }); const legacyED25519SenderAccount = Account.generate(); diff --git a/tests/e2e/transaction/transactionSubmission.test.ts b/tests/e2e/transaction/transactionSubmission.test.ts index a2691ecb6..ed7a72d0c 100644 --- a/tests/e2e/transaction/transactionSubmission.test.ts +++ b/tests/e2e/transaction/transactionSubmission.test.ts @@ -3,9 +3,6 @@ import { Account, - AptosConfig, - Network, - Aptos, U64, Deserializer, SigningSchemeInput, @@ -18,10 +15,11 @@ import { } from "../../../src"; import { MAX_U64_BIG_INT } from "../../../src/bcs/consts"; import { longTestTimeout } from "../../unit/helper"; +import { getAptosClient } from "../helper"; import { fundAccounts, multiSignerScriptBytecode, publishTransferPackage, singleSignerScriptBytecode } from "./helper"; -const config = new AptosConfig({ network: Network.LOCAL }); -const aptos = new Aptos(config); +const { aptos } = getAptosClient(); + describe("transaction submission", () => { const contractPublisherAccount = Account.generate(); const singleSignerED25519SenderAccount = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: false }); diff --git a/tests/e2e/transactionManagement/accountSequenceNumber.test.ts b/tests/e2e/transactionManagement/accountSequenceNumber.test.ts index 1147d4873..73566a25b 100644 --- a/tests/e2e/transactionManagement/accountSequenceNumber.test.ts +++ b/tests/e2e/transactionManagement/accountSequenceNumber.test.ts @@ -1,14 +1,10 @@ import { longTestTimeout } from "../../unit/helper"; -import { Aptos } from "../../../src/api/aptos"; -import { AptosConfig } from "../../../src/api/aptosConfig"; import { Account } from "../../../src/core"; import * as AccountQueries from "../../../src/internal/account"; - -import { Network } from "../../../src/utils/apiEndpoints"; import { AccountSequenceNumber } from "../../../src/transactions/management/accountSequenceNumber"; +import { getAptosClient } from "../helper"; -const aptosConfig = new AptosConfig({ network: Network.LOCAL }); -const aptos = new Aptos(aptosConfig); +const { aptos, config: aptosConfig } = getAptosClient(); const account = Account.generate(); diff --git a/tests/e2e/transactionManagement/transactionWorker.test.ts b/tests/e2e/transactionManagement/transactionWorker.test.ts index ddf3ba087..dbba48e83 100644 --- a/tests/e2e/transactionManagement/transactionWorker.test.ts +++ b/tests/e2e/transactionManagement/transactionWorker.test.ts @@ -1,14 +1,11 @@ import { longTestTimeout } from "../../unit/helper"; -import { Aptos } from "../../../src/api/aptos"; -import { AptosConfig } from "../../../src/api/aptosConfig"; import { Account } from "../../../src/core"; -import { Network } from "../../../src/utils/apiEndpoints"; import { InputGenerateTransactionPayloadData } from "../../../src/transactions/types"; import { TransactionWorker } from "../../../src/transactions/management/transactionWorker"; import { TransactionResponseType, TypeTagAddress, TypeTagU64 } from "../../../src"; +import { getAptosClient } from "../helper"; -const aptosConfig = new AptosConfig({ network: Network.LOCAL }); -const aptos = new Aptos(aptosConfig); +const { aptos, config: aptosConfig } = getAptosClient(); const sender = Account.generate(); const recipient = Account.generate();