Skip to content

Commit 36e0526

Browse files
CoderZhiclaude
andcommitted
fix: preserve ActionCore fields in signContainer (Bug 2)
test: add regression guard confirming signContainer keeps nonce/gasLimit/fees Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent cc33a21 commit 36e0526

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

iotex/callers_typed_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,43 @@ func TestCall_TypedTx_RoutesToContainer(t *testing.T) {
185185
require.Equal(t, uint64(50000), decoded.Gas())
186186
}
187187

188+
// TestCall_TypedTx_ActionCoreFieldsPreserved confirms that signContainer does
189+
// not strip non-ChainID fields from ActionCore (Bug 2 regression guard).
190+
func TestCall_TypedTx_ActionCoreFieldsPreserved(t *testing.T) {
191+
ctrl := gomock.NewController(t)
192+
193+
acc, err := account.HexStringToAccount(_rlpTestKey)
194+
require.NoError(t, err)
195+
to, err := address.FromString(_rlpTestTo)
196+
require.NoError(t, err)
197+
198+
api := mock_iotexapi.NewMockAPIServiceClient(ctrl)
199+
var captured *iotextypes.Action
200+
api.EXPECT().
201+
SendAction(gomock.Any(), gomock.Any()).
202+
DoAndReturn(func(_ context.Context, req *iotexapi.SendActionRequest, _ ...grpc.CallOption) (*iotexapi.SendActionResponse, error) {
203+
captured = req.GetAction()
204+
return &iotexapi.SendActionResponse{ActionHash: strings.Repeat("0", 64)}, nil
205+
})
206+
207+
c := NewAuthedClient(api, _rlpTestChainID, acc)
208+
_, err = c.Transfer(to, big.NewInt(1)).
209+
SetNonce(7).
210+
SetTxType(dynamicFeeTxType).
211+
SetGasTipCap(big.NewInt(500000000)).
212+
SetGasFeeCap(big.NewInt(1500000000)).
213+
SetGasLimit(42000).
214+
Call(context.Background())
215+
require.NoError(t, err)
216+
217+
core := captured.GetCore()
218+
require.Equal(t, uint64(7), core.GetNonce())
219+
require.Equal(t, uint64(42000), core.GetGasLimit())
220+
require.Equal(t, "500000000", core.GetGasTipCap())
221+
require.Equal(t, "1500000000", core.GetGasFeeCap())
222+
require.Equal(t, _rlpTestChainID, core.GetChainID())
223+
}
224+
188225
// TestSetAccessList_DefensiveCopy confirms mutating the caller's slice after
189226
// the setter does not change what the SDK will send.
190227
func TestSetAccessList_DefensiveCopy(t *testing.T) {

iotex/utils.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@ func signContainer(a account.Account, act *iotextypes.ActionCore) (*iotextypes.A
6868
if err != nil {
6969
return nil, err
7070
}
71+
act.Action = &iotextypes.ActionCore_TxContainer{
72+
TxContainer: &iotextypes.TxContainer{Raw: raw},
73+
}
7174
return &iotextypes.Action{
72-
Core: &iotextypes.ActionCore{
73-
ChainID: act.GetChainID(),
74-
Action: &iotextypes.ActionCore_TxContainer{
75-
TxContainer: &iotextypes.TxContainer{Raw: raw},
76-
},
77-
},
75+
Core: act,
7876
SenderPubKey: a.PublicKey().Bytes(),
7977
Signature: actionSig,
8078
Encoding: iotextypes.Encoding_TX_CONTAINER,

0 commit comments

Comments
 (0)