-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add waitForTransaction method to Network type (#48)
* Add waitForTransaction method to Network type * Fix function and add test * Add test for timeout * Remove default in coment * Add TransactionReceipt type * Add to field to TransactionReceipt * Add waitForTransaction to ethers binding * Update comments and remove type from receipt * Remove type field from ethers binding * Add waitForTransaction to viem binding * Add changeset * Switch to patch change
- Loading branch information
Showing
7 changed files
with
182 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@delvtech/evm-client-ethers": patch | ||
"@delvtech/evm-client-viem": patch | ||
"@delvtech/evm-client": patch | ||
--- | ||
|
||
Add `waitForTransaction` method to `Network` type. |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
NetworkStub, | ||
transactionToReceipt, | ||
} from 'src/network/stubs/NetworkStub'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
describe('NetworkStub', () => { | ||
it('waits for stubbed transactions', async () => { | ||
const network = new NetworkStub(); | ||
|
||
const txHash = '0x123abc'; | ||
const stubbedTx = { | ||
gas: 100n, | ||
gasPrice: 100n, | ||
input: '0x456def', | ||
nonce: 0, | ||
type: '0x0', | ||
value: 0n, | ||
} as const; | ||
|
||
const waitPromise = network.waitForTransaction(txHash); | ||
|
||
await new Promise((resolve) => { | ||
setTimeout(() => { | ||
network.stubGetTransaction({ | ||
args: [txHash], | ||
value: stubbedTx, | ||
}); | ||
resolve(undefined); | ||
}, 1000); | ||
}); | ||
|
||
const tx = await waitPromise; | ||
|
||
expect(tx).toEqual(transactionToReceipt(stubbedTx)); | ||
}); | ||
|
||
it('reaches timeout when waiting for transactions that are never stubbed', async () => { | ||
const network = new NetworkStub(); | ||
|
||
const waitPromise = await network.waitForTransaction('0x123abc', { | ||
timeout: 1000, | ||
}); | ||
|
||
expect(waitPromise).toBe(undefined); | ||
}); | ||
}); |
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