Skip to content

Commit

Permalink
test: fix and extend unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strumswell committed Aug 16, 2024
1 parent fafa1e8 commit bd5bed5
Show file tree
Hide file tree
Showing 6 changed files with 468 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist/
coverage/
.idea/
.DS_Store
227 changes: 227 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"homepage": "https://github.com/spherity/timestamp#readme",
"devDependencies": {
"@vitest/coverage-v8": "^2.0.5",
"pkgroll": "^2.4.2",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
Expand Down
19 changes: 8 additions & 11 deletions src/TimestampController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ type RootHashOption = {
type TreeOrRootOptions = TreeOptions | RootHashOption | undefined;

export class TimestampController {
private provider: Provider;
private signer?: Signer;
private contract: TypedContract<typeof TRUSTED_HINT_REGISTRY_ABI>;
private merkleTree?: StandardMerkleTree<any[]>;
private rootHash?: HexString;
private readonly provider: Provider;
private readonly signer?: Signer;
private readonly contract: TypedContract<typeof TRUSTED_HINT_REGISTRY_ABI>;
private readonly merkleTree?: StandardMerkleTree<any[]>;
private readonly rootHash?: HexString;

/**
* Creates a new instance of the TimestampController class.
Expand Down Expand Up @@ -102,14 +102,11 @@ export class TimestampController {
* @throws {TimestampControllerError} If the transaction fails or no root hash is available.
*/
async anchorRootHash(namespace: HexString, list: HexString): Promise<ContractTransactionResponse> {
if (!this.merkleTree) {
throw new TimestampControllerError('No merkle tree available to anchor.');
}
if (!this.rootHash) {
throw new TimestampControllerError('No root hash available to anchor.');
if (!this.merkleTree && !this.rootHash) {
throw new TimestampControllerError('No merkle tree or root hash available to anchor.');
}

const key = this.rootHash;
const key = this.rootHash!;
const value = "0x1000000000000000000000000000000000000000000000000000000000000000";

try {
Expand Down
Loading

0 comments on commit bd5bed5

Please sign in to comment.