Skip to content

Commit

Permalink
Adding integration tests for the new trusted calls (omni account) (#3173
Browse files Browse the repository at this point in the history
)

* updating context types

* exporting di-utils functions

* adding initial omni-account-helpers

* exporting signer type

* adding test for create_account_store

* fixing verify_web3_identity helper

* adding more helpers

* adding test for add_account

* removing unnecessary step

* adding delay to wait for events to be processed in the worker

* incrementing nonce on dispatch_as_signed

* updating definitions

* reusing old helpers

* updating ts helpers

* disabling timeout

* making nonce explicit

* updating comments

* fixing usage of build web3 validation data

* test add web2 account

* fixing remove_accounts opaque call

* updating helpers

* adding test for remove_accounts

* putting back timeout

* removing comments

* adding helper

* adding tests for publicize_account

* increasing timeout

* adding test for incrementing nonce when dispatch_as_signed

* refactoring fundAccount helper

* refactoring helper name

* refactoring sender name to alice

* adding request_intent test

* setting up omni-account integration tests

* cleaning up helpers

* removing unnecessary delay

* fixing clippy issue

* increasing delay for events to be processed

* adding get_account_by_member_hash to omni account repository

* getting omni account from the parachain when the in-memory store is not
up to date

* cleaning up tests, removing delay

* increasing timeout

* adding support for email verification on create_account_store with email
identity

* updating type definitions

* fixing clippy issue

* client packages: use `TrustedOperationAuthenticated` (#3174)

Signed-off-by: Jonathan Alvarez <[email protected]>

---------

Signed-off-by: Jonathan Alvarez <[email protected]>
Co-authored-by: Kai <[email protected]>
Co-authored-by: Jonathan Alvarez <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2024
1 parent f753f9c commit af72747
Show file tree
Hide file tree
Showing 24 changed files with 757 additions and 107 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
fi
if [ "${{ github.event.inputs.check-omni-executor }}" = "true" ] || [ "${{ steps.filter.outputs.omni_executor_src }}" = "true" ]; then
check_omni_executor=true
fi
fi
if [ "${{ github.event.inputs.push-docker }}" = "true" ]; then
push_docker=true
elif [ "${{ github.event_name }}" = 'push' ] && [ "${{ github.ref }}" = 'refs/heads/dev' ]; then
Expand Down Expand Up @@ -750,6 +750,7 @@ jobs:
- test_name: lit-dr-vc-test
- test_name: lit-parentchain-nonce
- test_name: lit-test-failed-parentchain-extrinsic
- test_name: lit-omni-account-test
name: ${{ matrix.test_name }}
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -820,6 +821,7 @@ jobs:
- test_name: lit-di-identity-multiworker-test
- test_name: lit-dr-vc-multiworker-test
- test_name: lit-resume-worker
- test_name: lit-omni-account-multiworker-test
name: ${{ matrix.test_name }}
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions parachain/pallets/omni-account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pub mod pallet {
PostDispatchInfo,
sp_runtime::DispatchErrorWithPostInfo<PostDispatchInfo>,
> = call.dispatch(frame_system::RawOrigin::Signed(omni_account.clone()).into());
system::Pallet::<T>::inc_account_nonce(&omni_account);
Self::deposit_event(Event::DispatchedAsSigned {
who: omni_account,
result: result.map(|_| ()).map_err(|e| e.error),
Expand Down
29 changes: 29 additions & 0 deletions parachain/pallets/omni-account/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,32 @@ fn dispatch_as_omni_account_increments_omni_account_nonce() {
assert_eq!(System::account_nonce(alice().omni_account), 1);
});
}

#[test]
fn dispatch_as_signed_account_increments_omni_account_nonce() {
new_test_ext().execute_with(|| {
let tee_signer = get_tee_signer();

assert_ok!(Balances::transfer(
RuntimeOrigin::signed(alice().native_account),
alice().omni_account,
6
));

assert_ok!(OmniAccount::create_account_store(
RuntimeOrigin::signed(tee_signer.clone()),
alice().identity,
));

assert_eq!(System::account_nonce(alice().omni_account), 0);

let call = make_balance_transfer_call(bob().native_account, 5);

assert_ok!(OmniAccount::dispatch_as_signed(
RuntimeOrigin::signed(tee_signer),
alice().identity.hash(),
call
));
assert_eq!(System::account_nonce(alice().omni_account), 1);
});
}
1 change: 1 addition & 0 deletions tee-worker/identity/client-api/parachain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Expose the OmniAccount's trusted calls: `request_intent`, `create_account_store`, `add_account`, and `remove_accounts`.
- Add `TrustedCallAuthenticated` and `TCAuthentication` trusted call structs.
- Add `TrustedCallResult` to handle OmniAccount's call results.
- Add `TrustedOperationAuthenticated` type definition.

## [0.9.20-4.1] - 2024-09-30

Expand Down
2 changes: 1 addition & 1 deletion tee-worker/identity/client-api/parachain-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/src/index.js",
"module": "dist/src/index.js",
"sideEffects": false,
"version": "0.9.20-next.7",
"version": "0.9.20-next.8",
"scripts": {
"clean": "rm -rf dist build node_modules",
"update-metadata": "curl -s -H \"Content-Type: application/json\" -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9944 > prepare-build/litentry-parachain-metadata.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ export default {
get: "(Getter)",
},
},
TrustedOperationAuthenticated: {
_enum: {
indirect_call: "Null",
direct_call: "(TrustedCallAuthenticated)",
get: "(Getter)",
},
},
TrustedCallSigned: {
call: "TrustedCall",
index: "u32",
index: "Index",
signature: "LitentryMultiSignature",
},
TrustedGetterSigned: {
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/identity/client-api/sidechain-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/src/index.js",
"module": "dist/src/index.js",
"sideEffects": false,
"version": "0.9.20-next.7",
"version": "0.9.20-next.8",
"scripts": {
"clean": "rm -rf dist build node_modules",
"update-metadata": "../../bin/litentry-cli print-sgx-metadata-raw > prepare-build/litentry-sidechain-metadata.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@litentry/client-sdk",
"description": "This package provides helpers for dApps to interact with the Litentry Protocol.",
"version": "1.0.0-next.1",
"version": "1.0.0-next.2",
"license": "GPL-3.0-or-later",
"dependencies": {},
"devDependencies": {
"@polkadot/rpc-provider": "^10.9.1"
},
"peerDependencies": {
"@litentry/parachain-api": "0.9.20-next.7",
"@litentry/sidechain-api": "0.9.20-next.7",
"@litentry/parachain-api": "0.9.20-next.8",
"@litentry/sidechain-api": "0.9.20-next.8",
"@litentry/chaindata": "*",
"@polkadot/api": "^10.9.1",
"@polkadot/types": "^10.9.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function createRequestType(
}),
});

