Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 142 additions & 111 deletions js/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => {
call: "transfer",
args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)],
with: [
{
signed: config.alice,
pallet: "balances",
call: "transfer",
args: [config.bob.address, PINT.mul(BALANCE_THOUSAND)],
},
{
signed: config.alice,
pallet: "balances",
call: "transfer",
args: [config.charlie.address, PINT.mul(BALANCE_THOUSAND)],
},
{
signed: config.alice,
pallet: "balances",
Expand Down Expand Up @@ -117,121 +129,121 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => {
},
},
{
required: ["priceFeed.mapAssetPriceFeed"],
required: ["assetIndex.deposit"],
signed: config.alice,
pallet: "assetIndex",
call: "withdraw",
args: [PINT.mul(BALANCE_THOUSAND).div(new BN(4))],
verify: async () => {
assert(
(
(
await api.query.assetIndex.pendingWithdrawals(
config.alice.address
)
).toHuman() as any
).length === 1,
"assetIndex.withdraw failed"
);
},
},
{
required: ["assetIndex.withdraw"],
shared: async () => {
const currentBlock = (
await api.derive.chain.bestNumber()
).toNumber();
const pendingWithdrawls =
await api.query.assetIndex.pendingWithdrawals(
config.alice.address
);

const end = (pendingWithdrawls as any).toHuman()[0].end_block;
const needsToWait =
end - currentBlock > WITHDRAWALS_PERIOD
? end - currentBlock - WITHDRAWALS_PERIOD
: 0;

console.log(
`\t | waiting for the withdrawls peirod (around ${Math.floor(
(needsToWait * 12) / 60
)} mins)...`
);

await waitBlock(needsToWait);
},
signed: config.alice,
pallet: "assetIndex",
call: "completeWithdraw",
args: [],
verify: async () => {
assert(
(
(await api.query.assetIndex.pendingWithdrawals(
config.alice.address
)) as any
).isNone,
"assetIndex.completeWithdraw failed"
);
// assert(
// (
// (
// await api.query.assetIndex.pendingWithdrawals(
// config.alice.address
// )
// ).toHuman() as any
// ).length === 1,
// "assetIndex.withdraw failed"
// );
},
},
// {
// required: ["assetIndex.withdraw"],
// shared: async () => {
// const currentBlock = (
// await api.derive.chain.bestNumber()
// ).toNumber();
// const pendingWithdrawls =
// await api.query.assetIndex.pendingWithdrawals(
// config.alice.address
// );
//
// const end = (pendingWithdrawls as any).toHuman()[0].end_block;
// const needsToWait =
// end - currentBlock > WITHDRAWALS_PERIOD
// ? end - currentBlock - WITHDRAWALS_PERIOD
// : 0;
//
// console.log(
// `\t | waiting for the withdrawls peirod (around ${Math.floor(
// (needsToWait * 12) / 60
// )} mins)...`
// );
//
// await waitBlock(needsToWait);
// },
// signed: config.alice,
// pallet: "assetIndex",
// call: "completeWithdraw",
// args: [],
// verify: async () => {
// // assert(
// // (
// // (await api.query.assetIndex.pendingWithdrawals(
// // config.alice.address
// // )) as any
// // ).isNone,
// // "assetIndex.completeWithdraw failed"
// // );
// },
// },
/* remote-asset-manager*/
{
required: ["priceFeed.mapAssetPriceFeed"],
signed: config.alice,
pallet: "remoteAssetManager",
call: "sendAddProxy",
args: [ASSET_ID_A, "Any", config.alice.address],
verify: async () => {
assert(
JSON.stringify(
(
await api.query.remoteAssetManager.proxies(
ASSET_ID_A,
config.alice.address
)
).toJSON()
) ===
JSON.stringify({
added: ["Any"],
}),
"remoteAssetManager.sendAddProxy failed"
);
},
},
{
required: ["priceFeed.mapAssetPriceFeed"],
signed: config.alice,
pallet: "remoteAssetManager",
call: "sendBond",
args: [
ASSET_ID_A,
config.alice.address,
1000,
api.createType("RewardDestination", {
Staked: null,
}),
],
verify: async () => {
assert(
JSON.stringify(
(
await api.query.remoteAssetManager.palletStakingLedger(
ASSET_ID_A
)
).toJSON()
) ===
JSON.stringify({
controller: config.alice.address,
bonded: 1000,
unbonded: 0,
unlocked_chunks: [0],
}),

"remoteAssetManager.sendBond failed"
);
},
},
// {
// required: ["assetIndex.addAsset"],
// signed: config.alice,
// pallet: "remoteAssetManager",
// call: "sendAddProxy",
// args: [ASSET_ID_A, "Any", config.alice.address],
// verify: async () => {
// assert(
// JSON.stringify(
// (
// await api.query.remoteAssetManager.proxies(
// ASSET_ID_A,
// config.alice.address
// )
// ).toJSON()
// ) ===
// JSON.stringify({
// added: ["Any"],
// }),
// "remoteAssetManager.sendAddProxy failed"
// );
// },
// },
// {
// required: ["priceFeed.mapAssetPriceFeed"],
// signed: config.alice,
// pallet: "remoteAssetManager",
// call: "sendBond",
// args: [
// ASSET_ID_A,
// config.alice.address,
// 1000,
// api.createType("RewardDestination", {
// Staked: null,
// }),
// ],
// verify: async () => {
// assert(
// JSON.stringify(
// (
// await api.query.remoteAssetManager.palletStakingLedger(
// ASSET_ID_A
// )
// ).toJSON()
// ) ===
// JSON.stringify({
// controller: config.alice.address,
// bonded: 1000,
// unbonded: 0,
// unlocked_chunks: [0],
// }),
//
// "remoteAssetManager.sendBond failed"
// );
// },
// },
/* committee */
{
signed: config.alice,
Expand Down Expand Up @@ -318,10 +330,27 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => {
{
required: ["committee.vote"],
shared: async () => {
const hash = (
(await api.query.committee.activeProposals()) as any
)[0];
return hash;
return new Promise(async (resolve) => {
await waitBlock(1);
const hash = (
(await api.query.committee.activeProposals()) as any
)[0];
const currentBlock = (
await api.derive.chain.bestNumber()
).toNumber();

const end = (
(await api.query.committee.votes(hash)).toJSON() as any
).end as number;

const needsToWait = end - currentBlock;
console.log(
`\t | waiting for the end of voting peirod ( ${needsToWait} blocks )`
);

await waitBlock(needsToWait > 0 ? needsToWait : 0);
resolve(hash);
});
},
signed: config.alice,
pallet: "committee",
Expand All @@ -331,6 +360,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => {
const proposals = await api.query.committee.executedProposals(
hash
);

assert(
(proposals as any).isSome,
"no proposal executed after committe.close"
Expand Down Expand Up @@ -392,6 +422,7 @@ const TESTS = (api: ApiPromise, config: ExtrinsicConfig): Extrinsic[] => {
},
},
{
required: ["chainlinkFeed.createFeed"],
signed: config.alice,
pallet: "chainlinkFeed",
call: "submit",
Expand Down
6 changes: 5 additions & 1 deletion js/e2e/src/extrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ export class Extrinsic {
// thisecute verify script
if (this.verify) {
console.log(`\t | verify: ${this.pallet}.${this.call}`);
await this.verify(this.shared);
await this.verify(this.shared).catch((err: any) => {
errors.push(
`====> Error: ${this.pallet}.${this.call} verify failed: ${err}`
);
});
}

if (res && res.unsub) {
Expand Down