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

feat!: add datacenter and resource tests, print offer-info to stdout #1096

Merged
merged 13 commits into from
Jan 21, 2025
2 changes: 1 addition & 1 deletion packages/cli/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"whatwg-url": "^14.0.0"
},
"dependencies": {
"@fluencelabs/deal-ts-clients": "0.23.2-feat-marketplace-v2-resources-eb89b78-7511-1.0",
"@fluencelabs/deal-ts-clients": "0.23.2-feat-marketplace-v2-resources-535b24c-7525-1.0",
"@kubernetes/client-node": "github:fluencelabs/kubernetes-client-javascript#e72ee00a52fec4eb4a8327632895d888ee504f4d",
"@libp2p/crypto": "4.0.1",
"@libp2p/peer-id-factory": "4.0.5",
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/package/src/commands/provider/deal-exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
continue;
}

await signBatch(
`Remove the following workers from deal ${dealId}:\n\n${workers
await signBatch({
title: `Remove the following workers from deal ${dealId}:\n\n${workers
.map(({ worker: { onchainId } }) => {
return onchainId;
})
.join("\n")}`,
[
populatedTxs: [
populateTx(
firstWorker.deal.removeWorker,
firstWorker.worker.onchainId,
Expand All @@ -136,7 +136,7 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
return populateTx(deal.removeWorker, onchainId);
}),
],
);
});
}
}
}
2 changes: 1 addition & 1 deletion packages/cli/package/src/commands/provider/offer-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export default class OfferInfo extends BaseCommand<typeof OfferInfo> {
const { flags } = await initCli(this, await this.parse(OfferInfo));
const offers = await resolveCreatedOffers(flags);
const offerInfoResult = await getOffersInfo(offers);
commandObj.logToStderr(await offersInfoToString(offerInfoResult));
commandObj.log(await offersInfoToString(offerInfoResult));
}
}
68 changes: 36 additions & 32 deletions packages/cli/package/src/lib/chain/commitment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ export async function createCommitments(flags: PeerAndOfferNameFlags) {
let createCommitmentsTxReceipts;

try {
createCommitmentsTxReceipts = await signBatch(
`Create commitments for the following peers:\n\n${computePeers
createCommitmentsTxReceipts = await signBatch({
title: `Create commitments for the following peers:\n\n${computePeers
.map(({ name, peerId }) => {
return `Peer: ${name}\nPeerId: ${peerId}`;
})
.join("\n\n")}`,
[firstCommitmentTx, ...restCommitmentTxs],
);
populatedTxs: [firstCommitmentTx, ...restCommitmentTxs],
});
} catch (e) {
const errorString = stringifyUnknown(e);

Expand Down Expand Up @@ -440,9 +440,9 @@ export async function removeCommitments(flags: CCFlags) {
},
).join("\n\n");

