Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug toString to signer and key stores #408

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/account.js

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

1 change: 1 addition & 0 deletions lib/key_stores/in_memory_key_store.d.ts

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

3 changes: 3 additions & 0 deletions lib/key_stores/in_memory_key_store.js

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

1 change: 1 addition & 0 deletions lib/key_stores/merge_key_store.d.ts

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

3 changes: 3 additions & 0 deletions lib/key_stores/merge_key_store.js

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

1 change: 1 addition & 0 deletions lib/key_stores/unencrypted_file_system_keystore.d.ts

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

3 changes: 3 additions & 0 deletions lib/key_stores/unencrypted_file_system_keystore.js

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

1 change: 1 addition & 0 deletions lib/signer.d.ts

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

3 changes: 3 additions & 0 deletions lib/signer.js

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

2 changes: 1 addition & 1 deletion src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Account {
const result = await exponentialBackoff(TX_STATUS_RETRY_WAIT, TX_NONCE_RETRY_NUMBER, TX_STATUS_RETRY_WAIT_BACKOFF, async () => {
const accessKeyInfo = await this.findAccessKey(receiverId, actions);
if (!accessKeyInfo) {
throw new TypedError(`Can not sign transactions for account ${this.accountId}, no matching key pair found in Signer.`, 'KeyNotFound');
throw new TypedError(`Can not sign transactions for account ${this.accountId} on network ${this.connection.networkId}, no matching key pair found in ${this.connection.signer}.`, 'KeyNotFound');
}
const { publicKey, accessKey } = accessKeyInfo;

Expand Down
4 changes: 4 additions & 0 deletions src/key_stores/in_memory_key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ export class InMemoryKeyStore extends KeyStore {
});
return result;
}

toString(): string {
return 'InMemoryKeyStore';
}
}
6 changes: 5 additions & 1 deletion src/key_stores/merge_key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ export class MergeKeyStore extends KeyStore {
}
return Array.from(result);
}
}

toString(): string {
return `MergeKeyStore(${this.keyStores.join(', ')})`;
}
}
4 changes: 4 additions & 0 deletions src/key_stores/unencrypted_file_system_keystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ export class UnencryptedFileSystemKeyStore extends KeyStore {
.filter(file => file.endsWith('.json'))
.map(file => file.replace(/.json$/, ''));
}

toString(): string {
return `UnencryptedFileSystemKeyStore(${this.keyDir})`;
}
}
4 changes: 4 additions & 0 deletions src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ export class InMemorySigner extends Signer {
}
return keyPair.sign(hash);
}

toString(): string {
return `InMemorySigner(${this.keyStore})`;
}
}
2 changes: 1 addition & 1 deletion test/account.access_key.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('remove access key no longer works', async() => {
await contract.setValue({value: 'test'});
fail('should throw an error');
} catch (e) {
expect(e.message).toEqual(`Can not sign transactions for account ${workingAccount.accountId}, no matching key pair found in Signer.`);
expect(e.message).toEqual(`Can not sign transactions for account ${workingAccount.accountId} on network unittest, no matching key pair found in InMemorySigner(InMemoryKeyStore).`);
expect(e.type).toEqual('KeyNotFound');
}
});
Expand Down