Repository: ethereum/web3.py
Issue: string and byte conversion in events.py corrupts data

* Version: 3.2.0
* Python: 3.5
* OS: linux


### What was wrong?
My strings passed in contract events get corrupted. They look like this when I listen to events:
`'_ipfsaddr': '\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00`'`

### solution

```
--- events.py   2016-12-07 14:21:27.523182611 +0100
+++ events-new.py       2016-12-07 14:18:24.779178254 +0100
@@ -116,8 +116,8 @@
     entries using the correct types.
     """
     return [
-        'bytes32' if arg_type in {'bytes', 'string'} else arg_type
-        for arg_type in input_types
+        #'bytes32' if arg_type in {'bytes', 'string'} else arg_type
+        arg_type for arg_type in input_types
     ]
```
now I get my ipfs address correctly:
`'_ipfsaddr': 'QmSL2Zj3QmQFNcF6pethSYDF8fGYpz1LDeFiaLSzkCtAQ2'`

Changed files:
web3/utils/functional.py, web3/utils/abi.py, web3/utils/events.py, tests/contracts/test_extracting_event_data.py, tests/contracts/conftest.py

diff --git a/tests/contracts/conftest.py b/tests/contracts/conftest.py
index dc5a9036..4dab8fff 100644
--- a/tests/contracts/conftest.py
+++ b/tests/contracts/conftest.py
@@ -282,6 +282,7 @@ contract Emitter {
     event LogDoubleWithIndex(uint arg0, uint indexed arg1);
     event LogTripleWithIndex(uint arg0, uint indexed arg1, uint indexed arg2);
     event LogQuadrupleWithIndex(uint arg0, uint arg1, uint indexed arg2, uint indexed arg3);
+    event LogDynamicArgs(string indexed arg0, string arg1);
 
     // Bytes and String
     event LogBytes(bytes v);
@@ -341,14 +342,18 @@ contract Emitter {
         else if (which == WhichEvent.LogQuadrupleWithIndex) LogQuadrupleWithIndex(arg0, arg1, arg2, arg3);
         else throw;
     }
+
+    function logDynamicArgs(string arg0, string arg1) public {
+        LogDynamicArgs(arg0, arg1);
+    }
 }
 """))
 
-CONTRACT_EMITTER_CODE = "0x60606040526104ae806100126000396000f3606060405236156100615760e060020a60003504630bb563d6811461006357806317c0c1801461013657806320f0256e1461017057806390b41d8b146101ca5780639c37705314610215578063aa6fd82214610267578063e17bf956146102a9575b005b60206004803580820135601f810184900490930260809081016040526060848152610061946024939192918401918190838280828437509496505050505050507fa95e6e2a182411e7a6f9ed114a85c3761d87f9b8f453d842c71235aa64fff99f8160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156101255780820380516001836020036101000a031916815260200191505b509250505060405180910390a15b50565b610061600435600181141561037a577f1e86022f78f8d04f8e3dfd13a2bdb280403e6632877c0dbee5e4eeb259908a5c60006060a1610133565b6100616004356024356044356064356084356005851415610392576060848152608084815260a084905260c08390527ff039d147f23fe975a4254bdf6b1502b8c79132ae1833986b7ccef2638e73fdf991a15b5050505050565b61006160043560243560443560038314156103d457606082815260808290527fdf0cb1dea99afceb3ea698d62e705b736f1345a7eee9eb07e63d1f8f556c1bc590604090a15b505050565b6100616004356024356044356064356004841415610428576060838152608083905260a08290527f4a25b279c7c585f25eda9788ac9420ebadae78ca6b206a0e6ab488fd81f550629080a15b50505050565b61006160043560243560028214156104655760608181527f56d2ef3c5228bf5d88573621e325a4672ab50e033749a601e4f4a5e1dce905d490602090a15b5050565b60206004803580820135601f810184900490930260809081016040526060848152610061946024939192918401918190838280828437509496505050505050507f532fd6ea96cfb78bb46e09279a26828b8b493de1a2b8b1ee1face527978a15a58160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156101255780820380516001836020036101000a03191681526020019150509250505060405180910390a150565b600081141561038d5760006060a0610133565b610002565b600b85141561038d5760608481526080849052819083907fa30ece802b64cd2b7e57dabf4010aabf5df26d1556977affb07b98a77ad955b590604090a36101c3565b600983141561040f57606082815281907f057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca90602090a2610210565b600883141561038d5760608281528190602090a1610210565b600a84141561038d576060838152819083907ff16c999b533366ca5138d78e85da51611089cd05749f098d6c225d4cd42ee6ec90602090a3610261565b600782141561049a57807ff70fe689e290d8ce2b2a388ac28db36fbb0e16a6d89c6804c461f65a1b40bb1560006060a26102a5565b600682141561038d578060006060a16102a556"
+CONTRACT_EMITTER_CODE = "0x606060405234610000575b610772806100186000396000f36060604052361561006c5760e060020a60003504630bb563d6811461007157806317c0c180146100c657806320f0256e146100d857806390b41d8b146100f65780639c3770531461010e578063aa6fd82214610129578063acabb9ed1461013e578063e17bf956146101d0575b610000565b34610000576100c4600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965061022595505050505050565b005b34610000576100c46004356102b8565b005b34610000576100c460043560243560443560643560843561031e565b005b34610000576100c46004356024356044356103e0565b005b34610000576100c46004356024356044356064356104b3565b005b34610000576100c4600435602435610563565b005b34610000576100c4600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284375050604080516020601f89358b0180359182018390048302840183019094528083529799988101979196509182019450925082915084018382808284375094965061061895505050505050565b005b34610000576100c4600480803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496506106df95505050505050565b005b7fa95e6e2a182411e7a6f9ed114a85c3761d87f9b8f453d842c71235aa64fff99f8160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156102a75780820380516001836020036101000a031916815260200191505b509250505060405180910390a15b50565b600181600b81116100005714156102f7576040517f1e86022f78f8d04f8e3dfd13a2bdb280403e6632877c0dbee5e4eeb259908a5c90600090a16102b5565b600081600b811161000057141561006c57604051600090a06102b5565b610000565b5b5b50565b600585600b811161000057141561037b5760408051858152602081018590528082018490526060810183905290517ff039d147f23fe975a4254bdf6b1502b8c79132ae1833986b7ccef2638e73fdf99181900360800190a16103d7565b600b85600b811161000057141561006c5780827fa30ece802b64cd2b7e57dabf4010aabf5df26d1556977affb07b98a77ad955b58686604051808381526020018281526020019250505060405180910390a36103d7565b610000565b5b5b5050505050565b600383600b811161000057141561043157604080518381526020810183905281517fdf0cb1dea99afceb3ea698d62e705b736f1345a7eee9eb07e63d1f8f556c1bc5929181900390910190a16104ab565b600983600b811161000057141561047d5760408051838152905182917f057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca919081900360200190a26104ab565b600883600b811161000057141561006c57604080518381529051829181900360200190a16104ab565b610000565b5b5b5b505050565b600484600b811161000057141561050957604080518481526020810184905280820183905290517f4a25b279c7c585f25eda9788ac9420ebadae78ca6b206a0e6ab488fd81f550629181900360600190a161055b565b600a84600b811161000057141561006c57604080518481529051829184917ff16c999b533366ca5138d78e85da51611089cd05749f098d6c225d4cd42ee6ec9181900360200190a361055b565b610000565b5b5b50505050565b600282600b81116100005714156105ac576040805182815290517f56d2ef3c5228bf5d88573621e325a4672ab50e033749a601e4f4a5e1dce905d49181900360200190a1610611565b600782600b81116100005714156105ed5760405181907ff70fe689e290d8ce2b2a388ac28db36fbb0e16a6d89c6804c461f65a1b40bb1590600090a2610611565b600682600b811161000057141561006c576040518190600090a1610611565b610000565b5b5b5b5050565b81604051808280519060200190808383829060006004602084601f0104600302600f01f15090500191505060405180910390207fe77cf33df73da7bc2e253a2dae617e6f15e4e337eaa462a108903af4643d1b758260405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156106cd5780820380516001836020036101000a031916815260200191505b509250505060405180910390a25b5050565b7f532fd6ea96cfb78bb46e09279a26828b8b493de1a2b8b1ee1face527978a15a58160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156102a75780820380516001836020036101000a031916815260200191505b509250505060405180910390a15b5056"
 
-CONTRACT_EMITTER_RUNTIME = "0x606060405236156100615760e060020a60003504630bb563d6811461006357806317c0c1801461013657806320f0256e1461017057806390b41d8b146101ca5780639c37705314610215578063aa6fd82214610267578063e17bf956146102a9575b005b60206004803580820135601f810184900490930260809081016040526060848152610061946024939192918401918190838280828437509496505050505050507fa95e6e2a182411e7a6f9ed114a85c3761d87f9b8f453d842c71235aa64fff99f8160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156101255780820380516001836020036101000a031916815260200191505b509250505060405180910390a15b50565b610061600435600181141561037a577f1e86022f78f8d04f8e3dfd13a2bdb280403e6632877c0dbee5e4eeb259908a5c60006060a1610133565b6100616004356024356044356064356084356005851415610392576060848152608084815260a084905260c08390527ff039d147f23fe975a4254bdf6b1502b8c79132ae1833986b7ccef2638e73fdf991a15b5050505050565b61006160043560243560443560038314156103d457606082815260808290527fdf0cb1dea99afceb3ea698d62e705b736f1345a7eee9eb07e63d1f8f556c1bc590604090a15b505050565b6100616004356024356044356064356004841415610428576060838152608083905260a08290527f4a25b279c7c585f25eda9788ac9420ebadae78ca6b206a0e6ab488fd81f550629080a15b50505050565b61006160043560243560028214156104655760608181527f56d2ef3c5228bf5d88573621e325a4672ab50e033749a601e4f4a5e1dce905d490602090a15b5050565b60206004803580820135601f810184900490930260809081016040526060848152610061946024939192918401918190838280828437509496505050505050507f532fd6ea96cfb78bb46e09279a26828b8b493de1a2b8b1ee1face527978a15a58160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156101255780820380516001836020036101000a03191681526020019150509250505060405180910390a150565b600081141561038d5760006060a0610133565b610002565b600b85141561038d5760608481526080849052819083907fa30ece802b64cd2b7e57dabf4010aabf5df26d1556977affb07b98a77ad955b590604090a36101c3565b600983141561040f57606082815281907f057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca90602090a2610210565b600883141561038d5760608281528190602090a1610210565b600a84141561038d576060838152819083907ff16c999b533366ca5138d78e85da51611089cd05749f098d6c225d4cd42ee6ec90602090a3610261565b600782141561049a57807ff70fe689e290d8ce2b2a388ac28db36fbb0e16a6d89c6804c461f65a1b40bb1560006060a26102a5565b600682141561038d578060006060a16102a556"
+CONTRACT_EMITTER_RUNTIME = "0x6060604052361561006c5760e060020a60003504630bb563d6811461007157806317c0c180146100c657806320f0256e146100d857806390b41d8b146100f65780639c3770531461010e578063aa6fd82214610129578063acabb9ed1461013e578063e17bf956146101d0575b610000565b34610000576100c4600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965061022595505050505050565b005b34610000576100c46004356102b8565b005b34610000576100c460043560243560443560643560843561031e565b005b34610000576100c46004356024356044356103e0565b005b34610000576100c46004356024356044356064356104b3565b005b34610000576100c4600435602435610563565b005b34610000576100c4600480803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284375050604080516020601f89358b0180359182018390048302840183019094528083529799988101979196509182019450925082915084018382808284375094965061061895505050505050565b005b34610000576100c4600480803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496506106df95505050505050565b005b7fa95e6e2a182411e7a6f9ed114a85c3761d87f9b8f453d842c71235aa64fff99f8160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156102a75780820380516001836020036101000a031916815260200191505b509250505060405180910390a15b50565b600181600b81116100005714156102f7576040517f1e86022f78f8d04f8e3dfd13a2bdb280403e6632877c0dbee5e4eeb259908a5c90600090a16102b5565b600081600b811161000057141561006c57604051600090a06102b5565b610000565b5b5b50565b600585600b811161000057141561037b5760408051858152602081018590528082018490526060810183905290517ff039d147f23fe975a4254bdf6b1502b8c79132ae1833986b7ccef2638e73fdf99181900360800190a16103d7565b600b85600b811161000057141561006c5780827fa30ece802b64cd2b7e57dabf4010aabf5df26d1556977affb07b98a77ad955b58686604051808381526020018281526020019250505060405180910390a36103d7565b610000565b5b5b5050505050565b600383600b811161000057141561043157604080518381526020810183905281517fdf0cb1dea99afceb3ea698d62e705b736f1345a7eee9eb07e63d1f8f556c1bc5929181900390910190a16104ab565b600983600b811161000057141561047d5760408051838152905182917f057bc32826fbe161da1c110afcdcae7c109a8b69149f727fc37a603c60ef94ca919081900360200190a26104ab565b600883600b811161000057141561006c57604080518381529051829181900360200190a16104ab565b610000565b5b5b5b505050565b600484600b811161000057141561050957604080518481526020810184905280820183905290517f4a25b279c7c585f25eda9788ac9420ebadae78ca6b206a0e6ab488fd81f550629181900360600190a161055b565b600a84600b811161000057141561006c57604080518481529051829184917ff16c999b533366ca5138d78e85da51611089cd05749f098d6c225d4cd42ee6ec9181900360200190a361055b565b610000565b5b5b50505050565b600282600b81116100005714156105ac576040805182815290517f56d2ef3c5228bf5d88573621e325a4672ab50e033749a601e4f4a5e1dce905d49181900360200190a1610611565b600782600b81116100005714156105ed5760405181907ff70fe689e290d8ce2b2a388ac28db36fbb0e16a6d89c6804c461f65a1b40bb1590600090a2610611565b600682600b811161000057141561006c576040518190600090a1610611565b610000565b5b5b5b5050565b81604051808280519060200190808383829060006004602084601f0104600302600f01f15090500191505060405180910390207fe77cf33df73da7bc2e253a2dae617e6f15e4e337eaa462a108903af4643d1b758260405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156106cd5780820380516001836020036101000a031916815260200191505b509250505060405180910390a25b5050565b7f532fd6ea96cfb78bb46e09279a26828b8b493de1a2b8b1ee1face527978a15a58160405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156102a75780820380516001836020036101000a031916815260200191505b509250505060405180910390a15b5056"
 
-CONTRACT_EMITTER_ABI = json.loads('[{"constant":false,"inputs":[{"name":"v","type":"string"}],"name":"logString","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"which","type":"uint8"}],"name":"logNoArgs","outputs":[],"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":"logQuadruple","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"which","type":"uint8"},{"name":"arg0","type":"uint256"},{"name":"arg1","type":"uint256"}],"name":"logDouble","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"which","type":"uint8"},{"name":"arg0","type":"uint256"},{"name":"arg1","type":"uint256"},{"name":"arg2","type":"uint256"}],"name":"logTriple","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"which","type":"uint8"},{"name":"arg0","type":"uint256"}],"name":"logSingle","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"v","type":"bytes"}],"name":"logBytes","outputs":[],"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"}],"name":"LogSingleArg","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":false,"name":"arg1","type":"uint256"}],"name":"LogDoubleArg","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":false,"name":"arg1","type":"uint256"},{"indexed":false,"name":"arg2","type":"uint256"}],"name":"LogTripleArg","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"}],"name":"LogQuadrupleArg","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"arg0","type":"uint256"}],"name":"LogSingleAnonymous","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"arg0","type":"uint256"}],"name":"LogSingleWithIndex","type":"event"},{"anonymous":true,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":true,"name":"arg1","type":"uint256"}],"name":"LogDoubleAnonymous","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":true,"name":"arg1","type":"uint256"}],"name":"LogDoubleWithIndex","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":true,"name":"arg1","type":"uint256"},{"indexed":true,"name":"arg2","type":"uint256"}],"name":"LogTripleWithIndex","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"}],"name":"LogQuadrupleWithIndex","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"v","type":"bytes"}],"name":"LogBytes","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"v","type":"string"}],"name":"LogString","type":"event"}]')
+CONTRACT_EMITTER_ABI = json.loads('[{"constant":false,"inputs":[{"name":"v","type":"string"}],"name":"logString","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"which","type":"uint8"}],"name":"logNoArgs","outputs":[],"payable":false,"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":"logQuadruple","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"which","type":"uint8"},{"name":"arg0","type":"uint256"},{"name":"arg1","type":"uint256"}],"name":"logDouble","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"which","type":"uint8"},{"name":"arg0","type":"uint256"},{"name":"arg1","type":"uint256"},{"name":"arg2","type":"uint256"}],"name":"logTriple","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"which","type":"uint8"},{"name":"arg0","type":"uint256"}],"name":"logSingle","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"arg0","type":"string"},{"name":"arg1","type":"string"}],"name":"logDynamicArgs","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"v","type":"bytes"}],"name":"logBytes","outputs":[],"payable":false,"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"}],"name":"LogSingleArg","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":false,"name":"arg1","type":"uint256"}],"name":"LogDoubleArg","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":false,"name":"arg1","type":"uint256"},{"indexed":false,"name":"arg2","type":"uint256"}],"name":"LogTripleArg","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"}],"name":"LogQuadrupleArg","type":"event"},{"anonymous":true,"inputs":[{"indexed":true,"name":"arg0","type":"uint256"}],"name":"LogSingleAnonymous","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"arg0","type":"uint256"}],"name":"LogSingleWithIndex","type":"event"},{"anonymous":true,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":true,"name":"arg1","type":"uint256"}],"name":"LogDoubleAnonymous","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":true,"name":"arg1","type":"uint256"}],"name":"LogDoubleWithIndex","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"arg0","type":"uint256"},{"indexed":true,"name":"arg1","type":"uint256"},{"indexed":true,"name":"arg2","type":"uint256"}],"name":"LogTripleWithIndex","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"}],"name":"LogQuadrupleWithIndex","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"arg0","type":"string"},{"indexed":false,"name":"arg1","type":"string"}],"name":"LogDynamicArgs","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"v","type":"bytes"}],"name":"LogBytes","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"v","type":"string"}],"name":"LogString","type":"event"}]')
 
 
 @pytest.fixture()
@@ -439,6 +444,7 @@ class LogTopics(object):
     LogQuadrupleWithIndex = event_signature_to_log_topic("LogQuadrupleWithIndex(uint256,uint256,uint256,uint256)")
     LogBytes = event_signature_to_log_topic("LogBytes(bytes)")
     LogString = event_signature_to_log_topic("LogString(string)")
+    LogDynamicArgs = event_signature_to_log_topic("LogDynamicArgs(string,string)")
 
 
 @pytest.fixture()
diff --git a/tests/contracts/test_extracting_event_data.py b/tests/contracts/test_extracting_event_data.py
index 227f56ad..e27b34df 100644
--- a/tests/contracts/test_extracting_event_data.py
+++ b/tests/contracts/test_extracting_event_data.py
@@ -3,6 +3,12 @@ import pytest
 from web3.utils.events import (
     get_event_data,
 )
+from web3.utils.string import (
+    force_text,
+)
+from web3.utils.encoding import (
+    decode_hex,
+)
 
 
 @pytest.fixture()
@@ -74,3 +80,39 @@ def test_event_data_extraction(web3,
     assert event_data['transactionIndex'] == txn_receipt['transactionIndex']
     assert event_data['address'] == emitter.address
     assert event_data['event'] == event_name
+
+
+def test_dynamic_length_argument_extraction(web3,
+                                            emitter,
+                                            wait_for_transaction,
+                                            emitter_log_topics,
+                                            emitter_event_ids):
+    string_0 = "this-is-the-first-string-which-exceeds-32-bytes-in-length"
+    string_1 = "this-is-the-second-string-which-exceeds-32-bytes-in-length"
+    txn_hash = emitter.transact().logDynamicArgs(string_0, string_1)
+    txn_receipt = wait_for_transaction(web3, txn_hash)
+
+    assert len(txn_receipt['logs']) == 1
+    log_entry = txn_receipt['logs'][0]
+
+    event_abi = emitter._find_matching_event_abi('LogDynamicArgs')
+
+    event_topic = emitter_log_topics.LogDynamicArgs
+    assert event_topic in log_entry['topics']
+
+    string_0_topic = web3.sha3(string_0, encoding='utf8')
+    assert string_0_topic in log_entry['topics']
+
+    event_data = get_event_data(event_abi, log_entry)
+
+    expected_args = {
+        "arg0": force_text(decode_hex(string_0_topic)),
+        "arg1": string_1,
+    }
+
+    assert event_data['args'] == expected_args
+    assert event_data['blockHash'] == txn_receipt['blockHash']
+    assert event_data['blockNumber'] == txn_receipt['blockNumber']
+    assert event_data['transactionIndex'] == txn_receipt['transactionIndex']
+    assert event_data['address'] == emitter.address
+    assert event_data['event'] == 'LogDynamicArgs'
diff --git a/web3/utils/abi.py b/web3/utils/abi.py
index 9637112b..9b7f962d 100644
--- a/web3/utils/abi.py
+++ b/web3/utils/abi.py
@@ -11,6 +11,9 @@ from .string import (
     coerce_args_to_text,
     coerce_return_to_text,
 )
+from .functional import (
+    cast_return_to_tuple,
+)
 from .formatting import (
     add_0x_prefix,
 )
@@ -265,6 +268,7 @@ def is_probably_enum(abi_type):
     return bool(re.match(ENUM_REGEX, abi_type))
 
 
+@cast_return_to_tuple
 def normalize_event_input_types(abi_args):
     for arg in abi_args:
         if is_recognized_type(arg['type']):
diff --git a/web3/utils/events.py b/web3/utils/events.py
index 616e82ba..72d6b709 100644
--- a/web3/utils/events.py
+++ b/web3/utils/events.py
@@ -5,8 +5,14 @@ from eth_abi import (
     decode_single,
     encode_single,
 )
+from eth_abi.abi import (
+    process_type,
+)
 
 from .encoding import encode_hex
+from .functional import (
+    cast_return_to_tuple,
+)
 from .types import (
     is_array,
 )
@@ -14,7 +20,6 @@ from .string import (
     coerce_return_to_text,
 )
 from .abi import (
-    get_abi_input_types,
     get_abi_input_names,
     get_indexed_event_inputs,
     exclude_indexed_event_inputs,
@@ -109,16 +114,29 @@ def construct_event_data_set(event_abi, arguments=None):
     return topics
 
 
-def coerce_event_abi_types_for_decoding(input_types):
+def is_dynamic_sized_type(_type):
+    base_type, type_size, arrlist = process_type(_type)
+    if arrlist:
+        return True
+    elif base_type == 'string':
+        return True
+    elif base_type == 'bytes' and type_size == '':
+        return True
+    return False
+
+
+@cast_return_to_tuple
+def get_event_abi_types_for_decoding(event_inputs):
     """