const operation = api.createType('TrustedOperation', {
const operation = api.createType('TrustedOperationAuthenticated', {
direct_call: callAuthenticated,
});

Expand Down
16 changes: 8 additions & 8 deletions tee-worker/identity/client-sdk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tee-worker/identity/docker/lit-omni-account-multiworker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
lit-omni-account-multiworker-test:
image: litentry/identity-cli:latest
container_name: lit-omni-account-multiworker-test
volumes:
- ../ts-tests:/ts-tests
- ../client-api:/client-api
- ../cli:/usr/local/worker-cli
build:
context: ..
dockerfile: build.Dockerfile
target: deployed-client
depends_on:
litentry-worker-3:
condition: service_healthy
networks:
- litentry-test-network
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh omni_account.test.ts 2>&1' "
restart: "no"
networks:
litentry-test-network:
driver: bridge
22 changes: 22 additions & 0 deletions tee-worker/identity/docker/lit-omni-account-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
lit-omni-account-test:
image: litentry/identity-cli:latest
container_name: litentry-omni-account-test
volumes:
- ../ts-tests:/ts-tests
- ../client-api:/client-api
- ../cli:/usr/local/worker-cli
build:
context: ..
dockerfile: build.Dockerfile
target: deployed-client
depends_on:
litentry-worker-1:
condition: service_healthy
networks:
- litentry-test-network
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh omni_account.test.ts 2>&1' "
restart: "no"
networks:
litentry-test-network:
driver: bridge
6 changes: 0 additions & 6 deletions tee-worker/identity/enclave-runtime/src/rpc/common_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use lc_identity_verification::{
web2::{email, twitter},
VerificationCodeStore,
};
use lc_omni_account::InMemoryStore as OmniAccountStore;
use litentry_macros::{if_development, if_development_or};
use litentry_primitives::{aes_decrypt, AesRequest, DecryptableRequest, Identity};
use log::debug;
Expand Down Expand Up @@ -477,11 +476,6 @@ pub fn add_common_api<Author, GetterExecutor, AccessShieldingKey, OcallApi, Stat
"Could not parse omni account"
))),
};
match OmniAccountStore::get_member_accounts(&omni_account) {
Ok(Some(_member_accounts)) => {},
_ =>
return Ok(json!(compute_hex_encoded_return_error("Omni account not found"))),
}
let mut mailer = email::sendgrid_mailer::SendGridMailer::new(
data_provider_config.sendgrid_api_key.clone(),
data_provider_config.sendgrid_from_email.clone(),
Expand Down

This file was deleted.

Loading

0 comments on commit af72747

Please sign in to comment.