Unverified Commit e6a72ea4 authored by Zeke Mostov's avatar Zeke Mostov
Browse files

feat: Add pallet methods `crowdloan.{contrbute, withdraw}`

Closes #407.

 feature: Adds `crowdloan.contribute` & `crowdloan.withdraw`, which will enable users to participate in crowdloans.

testing: Adds metadata from westend spec version 50, which has the components for PLO process. This metadata is used in the new unit tests.
parent 878aa749
......@@ -23,7 +23,7 @@
"test": "jest"
},
"dependencies": {
"@polkadot/api": "4.0.3",
"@polkadot/api": "4.1.1",
"memoizee": "^0.4.14"
},
"devDependencies": {
......@@ -31,7 +31,7 @@
"@types/memoizee": "^0.4.3",
"standard-version": "^9.1.1",
"ts-node": "^9.0.0",
"typedoc": "^0.20.28",
"typedoc": "^0.20.32",
"typedoc-plugin-markdown": "^3.6.0"
},
"resolutions": {
......
import {
TEST_BASE_TX_INFO,
TEST_METHOD_ARGS,
testBaseTxInfo,
WND_50_TEST_OPTIONS,
} from '../../util';
import { contribute } from './contribute';
describe('crowdloan::contribute', () => {
it('should work', () => {
const unsigned = contribute(
TEST_METHOD_ARGS.crowdloan.contribute,
TEST_BASE_TX_INFO,
WND_50_TEST_OPTIONS
);
testBaseTxInfo(unsigned);
expect(unsigned.method).toBe(
'0x2a013013f6ffffffffff3f010101ffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
);
});
});
import {
Args,
BaseTxInfo,
createMethod,
OptionsWithMeta,
UnsignedTransaction,
} from '../../util';
import { MultiSignature } from './types';
export interface CrowdloanContributeArgs extends Args {
index: number | string;
value: number | string;
signature: MultiSignature;
}
export function contribute(
args: CrowdloanContributeArgs,
info: BaseTxInfo,
options: OptionsWithMeta
): UnsignedTransaction {
return createMethod(
{
method: {
args,
name: 'contribute',
pallet: 'crowdloan',
},
...info,
},
options
);
}
export * from './contribute';
export * from './types';
export * from './withdraw';
export type MultiSignature = {
Ed25519?: string;
Sr25519?: string;
Ecdsa?: string;
};
import {
TEST_BASE_TX_INFO,
TEST_METHOD_ARGS,
testBaseTxInfo,
WND_50_TEST_OPTIONS,
} from '../../util';
import { withdraw } from './withdraw';
describe('crowdloan::withdraw', () => {
it('should work', () => {
const unsigned = withdraw(
TEST_METHOD_ARGS.crowdloan.withdraw,
TEST_BASE_TX_INFO,
WND_50_TEST_OPTIONS
);
testBaseTxInfo(unsigned);
expect(unsigned.method).toBe(
'0x2a0290b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe2230'
);
});
});
import {
Args,
BaseTxInfo,
createMethod,
OptionsWithMeta,
UnsignedTransaction,
} from '../../util';
export interface CroadloanWithdrawArgs extends Args {
who: string;
index: number | string;
}
export function withdraw(
args: CroadloanWithdrawArgs,
info: BaseTxInfo,
options: OptionsWithMeta
): UnsignedTransaction {
return createMethod(
{
method: {
args,
name: 'withdraw',
pallet: 'crowdloan',
},
...info,
},
options
);
}
import * as balances from './balances';
import * as claims from './claims';
import * as crowdloan from './crowdloan';
import * as democracy from './democracy';
import * as poll from './poll';
import * as proxy from './proxy';
......@@ -12,6 +13,7 @@ import * as vesting from './vesting';
export {
balances,
claims,
crowdloan,
democracy,
poll,
proxy,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -13,6 +13,8 @@ import { getRegistry } from './metadata';
import apiV1_17_2MetadataRpc from './metadataStatic_api_v1_17_2';
// Static metadata from @polkadot/api v1.32.0. Useful for testing updated proxy methods.
import polkadot23MetadataRpc from './metadataStaticPolkadot23';
// Static metadata from Westend v50. Useful for testing PLO functionality
import westend50MetadataRpc from './metadataStaticWestend50';
import { UnsignedTransaction } from './types';
export { metadataRpc };
......@@ -95,6 +97,11 @@ export const DOT_23_TEST_OPTIONS = {
registry: getRegistry('Polkadot', 'polkadot', 23, polkadot23MetadataRpc),
};
export const WND_50_TEST_OPTIONS = {
metadataRpc: westend50MetadataRpc,
registry: getRegistry('Westend', 'westend', 50, westend50MetadataRpc),
};
/**
* Test helper to test that all base tx information is correctly populated.
*
......@@ -306,6 +313,19 @@ export const TEST_METHOD_ARGS = {
target: 'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P', // seed "//Charlie"
},
},
crowdloan: {
contribute: {
value: '90071992547409910',
index: 12,
signature: {
Sr25519: '0xFFFFFFFFFFFFFFFF',
},
},
withdraw: {
index: 12,
who: 'Fr4NzY1udSFFLzb2R3qxVQkwz9cZraWkyfH4h3mVVk7BK7P', // seed "//Charlie"
},
},
};
/**
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment