Skip to content

Commit

Permalink
Change all instances of _PK to _PRIVATE_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
matt committed Sep 4, 2024
1 parent b76ff9d commit e437e35
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ts-run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
env:
NEXT_PUBLIC_MODULE_ADDRESS: |-
4bab58978ec1b1bef032eeb285ad47a6a9b997d646c19b598c35f46b26ff9ece
PUBLISHER_PK: |-
PUBLISHER_PRIVATE_KEY: |-
29479e9e5fe47ba9a8af509dd6da1f907510bcf8917bfb19b7079d8c63c0b720
START_LOCAL_NODE_FOR_TEST: 'true'
TS_DIR: 'src/typescript'
Expand Down
4 changes: 2 additions & 2 deletions src/docker/aptos-node/initialize-contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export BIG_MONEY_GUY="big_money_guy"
aptos init --profile $PUBLISHER \
--rest-url http://host.docker.internal:8080/v1 \
--faucet-url http://host.docker.internal:8081 \
--private-key $PUBLISHER_PK \
--private-key $PUBLISHER_PRIVATE_KEY \
--encoding hex \
--assume-yes \
--network custom

aptos init --profile $BIG_MONEY_GUY \
--rest-url http://host.docker.internal:8080/v1 \
--faucet-url http://host.docker.internal:8081 \
--private-key $BIG_MONEY_GUY_PK \
--private-key $BIG_MONEY_GUY_PRIVATE_KEY \
--encoding hex \
--assume-yes \
--network custom
Expand Down
4 changes: 2 additions & 2 deletions src/docker/compose.local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ services:
context: '../../'
dockerfile: 'src/docker/aptos-node/Dockerfile'
environment:
PUBLISHER_PK: '${PUBLISHER_PK}'
BIG_MONEY_GUY_PK: '${BIG_MONEY_GUY_PK}'
PUBLISHER_PRIVATE_KEY: '${PUBLISHER_PRIVATE_KEY}'
BIG_MONEY_GUY_PRIVATE_KEY: '${BIG_MONEY_GUY_PRIVATE_KEY}'
EMOJICOIN_MODULE_ADDRESS: '${EMOJICOIN_MODULE_ADDRESS}'
depends_on:
aptos-node:
Expand Down
4 changes: 2 additions & 2 deletions src/docker/example.local.env
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ BROKER_PORT="3009"
# production or for any real value transactions.
# If you change this, local tests will fail unless you also change the
# corresponding `*_ADDRESS` values that are derived from this key.
PUBLISHER_PK="0xeaa964d1353b075ac63b0c5a0c1e92aa93355be1402f6077581e37e2a846105e"
PUBLISHER_PRIVATE_KEY="0xeaa964d1353b075ac63b0c5a0c1e92aa93355be1402f6077581e37e2a846105e"

# The caching time for server-side requests for the NextJS web application.
REVALIDATION_TIME="1"
Expand All @@ -81,4 +81,4 @@ HASH_SEED="some random string that is not public"
# The private key for the "big money guy", who sends transactions in tests.
# Corresponds to the address:
# 0xb168d5a1137a3254a9443459ae5b4959e8f5c835858f04e5a01fe133d237d00d
BIG_MONEY_GUY_PK="0xa5e11183d0c23b8c49b40dd71bba7fa0992aed9b89c42934a1bb8f6e4ccc4ec4"
BIG_MONEY_GUY_PRIVATE_KEY="0xa5e11183d0c23b8c49b40dd71bba7fa0992aed9b89c42934a1bb8f6e4ccc4ec4"
2 changes: 1 addition & 1 deletion src/typescript/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ NEXT_PUBLIC_MODULE_ADDRESS="0x4bab58978ec1b1bef032eeb285ad47a6a9b997d646c19b598c
NEXT_PUBLIC_REWARDS_MODULE_ADDRESS="0x76044a237dcc3f71af75fb314f016e8032633587f7d70df4e70777f2b0221e75"

# Randomly generated private key for tests. This is only used in e2e tests and for script data generation.
PUBLISHER_PK="29479e9e5fe47ba9a8af509dd6da1f907510bcf8917bfb19b7079d8c63c0b720"
PUBLISHER_PRIVATE_KEY="29479e9e5fe47ba9a8af509dd6da1f907510bcf8917bfb19b7079d8c63c0b720"

INBOX_URL="http://localhost:3000"
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/utils/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const { aptos, publisher } = getTestHelpers();

// const PUBLISHER = publisher;
const PUBLISHER = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(process.env.PUBLISHER_PK!),
privateKey: new Ed25519PrivateKey(process.env.PUBLISHER_PRIVATE_KEY!),
});

if (!(NUM_TRADERS % CHUNK_SIZE === 0)) {
Expand Down
4 changes: 2 additions & 2 deletions src/typescript/sdk/tests/pre-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
Inbox,
LocalNode,
publishForTest,
getPublisherPKForTest,
getTestPublisherPrivateKey,
PK_PATH,
PUBLISH_RES_PATH,
} = require("./utils");
Expand All @@ -23,7 +23,7 @@ module.exports = async function setup() {
fs.mkdirSync(path.dirname(PK_PATH), { recursive: true });
fs.mkdirSync(path.dirname(PUBLISH_RES_PATH), { recursive: true });

const pk = await getPublisherPKForTest();
const pk = await getTestPublisherPrivateKey();
if (!pk) {
throw new Error("Please provide a private key for testing");
};
Expand Down
16 changes: 9 additions & 7 deletions src/typescript/sdk/tests/utils/load-priv-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
import { Account, AccountAddress, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";
import { VERCEL } from "../../src/const";

export const getPublisherPKForTest = async () => {
export const getTestPublisherPrivateKey = async () => {
if (VERCEL) {
throw new Error("This function should not be called in a Vercel deployment.");
}
// If the publisher private key is not set by now, throw an error.
if (!process.env.PUBLISHER_PK) {
console.warn("Missing PUBLISHER_PK environment variable for test, using the default value.");
process.env.PUBLISHER_PK = "29479e9e5fe47ba9a8af509dd6da1f907510bcf8917bfb19b7079d8c63c0b720";
if (!process.env.PUBLISHER_PRIVATE_KEY) {
console.warn(
"Missing PUBLISHER_PRIVATE_KEY environment variable for test, using the default value.");
process.env.PUBLISHER_PRIVATE_KEY =
"29479e9e5fe47ba9a8af509dd6da1f907510bcf8917bfb19b7079d8c63c0b720";
}

const derivedAccount = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(process.env.PUBLISHER_PK),
privateKey: new Ed25519PrivateKey(process.env.PUBLISHER_PRIVATE_KEY),
});
const derivedAddress = derivedAccount.accountAddress.toString();
const normalizedEnvAddress = AccountAddress.from(process.env.NEXT_PUBLIC_MODULE_ADDRESS!);

if (derivedAddress !== normalizedEnvAddress.toString()) {
const msg = `${derivedAddress} !== ${process.env.NEXT_PUBLIC_MODULE_ADDRESS}`;
throw new Error(`PUBLISHER_PK does not match NEXT_PUBLIC_MODULE_ADDRESS: ${msg}`);
throw new Error(`PUBLISHER_PRIVATE_KEY does not match NEXT_PUBLIC_MODULE_ADDRESS: ${msg}`);
}

return process.env.PUBLISHER_PK;
return process.env.PUBLISHER_PRIVATE_KEY;
};

0 comments on commit e437e35

Please sign in to comment.