def test_handler(): app = ExampleApp() p = ProtocolHandler(app) # Echo req = Request(echo=RequestEcho(message='hello')) raw = p.process('echo', req) resp = __deserialze(raw) assert resp.echo.message == 'hello' # Flush req = Request(flush=RequestFlush()) raw = p.process('flush', req) resp = __deserialze(raw) assert isinstance(resp.flush, ResponseFlush) # Info req = Request(info=RequestInfo(version='16')) raw = p.process('info', req) resp = __deserialze(raw) assert resp.info.version == '16' assert resp.info.data == 'hello' assert resp.info.last_block_height == 0 assert resp.info.last_block_app_hash == b'0x12' # init_chain val_a = ValidatorUpdate(power=10, pub_key=PubKey(type='amino_encoded', data=b'a_pub_key')) val_b = ValidatorUpdate(power=10, pub_key=PubKey(type='amino_encoded', data=b'b_pub_key')) v = [val_a, val_b] req = Request(init_chain=RequestInitChain(validators=v)) raw = p.process('init_chain', req) resp = __deserialze(raw) assert isinstance(resp.init_chain, ResponseInitChain) # check_tx req = Request(check_tx=RequestCheckTx(tx=b'helloworld')) raw = p.process('check_tx', req) resp = __deserialze(raw) assert resp.check_tx.code == CodeTypeOk assert resp.check_tx.data == b'helloworld' assert resp.check_tx.log == 'bueno' # deliver_tx req = Request(deliver_tx=RequestDeliverTx(tx=b'helloworld')) raw = p.process('deliver_tx', req) resp = __deserialze(raw) assert resp.deliver_tx.code == CodeTypeOk assert resp.deliver_tx.data == b'helloworld' assert resp.deliver_tx.log == 'bueno' # query req = Request(query=RequestQuery(path='/dave', data=b'0x12')) raw = p.process('query', req) resp = __deserialze(raw) assert resp.query.code == CodeTypeOk assert resp.query.value == b'0x12' # begin_block req = Request(begin_block=RequestBeginBlock(hash=b'0x12')) raw = p.process('begin_block', req) resp = __deserialze(raw) assert isinstance(resp.begin_block, ResponseBeginBlock) # end_block req = Request(end_block=RequestEndBlock(height=10)) raw = p.process('end_block', req) resp = __deserialze(raw) assert resp.end_block.validator_updates assert len(resp.end_block.validator_updates) == 2 assert resp.end_block.validator_updates[0].pub_key.data == b'a_pub_key' assert resp.end_block.validator_updates[1].pub_key.data == b'b_pub_key' # Commit req = Request(commit=RequestCommit()) raw = p.process('commit', req) resp = __deserialze(raw) assert resp.commit.data == b'0x1234' # No match raw = p.process('whatever', None) resp = __deserialze(raw) assert resp.exception.error == "ABCI request not found" # set_option req = Request(set_option=RequestSetOption(key='name', value='dave')) raw = p.process('set_option', req) resp = __deserialze(raw) assert resp.set_option.code == CodeTypeOk assert resp.set_option.log == 'name=dave'
def generate_init_chain_request(chain_id, vals=None): vals = vals if vals is not None else [generate_validator()] return RequestInitChain(validators=vals, chain_id=chain_id)