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

Ts type defination #1642

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ jobs:
- test_name: lit-identity-test
- test_name: lit-parentchain-nonce
- test_name: lit-batch-test
- test_name: lit-bulk-identity-test
- test_name: lit-bulk-vc-test

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions scripts/ts-utils/move-vcregistry-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ async function encodeExtrinsic() {
if (data.length === 0 || txs.length >= BATCH_SIZE) {
i++
const extrinsics = defaultAPI.tx.utility.batch(batchTxs);
const sudoExtrinsic = defaultAPI.tx.sudo.sudo(extrinsics);
console.log(colors.green(`extrinsic ${i} encode`), sudoExtrinsic.toHex());
console.log(colors.green(`extrinsic ${i} encode`), extrinsics.toHex());
txs = [];
}
}
Expand Down
5 changes: 2 additions & 3 deletions tee-worker/docker/lit-batch-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ services:
condition: service_healthy
networks:
- integritee-test-network
entrypoint:
"bash -c '/usr/local/worker-cli/lit_ts_test.sh test-batch 2>&1' "
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_test.sh test-batch 2>&1' "
restart: "no"
networks:
integritee-test-network:
driver: bridge
driver: bridge
25 changes: 25 additions & 0 deletions tee-worker/docker/lit-bulk-identity-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
lit-bulk-identity-test:
image: integritee-cli:dev
container_name: litentry-bulk-identity-test
volumes:
- ../ts-tests:/ts-tests
- ../cli:/usr/local/worker-cli
build:
context: ..
dockerfile: build.Dockerfile
target: deployed-client
depends_on:
integritee-node:
condition: service_healthy
integritee-worker-1:
condition: service_healthy
integritee-worker-2:
condition: service_healthy
networks:
- integritee-test-network
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_test.sh test-bulk-identity 2>&1' "
restart: "no"
networks:
integritee-test-network:
driver: bridge
25 changes: 25 additions & 0 deletions tee-worker/docker/lit-bulk-vc-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
lit-bulk-vc-test:
image: integritee-cli:dev
container_name: litentry-bulk-vc-test
volumes:
- ../ts-tests:/ts-tests
- ../cli:/usr/local/worker-cli
build:
context: ..
dockerfile: build.Dockerfile
target: deployed-client
depends_on:
integritee-node:
condition: service_healthy
integritee-worker-1:
condition: service_healthy
integritee-worker-2:
condition: service_healthy
networks:
- integritee-test-network
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_test.sh test-bulk-vc 2>&1' "
restart: "no"
networks:
integritee-test-network:
driver: bridge
72 changes: 35 additions & 37 deletions tee-worker/ts-tests/bulk_identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@ import {
assertIdentityCreated,
assertIdentityRemoved,
assertIdentityVerified,
assertInitialIDGraphCreated,
} from './common/utils';
import { KeyringPair } from '@polkadot/keyring/types';
import { ethers } from 'ethers';
import { LitentryIdentity, LitentryValidationData } from './common/type-definitions';
import { handleIdentityEvents } from './common/utils';
import { assert } from 'chai';
import { listenEvent, multiAccountTxSender } from './common/transactions';
import { multiAccountTxSender } from './common/transactions';
import { u8aToHex } from '@polkadot/util';
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.

