Encode Ethereum RPC quantities and byte strings correctly

A serializer that adds a leading zero to every hexadecimal value can produce valid calldata and invalid block numbers in the same request.

Test zero and an odd-length value

Use three boundary cases when testing a serializer. The block number zero is a quantity. A single zero byte is data. An empty byte string has its own spelling.

quantity(0) = 0x0
data([0])   = 0x00
data([])    = 0x

For the integer fifteen, emit 0xf. To send one byte with the same numeric value, emit 0x0f. Quantities discard leading zeroes while byte strings keep two digits per byte.

Preserve the parameter type

Take the encoding rule from the method schema before serializing. A storage key supplied as a fixed-width byte string needs its padding even when its high bytes are zero. Converting every string through an integer loses that information. eips.ethereum.org EIP-1474