def test_from_string_wrong_length(self): with self.assertRaises(ValueError) as ctx: UInt160.from_string("1122") self.assertEqual("Invalid UInt160 Format: 4 chars != 40 chars", str(ctx.exception)) with self.assertRaises(ValueError) as ctx: UInt256.from_string("1122") self.assertEqual("Invalid UInt256 Format: 4 chars != 64 chars", str(ctx.exception))
def test_new_watch_only_account(self): from neo3.core.types import UInt160 for testcase in account_list: account = Account.watch_only( UInt160.from_string(testcase['script_hash'])) self.assertEqual(testcase['address'], account.address) self.assertIsNone(account.encrypted_key) self.assertEqual(testcase['script_hash'], str(account.script_hash)) self.assertIsNone(account.public_key)
def test_from_string_various(self): uint160 = UInt160.from_string("11" * 20) expected_data_uint160 = bytearray([0x11] * 20) self.assertEqual(expected_data_uint160, uint160.to_array()) uint256 = UInt256.from_string("11" * 32) expected_data_uint256 = bytearray([0x11] * 32) self.assertEqual(expected_data_uint256, uint256.to_array()) uint160_from_bytes = UInt160.deserialize_from_bytes( expected_data_uint160) self.assertEqual(expected_data_uint160, uint160_from_bytes.to_array()) uint256_from_bytes = UInt256.deserialize_from_bytes( expected_data_uint256) self.assertEqual(expected_data_uint256, uint256_from_bytes.to_array()) # test deserialize with too much data data_uint160 = bytearray(21 * [0x11]) uint160_from_bytes = UInt160.deserialize_from_bytes(data_uint160) self.assertEqual(data_uint160[:20], uint160_from_bytes.to_array()) data_uint256 = bytearray(33 * [0x11]) uint256_from_bytes = UInt256.deserialize_from_bytes(data_uint256) self.assertEqual(expected_data_uint256[:32], uint256_from_bytes.to_array()) # test deserialize with too little data data_uint160 = bytearray(19 * [0x11]) data_uint256 = bytearray(31 * [0x11]) with self.assertRaises(ValueError) as ctx: UInt160.deserialize_from_bytes(data_uint160) self.assertEqual( "Insufficient data 19 bytes is less than the required 20", str(ctx.exception)) with self.assertRaises(ValueError) as ctx: UInt256.deserialize_from_bytes(data_uint256) self.assertEqual( "Insufficient data 31 bytes is less than the required 32", str(ctx.exception))
[contract_owner_hash]) print('invoke method balanceOf my NEO:', end=' ') engine.print_results() engine.invoke_method_of_arbitrary_contract(gas.hash, 'balanceOf', [contract_owner_hash]) print('invoke method balanceOf my GAS:', end=' ') engine.print_results() engine.invoke_method_with_print( "deposit", params=[ contract_owner_hash, neo.hash, gas.hash, _30_days_later_ending_milisecond, mint_ratio, 1 ], signers=[ Signer(UInt160.from_string(contract_owner_hash), WitnessScope.GLOBAL) ]) engine.invoke_method_with_print( "deposit", params=[ contract_owner_hash, neo.hash, gas.hash, _30_days_later_ending_milisecond, mint_ratio, 100 ], signers=[ Signer(UInt160.from_string(contract_owner_hash), WitnessScope.GLOBAL) ]) engine.invoke_method_of_arbitrary_contract(neo.hash, 'balanceOf', [contract_owner_hash]) print('invoke method balanceOf my NEO:', end=' ') engine.print_results() engine.get_rToken_balance(rcToken_address, contract_owner_hash)