Skip to content

Commit a49d337

Browse files
authored
Fix token symbol testnet (#2159)
# Goal The goal of this PR is to fix an issue with the token symbols for testnet found while testing CheckMetadataHash extension. Part of #2011 # Discussion - Corrected the symbols used for `node/service/src/chain_spec/frequency_paseo.rs` - Corrected the symbols used in the `substrate_wasm_builder::WasmBuilder::init_with_defaults().enable_metadata_hash` - Added a skipped e2e test that can be run to test transacting using the `metadata_hash` - Required: Update cargo deny exclusions - Adjacent: Updated the API Augment packages - Adjacent: Updated the API Augment to have all the no-op signed extensions and remove warnings - Adjacent: Updated the API Augment to list all the old v1 rpcs remove warnings # Checklist - [x] Updated js/api-augment for Custom RPC OR Runtime API? - [x] e2e Tests added? - [x] Spec version incremented? # How to Test With the e2e test: - Build Frequency using the feature `metadata-hash` (EZ mode: edit line 109 of `init.sh` to have it as one of the features) - Set the `skip` in `e2e/signed-extensions/checkMetadataHash.test.ts` to be only - Run `make js` - `cd e2e` - `npm i ../js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz` - `npm run test:serial` 1. See that the test passes 2. See that there are no warnings about signed extensions 3. See that there are no warnings about rpcs Note: You will see an warning about `PORTABLEREGISTRY: Unable to determine runtime Call type, cannot inspect sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic` However that appears to be due to an issue with the latest version of Polkadotjs/api and not related to these changes nor does it impact the running of the api.
1 parent f86762f commit a49d337

File tree

15 files changed

+582
-374
lines changed

15 files changed

+582
-374
lines changed

deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ ignore = [
7474
{ id = "RUSTSEC-2024-0336", reason = "Only use of [email protected] is in futures-rustls which does not use the effected code" },
7575
{ id = "RUSTSEC-2024-0344", reason = "We are only able to remove this once parity updates its dependencies. Older versions of curve25519-dalek should get replaces with >= 4.1.3" },
7676
{ id = "RUSTSEC-2022-0093", reason = "The vulnerable code is not exploitable in Frequency because the signing function is not exposed in a way that allows the use of arbitrary public keys, ensuring protection against the described vulnerability." },
77+
{ id = "RUSTSEC-2024-0370", reason = "proc-macro-error is used by a few dependencies, and while unmaintained, is not currently an issue." },
7778
]
7879
# If this is true, then cargo deny will use the git executable to fetch advisory database.
7980
# If this is false, then it uses a built-in git library.

e2e/package-lock.json

Lines changed: 150 additions & 124 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
"@frequency-chain/api-augment": "file:../js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz",
2222
"@helia/unixfs": "^3.0.7",
2323
"@noble/curves": "^1.6.0",
24-
"@polkadot/api": "13.0.1",
25-
"@polkadot/types": "13.0.1",
24+
"@polkadot-api/merkleize-metadata": "^1.1.2",
25+
"@polkadot/api": "13.1.1",
26+
"@polkadot/types": "13.1.1",
2627
"@polkadot/util": "13.1.1",
2728
"helia": "^4.2.6",
2829
"multiformats": "^13.3.0",
@@ -37,7 +38,7 @@
3738
"eslint-plugin-mocha": "^10.5.0",
3839
"globals": "^15.9.0",
3940
"mocha": "^10.7.3",
40-
"node-datachannel": "^0.11.0",
41+
"node-datachannel": "^0.12.0",
4142
"prettier": "^3.3.3",
4243
"sinon": "^19.0.2",
4344
"tsx": "^4.19.1",

e2e/scaffolding/extrinsicHelpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import '@frequency-chain/api-augment';
22
import { ApiPromise, ApiRx } from '@polkadot/api';
3-
import { ApiTypes, AugmentedEvent, SubmittableExtrinsic } from '@polkadot/api/types';
3+
import { ApiTypes, AugmentedEvent, SubmittableExtrinsic, SignerOptions } from '@polkadot/api/types';
44
import { KeyringPair } from '@polkadot/keyring/types';
55
import { Compact, u128, u16, u32, u64, Vec, Option, Bool } from '@polkadot/types';
66
import { FrameSystemAccountInfo, PalletPasskeyPasskeyPayload, SpRuntimeDispatchError } from '@polkadot/types/lookup';
@@ -175,14 +175,14 @@ export class Extrinsic<N = unknown, T extends ISubmittableResult = ISubmittableR
175175
}
176176

