Skip to content

Commit

Permalink
Merge branch 'main' into 1994
Browse files Browse the repository at this point in the history
  • Loading branch information
saraswatpuneet committed Nov 25, 2024
2 parents f1af612 + e95a823 commit 313a395
Show file tree
Hide file tree
Showing 55 changed files with 5,927 additions and 117 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,35 @@ jobs:
path: js/api-augment/dist
if-no-files-found: error

build-js-schemas:
name: Build JS Schemas
runs-on: ubuntu-22.04
container: ghcr.io/frequency-chain/frequency/ci-base-image:1.3.1
steps:
- name: Check Out Repo
uses: actions/checkout@v4
with:
ref: ${{env.RELEASE_BRANCH_NAME}}
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
registry-url: "https://registry.npmjs.org"
cache-dependency-path: js/schemas/package-lock.json
- name: Install
run: npm install
working-directory: js/schemas
- name: Build
run: npm run build
working-directory: js/schemas
- name: Upload Dist Dir
uses: actions/upload-artifact@v4
with:
name: js-schemas-${{github.run_id}}
path: js/schemas/dist
if-no-files-found: error

test-version-matches-release:
needs: build-binaries
name: Test Version Matches Release
Expand Down Expand Up @@ -619,6 +648,7 @@ jobs:
test-version-matches-release,
build-rust-developer-docs,
build-js-api-augment,
build-js-schemas,
]
name: Wait for All Builds to Finish
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -1051,3 +1081,44 @@ jobs:
working-directory: ./js/api-augment/dist
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

release-js-schemas:
needs: wait-for-all-builds
name: Release JS Schemas
runs-on: ubuntu-22.04
steps:
- name: Check Out Repo
uses: actions/checkout@v4
with:
ref: ${{env.RELEASE_BRANCH_NAME}}
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
registry-url: "https://registry.npmjs.org"
cache-dependency-path: js/schemas/package-lock.json
- name: Download Dist Dir
id: download
uses: actions/download-artifact@v4
with:
name: js-schemas-${{github.run_id}}
path: js/schemas/dist
- name: Version Package
if: env.TEST_RUN != 'true'
run: npm version --new-version "${{env.NEW_RELEASE_TAG}}" --no-git-tag-version
working-directory: js/schemas/dist
- name: Release on NPM @latest
if: env.TEST_RUN != 'true' &&
steps.is-full-release.outputs.is-full-release == 'true'
run: npm publish --tag latest --access public
working-directory: ./js/schemas/dist
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
- name: Release Candidate on NPM
if: env.TEST_RUN != 'true' &&
steps.is-full-release.outputs.is-full-release != 'true'
run: npm publish --tag next --access public
working-directory: ./js/schemas/dist
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
41 changes: 40 additions & 1 deletion .github/workflows/verify-pr-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ jobs:
steps:
- name: Check Out Repo
uses: actions/checkout@v4
# using older version of cargo deny since the new one requires rustc version >= 1.81
- name: Set Up Cargo Deny
run: |
cargo install --force --locked cargo-deny
cargo install --force --locked cargo-deny@0.16.1
cargo generate-lockfile
- name: Run Cargo Deny
run: cargo deny check --hide-inclusion-graph -c deny.toml
Expand Down Expand Up @@ -453,6 +454,44 @@ jobs:
path: js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz
if-no-files-found: error

verify-js-schemas:
name: Verify JS Schemas
runs-on: ubuntu-22.04
container: ghcr.io/frequency-chain/frequency/ci-base-image:1.3.1
steps:
- name: Check Out Repo
uses: actions/checkout@v4
- name: Set up NodeJs
uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
cache-dependency-path: js/schemas/package-lock.json
- name: Install Latest Versions
run: npm install
working-directory: js/schemas
- name: Lint
run: npm run lint
working-directory: js/schemas
- name: Test
run: npm test
working-directory: js/schemas
- name: Build
run: npm run build
working-directory: js/schemas
- name: Publish Dry Run
run: npm publish --dry-run
working-directory: js/schemas/dist
- name: Generate npm tarball
run: npm pack
working-directory: js/schemas/dist
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: artifacts-schemas-${{github.run_id}}
path: js/schemas/dist/frequency-chain-schemas-0.0.0.tgz
if-no-files-found: error

