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
feat: Add txpool_content RPC method #1539
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, {}); | ||
}); | ||
|
||
}); | ||
domob1812 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding to #763
Can this be shifted to a separate utility? since other
txpool_*
methods might need it. If yes, which place is most suitable?