Skip to content

Commit

Permalink
Merge pull request #16247 from brave/eth_sign_transaction
Browse files Browse the repository at this point in the history
Add eth_signTransaction and eth_sendRawTransaction
  • Loading branch information
darkdh authored Dec 8, 2022
2 parents 3009b92 + 6e3b544 commit 85227ab
Show file tree
Hide file tree
Showing 54 changed files with 1,002 additions and 473 deletions.
2 changes: 1 addition & 1 deletion android/android_browser_tests.gni
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android_test_exception_sources = [
"//brave/browser/brave_wallet/brave_wallet_sign_message_browsertest.cc",
"//brave/browser/brave_wallet/brave_wallet_tab_helper_browsertest.cc",
"//brave/browser/brave_wallet/ethereum_provider_browsertest.cc",
"//brave/browser/brave_wallet/send_transaction_browsertest.cc",
"//brave/browser/brave_wallet/send_or_sign_transaction_browsertest.cc",
"//brave/browser/brave_wallet/solana_provider_browsertest.cc",
"//brave/browser/brave_wallet/solana_provider_renderer_browsertest.cc",
"//brave/browser/brave_wallet/wallet_watch_asset_browsertest.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ public static TxData getTxData(
res.to = to;
res.value = value;
res.data = data;
res.signedTransaction = "";

return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ public void validateTxDataTest() {
String varName = f.getName();
if (varName.equals("nonce") || varName.equals("gasPrice")
|| varName.equals("gasLimit") || varName.equals("to")
|| varName.equals("value") || varName.equals("data")) {
|| varName.equals("value") || varName.equals("data")
|| varName.equals("signedTransaction")) {
continue;
}
if (v == null) {
Expand All @@ -424,6 +425,7 @@ public void validateTxDataTest() {
testStruct.to = "";
testStruct.value = "";
testStruct.data = new byte[0];
testStruct.signedTransaction = "";
try {
java.nio.ByteBuffer byteBuffer = testStruct.serialize();
TxData testStructDeserialized = TxData.deserialize(byteBuffer);
Expand Down
11 changes: 9 additions & 2 deletions browser/brave_wallet/eth_pending_tx_tracker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,13 @@ TEST_F(EthPendingTxTrackerUnitTest, UpdatePendingTransactions) {
tx_state_manager.AddOrUpdateTx(meta);
meta.set_id("004");
meta.set_from(addr2);
meta.tx()->set_nonce(uint256_t(4));
meta.set_status(mojom::TransactionStatus::Signed);
tx_state_manager.AddOrUpdateTx(meta);
meta.set_id("005");
meta.set_from(addr2);
meta.tx()->set_nonce(uint256_t(5));
meta.set_status(mojom::TransactionStatus::Submitted);
meta.set_status(mojom::TransactionStatus::Signed);
tx_state_manager.AddOrUpdateTx(meta);

test_url_loader_factory()->SetInterceptor(
Expand All @@ -200,7 +205,7 @@ TEST_F(EthPendingTxTrackerUnitTest, UpdatePendingTransactions) {

size_t num_pending;
EXPECT_TRUE(pending_tx_tracker.UpdatePendingTransactions(&num_pending));
EXPECT_EQ(3UL, num_pending);
EXPECT_EQ(4UL, num_pending);
WaitForResponse();
auto meta_from_state = tx_state_manager.GetEthTx("001");
ASSERT_NE(meta_from_state, nullptr);
Expand All @@ -212,6 +217,8 @@ TEST_F(EthPendingTxTrackerUnitTest, UpdatePendingTransactions) {
meta_from_state = tx_state_manager.GetEthTx("003");
ASSERT_EQ(meta_from_state, nullptr);
meta_from_state = tx_state_manager.GetEthTx("004");
ASSERT_EQ(meta_from_state, nullptr);
meta_from_state = tx_state_manager.GetEthTx("005");
ASSERT_NE(meta_from_state, nullptr);
EXPECT_EQ(meta_from_state->status(), mojom::TransactionStatus::Confirmed);
EXPECT_EQ(meta_from_state->tx_receipt().contract_address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class WalletNotificationServiceUnitTest : public testing::Test {
}

bool WasNotificationDisplayedOnStatusChange(mojom::TransactionStatus status) {
std::unique_ptr<EthTransaction> tx =
std::make_unique<EthTransaction>(*EthTransaction::FromTxData(
mojom::TxData::New("0x01", "0x4a817c800", "0x5208",
"0x3535353535353535353535353535353535353535",
"0x0de0b6b3a7640000", std::vector<uint8_t>())));
std::unique_ptr<EthTransaction> tx = std::make_unique<EthTransaction>(
*EthTransaction::FromTxData(mojom::TxData::New(
"0x01", "0x4a817c800", "0x5208",
"0x3535353535353535353535353535353535353535", "0x0de0b6b3a7640000",
std::vector<uint8_t>(), false, absl::nullopt)));
EthTxMeta meta(std::move(tx));
meta.set_status(status);
notification_service_->OnTransactionStatusChanged(meta.ToTransactionInfo());
Expand Down
Loading

0 comments on commit 85227ab

Please sign in to comment.