Skip to content

Commit 3829501

Browse files
committed
[tests] Make clients used for tests more consistent
1 parent 622ce59 commit 3829501

File tree

5 files changed

+45
-67
lines changed

5 files changed

+45
-67
lines changed

tests/e2e/api/account.test.ts

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ describe("account api", () => {
4343
});
4444

4545
test("it fetches account modules with a limit", async () => {
46-
const config = new AptosConfig({ network: Network.LOCAL });
47-
const aptos = new Aptos(config);
46+
const { aptos } = getAptosClient();
4847
const data = await aptos.getAccountModules({
4948
accountAddress: "0x1",
5049
options: {
@@ -55,8 +54,7 @@ describe("account api", () => {
5554
});
5655

5756
test("it fetches account modules with pagination", async () => {
58-
const config = new AptosConfig({ network: Network.LOCAL });
59-
const aptos = new Aptos(config);
57+
const { aptos } = getAptosClient();
6058
let { modules, cursor } = await aptos.getAccountModulesPage({
6159
accountAddress: "0x1",
6260
options: {
@@ -82,8 +80,7 @@ describe("account api", () => {
8280
});
8381

8482
test("it fetches an account module", async () => {
85-
const config = new AptosConfig({ network: Network.LOCAL });
86-
const aptos = new Aptos(config);
83+
const { aptos } = getAptosClient();
8784
const data = await aptos.getAccountModule({
8885
accountAddress: "0x1",
8986
moduleName: "coin",
@@ -92,17 +89,15 @@ describe("account api", () => {
9289
});
9390

9491
test("it fetches account resources", async () => {
95-
const config = new AptosConfig({ network: Network.LOCAL });
96-
const aptos = new Aptos(config);
92+
const { aptos } = getAptosClient();
9793
const data = await aptos.getAccountResources({
9894
accountAddress: "0x1",
9995
});
10096
expect(data.length).toBeGreaterThan(0);
10197
});
10298

10399
test("it fetches account resources with a limit", async () => {
104-
const config = new AptosConfig({ network: Network.LOCAL });
105-
const aptos = new Aptos(config);
100+
const { aptos } = getAptosClient();
106101
const data = await aptos.getAccountResources({
107102
accountAddress: "0x1",
108103
options: {
@@ -113,8 +108,7 @@ describe("account api", () => {
113108
});
114109

115110
test("it fetches account resources with pagination", async () => {
116-
const config = new AptosConfig({ network: Network.LOCAL });
117-
const aptos = new Aptos(config);
111+
const { aptos } = getAptosClient();
118112
const { resources, cursor } = await aptos.getAccountResourcesPage({
119113
accountAddress: "0x1",
120114
options: {
@@ -136,8 +130,7 @@ describe("account api", () => {
136130
});
137131

138132
test("it fetches an account resource without a type", async () => {
139-
const config = new AptosConfig({ network: Network.LOCAL });
140-
const aptos = new Aptos(config);
133+
const { aptos } = getAptosClient();
141134
const data = await aptos.getAccountResource({
142135
accountAddress: "0x1",
143136
resourceType: "0x1::account::Account",
@@ -149,8 +142,7 @@ describe("account api", () => {
149142
});
150143

151144
test("it fetches an account resource typed", async () => {
152-
const config = new AptosConfig({ network: Network.LOCAL });
153-
const aptos = new Aptos(config);
145+
const { aptos } = getAptosClient();
154146
type AccountRes = {
155147
authentication_key: string;
156148
coin_register_events: {
@@ -186,8 +178,7 @@ describe("account api", () => {
186178
});
187179

188180
test("it fetches account transactions", async () => {
189-
const config = new AptosConfig({ network: Network.LOCAL });
190-
const aptos = new Aptos(config);
181+
const { aptos } = getAptosClient();
191182
const senderAccount = Account.generate();
192183
await aptos.fundAccount({
193184
accountAddress: senderAccount.accountAddress,
@@ -217,8 +208,7 @@ describe("account api", () => {
217208
});
218209

219210
test("it fetches account transactions count", async () => {
220-
const config = new AptosConfig({ network: Network.LOCAL });
221-
const aptos = new Aptos(config);
211+
const { aptos } = getAptosClient();
222212
const senderAccount = Account.generate();
223213
const response = await aptos.fundAccount({
224214
accountAddress: senderAccount.accountAddress,
@@ -233,8 +223,7 @@ describe("account api", () => {
233223
});
234224

235225
test("it fetches account coins data", async () => {
236-
const config = new AptosConfig({ network: Network.LOCAL });
237-
const aptos = new Aptos(config);
226+
const { aptos } = getAptosClient();
238227
const senderAccount = Account.generate();
239228
const fundTxn = await aptos.fundAccount({
240229
accountAddress: senderAccount.accountAddress,
@@ -250,8 +239,7 @@ describe("account api", () => {
250239
});
251240

252241
test("it fetches account coins count", async () => {
253-
const config = new AptosConfig({ network: Network.LOCAL });
254-
const aptos = new Aptos(config);
242+
const { aptos } = getAptosClient();
255243
const senderAccount = Account.generate();
256244
const fundTxn = await aptos.fundAccount({
257245
accountAddress: senderAccount.accountAddress,
@@ -266,8 +254,7 @@ describe("account api", () => {
266254
});
267255

268256
test("it fetches account's coin amount", async () => {
269-
const config = new AptosConfig({ network: Network.LOCAL });
270-
const aptos = new Aptos(config);
257+
const { aptos } = getAptosClient();
271258
const senderAccount = Account.generate();
272259
const fundTxn = await aptos.fundAccount({
273260
accountAddress: senderAccount.accountAddress,
@@ -317,8 +304,7 @@ describe("account api", () => {
317304
});
318305

319306
test("it fetches account balance by coin type (APT)", async () => {
320-
const config = new AptosConfig({ network: Network.LOCAL });
321-
const aptos = new Aptos(config);
307+
const { aptos } = getAptosClient();
322308
const account = Account.generate();
323309

324310
const fundTxn = await aptos.fundAccount({
@@ -335,8 +321,7 @@ describe("account api", () => {
335321
});
336322

337323
test("it fetches account balance by FA metadata address (APT)", async () => {
338-
const config = new AptosConfig({ network: Network.LOCAL });
339-
const aptos = new Aptos(config);
324+
const { aptos } = getAptosClient();
340325
const account = Account.generate();
341326

342327
const fundTxn = await aptos.fundAccount({
@@ -353,8 +338,7 @@ describe("account api", () => {
353338
});
354339

355340
test("lookupOriginalAccountAddress - Look up account address before key rotation", async () => {
356-
const config = new AptosConfig({ network: Network.LOCAL });
357-
const aptos = new Aptos(config);
341+
const { aptos } = getAptosClient();
358342
const account = Account.generate();
359343

360344
// Fund and create account on-chain
@@ -367,8 +351,7 @@ describe("account api", () => {
367351
});
368352

369353
test("it fetches account owned token from collection", async () => {
370-
const config = new AptosConfig({ network: Network.LOCAL });
371-
const aptos = new Aptos(config);
354+
const { aptos } = getAptosClient();
372355
const creator = Account.generate();
373356
await aptos.fundAccount({ accountAddress: creator.accountAddress, amount: FUND_AMOUNT });
374357
const collectionCreationTransaction = await aptos.createCollectionTransaction({
@@ -410,10 +393,7 @@ describe("account api", () => {
410393
});
411394

412395
describe("it derives an account from a private key", () => {
413-
const config = new AptosConfig({
414-
network: Network.LOCAL,
415-
});
416-
const aptos = new Aptos(config);
396+
const { aptos } = getAptosClient();
417397

418398
test("single sender ed25519", async () => {
419399
const account = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: false });
@@ -459,8 +439,7 @@ describe("account api", () => {
459439

460440
describe("Key Rotation", () => {
461441
test("it should rotate ed25519 to ed25519 auth key correctly", async () => {
462-
const config = new AptosConfig({ network: Network.LOCAL });
463-
const aptos = new Aptos(config);
442+
const { aptos } = getAptosClient();
464443

465444
// Current Account
466445
const account = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: true });
@@ -491,8 +470,7 @@ describe("account api", () => {
491470
}, 10000);
492471

493472
test("it should rotate ed25519 to multi-ed25519 auth key correctly", async () => {
494-
const config = new AptosConfig({ network: Network.LOCAL });
495-
const aptos = new Aptos(config);
473+
const { aptos } = getAptosClient();
496474

497475
// Current Account
498476
const account = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: true });
@@ -530,8 +508,7 @@ describe("account api", () => {
530508
}, 10000);
531509

532510
test("it should rotate ed25519 to multikey auth key correctly", async () => {
533-
const config = new AptosConfig({ network: Network.LOCAL });
534-
const aptos = new Aptos(config);
511+
const { aptos } = getAptosClient();
535512

536513
// Current Account
537514
const account = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: true });
@@ -568,8 +545,7 @@ describe("account api", () => {
568545
}, 10000);
569546

570547
test("it should rotate ed25519 to unverified auth key correctly", async () => {
571-
const config = new AptosConfig({ network: Network.LOCAL });
572-
const aptos = new Aptos(config);
548+
const { aptos } = getAptosClient();
573549

574550
// Current Account
575551
const account = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: true });
@@ -601,8 +577,7 @@ describe("account api", () => {
601577
});
602578

603579
describe("Account Derivation APIs", () => {
604-
const config = new AptosConfig({ network: Network.LOCAL });
605-
const aptos = new Aptos(config);
580+
const { aptos } = getAptosClient();
606581

607582
const minterAccount = Account.generate();
608583

tests/e2e/api/coin.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import { getAptosClient } from "../helper";
1212

1313
describe("coin", () => {
1414
test("it generates a transfer coin transaction with AptosCoin coin type", async () => {
15-
const config = new AptosConfig({ network: Network.LOCAL });
16-
const aptos = new Aptos(config);
15+
const { aptos } = getAptosClient();
1716
const sender = Account.generate();
1817
const recipient = Account.generate();
1918
await aptos.fundAccount({ accountAddress: sender.accountAddress, amount: FUND_AMOUNT });

tests/e2e/api/keyless.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
import {
66
Account,
7+
Aptos,
8+
AptosConfig,
79
FederatedKeylessAccount,
810
Groth16Zkp,
911
KeylessAccount,
1012
ProofFetchStatus,
1113
ZeroKnowledgeSig,
1214
ZkProof,
1315
ZkpVariant,
16+
Network,
1417
} from "../../../src";
1518

1619
import { FUND_AMOUNT, TRANSFER_AMOUNT } from "../../unit/helper";
17-
import { getAptosClient } from "../helper";
1820
import { EPHEMERAL_KEY_PAIR, simpleCoinTransactionHeler as simpleCoinTransactionHelper } from "../transaction/helper";
1921

2022
export const TEST_JWT_TOKENS = [
@@ -67,7 +69,9 @@ const KEYLESS_TEST_TIMEOUT = 12000;
6769

6870
describe("keyless api", () => {
6971
const ephemeralKeyPair = EPHEMERAL_KEY_PAIR;
70-
const { aptos } = getAptosClient();
72+
// Keyless only works in devnet and others
73+
const aptosConfig = new AptosConfig({ network: Network.DEVNET });
74+
const aptos = new Aptos(aptosConfig);
7175
const jwkAccount = Account.generate();
7276

7377
beforeEach(async () => {

tests/e2e/api/staking.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { AptosConfig, Aptos, Network } from "../../../src";
55
import { longTestTimeout } from "../../unit/helper";
6+
import { getAptosClient } from "../helper";
67

78
describe("staking api", () => {
89
test(
@@ -26,8 +27,7 @@ describe("staking api", () => {
2627
);
2728

2829
test("it returns 0 if the poolAddress does not exist", async () => {
29-
const config = new AptosConfig({ network: Network.DEVNET });
30-
const aptos = new Aptos(config);
30+
const { aptos } = getAptosClient();
3131
const badAddress = "0x12345678901234567850020dfd67646b1e46282999483e7064e70f02f7e12345";
3232
const numDelegators = await aptos.getNumberOfDelegators({ poolAddress: badAddress });
3333
expect(numDelegators).toBe(0);

tests/e2e/api/verifySignatureAsync.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44
import {
55
Account,
66
AccountAddress,
7+
AptosConfig,
78
Ed25519PrivateKey,
8-
Secp256k1PrivateKey,
9-
SigningSchemeInput,
10-
MultiKey,
11-
MultiKeyAccount,
9+
Groth16Zkp,
10+
KeylessAccount,
1211
MultiEd25519Account,
1312
MultiEd25519PublicKey,
14-
KeylessAccount,
13+
MultiKey,
14+
MultiKeyAccount,
15+
Network,
16+
Secp256k1PrivateKey,
17+
SigningSchemeInput,
18+
ZeroKnowledgeSig,
1519
ZkProof,
16-
Groth16Zkp,
1720
ZkpVariant,
18-
ZeroKnowledgeSig,
1921
} from "../../../src";
2022

2123
import {
2224
ed25519,
23-
secp256k1TestObject,
24-
keylessTestObject,
2525
EPHEMERAL_KEY_PAIR,
26+
keylessTestObject,
27+
secp256k1TestObject,
2628
singleSignerED25519,
27-
EXPIRED_EPHEMERAL_KEY_PAIR,
2829
} from "../../unit/helper";
29-
import { getAptosClient } from "../helper";
3030

3131
describe("verifySignatureAsync", () => {
32-
const { aptos } = getAptosClient();
33-
const aptosConfig = aptos.config;
32+
// This can only run against a real network, so we'll make it devnet
33+
const aptosConfig = new AptosConfig({ network: Network.DEVNET });
3434

3535
it("signs a message with single signer Secp256k1 scheme and verifies successfully", async () => {
3636
const { privateKey: privateKeyBytes, address, signatureHex, messageEncoded, stringMessage } = secp256k1TestObject;

0 commit comments

Comments
 (0)