Skip to content

Commit

Permalink
Merge pull request #17 from krypc-code/Hedera-KrypC
Browse files Browse the repository at this point in the history
feat: hedera added test cases :krypc
  • Loading branch information
isaackps authored Mar 25, 2024
2 parents 739981a + 352b84c commit 1047258
Show file tree
Hide file tree
Showing 7 changed files with 463 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/implementations/deploy/document-store/document-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ const deployParams: DeployDocumentStoreCommand = {
dryRun: false,
};

const deployParamsHederaTestnet: DeployDocumentStoreCommand = {
storeName: "Test Document Store",
owner: "0x1234",
network: "hederatestnet",
key: "0000000000000000000000000000000000000000000000000000000000000001",
maxPriorityFeePerGasScale: 1,
dryRun: false,
};

describe("document-store", () => {
describe("deployDocumentStore", () => {
const documentStoreFactory: any = DocumentStoreFactory;
Expand Down Expand Up @@ -104,5 +113,79 @@ describe("document-store", () => {
const addr = await passedSigner.getAddress();
expect(mockedDeploy.mock.calls[0][1]).toStrictEqual(addr);
});

//Hedera Testnet
it("should take in the key from environment variable for hederatestnet", async () => {
process.env.OA_PRIVATE_KEY = "0000000000000000000000000000000000000000000000000000000000000002";

await deployDocumentStore({
storeName: "Test",
network: "hederatestnet",
dryRun: false,
maxPriorityFeePerGasScale: 1,
});

const passedSigner: Wallet = mockedDocumentStoreFactory.mock.calls[0][0];
expect(passedSigner.privateKey).toBe(`0x${process.env.OA_PRIVATE_KEY}`);
});

it("should take in the key from key file for hederatestnet", async () => {
await deployDocumentStore({
storeName: "Test",
network: "hederatestnet",
keyFile: join(__dirname, "..", "..", "..", "..", "examples", "sample-key"),
dryRun: false,
maxPriorityFeePerGasScale: 1,
});

const passedSigner: Wallet = mockedDocumentStoreFactory.mock.calls[0][0];
expect(passedSigner.privateKey).toBe(`0x0000000000000000000000000000000000000000000000000000000000000003`);
});

it("should pass in the correct params and return the deployed instance for hederatestnet", async () => {
const instance = await deployDocumentStore(deployParamsHederaTestnet);

const passedSigner: Wallet = mockedDocumentStoreFactory.mock.calls[0][0];

expect(passedSigner.privateKey).toBe(`0x${deployParamsHederaTestnet.key}`);
expect(mockedDeploy.mock.calls[0][0]).toStrictEqual(deployParamsHederaTestnet.storeName);
expect(mockedDeploy.mock.calls[0][1]).toStrictEqual(deployParamsHederaTestnet.owner);
// 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");
});

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

it("should throw when keys are not found anywhere for hederatestnet", async () => {
await expect(
deployDocumentStore({
storeName: "Test",
network: "hederatestnet",
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 default the owner as the deployer for hederatestnet", async () => {
process.env.OA_PRIVATE_KEY = "0000000000000000000000000000000000000000000000000000000000000002";

await deployDocumentStore({
maxPriorityFeePerGasScale: 1,
storeName: "Test",
network: "hederatestnet",
dryRun: false,
});

const passedSigner: Wallet = mockedDocumentStoreFactory.mock.calls[0][0];
const addr = await passedSigner.getAddress();
expect(mockedDeploy.mock.calls[0][1]).toStrictEqual(addr);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const deployParams: DeployTitleEscrowFactoryCommand = {
maxPriorityFeePerGasScale: 1.0,
};

const deployParamsHederaTestnet: DeployTitleEscrowFactoryCommand = {
network: "hederatestnet",
key: "0000000000000000000000000000000000000000000000000000000000000001",
dryRun: false,
maxPriorityFeePerGasScale: 1.0,
};

describe("title escrow factory", () => {
describe("deployTitleEscrowFactory", () => {
const mockedTitleEscrowFactory: jest.Mock<TitleEscrowFactory__factory> = TitleEscrowFactory__factory as any;
Expand Down Expand Up @@ -82,5 +89,58 @@ describe("title escrow factory", () => {
"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"
);
});

//Hedera Testnet
it("should take in the key from environment variable for hederatestnet", async () => {
process.env.OA_PRIVATE_KEY = "0000000000000000000000000000000000000000000000000000000000000002";

await deployTitleEscrowFactory({
network: "hederatestnet",
dryRun: false,
maxPriorityFeePerGasScale: 1.0,
});

const passedSigner: Wallet = mockedTitleEscrowFactory.mock.calls[0][0];
expect(passedSigner.privateKey).toBe(`0x${process.env.OA_PRIVATE_KEY}`);
});

it("should take in the key from key file for hederatestnet", async () => {
await deployTitleEscrowFactory({
network: "hederatestnet",
keyFile: join(__dirname, "..", "..", "..", "..", "examples", "sample-key"),
dryRun: false,
maxPriorityFeePerGasScale: 1.0,
});

const passedSigner: Wallet = mockedTitleEscrowFactory.mock.calls[0][0];
expect(passedSigner.privateKey).toBe(`0x0000000000000000000000000000000000000000000000000000000000000003`);
});

it("should pass in the correct params and return the deployed instance for hederatestnet", async () => {
const instance = await deployTitleEscrowFactory(deployParamsHederaTestnet);

const passedSigner: Wallet = mockedTitleEscrowFactory.mock.calls[0][0];

expect(passedSigner.privateKey).toBe(`0x${deployParamsHederaTestnet.key}`);
// price should be any length string of digits
expect(instance.contractAddress).toBe("contractAddress");
});

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

it("should throw when keys are not found anywhere for hederatestnet", async () => {
await expect(
deployTitleEscrowFactory({
network: "hederatestnet",
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"
);
});
});
});
83 changes: 83 additions & 0 deletions src/implementations/document-store/issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ const deployParams: DocumentStoreIssueCommand = {
dryRun: false,
};

const deployParamsHederaTestnet: DocumentStoreIssueCommand = {
hash: "0xabcd",
address: "0x1234",
network: "hederatestnet",
key: "0000000000000000000000000000000000000000000000000000000000000001",
maxPriorityFeePerGasScale: 1,
dryRun: false,
};
// TODO the following test is very fragile and might break on every interface change of DocumentStoreFactory
// ideally must setup ganache, and run the function over it
describe("issue document-store", () => {
Expand Down Expand Up @@ -118,4 +126,79 @@ describe("issue document-store", () => {
"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"
);
});

//Hedera Testnet
it("should take in the key from environment variable for hederatestnet", async () => {
process.env.OA_PRIVATE_KEY = "0000000000000000000000000000000000000000000000000000000000000002";

await issueToDocumentStore({
hash: "0xabcd",
address: "0x1234",
network: "hederatestnet",
dryRun: false,
maxPriorityFeePerGasScale: 1,
});

const passedSigner: Wallet = mockedConnect.mock.calls[0][1];
expect(passedSigner.privateKey).toBe(`0x${process.env.OA_PRIVATE_KEY}`);
});

it("should pass in the correct params and return the deployed instance for hederatestnet", async () => {
const instance = await issueToDocumentStore(deployParamsHederaTestnet);

const passedSigner: Wallet = mockedConnect.mock.calls[0][1];

expect(passedSigner.privateKey).toBe(`0x${deployParamsHederaTestnet.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParamsHederaTestnet.address);
expect(mockCallStaticIssue).toHaveBeenCalledTimes(1);
expect(mockedIssue.mock.calls[0][0]).toEqual(deployParamsHederaTestnet.hash);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
});

it("should take in the key from key file for hederatestnet", async () => {
await issueToDocumentStore({
hash: "0xabcd",
address: "0x1234",
network: "hederatestnet",
keyFile: join(__dirname, "..", "..", "..", "examples", "sample-key"),
dryRun: false,
maxPriorityFeePerGasScale: 1,
});

const passedSigner: Wallet = mockedConnect.mock.calls[0][1];
expect(passedSigner.privateKey).toBe(`0x0000000000000000000000000000000000000000000000000000000000000003`);
});

it("should accept hash without 0x prefix and return deployed instance for hederatestnet", async () => {
const instance = await issueToDocumentStore({ ...deployParamsHederaTestnet, hash: addAddressPrefix("abcd") });

const passedSigner: Wallet = mockedConnect.mock.calls[0][1];

expect(passedSigner.privateKey).toBe(`0x${deployParamsHederaTestnet.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParamsHederaTestnet.address);
expect(mockCallStaticIssue).toHaveBeenCalledTimes(1);
expect(mockedIssue.mock.calls[0][0]).toEqual(deployParamsHederaTestnet.hash);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
});

it("should allow errors to bubble up for hederatestnet", async () => {
mockedConnect.mockImplementation(() => {
throw new Error("An Error");
});
await expect(issueToDocumentStore(deployParamsHederaTestnet)).rejects.toThrow("An Error");
});

it("should throw when keys are not found anywhere for hederatestnet", async () => {
await expect(
issueToDocumentStore({
hash: "0xabcd",
address: "0x1234",
network: "hederatestnet",
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"
);
});
});
82 changes: 82 additions & 0 deletions src/implementations/document-store/revoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ const deployParams: DocumentStoreRevokeCommand = {
dryRun: false,
};

const deployParamsHederaTestnet: DocumentStoreRevokeCommand = {
hash: "0xabcd",
address: "0x1234",
network: "sepolia",
key: "0000000000000000000000000000000000000000000000000000000000000001",
maxPriorityFeePerGasScale: 1,
dryRun: false,
};
// TODO the following test is very fragile and might break on every interface change of DocumentStoreFactory
// ideally must setup ganache, and run the function over it
describe("document-store", () => {
Expand Down Expand Up @@ -118,5 +126,79 @@ describe("document-store", () => {
"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"
);
});

//Hedera Testnet
it("should pass in the correct params and return the deployed instance for hederatestnet", async () => {
const instance = await revokeToDocumentStore(deployParamsHederaTestnet);

const passedSigner: Wallet = mockedConnect.mock.calls[0][1];

expect(passedSigner.privateKey).toBe(`0x${deployParamsHederaTestnet.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParamsHederaTestnet.address);
expect(mockCallStaticRevoke).toHaveBeenCalledTimes(1);
expect(mockedRevoke.mock.calls[0][0]).toEqual(deployParamsHederaTestnet.hash);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
});

it("should accept hash without 0x prefix and return deployed instance for hederatestnet", async () => {
const instance = await revokeToDocumentStore({ ...deployParamsHederaTestnet, hash: addAddressPrefix("abcd") });

const passedSigner: Wallet = mockedConnect.mock.calls[0][1];

expect(passedSigner.privateKey).toBe(`0x${deployParamsHederaTestnet.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParamsHederaTestnet.address);
expect(mockCallStaticRevoke).toHaveBeenCalledTimes(1);
expect(mockedRevoke.mock.calls[0][0]).toEqual(deployParamsHederaTestnet.hash);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
});

it("should take in the key from environment variable for hederatestnet", async () => {
process.env.OA_PRIVATE_KEY = "0000000000000000000000000000000000000000000000000000000000000002";
await revokeToDocumentStore({
hash: "0xabcd",
address: "0x1234",
network: "hederatestnet",
dryRun: false,
maxPriorityFeePerGasScale: 1,
});

const passedSigner: Wallet = mockedConnect.mock.calls[0][1];
expect(passedSigner.privateKey).toBe(`0x${process.env.OA_PRIVATE_KEY}`);
});

it("should take in the key from key file for hederatestnet", async () => {
await revokeToDocumentStore({
hash: "0xabcd",
address: "0x1234",
network: "hederatestnet",
keyFile: join(__dirname, "..", "..", "..", "examples", "sample-key"),
dryRun: false,
maxPriorityFeePerGasScale: 1,
});

const passedSigner: Wallet = mockedConnect.mock.calls[0][1];
expect(passedSigner.privateKey).toBe(`0x0000000000000000000000000000000000000000000000000000000000000003`);
});

it("should allow errors to bubble up for hederatestnet", async () => {
mockedConnect.mockImplementation(() => {
throw new Error("An Error");
});
await expect(revokeToDocumentStore(deployParamsHederaTestnet)).rejects.toThrow("An Error");
});

it("should throw when keys are not found anywhere for hederatestnet", async () => {
await expect(
revokeToDocumentStore({
hash: "0xabcd",
address: "0x1234",
network: "hederatestnet",
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"
);
});
});
});
Loading

0 comments on commit 1047258

Please sign in to comment.