Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
osslgtm committed Aug 28, 2023
1 parent ba7b93b commit ebf030d
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 306 deletions.
4 changes: 3 additions & 1 deletion src/commands/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ export const isWalletOption = (option: any): option is WalletOption => {

export type WalletOrSignerOption = Partial<PrivateKeyOption> | Partial<AwsKmsSignerOption> | Partial<WalletOption>;

export interface GasOption {
export interface GasPriceScale {
maxPriorityFeePerGasScale: number;
}
export interface GasOption extends GasPriceScale {
dryRun: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/title-escrow/endorse-transfer-of-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const handler = async (args: TitleEscrowNominateBeneficiaryCommand): Prom
warn(
`Please note that if you do not have the correct privileges to the transferable record, then this command will fail.`
);
const { transactionReceipt, nominatedBeneficiary } = await endorseNominatedBeneficiary(args);
const { transactionReceipt } = await endorseNominatedBeneficiary(args);
displayTransactionPrice(transactionReceipt);
const { transactionHash } = transactionReceipt;
success(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("document-store", () => {
expect(mockedDeploy.mock.calls[0][0]).toStrictEqual(deployParams.storeName);
expect(mockedDeploy.mock.calls[0][1]).toStrictEqual(deployParams.owner);
// price should be any length string of digits
expect(mockedDeploy.mock.calls[0][1].maxPriorityFeePerGas.toString()).toStrictEqual(expect.stringMatching(/\d+/));
expect(mockedDeploy.mock.calls[0][2].maxPriorityFeePerGas.toString()).toStrictEqual(expect.stringMatching(/\d+/));
expect(instance.contractAddress).toBe("contractAddress");
});

Expand Down
10 changes: 3 additions & 7 deletions src/implementations/deploy/document-store/document-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { getLogger } from "../../../logger";
import { getWalletOrSigner } from "../../utils/wallet";
import { dryRunMode } from "../../utils/dryRun";
import { TransactionReceipt } from "@ethersproject/abstract-provider";
import { calculateMaxFee, scaleBigNumber } from "../../../utils";
import { getGasFees } from "../../../utils";

const { trace } = getLogger("deploy:document-store");

export const deployDocumentStore = async ({
storeName,
owner,
network,
maxPriorityFeePerGasScale,
dryRun,
passedOnWallet,
...rest
Expand All @@ -29,11 +28,8 @@ export const deployDocumentStore = async ({
}
const factory = new DocumentStoreFactory(wallet);
signale.await(`Sending transaction to pool`);
const { maxFeePerGas, maxPriorityFeePerGas } = await wallet.provider.getFeeData();
const transaction = await factory.deploy(storeName, ownerAddress, {
maxPriorityFeePerGas: scaleBigNumber(maxPriorityFeePerGas, maxPriorityFeePerGasScale),
maxFeePerGas: calculateMaxFee(maxFeePerGas, maxPriorityFeePerGas, maxPriorityFeePerGasScale),
});
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
const transaction = await factory.deploy(storeName, ownerAddress, { ...gasFees });
trace(`Tx hash: ${transaction.deployTransaction.hash}`);
trace(`Block Number: ${transaction.deployTransaction.blockNumber}`);
signale.await(`Waiting for transaction ${transaction.deployTransaction.hash} to be mined`);
Expand Down
231 changes: 97 additions & 134 deletions src/implementations/deploy/token-registry/token-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,155 +14,118 @@ const deployParams: DeployTokenRegistryCommand = {
standalone: false,
};

describe("token-registry", () => {
describe("deployTokenRegistry", () => {
const mockedEthersContract: jest.Mock<Contract> = Contract as any;
// eslint-disable-next-line jest/prefer-spy-on
mockedEthersContract.prototype.deploy = jest.fn();
const mockedDeploy: jest.Mock = mockedEthersContract.prototype.deploy;

// increase timeout because ethers is throttling
jest.setTimeout(30000);

beforeEach(() => {
mockedDeploy.mockReset();
mockedDeploy.mockResolvedValue({
hash: "hash",
blockNumber: "blockNumber",
wait: () =>
Promise.resolve({
events: [
{
topics: [
"0x3588ebb5c75fdf91927f8472318f41513ee567c2612a5ce52ac840dcf6f162f5", // deployment
"0x000000000000000000000000426c58c2b29111eafc53bdcb9c99dc7714fdb262",
"0x000000000000000000000000e5c75026d5f636c89cc77583b6bce7c99f512763",
"0x0000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca6",
],
data: "0x000000000000000000000000878a327daa390bc602ae259d3a374610356b6485000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca60000000000000000000000000000000000000000000000000000000000000011563420546f6b656e20526567697374727900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000",
args: [
"0xd6C249d0756059E21Ef4Aef4711B69b76927BEA7",
"0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6",
"0x8d366250A96deBE81C8619459a503a0eEBE33ca6",
"0x878A327daA390Bc602Ae259D3A374610356b6485",
"0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca60000000000000000000000000000000000000000000000000000000000000011563420546f6b656e20526567697374727900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000",
] as unknown as DeploymentEvent,
},
],
}),
});
describe("deploy Token Registry", () => {
const mockedEthersContract: jest.Mock<Contract> = Contract as any;
// eslint-disable-next-line jest/prefer-spy-on
mockedEthersContract.prototype.deploy = jest.fn();
const mockedDeploy: jest.Mock = mockedEthersContract.prototype.deploy;

// increase timeout because ethers is throttling
jest.setTimeout(30000);

beforeEach(() => {
mockedDeploy.mockReset();
mockedDeploy.mockResolvedValue({
hash: "hash",
blockNumber: "blockNumber",
wait: () =>
Promise.resolve({
events: [
{
topics: [
"0x3588ebb5c75fdf91927f8472318f41513ee567c2612a5ce52ac840dcf6f162f5", // deployment
"0x000000000000000000000000426c58c2b29111eafc53bdcb9c99dc7714fdb262",
"0x000000000000000000000000e5c75026d5f636c89cc77583b6bce7c99f512763",
"0x0000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca6",
],
data: "0x000000000000000000000000878a327daa390bc602ae259d3a374610356b6485000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca60000000000000000000000000000000000000000000000000000000000000011563420546f6b656e20526567697374727900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000",
args: [
"0xd6C249d0756059E21Ef4Aef4711B69b76927BEA7",
"0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6",
"0x8d366250A96deBE81C8619459a503a0eEBE33ca6",
"0x878A327daA390Bc602Ae259D3A374610356b6485",
"0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000008d366250a96debe81c8619459a503a0eebe33ca60000000000000000000000000000000000000000000000000000000000000011563420546f6b656e20526567697374727900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000",
] as unknown as DeploymentEvent,
},
],
}),
});
});

it("should pass in the correct params and return the deployed instance", async () => {
await deployTokenRegistry(deployParams);

const expectedInitParams = encodeInitParams({
name: deployParams.registryName,
symbol: deployParams.registrySymbol,
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});

expect(mockedDeploy.mock.calls[0][0]).toEqual("0xE5C75026d5f636C89cc77583B6BCe7C99F512763");
expect(mockedDeploy.mock.calls[0][1]).toEqual(expectedInitParams);
it("should pass in the correct params and return the deployed instance", async () => {
await deployTokenRegistry(deployParams);

// price should be any length string of digits
expect(mockedDeploy.mock.calls[0][2].maxPriorityFeePerGas.toString()).toStrictEqual(expect.stringMatching(/\d+/));
// expect(instance.contractAddress).toBe("contractAddress"); // TODO
const expectedInitParams = encodeInitParams({
name: deployParams.registryName,
symbol: deployParams.registrySymbol,
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});

it("should allow errors to bubble up", async () => {
mockedDeploy.mockRejectedValue(new Error("An Error"));
await expect(deployTokenRegistry(deployParams)).rejects.toThrow("An Error");
});
expect(mockedDeploy.mock.calls[0][0]).toEqual("0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6");
expect(mockedDeploy.mock.calls[0][1]).toEqual(expectedInitParams);

it("should throw when keys are not found anywhere", async () => {
await expect(
deployTokenRegistry({
registryName: "Test",
registrySymbol: "Tst",
network: "sepolia",
maxPriorityFeePerGasScale: 1,
dryRun: false,
})
).rejects.toThrow(
"No private key found in OA_PRIVATE_KEY, key, key-file, please supply at least one or supply an encrypted wallet path, or provide aws kms signer information"
);
// price should be any length string of digits
// expect(mockedDeploy.mock.calls[0][2].gasPrice.toString()).toStrictEqual(expect.stringMatching(/\d+/));
// expect(instance.contractAddress).toBe("contractAddress"); // TODO
});

it("should pass in the correct params with standalone and return the deployed instance", async () => {
const deployStandalone = {
standalone: true,
...deployParams,
};
await deployTokenRegistry(deployStandalone);

const expectedInitParams = encodeInitParams({
name: deployParams.registryName,
symbol: deployParams.registrySymbol,
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});
it("should pass in the correct params and return the deployed instance", async () => {
await deployTokenRegistry(deployParams);

const expectedInitParams = encodeInitParams({
name: deployParams.registryName,
symbol: deployParams.registrySymbol,
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});
expect(mockedDeploy.mock.calls[0][0]).toEqual("0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6");
expect(mockedDeploy.mock.calls[0][1]).toEqual(expectedInitParams);

expect(mockedDeploy.mock.calls[0][0]).toEqual("0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6");
expect(mockedDeploy.mock.calls[0][1]).toEqual(expectedInitParams);
// price should be any length string of digits
// expect(mockedDeploy.mock.calls[0][2].gasPrice.toString()).toStrictEqual(expect.stringMatching(/\d+/));
// expect(instance.contractAddress).toBe("contractAddress"); // TODO
});

// price should be any length string of digits
// expect(mockedDeploy.mock.calls[0][2].gasPrice.toString()).toStrictEqual(expect.stringMatching(/\d+/));
// expect(instance.contractAddress).toBe("contractAddress"); // TODO
});
it("should pass in the correct params with unspecified standalone and return the deployed instance", async () => {
const deployParamsUnspecified = deployParams;
delete deployParamsUnspecified.standalone;
await deployTokenRegistry(deployParamsUnspecified);

it("should pass in the correct params with standalone and return the deployed instance", async () => {
const deployStandalone = {
standalone: true,
...deployParams,
};
await deployTokenRegistry(deployStandalone);

const expectedInitParams = encodeInitParams({
name: deployParams.registryName,
symbol: deployParams.registrySymbol,
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});

expect(mockedDeploy.mock.calls[0][0]).toEqual("0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6");
expect(mockedDeploy.mock.calls[0][1]).toEqual(expectedInitParams);

// price should be any length string of digits
// expect(mockedDeploy.mock.calls[0][2].gasPrice.toString()).toStrictEqual(expect.stringMatching(/\d+/));
// expect(instance.contractAddress).toBe("contractAddress"); // TODO
const expectedInitParams = encodeInitParams({
name: deployParams.registryName,
symbol: deployParams.registrySymbol,
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});

it("should pass in the correct params with unspecified standalone and return the deployed instance", async () => {
const deployParamsUnspecified = deployParams;
delete deployParamsUnspecified.standalone;
await deployTokenRegistry(deployParamsUnspecified);
expect(mockedDeploy.mock.calls[0][0]).toEqual("0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6");
expect(mockedDeploy.mock.calls[0][1]).toEqual(expectedInitParams);

const expectedInitParams = encodeInitParams({
name: deployParams.registryName,
symbol: deployParams.registrySymbol,
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});

expect(mockedDeploy.mock.calls[0][0]).toEqual("0xC78BA1a49663Ef8b920F36B036E91Ab40D8F26D6");
expect(mockedDeploy.mock.calls[0][1]).toEqual(expectedInitParams);

// price should be any length string of digits
// expect(mockedDeploy.mock.calls[0][2].gasPrice.toString()).toStrictEqual(expect.stringMatching(/\d+/));
// expect(instance.contractAddress).toBe("contractAddress"); // TODO
});
// price should be any length string of digits
// expect(mockedDeploy.mock.calls[0][2].gasPrice.toString()).toStrictEqual(expect.stringMatching(/\d+/));
// expect(instance.contractAddress).toBe("contractAddress"); // TODO
});

it("should allow errors to bubble up", async () => {
mockedDeploy.mockRejectedValue(new Error("An Error"));
await expect(deployTokenRegistry(deployParams)).rejects.toThrow("An Error");
});
it("should allow errors to bubble up", async () => {
mockedDeploy.mockRejectedValue(new Error("An Error"));
await expect(deployTokenRegistry(deployParams)).rejects.toThrow("An Error");
});

it("should throw when keys are not found anywhere", async () => {
delete process.env.OA_PRIVATE_KEY;
await expect(
deployTokenRegistry({
registryName: "Test",
registrySymbol: "Tst",
network: "sepolia",
dryRun: false,
maxPriorityFeePerGasScale: 1,
})
).rejects.toThrow(
"No private key found in OA_PRIVATE_KEY, key, key-file, please supply at least one or supply an encrypted wallet path, or provide aws kms signer information"
);
});
it("should throw when keys are not found anywhere", async () => {
delete process.env.OA_PRIVATE_KEY;
await expect(
deployTokenRegistry({
registryName: "Test",
registrySymbol: "Tst",
network: "sepolia",
dryRun: false,
maxPriorityFeePerGasScale: 1.0,
})
).rejects.toThrow(
"No private key found in OA_PRIVATE_KEY, key, key-file, please supply at least one or supply an encrypted wallet path, or provide aws kms signer information"
);
});
});
15 changes: 4 additions & 11 deletions src/implementations/deploy/token-registry/token-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getLogger } from "../../../logger";
import { getWalletOrSigner } from "../../utils/wallet";
import { dryRunMode } from "../../utils/dryRun";
import { TransactionReceipt } from "@ethersproject/abstract-provider";
import { calculateMaxFee, scaleBigNumber } from "../../../utils";
import { getGasFees } from "../../../utils";
const { trace } = getLogger("deploy:token-registry");

export const deployTokenRegistry = async ({
Expand All @@ -24,7 +24,6 @@ export const deployTokenRegistry = async ({
deployer: deployerContractAddress,
standalone,
network,
maxPriorityFeePerGasScale,
dryRun,
passedOnWallet, // passedOnWallet variable will only be used if we are calling it from create.
...rest
Expand Down Expand Up @@ -72,7 +71,7 @@ export const deployTokenRegistry = async ({
standalone = true;
}

const { maxFeePerGas, maxPriorityFeePerGas } = await wallet.provider.getFeeData();
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });

if (!standalone) {
if (!deployerContractAddress || !implAddress) {
Expand All @@ -95,10 +94,7 @@ export const deployTokenRegistry = async ({
});
process.exit(0);
}
const tx = await deployerContract.deploy(implAddress, initParam, {
maxPriorityFeePerGas: scaleBigNumber(maxPriorityFeePerGas, maxPriorityFeePerGasScale),
maxFeePerGas: calculateMaxFee(maxFeePerGas, maxPriorityFeePerGas, maxPriorityFeePerGasScale),
});
const tx = await deployerContract.deploy(implAddress, initParam, { ...gasFees });
trace(`[Transaction] Pending ${tx.hash}`);
const receipt = await tx.wait();
const registryAddress = getEventFromReceipt<DeploymentEvent>(
Expand All @@ -119,10 +115,7 @@ export const deployTokenRegistry = async ({
});
process.exit(0);
}
const token = await tokenFactory.deploy(registryName, registrySymbol, factoryAddress, {
maxPriorityFeePerGas: scaleBigNumber(maxPriorityFeePerGas, maxPriorityFeePerGasScale),
maxFeePerGas: calculateMaxFee(maxFeePerGas, maxPriorityFeePerGas, maxPriorityFeePerGasScale),
});
const token = await tokenFactory.deploy(registryName, registrySymbol, factoryAddress, { ...gasFees });
const registryAddress = token.address;
return { transaction: await token.deployTransaction.wait(), contractAddress: registryAddress };
}
Expand Down
10 changes: 3 additions & 7 deletions src/implementations/document-store/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { DocumentStoreIssueCommand } from "../../commands/document-store/documen
import { getWalletOrSigner } from "../utils/wallet";
import { dryRunMode } from "../utils/dryRun";
import { TransactionReceipt } from "@ethersproject/providers";
import { calculateMaxFee, scaleBigNumber } from "../../utils";
import { getGasFees } from "../../utils";

const { trace } = getLogger("document-store:issue");

export const issueToDocumentStore = async ({
address,
hash,
network,
maxPriorityFeePerGasScale,
dryRun,
...rest
}: DocumentStoreIssueCommand): Promise<TransactionReceipt> => {
Expand All @@ -28,14 +27,11 @@ export const issueToDocumentStore = async ({
}

signale.await(`Sending transaction to pool`);
const { maxFeePerGas, maxPriorityFeePerGas } = await wallet.provider.getFeeData();
const gasFees = await getGasFees({ provider: wallet.provider, ...rest });
const documentStore = await DocumentStoreFactory.connect(address, wallet);
await documentStore.callStatic.issue(hash);

const transaction = await documentStore.issue(hash, {
maxPriorityFeePerGas: scaleBigNumber(maxPriorityFeePerGas, maxPriorityFeePerGasScale),
maxFeePerGas: calculateMaxFee(maxFeePerGas, maxPriorityFeePerGas, maxPriorityFeePerGasScale),
});
const transaction = await documentStore.issue(hash, { ...gasFees });
trace(`Tx hash: ${transaction.hash}`);
trace(`Block Number: ${transaction.blockNumber}`);
signale.await(`Waiting for transaction ${transaction.hash} to be mined`);
Expand Down
Loading

0 comments on commit ebf030d

Please sign in to comment.