-    Event logs use the `sha3(value)` for inputs of type `bytes` or `string`.
-    Because of this we need to modify the types so that we can decode the log
-    entries using the correct types.
+    Event logs use the `sha3(value)` for indexed inputs of type `bytes` or
+    `string`.  Because of this we need to modify the types so that we can
+    decode the log entries using the correct types.
     """
-    return [
-        'bytes32' if arg_type in {'bytes', 'string'} else arg_type
-        for arg_type in input_types
-    ]
+    for input_abi in event_inputs:
+        if input_abi['indexed'] and is_dynamic_sized_type(input_abi['type']):
+            yield 'bytes32'
+        else:
+            yield input_abi['type']
 
 
 @coerce_return_to_text
@@ -132,10 +150,8 @@ def get_event_data(event_abi, log_entry):
         log_topics = log_entry['topics'][1:]
 
     log_topics_abi = get_indexed_event_inputs(event_abi)
-    log_topic_raw_types = get_abi_input_types({
-        'inputs': normalize_event_input_types(log_topics_abi),
-    })
-    log_topic_types = coerce_event_abi_types_for_decoding(log_topic_raw_types)
+    log_topic_normalized_inputs = normalize_event_input_types(log_topics_abi)
+    log_topic_types = get_event_abi_types_for_decoding(log_topic_normalized_inputs)
     log_topic_names = get_abi_input_names({'inputs': log_topics_abi})
 
     if len(log_topics) != len(log_topic_types):
@@ -146,10 +162,8 @@ def get_event_data(event_abi, log_entry):
 
     log_data = log_entry['data']
     log_data_abi = exclude_indexed_event_inputs(event_abi)
-    log_data_raw_types = get_abi_input_types({
-        'inputs': normalize_event_input_types(log_data_abi),
-    })
-    log_data_types = coerce_event_abi_types_for_decoding(log_data_raw_types)
+    log_data_normalized_inputs = normalize_event_input_types(log_data_abi)
+    log_data_types = get_event_abi_types_for_decoding(log_data_normalized_inputs)
     log_data_names = get_abi_input_names({'inputs': log_data_abi})
 
     # sanity check that there are not name intersections between the topic
diff --git a/web3/utils/functional.py b/web3/utils/functional.py
index 372734ea..6601573d 100644
--- a/web3/utils/functional.py
+++ b/web3/utils/functional.py
@@ -23,3 +23,16 @@ def apply_formatters_to_return(*formatters):
             return formatter(value)
         return inner
     return outer
+
+
+def cast_return(_type):
+    def outer(fn):
+        @functools.wraps(fn)
+        def inner(*args, **kwargs):
+            return _type(fn(*args, **kwargs))
+
+        return inner
+    return outer
+
+
+cast_return_to_tuple = cast_return(tuple)