Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Merge 335d753 into 60c8f8c
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Jun 5, 2019
2 parents 60c8f8c + 335d753 commit 0fcd887
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ All notable changes to this project are documented in this file.
- Fix ``config maxpeers`` and update tests
- Fix error while parsing list arguments from prompt for smart contract test invocations
- Fix ``Runtime.GetTrigger`` and ``Transaction.GetType`` syscalls pushing wrong StackItem type
- Update handling of default cause for ``PICKITEM`` instruction


[0.8.4] 2019-02-14
Expand Down
4 changes: 2 additions & 2 deletions neo/SmartContract/tests/test_vm_error_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def test_negative_array_indexing(self):

def test_invalid_type_indexing(self):
with self.assertLogHandler('vm', DEBUG) as log_context:
tx, results, total_ops, engine = TestBuild(self.script, [3, ['my_arg0']], self.GetWallet1(), '0210', '07')
tx, results, total_ops, engine = TestBuild(self.script, [3, [1]], self.GetWallet1(), '0210', '07')
self.assertTrue(len(log_context.output) > 0)
log_msg = log_context.output[0]
# an index of 1 for an array with length one is out of bounds
self.assertTrue("Array index is less than zero or 1 exceeds list length 1" in log_msg)
self.assertTrue("Item is not an Array or Map but of type" in log_msg)

def test_invalid_appcall(self):
with self.assertLogHandler('vm', DEBUG) as log_context:
Expand Down
10 changes: 2 additions & 8 deletions neo/VM/ExecutionEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,13 +924,7 @@ def ExecuteInstruction(self):
else:
return self.VM_FAULT_and_report(VMFault.DICT_KEY_NOT_FOUND, key, collection.Keys)
else:
byte_array = collection.GetByteArray()
index = key.GetBigInteger()
if index < 0 or index >= len(byte_array):
self.VM_FAULT_and_report(VMFault.PICKITEM_INVALID_INDEX, index, len(byte_array))
return
estack.PushT(byte_array[index])
self.CheckStackSize(True, -1)
return self.VM_FAULT_and_report(VMFault.PICKITEM_INVALID_TYPE, key, collection)

elif opcode == SETITEM:
value = estack.Pop()
Expand Down Expand Up @@ -1290,7 +1284,7 @@ def VM_FAULT_and_report(self, id, *args):
elif id == VMFault.PICKITEM_INVALID_TYPE:
index = args[0]
item = args[1]
error_msg = "Cannot access item at index {}. Item is not an array or dict but of type: {}".format(index, type(item))
error_msg = "Cannot access item at index {}. Item is not an Array or Map but of type: {}".format(index, type(item))

elif id == VMFault.PICKITEM_NEGATIVE_INDEX:
error_msg = "Attempting to access an array using a negative index"
Expand Down
15 changes: 0 additions & 15 deletions neo/VM/tests/test_interop_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,6 @@ def test_op_map7(self):
self.assertTrue(len(log_context.output) > 0)
self.assertTrue('VMFault.KEY_IS_COLLECTION' in log_context.output[0])

def test_op_map8(self):
with self.assertLogHandler('vm', logging.DEBUG) as log_context:
# pick item out of bounds
self.econtext.EvaluationStack.PushT(StackItem.New('a'))
self.econtext.EvaluationStack.PushT(StackItem.New('a'))
self.econtext.Script._value = OpCode.PICKITEM
self.engine.ExecuteInstruction()

self.assertTrue(len(log_context.output) > 0)
log_msg = log_context.output[0]
expected_msg = "Array index is less than zero or 97 exceeds list length 1"
self.assertTrue(expected_msg in log_msg)

self.assertEqual(self.engine.State, VMState.FAULT)

def test_op_map9(self):
with self.assertLogHandler('vm', logging.DEBUG) as log_context:
# pick item key not found
Expand Down

0 comments on commit 0fcd887

Please sign in to comment.