177177
// This uses automatic nonce management by default.
178-
public async signAndSend(inputNonce?: AutoNonce) {
178+
public async signAndSend(inputNonce?: AutoNonce, options: Partial<SignerOptions> = {}) {
179179
const nonce = await autoNonce.auto(this.keys, inputNonce);
180180

181181
try {
182182
const op = this.extrinsic();
183183
// Era is 0 for tests due to issues with BirthBlock
184184
return await firstValueFrom(
185-
op.signAndSend(this.keys, { nonce, era: 0 }).pipe(
185+
op.signAndSend(this.keys, { nonce, era: 0, ...options }).pipe(
186186
tap((result) => {
187187
// If we learn a transaction has an error status (this does NOT include RPC errors)
188188
// Then throw an error

e2e/scaffolding/funding.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ export const fundingSources = [
1414
'capacity-staking',
1515
'capacity-transactions',
1616
'capacity-unstaking',
17+
'check-metadata-hash',
1718
'frequency-misc',
1819
'handles',
1920
'load-signature-registry',
2021
'messages-add-ipfs',
2122
'misc-util-batch',
2223
'msa-create-msa',
2324
'msa-key-management',
25+
'passkey-proxy',
2426
'proxy-pallet',
2527
'scenarios-grant-delegation',
2628
'schemas-create',
@@ -29,7 +31,6 @@ export const fundingSources = [
2931
'stateful-storage-handle-sig-req',
3032
'sudo-transactions',
3133
'time-release',
32-
'passkey-proxy',
3334
] as const;
3435

3536
// Get the correct key for this Funding Source
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import '@frequency-chain/api-augment';
2+
3+
import assert from 'assert';
4+
5+
import { KeyringPair } from '@polkadot/keyring/types';
6+
import { merkleizeMetadata } from '@polkadot-api/merkleize-metadata';
7+
import { Extrinsic, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
8+
import {
9+
createKeys,
10+
createAndFundKeypair,
11+
assertExtrinsicSuccess,
12+
generateSchemaPartialName,
13+
} from '../scaffolding/helpers';
14+
import { getFundingSource } from '../scaffolding/funding';
15+
import { u8aToHex } from '@polkadot/util';
16+
17+
const fundingSource = getFundingSource('check-metadata-hash');
18+
19+
// This is skipped as it requires the e2e tests to be run
20+
// against a Frequency build that has the metadata-hash feature
21+
// enabled. That feature is a large increase in compile time however.
22+
describe.skip('Check Metadata Hash', function () {
23+
let keys: KeyringPair;
24+
let accountWithNoFunds: KeyringPair;
25+
26+
before(async function () {
27+
keys = await createAndFundKeypair(fundingSource, 10_000_000n);
28+
accountWithNoFunds = createKeys();
29+
});
30+
31+
it('should successfully transfer funds', async function () {
32+
const tx = ExtrinsicHelper.api.tx.balances.transferKeepAlive(accountWithNoFunds.address, 5_000_000n);
33+
34+
const api = ExtrinsicHelper.apiPromise;
35+
const metadata = await api.call.metadata.metadataAtVersion(15);
36+
const { specName, specVersion } = api.runtimeVersion;
37+
const merkleInfo = {
38+
base58Prefix: api.consts.system.ss58Prefix.toNumber(),
39+
decimals: api.registry.chainDecimals[0],
40+
specName: specName.toString(),
41+
specVersion: specVersion.toNumber(),
42+
tokenSymbol: api.registry.chainTokens[0],
43+
};
44+
45+
const merkleizedMetadata = merkleizeMetadata(metadata.toHex(), merkleInfo);
46+
const metadataHash = u8aToHex(merkleizedMetadata.digest());
47+
48+
const extrinsic = new Extrinsic(() => tx, keys);
49+
50+
const { eventMap } = await extrinsic.signAndSend('auto', {
51+
withSignedTransaction: true,
52+
mode: 1,
53+
metadataHash,
54+
});
55+
56+
assertExtrinsicSuccess(eventMap);
57+
});
58+
});

js/api-augment/index.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
2+
import { DefinitionRpc } from '@polkadot/types/types';
23
import './interfaces/types-lookup.js';
34
import './interfaces/augment-api.js';
45
import './interfaces/augment-types.js';
56
import './interfaces/index.js';
67
import * as definitions from './interfaces/definitions.js';
8+
import { v1SubstrateRpcs } from './substrate_v1_rpcs.js';
79

810
/**
911
* Build up the types for ApiPromise.create
@@ -18,12 +20,16 @@ export const types = Object.entries(definitions).reduce((acc, [_key, value]) =>
1820
/**
1921
* Build up the rpc calls for ApiPromise.create
2022
*/
21-
export const rpc = Object.entries(definitions).reduce((acc, [key, value]) => {
22-
return {
23-
...acc,
24-
[key]: value.rpc,
25-
};
26-
}, {});
23+
export const rpc: Record<string, Record<string, DefinitionRpc>> = Object.entries(definitions).reduce(
24+
(acc, [key, value]) => {
25+
return {
26+
...acc,
27+
[key]: value.rpc,
28+
};
29+
},
30+
// v1 rpc calls to be ignored
31+
{ ...v1SubstrateRpcs }
32+
);
2733

2834
/**
2935
* Frequency Specific Signed Extensions
@@ -38,6 +44,14 @@ export const signedExtensions: ExtDef = {
3844
extrinsic: {},
3945
payload: {},
4046
},
47+
StaleHashCheckExtension: {
48+
extrinsic: {},
49+
payload: {},
50+
},
51+
StorageWeightReclaim: {
52+
extrinsic: {},
53+
payload: {},
54+
},
4155
};
4256

4357
/**

0 commit comments

Comments
 (0)