Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 536ff6c

Browse files
committed
Added ABI section and tester section
1 parent db17a6a commit 536ff6c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,24 @@ Creates encrypted private key storaes
163163
* `decode_keystore_json(jsondata, password)` - returns the private key from an encrypted keystore object. NOTE: if you are loading from a file, the most convenient way to do this is `import json; key = decode_keystore_json(json.load(open('filename.json')), 'password')`
164164
* `make_keystore_json(key, pw, kdf='pbkdf2', cipher='aes-128-ctr')` - creates an encrypted keystore object for the key. Keeping `kdf` and `cipher` at their default values is recommended.
165165

166+
### ethereum.abi
167+
168+
Most compilers for HLLs (solidity, serpent, viper, etc) on top of Ethereum have the option to output an ABI declaration for a program. This is a json object that looks something like this:
169+
170+
[{"name": "ecrecover(uint256,uint256,uint256,uint256)", "type": "function", "constant": false,
171+
"inputs": [{"name": "h", "type": "uint256"}, {"name": "v", "type": "uint256"}, {"name": "r", "type": "uint256"}, {"name": "s", "type": "uint256"}],
172+
"outputs": [{"name": "out", "type": "int256[]"}]},
173+
{"name": "PubkeyTripleLogEvent(uint256,uint256,uint256)", "type": "event",
174+
"inputs": [{"name": "x", "type": "uint256", "indexed": false}, {"name": "y", "type": "uint256", "indexed": false}, {"name": "z", "type": "uint256", "indexed": false}]}]
175+
176+
You can initialize an `abi.ContractTranslator` object to encode and decode data for contracts as follows:
177+
178+
true, false = True, False
179+
ct = abi.ContractTranslator(<json here>)
180+
txdata = ct.encode('function_name', [arg1, arg2, arg3])
181+
182+
You can also call `ct.decode_event([topic1, topic2...], logdata)` to decode a log.
183+
166184
### RLP encoding and decoding
167185

168186
For any transaction or block, you can simply do:
@@ -195,6 +213,29 @@ The pyethereum codebase is designed to be maximally friendly for use across many
195213
* `get_uncle_candidates(chain, state)` - called in `mk_head_candidate` to include uncles in a block
196214
* Create a chain config with the `CONSENSUS_STRATEGY` set to whatever you named your new consensus strategy
197215

216+
## Tester module
217+
218+
See https://github.com/ethereum/pyethereum/wiki/Using-pyethereum.tester
219+
220+
## Tests
221+
222+
Run `python3.6 -m pytest ethereum/tests/<filename>` for any .py file in that directory. Currently all tests are passing except for a few Metropolis-specific state tests and block tests.
223+
224+
To make your own state tests, use the tester module as follows:
225+
226+
```python
227+
from ethereum.tools import tester as t
228+
import json
229+
c = t.Chain()
230+
x = c.contract(<code>, language=<language>)
231+
pre = t.mk_state_test_prefill(c)
232+
x.foo(<args>)
233+
post = t.mk_state_test_postfill(c, pre)
234+
open('output.json', 'w').write(json.dumps(post, indent=4))
235+
```
236+
237+
To make a test filler file instead, do `post = t.mk_state_test_postfill(c, pre, True)`.
238+
198239
## Licence
199240

200241
See LICENCE

0 commit comments

Comments
 (0)