verify-node-docker-images:
needs: build-binaries
name: Verify Node Docker Images
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions e2e/capacity/capacityFail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
assertAddNewKey,
} from '../scaffolding/helpers';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';

const FUNDS_AMOUNT: bigint = 50n * DOLLARS;
const fundingSource = getFundingSource('capacity-transactions-fail');
Expand Down Expand Up @@ -111,7 +112,7 @@ describe('Capacity Transaction Failures', function () {

// As current owner, add a new set of control keys that do not have a balance.
const newControlKeypair = createKeys('NewKeyNoBalance');
const newPublicKey = newControlKeypair.publicKey;
const newPublicKey = getUnifiedPublicKey(newControlKeypair);
const addKeyPayload: AddKeyData = await generateAddKeyPayload({
msaId: capacityProvider,
newPublicKey: newPublicKey,
Expand Down Expand Up @@ -193,7 +194,7 @@ describe('Capacity Transaction Failures', function () {
// Add new key
const newKeyPayload: AddKeyData = await generateAddKeyPayload({
msaId: new u64(ExtrinsicHelper.api.registry, capacityProvider),
newPublicKey: noTokensKeys.publicKey,
newPublicKey: getUnifiedPublicKey(noTokensKeys),
});
const addKeyData = ExtrinsicHelper.api.registry.createType('PalletMsaAddKeyData', newKeyPayload);

Expand Down
5 changes: 3 additions & 2 deletions e2e/capacity/capacity_rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../scaffolding/helpers';
import { FeeDetails } from '@polkadot/types/interfaces';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';

const FUNDS_AMOUNT: bigint = 50n * DOLLARS;
const fundingSource = getFundingSource('capacity-rpcs');
Expand Down Expand Up @@ -46,7 +47,7 @@ describe('Capacity RPC', function () {
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', addProviderPayload);
const delegatorKeys = createKeys('delegatorKeys');
const call = ExtrinsicHelper.api.tx.msa.createSponsoredAccountWithDelegation(
delegatorKeys.publicKey,
getUnifiedPublicKey(delegatorKeys),
signPayloadSr25519(delegatorKeys, addProviderData),
addProviderPayload
);
Expand Down Expand Up @@ -89,7 +90,7 @@ describe('Capacity RPC', function () {
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', addProviderPayload);
const delegatorKeys = createKeys('delegatorKeys');
const insideTx = ExtrinsicHelper.api.tx.msa.createSponsoredAccountWithDelegation(
delegatorKeys.publicKey,
getUnifiedPublicKey(delegatorKeys),
signPayloadSr25519(delegatorKeys, addProviderData),
addProviderPayload
);
Expand Down
3 changes: 2 additions & 1 deletion e2e/capacity/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from '../scaffolding/helpers';
import { ipfsCid } from '../messages/ipfs';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';

const FUNDS_AMOUNT: bigint = 50n * DOLLARS;
const fundingSource = getFundingSource('capacity-transactions');
Expand Down Expand Up @@ -92,7 +93,7 @@ describe('Capacity Transactions', function () {

authorizedKeys.push(await createAndFundKeypair(fundingSource, 50_000_000n));
defaultPayload.msaId = capacityProvider;
defaultPayload.newPublicKey = authorizedKeys[0].publicKey;
defaultPayload.newPublicKey = getUnifiedPublicKey(authorizedKeys[0]);

const payload = await generateAddKeyPayload(defaultPayload);
const addKeyData = ExtrinsicHelper.api.registry.createType('PalletMsaAddKeyData', payload);
Expand Down
9 changes: 5 additions & 4 deletions e2e/capacity/transactionsBatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getTestHandle,
} from '../scaffolding/helpers';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedPublicKey } from '../scaffolding/ethereum';

const FUNDS_AMOUNT: bigint = 50n * DOLLARS;
const fundingSource = getFundingSource('capacity-transactions-batch');
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('Capacity Transactions Batch', function () {
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', addProviderPayload);
const delegatorKeys = createKeys('delegatorKeys');
const createSponsoredAccountWithDelegation = ExtrinsicHelper.api.tx.msa.createSponsoredAccountWithDelegation(
delegatorKeys.publicKey,
getUnifiedPublicKey(delegatorKeys),
signPayloadSr25519(delegatorKeys, addProviderData),
addProviderPayload
);
Expand All @@ -70,7 +71,7 @@ describe('Capacity Transactions Batch', function () {
};

const claimHandle = ExtrinsicHelper.api.tx.handles.claimHandle(
delegatorKeys.publicKey,
getUnifiedPublicKey(delegatorKeys),
claimHandleProof,
claimHandlePayload
);
Expand All @@ -95,7 +96,7 @@ describe('Capacity Transactions Batch', function () {
const addProviderData = ExtrinsicHelper.api.registry.createType('PalletMsaAddProvider', addProviderPayload);
const delegatorKeys = createKeys('delegatorKeys');
const createSponsoredAccountWithDelegation = ExtrinsicHelper.api.tx.msa.createSponsoredAccountWithDelegation(
delegatorKeys.publicKey,
getUnifiedPublicKey(delegatorKeys),
signPayloadSr25519(delegatorKeys, addProviderData),
addProviderPayload
);
Expand All @@ -116,7 +117,7 @@ describe('Capacity Transactions Batch', function () {
};

const claimHandle = ExtrinsicHelper.api.tx.handles.claimHandle(
delegatorKeys.publicKey,
getUnifiedPublicKey(delegatorKeys),
calimHandleProof,
claimHandlePayload
);
Expand Down
13 changes: 13 additions & 0 deletions e2e/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ export default tseslint.config(
},
],
'allow-namespace': 'off',
'no-restricted-syntax': [
'error',
{
message:
'Direct usage of keyPair.address is not allowed in this file. please use getUnifiedAddress function.',
selector: 'MemberExpression[property.name="address"]',
},
{
message:
'Direct usage of keyPair.publicKey is not allowed in this file. please use getUnifiedPublicKey function',
selector: 'MemberExpression[property.name="publicKey"]',
},
],
},
}
);
4 changes: 2 additions & 2 deletions e2e/load-tests/signatureRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { KeyringPair } from '@polkadot/keyring/types';
import { AddKeyData, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { u64, Option } from '@polkadot/types';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedAddress } from '../scaffolding/ethereum';
import { getUnifiedAddress, getUnifiedPublicKey } from '../scaffolding/ethereum';

interface GeneratedMsa {
id: u64;
Expand Down Expand Up @@ -154,7 +154,7 @@ async function addSigs(msaId: u64, keys: KeyringPair, blockNumber: number, nonce

const defaultPayload: AddKeyData = {};
defaultPayload.msaId = msaId;
defaultPayload.newPublicKey = newKeys.publicKey;
defaultPayload.newPublicKey = getUnifiedPublicKey(newKeys);
const payload = await generateAddKeyPayload(defaultPayload, 100, blockNumber);

const addKeyData = ExtrinsicHelper.api.registry.createType('PalletMsaAddKeyData', payload);
Expand Down
67 changes: 67 additions & 0 deletions e2e/miscellaneous/balance.ethereum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import '@frequency-chain/api-augment';
import assert from 'assert';
import { DOLLARS, createAndFundKeypair, createKeys } from '../scaffolding/helpers';
import { KeyringPair } from '@polkadot/keyring/types';
import { Extrinsic, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { getFundingSource } from '../scaffolding/funding';
import { getUnifiedAddress } from '../scaffolding/ethereum';

const fundingSource: KeyringPair = getFundingSource('frequency-balance-ethereum');

describe('Balance transfer ethereum', function () {
describe('setup', function () {
let senderSr25519Keys: KeyringPair;
let senderEthereumKeys: KeyringPair;
let ethereumKeys: KeyringPair;
let ethereumKeys2: KeyringPair;
let sr25519Keys: KeyringPair;

before(async function () {
senderSr25519Keys = await createAndFundKeypair(fundingSource, 30n * DOLLARS);
senderEthereumKeys = await createAndFundKeypair(fundingSource, 30n * DOLLARS, undefined, undefined, 'ethereum');
ethereumKeys = await createKeys('another-key-1', 'ethereum');
ethereumKeys2 = await createKeys('another-key-2', 'ethereum');
sr25519Keys = await createKeys('another-sr25519', 'sr25519');
});

it('should transfer from sr25519 to ethereum style key', async function () {
const transferAmount = 10n * DOLLARS;
const extrinsic = new Extrinsic(
() => ExtrinsicHelper.api.tx.balances.transferKeepAlive(getUnifiedAddress(ethereumKeys), transferAmount),
senderSr25519Keys,
ExtrinsicHelper.api.events.balances.Transfer
);
const { target } = await extrinsic.signAndSend();
assert.notEqual(target, undefined, 'should have returned Transfer event');
const accountInfo = await ExtrinsicHelper.getAccountInfo(ethereumKeys);
assert(accountInfo.data.free.toBigInt() >= transferAmount);
});

it('should transfer from sr25519 to ethereum 20 byte address', async function () {
const transferAmount = 10n * DOLLARS;
const extrinsic = new Extrinsic(
// this is using MultiAddress::Address20 type in Rust since addressRaw is 20 bytes ethereum address
() => ExtrinsicHelper.api.tx.balances.transferKeepAlive(ethereumKeys2.addressRaw, transferAmount),
senderSr25519Keys,
ExtrinsicHelper.api.events.balances.Transfer
);
const { target } = await extrinsic.signAndSend();
assert.notEqual(target, undefined, 'should have returned Transfer event');
const accountInfo = await ExtrinsicHelper.getAccountInfo(ethereumKeys2);
assert(accountInfo.data.free.toBigInt() >= transferAmount);
});

it('should transfer from an ethereum key to sr25519 key', async function () {
const transferAmount = 10n * DOLLARS;
const extrinsic = new Extrinsic(
() => ExtrinsicHelper.api.tx.balances.transferKeepAlive(getUnifiedAddress(sr25519Keys), transferAmount),
senderEthereumKeys,
ExtrinsicHelper.api.events.balances.Transfer
);
const { target } = await extrinsic.signAndSend();
assert.notEqual(target, undefined, 'should have returned Transfer event');
const accountInfo = await ExtrinsicHelper.getAccountInfo(sr25519Keys);
assert(accountInfo.data.free.toBigInt() >= transferAmount);
});
});
});
6 changes: 3 additions & 3 deletions e2e/miscellaneous/frequency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Extrinsic, ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { getFundingSource } from '../scaffolding/funding';
import { u8, Option } from '@polkadot/types';
import { u8aToHex } from '@polkadot/util/u8a/toHex';
import { getUnifiedAddress } from '../scaffolding/ethereum';
import { getUnifiedAddress, getUnifiedPublicKey } from '../scaffolding/ethereum';

const fundingSource: KeyringPair = getFundingSource('frequency-misc');

Expand All @@ -23,7 +23,7 @@ describe('Frequency', function () {
it('Get events successfully', async function () {
const balance_pallet = new u8(ExtrinsicHelper.api.registry, 10);
const transfer_event = new u8(ExtrinsicHelper.api.registry, 2);
const dest_account = u8aToHex(keypairB.publicKey).slice(2);
const dest_account = u8aToHex(getUnifiedPublicKey(keypairB)).slice(2);
const beforeBlockNumber = await getBlockNumber();

const extrinsic = new Extrinsic(
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('Frequency', function () {
}
// wait a little for all of the above transactions to get queued
await new Promise((resolve) => setTimeout(resolve, 1000));
const missingNonce = await ExtrinsicHelper.getMissingNonceValues(keypairB.publicKey);
const missingNonce = await ExtrinsicHelper.getMissingNonceValues(getUnifiedPublicKey(keypairB));
assert.equal(missingNonce.length, 4, 'Could not get missing nonce values');

// applying the missing nonce values to next transactions to unblock the stuck ones
Expand Down
Loading

0 comments on commit 313a395

Please sign in to comment.