Allow null in some fields for eth_sendTransaction (#33564)

This commit is contained in:
Anton Paymyshev
2026-02-04 18:02:58 +07:00
committed by GitHub
parent 2c25da29dc
commit b0c127eef8
3 changed files with 50 additions and 4 deletions
@@ -130,11 +130,22 @@ mojom::TxData1559Ptr ParseEthTransaction1559Params(
tx_data->base_data = std::move(base_data_ret);
// MM accepts `null` in these fields as no value:
// https://github.com/MetaMask/core/blob/5d9dec2085607b9dbf7667e328a16a5652da07fa/packages/transaction-controller/src/utils/validation.ts#L374-L395
if (tx->max_priority_fee_per_gas) {
tx_data->max_priority_fee_per_gas = *tx->max_priority_fee_per_gas;
if (tx->max_priority_fee_per_gas->is_string()) {
tx_data->max_priority_fee_per_gas =
tx->max_priority_fee_per_gas->GetString();
} else if (!tx->max_priority_fee_per_gas->is_none()) {
return nullptr;
}
}
if (tx->max_fee_per_gas) {
tx_data->max_fee_per_gas = *tx->max_fee_per_gas;
if (tx->max_fee_per_gas->is_string()) {
tx_data->max_fee_per_gas = tx->max_fee_per_gas->GetString();
} else if (!tx->max_fee_per_gas->is_none()) {
return nullptr;
}
}
return tx_data;
@@ -137,6 +137,41 @@ TEST(EthResponseHelperUnitTest, ParseEthTransaction1559Params) {
EXPECT_TRUE(tx_data->max_fee_per_gas.empty());
}
TEST(EthResponseHelperUnitTest, ParseEthTransaction1559ParamsHandleNulls) {
std::string json(
R"({
"params": [{
"from": "0x7f84E0DfF3ffd0af78770cF86c1b1DdFF99d51C8",
"to": "0x7f84E0DfF3ffd0af78770cF86c1b1DdFF99d51C7",
"gas": "0x146",
"value": "0x25F38E9E0000000",
"data": "0x010203",
"nonce": "0x01",
}]
})");
auto params = ParseParamsList(json);
std::string from;
mojom::TxData1559Ptr tx_data = ParseEthTransaction1559Params(params, from);
EXPECT_EQ(tx_data->max_fee_per_gas, "");
EXPECT_EQ(tx_data->max_priority_fee_per_gas, "");
// nulls in these fields are parsed as no value.
params[0].GetDict().Set("maxFeePerGas", base::Value());
params[0].GetDict().Set("maxPriorityFeePerGas", base::Value());
tx_data = ParseEthTransaction1559Params(params, from);
EXPECT_EQ(tx_data->max_fee_per_gas, "");
EXPECT_EQ(tx_data->max_priority_fee_per_gas, "");
// Non string values fail parsing.
params[0].GetDict().Set("maxFeePerGas", base::Value(123));
EXPECT_FALSE(ParseEthTransaction1559Params(params, from));
params[0].GetDict().Set("maxFeePerGas", base::Value());
params[0].GetDict().Set("maxPriorityFeePerGas", base::DictValue());
EXPECT_FALSE(ParseEthTransaction1559Params(params, from));
}
TEST(EthResponseHelperUnitTest, ShouldCreate1559Tx) {
// Test both EIP1559 and legacy gas fee fields are specified.
std::string json(
@@ -13,7 +13,7 @@ namespace json_rpc_requests {
DOMString? value;
DOMString? data;
DOMString? nonce;
DOMString? maxPriorityFeePerGas;
DOMString? maxFeePerGas;
any? maxPriorityFeePerGas;
any? maxFeePerGas;
};
};