-
Notifications
You must be signed in to change notification settings - Fork 20
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
Data providers tests for vip3 #2431
Changes from all commits
dfb6095
d924341
f09fef4
cc54692
5603473
f884970
23e886c
934de08
568f336
c6504e2
6738c79
d2ec757
c654917
e51c132
248fb0a
ed722f2
41b613a
e5dd23b
79feee1
4a945ee
f76265a
24a4787
9d37fc2
3b0d09c
53843ae
10292b5
fb88115
cd91504
1ffd66d
70f825c
0411ac4
a9e8e19
0376100
772fd21
dfac634
5da02c2
f45272f
9e37d11
6b7eb64
639d04e
3e374c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
services: | ||
lit-data-providers-test: | ||
image: litentry/litentry-cli:latest | ||
container_name: litentry-data-providers-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-node: | ||
condition: service_healthy | ||
litentry-worker-1: | ||
condition: service_healthy | ||
networks: | ||
- litentry-test-network | ||
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh test-data-providers 2>&1' " | ||
restart: "no" | ||
networks: | ||
litentry-test-network: | ||
driver: bridge |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
NODE_ENV = local | ||
WORKER_ENDPOINT = wss://localhost:2000 | ||
NODE_ENDPOINT = ws://localhost:9944 | ||
NODE_ENDPOINT = ws://localhost:9944 | ||
BINARY_DIR=../../bin | ||
LITENTRY_CLI_DIR=../../bin/litentry-cli |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { CorePrimitivesAssertion, CorePrimitivesNetworkWeb3Network } from 'parachain-api'; | ||
import type { Codec } from '@polkadot/types-codec/types'; | ||
import type { U8aLike } from '@polkadot/util/types'; | ||
type DataProvider = { | ||
id: string; | ||
name: string; | ||
url: string; | ||
}; | ||
|
||
type AssertionGenericPayload = string | Array<string | number | Codec | U8aLike> | Record<string, unknown>; | ||
|
||
import vip3Json from './vip3-credential-test.json' assert { type: 'json' }; | ||
export const vip3CredentialJson = vip3Json as unknown as CredentialDefinition[]; | ||
|
||
export interface CredentialDefinition { | ||
id: string; | ||
name: string; | ||
description: string; | ||
assertion: { | ||
id: CorePrimitivesAssertion['type']; | ||
payload: AssertionGenericPayload; | ||
}; | ||
dataProvider: DataProvider; | ||
network: CorePrimitivesNetworkWeb3Network['type']; | ||
mockDid: string; | ||
mockWeb3Network: string; | ||
expectedCredentialValue: boolean; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[ | ||
{ | ||
"id": "vip3-membership-card-gold", | ||
"name": "VIP3 Membership Card Gold", | ||
"description": "VIP3 Membership Card Gold", | ||
"assertion": { | ||
"id": "Vip3MembershipCard", | ||
"payload": "Gold" | ||
}, | ||
"dataProvider": "vip3", | ||
"network": "ethereum", | ||
"mockDid": "litentry:evm:0x651614cA9097C5ba189Ef85e7851Ef9cff592B2c", | ||
"mockWeb3Network": "bsc,ethereum", | ||
"expectedCredentialValue": true | ||
}, | ||
{ | ||
"id": "vip3-membership-card-silver", | ||
"name": "VIP3 Membership Card Silver", | ||
"description": "VIP3 Membership Card Silver", | ||
"assertion": { | ||
"id": "Vip3MembershipCard", | ||
"payload": "Silver" | ||
}, | ||
"dataProvider": "vip3", | ||
"network": "ethereum", | ||
"mockDid": "litentry:evm:0x10CdF7F7A32E2F24c853AE6567b75D862Ee2B46f", | ||
"mockWeb3Network": "bsc,ethereum", | ||
"expectedCredentialValue": true | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { randomBytes, KeyObject } from 'crypto'; | ||
import { step } from 'mocha-steps'; | ||
import { assert } from 'chai'; | ||
import { buildIdentityFromKeypair, decryptWithAes, initIntegrationTestContext, PolkadotSigner } from './common/utils'; | ||
import { randomSubstrateWallet } from './common/helpers'; | ||
import { assertIsInSidechainBlock } from './common/utils/assertion'; | ||
import { | ||
getSidechainNonce, | ||
getTeeShieldingKey, | ||
sendRequestFromTrustedCall, | ||
createSignedTrustedCallRequestVc, | ||
} from './common/di-utils'; // @fixme move to a better place | ||
import type { IntegrationTestContext } from './common/common-types'; | ||
import { CorePrimitivesIdentity, RequestVCResult } from 'parachain-api'; | ||
import { aesKey } from './common/call'; | ||
import { $ as zx } from 'zx'; | ||
import { subscribeToEventsWithExtHash } from './common/transactions'; | ||
import { KeyringPair } from '@polkadot/keyring/types'; | ||
import { u8aToHex } from '@polkadot/util'; | ||
import { vip3CredentialJson, CredentialDefinition } from './common/credential-json'; | ||
describe('Test Vc (direct invocation)', function () { | ||
let context: IntegrationTestContext = undefined as any; | ||
let teeShieldingKey: KeyObject = undefined as any; | ||
const substrateIdentities: CorePrimitivesIdentity[] = []; | ||
|
||
const clientDir = process.env.LITENTRY_CLI_DIR; | ||
const reqExtHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; | ||
const keyringPairs: KeyringPair[] = []; | ||
let argvId = ''; | ||
const credentialsJson: CredentialDefinition[] = [...vip3CredentialJson]; | ||
|
||
this.timeout(6000000); | ||
before(async () => { | ||
context = await initIntegrationTestContext(process.env.WORKER_ENDPOINT!, process.env.NODE_ENDPOINT!); | ||
teeShieldingKey = await getTeeShieldingKey(context); | ||
}); | ||
|
||
// usage example: | ||
// `pnpm run test-data-providers:local --id=vip3-membership-card-gold` for single test | ||
// `pnpm run test-data-providers:local` for all tests | ||
const argv = process.argv.indexOf('--id'); | ||
argvId = process.argv[argv + 1]; | ||
const { | ||
protocol: workerProtocal, | ||
hostname: workerHostname, | ||
port: workerPort, | ||
} = new URL(process.env.WORKER_ENDPOINT!); | ||
const { protocol: nodeProtocal, hostname: nodeHostname, port: nodePort } = new URL(process.env.NODE_ENDPOINT!); | ||
|
||
async function linkIdentityViaCli(id: string) { | ||
const credentialDefinitions = credentialsJson.find((item) => item.id === id) as CredentialDefinition; | ||
|
||
const keyringPair = randomSubstrateWallet(); | ||
keyringPairs.push(keyringPair); | ||
const formatAddress = u8aToHex(keyringPair.publicKey); | ||
|
||
const substrateIdentity = await buildIdentityFromKeypair(new PolkadotSigner(keyringPair), context); | ||
substrateIdentities.push(substrateIdentity); | ||
const eventsPromise = subscribeToEventsWithExtHash(reqExtHash, context); | ||
try { | ||
// CLIENT = "$CLIENT_BIN -p $NPORT -P $WORKER1PORT -u $NODEURL -U $WORKER1URL" | ||
const commandPromise = zx`${clientDir} -p ${nodePort} -P ${workerPort} -u ${ | ||
nodeProtocal + nodeHostname | ||
} -U ${workerProtocal + workerHostname}\ | ||
trusted -d link-identity did:litentry:substrate:${formatAddress}\ | ||
did:${credentialDefinitions.mockDid}\ | ||
${credentialDefinitions.mockWeb3Network}`; | ||
|
||
await commandPromise; | ||
} catch (error: any) { | ||
console.log(`Exit code: ${error.exitCode}`); | ||
console.log(`Error: ${error.stderr}`); | ||
throw error; | ||
} | ||
|
||
const events = (await eventsPromise).map(({ event }) => event); | ||
assert.equal(events.length, 1); | ||
} | ||
|
||
async function requestVc(id: string, index: number) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to utilise this function for other scenarios, like NFT holder or BNB domain? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're referring to other cases, right? Currently, this pr is for VIP3, but I am testing the other cases. To avoid ambiguity, I am redefining credentials array here. |
||
const credentialDefinitions = credentialsJson.find((item) => item.id === id) as CredentialDefinition; | ||
|
||
const assertion = { | ||
[credentialDefinitions.assertion.id]: credentialDefinitions.assertion.payload, | ||
}; | ||
|
||
let currentNonce = (await getSidechainNonce(context, teeShieldingKey, substrateIdentities[index])).toNumber(); | ||
const getNextNonce = () => currentNonce++; | ||
const nonce = getNextNonce(); | ||
console.log(nonce, substrateIdentities[index].toHuman(), u8aToHex(keyringPairs[index].publicKey)); | ||
|
||
const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; | ||
const requestVcCall = await createSignedTrustedCallRequestVc( | ||
context.api, | ||
context.mrEnclave, | ||
context.api.createType('Index', nonce), | ||
new PolkadotSigner(keyringPairs[index]), | ||
substrateIdentities[index], | ||
context.api.createType('Assertion', assertion).toHex(), | ||
context.api.createType('Option<RequestAesKey>', aesKey).toHex(), | ||
requestIdentifier | ||
); | ||
const res = await sendRequestFromTrustedCall(context, teeShieldingKey, requestVcCall); | ||
await assertIsInSidechainBlock(`${Object.keys(assertion)[0]} requestVcCall`, res); | ||
|
||
const vcResults = context.api.createType('RequestVCResult', res.value) as unknown as RequestVCResult; | ||
const decryptVcPayload = decryptWithAes(aesKey, vcResults.vc_payload, 'utf-8').replace('0x', ''); | ||
const vcPayloadJson = JSON.parse(decryptVcPayload); | ||
|
||
assert.equal(vcPayloadJson.credentialSubject.values[0], credentialDefinitions.expectedCredentialValue); | ||
} | ||
|
||
if (argvId && credentialsJson.find((item) => item.id === argvId)) { | ||
const credentialDefinitions = credentialsJson.find((item) => item.id === argvId) as CredentialDefinition; | ||
|
||
step( | ||
`linking identity::${credentialDefinitions.mockDid} via cli and request vc::${credentialDefinitions.mockDid}`, | ||
async function () { | ||
await linkIdentityViaCli(argvId); | ||
await requestVc(argvId, 0); | ||
} | ||
); | ||
} else { | ||
credentialsJson.forEach(({ id }, index) => { | ||
step( | ||
`linking identity::${credentialsJson[index].mockDid} via cli and request vc::${credentialsJson[index].id}`, | ||
async function () { | ||
await linkIdentityViaCli(id); | ||
await requestVc(id, index); | ||
} | ||
); | ||
}); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to utilise this function for other VC scenarios, like NFT holder or BNB domain?