This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
txpool_content
RPC method. (#1539)
This adds support for the txpool_content RPC method, which is a Geth extension to the JSON-RPC API. For more details, see the specification at https://geth.ethereum.org/docs/rpc/ns-txpool. Co-authored-by: David Murdoch <[email protected]>
- Loading branch information
1 parent
4e9a443
commit bdf6a64
Showing
3 changed files
with
182 additions
and
6 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
124 changes: 124 additions & 0 deletions
124
src/chains/ethereum/ethereum/tests/api/txpool/content.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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import getProvider from "../../helpers/getProvider"; | ||
import assert from "assert"; | ||
import EthereumProvider from "../../../src/provider"; | ||
|
||
describe("txpool", () => { | ||
describe("content", () => { | ||
let provider: EthereumProvider; | ||
let accounts: string[]; | ||
beforeEach(async () => { | ||
provider = await getProvider({ | ||
miner: { blockTime: 1000 } | ||
}); | ||
accounts = await provider.send("eth_accounts"); | ||
}); | ||
|
||
it("returns the expected transaction data fields", async () => { | ||
let txJson = { | ||
from: accounts[1], | ||
to: accounts[2], | ||
value: "0x123", | ||
input: "0xaabbcc", | ||
gas: "0x10000", | ||
type: "0x2", | ||
maxPriorityFeePerGas: "0xf", | ||
maxFeePerGas: "0xffffffff" | ||
} as any; | ||
const hash = await provider.send("eth_sendTransaction", [txJson]); | ||
|
||
const { pending } = await provider.send("txpool_content"); | ||
const txData = pending[accounts[1]]["0"]; | ||
|
||
txJson["hash"] = hash; | ||
txJson["blockHash"] = null; | ||
txJson["blockNumber"] = null; | ||
txJson["transactionIndex"] = null; | ||
|
||
for (const [key, value] of Object.entries(txJson)) { | ||
assert.deepStrictEqual(value, txData[key]); | ||
} | ||
}); | ||
|
||
it("handles pending transactions", async () => { | ||
const tx1 = await provider.send("eth_sendTransaction", [ | ||
{ | ||
from: accounts[1], | ||
to: accounts[2] | ||
} | ||
]); | ||
const tx2 = await provider.send("eth_sendTransaction", [ | ||
{ | ||
from: accounts[2], | ||
to: accounts[3] | ||
} | ||
]); | ||
const tx3 = await provider.send("eth_sendTransaction", [ | ||
{ | ||
from: accounts[1], | ||
to: accounts[2] | ||
} | ||
]); | ||
|
||
const { pending } = await provider.send("txpool_content"); | ||
assert.strictEqual(pending[accounts[1]]["0"].hash, tx1); | ||
assert.strictEqual(pending[accounts[1]]["1"].hash, tx3); | ||
assert.strictEqual(pending[accounts[2]]["0"].hash, tx2); | ||
}); | ||
|
||
it("handles replaced transactions", async () => { | ||
const tx1 = await provider.send("eth_sendTransaction", [ | ||
{ | ||
from: accounts[1], | ||
to: accounts[2], | ||
value: "0x42", | ||
nonce: "0x0", | ||
type: "0x2", | ||
maxPriorityFeePerGas: "0xa0000000", | ||
maxFeePerGas: "0xa0000000" | ||
} | ||
]); | ||
const tx2 = await provider.send("eth_sendTransaction", [ | ||
{ | ||
from: accounts[1], | ||
to: accounts[2], | ||
value: "0x4200", | ||
nonce: "0x0", | ||
type: "0x2", | ||
maxPriorityFeePerGas: "0xf0000000", | ||
maxFeePerGas: "0xf0000000" | ||
} | ||
]); | ||
|
||
const { pending } = await provider.send("txpool_content"); | ||
assert.strictEqual(pending[accounts[1]]["0"].hash, tx2); | ||
assert.strictEqual(pending[accounts[1]]["1"], undefined); | ||
}); | ||
|
||
it("handles queued transactions", async () => { | ||
const tx = await provider.send("eth_sendTransaction", [ | ||
{ | ||
from: accounts[1], | ||
to: accounts[2], | ||
nonce: "0x123" | ||
} | ||
]); | ||
|
||
const { queued } = await provider.send("txpool_content"); | ||
assert.strictEqual(queued[accounts[1]]["291"].hash, tx); | ||
}); | ||
|
||
it("does not return confirmed transactions", async () => { | ||
await provider.send("eth_subscribe", ["newHeads"]); | ||
await provider.send("eth_sendTransaction", [ | ||
{ from: accounts[1], to: accounts[2] } | ||
]); | ||
await provider.send("evm_mine"); | ||
await provider.once("message"); | ||
|
||
const { pending, queued } = await provider.send("txpool_content"); | ||
assert.deepStrictEqual(pending, {}); | ||
assert.deepStrictEqual(queued, {}); | ||
}); | ||
|
||
}); | ||
}); |