@@ -384,6 +439,12 @@ describe('useEtherspotTransactions()', () => {
expect(estimated[0].estimatedBatches[1].cost.toString()).toBe('200000');
expect(estimated[1].estimatedBatches[0].cost.toString()).toBe('325000');
expect(estimated[2].estimatedBatches[0].cost.toString()).toBe('325000');
+
+ const sent = await result.current.send();
+ expect(sent[0].sentBatches[0].userOpHash).toBe('0x7c');
+ expect(sent[0].sentBatches[1].userOpHash).toBe('0x7e');
+ expect(sent[1].sentBatches[0].userOpHash).toBe('0x46');
+ expect(sent[2].sentBatches[0].userOpHash).toBe('0x7d');
});
it('estimates and calls onEstimated for each batch group', async () => {
@@ -448,6 +509,68 @@ describe('useEtherspotTransactions()', () => {
expect(onEstimated2.mock.calls[0][0]).toStrictEqual(estimated[1].estimatedBatches);
});
+ it('sends and calls onSent for each batch group', async () => {
+ const onSent1 = jest.fn((sent) => sent);
+ const onSent2 = jest.fn((sent) => sent);
+
+ const wrapper = ({ children }) => (
+
+
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {children}
+
+ );
+
+ const { result } = renderHook(() => useEtherspotTransactions(), { wrapper });
+
+ const sent = await result.current.send();
+
+ expect(onSent1).toBeCalledTimes(1);
+ expect(onSent2).toBeCalledTimes(1);
+ expect(onSent1.mock.calls[0][0]).toStrictEqual(sent[0].sentBatches);
+ expect(onSent2.mock.calls[0][0]).toStrictEqual(sent[1].sentBatches);
+ });
+
it('estimates and returns error messages for each batch group', async () => {
const onEstimated1 = jest.fn((estimated) => estimated);
const onEstimated2 = jest.fn((estimated) => estimated);
@@ -503,7 +626,67 @@ describe('useEtherspotTransactions()', () => {
expect(onEstimated2.mock.calls[0][0]).toStrictEqual(estimated[1].estimatedBatches);
});
- it('estimates and returns error messages for batch group by ID', async () => {
+ it('estimates successfully and returns error messages on send for each batch group', async () => {
+ const onSent1 = jest.fn((sent) => sent);
+ const onSent2 = jest.fn((sent) => sent);
+
+ const wrapper = ({ children }) => (
+
+
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {children}
+
+ );
+
+ const { result } = renderHook(() => useEtherspotTransactions(), { wrapper });
+
+ const estimated = await result.current.estimate();
+
+ expect(estimated[0].estimatedBatches[0].cost.toString()).toBe('350000');
+ expect(estimated[1].estimatedBatches[0].cost.toString()).toBe('250000');
+
+ const sent = await result.current.send();
+
+ expect(sent[0].sentBatches[0].errorMessage).toBe('Transaction reverted: chain too hot');
+ expect(sent[1].sentBatches[0].errorMessage).toBe('Transaction reverted: invalid signature');
+ expect(onSent1.mock.calls[0][0]).toStrictEqual(sent[0].sentBatches);
+ expect(onSent2.mock.calls[0][0]).toStrictEqual(sent[1].sentBatches);
+ });
+
+ it('estimates valid and returns error messages for invalid batch group by ID', async () => {
const onEstimated1 = jest.fn((estimated) => estimated);
const onEstimated2 = jest.fn((estimated) => estimated);
const onEstimated3 = jest.fn((estimated) => estimated);
@@ -585,4 +768,87 @@ describe('useEtherspotTransactions()', () => {
expect(onEstimated2.mock.calls[0][0]).toStrictEqual(estimated2[0].estimatedBatches);
expect(onEstimated3.mock.calls[0][0]).toStrictEqual(estimated2[1].estimatedBatches);
});
+
+ it('sends valid and returns error messages for invalid batch group by ID', async () => {
+ const onSent1 = jest.fn((estimated) => estimated);
+ const onSent2 = jest.fn((estimated) => estimated);
+ const onSent3 = jest.fn((estimated) => estimated);
+
+ const wrapper = ({ children }) => (
+
+
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {children}
+
+ );
+
+ const { result } = renderHook(() => useEtherspotTransactions(), { wrapper });
+
+ const sent1 = await result.current.send(['test-id-1']);
+ expect(sent1.length).toBe(1);
+ expect(sent1[0].sentBatches[0].errorMessage).toBe('Transaction reverted: chain too hot');
+ expect(onSent1.mock.calls[0][0]).toStrictEqual(sent1[0].sentBatches);
+
+ const sent2 = await result.current.send(['test-id-2', 'test-id-3']);
+ expect(sent2.length).toBe(2);
+ expect(sent2[0].sentBatches[0].userOpHash).toBe('0x46');
+ expect(sent2[1].sentBatches[0].userOpHash).toBe('0x47');
+ expect(onSent2.mock.calls[0][0]).toStrictEqual(sent2[0].sentBatches);
+ expect(onSent3.mock.calls[0][0]).toStrictEqual(sent2[1].sentBatches);
+ });
})
diff --git a/package-lock.json b/package-lock.json
index 6bdb7a7..255cfc7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@etherspot/transaction-kit",
- "version": "0.6.2",
+ "version": "0.6.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@etherspot/transaction-kit",
- "version": "0.6.2",
+ "version": "0.6.3",
"license": "MIT",
"dependencies": {
"@etherspot/eip1271-verification-util": "^0.1.2",
diff --git a/package.json b/package.json
index f70abc1..9a60e2b 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "@etherspot/transaction-kit",
"description": "React Etherspot Transaction Kit",
- "version": "0.6.2",
+ "version": "0.6.3",
"main": "dist/cjs/index.js",
"scripts": {
"rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c",
diff --git a/src/providers/EtherspotTransactionKitContextProvider.tsx b/src/providers/EtherspotTransactionKitContextProvider.tsx
index 2a298d0..3208eec 100644
--- a/src/providers/EtherspotTransactionKitContextProvider.tsx
+++ b/src/providers/EtherspotTransactionKitContextProvider.tsx
@@ -114,7 +114,7 @@ const EtherspotTransactionKitContextProvider = ({ children }: EtherspotTransacti
const userOpHash = await etherspotPrimeSdk.send(estimatedBatch.userOp);
sentBatches.push({ ...estimatedBatch, userOpHash });
} catch (e) {
- sentBatches.push({ ...estimatedBatch, errorMessage: (e instanceof Error && e.message) || 'Failed to estimate!' });
+ sentBatches.push({ ...estimatedBatch, errorMessage: (e instanceof Error && e.message) || 'Failed to send!' });
}
}