Skip to content

Commit

Permalink
Update as per update in deps and unskip some tests for mainnet
Browse files Browse the repository at this point in the history
Signed-off-by: lovesh <[email protected]>
  • Loading branch information
lovesh committed May 13, 2024
1 parent d315490 commit c01f5c7
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 97 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/integration-tests-ipfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
mainnet:
runs-on: ubuntu-latest
env:
DisableDidKeyAndTrustRegistryTests: true
CONFIG_DOCK_NODE_IMAGE_TAG: 'mainnet'
steps:
- uses: actions/checkout@v2
Expand All @@ -40,7 +39,6 @@ jobs:
testnet:
runs-on: ubuntu-latest
env:
DisableDidKeyAndTrustRegistryTests: true
CONFIG_DOCK_NODE_IMAGE_TAG: 'testnet'
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +29,6 @@ jobs:
testnet:
runs-on: ubuntu-latest
env:
DisableNewAccumulatorTests: true
CONFIG_DOCK_NODE_IMAGE_TAG: 'testnet'
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 2 additions & 10 deletions src/modules/accumulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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}`);
}
Expand Down
67 changes: 30 additions & 37 deletions tests/integration/anoncreds/accumulator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
FullNodeEndpoint,
TestAccountURI,
TestKeyringOpts,
DisableNewAccumulatorTests,
} from '../../test-constants';
import {
DidKeypair,
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);

Expand Down
56 changes: 26 additions & 30 deletions tests/integration/anoncreds/derived-credentials.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
BoundCheckSnarkSetup,
Accumulator,
PositiveAccumulator,
dockAccumulatorParams, AccumulatorPublicKey, deepClone,
dockAccumulatorParams, AccumulatorPublicKey,
Encoder, BDDT16MacSecretKey, MEM_CHECK_STR, KBUniversalAccumulator,
MEM_CHECK_KV_STR,
RevocationStatusProtocol,
Expand All @@ -18,7 +18,6 @@ import {
TestAccountURI,
TestKeyringOpts,
Schemes,
DisableNewAccumulatorTests,
} from '../../test-constants';
import { createNewDockDID, DidKeypair } from '../../../src/utils/did';
import { getProofMatcherDoc, registerNewDIDUsingPair } from '../helpers';
Expand All @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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: {},
});

Expand All @@ -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);

Expand All @@ -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: {},
});

Expand Down
5 changes: 1 addition & 4 deletions tests/integration/did/did-key.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/trust-registry-module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
FullNodeEndpoint,
TestKeyringOpts,
TestAccountURI,
DisableDidKeyAndTrustRegistryTests,
} from '../test-constants';

import {
Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions tests/test-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c01f5c7

Please sign in to comment.