Skip to content

Conversation

@0xverin
Copy link
Contributor

@0xverin 0xverin commented Mar 15, 2023

resolves #1392

@0xverin 0xverin force-pushed the 1392-build-assertion branch from 0141966 to 30e0998 Compare March 15, 2023 11:27
Copy link
Collaborator

@Kailai-Wang Kailai-Wang left a 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).

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[];
Copy link
Collaborator

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

Comment on lines 396 to 427
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`'
);
});
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This step seems identical with the previous one, we should have comment at least about why we repeat it
  2. even though we repeat it - we should have a different step name
  3. we should avoid duplicate code on step-level
  4. we should avoid duplicate code inside a step: I don't see any difference between const resp_not_exist_identities... and const resp_not_created_identities... except for the signer. Can't we use a function to wrap it up?

Copy link
Contributor Author

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.

Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see below

Copy link
Collaborator

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.

Copy link
Contributor Author

@0xverin 0xverin Mar 15, 2023

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)

Copy link
Collaborator

@Kailai-Wang Kailai-Wang Mar 15, 2023

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)

Copy link
Contributor Author

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.

@0xverin 0xverin requested a review from Kailai-Wang March 16, 2023 14:53
Copy link
Collaborator

@Kailai-Wang Kailai-Wang left a 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.

Comment on lines 294 to 295
step('remove prime identity NOT allowed', async function () {
// create substrate identity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indention problem?

expect(events.length).to.be.equal(1);
const result = events[0].method as string;
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indention

ethereumIdentity,
substrateIdentity,
])) as string[];
const identites = [twitterIdentity, ethereumIdentity, substrateIdentity];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: identities

Comment on lines 178 to 180



Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many line breakers :(

Comment on lines 22 to 25


// 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
Copy link
Collaborator

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

@Kailai-Wang
Copy link
Collaborator

And please resolve any conversation that is already addressed.

@0xverin 0xverin force-pushed the 1392-build-assertion branch from 48babc3 to 2cfc52f Compare March 17, 2023 03:17
@0xverin
Copy link
Contributor Author

0xverin commented Mar 17, 2023

I finally found where my local formatter configuration was wrong, my formatter was conflicting.:(

@0xverin 0xverin merged commit f4d9572 into dev Mar 17, 2023
@0xverin 0xverin deleted the 1392-build-assertion branch March 17, 2023 07:18
wangminqi added a commit that referenced this pull request Mar 19, 2023
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build_assertion error doesn't propagate to parachain

3 participants