-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
47 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 21 additions & 7 deletions
28
packages/fcl-ethereum-provider/src/rpc/handlers/eth-send-transaction.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import {AccountManager} from "../../accounts/account-manager" | ||
import {NetworkManager} from "../../network/network-manager" | ||
import {ethSendTransaction} from "./eth-send-transaction" | ||
|
||
jest.mock("../../accounts/account-manager") | ||
jest.mock("../../network/network-manager") | ||
|
||
describe("eth_sendTransaction handler", () => { | ||
test("should call the AccountManager to send a transaction", async () => { | ||
const mockAccountManager = new (AccountManager as any)() | ||
mockAccountManager.sendTransaction.mockResolvedValue("0x123456") | ||
|
||
const params = { | ||
from: "0x1234", | ||
to: "0x5678", | ||
value: "0x100", | ||
} | ||
const mockNetworkManager = new (NetworkManager as any)() | ||
mockNetworkManager.getChainId.mockResolvedValue(1) | ||
|
||
const evmTxHash = await ethSendTransaction(mockAccountManager, params) | ||
const params = [ | ||
{ | ||
from: "0x1234", | ||
to: "0x5678", | ||
value: "0x100", | ||
}, | ||
] | ||
|
||
const evmTxHash = await ethSendTransaction( | ||
mockAccountManager, | ||
mockNetworkManager, | ||
params | ||
) | ||
|
||
expect(mockAccountManager.sendTransaction).toHaveBeenCalled() | ||
expect(mockAccountManager.sendTransaction).toHaveBeenCalledTimes(1) | ||
expect(mockAccountManager.sendTransaction).toHaveBeenCalledWith(params) | ||
expect(mockAccountManager.sendTransaction).toHaveBeenCalledWith({ | ||
...params[0], | ||
chainId: 1, | ||
}) | ||
expect(evmTxHash).toEqual("0x123456") | ||
}) | ||
}) |
8 changes: 7 additions & 1 deletion
8
packages/fcl-ethereum-provider/src/rpc/handlers/eth-send-transaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import {AccountManager} from "../../accounts/account-manager" | ||
import {NetworkManager} from "../../network/network-manager" | ||
|
||
export async function ethSendTransaction( | ||
accountManager: AccountManager, | ||
networkManager: NetworkManager, | ||
params: any | ||
) { | ||
return await accountManager.sendTransaction(params) | ||
return await accountManager.sendTransaction({ | ||
...params[0], | ||
// We pass the chainId to avoid race conditions where the chainId changes | ||
chainId: await networkManager.getChainId(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters