Skip to content

Commit

Permalink
Fix the remaining instances of pk and PK
Browse files Browse the repository at this point in the history
Get the last one
  • Loading branch information
matt committed Sep 6, 2024
1 parent e437e35 commit b8ab9af
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/typescript/sdk/tests/e2e/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("tests publishing modules to a local network", () => {
const moduleName = "main";
const packageName = "template";
const publishResult = await publishPackage({
pk: publisher.privateKey,
privateKey: publisher.privateKey,
includedArtifacts: "none",
namedAddresses: {
[packageName]: publisher.accountAddress,
Expand Down
14 changes: 7 additions & 7 deletions src/typescript/sdk/tests/pre-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
LocalNode,
publishForTest,
getTestPublisherPrivateKey,
PK_PATH,
PUBLISHER_PRIVATE_KEY_PATH,
PUBLISH_RES_PATH,
} = require("./utils");

Expand All @@ -20,14 +20,14 @@ module.exports = async function setup() {
const inbox = new Inbox();
await inbox.run();
}
fs.mkdirSync(path.dirname(PK_PATH), { recursive: true });
fs.mkdirSync(path.dirname(PUBLISHER_PRIVATE_KEY_PATH), { recursive: true });
fs.mkdirSync(path.dirname(PUBLISH_RES_PATH), { recursive: true });

const pk = await getTestPublisherPrivateKey();
if (!pk) {
const privateKeyString = await getTestPublisherPrivateKey();
if (!privateKeyString) {
throw new Error("Please provide a private key for testing");
};
fs.writeFileSync(PK_PATH, pk);
const publishResult = JSON.stringify(await publishForTest(pk), null, 2);
}
fs.writeFileSync(PUBLISHER_PRIVATE_KEY_PATH, privateKeyString);
const publishResult = JSON.stringify(await publishForTest(privateKeyString), null, 2);
fs.writeFileSync(PUBLISH_RES_PATH, publishResult);
};
8 changes: 5 additions & 3 deletions src/typescript/sdk/tests/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { getAptosClient } from "./aptos-client";
import { type TestHelpers } from "./types";

export const TS_UNIT_TEST_DIR = path.join(getGitRoot(), "src/typescript/sdk/tests");
export const PK_PATH = path.resolve(path.join(TS_UNIT_TEST_DIR, ".tmp", ".pk"));
export const PUBLISHER_PRIVATE_KEY_PATH = path.resolve(
path.join(TS_UNIT_TEST_DIR, ".tmp", ".publisher_private_key")
);
export const PUBLISH_RES_PATH = path.resolve(
path.join(TS_UNIT_TEST_DIR, ".tmp", ".publish_result")
);
Expand All @@ -24,9 +26,9 @@ export const PUBLISH_RES_PATH = path.resolve(
export function getTestHelpers(): TestHelpers {
const { aptos } = getAptosClient();

const pk = fs.readFileSync(PK_PATH).toString();
const privateKeyString = fs.readFileSync(PUBLISHER_PRIVATE_KEY_PATH).toString();
const publisher = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(Hex.fromHexString(pk).toUint8Array()),
privateKey: new Ed25519PrivateKey(Hex.fromHexString(privateKeyString).toUint8Array()),
});
const publishPackageResult = JSON.parse(fs.readFileSync(PUBLISH_RES_PATH).toString());

Expand Down
14 changes: 7 additions & 7 deletions src/typescript/sdk/tests/utils/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { MAX_GAS_FOR_PUBLISH, ONE_APT, EMOJICOIN_DOT_FUN_MODULE_NAME } from "../
import { getGitRoot } from "./helpers";

export async function publishPackage(args: {
pk: PrivateKey;
privateKey: PrivateKey;
network: Network;
includedArtifacts: string | undefined;
namedAddresses: Record<string, AccountAddressInput>;
packageDirRelativeToRoot: string;
}): Promise<PublishPackageResult> {
const { pk, network, namedAddresses, packageDirRelativeToRoot: packageDirRelative } = args;
const { privateKey, network, namedAddresses, packageDirRelativeToRoot: packageDirRelative } = args;

Check failure on line 24 in src/typescript/sdk/tests/utils/publish.ts

View workflow job for this annotation

GitHub Actions / ts-run-lint

This line has a length of 101. Maximum allowed is 100
const includedArtifacts = args.includedArtifacts || "none";

let aptosExecutableAvailable = true;
Expand All @@ -39,7 +39,7 @@ export async function publishPackage(args: {
.map(([name, address]) => `${name}=${address.toString()}`)
.join(",");

const pkString = new Hex(pk.toUint8Array()).toStringWithoutPrefix();
const privateKeyString = new Hex(privateKey.toUint8Array()).toStringWithoutPrefix();

const shellArgs = [
aptosExecutableAvailable ? "npx @aptos-labs/aptos-cli" : "aptos",
Expand All @@ -50,7 +50,7 @@ export async function publishPackage(args: {
...["--url", NetworkToNodeAPI[network]],
...["--package-dir", packageDir],
...["--included-artifacts", includedArtifacts],
...["--private-key", pkString],
...["--private-key", privateKeyString],
...["--encoding", "hex"],
"--assume-yes",
"--override-size-check",
Expand Down Expand Up @@ -106,10 +106,10 @@ function extractJsonFromText(originalCommand: string, text: string): ResultJSON
return null;
}

export async function publishForTest(pk: string): Promise<PublishPackageResult> {
export async function publishForTest(privateKeyString: string): Promise<PublishPackageResult> {
const { aptos } = getAptosClient();
const publisher = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(Hex.fromHexString(pk).toUint8Array()),
privateKey: new Ed25519PrivateKey(Hex.fromHexString(privateKeyString).toUint8Array()),
});

let publisherBalance = await aptos.account
Expand All @@ -130,7 +130,7 @@ export async function publishForTest(pk: string): Promise<PublishPackageResult>
const moduleName = EMOJICOIN_DOT_FUN_MODULE_NAME;
const packageName = moduleName;
return publishPackage({
pk: publisher.privateKey,
privateKey: publisher.privateKey,
includedArtifacts: "none",
namedAddresses: {
[packageName]: publisher.accountAddress,
Expand Down

0 comments on commit b8ab9af

Please sign in to comment.