core: fix Management.GetContract

This commit is contained in:
Anna Shaleva 2021-03-19 20:05:05 +03:00
parent 57d4990fe6
commit 96e198de97
2 changed files with 9 additions and 8 deletions

View file

@ -131,6 +131,9 @@ func (m *Management) getContract(ic *interop.Context, args []stackitem.Item) sta
}
ctr, err := m.GetContract(ic.DAO, hash)
if err != nil {
if err == storage.ErrKeyNotFound {
return stackitem.Null{}
}
panic(err)
}
return contractToStack(ctr)

View file

@ -349,14 +349,14 @@ func checkContractState(t *testing.T, bc *Blockchain, h util.Uint160, cs *state.
mgmtHash := bc.contracts.Management.Hash
res, err := invokeContractMethod(bc, 1_00000000, mgmtHash, "getContract", h.BytesBE())
require.NoError(t, err)
if cs == nil {
require.Equal(t, vm.FaultState, res.VMState)
return
}
require.Equal(t, vm.HaltState, res.VMState)
require.Equal(t, 1, len(res.Stack))
if cs == nil {
require.Equal(t, stackitem.Null{}, res.Stack[0])
} else {
compareContractStates(t, cs, res.Stack[0])
}
}
func TestContractUpdate(t *testing.T) {
bc := newTestChain(t)
@ -574,9 +574,7 @@ func TestContractDestroy(t *testing.T) {
Item: stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(cs1.Hash.BytesBE())}),
}})
t.Run("check contract", func(t *testing.T) {
res, err := invokeContractMethod(bc, 1_00000000, mgmtHash, "getContract", cs1.Hash.BytesBE())
require.NoError(t, err)
checkFAULTState(t, res)
checkContractState(t, bc, cs1.Hash, nil)
})
})