Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: blockchain without deployer #271

Merged
merged 8 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/commands/deploy/token-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const builder = (yargs: Argv): Argv =>
.option("standalone", {
description: "Use Standalone Deployer, used with Title Escrow Factory (Optional)",
type: "boolean",
default: false,
})
.option("factory", {
description: "Address of Title Escrow Factory (Optional)",
Expand Down
6 changes: 3 additions & 3 deletions src/implementations/config/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ export const getTokenRegistryAddress = async (
passedOnWallet: Wallet | ConnectedSigner,
network: NetworkCmdName
): Promise<string> => {
const tokenRegistry = await deployTokenRegistry({
const { contractAddress } = await deployTokenRegistry({
encryptedWalletPath,
passedOnWallet,
network,
dryRun: false,
registryName: "Token Registry",
registrySymbol: "TR",
});
success(`Token registry deployed, address: ${highlight(tokenRegistry)}`);
return tokenRegistry.contractAddress;
success(`Token registry deployed, address: ${highlight(contractAddress)}`);
return contractAddress;
};

export const getDocumentStoreAddress = async (
Expand Down
41 changes: 41 additions & 0 deletions src/implementations/deploy/token-registry/token-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const deployParams: DeployTokenRegistryCommand = {
network: "sepolia",
key: "0000000000000000000000000000000000000000000000000000000000000001",
dryRun: false,
standalone: false,
};

describe("deploy Token Registry", () => {
Expand Down Expand Up @@ -67,6 +68,46 @@ describe("deploy Token Registry", () => {
// 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",
});

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
});

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);

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
});

it("should allow errors to bubble up", async () => {
mockedDeploy.mockRejectedValue(new Error("An Error"));
await expect(deployTokenRegistry(deployParams)).rejects.toThrow("An Error");
Expand Down
20 changes: 14 additions & 6 deletions src/implementations/deploy/token-registry/token-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ export const deployTokenRegistry = async ({
trace("[Status] Title Escrow Factory interface check is OK.");

info(`Using ${factoryAddress} as Title Escrow factory.`);

// Blockchains where deployers are not supported.
if (!isValidAddress(deployerContractAddress)) {
deployerContractAddress = defaultDeployerContractAddress;
}
if (!isValidAddress(implAddress)) {
implAddress = defaultTokenImplementationContractAddress;
}

if (standalone !== false && (!deployerContractAddress || !implAddress)) {
console.error(`Network ${chainId} does not support "quick-start" mode. Defaulting to --standalone mode.`);
standalone = true;
}

if (!standalone) {
if (!isValidAddress(deployerContractAddress)) {
deployerContractAddress = defaultDeployerContractAddress;
}
if (!isValidAddress(implAddress)) {
implAddress = defaultTokenImplementationContractAddress;
}
if (!deployerContractAddress || !implAddress) {
throw new Error(`Network ${chainId} currently is not supported. Use --standalone instead.`);
}
Expand Down
Loading