Skip to content

Commit

Permalink
feat(core): set dynamic fees in network:generate (#4150)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner authored Nov 6, 2020
1 parent 1f74681 commit feb1d6b
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 87 deletions.
57 changes: 24 additions & 33 deletions __tests__/unit/core/commands/network-generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe("GenerateCommand", () => {
const ensureDirSync = jest.spyOn(fs, "ensureDirSync").mockImplementation();
const writeJSONSync = jest.spyOn(fs, "writeJSONSync").mockImplementation();
const writeFileSync = jest.spyOn(fs, "writeFileSync").mockImplementation();
const copyFileSync = jest.spyOn(fs, "copyFileSync").mockImplementation();

await cli
.withFlags({
Expand All @@ -49,10 +48,8 @@ describe("GenerateCommand", () => {
expect(ensureDirSync).toHaveBeenCalledWith(configCore);
expect(ensureDirSync).toHaveBeenCalledWith(configCrypto);

expect(writeJSONSync).toHaveBeenCalledTimes(7); // 5x Core + 2x Crypto

expect(writeJSONSync).toHaveBeenCalledTimes(8); // 5x Core + 2x Crypto + App
expect(writeFileSync).toHaveBeenCalledTimes(2); // index.ts && .env
expect(copyFileSync).toHaveBeenCalledTimes(1); // App.json
});

it("should throw if the core configuration destination already exists", async () => {
Expand Down Expand Up @@ -176,7 +173,6 @@ describe("GenerateCommand", () => {
const ensureDirSync = jest.spyOn(fs, "ensureDirSync").mockImplementation();
const writeJSONSync = jest.spyOn(fs, "writeJSONSync").mockImplementation();
const writeFileSync = jest.spyOn(fs, "writeFileSync").mockImplementation();
const copyFileSync = jest.spyOn(fs, "copyFileSync").mockImplementation();

prompts.inject([
"testnet",
Expand Down Expand Up @@ -204,18 +200,15 @@ describe("GenerateCommand", () => {
expect(ensureDirSync).toHaveBeenCalledWith(configCore);
expect(ensureDirSync).toHaveBeenCalledWith(configCrypto);

expect(writeJSONSync).toHaveBeenCalledTimes(7); // 5x Core + 2x Crypto

expect(writeJSONSync).toHaveBeenCalledTimes(8); // 5x Core + 2x Crypto + App
expect(writeFileSync).toHaveBeenCalledTimes(2); // index.ts && .env
expect(copyFileSync).toHaveBeenCalledTimes(1); // App.json
});

it("should generate a new configuration if the properties are confirmed and distribute is set to false", async () => {
const existsSync = jest.spyOn(fs, "existsSync").mockImplementation();
const ensureDirSync = jest.spyOn(fs, "ensureDirSync").mockImplementation();
const writeJSONSync = jest.spyOn(fs, "writeJSONSync").mockImplementation();
const writeFileSync = jest.spyOn(fs, "writeFileSync").mockImplementation();
const copyFileSync = jest.spyOn(fs, "copyFileSync").mockImplementation();

prompts.inject([
"testnet",
Expand Down Expand Up @@ -243,18 +236,15 @@ describe("GenerateCommand", () => {
expect(ensureDirSync).toHaveBeenCalledWith(configCore);
expect(ensureDirSync).toHaveBeenCalledWith(configCrypto);

expect(writeJSONSync).toHaveBeenCalledTimes(7); // 5x Core + 2x Crypto

expect(writeJSONSync).toHaveBeenCalledTimes(8); // 5x Core + 2x Crypto + App
expect(writeFileSync).toHaveBeenCalledTimes(2); // index.ts && .env
expect(copyFileSync).toHaveBeenCalledTimes(1); // App.json
});

it("should generate a new configuration with additional flags", async () => {
const existsSync = jest.spyOn(fs, "existsSync").mockImplementation();
const ensureDirSync = jest.spyOn(fs, "ensureDirSync").mockImplementation();
const writeJSONSync = jest.spyOn(fs, "writeJSONSync").mockImplementation();
const writeFileSync = jest.spyOn(fs, "writeFileSync").mockImplementation();
const copyFileSync = jest.spyOn(fs, "copyFileSync").mockImplementation();

await cli
.withFlags({
Expand All @@ -273,6 +263,7 @@ describe("GenerateCommand", () => {
explorer: "myex.io",
distribute: "true",
epoch: "2020-11-04T00:00:00.000Z",
htlcEnabled: true,
feeStaticTransfer: 1,
feeStaticSecondSignature: 2,
feeStaticDelegateRegistration: 3,
Expand All @@ -284,6 +275,20 @@ describe("GenerateCommand", () => {
feeStaticHtlcLock: 9,
feeStaticHtlcClaim: 10,
feeStaticHtlcRefund: 11,
feeDynamicEnabled: true,
feeDynamicMinFeePool: 100,
feeDynamicMinFeeBroadcast: 200,
feeDynamicBytesTransfer: 1,
feeDynamicBytesSecondSignature: 2,
feeDynamicBytesDelegateRegistration: 3,
feeDynamicBytesVote: 4,
feeDynamicBytesMultiSignature: 5,
feeDynamicBytesIpfs: 6,
feeDynamicBytesMultiPayment: 7,
feeDynamicBytesDelegateResignation: 8,
feeDynamicBytesHtlcLock: 9,
feeDynamicBytesHtlcClaim: 10,
feeDynamicBytesHtlcRefund: 11,
coreDBHost: "127.0.0.1",
coreDBPort: 3001,
coreDBUsername: "username",
Expand All @@ -293,7 +298,7 @@ describe("GenerateCommand", () => {
coreAPIPort: 3003,
coreWebhooksPort: 3004,
coreMonitorPort: 3005,
peers: "127.0.0.1,127.0.0.2",
peers: "127.0.0.1:4444,127.0.0.2",
})
.execute(Command);

Expand All @@ -303,18 +308,15 @@ describe("GenerateCommand", () => {
expect(ensureDirSync).toHaveBeenCalledWith(configCore);
expect(ensureDirSync).toHaveBeenCalledWith(configCrypto);

expect(writeJSONSync).toHaveBeenCalledTimes(7); // 5x Core + 2x Crypto

expect(writeJSONSync).toHaveBeenCalledTimes(8); // 5x Core + 2x Crypto + App
expect(writeFileSync).toHaveBeenCalledTimes(2); // index.ts && .env
expect(copyFileSync).toHaveBeenCalledTimes(1); // App.json
});

it("should generate a new configuration using force option", async () => {
const existsSync = jest.spyOn(fs, "existsSync").mockImplementation();
const ensureDirSync = jest.spyOn(fs, "ensureDirSync").mockImplementation();
const writeJSONSync = jest.spyOn(fs, "writeJSONSync").mockImplementation();
const writeFileSync = jest.spyOn(fs, "writeFileSync").mockImplementation();
const copyFileSync = jest.spyOn(fs, "copyFileSync").mockImplementation();

await cli
.withFlags({
Expand All @@ -329,18 +331,15 @@ describe("GenerateCommand", () => {
expect(ensureDirSync).toHaveBeenCalledWith(configCore);
expect(ensureDirSync).toHaveBeenCalledWith(configCrypto);

expect(writeJSONSync).toHaveBeenCalledTimes(7); // 5x Core + 2x Crypto

expect(writeJSONSync).toHaveBeenCalledTimes(8); // 5x Core + 2x Crypto + App
expect(writeFileSync).toHaveBeenCalledTimes(2); // index.ts && .env
expect(copyFileSync).toHaveBeenCalledTimes(1); // App.json
});

it("should overwrite if overwriteConfig is set", async () => {
const existsSync = jest.spyOn(fs, "existsSync").mockImplementation();
const ensureDirSync = jest.spyOn(fs, "ensureDirSync").mockImplementation();
const writeJSONSync = jest.spyOn(fs, "writeJSONSync").mockImplementation();
const writeFileSync = jest.spyOn(fs, "writeFileSync").mockImplementation();
const copyFileSync = jest.spyOn(fs, "copyFileSync").mockImplementation();

await cli
.withFlags({
Expand Down Expand Up @@ -368,18 +367,15 @@ describe("GenerateCommand", () => {
expect(ensureDirSync).toHaveBeenCalledWith(configCore);
expect(ensureDirSync).toHaveBeenCalledWith(configCrypto);

expect(writeJSONSync).toHaveBeenCalledTimes(7); // 5x Core + 2x Crypto

expect(writeJSONSync).toHaveBeenCalledTimes(8); // 5x Core + 2x Crypto + App
expect(writeFileSync).toHaveBeenCalledTimes(2); // index.ts && .env
expect(copyFileSync).toHaveBeenCalledTimes(1); // App.json
});

it("should generate crypto on custom path", async () => {
const existsSync = jest.spyOn(fs, "existsSync").mockImplementation();
const ensureDirSync = jest.spyOn(fs, "ensureDirSync").mockImplementation();
const writeJSONSync = jest.spyOn(fs, "writeJSONSync").mockImplementation();
const writeFileSync = jest.spyOn(fs, "writeFileSync").mockImplementation();
const copyFileSync = jest.spyOn(fs, "copyFileSync").mockImplementation();

await cli
.withFlags({
Expand Down Expand Up @@ -407,18 +403,15 @@ describe("GenerateCommand", () => {
expect(ensureDirSync).toHaveBeenCalledWith("/path/to/config/testnet");
expect(ensureDirSync).toHaveBeenCalledWith("/path/to/config/testnet/crypto");

expect(writeJSONSync).toHaveBeenCalledTimes(7); // 5x Core + 2x Crypto

expect(writeJSONSync).toHaveBeenCalledTimes(8); // 5x Core + 2x Crypto + App
expect(writeFileSync).toHaveBeenCalledTimes(2); // index.ts && .env
expect(copyFileSync).toHaveBeenCalledTimes(1); // App.json
});

it("should allow empty peers", async () => {
const existsSync = jest.spyOn(fs, "existsSync").mockImplementation();
const ensureDirSync = jest.spyOn(fs, "ensureDirSync").mockImplementation();
const writeJSONSync = jest.spyOn(fs, "writeJSONSync").mockImplementation();
const writeFileSync = jest.spyOn(fs, "writeFileSync").mockImplementation();
const copyFileSync = jest.spyOn(fs, "copyFileSync").mockImplementation();

await cli
.withFlags({
Expand Down Expand Up @@ -446,9 +439,7 @@ describe("GenerateCommand", () => {
expect(ensureDirSync).toHaveBeenCalledWith(configCore);
expect(ensureDirSync).toHaveBeenCalledWith(configCrypto);

expect(writeJSONSync).toHaveBeenCalledTimes(7); // 5x Core + 2x Crypto

expect(writeJSONSync).toHaveBeenCalledTimes(8); // 5x Core + 2x Crypto + App
expect(writeFileSync).toHaveBeenCalledTimes(2); // index.ts && .env
expect(copyFileSync).toHaveBeenCalledTimes(1); // App.json
});
});
Loading

0 comments on commit feb1d6b

Please sign in to comment.