diff --git a/internal/contracts/contracts_test.go b/internal/contracts/contracts_test.go index c757f9651..9b6fea22d 100644 --- a/internal/contracts/contracts_test.go +++ b/internal/contracts/contracts_test.go @@ -226,9 +226,11 @@ func generateManagementHelperContracts(t *testing.T, saveState bool) { emit.AppCall(w.BinWriter, mgmtHash, "destroy", callflag.All) emit.Opcodes(w.BinWriter, opcode.DROP) emit.Opcodes(w.BinWriter, opcode.RET) - invalidStackOff := w.Len() + invalidStack1Off := w.Len() emit.Opcodes(w.BinWriter, opcode.NEWARRAY0, opcode.DUP, opcode.DUP, opcode.APPEND) // recursive array - emit.Syscall(w.BinWriter, interopnames.SystemStorageGetReadOnlyContext) // interop item + emit.Opcodes(w.BinWriter, opcode.RET) + invalidStack2Off := w.Len() + emit.Syscall(w.BinWriter, interopnames.SystemStorageGetReadOnlyContext) // interop item emit.Opcodes(w.BinWriter, opcode.RET) callT0Off := w.Len() emit.Opcodes(w.BinWriter, opcode.CALLT, 0, 0, opcode.PUSH1, opcode.ADD, opcode.RET) @@ -380,9 +382,14 @@ func generateManagementHelperContracts(t *testing.T, saveState bool) { ReturnType: smartcontract.VoidType, }, { - Name: "invalidStack", - Offset: invalidStackOff, - ReturnType: smartcontract.VoidType, + Name: "invalidStack1", + Offset: invalidStack1Off, + ReturnType: smartcontract.AnyType, + }, + { + Name: "invalidStack2", + Offset: invalidStack2Off, + ReturnType: smartcontract.AnyType, }, { Name: "callT0", diff --git a/internal/contracts/management_helper/management_helper1.manifest.json b/internal/contracts/management_helper/management_helper1.manifest.json index b7b549053..181b16b7c 100644 --- a/internal/contracts/management_helper/management_helper1.manifest.json +++ b/internal/contracts/management_helper/management_helper1.manifest.json @@ -1 +1 @@ -{"name":"TestMain","abi":{"methods":[{"name":"add","offset":1,"parameters":[{"name":"addend1","type":"Integer"},{"name":"addend2","type":"Integer"}],"returntype":"Integer","safe":false},{"name":"add","offset":3,"parameters":[{"name":"addend1","type":"Integer"},{"name":"addend2","type":"Integer"},{"name":"addend3","type":"Integer"}],"returntype":"Integer","safe":false},{"name":"ret7","offset":6,"parameters":[],"returntype":"Integer","safe":false},{"name":"drop","offset":8,"parameters":null,"returntype":"Void","safe":false},{"name":"_initialize","offset":10,"parameters":null,"returntype":"Void","safe":false},{"name":"add3","offset":15,"parameters":[{"name":"addend","type":"Integer"}],"returntype":"Integer","safe":false},{"name":"invalidReturn","offset":18,"parameters":null,"returntype":"Integer","safe":false},{"name":"justReturn","offset":21,"parameters":null,"returntype":"Void","safe":false},{"name":"verify","offset":22,"parameters":null,"returntype":"Boolean","safe":false},{"name":"_deploy","offset":27,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"getValue","offset":158,"parameters":null,"returntype":"String","safe":false},{"name":"putValue","offset":138,"parameters":[{"name":"value","type":"String"}],"returntype":"Void","safe":false},{"name":"delValue","offset":178,"parameters":[{"name":"key","type":"String"}],"returntype":"Void","safe":false},{"name":"onNEP11Payment","offset":215,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"tokenid","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":189,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"update","offset":244,"parameters":[{"name":"nef","type":"ByteArray"},{"name":"manifest","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"update","offset":241,"parameters":[{"name":"nef","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"destroy","offset":284,"parameters":null,"returntype":"Void","safe":false},{"name":"invalidStack","offset":324,"parameters":null,"returntype":"Void","safe":false},{"name":"callT0","offset":334,"parameters":[{"name":"address","type":"Hash160"}],"returntype":"Integer","safe":false},{"name":"callT1","offset":340,"parameters":null,"returntype":"Integer","safe":false},{"name":"callT2","offset":344,"parameters":null,"returntype":"Integer","safe":false},{"name":"burnGas","offset":348,"parameters":[{"name":"amount","type":"Integer"}],"returntype":"Void","safe":false},{"name":"invocCounter","offset":354,"parameters":null,"returntype":"Integer","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5","methods":["balanceOf"]},{"contract":"0x0000000000000000000000000000000000000000","methods":["method"]}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file +{"name":"TestMain","abi":{"methods":[{"name":"add","offset":1,"parameters":[{"name":"addend1","type":"Integer"},{"name":"addend2","type":"Integer"}],"returntype":"Integer","safe":false},{"name":"add","offset":3,"parameters":[{"name":"addend1","type":"Integer"},{"name":"addend2","type":"Integer"},{"name":"addend3","type":"Integer"}],"returntype":"Integer","safe":false},{"name":"ret7","offset":6,"parameters":[],"returntype":"Integer","safe":false},{"name":"drop","offset":8,"parameters":null,"returntype":"Void","safe":false},{"name":"_initialize","offset":10,"parameters":null,"returntype":"Void","safe":false},{"name":"add3","offset":15,"parameters":[{"name":"addend","type":"Integer"}],"returntype":"Integer","safe":false},{"name":"invalidReturn","offset":18,"parameters":null,"returntype":"Integer","safe":false},{"name":"justReturn","offset":21,"parameters":null,"returntype":"Void","safe":false},{"name":"verify","offset":22,"parameters":null,"returntype":"Boolean","safe":false},{"name":"_deploy","offset":27,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"getValue","offset":158,"parameters":null,"returntype":"String","safe":false},{"name":"putValue","offset":138,"parameters":[{"name":"value","type":"String"}],"returntype":"Void","safe":false},{"name":"delValue","offset":178,"parameters":[{"name":"key","type":"String"}],"returntype":"Void","safe":false},{"name":"onNEP11Payment","offset":215,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"tokenid","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":189,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"update","offset":244,"parameters":[{"name":"nef","type":"ByteArray"},{"name":"manifest","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"update","offset":241,"parameters":[{"name":"nef","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"destroy","offset":284,"parameters":null,"returntype":"Void","safe":false},{"name":"invalidStack1","offset":324,"parameters":null,"returntype":"Any","safe":false},{"name":"invalidStack2","offset":329,"parameters":null,"returntype":"Any","safe":false},{"name":"callT0","offset":335,"parameters":[{"name":"address","type":"Hash160"}],"returntype":"Integer","safe":false},{"name":"callT1","offset":341,"parameters":null,"returntype":"Integer","safe":false},{"name":"callT2","offset":345,"parameters":null,"returntype":"Integer","safe":false},{"name":"burnGas","offset":349,"parameters":[{"name":"amount","type":"Integer"}],"returntype":"Void","safe":false},{"name":"invocCounter","offset":355,"parameters":null,"returntype":"Integer","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5","methods":["balanceOf"]},{"contract":"0x0000000000000000000000000000000000000000","methods":["method"]}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/internal/contracts/management_helper/management_helper1.nef b/internal/contracts/management_helper/management_helper1.nef index 7f37f6ea2..85288654f 100644 Binary files a/internal/contracts/management_helper/management_helper1.nef and b/internal/contracts/management_helper/management_helper1.nef differ diff --git a/internal/contracts/management_helper/management_helper2.manifest.json b/internal/contracts/management_helper/management_helper2.manifest.json index a02302fc0..1f4efc56c 100644 --- a/internal/contracts/management_helper/management_helper2.manifest.json +++ b/internal/contracts/management_helper/management_helper2.manifest.json @@ -1 +1 @@ -{"name":"TestAux","abi":{"methods":[{"name":"simpleMethod","offset":0,"parameters":null,"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"0xf2bf3585b5b3287fd65bc0451b348714b4fdb908","methods":["add","drop","add3","invalidReturn","justReturn","getValue"]}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file +{"name":"TestAux","abi":{"methods":[{"name":"simpleMethod","offset":0,"parameters":null,"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"0x5a6a3b6c716e31465ed9be0b234d6223498c9f4e","methods":["add","drop","add3","invalidReturn","justReturn","getValue"]}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/pkg/core/blockchain_core_test.go b/pkg/core/blockchain_core_test.go index 93791d447..fc1025cf3 100644 --- a/pkg/core/blockchain_core_test.go +++ b/pkg/core/blockchain_core_test.go @@ -1699,11 +1699,15 @@ func TestInvalidNotification(t *testing.T) { cs, _ := contracts.GetTestContractState(t, pathToInternalContracts, 4, 5, random.Uint160()) // sender and IDs are not important for the test require.NoError(t, bc.contracts.Management.PutContractState(bc.dao, cs)) - aer, err := invokeContractMethod(bc, 1_00000000, cs.Hash, "invalidStack") + aer, err := invokeContractMethod(bc, 1_00000000, cs.Hash, "invalidStack1") require.NoError(t, err) - require.Equal(t, 2, len(aer.Stack)) + require.Equal(t, 1, len(aer.Stack)) require.Nil(t, aer.Stack[0]) - require.Equal(t, stackitem.InteropT, aer.Stack[1].Type()) + + aer, err = invokeContractMethod(bc, 1_00000000, cs.Hash, "invalidStack2") + require.NoError(t, err) + require.Equal(t, 1, len(aer.Stack)) + require.Equal(t, stackitem.InteropT, aer.Stack[0].Type()) } // Test that deletion of non-existent doesn't result in error in tx or block addition.