def test_write_storage_transaction(self): func = WasmInvokeFunction('storage_write') 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))
def test_balance_of_transaction(self): func = WasmInvokeFunction('balanceOf') func.set_params_value(Address.b58decode('ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD')) tx = sdk.wasm_vm.make_invoke_transaction(self.oep4_contract_address, func, acct4.get_address(), self.gas_price, self.gas_limit) target_payload = '0faeff23255536928b308e5caa38bc2dc14f30c31e0962616c6' \ '16e63654f6646b1a18af6b7c9f8a4602f9f73eeb3030f0c29b7' self.assertEqual(target_payload, tx.payload.hex()) tx.sign_transaction(acct4) result = sdk.rpc.send_raw_transaction_pre_exec(tx) self.assertGreaterEqual(WasmData.to_int(result.get('Result')), 0)
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, acct3.get_address(), self.gas_price, self.gas_limit) target_payload = '5daf0ec53b21abfab6459c7ba7f760c376e18ebf110c73746f726167655f72656164036b6579' self.assertEqual(target_payload, tx.payload.hex()) tx.sign_transaction(acct3) result = sdk.rpc.send_raw_transaction_pre_exec(tx) self.assertTrue(isinstance(result, dict)) result = result.get('Result', '') self.assertTrue(isinstance(result, str))
def test_transfer_tx(self): amount = 100 func = WasmInvokeFunction('transfer') func.set_params_value(acct1.get_address(), Address.b58decode('AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve'), amount) tx = sdk.wasm_vm.make_invoke_transaction(self.oep4_contract_address, func, acct2.get_address(), self.gas_price, self.gas_limit) target_payload = '0faeff23255536928b308e5caa38bc2dc14f30c341087472616e7366657246b1a18af6b7c9f8a4602f9f73' \ 'eeb3030f0c29b7d2c124dd088190f709b684e0bc676d70c41b377664000000000000000000000000000000' self.assertEqual(target_payload, tx.payload.hex()) tx.sign_transaction(acct1, acct2) result = sdk.rpc.send_raw_transaction_pre_exec(tx) self.assertEqual('01', result.get('Result')) self.assertEqual(1, result.get('State')) notify_list = Event.get_event_from_event_list_by_contract_address(result.get('Notify'), self.oep4_contract_address) self.assertEqual(self.oep4_contract_address, notify_list[0].get('ContractAddress')) states = notify_list[1].get('States') self.assertEqual('transfer', WasmData.to_utf8(states[0])) self.assertEqual(acct1.get_address().b58encode(), WasmData.to_b58_address(states[1])) self.assertEqual('AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hve', WasmData.to_b58_address(states[2])) self.assertEqual(amount, WasmData.to_int(states[3]))
def test_invoke_add_transaction(self): func = WasmInvokeFunction('add') 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) target_payload = '5daf0ec53b21abfab6459c7ba7f760c376e18ebf2403616464fefffff' \ 'fffffffffffffffffffffffff03000000000000000000000000000000' self.assertEqual(target_payload, tx.payload.hex()) tx.sign_transaction(acct3) result = sdk.rpc.send_raw_transaction_pre_exec(tx).get('Result', '') self.assertEqual('01000000000000000000000000000000', result) self.assertEqual(1, WasmData.to_int(result)) func = WasmInvokeFunction('add') func.set_params_value(1, 2) 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 = '5daf0ec53b21abfab6459c7ba7f760c376e18ebf24036164640100000' \ '000000000000000000000000002000000000000000000000000000000' self.assertEqual(target_payload, tx.payload.hex()) tx.sign_transaction(acct3) result = sdk.rpc.send_raw_transaction_pre_exec(tx).get('Result', '') self.assertEqual('03000000000000000000000000000000', result) self.assertEqual(3, WasmData.to_int(result)) func.set_params_value(2 ** 127 - 1, -2 ** 127) tx = sdk.wasm_vm.make_invoke_transaction(self.basic_test_case_contract_address, func, acct2.get_address(), self.gas_price, self.gas_limit) target_payload = '5daf0ec53b21abfab6459c7ba7f760c376e18ebf2403616464fffffff' \ 'fffffffffffffffffffffff7f00000000000000000000000000000080' self.assertEqual(target_payload, tx.payload.hex()) tx.sign_transaction(acct2) result = sdk.rpc.send_raw_transaction_pre_exec(tx).get('Result') self.assertEqual('ffffffffffffffffffffffffffffffff', result) self.assertEqual(-1, WasmData.to_int(result))