-
Couldn't load subscription status.
- 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
Conversation
a6017a0 to
0141966
Compare
0141966 to
30e0998
Compare
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.
I get the idea behind the tests, but I have a few comments about the coding (style).
tee-worker/ts-tests/identity.test.ts
Outdated
| 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[]; |
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 .prettierrc if you believe the old one has better readability
tee-worker/ts-tests/identity.test.ts
Outdated
| 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`' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
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.
- This step seems identical with the previous one, we should have comment at least about why we repeat it
- even though we repeat it - we should have a different step name
- we should avoid duplicate code on step-level
- we should avoid duplicate code inside a step: I don't see any difference between
const resp_not_exist_identities...andconst resp_not_created_identities...except for the signer. Can't we use a function to wrap it up?
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.
The difference between the two removeErrorIdentities is that there is no challengeCode for context.defaultSigner[2],so for the convenience of testing, I directly change the signer and repeat it.
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.
Yes I know the signer is different :) I mean we should point it out in the comment and try to remove duplicate code.
|
|
||
| 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); |
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.
A small improvement: I think we can move it out of the loop - we'll get the same result each time anyway.
|
|
||
| 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); |
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.
see below
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
select a random assertion
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 comment
The 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.
Looks better, thanks.
There're many formatting problems though, please fix it before committing.
Btw I don't think these .ts files went through prettier.
tee-worker/ts-tests/identity.test.ts
Outdated
| step('remove prime identity NOT allowed', async function () { | ||
| // create substrate identity |
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.
Indention problem?
tee-worker/ts-tests/identity.test.ts
Outdated
| expect(events.length).to.be.equal(1); | ||
| const result = events[0].method as string; | ||
| }); | ||
| }); |
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.
Indention
tee-worker/ts-tests/identity.test.ts
Outdated
| ethereumIdentity, | ||
| substrateIdentity, | ||
| ])) as string[]; | ||
| const identites = [twitterIdentity, ethereumIdentity, substrateIdentity]; |
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.
typo: identities
|
|
||
|
|
||
|
|
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.
too many line breakers :(
|
|
||
|
|
||
| // it doesn't make much difference test A1 only vs test A1 - A11, one VC type is enough. | ||
| //So only use A1 to trigger the wrong event |
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.
extra line breakers
comments: first line with space, second line without
|
And please resolve any conversation that is already addressed. |
48babc3 to
2cfc52f
Compare
|
I finally found where my local formatter configuration was wrong, my formatter was conflicting.:( |
* build_assertion error propagate to parachain (#1456) * AssertionBuildFail: add more details * handle errors in on_success method * emit event when vc is non-exists * remove event * remove VCNotExist from Event * Fix benchmarking pallet-teerex (#1460) * remove tee-dev from node default feature * only rococo has tee-dev * remove sccache in docker * missing RUN * update Dockerfile * sleep for 1 second before the event websocket reconnect(fix #1416) (#1462) * debug: Sync of Moonbeam upstream debug (#1450) * debug: change of test * debug: fix benchmark * Fix the panic from WeightInfo in CI (#1466) * update comment * update runner tag * minor update, cleanup history data * fix errors in teeracle * [benchmarking bot] Auto commit generated weights files (#1465) Co-authored-by: Kailai-Wang <[email protected]> * using pallet weights --------- Co-authored-by: BillyWooo <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Kailai-Wang <[email protected]> * build_assertion error case test (#1463) * error verify * batch call of identity * batch call of vc * format code * delete useless code * verify error identity * create error identities * delete useless code * delete useless code * add comment&delete useless code * format code * txs types * step error vc * catch dispatchError * revoke error test * requestVc error * change assert log * fix merge errors * add checkFailReason * check fail reason * move nonce out loop * format code * change test flow(only use A1 trigger error event) * format code * IDGraph adjustment (#1478) * only keep idgraph for verified event * add get_id_graph_with_max_len * add tee pallets unittests * adjust idgraph and prettier * use context.api for better naming * remove empty lines --------- Co-authored-by: Zhouhui Tian <[email protected]> Co-authored-by: Kai <[email protected]> Co-authored-by: Linfeng.Yuan <[email protected]> Co-authored-by: BillyWooo <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Kailai-Wang <[email protected]> Co-authored-by: Verin1005 <[email protected]>
resolves #1392