Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix full:testnet command #291

Merged
merged 8 commits into from
Nov 2, 2023
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
2 changes: 1 addition & 1 deletion packages/api-http/integration/routes/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, Sandbox } from "../../../test-framework";
import { prepareSandbox, ApiContext } from "../../test/helpers/prepare-sandbox";
import { request } from "../../test/helpers/request";
import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";

import transactionTypes from "../../test/fixtures/transactions_types.json";
import transactions from "../../test/fixtures/transactions.json";
Expand Down
5 changes: 4 additions & 1 deletion packages/api/source/commands/config-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class Command extends Commands.Command {
);

const configDestination = this.app.getCorePath("config");
const configSource = resolve(__dirname, `../../bin/config/${flags.network}`);
const configSource = resolve(
__dirname,
`../../bin/config/${flags.network}/${this.app.get(Identifiers.ApplicationName)}`,
);

await this.components.taskList([
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { dirSync, setGracefulCleanup } from "tmp";

import appJson from "../../../core/bin/config/testnet/app.json";
import appJson from "../../../core/bin/config/testnet/mainsail/app.json";
import { describe } from "../../../test-framework";
import { AppGenerator } from "./app";
import { makeApplication } from "../application-factory";

describe<{
dataPath: string;
Expand All @@ -12,9 +13,11 @@ describe<{
setGracefulCleanup();
});

beforeEach((context) => {
beforeEach(async (context) => {
const app = await makeApplication();

context.dataPath = dirSync().name;
context.appGenerator = new AppGenerator();
context.appGenerator = app.resolve(AppGenerator);
});

it("#generateDefault - should default data", ({ appGenerator }) => {
Expand Down
18 changes: 13 additions & 5 deletions packages/configuration-generator/source/generators/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { injectable } from "@mainsail/container";
import { Contracts, Exceptions } from "@mainsail/contracts";
import { inject, injectable } from "@mainsail/container";
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
import { Utils } from "@mainsail/kernel";
import { readJSONSync } from "fs-extra";
import { resolve } from "path";
Expand All @@ -10,12 +10,20 @@ interface PluginEntry {

@injectable()
export class AppGenerator {
generateDefault(): Contracts.Types.JsonObject {
return readJSONSync(resolve(__dirname, "../../../core/bin/config/testnet/app.json"));
@inject(Identifiers.Application)
private app!: Contracts.Kernel.Application;

generateDefault(packageName = "core"): Contracts.Types.JsonObject {
packageName = packageName.replace("@mainsail/", "");

const applicationName = this.app.get<string>(Identifiers.ApplicationName);
return readJSONSync(
resolve(__dirname, `../../../${packageName}/bin/config/testnet/${applicationName}/app.json`),
);
}

generate(options: Contracts.NetworkGenerator.InternalOptions): Contracts.Types.JsonObject {
const template = this.generateDefault();
const template = this.generateDefault(options.packageName);

// This isn't very sophisticated, but here we ensure the correct 'address' package is part
// of the app.json depending on 'options'. A more generic approach would be to read all loaded container plugins.
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/source/contracts/network-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type InternalOptions = EnvironmentOptions &
peers: string[];

// General
packageName?: string;
configPath?: string;
overwriteConfig: boolean;
force: boolean;
Expand Down
8 changes: 4 additions & 4 deletions packages/core/source/commands/config-generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ describe<{

await cli.execute(Command);

existsSync.calledWith(configCore);
ensureDirSync.calledWith(configCore);
existsSync.calledWith(configCore + "/mainsail");
ensureDirSync.calledWith(configCore + "/mainsail");
writeJSONSync.calledTimes(5);
writeFileSync.calledOnce();
});
Expand Down Expand Up @@ -283,8 +283,8 @@ describe<{

await cli.withFlags({ distribute: false }).execute(Command);

existsSync.calledWith(configCore);
ensureDirSync.calledWith(configCore);
existsSync.calledWith(configCore + "/mainsail");
ensureDirSync.calledWith(configCore + "/mainsail");
writeJSONSync.calledTimes(5);
writeFileSync.calledOnce();
});
Expand Down
11 changes: 8 additions & 3 deletions packages/core/source/commands/config-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class Command extends Commands.Command {
let options: Flags = {
...defaults,
...flags,
packageName: this.app.get<AppContracts.Types.PackageJson>(CliIdentifiers.Package).name,
};

const configurationApp = await makeApplication(this.#getConfigurationPath(options), options);
Expand Down Expand Up @@ -254,9 +255,11 @@ export class Command extends Commands.Command {
...defaults,
...flags,
...response,
packageName: this.app.get<AppContracts.Types.PackageJson>(CliIdentifiers.Package).name,
};

configurationApp.rebind(Identifiers.ConfigurationPath).toConstantValue(this.#getConfigurationPath(options));
const path = this.#getConfigurationPath(options, configurationApp.get(CliIdentifiers.ApplicationName));
configurationApp.rebind(Identifiers.ConfigurationPath).toConstantValue(path);

if (!response.confirm) {
throw new Error("You'll need to confirm the input to continue.");
Expand Down Expand Up @@ -293,10 +296,12 @@ export class Command extends Commands.Command {
};
}

#getConfigurationPath(options: Flags): string {
#getConfigurationPath(options: Flags, applicationName?: string): string {
const paths = envPaths(options.token, { suffix: "core" });
const configPath = options.configPath ? options.configPath : paths.config;

return path.join(configPath, options.network);
return applicationName
? path.join(configPath, options.network, applicationName)
: path.join(configPath, options.network);
}
}
5 changes: 4 additions & 1 deletion packages/core/source/commands/config-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class Command extends Commands.Command {
);

const configDestination = this.app.getCorePath("config");
const configSource = resolve(__dirname, `../../bin/config/${flags.network}`);
const configSource = resolve(
__dirname,
`../../bin/config/${flags.network}/${this.app.get(Identifiers.ApplicationName)}`,
);

await this.components.taskList([
{
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-address-base58/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ServiceProvider as CoreValidation } from "@mainsail/validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { AddressFactory } from "./address.factory";
import { schemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-address-bech32/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ServiceProvider as CoreValidation } from "@mainsail/validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { AddressFactory } from "./address.factory";
import { makeSchemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-address-bech32m/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ServiceProvider as CoreValidation } from "@mainsail/validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { AddressFactory } from "./address.factory";
import { schemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-address-keccak256/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ServiceProvider as CoreValidation } from "@mainsail/validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { AddressFactory } from "./address.factory";
import { schemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-address-ss58/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ServiceProvider as CoreValidation } from "@mainsail/validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { AddressFactory } from "./address.factory";
import { schemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-block/source/block.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Contracts } from "@mainsail/contracts";
import clone from "lodash.clone";

import crypto from "../../core/bin/config/testnet/crypto.json";
import crypto from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Factories } from "../../test-framework";
import { blockData } from "../test/fixtures/block";
import { sealBlock } from "./block";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-block/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { schemas as transactionSchemas } from "@mainsail/crypto-transaction";
import { makeKeywords, schemas as sharedSchemas } from "@mainsail/crypto-validation";
import { Validator } from "@mainsail/validation/source/validator";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { schemas } from "./schemas";

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-block/test/helpers/prepare-sandbox.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Identifiers } from "@mainsail/contracts";
import { ServiceProvider as CoreCryptoTransaction } from "@mainsail/crypto-transaction";

import crypto from "../../../core/bin/config/testnet/crypto.json";
import crypto from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { ServiceProvider as CoreCryptoAddressBech32m } from "../../../crypto-address-bech32m";
import { ServiceProvider as CoreCryptoConfig } from "../../../crypto-config";
import { Configuration } from "../../../crypto-config/source/configuration";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-config/source/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe } from "../../test-framework";
import { Configuration } from "./configuration";

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-key-pair-bls12-381/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { schemas as baseSchemas } from "@mainsail/crypto-validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { KeyPairFactory } from "./pair";
import { schemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-key-pair-ecdsa/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { schemas as baseSchemas } from "@mainsail/crypto-validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { KeyPairFactory } from "./pair";
import { schemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-key-pair-ed25519/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { schemas as baseSchemas } from "@mainsail/crypto-validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { KeyPairFactory } from "./pair";
import { schemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-key-pair-schnorr/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { schemas as baseSchemas } from "@mainsail/crypto-validation";
import { Validator } from "@mainsail/validation/source/validator";
import { generateMnemonic } from "bip39";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { KeyPairFactory } from "./pair";
import { schemas } from "./schemas";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-messages/source/factory.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Contracts, Identifiers } from "@mainsail/contracts";

import crypto from "../../core/bin/config/testnet/crypto.json";
import crypto from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Factories, Sandbox } from "../../test-framework";
import { Types } from "../../test-framework/source/factories";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-messages/source/keywords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Contracts, Identifiers } from "@mainsail/contracts";
import { Configuration } from "@mainsail/crypto-config";
import { Validator } from "@mainsail/validation/source/validator";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import { makeKeywords } from "./keywords";

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-messages/source/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { schemas as consensusSchemas } from "@mainsail/crypto-consensus-bls12-38
import { makeKeywords as makeBaseKeywords, schemas as baseSchemas } from "@mainsail/crypto-validation";
import { Validator } from "@mainsail/validation/source/validator";

import cryptoJson from "../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../test-framework";
import {
precommitData,
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-messages/test/helpers/prepare-sandbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Contracts, Identifiers } from "@mainsail/contracts";

import crypto from "../../../core/bin/config/testnet/crypto.json";
import crypto from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { ServiceProvider as CoreCryptoAddressBech32m } from "../../../crypto-address-bech32m";
import { ServiceProvider as CryptoBlock } from "../../../crypto-block";
import { ServiceProvider as CoreCryptoConfig } from "../../../crypto-config";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Identifiers } from "@mainsail/contracts";
import { Configuration } from "@mainsail/crypto-config";
import { Validator } from "@mainsail/validation/source/validator";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { makeKeywords } from "./keywords";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ServiceProvider as CryptoValidationServiceProvider } from "@mainsail/cr
import { ServiceProvider as ValidationServiceProvider } from "@mainsail/validation";
import { BigNumber } from "@mainsail/utils";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { makeKeywords } from "../validation";
import { MultiPaymentTransaction } from "./1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ServiceProvider as CryptoValidationServiceProvider } from "@mainsail/cr
import { ServiceProvider as ValidationServiceProvider } from "@mainsail/validation";
import { BigNumber } from "@mainsail/utils";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { MultiSignatureRegistrationTransaction } from "./1";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ServiceProvider as CryptoValidationServiceProvider } from "@mainsail/cr
import { ServiceProvider as ValidationServiceProvider } from "@mainsail/validation";
import { BigNumber } from "@mainsail/utils";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { TransferTransaction } from "./1";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Configuration } from "@mainsail/crypto-config";
import { makeKeywords } from "@mainsail/crypto-validation";
import { Validator } from "@mainsail/validation/source/validator";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { schemas } from "./schemas";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ServiceProvider as CryptoValidationServiceProvider } from "@mainsail/cr
import { BigNumber } from "@mainsail/utils";
import { ServiceProvider as ValidationServiceProvider } from "@mainsail/validation";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { ServiceProvider as CryptoConsensusServiceProvider } from "../../../crypto-consensus-bls12-381";
import { describe, Sandbox } from "../../../test-framework";
import { schemas } from "../validation/schemas";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ServiceProvider as CryptoValidationServiceProvider } from "@mainsail/cr
import { ServiceProvider as ValidationServiceProvider } from "@mainsail/validation";
import { BigNumber } from "@mainsail/utils";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { ValidatorResignationTransaction } from "./1";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Identifiers } from "@mainsail/contracts";
import { Configuration } from "@mainsail/crypto-config";
import { Validator } from "@mainsail/validation/source/validator";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { makeKeywords } from "./keywords";

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-transaction-vote/source/versions/1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ServiceProvider as CryptoValidationServiceProvider } from "@mainsail/cr
import { ServiceProvider as ValidationServiceProvider } from "@mainsail/validation";
import { BigNumber, ByteBuffer } from "@mainsail/utils";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { makeKeywords } from "../validation";
import { VoteTransaction } from "./index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Identifiers } from "@mainsail/contracts";
import { Configuration } from "@mainsail/crypto-config";
import { Validator } from "@mainsail/validation/source/validator";

import cryptoJson from "../../../core/bin/config/testnet/crypto.json";
import cryptoJson from "../../../core/bin/config/testnet/mainsail/crypto.json";
import { describe, Sandbox } from "../../../test-framework";
import { makeFormats } from "./formats";

Expand Down
Loading
Loading