From c01f5c78c89b29ff106db2f0452d65f76f8a1493 Mon Sep 17 00:00:00 2001 From: lovesh Date: Sat, 11 May 2024 02:31:37 +0530 Subject: [PATCH] Update as per update in deps and unskip some tests for mainnet Signed-off-by: lovesh --- .github/workflows/integration-tests-ipfs.yml | 2 - .github/workflows/integration-tests.yml | 3 - package.json | 2 +- src/modules/accumulator.js | 12 +--- .../integration/anoncreds/accumulator.test.js | 67 +++++++++---------- .../anoncreds/derived-credentials.test.js | 56 +++++++--------- tests/integration/did/did-key.test.js | 5 +- .../integration/trust-registry-module.test.js | 5 +- tests/test-constants.js | 6 -- 9 files changed, 61 insertions(+), 97 deletions(-) diff --git a/.github/workflows/integration-tests-ipfs.yml b/.github/workflows/integration-tests-ipfs.yml index bdd1b6d0e..35a96ec4b 100644 --- a/.github/workflows/integration-tests-ipfs.yml +++ b/.github/workflows/integration-tests-ipfs.yml @@ -22,7 +22,6 @@ jobs: mainnet: runs-on: ubuntu-latest env: - DisableDidKeyAndTrustRegistryTests: true CONFIG_DOCK_NODE_IMAGE_TAG: 'mainnet' steps: - uses: actions/checkout@v2 @@ -40,7 +39,6 @@ jobs: testnet: runs-on: ubuntu-latest env: - DisableDidKeyAndTrustRegistryTests: true CONFIG_DOCK_NODE_IMAGE_TAG: 'testnet' steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 241f9f45c..c39f592d3 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -17,8 +17,6 @@ jobs: mainnet: runs-on: ubuntu-latest env: - DisableDidKeyAndTrustRegistryTests: true - DisableNewAccumulatorTests: true CONFIG_DOCK_NODE_IMAGE_TAG: 'mainnet' steps: - uses: actions/checkout@v2 @@ -31,7 +29,6 @@ jobs: testnet: runs-on: ubuntu-latest env: - DisableNewAccumulatorTests: true CONFIG_DOCK_NODE_IMAGE_TAG: 'testnet' steps: - uses: actions/checkout@v2 diff --git a/package.json b/package.json index c5e49671e..96a625b27 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "txn-pricing": "npx babel-node scripts/txn-pricing.js", "claim-deduction-example": "npx babel-node example/claim-deduction.js", "anchor-example": "npx babel-node example/anchor.js", - "test-examples": "yarn dock-did-example && yarn did-resolver-example && yarn revocation-example && yarn vcdm-example && yarn standard-schemas-example && yarn schema-example && yarn schema-validation-example && yarn blob-example && yarn claim-deduction-example && yarn anchor-example && yarn bbs-dock-example", + "test-examples": "yarn dock-did-example && yarn did-resolver-example && yarn revocation-example && yarn vcdm-example && yarn standard-schemas-example && yarn schema-example && yarn schema-validation-example && yarn blob-example && yarn claim-deduction-example && yarn anchor-example && yarn bbs-dock-example && open-badges-example", "get-did": "npx babel-node scripts/get_did_doc.js", "upgrade_with_sudo": "npx babel-node scripts/runtime_upgrade_with_sudo.js", "onboard_with_sudo": "npx babel-node scripts/onboard_validator_with_sudo.js", diff --git a/src/modules/accumulator.js b/src/modules/accumulator.js index b2ec99f92..65c279104 100644 --- a/src/modules/accumulator.js +++ b/src/modules/accumulator.js @@ -109,11 +109,7 @@ export default class AccumulatorModule extends WithParamsAndPublicKeys { if (typ === AccumulatorType.VBPos || typ === AccumulatorType.VBUni) { return u8aToHex(accumulated); } else if (typ === AccumulatorType.KBUni) { - // Create a single Uint8Array and convert it to hex. The 2 are guaranteed to be of the same length - const merged = new Uint8Array(accumulated.mem.length + accumulated.nonMem.length); - merged.set(accumulated.mem); - merged.set(accumulated.nonMem, accumulated.mem.length); - return u8aToHex(merged); + return u8aToHex(accumulated.toBytes()); } else { throw new Error(`Unknown accumulator type ${typ}`); } @@ -129,11 +125,7 @@ export default class AccumulatorModule extends WithParamsAndPublicKeys { if (typ === AccumulatorType.VBPos || typ === AccumulatorType.VBUni) { return hexToU8a(accumulated); } else if (typ === AccumulatorType.KBUni) { - // Create 2 Uint8Array from this hex. The 2 are guaranteed to be of the same length - const merged = hexToU8a(accumulated); - const mem = merged.subarray(0, merged.length / 2); - const nonMem = merged.subarray(merged.length / 2); - return new KBUniversalAccumulatorValue(mem, nonMem); + return KBUniversalAccumulatorValue.fromBytes(hexToU8a(accumulated)); } else { throw new Error(`Unknown accumulator type ${typ}`); } diff --git a/tests/integration/anoncreds/accumulator.test.js b/tests/integration/anoncreds/accumulator.test.js index 6b604f5a9..980ad670c 100644 --- a/tests/integration/anoncreds/accumulator.test.js +++ b/tests/integration/anoncreds/accumulator.test.js @@ -17,7 +17,6 @@ import { FullNodeEndpoint, TestAccountURI, TestKeyringOpts, - DisableNewAccumulatorTests, } from '../../test-constants'; import { DidKeypair, @@ -43,8 +42,6 @@ describe('Accumulator Module', () => { const seed2 = randomAsHex(32); const seedAccum = randomAsHex(32); - const buildTest = DisableNewAccumulatorTests ? test.skip : test; - beforeAll(async () => { await dock.init({ keyring: TestKeyringOpts, @@ -286,37 +283,35 @@ describe('Accumulator Module', () => { ); expect(await chainModule.getAccumulator(id2, false)).toEqual(null); - if (!DisableNewAccumulatorTests) { - const id3 = randomAsHex(32); - const accumulated3 = randomAsHex(100); - await chainModule.addKBUniversalAccumulator( - id3, - accumulated3, - [did2, keyId], - did2, - pair2, - { didModule: dock.did }, - false, - ); + const id3 = randomAsHex(32); + const accumulated3 = randomAsHex(100); + await chainModule.addKBUniversalAccumulator( + id3, + accumulated3, + [did2, keyId], + did2, + pair2, + { didModule: dock.did }, + false, + ); - const accum3 = await chainModule.getAccumulator(id3, false); - expect(accum3.created > 0).toBe(true); - expect(accum3.lastModified > 0).toBe(true); - expect(accum3.created).toEqual(accum3.lastModified); - expect(accum3.type).toEqual('kb-universal'); - expect(accum3.accumulated).toEqual(accumulated3); - expect(accum3.keyRef).toEqual([typedHexDID(dock.api, did2), keyId]); - expect(accum3.publicKey).toBeUndefined(); + const accum3 = await chainModule.getAccumulator(id3, false); + expect(accum3.created > 0).toBe(true); + expect(accum3.lastModified > 0).toBe(true); + expect(accum3.created).toEqual(accum3.lastModified); + expect(accum3.type).toEqual('kb-universal'); + expect(accum3.accumulated).toEqual(accumulated3); + expect(accum3.keyRef).toEqual([typedHexDID(dock.api, did2), keyId]); + expect(accum3.publicKey).toBeUndefined(); - await chainModule.removeAccumulator( - id3, - did2, - pair2, - { didModule: dock.did }, - false, - ); - expect(await chainModule.getAccumulator(id3, false)).toEqual(null); - } + await chainModule.removeAccumulator( + id3, + did2, + pair2, + { didModule: dock.did }, + false, + ); + expect(await chainModule.getAccumulator(id3, false)).toEqual(null); } async function checkUpdate(keyId) { @@ -534,9 +529,7 @@ describe('Accumulator Module', () => { } await check(0); - if (!DisableNewAccumulatorTests) { - await check(1); - } + await check(1); } test('Can add and remove accumulator', async () => { @@ -620,11 +613,11 @@ describe('Accumulator Module', () => { expect(params3).toEqual(null); }, 50000); - buildTest('Can add and remove accumulator without public key', async () => { + test('Can add and remove accumulator without public key', async () => { await checkAddRemove(0); }, 50000); - buildTest('Update accumulator without public key', async () => { + test('Update accumulator without public key', async () => { await checkUpdate(0); }, 50000); diff --git a/tests/integration/anoncreds/derived-credentials.test.js b/tests/integration/anoncreds/derived-credentials.test.js index 66b555fb7..3382f9639 100644 --- a/tests/integration/anoncreds/derived-credentials.test.js +++ b/tests/integration/anoncreds/derived-credentials.test.js @@ -6,7 +6,7 @@ import { BoundCheckSnarkSetup, Accumulator, PositiveAccumulator, - dockAccumulatorParams, AccumulatorPublicKey, deepClone, + dockAccumulatorParams, AccumulatorPublicKey, Encoder, BDDT16MacSecretKey, MEM_CHECK_STR, KBUniversalAccumulator, MEM_CHECK_KV_STR, RevocationStatusProtocol, @@ -18,7 +18,6 @@ import { TestAccountURI, TestKeyringOpts, Schemes, - DisableNewAccumulatorTests, } from '../../test-constants'; import { createNewDockDID, DidKeypair } from '../../../src/utils/did'; import { getProofMatcherDoc, registerNewDIDUsingPair } from '../helpers'; @@ -33,6 +32,7 @@ import { DockResolver } from '../../../src/resolver'; import { createPresentation } from '../../create-presentation'; import AccumulatorModule, { AccumulatorType } from '../../../src/modules/accumulator'; import { getKeyedProofsFromVerifiedPresentation } from '../../../src/utils/vc/presentations'; +import { deepClone } from '../../../src/utils/common'; // TODO: move to fixtures const residentCardSchema = { @@ -259,27 +259,25 @@ describe.each(Schemes)('Derived Credentials', ({ posAccumWitness = await accumulator.membershipWitness(encodedMember, posAccumKeypair.secretKey, posAccumState); expect(accumulator.verifyMembershipWitness(encodedMember, posAccumWitness, posAccumKeypair.publicKey, params)).toEqual(true); - if (!DisableNewAccumulatorTests) { - const accumulator1 = PositiveAccumulator.initialize(params, posKvAccumKeypair.secretKey); - await accumulator1.addBatch(members, posKvAccumKeypair.secretKey, posKvAccumState); - // For KV accumulator, keyId is 0 - await writeAccumToChain(posKvAccumulatorId, 0, accumulator1); - posKvAccumWitness = await accumulator1.membershipWitness(encodedMember, posKvAccumKeypair.secretKey, posKvAccumState); - posKvAccumSecretKey = posKvAccumKeypair.secretKey; - - const accumulator2 = await KBUniversalAccumulator.initialize(members, params, uniAccumKeypair.secretKey, uniAccumState); - await accumulator2.add(encodedMember, uniAccumKeypair.secretKey, uniAccumState); - await writeAccumToChain(uniAccumulatorId, 2, accumulator2); - uniAccumWitness = await accumulator2.membershipWitness(encodedMember, uniAccumKeypair.secretKey, uniAccumState); - expect(accumulator2.verifyMembershipWitness(encodedMember, uniAccumWitness, uniAccumKeypair.publicKey, params)).toEqual(true); - - const accumulator3 = await KBUniversalAccumulator.initialize(members, params, uniKvAccumKeypair.secretKey, uniKvAccumState); - await accumulator3.add(encodedMember, uniKvAccumKeypair.secretKey, uniKvAccumState); - // For KV accumulator, keyId is 0 - await writeAccumToChain(uniKvAccumulatorId, 0, accumulator3); - uniKvAccumWitness = await accumulator3.membershipWitness(encodedMember, uniKvAccumKeypair.secretKey, uniKvAccumState); - uniKvAccumSecretKey = uniKvAccumKeypair.secretKey; - } + const accumulator1 = PositiveAccumulator.initialize(params, posKvAccumKeypair.secretKey); + await accumulator1.addBatch(members, posKvAccumKeypair.secretKey, posKvAccumState); + // For KV accumulator, keyId is 0 + await writeAccumToChain(posKvAccumulatorId, 0, accumulator1); + posKvAccumWitness = await accumulator1.membershipWitness(encodedMember, posKvAccumKeypair.secretKey, posKvAccumState); + posKvAccumSecretKey = posKvAccumKeypair.secretKey; + + const accumulator2 = await KBUniversalAccumulator.initialize(members, params, uniAccumKeypair.secretKey, uniAccumState); + await accumulator2.add(encodedMember, uniAccumKeypair.secretKey, uniAccumState); + await writeAccumToChain(uniAccumulatorId, 2, accumulator2); + uniAccumWitness = await accumulator2.membershipWitness(encodedMember, uniAccumKeypair.secretKey, uniAccumState); + expect(accumulator2.verifyMembershipWitness(encodedMember, uniAccumWitness, uniAccumKeypair.publicKey, params)).toEqual(true); + + const accumulator3 = await KBUniversalAccumulator.initialize(members, params, uniKvAccumKeypair.secretKey, uniKvAccumState); + await accumulator3.add(encodedMember, uniKvAccumKeypair.secretKey, uniKvAccumState); + // For KV accumulator, keyId is 0 + await writeAccumToChain(uniKvAccumulatorId, 0, accumulator3); + uniKvAccumWitness = await accumulator3.membershipWitness(encodedMember, uniKvAccumKeypair.secretKey, uniKvAccumState); + uniKvAccumSecretKey = uniKvAccumKeypair.secretKey; }, 30000); async function createAndVerifyPresentation(credentials, verifyOptions = {}, accumSecretKey = undefined) { @@ -394,8 +392,6 @@ describe.each(Schemes)('Derived Credentials', ({ return [presentationInstance, presentationOptions]; } - const buildTest = DisableNewAccumulatorTests ? test.skip : test; - test(`For ${Name}, holder creates a derived verifiable credential from a credential with selective disclosure`, async () => { const issuerKey = getKeyDoc(did1, keypair, keypair.type, keypair.id); const unsignedCred = { @@ -559,7 +555,7 @@ describe.each(Schemes)('Derived Credentials', ({ }); }); - buildTest(`For ${Name}, persist credential status using VB positive accumulator with keyed-verification when deriving`, async () => { + test(`For ${Name}, persist credential status using VB positive accumulator with keyed-verification when deriving`, async () => { // No public key exists const queriedAccum = await dock.accumulatorModule.getAccumulator(posKvAccumulatorId, false, false); @@ -594,7 +590,7 @@ describe.each(Schemes)('Derived Credentials', ({ }, posKvAccumSecretKey); }); - buildTest(`For ${Name}, persist credential status using KB universal accumulator when deriving`, async () => { + test(`For ${Name}, persist credential status using KB universal accumulator when deriving`, async () => { const queriedAccum = await dock.accumulatorModule.getAccumulator(uniAccumulatorId, false, true); const verifAccumulator = KBUniversalAccumulator.fromAccumulated(AccumulatorModule.accumulatedFromHex(queriedAccum.accumulated, AccumulatorType.KBUni)); @@ -623,7 +619,7 @@ describe.each(Schemes)('Derived Credentials', ({ expect(credentials[0].credentialStatus).toEqual({ ...credentialStatus, revocationId: undefined, // Because revocation id is never revealed - accumulated: `${b58.encode(accAsU8.mem)},${b58.encode(accAsU8.nonMem)}`, + accumulated: `${b58.encode(accAsU8.toBytes())}`, extra: {}, }); @@ -637,7 +633,7 @@ describe.each(Schemes)('Derived Credentials', ({ }); }); - buildTest(`For ${Name}, persist credential status using KB universal accumulator with keyed-verification when deriving`, async () => { + test(`For ${Name}, persist credential status using KB universal accumulator with keyed-verification when deriving`, async () => { // No public key exists const queriedAccum = await dock.accumulatorModule.getAccumulator(uniKvAccumulatorId, false, false); @@ -663,7 +659,7 @@ describe.each(Schemes)('Derived Credentials', ({ expect(credentials[0].credentialStatus).toEqual({ ...credentialStatus, revocationId: undefined, // Because revocation id is never revealed - accumulated: `${b58.encode(accAsU8.mem)},${b58.encode(accAsU8.nonMem)}`, + accumulated: `${b58.encode(accAsU8.toBytes())}`, extra: {}, }); diff --git a/tests/integration/did/did-key.test.js b/tests/integration/did/did-key.test.js index 61ea643f7..168910bd3 100644 --- a/tests/integration/did/did-key.test.js +++ b/tests/integration/did/did-key.test.js @@ -11,12 +11,9 @@ import { FullNodeEndpoint, TestKeyringOpts, TestAccountURI, - DisableDidKeyAndTrustRegistryTests, } from '../../test-constants'; -const buildTest = DisableDidKeyAndTrustRegistryTests ? describe.skip : describe; - -buildTest('Basic DID tests', () => { +describe('Basic DID tests', () => { const dock = new DockAPI(); // Generate a random DID diff --git a/tests/integration/trust-registry-module.test.js b/tests/integration/trust-registry-module.test.js index 85aca483f..403f87cef 100644 --- a/tests/integration/trust-registry-module.test.js +++ b/tests/integration/trust-registry-module.test.js @@ -8,7 +8,6 @@ import { FullNodeEndpoint, TestKeyringOpts, TestAccountURI, - DisableDidKeyAndTrustRegistryTests, } from '../test-constants'; import { @@ -18,9 +17,7 @@ import { } from '../../src/utils/did'; import { registerNewDIDUsingPair } from './helpers'; -const buildTest = DisableDidKeyAndTrustRegistryTests ? describe.skip : describe; - -buildTest('Trust Registry', () => { +describe('Trust Registry', () => { const dock = new DockAPI(); // Create a new convener DID, the DID will be registered on the network and own the trust registry diff --git a/tests/test-constants.js b/tests/test-constants.js index a11ff9d08..c6484500b 100644 --- a/tests/test-constants.js +++ b/tests/test-constants.js @@ -78,12 +78,6 @@ export const TestAccountCouncilMemberURI = fromEnv( export const MinGasPrice = fromEnv('MinGasPrice', DefaultMinGasPrice); export const MaxGas = fromEnv('MaxGas', DefaultMaxGas); export const TestSchemes = fromEnv('TestSchemes', DefaultTestSchemes); -export const DisableDidKeyAndTrustRegistryTests = boolEnv( - fromEnv('DisableDidKeyAndTrustRegistryTests', 'false'), -); -export const DisableNewAccumulatorTests = boolEnv( - fromEnv('DisableNewAccumulatorTests', 'false'), -); export const BBS = { Name: 'BBS',