Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
566faae
add update_provider_via_governance extrinsic
saraswatpuneet Sep 2, 2025
c6a6446
provider update related ext
saraswatpuneet Sep 2, 2025
ff260b4
add extrinsics to update a given application
saraswatpuneet Sep 2, 2025
fa1dfcb
add provider/application update tests
saraswatpuneet Sep 3, 2025
e8d61b7
add benchmarks and tests
saraswatpuneet Sep 3, 2025
ce09338
Update weights
saraswatpuneet Sep 3, 2025
02208fe
update weights and add e2e tests
saraswatpuneet Sep 3, 2025
5f47790
lint e2e
saraswatpuneet Sep 3, 2025
3e53ac9
Merge branch 'feat/provider-context-development' into 2549_update_pro…
saraswatpuneet Sep 3, 2025
8fcd4d3
add a non sudo required create application function and block it in r…
saraswatpuneet Sep 4, 2025
fa789ef
cleanups
saraswatpuneet Sep 4, 2025
19dac9b
better assertions
saraswatpuneet Sep 4, 2025
232bf98
update benchmarks to run over a lenght of locales
saraswatpuneet Sep 4, 2025
013b982
Update weights
saraswatpuneet Sep 4, 2025
156ae37
make benchmakrs more grandular
saraswatpuneet Sep 4, 2025
9af87fb
temporary: to make benchmarks run with m,n
saraswatpuneet Sep 4, 2025
720a627
Update weights
saraswatpuneet Sep 4, 2025
a8e49d7
improve benchmarks
saraswatpuneet Sep 4, 2025
e7f01ed
Update weights
saraswatpuneet Sep 4, 2025
d7451c3
set correct weights on extrinsics
saraswatpuneet Sep 4, 2025
1dab27b
Update weights
saraswatpuneet Sep 4, 2025
1fa7330
fix lint
saraswatpuneet Sep 4, 2025
7e40764
block on filter
saraswatpuneet Sep 4, 2025
5680042
remove hidden in test
saraswatpuneet Sep 5, 2025
c6a4a74
update pallet readme with new apis and runtime api
saraswatpuneet Sep 5, 2025
6517305
set proper removabls of older cids from logo storage
saraswatpuneet Sep 5, 2025
a8643af
Update weights
saraswatpuneet Sep 5, 2025
b944fe8
better assertions
saraswatpuneet Sep 6, 2025
267f015
remove unused variable
saraswatpuneet Sep 6, 2025
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
126 changes: 126 additions & 0 deletions e2e/msa/update_provider_application.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import '@frequency-chain/api-augment';
import assert from 'assert';
import { KeyringPair } from '@polkadot/keyring/types';
import { fileURLToPath } from 'url';
import path from 'path';

import { createAndFundKeypair, DOLLARS, generateValidProviderPayloadWithName } from '../scaffolding/helpers';
import { ExtrinsicHelper, EventMap } from '../scaffolding/extrinsicHelpers';
import { getFundingSource, getSudo } from '../scaffolding/funding';
import { isTestnet } from '../scaffolding/env';

// reconstruct __dirname in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

let fundingSource: KeyringPair;

