-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* proxy st * treasury * proxy lint * fmt * reduce validators * withdrawn and deposits * added test * fmt * remove non-used vars! * fmt * fix more tests * fix dancebox instead of Dancebox * remove line
- Loading branch information
Showing
7 changed files
with
292 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import "@tanssi/api-augment"; | ||
import { ApiDecoration } from "@polkadot/api/types"; | ||
import chalk from "chalk"; | ||
import { expect, beforeAll, describeSuite } from "@moonwall/cli"; | ||
import type { PalletProxyProxyDefinition } from "@polkadot/types/lookup"; | ||
import { ApiPromise } from "@polkadot/api"; | ||
|
||
describeSuite({ | ||
id: "S17", | ||
title: "Verify account proxies created", | ||
foundationMethods: "read_only", | ||
testCases: ({ context, it, log }) => { | ||
const proxiesPerAccount: { [account: string]: PalletProxyProxyDefinition[] } = {}; | ||
const proxyAccList: string[] = []; | ||
let atBlockNumber: number = 0; | ||
let apiAt: ApiDecoration<"promise">; | ||
let paraApi: ApiPromise; | ||
|
||
beforeAll(async function () { | ||
paraApi = context.polkadotJs("para"); | ||
const limit = 1000; | ||
let last_key = ""; | ||
let count = 0; | ||
|
||
// Configure the api at a specific block | ||
// (to avoid inconsistency querying over multiple block when the test takes a long time to | ||
// query data and blocks are being produced) | ||
atBlockNumber = process.env.BLOCK_NUMBER | ||
? parseInt(process.env.BLOCK_NUMBER) | ||
: (await paraApi.rpc.chain.getHeader()).number.toNumber(); | ||
apiAt = await paraApi.at(await paraApi.rpc.chain.getBlockHash(atBlockNumber)); | ||
|
||
for (;;) { | ||
const query = await apiAt.query.proxy.proxies.entriesPaged({ | ||
args: [], | ||
pageSize: limit, | ||
startKey: last_key, | ||
}); | ||
|
||
if (query.length == 0) { | ||
break; | ||
} | ||
count += query.length; | ||
|
||
// TEMPLATE: convert the data into the format you want (usually a dictionary per account) | ||
for (const proxyData of query) { | ||
const accountId = `0x${proxyData[0].toHex().slice(-40)}`; | ||
last_key = proxyData[0].toString(); | ||
proxiesPerAccount[accountId] = proxyData[1][0].toArray(); | ||
proxyAccList.push(accountId); | ||
} | ||
|
||
// log logs to make sure it keeps progressing | ||
// TEMPLATE: Adapt log line | ||
if (count % (10 * limit) == 0) { | ||
log(`Retrieved ${count} proxies`); | ||
} | ||
} | ||
|
||
// TEMPLATE: Adapt proxies | ||
log(`Retrieved ${count} total proxies`); | ||
}, 30_000); | ||
|
||
it({ | ||
id: "C100", | ||
title: "should have no more than the maximum allowed proxies", | ||
timeout: 240000, | ||
test: async function () { | ||
const maxProxies = paraApi.consts.proxy.maxProxies.toNumber(); | ||
const failedProxies: { accountId: string; proxiesCount: number }[] = []; | ||
|
||
for (const accountId of Object.keys(proxiesPerAccount)) { | ||
const proxiesCount = proxiesPerAccount[accountId].length; | ||
if (proxiesCount > maxProxies) { | ||
failedProxies.push({ accountId, proxiesCount }); | ||
} | ||
} | ||
|
||
if (failedProxies.length > 0) { | ||
log("Failed accounts with too many proxies:"); | ||
log( | ||
failedProxies | ||
.map(({ accountId, proxiesCount }) => { | ||
return `accountId: ${accountId} - ${chalk.red( | ||
proxiesCount.toString().padStart(4, " ") | ||
)} proxies (expected max: ${maxProxies})`; | ||
}) | ||
.join(`\n`) | ||
); | ||
} | ||
|
||
expect(failedProxies.length, "Failed max proxies").to.equal(0); | ||
|
||
log(`Verified ${Object.keys(proxiesPerAccount).length} total accounts (at #${atBlockNumber})`); | ||
}, | ||
}); | ||
|
||
it({ | ||
id: "C200", | ||
title: "should have a maximum allowed proxies of 32", | ||
test: async function () { | ||
const runtimeName = paraApi.runtimeVersion.specName.toString(); | ||
const maxProxies = (await paraApi.consts.proxy.maxProxies).toNumber(); | ||
|
||
switch (runtimeName) { | ||
case "dancebox": | ||
expect(maxProxies).to.equal(32); | ||
break; | ||
case "flashbox": | ||
expect(maxProxies).to.equal(32); | ||
break; | ||
} | ||
|
||
log(`Verified maximum allowed proxies constant`); | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { beforeAll, describeSuite, expect } from "@moonwall/cli"; | ||
|
||
import { ApiPromise } from "@polkadot/api"; | ||
import { fetchWithdrawnAmount, fetchDepositedAmount } from "util/block"; | ||
|
||
describeSuite({ | ||
id: "S08", | ||
title: "Sample suite that only runs on Dancebox chains", | ||
foundationMethods: "read_only", | ||
testCases: ({ it, context }) => { | ||
let api: ApiPromise; | ||
|
||
beforeAll(() => { | ||
api = context.polkadotJs(); | ||
}); | ||
|
||
it({ | ||
id: "C03", | ||
title: "Supply variance is correct", | ||
test: async function () { | ||
const latestBlock = await api.rpc.chain.getBlock(); | ||
|
||
const latestBlockHash = latestBlock.block.hash; | ||
const latestParentBlockHash = latestBlock.block.header.parentHash; | ||
const apiAtIssuanceAfter = await api.at(latestBlockHash); | ||
const apiAtIssuanceBefore = await api.at(latestParentBlockHash); | ||
|
||
const supplyBefore = (await apiAtIssuanceBefore.query.balances.totalIssuance()).toBigInt(); | ||
|
||
const events = await apiAtIssuanceAfter.query.system.events(); | ||
|
||
const withdrawnAmount = await fetchWithdrawnAmount(events); | ||
const depositAmount = await fetchDepositedAmount(events); | ||
|
||
const supplyAfter = (await apiAtIssuanceAfter.query.balances.totalIssuance()).toBigInt(); | ||
expect(supplyAfter).to.equal(supplyBefore + depositAmount - withdrawnAmount); | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import "@tanssi/api-augment"; | ||
import { ApiDecoration } from "@polkadot/api/types"; | ||
import { describeSuite, expect, beforeAll } from "@moonwall/cli"; | ||
import { ApiPromise } from "@polkadot/api"; | ||
|
||
describeSuite({ | ||
id: "S24", | ||
title: "Verify treasury consistency", | ||
foundationMethods: "read_only", | ||
testCases: ({ context, it, log }) => { | ||
let atBlockNumber: number = 0; | ||
let apiAt: ApiDecoration<"promise">; | ||
let paraApi: ApiPromise; | ||
|
||
beforeAll(async function () { | ||
paraApi = context.polkadotJs("para"); | ||
atBlockNumber = (await paraApi.rpc.chain.getHeader()).number.toNumber(); | ||
apiAt = await paraApi.at(await paraApi.rpc.chain.getBlockHash(atBlockNumber)); | ||
}); | ||
|
||
it({ | ||
id: "C100", | ||
title: "should have value > 0", | ||
test: async function () { | ||
// Load data | ||
const treasuryPalletId = paraApi.consts.treasury.palletId; | ||
const treasuryAccount = await apiAt.query.system.account( | ||
`0x6d6f646C${treasuryPalletId.toString().slice(2)}0000000000000000000000000000000000000000` | ||
); | ||
|
||
console.log( | ||
`0x6d6f646C${treasuryPalletId.toString().slice(2)}0000000000000000000000000000000000000000` | ||
); | ||
expect(treasuryAccount.data.free.toBigInt() > 0n).to.be.true; | ||
expect(treasuryAccount.data.reserved.toBigInt()).to.be.equal(0n); | ||
|
||
log(`Verified treasury free/reserved balance`); | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters