Skip to content
Open
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
37 changes: 37 additions & 0 deletions iotex/callers_typed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,43 @@ func TestCall_TypedTx_RoutesToContainer(t *testing.T) {
require.Equal(t, uint64(50000), decoded.Gas())
}

// TestCall_TypedTx_ActionCoreFieldsPreserved confirms that signContainer does
// not strip non-ChainID fields from ActionCore (Bug 2 regression guard).
func TestCall_TypedTx_ActionCoreFieldsPreserved(t *testing.T) {
ctrl := gomock.NewController(t)

acc, err := account.HexStringToAccount(_rlpTestKey)
require.NoError(t, err)
to, err := address.FromString(_rlpTestTo)
require.NoError(t, err)

api := mock_iotexapi.NewMockAPIServiceClient(ctrl)
var captured *iotextypes.Action
api.EXPECT().
SendAction(gomock.Any(), gomock.Any()).
DoAndReturn(func(_ context.Context, req *iotexapi.SendActionRequest, _ ...grpc.CallOption) (*iotexapi.SendActionResponse, error) {
captured = req.GetAction()
return &iotexapi.SendActionResponse{ActionHash: strings.Repeat("0", 64)}, nil
})

c := NewAuthedClient(api, _rlpTestChainID, acc)
_, err = c.Transfer(to, big.NewInt(1)).
SetNonce(7).
SetTxType(dynamicFeeTxType).
SetGasTipCap(big.NewInt(500000000)).
SetGasFeeCap(big.NewInt(1500000000)).
SetGasLimit(42000).
Call(context.Background())
require.NoError(t, err)

core := captured.GetCore()
require.Equal(t, uint64(7), core.GetNonce())
require.Equal(t, uint64(42000), core.GetGasLimit())
require.Equal(t, "500000000", core.GetGasTipCap())
require.Equal(t, "1500000000", core.GetGasFeeCap())
require.Equal(t, _rlpTestChainID, core.GetChainID())
}

// TestSetAccessList_DefensiveCopy confirms mutating the caller's slice after
// the setter does not change what the SDK will send.
func TestSetAccessList_DefensiveCopy(t *testing.T) {
Expand Down
10 changes: 4 additions & 6 deletions iotex/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@ func signContainer(a account.Account, act *iotextypes.ActionCore) (*iotextypes.A
if err != nil {
return nil, err
}
act.Action = &iotextypes.ActionCore_TxContainer{
TxContainer: &iotextypes.TxContainer{Raw: raw},
}
return &iotextypes.Action{
Core: &iotextypes.ActionCore{
ChainID: act.GetChainID(),
Action: &iotextypes.ActionCore_TxContainer{
TxContainer: &iotextypes.TxContainer{Raw: raw},
},
},
Core: act,
SenderPubKey: a.PublicKey().Bytes(),
Signature: actionSig,
Encoding: iotextypes.Encoding_TX_CONTAINER,
Expand Down
Loading