Skip to content

Commit

Permalink
fix: throw error in getSmartAccountAddressFromInitialSigner if init…
Browse files Browse the repository at this point in the history
…ial signer is undefined (#166)

* fix: throw error in `getSmartAccountAddressFromInitialSigner` if initial signer is undefined

* changeset
  • Loading branch information
coffeexcoin authored Jan 10, 2025
1 parent 0f3826b commit 46fd96b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-pears-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@abstract-foundation/agw-client': patch
---

Fix getSmartAccountAddressFromInitialSigner to throw if initial signer is undefined
3 changes: 3 additions & 0 deletions packages/agw-client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export async function getSmartAccountAddressFromInitialSigner<
initialSigner: Address,
publicClient: PublicClient<Transport, chain>,
): Promise<Hex> {
if (initialSigner === undefined) {
throw new Error('Initial signer is required to get smart account address');
}
// Generate salt based off address
const addressBytes = toBytes(initialSigner);
const salt = keccak256(addressBytes);
Expand Down
11 changes: 11 additions & 0 deletions packages/agw-client/test/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ describe('convertBigIntToString', () => {
});

describe('getSmartAccountAddressFromInitialSigner', () => {
it('should throw an error if initial signer is undefined', async () => {
const publicClient = {
readContract: vi.fn().mockResolvedValue(address.smartAccountAddress),
};
expect(
getSmartAccountAddressFromInitialSigner(undefined!, publicClient as any),
).rejects.toThrowError(
'Initial signer is required to get smart account address',
);
});

it('should return the smart account address', () => {
const initialSigner = address.signerAddress;
const publicClient = {
Expand Down

0 comments on commit 46fd96b

Please sign in to comment.