diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 978bc8b2cb..3c2dc8762b 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -3,3 +3,4 @@ 39f4453c2fe31be58ae187669a3f355093bf9361 69f49ee1ffa8ca98d66d9b960976a490c846c82f 831ff0f64a6db983cc2695af803942091ea877a1 +784ece4e96249027607e66b4ebceb3cfde268ce8 diff --git a/newsfragments/2516.misc.rst b/newsfragments/2516.misc.rst new file mode 100644 index 0000000000..165a8c401b --- /dev/null +++ b/newsfragments/2516.misc.rst @@ -0,0 +1 @@ +Add Black linting to ``_utils/module_testing`` diff --git a/tox.ini b/tox.ini index 764fe09aaa..1142ec7a5e 100644 --- a/tox.ini +++ b/tox.ini @@ -64,8 +64,7 @@ basepython=python extras=linter commands= flake8 {toxinidir}/web3 {toxinidir}/ens {toxinidir}/ethpm {toxinidir}/tests --exclude {toxinidir}/ethpm/ethpm-spec - black {toxinidir}/ethpm {toxinidir}/web3/auto {toxinidir}/web3/utils --exclude {toxinidir}/ethpm/ethpm-spec --check - black {toxinidir}/web3/_utils --exclude {toxinidir}/web3/_utils/module_testing --check + black {toxinidir}/ethpm {toxinidir}/web3/auto {toxinidir}/web3/utils {toxinidir}/web3/_utils --exclude {toxinidir}/ethpm/ethpm-spec --check isort --recursive --check-only --diff {toxinidir}/web3/ {toxinidir}/ens/ {toxinidir}/ethpm/ {toxinidir}/tests/ mypy -p web3 -p ethpm -p ens --config-file {toxinidir}/mypy.ini diff --git a/web3/_utils/module_testing/__init__.py b/web3/_utils/module_testing/__init__.py index e3ecdae230..3638ac4c6e 100644 --- a/web3/_utils/module_testing/__init__.py +++ b/web3/_utils/module_testing/__init__.py @@ -7,7 +7,7 @@ ) from .go_ethereum_txpool_module import ( # noqa: F401 GoEthereumAsyncTxPoolModuleTest, - GoEthereumTxPoolModuleTest + GoEthereumTxPoolModuleTest, ) from .net_module import ( # noqa: F401 AsyncNetModuleTest, diff --git a/web3/_utils/module_testing/emitter_contract.py b/web3/_utils/module_testing/emitter_contract.py index 72a91fe717..6d3aaaca47 100644 --- a/web3/_utils/module_testing/emitter_contract.py +++ b/web3/_utils/module_testing/emitter_contract.py @@ -275,17 +275,17 @@ "indexed": True, "internalType": "address", "name": "arg0", - "type": "address" + "type": "address", }, { "indexed": False, "internalType": "address", "name": "arg1", - "type": "address" - } + "type": "address", + }, ], "name": "LogAddressIndexed", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -294,36 +294,26 @@ "indexed": False, "internalType": "address", "name": "arg0", - "type": "address" + "type": "address", }, { "indexed": False, "internalType": "address", "name": "arg1", - "type": "address" - } + "type": "address", + }, ], "name": "LogAddressNotIndexed", - "type": "event" - }, - { - "anonymous": True, - "inputs": [], - "name": "LogAnonymous", - "type": "event" + "type": "event", }, + {"anonymous": True, "inputs": [], "name": "LogAnonymous", "type": "event"}, { "anonymous": False, "inputs": [ - { - "indexed": False, - "internalType": "bytes", - "name": "v", - "type": "bytes" - } + {"indexed": False, "internalType": "bytes", "name": "v", "type": "bytes"} ], "name": "LogBytes", - "type": "event" + "type": "event", }, { "anonymous": True, @@ -332,17 +322,17 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", }, { "indexed": True, "internalType": "uint256", "name": "arg1", - "type": "uint256" - } + "type": "uint256", + }, ], "name": "LogDoubleAnonymous", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -351,17 +341,17 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", }, { "indexed": False, "internalType": "uint256", "name": "arg1", - "type": "uint256" - } + "type": "uint256", + }, ], "name": "LogDoubleArg", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -370,17 +360,17 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", }, { "indexed": True, "internalType": "uint256", "name": "arg1", - "type": "uint256" - } + "type": "uint256", + }, ], "name": "LogDoubleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -389,17 +379,17 @@ "indexed": True, "internalType": "string", "name": "arg0", - "type": "string" + "type": "string", }, { "indexed": False, "internalType": "string", "name": "arg1", - "type": "string" - } + "type": "string", + }, ], "name": "LogDynamicArgs", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -408,24 +398,19 @@ "indexed": True, "internalType": "bytes2[]", "name": "arg0", - "type": "bytes2[]" + "type": "bytes2[]", }, { "indexed": False, "internalType": "bytes2[]", "name": "arg1", - "type": "bytes2[]" - } + "type": "bytes2[]", + }, ], "name": "LogListArgs", - "type": "event" - }, - { - "anonymous": False, - "inputs": [], - "name": "LogNoArguments", - "type": "event" + "type": "event", }, + {"anonymous": False, "inputs": [], "name": "LogNoArguments", "type": "event"}, { "anonymous": False, "inputs": [ @@ -433,29 +418,29 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", }, { "indexed": False, "internalType": "uint256", "name": "arg1", - "type": "uint256" + "type": "uint256", }, { "indexed": False, "internalType": "uint256", "name": "arg2", - "type": "uint256" + "type": "uint256", }, { "indexed": False, "internalType": "uint256", "name": "arg3", - "type": "uint256" - } + "type": "uint256", + }, ], "name": "LogQuadrupleArg", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -464,29 +449,29 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", }, { "indexed": False, "internalType": "uint256", "name": "arg1", - "type": "uint256" + "type": "uint256", }, { "indexed": True, "internalType": "uint256", "name": "arg2", - "type": "uint256" + "type": "uint256", }, { "indexed": True, "internalType": "uint256", "name": "arg3", - "type": "uint256" - } + "type": "uint256", + }, ], "name": "LogQuadrupleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": True, @@ -495,11 +480,11 @@ "indexed": True, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", } ], "name": "LogSingleAnonymous", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -508,11 +493,11 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", } ], "name": "LogSingleArg", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -521,24 +506,19 @@ "indexed": True, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", } ], "name": "LogSingleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": False, - "internalType": "string", - "name": "v", - "type": "string" - } + {"indexed": False, "internalType": "string", "name": "v", "type": "string"} ], "name": "LogString", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -547,41 +527,29 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", }, { "components": [ - { - "internalType": "uint256", - "name": "a", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "b", - "type": "uint256" - }, + {"internalType": "uint256", "name": "a", "type": "uint256"}, + {"internalType": "uint256", "name": "b", "type": "uint256"}, { "components": [ - { - "internalType": "uint256", - "name": "c", - "type": "uint256" - } + {"internalType": "uint256", "name": "c", "type": "uint256"} ], "internalType": "struct Emitter.NestedTestTuple", "name": "nested", - "type": "tuple" - } + "type": "tuple", + }, ], "indexed": False, "internalType": "struct Emitter.TestTuple", "name": "arg1", - "type": "tuple" - } + "type": "tuple", + }, ], "name": "LogStructArgs", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -590,23 +558,23 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", }, { "indexed": False, "internalType": "uint256", "name": "arg1", - "type": "uint256" + "type": "uint256", }, { "indexed": False, "internalType": "uint256", "name": "arg2", - "type": "uint256" - } + "type": "uint256", + }, ], "name": "LogTripleArg", - "type": "event" + "type": "event", }, { "anonymous": False, @@ -615,220 +583,194 @@ "indexed": False, "internalType": "uint256", "name": "arg0", - "type": "uint256" + "type": "uint256", }, { "indexed": True, "internalType": "uint256", "name": "arg1", - "type": "uint256" + "type": "uint256", }, { "indexed": True, "internalType": "uint256", "name": "arg2", - "type": "uint256" - } + "type": "uint256", + }, ], "name": "LogTripleWithIndex", - "type": "event" + "type": "event", }, { "inputs": [ - { - "internalType": "address", "name": "arg0", "type": "address" - }, - { - "internalType": "address", "name": "arg1", "type": "address" - } + {"internalType": "address", "name": "arg0", "type": "address"}, + {"internalType": "address", "name": "arg1", "type": "address"}, ], "name": "logAddressIndexedArgs", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ - { - "internalType": "address", "name": "arg0", "type": "address" - }, - { - "internalType": "address", "name": "arg1", "type": "address" - } + {"internalType": "address", "name": "arg0", "type": "address"}, + {"internalType": "address", "name": "arg1", "type": "address"}, ], "name": "logAddressNotIndexedArgs", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { - "inputs": [{ - "internalType": "bytes", "name": "v", "type": "bytes" - }], + "inputs": [{"internalType": "bytes", "name": "v", "type": "bytes"}], "name": "logBytes", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ { "internalType": "enum Emitter.WhichEvent", "name": "which", - "type": "uint8" + "type": "uint8", }, - { - "internalType": "uint256", "name": "arg0", "type": "uint256" - }, - { - "internalType": "uint256", "name": "arg1", "type": "uint256" - } + {"internalType": "uint256", "name": "arg0", "type": "uint256"}, + {"internalType": "uint256", "name": "arg1", "type": "uint256"}, ], "name": "logDouble", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ {"internalType": "string", "name": "arg0", "type": "string"}, - {"internalType": "string", "name": "arg1", "type": "string"} + {"internalType": "string", "name": "arg1", "type": "string"}, ], "name": "logDynamicArgs", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ {"internalType": "bytes2[]", "name": "arg0", "type": "bytes2[]"}, - {"internalType": "bytes2[]", "name": "arg1", "type": "bytes2[]"} + {"internalType": "bytes2[]", "name": "arg1", "type": "bytes2[]"}, ], "name": "logListArgs", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ { "internalType": "enum Emitter.WhichEvent", "name": "which", - "type": "uint8" + "type": "uint8", } ], "name": "logNoArgs", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ { "internalType": "enum Emitter.WhichEvent", "name": "which", - "type": "uint8" + "type": "uint8", }, {"internalType": "uint256", "name": "arg0", "type": "uint256"}, {"internalType": "uint256", "name": "arg1", "type": "uint256"}, {"internalType": "uint256", "name": "arg2", "type": "uint256"}, - {"internalType": "uint256", "name": "arg3", "type": "uint256"} + {"internalType": "uint256", "name": "arg3", "type": "uint256"}, ], "name": "logQuadruple", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ { "internalType": "enum Emitter.WhichEvent", "name": "which", - "type": "uint8" + "type": "uint8", }, - {"internalType": "uint256", "name": "arg0", "type": "uint256"} + {"internalType": "uint256", "name": "arg0", "type": "uint256"}, ], "name": "logSingle", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [{"internalType": "string", "name": "v", "type": "string"}], "name": "logString", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ {"internalType": "uint256", "name": "arg0", "type": "uint256"}, { "components": [ - { - "internalType": "uint256", - "name": "a", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "b", - "type": "uint256" - }, + {"internalType": "uint256", "name": "a", "type": "uint256"}, + {"internalType": "uint256", "name": "b", "type": "uint256"}, { "components": [ - { - "internalType": "uint256", - "name": "c", - "type": "uint256" - } + {"internalType": "uint256", "name": "c", "type": "uint256"} ], "internalType": "struct Emitter.NestedTestTuple", "name": "nested", - "type": "tuple" - } + "type": "tuple", + }, ], "internalType": "struct Emitter.TestTuple", "name": "arg1", - "type": "tuple" - } + "type": "tuple", + }, ], "name": "logStruct", "outputs": [], "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "inputs": [ { "internalType": "enum Emitter.WhichEvent", "name": "which", - "type": "uint8" + "type": "uint8", }, {"internalType": "uint256", "name": "arg0", "type": "uint256"}, {"internalType": "uint256", "name": "arg1", "type": "uint256"}, - {"internalType": "uint256", "name": "arg2", "type": "uint256"} + {"internalType": "uint256", "name": "arg2", "type": "uint256"}, ], "name": "logTriple", "outputs": [], "stateMutability": "nonpayable", - "type": "function" - } + "type": "function", + }, ] EMITTER_ENUM = { - 'LogAnonymous': 0, - 'LogNoArguments': 1, - 'LogSingleArg': 2, - 'LogDoubleArg': 3, - 'LogTripleArg': 4, - 'LogQuadrupleArg': 5, - 'LogSingleAnonymous': 6, - 'LogSingleWithIndex': 7, - 'LogDoubleAnonymous': 8, - 'LogDoubleWithIndex': 9, - 'LogTripleWithIndex': 10, - 'LogQuadrupleWithIndex': 11, - 'LogStructArg': 12 + "LogAnonymous": 0, + "LogNoArguments": 1, + "LogSingleArg": 2, + "LogDoubleArg": 3, + "LogTripleArg": 4, + "LogQuadrupleArg": 5, + "LogSingleAnonymous": 6, + "LogSingleWithIndex": 7, + "LogDoubleAnonymous": 8, + "LogDoubleWithIndex": 9, + "LogTripleWithIndex": 10, + "LogQuadrupleWithIndex": 11, + "LogStructArg": 12, } diff --git a/web3/_utils/module_testing/emitter_contract_old.py b/web3/_utils/module_testing/emitter_contract_old.py index 1cacae0f36..8dee09e6fe 100644 --- a/web3/_utils/module_testing/emitter_contract_old.py +++ b/web3/_utils/module_testing/emitter_contract_old.py @@ -158,517 +158,284 @@ CONTRACT_EMITTER_ABI_OLD = [ { "constant": False, - "inputs": [ - { - "name": "v", - "type": "string" - } - ], + "inputs": [{"name": "v", "type": "string"}], "name": "logString", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, - "inputs": [ - { - "name": "which", - "type": "uint8" - } - ], + "inputs": [{"name": "which", "type": "uint8"}], "name": "logNoArgs", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, "inputs": [ - { - "name": "which", - "type": "uint8" - }, - { - "name": "arg0", - "type": "uint256" - }, - { - "name": "arg1", - "type": "uint256" - }, - { - "name": "arg2", - "type": "uint256" - }, - { - "name": "arg3", - "type": "uint256" - } + {"name": "which", "type": "uint8"}, + {"name": "arg0", "type": "uint256"}, + {"name": "arg1", "type": "uint256"}, + {"name": "arg2", "type": "uint256"}, + {"name": "arg3", "type": "uint256"}, ], "name": "logQuadruple", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, "inputs": [ - { - "name": "which", - "type": "uint8" - }, - { - "name": "arg0", - "type": "uint256" - }, - { - "name": "arg1", - "type": "uint256" - } + {"name": "which", "type": "uint8"}, + {"name": "arg0", "type": "uint256"}, + {"name": "arg1", "type": "uint256"}, ], "name": "logDouble", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, "inputs": [ - { - "name": "arg0", - "type": "bytes2[]" - }, - { - "name": "arg1", - "type": "bytes2[]" - } + {"name": "arg0", "type": "bytes2[]"}, + {"name": "arg1", "type": "bytes2[]"}, ], "name": "logListArgs", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, "inputs": [ - { - "name": "which", - "type": "uint8" - }, - { - "name": "arg0", - "type": "uint256" - }, - { - "name": "arg1", - "type": "uint256" - }, - { - "name": "arg2", - "type": "uint256" - } + {"name": "which", "type": "uint8"}, + {"name": "arg0", "type": "uint256"}, + {"name": "arg1", "type": "uint256"}, + {"name": "arg2", "type": "uint256"}, ], "name": "logTriple", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, "inputs": [ - { - "name": "which", - "type": "uint8" - }, - { - "name": "arg0", - "type": "uint256" - } + {"name": "which", "type": "uint8"}, + {"name": "arg0", "type": "uint256"}, ], "name": "logSingle", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, "inputs": [ - { - "name": "arg0", - "type": "string" - }, - { - "name": "arg1", - "type": "string" - } + {"name": "arg0", "type": "string"}, + {"name": "arg1", "type": "string"}, ], "name": "logDynamicArgs", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, "inputs": [ - { - "name": "arg0", - "type": "address" - }, - { - "name": "arg1", - "type": "address" - } + {"name": "arg0", "type": "address"}, + {"name": "arg1", "type": "address"}, ], "name": "logAddressIndexedArgs", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, - "inputs": [ - { - "name": "v", - "type": "bytes" - } - ], + "inputs": [{"name": "v", "type": "bytes"}], "name": "logBytes", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "constant": False, "inputs": [ - { - "name": "arg0", - "type": "address" - }, - { - "name": "arg1", - "type": "address" - } + {"name": "arg0", "type": "address"}, + {"name": "arg1", "type": "address"}, ], "name": "logAddressNotIndexedArgs", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" - }, - { - "anonymous": True, - "inputs": [], - "name": "LogAnonymous", - "type": "event" - }, - { - "anonymous": False, - "inputs": [], - "name": "LogNoArguments", - "type": "event" + "type": "function", }, + {"anonymous": True, "inputs": [], "name": "LogAnonymous", "type": "event"}, + {"anonymous": False, "inputs": [], "name": "LogNoArguments", "type": "event"}, { "anonymous": False, - "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"indexed": False, "name": "arg0", "type": "uint256"}], "name": "LogSingleArg", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - }, - { - "indexed": False, - "name": "arg1", - "type": "uint256" - } + {"indexed": False, "name": "arg0", "type": "uint256"}, + {"indexed": False, "name": "arg1", "type": "uint256"}, ], "name": "LogDoubleArg", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - }, - { - "indexed": False, - "name": "arg1", - "type": "uint256" - }, - { - "indexed": False, - "name": "arg2", - "type": "uint256" - } + {"indexed": False, "name": "arg0", "type": "uint256"}, + {"indexed": False, "name": "arg1", "type": "uint256"}, + {"indexed": False, "name": "arg2", "type": "uint256"}, ], "name": "LogTripleArg", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - }, - { - "indexed": False, - "name": "arg1", - "type": "uint256" - }, - { - "indexed": False, - "name": "arg2", - "type": "uint256" - }, - { - "indexed": False, - "name": "arg3", - "type": "uint256" - } + {"indexed": False, "name": "arg0", "type": "uint256"}, + {"indexed": False, "name": "arg1", "type": "uint256"}, + {"indexed": False, "name": "arg2", "type": "uint256"}, + {"indexed": False, "name": "arg3", "type": "uint256"}, ], "name": "LogQuadrupleArg", - "type": "event" + "type": "event", }, { "anonymous": False, - "inputs": [ - { - "indexed": False, - "name": "v", - "type": "string" - } - ], + "inputs": [{"indexed": False, "name": "v", "type": "string"}], "name": "LogString", - "type": "event" + "type": "event", }, { "anonymous": False, - "inputs": [ - { - "indexed": False, - "name": "v", - "type": "bytes" - } - ], + "inputs": [{"indexed": False, "name": "v", "type": "bytes"}], "name": "LogBytes", - "type": "event" + "type": "event", }, { "anonymous": False, - "inputs": [ - { - "indexed": True, - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"indexed": True, "name": "arg0", "type": "uint256"}], "name": "LogSingleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": True, - "inputs": [ - { - "indexed": True, - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"indexed": True, "name": "arg0", "type": "uint256"}], "name": "LogSingleAnonymous", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - }, - { - "indexed": True, - "name": "arg1", - "type": "uint256" - } + {"indexed": False, "name": "arg0", "type": "uint256"}, + {"indexed": True, "name": "arg1", "type": "uint256"}, ], "name": "LogDoubleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": True, "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - }, - { - "indexed": True, - "name": "arg1", - "type": "uint256" - } + {"indexed": False, "name": "arg0", "type": "uint256"}, + {"indexed": True, "name": "arg1", "type": "uint256"}, ], "name": "LogDoubleAnonymous", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - }, - { - "indexed": True, - "name": "arg1", - "type": "uint256" - }, - { - "indexed": True, - "name": "arg2", - "type": "uint256" - } + {"indexed": False, "name": "arg0", "type": "uint256"}, + {"indexed": True, "name": "arg1", "type": "uint256"}, + {"indexed": True, "name": "arg2", "type": "uint256"}, ], "name": "LogTripleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - }, - { - "indexed": False, - "name": "arg1", - "type": "uint256" - }, - { - "indexed": True, - "name": "arg2", - "type": "uint256" - }, - { - "indexed": True, - "name": "arg3", - "type": "uint256" - } + {"indexed": False, "name": "arg0", "type": "uint256"}, + {"indexed": False, "name": "arg1", "type": "uint256"}, + {"indexed": True, "name": "arg2", "type": "uint256"}, + {"indexed": True, "name": "arg3", "type": "uint256"}, ], "name": "LogQuadrupleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": True, - "name": "arg0", - "type": "string" - }, - { - "indexed": False, - "name": "arg1", - "type": "string" - } + {"indexed": True, "name": "arg0", "type": "string"}, + {"indexed": False, "name": "arg1", "type": "string"}, ], "name": "LogDynamicArgs", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": True, - "name": "arg0", - "type": "bytes2[]" - }, - { - "indexed": False, - "name": "arg1", - "type": "bytes2[]" - } + {"indexed": True, "name": "arg0", "type": "bytes2[]"}, + {"indexed": False, "name": "arg1", "type": "bytes2[]"}, ], "name": "LogListArgs", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": True, - "name": "arg0", - "type": "address" - }, - { - "indexed": False, - "name": "arg1", - "type": "address" - } + {"indexed": True, "name": "arg0", "type": "address"}, + {"indexed": False, "name": "arg1", "type": "address"}, ], "name": "LogAddressIndexed", - "type": "event" + "type": "event", }, { "anonymous": False, "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "address" - }, - { - "indexed": False, - "name": "arg1", - "type": "address" - } + {"indexed": False, "name": "arg0", "type": "address"}, + {"indexed": False, "name": "arg1", "type": "address"}, ], "name": "LogAddressNotIndexed", - "type": "event" - } + "type": "event", + }, ] EMITTER_ENUM_OLD = { - 'LogAnonymous': 0, - 'LogNoArguments': 1, - 'LogSingleArg': 2, - 'LogDoubleArg': 3, - 'LogTripleArg': 4, - 'LogQuadrupleArg': 5, - 'LogSingleAnonymous': 6, - 'LogSingleWithIndex': 7, - 'LogDoubleAnonymous': 8, - 'LogDoubleWithIndex': 9, - 'LogTripleWithIndex': 10, - 'LogQuadrupleWithInde': 11, + "LogAnonymous": 0, + "LogNoArguments": 1, + "LogSingleArg": 2, + "LogDoubleArg": 3, + "LogTripleArg": 4, + "LogQuadrupleArg": 5, + "LogSingleAnonymous": 6, + "LogSingleWithIndex": 7, + "LogDoubleAnonymous": 8, + "LogDoubleWithIndex": 9, + "LogTripleWithIndex": 10, + "LogQuadrupleWithInde": 11, } diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 7ecdace1d9..ce14cd6565 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -85,13 +85,17 @@ Wei, ) -UNKNOWN_ADDRESS = ChecksumAddress(HexAddress(HexStr('0xdEADBEeF00000000000000000000000000000000'))) +UNKNOWN_ADDRESS = ChecksumAddress( + HexAddress(HexStr("0xdEADBEeF00000000000000000000000000000000")) +) -UNKNOWN_HASH = HexStr('0xdeadbeef00000000000000000000000000000000000000000000000000000000') +UNKNOWN_HASH = HexStr( + "0xdeadbeef00000000000000000000000000000000000000000000000000000000" +) # "test offchain lookup" as an abi-encoded string -OFFCHAIN_LOOKUP_TEST_DATA = '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000' # noqa: E501 +OFFCHAIN_LOOKUP_TEST_DATA = "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001474657374206f6666636861696e206c6f6f6b7570000000000000000000000000" # noqa: E501 # "web3py" as an abi-encoded string -WEB3PY_AS_HEXBYTES = '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067765623370790000000000000000000000000000000000000000000000000000' # noqa: E501 +WEB3PY_AS_HEXBYTES = "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067765623370790000000000000000000000000000000000000000000000000000" # noqa: E501 if TYPE_CHECKING: from web3 import Web3 # noqa: F401 @@ -115,118 +119,118 @@ async def test_eth_send_transaction_legacy( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': await async_w3.eth.gas_price, # type: ignore + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "gasPrice": await async_w3.eth.gas_price, # type: ignore } txn_hash = await async_w3.eth.send_transaction(txn_params) # type: ignore txn = await async_w3.eth.get_transaction(txn_hash) # type: ignore - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['gasPrice'] == txn_params['gasPrice'] + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["gasPrice"] == txn_params["gasPrice"] @pytest.mark.asyncio async def test_eth_send_transaction( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': async_w3.toWei(3, 'gwei'), - 'maxPriorityFeePerGas': async_w3.toWei(1, 'gwei'), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": async_w3.toWei(3, "gwei"), + "maxPriorityFeePerGas": async_w3.toWei(1, "gwei"), } txn_hash = await async_w3.eth.send_transaction(txn_params) # type: ignore txn = await async_w3.eth.get_transaction(txn_hash) # type: ignore - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['maxFeePerGas'] == txn_params['maxFeePerGas'] - assert txn['maxPriorityFeePerGas'] == txn_params['maxPriorityFeePerGas'] - assert txn['gasPrice'] == txn_params['maxFeePerGas'] + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["maxFeePerGas"] == txn_params["maxFeePerGas"] + assert txn["maxPriorityFeePerGas"] == txn_params["maxPriorityFeePerGas"] + assert txn["gasPrice"] == txn_params["maxFeePerGas"] @pytest.mark.asyncio async def test_eth_send_transaction_default_fees( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, } txn_hash = await async_w3.eth.send_transaction(txn_params) # type: ignore txn = await async_w3.eth.get_transaction(txn_hash) # type: ignore - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['maxPriorityFeePerGas'] == 1 * 10**9 - assert txn['maxFeePerGas'] >= 1 * 10**9 - assert txn['gasPrice'] == txn['maxFeePerGas'] + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["maxPriorityFeePerGas"] == 1 * 10**9 + assert txn["maxFeePerGas"] >= 1 * 10**9 + assert txn["gasPrice"] == txn["maxFeePerGas"] @pytest.mark.asyncio async def test_eth_send_transaction_hex_fees( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': hex(250 * 10**9), - 'maxPriorityFeePerGas': hex(2 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": hex(250 * 10**9), + "maxPriorityFeePerGas": hex(2 * 10**9), } txn_hash = await async_w3.eth.send_transaction(txn_params) # type: ignore txn = await async_w3.eth.get_transaction(txn_hash) # type: ignore - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['maxFeePerGas'] == 250 * 10**9 - assert txn['maxPriorityFeePerGas'] == 2 * 10**9 + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["maxFeePerGas"] == 250 * 10**9 + assert txn["maxPriorityFeePerGas"] == 2 * 10**9 @pytest.mark.asyncio async def test_eth_send_transaction_no_gas( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'maxFeePerGas': Wei(250 * 10**9), - 'maxPriorityFeePerGas': Wei(2 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "maxFeePerGas": Wei(250 * 10**9), + "maxPriorityFeePerGas": Wei(2 * 10**9), } txn_hash = await async_w3.eth.send_transaction(txn_params) # type: ignore txn = await async_w3.eth.get_transaction(txn_hash) # type: ignore - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 121000 # 21000 + buffer + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 121000 # 21000 + buffer @pytest.mark.asyncio async def test_eth_send_transaction_with_gas_price( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': Wei(1), - 'maxFeePerGas': Wei(250 * 10**9), - 'maxPriorityFeePerGas': Wei(2 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "gasPrice": Wei(1), + "maxFeePerGas": Wei(250 * 10**9), + "maxPriorityFeePerGas": Wei(2 * 10**9), } with pytest.raises(TransactionTypeMismatch): await async_w3.eth.send_transaction(txn_params) # type: ignore @@ -236,49 +240,51 @@ async def test_eth_send_transaction_no_priority_fee( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': Wei(250 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": Wei(250 * 10**9), } - with pytest.raises(InvalidTransaction, match='maxPriorityFeePerGas must be defined'): + with pytest.raises( + InvalidTransaction, match="maxPriorityFeePerGas must be defined" + ): await async_w3.eth.send_transaction(txn_params) # type: ignore @pytest.mark.asyncio async def test_eth_send_transaction_no_max_fee( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - maxPriorityFeePerGas = async_w3.toWei(2, 'gwei') + maxPriorityFeePerGas = async_w3.toWei(2, "gwei") txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxPriorityFeePerGas': maxPriorityFeePerGas, + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxPriorityFeePerGas": maxPriorityFeePerGas, } txn_hash = await async_w3.eth.send_transaction(txn_params) # type: ignore txn = await async_w3.eth.get_transaction(txn_hash) # type: ignore - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 - block = await async_w3.eth.get_block('latest') # type: ignore - assert txn['maxFeePerGas'] == maxPriorityFeePerGas + 2 * block['baseFeePerGas'] + block = await async_w3.eth.get_block("latest") # type: ignore + assert txn["maxFeePerGas"] == maxPriorityFeePerGas + 2 * block["baseFeePerGas"] @pytest.mark.asyncio async def test_eth_send_transaction_max_fee_less_than_tip( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': Wei(1 * 10**9), - 'maxPriorityFeePerGas': Wei(2 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": Wei(1 * 10**9), + "maxPriorityFeePerGas": Wei(2 * 10**9), } with pytest.raises( InvalidTransaction, match="maxFeePerGas must be >= maxPriorityFeePerGas" @@ -293,38 +299,43 @@ async def test_validation_middleware_chain_id_mismatch( actual_chain_id = await async_w3.eth.chain_id # type: ignore txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': Wei(21000), - 'maxFeePerGas': async_w3.toWei(2, 'gwei'), - 'maxPriorityFeePerGas': async_w3.toWei(1, 'gwei'), - 'chainId': wrong_chain_id, - + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": Wei(21000), + "maxFeePerGas": async_w3.toWei(2, "gwei"), + "maxPriorityFeePerGas": async_w3.toWei(1, "gwei"), + "chainId": wrong_chain_id, } with pytest.raises( ValidationError, - match=f'The transaction declared chain ID {wrong_chain_id}, ' - f'but the connected node is on {actual_chain_id}' + match=f"The transaction declared chain ID {wrong_chain_id}, " + f"but the connected node is on {actual_chain_id}", ): await async_w3.eth.send_transaction(txn_params) # type: ignore @pytest.mark.asyncio async def test_geth_poa_middleware(self, async_w3: "Web3") -> None: - return_block_with_long_extra_data = await async_construct_result_generator_middleware( - { - RPCEndpoint('eth_getBlockByNumber'): lambda *_: {'extraData': '0x' + 'ff' * 33}, - } + return_block_with_long_extra_data = ( + await async_construct_result_generator_middleware( + { + RPCEndpoint("eth_getBlockByNumber"): lambda *_: { + "extraData": "0x" + "ff" * 33 + }, + } + ) + ) + async_w3.middleware_onion.inject(async_geth_poa_middleware, "poa", layer=0) + async_w3.middleware_onion.inject( + return_block_with_long_extra_data, "extradata", layer=0 ) - async_w3.middleware_onion.inject(async_geth_poa_middleware, 'poa', layer=0) - async_w3.middleware_onion.inject(return_block_with_long_extra_data, 'extradata', layer=0) - block = await async_w3.eth.get_block('latest') # type: ignore - assert 'extraData' not in block - assert block.proofOfAuthorityData == b'\xff' * 33 + block = await async_w3.eth.get_block("latest") # type: ignore + assert "extraData" not in block + assert block.proofOfAuthorityData == b"\xff" * 33 # clean up - async_w3.middleware_onion.remove('poa') - async_w3.middleware_onion.remove('extradata') + async_w3.middleware_onion.remove("poa") + async_w3.middleware_onion.remove("extradata") @pytest.mark.asyncio async def test_eth_send_raw_transaction(self, async_w3: "Web3") -> None: @@ -333,8 +344,12 @@ async def test_eth_send_raw_transaction(self, async_w3: "Web3") -> None: # It never needs to be mined, we just want the transaction hash back to confirm. # tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 1, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501 # NOTE: nonce=1 to make txn unique from the non-async version of this test - raw_txn = HexBytes('0xf8650180825208940000000000000000000000000000000000000000808086eecac466e115a0ffdd42d7dee4ac85427468bc616812e49432e285e4e8f5cd9381163ac3b28108a04ec6b0d89ecbd5e89b0399f336ad50f283fafd70e86593250bf5a2adfb93d17e') # noqa: E501 - expected_hash = HexStr('0x52b0ff9cb472f25872fa8ec6a62fa59454fc2ae7901cfcc6cc89d096f49b8fc1') + raw_txn = HexBytes( + "0xf8650180825208940000000000000000000000000000000000000000808086eecac466e115a0ffdd42d7dee4ac85427468bc616812e49432e285e4e8f5cd9381163ac3b28108a04ec6b0d89ecbd5e89b0399f336ad50f283fafd70e86593250bf5a2adfb93d17e" # noqa: E501 + ) + expected_hash = HexStr( + "0x52b0ff9cb472f25872fa8ec6a62fa59454fc2ae7901cfcc6cc89d096f49b8fc1" + ) txn_hash = await async_w3.eth.send_raw_transaction(raw_txn) # type: ignore assert txn_hash == async_w3.toBytes(hexstr=expected_hash) @@ -343,12 +358,12 @@ async def test_gas_price_strategy_middleware( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, } - two_gwei_in_wei = async_w3.toWei(2, 'gwei') + two_gwei_in_wei = async_w3.toWei(2, "gwei") def gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: return two_gwei_in_wei @@ -358,61 +373,71 @@ def gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: txn_hash = await async_w3.eth.send_transaction(txn_params) # type: ignore txn = await async_w3.eth.get_transaction(txn_hash) # type: ignore - assert txn['gasPrice'] == two_gwei_in_wei + assert txn["gasPrice"] == two_gwei_in_wei async_w3.eth.set_gas_price_strategy(None) # reset strategy @pytest.mark.asyncio @pytest.mark.parametrize( - "max_fee", - (1000000000, None), - ids=["with_max_fee", "without_max_fee"] + "max_fee", (1000000000, None), ids=["with_max_fee", "without_max_fee"] ) async def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn( - self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress, max_fee: Wei, + self, + async_w3: "Web3", + unlocked_account_dual_type: ChecksumAddress, + max_fee: Wei, ) -> None: - max_priority_fee = async_w3.toWei(1, 'gwei') + max_priority_fee = async_w3.toWei(1, "gwei") txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxPriorityFeePerGas': max_priority_fee, + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxPriorityFeePerGas": max_priority_fee, } if max_fee is not None: txn_params = assoc(txn_params, "maxFeePerGas", max_fee) def gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: - return async_w3.toWei(2, 'gwei') + return async_w3.toWei(2, "gwei") + async_w3.eth.set_gas_price_strategy(gas_price_strategy) txn_hash = await async_w3.eth.send_transaction(txn_params) # type: ignore txn = await async_w3.eth.get_transaction(txn_hash) # type: ignore - latest_block = await async_w3.eth.get_block('latest') # type: ignore - assert txn['maxFeePerGas'] == max_fee if max_fee is not None \ - else 2 * latest_block['baseFeePerGas'] + max_priority_fee - assert txn['maxPriorityFeePerGas'] == max_priority_fee - assert txn['gasPrice'] == txn['maxFeePerGas'] + latest_block = await async_w3.eth.get_block("latest") # type: ignore + assert ( + txn["maxFeePerGas"] == max_fee + if max_fee is not None + else 2 * latest_block["baseFeePerGas"] + max_priority_fee + ) + assert txn["maxPriorityFeePerGas"] == max_priority_fee + assert txn["gasPrice"] == txn["maxFeePerGas"] async_w3.eth.set_gas_price_strategy(None) # reset strategy @pytest.mark.asyncio async def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip( - self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress, + self, + async_w3: "Web3", + unlocked_account_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': Wei(1000000000), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": Wei(1000000000), } def gas_price_strategy(_w3: "Web3", _txn: TxParams) -> Wei: - return async_w3.toWei(2, 'gwei') + return async_w3.toWei(2, "gwei") + async_w3.eth.set_gas_price_strategy(gas_price_strategy) - with pytest.raises(InvalidTransaction, match="maxPriorityFeePerGas must be defined"): + with pytest.raises( + InvalidTransaction, match="maxPriorityFeePerGas must be defined" + ): await async_w3.eth.send_transaction(txn_params) # type: ignore async_w3.eth.set_gas_price_strategy(None) # reset strategy @@ -421,43 +446,47 @@ def gas_price_strategy(_w3: "Web3", _txn: TxParams) -> Wei: async def test_eth_estimate_gas( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - gas_estimate = await async_w3.eth.estimate_gas({ # type: ignore - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - }) + gas_estimate = await async_w3.eth.estimate_gas( + { # type: ignore + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + } + ) assert is_integer(gas_estimate) assert gas_estimate > 0 @pytest.mark.asyncio async def test_eth_fee_history(self, async_w3: "Web3") -> None: - fee_history = await async_w3.eth.fee_history(1, 'latest', [50]) # type: ignore - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - assert is_list_like(fee_history['reward']) - assert is_list_like(fee_history['reward'][0]) + fee_history = await async_w3.eth.fee_history(1, "latest", [50]) # type: ignore + assert is_list_like(fee_history["baseFeePerGas"]) + assert is_list_like(fee_history["gasUsedRatio"]) + assert is_integer(fee_history["oldestBlock"]) + assert fee_history["oldestBlock"] >= 0 + assert is_list_like(fee_history["reward"]) + assert is_list_like(fee_history["reward"][0]) @pytest.mark.asyncio async def test_eth_fee_history_with_integer( self, async_w3: "Web3", empty_block: BlockData ) -> None: - fee_history = await async_w3.eth.fee_history(1, empty_block['number'], [50]) # type: ignore - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - assert is_list_like(fee_history['reward']) - assert is_list_like(fee_history['reward'][0]) + fee_history = await async_w3.eth.fee_history(1, empty_block["number"], [50]) # type: ignore + assert is_list_like(fee_history["baseFeePerGas"]) + assert is_list_like(fee_history["gasUsedRatio"]) + assert is_integer(fee_history["oldestBlock"]) + assert fee_history["oldestBlock"] >= 0 + assert is_list_like(fee_history["reward"]) + assert is_list_like(fee_history["reward"][0]) @pytest.mark.asyncio - async def test_eth_fee_history_no_reward_percentiles(self, async_w3: "Web3") -> None: - fee_history = await async_w3.eth.fee_history(1, 'latest') # type: ignore - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 + async def test_eth_fee_history_no_reward_percentiles( + self, async_w3: "Web3" + ) -> None: + fee_history = await async_w3.eth.fee_history(1, "latest") # type: ignore + assert is_list_like(fee_history["baseFeePerGas"]) + assert is_list_like(fee_history["gasUsedRatio"]) + assert is_integer(fee_history["oldestBlock"]) + assert fee_history["oldestBlock"] >= 0 @pytest.mark.asyncio async def test_eth_max_priority_fee(self, async_w3: "Web3") -> None: @@ -469,26 +498,28 @@ async def test_eth_max_priority_fee_with_fee_history_calculation( self, async_w3: "Web3" ) -> None: fail_max_prio_middleware = await async_construct_error_generator_middleware( - {RPCEndpoint("eth_maxPriorityFeePerGas"): lambda *_: ''} + {RPCEndpoint("eth_maxPriorityFeePerGas"): lambda *_: ""} + ) + async_w3.middleware_onion.add( + fail_max_prio_middleware, name="fail_max_prio_middleware" ) - async_w3.middleware_onion.add(fail_max_prio_middleware, name='fail_max_prio_middleware') with pytest.warns( UserWarning, match="There was an issue with the method eth_maxPriorityFeePerGas. Calculating using " - "eth_feeHistory." + "eth_feeHistory.", ): max_priority_fee = await async_w3.eth.max_priority_fee # type: ignore assert is_integer(max_priority_fee) - async_w3.middleware_onion.remove('fail_max_prio_middleware') # clean up + async_w3.middleware_onion.remove("fail_max_prio_middleware") # clean up @pytest.mark.asyncio async def test_eth_getBlockByHash( self, async_w3: "Web3", empty_block: BlockData ) -> None: - block = await async_w3.eth.get_block(empty_block['hash']) # type: ignore - assert block['hash'] == empty_block['hash'] + block = await async_w3.eth.get_block(empty_block["hash"]) # type: ignore + assert block["hash"] == empty_block["hash"] @pytest.mark.asyncio async def test_eth_getBlockByHash_not_found(self, async_w3: "Web3") -> None: @@ -496,26 +527,24 @@ async def test_eth_getBlockByHash_not_found(self, async_w3: "Web3") -> None: await async_w3.eth.get_block(UNKNOWN_HASH) # type: ignore @pytest.mark.asyncio - async def test_eth_getBlockByHash_pending( - self, async_w3: "Web3" - ) -> None: - block = await async_w3.eth.get_block('pending') # type: ignore - assert block['hash'] is None + async def test_eth_getBlockByHash_pending(self, async_w3: "Web3") -> None: + block = await async_w3.eth.get_block("pending") # type: ignore + assert block["hash"] is None @pytest.mark.asyncio async def test_eth_getBlockByNumber_with_integer( self, async_w3: "Web3", empty_block: BlockData ) -> None: - block = await async_w3.eth.get_block(empty_block['number']) # type: ignore - assert block['number'] == empty_block['number'] + block = await async_w3.eth.get_block(empty_block["number"]) # type: ignore + assert block["number"] == empty_block["number"] @pytest.mark.asyncio async def test_eth_getBlockByNumber_latest( self, async_w3: "Web3", empty_block: BlockData ) -> None: current_block_number = await async_w3.eth.block_number # type: ignore - block = await async_w3.eth.get_block('latest') # type: ignore - assert block['number'] == current_block_number + block = await async_w3.eth.get_block("latest") # type: ignore + assert block["number"] == current_block_number @pytest.mark.asyncio async def test_eth_getBlockByNumber_not_found( @@ -529,25 +558,25 @@ async def test_eth_getBlockByNumber_pending( self, async_w3: "Web3", empty_block: BlockData ) -> None: current_block_number = await async_w3.eth.block_number # type: ignore - block = await async_w3.eth.get_block('pending') # type: ignore - assert block['number'] == current_block_number + 1 + block = await async_w3.eth.get_block("pending") # type: ignore + assert block["number"] == current_block_number + 1 @pytest.mark.asyncio async def test_eth_getBlockByNumber_earliest( self, async_w3: "Web3", empty_block: BlockData ) -> None: genesis_block = await async_w3.eth.get_block(BlockNumber(0)) # type: ignore - block = await async_w3.eth.get_block('earliest') # type: ignore - assert block['number'] == 0 - assert block['hash'] == genesis_block['hash'] + block = await async_w3.eth.get_block("earliest") # type: ignore + assert block["number"] == 0 + assert block["hash"] == genesis_block["hash"] @pytest.mark.asyncio async def test_eth_getBlockByNumber_full_transactions( self, async_w3: "Web3", block_with_txn: BlockData ) -> None: - block = await async_w3.eth.get_block(block_with_txn['number'], True) # type: ignore - transaction = block['transactions'][0] - assert transaction['hash'] == block_with_txn['transactions'][0] + block = await async_w3.eth.get_block(block_with_txn["number"], True) # type: ignore + transaction = block["transactions"][0] + assert transaction["hash"] == block_with_txn["transactions"][0] @pytest.mark.asyncio async def test_eth_get_raw_transaction( @@ -558,7 +587,9 @@ async def test_eth_get_raw_transaction( @pytest.mark.asyncio async def test_eth_get_raw_transaction_raises_error(self, async_w3: "Web3") -> None: - with pytest.raises(TransactionNotFound, match=f"Transaction with hash: '{UNKNOWN_HASH}'"): + with pytest.raises( + TransactionNotFound, match=f"Transaction with hash: '{UNKNOWN_HASH}'" + ): await async_w3.eth.get_raw_transaction(UNKNOWN_HASH) # type: ignore @pytest.mark.asyncio @@ -566,48 +597,52 @@ async def test_eth_get_raw_transaction_by_block( self, async_w3: "Web3", block_with_txn: BlockData, - unlocked_account_dual_type: ChecksumAddress + unlocked_account_dual_type: ChecksumAddress, ) -> None: # eth_getRawTransactionByBlockNumberAndIndex: block identifier # send a txn to make sure pending block has at least one txn await async_w3.eth.send_transaction( # type: ignore { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), } ) - pending_block = await async_w3.eth.get_block('pending') # type: ignore - last_pending_txn_index = len(pending_block['transactions']) - 1 + pending_block = await async_w3.eth.get_block("pending") # type: ignore + last_pending_txn_index = len(pending_block["transactions"]) - 1 raw_txn = await async_w3.eth.get_raw_transaction_by_block( # type: ignore - 'pending', last_pending_txn_index + "pending", last_pending_txn_index ) assert is_bytes(raw_txn) # eth_getRawTransactionByBlockNumberAndIndex: block number - block_with_txn_number = block_with_txn['number'] + block_with_txn_number = block_with_txn["number"] raw_transaction = await async_w3.eth.get_raw_transaction_by_block( # type: ignore block_with_txn_number, 0 ) assert is_bytes(raw_transaction) # eth_getRawTransactionByBlockHashAndIndex: block hash - block_with_txn_hash = block_with_txn['hash'] + block_with_txn_hash = block_with_txn["hash"] raw_transaction = await async_w3.eth.get_raw_transaction_by_block( # type: ignore block_with_txn_hash, 0 ) assert is_bytes(raw_transaction) @pytest.mark.asyncio - @pytest.mark.parametrize('unknown_block_num_or_hash', (1234567899999, UNKNOWN_HASH)) + @pytest.mark.parametrize("unknown_block_num_or_hash", (1234567899999, UNKNOWN_HASH)) async def test_eth_get_raw_transaction_by_block_raises_error( self, async_w3: "Web3", unknown_block_num_or_hash: Union[int, HexBytes] ) -> None: - with pytest.raises(TransactionNotFound, match=( - f"Transaction index: 0 on block id: {to_hex_if_integer(unknown_block_num_or_hash)!r} " - f"not found." - )): - await async_w3.eth.get_raw_transaction_by_block( # type: ignore + with pytest.raises( + TransactionNotFound, + match=( + f"Transaction index: 0 on block id: " + f"{to_hex_if_integer(unknown_block_num_or_hash)!r} " + f"not found." + ), + ): + await async_w3.eth.get_raw_transaction_by_block( # type: ignore unknown_block_num_or_hash, 0 ) @@ -617,9 +652,10 @@ async def test_eth_get_raw_transaction_by_block_raises_error_block_identifier( ) -> None: unknown_identifier = "unknown" with pytest.raises( - ValueError, match=( + ValueError, + match=( f"Value did not match any of the recognized block identifiers: {unknown_identifier}" - ) + ), ): await async_w3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore @@ -672,18 +708,16 @@ async def test_eth_get_transaction_count( assert transaction_count >= 0 @pytest.mark.asyncio - async def test_eth_call( - self, async_w3: "Web3", math_contract: "Contract" - ) -> None: + async def test_eth_call(self, async_w3: "Web3", math_contract: "Contract") -> None: coinbase = await async_w3.eth.coinbase # type: ignore txn_params = math_contract._prepare_transaction( - fn_name='add', + fn_name="add", fn_args=(7, 11), - transaction={'from': coinbase, 'to': math_contract.address}, + transaction={"from": coinbase, "to": math_contract.address}, ) call_result = await async_w3.eth.call(txn_params) # type: ignore assert is_string(call_result) - result = async_w3.codec.decode_single('uint256', call_result) + result = async_w3.codec.decode_single("uint256", call_result) assert result == 18 @pytest.mark.asyncio @@ -692,21 +726,21 @@ async def test_eth_call_with_override( ) -> None: coinbase = await async_w3.eth.coinbase # type: ignore txn_params = revert_contract._prepare_transaction( - fn_name='normalFunction', - transaction={'from': coinbase, 'to': revert_contract.address}, + fn_name="normalFunction", + transaction={"from": coinbase, "to": revert_contract.address}, ) call_result = await async_w3.eth.call(txn_params) # type: ignore - result = async_w3.codec.decode_single('bool', call_result) + result = async_w3.codec.decode_single("bool", call_result) assert result is True # override runtime bytecode: `normalFunction` returns `false` - override_code = HexStr('0x6080604052348015600f57600080fd5b5060043610603c5760003560e01c8063185c38a4146041578063c06a97cb146049578063d67e4b84146051575b600080fd5b60476071565b005b604f60df565b005b605760e4565b604051808215151515815260200191505060405180910390f35b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f46756e6374696f6e20686173206265656e2072657665727465642e000000000081525060200191505060405180910390fd5b600080fd5b60008090509056fea2646970667358221220bb71e9e9a2e271cd0fbe833524a3ea67df95f25ea13aef5b0a761fa52b538f1064736f6c63430006010033') # noqa: E501 + override_code = HexStr( + "0x6080604052348015600f57600080fd5b5060043610603c5760003560e01c8063185c38a4146041578063c06a97cb146049578063d67e4b84146051575b600080fd5b60476071565b005b604f60df565b005b605760e4565b604051808215151515815260200191505060405180910390f35b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f46756e6374696f6e20686173206265656e2072657665727465642e000000000081525060200191505060405180910390fd5b600080fd5b60008090509056fea2646970667358221220bb71e9e9a2e271cd0fbe833524a3ea67df95f25ea13aef5b0a761fa52b538f1064736f6c63430006010033" # noqa: E501 + ) call_result = await async_w3.eth.call( # type: ignore - txn_params, - 'latest', - {revert_contract.address: {'code': override_code}} + txn_params, "latest", {revert_contract.address: {"code": override_code}} ) - result = async_w3.codec.decode_single('bool', call_result) + result = async_w3.codec.decode_single("bool", call_result) assert result is False @pytest.mark.asyncio @@ -715,13 +749,13 @@ async def test_eth_call_with_0_result( ) -> None: coinbase = await async_w3.eth.coinbase # type: ignore txn_params = math_contract._prepare_transaction( - fn_name='add', + fn_name="add", fn_args=(0, 0), - transaction={'from': coinbase, 'to': math_contract.address}, + transaction={"from": coinbase, "to": math_contract.address}, ) call_result = await async_w3.eth.call(txn_params) # type: ignore assert is_string(call_result) - result = async_w3.codec.decode_single('uint256', call_result) + result = async_w3.codec.decode_single("uint256", call_result) assert result == 0 @pytest.mark.asyncio @@ -731,8 +765,9 @@ async def test_eth_call_revert_with_msg( revert_contract: "Contract", unlocked_account: ChecksumAddress, ) -> None: - with pytest.raises(ContractLogicError, - match='execution reverted: Function has been reverted'): + with pytest.raises( + ContractLogicError, match="execution reverted: Function has been reverted" + ): txn_params = revert_contract._prepare_transaction( fn_name="revertWithMessage", transaction={ @@ -773,7 +808,7 @@ async def test_eth_call_offchain_lookup( async_mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_json_data=WEB3PY_AS_HEXBYTES, ) response_caller = await async_offchain_lookup_contract.caller().testOffchainLookup( # noqa: E501 type: ignore @@ -782,16 +817,22 @@ async def test_eth_call_offchain_lookup( response_function_call = await async_offchain_lookup_contract.functions.testOffchainLookup( # noqa: E501 type: ignore OFFCHAIN_LOOKUP_TEST_DATA ).call() - assert async_w3.codec.decode_abi(['string'], response_caller)[0] == 'web3py' - assert async_w3.codec.decode_abi(['string'], response_function_call)[0] == 'web3py' + assert async_w3.codec.decode_abi(["string"], response_caller)[0] == "web3py" + assert ( + async_w3.codec.decode_abi(["string"], response_function_call)[0] == "web3py" + ) @pytest.mark.asyncio async def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled( - self, async_w3: "Web3", async_offchain_lookup_contract: "Contract", + self, + async_w3: "Web3", + async_offchain_lookup_contract: "Contract", ) -> None: # test AsyncContractCaller with pytest.raises(OffchainLookup): - await async_offchain_lookup_contract.caller(ccip_read_enabled=False).testOffchainLookup( # noqa: E501 type: ignore + await async_offchain_lookup_contract.caller( + ccip_read_enabled=False + ).testOffchainLookup( # noqa: E501 type: ignore OFFCHAIN_LOOKUP_TEST_DATA ) @@ -825,7 +866,7 @@ async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag( async_mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_json_data=WEB3PY_AS_HEXBYTES, ) @@ -835,7 +876,7 @@ async def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag( # noqa: E501 type: ignore OFFCHAIN_LOOKUP_TEST_DATA ).call(ccip_read_enabled=True) - assert async_w3.codec.decode_abi(['string'], response)[0] == 'web3py' + assert async_w3.codec.decode_abi(["string"], response)[0] == "web3py" async_w3.provider.global_ccip_read_enabled = True # cleanup @@ -871,9 +912,9 @@ async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_req async_mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_json_data=WEB3PY_AS_HEXBYTES, - json_data_field='not_data', + json_data_field="not_data", ) with pytest.raises(ValidationError, match="missing 'data' field"): await async_offchain_lookup_contract.caller().testOffchainLookup( @@ -881,7 +922,7 @@ async def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_req ) @pytest.mark.asyncio - @pytest.mark.parametrize('status_code_non_4xx_error', [100, 300, 500, 600]) + @pytest.mark.parametrize("status_code_non_4xx_error", [100, 300, 500, 600]) async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( self, async_w3: "Web3", @@ -900,14 +941,14 @@ async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_ # non-4xx status and that the POST logic is also working as expected. async_mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_status_code=status_code_non_4xx_error, mocked_json_data=WEB3PY_AS_HEXBYTES, ) async_mock_offchain_lookup_request_response( monkeypatch, - http_method='POST', - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}.json', + http_method="POST", + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}.json", mocked_status_code=200, mocked_json_data=WEB3PY_AS_HEXBYTES, sender=normalized_contract_address, @@ -916,7 +957,7 @@ async def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_ response = await async_offchain_lookup_contract.caller().testOffchainLookup( OFFCHAIN_LOOKUP_TEST_DATA ) - assert async_w3.codec.decode_abi(['string'], response)[0] == 'web3py' + assert async_w3.codec.decode_abi(["string"], response)[0] == "web3py" @pytest.mark.asyncio async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code( @@ -932,7 +973,7 @@ async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_co async_mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_status_code=randint(400, 499), mocked_json_data=WEB3PY_AS_HEXBYTES, ) @@ -943,7 +984,9 @@ async def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_co @pytest.mark.asyncio async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail( - self, async_w3: "Web3", async_offchain_lookup_contract: "Contract", + self, + async_w3: "Web3", + async_offchain_lookup_contract: "Contract", ) -> None: # GET and POST requests should fail since responses are not mocked with pytest.raises( @@ -967,55 +1010,43 @@ async def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests async_mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/0x.json', + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/0x.json", ) with pytest.raises(TooManyRequests, match="Too many CCIP read redirects"): await async_offchain_lookup_contract.caller().continuousOffchainLookup() # noqa: E501 type: ignore @pytest.mark.asyncio - async def test_async_eth_hashrate( - self, - async_w3: "Web3" - ) -> None: + async def test_async_eth_hashrate(self, async_w3: "Web3") -> None: hashrate = await async_w3.eth.hashrate # type: ignore assert is_integer(hashrate) assert hashrate >= 0 @pytest.mark.asyncio - async def test_async_eth_chain_id( - self, - async_w3: "Web3" - ) -> None: + async def test_async_eth_chain_id(self, async_w3: "Web3") -> None: chain_id = await async_w3.eth.chain_id # type: ignore # chain id value from geth fixture genesis file assert chain_id == 131277322940537 @pytest.mark.asyncio - async def test_async_eth_mining( - self, - async_w3: "Web3" - ) -> None: + async def test_async_eth_mining(self, async_w3: "Web3") -> None: mining = await async_w3.eth.mining # type: ignore assert is_boolean(mining) @pytest.mark.asyncio async def test_async_eth_get_transaction_receipt_mined( - self, - async_w3: "Web3", - block_with_txn: BlockData, - mined_txn_hash: HexStr + self, async_w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: receipt = await async_w3.eth.get_transaction_receipt(mined_txn_hash) # type: ignore assert is_dict(receipt) - assert receipt['blockNumber'] == block_with_txn['number'] - assert receipt['blockHash'] == block_with_txn['hash'] - assert receipt['transactionIndex'] == 0 - assert receipt['transactionHash'] == HexBytes(mined_txn_hash) - assert is_checksum_address(receipt['to']) - assert receipt['from'] is not None - assert is_checksum_address(receipt['from']) - - effective_gas_price = receipt['effectiveGasPrice'] + assert receipt["blockNumber"] == block_with_txn["number"] + assert receipt["blockHash"] == block_with_txn["hash"] + assert receipt["transactionIndex"] == 0 + assert receipt["transactionHash"] == HexBytes(mined_txn_hash) + assert is_checksum_address(receipt["to"]) + assert receipt["from"] is not None + assert is_checksum_address(receipt["from"]) + + effective_gas_price = receipt["effectiveGasPrice"] assert isinstance(effective_gas_price, int) assert effective_gas_price > 0 @@ -1023,14 +1054,16 @@ async def test_async_eth_get_transaction_receipt_mined( async def test_async_eth_get_transaction_receipt_unmined( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - txn_hash = await async_w3.eth.send_transaction({ # type: ignore - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': async_w3.toWei(3, 'gwei'), - 'maxPriorityFeePerGas': async_w3.toWei(1, 'gwei') - }) + txn_hash = await async_w3.eth.send_transaction( + { # type: ignore + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": async_w3.toWei(3, "gwei"), + "maxPriorityFeePerGas": async_w3.toWei(1, "gwei"), + } + ) with pytest.raises(TransactionNotFound): await async_w3.eth.get_transaction_receipt(txn_hash) # type: ignore @@ -1044,39 +1077,36 @@ async def test_async_eth_get_transaction_receipt_with_log_entry( ) -> None: receipt = await async_w3.eth.wait_for_transaction_receipt(txn_hash_with_log) # type: ignore assert is_dict(receipt) - assert receipt['blockNumber'] == block_with_txn_with_log['number'] - assert receipt['blockHash'] == block_with_txn_with_log['hash'] - assert receipt['transactionIndex'] == 0 - assert receipt['transactionHash'] == HexBytes(txn_hash_with_log) + assert receipt["blockNumber"] == block_with_txn_with_log["number"] + assert receipt["blockHash"] == block_with_txn_with_log["hash"] + assert receipt["transactionIndex"] == 0 + assert receipt["transactionHash"] == HexBytes(txn_hash_with_log) - assert len(receipt['logs']) == 1 - log_entry = receipt['logs'][0] + assert len(receipt["logs"]) == 1 + log_entry = receipt["logs"][0] - assert log_entry['blockNumber'] == block_with_txn_with_log['number'] - assert log_entry['blockHash'] == block_with_txn_with_log['hash'] - assert log_entry['logIndex'] == 0 - assert is_same_address(log_entry['address'], emitter_contract.address) - assert log_entry['transactionIndex'] == 0 - assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log) + assert log_entry["blockNumber"] == block_with_txn_with_log["number"] + assert log_entry["blockHash"] == block_with_txn_with_log["hash"] + assert log_entry["logIndex"] == 0 + assert is_same_address(log_entry["address"], emitter_contract.address) + assert log_entry["transactionIndex"] == 0 + assert log_entry["transactionHash"] == HexBytes(txn_hash_with_log) @pytest.mark.asyncio async def test_async_eth_wait_for_transaction_receipt_mined( - self, - async_w3: "Web3", - block_with_txn: BlockData, - mined_txn_hash: HexStr + self, async_w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: receipt = await async_w3.eth.wait_for_transaction_receipt(mined_txn_hash) # type: ignore assert is_dict(receipt) - assert receipt['blockNumber'] == block_with_txn['number'] - assert receipt['blockHash'] == block_with_txn['hash'] - assert receipt['transactionIndex'] == 0 - assert receipt['transactionHash'] == HexBytes(mined_txn_hash) - assert is_checksum_address(receipt['to']) - assert receipt['from'] is not None - assert is_checksum_address(receipt['from']) - - effective_gas_price = receipt['effectiveGasPrice'] + assert receipt["blockNumber"] == block_with_txn["number"] + assert receipt["blockHash"] == block_with_txn["hash"] + assert receipt["transactionIndex"] == 0 + assert receipt["transactionHash"] == HexBytes(mined_txn_hash) + assert is_checksum_address(receipt["to"]) + assert receipt["from"] is not None + assert is_checksum_address(receipt["from"]) + + effective_gas_price = receipt["effectiveGasPrice"] assert isinstance(effective_gas_price, int) assert effective_gas_price > 0 @@ -1084,19 +1114,22 @@ async def test_async_eth_wait_for_transaction_receipt_mined( async def test_async_eth_wait_for_transaction_receipt_unmined( self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - txn_hash = await async_w3.eth.send_transaction({ # type: ignore - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': async_w3.toWei(3, 'gwei'), - 'maxPriorityFeePerGas': async_w3.toWei(1, 'gwei') - }) + txn_hash = await async_w3.eth.send_transaction( + { # type: ignore + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": async_w3.toWei(3, "gwei"), + "maxPriorityFeePerGas": async_w3.toWei(1, "gwei"), + } + ) timeout = 2 with pytest.raises(TimeExhausted) as exc_info: - await async_w3.eth.wait_for_transaction_receipt(txn_hash, # type: ignore - timeout=timeout) + await async_w3.eth.wait_for_transaction_receipt( + txn_hash, timeout=timeout # type: ignore + ) assert (_ in str(exc_info) for _ in [repr(txn_hash), timeout]) @@ -1110,31 +1143,27 @@ async def test_async_eth_wait_for_transaction_receipt_with_log_entry( ) -> None: receipt = await async_w3.eth.wait_for_transaction_receipt(txn_hash_with_log) # type: ignore assert is_dict(receipt) - assert receipt['blockNumber'] == block_with_txn_with_log['number'] - assert receipt['blockHash'] == block_with_txn_with_log['hash'] - assert receipt['transactionIndex'] == 0 - assert receipt['transactionHash'] == HexBytes(txn_hash_with_log) + assert receipt["blockNumber"] == block_with_txn_with_log["number"] + assert receipt["blockHash"] == block_with_txn_with_log["hash"] + assert receipt["transactionIndex"] == 0 + assert receipt["transactionHash"] == HexBytes(txn_hash_with_log) - assert len(receipt['logs']) == 1 - log_entry = receipt['logs'][0] + assert len(receipt["logs"]) == 1 + log_entry = receipt["logs"][0] - assert log_entry['blockNumber'] == block_with_txn_with_log['number'] - assert log_entry['blockHash'] == block_with_txn_with_log['hash'] - assert log_entry['logIndex'] == 0 - assert is_same_address(log_entry['address'], emitter_contract.address) - assert log_entry['transactionIndex'] == 0 - assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log) + assert log_entry["blockNumber"] == block_with_txn_with_log["number"] + assert log_entry["blockHash"] == block_with_txn_with_log["hash"] + assert log_entry["logIndex"] == 0 + assert is_same_address(log_entry["address"], emitter_contract.address) + assert log_entry["transactionIndex"] == 0 + assert log_entry["transactionHash"] == HexBytes(txn_hash_with_log) @pytest.mark.asyncio async def test_async_eth_accounts(self, async_w3: "Web3") -> None: accounts = await async_w3.eth.accounts # type: ignore assert is_list_like(accounts) assert len(accounts) != 0 - assert all(( - is_checksum_address(account) - for account - in accounts - )) + assert all((is_checksum_address(account) for account in accounts)) assert await async_w3.eth.coinbase in accounts # type: ignore @pytest.mark.asyncio @@ -1145,15 +1174,15 @@ async def test_async_eth_get_logs_without_logs( filter_params: FilterParams = { "fromBlock": BlockNumber(0), - "toBlock": BlockNumber(block_with_txn_with_log['number'] - 1), + "toBlock": BlockNumber(block_with_txn_with_log["number"] - 1), } result = await async_w3.eth.get_logs(filter_params) # type: ignore assert len(result) == 0 # the range is wrong filter_params = { - "fromBlock": block_with_txn_with_log['number'], - "toBlock": BlockNumber(block_with_txn_with_log['number'] - 1), + "fromBlock": block_with_txn_with_log["number"], + "toBlock": BlockNumber(block_with_txn_with_log["number"] - 1), } result = await async_w3.eth.get_logs(filter_params) # type: ignore assert len(result) == 0 @@ -1191,15 +1220,12 @@ async def test_async_eth_get_logs_with_logs( # the range includes the block where the log resides in filter_params: FilterParams = { - "fromBlock": block_with_txn_with_log['number'], - "toBlock": block_with_txn_with_log['number'], + "fromBlock": block_with_txn_with_log["number"], + "toBlock": block_with_txn_with_log["number"], } result = await async_w3.eth.get_logs(filter_params) # type: ignore assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) # specify only `from_block`. by default `to_block` should be 'latest' @@ -1208,10 +1234,7 @@ async def test_async_eth_get_logs_with_logs( } result = await async_w3.eth.get_logs(filter_params) # type: ignore assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) # Test with `address` @@ -1223,10 +1246,7 @@ async def test_async_eth_get_logs_with_logs( } result = await async_w3.eth.get_logs(filter_params) # type: ignore assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) @pytest.mark.asyncio @@ -1244,34 +1264,36 @@ async def test_async_eth_get_logs_with_logs_topic_args( "fromBlock": BlockNumber(0), "topics": [ None, - HexStr('0x000000000000000000000000000000000000000000000000000000000000d431')], + HexStr( + "0x000000000000000000000000000000000000000000000000000000000000d431" + ), + ], } result = await async_w3.eth.get_logs(filter_params) # type: ignore assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) # Test with None indexed arg filter_params = { "fromBlock": BlockNumber(0), "topics": [ - HexStr('0x057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca'), - None], + HexStr( + "0x057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca" + ), + None, + ], } result = await async_w3.eth.get_logs(filter_params) # type: ignore assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) @pytest.mark.asyncio - async def test_async_eth_get_logs_with_logs_none_topic_args(self, async_w3: "Web3") -> None: + async def test_async_eth_get_logs_with_logs_none_topic_args( + self, async_w3: "Web3" + ) -> None: # Test with None overflowing filter_params: FilterParams = { "fromBlock": BlockNumber(0), @@ -1291,13 +1313,13 @@ async def test_async_eth_syncing(self, async_w3: "Web3") -> None: assert syncing is False elif is_dict(syncing): sync_dict = cast(SyncStatus, syncing) - assert 'startingBlock' in sync_dict - assert 'currentBlock' in sync_dict - assert 'highestBlock' in sync_dict + assert "startingBlock" in sync_dict + assert "currentBlock" in sync_dict + assert "highestBlock" in sync_dict - assert is_integer(sync_dict['startingBlock']) - assert is_integer(sync_dict['currentBlock']) - assert is_integer(sync_dict['highestBlock']) + assert is_integer(sync_dict["startingBlock"]) + assert is_integer(sync_dict["currentBlock"]) + assert is_integer(sync_dict["highestBlock"]) @pytest.mark.asyncio async def test_async_eth_get_storage_at( @@ -1311,22 +1333,22 @@ async def test_async_eth_get_storage_at( async def test_async_eth_get_storage_at_ens_name( self, async_w3: "Web3", emitter_contract_address: ChecksumAddress ) -> None: - with ens_addresses(async_w3, {'emitter.eth': emitter_contract_address}): - storage = await async_w3.eth.get_storage_at('emitter.eth', 0) # type: ignore + with ens_addresses(async_w3, {"emitter.eth": emitter_contract_address}): + storage = await async_w3.eth.get_storage_at("emitter.eth", 0) # type: ignore assert isinstance(storage, HexBytes) @pytest.mark.asyncio - async def test_async_eth_get_storage_at_invalid_address(self, async_w3: "Web3") -> None: + async def test_async_eth_get_storage_at_invalid_address( + self, async_w3: "Web3" + ) -> None: coinbase = await async_w3.eth.coinbase # type: ignore with pytest.raises(InvalidAddress): await async_w3.eth.get_storage_at( - ChecksumAddress(HexAddress(HexStr(coinbase.lower()))), - 0) # type: ignore + ChecksumAddress(HexAddress(HexStr(coinbase.lower()))), 0 + ) # type: ignore def test_async_provider_default_account( - self, - async_w3: "Web3", - unlocked_account_dual_type: ChecksumAddress + self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: # check defaults to empty @@ -1348,7 +1370,7 @@ def test_async_provider_default_block( # check defaults to 'latest' default_block = async_w3.eth.default_block - assert default_block == 'latest' + assert default_block == "latest" # check setter async_w3.eth.default_block = BlockNumber(12345) @@ -1356,11 +1378,10 @@ def test_async_provider_default_block( assert default_block == BlockNumber(12345) # reset to default - async_w3.eth.default_block = 'latest' + async_w3.eth.default_block = "latest" class EthModuleTest: - def test_eth_syncing(self, w3: "Web3") -> None: syncing = w3.eth.syncing @@ -1370,13 +1391,13 @@ def test_eth_syncing(self, w3: "Web3") -> None: assert syncing is False elif is_dict(syncing): sync_dict = cast(SyncStatus, syncing) - assert 'startingBlock' in sync_dict - assert 'currentBlock' in sync_dict - assert 'highestBlock' in sync_dict + assert "startingBlock" in sync_dict + assert "currentBlock" in sync_dict + assert "highestBlock" in sync_dict - assert is_integer(sync_dict['startingBlock']) - assert is_integer(sync_dict['currentBlock']) - assert is_integer(sync_dict['highestBlock']) + assert is_integer(sync_dict["startingBlock"]) + assert is_integer(sync_dict["currentBlock"]) + assert is_integer(sync_dict["highestBlock"]) def test_eth_coinbase(self, w3: "Web3") -> None: coinbase = w3.eth.coinbase @@ -1397,31 +1418,31 @@ def test_eth_chain_id(self, w3: "Web3") -> None: assert chain_id == 131277322940537 def test_eth_fee_history(self, w3: "Web3") -> None: - fee_history = w3.eth.fee_history(1, 'latest', [50]) - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - assert is_list_like(fee_history['reward']) - assert is_list_like(fee_history['reward'][0]) - - def test_eth_fee_history_with_integer(self, - w3: "Web3", - empty_block: BlockData) -> None: - fee_history = w3.eth.fee_history(1, empty_block['number'], [50]) - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - assert is_list_like(fee_history['reward']) - assert is_list_like(fee_history['reward'][0]) + fee_history = w3.eth.fee_history(1, "latest", [50]) + assert is_list_like(fee_history["baseFeePerGas"]) + assert is_list_like(fee_history["gasUsedRatio"]) + assert is_integer(fee_history["oldestBlock"]) + assert fee_history["oldestBlock"] >= 0 + assert is_list_like(fee_history["reward"]) + assert is_list_like(fee_history["reward"][0]) + + def test_eth_fee_history_with_integer( + self, w3: "Web3", empty_block: BlockData + ) -> None: + fee_history = w3.eth.fee_history(1, empty_block["number"], [50]) + assert is_list_like(fee_history["baseFeePerGas"]) + assert is_list_like(fee_history["gasUsedRatio"]) + assert is_integer(fee_history["oldestBlock"]) + assert fee_history["oldestBlock"] >= 0 + assert is_list_like(fee_history["reward"]) + assert is_list_like(fee_history["reward"][0]) def test_eth_fee_history_no_reward_percentiles(self, w3: "Web3") -> None: - fee_history = w3.eth.fee_history(1, 'latest') - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 + fee_history = w3.eth.fee_history(1, "latest") + assert is_list_like(fee_history["baseFeePerGas"]) + assert is_list_like(fee_history["gasUsedRatio"]) + assert is_integer(fee_history["oldestBlock"]) + assert fee_history["oldestBlock"] >= 0 def test_eth_gas_price(self, w3: "Web3") -> None: gas_price = w3.eth.gas_price @@ -1432,31 +1453,31 @@ def test_eth_max_priority_fee(self, w3: "Web3") -> None: max_priority_fee = w3.eth.max_priority_fee assert is_integer(max_priority_fee) - def test_eth_max_priority_fee_with_fee_history_calculation(self, w3: "Web3") -> None: + def test_eth_max_priority_fee_with_fee_history_calculation( + self, w3: "Web3" + ) -> None: fail_max_prio_middleware = construct_error_generator_middleware( - {RPCEndpoint("eth_maxPriorityFeePerGas"): lambda *_: ''} + {RPCEndpoint("eth_maxPriorityFeePerGas"): lambda *_: ""} + ) + w3.middleware_onion.add( + fail_max_prio_middleware, name="fail_max_prio_middleware" ) - w3.middleware_onion.add(fail_max_prio_middleware, name='fail_max_prio_middleware') with pytest.warns( UserWarning, match="There was an issue with the method eth_maxPriorityFeePerGas. Calculating using " - "eth_feeHistory." + "eth_feeHistory.", ): max_priority_fee = w3.eth.max_priority_fee assert is_integer(max_priority_fee) - w3.middleware_onion.remove('fail_max_prio_middleware') # clean up + w3.middleware_onion.remove("fail_max_prio_middleware") # clean up def test_eth_accounts(self, w3: "Web3") -> None: accounts = w3.eth.accounts assert is_list_like(accounts) assert len(accounts) != 0 - assert all(( - is_checksum_address(account) - for account - in accounts - )) + assert all((is_checksum_address(account) for account in accounts)) assert w3.eth.coinbase in accounts def test_eth_block_number(self, w3: "Web3") -> None: @@ -1481,7 +1502,7 @@ def test_eth_get_balance(self, w3: "Web3") -> None: assert balance >= 0 def test_eth_get_balance_with_block_identifier(self, w3: "Web3") -> None: - miner_address = w3.eth.get_block(1)['miner'] + miner_address = w3.eth.get_block(1)["miner"] genesis_balance = w3.eth.get_balance(miner_address, 0) later_balance = w3.eth.get_balance(miner_address, 1) @@ -1489,14 +1510,14 @@ def test_eth_get_balance_with_block_identifier(self, w3: "Web3") -> None: assert is_integer(later_balance) assert later_balance > genesis_balance - @pytest.mark.parametrize('address, expect_success', [ - ('test-address.eth', True), - ('not-an-address.eth', False) - ]) + @pytest.mark.parametrize( + "address, expect_success", + [("test-address.eth", True), ("not-an-address.eth", False)], + ) def test_eth_get_balance_with_ens_name( self, w3: "Web3", address: ChecksumAddress, expect_success: bool ) -> None: - with ens_addresses(w3, {'test-address.eth': w3.eth.accounts[0]}): + with ens_addresses(w3, {"test-address.eth": w3.eth.accounts[0]}): if expect_success: balance = w3.eth.get_balance(address) assert is_integer(balance) @@ -1514,14 +1535,16 @@ def test_eth_get_storage_at( def test_eth_get_storage_at_ens_name( self, w3: "Web3", emitter_contract_address: ChecksumAddress ) -> None: - with ens_addresses(w3, {'emitter.eth': emitter_contract_address}): - storage = w3.eth.get_storage_at('emitter.eth', 0) + with ens_addresses(w3, {"emitter.eth": emitter_contract_address}): + storage = w3.eth.get_storage_at("emitter.eth", 0) assert isinstance(storage, HexBytes) def test_eth_get_storage_at_invalid_address(self, w3: "Web3") -> None: coinbase = w3.eth.coinbase with pytest.raises(InvalidAddress): - w3.eth.get_storage_at(ChecksumAddress(HexAddress(HexStr(coinbase.lower()))), 0) + w3.eth.get_storage_at( + ChecksumAddress(HexAddress(HexStr(coinbase.lower()))), 0 + ) def test_eth_get_transaction_count( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress @@ -1533,20 +1556,26 @@ def test_eth_get_transaction_count( def test_eth_get_transaction_count_ens_name( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - with ens_addresses(w3, {'unlocked-acct-dual-type.eth': unlocked_account_dual_type}): - transaction_count = w3.eth.get_transaction_count('unlocked-acct-dual-type.eth') + with ens_addresses( + w3, {"unlocked-acct-dual-type.eth": unlocked_account_dual_type} + ): + transaction_count = w3.eth.get_transaction_count( + "unlocked-acct-dual-type.eth" + ) assert is_integer(transaction_count) assert transaction_count >= 0 def test_eth_get_transaction_count_invalid_address(self, w3: "Web3") -> None: coinbase = w3.eth.coinbase with pytest.raises(InvalidAddress): - w3.eth.get_transaction_count(ChecksumAddress(HexAddress(HexStr(coinbase.lower())))) + w3.eth.get_transaction_count( + ChecksumAddress(HexAddress(HexStr(coinbase.lower()))) + ) def test_eth_getBlockTransactionCountByHash_empty_block( self, w3: "Web3", empty_block: BlockData ) -> None: - transaction_count = w3.eth.get_block_transaction_count(empty_block['hash']) + transaction_count = w3.eth.get_block_transaction_count(empty_block["hash"]) assert is_integer(transaction_count) assert transaction_count == 0 @@ -1554,7 +1583,7 @@ def test_eth_getBlockTransactionCountByHash_empty_block( def test_eth_getBlockTransactionCountByNumber_empty_block( self, w3: "Web3", empty_block: BlockData ) -> None: - transaction_count = w3.eth.get_block_transaction_count(empty_block['number']) + transaction_count = w3.eth.get_block_transaction_count(empty_block["number"]) assert is_integer(transaction_count) assert transaction_count == 0 @@ -1562,7 +1591,7 @@ def test_eth_getBlockTransactionCountByNumber_empty_block( def test_eth_getBlockTransactionCountByHash_block_with_txn( self, w3: "Web3", block_with_txn: BlockData ) -> None: - transaction_count = w3.eth.get_block_transaction_count(block_with_txn['hash']) + transaction_count = w3.eth.get_block_transaction_count(block_with_txn["hash"]) assert is_integer(transaction_count) assert transaction_count >= 1 @@ -1570,24 +1599,30 @@ def test_eth_getBlockTransactionCountByHash_block_with_txn( def test_eth_getBlockTransactionCountByNumber_block_with_txn( self, w3: "Web3", block_with_txn: BlockData ) -> None: - transaction_count = w3.eth.get_block_transaction_count(block_with_txn['number']) + transaction_count = w3.eth.get_block_transaction_count(block_with_txn["number"]) assert is_integer(transaction_count) assert transaction_count >= 1 - def test_eth_getUncleCountByBlockHash(self, w3: "Web3", empty_block: BlockData) -> None: - uncle_count = w3.eth.get_uncle_count(empty_block['hash']) + def test_eth_getUncleCountByBlockHash( + self, w3: "Web3", empty_block: BlockData + ) -> None: + uncle_count = w3.eth.get_uncle_count(empty_block["hash"]) assert is_integer(uncle_count) assert uncle_count == 0 - def test_eth_getUncleCountByBlockNumber(self, w3: "Web3", empty_block: BlockData) -> None: - uncle_count = w3.eth.get_uncle_count(empty_block['number']) + def test_eth_getUncleCountByBlockNumber( + self, w3: "Web3", empty_block: BlockData + ) -> None: + uncle_count = w3.eth.get_uncle_count(empty_block["number"]) assert is_integer(uncle_count) assert uncle_count == 0 - def test_eth_get_code(self, w3: "Web3", math_contract_address: ChecksumAddress) -> None: + def test_eth_get_code( + self, w3: "Web3", math_contract_address: ChecksumAddress + ) -> None: code = w3.eth.get_code(math_contract_address) assert isinstance(code, HexBytes) assert len(code) > 0 @@ -1595,27 +1630,33 @@ def test_eth_get_code(self, w3: "Web3", math_contract_address: ChecksumAddress) def test_eth_get_code_ens_address( self, w3: "Web3", math_contract_address: ChecksumAddress ) -> None: - with ens_addresses( - w3, {'mathcontract.eth': math_contract_address} - ): - code = w3.eth.get_code('mathcontract.eth') + with ens_addresses(w3, {"mathcontract.eth": math_contract_address}): + code = w3.eth.get_code("mathcontract.eth") assert isinstance(code, HexBytes) assert len(code) > 0 - def test_eth_get_code_invalid_address(self, w3: "Web3", math_contract: "Contract") -> None: + def test_eth_get_code_invalid_address( + self, w3: "Web3", math_contract: "Contract" + ) -> None: with pytest.raises(InvalidAddress): - w3.eth.get_code(ChecksumAddress(HexAddress(HexStr(math_contract.address.lower())))) + w3.eth.get_code( + ChecksumAddress(HexAddress(HexStr(math_contract.address.lower()))) + ) def test_eth_get_code_with_block_identifier( self, w3: "Web3", emitter_contract: "Contract" ) -> None: - code = w3.eth.get_code(emitter_contract.address, block_identifier=w3.eth.block_number) + code = w3.eth.get_code( + emitter_contract.address, block_identifier=w3.eth.block_number + ) assert isinstance(code, HexBytes) assert len(code) > 0 - def test_eth_sign(self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress) -> None: + def test_eth_sign( + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress + ) -> None: signature = w3.eth.sign( - unlocked_account_dual_type, text='Message tö sign. Longer than hash!' + unlocked_account_dual_type, text="Message tö sign. Longer than hash!" ) assert is_bytes(signature) assert len(signature) == 32 + 32 + 1 @@ -1624,33 +1665,33 @@ def test_eth_sign(self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress) hexsign = w3.eth.sign( unlocked_account_dual_type, hexstr=HexStr( - '0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821' - ) + "0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821" + ), ) assert hexsign == signature intsign = w3.eth.sign( unlocked_account_dual_type, - 0x4d6573736167652074c3b6207369676e2e204c6f6e676572207468616e206861736821 + 0x4D6573736167652074C3B6207369676E2E204C6F6E676572207468616E206861736821, ) assert intsign == signature bytessign = w3.eth.sign( - unlocked_account_dual_type, b'Message t\xc3\xb6 sign. Longer than hash!' + unlocked_account_dual_type, b"Message t\xc3\xb6 sign. Longer than hash!" ) assert bytessign == signature new_signature = w3.eth.sign( - unlocked_account_dual_type, text='different message is different' + unlocked_account_dual_type, text="different message is different" ) assert new_signature != signature def test_eth_sign_ens_names( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - with ens_addresses(w3, {'unlocked-acct.eth': unlocked_account_dual_type}): + with ens_addresses(w3, {"unlocked-acct.eth": unlocked_account_dual_type}): signature = w3.eth.sign( - 'unlocked-acct.eth', text='Message tö sign. Longer than hash!' + "unlocked-acct.eth", text="Message tö sign. Longer than hash!" ) assert is_bytes(signature) assert len(signature) == 32 + 32 + 1 @@ -1661,7 +1702,7 @@ def test_eth_sign_typed_data( unlocked_account_dual_type: ChecksumAddress, skip_if_testrpc: Callable[["Web3"], None], ) -> None: - validJSONMessage = ''' + validJSONMessage = """ { "types": { "EIP712Domain": [ @@ -1699,22 +1740,23 @@ def test_eth_sign_typed_data( "contents": "Hello, Bob!" } } - ''' + """ skip_if_testrpc(w3) - signature = HexBytes(w3.eth.sign_typed_data( - unlocked_account_dual_type, - json.loads(validJSONMessage) - )) + signature = HexBytes( + w3.eth.sign_typed_data( + unlocked_account_dual_type, json.loads(validJSONMessage) + ) + ) assert len(signature) == 32 + 32 + 1 def test_invalid_eth_sign_typed_data( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress, - skip_if_testrpc: Callable[["Web3"], None] + skip_if_testrpc: Callable[["Web3"], None], ) -> None: skip_if_testrpc(w3) - invalid_typed_message = ''' + invalid_typed_message = """ { "types": { "EIP712Domain": [ @@ -1752,170 +1794,176 @@ def test_invalid_eth_sign_typed_data( "contents": "Hello, Bob!" } } - ''' - with pytest.raises(ValueError, - match=r".*Expected 2 items for array type Person\[2\], got 1 items.*"): + """ + with pytest.raises( + ValueError, + match=r".*Expected 2 items for array type Person\[2\], got 1 items.*", + ): w3.eth.sign_typed_data( - unlocked_account_dual_type, - json.loads(invalid_typed_message) + unlocked_account_dual_type, json.loads(invalid_typed_message) ) def test_eth_sign_transaction_legacy( - self, - w3: "Web3", - unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': w3.eth.gas_price, - 'nonce': Nonce(0), + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "gasPrice": w3.eth.gas_price, + "nonce": Nonce(0), } result = w3.eth.sign_transaction(txn_params) - signatory_account = w3.eth.account.recover_transaction(result['raw']) + signatory_account = w3.eth.account.recover_transaction(result["raw"]) assert unlocked_account == signatory_account - assert result['tx']['to'] == txn_params['to'] - assert result['tx']['value'] == txn_params['value'] - assert result['tx']['gas'] == txn_params['gas'] - assert result['tx']['gasPrice'] == txn_params['gasPrice'] - assert result['tx']['nonce'] == txn_params['nonce'] + assert result["tx"]["to"] == txn_params["to"] + assert result["tx"]["value"] == txn_params["value"] + assert result["tx"]["gas"] == txn_params["gas"] + assert result["tx"]["gasPrice"] == txn_params["gasPrice"] + assert result["tx"]["nonce"] == txn_params["nonce"] def test_eth_sign_transaction( - self, - w3: "Web3", - unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(2, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), - 'nonce': Nonce(0), + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(2, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), + "nonce": Nonce(0), } result = w3.eth.sign_transaction(txn_params) - signatory_account = w3.eth.account.recover_transaction(result['raw']) + signatory_account = w3.eth.account.recover_transaction(result["raw"]) assert unlocked_account == signatory_account - assert result['tx']['to'] == txn_params['to'] - assert result['tx']['value'] == txn_params['value'] - assert result['tx']['gas'] == txn_params['gas'] - assert result['tx']['maxFeePerGas'] == txn_params['maxFeePerGas'] - assert result['tx']['maxPriorityFeePerGas'] == txn_params['maxPriorityFeePerGas'] - assert result['tx']['nonce'] == txn_params['nonce'] + assert result["tx"]["to"] == txn_params["to"] + assert result["tx"]["value"] == txn_params["value"] + assert result["tx"]["gas"] == txn_params["gas"] + assert result["tx"]["maxFeePerGas"] == txn_params["maxFeePerGas"] + assert ( + result["tx"]["maxPriorityFeePerGas"] == txn_params["maxPriorityFeePerGas"] + ) + assert result["tx"]["nonce"] == txn_params["nonce"] def test_eth_sign_transaction_hex_fees( - self, - w3: "Web3", - unlocked_account: ChecksumAddress + self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': hex(w3.toWei(2, 'gwei')), - 'maxPriorityFeePerGas': hex(w3.toWei(1, 'gwei')), - 'nonce': Nonce(0), + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": hex(w3.toWei(2, "gwei")), + "maxPriorityFeePerGas": hex(w3.toWei(1, "gwei")), + "nonce": Nonce(0), } result = w3.eth.sign_transaction(txn_params) - signatory_account = w3.eth.account.recover_transaction(result['raw']) + signatory_account = w3.eth.account.recover_transaction(result["raw"]) assert unlocked_account == signatory_account - assert result['tx']['to'] == txn_params['to'] - assert result['tx']['value'] == txn_params['value'] - assert result['tx']['gas'] == txn_params['gas'] - assert result['tx']['maxFeePerGas'] == int(str(txn_params['maxFeePerGas']), 16) - assert result['tx']['maxPriorityFeePerGas'] == int( - str(txn_params['maxPriorityFeePerGas']), 16 + assert result["tx"]["to"] == txn_params["to"] + assert result["tx"]["value"] == txn_params["value"] + assert result["tx"]["gas"] == txn_params["gas"] + assert result["tx"]["maxFeePerGas"] == int(str(txn_params["maxFeePerGas"]), 16) + assert result["tx"]["maxPriorityFeePerGas"] == int( + str(txn_params["maxPriorityFeePerGas"]), 16 ) - assert result['tx']['nonce'] == txn_params['nonce'] + assert result["tx"]["nonce"] == txn_params["nonce"] def test_eth_sign_transaction_ens_names( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: - with ens_addresses(w3, {'unlocked-account.eth': unlocked_account}): + with ens_addresses(w3, {"unlocked-account.eth": unlocked_account}): txn_params: TxParams = { - 'from': 'unlocked-account.eth', - 'to': 'unlocked-account.eth', - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(2, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), - 'nonce': Nonce(0), + "from": "unlocked-account.eth", + "to": "unlocked-account.eth", + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(2, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), + "nonce": Nonce(0), } result = w3.eth.sign_transaction(txn_params) - signatory_account = w3.eth.account.recover_transaction(result['raw']) + signatory_account = w3.eth.account.recover_transaction(result["raw"]) assert unlocked_account == signatory_account - assert result['tx']['to'] == unlocked_account - assert result['tx']['value'] == txn_params['value'] - assert result['tx']['gas'] == txn_params['gas'] - assert result['tx']['maxFeePerGas'] == txn_params['maxFeePerGas'] - assert result['tx']['maxPriorityFeePerGas'] == txn_params['maxPriorityFeePerGas'] - assert result['tx']['nonce'] == txn_params['nonce'] + assert result["tx"]["to"] == unlocked_account + assert result["tx"]["value"] == txn_params["value"] + assert result["tx"]["gas"] == txn_params["gas"] + assert result["tx"]["maxFeePerGas"] == txn_params["maxFeePerGas"] + assert ( + result["tx"]["maxPriorityFeePerGas"] + == txn_params["maxPriorityFeePerGas"] + ) + assert result["tx"]["nonce"] == txn_params["nonce"] def test_eth_send_transaction_addr_checksum_required( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: non_checksum_addr = unlocked_account.lower() txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(2, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(2, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), } with pytest.raises(InvalidAddress): - invalid_params = cast(TxParams, dict(txn_params, **{'from': non_checksum_addr})) + invalid_params = cast( + TxParams, dict(txn_params, **{"from": non_checksum_addr}) + ) w3.eth.send_transaction(invalid_params) with pytest.raises(InvalidAddress): - invalid_params = cast(TxParams, dict(txn_params, **{'to': non_checksum_addr})) + invalid_params = cast( + TxParams, dict(txn_params, **{"to": non_checksum_addr}) + ) w3.eth.send_transaction(invalid_params) def test_eth_send_transaction_legacy( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': w3.toWei(1, 'gwei'), # post-london needs to be more than the base fee + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "gasPrice": w3.toWei( + 1, "gwei" + ), # post-london needs to be more than the base fee } txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['gasPrice'] == txn_params['gasPrice'] + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["gasPrice"] == txn_params["gasPrice"] def test_eth_send_transaction( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(3, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(3, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), } txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['maxFeePerGas'] == txn_params['maxFeePerGas'] - assert txn['maxPriorityFeePerGas'] == txn_params['maxPriorityFeePerGas'] - assert txn['gasPrice'] == txn_params['maxFeePerGas'] + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["maxFeePerGas"] == txn_params["maxFeePerGas"] + assert txn["maxPriorityFeePerGas"] == txn_params["maxPriorityFeePerGas"] + assert txn["gasPrice"] == txn_params["maxFeePerGas"] def test_eth_send_transaction_with_nonce( self, w3: "Web3", unlocked_account: ChecksumAddress @@ -1923,97 +1971,97 @@ def test_eth_send_transaction_with_nonce( mine_pending_block(w3) # gives an accurate transaction count after mining txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, # unique maxFeePerGas to ensure transaction hash different from other tests - 'maxFeePerGas': w3.toWei(4.321, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), - 'nonce': w3.eth.get_transaction_count(unlocked_account), + "maxFeePerGas": w3.toWei(4.321, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), + "nonce": w3.eth.get_transaction_count(unlocked_account), } txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['maxFeePerGas'] == txn_params['maxFeePerGas'] - assert txn['maxPriorityFeePerGas'] == txn_params['maxPriorityFeePerGas'] - assert txn['nonce'] == txn_params['nonce'] - assert txn['gasPrice'] == txn_params['maxFeePerGas'] + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["maxFeePerGas"] == txn_params["maxFeePerGas"] + assert txn["maxPriorityFeePerGas"] == txn_params["maxPriorityFeePerGas"] + assert txn["nonce"] == txn_params["nonce"] + assert txn["gasPrice"] == txn_params["maxFeePerGas"] def test_eth_send_transaction_default_fees( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, } txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['maxPriorityFeePerGas'] == 1 * 10**9 - assert txn['maxFeePerGas'] >= 1 * 10**9 - assert txn['gasPrice'] == txn['maxFeePerGas'] + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["maxPriorityFeePerGas"] == 1 * 10**9 + assert txn["maxFeePerGas"] >= 1 * 10**9 + assert txn["gasPrice"] == txn["maxFeePerGas"] def test_eth_send_transaction_hex_fees( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': hex(250 * 10**9), - 'maxPriorityFeePerGas': hex(2 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": hex(250 * 10**9), + "maxPriorityFeePerGas": hex(2 * 10**9), } txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 - assert txn['maxFeePerGas'] == 250 * 10**9 - assert txn['maxPriorityFeePerGas'] == 2 * 10**9 + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 + assert txn["maxFeePerGas"] == 250 * 10**9 + assert txn["maxPriorityFeePerGas"] == 2 * 10**9 def test_eth_send_transaction_no_gas( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'maxFeePerGas': Wei(250 * 10**9), - 'maxPriorityFeePerGas': Wei(2 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "maxFeePerGas": Wei(250 * 10**9), + "maxPriorityFeePerGas": Wei(2 * 10**9), } txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 121000 # 21000 + buffer + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 121000 # 21000 + buffer def test_eth_send_transaction_with_gas_price( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': Wei(1), - 'maxFeePerGas': Wei(250 * 10**9), - 'maxPriorityFeePerGas': Wei(2 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "gasPrice": Wei(1), + "maxFeePerGas": Wei(250 * 10**9), + "maxPriorityFeePerGas": Wei(2 * 10**9), } with pytest.raises(TransactionTypeMismatch): w3.eth.send_transaction(txn_params) @@ -2022,47 +2070,49 @@ def test_eth_send_transaction_no_priority_fee( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': Wei(250 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": Wei(250 * 10**9), } - with pytest.raises(InvalidTransaction, match='maxPriorityFeePerGas must be defined'): + with pytest.raises( + InvalidTransaction, match="maxPriorityFeePerGas must be defined" + ): w3.eth.send_transaction(txn_params) def test_eth_send_transaction_no_max_fee( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - maxPriorityFeePerGas = w3.toWei(2, 'gwei') + maxPriorityFeePerGas = w3.toWei(2, "gwei") txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxPriorityFeePerGas': maxPriorityFeePerGas, + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxPriorityFeePerGas": maxPriorityFeePerGas, } txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - assert is_same_address(txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert txn['value'] == 1 - assert txn['gas'] == 21000 + assert is_same_address(txn["from"], cast(ChecksumAddress, txn_params["from"])) + assert is_same_address(txn["to"], cast(ChecksumAddress, txn_params["to"])) + assert txn["value"] == 1 + assert txn["gas"] == 21000 - block = w3.eth.get_block('latest') - assert txn['maxFeePerGas'] == maxPriorityFeePerGas + 2 * block['baseFeePerGas'] + block = w3.eth.get_block("latest") + assert txn["maxFeePerGas"] == maxPriorityFeePerGas + 2 * block["baseFeePerGas"] def test_eth_send_transaction_max_fee_less_than_tip( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': Wei(1 * 10**9), - 'maxPriorityFeePerGas': Wei(2 * 10**9), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": Wei(1 * 10**9), + "maxPriorityFeePerGas": Wei(2 * 10**9), } with pytest.raises( InvalidTransaction, match="maxFeePerGas must be >= maxPriorityFeePerGas" @@ -2076,72 +2126,78 @@ def test_validation_middleware_chain_id_mismatch( actual_chain_id = w3.eth.chain_id txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': Wei(21000), - 'maxFeePerGas': w3.toWei(2, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), - 'chainId': wrong_chain_id, - + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": Wei(21000), + "maxFeePerGas": w3.toWei(2, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), + "chainId": wrong_chain_id, } with pytest.raises( ValidationError, - match=f'The transaction declared chain ID {wrong_chain_id}, ' - f'but the connected node is on {actual_chain_id}' + match=f"The transaction declared chain ID {wrong_chain_id}, " + f"but the connected node is on {actual_chain_id}", ): w3.eth.send_transaction(txn_params) @pytest.mark.parametrize( - "max_fee", - (1000000000, None), - ids=["with_max_fee", "without_max_fee"] + "max_fee", (1000000000, None), ids=["with_max_fee", "without_max_fee"] ) def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress, max_fee: Wei ) -> None: - max_priority_fee = w3.toWei(1, 'gwei') + max_priority_fee = w3.toWei(1, "gwei") txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxPriorityFeePerGas': max_priority_fee, + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxPriorityFeePerGas": max_priority_fee, } if max_fee is not None: txn_params = assoc(txn_params, "maxFeePerGas", max_fee) def gas_price_strategy(_w3: "Web3", _txn: TxParams) -> Wei: - return w3.toWei(2, 'gwei') + return w3.toWei(2, "gwei") + w3.eth.set_gas_price_strategy(gas_price_strategy) txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - latest_block = w3.eth.get_block('latest') - assert txn['maxFeePerGas'] == max_fee if max_fee is not None \ - else 2 * latest_block['baseFeePerGas'] + max_priority_fee - assert txn['maxPriorityFeePerGas'] == max_priority_fee - assert txn['gasPrice'] == txn['maxFeePerGas'] + latest_block = w3.eth.get_block("latest") + assert ( + txn["maxFeePerGas"] == max_fee + if max_fee is not None + else 2 * latest_block["baseFeePerGas"] + max_priority_fee + ) + assert txn["maxPriorityFeePerGas"] == max_priority_fee + assert txn["gasPrice"] == txn["maxFeePerGas"] w3.eth.set_gas_price_strategy(None) # reset strategy def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip( - self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress, + self, + w3: "Web3", + unlocked_account_dual_type: ChecksumAddress, ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': Wei(1000000000), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": Wei(1000000000), } def gas_price_strategy(_w3: "Web3", _txn: TxParams) -> Wei: - return w3.toWei(2, 'gwei') + return w3.toWei(2, "gwei") + w3.eth.set_gas_price_strategy(gas_price_strategy) - with pytest.raises(InvalidTransaction, match="maxPriorityFeePerGas must be defined"): + with pytest.raises( + InvalidTransaction, match="maxPriorityFeePerGas must be defined" + ): w3.eth.send_transaction(txn_params) w3.eth.set_gas_price_strategy(None) # reset strategy @@ -2150,69 +2206,79 @@ def test_eth_replace_transaction_legacy( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': w3.toWei(1, 'gwei'), # must be greater than base_fee post London + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "gasPrice": w3.toWei( + 1, "gwei" + ), # must be greater than base_fee post London } txn_hash = w3.eth.send_transaction(txn_params) - txn_params['gasPrice'] = w3.toWei(2, 'gwei') + txn_params["gasPrice"] = w3.toWei(2, "gwei") replace_txn_hash = w3.eth.replace_transaction(txn_hash, txn_params) replace_txn = w3.eth.get_transaction(replace_txn_hash) - assert is_same_address(replace_txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(replace_txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert replace_txn['value'] == 1 - assert replace_txn['gas'] == 21000 - assert replace_txn['gasPrice'] == txn_params['gasPrice'] + assert is_same_address( + replace_txn["from"], cast(ChecksumAddress, txn_params["from"]) + ) + assert is_same_address( + replace_txn["to"], cast(ChecksumAddress, txn_params["to"]) + ) + assert replace_txn["value"] == 1 + assert replace_txn["gas"] == 21000 + assert replace_txn["gasPrice"] == txn_params["gasPrice"] def test_eth_replace_transaction( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - two_gwei_in_wei = w3.toWei(2, 'gwei') - three_gwei_in_wei = w3.toWei(3, 'gwei') + two_gwei_in_wei = w3.toWei(2, "gwei") + three_gwei_in_wei = w3.toWei(3, "gwei") txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': two_gwei_in_wei, - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": two_gwei_in_wei, + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), } txn_hash = w3.eth.send_transaction(txn_params) - txn_params['maxFeePerGas'] = three_gwei_in_wei - txn_params['maxPriorityFeePerGas'] = two_gwei_in_wei + txn_params["maxFeePerGas"] = three_gwei_in_wei + txn_params["maxPriorityFeePerGas"] = two_gwei_in_wei replace_txn_hash = w3.eth.replace_transaction(txn_hash, txn_params) replace_txn = w3.eth.get_transaction(replace_txn_hash) - assert is_same_address(replace_txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(replace_txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert replace_txn['value'] == 1 - assert replace_txn['gas'] == 21000 - assert replace_txn['maxFeePerGas'] == three_gwei_in_wei - assert replace_txn['maxPriorityFeePerGas'] == two_gwei_in_wei + assert is_same_address( + replace_txn["from"], cast(ChecksumAddress, txn_params["from"]) + ) + assert is_same_address( + replace_txn["to"], cast(ChecksumAddress, txn_params["to"]) + ) + assert replace_txn["value"] == 1 + assert replace_txn["gas"] == 21000 + assert replace_txn["maxFeePerGas"] == three_gwei_in_wei + assert replace_txn["maxPriorityFeePerGas"] == two_gwei_in_wei def test_eth_replace_transaction_underpriced( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(3, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(2, 'gwei'), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(3, "gwei"), + "maxPriorityFeePerGas": w3.toWei(2, "gwei"), } txn_hash = w3.eth.send_transaction(txn_params) - one_gwei_in_wei = w3.toWei(1, 'gwei') - txn_params['maxFeePerGas'] = one_gwei_in_wei - txn_params['maxPriorityFeePerGas'] = one_gwei_in_wei + one_gwei_in_wei = w3.toWei(1, "gwei") + txn_params["maxFeePerGas"] = one_gwei_in_wei + txn_params["maxPriorityFeePerGas"] = one_gwei_in_wei with pytest.raises(ValueError, match="replacement transaction underpriced"): w3.eth.replace_transaction(txn_hash, txn_params) @@ -2221,29 +2287,31 @@ def test_eth_replace_transaction_non_existing_transaction( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(3, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(3, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), } with pytest.raises(TransactionNotFound): w3.eth.replace_transaction( - HexStr('0x98e8cc09b311583c5079fa600f6c2a3bea8611af168c52e4b60b5b243a441997'), - txn_params + HexStr( + "0x98e8cc09b311583c5079fa600f6c2a3bea8611af168c52e4b60b5b243a441997" + ), + txn_params, ) def test_eth_replace_transaction_already_mined( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(2, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(2, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), } txn_hash = w3.eth.send_transaction(txn_params) try: @@ -2252,8 +2320,8 @@ def test_eth_replace_transaction_already_mined( finally: w3.geth.miner.stop() # type: ignore - txn_params['maxFeePerGas'] = w3.toWei(3, 'gwei') - txn_params['maxPriorityFeePerGas'] = w3.toWei(2, 'gwei') + txn_params["maxFeePerGas"] = w3.toWei(3, "gwei") + txn_params["maxPriorityFeePerGas"] = w3.toWei(2, "gwei") with pytest.raises(ValueError, match="Supplied transaction with hash"): w3.eth.replace_transaction(txn_hash, txn_params) @@ -2261,19 +2329,19 @@ def test_eth_replace_transaction_incorrect_nonce( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(2, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(2, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), } txn_hash = w3.eth.send_transaction(txn_params) txn = w3.eth.get_transaction(txn_hash) - txn_params['maxFeePerGas'] = w3.toWei(3, 'gwei') - txn_params['maxPriorityFeePerGas'] = w3.toWei(2, 'gwei') - txn_params['nonce'] = Nonce(txn['nonce'] + 1) + txn_params["maxFeePerGas"] = w3.toWei(3, "gwei") + txn_params["maxPriorityFeePerGas"] = w3.toWei(2, "gwei") + txn_params["nonce"] = Nonce(txn["nonce"] + 1) with pytest.raises(ValueError): w3.eth.replace_transaction(txn_hash, txn_params) @@ -2281,172 +2349,186 @@ def test_eth_replace_transaction_gas_price_too_low( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': w3.toWei(2, 'gwei'), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "gasPrice": w3.toWei(2, "gwei"), } txn_hash = w3.eth.send_transaction(txn_params) - txn_params['gasPrice'] = w3.toWei(1, 'gwei') + txn_params["gasPrice"] = w3.toWei(1, "gwei") with pytest.raises(ValueError): w3.eth.replace_transaction(txn_hash, txn_params) def test_eth_replace_transaction_gas_price_defaulting_minimum( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: - gas_price = w3.toWei(1, 'gwei') + gas_price = w3.toWei(1, "gwei") txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': gas_price, + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "gasPrice": gas_price, } txn_hash = w3.eth.send_transaction(txn_params) - txn_params.pop('gasPrice') + txn_params.pop("gasPrice") replace_txn_hash = w3.eth.replace_transaction(txn_hash, txn_params) replace_txn = w3.eth.get_transaction(replace_txn_hash) - assert replace_txn['gasPrice'] == math.ceil(gas_price * 1.125) # minimum gas price + assert replace_txn["gasPrice"] == math.ceil( + gas_price * 1.125 + ) # minimum gas price def test_eth_replace_transaction_gas_price_defaulting_strategy_higher( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': w3.toWei(1, 'gwei'), + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "gasPrice": w3.toWei(1, "gwei"), } txn_hash = w3.eth.send_transaction(txn_params) - two_gwei_in_wei = w3.toWei(2, 'gwei') + two_gwei_in_wei = w3.toWei(2, "gwei") def higher_gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: return two_gwei_in_wei w3.eth.set_gas_price_strategy(higher_gas_price_strategy) - txn_params.pop('gasPrice') + txn_params.pop("gasPrice") replace_txn_hash = w3.eth.replace_transaction(txn_hash, txn_params) replace_txn = w3.eth.get_transaction(replace_txn_hash) - assert replace_txn['gasPrice'] == two_gwei_in_wei # Strategy provides higher gas price + assert ( + replace_txn["gasPrice"] == two_gwei_in_wei + ) # Strategy provides higher gas price w3.eth.set_gas_price_strategy(None) # reset strategy def test_eth_replace_transaction_gas_price_defaulting_strategy_lower( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: - gas_price = w3.toWei(2, 'gwei') + gas_price = w3.toWei(2, "gwei") txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': gas_price, + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "gasPrice": gas_price, } txn_hash = w3.eth.send_transaction(txn_params) def lower_gas_price_strategy(w3: "Web3", txn: TxParams) -> Wei: - return w3.toWei(1, 'gwei') + return w3.toWei(1, "gwei") w3.eth.set_gas_price_strategy(lower_gas_price_strategy) - txn_params.pop('gasPrice') + txn_params.pop("gasPrice") replace_txn_hash = w3.eth.replace_transaction(txn_hash, txn_params) replace_txn = w3.eth.get_transaction(replace_txn_hash) # Strategy provides lower gas price - minimum preferred - assert replace_txn['gasPrice'] == math.ceil(gas_price * 1.125) + assert replace_txn["gasPrice"] == math.ceil(gas_price * 1.125) w3.eth.set_gas_price_strategy(None) # reset strategy def test_eth_modify_transaction_legacy( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'gasPrice': w3.toWei(1, 'gwei'), # must be greater than base_fee post London + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "gasPrice": w3.toWei( + 1, "gwei" + ), # must be greater than base_fee post London } txn_hash = w3.eth.send_transaction(txn_params) modified_txn_hash = w3.eth.modify_transaction( - txn_hash, gasPrice=(cast(int, txn_params['gasPrice']) * 2), value=2 + txn_hash, gasPrice=(cast(int, txn_params["gasPrice"]) * 2), value=2 ) modified_txn = w3.eth.get_transaction(modified_txn_hash) - assert is_same_address(modified_txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(modified_txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert modified_txn['value'] == 2 - assert modified_txn['gas'] == 21000 - assert modified_txn['gasPrice'] == cast(int, txn_params['gasPrice']) * 2 + assert is_same_address( + modified_txn["from"], cast(ChecksumAddress, txn_params["from"]) + ) + assert is_same_address( + modified_txn["to"], cast(ChecksumAddress, txn_params["to"]) + ) + assert modified_txn["value"] == 2 + assert modified_txn["gas"] == 21000 + assert modified_txn["gasPrice"] == cast(int, txn_params["gasPrice"]) * 2 def test_eth_modify_transaction( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: txn_params: TxParams = { - 'from': unlocked_account, - 'to': unlocked_account, - 'value': Wei(1), - 'gas': 21000, - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei'), - 'maxFeePerGas': w3.toWei(2, 'gwei'), + "from": unlocked_account, + "to": unlocked_account, + "value": Wei(1), + "gas": 21000, + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), + "maxFeePerGas": w3.toWei(2, "gwei"), } txn_hash = w3.eth.send_transaction(txn_params) modified_txn_hash = w3.eth.modify_transaction( txn_hash, value=2, - maxPriorityFeePerGas=(cast(Wei, txn_params['maxPriorityFeePerGas']) * 2), - maxFeePerGas=(cast(Wei, txn_params['maxFeePerGas']) * 2), + maxPriorityFeePerGas=(cast(Wei, txn_params["maxPriorityFeePerGas"]) * 2), + maxFeePerGas=(cast(Wei, txn_params["maxFeePerGas"]) * 2), ) modified_txn = w3.eth.get_transaction(modified_txn_hash) - assert is_same_address(modified_txn['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(modified_txn['to'], cast(ChecksumAddress, txn_params['to'])) - assert modified_txn['value'] == 2 - assert modified_txn['gas'] == 21000 - assert modified_txn['maxPriorityFeePerGas'] == cast(Wei, txn_params[ - 'maxPriorityFeePerGas']) * 2 - assert modified_txn['maxFeePerGas'] == cast(Wei, txn_params['maxFeePerGas']) * 2 + assert is_same_address( + modified_txn["from"], cast(ChecksumAddress, txn_params["from"]) + ) + assert is_same_address( + modified_txn["to"], cast(ChecksumAddress, txn_params["to"]) + ) + assert modified_txn["value"] == 2 + assert modified_txn["gas"] == 21000 + assert ( + modified_txn["maxPriorityFeePerGas"] + == cast(Wei, txn_params["maxPriorityFeePerGas"]) * 2 + ) + assert modified_txn["maxFeePerGas"] == cast(Wei, txn_params["maxFeePerGas"]) * 2 def test_eth_send_raw_transaction( self, w3: "Web3", unlocked_account: ChecksumAddress ) -> None: signed_tx = w3.eth.account.sign_transaction( { - 'to': '0x0000000000000000000000000000000000000000', - 'value': 0, - 'nonce': w3.eth.get_transaction_count(unlocked_account), - 'gas': 21000, - 'maxFeePerGas': 1000000000, - 'maxPriorityFeePerGas': 1000000000, - 'chainId': 131277322940537 + "to": "0x0000000000000000000000000000000000000000", + "value": 0, + "nonce": w3.eth.get_transaction_count(unlocked_account), + "gas": 21000, + "maxFeePerGas": 1000000000, + "maxPriorityFeePerGas": 1000000000, + "chainId": 131277322940537, }, # unlocked_account private key: - '0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01' + "0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01", ) txn_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction) assert txn_hash == signed_tx.hash - def test_eth_call( - self, w3: "Web3", math_contract: "Contract" - ) -> None: + def test_eth_call(self, w3: "Web3", math_contract: "Contract") -> None: coinbase = w3.eth.coinbase txn_params = math_contract._prepare_transaction( - fn_name='add', + fn_name="add", fn_args=(7, 11), - transaction={'from': coinbase, 'to': math_contract.address}, + transaction={"from": coinbase, "to": math_contract.address}, ) call_result = w3.eth.call(txn_params) assert is_string(call_result) - result = w3.codec.decode_single('uint256', call_result) + result = w3.codec.decode_single("uint256", call_result) assert result == 18 def test_eth_call_with_override( @@ -2454,21 +2536,21 @@ def test_eth_call_with_override( ) -> None: coinbase = w3.eth.coinbase txn_params = revert_contract._prepare_transaction( - fn_name='normalFunction', - transaction={'from': coinbase, 'to': revert_contract.address}, + fn_name="normalFunction", + transaction={"from": coinbase, "to": revert_contract.address}, ) call_result = w3.eth.call(txn_params) - result = w3.codec.decode_single('bool', call_result) + result = w3.codec.decode_single("bool", call_result) assert result is True # override runtime bytecode: `normalFunction` returns `false` - override_code = HexStr('0x6080604052348015600f57600080fd5b5060043610603c5760003560e01c8063185c38a4146041578063c06a97cb146049578063d67e4b84146051575b600080fd5b60476071565b005b604f60df565b005b605760e4565b604051808215151515815260200191505060405180910390f35b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f46756e6374696f6e20686173206265656e2072657665727465642e000000000081525060200191505060405180910390fd5b600080fd5b60008090509056fea2646970667358221220bb71e9e9a2e271cd0fbe833524a3ea67df95f25ea13aef5b0a761fa52b538f1064736f6c63430006010033') # noqa: E501 + override_code = HexStr( + "0x6080604052348015600f57600080fd5b5060043610603c5760003560e01c8063185c38a4146041578063c06a97cb146049578063d67e4b84146051575b600080fd5b60476071565b005b604f60df565b005b605760e4565b604051808215151515815260200191505060405180910390f35b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f46756e6374696f6e20686173206265656e2072657665727465642e000000000081525060200191505060405180910390fd5b600080fd5b60008090509056fea2646970667358221220bb71e9e9a2e271cd0fbe833524a3ea67df95f25ea13aef5b0a761fa52b538f1064736f6c63430006010033" # noqa: E501 + ) call_result = w3.eth.call( - txn_params, - 'latest', - {revert_contract.address: {'code': override_code}} + txn_params, "latest", {revert_contract.address: {"code": override_code}} ) - result = w3.codec.decode_single('bool', call_result) + result = w3.codec.decode_single("bool", call_result) assert result is False def test_eth_call_with_0_result( @@ -2476,13 +2558,13 @@ def test_eth_call_with_0_result( ) -> None: coinbase = w3.eth.coinbase txn_params = math_contract._prepare_transaction( - fn_name='add', + fn_name="add", fn_args=(0, 0), - transaction={'from': coinbase, 'to': math_contract.address}, + transaction={"from": coinbase, "to": math_contract.address}, ) call_result = w3.eth.call(txn_params) assert is_string(call_result) - result = w3.codec.decode_single('uint256', call_result) + result = w3.codec.decode_single("uint256", call_result) assert result == 0 def test_eth_call_revert_with_msg( @@ -2491,8 +2573,9 @@ def test_eth_call_revert_with_msg( revert_contract: "Contract", unlocked_account: ChecksumAddress, ) -> None: - with pytest.raises(ContractLogicError, - match='execution reverted: Function has been reverted'): + with pytest.raises( + ContractLogicError, match="execution reverted: Function has been reverted" + ): txn_params = revert_contract._prepare_transaction( fn_name="revertWithMessage", transaction={ @@ -2525,19 +2608,23 @@ def test_eth_call_offchain_lookup( unlocked_account: ChecksumAddress, monkeypatch: "MonkeyPatch", ) -> None: - normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + normalized_contract_address = to_hex_if_bytes( + offchain_lookup_contract.address + ).lower() mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_json_data=WEB3PY_AS_HEXBYTES, ) response = offchain_lookup_contract.functions.testOffchainLookup( OFFCHAIN_LOOKUP_TEST_DATA ).call() - assert w3.codec.decode_abi(['string'], response)[0] == 'web3py' + assert w3.codec.decode_abi(["string"], response)[0] == "web3py" def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled( - self, w3: "Web3", offchain_lookup_contract: "Contract", + self, + w3: "Web3", + offchain_lookup_contract: "Contract", ) -> None: # test ContractFunction call with pytest.raises(OffchainLookup): @@ -2555,7 +2642,9 @@ def test_eth_call_offchain_lookup_raises_when_ccip_read_is_disabled( w3.provider.global_ccip_read_enabled = False with pytest.raises(OffchainLookup): - offchain_lookup_contract.functions.testOffchainLookup(OFFCHAIN_LOOKUP_TEST_DATA).call() + offchain_lookup_contract.functions.testOffchainLookup( + OFFCHAIN_LOOKUP_TEST_DATA + ).call() w3.provider.global_ccip_read_enabled = True # cleanup @@ -2566,10 +2655,12 @@ def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag( unlocked_account: ChecksumAddress, monkeypatch: "MonkeyPatch", ) -> None: - normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + normalized_contract_address = to_hex_if_bytes( + offchain_lookup_contract.address + ).lower() mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_json_data=WEB3PY_AS_HEXBYTES, ) @@ -2578,7 +2669,7 @@ def test_eth_call_offchain_lookup_call_flag_overrides_provider_flag( response = offchain_lookup_contract.functions.testOffchainLookup( OFFCHAIN_LOOKUP_TEST_DATA ).call(ccip_read_enabled=True) - assert w3.codec.decode_abi(['string'], response)[0] == 'web3py' + assert w3.codec.decode_abi(["string"], response)[0] == "web3py" w3.provider.global_ccip_read_enabled = True # cleanup @@ -2606,19 +2697,21 @@ def test_eth_call_offchain_lookup_raises_for_improperly_formatted_rest_request_r unlocked_account: ChecksumAddress, monkeypatch: "MonkeyPatch", ) -> None: - normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + normalized_contract_address = to_hex_if_bytes( + offchain_lookup_contract.address + ).lower() mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_json_data=WEB3PY_AS_HEXBYTES, - json_data_field='not_data', + json_data_field="not_data", ) with pytest.raises(ValidationError, match="missing 'data' field"): offchain_lookup_contract.functions.testOffchainLookup( OFFCHAIN_LOOKUP_TEST_DATA ).call() - @pytest.mark.parametrize('status_code_non_4xx_error', [100, 300, 500, 600]) + @pytest.mark.parametrize("status_code_non_4xx_error", [100, 300, 500, 600]) def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_tests_POST( self, w3: "Web3", @@ -2627,7 +2720,9 @@ def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_te monkeypatch: "MonkeyPatch", status_code_non_4xx_error: int, ) -> None: - normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + normalized_contract_address = to_hex_if_bytes( + offchain_lookup_contract.address + ).lower() # The next url in our test contract doesn't contain '{data}', triggering the POST request # logic. The idea here is to return a bad status for the first url (GET) and a success @@ -2635,14 +2730,14 @@ def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_te # non 4xx status and that the POST logic is also working as expected. mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_status_code=status_code_non_4xx_error, mocked_json_data=WEB3PY_AS_HEXBYTES, ) mock_offchain_lookup_request_response( monkeypatch, - http_method='POST', - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}.json', + http_method="POST", + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}.json", mocked_status_code=200, mocked_json_data=WEB3PY_AS_HEXBYTES, sender=normalized_contract_address, @@ -2651,7 +2746,7 @@ def test_eth_call_offchain_lookup_tries_next_url_for_non_4xx_error_status_and_te response = offchain_lookup_contract.functions.testOffchainLookup( OFFCHAIN_LOOKUP_TEST_DATA ).call() - assert w3.codec.decode_abi(['string'], response)[0] == 'web3py' + assert w3.codec.decode_abi(["string"], response)[0] == "web3py" def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code( self, @@ -2660,10 +2755,12 @@ def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code( unlocked_account: ChecksumAddress, monkeypatch: "MonkeyPatch", ) -> None: - normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + normalized_contract_address = to_hex_if_bytes( + offchain_lookup_contract.address + ).lower() mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json', # noqa: E501 + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/{OFFCHAIN_LOOKUP_TEST_DATA}.json", # noqa: E501 mocked_status_code=randint(400, 499), mocked_json_data=WEB3PY_AS_HEXBYTES, ) @@ -2673,7 +2770,9 @@ def test_eth_call_offchain_lookup_calls_raise_for_status_for_4xx_status_code( ).call() def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail( - self, w3: "Web3", offchain_lookup_contract: "Contract", + self, + w3: "Web3", + offchain_lookup_contract: "Contract", ) -> None: # GET and POST requests should fail since responses are not mocked with pytest.raises( @@ -2690,10 +2789,12 @@ def test_eth_call_continuous_offchain_lookup_raises_with_too_many_requests( unlocked_account: ChecksumAddress, monkeypatch: "MonkeyPatch", ) -> None: - normalized_contract_address = to_hex_if_bytes(offchain_lookup_contract.address).lower() + normalized_contract_address = to_hex_if_bytes( + offchain_lookup_contract.address + ).lower() mock_offchain_lookup_request_response( monkeypatch, - mocked_request_url=f'https://web3.py/gateway/{normalized_contract_address}/0x.json', + mocked_request_url=f"https://web3.py/gateway/{normalized_contract_address}/0x.json", ) with pytest.raises(TooManyRequests, match="Too many CCIP read redirects"): offchain_lookup_contract.caller().continuousOffchainLookup() @@ -2704,8 +2805,9 @@ def test_eth_estimate_gas_revert_with_msg( revert_contract: "Contract", unlocked_account: ChecksumAddress, ) -> None: - with pytest.raises(ContractLogicError, - match='execution reverted: Function has been reverted'): + with pytest.raises( + ContractLogicError, match="execution reverted: Function has been reverted" + ): txn_params = revert_contract._prepare_transaction( fn_name="revertWithMessage", transaction={ @@ -2734,30 +2836,33 @@ def test_eth_estimate_gas_revert_without_msg( def test_eth_estimate_gas( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - gas_estimate = w3.eth.estimate_gas({ - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - }) + gas_estimate = w3.eth.estimate_gas( + { + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + } + ) assert is_integer(gas_estimate) assert gas_estimate > 0 def test_eth_estimate_gas_with_block( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - gas_estimate = w3.eth.estimate_gas({ - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - }, 'latest') + gas_estimate = w3.eth.estimate_gas( + { + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + }, + "latest", + ) assert is_integer(gas_estimate) assert gas_estimate > 0 - def test_eth_getBlockByHash( - self, w3: "Web3", empty_block: BlockData - ) -> None: - block = w3.eth.get_block(empty_block['hash']) - assert block['hash'] == empty_block['hash'] + def test_eth_getBlockByHash(self, w3: "Web3", empty_block: BlockData) -> None: + block = w3.eth.get_block(empty_block["hash"]) + assert block["hash"] == empty_block["hash"] def test_eth_getBlockByHash_not_found( self, w3: "Web3", empty_block: BlockData @@ -2765,24 +2870,22 @@ def test_eth_getBlockByHash_not_found( with pytest.raises(BlockNotFound): w3.eth.get_block(UNKNOWN_HASH) - def test_eth_getBlockByHash_pending( - self, w3: "Web3" - ) -> None: - block = w3.eth.get_block('pending') - assert block['hash'] is None + def test_eth_getBlockByHash_pending(self, w3: "Web3") -> None: + block = w3.eth.get_block("pending") + assert block["hash"] is None def test_eth_getBlockByNumber_with_integer( self, w3: "Web3", empty_block: BlockData ) -> None: - block = w3.eth.get_block(empty_block['number']) - assert block['number'] == empty_block['number'] + block = w3.eth.get_block(empty_block["number"]) + assert block["number"] == empty_block["number"] def test_eth_getBlockByNumber_latest( self, w3: "Web3", empty_block: BlockData ) -> None: current_block_number = w3.eth.block_number - block = w3.eth.get_block('latest') - assert block['number'] == current_block_number + block = w3.eth.get_block("latest") + assert block["number"] == current_block_number def test_eth_getBlockByNumber_not_found( self, w3: "Web3", empty_block: BlockData @@ -2794,80 +2897,80 @@ def test_eth_getBlockByNumber_pending( self, w3: "Web3", empty_block: BlockData ) -> None: current_block_number = w3.eth.block_number - block = w3.eth.get_block('pending') - assert block['number'] == current_block_number + 1 + block = w3.eth.get_block("pending") + assert block["number"] == current_block_number + 1 def test_eth_getBlockByNumber_earliest( self, w3: "Web3", empty_block: BlockData ) -> None: genesis_block = w3.eth.get_block(BlockNumber(0)) - block = w3.eth.get_block('earliest') - assert block['number'] == 0 - assert block['hash'] == genesis_block['hash'] + block = w3.eth.get_block("earliest") + assert block["number"] == 0 + assert block["hash"] == genesis_block["hash"] def test_eth_getBlockByNumber_full_transactions( self, w3: "Web3", block_with_txn: BlockData ) -> None: - block = w3.eth.get_block(block_with_txn['number'], True) - transaction = block['transactions'][0] - assert transaction['hash'] == block_with_txn['transactions'][0] # type: ignore + block = w3.eth.get_block(block_with_txn["number"], True) + transaction = block["transactions"][0] + assert transaction["hash"] == block_with_txn["transactions"][0] # type: ignore - def test_eth_getTransactionByHash( - self, w3: "Web3", mined_txn_hash: HexStr - ) -> None: + def test_eth_getTransactionByHash(self, w3: "Web3", mined_txn_hash: HexStr) -> None: transaction = w3.eth.get_transaction(mined_txn_hash) assert is_dict(transaction) - assert transaction['hash'] == HexBytes(mined_txn_hash) + assert transaction["hash"] == HexBytes(mined_txn_hash) def test_eth_getTransactionByHash_contract_creation( self, w3: "Web3", math_contract_deploy_txn_hash: HexStr ) -> None: transaction = w3.eth.get_transaction(math_contract_deploy_txn_hash) assert is_dict(transaction) - assert transaction['to'] is None, f"to field is {transaction['to']!r}" + assert transaction["to"] is None, f"to field is {transaction['to']!r}" def test_eth_getTransactionByBlockHashAndIndex( self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: - transaction = w3.eth.get_transaction_by_block(block_with_txn['hash'], 0) + transaction = w3.eth.get_transaction_by_block(block_with_txn["hash"], 0) assert is_dict(transaction) - assert transaction['hash'] == HexBytes(mined_txn_hash) + assert transaction["hash"] == HexBytes(mined_txn_hash) def test_eth_getTransactionByBlockNumberAndIndex( self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: - transaction = w3.eth.get_transaction_by_block(block_with_txn['number'], 0) + transaction = w3.eth.get_transaction_by_block(block_with_txn["number"], 0) assert is_dict(transaction) - assert transaction['hash'] == HexBytes(mined_txn_hash) + assert transaction["hash"] == HexBytes(mined_txn_hash) def test_eth_get_transaction_receipt_mined( self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: receipt = w3.eth.get_transaction_receipt(mined_txn_hash) assert is_dict(receipt) - assert receipt['blockNumber'] == block_with_txn['number'] - assert receipt['blockHash'] == block_with_txn['hash'] - assert receipt['transactionIndex'] == 0 - assert receipt['transactionHash'] == HexBytes(mined_txn_hash) - assert is_checksum_address(receipt['to']) - assert receipt['from'] is not None - assert is_checksum_address(receipt['from']) - - effective_gas_price = receipt['effectiveGasPrice'] + assert receipt["blockNumber"] == block_with_txn["number"] + assert receipt["blockHash"] == block_with_txn["hash"] + assert receipt["transactionIndex"] == 0 + assert receipt["transactionHash"] == HexBytes(mined_txn_hash) + assert is_checksum_address(receipt["to"]) + assert receipt["from"] is not None + assert is_checksum_address(receipt["from"]) + + effective_gas_price = receipt["effectiveGasPrice"] assert isinstance(effective_gas_price, int) assert effective_gas_price > 0 def test_eth_get_transaction_receipt_unmined( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - txn_hash = w3.eth.send_transaction({ - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(3, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei') - }) + txn_hash = w3.eth.send_transaction( + { + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(3, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), + } + ) with pytest.raises(TransactionNotFound): w3.eth.get_transaction_receipt(txn_hash) @@ -2880,52 +2983,51 @@ def test_eth_get_transaction_receipt_with_log_entry( ) -> None: receipt = w3.eth.get_transaction_receipt(txn_hash_with_log) assert is_dict(receipt) - assert receipt['blockNumber'] == block_with_txn_with_log['number'] - assert receipt['blockHash'] == block_with_txn_with_log['hash'] - assert receipt['transactionIndex'] == 0 - assert receipt['transactionHash'] == HexBytes(txn_hash_with_log) + assert receipt["blockNumber"] == block_with_txn_with_log["number"] + assert receipt["blockHash"] == block_with_txn_with_log["hash"] + assert receipt["transactionIndex"] == 0 + assert receipt["transactionHash"] == HexBytes(txn_hash_with_log) - assert len(receipt['logs']) == 1 - log_entry = receipt['logs'][0] + assert len(receipt["logs"]) == 1 + log_entry = receipt["logs"][0] - assert log_entry['blockNumber'] == block_with_txn_with_log['number'] - assert log_entry['blockHash'] == block_with_txn_with_log['hash'] - assert log_entry['logIndex'] == 0 - assert is_same_address(log_entry['address'], emitter_contract.address) - assert log_entry['transactionIndex'] == 0 - assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log) + assert log_entry["blockNumber"] == block_with_txn_with_log["number"] + assert log_entry["blockHash"] == block_with_txn_with_log["hash"] + assert log_entry["logIndex"] == 0 + assert is_same_address(log_entry["address"], emitter_contract.address) + assert log_entry["transactionIndex"] == 0 + assert log_entry["transactionHash"] == HexBytes(txn_hash_with_log) def test_eth_wait_for_transaction_receipt_mined( - self, - w3: "Web3", - block_with_txn: BlockData, - mined_txn_hash: HexStr + self, w3: "Web3", block_with_txn: BlockData, mined_txn_hash: HexStr ) -> None: receipt = w3.eth.wait_for_transaction_receipt(mined_txn_hash) assert is_dict(receipt) - assert receipt['blockNumber'] == block_with_txn['number'] - assert receipt['blockHash'] == block_with_txn['hash'] - assert receipt['transactionIndex'] == 0 - assert receipt['transactionHash'] == HexBytes(mined_txn_hash) - assert is_checksum_address(receipt['to']) - assert receipt['from'] is not None - assert is_checksum_address(receipt['from']) - - effective_gas_price = receipt['effectiveGasPrice'] + assert receipt["blockNumber"] == block_with_txn["number"] + assert receipt["blockHash"] == block_with_txn["hash"] + assert receipt["transactionIndex"] == 0 + assert receipt["transactionHash"] == HexBytes(mined_txn_hash) + assert is_checksum_address(receipt["to"]) + assert receipt["from"] is not None + assert is_checksum_address(receipt["from"]) + + effective_gas_price = receipt["effectiveGasPrice"] assert isinstance(effective_gas_price, int) assert effective_gas_price > 0 def test_eth_wait_for_transaction_receipt_unmined( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - txn_hash = w3.eth.send_transaction({ - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), - 'gas': 21000, - 'maxFeePerGas': w3.toWei(3, 'gwei'), - 'maxPriorityFeePerGas': w3.toWei(1, 'gwei') - }) + txn_hash = w3.eth.send_transaction( + { + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), + "gas": 21000, + "maxFeePerGas": w3.toWei(3, "gwei"), + "maxPriorityFeePerGas": w3.toWei(1, "gwei"), + } + ) timeout = 2 with pytest.raises(TimeExhausted) as exc_info: @@ -2942,20 +3044,20 @@ def test_eth_wait_for_transaction_receipt_with_log_entry( ) -> None: receipt = w3.eth.wait_for_transaction_receipt(txn_hash_with_log) assert is_dict(receipt) - assert receipt['blockNumber'] == block_with_txn_with_log['number'] - assert receipt['blockHash'] == block_with_txn_with_log['hash'] - assert receipt['transactionIndex'] == 0 - assert receipt['transactionHash'] == HexBytes(txn_hash_with_log) + assert receipt["blockNumber"] == block_with_txn_with_log["number"] + assert receipt["blockHash"] == block_with_txn_with_log["hash"] + assert receipt["transactionIndex"] == 0 + assert receipt["transactionHash"] == HexBytes(txn_hash_with_log) - assert len(receipt['logs']) == 1 - log_entry = receipt['logs'][0] + assert len(receipt["logs"]) == 1 + log_entry = receipt["logs"][0] - assert log_entry['blockNumber'] == block_with_txn_with_log['number'] - assert log_entry['blockHash'] == block_with_txn_with_log['hash'] - assert log_entry['logIndex'] == 0 - assert is_same_address(log_entry['address'], emitter_contract.address) - assert log_entry['transactionIndex'] == 0 - assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log) + assert log_entry["blockNumber"] == block_with_txn_with_log["number"] + assert log_entry["blockHash"] == block_with_txn_with_log["hash"] + assert log_entry["logIndex"] == 0 + assert is_same_address(log_entry["address"], emitter_contract.address) + assert log_entry["transactionIndex"] == 0 + assert log_entry["transactionHash"] == HexBytes(txn_hash_with_log) def test_eth_getUncleByBlockHashAndIndex(self, w3: "Web3") -> None: # TODO: how do we make uncles.... @@ -2980,7 +3082,7 @@ def test_eth_newFilter(self, w3: "Web3") -> None: assert result is True def test_eth_newBlockFilter(self, w3: "Web3") -> None: - filter = w3.eth.filter('latest') + filter = w3.eth.filter("latest") assert is_string(filter.filter_id) changes = w3.eth.get_filter_changes(filter.filter_id) @@ -2996,7 +3098,7 @@ def test_eth_newBlockFilter(self, w3: "Web3") -> None: assert result is True def test_eth_newPendingTransactionFilter(self, w3: "Web3") -> None: - filter = w3.eth.filter('pending') + filter = w3.eth.filter("pending") assert is_string(filter.filter_id) changes = w3.eth.get_filter_changes(filter.filter_id) @@ -3018,15 +3120,15 @@ def test_eth_get_logs_without_logs( filter_params: FilterParams = { "fromBlock": BlockNumber(0), - "toBlock": BlockNumber(block_with_txn_with_log['number'] - 1), + "toBlock": BlockNumber(block_with_txn_with_log["number"] - 1), } result = w3.eth.get_logs(filter_params) assert len(result) == 0 # the range is wrong filter_params = { - "fromBlock": block_with_txn_with_log['number'], - "toBlock": BlockNumber(block_with_txn_with_log['number'] - 1), + "fromBlock": block_with_txn_with_log["number"], + "toBlock": BlockNumber(block_with_txn_with_log["number"] - 1), } result = w3.eth.get_logs(filter_params) assert len(result) == 0 @@ -3063,15 +3165,12 @@ def test_eth_get_logs_with_logs( # the range includes the block where the log resides in filter_params: FilterParams = { - "fromBlock": block_with_txn_with_log['number'], - "toBlock": block_with_txn_with_log['number'], + "fromBlock": block_with_txn_with_log["number"], + "toBlock": block_with_txn_with_log["number"], } result = w3.eth.get_logs(filter_params) assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) # specify only `from_block`. by default `to_block` should be 'latest' @@ -3080,10 +3179,7 @@ def test_eth_get_logs_with_logs( } result = w3.eth.get_logs(filter_params) assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) # Test with `address` @@ -3108,30 +3204,30 @@ def test_eth_get_logs_with_logs_topic_args( "fromBlock": BlockNumber(0), "topics": [ None, - HexStr('0x000000000000000000000000000000000000000000000000000000000000d431')], + HexStr( + "0x000000000000000000000000000000000000000000000000000000000000d431" + ), + ], } result = w3.eth.get_logs(filter_params) assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) # Test with None indexed arg filter_params = { "fromBlock": BlockNumber(0), "topics": [ - HexStr('0x057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca'), - None], + HexStr( + "0x057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca" + ), + None, + ], } result = w3.eth.get_logs(filter_params) assert_contains_log( - result, - block_with_txn_with_log, - emitter_contract_address, - txn_hash_with_log + result, block_with_txn_with_log, emitter_contract_address, txn_hash_with_log ) def test_eth_get_logs_with_logs_none_topic_args(self, w3: "Web3") -> None: @@ -3147,11 +3243,11 @@ def test_eth_get_logs_with_logs_none_topic_args(self, w3: "Web3") -> None: def test_eth_call_old_contract_state( self, w3: "Web3", math_contract: "Contract", unlocked_account: ChecksumAddress ) -> None: - start_block = w3.eth.get_block('latest') + start_block = w3.eth.get_block("latest") block_num = start_block["number"] block_hash = start_block["hash"] - math_contract.functions.increment().transact({'from': unlocked_account}) + math_contract.functions.increment().transact({"from": unlocked_account}) # This isn't an incredibly convincing test since we can't mine, and # the default resolved block is latest, So if block_identifier was ignored @@ -3159,11 +3255,19 @@ def test_eth_call_old_contract_state( # Ideas to improve this test: # - Enable on-demand mining in more clients # - Increment the math contract in all of the fixtures, and check the value in an old block - block_hash_call_result = math_contract.functions.counter().call(block_identifier=block_hash) - block_num_call_result = math_contract.functions.counter().call(block_identifier=block_num) - latest_call_result = math_contract.functions.counter().call(block_identifier='latest') + block_hash_call_result = math_contract.functions.counter().call( + block_identifier=block_hash + ) + block_num_call_result = math_contract.functions.counter().call( + block_identifier=block_num + ) + latest_call_result = math_contract.functions.counter().call( + block_identifier="latest" + ) default_call_result = math_contract.functions.counter().call() - pending_call_result = math_contract.functions.counter().call(block_identifier='pending') + pending_call_result = math_contract.functions.counter().call( + block_identifier="pending" + ) assert block_hash_call_result == 0 assert block_num_call_result == 0 @@ -3171,7 +3275,9 @@ def test_eth_call_old_contract_state( assert default_call_result == 0 if pending_call_result != 1: - raise AssertionError(f"pending call result was {pending_call_result} instead of 1") + raise AssertionError( + f"pending call result was {pending_call_result} instead of 1" + ) def test_eth_uninstall_filter(self, w3: "Web3") -> None: filter = w3.eth.filter({}) @@ -3185,29 +3291,36 @@ def test_eth_uninstall_filter(self, w3: "Web3") -> None: def test_eth_submit_hashrate(self, w3: "Web3") -> None: # node_id from EIP 1474: https://github.com/ethereum/EIPs/pull/1474/files - node_id = HexStr('59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c') + node_id = HexStr( + "59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c" + ) result = w3.eth.submit_hashrate(5000, node_id) assert result is True def test_eth_submit_work(self, w3: "Web3") -> None: nonce = 1 - pow_hash = HexStr('0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef') - mix_digest = HexStr('0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000') + pow_hash = HexStr( + "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" + ) + mix_digest = HexStr( + "0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000" + ) result = w3.eth.submit_work(nonce, pow_hash, mix_digest) assert result is False - def test_eth_get_raw_transaction( - self, w3: "Web3", mined_txn_hash: HexStr - ) -> None: + def test_eth_get_raw_transaction(self, w3: "Web3", mined_txn_hash: HexStr) -> None: raw_transaction = w3.eth.get_raw_transaction(mined_txn_hash) assert is_bytes(raw_transaction) def test_eth_get_raw_transaction_raises_error(self, w3: "Web3") -> None: - with pytest.raises(TransactionNotFound, match=f"Transaction with hash: '{UNKNOWN_HASH}'"): + with pytest.raises( + TransactionNotFound, match=f"Transaction with hash: '{UNKNOWN_HASH}'" + ): w3.eth.get_raw_transaction(UNKNOWN_HASH) def test_eth_get_raw_transaction_by_block( - self, w3: "Web3", + self, + w3: "Web3", unlocked_account_dual_type: ChecksumAddress, block_with_txn: BlockData, ) -> None: @@ -3215,36 +3328,39 @@ def test_eth_get_raw_transaction_by_block( # send a txn to make sure pending block has at least one txn w3.eth.send_transaction( { - 'from': unlocked_account_dual_type, - 'to': unlocked_account_dual_type, - 'value': Wei(1), + "from": unlocked_account_dual_type, + "to": unlocked_account_dual_type, + "value": Wei(1), } ) - last_pending_txn_index = len(w3.eth.get_block('pending')['transactions']) - 1 - raw_transaction = w3.eth.get_raw_transaction_by_block('pending', last_pending_txn_index) + last_pending_txn_index = len(w3.eth.get_block("pending")["transactions"]) - 1 + raw_transaction = w3.eth.get_raw_transaction_by_block( + "pending", last_pending_txn_index + ) assert is_bytes(raw_transaction) # eth_getRawTransactionByBlockNumberAndIndex: block number - block_with_txn_number = block_with_txn['number'] + block_with_txn_number = block_with_txn["number"] assert is_integer(block_with_txn_number) raw_transaction = w3.eth.get_raw_transaction_by_block(block_with_txn_number, 0) assert is_bytes(raw_transaction) # eth_getRawTransactionByBlockHashAndIndex: block hash - block_with_txn_hash = block_with_txn['hash'] + block_with_txn_hash = block_with_txn["hash"] assert is_bytes(block_with_txn_hash) raw_transaction = w3.eth.get_raw_transaction_by_block(block_with_txn_hash, 0) assert is_bytes(raw_transaction) - @pytest.mark.parametrize('unknown_block_num_or_hash', (1234567899999, UNKNOWN_HASH)) + @pytest.mark.parametrize("unknown_block_num_or_hash", (1234567899999, UNKNOWN_HASH)) def test_eth_get_raw_transaction_by_block_raises_error( self, w3: "Web3", unknown_block_num_or_hash: Union[int, HexBytes] ) -> None: with pytest.raises( - TransactionNotFound, match=( + TransactionNotFound, + match=( f"Transaction index: 0 on block id: " f"{to_hex_if_integer(unknown_block_num_or_hash)!r} not found." - ) + ), ): w3.eth.get_raw_transaction_by_block(unknown_block_num_or_hash, 0) @@ -3253,16 +3369,15 @@ def test_eth_get_raw_transaction_by_block_raises_error_block_identifier( ) -> None: unknown_identifier = "unknown" with pytest.raises( - ValueError, match=( + ValueError, + match=( f"Value did not match any of the recognized block identifiers: {unknown_identifier}" - ) + ), ): w3.eth.get_raw_transaction_by_block(unknown_identifier, 0) # type: ignore def test_default_account( - self, - w3: "Web3", - unlocked_account_dual_type: ChecksumAddress + self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: # check defaults to empty @@ -3284,7 +3399,7 @@ def test_default_block( # check defaults to 'latest' default_block = w3.eth.default_block - assert default_block == 'latest' + assert default_block == "latest" # check setter w3.eth.default_block = BlockNumber(12345) @@ -3292,4 +3407,4 @@ def test_default_block( assert default_block == BlockNumber(12345) # reset to default - w3.eth.default_block = 'latest' + w3.eth.default_block = "latest" diff --git a/web3/_utils/module_testing/event_contract.py b/web3/_utils/module_testing/event_contract.py index 0bd0224210..c3425abc69 100644 --- a/web3/_utils/module_testing/event_contract.py +++ b/web3/_utils/module_testing/event_contract.py @@ -1,4 +1,3 @@ - EVNT_CONTRACT_CODE = ( "6080604052348015600f57600080fd5b5061010b8061001f6000396000f30060806040526004361" "0603f576000357c0100000000000000000000000000000000000000000000000000000000900463" @@ -25,40 +24,23 @@ EVNT_CONTRACT_ABI = [ { "constant": False, - "inputs": [ - { - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"name": "arg0", "type": "uint256"}], "name": "logTwoEvents", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "anonymous": False, - "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"indexed": False, "name": "arg0", "type": "uint256"}], "name": "LogSingleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": False, - "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"indexed": False, "name": "arg0", "type": "uint256"}], "name": "LogSingleArg", - "type": "event" - } + "type": "event", + }, ] diff --git a/web3/_utils/module_testing/go_ethereum_admin_module.py b/web3/_utils/module_testing/go_ethereum_admin_module.py index 0100d76436..34aa93379d 100644 --- a/web3/_utils/module_testing/go_ethereum_admin_module.py +++ b/web3/_utils/module_testing/go_ethereum_admin_module.py @@ -18,7 +18,10 @@ class GoEthereumAdminModuleTest: def test_add_peer(self, w3: "Web3") -> None: result = w3.geth.admin.add_peer( - EnodeURI('enode://f1a6b0bdbf014355587c3018454d070ac57801f05d3b39fe85da574f002a32e929f683d72aa5a8318382e4d3c7a05c9b91687b0d997a39619fb8a6e7ad88e512@1.1.1.1:30303'),) # noqa: E501 + EnodeURI( + "enode://f1a6b0bdbf014355587c3018454d070ac57801f05d3b39fe85da574f002a32e929f683d72aa5a8318382e4d3c7a05c9b91687b0d997a39619fb8a6e7ad88e512@1.1.1.1:30303" # noqa: E501 + ), + ) assert result is True def test_admin_datadir(self, w3: "Web3", datadir: str) -> None: @@ -27,20 +30,22 @@ def test_admin_datadir(self, w3: "Web3", datadir: str) -> None: def test_admin_node_info(self, w3: "Web3") -> None: result = w3.geth.admin.node_info() - expected = AttributeDict({ - 'id': '', - 'name': '', - 'enode': '', - 'ip': '', - 'ports': AttributeDict({}), - 'listenAddr': '', - 'protocols': AttributeDict({}) - }) + expected = AttributeDict( + { + "id": "", + "name": "", + "enode": "", + "ip": "", + "ports": AttributeDict({}), + "listenAddr": "", + "protocols": AttributeDict({}), + } + ) # Test that result gives at least the keys that are listed in `expected` assert not set(expected.keys()).difference(result.keys()) def test_admin_peers(self, w3: "Web3") -> None: - enode = w3.geth.admin.node_info()['enode'] + enode = w3.geth.admin.node_info()["enode"] w3.geth.admin.add_peer(enode) result = w3.geth.admin.peers() assert len(result) == 1 @@ -53,11 +58,13 @@ def test_admin_start_stop_http(self, w3: "Web3") -> None: assert start is True def test_admin_start_stop_rpc(self, w3: "Web3") -> None: - with pytest.warns(DeprecationWarning, match='deprecated in favor of stop_http'): + with pytest.warns(DeprecationWarning, match="deprecated in favor of stop_http"): stop = w3.geth.admin.stop_rpc() assert stop is True - with pytest.warns(DeprecationWarning, match='deprecated in favor of start_http'): + with pytest.warns( + DeprecationWarning, match="deprecated in favor of start_http" + ): start = w3.geth.admin.start_rpc() assert start is True @@ -70,7 +77,6 @@ def test_admin_start_stop_ws(self, w3: "Web3") -> None: class GoEthereumAsyncAdminModuleTest: - @pytest.mark.asyncio async def test_async_datadir(self, async_w3: "Web3") -> None: datadir = await async_w3.geth.admin.datadir() # type: ignore @@ -88,7 +94,7 @@ async def test_async_nodes(self, async_w3: "Web3") -> None: @pytest.mark.asyncio async def test_admin_peers(self, w3: "Web3") -> None: - enode = await w3.geth.admin.node_info()['enode'] # type: ignore + enode = await w3.geth.admin.node_info()["enode"] # type: ignore w3.geth.admin.add_peer(enode) result = await w3.geth.admin.peers() # type: ignore assert len(result) == 1 @@ -103,11 +109,13 @@ async def test_admin_start_stop_http(self, w3: "Web3") -> None: @pytest.mark.asyncio async def test_admin_start_stop_rpc(self, w3: "Web3") -> None: - with pytest.warns(DeprecationWarning, match='deprecated in favor of stop_http'): + with pytest.warns(DeprecationWarning, match="deprecated in favor of stop_http"): stop = await w3.geth.admin.stop_rpc() assert stop is True - with pytest.warns(DeprecationWarning, match='deprecated in favor of start_http'): + with pytest.warns( + DeprecationWarning, match="deprecated in favor of start_http" + ): start = await w3.geth.admin.start_rpc() assert start is True diff --git a/web3/_utils/module_testing/go_ethereum_personal_module.py b/web3/_utils/module_testing/go_ethereum_personal_module.py index 54a9be0c36..03ac3cd735 100644 --- a/web3/_utils/module_testing/go_ethereum_personal_module.py +++ b/web3/_utils/module_testing/go_ethereum_personal_module.py @@ -32,16 +32,22 @@ if TYPE_CHECKING: from web3 import Web3 # noqa: F401 -PRIVATE_KEY_HEX = '0x56ebb41875ceedd42e395f730e03b5c44989393c9f0484ee6bc05f933673458f' -SECOND_PRIVATE_KEY_HEX = '0x56ebb41875ceedd42e395f730e03b5c44989393c9f0484ee6bc05f9336712345' -THIRD_PRIVATE_KEY_HEX = '0x56ebb41875ceedd42e395f730e03b5c44989393c9f0484ee6bc05f9336754321' -PASSWORD = 'web3-testing' -ADDRESS = '0x844B417c0C58B02c2224306047B9fb0D3264fE8c' -SECOND_ADDRESS = '0xB96b6B21053e67BA59907E252D990C71742c41B8' +PRIVATE_KEY_HEX = "0x56ebb41875ceedd42e395f730e03b5c44989393c9f0484ee6bc05f933673458f" +SECOND_PRIVATE_KEY_HEX = ( + "0x56ebb41875ceedd42e395f730e03b5c44989393c9f0484ee6bc05f9336712345" +) +THIRD_PRIVATE_KEY_HEX = ( + "0x56ebb41875ceedd42e395f730e03b5c44989393c9f0484ee6bc05f9336754321" +) +PASSWORD = "web3-testing" +ADDRESS = "0x844B417c0C58B02c2224306047B9fb0D3264fE8c" +SECOND_ADDRESS = "0xB96b6B21053e67BA59907E252D990C71742c41B8" -PRIVATE_KEY_FOR_UNLOCK = '0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01' -ACCOUNT_FOR_UNLOCK = '0x12efDc31B1a8FA1A1e756DFD8A1601055C971E13' +PRIVATE_KEY_FOR_UNLOCK = ( + "0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01" +) +ACCOUNT_FOR_UNLOCK = "0x12efDc31B1a8FA1A1e756DFD8A1601055C971E13" class GoEthereumPersonalModuleTest: @@ -53,20 +59,16 @@ def test_personal_list_accounts(self, w3: "Web3") -> None: accounts = w3.geth.personal.list_accounts() assert is_list_like(accounts) assert len(accounts) > 0 - assert all(( - is_checksum_address(item) - for item - in accounts - )) + assert all((is_checksum_address(item) for item in accounts)) def test_personal_list_wallets(self, w3: "Web3") -> None: wallets = w3.geth.personal.list_wallets() assert is_list_like(wallets) assert len(wallets) > 0 - assert is_checksum_address(wallets[0]['accounts'][0]['address']) - assert is_string(wallets[0]['accounts'][0]['url']) - assert is_string(wallets[0]['status']) - assert is_string(wallets[0]['url']) + assert is_checksum_address(wallets[0]["accounts"][0]["address"]) + assert is_string(wallets[0]["accounts"][0]["url"]) + assert is_string(wallets[0]["status"]) + assert is_string(wallets[0]["url"]) def test_personal_lock_account( self, w3: "Web3", unlockable_account_dual_type: ChecksumAddress @@ -81,8 +83,7 @@ def test_personal_unlock_account_success( unlockable_account_pw: str, ) -> None: result = w3.geth.personal.unlock_account( - unlockable_account_dual_type, - unlockable_account_pw + unlockable_account_dual_type, unlockable_account_pw ) assert result is True @@ -90,7 +91,9 @@ def test_personal_unlock_account_failure( self, w3: "Web3", unlockable_account_dual_type: ChecksumAddress ) -> None: with pytest.raises(ValueError): - w3.geth.personal.unlock_account(unlockable_account_dual_type, 'bad-password') + w3.geth.personal.unlock_account( + unlockable_account_dual_type, "bad-password" + ) def test_personal_new_account(self, w3: "Web3") -> None: new_account = w3.geth.personal.new_account(PASSWORD) @@ -102,23 +105,29 @@ def test_personal_send_transaction( unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: - assert w3.eth.get_balance(unlockable_account_dual_type) > constants.WEI_PER_ETHER + assert ( + w3.eth.get_balance(unlockable_account_dual_type) > constants.WEI_PER_ETHER + ) txn_params: TxParams = { - 'from': unlockable_account_dual_type, - 'to': unlockable_account_dual_type, - 'gas': 21000, - 'value': Wei(1), - 'gasPrice': w3.toWei(1, 'gwei'), + "from": unlockable_account_dual_type, + "to": unlockable_account_dual_type, + "gas": 21000, + "value": Wei(1), + "gasPrice": w3.toWei(1, "gwei"), } txn_hash = w3.geth.personal.send_transaction(txn_params, unlockable_account_pw) assert txn_hash transaction = w3.eth.get_transaction(txn_hash) - assert is_same_address(transaction['from'], cast(ChecksumAddress, txn_params['from'])) - assert is_same_address(transaction['to'], cast(ChecksumAddress, txn_params['to'])) - assert transaction['gas'] == txn_params['gas'] - assert transaction['value'] == txn_params['value'] - assert transaction['gasPrice'] == txn_params['gasPrice'] + assert is_same_address( + transaction["from"], cast(ChecksumAddress, txn_params["from"]) + ) + assert is_same_address( + transaction["to"], cast(ChecksumAddress, txn_params["to"]) + ) + assert transaction["gas"] == txn_params["gas"] + assert transaction["value"] == txn_params["value"] + assert transaction["gasPrice"] == txn_params["gasPrice"] def test_personal_sign_and_ecrecover( self, @@ -126,11 +135,9 @@ def test_personal_sign_and_ecrecover( unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: - message = 'test-web3-geth-personal-sign' + message = "test-web3-geth-personal-sign" signature = w3.geth.personal.sign( - message, - unlockable_account_dual_type, - unlockable_account_pw + message, unlockable_account_dual_type, unlockable_account_pw ) signer = w3.geth.personal.ec_recover(message, signature) assert is_same_address(signer, unlockable_account_dual_type) @@ -144,7 +151,7 @@ def test_personal_sign_typed_data( unlockable_account_dual_type: ChecksumAddress, unlockable_account_pw: str, ) -> None: - typed_message = ''' + typed_message = """ { "types": { "EIP712Domain": [ @@ -182,12 +189,14 @@ def test_personal_sign_typed_data( "contents": "Hello, Bob!" } } - ''' - signature = HexBytes(w3.geth.personal.sign_typed_data( - json.loads(typed_message), - unlockable_account_dual_type, - unlockable_account_pw - )) + """ + signature = HexBytes( + w3.geth.personal.sign_typed_data( + json.loads(typed_message), + unlockable_account_dual_type, + unlockable_account_pw, + ) + ) expected_signature = HexBytes( "0xc8b56aaeefd10ab4005c2455daf28d9082af661ac347cd" @@ -199,23 +208,25 @@ def test_personal_sign_typed_data( class GoEthereumAsyncPersonalModuleTest: - @pytest.mark.asyncio - async def test_async_sign_and_ec_recover(self, - async_w3: "Web3", - unlockable_account_dual_type: ChecksumAddress, - unlockable_account_pw: str) -> None: + async def test_async_sign_and_ec_recover( + self, + async_w3: "Web3", + unlockable_account_dual_type: ChecksumAddress, + unlockable_account_pw: str, + ) -> None: message = "This is a test" - signature = await async_w3.geth.personal.sign(message, # type: ignore - unlockable_account_dual_type, - unlockable_account_pw) + signature = await async_w3.geth.personal.sign( + message, unlockable_account_dual_type, unlockable_account_pw # type: ignore + ) address = await async_w3.geth.personal.ec_recover(message, signature) # type: ignore assert is_same_address(unlockable_account_dual_type, address) @pytest.mark.asyncio async def test_async_import_key(self, async_w3: "Web3") -> None: - address = await async_w3.geth.personal.import_raw_key(THIRD_PRIVATE_KEY_HEX, # type: ignore - "Testing") + address = await async_w3.geth.personal.import_raw_key( + THIRD_PRIVATE_KEY_HEX, "Testing" # type: ignore + ) assert address is not None @pytest.mark.asyncio @@ -235,41 +246,50 @@ async def test_async_new_account(self, async_w3: "Web3") -> None: assert is_checksum_address(account) @pytest.mark.asyncio - async def test_async_unlock_lock_account(self, - async_w3: "Web3", - unlockable_account_dual_type: ChecksumAddress, - unlockable_account_pw: str) -> None: + async def test_async_unlock_lock_account( + self, + async_w3: "Web3", + unlockable_account_dual_type: ChecksumAddress, + unlockable_account_pw: str, + ) -> None: unlocked = await async_w3.geth.personal.unlock_account( # type: ignore - unlockable_account_dual_type, - unlockable_account_pw) + unlockable_account_dual_type, unlockable_account_pw + ) assert unlocked is True locked = await async_w3.geth.personal.lock_account( # type: ignore - unlockable_account_dual_type) + unlockable_account_dual_type + ) assert locked is True @pytest.mark.asyncio - async def test_async_send_transaction(self, - async_w3: "Web3", - unlockable_account_dual_type: ChecksumAddress, - unlockable_account_pw: str) -> None: + async def test_async_send_transaction( + self, + async_w3: "Web3", + unlockable_account_dual_type: ChecksumAddress, + unlockable_account_pw: str, + ) -> None: tx_params = TxParams() tx_params["to"] = unlockable_account_dual_type tx_params["from"] = unlockable_account_dual_type tx_params["value"] = Wei(123) response = await async_w3.geth.personal.send_transaction( # type: ignore - tx_params, - unlockable_account_pw) + tx_params, unlockable_account_pw + ) assert response is not None - @pytest.mark.xfail(reason="personal_signTypedData JSON RPC call has not been released in geth") + @pytest.mark.xfail( + reason="personal_signTypedData JSON RPC call has not been released in geth" + ) @pytest.mark.asyncio - async def test_async_sign_typed_data(self, - async_w3: "Web3", - unlockable_account_dual_type: ChecksumAddress, - unlockable_account_pw: str) -> None: + async def test_async_sign_typed_data( + self, + async_w3: "Web3", + unlockable_account_dual_type: ChecksumAddress, + unlockable_account_pw: str, + ) -> None: message = {"message": "This is a test"} - signature = await async_w3.geth.personal.sign_typed_data(message, # type: ignore - unlockable_account_dual_type, - unlockable_account_pw) + signature = await async_w3.geth.personal.sign_typed_data( + message, unlockable_account_dual_type, unlockable_account_pw # type: ignore + ) address = await async_w3.geth.personal.ec_recover(message, signature) # type: ignore assert is_same_address(unlockable_account_dual_type, address) diff --git a/web3/_utils/module_testing/go_ethereum_txpool_module.py b/web3/_utils/module_testing/go_ethereum_txpool_module.py index 23a8a87498..9b05a4ccfa 100644 --- a/web3/_utils/module_testing/go_ethereum_txpool_module.py +++ b/web3/_utils/module_testing/go_ethereum_txpool_module.py @@ -4,7 +4,6 @@ class GoEthereumAsyncTxPoolModuleTest: - @pytest.mark.asyncio async def test_async_geth_txpool_inspect(self, async_w3: "Web3") -> None: test_data = await async_w3.geth.txpool.inspect() # type: ignore @@ -22,7 +21,6 @@ async def test_async_geth_txpool_status(self, async_w3: "Web3") -> None: class GoEthereumTxPoolModuleTest: - def test_geth_txpool_inspect(self, w3: "Web3") -> None: test_data = w3.geth.txpool.inspect() # type: ignore assert "pending" in test_data diff --git a/web3/_utils/module_testing/indexed_event_contract.py b/web3/_utils/module_testing/indexed_event_contract.py index 20010dc60d..1f090b6474 100644 --- a/web3/_utils/module_testing/indexed_event_contract.py +++ b/web3/_utils/module_testing/indexed_event_contract.py @@ -1,4 +1,3 @@ - IND_EVENT_CONTRACT_CODE = ( "6080604052348015600f57600080fd5b506101018061001f6000396000f30060806040526004361" "0603f576000357c0100000000000000000000000000000000000000000000000000000000900463" @@ -25,40 +24,23 @@ IND_EVENT_CONTRACT_ABI = [ { "constant": False, - "inputs": [ - { - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"name": "arg0", "type": "uint256"}], "name": "logTwoEvents", "outputs": [], "payable": False, "stateMutability": "nonpayable", - "type": "function" + "type": "function", }, { "anonymous": False, - "inputs": [ - { - "indexed": True, - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"indexed": True, "name": "arg0", "type": "uint256"}], "name": "LogSingleWithIndex", - "type": "event" + "type": "event", }, { "anonymous": False, - "inputs": [ - { - "indexed": False, - "name": "arg0", - "type": "uint256" - } - ], + "inputs": [{"indexed": False, "name": "arg0", "type": "uint256"}], "name": "LogSingleArg", - "type": "event" - } + "type": "event", + }, ] diff --git a/web3/_utils/module_testing/math_contract.py b/web3/_utils/module_testing/math_contract.py index d351f0d5a6..2487f58ded 100644 --- a/web3/_utils/module_testing/math_contract.py +++ b/web3/_utils/module_testing/math_contract.py @@ -1,4 +1,3 @@ - MATH_BYTECODE = ( "606060405261022e806100126000396000f360606040523615610074576000357c01000000000000" "000000000000000000000000000000000000000000009004806316216f391461007657806361bc22" @@ -67,7 +66,7 @@ "outputs": [ {"name": "", "type": "uint256"}, ], - "type": "function" + "type": "function", }, { "constant": False, @@ -91,7 +90,7 @@ ] # The de-compiled math contract, for reference: -''' +""" contract Contract { function main() { memory[0x40:0x60] = 0x60; @@ -190,4 +189,4 @@ return var0; } } -''' +""" diff --git a/web3/_utils/module_testing/module_testing_utils.py b/web3/_utils/module_testing/module_testing_utils.py index 06dfa20674..cbf86cbebb 100644 --- a/web3/_utils/module_testing/module_testing_utils.py +++ b/web3/_utils/module_testing/module_testing_utils.py @@ -47,7 +47,7 @@ def mine_pending_block(w3: "Web3") -> None: w3.geth.miner.start() # type: ignore start = time.time() while time.time() < start + timeout: - if len(w3.eth.get_block('pending')['transactions']) == 0: + if len(w3.eth.get_block("pending")["transactions"]) == 0: break w3.geth.miner.stop() # type: ignore @@ -60,22 +60,21 @@ def assert_contains_log( ) -> None: assert len(result) == 1 log_entry = result[0] - assert log_entry['blockNumber'] == block_with_txn_with_log['number'] - assert log_entry['blockHash'] == block_with_txn_with_log['hash'] - assert log_entry['logIndex'] == 0 - assert is_same_address(log_entry['address'], emitter_contract_address) - assert log_entry['transactionIndex'] == 0 - assert log_entry['transactionHash'] == HexBytes(txn_hash_with_log) + assert log_entry["blockNumber"] == block_with_txn_with_log["number"] + assert log_entry["blockHash"] == block_with_txn_with_log["hash"] + assert log_entry["logIndex"] == 0 + assert is_same_address(log_entry["address"], emitter_contract_address) + assert log_entry["transactionIndex"] == 0 + assert log_entry["transactionHash"] == HexBytes(txn_hash_with_log) def mock_offchain_lookup_request_response( monkeypatch: "MonkeyPatch", - http_method: Literal['GET', 'POST'] = 'GET', + http_method: Literal["GET", "POST"] = "GET", mocked_request_url: str = None, mocked_status_code: int = 200, - mocked_json_data: str = '0x', - json_data_field: str = 'data', - + mocked_json_data: str = "0x", + json_data_field: str = "data", # required only for POST validation: sender: str = None, calldata: str = None, @@ -84,10 +83,12 @@ class MockedResponse: status_code = mocked_status_code @staticmethod - def json() -> Dict[str, str]: return {json_data_field: mocked_json_data} # noqa: E704 + def json() -> Dict[str, str]: + return {json_data_field: mocked_json_data} # noqa: E704 @staticmethod - def raise_for_status() -> None: raise Exception("called raise_for_status()") # noqa: E704 + def raise_for_status() -> None: + raise Exception("called raise_for_status()") # noqa: E704 def _mock_specific_request( *args: Any, **kwargs: Any @@ -96,32 +97,30 @@ def _mock_specific_request( # mock response only to specified url while validating appropriate fields if url_from_args == mocked_request_url: - assert kwargs['timeout'] == 10 - if http_method.upper() == 'POST': - assert kwargs['data'] == {'data': calldata, 'sender': sender} + assert kwargs["timeout"] == 10 + if http_method.upper() == "POST": + assert kwargs["data"] == {"data": calldata, "sender": sender} return MockedResponse() # else, make a normal request (no mocking) session = get_session(url_from_args) - return session.request( - method=http_method.upper(), - url=url_from_args, - **kwargs - ) + return session.request(method=http_method.upper(), url=url_from_args, **kwargs) - monkeypatch.setattr(f'requests.Session.{http_method.lower()}', _mock_specific_request) + monkeypatch.setattr( + f"requests.Session.{http_method.lower()}", _mock_specific_request + ) # -- async -- # + def async_mock_offchain_lookup_request_response( monkeypatch: "MonkeyPatch", - http_method: Literal['GET', 'POST'] = 'GET', + http_method: Literal["GET", "POST"] = "GET", mocked_request_url: str = None, mocked_status_code: int = 200, - mocked_json_data: str = '0x', - json_data_field: str = 'data', - + mocked_json_data: str = "0x", + json_data_field: str = "data", # required only for POST validation: sender: str = None, calldata: str = None, @@ -134,10 +133,12 @@ def __await__(self) -> Generator[Any, Any, Any]: return self @staticmethod - async def json() -> Dict[str, str]: return {json_data_field: mocked_json_data} # noqa: E704 + async def json() -> Dict[str, str]: + return {json_data_field: mocked_json_data} # noqa: E704 @staticmethod - def raise_for_status() -> None: raise Exception("called raise_for_status()") # noqa: E501, E704 + def raise_for_status() -> None: + raise Exception("called raise_for_status()") # noqa: E501, E704 async def _mock_specific_request( *args: Any, **kwargs: Any @@ -146,17 +147,17 @@ async def _mock_specific_request( # mock response only to specified url while validating appropriate fields if url_from_args == mocked_request_url: - assert kwargs['timeout'] == ClientTimeout(10) - if http_method.upper() == 'post': - assert kwargs['data'] == {'data': calldata, 'sender': sender} + assert kwargs["timeout"] == ClientTimeout(10) + if http_method.upper() == "post": + assert kwargs["data"] == {"data": calldata, "sender": sender} return AsyncMockedResponse() # else, make a normal request (no mocking) session = await get_async_session(url_from_args) return await session.request( - method=http_method.upper(), - url=url_from_args, - **kwargs + method=http_method.upper(), url=url_from_args, **kwargs ) - monkeypatch.setattr(f'aiohttp.ClientSession.{http_method.lower()}', _mock_specific_request) + monkeypatch.setattr( + f"aiohttp.ClientSession.{http_method.lower()}", _mock_specific_request + ) diff --git a/web3/_utils/module_testing/no_receive_contract.py b/web3/_utils/module_testing/no_receive_contract.py index b919b2f96a..2afeb62353 100644 --- a/web3/_utils/module_testing/no_receive_contract.py +++ b/web3/_utils/module_testing/no_receive_contract.py @@ -1,4 +1,4 @@ -CONTRACT_NO_RECEIVE_SOURCE_CODE = ''' +CONTRACT_NO_RECEIVE_SOURCE_CODE = """ pragma solidity ^0.6.0; @@ -18,10 +18,10 @@ } } -''' +""" -CONTRACT_NO_RECEIVE_FUNCTION_ABI = ''' +CONTRACT_NO_RECEIVE_FUNCTION_ABI = """ [ { "stateMutability": "nonpayable", @@ -60,7 +60,7 @@ "type": "function" } ] -''' +""" CONTRACT_NO_RECEIVE_FUNCTION_CODE = "608060405234801561001057600080fd5b50610396806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80635d3a1f9d14610068578063e00fe2eb14610183575b6040805180820190915260088082526766616c6c6261636b60c01b6020909201918252610065916000916102c8565b50005b61010e6004803603602081101561007e57600080fd5b81019060208101813564010000000081111561009957600080fd5b8201836020820111156100ab57600080fd5b803590602001918460018302840111640100000000831117156100cd57600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061018b945050505050565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610148578181015183820152602001610130565b50505050905090810190601f1680156101755780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61010e610231565b80516060906101a19060009060208501906102c8565b805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156102255780601f106101fa57610100808354040283529160200191610225565b820191906000526020600020905b81548152906001019060200180831161020857829003601f168201915b50505050509050919050565b60008054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156102bd5780601f10610292576101008083540402835291602001916102bd565b820191906000526020600020905b8154815290600101906020018083116102a057829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061030957805160ff1916838001178555610336565b82800160010185558215610336579182015b8281111561033657825182559160200191906001019061031b565b50610342929150610346565b5090565b6102c591905b80821115610342576000815560010161034c56fea26469706673582212208c33db8b08eb0abda95d96bba0df24cf6356f47eb17c4f556a3427dc161852db64736f6c63430006010033" # noqa: E501 diff --git a/web3/_utils/module_testing/offchain_lookup_contract.py b/web3/_utils/module_testing/offchain_lookup_contract.py index ee4240b8bd..7f7e1f35e7 100644 --- a/web3/_utils/module_testing/offchain_lookup_contract.py +++ b/web3/_utils/module_testing/offchain_lookup_contract.py @@ -3,7 +3,8 @@ # contract source at .contract_sources/OffchainLookup.sol OFFCHAIN_LOOKUP_BYTECODE = "608060405260405180604001604052806040518060600160405280602c815260200162000ec9602c9139815260200160405180606001604052806025815260200162000ef56025913981525060009060026200005d92919062000072565b503480156200006b57600080fd5b506200025b565b828054828255906000526020600020908101928215620000c6579160200282015b82811115620000c5578251829080519060200190620000b4929190620000d9565b509160200191906001019062000093565b5b509050620000d591906200016a565b5090565b828054620000e79062000226565b90600052602060002090601f0160209004810192826200010b576000855562000157565b82601f106200012657805160ff191683800117855562000157565b8280016001018555821562000157579182015b828111156200015657825182559160200191906001019062000139565b5b50905062000166919062000192565b5090565b5b808211156200018e5760008181620001849190620001b1565b506001016200016b565b5090565b5b80821115620001ad57600081600090555060010162000193565b5090565b508054620001bf9062000226565b6000825580601f10620001d35750620001f4565b601f016020900490600052602060002090810190620001f3919062000192565b5b50565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200023f57607f821691505b602082108103620002555762000254620001f7565b5b50919050565b610c5e806200026b6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806309a3c01b146100465780636337ed5814610064578063da96d05a14610094575b600080fd5b61004e6100c4565b60405161005b9190610424565b60405180910390f35b61007e600480360381019061007991906104bf565b610114565b60405161008b9190610424565b60405180910390f35b6100ae60048036038101906100a9919061050c565b610202565b6040516100bb9190610424565b60405180910390f35b606080306000826309a3c01b60e01b846040517f556f183000000000000000000000000000000000000000000000000000000000815260040161010b9594939291906107d5565b60405180910390fd5b606060008383810190610127919061096d565b90507fd9bdd1345ca2a00d0c1413137c1b2b1d0a35e5b0e11508f3b3eff856286af0758160405160200161015b91906109fd565b60405160208183030381529060405280519060200120146101b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a890610a71565b60405180910390fd5b306000858563da96d05a60e01b88886040517f556f18300000000000000000000000000000000000000000000000000000000081526004016101f99796959493929190610abe565b60405180910390fd5b606060008585810190610215919061096d565b90507faed76f463930323372899e36460e078e5292aac45f645bbe567be6fca83ede108160405160200161024991906109fd565b604051602081830303815290604052805190602001201461029f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161029690610b9c565b60405180910390fd5b600084848101906102b0919061096d565b90507fd9bdd1345ca2a00d0c1413137c1b2b1d0a35e5b0e11508f3b3eff856286af075816040516020016102e491906109fd565b604051602081830303815290604052805190602001201461033a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161033190610c08565b60405180910390fd5b86868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505092505050949350505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103c55780820151818401526020810190506103aa565b838111156103d4576000848401525b50505050565b6000601f19601f8301169050919050565b60006103f68261038b565b6104008185610396565b93506104108185602086016103a7565b610419816103da565b840191505092915050565b6000602082019050818103600083015261043e81846103eb565b905092915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f84011261047f5761047e61045a565b5b8235905067ffffffffffffffff81111561049c5761049b61045f565b5b6020830191508360018202830111156104b8576104b7610464565b5b9250929050565b600080602083850312156104d6576104d5610450565b5b600083013567ffffffffffffffff8111156104f4576104f3610455565b5b61050085828601610469565b92509250509250929050565b6000806000806040858703121561052657610525610450565b5b600085013567ffffffffffffffff81111561054457610543610455565b5b61055087828801610469565b9450945050602085013567ffffffffffffffff81111561057357610572610455565b5b61057f87828801610469565b925092505092959194509250565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105b88261058d565b9050919050565b6105c8816105ad565b82525050565b600081549050919050565b600082825260208201905092915050565b60008190508160005260206000209050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061064657607f821691505b602082108103610659576106586105ff565b5b50919050565b600082825260208201905092915050565b60008190508160005260206000209050919050565b600081546106928161062e565b61069c818661065f565b945060018216600081146106b757600181146106c9576106fc565b60ff19831686526020860193506106fc565b6106d285610670565b60005b838110156106f4578154818901526001820191506020810190506106d5565b808801955050505b50505092915050565b60006107118383610685565b905092915050565b6000600182019050919050565b6000610731826105ce565b61073b81856105d9565b93508360208202850161074d856105ea565b8060005b85811015610788578484038952816107698582610705565b945061077483610719565b925060208a01995050600181019050610751565b50829750879550505050505092915050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6107cf8161079a565b82525050565b600060a0820190506107ea60008301886105bf565b81810360208301526107fc8187610726565b9050818103604083015261081081866103eb565b905061081f60608301856107c6565b818103608083015261083181846103eb565b90509695505050505050565b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61087a826103da565b810181811067ffffffffffffffff8211171561089957610898610842565b5b80604052505050565b60006108ac610446565b90506108b88282610871565b919050565b600067ffffffffffffffff8211156108d8576108d7610842565b5b6108e1826103da565b9050602081019050919050565b82818337600083830152505050565b600061091061090b846108bd565b6108a2565b90508281526020810184848401111561092c5761092b61083d565b5b6109378482856108ee565b509392505050565b600082601f8301126109545761095361045a565b5b81356109648482602086016108fd565b91505092915050565b60006020828403121561098357610982610450565b5b600082013567ffffffffffffffff8111156109a1576109a0610455565b5b6109ad8482850161093f565b91505092915050565b600081519050919050565b600081905092915050565b60006109d7826109b6565b6109e181856109c1565b93506109f18185602086016103a7565b80840191505092915050565b6000610a0982846109cc565b915081905092915050565b600082825260208201905092915050565b7f7465737420646174612076616c69646174696f6e206661696c65642e00000000600082015250565b6000610a5b601c83610a14565b9150610a6682610a25565b602082019050919050565b60006020820190508181036000830152610a8a81610a4e565b9050919050565b6000610a9d8385610396565b9350610aaa8385846108ee565b610ab3836103da565b840190509392505050565b600060a082019050610ad3600083018a6105bf565b8181036020830152610ae58189610726565b90508181036040830152610afa818789610a91565b9050610b0960608301866107c6565b8181036080830152610b1c818486610a91565b905098975050505050505050565b7f68747470207265717565737420726573756c742076616c69646174696f6e206660008201527f61696c65642e0000000000000000000000000000000000000000000000000000602082015250565b6000610b86602683610a14565b9150610b9182610b2a565b604082019050919050565b60006020820190508181036000830152610bb581610b79565b9050919050565b7f6578747261446174612076616c69646174696f6e206661696c65642e00000000600082015250565b6000610bf2601c83610a14565b9150610bfd82610bbc565b602082019050919050565b60006020820190508181036000830152610c2181610be5565b905091905056fea2646970667358221220528c32029f8724a4e2b6a2a469880824c952eae5971f18628559629192c102b164736f6c634300080d003368747470733a2f2f776562332e70792f676174657761792f7b73656e6465727d2f7b646174617d2e6a736f6e68747470733a2f2f776562332e70792f676174657761792f7b73656e6465727d2e6a736f6e" # noqa: E501 OFFCHAIN_LOOKUP_BYTECODE_RUNTIME = "608060405234801561001057600080fd5b50600436106100415760003560e01c806309a3c01b146100465780636337ed5814610064578063da96d05a14610094575b600080fd5b61004e6100c4565b60405161005b9190610424565b60405180910390f35b61007e600480360381019061007991906104bf565b610114565b60405161008b9190610424565b60405180910390f35b6100ae60048036038101906100a9919061050c565b610202565b6040516100bb9190610424565b60405180910390f35b606080306000826309a3c01b60e01b846040517f556f183000000000000000000000000000000000000000000000000000000000815260040161010b9594939291906107d5565b60405180910390fd5b606060008383810190610127919061096d565b90507fd9bdd1345ca2a00d0c1413137c1b2b1d0a35e5b0e11508f3b3eff856286af0758160405160200161015b91906109fd565b60405160208183030381529060405280519060200120146101b1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101a890610a71565b60405180910390fd5b306000858563da96d05a60e01b88886040517f556f18300000000000000000000000000000000000000000000000000000000081526004016101f99796959493929190610abe565b60405180910390fd5b606060008585810190610215919061096d565b90507faed76f463930323372899e36460e078e5292aac45f645bbe567be6fca83ede108160405160200161024991906109fd565b604051602081830303815290604052805190602001201461029f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161029690610b9c565b60405180910390fd5b600084848101906102b0919061096d565b90507fd9bdd1345ca2a00d0c1413137c1b2b1d0a35e5b0e11508f3b3eff856286af075816040516020016102e491906109fd565b604051602081830303815290604052805190602001201461033a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161033190610c08565b60405180910390fd5b86868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505092505050949350505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103c55780820151818401526020810190506103aa565b838111156103d4576000848401525b50505050565b6000601f19601f8301169050919050565b60006103f68261038b565b6104008185610396565b93506104108185602086016103a7565b610419816103da565b840191505092915050565b6000602082019050818103600083015261043e81846103eb565b905092915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b600080fd5b60008083601f84011261047f5761047e61045a565b5b8235905067ffffffffffffffff81111561049c5761049b61045f565b5b6020830191508360018202830111156104b8576104b7610464565b5b9250929050565b600080602083850312156104d6576104d5610450565b5b600083013567ffffffffffffffff8111156104f4576104f3610455565b5b61050085828601610469565b92509250509250929050565b6000806000806040858703121561052657610525610450565b5b600085013567ffffffffffffffff81111561054457610543610455565b5b61055087828801610469565b9450945050602085013567ffffffffffffffff81111561057357610572610455565b5b61057f87828801610469565b925092505092959194509250565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006105b88261058d565b9050919050565b6105c8816105ad565b82525050565b600081549050919050565b600082825260208201905092915050565b60008190508160005260206000209050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061064657607f821691505b602082108103610659576106586105ff565b5b50919050565b600082825260208201905092915050565b60008190508160005260206000209050919050565b600081546106928161062e565b61069c818661065f565b945060018216600081146106b757600181146106c9576106fc565b60ff19831686526020860193506106fc565b6106d285610670565b60005b838110156106f4578154818901526001820191506020810190506106d5565b808801955050505b50505092915050565b60006107118383610685565b905092915050565b6000600182019050919050565b6000610731826105ce565b61073b81856105d9565b93508360208202850161074d856105ea565b8060005b85811015610788578484038952816107698582610705565b945061077483610719565b925060208a01995050600181019050610751565b50829750879550505050505092915050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6107cf8161079a565b82525050565b600060a0820190506107ea60008301886105bf565b81810360208301526107fc8187610726565b9050818103604083015261081081866103eb565b905061081f60608301856107c6565b818103608083015261083181846103eb565b90509695505050505050565b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61087a826103da565b810181811067ffffffffffffffff8211171561089957610898610842565b5b80604052505050565b60006108ac610446565b90506108b88282610871565b919050565b600067ffffffffffffffff8211156108d8576108d7610842565b5b6108e1826103da565b9050602081019050919050565b82818337600083830152505050565b600061091061090b846108bd565b6108a2565b90508281526020810184848401111561092c5761092b61083d565b5b6109378482856108ee565b509392505050565b600082601f8301126109545761095361045a565b5b81356109648482602086016108fd565b91505092915050565b60006020828403121561098357610982610450565b5b600082013567ffffffffffffffff8111156109a1576109a0610455565b5b6109ad8482850161093f565b91505092915050565b600081519050919050565b600081905092915050565b60006109d7826109b6565b6109e181856109c1565b93506109f18185602086016103a7565b80840191505092915050565b6000610a0982846109cc565b915081905092915050565b600082825260208201905092915050565b7f7465737420646174612076616c69646174696f6e206661696c65642e00000000600082015250565b6000610a5b601c83610a14565b9150610a6682610a25565b602082019050919050565b60006020820190508181036000830152610a8a81610a4e565b9050919050565b6000610a9d8385610396565b9350610aaa8385846108ee565b610ab3836103da565b840190509392505050565b600060a082019050610ad3600083018a6105bf565b8181036020830152610ae58189610726565b90508181036040830152610afa818789610a91565b9050610b0960608301866107c6565b8181036080830152610b1c818486610a91565b905098975050505050505050565b7f68747470207265717565737420726573756c742076616c69646174696f6e206660008201527f61696c65642e0000000000000000000000000000000000000000000000000000602082015250565b6000610b86602683610a14565b9150610b9182610b2a565b604082019050919050565b60006020820190508181036000830152610bb581610b79565b9050919050565b7f6578747261446174612076616c69646174696f6e206661696c65642e00000000600082015250565b6000610bf2601c83610a14565b9150610bfd82610bbc565b602082019050919050565b60006020820190508181036000830152610c2181610be5565b905091905056fea2646970667358221220528c32029f8724a4e2b6a2a469880824c952eae5971f18628559629192c102b164736f6c634300080d0033" # noqa: E501 -OFFCHAIN_LOOKUP_ABI = json.loads('''[ +OFFCHAIN_LOOKUP_ABI = json.loads( + """[ { "inputs": [ { @@ -101,4 +102,5 @@ "stateMutability": "nonpayable", "type": "function" } -]''') +]""" +) diff --git a/web3/_utils/module_testing/receive_contract.py b/web3/_utils/module_testing/receive_contract.py index d22091287c..fbc264b335 100644 --- a/web3/_utils/module_testing/receive_contract.py +++ b/web3/_utils/module_testing/receive_contract.py @@ -1,4 +1,4 @@ -CONTRACT_RECEIVE_FUNCTION_SOURCE = ''' +CONTRACT_RECEIVE_FUNCTION_SOURCE = """ pragma solidity ^0.6.0; @@ -21,10 +21,10 @@ return text = new_text; } } -''' +""" -CONTRACT_RECEIVE_FUNCTION_ABI = ''' +CONTRACT_RECEIVE_FUNCTION_ABI = """ [ { "stateMutability": "payable", @@ -67,7 +67,7 @@ "type": "receive" } ] -''' +""" CONTRACT_RECEIVE_FUNCTION_CODE = "608060405234801561001057600080fd5b506103da806100206000396000f3fe60806040526004361061002d5760003560e01c80635d3a1f9d14610092578063e00fe2eb146101ba57610063565b3661006357604080518082019091526007808252667265636569766560c81b60209092019182526100609160009161030c565b50005b6040805180820190915260088082526766616c6c6261636b60c01b60209092019182526100609160009161030c565b34801561009e57600080fd5b50610145600480360360208110156100b557600080fd5b8101906020810181356401000000008111156100d057600080fd5b8201836020820111156100e257600080fd5b8035906020019184600183028401116401000000008311171561010457600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506101cf945050505050565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561017f578181015183820152602001610167565b50505050905090810190601f1680156101ac5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101c657600080fd5b50610145610275565b80516060906101e590600090602085019061030c565b805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156102695780601f1061023e57610100808354040283529160200191610269565b820191906000526020600020905b81548152906001019060200180831161024c57829003601f168201915b50505050509050919050565b60008054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156103015780601f106102d657610100808354040283529160200191610301565b820191906000526020600020905b8154815290600101906020018083116102e457829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061034d57805160ff191683800117855561037a565b8280016001018555821561037a579182015b8281111561037a57825182559160200191906001019061035f565b5061038692915061038a565b5090565b61030991905b80821115610386576000815560010161039056fea2646970667358221220b93632f6dd6614e84675a1453e32b49de37a5d658a6e73173705c5a7dffc0bdd64736f6c63430006010033" # noqa: E501 diff --git a/web3/_utils/module_testing/revert_contract.py b/web3/_utils/module_testing/revert_contract.py index 6a7e65ceed..3295d6375d 100644 --- a/web3/_utils/module_testing/revert_contract.py +++ b/web3/_utils/module_testing/revert_contract.py @@ -25,7 +25,8 @@ REVERT_CONTRACT_RUNTIME_CODE = "6080604052348015600f57600080fd5b5060043610603c5760003560e01c8063185c38a4146041578063c06a97cb146049578063d67e4b84146051575b600080fd5b60476071565b005b604f60df565b005b605760e4565b604051808215151515815260200191505060405180910390f35b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f46756e6374696f6e20686173206265656e2072657665727465642e000000000081525060200191505060405180910390fd5b600080fd5b6000600190509056fea264697066735822122062c811906544562ea796d11199e2d956938f2a76c2aa3053dc7ab2470d854c0a64736f6c63430006060033" # noqa: E501 -_REVERT_CONTRACT_ABI = json.loads('''[ +_REVERT_CONTRACT_ABI = json.loads( + """[ { "inputs": [], "name": "normalFunction", @@ -56,4 +57,5 @@ "stateMutability": "pure", "type": "function" } -]''') +]""" +) diff --git a/web3/_utils/module_testing/web3_module.py b/web3/_utils/module_testing/web3_module.py index 73abb9cbfb..5c007d9498 100644 --- a/web3/_utils/module_testing/web3_module.py +++ b/web3/_utils/module_testing/web3_module.py @@ -35,148 +35,196 @@ def _check_web3_clientVersion(self, client_version: str) -> NoReturn: # Contract that calculated test values can be found at # https://kovan.etherscan.io/address/0xb9be06f5b99372cf9afbccadbbb9954ccaf7f4bb#code @pytest.mark.parametrize( - 'types,values,expected', + "types,values,expected", ( ( - ['bool'], + ["bool"], [True], - HexBytes("0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2"), + HexBytes( + "0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2" + ), ), ( - ['uint8', 'uint8', 'uint8'], + ["uint8", "uint8", "uint8"], [97, 98, 99], - HexBytes("0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45"), + HexBytes( + "0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45" + ), ), ( - ['uint248'], + ["uint248"], [30], - HexBytes("0x30f95d210785601eb33ae4d53d405b26f920e765dff87cca8e9a4aec99f82671"), + HexBytes( + "0x30f95d210785601eb33ae4d53d405b26f920e765dff87cca8e9a4aec99f82671" + ), ), ( - ['bool', 'uint16'], + ["bool", "uint16"], [True, 299], - HexBytes("0xed18599ccd80ee9fae9a28b0e34a5573c3233d7468f808fd659bc171cf0b43bd"), + HexBytes( + "0xed18599ccd80ee9fae9a28b0e34a5573c3233d7468f808fd659bc171cf0b43bd" + ), ), ( - ['int256'], + ["int256"], [-10], - HexBytes("0xd6fb717f7e270a360f5093ce6a7a3752183e89c9a9afe5c0cb54b458a304d3d5"), + HexBytes( + "0xd6fb717f7e270a360f5093ce6a7a3752183e89c9a9afe5c0cb54b458a304d3d5" + ), ), ( - ['int256'], + ["int256"], [10], - HexBytes("0xc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a8"), + HexBytes( + "0xc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a8" + ), ), ( - ['int8', 'uint8'], + ["int8", "uint8"], [-10, 18], - HexBytes("0x5c6ab1e634c08d9c0f4df4d789e8727943ef010dd7ca8e3c89de197a26d148be"), + HexBytes( + "0x5c6ab1e634c08d9c0f4df4d789e8727943ef010dd7ca8e3c89de197a26d148be" + ), ), ( - ['address'], + ["address"], ["0x49eddd3769c0712032808d86597b84ac5c2f5614"], InvalidAddress, ), ( - ['address'], + ["address"], ["0x49EdDD3769c0712032808D86597B84ac5c2F5614"], - HexBytes("0x2ff37b5607484cd4eecf6d13292e22bd6e5401eaffcc07e279583bc742c68882"), + HexBytes( + "0x2ff37b5607484cd4eecf6d13292e22bd6e5401eaffcc07e279583bc742c68882" + ), ), ( - ['bytes2'], - ['0x5402'], - HexBytes("0x4ed9171bda52fca71ab28e7f452bd6eacc3e5a568a47e0fa53b503159a9b8910"), + ["bytes2"], + ["0x5402"], + HexBytes( + "0x4ed9171bda52fca71ab28e7f452bd6eacc3e5a568a47e0fa53b503159a9b8910" + ), ), ( - ['bytes3'], - ['0x5402'], - HexBytes("0x4ed9171bda52fca71ab28e7f452bd6eacc3e5a568a47e0fa53b503159a9b8910"), + ["bytes3"], + ["0x5402"], + HexBytes( + "0x4ed9171bda52fca71ab28e7f452bd6eacc3e5a568a47e0fa53b503159a9b8910" + ), ), ( - ['bytes'], + ["bytes"], [ - '0x636865636b6c6f6e6762797465737472696e676167' - '61696e7374736f6c6964697479736861336861736866756e6374696f6e' + "0x636865636b6c6f6e6762797465737472696e676167" + "61696e7374736f6c6964697479736861336861736866756e6374696f6e" ], - HexBytes("0xd78a84d65721b67e4011b10c99dafdedcdcd7cb30153064f773e210b4762e22f"), + HexBytes( + "0xd78a84d65721b67e4011b10c99dafdedcdcd7cb30153064f773e210b4762e22f" + ), ), ( - ['string'], - ['testing a string!'], - HexBytes("0xe8c275c0b4070a5ec6cfcb83f0ba394b30ddd283de785d43f2eabfb04bd96747"), + ["string"], + ["testing a string!"], + HexBytes( + "0xe8c275c0b4070a5ec6cfcb83f0ba394b30ddd283de785d43f2eabfb04bd96747" + ), ), ( - ['string', 'bool', 'uint16', 'bytes2', 'address'], + ["string", "bool", "uint16", "bytes2", "address"], [ - 'testing a string!', + "testing a string!", False, 299, - '0x5402', + "0x5402", "0x49eddd3769c0712032808d86597b84ac5c2f5614", ], InvalidAddress, ), ( - ['string', 'bool', 'uint16', 'bytes2', 'address'], + ["string", "bool", "uint16", "bytes2", "address"], [ - 'testing a string!', + "testing a string!", False, 299, - '0x5402', + "0x5402", "0x49EdDD3769c0712032808D86597B84ac5c2F5614", ], - HexBytes("0x8cc6eabb25b842715e8ca39e2524ed946759aa37bfb7d4b81829cf5a7e266103"), + HexBytes( + "0x8cc6eabb25b842715e8ca39e2524ed946759aa37bfb7d4b81829cf5a7e266103" + ), ), ( - ['bool[2][]'], + ["bool[2][]"], [[[True, False], [False, True]]], - HexBytes("0x1eef261f2eb51a8c736d52be3f91ff79e78a9ec5df2b7f50d0c6f98ed1e2bc06"), + HexBytes( + "0x1eef261f2eb51a8c736d52be3f91ff79e78a9ec5df2b7f50d0c6f98ed1e2bc06" + ), ), ( - ['bool[]'], + ["bool[]"], [[True, False, True]], - HexBytes("0x5c6090c0461491a2941743bda5c3658bf1ea53bbd3edcde54e16205e18b45792"), + HexBytes( + "0x5c6090c0461491a2941743bda5c3658bf1ea53bbd3edcde54e16205e18b45792" + ), ), ( - ['uint24[]'], + ["uint24[]"], [[1, 0, 1]], - HexBytes("0x5c6090c0461491a2941743bda5c3658bf1ea53bbd3edcde54e16205e18b45792"), + HexBytes( + "0x5c6090c0461491a2941743bda5c3658bf1ea53bbd3edcde54e16205e18b45792" + ), ), ( - ['uint8[2]'], + ["uint8[2]"], [[8, 9]], - HexBytes("0xc7694af312c4f286114180fd0ba6a52461fcee8a381636770b19a343af92538a"), + HexBytes( + "0xc7694af312c4f286114180fd0ba6a52461fcee8a381636770b19a343af92538a" + ), ), ( - ['uint256[2]'], + ["uint256[2]"], [[8, 9]], - HexBytes("0xc7694af312c4f286114180fd0ba6a52461fcee8a381636770b19a343af92538a"), + HexBytes( + "0xc7694af312c4f286114180fd0ba6a52461fcee8a381636770b19a343af92538a" + ), ), ( - ['uint8[]'], + ["uint8[]"], [[8]], - HexBytes("0xf3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee3"), + HexBytes( + "0xf3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee3" + ), ), ( - ['address[]'], - [[ - "0x49EdDD3769c0712032808D86597B84ac5c2F5614", - "0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5", - ]], - HexBytes("0xb98565c0c26a962fd54d93b0ed6fb9296e03e9da29d2281ed3e3473109ef7dde"), + ["address[]"], + [ + [ + "0x49EdDD3769c0712032808D86597B84ac5c2F5614", + "0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5", + ] + ], + HexBytes( + "0xb98565c0c26a962fd54d93b0ed6fb9296e03e9da29d2281ed3e3473109ef7dde" + ), ), ( - ['address[]'], - [[ - "0x49EdDD3769c0712032808D86597B84ac5c2F5614", - "0xa6b759bbbf4b59d24acf7e06e79f3a5d104fdce5", - ]], + ["address[]"], + [ + [ + "0x49EdDD3769c0712032808D86597B84ac5c2F5614", + "0xa6b759bbbf4b59d24acf7e06e79f3a5d104fdce5", + ] + ], InvalidAddress, ), ), ) def test_solidityKeccak( - self, w3: "Web3", types: Sequence[TypeStr], values: Sequence[Any], expected: HexBytes + self, + w3: "Web3", + types: Sequence[TypeStr], + values: Sequence[Any], + expected: HexBytes, ) -> None: if isinstance(expected, type) and issubclass(expected, Exception): with pytest.raises(expected): # type: ignore @@ -187,31 +235,42 @@ def test_solidityKeccak( assert actual == expected @pytest.mark.parametrize( - 'types, values, expected', + "types, values, expected", ( ( - ['address'], - ['one.eth'], - HexBytes("0x2ff37b5607484cd4eecf6d13292e22bd6e5401eaffcc07e279583bc742c68882"), + ["address"], + ["one.eth"], + HexBytes( + "0x2ff37b5607484cd4eecf6d13292e22bd6e5401eaffcc07e279583bc742c68882" + ), ), ( - ['address[]'], - [['one.eth', 'two.eth']], - HexBytes("0xb98565c0c26a962fd54d93b0ed6fb9296e03e9da29d2281ed3e3473109ef7dde"), + ["address[]"], + [["one.eth", "two.eth"]], + HexBytes( + "0xb98565c0c26a962fd54d93b0ed6fb9296e03e9da29d2281ed3e3473109ef7dde" + ), ), ), ) def test_solidityKeccak_ens( - self, w3: "Web3", types: Sequence[TypeStr], values: Sequence[str], expected: HexBytes + self, + w3: "Web3", + types: Sequence[TypeStr], + values: Sequence[str], + expected: HexBytes, ) -> None: - with ens_addresses(w3, { - 'one.eth': ChecksumAddress( - HexAddress(HexStr("0x49EdDD3769c0712032808D86597B84ac5c2F5614")) - ), - 'two.eth': ChecksumAddress( - HexAddress(HexStr("0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5")) - ), - }): + with ens_addresses( + w3, + { + "one.eth": ChecksumAddress( + HexAddress(HexStr("0x49EdDD3769c0712032808D86597B84ac5c2F5614")) + ), + "two.eth": ChecksumAddress( + HexAddress(HexStr("0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5")) + ), + }, + ): # when called as class method, any name lookup attempt will fail with pytest.raises(InvalidAddress): Web3.solidityKeccak(types, values) @@ -221,12 +280,12 @@ def test_solidityKeccak_ens( assert actual == expected @pytest.mark.parametrize( - 'types,values', + "types,values", ( - (['address'], ['0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5', True]), - (['address', 'bool'], ['0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5']), - ([], ['0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5']), - ) + (["address"], ["0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5", True]), + (["address", "bool"], ["0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5"]), + ([], ["0xA6b759bBbf4B59D24acf7E06e79f3a5D104fdCE5"]), + ), ) def test_solidityKeccak_same_number_of_types_and_values( self, w3: "Web3", types: Sequence[TypeStr], values: Sequence[Any]