await signBatch(
`Remove the following commitments:\n\n${CCsWithWaitDelegationStatusString}`,
[
await signBatch({
title: `Remove the following commitments:\n\n${CCsWithWaitDelegationStatusString}`,
populatedTxs: [
populateTx(
contracts.diamond.removeCommitment,
firstCCWithWaitDelegationStatus.ccId,
Expand All @@ -451,7 +451,7 @@ export async function removeCommitments(flags: CCFlags) {
return populateTx(contracts.diamond.removeCommitment, ccId);
}),
],
);
});

commandObj.logToStderr(
`Removed commitments:\n\n${CCsWithWaitDelegationStatusString}`,
Expand Down Expand Up @@ -573,10 +573,13 @@ export async function collateralWithdraw(

if (firstMoveResourcesFromDealTx !== undefined) {
try {
await signBatch(
`Moving resources from the following deals:\n${dealsString}`,
[firstMoveResourcesFromDealTx, ...restMoveResourcesFromDealTxs],
);
await signBatch({
title: `Moving resources from the following deals:\n${dealsString}`,
populatedTxs: [
firstMoveResourcesFromDealTx,
...restMoveResourcesFromDealTxs,
],
});
} catch (e) {
commandObj.warn(
`Wasn't able to move resources from deals for ${stringifyBasicCommitmentInfo(commitment)}. Most likely the reason is you must wait until the provider exits from all the following deals:\n${dealsString}`,
Expand Down Expand Up @@ -609,22 +612,23 @@ export async function collateralWithdraw(
},
);

await signBatch(
`${firstNotExitedUnit === undefined ? "Finish" : "Remove compute units from capacity commitments and finish"} commitment ${peerName === undefined ? ccId : `for ${peerName} (${ccId})`} ${ccId}`,
firstNotExitedUnit === undefined
? [populateTx(contracts.diamond.finishCommitment, ccId)]
: [
populateTx(contracts.diamond.removeCUFromCC, ccId, [
firstNotExitedUnit.unitId,
]),
...restNotExitedUnits.map(({ unitId }) => {
return populateTx(contracts.diamond.removeCUFromCC, ccId, [
unitId,
]);
}),
populateTx(contracts.diamond.finishCommitment, ccId),
],
);
await signBatch({
title: `${firstNotExitedUnit === undefined ? "Finish" : "Remove compute units from capacity commitments and finish"} commitment ${peerName === undefined ? ccId : `for ${peerName} (${ccId})`} ${ccId}`,
populatedTxs:
firstNotExitedUnit === undefined
? [populateTx(contracts.diamond.finishCommitment, ccId)]
: [
populateTx(contracts.diamond.removeCUFromCC, ccId, [
firstNotExitedUnit.unitId,
]),
...restNotExitedUnits.map(({ unitId }) => {
return populateTx(contracts.diamond.removeCUFromCC, ccId, [
unitId,
]);
}),
populateTx(contracts.diamond.finishCommitment, ccId),
],
});
}
}

Expand All @@ -633,19 +637,19 @@ export async function collateralRewardWithdraw(flags: CCFlags) {
const [firstCommitment, ...restCommitments] = commitments;
const { contracts } = await getContracts();

await signBatch(
`Withdraw rewards for commitments:\n\n${commitments
await signBatch({
title: `Withdraw rewards for commitments:\n\n${commitments
.map(({ ccId }) => {
return ccId;
})
.join("\n")}`,
[
populatedTxs: [
populateTx(contracts.diamond.withdrawReward, firstCommitment.ccId),
...restCommitments.map(({ ccId }) => {
return populateTx(contracts.diamond.withdrawReward, ccId);
}),
],
);
});
}

export function stringifyBasicCommitmentInfo({
Expand Down
20 changes: 10 additions & 10 deletions packages/cli/package/src/lib/chain/offer/updateOffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ export async function updateOffers(flags: OffersArgs) {
return;
}

await signBatch(
`Updating offers:\n\n${populatedTxs
await signBatch({
title: `Updating offers:\n\n${populatedTxs
.map(({ offerName, offerId }) => {
return `${offerName} (${offerId})`;
})
.join("\n")}`,
[firstUpdateOffersTx, ...restUpdateOffersTxs],
assertProviderIsRegistered,
);
populatedTxs: [firstUpdateOffersTx, ...restUpdateOffersTxs],
validateAddress: assertProviderIsRegistered,
});

const peersToDeploy = populatedTxs.flatMap(({ txs }) => {
return txs.flatMap(({ peersToDeploy }) => {
Expand Down Expand Up @@ -190,15 +190,15 @@ export async function removeOffers(flags: OffersArgs) {
return;
}

await signBatch(
`Removing offers:\n\n${populatedTxs
await signBatch({
title: `Removing offers:\n\n${populatedTxs
.map(({ offerName, offerId }) => {
return `${offerName} (${offerId})`;
})
.join("\n")}`,
[firstRemoveOffersTx, ...restRemoveOffersTxs],
assertProviderIsRegistered,
);
populatedTxs: [firstRemoveOffersTx, ...restRemoveOffersTxs],
validateAddress: assertProviderIsRegistered,
});

const providerArtifactsConfig = await initNewProviderArtifactsConfig();

Expand Down
12 changes: 12 additions & 0 deletions packages/cli/package/src/lib/configs/initConfigNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function getConfigInitFunction<
getSchemaDirPath,
getConfigPath,
description,
reset = false,
}: InitConfigOptions<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>,
getDefaultConfig?: GetDefaultConfig<
GetLatestConfig<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>
Expand All @@ -119,6 +120,10 @@ export function getConfigInitFunction<
return async () => {
const expectedConfigPath = await getConfigPath();

if (reset) {
initializedConfigs.delete(expectedConfigPath);
}

const previouslyInitializedConfig =
await initializedConfigs.get(expectedConfigPath);

Expand Down Expand Up @@ -159,6 +164,7 @@ export function getConfigInitFunction<
getDefaultConfig,
getSchemaDirPath,
description,
reset,
});

if (getLatestConfigRes === null) {
Expand Down Expand Up @@ -278,6 +284,7 @@ async function getLatestConfig<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>({
getDefaultConfig,
getSchemaDirPath,
description,
reset,
}: {
options: OptionsTuple<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>;
expectedConfigPath: string;
Expand All @@ -286,6 +293,7 @@ async function getLatestConfig<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>({
| undefined;
getSchemaDirPath: GetPath | undefined;
description: string;
reset: boolean;
}): Promise<{
latestConfig: GetLatestConfig<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>;
latestConfigString: string;
Expand Down Expand Up @@ -428,6 +436,10 @@ async function getLatestConfig<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>({
currentConfig = { version: initialVersion + index, ...migrated };
}

if (reset && configOptions.onReset !== undefined) {
await configOptions.onReset();
}

if (configOptions.refineSchema !== undefined) {
configOptions.schema = await configOptions.refineSchema(
// @ts-expect-error - we have to do this to be able to modify pieces of the schema independently
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package/src/lib/configs/initConfigNewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type ConfigOptionsWithoutMigrate<Config> = {
refineSchema?: (
schema: Schema<Config>,
) => Promise<Schema<Config>> | Schema<Config>;
onReset?: () => void | Promise<void>;
};

export type ConfigOptions<PrevConfig, Config> = PrevConfig extends undefined
Expand Down Expand Up @@ -104,4 +105,5 @@ export type InitConfigOptions<
options: OptionsTuple<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>;
getConfigPath: GetPath;
getSchemaDirPath?: GetPath;
reset?: boolean;
};
Loading
Loading