describe('Update Provider and Application', function () {
let sudoKeys: KeyringPair;
let providerKeys: KeyringPair;
let providerId: bigint;

before(async function () {
sudoKeys = getSudo().keys;
fundingSource = await getFundingSource(import.meta.url);
providerKeys = await createAndFundKeypair(fundingSource, 10n * DOLLARS, 'upd-provider');

// create MSA and register provider
const f = ExtrinsicHelper.createMsa(providerKeys);
await f.fundAndSend(fundingSource);

const providerEntry = generateValidProviderPayloadWithName('UpdProv');
const createProviderOp = ExtrinsicHelper.createProviderV2(providerKeys, providerEntry);
const { target: providerEvent } = await createProviderOp.signAndSend();
assert.notEqual(providerEvent, undefined, 'should emit ProviderCreated');
providerId = providerEvent!.data.providerId.toBigInt();
assert(providerId > 0n, 'providerId should be > 0');
});

describe('update provider via governance', function () {
it('should successfully update provider defaultName via governance', async function () {
if (isTestnet()) this.skip();
const updated = generateValidProviderPayloadWithName('UpdProv2');

const op = ExtrinsicHelper.updateProviderViaGovernance(sudoKeys, providerKeys, updated);
const { target } = await op.signAndSend();
assert.notEqual(target, undefined, 'should emit ProviderUpdated');

// Verify default name changed via runtime API
const ctx = await ExtrinsicHelper.apiPromise.call.msaRuntimeApi.getProviderApplicationContext(
providerId,
null,
null
);
assert.equal(ctx.isSome, true, 'provider context should be some');
const result = ctx.unwrap();
const defaultName = new TextDecoder().decode(result.defaultName.toU8a(true));
assert.equal(defaultName, 'UpdProv2', 'provider default name should update');
});
});

describe('propose to update provider', function () {
it('should submit a proposal to update provider', async function () {
if (isTestnet()) this.skip();
const updated = generateValidProviderPayloadWithName('UpdProv3');

const op = ExtrinsicHelper.proposeToUpdateProvider(providerKeys, updated);
const { target } = await op.signAndSend();
assert.notEqual(target, undefined, 'should emit Council.Proposed');
});
});

describe('update application via governance', function () {
let applicationId: bigint;

before(async function () {
if (isTestnet()) this.skip();
// create a base application to update
const app = generateValidProviderPayloadWithName('BaseApp');
const createAppOp = ExtrinsicHelper.createApplicationViaGovernance(sudoKeys, providerKeys, app);
const { target } = await createAppOp.signAndSend();
assert.notEqual(target, undefined, 'should emit ApplicationCreated');
applicationId = target!.data.applicationId.toBigInt();
});

it('should update an existing application via governance', async function () {
if (isTestnet()) this.skip();
const updated = generateValidProviderPayloadWithName('AppUpdated');

const op = ExtrinsicHelper.updateApplicationViaGovernance(sudoKeys, providerKeys, applicationId, updated);
const { target } = await op.signAndSend();
assert.notEqual(target, undefined, 'should emit ApplicationContextUpdated');

// fetch context and verify name
const ctx = await ExtrinsicHelper.apiPromise.call.msaRuntimeApi.getProviderApplicationContext(
providerId,
applicationId,
null
);
assert.equal(ctx.isSome, true, 'app context should be some');
const result = ctx.unwrap();
const defaultName = new TextDecoder().decode(result.defaultName.toU8a(true));
assert.equal(defaultName, 'AppUpdated', 'app default name should update');
});
});

describe('propose to update application', function () {
it('should submit a proposal to update application', async function () {
if (isTestnet()) this.skip();
// create an app to have an index
const app = generateValidProviderPayloadWithName('PropBase');
const { target } = await ExtrinsicHelper.createApplicationViaGovernance(
sudoKeys,
providerKeys,
app
).signAndSend();
assert.notEqual(target, undefined, 'should emit ApplicationCreated');
const appId = target!.data.applicationId.toBigInt();

const updated = generateValidProviderPayloadWithName('PropUpd');
const op = ExtrinsicHelper.proposeToUpdateApplication(providerKeys, appId, updated);
const { target: proposed } = await op.signAndSend();
assert.notEqual(proposed, undefined, 'should emit Council.Proposed');
});
});
});
69 changes: 69 additions & 0 deletions e2e/scaffolding/extrinsicHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,75 @@ export class ExtrinsicHelper {
);
}

public static updateProviderViaGovernance(
sudoKeys: KeyringPair,
providerKeys: KeyringPair,
details: ProviderRegistryEntry
) {
return new Extrinsic(
() =>
ExtrinsicHelper.api.tx.msa.updateProviderViaGovernance(getUnifiedPublicKey(providerKeys), {
defaultName: details.defaultName,
localizedNames: details.localizedNames,
defaultLogo250100PngCid: details.defaultLogo250100PngCid,
localizedLogo250100PngCids: details.localizedLogo250100PngCids,
}),
sudoKeys,
ExtrinsicHelper.api.events.msa.ProviderUpdated
);
}

public static proposeToUpdateProvider(providerKeys: KeyringPair, details: ProviderRegistryEntry) {
return new Extrinsic(
() =>
ExtrinsicHelper.api.tx.msa.proposeToUpdateProvider({
defaultName: details.defaultName,
localizedNames: details.localizedNames,
defaultLogo250100PngCid: details.defaultLogo250100PngCid,
localizedLogo250100PngCids: details.localizedLogo250100PngCids,
}),
providerKeys,
ExtrinsicHelper.api.events.council.Proposed
);
}

public static updateApplicationViaGovernance(
sudoKeys: KeyringPair,
providerKeys: KeyringPair,
applicationIndex: AnyNumber,
appDetails: ProviderRegistryEntry
) {
return new Extrinsic(
() =>
ExtrinsicHelper.api.tx.msa.updateApplicationViaGovernance(getUnifiedPublicKey(providerKeys), applicationIndex, {
defaultName: appDetails.defaultName,
localizedNames: appDetails.localizedNames,
defaultLogo250100PngCid: appDetails.defaultLogo250100PngCid,
localizedLogo250100PngCids: appDetails.localizedLogo250100PngCids,
}),
sudoKeys,
ExtrinsicHelper.api.events.msa.ApplicationContextUpdated
);
}

public static proposeToUpdateApplication(
providerKeys: KeyringPair,
applicationIndex: AnyNumber,
appDetails: ProviderRegistryEntry
) {
return new Extrinsic(
() =>
ExtrinsicHelper.api.tx.msa.proposeToUpdateApplication(applicationIndex, {
defaultName: appDetails.defaultName,
localizedNames: appDetails.localizedNames,
defaultLogo250100PngCid: appDetails.defaultLogo250100PngCid,
localizedLogo250100PngCids: appDetails.localizedLogo250100PngCids,
}),
providerKeys,
ExtrinsicHelper.api.events.council.Proposed
);
}

public static uploadLogo(providerKeys: KeyringPair, logoCid: any, logoBytes: any) {
return new Extrinsic(
() => ExtrinsicHelper.api.tx.msa.uploadLogo(logoCid, logoBytes),
Expand Down
Loading
Loading