Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [2.0.3] - 2025-08-22

### Added Changes

Comment thread
RanaBug marked this conversation as resolved.
- `chainId` is mandatory in the `transaction()` method.
- For `send` and `estimate`, the `etherspotModularSdk` is initialized using the transaction's `chainId` rather than the provider's `chainId`.
## [2.0.2] - 2025-07-24

### Added Changes
Expand Down
29 changes: 24 additions & 5 deletions __tests__/EtherspotTransactionKit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ describe('EtherspotTransactionKit', () => {

it('should use default values for optional parameters', () => {
const txParams = {
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
};

Expand All @@ -206,15 +207,15 @@ describe('EtherspotTransactionKit', () => {

it('should throw error for missing to address', () => {
expect(() => {
transactionKit.transaction({ to: '' });
transactionKit.transaction({ chainId: 1, to: '' });
}).toThrow('transaction(): to is required.');
});

it('should throw error for invalid to address', () => {
(isAddress as unknown as jest.Mock).mockReturnValue(false);

expect(() => {
transactionKit.transaction({ to: 'invalid-address' });
transactionKit.transaction({ chainId: 1, to: 'invalid-address' });
}).toThrow(`transaction(): 'invalid-address' is not a valid address.`);
});

Expand All @@ -230,6 +231,7 @@ describe('EtherspotTransactionKit', () => {
it('should throw error for invalid value', () => {
expect(() => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: 'invalid',
});
Expand All @@ -241,6 +243,7 @@ describe('EtherspotTransactionKit', () => {
it('should throw error for negative value', () => {
expect(() => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: '-1',
});
Expand All @@ -251,6 +254,7 @@ describe('EtherspotTransactionKit', () => {

it('should accept bigint value', () => {
const txParams = {
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: BigInt(1000),
};
Expand All @@ -266,6 +270,7 @@ describe('EtherspotTransactionKit', () => {
describe('name', () => {
beforeEach(() => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
});
});
Expand Down Expand Up @@ -319,6 +324,7 @@ describe('EtherspotTransactionKit', () => {
describe('remove', () => {
it('should remove named transaction', () => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
});
transactionKit.name({ transactionName: 'test' });
Expand All @@ -341,6 +347,7 @@ describe('EtherspotTransactionKit', () => {

it('should throw error if transaction not named', () => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
});

Expand All @@ -355,6 +362,7 @@ describe('EtherspotTransactionKit', () => {
describe('update', () => {
beforeEach(() => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
});
transactionKit.name({ transactionName: 'test' });
Expand All @@ -380,6 +388,7 @@ describe('EtherspotTransactionKit', () => {
describe('estimate', () => {
beforeEach(() => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: '1000000000000000000',
data: '0x1234',
Expand Down Expand Up @@ -504,6 +513,7 @@ describe('EtherspotTransactionKit', () => {
it('should allow transaction with value = 0 and data = 0x', async () => {
const kit = new EtherspotTransactionKit(mockConfig);
kit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: '0',
data: '0x',
Expand Down Expand Up @@ -547,6 +557,7 @@ describe('EtherspotTransactionKit', () => {
describe('send', () => {
beforeEach(() => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: '1000000000000000000',
data: '0x1234',
Expand Down Expand Up @@ -658,6 +669,7 @@ describe('EtherspotTransactionKit', () => {

it('should allow sending transaction with value = 0 and data = 0x', async () => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: '0',
data: '0x',
Expand Down Expand Up @@ -743,6 +755,7 @@ describe('EtherspotTransactionKit', () => {

it('should return state with transaction', () => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: '1000000000000000000',
});
Expand Down Expand Up @@ -779,6 +792,7 @@ describe('EtherspotTransactionKit', () => {
expect(() => {
debugKit.setDebugMode(true);
debugKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
});
debugKit.name({ transactionName: 'debug-tx' });
Expand Down Expand Up @@ -828,6 +842,7 @@ describe('EtherspotTransactionKit', () => {
it('should reset all state', () => {
// Set up some state
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
});
transactionKit.name({ transactionName: 'test' });
Expand Down Expand Up @@ -870,6 +885,7 @@ describe('EtherspotTransactionKit', () => {
describe('State management during operations', () => {
beforeEach(() => {
transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
value: '1000000000000000000',
});
Expand Down Expand Up @@ -929,23 +945,24 @@ describe('EtherspotTransactionKit', () => {
});

describe('Provider integration', () => {
it('should handle provider chain ID changes', () => {
it('should use explicit chainId from transaction call', () => {
mockProvider.getChainId.mockReturnValue(5);

transactionKit.transaction({
chainId: 1,
to: '0x1234567890123456789012345678901234567890',
});

const state = transactionKit.getState();
expect(state.workingTransaction?.chainId).toBe(1);

// Test with no explicit chainId
transactionKit.transaction({
chainId: 137,
to: '0x1234567890123456789012345678901234567890',
value: '1',
});
const state2 = transactionKit.getState();
expect(state2.workingTransaction?.chainId).toBe(1); // Should use default
expect(state2.workingTransaction?.chainId).toBe(137);
});
Comment thread
RanaBug marked this conversation as resolved.

it('should handle SDK instance errors gracefully', async () => {
Expand All @@ -972,12 +989,14 @@ describe('Batch operations', () => {
mockSdk.send.mockReset();
mockSdk.totalGasEstimated.mockReset();
transactionKit.transaction({
chainId: 1,
to: '0x1111111111111111111111111111111111111111',
value: '1000000000000000000',
});
transactionKit.name({ transactionName: 'tx1' });
transactionKit.addToBatch({ batchName: 'batch1' });
transactionKit.transaction({
chainId: 1,
to: '0x2222222222222222222222222222222222222222',
value: '2000000000000000000',
});
Expand Down
4 changes: 2 additions & 2 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000dead',
value: '1000000000000000000',
});
Expand All @@ -57,6 +58,7 @@ const App = () => {
transactionName: 'tx1',
}) as INamedTransaction;
named.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000beef',
value: '2000000000000000000',
});
Expand Down Expand Up @@ -86,6 +88,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000cafe',
value: '3000000000000000000',
});
Expand All @@ -104,6 +107,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000babe',
value: '4000000000000000000',
});
Expand Down Expand Up @@ -252,6 +256,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000f00d',
value: '5000000000000000000',
});
Expand All @@ -272,6 +277,7 @@ const App = () => {
try {
// Ensure tx3 is in batch1
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000babe',
value: '4000000000000000000',
});
Expand All @@ -295,6 +301,7 @@ const App = () => {
try {
// Add tx5 to batch2
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000c0de',
value: '6000000000000000000',
});
Expand All @@ -304,6 +311,7 @@ const App = () => {
named.addToBatch({ batchName: 'batch2' });
// Add tx6 to batch2
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000c0fe',
value: '7000000000000000000',
});
Expand All @@ -327,6 +335,7 @@ const App = () => {
try {
// Ensure tx3 is in batch1
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000babe',
value: '4000000000000000000',
});
Expand All @@ -336,6 +345,7 @@ const App = () => {
named.addToBatch({ batchName: 'batch1' });
// Now update tx3 in batch1
named.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000feed',
value: '8880000000000000000',
});
Expand All @@ -353,6 +363,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000aabb',
value: '1000000000000000000',
});
Expand Down Expand Up @@ -389,6 +400,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000cafe',
value: '123',
});
Expand Down Expand Up @@ -423,7 +435,7 @@ const App = () => {
label: 'Add Transaction with Invalid Address',
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({ to: 'not-an-address', value: '1' });
kit.transaction({ chainId: 137, to: 'not-an-address', value: '1' });
logAndUpdateState('Should not see this.');
} catch (e) {
logAndUpdateState('Error: ' + (e as Error).message);
Expand All @@ -435,6 +447,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000dead',
value: '-1',
});
Expand Down Expand Up @@ -474,6 +487,7 @@ const App = () => {
try {
// Create empty batchD by adding and removing a tx
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000dede',
value: '1',
});
Expand Down Expand Up @@ -512,6 +526,7 @@ const App = () => {
try {
// Add tx10 to batchE
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000eeee',
value: '1',
});
Expand All @@ -533,6 +548,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000f0f0',
value: '1',
});
Expand All @@ -548,6 +564,7 @@ const App = () => {
action: async (logAndUpdateState: (msg: string) => void) => {
try {
kit.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000f1f1',
value: '1',
});
Expand All @@ -556,6 +573,7 @@ const App = () => {
}) as INamedTransaction;
named.addToBatch({ batchName: 'batchF' });
named.transaction({
chainId: 137,
to: '0x000000000000000000000000000000000000f2f2',
value: '2',
});
Expand Down
Loading