forked from cerc-io/laconicd-deprecated
tests(filters): add logs by topic test case (#1515)
* tests(filters) add logs by topic test case * fix(logs): add getLogs http call in test * tests(logs) add test case for getLogs by topic * tests(logs) fix lint errors
This commit is contained in:
parent
7f8b51e4c6
commit
7a042c488c
@ -3,7 +3,7 @@
|
|||||||
, rev ? "dirty"
|
, rev ? "dirty"
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
version = "v0.17.1";
|
version = "v0.20.0-rc2";
|
||||||
pname = "ethermintd";
|
pname = "ethermintd";
|
||||||
tags = [ "netgo" ];
|
tags = [ "netgo" ];
|
||||||
ldflags = lib.concatStringsSep "\n" ([
|
ldflags = lib.concatStringsSep "\n" ([
|
||||||
|
@ -9,6 +9,7 @@ from .utils import (
|
|||||||
deploy_contract,
|
deploy_contract,
|
||||||
send_successful_transaction,
|
send_successful_transaction,
|
||||||
send_transaction,
|
send_transaction,
|
||||||
|
w3_wait_for_new_blocks,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Smart contract names
|
# Smart contract names
|
||||||
@ -21,6 +22,35 @@ CHANGE_GREETING_TOPIC = Web3.keccak(text="ChangeGreeting(address,string)")
|
|||||||
TRANSFER_TOPIC = Web3.keccak(text="Transfer(address,address,uint256)")
|
TRANSFER_TOPIC = Web3.keccak(text="Transfer(address,address,uint256)")
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_logs_by_topic(cluster):
|
||||||
|
w3: Web3 = cluster.w3
|
||||||
|
|
||||||
|
contract, _ = deploy_contract(w3, CONTRACTS["Greeter"])
|
||||||
|
|
||||||
|
topic = Web3.keccak(text="ChangeGreeting(address,string)")
|
||||||
|
|
||||||
|
# with tx
|
||||||
|
tx = contract.functions.setGreeting("world").build_transaction()
|
||||||
|
receipt = send_transaction(w3, tx)
|
||||||
|
assert receipt.status == 1
|
||||||
|
|
||||||
|
# The getLogs method under the hood works as a filter
|
||||||
|
# with the specified topics and a block range.
|
||||||
|
# If the block range is not specified, it defaults
|
||||||
|
# to fromBlock: "latest", toBlock: "latest".
|
||||||
|
# Then, if we make a getLogs call within the same block that the tx
|
||||||
|
# happened, we will get a log in the result. However, if we make the call
|
||||||
|
# one or more blocks later, the result will be an empty array.
|
||||||
|
logs = w3.eth.get_logs({"topics": [topic.hex()]})
|
||||||
|
|
||||||
|
assert len(logs) == 1
|
||||||
|
assert logs[0]["address"] == contract.address
|
||||||
|
|
||||||
|
w3_wait_for_new_blocks(w3, 2)
|
||||||
|
logs = w3.eth.get_logs({"topics": [topic.hex()]})
|
||||||
|
assert len(logs) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_pending_transaction_filter(cluster):
|
def test_pending_transaction_filter(cluster):
|
||||||
w3: Web3 = cluster.w3
|
w3: Web3 = cluster.w3
|
||||||
flt = w3.eth.filter("pending")
|
flt = w3.eth.filter("pending")
|
||||||
|
Loading…
Reference in New Issue
Block a user