Skip to content

Commit

Permalink
fix: astron test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nghaninn committed Dec 4, 2024
1 parent 79fafe1 commit a9826dc
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 129 deletions.
4 changes: 2 additions & 2 deletions src/commands/title-escrow/title-escrow-command.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export type BaseTitleEscrowCommand = NetworkAndWalletSignerOption &
GasOption & {
tokenRegistry: string;
tokenId: string;
remark: string;
encryptionKey: string;
remark?: string;
encryptionKey?: string;
};
export type TitleEscrowTransferHolderCommand = BaseTitleEscrowCommand & {
newHolder: string;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/token-registry/token-registry-command.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export type TokenRegistryIssueCommand = NetworkAndWalletSignerOption &
beneficiary: string;
holder: string;
tokenId: string;
remark: string;
encryptionKey: string;
remark?: string;
encryptionKey?: string;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { deployTokenRegistry } from "./token-registry";
import { encodeInitParams } from "./helpers";
import { Contract } from "ethers";
import { DeployTokenRegistryCommand } from "../../../commands/deploy/deploy.types";
import { DeploymentEvent } from "@tradetrust-tt/token-registry/dist/contracts/contracts/utils/TDocDeployer";
import { encodeInitParams } from "./helpers";
import { deployTokenRegistry } from "./token-registry";

const deployParams: DeployTokenRegistryCommand = {
registryName: "Test",
Expand Down Expand Up @@ -45,7 +44,7 @@ describe("deploy Token Registry", () => {
"0x88f17c6964c859cf0bb9ee53d91685b2529e0976",
"0x0f1fc16ef456d0fdc7c53d1d94f4a2e97c7064e3",
"0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000088f17c6964c859cf0bb9ee53d91685b2529e09760000000000000000000000000000000000000000000000000000000000000001410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014100000000000000000000000000000000000000000000000000000000000000",
] as unknown as DeploymentEvent,
] as unknown,
},
],
}),
Expand All @@ -61,7 +60,7 @@ describe("deploy Token Registry", () => {
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});

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

// price should be any length string of digits
Expand All @@ -82,7 +81,7 @@ describe("deploy Token Registry", () => {
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});

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

// price should be any length string of digits
Expand All @@ -101,7 +100,7 @@ describe("deploy Token Registry", () => {
deployer: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
});

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

