Skip to content

Commit

Permalink
fix: do not duplicate hex prefixes in wallet_getCallsStatus receipts (
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook authored Dec 3, 2024
1 parent 2bf0514 commit 7668262
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
55 changes: 54 additions & 1 deletion src/services/safe-wallet-provider/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,60 @@ describe('SafeWalletProvider', () => {
})

describe('wallet_getCallsStatus', () => {
it('should return a confirmed transaction', async () => {
it('should return a confirmed transaction if blockNumber/gasUsed are hex', async () => {
const receipt: Pick<TransactionReceipt, 'logs' | 'blockHash' | 'blockNumber' | 'gasUsed'> = {
logs: [],
blockHash: faker.string.hexadecimal(),
// Typed as number/bigint; is hex
blockNumber: faker.string.hexadecimal() as unknown as number,
gasUsed: faker.string.hexadecimal() as unknown as bigint,
}
const sdk = {
getBySafeTxHash: jest.fn().mockResolvedValue({
txStatus: 'SUCCESS',
txHash: '0x123',
txData: {
dataDecoded: {
parameters: [{ valueDecoded: [1] }],
},
},
}),
proxy: jest.fn().mockImplementation((method) => {
if (method === 'eth_getTransactionReceipt') {
return Promise.resolve(receipt)
}
return Promise.reject('Unknown method')
}),
}
const safeWalletProvider = new SafeWalletProvider(safe, sdk as any)

const params = ['0x123']

const status = await safeWalletProvider.request(1, { method: 'wallet_getCallsStatus', params } as any, appInfo)

expect(sdk.getBySafeTxHash).toHaveBeenCalledWith(params[0])
expect(sdk.proxy).toHaveBeenCalledWith('eth_getTransactionReceipt', params)
expect(status).toStrictEqual({
id: 1,
jsonrpc: '2.0',
result: {
receipts: [
{
blockHash: receipt.blockHash,
blockNumber: receipt.blockNumber,
chainId: '0x1',
gasUsed: receipt.gasUsed,
logs: receipt.logs,
status: '0x1',
transactionHash: '0x123',
},
],
status: 'CONFIRMED',
},
})
})

it('should return a confirmed transaction if blockNumber/gasUsed are number/bigint', async () => {
const receipt: Pick<TransactionReceipt, 'logs' | 'blockHash' | 'blockNumber' | 'gasUsed'> = {
logs: [],
blockHash: faker.string.hexadecimal(),
Expand Down
9 changes: 7 additions & 2 deletions src/services/safe-wallet-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,18 @@ export class SafeWalletProvider {
}

const calls = tx.txData?.dataDecoded?.parameters?.[0].valueDecoded?.length ?? 1

// Typed as number; is hex
const blockNumber = Number(receipt.blockNumber)
const gasUsed = Number(receipt.gasUsed)

const receipts = Array.from({ length: calls }, () => ({
logs: receipt.logs,
status: numberToHex(tx.txStatus === TransactionStatus.SUCCESS ? 1 : 0),
chainId: numberToHex(this.safe.chainId),
blockHash: receipt.blockHash as `0x${string}`,
blockNumber: numberToHex(receipt.blockNumber),
gasUsed: numberToHex(receipt.gasUsed),
blockNumber: numberToHex(blockNumber),
gasUsed: numberToHex(gasUsed),
transactionHash: tx.txHash as `0x${string}`,
}))

Expand Down

0 comments on commit 7668262

Please sign in to comment.