Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.
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
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
"@tradetrust-tt/document-store": "^4.1.1",
"@tradetrust-tt/token-registry": "^5.2.0",
"@tradetrust-tt/tradetrust": "^6.10.0",
"@tradetrust-tt/tradetrust-config": "^1.19.0",
"@tradetrust-tt/tt-verify": "^9.5.0",
"@trustvc/trustvc": "^1.7.0",
"@tradetrust-tt/tradetrust-config": "^1.18.0",
"@tradetrust-tt/tt-verify": "^9.4.0",
"@trustvc/trustvc": "1.6.0-alpha.3",
"ajv": "^8.4.0",
"ajv-formats": "^2.1.0",
"chalk": "^4.1.2",
Expand Down
87 changes: 40 additions & 47 deletions src/implementations/token-registry/issue-astron.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { TradeTrustToken__factory } from "@tradetrust-tt/token-registry/contracts";
import { Wallet } from "ethers";

import { TokenRegistryIssueCommand } from "../../commands/token-registry/token-registry-command.type";
import { addAddressPrefix } from "../../utils";
import { issueToTokenRegistry } from "./issue";
import { mint } from "@trustvc/trustvc";

jest.mock("@tradetrust-tt/token-registry/contracts");
jest.mock("@trustvc/trustvc", () => ({
mint: jest.fn(),
}));

