Skip to content

Commit

Permalink
Updated tests wrt changes in vault generation and parameter validations
Browse files Browse the repository at this point in the history
  • Loading branch information
SDargarh committed Aug 28, 2023
1 parent 5e8fbea commit c84b6dd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 38 deletions.
73 changes: 42 additions & 31 deletions src/lib/test/keyring.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ beforeAll(async() => {

result = await vault.generateVault(bufView,pin,phrase)
vaultAddress=result.response
await vault.getAccounts(bufView);
await vault.getAccounts();

});
describe('exportMnemonic' , ()=>{
Expand Down Expand Up @@ -115,14 +115,14 @@ describe('addAccount' , ()=>{

})

test('addAccount/empty encryption key' , async()=>{
test('addAccount/empty encryption key' , async()=>{
try{
let result = await vault.addAccount(null,pin)
}
catch(e){
expect(e.message).toBe("Cannot read properties of undefined (reading 'length')")
expect(e.message).toBe("Incorrect Encryption Key or vault string")
}

})

test('addAccount/empty pin' , async()=>{
Expand Down Expand Up @@ -892,6 +892,18 @@ describe('changePin',()=>{

})

test('changePin/wrong currentpin' , async()=>{
try{
let result = await vault.changePin(111111,pin,bufView)

}
catch(e){
expect(e).toBe('Wrong pin type, format or length')
}


})

test('changePin/invalid currentpin' , async()=>{
try{
let result = await vault.changePin('aefe',pin,bufView)
Expand Down Expand Up @@ -942,19 +954,23 @@ describe('changePin',()=>{
})

test('changePin/empty encryption key' , async()=>{

let result = await vault.changePin(pin,pin,null)
expect(result).toHaveProperty('response')



try{
let result = await vault.changePin(pin,pin,null)
}
catch(e){
expect(e.message).toBe("Incorrect Encryption Key or vault string")
}


})

test('changePin/invalid encryption key' , async()=>{

try{
let result = await vault.changePin(pin,pin,'efefe')
expect(result).toHaveProperty('response')
}
catch(e){
expect(e.message).toBe("Incorrect Encryption Key or vault string")
}



Expand Down Expand Up @@ -996,17 +1012,23 @@ describe('deleteAccount',()=>{

})
test('deleteAccount/empty encryption key' , async()=>{

try{
let result = await vault.deleteAccount(null,accAddress,pin)
expect(result.error).toBe('This address is not present in the vault')
}
catch(e){
expect(e.message).toBe("Incorrect Encryption Key or vault string")
}


})

test('deleteAccount/invalid encryption key' , async()=>{

try{
let result = await vault.deleteAccount(null,accAddress,pin)
expect(result.error).toBe('This address is not present in the vault')
}
catch(e){
expect(e.message).toBe("Incorrect Encryption Key or vault string")
}


})
Expand Down Expand Up @@ -1066,22 +1088,11 @@ describe('deleteAccount',()=>{
describe('getAccounts',()=>{
test('getAccounts/valid' , async()=>{
await vault.restoreKeyringState(vaultAddress,pin,bufView)
let result = await vault.getAccounts(bufView)
let result = await vault.getAccounts()
expect(result).toHaveProperty('response')

})
test('getAccounts/empty encryption key ' , async()=>{

let result = await vault.getAccounts(null)
expect(result.error).toBe('Incorrect Encryption Key or vault string')

})
test('getAccounts/invalid encryption key ' , async()=>{

let result = await vault.getAccounts("aefefe")
expect(result.error).toBe('Incorrect Encryption Key or vault string')

})

})


Expand Down Expand Up @@ -1142,7 +1153,7 @@ describe('signTransaction',()=>{

}
catch(e){
expect(e.message).toBe("No keyring found for the requested account.")
expect(e.message).toBe("Cannot read properties of undefined (reading 'toLowerCase')")

}

Expand Down Expand Up @@ -1173,7 +1184,7 @@ describe('signTransaction',()=>{

}
catch(e){
expect(e.message).toBe("No keyring found for the requested account.")
expect(e.message).toBe("Cannot read properties of undefined (reading 'toLowerCase')")

}

Expand Down
14 changes: 7 additions & 7 deletions src/lib/test/vault.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('getSupportedChains' , ()=>{

test('getSupportedChains' , async()=>{

let result = await new Vault().getSupportedChains()
let result = await new Vault({}).getSupportedChains()
expect({
evmChains: { ethereum: 'ETH', bsc: 'BSC', polygon: 'MATIC', optimism: 'OP', arbitrum: 'ARB', mantle: 'MNT', velas: 'VLX' },
nonEvmChains: { bitcoin: 'BTC' }
Expand All @@ -28,7 +28,7 @@ describe('generateMnemonic' , ()=>{

test('generateMnemonic' , async()=>{

let result = await new Vault().generateMnemonic()
let result = await new Vault({}).generateMnemonic()
Mnemonic=result
expect(typeof(result)).toBe("string")

Expand Down Expand Up @@ -58,22 +58,22 @@ describe("generateVault",()=>{
const buf = new ArrayBuffer(32);
const bufView = new Uint8Array(buf);

let result = await new Vault().generateVault(bufView,null,Mnemonic)
let result = await new Vault({}).generateVault(bufView,null,Mnemonic)
expect(result.error).toBe("Wrong pin type, format or length")

})

test('generateVault/empty encrption key' , async()=>{
const buf = new ArrayBuffer(32);
const bufView = new Uint8Array(buf);
let result = await new Vault().generateVault(null,1111,Mnemonic)
let result = await new Vault({}).generateVault(null,1111,Mnemonic)
expect(result.error).toBe('Wrong pin type, format or length')

})
test('generateVault/empty encrption key' , async()=>{
const buf = new ArrayBuffer(32);
const bufView = new Uint8Array(buf);
let result = await new Vault().generateVault(null,111111,Mnemonic)
let result = await new Vault({}).generateVault(null,111111,Mnemonic)
expect(result.error).toBe('Please enter both encryptionKey and pin')

})
Expand All @@ -82,7 +82,7 @@ describe("generateVault",()=>{
const buf = new ArrayBuffer(32);
const bufView = new Uint8Array(buf);
try{
let result = await new Vault().generateVault(bufView,1111,null)
let result = await new Vault({}).generateVault(bufView,1111,null)
}
catch(e){
expect(e.message).toBe('Seed phrase is invalid.')
Expand All @@ -95,7 +95,7 @@ describe("generateVault",()=>{
const buf = new ArrayBuffer(32);
const bufView = new Uint8Array(buf);

let result = await new Vault().generateVault(null,null,null)
let result = await new Vault({}).generateVault(null,null,null)
expect(result.error).toBe("Wrong pin type, format or length")


Expand Down

1 comment on commit c84b6dd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report (69%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files68607069.21 
chains100100100100 
   index.js100100100100 
config100100100100 
   index.js100100100100 
constants100100100100 
   index.js100100100100 
constants/responses100100100100 
   index.js100100100100 
lib64.8660.2866.6666.23 
   keyring.js62.0859.6263.6363.5445, 131, 137–149, 169, 177–185, 194–196, 239–337, 356, 364–365, 373–383, 394, 414–425, 441–444, 476–480, 491–500, 534, 557–613, 645, 676, 684–700, 726–728, 759–767, 790–794, 813, 851
   vault.js84.7467.858084.7419, 26, 41–44, 56, 65–68
utils78.435681.2579.16 
   helper.js78.435681.2579.1610–17, 51–52, 68, 80, 92, 105–107, 123–125, 158–162, 203–205

Please sign in to comment.