-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aztec-js): tx.wait waits for rpc to be synced
- Loading branch information
1 parent
2f66de1
commit 5cd1b12
Showing
9 changed files
with
108 additions
and
1 deletion.
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
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
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,46 @@ | ||
import { AztecRPC, TxHash, TxReceipt, TxStatus } from '@aztec/types'; | ||
|
||
import { MockProxy, mock } from 'jest-mock-extended'; | ||
|
||
import { SentTx } from './sent_tx.js'; | ||
|
||
describe('SentTx', () => { | ||
let rpc: MockProxy<AztecRPC>; | ||
let txHashPromise: Promise<TxHash>; | ||
|
||
let sentTx: SentTx; | ||
|
||
beforeEach(() => { | ||
rpc = mock(); | ||
txHashPromise = Promise.resolve(TxHash.fromBigInt(1n)); | ||
sentTx = new SentTx(rpc, txHashPromise); | ||
}); | ||
|
||
describe('wait', () => { | ||
let txReceipt: TxReceipt; | ||
beforeEach(() => { | ||
txReceipt = { status: TxStatus.MINED, blockNumber: 20 } as TxReceipt; | ||
rpc.getTxReceipt.mockResolvedValue(txReceipt); | ||
}); | ||
|
||
it('waits for all notes accounts to be synced', async () => { | ||
rpc.getSyncStatus | ||
.mockResolvedValueOnce({ blocks: 25, notes: { '0x1': 19, '0x2': 20 } }) | ||
.mockResolvedValueOnce({ blocks: 25, notes: { '0x1': 20, '0x2': 20 } }); | ||
|
||
const actual = await sentTx.wait({ timeout: 1, interval: 0.4 }); | ||
expect(actual).toEqual(txReceipt); | ||
}); | ||
|
||
it('fails if an account is not synced', async () => { | ||
rpc.getSyncStatus.mockResolvedValue({ blocks: 25, notes: { '0x1': 19, '0x2': 20 } }); | ||
await expect(sentTx.wait({ timeout: 1, interval: 0.4 })).rejects.toThrowError(/timeout/i); | ||
}); | ||
|
||
it('does not wait for notes sync', async () => { | ||
rpc.getSyncStatus.mockResolvedValue({ blocks: 19, notes: { '0x1': 19, '0x2': 19 } }); | ||
const actual = await sentTx.wait({ timeout: 1, interval: 0.4, waitForNotesSync: false }); | ||
expect(actual).toEqual(txReceipt); | ||
}); | ||
}); | ||
}); |
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