-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): add tests for blockheight and sortkey, break tests into…
… domain centric files
- Loading branch information
1 parent
ecb279d
commit f094f15
Showing
12 changed files
with
374 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
*/ | ||
export * from './arweave.js'; | ||
export * from './http-client.js'; | ||
export * from './smartweave/index.js'; |
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,13 @@ | ||
import { SmartWeaveSortKey } from './evaluation.js'; | ||
|
||
describe(`Smartweave eval utils`, () => { | ||
it(`should throw on a bad sort key`, async () => { | ||
const sortKey = '123,456,abc'; | ||
const error = await (async () => new SmartWeaveSortKey(sortKey))().catch( | ||
(e) => e, | ||
); | ||
|
||
expect(error).toBeInstanceOf(Error); | ||
expect(error.message).toContain(sortKey); | ||
}); | ||
}); |
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,49 @@ | ||
/** | ||
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import { SORT_KEY_REGEX } from '../../constants.js'; | ||
|
||
export class SmartWeaveSortKey { | ||
private _sortKey: string; | ||
constructor(sortKey: string) { | ||
if (!SmartWeaveSortKey.validate(sortKey)) { | ||
throw new Error(`Invalid sort key: ${sortKey}`); | ||
} | ||
|
||
this._sortKey = sortKey; | ||
} | ||
|
||
static validate(sortKey: string): boolean { | ||
return SORT_KEY_REGEX.test(sortKey); | ||
} | ||
|
||
toString(): string { | ||
return this._sortKey; | ||
} | ||
|
||
parts(): string[] { | ||
return this._sortKey.split(','); | ||
} | ||
blockHeight(): number { | ||
return parseInt(this.parts()[0]); | ||
} | ||
timestamp(): number { | ||
return parseInt(this.parts()[1]); | ||
} | ||
hash(): string { | ||
return this.parts()[2]; | ||
} | ||
} |
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,17 @@ | ||
/** | ||
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
export * from './evaluation.js'; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.