github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/integration/sawtooth_integration/tests/test_intkey_cli.py (about) 1 # Copyright 2017 Intel Corporation 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # ------------------------------------------------------------------------------ 15 16 import unittest 17 import logging 18 import subprocess 19 import shlex 20 21 import cbor 22 23 from sawtooth_integration.tests.integration_tools import wait_for_rest_apis 24 from sawtooth_integration.tests.integration_tools import RestClient 25 26 27 LOGGER = logging.getLogger(__name__) 28 29 30 URL = 'http://rest-api:8008' 31 WAIT = 300 32 33 34 class IntkeyClient(RestClient): 35 def __init__(self, url): 36 super().__init__( 37 url=url, 38 namespace='1cf126') 39 40 def get_keys(self): 41 return { 42 key: value 43 for entry in self.get_data() 44 for key, value in cbor.loads(entry).items() 45 } 46 47 48 class TestInkeyCli(unittest.TestCase): 49 @classmethod 50 def setUpClass(cls): 51 wait_for_rest_apis([URL]) 52 53 cls.client = IntkeyClient(url=URL) 54 55 def test_intkey_cli(self): 56 _send_command('sawtooth keygen') 57 58 commands = ( 59 'set cat 5', # cat = 5 60 'inc cat 3', # cat = 8 61 'inc not-set 6', # invalid 62 'set dog 8', # dog = 8 63 'dec cat 4', # cat = 4 64 'dec dog 10', # invalid (can't go below 0) 65 'inc dog 100000000000', # invalid (can't go above 2**32) 66 'inc dog 3', # dog = 11 67 ) 68 69 for command in commands: 70 _send_command( 71 'intkey {} --url {} --wait {}'.format( 72 command, URL, WAIT)) 73 74 display = ( 75 'show cat', 76 'show dog', 77 'show not-set', 78 'list' 79 ) 80 81 for command in display: 82 _send_command( 83 'intkey {} --url {}'.format( 84 command, URL)) 85 86 self.assertEqual( 87 self.client.get_keys(), 88 { 89 'cat': 4, 90 'dog': 11 91 }) 92 93 94 def _send_command(command): 95 return subprocess.run( 96 shlex.split( 97 command))