From dd46eaee2a81694d3f0e601da32650c672e8f70d Mon Sep 17 00:00:00 2001 From: David McFadzean Date: Wed, 20 Mar 2024 13:53:05 -0400 Subject: [PATCH] Fix unit tests --- data/wallet.bak | 75 ++++++++++++++++++++++++++++++++++++++++++++++ gatekeeper.test.js | 39 +----------------------- keymaster.js | 2 +- keymaster.test.js | 16 +++++----- 4 files changed, 85 insertions(+), 47 deletions(-) create mode 100644 data/wallet.bak diff --git a/data/wallet.bak b/data/wallet.bak new file mode 100644 index 00000000..79227952 --- /dev/null +++ b/data/wallet.bak @@ -0,0 +1,75 @@ +{ + "seed": { + "mnemonic": "uUl9dUCmlRFDFRUhv7B2YWguG7jY-CaKRYOKj_98RWf10754kRjWby7As4xrCKbsuGV2nX-K1QeAOus7067qeIxFo35gtpdHiOitVWnxn0mHCtiH0PDpsXcKPFwTeI9jq5UEmevLF-B5yn7F2Qz8uXYQ0s-N", + "hdkey": { + "xpriv": "xprv9s21ZrQH143K38fwaCm1SeWdphFLhbUKbnwxdA1oEPsgavcn1nt2vLeRvkkfPy9RoQxCZXfmYNyP977QmpDR3GFK433bgBXSmaPRTBGPoyX", + "xpub": "xpub661MyMwAqRbcFckQgEJ1onTNNj5q74CAy1sZRYRQnjQfTiwvZLCHU8xun3UCVwkGc52yF9bZZbPXaMEpkKjRVuqLRTbCorkxfRmY4WXStK5" + } + }, + "counter": 8, + "ids": { + "David": { + "did": "did:mdip:z3v8AuabNBnymLADSwWpDJPdEhvt2kS5v7UXypjzPnkqfdnW6ri", + "account": 1, + "index": 0, + "owned": [ + "did:mdip:z3v8AuaYMHafTVzrykyRyXjWsTuByAYon8pA7W5iZZtXYBqkMV7", + "did:mdip:z3v8AuaYM272pA9GDrnawbjLmL65Hxc131e9Vt1EqteRHXZkk1J", + "did:mdip:z3v8AuadYk2AHM3oQdwj2d4J5VeG8wzShDkDeHJVXjnXS3Zg2qd", + "did:mdip:z3v8AuagpiowaGV48THePjz41zgqwdVp8x4ThXD34bL7NtUtrzU", + "did:mdip:z3v8AuaggWbYhN2oqwVQCYTeT3whCZyovrXtyPqC4uwwtB2GhN7", + "did:mdip:z3v8AuaYB9P3wMWFQ3nCEZsmEfWfZ9V6Gt1dbmguZfSkPieaEEH", + "did:mdip:z3v8Auaaj52QQxEDrW93xhUdisRxURN8soSrkHtF3P8iXiqWWj8", + "did:mdip:z3v8AuaZu9GYACZvkBBVfTUFPf8Nwe6VjC7eZEiKpb3JBTbSPmg", + "did:mdip:z3v8AuahQDpnHEPkHgbhKabjSbSH8Vi8fKhahCxDqZVRGhaS962" + ], + "held": [ + "did:mdip:z3v8AuaboMc8LJW7k1Rn23qjaJMoH6vMrfnU4ouprsSayy9QE4f" + ] + }, + "Alpha": { + "did": "did:mdip:z3v8AuackpFBm4kgetF7qYk88HvWthGY9VewyKqYDV5xogMNWVd", + "account": 1, + "index": 6, + "owned": [ + "did:mdip:z3v8AuaboMc8LJW7k1Rn23qjaJMoH6vMrfnU4ouprsSayy9QE4f", + "did:mdip:z3v8AuabiAPcUDB9zDc9HB8reUXfR4BorbbuDSCZP616NEYD6FN" + ] + }, + "Bubba": { + "did": "did:mdip:z3v8Auafr3xUZnciBuRiwpyifuot342JwBw4weCvvAohSncYx1t", + "account": 4, + "index": 2, + "owned": [ + "did:mdip:z3v8AuabyKpKraCMjveuxGbPeDGbg394ZvL4sa4v4HsDewMEGAH", + "did:mdip:z3v8AuaeJkyqtUZbK84rD18TcWycKHSsKoXLEk7Gvb6bTUsJ7LE", + "did:mdip:z3v8AuaeGum7MN7rDCUMPcC19DFwPNPMs233vQRHxD8anXEc4qG", + "did:mdip:z3v8Auaf8QrrFEaGxK2apUwBk9MbntxWgyqfXMHiQ9PV6CTr8kt", + "did:mdip:z3v8AuacTHXEtMfaNdkP2Y9P1YeVUeAQPTLhdCFUiPRskZc1jpi", + "did:mdip:z3v8AuababPKv4HGPpv9UYyHQZu5TnCYyR2H5DdALwb2aG29Wga", + "did:mdip:z3v8AuaTdLaYU9Apvyedk4XNwaFGU8voHtFGfijEjPsCtxtHBXL", + "did:mdip:z3v8AuagpnR5qtVgXp5FfwL5xtP1i7udRWoHVRN4xRJxbBop9sc", + "did:mdip:z3v8Auah2jBurFYwJUeDYgMsfdznNPxFytuLM8VnuEGsq5uzBhm", + "did:mdip:z3v8AuagKPzo4JzQR9HmTgL7k4tkJrnpnmNGLJmcPWe83JHmEnm", + "did:mdip:z3v8AuagoYAu9KSs3Uzmj2bSwocdydBJe7WV4DYFvXnjEokcVA3", + "did:mdip:z3v8AuaXRBuGV3cpXKghCixa1UuWvhz7JpXffqYR9M9jwMaD199", + "did:mdip:z3v8AuabPSrC1SxF3UC5X8WEzn3ZZr1T9pk8vP5sHczjUfQCn55" + ] + } + }, + "current": "Bubba", + "names": { + "social": "did:mdip:z3v8AuaYMHafTVzrykyRyXjWsTuByAYon8pA7W5iZZtXYBqkMV7", + "Alex": "did:mdip:z3v8AuajuYULXU4mxx3jWTaMFtiNNncLAJew3j85acdkr9P4XaW", + "Christian": "did:mdip:z3v8AuacJqNkwUrSRDcbvXWNWw3GPLksq2iGzC4EPmSBc7FuxGN", + "Vigas": "did:mdip:z3v8AuafCzChd82dqhgUW8v3gtQXGQcAUBjjmrrgoGE5h1LuhUA", + "twitter": "did:mdip:z3v8AuaboMc8LJW7k1Rn23qjaJMoH6vMrfnU4ouprsSayy9QE4f", + "me": "did:mdip:z3v8AuabNBnymLADSwWpDJPdEhvt2kS5v7UXypjzPnkqfdnW6ri", + "flaxscrip": "did:mdip:z3v8AuaeNsiAhhDjkDyHCVrwAo73NQsnTzX2UoziGPaegt5SHPR", + "email": "did:mdip:z3v8Auaaj52QQxEDrW93xhUdisRxURN8soSrkHtF3P8iXiqWWj8", + "ch1": "did:mdip:z3v8AuacTHXEtMfaNdkP2Y9P1YeVUeAQPTLhdCFUiPRskZc1jpi", + "ch2": "did:mdip:z3v8AuagKPzo4JzQR9HmTgL7k4tkJrnpnmNGLJmcPWe83JHmEnm", + "ch3": "did:mdip:z3v8AuabiAPcUDB9zDc9HB8reUXfR4BorbbuDSCZP616NEYD6FN", + "rsp3": "did:mdip:z3v8AuahQDpnHEPkHgbhKabjSbSH8Vi8fKhahCxDqZVRGhaS962" + } +} \ No newline at end of file diff --git a/gatekeeper.test.js b/gatekeeper.test.js index 4ab878f9..15214e0a 100644 --- a/gatekeeper.test.js +++ b/gatekeeper.test.js @@ -109,7 +109,7 @@ async function createAssetTxn(agent, keypair) { mdip: { version: 1, type: "asset", - registry: "BTC", + registry: "hyperswarm", }, controller: agent, data: "mockData", @@ -147,43 +147,6 @@ describe('createDID', () => { expect(did.startsWith('did:mdip:')); }); - it('should create DID for peerbit registry', async () => { - mockFs({}); - - const keypair = cipher.generateRandomJwk(); - const agentTxn = await createAgentTxn(keypair, 1, 'peerbit'); - - const did = await gatekeeper.createDID(agentTxn); - - expect(did.length).toBe(60); - expect(did.startsWith('did:mdip:')); - }); - - - it('should create DID for BTC registry', async () => { - mockFs({}); - - const keypair = cipher.generateRandomJwk(); - const agentTxn = await createAgentTxn(keypair, 1, 'BTC'); - - const did = await gatekeeper.createDID(agentTxn); - - expect(did.length).toBe(60); - expect(did.startsWith('did:mdip:')); - }); - - it('should create DID for tBTC registry', async () => { - mockFs({}); - - const keypair = cipher.generateRandomJwk(); - const agentTxn = await createAgentTxn(keypair, 1, 'tBTC'); - - const did = await gatekeeper.createDID(agentTxn); - - expect(did.length).toBe(60); - expect(did.startsWith('did:mdip:')); - }); - it('should create DID for local registry', async () => { mockFs({}); diff --git a/keymaster.js b/keymaster.js index 346bf7be..3de4f717 100644 --- a/keymaster.js +++ b/keymaster.js @@ -67,7 +67,7 @@ export function loadWallet() { return newWallet(); } -export async function backupWallet(registry = 'BTC') { +export async function backupWallet(registry = defaultRegistry) { const wallet = loadWallet(); const keypair = hdKeyPair(); const msg = JSON.stringify(wallet); diff --git a/keymaster.test.js b/keymaster.test.js index 5a9760ed..0d4f1790 100644 --- a/keymaster.test.js +++ b/keymaster.test.js @@ -1244,10 +1244,10 @@ describe('verifyResponse', () => { it('should demonstrate full workflow', async () => { mockFs({}); - const alice = await keymaster.createId('Alice', 'BTC'); - const bob = await keymaster.createId('Bob', 'tBTC'); - const carol = await keymaster.createId('Carol', 'peerbit'); - const victor = await keymaster.createId('Victor', 'peerbit'); + const alice = await keymaster.createId('Alice'); + const bob = await keymaster.createId('Bob'); + const carol = await keymaster.createId('Carol'); + const victor = await keymaster.createId('Victor'); keymaster.useId('Alice'); @@ -1257,8 +1257,8 @@ describe('verifyResponse', () => { const bc1 = await keymaster.bindCredential(credential1, carol); const bc2 = await keymaster.bindCredential(credential2, carol); - const vc1 = await keymaster.attestCredential(bc1, 'BTC'); - const vc2 = await keymaster.attestCredential(bc2, 'BTC'); + const vc1 = await keymaster.attestCredential(bc1); + const vc2 = await keymaster.attestCredential(bc2); keymaster.useId('Bob'); @@ -1268,8 +1268,8 @@ describe('verifyResponse', () => { const bc3 = await keymaster.bindCredential(credential3, carol); const bc4 = await keymaster.bindCredential(credential4, carol); - const vc3 = await keymaster.attestCredential(bc3, 'tBTC'); - const vc4 = await keymaster.attestCredential(bc4, 'tBTC'); + const vc3 = await keymaster.attestCredential(bc3); + const vc4 = await keymaster.attestCredential(bc4); keymaster.useId('Carol');