describeLitentry('multiple accounts test', 10, async (context) => {
describeLitentry('multiple accounts test', 2, async (context) => {
const aesKey = '0x22fc82db5b606998ad45099b7978b5b4f9dd4ea6017e57370ac56141caaabd12';
var substraetSigners: KeyringPair[] = [];
var substrateSigners: KeyringPair[] = [];
var ethereumSigners: ethers.Wallet[] = [];
var web3Validations: LitentryValidationData[] = [];
var identities: LitentryIdentity[] = [];
step('setup signers', async () => {
substraetSigners = context.web3Signers.map((web3Signer) => {
substrateSigners = context.web3Signers.map((web3Signer) => {
return web3Signer.substrateWallet;
});
ethereumSigners = context.web3Signers.map((web3Signer) => {
Expand All @@ -36,36 +38,36 @@ describeLitentry('multiple accounts test', 10, async (context) => {
});
step('send test token to each account', async () => {
const txs: any = [];
for (let i = 0; i < substraetSigners.length; i++) {
for (let i = 0; i < substrateSigners.length; i++) {
//1 token
const tx = context.api.tx.balances.transfer(substraetSigners[i].address, '1000000000000');
const tx = context.api.tx.balances.transfer(substrateSigners[i].address, '1000000000000');
txs.push(tx);
}
await context.api.tx.utility.batch(txs).signAndSend(context.substrateWallet.alice);
await listenEvent(context.api, 'balances', ['Transfer'], txs.length, [
u8aToHex(context.substrateWallet.alice.addressRaw),
]);

await new Promise((resolve) => {
context.api.tx.utility
.batch(txs)
.signAndSend(context.substrateWallet.alice, async (result: SubmittableResult) => {
if (result.status.isInBlock) {
console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
resolve(result.status);
} else if (result.status.isInvalid) {
console.log(`Transaction is ${result.status}`);
}
});
});
});

//test with multiple accounts
step('test set usershieldingkey with multiple accounts', async () => {
let txs = await buildIdentityTxs(context, substraetSigners, [], 'setUserShieldingKey');
const resp_events = await multiAccountTxSender(context, txs, substraetSigners, 'identityManagement', [
let txs = await buildIdentityTxs(context, substrateSigners, [], 'setUserShieldingKey');
const resp_events = await multiAccountTxSender(context, txs, substrateSigners, 'identityManagement', [
'UserShieldingKeySet',
]);

const event_datas = await handleIdentityEvents(context, aesKey, resp_events, 'UserShieldingKeySet');
assert.equal(
resp_events.length,
substraetSigners.length,
'set usershieldingkey with multiple accounts check fail'
);
event_datas.forEach((data: any, index: number) => {
assert.equal(
data.who,
u8aToHex(substraetSigners[index].addressRaw),
`shielding key should be set,account ${index + 1} is not set`
);
event_datas.forEach(async (data: any, index: number) => {
await assertInitialIDGraphCreated(context.api, substrateSigners[index], data);
});
});

Expand All @@ -76,55 +78,51 @@ describeLitentry('multiple accounts test', 10, async (context) => {
identities.push(identity);
}

let txs = await buildIdentityTxs(context, substraetSigners, identities, 'createIdentity');
let txs = await buildIdentityTxs(context, substrateSigners, identities, 'createIdentity');

const resp_events = await multiAccountTxSender(context, txs, substraetSigners, 'identityManagement', [
const resp_events = await multiAccountTxSender(context, txs, substrateSigners, 'identityManagement', [
'IdentityCreated',
]);
const resp_events_datas = await handleIdentityEvents(context, aesKey, resp_events, 'IdentityCreated');

assert.equal(resp_events.length, identities.length, 'create identities with multiple accounts check fail');

for (let index = 0; index < resp_events_datas.length; index++) {
console.log('createIdentity', index);
assertIdentityCreated(substraetSigners[index], resp_events_datas[index]);
assertIdentityCreated(substrateSigners[index], resp_events_datas[index]);
}
const validations = await buildValidations(
context,
resp_events_datas,
identities,
'ethereum',
substraetSigners,
substrateSigners,
ethereumSigners
);

web3Validations = [...validations];
});

step('test verifyIdentity with multiple accounts', async () => {
let txs = await buildIdentityTxs(context, substraetSigners, identities, 'verifyIdentity', web3Validations);
const resp_events = await multiAccountTxSender(context, txs, substraetSigners, 'identityManagement', [
let txs = await buildIdentityTxs(context, substrateSigners, identities, 'verifyIdentity', web3Validations);
const resp_events = await multiAccountTxSender(context, txs, substrateSigners, 'identityManagement', [
'IdentityVerified',
]);
assert.equal(resp_events.length, txs.length, 'verify identities with multiple accounts check fail');
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(substraetSigners[index], resp_events_datas);
assertIdentityVerified(substrateSigners[index], resp_events_datas);
}
});

step('test removeIdentity with multiple accounts', async () => {
let txs = await buildIdentityTxs(context, substraetSigners, identities, 'removeIdentity');
let txs = await buildIdentityTxs(context, substrateSigners, identities, 'removeIdentity');

const resp_events = await multiAccountTxSender(context, txs, substraetSigners, 'identityManagement', [
const resp_events = await multiAccountTxSender(context, txs, substrateSigners, 'identityManagement', [
'IdentityRemoved',
]);
assert.equal(resp_events.length, txs.length, 'remove identities with multiple accounts check fail');
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(substraetSigners[index], resp_events_datas);
assertIdentityRemoved(substrateSigners[index], resp_events_datas);
}
});
});
24 changes: 16 additions & 8 deletions tee-worker/ts-tests/bulk_vc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { step } from 'mocha-steps';
import { checkVc, describeLitentry, encryptWithTeeShieldingKey } from './common/utils';
import { KeyringPair } from '@polkadot/keyring/types';
import { ethers } from 'ethers';
import { u8aToHex } from '@polkadot/util';
import { Assertion, IndexingNetwork, TransactionSubmit } 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 { listenEvent, multiAccountTxSender } from './common/transactions';
import { SubmittableResult } from '@polkadot/api';
import { multiAccountTxSender } from './common/transactions';
const assertion = <Assertion>{
A1: 'A1',
A2: ['A2'],
Expand All @@ -24,7 +24,7 @@ const assertion = <Assertion>{
//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', 10, async (context) => {
describeLitentry('multiple accounts test', 2, async (context) => {
const aesKey = '0x22fc82db5b606998ad45099b7978b5b4f9dd4ea6017e57370ac56141caaabd12';
var substrateSigners: KeyringPair[] = [];
var ethereumSigners: ethers.Wallet[] = [];
Expand All @@ -44,13 +44,21 @@ describeLitentry('multiple accounts test', 10, async (context) => {
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 context.api.tx.utility.batch(txs).signAndSend(context.substrateWallet.alice);
await listenEvent(context.api, 'balances', ['Transfer'], txs.length, [
u8aToHex(context.substrateWallet.alice.addressRaw),
]);

await new Promise((resolve) => {
context.api.tx.utility
.batch(txs)
.signAndSend(context.substrateWallet.alice, async (result: SubmittableResult) => {
if (result.status.isInBlock) {
console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
resolve(result.status);
} else if (result.status.isInvalid) {
console.log(`Transaction is ${result.status}`);
}
});
});
});
//test with multiple accounts
step('test set usershieldingkey with multiple accounts', async () => {
Expand Down
Loading