-
Notifications
You must be signed in to change notification settings - Fork 18
build_assertion error case test #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
924deee
8e5484a
0818632
658cb9b
7eafecf
820ac8a
6be62b8
c46db24
8013596
8e55e0d
363bad8
8c5da1c
e092369
11f48cd
48fd295
8b4f9d1
f70a3fe
9f1079c
25eeedf
30e0998
22cfc31
f044ffa
c541348
19145ac
9e77c3b
2cfc52f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| import { describeLitentry, encryptWithTeeShieldingKey, generateVerificationMessage, listenEvent, sendTxUntilInBlock } from './utils'; | ||
| import { | ||
| describeLitentry, | ||
| encryptWithTeeShieldingKey, | ||
| generateVerificationMessage, | ||
| listenEvent, | ||
| sendTxUntilInBlock, | ||
| } from './utils'; | ||
| import { hexToU8a, u8aConcat, u8aToHex, u8aToU8a, stringToU8a } from '@polkadot/util'; | ||
| import { | ||
| setUserShieldingKey, | ||
|
|
@@ -213,7 +219,6 @@ describeLitentry('Test Identity', (context) => { | |
| assert.isNotEmpty(resp_extension_substrate.challengeCode, 'challengeCode empty'); | ||
| } | ||
| }); | ||
|
|
||
| step('verify identities', async function () { | ||
| //Alice verify all identities | ||
| const [twitter_identity_verified, ethereum_identity_verified, substrate_identity_verified] = | ||
|
|
@@ -310,7 +315,9 @@ describeLitentry('Test Identity', (context) => { | |
|
|
||
| step('remove prime identity NOT allowed', async function () { | ||
| // create substrate identity | ||
| const [resp_substrate] = (await createIdentities(context, context.defaultSigner[0], aesKey, true, [substrateIdentity])) as IdentityGenericEvent[]; | ||
| const [resp_substrate] = (await createIdentities(context, context.defaultSigner[0], aesKey, true, [ | ||
| substrateIdentity, | ||
| ])) as IdentityGenericEvent[]; | ||
| assertIdentityCreated(context.defaultSigner[0], resp_substrate); | ||
|
|
||
| if (resp_substrate) { | ||
|
|
@@ -330,13 +337,9 @@ describeLitentry('Test Identity', (context) => { | |
| } | ||
|
|
||
| // remove substrate identity | ||
| const [substrate_identity_removed] = (await removeIdentities( | ||
| context, | ||
| context.defaultSigner[0], | ||
| aesKey, | ||
| true, | ||
| [substrateIdentity] | ||
| )) as IdentityGenericEvent[]; | ||
| const [substrate_identity_removed] = (await removeIdentities(context, context.defaultSigner[0], aesKey, true, [ | ||
| substrateIdentity, | ||
| ])) as IdentityGenericEvent[]; | ||
| assertIdentityRemoved(context.defaultSigner[0], substrate_identity_removed); | ||
|
|
||
| // remove prime identity | ||
|
|
@@ -353,6 +356,7 @@ describeLitentry('Test Identity', (context) => { | |
| await sendTxUntilInBlock(context.substrate, tx, context.defaultSigner[0]); | ||
|
|
||
| const events = await listenEvent(context.substrate, 'identityManagement', ['StfError']); | ||
|
|
||
| expect(events.length).to.be.equal(1); | ||
| const result = events[0].method as string; | ||
| }); | ||
|
|
@@ -389,6 +393,38 @@ describeLitentry('Test Identity', (context) => { | |
| }); | ||
| }); | ||
|
|
||
| step('remove error identities', async function () { | ||
| //remove a nonexistent identity from an account | ||
| const resp_not_exist_identities = (await removeErrorIdentities(context, context.defaultSigner[0], true, [ | ||
| twitterIdentity, | ||
| ethereumIdentity, | ||
| substrateIdentity, | ||
| ])) as string[]; | ||
|
|
||
| resp_not_exist_identities.map((item: any) => { | ||
| const result = item.toHuman().data.reason; | ||
| assert( | ||
| result.search('IdentityNotExist') !== -1, | ||
| 'remove twitter should fail with reason `IdentityNotExist`' | ||
| ); | ||
| }); | ||
|
|
||
| //remove a challenge code before the code is set | ||
| const resp_not_created_identities = (await removeErrorIdentities(context, context.defaultSigner[2], true, [ | ||
| twitterIdentity, | ||
| ethereumIdentity, | ||
| substrateIdentity, | ||
| ])) as string[]; | ||
|
|
||
| resp_not_created_identities.map((item: any) => { | ||
| const result = item.toHuman().data.reason; | ||
| assert( | ||
| result.search('IdentityNotExist') !== -1, | ||
| 'remove twitter should fail with reason `IdentityNotExist`' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
|
||
| step('set error user shielding key', async function () { | ||
| const result = await setErrorUserShieldingKey(context, context.defaultSigner[0], errorAseKey, true); | ||
| assert.equal( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { encryptWithTeeShieldingKey, listenEvent, sendTxUntilInBlock, sendTxUnti | |
| import { KeyringPair } from '@polkadot/keyring/types'; | ||
| import { HexString } from '@polkadot/util/types'; | ||
| import { | ||
| Assertion, | ||
| IntegrationTestContext, | ||
| LitentryIdentity, | ||
| LitentryValidationData, | ||
|
|
@@ -149,3 +150,79 @@ export async function removeErrorIdentities( | |
| } | ||
| return undefined; | ||
| } | ||
| export async function requestErrorVCs( | ||
| context: IntegrationTestContext, | ||
| signer: KeyringPair, | ||
| aesKey: HexString, | ||
| listening: boolean, | ||
| mrEnclave: HexString, | ||
| assertion: Assertion | ||
| ): Promise< | ||
| | { | ||
| account: HexString; | ||
| index: HexString; | ||
| vc: HexString; | ||
| }[] | ||
| | undefined | ||
| > { | ||
| let txs: TransactionSubmit[] = []; | ||
| let len = 0; | ||
|
|
||
| for (const key in assertion) { | ||
| len++; | ||
| const tx = context.substrate.tx.vcManagement.requestVc(mrEnclave, { | ||
| [key]: assertion[key as keyof Assertion], | ||
| }); | ||
| const nonce = await context.substrate.rpc.system.accountNextIndex(signer.address); | ||
|
|
||
| let newNonce = nonce.toNumber() + (len - 1); | ||
| txs.push({ tx, nonce: newNonce }); | ||
| } | ||
|
|
||
| await sendTxUntilInBlockList(context.substrate, txs, signer); | ||
|
|
||
| if (listening) { | ||
| const events = (await listenEvent(context.substrate, 'vcManagement', ['StfError'])) as any; | ||
| expect(events.length).to.be.equal(len); | ||
| return events; | ||
| } | ||
| return undefined; | ||
| } | ||
| export async function disableErrorVCs( | ||
| context: IntegrationTestContext, | ||
| signer: KeyringPair, | ||
| listening: boolean, | ||
| indexList: HexString[] | ||
| ): Promise<string[] | undefined> { | ||
| let txs: TransactionSubmit[] = []; | ||
|
|
||
| for (let k = 0; k < indexList.length; k++) { | ||
| const tx = context.substrate.tx.vcManagement.disableVc(indexList[k]); | ||
| const nonce = await context.substrate.rpc.system.accountNextIndex(signer.address); | ||
|
||
| let newNonce = nonce.toNumber() + k; | ||
| txs.push({ tx, nonce: newNonce }); | ||
| } | ||
|
|
||
| const res = (await sendTxUntilInBlockList(context.substrate, txs, signer)) as string[]; | ||
|
|
||
| return res.length ? res : undefined; | ||
| } | ||
| export async function revokeErrorVCs( | ||
| context: IntegrationTestContext, | ||
| signer: KeyringPair, | ||
| listening: boolean, | ||
| indexList: HexString[] | ||
| ): Promise<string[] | undefined> { | ||
| let txs: TransactionSubmit[] = []; | ||
|
|
||
| for (let k = 0; k < indexList.length; k++) { | ||
| const tx = context.substrate.tx.vcManagement.revokeVc(indexList[k]); | ||
| const nonce = await context.substrate.rpc.system.accountNextIndex(signer.address); | ||
|
||
| let newNonce = nonce.toNumber() + k; | ||
| txs.push({ tx, nonce: newNonce }); | ||
| } | ||
|
|
||
| const res = (await sendTxUntilInBlockList(context.substrate, txs, signer)) as string[]; | ||
|
|
||
| return res.length ? res : undefined; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of my general feelings here is (you might have other opinions): We want to cover as many test cases as possible, but we don't want to over-test them. For example, we want to test the error handling of the case where a user requests a VC without setting the shielding key. This is a good test case, but we don't have to repeat it for all VC types that we have - because there isn't any difference in terms of such error handling for different assertion enums (if we have one someday, then we should test it). So it doesn't make much difference you test A1 only vs you test A1 - A11, one VC type is enough. Making it a vector of VCs impairs the code readability and prolongs the whole test time unnecessarily. The same applies to the identity test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My idea is to select a random assertion to trigger the specified error, I don't know the difference between them, I worry that it will not cover all case(maybe A1 trigger,but A2 not trigger) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But if I understand the code correctly, we iterate over all assertions here (instead of choosing one randomly). And yes there's no difference in terms of that specific error handling, we can ask eric or zhouhui if we are unsure. I'm mainly concerned about the execution time - it probably won't be such a problem if a step takes 5s. Imagine we have 100 assertions later, we can't afford to test them all for a generic handling that applies to all assertion types (we should still do individual test if something differs) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have confirmed with @zhouhuitian that only one test is needed, and all the procedures are the same,so only use A1 to triggers the error events. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please feel free to adjust
.prettierrcif you believe the old one has better readability