Skip to content

Commit 9f1079c

Browse files
committed
requestVc error
1 parent f70a3fe commit 9f1079c

File tree

2 files changed

+69
-18
lines changed

2 files changed

+69
-18
lines changed

tee-worker/ts-tests/indirect_error_calls.ts

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { encryptWithTeeShieldingKey, listenEvent, sendTxUntilInBlock, sendTxUnti
22
import { KeyringPair } from '@polkadot/keyring/types';
33
import { HexString } from '@polkadot/util/types';
44
import {
5+
Assertion,
56
IntegrationTestContext,
67
LitentryIdentity,
78
LitentryValidationData,
@@ -149,12 +150,50 @@ export async function removeErrorIdentities(
149150
}
150151
return undefined;
151152
}
153+
export async function requestErrorVCs(
154+
context: IntegrationTestContext,
155+
signer: KeyringPair,
156+
aesKey: HexString,
157+
listening: boolean,
158+
mrEnclave: HexString,
159+
assertion: Assertion
160+
): Promise<
161+
| {
162+
account: HexString;
163+
index: HexString;
164+
vc: HexString;
165+
}[]
166+
| undefined
167+
> {
168+
let txs: TransactionSubmit[] = [];
169+
let len = 0;
170+
171+
for (const key in assertion) {
172+
len++;
173+
const tx = context.substrate.tx.vcManagement.requestVc(mrEnclave, {
174+
[key]: assertion[key as keyof Assertion],
175+
});
176+
const nonce = await context.substrate.rpc.system.accountNextIndex(signer.address);
177+
178+
let newNonce = nonce.toNumber() + (len - 1);
179+
txs.push({ tx, nonce: newNonce });
180+
}
181+
182+
await sendTxUntilInBlockList(context.substrate, txs, signer);
183+
184+
if (listening) {
185+
const events = (await listenEvent(context.substrate, 'vcManagement', ['StfError'])) as any;
186+
expect(events.length).to.be.equal(len);
187+
return events;
188+
}
189+
return undefined;
190+
}
152191
export async function disableErrorVCs(
153192
context: IntegrationTestContext,
154193
signer: KeyringPair,
155194
listening: boolean,
156195
indexList: HexString[]
157-
): Promise<HexString[] | undefined> {
196+
): Promise<string[] | undefined> {
158197
let txs: TransactionSubmit[] = [];
159198

160199
for (let k = 0; k < indexList.length; k++) {
@@ -164,18 +203,9 @@ export async function disableErrorVCs(
164203
txs.push({ tx, nonce: newNonce });
165204
}
166205

167-
await sendTxUntilInBlockList(context.substrate, txs, signer);
168-
if (listening) {
169-
const events = (await listenEvent(context.substrate, 'vcManagement', ['VCDisabled'])) as any;
170-
expect(events.length).to.be.equal(indexList.length);
171-
let results: HexString[] = [];
172-
for (let m = 0; m < events.length; m++) {
173-
results.push(events[m].data.index.toHex());
174-
}
206+
const res = (await sendTxUntilInBlockList(context.substrate, txs, signer)) as string[];
175207

176-
return [...results];
177-
}
178-
return undefined;
208+
return res.length ? res : undefined;
179209
}
180210
export async function revokeErrorVCs(
181211
context: IntegrationTestContext,

tee-worker/ts-tests/vc.test.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { assert } from 'chai';
66
import { u8aToHex } from '@polkadot/util';
77
import { HexString } from '@polkadot/util/types';
88
import { blake2AsHex } from '@polkadot/util-crypto';
9-
import { disableErrorVCs, revokeErrorVCs } from './indirect_error_calls';
9+
import { requestErrorVCs, disableErrorVCs, revokeErrorVCs } from './indirect_error_calls';
1010

1111
const assertion = <Assertion>{
1212
A1: 'A1',
@@ -59,7 +59,25 @@ describeLitentry('VC test', async (context) => {
5959
indexList.push(res[k].index);
6060
}
6161
});
62+
step('Request Error VC', async () => {
63+
const resp_request_error = (await requestErrorVCs(
64+
context,
65+
context.defaultSigner[1],
66+
aesKey,
67+
true,
68+
context.mrEnclave,
69+
assertion
70+
)) as any;
71+
72+
resp_request_error.map((item: any) => {
73+
const result = item.toHuman().data.reason;
6274

75+
assert(
76+
result.search('User shielding key is missing') !== -1,
77+
'remove twitter should fail with reason `User shielding key is missing`'
78+
);
79+
});
80+
});
6381
step('Disable VC', async () => {
6482
const res = (await disableVCs(context, context.defaultSigner[0], aesKey, true, indexList)) as HexString[];
6583
for (let k = 0; k < res.length; k++) {
@@ -70,11 +88,14 @@ describeLitentry('VC test', async (context) => {
7088
});
7189
step('Disable error VC', async () => {
7290
//Bob dont't request VC before
73-
const res = (await disableErrorVCs(context, context.defaultSigner[0], true, indexList)) as HexString[];
74-
for (let k = 0; k < res.length; k++) {
75-
assert.equal(res[k], indexList[k], 'check index error');
76-
const registry = (await context.substrate.query.vcManagement.vcRegistry(indexList[k])) as any;
77-
assert.equal(registry.toHuman()!['status'], 'Disabled');
91+
const resp_disable_error = (await disableErrorVCs(
92+
context,
93+
context.defaultSigner[0],
94+
true,
95+
indexList
96+
)) as HexString[];
97+
for (let k = 0; k < resp_disable_error.length; k++) {
98+
assert.equal(resp_disable_error[k], 'vcManagement.VCAlreadyDisabled', 'check disableVc error');
7899
}
79100
});
80101

0 commit comments

Comments
 (0)