generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
should fix bug in dcx identity vault
- Loading branch information
Bnonni
committed
Aug 26, 2024
1 parent
f089ebb
commit 0365c69
Showing
6 changed files
with
163 additions
and
286 deletions.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,40 +1,116 @@ | ||
import { LevelStore, MemoryStore } from '@web5/common'; | ||
import { expect } from 'chai'; | ||
import { DcxIdentityVault, FileSystem } from '../src/index.js'; | ||
import { DcxIdentityVault, Mnemonic, FileSystem } from '../src/index.js'; | ||
import { LevelStore, MemoryStore } from '@web5/common'; | ||
|
||
type DxcxIdentityVaultStatus = { initialized: boolean; lastBackup: string | null; lastRestore: string | null }; | ||
|
||
describe('DcxIdentityVault class', () => { | ||
const location = '__TEST_DATA__/DCX_COMMON/AGENT/DATASTORE'; | ||
process.env.NODE_ENV = 'test'; | ||
|
||
describe('DcxIdentityVault', () => { | ||
const location = '__TEST_DATA__/DCX/AGENT/VAULT_STORE'; | ||
const dwnEndpoints = ['http://localhost:3000']; | ||
let recoveryPhrase = Mnemonic.createRecoveryPhrase(); | ||
let password = Mnemonic.createPassword(); | ||
let vaultStatus: DxcxIdentityVaultStatus; | ||
let returnedRecoveryPhrase: string; | ||
|
||
afterEach(async () => { | ||
await FileSystem.rm('__TEST_DATA__', { recursive: true, force: true }); | ||
}); | ||
|
||
describe('takes two constructor arguments', () => { | ||
it('should initialize successfully with default IdentityVaultParams', () => { | ||
const defaultVault = new DcxIdentityVault(); | ||
describe(`defaultVault = new DcxIdentityVault({ location: ${location} })`, () => { | ||
recoveryPhrase = Mnemonic.createRecoveryPhrase(); | ||
password = Mnemonic.createPassword(); | ||
const defaultVault = new DcxIdentityVault({ location }); | ||
|
||
it('should be instanceof DcxIdentityVault', () => { | ||
expect(defaultVault).to.be.instanceof(DcxIdentityVault); | ||
expect(defaultVault).to.have.property('store'); | ||
expect(defaultVault).to.have.property('keyDerivationWorkFactor'); | ||
expect(defaultVault).to.have.property('contentEncryptionKey'); | ||
}); | ||
|
||
it('should initialize successfully with default IdentityVaultParams', () => { | ||
const levelVault = new DcxIdentityVault({ store: new MemoryStore<string, string>() }); | ||
expect(levelVault).to.be.instanceof(DcxIdentityVault); | ||
expect(levelVault).to.have.property('store'); | ||
expect(levelVault).to.have.property('keyDerivationWorkFactor'); | ||
expect(levelVault).to.have.property('contentEncryptionKey'); | ||
it('should have property "store" as instanceof LevelStore', () => { | ||
expect(defaultVault).to.have.property('store').that.is.instanceof(LevelStore); | ||
}); | ||
|
||
it('should have property "keyDerivationWorkFactor" as number equal to 210_000', async () => { | ||
expect(defaultVault).to.have.property('keyDerivationWorkFactor').that.is.a('number').and.equals(210_000); | ||
}); | ||
|
||
describe('await defaultVault.getStatus()', () => { | ||
it('should have status of initialized=false lastBackup=null lastRestore=null', async () => { | ||
vaultStatus = await defaultVault.getStatus(); | ||
expect(vaultStatus.initialized).to.be.false; | ||
expect(vaultStatus.lastBackup).to.be.null; | ||
expect(vaultStatus.lastRestore).to.be.null; | ||
}); | ||
}); | ||
|
||
describe('await defaultVault.initialize({ password, recoveryPhrase, dwnEndpoints })', () => { | ||
it('should initialize successfully with params { password, recoveryPhrase, dwnEndpoints }', async () => { | ||
returnedRecoveryPhrase = await defaultVault.initialize({ password, recoveryPhrase, dwnEndpoints }); | ||
}); | ||
|
||
it('should return a matching recoveryPhrase', async () => { | ||
expect(recoveryPhrase).to.equal(returnedRecoveryPhrase); | ||
}); | ||
|
||
it('should have property "contentEncryptionKey" after initialization', async () => { | ||
expect(defaultVault).to.have.property('contentEncryptionKey'); | ||
}); | ||
|
||
it('should have updated status of initialized=true lastBackup=null lastRestore=null', async () => { | ||
vaultStatus = await defaultVault.getStatus(); | ||
expect(vaultStatus.initialized).to.be.true; | ||
expect(vaultStatus.lastBackup).to.be.null; | ||
expect(vaultStatus.lastRestore).to.be.null; | ||
}); | ||
}); | ||
}); | ||
|
||
describe(`customVault = new DcxIdentityVault({ store: new MemoryStore(), location: ${location} })`, () => { | ||
recoveryPhrase = Mnemonic.createRecoveryPhrase(); | ||
password = Mnemonic.createPassword(); | ||
const customVault = new DcxIdentityVault({ store: new MemoryStore(), location }); | ||
|
||
it('should be instanceof DcxIdentityVault', () => { | ||
expect(customVault).to.be.instanceof(DcxIdentityVault); | ||
}); | ||
|
||
it('should have property "store" as instanceof MemoryStore', () => { | ||
expect(customVault).to.have.property('store').that.is.instanceof(MemoryStore); | ||
}); | ||
|
||
it('should have property "keyDerivationWorkFactor" as number equal to 210_000', async () => { | ||
expect(customVault).to.have.property('keyDerivationWorkFactor').that.is.a('number').and.equals(210_000); | ||
}); | ||
|
||
it('should initialize successfully with custom IdentityVaultParams', () => { | ||
const customAgentVault = new DcxIdentityVault({ | ||
keyDerivationWorkFactor : 420_000, | ||
store : new LevelStore({ location }), | ||
describe('await customVault.getStatus()', () => { | ||
it('should have status of initialized=false lastBackup=null lastRestore=null', async () => { | ||
vaultStatus = await customVault.getStatus(); | ||
expect(vaultStatus.initialized).to.be.false; | ||
expect(vaultStatus.lastBackup).to.be.null; | ||
expect(vaultStatus.lastRestore).to.be.null; | ||
}); | ||
}); | ||
|
||
describe('await customVault.initialize({ password, recoveryPhrase, dwnEndpoints })', () => { | ||
it('should initialize successfully with params { password, recoveryPhrase, dwnEndpoints }', async () => { | ||
returnedRecoveryPhrase = await customVault.initialize({ password, recoveryPhrase, dwnEndpoints }); | ||
}); | ||
|
||
it('should return a matching recoveryPhrase', () => { | ||
expect(recoveryPhrase).to.equal(returnedRecoveryPhrase); | ||
}); | ||
|
||
it('should have property "contentEncryptionKey" after initialization', () => { | ||
expect(customVault).to.have.property('contentEncryptionKey'); | ||
}); | ||
|
||
it('should have updated status of initialized=true lastBackup=null lastRestore=null', async () => { | ||
vaultStatus = await customVault.getStatus(); | ||
expect(vaultStatus.initialized).to.be.true; | ||
expect(vaultStatus.lastBackup).to.be.null; | ||
expect(vaultStatus.lastRestore).to.be.null; | ||
}); | ||
expect(customAgentVault).to.be.instanceof(DcxIdentityVault); | ||
expect(customAgentVault).to.have.property('store'); | ||
expect(customAgentVault).to.have.property('keyDerivationWorkFactor'); | ||
expect(customAgentVault).to.have.property('contentEncryptionKey'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.