Skip to content
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

Use augmented and generated types #1703

Merged
merged 30 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
02c0d2e
types generated with parachain-metadata
0xverin May 16, 2023
62078af
change gen-type
0xverin May 16, 2023
6baea67
tsconfig.json
0xverin May 16, 2023
01c6829
add env
0xverin May 16, 2023
cb4ebbc
upgrade typegen && re-generate
0xverin May 16, 2023
88946b5
fix package conflict
0xverin May 16, 2023
750d4fa
fix types
0xverin May 16, 2023
f844315
remove comments
0xverin May 16, 2023
d8d5a0e
fix ci
0xverin May 17, 2023
939e871
upgradte polkadot<api types>
0xverin May 17, 2023
317b8ab
upgrade @polkador/kering
0xverin May 17, 2023
2b583d6
add sidechain-types
0xverin May 18, 2023
1e00b98
add @polkadot/types/lookup
0xverin May 22, 2023
de37126
Merge branch 'dev' into 1673-use-generated-types
0xverin May 22, 2023
9324355
fix createType
0xverin May 24, 2023
5ed93e0
Merge branch 'dev' into 1673-use-generated-types
0xverin May 24, 2023
4355e7b
remove toHex()
0xverin May 24, 2023
5e7662f
fix ci & fix type
0xverin May 24, 2023
bb39b1e
Merge branch 'dev' into 1673-use-generated-types
0xverin May 25, 2023
18c8e50
refactor identity&validation types
0xverin May 31, 2023
3dc50f0
Merge branch 'dev' into 1673-use-generated-types
0xverin May 31, 2023
e78a07a
fix checkIdgraph
0xverin May 31, 2023
ad8e9cc
remove WorkerRpcReturnValue
0xverin May 31, 2023
8e3ea50
fix ci & format
0xverin May 31, 2023
b082d30
modified as type
0xverin May 31, 2023
472d4ca
modified Assertion type
0xverin May 31, 2023
f85448a
refactor assert
0xverin Jun 1, 2023
bda99a7
fix vc ci
0xverin Jun 1, 2023
514f003
add storage query sleep
0xverin Jun 1, 2023
6631fc0
Merge branch 'dev' into 1673-use-generated-types
0xverin Jun 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions tee-worker/ts-tests/batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { u8aToHex } from '@polkadot/util';
import { step } from 'mocha-steps';
import { assert } from 'chai';
import { LitentryIdentity, LitentryValidationData } from './common/type-definitions';
import { multiAccountTxSender, sendTxsWithUtility } from './common/transactions';
import {
generateWeb3Wallets,
Expand All @@ -20,10 +19,11 @@ import {
assertIdentityRemoved,
} from './common/utils';
import { ethers } from 'ethers';

import type { LitentryPrimitivesIdentity } from '@polkadot/types/lookup';
import type { LitentryValidationData } from './parachain-interfaces/identity/types';
describeLitentry('Test Batch Utility', 0, (context) => {
const aesKey = '0x22fc82db5b606998ad45099b7978b5b4f9dd4ea6017e57370ac56141caaabd12';
let identities: LitentryIdentity[] = [];
let identities: LitentryPrimitivesIdentity[] = [];
let validations: LitentryValidationData[] = [];
var ethereumSigners: ethers.Wallet[] = [];

Expand Down Expand Up @@ -54,7 +54,7 @@ describeLitentry('Test Batch Utility', 0, (context) => {
step('batch test: create identities', async function () {
for (let index = 0; index < ethereumSigners.length; index++) {
const signer = ethereumSigners[index];
const ethereum_identity = await buildIdentityHelper(signer.address, 'Ethereum', 'Evm');
const ethereum_identity = await buildIdentityHelper(signer.address, 'Ethereum', 'Evm', context);
identities.push(ethereum_identity);

//check idgraph from sidechain storage before create
Expand All @@ -67,17 +67,21 @@ describeLitentry('Test Batch Utility', 0, (context) => {
identity_hex
);
assert.equal(
resp_id_graph.verification_request_block,
resp_id_graph.verificationRequestBlock.toHuman(),
null,
'verification_request_block should be null before create'
'verificationRequestBlock should be null before create'
);
assert.equal(
resp_id_graph.linking_request_block,
resp_id_graph.creationRequestBlock.toHuman(),
null,
'linking_request_block should be null before create'
'creationRequestBlock should be null before create'
);

assert.equal(resp_id_graph.is_verified, false, 'IDGraph is_verified should be equal false before create');
assert.equal(
resp_id_graph.isVerified.toHuman(),
false,
'IDGraph is_verified should be equal false before create'
);
}
const txs = await buildIdentityTxs(context, context.substrateWallet.alice, identities, 'createIdentity');

Expand All @@ -89,9 +93,9 @@ describeLitentry('Test Batch Utility', 0, (context) => {
['IdentityCreated']
);
const event_datas = await handleIdentityEvents(context, aesKey, resp_events, 'IdentityCreated');
for (let i = 0; i < event_datas.length; i++) {
assertIdentityCreated(context.substrateWallet.alice, event_datas[i]);
}

await assertIdentityCreated(context, context.substrateWallet.alice, resp_events, aesKey, identities);

const ethereum_validations = await buildValidations(
context,
event_datas,
Expand All @@ -109,7 +113,7 @@ describeLitentry('Test Batch Utility', 0, (context) => {
const resp_events = await sendTxsWithUtility(context, context.substrateWallet.bob, txs, 'identityManagement', [
'CreateIdentityFailed',
]);
await checkErrorDetail(resp_events, 'UserShieldingKeyNotFound', true);
await checkErrorDetail(resp_events, 'UserShieldingKeyNotFound');
});
step('batch test: verify identity', async function () {
let txs = await buildIdentityTxs(
Expand All @@ -124,9 +128,7 @@ describeLitentry('Test Batch Utility', 0, (context) => {
'IdentityVerified',
]);

let event_datas = await handleIdentityEvents(context, aesKey, resp_events, 'IdentityVerified');

assertIdentityVerified(context.substrateWallet.alice, event_datas);
await assertIdentityVerified(context, context.substrateWallet.alice, resp_events, aesKey, identities);
});

step('batch test: verify error identity', async function () {
Expand All @@ -140,26 +142,31 @@ describeLitentry('Test Batch Utility', 0, (context) => {
let resp_events = await sendTxsWithUtility(context, context.substrateWallet.alice, txs, 'identityManagement', [
'VerifyIdentityFailed',
]);
const resp_event_datas = await handleIdentityEvents(context, aesKey, resp_events, 'Failed');
await checkErrorDetail(resp_event_datas, 'ChallengeCodeNotFound', false);
await checkErrorDetail(resp_events, 'ChallengeCodeNotFound');
});
//query here in the hope that the status remains unchanged after verify error identity
step('batch test:check IDGraph after verifyIdentity', async function () {
for (let index = 0; index < identities.length; index++) {
const identity_hex = context.api.createType('LitentryIdentity', identities[index]).toHex();
const identity_hex = context.sidechainRegistry
.createType('LitentryPrimitivesIdentity', identities[index])
.toHex();
const resp_id_graph = await checkIDGraph(
context,
'IdentityManagement',
'IDGraphs',
u8aToHex(context.substrateWallet.alice.addressRaw),
identity_hex
);
assert.notEqual(
resp_id_graph.verification_request_block,
null,
'verification_request_block should not be null after verifyIdentity'

assert(
Number(resp_id_graph.verificationRequestBlock.toHuman()) > 0,
'verificationRequestBlock should be greater than 0 after verifyIdentity'
);
assert.equal(resp_id_graph.is_verified, true, 'is_verified should be true after verifyIdentity');
assert(
Number(resp_id_graph.creationRequestBlock.toHuman()) > 0,
'creationRequestBlock should be greater than 0 after verifyIdentity'
);
assert.equal(resp_id_graph.isVerified.toHuman(), true, 'isVerified should be true after verifyIdentity');
}
});
step('batch test: remove identities', async function () {
Expand All @@ -171,10 +178,8 @@ describeLitentry('Test Batch Utility', 0, (context) => {
'identityManagement',
['IdentityRemoved']
);
const resp_event_datas = await handleIdentityEvents(context, aesKey, resp_remove_events, 'IdentityRemoved');
for (let i = 0; i < resp_event_datas.length; i++) {
assertIdentityRemoved(context.substrateWallet.alice, resp_event_datas[i]);
}

await assertIdentityRemoved(context, context.substrateWallet.alice, resp_remove_events);
});
step('batch test: remove error identities', async function () {
let txs = await buildIdentityTxs(context, context.substrateWallet.alice, identities, 'removeIdentity');
Expand All @@ -185,14 +190,15 @@ describeLitentry('Test Batch Utility', 0, (context) => {
'identityManagement',
['RemoveIdentityFailed']
);
const resp_event_datas = await handleIdentityEvents(context, aesKey, resp_remove_events, 'Failed');
await checkErrorDetail(resp_event_datas, 'IdentityNotExist', false);
await checkErrorDetail(resp_remove_events, 'IdentityNotExist');
});

//query here in the hope that the status remains unchanged after removes error identity
step('check IDGraph after removeIdentity', async function () {
for (let index = 0; index < identities.length; index++) {
const identity_hex = context.api.createType('LitentryIdentity', identities[index]).toHex();
const identity_hex = context.sidechainRegistry
.createType('LitentryPrimitivesIdentity', identities[index])
.toHex();

const resp_id_graph = await checkIDGraph(
context,
Expand All @@ -202,16 +208,16 @@ describeLitentry('Test Batch Utility', 0, (context) => {
identity_hex
);
assert.equal(
resp_id_graph.verification_request_block,
resp_id_graph.verificationRequestBlock.toHuman(),
null,
'verification_request_block should be null after removeIdentity'
'verificationRequestBlock should be null after removeIdentity'
);
assert.equal(
resp_id_graph.linking_request_block,
resp_id_graph.creationRequestBlock.toHuman(),
null,
'linking_request_block should be null after removeIdentity'
'creationRequestBlock should be null after removeIdentity'
);
assert.equal(resp_id_graph.is_verified, false, 'is_verified should be false after removeIdentity');
assert.equal(resp_id_graph.isVerified.toHuman(), false, 'isVerified should be false after removeIdentity');
}
});
});
49 changes: 13 additions & 36 deletions tee-worker/ts-tests/bulk_identity.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { step } from 'mocha-steps';
import {
buildValidations,
describeLitentry,
buildIdentityTxs,
buildIdentityHelper,
assertIdentityCreated,
assertIdentityRemoved,
assertIdentityVerified,
assertInitialIDGraphCreated,
} from './common/utils';
import { buildValidations, describeLitentry, buildIdentityTxs, buildIdentityHelper } from './common/utils';
import { KeyringPair } from '@polkadot/keyring/types';
import { ethers } from 'ethers';
import { LitentryIdentity, LitentryValidationData } from './common/type-definitions';
import type { BatchCall, IdentityGenericEvent } from './common/type-definitions';
import type { LitentryPrimitivesIdentity } from '@polkadot/types/lookup';
import type { LitentryValidationData } from './parachain-interfaces/identity/types';
import type { Call } from '@polkadot/types/interfaces/types';
import type { Vec } from '@polkadot/types';
import { handleIdentityEvents } from './common/utils';
import { assert } from 'chai';
import { multiAccountTxSender } from './common/transactions';
import { SubmittableResult } from '@polkadot/api';

//Explain how to use this test, which has two important parameters:
//1.The "number" parameter in describeLitentry represents the number of accounts generated, including Substrate wallets and Ethereum wallets.If you want to use a large number of accounts for testing, you can modify this parameter.
//2.Each time the test code is executed, new wallet account will be used.
Expand All @@ -25,7 +20,7 @@ describeLitentry('multiple accounts test', 2, async (context) => {
var substrateSigners: KeyringPair[] = [];
var ethereumSigners: ethers.Wallet[] = [];
var web3Validations: LitentryValidationData[] = [];
var identities: LitentryIdentity[] = [];
var identities: LitentryPrimitivesIdentity[] = [];
step('setup signers', async () => {
substrateSigners = context.web3Signers.map((web3Signer) => {
return web3Signer.substrateWallet;
Expand All @@ -35,15 +30,15 @@ describeLitentry('multiple accounts test', 2, async (context) => {
});
});
step('send test token to each account', async () => {
const txs: any = [];
const txs: BatchCall = [];
for (let i = 0; i < substrateSigners.length; i++) {
//1 token
const tx = context.api.tx.balances.transfer(substrateSigners[i].address, '1000000000000');
txs.push(tx);
}
await new Promise((resolve, reject) => {
context.api.tx.utility
.batch(txs)
.batch(txs as Vec<Call>)
.signAndSend(context.substrateWallet.alice, (result: SubmittableResult) => {
console.log(`Current status is ${result.status}`);
if (result.status.isFinalized) {
Expand All @@ -62,17 +57,12 @@ describeLitentry('multiple accounts test', 2, async (context) => {
const resp_events = await multiAccountTxSender(context, txs, substrateSigners, 'identityManagement', [
'UserShieldingKeySet',
]);

const event_datas = await handleIdentityEvents(context, aesKey, resp_events, 'UserShieldingKeySet');
event_datas.forEach(async (data: any, index: number) => {
await assertInitialIDGraphCreated(context.api, substrateSigners[index], data);
});
});

//test identity with multiple accounts
step('test createIdentity with multiple accounts', async () => {
for (let index = 0; index < ethereumSigners.length; index++) {
let identity = await buildIdentityHelper(ethereumSigners[index].address, 'Ethereum', 'Evm');
let identity = await buildIdentityHelper(ethereumSigners[index].address, 'Ethereum', 'Evm', context);
identities.push(identity);
}

Expand All @@ -82,11 +72,6 @@ describeLitentry('multiple accounts test', 2, async (context) => {
'IdentityCreated',
]);
const resp_events_datas = await handleIdentityEvents(context, aesKey, resp_events, 'IdentityCreated');

for (let index = 0; index < resp_events_datas.length; index++) {
console.log('createIdentity', index);
assertIdentityCreated(substrateSigners[index], resp_events_datas[index]);
}
const validations = await buildValidations(
context,
resp_events_datas,
Expand All @@ -104,11 +89,7 @@ describeLitentry('multiple accounts test', 2, async (context) => {
const resp_events = await multiAccountTxSender(context, txs, substrateSigners, 'identityManagement', [
'IdentityVerified',
]);
const [resp_events_datas] = await handleIdentityEvents(context, aesKey, resp_events, 'IdentityVerified');
for (let index = 0; index < resp_events_datas.length; index++) {
console.log('verifyIdentity', index);
assertIdentityVerified(substrateSigners[index], resp_events_datas);
}
assert.equal(resp_events.length, txs.length, 'verify identities with multiple accounts check fail');
});

step('test removeIdentity with multiple accounts', async () => {
Expand All @@ -117,10 +98,6 @@ describeLitentry('multiple accounts test', 2, async (context) => {
const resp_events = await multiAccountTxSender(context, txs, substrateSigners, 'identityManagement', [
'IdentityRemoved',
]);
const [resp_events_datas] = await handleIdentityEvents(context, aesKey, resp_events, 'IdentityRemoved');
for (let index = 0; index < resp_events_datas.length; index++) {
console.log('verifyIdentity', index);
assertIdentityRemoved(substrateSigners[index], resp_events_datas);
}
assert.equal(resp_events.length, txs.length, 'remove identities with multiple accounts check fail');
});
});
26 changes: 10 additions & 16 deletions tee-worker/ts-tests/bulk_vc.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { step } from 'mocha-steps';
import { checkVc, describeLitentry, encryptWithTeeShieldingKey } from './common/utils';
import { KeyringPair } from '@polkadot/keyring/types';
import { ethers } from 'ethers';
import { Assertion, IndexingNetwork, TransactionSubmit } from './common/type-definitions';
import { hexToU8a } from '@polkadot/util';
import { IndexingNetwork } from './common/type-definitions';
import { handleVcEvents } from './common/utils';
import { blake2AsHex } from '@polkadot/util-crypto';
import { assert } from 'chai';
import { HexString } from '@polkadot/util/types';
import type { HexString } from '@polkadot/util/types';
import type { Assertion, TransactionSubmit } from './common/type-definitions';
import type { KeyringPair } from '@polkadot/keyring/types';
import { multiAccountTxSender } from './common/transactions';
import { ApiTypes, SubmittableExtrinsic } from '@polkadot/api/types';
import { SubmittableResult } from '@polkadot/api';
import { hexToU8a } from '@polkadot/util';
const assertion = <Assertion>{
const all_assertions = <Assertion>{
A1: 'A1',
A2: ['A2'],
A3: ['A3', 'A3', 'A3'],
Expand All @@ -21,25 +20,23 @@ const assertion = <Assertion>{
A10: '10.003',
A11: '10.004',
};

const assertion_A1: Assertion = {
A1: 'A1',
};
//Explain how to use this test, which has two important parameters:
//1.The "number" parameter in describeLitentry represents the number of accounts generated, including Substrate wallets and Ethereum wallets.If you want to use a large number of accounts for testing, you can modify this parameter.
//2.Each time the test code is executed, new wallet account will be used.

describeLitentry('multiple accounts test', 2, async (context) => {
const aesKey = '0x22fc82db5b606998ad45099b7978b5b4f9dd4ea6017e57370ac56141caaabd12';
var substrateSigners: KeyringPair[] = [];
var ethereumSigners: ethers.Wallet[] = [];
var vcIndexList: HexString[] = [];
// If want to test other assertions with multiple accounts,just need to make changes here.
let assertion_type = assertion.A1;
let assertion_type = assertion_A1;
step('init', async () => {
substrateSigners = context.web3Signers.map((web3Signer) => {
return web3Signer.substrateWallet;
});
ethereumSigners = context.web3Signers.map((web3Signer) => {
return web3Signer.ethereumWallet;
});
});
step('send test token to each account', async () => {
const txs: any[] = [];
Expand All @@ -49,7 +46,6 @@ describeLitentry('multiple accounts test', 2, async (context) => {
const tx = context.api.tx.balances.transfer(substrateSigners[i].address, '1000000000000');
txs.push(tx);
}

await new Promise((resolve, reject) => {
context.api.tx.utility
.batch(txs)
Expand Down Expand Up @@ -82,8 +78,6 @@ describeLitentry('multiple accounts test', 2, async (context) => {
step('test requestVc with multiple accounts', async () => {
let txs: TransactionSubmit[] = [];
for (let i = 0; i < substrateSigners.length; i++) {
console.log(assertion_type);

const tx = context.api.tx.vcManagement.requestVc(context.mrEnclave, assertion_type);
const nonce = (await context.api.rpc.system.accountNextIndex(substrateSigners[i].address)).toNumber();
txs.push({ tx, nonce });
Expand Down
Loading