/** * @jest-environment node */ import { stripStalePlanningNonceIfJsonObject } from './stripStalePlanningNonce' describe('stripStalePlanningNonceIfJsonObject', () => { it('removes nonce from a flat tx object', () => { const tx = { from: '0xa', to: '0xb', nonce: '0x5', data: '0x' } expect(stripStalePlanningNonceIfJsonObject(tx)).toEqual({ from: '0xa', to: '0xb', data: '0x', }) }) it('unwraps single-key wrapper then strips nonce', () => { const wrapped = { transaction: { from: '0xa', nonce: 1, value: '0x0' }, } expect(stripStalePlanningNonceIfJsonObject(wrapped)).toEqual({ from: '0xa', value: '0x0', }) }) it('parses JSON string and strips nonce', () => { const s = JSON.stringify({ to: '0xt', nonce: '2', gas: '21000' }) expect(stripStalePlanningNonceIfJsonObject(s)).toEqual({ to: '0xt', gas: '21000', }) }) it('returns opaque string on parse error', () => { expect(stripStalePlanningNonceIfJsonObject('not-json')).toBe('not-json') }) })