// price should be any length string of digits
Expand Down
4 changes: 2 additions & 2 deletions src/implementations/document-store/grant-role-astron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("document-store", () => {
expect(passedSigner.privateKey).toBe(`0x${deployParams.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedCallStaticGrantRole).toHaveBeenCalledTimes(1);
expect(mockedGrantRole.mock.calls[0][0]).toEqual("ISSUER");
expect(mockedGrantRole.mock.calls[0][0]).toBe("ISSUER");
expect(mockedGrantRole.mock.calls[0][1]).toEqual(deployParams.account);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
});
Expand All @@ -74,7 +74,7 @@ describe("document-store", () => {
expect(passedSigner.privateKey).toBe(`0x${deployParams.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedCallStaticGrantRole).toHaveBeenCalledTimes(1);
expect(mockedGrantRole.mock.calls[0][0]).toEqual("ISSUER");
expect(mockedGrantRole.mock.calls[0][0]).toBe("ISSUER");
expect(mockedGrantRole.mock.calls[0][1]).toEqual(deployParams.account);

expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
Expand Down
4 changes: 2 additions & 2 deletions src/implementations/document-store/revoke-role-astron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("document-store", () => {
expect(passedSigner.privateKey).toBe(`0x${deployParams.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedCallStaticRevokeRole).toHaveBeenCalledTimes(1);
expect(mockedRevokeRole.mock.calls[0][0]).toEqual("ISSUER");
expect(mockedRevokeRole.mock.calls[0][0]).toBe("ISSUER");
expect(mockedRevokeRole.mock.calls[0][1]).toEqual(deployParams.account);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
});
Expand All @@ -74,7 +74,7 @@ describe("document-store", () => {
expect(passedSigner.privateKey).toBe(`0x${deployParams.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedCallStaticRevokeRole).toHaveBeenCalledTimes(1);
expect(mockedRevokeRole.mock.calls[0][0]).toEqual("ISSUER");
expect(mockedRevokeRole.mock.calls[0][0]).toBe("ISSUER");
expect(mockedRevokeRole.mock.calls[0][1]).toEqual(deployParams.account);

expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe("document-store", () => {
expect(passedSigner.privateKey).toBe(`0x${deployParams.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedCallStaticGrantRole).toHaveBeenCalledTimes(1);
expect(mockedGrantRole.mock.calls[0][0]).toEqual("ADMIN");
expect(mockedGrantRole.mock.calls[0][0]).toBe("ADMIN");
expect(mockedGrantRole.mock.calls[0][1]).toEqual(deployParams.newOwner);

expect(await instance.grantTransaction).toStrictEqual({ transactionHash: "transactionHash" });
expect(await instance.revokeTransaction).toStrictEqual({ transactionHash: "transactionHash" });
await expect(instance.grantTransaction).resolves.toStrictEqual({ transactionHash: "transactionHash" });
await expect(instance.revokeTransaction).resolves.toStrictEqual({ transactionHash: "transactionHash" });
});

it("should accept account without 0x prefix and return deployed instance", async () => {
Expand All @@ -81,11 +81,11 @@ describe("document-store", () => {
expect(passedSigner.privateKey).toBe(`0x${deployParams.key}`);
expect(mockedConnect.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedCallStaticGrantRole).toHaveBeenCalledTimes(1);
expect(mockedGrantRole.mock.calls[0][0]).toEqual("ADMIN");
expect(mockedGrantRole.mock.calls[0][0]).toBe("ADMIN");
expect(mockedGrantRole.mock.calls[0][1]).toEqual(deployParams.newOwner);

expect(await instance.grantTransaction).toStrictEqual({ transactionHash: "transactionHash" });
expect(await instance.revokeTransaction).toStrictEqual({ transactionHash: "transactionHash" });
await expect(instance.grantTransaction).resolves.toStrictEqual({ transactionHash: "transactionHash" });
await expect(instance.revokeTransaction).resolves.toStrictEqual({ transactionHash: "transactionHash" });
});

it("should take in the key from environment variable", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TradeTrustToken__factory } from "@tradetrust-tt/token-registry/contracts";
import { Wallet } from "ethers";

import { BaseTitleEscrowCommand as TitleEscrowSurrenderDocumentCommand } from "../../commands/title-escrow/title-escrow-command.type";
import { acceptSurrendered } from "./acceptSurrendered";
import { BaseTitleEscrowCommand as TitleEscrowReturnDocumentCommand } from "../../commands/title-escrow/title-escrow-command.type";
import { acceptReturned } from "./acceptReturned";

jest.mock("@tradetrust-tt/token-registry/contracts");

const acceptSurrenderedDocumentParams: TitleEscrowSurrenderDocumentCommand = {
const acceptReturnedDocumentParams: TitleEscrowReturnDocumentCommand = {
tokenRegistry: "0x1122",
tokenId: "0x12345",
network: "astron",
Expand All @@ -15,7 +15,7 @@ const acceptSurrenderedDocumentParams: TitleEscrowSurrenderDocumentCommand = {
};

describe("title-escrow", () => {
describe("accepts surrendered transferable record", () => {
describe("accepts returned transferable record", () => {
const mockedTradeTrustTokenFactory: jest.Mock<TradeTrustToken__factory> = TradeTrustToken__factory as any;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore mock static method
Expand All @@ -42,17 +42,17 @@ describe("title-escrow", () => {
mockBurnToken.mockClear();
mockCallStaticBurnToken.mockClear();
});
it("should pass in the correct params and successfully accepts a surrendered transferable record", async () => {
it("should pass in the correct params and successfully accepts a returned transferable record", async () => {
const privateKey = "0000000000000000000000000000000000000000000000000000000000000001";
await acceptSurrendered({
...acceptSurrenderedDocumentParams,
await acceptReturned({
...acceptReturnedDocumentParams,
key: privateKey,
});

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

expect(passedSigner.privateKey).toBe(`0x${privateKey}`);
expect(mockedConnectERC721).toHaveBeenCalledWith(acceptSurrenderedDocumentParams.tokenRegistry, passedSigner);
expect(mockedConnectERC721).toHaveBeenCalledWith(acceptReturnedDocumentParams.tokenRegistry, passedSigner);
expect(mockCallStaticBurnToken).toHaveBeenCalledTimes(1);
expect(mockBurnToken).toHaveBeenCalledTimes(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,32 @@ describe("title-escrow", () => {

const mockedTitleEscrowAddress = "0x2133";
const mockedOwnerOf = jest.fn();
mockedOwnerOf.mockReturnValue(mockedTitleEscrowAddress);

const mockTransferOwners = jest.fn();
const mockCallStaticTransferOwners = jest.fn().mockResolvedValue(undefined);

const mockedBeneficiary = "0xdssfs";
const mockGetBeneficiary = jest.fn();
mockGetBeneficiary.mockReturnValue(mockedBeneficiary);

mockedConnectERC721.mockReturnValue({
ownerOf: mockedOwnerOf,
});
beforeAll(() => {
mockedOwnerOf.mockReturnValue(mockedTitleEscrowAddress);
mockGetBeneficiary.mockReturnValue(mockedBeneficiary);

mockedConnectTokenFactory.mockReturnValue({
transferBeneficiary: mockTransferOwners,
beneficiary: mockGetBeneficiary,
callStatic: {
transferBeneficiary: mockCallStaticTransferOwners,
},
});
mockTransferOwners.mockReturnValue({
hash: "hash",
wait: () => Promise.resolve({ transactionHash: "transactionHash" }),
mockedConnectERC721.mockReturnValue({
ownerOf: mockedOwnerOf,
});

mockedConnectTokenFactory.mockReturnValue({
transferBeneficiary: mockTransferOwners,
beneficiary: mockGetBeneficiary,
callStatic: {
transferBeneficiary: mockCallStaticTransferOwners,
},
});
mockTransferOwners.mockReturnValue({
hash: "hash",
wait: () => Promise.resolve({ transactionHash: "transactionHash" }),
});
});

beforeEach(() => {
Expand Down
37 changes: 20 additions & 17 deletions src/implementations/title-escrow/nominateBeneficiary-astron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,26 @@ describe("title-escrow", () => {
const mockGetBeneficiary = jest.fn();
const mockGetHolder = jest.fn();
const mockCallStaticNominateBeneficiary = jest.fn().mockResolvedValue(undefined);
mockGetBeneficiary.mockResolvedValue(mockedBeneficiary);
mockGetHolder.mockResolvedValue(mockedHolder);
mockedConnectERC721.mockReturnValue({
ownerOf: mockedOwnerOf,
});
mockedConnectTokenFactory.mockReturnValue({
nominate: mockNominateBeneficiary,
beneficiary: mockGetBeneficiary,
holder: mockGetHolder,
callStatic: {
nominate: mockCallStaticNominateBeneficiary,
},
});
mockedOwnerOf.mockReturnValue(mockedTitleEscrowAddress);
mockNominateBeneficiary.mockReturnValue({
hash: "hash",
wait: () => Promise.resolve({ transactionHash: "transactionHash" }),

beforeAll(() => {
mockGetBeneficiary.mockResolvedValue(mockedBeneficiary);
mockGetHolder.mockResolvedValue(mockedHolder);
mockedConnectERC721.mockReturnValue({
ownerOf: mockedOwnerOf,
});
mockedConnectTokenFactory.mockReturnValue({
nominate: mockNominateBeneficiary,
beneficiary: mockGetBeneficiary,
holder: mockGetHolder,
callStatic: {
nominate: mockCallStaticNominateBeneficiary,
},
});
mockedOwnerOf.mockReturnValue(mockedTitleEscrowAddress);
mockNominateBeneficiary.mockReturnValue({
hash: "hash",
wait: () => Promise.resolve({ transactionHash: "transactionHash" }),
});
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TitleEscrow__factory, TradeTrustToken__factory } from "@tradetrust-tt/token-registry/contracts";
import { Wallet } from "ethers";

import { BaseTitleEscrowCommand as TitleEscrowSurrenderDocumentCommand } from "../../commands/title-escrow/title-escrow-command.type";
import { rejectSurrendered } from "./rejectSurrendered";
import { BaseTitleEscrowCommand as TitleEscrowReturnDocumentCommand } from "../../commands/title-escrow/title-escrow-command.type";
import { rejectReturned } from "./rejectReturned";

jest.mock("@tradetrust-tt/token-registry/contracts");

const rejectSurrenderedDocumentParams: TitleEscrowSurrenderDocumentCommand = {
const rejectReturnedDocumentParams: TitleEscrowReturnDocumentCommand = {
tokenRegistry: "0x1122",
tokenId: "0x12345",
network: "astron",
Expand All @@ -15,7 +15,7 @@ const rejectSurrenderedDocumentParams: TitleEscrowSurrenderDocumentCommand = {
};

describe("title-escrow", () => {
describe("rejects surrendered transferable record", () => {
describe("rejects returned transferable record", () => {
const mockedTradeTrustTokenFactory: jest.Mock<TradeTrustToken__factory> = TradeTrustToken__factory as any;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore mock static method
Expand Down Expand Up @@ -79,18 +79,18 @@ describe("title-escrow", () => {
mockCallStaticRestoreTitle.mockClear();
});

it("should pass in the correct params and successfully rejects a surrendered transferable record", async () => {
it("should pass in the correct params and successfully rejects a returned transferable record", async () => {
const privateKey = "0000000000000000000000000000000000000000000000000000000000000001";
await rejectSurrendered({
...rejectSurrenderedDocumentParams,
await rejectReturned({
...rejectReturnedDocumentParams,
key: privateKey,
});
const passedSigner: Wallet = mockedConnectERC721.mock.calls[0][1];

expect(passedSigner.privateKey).toBe(`0x${privateKey}`);
expect(mockedConnectERC721).toHaveBeenCalledWith(rejectSurrenderedDocumentParams.tokenRegistry, passedSigner);
expect(mockedConnectERC721).toHaveBeenCalledWith(rejectReturnedDocumentParams.tokenRegistry, passedSigner);
expect(mockCallStaticRestoreTitle).toHaveBeenCalledTimes(1);
expect(mockRestoreTitle.mock.calls[0][0]).toBe(rejectSurrenderedDocumentParams.tokenId);
expect(mockRestoreTitle.mock.calls[0][0]).toBe(rejectReturnedDocumentParams.tokenId);
});
});
});
Loading

0 comments on commit a9826dc

Please sign in to comment.