diff --git a/src/core/account.ts b/src/core/account.ts index 16b93d453..91330cf6b 100644 --- a/src/core/account.ts +++ b/src/core/account.ts @@ -76,22 +76,21 @@ export class Account { /** * Derives an account with random private key and address * - * @param args.scheme SigningScheme - type of SigningScheme to use. - * Currently only Ed25519, MultiEd25519, and Secp256k1 are supported + * @param args.scheme optional SigningScheme - type of SigningScheme to use. Default to Ed25519 + * Currently only Ed25519 and Secp256k1 are supported * * @returns Account */ - static generate(args: { scheme: SigningScheme }): Account { - const { scheme } = args; + static generate(scheme?: SigningScheme): Account { let privateKey: PrivateKey; - if (scheme === SigningScheme.Ed25519) { - privateKey = Ed25519PrivateKey.generate(); - } else if (scheme === SigningScheme.Secp256k1Ecdsa) { - privateKey = Secp256k1PrivateKey.generate(); - } else { + switch (scheme) { + case SigningScheme.Secp256k1Ecdsa: + privateKey = Secp256k1PrivateKey.generate(); + break; // TODO: Add support for MultiEd25519 - throw new Error(`Can not generate new Private Key, unsupported signing scheme ${scheme}`); + default: + privateKey = Ed25519PrivateKey.generate(); } const address = new AccountAddress({ diff --git a/tests/e2e/api/account.test.ts b/tests/e2e/api/account.test.ts index 67f579d71..428fb7baf 100644 --- a/tests/e2e/api/account.test.ts +++ b/tests/e2e/api/account.test.ts @@ -3,7 +3,6 @@ import { Account, Aptos, AptosConfig, Network } from "../../../src"; import { U64 } from "../../../src/bcs/serializable/move-primitives"; -import { SigningScheme } from "../../../src/types"; import { sleep } from "../../../src/utils/helpers"; import { INDEXER_WAIT_TIME } from "../../unit/helper"; @@ -86,9 +85,9 @@ describe("account api", () => { test("it fetches account transactions", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); + const senderAccount = Account.generate(); await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const rawTxn = await aptos.generateTransaction({ sender: senderAccount.accountAddress.toString(), data: { @@ -115,7 +114,7 @@ describe("account api", () => { test("it fetches account transactions count", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); + const senderAccount = Account.generate(); const response = await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT, @@ -132,7 +131,7 @@ describe("account api", () => { test("it fetches account coins data", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); + const senderAccount = Account.generate(); const response = await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT, @@ -151,7 +150,7 @@ describe("account api", () => { test("it fetches account coins count", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); + const senderAccount = Account.generate(); const response = await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT, @@ -168,7 +167,7 @@ describe("account api", () => { test("lookupOriginalAccountAddress - Look up account address before key rotation", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const account = Account.generate({ scheme: SigningScheme.Ed25519 }); + const account = Account.generate(); // Fund and create account onchain await aptos.fundAccount({ accountAddress: account.accountAddress.toString(), amount: FUND_AMOUNT }); diff --git a/tests/e2e/api/coin.test.ts b/tests/e2e/api/coin.test.ts index 49f290f0a..64c9463b3 100644 --- a/tests/e2e/api/coin.test.ts +++ b/tests/e2e/api/coin.test.ts @@ -2,7 +2,6 @@ import { AptosConfig, Network, Aptos, Account, Deserializer } from "../../../src import { waitForTransaction } from "../../../src/internal/transaction"; import { RawTransaction, TransactionPayloadEntryFunction } from "../../../src/transactions/instances"; import { TypeTagStruct } from "../../../src/transactions/typeTag/typeTag"; -import { SigningScheme } from "../../../src/types"; import { sleep } from "../../../src/utils/helpers"; import { FUND_AMOUNT, INDEXER_WAIT_TIME } from "../../unit/helper"; @@ -10,8 +9,8 @@ describe("coin", () => { test("it generates a transfer coin transaction with AptosCoin coin type", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const sender = Account.generate({ scheme: SigningScheme.Ed25519 }); - const recipient = Account.generate({ scheme: SigningScheme.Ed25519 }); + const sender = Account.generate(); + const recipient = Account.generate(); await aptos.fundAccount({ accountAddress: sender.accountAddress.toString(), amount: FUND_AMOUNT }); const transaction = await aptos.transferCoinTransaction({ @@ -31,8 +30,8 @@ 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 sender = Account.generate({ scheme: SigningScheme.Ed25519 }); - const recipient = Account.generate({ scheme: SigningScheme.Ed25519 }); + const sender = Account.generate(); + const recipient = Account.generate(); await aptos.fundAccount({ accountAddress: sender.accountAddress.toString(), amount: FUND_AMOUNT }); const transaction = await aptos.transferCoinTransaction({ @@ -53,8 +52,8 @@ 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 sender = Account.generate({ scheme: SigningScheme.Ed25519 }); - const recipient = Account.generate({ scheme: SigningScheme.Ed25519 }); + const sender = Account.generate(); + const recipient = Account.generate(); await aptos.fundAccount({ accountAddress: sender.accountAddress.toString(), amount: FUND_AMOUNT }); await sleep(INDEXER_WAIT_TIME); diff --git a/tests/e2e/api/faucet.test.ts b/tests/e2e/api/faucet.test.ts index bd5519a9b..7e6af9037 100644 --- a/tests/e2e/api/faucet.test.ts +++ b/tests/e2e/api/faucet.test.ts @@ -2,14 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 import { Aptos, AptosConfig, Account, Network } from "../../../src"; -import { SigningScheme } from "../../../src/types"; import { FUND_AMOUNT } from "../../unit/helper"; describe("Faucet", () => { test("it should fund an account", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const testAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); + const testAccount = Account.generate(); // Fund the account await aptos.fundAccount({ accountAddress: testAccount.accountAddress.toString(), amount: FUND_AMOUNT }); diff --git a/tests/e2e/api/transaction.test.ts b/tests/e2e/api/transaction.test.ts index 9fe477147..7cb8eae6c 100644 --- a/tests/e2e/api/transaction.test.ts +++ b/tests/e2e/api/transaction.test.ts @@ -21,9 +21,9 @@ describe("transaction api", () => { }); test("returns true when transaction is pending", async () => { - const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); + const senderAccount = Account.generate(); await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const rawTxn = await aptos.generateTransaction({ sender: senderAccount.accountAddress.toString(), data: { @@ -47,9 +47,9 @@ describe("transaction api", () => { describe("fetch transaction queries", () => { let txn: TransactionResponse; beforeAll(async () => { - const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); + const senderAccount = Account.generate(); await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const rawTxn = await aptos.generateTransaction({ sender: senderAccount.accountAddress.toString(), data: { diff --git a/tests/e2e/api/transaction_builder.test.ts b/tests/e2e/api/transaction_builder.test.ts index 691bcc8b5..461019cd6 100644 --- a/tests/e2e/api/transaction_builder.test.ts +++ b/tests/e2e/api/transaction_builder.test.ts @@ -43,8 +43,8 @@ describe("transaction builder", () => { arguments: [ new U64(100), new U64(200), - new MoveObject(Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress), - new MoveObject(Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress), + new MoveObject(Account.generate().accountAddress), + new MoveObject(Account.generate().accountAddress), new U64(50), ], }); @@ -52,7 +52,7 @@ describe("transaction builder", () => { }); test("it generates a multi sig transaction payload", async () => { const payload = generateTransactionPayload({ - multisigAddress: Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, + multisigAddress: Account.generate().accountAddress, function: "0x1::aptos_account::transfer", type_arguments: [], arguments: [], @@ -72,7 +72,7 @@ describe("transaction builder", () => { test("it generates a raw transaction with script payload", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); const payload = generateTransactionPayload({ bytecode: @@ -81,8 +81,8 @@ describe("transaction builder", () => { arguments: [ new U64(100), new U64(200), - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, + Account.generate().accountAddress, + Account.generate().accountAddress, new U64(50), ], }); @@ -98,9 +98,9 @@ describe("transaction builder", () => { test("it generates a raw transaction with a multi sig payload", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ multisigAddress: bob.accountAddress, function: "0x1::aptos_account::transfer", @@ -119,9 +119,9 @@ describe("transaction builder", () => { test("it generates a raw transaction with an entry function payload", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ function: "0x1::aptos_account::transfer", type_arguments: [], @@ -140,7 +140,7 @@ describe("transaction builder", () => { test("it returns a serialized raw transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); const payload = generateTransactionPayload({ bytecode: @@ -149,8 +149,8 @@ describe("transaction builder", () => { arguments: [ new U64(100), new U64(200), - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, + Account.generate().accountAddress, + Account.generate().accountAddress, new U64(50), ], }); @@ -167,17 +167,15 @@ describe("transaction builder", () => { test("it returns a serialized raw transaction and secondary signers addresses", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ function: "0x1::aptos_account::transfer", type_arguments: [], arguments: [new MoveObject(bob.accountAddress), new U64(1)], }); - const secondarySignerAddress = Account.generate({ - scheme: SigningScheme.Ed25519, - }); + const secondarySignerAddress = Account.generate(); const transaction = await buildTransaction({ aptosConfig: config, sender: alice.accountAddress.toString(), @@ -196,15 +194,15 @@ describe("transaction builder", () => { test("it returns a serialized raw transaction and a fee payer address", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ function: "0x1::aptos_account::transfer", type_arguments: [], arguments: [new MoveObject(bob.accountAddress), new U64(1)], }); - const feePayer = Account.generate({ scheme: SigningScheme.Ed25519 }); + const feePayer = Account.generate(); const transaction = await buildTransaction({ aptosConfig: config, sender: alice.accountAddress.toString(), @@ -220,18 +218,16 @@ describe("transaction builder", () => { test("it returns a serialized raw transaction, secondary signers addresses and a fee payer address", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ function: "0x1::aptos_account::transfer", type_arguments: [], arguments: [new MoveObject(bob.accountAddress), new U64(1)], }); - const feePayer = Account.generate({ scheme: SigningScheme.Ed25519 }); - const secondarySignerAddress = Account.generate({ - scheme: SigningScheme.Ed25519, - }); + const feePayer = Account.generate(); + const secondarySignerAddress = Account.generate(); const transaction = await buildTransaction({ aptosConfig: config, sender: alice.accountAddress.toString(), @@ -253,7 +249,7 @@ describe("transaction builder", () => { test("it generates a signed raw transaction for simulation", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); const payload = generateTransactionPayload({ bytecode: @@ -262,8 +258,8 @@ describe("transaction builder", () => { arguments: [ new U64(100), new U64(200), - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, + Account.generate().accountAddress, + Account.generate().accountAddress, new U64(50), ], }); @@ -287,7 +283,7 @@ describe("transaction builder", () => { test("it signs a raw transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); const payload = generateTransactionPayload({ bytecode: @@ -296,8 +292,8 @@ describe("transaction builder", () => { arguments: [ new U64(100), new U64(200), - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, + Account.generate().accountAddress, + Account.generate().accountAddress, new U64(50), ], }); @@ -319,9 +315,9 @@ describe("transaction builder", () => { test("it signs a fee payer transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ multisigAddress: bob.accountAddress, function: "0x1::aptos_account::transfer", @@ -332,9 +328,7 @@ describe("transaction builder", () => { aptosConfig: config, sender: alice.accountAddress.toString(), payload, - feePayerAddress: Account.generate({ - scheme: SigningScheme.Ed25519, - }).accountAddress.toString(), + feePayerAddress: Account.generate().accountAddress.toString(), }); const accountAuthenticator = sign({ signer: alice, @@ -349,9 +343,9 @@ describe("transaction builder", () => { test("it signs a multi agent transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ bytecode: "a11ceb0b060000000701000402040a030e18042608052e4307713e08af01200000000101020401000100030800010403040100010505060100010607040100010708060100000201020202030207060c060c0303050503030b000108010b000108010b0001080101080102060c03010b0001090002070b000109000b000109000002070b000109000302050b000109000a6170746f735f636f696e04636f696e04436f696e094170746f73436f696e087769746864726177056d657267650765787472616374076465706f73697400000000000000000000000000000000000000000000000000000000000000010000011a0b000a0238000c070b010a0338000c080d070b0838010d070b020b03160b061738020c090b040b0738030b050b09380302", @@ -359,8 +353,8 @@ describe("transaction builder", () => { arguments: [ new U64(100), new U64(200), - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, + Account.generate().accountAddress, + Account.generate().accountAddress, new U64(50), ], }); @@ -384,7 +378,7 @@ describe("transaction builder", () => { test("it generates a single signer signed transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); const payload = generateTransactionPayload({ bytecode: @@ -393,8 +387,8 @@ describe("transaction builder", () => { arguments: [ new U64(100), new U64(200), - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, - Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress, + Account.generate().accountAddress, + Account.generate().accountAddress, new U64(50), ], }); @@ -417,7 +411,7 @@ describe("transaction builder", () => { test("it generates a multi agent signed transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); const bob = Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey({ @@ -456,9 +450,9 @@ describe("transaction builder", () => { test("it generates a fee payer signed transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ function: "0x1::aptos_account::transfer", type_arguments: [], @@ -492,9 +486,9 @@ describe("transaction builder", () => { test("it derives the transaction type as a RawTransaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ function: "0x1::aptos_account::transfer", type_arguments: [], @@ -512,9 +506,9 @@ describe("transaction builder", () => { test("it derives the transaction type as a FeePayerRawTransaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ function: "0x1::aptos_account::transfer", type_arguments: [], @@ -524,9 +518,7 @@ describe("transaction builder", () => { aptosConfig: config, sender: alice.accountAddress.toString(), payload, - feePayerAddress: Account.generate({ - scheme: SigningScheme.Ed25519, - }).accountAddress.toString(), + feePayerAddress: Account.generate().accountAddress.toString(), }); const transactionType = deriveTransactionType(transaction); @@ -536,9 +528,9 @@ describe("transaction builder", () => { test("it derives the transaction type as a MultiAgentRawTransaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const payload = generateTransactionPayload({ function: "0x1::aptos_account::transfer", type_arguments: [], @@ -548,11 +540,7 @@ describe("transaction builder", () => { aptosConfig: config, sender: alice.accountAddress.toString(), payload, - secondarySignerAddresses: [ - Account.generate({ - scheme: SigningScheme.Ed25519, - }).accountAddress.toString(), - ], + secondarySignerAddresses: [Account.generate().accountAddress.toString()], }); const transactionType = deriveTransactionType(transaction); expect(transactionType instanceof MultiAgentRawTransaction).toBeTruthy(); diff --git a/tests/e2e/api/transaction_submission.test.ts b/tests/e2e/api/transaction_submission.test.ts index 0592dad8b..8669e8136 100644 --- a/tests/e2e/api/transaction_submission.test.ts +++ b/tests/e2e/api/transaction_submission.test.ts @@ -20,7 +20,7 @@ describe("transaction submission", () => { test("it generates a script transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), @@ -40,9 +40,9 @@ describe("transaction submission", () => { test("it generates a multi sig transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), data: { @@ -62,9 +62,9 @@ describe("transaction submission", () => { test("it generates an entry function transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), data: { @@ -84,9 +84,9 @@ describe("transaction submission", () => { test("it simulates a multi agent script transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); await aptos.fundAccount({ accountAddress: bob.accountAddress.toString(), amount: FUND_AMOUNT }); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), @@ -117,7 +117,7 @@ describe("transaction submission", () => { test("it signs a script transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), @@ -140,9 +140,9 @@ describe("transaction submission", () => { test("it signs a multi sig transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), data: { @@ -165,9 +165,9 @@ describe("transaction submission", () => { test("it signs an entry function transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), data: { @@ -190,9 +190,9 @@ describe("transaction submission", () => { test("it submits a script transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); await aptos.fundAccount({ accountAddress: bob.accountAddress.toString(), amount: FUND_AMOUNT }); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), @@ -231,9 +231,9 @@ describe("transaction submission", () => { test("it submits an entry function transaction", async () => { const config = new AptosConfig({ network: Network.LOCAL }); const aptos = new Aptos(config); - const alice = Account.generate({ scheme: SigningScheme.Ed25519 }); + const alice = Account.generate(); await aptos.fundAccount({ accountAddress: alice.accountAddress.toString(), amount: FUND_AMOUNT }); - const bob = Account.generate({ scheme: SigningScheme.Ed25519 }); + const bob = Account.generate(); const rawTxn = await aptos.generateTransaction({ sender: alice.accountAddress.toString(), data: { diff --git a/tests/unit/account.test.ts b/tests/unit/account.test.ts index 27938c01c..3528b8e0d 100644 --- a/tests/unit/account.test.ts +++ b/tests/unit/account.test.ts @@ -16,9 +16,16 @@ import { SigningScheme } from "../../src/types"; import { ed25519, secp256k1TestObject, wallet } from "./helper"; describe("Ed25519 Account", () => { - it("should create an instance of Account correctly without error", () => { + it("should create an instance of Account correctly without error when scheme is not specified", () => { // Account with Ed25519 scheme - const edAccount = Account.generate({ scheme: SigningScheme.Ed25519 }); + const edAccount = Account.generate(); + expect(edAccount).toBeInstanceOf(Account); + expect(edAccount.signingScheme).toEqual(SigningScheme.Ed25519); + }); + + it("should create an instance of Account correctly without error when scheme is specified", () => { + // Account with Ed25519 scheme + const edAccount = Account.generate(SigningScheme.Ed25519); expect(edAccount).toBeInstanceOf(Account); expect(edAccount.signingScheme).toEqual(SigningScheme.Ed25519); }); @@ -95,9 +102,7 @@ describe("Ed25519 Account", () => { describe("Secp256k1 Account", () => { it("should create an instance of Account correctly without error", () => { // Account with Secp256k1 scheme - const secp256k1Account = Account.generate({ - scheme: SigningScheme.Secp256k1Ecdsa, - }); + const secp256k1Account = Account.generate(SigningScheme.Secp256k1Ecdsa); expect(secp256k1Account).toBeInstanceOf(Account); expect(secp256k1Account.signingScheme).toEqual(SigningScheme.Secp256k1Ecdsa); });