Skip to content

Commit

Permalink
ts-tests: avoid hardcoded runtime version (#3040)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Alvarez <[email protected]>
  • Loading branch information
jonalvarezz authored Sep 3, 2024
1 parent 3c15734 commit 306b717
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
10 changes: 7 additions & 3 deletions tee-worker/enclave-runtime/src/rpc/common_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use base58::FromBase58;
use codec::{Decode, Encode};
use core::result::Result;
use ita_sgx_runtime::{Runtime, System};
use ita_sgx_runtime::{Runtime, System, VERSION};
use ita_stf::{aes_encrypt_default, AesOutput, Getter, TrustedCallSigned};
use itc_parentchain::light_client::{concurrent_access::ValidatorAccess, ExtrinsicSender};
use itp_ocall_api::EnclaveAttestationOCallApi;
Expand Down Expand Up @@ -233,8 +233,12 @@ pub fn add_common_api<Author, GetterExecutor, AccessShieldingKey, OcallApi, Stat

io_handler.add_sync_method("state_getRuntimeVersion", |_: Params| {
debug!("worker_api_direct rpc was called: state_getRuntimeVersion");
let parsed = "world";
Ok(Value::String(format!("hello, {}", parsed)))
let runtime_version = VERSION;

let json_value =
RpcReturnValue::new(runtime_version.encode(), false, DirectRequestStatus::Ok);

Ok(json!(json_value.to_hex()))
});

// TODO: deprecate
Expand Down
29 changes: 23 additions & 6 deletions tee-worker/ts-tests/integration-tests/common/utils/assertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import { CorePrimitivesIdentity } from 'parachain-api';
import type { IntegrationTestContext } from '../common-types';
import { getIdGraphHash } from '../di-utils';
import type { HexString } from '@polkadot/util/types';
import { aesKey } from '../call';
import { nextRequestId } from '../helpers';
import { aesKey, sendRequest } from '../call';
import colors from 'colors';
import { WorkerRpcReturnValue, StfError } from 'parachain-api';
import { Bytes } from '@polkadot/types-codec';
import { decryptWithAes } from './crypto';
import { blake2AsHex } from '@polkadot/util-crypto';
import { base58Encode, blake2AsHex } from '@polkadot/util-crypto';
import { validateVcSchema } from '@litentry/vc-schema-validator';
import { PalletIdentityManagementTeeIdentityContext } from 'sidechain-api';
import { KeyObject } from 'crypto';
import * as base58 from 'micro-base58';
import { fail } from 'assert';

export function assertIdGraph(
actual: [CorePrimitivesIdentity, PalletIdentityManagementTeeIdentityContext][],
Expand Down Expand Up @@ -134,7 +133,7 @@ export async function assertVc(context: IntegrationTestContext, subject: CorePri

assert.equal(
vcPayloadJson.issuer.mrenclave,
base58.encode(registeredEnclave.mrenclave),
base58Encode(registeredEnclave.mrenclave),
"Check VC mrenclave: it should equal enclave's mrenclave from parachains enclave registry"
);

Expand All @@ -146,9 +145,27 @@ export async function assertVc(context: IntegrationTestContext, subject: CorePri

// step 7
// check runtime version is present
const [parachainSpecVersion, sidechainSpecVersion] = await Promise.all([
context.api.rpc.state.getRuntimeVersion(),
sendRequest(
context.tee,
{
jsonrpc: '2.0',
id: nextRequestId(context),
method: 'state_getRuntimeVersion',
params: [],
},
context.api
),
]).then(([parachainRuntime, sidechainReturnValue]) => {
const sidechainRuntime = context.api.createType('RuntimeVersion', sidechainReturnValue.value);

return [parachainRuntime.specVersion.toNumber(), sidechainRuntime.specVersion.toNumber()];
});

assert.deepEqual(
vcPayloadJson.issuer.runtimeVersion,
{ parachain: 9200, sidechain: 110 },
{ parachain: parachainSpecVersion, sidechain: sidechainSpecVersion },
'Check VC runtime version: it should equal the current defined versions'
);

Expand Down

0 comments on commit 306b717

Please sign in to comment.