Skip to content

Commit

Permalink
Use test constants keys/function address
Browse files Browse the repository at this point in the history
  • Loading branch information
heliuchuan committed Oct 11, 2023
1 parent 1ec477f commit 5a4233c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 45 deletions.
31 changes: 16 additions & 15 deletions tests/e2e/api/transaction_submission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
TransactionPayloadScript,
} from "../../../src/transactions/instances/transactionPayload";
import { SigningScheme } from "../../../src/types";
import { ALICE_PRIVATE_KEY, BOB_PRIVATE_KEY, TRANSFER_FUNCTION_ADDRESS } from "../../utils/const";

describe("transaction submission", () => {
describe("generateTransaction", () => {
Expand All @@ -26,7 +27,7 @@ describe("transaction submission", () => {
const aptos = new Aptos(config);
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const rawTxn = await aptos.generateTransaction({
Expand All @@ -49,15 +50,15 @@ describe("transaction submission", () => {
const aptos = new Aptos(config);
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const rawTxn = await aptos.generateTransaction({
sender: alice.accountAddress.toString(),
data: {
multisigAddress: bob.accountAddress,
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
},
Expand All @@ -74,14 +75,14 @@ describe("transaction submission", () => {
const aptos = new Aptos(config);
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const rawTxn = await aptos.generateTransaction({
sender: alice.accountAddress.toString(),
data: {
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
},
Expand All @@ -99,12 +100,12 @@ describe("transaction submission", () => {
const aptos = new Aptos(config);
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0xc1e06f150f7fa79c1ca0ad0f8d0b26d83abaf1bed0fc31de24b500d81a2ff924",
hexInput: BOB_PRIVATE_KEY,
}),
});
const rawTxn = await aptos.generateTransaction({
Expand Down Expand Up @@ -138,7 +139,7 @@ describe("transaction submission", () => {
const aptos = new Aptos(config);
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const rawTxn = await aptos.generateTransaction({
Expand All @@ -164,15 +165,15 @@ describe("transaction submission", () => {
const aptos = new Aptos(config);
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const rawTxn = await aptos.generateTransaction({
sender: alice.accountAddress.toString(),
data: {
multisigAddress: bob.accountAddress,
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
},
Expand All @@ -192,14 +193,14 @@ describe("transaction submission", () => {
const aptos = new Aptos(config);
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const rawTxn = await aptos.generateTransaction({
sender: alice.accountAddress.toString(),
data: {
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
},
Expand All @@ -220,12 +221,12 @@ describe("transaction submission", () => {
const aptos = new Aptos(config);
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0xc1e06f150f7fa79c1ca0ad0f8d0b26d83abaf1bed0fc31de24b500d81a2ff924",
hexInput: BOB_PRIVATE_KEY,
}),
});
const rawTxn = await aptos.generateTransaction({
Expand Down Expand Up @@ -282,7 +283,7 @@ describe("transaction submission", () => {
const rawTxn = await aptos.generateTransaction({
sender: alice.accountAddress.toString(),
data: {
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
},
Expand Down
61 changes: 31 additions & 30 deletions tests/unit/transaction_builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { Network } from "../../src/utils/apiEndpoints";
import { SignedTransaction } from "../../src/transactions/instances/signedTransaction";
import { U64 } from "../../src/bcs/serializable/move-primitives";
import { MoveObject } from "../../src/bcs/serializable/move-structs";
import { ALICE_PRIVATE_KEY, TRANSFER_FUNCTION_ADDRESS } from "../utils/const";

describe("transaction builder", () => {
describe("generate transaction payload", () => {
Expand All @@ -51,15 +52,15 @@ describe("transaction builder", () => {
test("it generates a multi sig transaction payload", async () => {
const payload = generateTransactionPayload({
multisigAddress: Account.generate({ scheme: SigningScheme.Ed25519 }).accountAddress,
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [],
});
expect(payload instanceof TransactionPayloadMultisig).toBeTruthy();
});
test("it generates an entry function transaction payload", async () => {
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [],
});
Expand All @@ -71,7 +72,7 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const payload = generateTransactionPayload({
Expand Down Expand Up @@ -99,13 +100,13 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
multisigAddress: bob.accountAddress,
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand All @@ -122,12 +123,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand All @@ -145,7 +146,7 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const payload = generateTransactionPayload({
Expand Down Expand Up @@ -174,12 +175,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand All @@ -205,12 +206,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand All @@ -231,12 +232,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand Down Expand Up @@ -266,7 +267,7 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const payload = generateTransactionPayload({
Expand Down Expand Up @@ -302,7 +303,7 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const payload = generateTransactionPayload({
Expand Down Expand Up @@ -336,13 +337,13 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
multisigAddress: bob.accountAddress,
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand All @@ -368,7 +369,7 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
Expand Down Expand Up @@ -405,7 +406,7 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const payload = generateTransactionPayload({
Expand Down Expand Up @@ -440,12 +441,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand Down Expand Up @@ -477,12 +478,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand Down Expand Up @@ -515,12 +516,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand All @@ -537,12 +538,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand All @@ -563,12 +564,12 @@ describe("transaction builder", () => {
const config = new AptosConfig({ network: Network.DEVNET });
const alice = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey({
hexInput: "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c",
hexInput: ALICE_PRIVATE_KEY,
}),
});
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const payload = generateTransactionPayload({
function: "0x1::aptos_account::transfer",
function: TRANSFER_FUNCTION_ADDRESS,
type_arguments: [],
arguments: [new MoveObject(bob.accountAddress), new U64(1)],
});
Expand Down
3 changes: 3 additions & 0 deletions tests/utils/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ALICE_PRIVATE_KEY = "0x5aba8dab1c523be32bd4dafe2cc612f7f8050ce42a3322b60216ef67dc97768c"
export const BOB_PRIVATE_KEY = "0xc1e06f150f7fa79c1ca0ad0f8d0b26d83abaf1bed0fc31de24b500d81a2ff924"
export const TRANSFER_FUNCTION_ADDRESS = "0x1::aptos_account::transfer"

0 comments on commit 5a4233c

Please sign in to comment.