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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ npx -p @tradetrust-tt/tradetrust-cli tradetrust <arguments>
| Stability | stability | 101010 | Stability | Mainnet |
| Stability Testnet | stabilitytestnet | 20180427 | Stability | Testnet |
| Astron | Astron | 1338 | Astron | Mainnet |
| Astron Testnet | Astrontestnet | 21002 | Astron | Testnet |

_Note: Network Name is the name used in the CLI --network options_

Expand Down
50 changes: 25 additions & 25 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
"dependencies": {
"@govtechsg/oa-encryption": "^1.3.5",
"@snyk/protect": "^1.1196.0",
"@tradetrust-tt/dnsprove": "^2.16.0",
"@tradetrust-tt/dnsprove": "^2.17.0",
"@tradetrust-tt/document-store": "^4.1.1",
"@tradetrust-tt/token-registry": "^5.1.3",
"@tradetrust-tt/token-registry": "^5.2.0",
"@tradetrust-tt/tradetrust": "^6.10.0",
"@tradetrust-tt/tradetrust-config": "^1.17.0",
"@tradetrust-tt/tt-verify": "^9.3.0",
"@tradetrust-tt/tradetrust-config": "^1.18.0",
"@tradetrust-tt/tt-verify": "^9.4.0",
"@trustvc/trustvc": "^1.2.7",
"ajv": "^8.4.0",
"ajv-formats": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`get should return dns-txt 1`] = `
[
{
"addr": "0xb1Bf514b3893357813F366282E887eE221D5C2dA",
"dnssec": false,
"net": "ethereum",
"netId": "21002",
"type": "openatts",
},
{
"addr": "0xdAEe89A37fEEBCBFAc94aBA63Fb163808dAc38Fb",
"dnssec": false,
"net": "ethereum",
"netId": "21002",
"type": "openatts",
},
]
`;
22 changes: 22 additions & 0 deletions src/commands/dns/txt-record/__test__/get-astrontestnet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { handler } from "../get";

describe("get", () => {
afterEach(() => {
jest.clearAllMocks();
});
it("should return dns-txt", async () => {
const consoleSpy = jest.spyOn(console, "table");
await handler({ location: "dev-astronlayer2.bitfactory.cn" });

const mockCall1 = consoleSpy.mock.calls[0][0];
mockCall1.sort((a: any, b: any) => {
if (a.netId < b.netId) return -1;
if (a.netId > b.netId) return 1;
if (a.addr < b.addr) return -1;
if (a.addr > b.addr) return 1;
return 0;
});
// dns-txt
expect(mockCall1).toMatchSnapshot();
});
});
9 changes: 9 additions & 0 deletions src/common/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export enum NetworkCmdName {
StabilityTestnet = "stabilitytestnet",
Stability = "stability",
Astron = "astron",
AstronTestnet = "astrontestnet",
}

const defaultInfuraProvider =
Expand Down Expand Up @@ -114,6 +115,14 @@ export const supportedNetwork: {
currency: "ASTRON",
gasStation: gasStation("https://astronscanl2.bitfactory.cn/gas-station"),
},
[NetworkCmdName.AstronTestnet]: {
explorer: "https://dev-astronscanl2.bitfactory.cn/",
provider: jsonRpcProvider("https://dev-astronlayer2.bitfactory.cn/query/"),
networkId: 21002,
networkName: NetworkCmdName.AstronTestnet,
currency: "ASTRON",
gasStation: gasStation("https://dev-astronscanl2.bitfactory.cn/gas-station"),
},
};

export const getSupportedNetwork = (networkCmdName: string): SupportedNetwork => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { deployDocumentStore } from "./document-store";
import { join } from "path";
import { Wallet } from "ethers";
import { DocumentStoreFactory } from "@tradetrust-tt/document-store";
import { DeployDocumentStoreCommand } from "../../../commands/deploy/deploy.types";

jest.mock("@tradetrust-tt/document-store");

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

describe("document-store", () => {
describe("deployDocumentStore", () => {
const documentStoreFactory: any = DocumentStoreFactory;
const mockedDocumentStoreFactory: jest.Mock<DocumentStoreFactory> = documentStoreFactory;
const mockedDeploy: jest.Mock = mockedDocumentStoreFactory.prototype.deploy;
// increase timeout because ethers is throttling
jest.setTimeout(30_000);
jest.spyOn(global, "fetch").mockImplementation(
jest.fn(() =>
Promise.resolve({
json: () =>
Promise.resolve({
standard: {
maxPriorityFee: 0,
maxFee: 0,
},
}),
})
) as jest.Mock
);

beforeEach(() => {
delete process.env.OA_PRIVATE_KEY;
mockedDocumentStoreFactory.mockReset();
mockedDeploy.mockReset();
mockedDeploy.mockResolvedValue({
deployTransaction: { hash: "hash", wait: () => Promise.resolve({ contractAddress: "contractAddress" }) },
});
});

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

await deployDocumentStore({
storeName: "Test",
network: "astrontestnet",
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", async () => {
await deployDocumentStore({
storeName: "Test",
network: "astrontestnet",
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", async () => {
const instance = await deployDocumentStore(deployParams);

const passedSigner: Wallet = mockedDocumentStoreFactory.mock.calls[0][0];
expect(passedSigner.privateKey).toBe(`0x${deployParams.key}`);
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][2].maxPriorityFeePerGas.toString()).toStrictEqual(expect.stringMatching(/\d+/));
expect(instance.contractAddress).toBe("contractAddress");
});

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

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

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

const passedSigner: Wallet = mockedDocumentStoreFactory.mock.calls[0][0];
const addr = await passedSigner.getAddress();
expect(mockedDeploy.mock.calls[0][1]).toStrictEqual(addr);
});
});
});
Loading