Skip to content

Commit

Permalink
Test and fix for delayed confirm on hyperswarm
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Dec 17, 2024
1 parent 55eba3e commit 352e365
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services/mediators/hyperswarm/src/hyperswarm-mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ async function flushQueue() {

await gatekeeper.clearQueue(REGISTRY, batch);
await relayMsg(msg);
await importBatch(batch);
await mergeBatch(batch);
}
}

Expand Down
58 changes: 58 additions & 0 deletions tests/hypr-confirm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as keymaster from '@mdip/keymaster/lib';
import * as wallet from '@mdip/keymaster/db/json';
import * as gatekeeper from '@mdip/gatekeeper/sdk';
import * as cipher from '@mdip/cipher/node';

async function runTest() {
const expires = new Date();
expires.setMinutes(expires.getMinutes() + 1);
const testOptions = { registry: 'hyperswarm', validUntil: expires.toISOString() };

const alice = await keymaster.createId('Alice', testOptions);
console.log(`alice: ${alice}`);

const asset = await keymaster.createAsset({ version: 1 }, testOptions);
const doc1 = await keymaster.resolveDID(asset);
console.log(JSON.stringify(doc1, null, 4));

const ok = await keymaster.updateAsset(asset, { version: 2 });

Check warning on line 18 in tests/hypr-confirm.js

View workflow job for this annotation

GitHub Actions / build-and-test

'ok' is assigned a value but never used
let doc2 = await keymaster.resolveDID(asset);
console.log(JSON.stringify(doc2, null, 4));

while (doc2.didDocumentMetadata.confirmed == false) {

Check warning on line 22 in tests/hypr-confirm.js

View workflow job for this annotation

GitHub Actions / build-and-test

Expected '===' and instead saw '=='

Check failure on line 22 in tests/hypr-confirm.js

View workflow job for this annotation

GitHub Actions / build-and-test

Refactor the code to avoid using this boolean literal
// wait for 1 second before checking again
await new Promise(resolve => setTimeout(resolve, 1000));

doc2 = await keymaster.resolveDID(asset);
console.log(JSON.stringify(doc2, null, 4));
}
}

async function main() {
await gatekeeper.start({
url: 'http://localhost:4224',
waitUntilReady: true,
});

await keymaster.start({
gatekeeper,
wallet,
cipher,
});

const backup = await keymaster.loadWallet();
await keymaster.newWallet(null, true);

try {
await runTest();
}
catch (error) {
console.log(error);
}

await keymaster.saveWallet(backup);
await keymaster.stop();
process.exit();
}

main();

0 comments on commit 352e365

Please sign in to comment.