Skip to content

Commit

Permalink
fix!: removes controller arg from bond and setController methods (#…
Browse files Browse the repository at this point in the history
…309)

* fix!: removes controller arg from bond and setController methods

* fix: updates the Kusama version in the metadata file
  • Loading branch information
Imod7 committed Jul 3, 2023
1 parent d96fe8c commit f951f56
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 39 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ yarn run build

We welcome contributions!

#### Commits

All the commits in this repo follow the [Conventional Commits spec](https://www.conventionalcommits.org/en/v1.0.0/#summary). When merging a PR, make sure 1) to use squash merge and 2) that the title of the PR follows the Conventional Commits spec.

#### Before submitting your PR, make sure to run the following commands

Run all tests:
Expand All @@ -84,7 +88,7 @@ yarn run lint
yarn run lint --fix
```

### Maintenence
### Maintenance

#### Yarn

Expand Down
26 changes: 26 additions & 0 deletions packages/txwrapper-dev/src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { kusamaMetadataHex } from '../metadata/kusama';
import { polkadotMetadataHex } from '../metadata/polkadot';
import { statemineMetadataHex } from '../metadata/statemine';
import { westendMetadataHex } from '../metadata/westend';
import {
memoizedKusamaGetRegistry,
memoizedPolkadotGetRegistry,
memoizedStatemineGetRegistry,
memoizedWestendGetRegistry,
} from '../registries';

export const KUSAMA_SPEC_VERSION = 9430;
export const POLKADOT_SPEC_VERSION = 9430;
const STATEMINT_SPEC_VERSION = 9360;
const WESTEND_SPEC_VERSION = 9430;

/**
* Base tx information common to all tested transactions
Expand Down Expand Up @@ -59,6 +62,21 @@ export const POLKADOT_TEST_BASE_TX_INFO = {
transactionVersion: 6,
};

export const WESTEND_TEST_BASE_TX_INFO = {
address: 'HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F', // seed "//Alice"
blockHash:
'0x1fc7493f3c1e9ac758a183839906475f8363aafb1b1d3e910fe16fab4ae1b582',
blockNumber: 4302222,
eraPeriod: 2400,
genesisHash:
'0xe3777fa922cafbff200cadeaea1a76bd7898ad5b89f7848999058b50e715f636',
metadataRpc: westendMetadataHex,
nonce: 2,
specVersion: WESTEND_SPEC_VERSION,
tip: 0,
transactionVersion: 6,
};

export const POLKADOT_TEST_OPTIONS = {
metadataRpc: polkadotMetadataHex,
registry: memoizedPolkadotGetRegistry(
Expand All @@ -85,6 +103,14 @@ export const STATEMINE_TEST_OPTIONS = {
statemineMetadataHex
),
};

export const WESTEND_TEST_OPTIONS = {
metadataRpc: westendMetadataHex,
registry: memoizedWestendGetRegistry(
WESTEND_SPEC_VERSION,
westendMetadataHex
),
};
/**
* Dummy arguments for all methods we're testing.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/txwrapper-dev/src/metadata/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './kusama';
export * from './mockCreateMetadata';
export * from './polkadot';
export * from './westend';
2 changes: 1 addition & 1 deletion packages/txwrapper-dev/src/metadata/kusama/metadataHex.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/txwrapper-dev/src/metadata/westend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './metadataHex';
3 changes: 3 additions & 0 deletions packages/txwrapper-dev/src/metadata/westend/metadataHex.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/txwrapper-dev/src/registries/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './kusamaRegistry';
export * from './polkadotRegistry';
export * from './statemineRegistry';
export * from './westendRegistry';
33 changes: 33 additions & 0 deletions packages/txwrapper-dev/src/registries/westendRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { TypeRegistry } from '@polkadot/types';
import { getSpecTypes } from '@polkadot/types-known';
import memoizee from 'memoizee';

import { mockGetRegistryBase } from './mockGetRegistry';

/**
* Get the Westend type registry for a given spec version for testing purposes
*
* @param specVersion
* @param metadataRpc
*/
export function getRegistryWestend(
specVersion: number,
metadataRpc: `0x${string}`
): TypeRegistry {
return mockGetRegistryBase({
chainProperties: {
ss58Format: 0,
tokenDecimals: 10,
tokenSymbol: 'WND',
},
specTypes: getSpecTypes(
new TypeRegistry(),
'Westend',
'westend',
specVersion
),
metadataRpc,
});
}

export const memoizedWestendGetRegistry = memoizee(getRegistryWestend);
20 changes: 9 additions & 11 deletions packages/txwrapper-substrate/src/methods/staking/bond.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
itHasCorrectBaseTxInfo,
KUSAMA_TEST_OPTIONS,
TEST_BASE_TX_INFO,
WESTEND_TEST_BASE_TX_INFO,
WESTEND_TEST_OPTIONS,
} from '@substrate/txwrapper-dev';

import { TEST_METHOD_ARGS } from '../../test-helpers';
Expand All @@ -11,26 +11,24 @@ describe('staking::bond', () => {
it('should work', () => {
const unsigned = bond(
TEST_METHOD_ARGS.staking.bond,
TEST_BASE_TX_INFO,
KUSAMA_TEST_OPTIONS
WESTEND_TEST_BASE_TX_INFO,
WESTEND_TEST_OPTIONS
);

itHasCorrectBaseTxInfo(unsigned);
expect(unsigned.method).toBe(
'0x0600008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48910100'
);
expect(unsigned.method).toBe('0x0600910100');
});

it('should take "staked" or "Staked" as payee', () => {
const unsignedLowerCase = bond(
{ ...TEST_METHOD_ARGS.staking.bond, payee: 'staked' },
TEST_BASE_TX_INFO,
KUSAMA_TEST_OPTIONS
WESTEND_TEST_BASE_TX_INFO,
WESTEND_TEST_OPTIONS
);
const unsignedCapitalized = bond(
{ ...TEST_METHOD_ARGS.staking.bond, payee: 'Staked' },
TEST_BASE_TX_INFO,
KUSAMA_TEST_OPTIONS
WESTEND_TEST_BASE_TX_INFO,
WESTEND_TEST_OPTIONS
);

expect(unsignedLowerCase.method).toBe(unsignedCapitalized.method);
Expand Down
4 changes: 0 additions & 4 deletions packages/txwrapper-substrate/src/methods/staking/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import {
import { StakingSetPayeeArgs } from './setPayee';

export interface StakingBondArgs extends StakingSetPayeeArgs {
/**
* The SS-58 encoded address of the Controller account.
*/
controller: string;
/**
* The number of tokens to bond.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import {
itHasCorrectBaseTxInfo,
KUSAMA_TEST_OPTIONS,
TEST_BASE_TX_INFO,
WESTEND_TEST_BASE_TX_INFO,
WESTEND_TEST_OPTIONS,
} from '@substrate/txwrapper-dev';

import { TEST_METHOD_ARGS } from '../../test-helpers';
import { setController } from './setController';

describe('staking::setController', () => {
it('should work', () => {
const unsigned = setController(
TEST_METHOD_ARGS.staking.setController,
TEST_BASE_TX_INFO,
KUSAMA_TEST_OPTIONS
{},
WESTEND_TEST_BASE_TX_INFO,
WESTEND_TEST_OPTIONS
);

itHasCorrectBaseTxInfo(unsigned);
expect(unsigned.method).toBe(
'0x0608008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48'
);
expect(unsigned.method).toBe('0x0608');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@ import {
UnsignedTransaction,
} from '@substrate/txwrapper-core';

export interface StakingSetControllerArgs extends Args {
/**
* The SS-58 encoded controller address.
*/
controller: string;
}

/**
* (Re-)set the controller of a stash. Comes into effect at the beginning of the next era.
* (Re-)sets the controller of a stash to the stash itself. Comes into effect at the beginning of the next era.
*
* @param args - Arguments specific to this method.
* @param info - Information required to construct the transaction.
* @param options - Registry and metadata used for constructing the method.
*/
export function setController(
args: StakingSetControllerArgs,
args: Args,
info: BaseTxInfo,
options: OptionsWithMeta
): UnsignedTransaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export const TEST_METHOD_ARGS = {
},
staking: {
bond: {
controller: '14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3', // seed "//Bob"
value: 100,
payee: 'Staked',
},
Expand All @@ -131,9 +130,6 @@ export const TEST_METHOD_ARGS = {
rebond: {
value: 100,
},
setController: {
controller: '14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3', // seed "//Bob"
},
setPayee: {
payee: 'Staked',
},
Expand Down

0 comments on commit f951f56

Please sign in to comment.