naitve: disallow contract name modification

This commit is contained in:
Evgeniy Stratonikov 2021-01-28 16:43:41 +03:00
parent c1cc7e6f9d
commit 2336415f42
2 changed files with 14 additions and 0 deletions

View file

@ -322,6 +322,9 @@ func (m *Management) Update(d dao.DAO, hash util.Uint160, neff *nef.File, manif
}
// if manifest was provided, update the contract manifest
if manif != nil {
if manif.Name != contract.Manifest.Name {
return nil, errors.New("contract name can't be changed")
}
if !manif.IsValid(contract.Hash) {
return nil, errors.New("invalid manifest for this contract")
}

View file

@ -375,6 +375,17 @@ func TestContractUpdate(t *testing.T) {
checkFAULTState(t, res)
})
t.Run("change name", func(t *testing.T) {
var badManifest = cs1.Manifest
badManifest.Name += "tail"
manifB, err := json.Marshal(badManifest)
require.NoError(t, err)
res, err := invokeContractMethod(bc, 10_00000000, cs1.Hash, "update", nef1b, manifB)
require.NoError(t, err)
checkFAULTState(t, res)
})
cs1.NEF.Script = append(cs1.NEF.Script, byte(opcode.RET))
cs1.NEF.Checksum = cs1.NEF.CalculateChecksum()
nef1b, err = cs1.NEF.Bytes()