示例#1
0
 def test_transfer_multi_args_0(self):
     transfer_1 = [
         acct1.get_address().to_bytes(),
         acct2.get_address().to_bytes(), 10
     ]
     transfer_2 = [
         acct2.get_address().to_bytes(),
         acct3.get_address().to_bytes(), 100
     ]
     transfer_list = [transfer_1, transfer_2]
     hex_contract_address = 'ca91a73433c016fbcbcf98051d385785a6a5d9be'
     func = InvokeFunction('transfer_multi')
     func.set_params_value(transfer_list)
     tx_hash = sdk.rpc.send_neo_vm_transaction(hex_contract_address, acct1,
                                               acct2, self.gas_price,
                                               self.gas_limit, func, False)
     self.assertEqual(64, len(tx_hash))
     time.sleep(randint(10, 15))
     event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
     states = Event.get_states_by_contract_address(event,
                                                   hex_contract_address)
     states[0] = Data.to_utf8_str(states[0])
     states[1][0][0] = Data.to_b58_address(states[1][0][0])
     self.assertEqual(acct1.get_address_base58(), states[1][0][0])
     states[1][0][1] = Data.to_b58_address(states[1][0][1])
     self.assertEqual(acct2.get_address_base58(), states[1][0][1])
     states[1][0][2] = Data.to_int(states[1][0][2])
     self.assertEqual(10, states[1][0][2])
     states[1][1][0] = Data.to_b58_address(states[1][1][0])
     self.assertEqual(acct2.get_address_base58(), states[1][1][0])
     states[1][1][1] = Data.to_b58_address(states[1][1][1])
     self.assertEqual(acct3.get_address_base58(), states[1][1][1])
     states[1][1][2] = Data.to_int(states[1][1][2])
     self.assertEqual(100, states[1][1][2])
示例#2
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))
示例#3
0
 def test_invoke_notify_transaction(self):
     func = WasmInvokeFunction('notify')
     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 = '5daf0ec53b21abfab6459c7ba7f760c376e18ebf07066e6f74696679'
     self.assertEqual(target_payload, tx.payload.hex())
     tx.sign_transaction(acct3)
     result = sdk.rpc.send_raw_transaction_pre_exec(tx)
     notify = result.get('Notify')[0]
     self.assertEqual(self.basic_test_case_contract_address,
                      notify.get('ContractAddress'))
     self.assertEqual('hello', notify.get('States')[0])
示例#4
0
    def test_oep4_transfer_multi(self):
        hex_contract_address = '1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'
        bytes_from_address1 = acct1.get_address().to_bytes()
        bytes_to_address1 = acct2.get_address().to_bytes()
        value1 = 2
        transfer1 = [bytes_from_address1, bytes_to_address1, value1]
        bytes_from_address2 = acct2.get_address().to_bytes()
        bytes_to_address2 = acct3.get_address().to_bytes()
        value2 = 1
        transfer2 = [bytes_from_address2, bytes_to_address2, value2]
        func = InvokeFunction('transferMulti')
        func.set_params_value(transfer1, transfer2)
        tx_hash = sdk.default_network.send_neo_vm_transaction(
            hex_contract_address, acct1, acct2, self.gas_price, self.gas_limit,
            func, False)
        time.sleep(randint(10, 15))
        event = sdk.rpc.get_contract_event_by_tx_hash(tx_hash)
        states_list = Event.get_states_by_contract_address(
            event, hex_contract_address)
        states_list[0][0] = Data.to_utf8_str(states_list[0][0])
        self.assertEqual('transfer', states_list[0][0])
        states_list[0][1] = Data.to_b58_address(states_list[0][1])
        self.assertEqual(acct1.get_address().b58encode(), states_list[0][1])
        states_list[0][2] = Data.to_b58_address(states_list[0][2])
        self.assertEqual(acct2.get_address().b58encode(), states_list[0][2])
        states_list[0][3] = Data.to_int(states_list[0][3])
        self.assertEqual(value1, states_list[0][3])

        states_list[1][0] = Data.to_utf8_str(states_list[1][0])
        self.assertEqual('transfer', states_list[1][0])
        states_list[1][1] = Data.to_b58_address(states_list[1][1])
        self.assertEqual(acct2.get_address().b58encode(), states_list[1][1])
        states_list[1][2] = Data.to_b58_address(states_list[1][2])
        self.assertEqual(acct3.get_address().b58encode(), states_list[1][2])
        states_list[1][3] = Data.to_int(states_list[1][3])
        self.assertEqual(value2, states_list[1][3])
示例#5
0
 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))