Skip to content

Commit

Permalink
update UT (#392)
Browse files Browse the repository at this point in the history
* update UT

* update UT

* update UT
  • Loading branch information
NashMiao authored Nov 4, 2019
1 parent 0f701b9 commit d2a6dcb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion tests/test_aio_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def test_get_balance(self):
@Ontology.runner
async def test_get_unbound_ong(self):
for address in self.address_list:
self.assertEqual(await sdk.aio_rpc.get_unbound_ong(address), sdk.native_vm.ong().unbound(address))
self.assertGreaterEqual(await sdk.aio_rpc.get_unbound_ong(address), 0)

@not_panic_exception
@Ontology.runner
Expand Down
2 changes: 1 addition & 1 deletion tests/test_restful.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_get_balance(self):
@not_panic_exception
def test_get_unbound_ong(self):
for address in self.address_list:
self.assertEqual(sdk.restful.get_unbound_ong(address), sdk.native_vm.ong().unbound(address))
self.assertGreaterEqual(sdk.restful.get_unbound_ong(address), 0)

@not_panic_exception
def test_get_grant_ong(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_get_balance(self):
@not_panic_exception
def test_get_unbound_ong(self):
for address in self.address_list:
self.assertEqual(sdk.rpc.get_unbound_ong(address), sdk.native_vm.ong().unbound(address))
self.assertGreaterEqual(sdk.rpc.get_unbound_ong(address), 0)

@not_panic_exception
def test_get_grant_ong(self):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_wasm_params_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,27 @@ def test_read_var_int(self):
for index, hex_uint in enumerate(wasm_hex_uint):
self.builder.set_buffer(hex_uint)
self.assertEqual(int_data[index], self.builder.read_var_uint())

def test_pop_str_struct(self):
hex_wasm_str = '01606438646337313735616137333633323165343639643539623663303661396531666462356432373735633' \
'83261396638333364333463643361343033356132303166653964633762333961653832643963356339316262' \
'663564313634366364042e6a70672032303165393337366361616131366561393832623561333165626130663' \
'36634823034383436383165383932333630646334373030363036323733626631366236613063343133393864' \
'65326532643936306633343030373936313061656538383536363736623231323233313966613037323665633' \
'16666323735396664336339313232646438333461666531376535316164666665626638326162633037656363'
target_struct = [
[
'd8dc7175aa736321e469d59b6c06a9e1fdb5d2775c82a9f833d34cd3a4035a201fe9dc7b39ae82d9c5c91bbf5d1646cd',
'.jpg',
'201e9376caaa16ea982b5a31eba0f3f4',
'0484681e892360dc4700606273bf16b6a0c41398de2e2d960f340079610aee885'
'6676b2122319fa0726ec1ff2759fd3c9122dd834afe17e51adffebf82abc07ecc'
]
]
self.builder.set_buffer(hex_wasm_str)
item_len = self.builder.read_var_uint()
for index in range(item_len):
self.assertEqual(target_struct[index][0], self.builder.pop_str())
self.assertEqual(target_struct[index][1], self.builder.pop_str())
self.assertEqual(target_struct[index][2], self.builder.pop_str())
self.assertEqual(target_struct[index][3], self.builder.pop_str())
30 changes: 8 additions & 22 deletions tests/test_wasm_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,43 +124,29 @@ def test_invoke_notify_transaction(self):
self.assertEqual(self.basic_test_case_contract_address, notify.get('ContractAddress'))
self.assertEqual('hello', notify.get('States')[0])

def read_storage_in_test_contract(self, key) -> str:
def test_read_storage(self):
func = WasmInvokeFunction('storage_read')
func.set_params_value(key)
tx = sdk.wasm_vm.make_invoke_transaction(self.basic_test_case_contract_address, func, acct2.get_address(),
func.set_params_value('key')
tx = sdk.wasm_vm.make_invoke_transaction(self.basic_test_case_contract_address, func, acct3.get_address(),
self.gas_price, self.gas_limit)
target_payload = '5daf0ec53b21abfab6459c7ba7f760c376e18ebf110c73746f726167655f72656164036b6579'
self.assertEqual(target_payload, tx.payload.hex())
tx.sign_transaction(acct2)
tx.sign_transaction(acct3)
result = sdk.rpc.send_raw_transaction_pre_exec(tx)
self.assertTrue(isinstance(result, dict))
return result.get('Result', '')
result = result.get('Result', '')
self.assertTrue(isinstance(result, str))

def test_write_read_delete_storage_transaction(self):
key = 'key'
def test_write_storage_transaction(self):
func = WasmInvokeFunction('storage_write')
func.set_params_value(key, 'value')
func.set_params_value('key', 'value')
tx = sdk.wasm_vm.make_invoke_transaction(self.basic_test_case_contract_address, func, acct1.get_address(),
self.gas_price, self.gas_limit)
target_payload = '5daf0ec53b21abfab6459c7ba7f760c376e18ebf180d73746f726167655f7772697465036b65790576616c7565'
self.assertEqual(target_payload, tx.payload.hex())
tx.sign_transaction(acct1)
tx_hash = sdk.rpc.send_raw_transaction(tx)
self.assertEqual(64, len(tx_hash))
sleep(15)
result = self.read_storage_in_test_contract(key)
self.assertEqual('0576616c7565', result)
func = WasmInvokeFunction('storage_delete')
func.set_params_value('key')
tx = sdk.wasm_vm.make_invoke_transaction(self.basic_test_case_contract_address, func, acct3.get_address(),
self.gas_price,
self.gas_limit)
tx.sign_transaction(acct3)
tx_hash = sdk.rpc.send_raw_transaction(tx)
self.assertEqual(64, len(tx_hash))
sleep(15)
result = self.read_storage_in_test_contract(key)
self.assertEqual('', result)

def test_balance_of_transaction(self):
func = WasmInvokeFunction('balanceOf')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async def test_get_block_by_hash(self):
async def test_get_unbound_ong(self):
try:
for address in self.address_list:
self.assertEqual(await sdk.websocket.get_unbound_ong(address), sdk.native_vm.ong().unbound(address))
self.assertGreaterEqual(await sdk.websocket.get_unbound_ong(address), 0)
finally:
await sdk.websocket.close_connect()

Expand Down

0 comments on commit d2a6dcb

Please sign in to comment.