-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and fix for delayed confirm on hyperswarm
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
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 GitHub Actions / build-and-test
|
||
// 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(); |