Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
feat: Add pallet methods crowdloan.{contrbute, withdraw}
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
emostov committed Mar 17, 2021
1 parent 878aa74 commit e6a72ea
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 139 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
"test": "jest"
},
"dependencies": {
"@polkadot/api": "4.0.3",
"@polkadot/api": "4.1.1",
"memoizee": "^0.4.14"
},
"devDependencies": {
"@substrate/dev": "^0.3.0",
"@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": {
Expand Down
23 changes: 23 additions & 0 deletions src/methods/crowdloan/contribute.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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'
);
});
});
32 changes: 32 additions & 0 deletions src/methods/crowdloan/contribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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
);
}
3 changes: 3 additions & 0 deletions src/methods/crowdloan/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './contribute';
export * from './types';
export * from './withdraw';
5 changes: 5 additions & 0 deletions src/methods/crowdloan/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type MultiSignature = {
Ed25519?: string;
Sr25519?: string;
Ecdsa?: string;
};
23 changes: 23 additions & 0 deletions src/methods/crowdloan/withdraw.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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'
);
});
});
30 changes: 30 additions & 0 deletions src/methods/crowdloan/withdraw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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
);
}
2 changes: 2 additions & 0 deletions src/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';
Expand All @@ -12,6 +13,7 @@ import * as vesting from './vesting';
export {
balances,
claims,
crowdloan,
democracy,
poll,
proxy,
Expand Down
4 changes: 4 additions & 0 deletions src/util/metadataStaticWestend50.ts

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/util/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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"
},
},
};

/**
Expand Down
Loading

0 comments on commit e6a72ea

Please sign in to comment.