Skip to content

Commit

Permalink
update UT & fix bug (#394)
Browse files Browse the repository at this point in the history
* update UT

* update UT

* update UT

* update README

* update UT & fix bug
  • Loading branch information
NashMiao authored Nov 4, 2019
1 parent 773561c commit fd68576
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ontology/contract/wasm/params_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def write_var_uint(self, value: int):
raise SDKException(ErrorCode.other_error('invalid data'))
elif value < 0xFD:
self.write_bytes(value.to_bytes(length=1, byteorder='little', signed=False))
elif value < 0xFFFF:
elif value <= 0xFFFF:
self.write_bytes(b'\xFD')
self.write_bytes(value.to_bytes(length=2, byteorder='little', signed=False))
elif value < 0xFFFFFFFF:
elif value <= 0xFFFFFFFF:
self.write_bytes(b'\xFE')
self.write_bytes(value.to_bytes(length=4, byteorder='little', signed=False))
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

setup(
name='ontology-python-sdk',
version='2.1.0.RC2',
version='2.1.0.RC3',
description='Comprehensive Python library for the Ontology BlockChain.',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
54 changes: 43 additions & 11 deletions tests/test_wasm_params_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,22 @@ def test_push_int(self):
self.assertRaises(SDKException, self.builder.push_int, WASM_INT128_MIN - 1)

def test_push_address(self):
b58_address_list = ['AS3SCXw8GKTEeXpdwVw7EcC4rqSebFYpfb', 'AJkkLbouowk6teTaxz1F2DYKfJh24PVk3r',
'Ad4pjz2bqep4RhQrUAzMuZJkBC3qJ1tZuT', 'AK98G45DhmPXg4TFPG1KjftvkEaHbU8SHM']
wasm_address_list = ['70a2ababdae0a9d1f9fc7296df3c6d343b772cf7', '20b1dc499cdf56ba70a574a1e17ac986d1f06ec2',
'e98f4998d837fcdd44a50561f7f32140c7c6c260', '24ed4f965d3a5a76f5d0e87633c0b76941fc8827']
b58_address_list = [
'AS7MjVEicEsJ4zjEfm2LoKoYoFsmapD7rT',
'AFmseVrdL9f9oyCzZefL9tG6UbviEH9ugK',
'AS3SCXw8GKTEeXpdwVw7EcC4rqSebFYpfb',
'AJkkLbouowk6teTaxz1F2DYKfJh24PVk3r',
'Ad4pjz2bqep4RhQrUAzMuZJkBC3qJ1tZuT',
'AK98G45DhmPXg4TFPG1KjftvkEaHbU8SHM'
]
wasm_address_list = [
'71609b2c2f7b9447b089ad1da31586f42ca9eb10',
'0000000000000000000000000000000000000007',
'70a2ababdae0a9d1f9fc7296df3c6d343b772cf7',
'20b1dc499cdf56ba70a574a1e17ac986d1f06ec2',
'e98f4998d837fcdd44a50561f7f32140c7c6c260',
'24ed4f965d3a5a76f5d0e87633c0b76941fc8827'
]
for index, b58_address in enumerate(b58_address_list):
self.builder.push_address(Address.b58decode(b58_address))
self.assertEqual(wasm_address_list[index], self.builder.to_bytes().hex())
Expand Down Expand Up @@ -89,16 +101,36 @@ def test_push_list(self):
self.builder.push_list(py_list)
self.assertEqual(wasm_list, self.builder.to_bytes().hex())

def test_read_var_int(self):
wasm_hex_uint = ['00', '01', 'fdfe00', 'fe00000100', 'fe01000100',
'feffffffff', 'ff0000000001000000', 'ffffffffffffffff0f', 'ffffffffffffffffff',
'ffffffffffffffffffff', 'ffffffffffffffffffffffff']
int_data = [0, 1, 254, 65536, 65537,
4294967295, 4294967296, 1152921504606846975, 18446744073709551615,
18446744073709551615, 18446744073709551615]
def test_read_var_uint(self):
wasm_hex_uint = [
'00',
'01',
'fdfe00',
'fe00000100',
'fe01000100',
'feffffffff',
'ff0000000001000000',
'ffffffffffffffff0f',
'ffffffffffffffffff',
]
int_data = [
0,
1,
254,
65536,
65537,
4294967295,
4294967296,
1152921504606846975,
18446744073709551615
]
for index, hex_uint in enumerate(wasm_hex_uint):
self.builder.write_var_uint(int_data[index])
self.assertEqual(wasm_hex_uint[index], self.builder.to_bytes().hex())
self.builder.clear_up()
self.builder.set_buffer(hex_uint)
self.assertEqual(int_data[index], self.builder.read_var_uint())
self.builder.clear_up()

def test_pop_str_struct(self):
hex_wasm_str = '01606438646337313735616137333633323165343639643539623663303661396531666462356432373735633' \
Expand Down
2 changes: 2 additions & 0 deletions tests/test_wasm_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_invoke_add_transaction(self):
func.set_params_value(-2, 3)
tx = sdk.wasm_vm.make_invoke_transaction(self.basic_test_case_contract_address, func, acct3.get_address(),
self.gas_price, self.gas_limit)
print(tx.payload.hex())
tx.sign_transaction(acct3)
result = sdk.rpc.send_raw_transaction_pre_exec(tx).get('Result', '')
self.assertEqual('01000000000000000000000000000000', result)
Expand All @@ -98,6 +99,7 @@ def test_invoke_add_transaction(self):
'000000000000000000000000002000000000000000000000000000000'
self.assertEqual(target_payload, tx.payload.hex())
tx.sign_transaction(acct3)
print(tx.serialize().hex())
result = sdk.rpc.send_raw_transaction_pre_exec(tx).get('Result', '')
self.assertEqual('03000000000000000000000000000000', result)
self.assertEqual(3, WasmData.to_int(result))
Expand Down

0 comments on commit fd68576

Please sign in to comment.