const deployParams: TokenRegistryIssueCommand = {
beneficiary: "0xabcd",
Expand All @@ -17,6 +18,16 @@ const deployParams: TokenRegistryIssueCommand = {
dryRun: false,
};

const mockTransaction = {
transactionHash: "0x194bdcf15e",
to: "0x1234",
from: "0x5678",
transactionIndex: 0,
blockHash: "0xabcd",
logs: [],
events: [],
};

describe("token-registry", () => {
describe("issue", () => {
// increase timeout because ethers is throttling
Expand All @@ -34,33 +45,16 @@ describe("token-registry", () => {
})
) as jest.Mock
);
const mockedTradeTrustTokenFactory: jest.Mock<TradeTrustToken__factory> = TradeTrustToken__factory as any;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore mock static method
const mockedConnectERC721: jest.Mock = mockedTradeTrustTokenFactory.connect;
const mockedIssue = jest.fn();
const mockCallStaticSafeMint = jest.fn().mockResolvedValue(undefined);

const mockTtErc721Contract = {
mint: mockedIssue,
callStatic: {
mint: mockCallStaticSafeMint,
},
};

beforeAll(() => {
mockedIssue.mockReturnValue({
hash: "hash",
wait: () => Promise.resolve({ transactionHash: "transactionHash" }),
});
});
const mockedMint = mint as jest.MockedFunction<typeof mint>;

beforeEach(() => {
delete process.env.OA_PRIVATE_KEY;
mockedTradeTrustTokenFactory.mockClear();
mockCallStaticSafeMint.mockClear();
mockedConnectERC721.mockReset();
mockedConnectERC721.mockResolvedValue(mockTtErc721Contract);
mockedMint.mockClear();
mockedMint.mockResolvedValue({
hash: "0x194bdcf15e",
blockNumber: 123,
wait: () => Promise.resolve(mockTransaction as any),
} as any);
});

it("should pass in the correct params and return the deployed instance", async () => {
Expand All @@ -70,32 +64,33 @@ describe("token-registry", () => {
key: privateKey,
});

const passedSigner: Wallet = mockedConnectERC721.mock.calls[0][1];
expect(passedSigner.privateKey).toBe(`0x${privateKey}`);
expect(mockedConnectERC721.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedIssue.mock.calls[0][0]).toEqual(deployParams.beneficiary);
expect(mockedIssue.mock.calls[0][1]).toEqual(deployParams.holder);
expect(mockedIssue.mock.calls[0][2]).toEqual(deployParams.tokenId);
expect(mockCallStaticSafeMint).toHaveBeenCalledTimes(1);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
expect(mockedMint).toHaveBeenCalledTimes(1);
const [contractOptions, signer, params] = mockedMint.mock.calls[0];
expect(contractOptions.tokenRegistryAddress).toEqual(deployParams.address);
expect((signer as Wallet).privateKey).toBe(`0x${privateKey}`);
expect(params.beneficiaryAddress).toEqual(deployParams.beneficiary);
expect(params.holderAddress).toEqual(deployParams.holder);
expect(params.tokenId).toEqual(deployParams.tokenId);
expect(instance).toStrictEqual(mockTransaction);
});

it("should accept tokenId without 0x prefix and return deployed instance", async () => {
const privateKey = "0000000000000000000000000000000000000000000000000000000000000001";
const tokenIdWithPrefix = addAddressPrefix("zyxw");
const instance = await issueToTokenRegistry({
...deployParams,
key: privateKey,
tokenId: addAddressPrefix("zyxw"),
tokenId: tokenIdWithPrefix,
});

const passedSigner: Wallet = mockedConnectERC721.mock.calls[0][1];
expect(passedSigner.privateKey).toBe(`0x${privateKey}`);
expect(mockedConnectERC721.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedIssue.mock.calls[0][0]).toEqual(deployParams.beneficiary);
expect(mockedIssue.mock.calls[0][1]).toEqual(deployParams.holder);
expect(mockedIssue.mock.calls[0][2]).toEqual(deployParams.tokenId);
expect(mockCallStaticSafeMint).toHaveBeenCalledTimes(1);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
expect(mockedMint).toHaveBeenCalledTimes(1);
const [contractOptions, signer, params] = mockedMint.mock.calls[0];
expect(contractOptions.tokenRegistryAddress).toEqual(deployParams.address);
expect((signer as Wallet).privateKey).toBe(`0x${privateKey}`);
expect(params.beneficiaryAddress).toEqual(deployParams.beneficiary);
expect(params.holderAddress).toEqual(deployParams.holder);
expect(params.tokenId).toEqual(tokenIdWithPrefix);
expect(instance).toStrictEqual(mockTransaction);
});

it("should throw when keys are not found anywhere", async () => {
Expand All @@ -106,9 +101,7 @@ describe("token-registry", () => {

it("should allow errors to bubble up", async () => {
process.env.OA_PRIVATE_KEY = "0000000000000000000000000000000000000000000000000000000000000002";
mockedConnectERC721.mockImplementation(() => {
throw new Error("An Error");
});
mockedMint.mockRejectedValue(new Error("An Error"));
await expect(issueToTokenRegistry(deployParams)).rejects.toThrow("An Error");
});
});
Expand Down
87 changes: 40 additions & 47 deletions src/implementations/token-registry/issue-astrontestnet.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { TradeTrustToken__factory } from "@tradetrust-tt/token-registry/contracts";
import { Wallet } from "ethers";

import { TokenRegistryIssueCommand } from "../../commands/token-registry/token-registry-command.type";
import { addAddressPrefix } from "../../utils";
import { issueToTokenRegistry } from "./issue";
import { mint } from "@trustvc/trustvc";

jest.mock("@tradetrust-tt/token-registry/contracts");
jest.mock("@trustvc/trustvc", () => ({
mint: jest.fn(),
}));

const deployParams: TokenRegistryIssueCommand = {
beneficiary: "0xabcd",
Expand All @@ -17,6 +18,16 @@ const deployParams: TokenRegistryIssueCommand = {
dryRun: false,
};

const mockTransaction = {
transactionHash: "0x194bdcf15e",
to: "0x1234",
from: "0x5678",
transactionIndex: 0,
blockHash: "0xabcd",
logs: [],
events: [],
};

describe("token-registry", () => {
describe("issue", () => {
// increase timeout because ethers is throttling
Expand All @@ -34,33 +45,16 @@ describe("token-registry", () => {
})
) as jest.Mock
);
const mockedTradeTrustTokenFactory: jest.Mock<TradeTrustToken__factory> = TradeTrustToken__factory as any;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore mock static method
const mockedConnectERC721: jest.Mock = mockedTradeTrustTokenFactory.connect;
const mockedIssue = jest.fn();
const mockCallStaticSafeMint = jest.fn().mockResolvedValue(undefined);

const mockTtErc721Contract = {
mint: mockedIssue,
callStatic: {
mint: mockCallStaticSafeMint,
},
};

beforeAll(() => {
mockedIssue.mockReturnValue({
hash: "hash",
wait: () => Promise.resolve({ transactionHash: "transactionHash" }),
});
});
const mockedMint = mint as jest.MockedFunction<typeof mint>;

beforeEach(() => {
delete process.env.OA_PRIVATE_KEY;
mockedTradeTrustTokenFactory.mockClear();
mockCallStaticSafeMint.mockClear();
mockedConnectERC721.mockReset();
mockedConnectERC721.mockResolvedValue(mockTtErc721Contract);
mockedMint.mockClear();
mockedMint.mockResolvedValue({
hash: "0x194bdcf15e",
blockNumber: 123,
wait: () => Promise.resolve(mockTransaction as any),
} as any);
});

it("should pass in the correct params and return the deployed instance", async () => {
Expand All @@ -70,32 +64,33 @@ describe("token-registry", () => {
key: privateKey,
});

const passedSigner: Wallet = mockedConnectERC721.mock.calls[0][1];
expect(passedSigner.privateKey).toBe(`0x${privateKey}`);
expect(mockedConnectERC721.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedIssue.mock.calls[0][0]).toEqual(deployParams.beneficiary);
expect(mockedIssue.mock.calls[0][1]).toEqual(deployParams.holder);
expect(mockedIssue.mock.calls[0][2]).toEqual(deployParams.tokenId);
expect(mockCallStaticSafeMint).toHaveBeenCalledTimes(1);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
expect(mockedMint).toHaveBeenCalledTimes(1);
const [contractOptions, signer, params] = mockedMint.mock.calls[0];
expect(contractOptions.tokenRegistryAddress).toEqual(deployParams.address);
expect((signer as Wallet).privateKey).toBe(`0x${privateKey}`);
expect(params.beneficiaryAddress).toEqual(deployParams.beneficiary);
expect(params.holderAddress).toEqual(deployParams.holder);
expect(params.tokenId).toEqual(deployParams.tokenId);
expect(instance).toStrictEqual(mockTransaction);
});

it("should accept tokenId without 0x prefix and return deployed instance", async () => {
const privateKey = "0000000000000000000000000000000000000000000000000000000000000001";
const tokenIdWithPrefix = addAddressPrefix("zyxw");
const instance = await issueToTokenRegistry({
...deployParams,
key: privateKey,
tokenId: addAddressPrefix("zyxw"),
tokenId: tokenIdWithPrefix,
});

const passedSigner: Wallet = mockedConnectERC721.mock.calls[0][1];
expect(passedSigner.privateKey).toBe(`0x${privateKey}`);
expect(mockedConnectERC721.mock.calls[0][0]).toEqual(deployParams.address);
expect(mockedIssue.mock.calls[0][0]).toEqual(deployParams.beneficiary);
expect(mockedIssue.mock.calls[0][1]).toEqual(deployParams.holder);
expect(mockedIssue.mock.calls[0][2]).toEqual(deployParams.tokenId);
expect(mockCallStaticSafeMint).toHaveBeenCalledTimes(1);
expect(instance).toStrictEqual({ transactionHash: "transactionHash" });
expect(mockedMint).toHaveBeenCalledTimes(1);
const [contractOptions, signer, params] = mockedMint.mock.calls[0];
expect(contractOptions.tokenRegistryAddress).toEqual(deployParams.address);
expect((signer as Wallet).privateKey).toBe(`0x${privateKey}`);
expect(params.beneficiaryAddress).toEqual(deployParams.beneficiary);
expect(params.holderAddress).toEqual(deployParams.holder);
expect(params.tokenId).toEqual(tokenIdWithPrefix);
expect(instance).toStrictEqual(mockTransaction);
});

it("should throw when keys are not found anywhere", async () => {
Expand All @@ -106,9 +101,7 @@ describe("token-registry", () => {

it("should allow errors to bubble up", async () => {
process.env.OA_PRIVATE_KEY = "0000000000000000000000000000000000000000000000000000000000000002";
mockedConnectERC721.mockImplementation(() => {
throw new Error("An Error");
});
mockedMint.mockRejectedValue(new Error("An Error"));
await expect(issueToTokenRegistry(deployParams)).rejects.toThrow("An Error");
});
});
Expand Down
Loading