Skip to content

Commit

Permalink
Merge branch 'main' into 1850-bug-transacting-with-capacity-should-no…
Browse files Browse the repository at this point in the history
…t-require-tokens-to-cover-transaction-cost
  • Loading branch information
mattheworris authored Jan 24, 2024
2 parents 57b7442 + 8679b88 commit f5c8b9f
Show file tree
Hide file tree
Showing 12 changed files with 703 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/verify-pr-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ jobs:
uses: actions/checkout@v4
- name: Set Up Cargo Deny
run: |
cargo install --force cargo-deny
cargo install --force --locked cargo-deny
cargo generate-lockfile
- name: Run Cargo Deny
run: cargo deny check --hide-inclusion-graph -c deny.toml
Expand Down
3 changes: 1 addition & 2 deletions e2e/capacity/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
getOrCreateAvroChatMessageItemizedSchema,
getOrCreateParquetBroadcastSchema,
getOrCreateAvroChatMessagePaginatedSchema,
generateItemizedSignaturePayloadV2,
generatePaginatedUpsertSignaturePayloadV2,
generatePaginatedDeleteSignaturePayloadV2,
getCapacity,
Expand Down Expand Up @@ -387,7 +386,7 @@ describe('Capacity Transactions', function () {
const target_hash = await getCurrentItemizedHash(delegatorProviderId, itemizedSchemaId);

const add_actions = [add_action, update_action];
const payload = await generateItemizedSignaturePayloadV2({
const payload = await generateItemizedSignaturePayload({
targetHash: target_hash,
schemaId: itemizedSchemaId,
actions: add_actions,
Expand Down
2 changes: 1 addition & 1 deletion e2e/package-lock.json

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

73 changes: 60 additions & 13 deletions e2e/scaffolding/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Keyring } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';
import { u16, u32, u64, Option } from '@polkadot/types';
import { u16, u32, u64, Option, Bytes } from '@polkadot/types';
import type { FrameSystemAccountInfo, PalletCapacityCapacityDetails } from '@polkadot/types/lookup';
import { Codec } from '@polkadot/types/types';
import { u8aToHex, u8aWrapBytes } from '@polkadot/util';
Expand All @@ -24,6 +24,7 @@ import {
MessageResponse,
MessageSourceId,
PageHash,
SchemaId,
} from '@frequency-chain/api-augment/interfaces';
import assert from 'assert';
import { AVRO_GRAPH_CHANGE } from '../schemas/fixtures/avroGraphChangeSchemaType';
Expand Down Expand Up @@ -87,7 +88,7 @@ export async function generateAddKeyPayload(
}

export async function generateItemizedSignaturePayload(
payloadInputs: ItemizedSignaturePayload,
payloadInputs: ItemizedSignaturePayload | ItemizedSignaturePayloadV2,
expirationOffset: number = 100,
blockNumber?: number
): Promise<ItemizedSignaturePayload> {
Expand All @@ -99,17 +100,63 @@ export async function generateItemizedSignaturePayload(
};
}

export async function generateItemizedSignaturePayloadV2(
payloadInputs: ItemizedSignaturePayloadV2,
expirationOffset: number = 100,
blockNumber?: number
): Promise<ItemizedSignaturePayloadV2> {
const { expiration, ...payload } = payloadInputs;
export function generateItemizedActions(items: { action: 'Add' | 'Update'; value: string }[]) {
return items.map(({ action, value }) => {
const actionObj = {};
actionObj[action] = new Bytes(ExtrinsicHelper.api.registry, value);
return actionObj;
});
}

return {
expiration: expiration || (blockNumber || (await getBlockNumber())) + expirationOffset,
...payload,
export async function generateItemizedActionsPayloadAndSignature(
payloadInput: ItemizedSignaturePayload | ItemizedSignaturePayloadV2,
payloadType: 'PalletStatefulStorageItemizedSignaturePayload' | 'PalletStatefulStorageItemizedSignaturePayloadV2',
signingKeys: KeyringPair
) {
const payloadData = await generateItemizedSignaturePayload(payloadInput);
const payload = ExtrinsicHelper.api.registry.createType(payloadType, payloadData);
const signature = signPayloadSr25519(signingKeys, payload);

return { payload: payloadData, signature };
}

export async function generateItemizedActionsSignedPayload(
actions: any[],
schemaId: SchemaId,
signingKeys: KeyringPair,
msaId: MessageSourceId
) {
const payloadInput: ItemizedSignaturePayload = {
msaId,
targetHash: await getCurrentItemizedHash(msaId, schemaId),
schemaId,
actions,
};

return generateItemizedActionsPayloadAndSignature(
payloadInput,
'PalletStatefulStorageItemizedSignaturePayload',
signingKeys
);
}

export async function generateItemizedActionsSignedPayloadV2(
actions: any[],
schemaId: SchemaId,
signingKeys: KeyringPair,
msaId: MessageSourceId
) {
const payloadInput: ItemizedSignaturePayloadV2 = {
targetHash: await getCurrentItemizedHash(msaId, schemaId),
schemaId,
actions,
};

return generateItemizedActionsPayloadAndSignature(
payloadInput,
'PalletStatefulStorageItemizedSignaturePayloadV2',
signingKeys
);
}

export async function generatePaginatedUpsertSignaturePayload(
Expand Down Expand Up @@ -270,7 +317,7 @@ export async function createDelegator(source: KeyringPair, amount?: bigint): Pro

export async function createDelegatorAndDelegation(
source: KeyringPair,
schemaId: u16,
schemaId: u16 | u16[],
providerId: u64,
providerKeys: KeyringPair
): Promise<[KeyringPair, u64]> {
Expand All @@ -280,7 +327,7 @@ export async function createDelegatorAndDelegation(
// Grant delegation to the provider
const payload = await generateDelegationPayload({
authorizedMsaId: providerId,
schemaIds: [schemaId],
schemaIds: Array.isArray(schemaId) ? schemaId : [schemaId],
});
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', payload);

Expand Down
16 changes: 11 additions & 5 deletions e2e/stateful-pallet-storage/handleItemized.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const fundingSource = getFundingSource('stateful-storage-handle-itemized');
describe('📗 Stateful Pallet Storage', function () {
let schemaId_deletable: SchemaId;
let schemaId_unsupported: SchemaId;
let delegatorKeys: KeyringPair;
let msa_id: MessageSourceId;
let providerId: MessageSourceId;
let providerKeys: KeyringPair;
Expand All @@ -46,7 +47,12 @@ describe('📗 Stateful Pallet Storage', function () {
assert.notEqual(event2, undefined, 'setup should return a SchemaCreated event');
schemaId_unsupported = event2!.data.schemaId;
// Create a MSA for the delegator and delegate to the provider
[, msa_id] = await createDelegatorAndDelegation(fundingSource, schemaId_deletable, providerId, providerKeys);
[delegatorKeys, msa_id] = await createDelegatorAndDelegation(
fundingSource,
schemaId_deletable,
providerId,
providerKeys
);
assert.notEqual(msa_id, undefined, 'setup should populate msa_id');
// Create an MSA that is not a provider to be used for testing failure cases
[badMsaId] = await createMsa(fundingSource);
Expand Down Expand Up @@ -104,7 +110,7 @@ describe('📗 Stateful Pallet Storage', function () {
const add_actions = [add_action];
const fake_schema_id = new u16(ExtrinsicHelper.api.registry, 65_534);
const itemized_add_result_1 = ExtrinsicHelper.applyItemActions(
providerKeys,
delegatorKeys,
fake_schema_id,
msa_id,
add_actions,
Expand All @@ -123,7 +129,7 @@ describe('📗 Stateful Pallet Storage', function () {
};
const add_actions = [add_action];
const itemized_add_result_1 = ExtrinsicHelper.applyItemActions(
providerKeys,
delegatorKeys,
schemaId_unsupported,
msa_id,
add_actions,
Expand Down Expand Up @@ -224,7 +230,7 @@ describe('📗 Stateful Pallet Storage', function () {
const remove_actions = [remove_action_1];
const fake_schema_id = new u16(ExtrinsicHelper.api.registry, 65_534);
const itemized_remove_result_1 = ExtrinsicHelper.applyItemActions(
providerKeys,
delegatorKeys,
fake_schema_id,
msa_id,
remove_actions,
Expand All @@ -243,7 +249,7 @@ describe('📗 Stateful Pallet Storage', function () {
};
const remove_actions = [remove_action_1];
const itemized_remove_result_1 = ExtrinsicHelper.applyItemActions(
providerKeys,
delegatorKeys,
schemaId_unsupported,
msa_id,
remove_actions,
Expand Down
17 changes: 12 additions & 5 deletions e2e/stateful-pallet-storage/handlePaginated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const fundingSource = getFundingSource('stateful-storage-handle-paginated');
describe('📗 Stateful Pallet Storage', function () {
let schemaId: SchemaId;
let schemaId_unsupported: SchemaId;
let delegatorKeys: KeyringPair;
let msa_id: MessageSourceId;
let providerId: MessageSourceId;
let providerKeys: KeyringPair;
Expand All @@ -44,7 +45,7 @@ describe('📗 Stateful Pallet Storage', function () {
schemaId_unsupported = event2!.data.schemaId;

// Create a MSA for the delegator and delegate to the provider
[, msa_id] = await createDelegatorAndDelegation(fundingSource, schemaId, providerId, providerKeys);
[delegatorKeys, msa_id] = await createDelegatorAndDelegation(fundingSource, schemaId, providerId, providerKeys);
assert.notEqual(msa_id, undefined, 'setup should populate msa_id');

// Create an MSA that is not a provider to be used for testing failure cases
Expand Down Expand Up @@ -142,7 +143,7 @@ describe('📗 Stateful Pallet Storage', function () {
const payload_1 = new Bytes(ExtrinsicHelper.api.registry, 'Hello World From Frequency');
const fake_schema_id = new u16(ExtrinsicHelper.api.registry, badSchemaId);
const paginated_add_result_1 = ExtrinsicHelper.upsertPage(
providerKeys,
delegatorKeys,
fake_schema_id,
msa_id,
page_id,
Expand All @@ -160,7 +161,7 @@ describe('📗 Stateful Pallet Storage', function () {
const target_hash = await getCurrentPaginatedHash(msa_id, schemaId, page_id);
const payload_1 = new Bytes(ExtrinsicHelper.api.registry, 'Hello World From Frequency');
const paginated_add_result_1 = ExtrinsicHelper.upsertPage(
providerKeys,
delegatorKeys,
schemaId_unsupported,
msa_id,
page_id,
Expand Down Expand Up @@ -207,7 +208,7 @@ describe('📗 Stateful Pallet Storage', function () {
describe('Paginated Storage Removal Negative Tests 😊/😥', function () {
it('🛑 should fail call to remove page with invalid schemaId', async function () {
const page_id = 0;
const paginated_add_result_1 = ExtrinsicHelper.removePage(providerKeys, badSchemaId, msa_id, page_id, 0);
const paginated_add_result_1 = ExtrinsicHelper.removePage(delegatorKeys, badSchemaId, msa_id, page_id, 0);
await assert.rejects(paginated_add_result_1.fundAndSend(fundingSource), {
name: 'InvalidSchemaId',
section: 'statefulStorage',
Expand All @@ -216,7 +217,13 @@ describe('📗 Stateful Pallet Storage', function () {

it('🛑 should fail call to remove page with invalid schema location', async function () {
const page_id = 0;
const paginated_add_result_1 = ExtrinsicHelper.removePage(providerKeys, schemaId_unsupported, msa_id, page_id, 0);
const paginated_add_result_1 = ExtrinsicHelper.removePage(
delegatorKeys,
schemaId_unsupported,
msa_id,
page_id,
0
);
await assert.rejects(paginated_add_result_1.fundAndSend(fundingSource), {
name: 'SchemaPayloadLocationMismatch',
section: 'statefulStorage',
Expand Down
Loading

0 comments on commit f5c8b9f

Please sign in to comment.