-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ref-imp): fix null delta throwing unexpected error (#957)
- Loading branch information
1 parent
bc8e8d4
commit 26bc857
Showing
6 changed files
with
90 additions
and
6 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 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
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
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,72 @@ | ||
import Delta from '../../lib/core/versions/latest/Delta'; | ||
import ErrorCode from '../../lib/core/versions/latest/ErrorCode'; | ||
import JasmineSidetreeErrorValidator from '../JasmineSidetreeErrorValidator'; | ||
|
||
function generateLongString (length: number): string { | ||
let result = ''; | ||
for (let i = 0; i < length; i++) { | ||
result = result + 'a'; | ||
} | ||
return result; | ||
} | ||
|
||
describe('Delta', () => { | ||
describe('validateEncodedDeltaSize', () => { | ||
it('should throw sidetree if encoded size exceeds max limit', () => { | ||
const mockEncodedDelta = generateLongString(2000); | ||
JasmineSidetreeErrorValidator.expectSidetreeErrorToBeThrown( | ||
() => { Delta.validateEncodedDeltaSize(mockEncodedDelta); }, | ||
ErrorCode.DeltaExceedsMaximumSize | ||
); | ||
}); | ||
|
||
it('should not throw if encoded size does not exceed max limit', () => { | ||
const mockEncodedDelta = generateLongString(1); | ||
try { | ||
Delta.validateEncodedDeltaSize(mockEncodedDelta); | ||
} catch (e) { | ||
fail(`Expected no error but got ${e}`); | ||
} | ||
}); | ||
}); | ||
|
||
describe('validateDelta', () => { | ||
it('should throw sidetree error if delta size exceeds max limit', () => { | ||
const mockDelta = { | ||
someKey: generateLongString(2000) | ||
}; | ||
JasmineSidetreeErrorValidator.expectSidetreeErrorToBeThrown( | ||
() => { Delta.validateDelta(mockDelta); }, | ||
ErrorCode.DeltaExceedsMaximumSize | ||
); | ||
}); | ||
|
||
it('should throw sidetree error if delta is null', () => { | ||
const mockDelta = null; | ||
JasmineSidetreeErrorValidator.expectSidetreeErrorToBeThrown( | ||
() => { Delta.validateDelta(mockDelta); }, | ||
ErrorCode.DeltaIsNullOrUndefined | ||
); | ||
}); | ||
|
||
it('should throw sidetree error if delta is undefined', () => { | ||
const mockDelta = undefined; | ||
JasmineSidetreeErrorValidator.expectSidetreeErrorToBeThrown( | ||
() => { Delta.validateDelta(mockDelta); }, | ||
ErrorCode.DeltaIsNullOrUndefined | ||
); | ||
}); | ||
|
||
it('should not throw if delta size is valid', () => { | ||
const mockDelta = { | ||
someKey: 'some value' | ||
}; | ||
|
||
try { | ||
Delta.validateDelta(mockDelta); | ||
} catch (e) { | ||
fail(`Expected no error but got ${e}`); | ||
} | ||
}); | ||
}); | ||
}); |